<?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 Fazendas por Cliente(s)</h3>
    <div class="users">

      <div class="filters filter_responsive">

        <form method="POST" action="<?= $base; ?>/reportfarms">
          <input type="hidden" id="isclear" name="filter[clear]">
          <div class="filter-items">        
            <select class="form-control" name="filter[searchType]">
              <option value="">Status</option>
              <option value="1" <?= ($arrayInfo['filter']['searchType'] == '1')?'selected':''; ?> >Ativo</option>
              <option value="2" <?= ($arrayInfo['filter']['searchType'] == '2')?'selected':''; ?> >Inativo</option>
            </select>

            <select class="form-control" name="filter[state]">
              <option value="">Estado</option>
              <?php foreach($arrayInfo['stateList'] as $state): ?>
                <option value="<?= $state['uf']; ?>" <?= ($arrayInfo['filter']['state'] ==  $state['uf'])?'selected':''; ?> ><?= $state['uf']; ?></option>
              <?php endforeach; ?>
            </select>

            <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>

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

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

      <table class="table table-bordered" id="reports">
        <tbody>
          <tr>
            <th scope="col">Item</th>
            <th scope="col">Status</th>
            <th scope="col">Cliente</th>
            <th scope="col">Fazenda</th>
            <th scope="col">Inscrição Estadual</th>
            <th scope="col">Responsável na Fazenda</th>
            <th scope="col">Fone resp na Fazenda</th>
            <th scope="col">Cidade-UF</th>
          </tr>

          <?php foreach($arrayInfo['farmsInfo'] as $key => $farm): ?>
            <tr>
              <td><?= ($key + 1); ?></td>
              <td><?= ($farm['status'] == 1)?'Ativo':'Inativo'; ?></td>
              <td><?= $farm['client_name']; ?></td>
              <td><?= $farm['name']; ?></td>
              <td><?= $farm['state_registration']; ?></td>
              <td><?= $farm['responsible']; ?></td>
              <td><?= $farm['phone']; ?></td>
              <td><?= $farm['city_name']; ?> - <?= $farm['state']; ?></td>
            </tr>
          <?php endforeach; ?>

        </tbody>
      </table>
    </div>

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

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

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