<?php
// ini_set('display_errors',1);
	session_start();
	require_once ("../../config/Cado.php");
	require_once ("../formatos/formato.php");
	require_once ("../cotizacion/cCotizacion.php");
	$oCotizacion = new cCotizacion();
	
	$dts = $oCotizacion->filtrar(fecha_mysql($_POST['txt_fil_cot_fec1']),fecha_mysql($_POST['txt_fil_cot_fec2']), 
	$_POST['hdd_fil_cli_id'],$_POST['txt_fil_docnum'],$_POST['cmb_fil_mon_id'],$_POST['cmb_fil_ven_est'],
	$_POST['cmb_fil_puntoventa_id']);
	$num_rows = mysqli_num_rows($dts);
?>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:5px;">
	
						<div class="table-responsive">	
					
					
					<table id="tabla_cotizacion" class="table table-bordered table-striped ">
							<thead>
								<tr>
									<th nowrap >OPC.</th>
									<th>FECHA</th>
									<th>PUNTO VENTA | EMPRESA</th>
									<th>DOCUMENTO</th>
									<th>ESTADO</th>
									<th align="right" >DOCS RELACIONADOS</th>
									<th>CLIENTE</th>
									<th>RUC/DNI</th>
									<th align="right" >TOTAL</th>
									
									
								</tr>
							</thead>
							<tbody>
								<?php while($dt = mysqli_fetch_assoc($dts)) { 
									$total +=$dt['tb_cotizacion_tot'];
									$emp = '';
								
									if($dt['empid']==0){
										$emp = '<span class="badge badge-warning">MIXTA</span>'; 
									}else{
										$emp = '<strong>'.$dt['tb_empresa_nomcom'].'</strong>';
									}
									
									?>
									<tr >
									<td nowrap >
									
		<?php if($dt['tb_cotizacion_est']==3){?>
		
				<span class="btn btn-sm btn-primary " style="cursor:pointer" onClick="cotizacion_form_vista('editar','<?php echo $dt['tb_cotizacion_id']?>')" ><i class="fas fa-edit"></i></span>
	
		<?php }else if($dt['tb_cotizacion_est']==2){
			?>
			
				<span class="btn btn-sm btn-primary " style="cursor:pointer" onClick="cotizacion_form_vista('editar','<?php echo $dt['tb_cotizacion_id']?>')" ><i class="fas fa-edit"></i></span>
		
		<?php	
		}else if($dt['tb_cotizacion_est']==1){
		?>
				<span class="btn btn-sm btn-primary" style="cursor:pointer" onClick="cotizacion_form_vista('editar','<?php echo $dt['tb_cotizacion_id']?>')" ><i class="fas fa-edit"></i></span>
		<?php 	
		}?>
		
		<a  class="btn btn-sm btn-info" style="cursor:pointer" href="../../files/cotizacion/cotizacion_imp_doc.php?cotid=<?php echo $dt['tb_cotizacion_id'] ?>" 
		target="_blank"><i class="fas fa-file-pdf"></i></a>
		
		<?php if($dt['tb_cotizacion_genven']== 0 ){
			if($dt['tb_cotizacion_est']!=3){
		?>
		<span class="btn btn-sm btn-success" style="cursor:pointer" title="GENERAR VENTA" onClick="generar_venta('<?php echo $dt['tb_cotizacion_id']?>','<?php echo $dt['empid'] ?>');" ><i class="fa fa-store"></i></span>
		
		<?php 		
		}} ?>
		
		<?php if($dt['tb_cotizacion_est']!=3){?>
		
		<span  class="btn btn-sm btn-secondary" style="cursor:pointer"  onclick="enviarCorreo('<?php echo $dt['tb_cotizacion_id']; ?>','<?php echo $dt['tb_cliente_id']; ?>');"><i class="fas fa-envelope-square "></i></span>
		<span class="btn btn-sm btn-warning" style="cursor:pointer" onclick="cotizacion_ticket_datos('<?php echo $dt['tb_cotizacion_id']?>')"><i class="fa fa-print"></i></span>
	  
		<?php }?>
		
		<?php if($dt['tb_cotizacion_est']==1){?>
		<span class="btn btn-sm btn-danger" style="cursor:pointer" title="ANULAR" onClick="actualizarestado('<?php echo $dt['tb_cotizacion_id']; ?>','est','3','<?php echo $dt['tb_cotizacion_numdoc']; ?>');" ><i class="fas fa-trash"></i></span>
		<?php } ?>
		
		<?php if($dt['tb_cotizacion_est']==1 && $dt['tb_cotizacion_edi']==1){?>
		<span class="btn btn-sm btn-warning" style="cursor:pointer" title="ACTUALIZAR" onClick="actualizarestado('<?php echo $dt['tb_cotizacion_id']; ?>','edi','0','<?php echo $dt['tb_cotizacion_numdoc']; ?>');" ><i class="fas fa-sync-alt"></i></span>	
		<?php } ?>
						
		</td>
										<td nowrap ><?php echo mostrarFecha($dt['tb_cotizacion_fec']) ?></td>
										<td nowrap ><?php echo $dt['tb_puntoventa_cod'].' | '.$emp ?></td>
										<td><?php echo $dt['tb_documento_abr'].' '.$dt['tb_cotizacion_numdoc']?></td>
										<td><?php 
										if($dt['tb_cotizacion_est']==1){
											echo '<small class="badge " style="cursor:pointer;background-color:#00897b;color:#fff;" >COTIZADA</small>';
										}else if($dt['tb_cotizacion_est']==2){
											
											if($dt['tb_cotizacion_genven']==0){
											echo '<small class="badge badge-success" style="cursor:pointer;" >ACEPTADA / NO GENERADO</small>';
										}else if($dt['tb_cotizacion_genven']==1){
											echo '<small class="badge badge-success" style="cursor:pointer;" >ACEPTADA / GENERADO</small>';
										}
										}else if($dt['tb_cotizacion_est']==3){
											echo '<small class="badge badge-danger" style="cursor:pointer;" >RECHAZADA</small>';
										}
										
										
										?></td>
										<td nowrap >								
										<?php 
										$dtsr = $oCotizacion->mostartDocrelacionado($dt['tb_cotizacion_id']);
										$numros = mysqli_num_rows($dtsr);
										if($numros>0){
											?>
										
										<label style="cursor:pointer" onclick="enviar_documentos('<?php echo $dt['tb_cotizacion_id']; ?>','<?php echo $dt['tb_cliente_id']; ?>')" 
										class="btn btn-sm btn-warning "><i class="fas fa-envelope-square "></i></label>
										
											
											<?php 
											
											
											while($dtr = mysqli_fetch_array($dtsr)){
											
											if($dtr['tb_cotizacion_docrelacionado_tip']==1){
											?>
											<a  class=" badge badge-primary" style="text-align:left" 
											href="../../files/venta/venta_impcpe_doc.php?venid=<?php echo $dtr['tb_venta_id'] ?>" target="_blank">
											<strong><?php echo $dtr['tb_venta_numdoc']; ?></strong></a>
											<?php 												
											}else{
												?>
												<a  class="badge badge-primary" style="text-align:left" 
											href="../../files/guiaremision/guiaremision_impcpe_doc.php?guiaid=<?php echo $dtr['tb_venta_id'] ?>" target="_blank">
											<strong><?php echo $dtr['tb_venta_numdoc']; ?></strong></a>
												<?php 
											}
											
											}
										}else{
											
											
											
										}
										?>
										</td>
										
										<td nowrap ><?php echo $dt['tb_cliente_nom'] ?></td>
										<td><?php echo $dt['tb_cliente_doc'] ?></td>
										<td align="right" ><?php echo formato_money($dt['tb_cotizacion_tot'])?></td>
										
										
									</tr>
								<?php } ?>
							</tbody>
							
		<tr >
			<td colspan="">TOTAL</td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td align="right"><strong><?php echo formato_money($total)?></strong></td>
			
		</tr>
							
							
						</table>
					
				
					</div>
					
					</div>
				</div>
			</div>
		</div>
		</div>
</section>
<script>
$(function() {  
		 $('#tabla_cotizacion').DataTable({
 
        "language": {
                "lengthMenu": "Mostrar _MENU_ registros",
                "zeroRecords": "No se encontraron resultados",
                "info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
                "infoFiltered": "(filtrado de un total de _MAX_ registros)",
                "sSearch": "Buscar:",
                "oPaginate": {
                    "sFirst": "Primero",
                    "sLast":"Último",
                    "sNext":"Siguiente",
                    "sPrevious": "Anterior"
			     },
			     "sProcessing":"Procesando...",
            }
    });  
	
		$('.table-responsive').doubleScroll();
	
  }); 
</script>