Ver Mensaje Individual
  #20 (permalink)  
Antiguo 23/09/2005, 17:57
Avatar de davidangel
davidangel
 
Fecha de Ingreso: abril-2005
Mensajes: 124
Antigüedad: 19 años, 7 meses
Puntos: 0
//************************************************** *************************************//
$q_max = "select max(nro + 1) as idmax from client_invoice";
$r_max=mysql_query($q_max);
$ro_max=mysql_fetch_array($r_max);
$num_max = formato_num($ro_max['idmax']);
// crear un registro para capturar el ID

$micro = md5(microtime()."otracosa");
$query_1="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,".$row[1]." , ".$row[2].", '".$num_max."', '".$row[4]."', '".$micro."', '".$row[6]."', '".$row[7]."', '".$row[8]."', '".$row[9]."', ".$row[10].", ".$row[11].", ".$row[12].", ".$row[13].", ".$row[14].", ".$row[15].", '".$row[16]."')";
mysql_query($query_1)or die("INVOICE -- > ERROR EN EL 1er INSERT 1ero".mysql_error().$query_1);
//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_s=mysql_fetch_array($r0))
{
$id_invoice=$row_s['id'];
}
//************************************************** *************************************//
//$query_1="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,".$row[1]." , ".$row[2].", ".$row[3].", '".$row[4]."', '".$micro."', '".$row[6]."', '".$row[7]."', '".$row[8]."', '".$row[9]."', ".$row[10].", ".$row[11].", ".$row[12].", ".$row[13].", ".$row[14].", ".$row[15].", '".$row[16]."')";
$query_up="UPDATE client_invoice SET name= '".$row[5]."' WHERE id=".$id_invoice;
mysql_query($query_up);
//copia de registros del invoice
$query_2="SELECT * FROM client_detalle_invoice where client_invoice_id=".$_SESSION['invoice_id'];
$result_2=mysql_query($query_2);
while($row_2=mysql_fetch_array($result_2))
{
$query_2_1="INSERT INTO client_detalle_invoice (id, fecha, client_invoice_id, items_id, slices_id, clients_id, descri, cantidad, costo, estatus) VALUES (NULL, '".$row_2[1]."', ".$id_invoice.", ".$row_2[3].", ".$row_2[4].", ".$row_2[5].", '".$row_2[6]."', ".$row_2[7].", ".$row_2[8].", '".$row_2[9]."')";
mysql_query($query_2_1);
}
//************************************************** **************************************//
$query_3="SELECT * FROM item_pedidos WHERE invoice_id=".$_SESSION['invoice_id'];
$result_3=mysql_query($query_3);
while($row_3=mysql_fetch_array($result_3))
{
$query_3_1="INSERT INTO item_pedidos (id, slices_id, items_id, invoice_id,fecha, modo, tipo, title, units, monto, doc_path, estatus) VALUES (NULL, ".$row_3[1].", ".$row_3[2].", ".$id_invoice.",'".$row_3[4]."', '".$row_3[5]."', '".$row_3[6]."', '".$row_3[7]."', ".$row_3[8].", ".$row_3[9].", ".$row_3[10].", '".$row_3[12]."')";
mysql_query($query_3_1);
}
$_SESSION['invoice_id']=$id_invoice;
$_SESSION['mensaje']['txt'] = MSG_6_111;
$_SESSION['mensaje']['status'] = true;

}
$enableHeader = true;
}
// BORRA UN INVOICE (falta borrar los items y los pedidos) ademas si es q tiene relacion con un proposal borrar tal relacion
if($action_i=="delete")
{
//eliminacion de la relacion con un proposal
// QUERY DE BORRADO - relacion entr proposal e invoice
/*$qr="DELETE FROM client_prop_inv WHERE client_invoice_id=".$_SESSION['invoice_id'];
mysql_query($qr) or die("<strong>Delete client_proposal<pre>".mysql_error()."</pre></strong>");*/
// QUERY DE BORRADO - detalle del invoice
//$qr="DELETE from client_detalle_invoice where client_invoice_id=".$_SESSION['invoice_id'];
$qr="UPDATE client_detalle_invoice SET estatus='B' WHERE client_invoice_id=".$_SESSION['invoice_id'];
mysql_query($qr) or die("<strong>Delete client_proposal<pre>".mysql_error()."</pre></strong>");
// QUERY DE BORRADO - productos por detalle
//$qr="delete from item_pedidos where invoice_id=".$_SESSION['invoice_id'];
$qr="UPDATE item_pedidos SET estatus='B' WHERE invoice_id=".$_SESSION['invoice_id'];
mysql_query($qr) or die("<strong>Delete client_proposal<pre>".mysql_error()."</pre></strong>");
// QUERY DE BORRADO - invoice
//$qr="DELETE FROM client_invoice WHERE id=".$_SESSION['invoice_id'];
$qr="UPDATE client_invoice SET estatus='B' WHERE id=".$_SESSION['invoice_id'];
mysql_query($qr) or die("<strong>Delete client_proposal<pre>".mysql_error()."</pre></strong>");
$_SESSION['client_estado']=1;
unset($_SESSION['invoice_id']);
$enableHeader = true;
}
// 6.4
if(isset($propInvoice)and($propInvoice!="")) {
$_SESSION['prop_invoice'] = $propInvoice;
}
// se cambia el estado del clients - Page
if(isset($cambia_client_estado))
{
unset($_SESSION['invoice_id']);
unset($_SESSION['client_profile_id']);
if($cambia_client_estado<3) {
unset($_SESSION['prop_invoice']);
}
if(!isset($_SESSION['prop_invoice'])) {
unset($_SESSION['proposal_id']);
}
$_SESSION['client_estado']=$cambia_client_estado;
$enableHeader = true;
}
//--------------------------------------------------------------------
// 6.2
if(isset($cambia_client_profile_estatus))
{
// se ACTIVA/DESACTIVA AL VENDOR
$dat = explode(PARSER,$cambia_client_profile_estatus);
if($dat[0]=='E'){ $new_st='D'; }else{ $new_st='E';}
$qr="UPDATE client_profile SET estatus='$new_st' WHERE id=".$dat[1];
mysql_query($qr) or die("<strong>Cambio de ESTATUS del Client<pre>".mysql_error()."</pre></strong>");
$enableHeader = true;
}
//-----------------------------------------------------------------------
// 6.3
// recoger variable que seleciona a un proposal creado
if(isset($propid)and(!is_null($propid))) {
$_SESSION['proposal_id'] = $propid;
$enableHeader = true;
}
//-----------------------------------------------------------------------
// 6.4
// recoger variable que seleciona a un invoice creado
if(isset($facid)and($facid!='')) {
$_SESSION['invoice_id'] = $facid;
$enableHeader = true;
}
//--------------------------------------------para borrar file
if(isset($delete_legal_file))
{
$qr="select path from client_files where id=".$delete_legal_file;
$re=mysql_query($qr) or die("<strong>Delete legal file<pre>".mysql_error()."</pre></strong>");
$row=mysql_fetch_array($re,MYSQL_ASSOC);
if($row['path']!=''){
$file_l=UPLOADS_DIR.$row['path'];
if(file_exists($file_l))
{
if(unlink($file_l))
{
// QUERY DE BORRADO
$qr="delete from client_files where id=".$delete_legal_file;
$re=mysql_query($qr) or die("<strong>Delete legal file<pre>".mysql_error()."</pre></strong>");
}
}
}
$enableHeader = true;
}
//-----------------------------------------------------------------------
if($enableHeader) {
// redireccion
header("Location: ".HOME_DIR);
exit;
}
?>