<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("../venta/cVenta.php");
$oVenta = new cVenta();
require_once("../formatos/formato.php");
if($_POST['action']=="editar")
{
	$dts = $oVenta->mostrarUno($_POST['ven_id']);
	$dt = mysqli_fetch_array($dts);
	$reg = mostrarFechaHora($dt['tb_venta_reg']);
	$fec = mostrarFecha($dt['tb_venta_fec']);
	$doc_id	= $dt['tb_documento_id'];
	$numdoc	= $dt['tb_venta_numdoc'];
	$cli_id	= $dt['tb_cliente_id'];
	$cli_nom = $dt['tb_cliente_nom'];
	$cli_doc = $dt['tb_cliente_doc'];
	$cli_dir = $dt['tb_cliente_dir'];
	$cli_tip = $dt['tb_cliente_tip'];
	$cli_pla = $dt['tb_cliente_pla'];
	$mon_id = $dt['tb_moneda_id'];
	$tipcam = $dt['tb_venta_tipcam'];
	$valven	= $dt['tb_venta_valven'];
	$igv	= $dt['tb_venta_igv'];
	$tot	= $dt['tb_venta_tot'];
	$ven_igvval	= $dt['tb_venta_igvval'];
	$est	= $dt['tb_venta_est'];
	$emp_nom	= $dt['tb_empresa_nomcom'];
	$piso_nom	= $dt['tb_piso_nom'];
	$almacen_nom	= $dt['tb_almacen_nom'];
	$ven_id	= $dt['tb_vendedor_id'];
	$lab1	= $dt['tb_venta_lab1'];
	$may	= $dt['tb_venta_may'];
	mysqli_free_result($dts);
}
?>
<script type="text/javascript">
	/* function cmb_ven_id(idf){
		$.ajax({
			type: "POST",
			url: "../vendedor/cmb_ven_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				ven_id: idf	
			}),
			beforeSend: function() {
				$('#cmb_ven_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_ven_id').html(html);
			},
			complete: function(){			
			}
		});
	} */
	
	
function cmb_mone_id(moneid)
	{	
		$.ajax({
			type: "POST",
			url: "../moneda/cmb_mon_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mon_id: moneid
			}),
			beforeSend: function(){
				$('#cmb_mone_id_vis').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_mone_id_vis').html(html);
				
			}
		});
	}
	
	function cmb_doc_id(idf){
		$.ajax({
			type: "POST",
			url: "../documento/cmb_doc_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mod_id: '3',
				def : '0',
				doc_id: idf,
				vista:	''
			}),
			beforeSend: function() {
				$('#cmb_doc_id_vis').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_doc_id_vis').html(html);
			},
			complete: function(){
			}
		});
	}
	function venta_pago_tabla_ver(){
		$.ajax({
			type: "POST",
			url: "../venta/venta_pago_tabla_vista.php",
			async:true,
			dataType: "html",                      
			data: ({
				ven_id:	'<?php echo $_POST["ven_id"]?>'
			}),
			beforeSend: function() {
				$('#div_venta_pago_tabla_vis').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_venta_pago_tabla_vis').html(html);
			},
			complete: function(){			
				$('#div_venta_pago_tabla_vis').removeClass("ui-state-disabled");
			}
		});     
	}
	
	
	
	function actualizar_precio(act,vendet_id,pre){
		$.ajax({
			type: "POST",
			url: "../venta/venta_reg.php",
			async:true,
			dataType: "json",                      
			data: ({
				action_venta:act,
				vendet_id:vendet_id,
				pre:pre
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				toastr["success"](data.msj);
			},
			complete: function(){			
				venta_detalle_tabla_vis(<?php echo $_POST['ven_id']; ?>);
			}
		});     
	}
	

	
	function venta_detalle_tabla_vis(ven_id){
		$.ajax({
			type: "POST",
			url: "../venta/venta_detalle_tabla_vista.php",
			async:true,
			dataType: "html",                      
			data: ({
				ven_id:	ven_id
			}),
			beforeSend: function() {
				$('#div_venta_detalle_tabla_vis').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_venta_detalle_tabla_vis').html(html);
			},
			complete: function(){			
				$('#div_venta_detalle_tabla_vis').removeClass("ui-state-disabled");
			}
		});     
		
		
		
		
	function venta_anulada_sunat(ven_id){
		$.ajax({
			type: "POST",
			url: "../venta/venta_reg.php",
			async:true,
			dataType: "html",                      
			data: ({
				action_venta:	'cambiarestadosunat',
				ven_id: ven_id
			}),
			beforeSend: function() {
				
			},
			success: function(html){
				
			},
			complete: function(){	
				$('#div_venta_form_dialog_vista').modal('hide');			
				venta_tabla();
			}
		});     
	}
	
	}
	$(function() {
			cmb_mone_id(<?php echo $mon_id?>);
			cmb_doc_id(<?php echo $doc_id?>);
			$("#txt_ven_numdoc_vis").addClass("ui-state-active");
			/* cmb_ven_id(<?php echo $ven_id?>); */
			venta_pago_tabla_ver();
			venta_detalle_tabla_vis(<?php echo $_POST["ven_id"]?>);
			$('#cmb_ven_est, #cmb_doc_id_vis, #cmb_ven_id,#cmb_mone_id_vis').attr('disabled','disabled');
			
			
						
	$('#btn_actestsunat').click(function() {
		venta_anulada_sunat(<?php echo $_POST['ven_id'] ?>);
	});	
	
		$('#btn_anular_mon').click(function(){
		$('#div_venta_form_dialog_vista').modal('hide');		
		venta_anular(<?php echo $_POST['ven_id'] ?>,'<?php echo $numdoc; ?>');
	});
			
			
		});
	</script>
	
	<div class="modal-header">		
		<h4 class="modal-title" id="titlemodal">Información de La Venta</h4> 
		<h4 class="modal-title text-orange" id="titlemodal">IGV VENTA : <?php echo $ven_igvval.' %'; ?></h4> 
	</div>
	
	
	
	<div class="row">
	
	<div class="col-lg-5 col-sm-12 col-12"> 
		<div class="box box-widget">
			<div class="box-header with-border">
				<div class="user-block"> 
					<img class="img-circle" src="../../imagenes/users/user1.jpg" alt="User Image" title="">
					<span class="username"><a style="color:#1A237E;"  title="DNI - RUC : <?php echo $cli_doc?>" href="javascript:void(0)"><?php echo "CLIENTE: ".$cli_nom;?></a></span>
					<span class="description" style="color:#B71C1C;"  > <?php echo ' DIR: '.$cli_dir?></span>
					<span class="description"> <?php echo ' PLACA: '.$cli_pla?></span>
				</div>
				
			</div>
			
			<div   class="box-body" style="display: block;">
				<div id="div_venta_pago_tabla_vis"></div>
			</div> 
		</div>
	</div>
	
			<div class="col-lg-7 col-sm-12 col-12"> 
			<div class="row"> 
			
			<div class="col-lg-4 col-sm-6 col-6"> 
				<label for="txt_ven_fec">Fecha:</label>
				<input title="FECHA DE REGISTRO : <?php echo "$reg";  ?>"  
				name="txt_ven_fec" type="text" class=" form-control input-sm fecha" id="txt_ven_fec" value="<?php echo $fec?>" size="10" maxlength="10" readonly>
			</div>
			<div class="col-lg-4 col-sm-6 col-6"> 
				<label for="cmb_doc_id_vis">Documento:</label>
				<select   name="cmb_doc_id_vis" id="cmb_doc_id_vis" class=" form-control input-sm" ></select>
			</div>
			<div class="col-lg-4 col-sm-6 col-6"> 
				<label for="txt_ven_numdoc_vis">N° Doc:</label>
				<input style="color: #880E4F;font-weight: bold" name="txt_ven_numdoc_vis" type="text" id="txt_ven_numdoc_vis"   value="<?php echo $numdoc?>"  readonly class=" form-control input-sm">
			</div>
			<!--
			<div class="col-lg-4 col-sm-6 col-12"> 
				<label for="cmb_ven_id">Vendedor: </label>
				<select style=" " name="cmb_ven_id" id="cmb_ven_id" class=" form-control input-sm"></select>
			</div>
			-->
			<div class="col-lg-4 col-sm-6 col-6" style="display:none"> 
				<label for="cmb_ven_est">Estado:</label>
				<select style=" " name="cmb_ven_est" id="cmb_ven_est" class=" form-control input-sm">
					<option value="">-</option>
					<option value="1" <?php if($est=='1')echo 'selected'?>>REGISTRADA</option>
					<option value="2" <?php if($est=='2')echo 'selected'?>>ANULADA</option>
				</select>
			</div>
			<div class="col-lg-4 col-sm-6 col-6">
				<label for="cmb_mone_id_vis">Moneda:</label><label class="pull-right"><?php echo ' '.$tipcam; ?></label>
				<select   name="cmb_mone_id_vis" id="cmb_mone_id_vis" class="form-control input-sm"></select>
			</div>
												
			<div class="col-lg-4 col-sm-6 col-6"> 
				<label for="">Empresa:</label>
				<input style=" "   type="text"   value="<?php echo $emp_nom?>"  readonly class=" form-control input-sm">
			</div>
			
			<div class="col-lg-4 col-sm-6 col-6" style="display:none"> 
				<label for="">Piso:</label>
				<input style=" "   type="text"   value="<?php echo $piso_nom?>"  readonly class=" form-control input-sm">
			</div>
			
			<div class="col-lg-4 col-sm-6 col-6 d-none"> 
				<label for="">Almacen:</label>
				<input style=" "   type="text"   value="<?php echo $almacen_nom?>"  readonly class=" form-control input-sm">
			</div>
			
			<div class="col-lg-4 col-sm-6 col-6"> 
				<label for="">IGV:</label>
				<input style=""   type="text"   value="<?php echo $ven_igvval.' %'?>"  readonly class=" form-control input-sm">
			</div>
		
	
		<input name="action_venta_vis" id="action_venta_vis" type="hidden" value="<?php echo $_POST['action']?>">
  
	</div>
	
			</div>
			
			
			
			
		
			<div class="col-lg-12 col-sm-12 col-12"> 
			</br>
				<div id="div_venta_detalle_tabla_vis"></div>
			</div>	
			
			
			<div class="col-lg-12 col-sm-12 col-md-12 col-12" style="height:15px;"> </div>
			
			
			<?php if ($_SESSION['usuariogrupo_id']=='1'){?>
			<div class="col-lg-12 col-sm-12 col-12"> 
				<span class="btn btn-outline-danger btn-sm" id="btn_actestsunat">ANULADA POR SUNAT</span>
				
				<span class="btn btn-outline-success btn-sm" id="btn_anular_mon">ANULAR PAGO/KARDEX</span>
				
				<span title="EMITIR DOCUMENTO :: ENVIAR A SUNAT :: IMPRIMIR" data-toggle="tooltip" 
				 data-placement="top"  class="btn btn-outline-info btn-sm" 
				 onClick="venta_ticket_datos('<?php echo $_POST['ven_id'] ?>');" >VOLVER A ENVIAR <i class="fas fa-angle-double-right"></i></span>	
			</div>
			<?php } ?>
			
	</div>
	
	<div class="box-footer float-right ">
		<button title="CERRAR VENTANA" type="button" data-dismiss="modal" class="btn btn-danger"><i class="fas fa-times"></i></button>
	</div>
				