<?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><?= $titlePage; ?></h3>
    <div class="users">

      <div class="filters filter_responsive">

        <form method="POST" action="<?= $base; ?>/reportpurchases">
          <input type="hidden" id="isclear" name="filter[clear]">
          <div class="filter-items">
            <select class="form-control" name="filter[by]">
              <option value="provider" <?= ($arrayInfo['filter']['by'] == 'provider')?'selected':''; ?> >Fornecedor</option>
              <option value="product" <?= ($arrayInfo['filter']['by'] == 'product')?'selected':''; ?> >Produto</option>          
            </select>

            <div style="position: relative;">
              <input type="hidden" name="filter[by_selected]" value="<?= $arrayInfo['filter']['by_selected']; ?>">
              <input type="text" name="filter[text]" style="width: 300px; margin-right: 10px;" class="form-control" id="search_by" placeholder="Pesquisar..." value="<?= $arrayInfo['filter']['text']; ?>">

              <div class="result-here searchresultall"></div>              
            </div>

            <select class="form-control" name="filter[p_group]">
              <option value="">Grupo</option>
              <option value="2" <?= ($arrayInfo['filter']['p_group'] == 2)?'selected':'' ?> >Com Estoque</option>
              <option value="1" <?= ($arrayInfo['filter']['p_group'] == 1)?'selected':'' ?> >Sem Estoque</option>
              <option value="3" <?= ($arrayInfo['filter']['p_group'] == 3)?'selected':'' ?> >Especial</option>
            </select>

            <!-- 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['paymentForm'] as $payment_item): ?>
                  <label>
                    <?= $payment_item['name']; ?>
                    <input type="checkbox" name="filter[payment_form][]" <?= (!empty($arrayInfo['filter']['payment_form']) && in_array($payment_item['id'], $arrayInfo['filter']['payment_form']))?'checked':''; ?> value="<?= $payment_item['id'] ?>">
                  </label>
                <?php endforeach; ?>
              </div>
            </div>
            
            <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>

            <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" class="proccess">PROCESSAR</button>
            <button id="reports_purchases" class="proccess">LIMPAR</button>
          </div>
        </form>

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


      <table class="table table-bordered">
        <tbody>
          
          <?= $data['head']; ?>

          <?= $data['body']; ?>

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

    <script src="<?= $base ?>/assets/js/reports.js"></script>
    <script src="<?= $base ?>/assets/js/purchases_reports.js"></script>

  </div>  		
</div>
<!-- /.content-system -->

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