<?php
require '../../conexion.php';
include '../../session.php';
?>


<div class="modal-header " >
    <button type="button" class="close"     
            data-dismiss="modal" arial-label="Close">x</button>
    <h4 class="modal-title"><strong><center>Registrar Nota de Credito de Ventas</center></strong></h4>
</div>
<form action="credito_control.php" method="post" accept-charset="utf-8" class="form-horizontal" >
    <div class="panel-body se">
        <input type="hidden" name="accion"  value="1">
        <input type="hidden" name="vtotal" value="0">
        <input type="hidden" name="vtotiva" value="0">
        <input type="hidden" name="vusu" value="<?php echo $_SESSION['usu_cod']; ?>">
        <input type="hidden" name="vsuc" value="<?php echo $_SESSION['cod_suc']; ?>">
        <input type="hidden" name="pagina" value="credito_index.php" id="vcod">
        <input type="hidden" name="vcod" value="0"/> 

        <div class="row">
            <div class="col-md-4"  >
                <?php
                $facturas = consultas::get_datos("select (((btrim(TO_CHAR(cod_suc, '000')) || '-') ||"
                                . " btrim(TO_CHAR(punto_expedicion, '000'))) || '-') "
                                . "|| btrim(TO_CHAR(numero_inicial+1, '0000000')) "
                                . "as factura,id_tim,fecha_fin from v_timbrados where id_tim=4;");
                ?>
                <label class="control-label">Nro Nota</label>
                <input type="text" required=""
                       placeholder="Digite factura"
                       class="form-control"
                       name="nronota" style="width : 150px"
                       value="<?php echo $facturas[0]['factura']; ?>"
                       readonly="">
            </div>

            <div class="col-md-4" style="left:15px ">          
                <label class="control-label">Nro Timbrado</label>
                <input type="text" required=""
                       class="form-control"
                       name="vtimbrado" style="width : 150px"
                       value="<?php echo $facturas[0]['id_tim']; ?>"
                       readonly="">
            </div>

            <div class="col-md-4" style="left:15px ">
                <?php
                $timbrado = consultas::get_datos("SELECT * from timbrados where id_tim=3");
                ?>
                <label class="control-label">Venc. Timbrado</label>
                <input type="date" required="" 
                       class="form-control"
                       value="<?php echo $facturas[0]['fecha_fin']; ?>"
                       readonly=""
                       style="width: 150px">
            </div>
        </div>

        <div class="row">

            <div class="col-md-4">
                <label class="control-label">Fecha</label>
                <input type="date" required="" 
                       placeholder="Especifique fecha"
                       class="form-control"
                       value="<?php echo date("Y-m-d") ?>"
                       name="vfecha" 
                       style="width: 145px"
                       max="<?php echo date('Y-m-d'); ?>" min="<?php echo date('Y-m-d'); ?>">
            </div>

            <div class="col-md-5" >
                <label class="control-label" style="margin-left: 50px">Motivo</label>
                <?php $ord = consultas::get_datos("SELECT * from motivo_nota where mot_nota=2"); ?>                                 
                <select name="vmotivo" class="select2" required="" style="width: 180px">
                    <?php
                    if (!empty($ord)) {
                        foreach ($ord as $or) {
                            ?>
                            <option value="<?php echo $or['mot_nota']; ?>">
                                <?php echo $or['mot_descri']; ?></option>
                            <?php
                        }
                    } else {
                        ?>
                        <option value="0">Debe insertar un registro</option>
                    <?php } ?>
                </select>
            </div>

        </div>

        <script> div_factura();</script>


        <div class="row">
            <div class="col-md-5">
                <?php $prv = consultas::get_datos("SELECT distinct id_cliente,cliente from v_cobros where estado='PAGADO'"); ?>                                 
                <label class="control-label">Clientes</label>
                <select name="idcliente" id="idcliente" class="select2" required="" style="width: 220px" onchange="div_factura()">
                    <?php
                    if (!empty($prv)) {
                        foreach ($prv as $prv) {
                            ?>
                            <option value="<?php echo $prv['id_cliente']; ?>">
                                <?php echo $prv['cliente']; ?></option>
                            <?php
                        }
                    } else {
                        ?>
                       
                    <?php } ?>

                </select>
            </div>

            <div class="form-group" id="div_factura" style="display:block">

            </div>
        </div>



        <div class="modal-footer">
            <button type="submit" class="btn btn-primary center-block">
                <i class="fa fa-floppy-o"></i> Registrar</button>
        </div>
    </div>
</form>


<script type="text/javascript">
    $(".select2").select2();
</script>