<?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>Adicionar Conta a Receber</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; ?>/savebillstoreceiver" enctype="multipart/form-data">
        <input type="hidden" name="copied" value="0">
        <input type="hidden" name="date_new_acount">
        <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="Ativo">
          </div>

          <div class="form-group col-md-3">
            <label for="providersList">Pagador</label>
            <input type="hidden" name="providers_list">
            <select name="type_search" id="providersList" class="form-control">
              <option value="">Selecionar</option>
              <option value="name">Nome</option>
              <option value="cpf">CPF</option>
              <option value="cnpj">CNPJ</option>       
            </select>
          </div>

          <div class="form-group col-md-4">
            <label for="input_provider_description">Descrição do Pagador</label>
            <input type="text" class="form-control" id="input_provider_description" name="provider_description">

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

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

            <div class="form-group col-md-3 hide">
              <label for="billstopay_description">Descrição da Origem</label>
              <input type="text" class="form-control" id="billstopay_description" name="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 nova Origem de Conta a Receber?</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="billstopay_repeat">
              <label for="billstopay_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<13;$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">Forma de Recebimento</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']; ?>"><?= $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 Recebimento</label>
              <input type="text" class="form-control" id="form_to_pay_description" name="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 Recebimento?</label>
            </div>

            <div class="form-group col-md-3 hide">
              <label for="payment_data">Chave PIX ou dados Bancários Informados ao Pagador</label>
              <input type="text" class="form-control" id="payment_data" name="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">
            </div>

            <div class="form-group col-md-2">
              <label for="id_request">Número Pedido</label>
              <input type="text" class="form-control" id="id_request" name="id_request">
            </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">
            </div>

            <div class="form-group col-md-2">
              <label for="expirate_date">Data a Receber</label>
              <input type="text" class="form-control" id="expirate_date" name="expirate_date" placeholder="00/00/0000">
            </div>

        </div>

        <div class="form-row">

            <div class="form-group col-md-2">
              <label for="payment_date">Data de Recebimento</label>
              <input type="text" class="form-control" id="payment_date" name="payment_date" placeholder="00/00/0000">
            </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">
            </div>

            <div class="form-group col-md-2">
              <label for="advance_value">Dedução de Entrada</label>
              <input type="text" class="form-control" id="advance_value" name="advance_value" readonly placeholder="0,00">
            </div>

            <div class="form-group col-md-2">
              <label for="value_to_pay">Valor a Receber</label>
              <input type="text" class="form-control" id="value_to_pay" name="value_to_pay" readonly placeholder="0,00">
            </div>

            <div class="form-group col-md-2">
              <label for="paid_out_value">Valor Recebido</label>
              <input type="text" class="form-control" id="paid_out_value" name="paid_out_value" placeholder="0,00">
            </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>
            </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"></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"></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']; ?>" ><?= $item['name']; ?></option>
              <?php endforeach; ?>
            </select>
          </div>
        </div>

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

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

      <div class="modal-stock" style="z-index: 9999;">
        <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 a Receber!</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/billstoreceiver.js"></script>
    <script src="<?=$base;?>/assets/js/billstoreceiver_function.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

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