<?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 Receber</h3>
    <div class="users">
      <div class="filters filter_responsive">

        <form method="POST" action="<?= $base; ?>/reportbillstoreceiver">
          <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':''; ?> >Recebimento</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>

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

            <!-- Lista de origens de contas a Receber -->
            <select class="form-control" name="filter[origin_type]" style="width: 200px;">
              <option value="">Origem do recebimento</option>
              <?php foreach($arrayInfo['receiver_origin'] as $origin_type): ?>
                <option value="<?= $origin_type['id'] ?>" <?= ($arrayInfo['filter']['origin_type'] == $origin_type['id'])?'selected':'' ?> ><?= $origin_type['name'] ?></option>
              <?php endforeach; ?>
            </select>

            <!-- Lista de origem de Recebimentos -->
            <div class="origin-payment form-control">
              <a href="#">Forma de recebimento</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>

            <!-- Nr do pedido -->
            <div style="position: relative;">
              <input type="text" name="filter[request_number]" style="width: 100px; margin-right: 10px;" class="form-control" id="request_number" placeholder="Nr Pedido..." value="<?= $arrayInfo['filter']['request_number']; ?>">
            </div>

            <!-- Nr do Documento -->
            <div style="position: relative;">
              <input type="text" name="filter[document_number]" style="width: 100px; margin-right: 10px;" class="form-control" id="document_number" placeholder="Nr Doc..." value="<?= $arrayInfo['filter']['document_number']; ?>">
            </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_billstoreceiver" class="proccess">LIMPAR</button>
          </div>
        </form>

        <div class="filter-buttons">
          <a href="<?= $base; ?>/reportbillstoreceiverpdf" target="_blank" class="btn btn-success">PDF</a>
          <a href="<?= $base; ?>/reportbillstoreceivercsv" 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 a receber</th>
            <th scope="col">Status</th>
            <th scope="col">Descrição do pagador</th>     
            <th scope="col">nº do Documento</th>
            <th scope="col">nº do Pedido</th>
            <th scope="col">Origem do recebimento</th>
            <th scope="col">Forma de recebimento</th>
            <th scope="col">Situação da Conta</th>
            <th scope="col">Data do recebimento</th>
            <th scope="col">Valor a receber R$</th>
            <th scope="col" style="width: 160px!important;">Valor recebido R$</th>
          </tr>

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

        </tbody>
      </table>

      <div class="view-total-purchase">
        <label style="font-size: 0.8rem;">Total a Receber</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 Recebido</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');?>