<?php
$id_cobro = $_POST['id_cobro'];
require '../../conexion.php';
$conexion = conexion::con();
?>
<?php if($id_cobro == '0'){
    $clientes = pg_fetch_all(pg_query($conexion, "SELECT * FROM v_clientes WHERE cli_estado = 'ACTIVO';"));
    $documentos_respaldatorios = pg_fetch_all(pg_query($conexion, "SELECT * FROM v_documentos_respaldatorios WHERE estado = 'ACTIVO' AND es_cobro ORDER BY id_doc;"));
    ?>
<div class="col-md-12">
    <div class="form-group">
        <label>Tipo de Documento</label>
        <select class="form-control select2" id="vtipo">
            <?php foreach($documentos_respaldatorios as $d){ ?>
                <option value="<?= $d['id_doc'];?>"><?= $d['descripcion'];?></option>
            <?php } ?>
        </select>
    </div>
    <div class="form-group">
        <label>Cliente</label>
        <select class="form-control select2" id="vcliente" onchange="panel_cliente();">
            <option value="0">SIN NOMBRE</option>
            <?php foreach($clientes as $c){ ?>
                <option value="<?= $c['id_cliente'];?>"><?= $c['cliente']." (".$c['per_ci'].")";?></option>
            <?php } ?>
        </select>
    </div>
    <div id="panel-cliente">
        
    </div>
    <script type="text/javascript">
        panel_cliente();
    </script>
    <div class="btn-group">
        <button class="btn btn-danger" data-dismiss="modal"><i class="fa fa-ban"></i> Cerrar</button>
        <button class="btn btn-success" onclick="agregar_grabar();"><i class="fa fa-save"></i> Grabar</button>
    </div>
</div>
<?php }else{ ?>
<?php   if($id_cobro == '-1'){
            $cab = pg_fetch_all(pg_query($conexion,"SELECT * FROM v_cobros WHERE id_cobro = (select max(id_cobro) from cobros);")); 
        }else{
            $cab = pg_fetch_all(pg_query($conexion,"SELECT * FROM v_cobros WHERE id_cobro = $id_cobro;"));
        } ?>
<div class="col-md-3">
    <div class="form-group">
        <input type="hidden" id="cobcod" value="<?= $cab[0]['id_cobro'];?>">
        <input type="hidden" id="vcliente" value="<?= $cab[0]['id_cliente'];?>">
        <input type="hidden" id="vcta_id" value="0">
        <label>Tipo de Documento</label>
        <input type="text" value="<?= $cab[0]['documento'];?>" class="form-control" disabled="">
    </div>
    <div class="form-group">
        <label>N° Documento</label>
        <input type="text" value="<?= $cab[0]['nro_documento'];?>" class="form-control" disabled="">
    </div>
    <div class="form-group">
        <label>Cliente</label>
        <input type="text" value="<?= $cab[0]['cliente'];?>" class="form-control" disabled="">
    </div>
    <div class="form-group">
        <label>A Nombre De</label>
        <input type="text" value="<?= $cab[0]['a_nombre_de'];?>" class="form-control" disabled="">
    </div>
    <div class="form-group">
        <label>RUC De</label>
        <input type="text" value="<?= $cab[0]['ruc_de'];?>" class="form-control" disabled="">
    </div>
</div>
<?php } ?>