<?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 Compra</h3>
    <div class="users">
      <!-- Message -->

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

      <!-- /Message -->
      <form method="POST" action="<?=$base;?>/savepurchase" id="form_validator">
        <div class="oculted">
          <span>
            <i>
              <div>
                <input type="hidden" name="can_proceed" value="">
                <input type="hidden" name="override_stock" value="2">
              </div>
            </i>
          </span>
        </div>
        <h4 class="bgb">Dados do Fornecedor</h4>
        <div class="form-row sm-red">

            <div class="form-group col-md-3" id="validate_note_number">
              <label for="inputNoteNumber">Número da Nota (*)</label>
              <input type="text" class="form-control" name="note_number" data-rules="required" id="inputNoteNumber" placeholder="01234567895">
            </div>

            <div class="form-group col-md-4" id="provider">
              <label for="inputProvider">Fornecedor (*)</label>
              <select name="provider" class="form-control" id="inputProvider">
                <option value="0">Selecionar</option>
                <?php foreach($providerList as $provider): ?>
                  <option value="<?= $provider['id'] ?>" ><?= $provider['company_name']; ?></option>
                <?php endforeach; ?>
              </select>
              <div class="errorpv"></div>
            </div>

            <div class="form-group col-md-2" id="validate_note_date">
              <label for="note_date">Data da Nota (*)</label>
              <input type="text" class="form-control" name="note_date" data-rules="required" id="note_date" placeholder="00/00/0000">
            </div>

        </div>

        <h4 class="bgb">Novo Item de Produto</h4>

        <div class="form-row sm-red">

          <div class="form-group col-md-2" id="validate_group">
            <label for="inputProduct">Produto (*)</label>
            <select name="product" class="form-control" id="inputProduct">
            </select>
            <div class="errorpd"></div>
          </div>

          <div class="form-group col-md-2" id="validate_group">
            <label for="inputGroup">Grupo (*)</label>
            <input class="form-control" type="hidden" name="group">
            <input class="form-control" type="text" name="groupName" readonly id="inputGroup">
          </div>            

          <div class="form-group col-md-2" id="validate_unity">
            <label for="inputUnity">Unidade (*)</label>
            <input class="form-control" type="hidden" name="unity">
            <input class="form-control" type="text" name="unityName" readonly id="inputUnity">
          </div>

          <div class="form-group col-md-2" id="presentation">
            <label for="inputPresentation">Apresentação (*)</label>
            <input class="form-control" type="hidden" name="presentation">
            <input class="form-control" type="text" name="presentationName" readonly id="inputPresentation">
          </div>

          <div class="form-group col-md-2" id="validate_quantity">
            <label for="inputQuantity">Quantidade (*)</label>
            <input type="text" class="form-control" name="quantity" data-rules="required" id="inputQuantity">
          </div>

          <div class="form-group col-md-2" id="validate_cost_price">
            <label for="cost_price">Preço de custo</label>
            <input type="text" class="form-control" name="product_price" data-rules="required" id="cost_price">
          </div>

          <div class="form-group col-md-2" >
            <label for="inputItemValue">Valor do item</label>
            <input type="text" class="form-control" readonly name="total" id="inputItemValue">
          </div>

        </div>

        <div class="form-row" id="add_product">
          <div class="button">
            <a href="#" id="addProduct" class="btn btn-success">Adicionar Produto</a>
          </div>
        </div>


        <h4 class="bgb">Produtos Da Nota</h4>
        <div class="form-row" id="insert_products"></div>
        
        <div class="form-row">
          <div class="view-total-purchase" >
            <label>Valor total dos itens</label>
            <input type="text" class="form-control" readonly name="total_amount" id="inputTotalAmount">
          </div>
        </div>


        <h4 class="bgb">Forma de Pagamento</h4> 

        <div class="form-row">
          <div class="form-group">
              <div class="form-check">
                <input class="form-check-input" type="checkbox" id="paymentIntegral">
                <label class="form-check-label" for="paymentIntegral">
                  Pagamento Integral
                </label>
              </div>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-2" id="rowInputIntegral">
            <label for="inputQuantityPayment">Pagar em Qts Vezes?</label>
            <input type="text" class="form-control" name="qtd_payment" id="inputQuantityPayment" placeholder="5">
          </div>
        </div>

        <div class="form-row">
          <div class="form-group">
              <div class="form-check">
                <input class="form-check-input" type="checkbox" id="paymentAdvance">
                <label class="form-check-label" for="paymentAdvance">
                  Adiantamento
                </label>
              </div>
          </div>
        </div>

        <div class="form-row" id="rowInputAdvance">

          <div class="form-group col-md-2" id="valueAdvance">
            <label for="inputPercentagem">Lançar a % de adiantamento</label>
            <input type="text" class="form-control" name="percent_advance" id="inputPercentAdvance" placeholder="5" maxlength="3">
          </div>

          <div class="form-group col-md-2" id="total_advance">
            <label for="inputPercentagem">Total adiantamento</label>
            <input type="text" class="form-control" name="total_advance" readonly id="inputTotalAdvance" placeholder="5">
          </div>

          <div class="form-group col-md-2">
            <label for="inputQuantityPayment">Pagar em Qts Vezes?</label>
            <input type="text" class="form-control" name="advance_qtd_payment" id="inputAdvanceQuantityPayment" placeholder="5">
          </div>
        </div>

        <div class="form-row">
          <div class=" button">
            <input type="submit" value="Próximo" class="btn btn-success">
            <a href="<?=$base;?>/purchases" class="btn btn-info">Voltar</a>
          </div>
        </div>

        <!-- Modais de opções adicionais (Manter estoque/opções de pagamento) -->
        <div class="modal-purchase">
          <div class="modal-content">
            <input type="hidden" id="type_payment" name="type_payment" value="Integral">
            <h4>Digite a data do primeiro pagamento</h4>
            <hr>
            <input type="text" name="firstPayment" id="firstPayment" class="form-control" placeholder="00/00/0000">
            <p class="payment-date"></p>
            <hr>
            <h4 class="qtd_days">Qtd. dias entre os pagamentos</h4>
            <hr class="qtd_days">
            <input type="text" name="daysPayment" id="daysPayment" class="form-control qtd_days">
            <p class="show-msg qtd_days"></p>
            <hr class="qtd_days">
            <h4>Forma de Pagamento</h4>
            <hr>
            <select class="form-control" id="p_form" name="pay_form">
              <?php foreach($payment_form as $p_item): ?>
                <option value="<?= $p_item['id']; ?>"><?= $p_item['name']; ?></option>
              <?php endforeach; ?>
            </select>
            <hr class="qtd_days">
            <p>Os próximos pagamentos seram agendados de acordo com o período escolhido!</p>
            <p>Os mesmos poderam ser editados posteriormente!</p>
            <div class="modal-button">
              <a href="#" id="finalize" class="btn btn-success">Finalizar compra</a>
              <a href="#" id="close-modal" class="btn btn-info">Voltar</a>
            </div>
          </div>
        </div>

        <div class="modal-stock">
          <div class="modal-content">
            <h4 id="msg-stock"></h4>
            <hr>
            <h4 class="qtd_days">Deseja considerar este estoque?</h4>
            <hr class="qtd_days">
            <hr class="qtd_days">
            <div class="modal-button">
              <a href="#" id="cancel_override" class="btn btn-info">Sim</a>
              <a href="#" id="confirm_override" class="btn btn-success">Não</a>
            </div>
          </div>
        </div>  
      </form>      

      <div class="message-add" id="show-msg-add"></div>
    </div>
    <script src="<?=$base;?>/assets/js/purchases.js"></script>
  </div>  		
</div>
<!-- /.content-system -->
<?=$render('footer');?>