<?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 Entregas</h3>
    <div class="users">
      <div class="filters filter_responsive">
        <form method="POST" action="<?= $base; ?>/reportdeliveries">
          <input type="hidden" id="isclear" name="filter[clear]">

          <div class="filter-items">
            <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>

            <div class="b_situation form-control" id="b_situation">
              <a href="#">Situação</a>
              <div class="status_r logistic" style=" flex-direction: column;">
                <?php foreach($arrayInfo['status_list'] as $status): ?>

                  <label>
                    <?= $status['name']; ?>
                    <input type="checkbox" id="<?= $status['id'] ?>" name="filter[status][]" <?= (isset($arrayInfo['filter']['status']) && in_array($status['id'], $arrayInfo['filter']['status']))?'checked':''; ?> value="<?= $status['id'] ?>">
                  </label>

                <?php endforeach; ?>
              </div>
            </div>

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

            <!-- Número do Doc -->
            <div style="margin-right: 10px;">
              <input type="text" name="filter[doc_number]" id="id_doc_number" style="width: 100px;" class="form-control" placeholder="Nr doc..." value="<?= $arrayInfo['filter']['doc_number']; ?>">
            </div>            

            <!-- Grupo de produtos -->
            <select class="form-control" name="filter[p_group]">
              <option value="">Grupo</option>
              <?php foreach($arrayInfo['group_list'] as $group): ?>
                <option value="<?= $group['id'] ?>" <?= ($arrayInfo['filter']['p_group'] == $group['id'])?'selected':'' ?> ><?= $group['name'] ?></option>
              <?php endforeach; ?>
            </select>

            <!-- Lista de produtos -->
            <select class="form-control" name="filter[product]" style="width: 300px;">
              <option value="">Produtos</option>
              <?php foreach($arrayInfo['products_list'] as $product): ?>
                <option value="<?= $product['id'] ?>" <?= ($arrayInfo['filter']['product'] == $product['id'])?'selected':'' ?> ><?= $product['name'] ?></option>
              <?php endforeach; ?>
            </select>

            <!-- Trasnaportadoras -->
            <select class="form-control" style="width: 250px;" name="filter[shipping_comp]">
              <option value="">Transportadoras</option>
              <?php foreach($arrayInfo['shipping_comp'] as $shipping): ?>
                <option value="<?= $shipping['id'] ?>" <?= ($arrayInfo['filter']['shipping_comp'] == $shipping['id'])?'selected':'' ?> ><?= $shipping['company_name'] ?></option>
              <?php endforeach; ?>
            </select>

            <!-- Lista de Clientes -->
            <div style="position: relative;">
              <input type="hidden" name="filter[client]" value="<?= $arrayInfo['filter']['client']; ?>">

              <input type="text" name="filter[client_name]" style="width: 300px; margin-right: 10px;" class="form-control" id="search_client" placeholder="Pesquisar por cliente..." value="<?= $arrayInfo['filter']['client_name']; ?>">

              <div class="result-here searchresultclient"></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: 250px; margin-right: 10px;" class="form-control" id="search_provider" placeholder="Pesquisar por fornecedor..." value="<?= $arrayInfo['filter']['provider_name']; ?>">
              
              <div class="result-here searchresultsprov"></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_logistic" class="proccess">LIMPAR</button>
          </div>
        </form>

        <div class="filter-buttons">
          <a href="<?= $base; ?>/reportdeliveriespdf" target="_blank" class="btn btn-success">PDF</a>
          <a href="<?= $base; ?>/reportdeliveriescsv" 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 da Entrega</th>
            <th scope="col">Situação da entrega</th>
            <th scope="col">Nr do pedido</th>
            <th scope="col">Nr da entrega</th>
            <th scope="col">Fornecedor</th>
            <th scope="col">Cliente</th>        
            <th scope="col">Produto</th>
            <th scope="col">Transportadora</th>
            <th scope="col">Qtde</th>
            <th scope="col">Nº Documento</th>
            <th scope="col" style="width: 160px!important;">Valor da entrega R$</th>
          </tr>

          <?php foreach ($arrayInfo['content']['result'] as $key => $l_item): ?>
            <tr>
              <td><?= ($key + 1); ?></td>
              <td><?= $l_item['date_deliverie']; ?></td>
              <td><?= $l_item['situation_name']; ?></td>
              <td><?= $l_item['deliveryInfo']['id_request']; ?></td>
              <td><?= $l_item['delivery_number']; ?></td>
              <td><?= $l_item['provider']; ?></td>
              <td><?= $l_item['client']; ?></td>
              <td><?= $l_item['product']; ?></td>
              <td><?= $l_item['shipping_company']; ?></td>
              <td><?= (!empty($l_item['amount_balance']))?$l_item['amount_balance']:$l_item['amount']; ?></td>
              <td><?= $l_item['shipping_invoice']; ?></td>
              <td style="width: 160px!important;"><?= (!empty($l_item['value_delivery_balance']))?$l_item['value_delivery_balance']:$l_item['value_delivery']; ?></td>
            </tr>
          <?php endforeach; ?>

        </tbody>
      </table>

      <!-- Total Balança -->
      <div class="view-total-purchase" style="width: 100%;margin: 20px 0; float: left; text-align: right; display: flex; align-items: center; justify-content: flex-end;">
        <label style="font-size: 0.8rem;">Soma das Quantides</label>
        <input type="text" class="form-control" readonly style="width: auto;float: right;border: 2px solid #152242; padding: 10px; color: #333; font-size: 17px; font-weight: bold; margin-left: 15px;" value="R$ <?= $arrayInfo['content']['total_balance']; ?>">
      </div>
      <!-- Total Valor Entrega -->
      <div class="view-total-purchase" style="width: 100%;margin: 20px 0; float: left; text-align: right; display: flex; align-items: center; justify-content: flex-end;">
        <label style="font-size: 0.8rem;">Soma Valor de Entrega:</label>
        <input type="text" class="form-control" readonly style="width: auto;float: right;border: 2px solid #152242; padding: 10px; color: #333; font-size: 17px; font-weight: bold; margin-left: 15px;" value="R$ <?= $arrayInfo['content']['total_vdelivery']; ?>">
      </div>

    </div>

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

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

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