<?php
$key = 'EixMKU90GHKJGhDVN78A';
session_start();

require_once ("../../config/Cado.php");

require_once ("../notadebito/cNotadebito.php");
$oNotadebito = new cNotadebito();

require_once ("../empresa/cEmpresa.php");
$oEmpresa = new cEmpresa();

require_once ("../cliente/cCliente.php");
$oCliente = new cCliente();
require_once ("../usuario/cUsuario.php");
$oUsuario = new cUsuario();

require_once("../formatos/formato.php");

if($_POST['cli_id']>0){
	$dts=$oCliente->mostrarUno($_POST['cli_id']);
	$dt = mysql_fetch_array($dts);
	
		$cli_nom=$dt['tb_cliente_nom'];
		$cli_doc=$dt['tb_cliente_doc'];
		$cli_con=$dt['tb_cliente_con'];
		$cli_tel=$dt['tb_cliente_tel'];
		$cli_ema=$dt['tb_cliente_ema'];


	mysql_free_result($dts);
}


$dts = $oNotadebito->mostrarUno($_POST['notdeb_id']);
	while($dt = mysql_fetch_array($dts)){
		$notdeb_numdoc	=$dt['tb_notadebito_numdoc'];
		$empid=$dt['tb_empresa_id'];
}


$dts=$oEmpresa->mostrarUno($empid);
$dt = mysql_fetch_array($dts);
	$emp_ruc=$dt['tb_empresa_ruc'];
	$emp_nomcom=$dt['tb_empresa_nomcom'];
	$emp_razsoc=$dt['tb_empresa_razsoc'];
	$emp_dir=$dt['tb_empresa_dir'];
	$emp_dir2=$dt['tb_empresa_dir2'];
	$emp_tel=$dt['tb_empresa_tel'];
	$emp_ema=$dt['tb_empresa_ema'];
	$emp_fir=$dt['tb_empresa_fir'];		
mysql_free_result($dts);
	


if($_SESSION['usuario_id']>0)
{
	$dts=$oUsuario->mostrarUno($_SESSION['usuario_id']);
	$dt = mysql_fetch_array($dts);
		$usugru		=$dt['tb_usuariogrupo_id'];
		$usugru_nom	=$dt['tb_usuariogrupo_nom'];
		$usu_nom	=$dt['tb_usuario_nom'];
		$apepat		=$dt['tb_usuario_apepat'];
		$apemat		=$dt['tb_usuario_apemat'];
		$ema		=$dt['tb_usuario_ema'];
	
	mysql_free_result($dts);
	
	$usuario_reg="$usu_nom $apepat $apemat";
}

$empresa=$_SESSION['empresa_nombre'];

	$asu='COMPROBANTES ELECTRONICOS';
	$destinatario='Estimado(a) cliente:<br>'.$cli_nom.'<br>';
	$titulo='COMPROBANTES ELECTRONICOS';


	$mentip="<p>Sírvase a descargar sus documentos.</p>";
	//$mentip.='<a href="http://www.marketerospe.com/demo/app/files/notacredito/notacredito_impcpe_doc.php?notid='.md5($key.$_POST['notdeb_id']).'">Descargar PDF</a><br/>';
	/* $mentip.='<a href="/app/venta/descargar_xml.php?id_factura='.md5($key.$_POST['notdeb_id']).'">Descargar XML</a><br/>'; */
	
	$tabla.='';


	$emisor="<p>Atentamente, $usuario_reg</p>";

	$firma='
	<table align="left" border="0" cellpadding="1" cellspacing="1" style="width:25%">
		<tbody>
			<tr>
				<td style="width:2%">
				<img width="100%" alt="Logo" src="http://www.grupovyf.com/intranet/imagenes/logo1.png" /> </td>
			</tr>
		</tbody>
	</table>';

	$men=$destinatario.''.$mentip.''.$tabla.''.$emisor.''.$firma;

?>

<script src="../../admin/plugins/ckeditor/ckeditor-standar/jquery.min.js"></script>
<script src="../../admin/plugins/ckeditor/ckeditor-standar/ckeditor.js"></script>
<script src="../../admin/plugins/ckeditor/ckeditor-standar/adapters/jquery.js"></script>
<script> var $j = jQuery.noConflict(true); </script>
<script type="text/javascript">

$(function(){
		
	$("#save_form_enviar").click(function(){
		$('#for_ven_corr').submit();
	});	
		
	$('#for_ven_corr').bootstrapValidator({
	    
	      message: 'Valor no Valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: { 
	   	
	      	txt_cli_ema: {
	      		group: '.col-lg-10',
	      		validators: {
	      			notEmpty: {
	      				message: 'Ingrese un correo*'
	      			}
	      		}
	      	},
	      }
	  }).on('success.form.bv', function(e) {
	  	
	  	$.ajax({
	  		type: "POST",
	  		url: "../notacredito/notacredito_correoreg.php",
	  		async:false,
	  		dataType: "json",
	  		data: $("#for_ven_corr").serialize(),
	  		beforeSend: function(){
					
				},
				success: function(data)
				{
					if(data.ven_corr_est==1){
						$('.modal').modal('hide');
						$('.in').removeClass('modal-backdrop');		
						toastr["info"](data.ven_corr_msj);		
					}else{
						toastr["error"](data.ven_corr_msj);		
					}
					
							
				},
				complete: function(){
					notadebito_tabla();
				}
			});	
	  });
	  
		
		
		
		
		
});

</script>
<script>

CKEDITOR.config.toolbar = [
	{ name: 'basicstyles', items: [ 'Bold', 'Italic', '-', 'RemoveFormat' ] },
	{ name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'] },
	{ name: 'links', items: [ 'Link', 'Unlink' ] },
	{ name: 'insert', items: [ 'Image','Table', 'HorizontalRule' ] },
	{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
	{ name: 'document', items: ['Maximize','-', 'Source' ] }
];

CKEDITOR.config.height = 250; 
CKEDITOR.replace('txt_cor_men');

</script>


	    <div class="col-lg-12 col-sm-12 col-xs-12" style="background-color:#fff;">
		
		
			<h4>ENVIAR CORREO:</h4>
		
		
		<form id="for_ven_corr">
			<input type="hidden" id="action_correo" name="action_correo" value="<?php echo $_POST['action']?>">
			<input type="hidden" id="hdd_rep_emp_id" name="hdd_rep_emp_id" value="<?php echo $_SESSION['empresa_id']?>">
			<input type="hidden" id="hdd_cli_id" name="hdd_cli_id" value="<?php echo $_POST['cli_id']?>" />
			<input type="hidden" id="hdd_ven_id" name="hdd_ven_id" value="<?php echo $_POST['notdeb_id']?>" />
			<input type="hidden" id="hdd_cli_nom" name="hdd_cli_nom" value="<?php echo $cli_nom?>" />

			<input name="cli_numdoc" class="" type="hidden" id="hdd_numdoc" value="<?php echo $cli_doc?>" >
			<input name="emp_numdoc" class="" type="hidden" id="hdd_numdoc" value="<?php echo $emp_ruc?>" >
			<input name="hdd_numdoc" class="" type="hidden" id="hdd_numdoc" value="<?php echo $notdeb_numdoc?>" >
			
			<div class="col-lg-6 col-md-6 col-xs-12">
							
			<div class="col-lg-2 col-md-3 col-xs-2">
			<label for="txt_cli_ema">Correo:</label>
			</div>
			
			<div class="col-lg-10 col-md-9 col-xs-10">
			<input name="txt_cli_ema" class="form-control" type="text" id="txt_cli_ema" value="<?php echo $cli_ema?>">
			</div>
			
			</div>
			
			<div class="col-lg-6 col-md-6 col-xs-12">
					
			<div class="col-lg-2 col-md-3 col-xs-2">
			<label for="txt_cli_con">Nombre:</label>
			</div>
			
			<div class="col-lg-10 col-md-9 col-xs-10">
			<input name="txt_cli_con" class="form-control" type="text" id="txt_cli_con" value="<?php echo $cli_con?>" readonly="true" >
			</div>
					
			</div>
			
			<div class="col-lg-12 col-md-12 col-xs-12" style="height:5px;">
			</div>
			
			
			<div class="col-lg-12 col-md-12 col-xs-12">
			
			<div class="col-lg-1 col-md-3 col-xs-2">
			<label for="">Cliente:</label>
			</div>
			
			<div class="col-lg-4 col-md-4 col-xs-10">
			<input name="txt_cli_doc" class="form-control" type="text" id="txt_cli_doc" value="<?php echo $cli_doc?>" readonly="true" >
			</div>
			
			<div class="col-lg-7 col-md-5 col-xs-12">
			<input name="txt_cli_nom" class="form-control" type="text" id="txt_cli_nom" value="<?php echo $cli_nom?>"  readonly="true" >
			</div>			
					
			</div>
			
			<div class="col-lg-12 col-md-12 col-xs-12" style="height:5px;">
			</div>
			
			<div class="col-lg-12 col-md-12 col-xs-12">
			
				<div class="col-lg-1 col-md-3 col-xs-2">
				<label for="txt_cor_asu">Asusto:</label>
				</div>
			
				<div class="col-lg-11 col-md-9 col-xs-10">
				<input name="txt_cor_asu" class="form-control" type="text" id="txt_cor_asu" value="<?php echo $asu?>" readonly="true" >
				</div>
				
			</div>
			
			<div class="col-lg-12 col-md-12 col-xs-12">
					<label for="txt_cor_men">Mensaje:</label>	
					<textarea name="txt_cor_men" id="txt_cor_men"><?php echo $men?></textarea>		
			</div>
			
			</form>

		<div class="box-footer pull-right">
		<button class="btn btn-primary" id="save_form_enviar">ENVIAR</button>
		<button type="button" data-dismiss="modal"  title="Canelar correo" class="btn btn-danger glyphicon glyphicon-remove"></button>		
		</div>
			
		</div>
		  