/////////////////////////////////////////////////////////////////////////////////////////////////
//actualizar
if(($s_invoice==="save")and ($_SESSION['invoice_id']!=''))
{
//$my ="DELETE FROM client_detalle_invoice where client_invoice_id = ".$_SESSION['invoice_id']."" ;
//mysql_query($my) or die("ERROR FATAL EN CONSULTA DE ELIMINACION AJAJJAJAJ".mysql_error().$my);
//insertar todos los registrod en la tabla detalle
for($q=1;$q<$numAP;$q++) {
$z ="id_unic".$q; $a = "id_i".$q; $b = "descript".$q; $c = "q".$q; $d = "cost".$q;
if($$a==""){$$a="0";}
if($$z==""){
$query="INSERT INTO client_detalle_invoice (id, fecha, client_invoice_id, items_id, slices_id, clients_id, descri, cantidad, costo, estatus) VALUES (NULL, '".date('Y-m-d')."', ".$_SESSION['invoice_id'].", ".$$a.", ".$_SESSION['slices_id'].", ".$_SESSION['clients_id'].", '".$$b."', ".$$c.", ".$$d.", 'E')";
mysql_query($query)or die("ERROR AL INSERT CON FOR".mysql_error().$query);
if($$a!="" and $$a!="0")
{
if(busca_produc($$a))
{
$qru="INSERT INTO item_pedidos (id, slices_id, items_id, invoice_id,fecha, modo, tipo, title, units, monto, doc_path, estatus) VALUES (NULL, ".$_SESSION['slices_id'].", ".$$a.", ".$_SESSION['invoice_id'].",'".date('Y-m-d')."', 'B', 'Sold', '".$$b."', ".$$c.", ".($$c * $$d).", NULL, 'E')";
mysql_query($qru)or die("ERROR FATAL INSERTAR REGISTROS DE ITEMS (1)!!!".mysql_error().$qru);
}
}
}else{
$query="UPDATE client_detalle_invoice SET fecha= '".date('Y-m-d')."', descri= '".$$b."', costo= ".$$d." ,cantidad =".$$c." WHERE id=".$$z."";
mysql_query($query)or die("ERROR AL INSERT CON FOR".mysql_error().$query);
if($$a!="" and $$a!="0")
{
if(busca_produc($$a))
{
$qru="update item_pedidos set title='".$$b."',units=".$$c." ,monto =".($$c * $$d)." where invoice_id=".$_SESSION['invoice_id']." and items_id=".$$a."";
mysql_query($qru)or die("ERROR FATAL INSERTAR REGISTROS DE ITEMS (2)!!!".mysql_error().$qru);
}
}
}
}
$id_pas1=true;
}
//para grabar un registro
if(($s_invoice==="save") and($_SESSION['invoice_id']=='')) {
//inserta un registro vacio
$micro = md5(microtime()."otracosa");
$query="INSERT INTO client_invoice (id, clients_id, slices_id, nro, fecha, name, direccion, sdate, kdate, descri, subtotal, descuento, newtotal, tax, taxmount,total, estatus) VALUES (NULL,".$_SESSION['clients_id']." , ".$_SESSION['slices_id'].", 0, '-', '".$micro."', '-', '-', '-', '-', 0, 0, 0, 0, 0, 0, 'D')";
$result= mysql_query($query)or die("ERROR EN EL 1er INSERT 1ero".mysql_error().$query);
//seleccion el id del registro anterior
$qu0="SELECT id from client_invoice where name = '".$micro."'";
$r0=mysql_query($qu0)or die("ERROR AL SELECCIONAR ID 2do".mysql_error());
if($row=mysql_fetch_array($r0))
{
$idi__new=$row['id'];
}
//inserta relacion de tablas
if($relation==="crea")
{
$_Q="INSERT INTO client_prop_inv (id, client_proposal_id, client_invoice_id, numero, slices_id, clients_id) VALUES (NULL, ".$id_1_pro.", ".$idi__new.", '".$id_2_num."', ".$_SESSION['slices_id'].", ".$_SESSION['clients_id'].")";
mysql_query($_Q)or die("ERROR EN GRABAR RELATION !!!!!!".mysql_error().$_Q);
}
//insertar todos los registrod en la tabla detalle
for($q=1;$q<$numAP;$q++)
{
$a = "id_i".$q; $b = "descript".$q; $c = "q".$q; $d = "cost".$q;
if($$a==""){$$a="0";}
$query="INSERT INTO client_detalle_invoice (id, fecha, client_invoice_id, items_id, slices_id, clients_id, descri, cantidad, costo, estatus) VALUES (NULL, '".date('Y-m-d')."', ".$idi__new.", ".$$a.", ".$_SESSION['slices_id'].", ".$_SESSION['clients_id'].", '".$$b."', ".$$c.", ".$$d.", 'E')";
mysql_query($query)or die("ERROR AL INSERT CON FOR".mysql_error().$query);
//////////GRABAR ITEMS////////
if($$a!="" and $$a!="0")
{
if(busca_produc($$a))
{
$qru="INSERT INTO item_pedidos (id, slices_id, items_id, invoice_id,fecha, modo, tipo, title, units, monto, doc_path, estatus) VALUES (NULL, ".$_SESSION['slices_id'].", ".$$a.", ".$idi__new.",'".date('Y-m-d')."', 'B', 'Sold', '".$$b."', ".$$c.", ".($$c * $$d).", NULL, 'E')";
mysql_query($qru)or die("ERROR FATAL INSERTAR REGISTROS DE ITEMS (3)!!!".mysql_error().$qru);
}
}
//////////////////////////////////////////
}
$id_pas=true;
}
?>
<html>
<head>
<title>Untitled</title>
<link rel="STYLESHEET" type="text/css" href="styles.css">
<script src="formatnumber.js" type="text/javascript"></script>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var g = <?php echo $numg;?>
//hallar subtotal de iframe
function elimina_item(id_i)
{
if(confirm('<?php echo MSG_6_90;?>'))
{
document.getElementById("nadd").value = "<?php echo $nadd;?>";
document.getElementById("s_invoice").value = "add";
document.getElementById("elimina_i").value = id_i;
mayopi_carga("fl_i","self");
}
}
function subtotal()
{
var dis;
var validnumber = /(^\d\d*\.\d*$)|(^\d\d*$)|(^\.\d\d*$)/;
var x1=0;
n= <?echo $numg;?>;
for(i=1;i<n;i++)
{
if((validnumber.test(document.getElementById('q'+i +'').value)) && (validnumber.test(document.getElementById('cost'+i +'').value)))
{
mas = parseFloat(document.getElementById('q'+i+'').value ) * parseFloat(document.getElementById('cost'+i+'').va lue);
document.getElementById('s_total'+i+'').value = formatNumber(mas,"0.00");
x1+= ( parseFloat(document.getElementById('s_total'+i+'') .value));
parent.document.getElementById('sub_total').value = formatNumber(x1,"0.00");
dis = parent.document.getElementById('dis').value;
st_d = (parseFloat(parent.document.getElementById('sub_to tal').value) * dis)/100;
parent.document.getElementById('nt').value = formatNumber(parseFloat(parent.document.getElement ById('sub_total').value) - st_d,"0.00");
tax = parent.document.getElementById('tax1').value;
taxp = parseFloat(parent.document.getElementById('nt').va lue * tax) /100;
parent.document.getElementById('tax2').value = formatNumber(taxp,"0.00");
tot = parseFloat(parent.document.getElementById('nt').va lue) + taxp;
parent.document.getElementById('tot').value = formatNumber(tot,"0.00");
}
}
}
////////////////////
//i = id ,
// pos name de donde empieso a poner
function borra_html(i,pos)
{
document.getElementById("id_i"+i).name="";
document.getElementById("descript"+i).name="";
document.getElementById("q"+i).name="";
document.getElementById("cost"+i).name="";
document.getElementById("s_total"+i).name="";
document.getElementById("id_unic"+i).name="";
var ge;
var w=0;
ge =<?echo $numg;?>;
a=pos;
for(z=i;z<ge;z++)
{
w = z +1;
if(w<ge){
document.getElementById("id_i"+w).name="x"+a+"[5]";
document.getElementById("descript"+w).name="x"+a+"[4]";
document.getElementById("q"+w).name="x"+a+"[1]";
document.getElementById("cost"+w).name="x"+a+"[2]";
document.getElementById("s_total"+w).name="x"+a+"[3]";
document.getElementById("id_unic"+w).name="";
a++;
}
}
document.getElementById("nadd").value = "<?php echo $nadd-1;?>";
document.getElementById("s_invoice").value = "add";
mayopi_carga("fl_i","self");
}
////////////////////
function save_id()
{
var a="";
var send = true;
var objRegExp = /^\w+([\s\-]?\w*)*$/i;
var numAp = 0;
/////////////////////// VALIDA INVOICE AND ITEMS ////////////////////////////////
if(parent.document.getElementById("invoice_name"). value=="") {
alert("<?php echo MSG_6_91;?>");
parent.document.getElementById("invoice_name").foc us();
return;
} else if(parent.document.getElementById("invoice_addr1") .value=="") {
alert("<?php echo MSG_6_92;?>");
parent.document.getElementById("invoice_addr1").fo cus();
return;
} else if(parent.document.getElementById("invoice_addr2") .value=="") {
alert("<?php echo MSG_6_92;?>");
parent.document.getElementById("invoice_addr2").fo cus();
return;
} else if(parent.document.getElementById("startdate").val ue=="") {
alert("<?php echo MSG_6_93;?>");
return;
} else if(parent.document.getElementById("enddate").value =="") {
alert("<?php echo MSG_6_94;?>");
return;
} else if(parent.document.getElementById("tot").value==0. 00){
alert("<?php echo MSG_6_95;?>");
return;
} |