<?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"><i class="fa fa-plus"></i> <strong>Registrar Presupuesto</strong></h4>
</div>
<form action="presupuesto_control.php" method="post" accept-charset="utf-8" class="form-horizontal" >
    <div class="modal-body">
        <input type="hidden" name="accion"  value="1">
        <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="presupuesto_index.php" id="vcod">
        <input type="hidden" name="vcod" value="0"/> 
        <div class="form-group">
            <label class="col-md-2 control-label">Fecha:</label>
            <div class="col-md-4 col-sm-4 col-lg-4">
                <input type="date" required="" class="form-control" value="<?php echo date("Y-m-d") ?>" name="vfecha"  max="<?php echo date('Y-m-d'); ?>">
            </div>
            <div class="col-md-5 col-sm-5 col-lg-5">
                <label class="control-label">Pedido ?: </label>
                <input type="checkbox" id="conped" name="conped" class="form-control toggle" value="1" data-toggle="toggle" data-on="<i class='fa fa-check'></i> SI" data-off="<i class='fa fa-close'></i> NO" data-width="80" data-offstyle="danger">
            </div>            
        </div> 
        <div class="form-group">
            <label class="col-md-2 control-label">Cliente:</label>
            <div class="col-md-9 col-sm-9 col-lg-9">
                <?php $clientes = consultas::get_datos("select * from v_clientes order by id_cliente"); ?>                                 
                <select name="vcliente" id="id_cliente" class="select2 form-control" required="" style="width: 100%">
                    <option value="">Seleccione un cliente</option>
                    <?php if(!empty($clientes)) {
                        foreach ($clientes as $cli) { ?>
                            <option value="<?php echo $cli['id_cliente']; ?>">
                                <?php echo "(".$cli['per_ci'].") ".$cli['cliente']; ?></option>
                            <?php
                        }
                    } else {
                        ?>
                        <option value="">Debe insertar un registro</option>
                    <?php } ?>
                </select>
            </div>
        </div>
        <div id="div_ped"></div>
        <div class="form-group">
            <label class="col-md-2 control-label">Validez:</label>
            <div class="col-md-4 col-sm-4 col-lg-4">
                <input type="number" required="" class="form-control" value="15" name="validez" id="validez1" min="5" max="30">
            </div>
        </div>        
    </div>
    <div class="modal-footer" id="div_ped_detalle"></div>    
    <div class="modal-footer">
        <button type="reset" data-dismiss="modal" class="btn btn-default pull-left">
            <i class="fa fa-close"></i> Cerrar</button>
        <button type="submit" class="btn btn-primary pull-right">
            <i class="fa fa-floppy-o"></i> Registrar</button>
    </div>
</form>

<script type="text/javascript">
    $("#conped").prop("checked", false).trigger('change');
    $(".select2").select2();
    $('.toggle').bootstrapToggle();
</script>
<script>
    $('#conped').on('change', function() {
        if( $('#conped').prop('checked')) {                       
            $('#id_cliente').val("").trigger('change');
        }else{
          $('#div_ped').html("");  
        }
    });  
    $('#id_cliente').on('change',function(){
        if(this.value && $('#conped').prop('checked')){
            $.ajax({
                type: "POST", url: "div_ped.php", data: {id_cliente: this.value}
            }).done(function (datos) {
                $("#div_ped").html(datos);
            });            
            $("#div_ped").show();                      
        }else{
          $('#div_ped').html("");           
        }
    });    
</script>


