<?php $render('header', ['loggedUser'=>$loggedUser, 'title'=>$titlePage]); ?>
<?=$render('sidebar', [
  'loggedUser'=>$loggedUser, 
  'pageActive'=>$pageActive,
  'permissions'=>$permissions
]);?>

<!-- Content System -->
<div class="content-wrapper">
  <div class="pages">
    <h3>Relatório de Contas a Pagar</h3>
    <div class="users">

      <div class="filters filter_responsive">

        <form method="POST" action="<?= $base; ?>/reportbillstopay">
          <input type="hidden" id="isclear" name="filter[clear]">

          <div class="filter-items">
            <select class="form-control" name="filter[expirate_where]">
              <option value="expirate_date" <?= ($arrayInfo['filter']['expirate_where'] == 'expirate_date')?'selected':''; ?> >Vencimento</option>
              <option value="payment_date" <?= ($arrayInfo['filter']['expirate_where'] == 'payment_date')?'selected':''; ?> >Pagamento</option>
            </select>

            <div class="dates" style="display: flex; margin-right: 10px;">
              <input type="text" name="filter[d_init]" id="dateInit" class="form-control" style="width: 120px!important;" placeholder="00/00/0000" value="<?= $arrayInfo['filter']['d_init']; ?>">

              <input type="text" name="filter[d_end]" id="dateEnd" class="form-control" style="width: 120px!important; margin-left: 10px;" placeholder="00/00/0000" value="<?= $arrayInfo['filter']['d_end']; ?>">
            </div>

            <!-- Status da conta -->
            <select class="form-control" name="filter[status]" style="width: 100px;">  
              <option value="1" <?= ($arrayInfo['filter']['status'] == '1')?'selected':'' ?> >Ativa</option>
              <option value="2" <?= ($arrayInfo['filter']['status'] == '2')?'selected':'' ?> >Inativa</option>     
            </select>

            <input type="text" class="form-control" style="width: 100px; margin: 0 10px 5px 0" placeholder="Nr Doc" name="filter[document_number]" value="<?= $arrayInfo['filter']['document_number']; ?>">

            <!-- Lista de tipos de contas a Pagar -->
            <div class="type_payaccount form-control">
              <a href="#">Tipo de conta a pagar</a>
              <div class="type_payaccount_list">
                <?php foreach($arrayInfo['billstype_list'] as $bills_type): ?>
                  <label>
                    <?= $bills_type['name']; ?>
                    <input type="checkbox" id="<?= $bills_type['id'] ?>" name="filter[bills_type][]" <?= (isset($arrayInfo['filter']['bills_type']) && in_array($bills_type['id'], $arrayInfo['filter']['bills_type']))?'checked':''; ?> value="<?= $bills_type['id'] ?>">
                  </label>
                <?php endforeach; ?>
              </div>
            </div>

            <!-- Lista de Fornecedores -->
            <div style="position: relative;">
              <input type="hidden" name="filter[provider]" value="<?= $arrayInfo['filter']['provider']; ?>">
              
              <input type="text" name="filter[provider_name]" style="width: 300px; margin-right: 10px;" class="form-control" id="search_provider" placeholder="Pesquisar Descrição..." value="<?= $arrayInfo['filter']['provider_name']; ?>">
            </div>

            <!-- Lista de origem de Pagamentos -->
            <div class="origin-payment form-control">
              <a href="#">Origem do Pagamento</a>
              <div class="option-pay-form">
                <?php foreach($arrayInfo['payment_form'] as $payment_item): ?>
                  <label>
                    <?= $payment_item['name']; ?>
                    <input type="checkbox" id="<?= $payment_item['id'] ?>" name="filter[payment_form][]" <?= (isset($arrayInfo['filter']['payment_form']) && in_array($payment_item['id'], $arrayInfo['filter']['payment_form']))?'checked':''; ?> value="<?= $payment_item['id'] ?>">
                  </label>
                <?php endforeach; ?>
              </div>
            </div>

            <!-- Situação da conta -->
            <div class="account-situation form-control">
              <a href="#">Situação da conta</a>
              <div class="option-acc-situation">
                <?php foreach($arrayInfo['situations'] as $situation_item): ?>
                  <label>
                    <?= $situation_item['name']; ?>
                    <input type="checkbox" id="<?= $situation_item['id'] ?>" name="filter[situation_account][]" <?= (isset($arrayInfo['filter']['situation_account']) && in_array($situation_item['id'], $arrayInfo['filter']['situation_account']))?'checked':''; ?> value="<?= $situation_item['id'] ?>">
                  </label>
                <?php endforeach; ?>
              </div>
            </div>

            <select class="form-control" name="filter[print]">
              <option value="">Formato</option>
              <option value="P" <?= ($arrayInfo['filter']['print'] == 'P')?'selected':'' ?> >Retrato</option>
              <option value="L" <?= ($arrayInfo['filter']['print'] == 'L')?'selected':'' ?> >Paisagem</option>
            </select>

            <input type="text" name="filter[limit]" id="max_result" class="form-control" value="<?= $arrayInfo['filter']['limit']; ?>">

            <button type="submit" id="submit_form" class="proccess">PROCESSAR</button>
            <button id="reports_billtopay" class="proccess">LIMPAR</button>
          </div>
        </form>

        <div class="filter-buttons">
          <a href="<?= $base; ?>/reportbillstopaypdf" target="_blank" class="btn btn-success">PDF</a>
          <a href="<?= $base; ?>/reportbillstopaycsv" target="_blank" class="btn btn-success">Excel</a>
        </div>

      </div>

      <table class="table table-bordered">
        <tbody>
          <tr>
            <th scope="col">Item</th>
            <th scope="col">Dt de vencimento</th>
            <th scope="col">Status</th>
            <th scope="col">Nr Pedido</th>
            <th scope="col">Nr Documento</th>
            <th scope="col">Descrição do Recebedor</th>
            <th scope="col">Tipo de conta</th>        
            <th scope="col">Origem do Pgto</th>
            <th scope="col">Situação da Conta</th>
            <th scope="col">Data do Pgto</th>
            <th scope="col">Valor a Pagar R$</th>
            <th scope="col" style="width: 160px!important;">Valor pago R$</th>
          </tr>

          <?php foreach ($arrayInfo['content']['result'] as $key => $btp_item): ?>
            <tr>
              <td><?= ($key + 1); ?></td>
              <td><?= $btp_item['expirate_date']; ?></td>
              <td><?= ($btp_item['status'] == 1)?'Ativo':'Inativo'; ?></td>
              <td><?= $btp_item['id_request']; ?></td>
              <td><?= $btp_item['document_number']; ?></td>
              <td><?= $btp_item['provider_description']; ?></td>
              <td><?= $btp_item['type_name']; ?></td>
              <td><?= $btp_item['formpay_name']; ?></td>
              <td><?= $btp_item['situation']['name']; ?></td>
              <td><?= $btp_item['payment_date']; ?></td>
              <td><?= $btp_item['value_to_pay']; ?></td>
              <td><?= $btp_item['paid_out_value']; ?></td>
            </tr>
          <?php endforeach; ?>

        </tbody>
      </table>

      <div class="view-total-purchase">
        <label style="font-size: 0.8rem;">Total a Pagar</label>
        <input type="text" class="form-control" readonly value="R$ <?= $arrayInfo['content']['total_pay']; ?>">
      </div>

      <div class="view-total-purchase">
        <label style="font-size: 0.8rem;">Total Pago</label>
        <input type="text" class="form-control" readonly value="R$ <?= $arrayInfo['content']['total']; ?>">
      </div>

    </div>
    
    <script src="<?= $base; ?>/assets/js/reports.js"></script>
    <script src="<?= $base; ?>/assets/js/billstopay_reports.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

<?=$render('footer');?>