<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
ejt("DELETE FROM parse1");
//
$s="UPDATE cotizaciones SET tot_real=round(tot_real,2),tot_cob=round(tot_cob,2) WHERE cot_pri=1";
ejt($s);
//
$s="SELECT * FROM cotizaciones 
	WHERE (tot_real - tot_cob)>0 AND (tot_real - tot_cob) <1  AND cot_pri='1' AND id_tip_pag='CO' 
	ORDER BY id_cotizacion";
$rs = grs($s);
while ($r = $rs->fetch_assoc()){
	$_ID=$r['id_cotizacion'];
	$_SE=$r['ser'];
	$_NU=$r['num'];
	$_TR=$r['tot_real'];
	$_TC=$r['tot_cob'];
	$_DI=$_TR - $_TC;
	$_PI=GenId("id_parse","parse1");
	$s="INSERT INTO parse1 VALUES ($_PI,'PROFORMA','$_SE','$_NU',$_TR,$_TC,$_DI)";
	ejt($s);
	$s="UPDATE cotizaciones SET tot_cob=tot_real WHERE id_cotizacion=$_ID";
	ejt($s);
}
echo "OK PROFORMAS <br>";
//
$s="UPDATE ventas SET tot=round(tot,2),ven_cob=round(ven_cob,2) WHERE ven_prin=1";
ejt($s);
//
$s="SELECT * FROM ventas 
	WHERE (tot - ven_cob)>0 AND (tot - ven_cob) <1  AND ven_prin=1 AND id_tip_pag='CO' 
	ORDER BY id_venta";
$rs = grs($s);
while ($r = $rs->fetch_assoc()){
	$_ID=$r['id_venta'];
	$_CO=$r['id_com'];
	$_CO=gs("com_nombre","comprobantes","id_comprobante=".$_CO);
	$_SE=$r['ser'];
	$_NU=$r['num'];
	$_TR=$r['tot'];
	$_TC=$r['ven_cob'];
	$_DI=$_TR - $_TC;
	$_PI=GenId("id_parse","parse1");
	$s="INSERT INTO parse1 VALUES ($_PI,'$_CO','$_SE','$_NU',$_TR,$_TC,$_DI)";
	ejt($s);
	$s="UPDATE ventas SET ven_cob=tot WHERE id_venta=$_ID";
	ejt($s);
}
echo "OK VENTAS <br>";

?>