<?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>Editar Conta a Pagar</h3>
    <div class="users">
      <!-- Message -->

      <?php if(!empty($error)): ?>
        <div class="alert <?=$error['alertType'];?>" role="alert">
          <?= $error['msg']; ?>
        </div>
      <?php endif; ?>

      <!-- /Message -->
      <form method="POST" id="form_validator" action="<?=$base;?>/updatebillstopay" enctype="multipart/form-data">
        <input type="hidden" name="cloned" value="<?= $bills_item['copied']; ?>">
        <input type="hidden" name="copied" value="0">
        <input type="hidden" name="date_new_acount">
        <input type="hidden" name="id_bills_item" value="<?= $bills_item['id']; ?>">
        <div class="form-row">
          <div class="form-group col-md-1">
            <label for="inputStatus">Status</label>
            <input type="text" readonly class="form-control" name="status" value="<?= ($bills_item['status'] == 1)?'Ativo':'Inativo' ?>">
          </div>

          <div class="form-group col-md-3">
            <label for="providersList">Fornecedor</label>
            <select name="providers_list" id="providersList" class="form-control">
              <option value="0">Selecionar</option>
              <?php foreach($array['providers_list'] as $item): ?>
                <option value="<?= $item['id']; ?>" <?= ($bills_item['id_provider'] == $item['id'])?'selected':'' ?> ><?= $item['company_name']; ?></option>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="form-group col-md-4">
            <label for="input_provider_description">Descrição do Fornecedor</label>
            <input type="text" class="form-control" id="input_provider_description" data-status="true" name="provider_description" value="<?= $bills_item['provider_description']; ?>" readonly>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-2">
            <label for="billstopayType">Tipo de Conta a Pagar</label>
            <select name="billstopay_list" id="billstopayType" class="form-control">
              <option value="0">Selecionar</option>
              <?php foreach($array['billstopay_type'] as $item): ?>
                <option value="<?= $item['id']; ?>" <?= ($bills_item['billstopay_type'] == $item['id'])?'selected':'' ?> ><?= $item['name']; ?></option>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="form-group col-md-3 hide">
            <label for="billstopay_description">Descrição do Contas a Pagar</label>
            <input type="text" class="form-control" id="billstopay_description" data-status="true" name="billstopay_description" value="<?= $bills_item['billstopay_description']; ?>">
          </div>

          <div class="form-group col-md-2 hide" style="display: flex; align-items: center;">
            <input type="checkbox" style="margin-right: 10px;" name="billstopay_new" id="billstopay_new">
            <label for="billstopay_new">Salvar novo Tipo de Contas a Pagar?</label>
          </div>

          <div class="form-group col-md-1.5" style="display: flex; align-items: center;">
            <input type="checkbox" style="margin-right: 10px;" name="billstopay_repeat" id="bills_repeat" disabled>
            <label for="bills_repeat">Repetir Mensal?</label>
          </div>

          <div class="form-group col-md-1.5">
            <label></label>
            <select name="qtd_repeat" class="form-control" disabled>
              <option value="0">Qtas vezes?</option>
              <?php for($i=1;$i<25;$i++): ?>
                <option value="<?= $i; ?>"><?= $i; ?></option>
              <?php endfor; ?>
            </select>
          </div>
        </div>

        <div class="form-row">            
          <div class="form-group col-md-2">
            <label for="form_to_pay">Origem do Pagamento</label>
            <select name="form_to_pay" id="form_to_pay" class="form-control">
              <option value="0">Selecionar</option>
              <?php foreach($array['payment_form'] as $item): ?>
                <option value="<?= $item['id']; ?>" <?= ($bills_item['form_to_pay'] == $item['id'])?'selected':'' ?> ><?= $item['name']; ?></option>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="form-group col-md-3 hide">
            <label for="form_to_pay_description">Descrição da Forma de Pgto</label>
            <input type="text" class="form-control" id="form_to_pay_description" data-status="true" name="form_to_pay_description" value="<?= $bills_item['form_to_pay_description']; ?>">
          </div>

          <div class="form-group col-md-2 hide" style="display: flex; align-items: center;">
            <input type="checkbox" style="margin-right: 10px;" name="billstopay_new_type" id="billstopay_new_type">
            <label for="billstopay_new_type">Salvar nova Forma de Pgto?</label>
          </div>

          <div class="form-group col-md-3 hide">
            <label for="payment_data">Destino: Dados bancários/chave PIX/Dados do Boleto</label>
            <input type="text" class="form-control" id="payment_data" name="payment_data" value="<?= $bills_item['payment_data']; ?>">
          </div>
        </div>

        <div class="form-row">            
          <div class="form-group col-md-2">
            <label for="document_date">Data do Documento</label>
            <input type="text" class="form-control" id="document_date" name="document_date" placeholder="00/00/0000" value="<?= $bills_item['document_date']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="expirate_date">Data de Vencimento</label>
            <input type="text" class="form-control" id="expirate_date" data-status="true" name="expirate_date" placeholder="00/00/0000" value="<?= $bills_item['expirate_date']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="document_number">Número Documento</label>
            <input type="text" class="form-control" id="document_number" name="document_number" value="<?= $bills_item['document_number']; ?>">
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-2">
            <label for="payment_date">Data de Pagamento</label>
            <input type="text" class="form-control" id="payment_date" name="payment_date" placeholder="00/00/0000" <?= ($bills_item['payment_date'])?'data-status="true"':''; ?> value="<?= $bills_item['payment_date']; ?>">
            <p style="color: red;" class="payment_date"></p>
          </div>

          <div class="form-group col-md-2">
            <label for="main_value">Valor Principal</label>
            <input type="text" class="form-control" id="main_value" name="main_value" value="<?= $bills_item['main_value']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="advance_value">Valor Adiantamento</label>
            <input type="text" class="form-control" id="advance_value" name="advance_value" readonly placeholder="0,00" value="<?= $bills_item['advance_value']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="value_to_pay">Valor a Pagar</label>
            <input type="text" class="form-control" id="value_to_pay" name="value_to_pay" readonly value="<?= $bills_item['value_to_pay']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="paid_out_value">Valor Pago</label>
            <input type="text" class="form-control" id="paid_out_value" name="paid_out_value" placeholder="0,00" value="<?= $bills_item['paid_out_value']; ?>">
          </div>

          <div class="form-group col-md-2">
            <label for="residual_value">Valor Residual</label>
            <input type="text" class="form-control" id="residual_value" name="residual_value" readonly value="<?= $bills_item['residual_value']; ?>">
          </div>
        </div>

        <div class="form-row">          
          <div class="form-group col-md-4">
            <label for="note">Observação</label>
            <textarea class="form-control" id="note" name="note" rows="8"><?= $bills_item['note']; ?></textarea>
          </div>

          <div class="form-group col-md-2">
            <label for="receipt_file">Anexar Comprovante</label>
            <input type="file" class="form-control" id="receipt_file" name="receipt_file">
          </div>

          <div class="form-group col-md-4 <?= (!empty($bills_item['receipt_file']))?'attachment':'' ?>">
              
            <?php if(!empty($bills_item['receipt_file'])): ?>
            
            <label for="inputLocation">Arquivo anexado:</label>
            <a href="<?= $base; ?>/media/vouchers/<?= $bills_item['receipt_file']; ?>" target="_blank"><?= $bills_item['receipt_file']; ?></a>
            <a data-ref="<?= $bills_item['id']; ?>" class="btn btn-danger white" id="delete_attachment">Deletar Arquivo</a>
            
          <?php endif; ?>

          </div>

          <div class="form-group col-md-2">              
            <label for="situation">Situação da Conta</label>
            <select name="situation" id="situation" class="form-control">
              <option value="0">Selecionar</option>
              <?php foreach($array['billstopay_situation'] as $item): ?>
                  <option value="<?= $item['id']; ?>" <?= ($bills_item['id_situation'] == $item['id'])?'selected':'' ?> ><?= $item['name']; ?></option>
                <?php endforeach; ?>
            </select>
          </div>
        </div>

        <div class="button">
          <button type="submit" class="btn btn-success">Salvar</button>
          <a href="<?=$base;?>/billstopay" class="btn btn-info">Voltar</a>
        </div>        
      </form>

      <div class="message-add" id="show-msg"></div>

      <div class="modal-stock">
        <div class="modal-content">
          <hr>
          <h4 class="qtd_days"></h4>
          <hr class="qtd_days">
          <input type="text" class="form-control" id="confirm_payment_date" name="confirm_payment_date" placeholder="00/00/0000">
          <p style="color: red;" class="confirm_payment_date"></p>
          <hr class="qtd_days">
          <div class="modal-button">
            <a href="#" id="confirm_date" class="btn btn-success">Confirmar</a>
              <a href="#" id="cancel_date" class="btn btn-info">Sair</a>
          </div>
        </div>
      </div>

      <!-- Modal Gerar nova conta valor residual -->
        <div class="modal-confirme-cancel">
        <div class="modal-content">
          <h4>Deseja gerar uma nova conta com o valor residual?</h4>
                <hr>
                <hr>
          <div class="modal-button">
            <a href="#" id="confirm_generate" class="btn btn-success">Sim</a>
              <a href="#" id="cancel_generate" class="btn btn-info">Não</a>
          </div>
        </div>
      </div>

      <!-- Modal new expirate date -->
      <div class="modal-new-expirate">
        <div class="modal-content">
          <hr>
          <h4 class="qtd_days">Digite a Nova Data de Vencimento!</h4>
          <hr class="qtd_days">
          <input type="text" class="form-control" id="new_expirate_date" name="new_expirate_date" placeholder="00/00/0000">
          <p style="color: red;" class="new_expirate_date"></p>
          <hr class="qtd_days">
          <div class="modal-button">
            <a href="#" id="confirm_expirate" class="btn btn-success">Confirmar</a>
              <a href="#" id="cancel_expirate" class="btn btn-info">Sair</a>
          </div>
        </div>
      </div>

    </div>

    <script src="<?= $base ?>/assets/js/billstopay.js"></script>
    <script src="<?= $base ?>/assets/js/billstopay_function.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

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