<?php

require_once("../comun/conexion3.php");
require_once("../comun/conex_ver.php");

require_once("../comun/actions.php");

require_once("../comun/funciones.php");

$action = new actions();
con_impo();

$txtbooking= strtoupper($_POST['booking']); //booking interteam

//OBTENGO EL ID DEL BOOKING (ITVER)
$txtidbooking= qry_('booking_interteam = "'.$txtbooking.'"','bookingexpint','booking'); //itver

$txtreferencia= strtoupper($_POST['referencia']);
   
$txtconsignee1=strtoupper($_POST['consignee1']);
$txtconsignee2= strtoupper($_POST['consignee2']);
$txtconsignee3=strtoupper($_POST['consignee3']);
$txtconsignee4 = strtoupper($_POST['consignee4']);
$txtconsignee5 = strtoupper($_POST['consignee5']);
$txtconsignee6 = strtoupper($_POST['consignee6']);

$txtnotify1=strtoupper($_POST['notify1']);
$txtnotify2= strtoupper($_POST['notify2']);
$txtnotify3=strtoupper($_POST['notify3']);
$txtnotify4 = strtoupper($_POST['notify4']);
$txtnotify5 = strtoupper($_POST['notify5']);
$txtnotify6 = strtoupper($_POST['notify6']);

$txtshipper1=strtoupper($_POST['shipper1']);
$txtshipper2= strtoupper($_POST['shipper2']);
$txtshipper3=strtoupper($_POST['shipper3']);
$txtshipper4 = strtoupper($_POST['shipper4']);
$txtshipper5 = strtoupper($_POST['shipper5']);
$txtshipper6 = strtoupper($_POST['shipper6']);

$txtmarks=strtoupper($_POST['marks']);
$txtquantity= strtoupper($_POST['quantity']);
$txtdescription=strtoupper($_POST['description']);
$txtno_piezas = strtoupper($_POST['no_piezas']);
$txtgross_weight = strtoupper($_POST['gross_weight']);
$txtnet_weight = strtoupper($_POST['net_weight']);

$txtvolume=strtoupper($_POST['volume']);
$txtharmonized_code= strtoupper($_POST['harmonized_code']);
$txtams=strtoupper($_POST['ams']);


$txtfiles = qry_(' booking = "'.$txtidbooking.'" ','bookingexpint','files');
// OBTENGO EL HBL DEL BOOKING

$txthbl = hbl_($txtidbooking);


/* ESTOS SIRVEN PARA GUARDAR EN LA BD IMPO
mysql_query("UPDATE hblexpint SET files='$txtfiles',hbl='$txthbl',shipper='$txtshipper1',shipper2='$txtshipper2',shipper3='$txtshipper3',shipper4='$txtshipper4',shipper5='$txtshipper5',shipper6='$txtshipper6',consignee='$txtconsignee1',consignee2='$txtconsignee2',consignee3='$txtconsignee3',consignee4='$txtconsignee4',consignee5='$txtconsignee5',consignee6='$txtconsignee6',notify='$txtnotify1',notify2='$txtnotify2',notify3='$txtnotify3',notify4='$txtnotify4',notify5='$txtnotify5',notify6='$txtnotify6',harmonized_code='$txtharmonized_code',transmision_ams='$txtams',hbl_veracruz=1,referencia_veracruz='$txtreferencia',fechaRegistro='".date("Y-m-d h:i:s")."' WHERE files='$txtfiles' and hbl ='$txthbl' limit 1");
 	 	
mysql_query("INSERT INTO detailcargaexpint  (files,bookingno,markandnos,bulk,type,cargo,weight,measurement,weight2,measurement2,typeenglish,cargoenglish,netweight,netmeasurement,freeweight,freemeasurement,freebulk,netweight2,imo) Values ('$txtfiles','$txtidbooking','$txtmarks','$txtquantity','$txttype','$txtdescription','$txtgross_weight','$txtvolume','$txtgross_weight','$txtvolume','$txttypeenglish','$txtdescription','$txtnet_weight','$txtvolume','$txtnet_weight','$txtvolume','$txtquantity','$txtnet_weight','$txtimo')");
*/

/* ESTOS SIRVEN PARA GUARDAR EN LA BD VERACRUZ */
$datos_anteriores = data("select * from hblexpint where booking_interteam ='$txtbooking'");
if($datos_anteriores[booking_interteam]!=''){
	$campos = array('shipper', 'shipper2', 'shipper3', 'shipper4', 'shipper5', 'shipper6', 'consignee', 'consignee2', 'consignee3','consignee4','consignee5','consignee6','notify2','notify3','notify4','notify5','notify6','harmonized_code','transmision_ams','referencia_veracruz');
	
	$valores = array($txtshipper1,$txtshipper2,$txtshipper3,$txtshipper4,$txtshipper5,$txtshipper6,$txtconsignee1,$txtconsignee2,$txtconsignee3,$txtconsignee4,$txtconsignee5,$txtconsignee6,$txtnotify1,$txtnotify2,$txtnotify3,$txtnotify4,$txtnotify5,$txtnotify6,$txtharmonized_code,$txtams,$txtreferencia);
	
	$registro_actualizacion = data("select * from hblexpint_actualizaciones where booking_interteam ='$txtbooking'");
	
	if($registro_actualizacion[idhbl]==''){
		mysql_query("insert into hblexpint_actualizaciones (hbl) values ('$txthbl')");
		$idhbl= mysql_insert_id();
	}else{
		$idhbl=$registro_actualizacion[idhbl];
	}
	
	while($i<=count($campos)){
	if($datos_anteriores[$campos[$i]]<>$valores[$i]){
		mysql_query("UPDATE hblexpint SET ".$campos[$i]." = '".$valores[$i]."' WHERE hbl ='$txthbl'");
		$i++;
	}
		
mysql_query("UPDATE hblexpint SET hbl='$txthbl',shipper='$txtshipper1',shipper2='$txtshipper2',shipper3='$txtshipper3',shipper4='$txtshipper4',shipper5='$txtshipper5',shipper6='$txtshipper6',consignee='$txtconsignee1',consignee2='$txtconsignee2',consignee3='$txtconsignee3',consignee4='$txtconsignee4',consignee5='$txtconsignee5',consignee6='$txtconsignee6',notify='$txtnotify1',notify2='$txtnotify2',notify3='$txtnotify3',notify4='$txtnotify4',notify5='$txtnotify5',notify6='$txtnotify6',harmonized_code='$txtharmonized_code',transmision_ams='$txtams',referencia_veracruz='$txtreferencia',fechaRegistro='".date("Y-m-d h:i:s")."',status ='REVISION PENDIENTE' WHERE hbl ='$txthbl' limit 1");
}else{
		mysql_query("insert into hblexpint (hbl, shipper, shipper2, shipper3, shipper4, shipper5, shipper6, consignee, consignee2, consignee3, 	
		consignee4, consignee5, consignee6, notify2, notify3, notify4, notify5, notify6,booking_interteam, harmonized_code, 
		transmision_ams, referencia_veracruz, fechaRegistro, status) values 	
		('$txthbl','$txtshipper1','$txtshipper2','$txtshipper3','$txtshipper4','$txtshipper5','$txtshipper6',
		'$txtconsignee1','$txtconsignee2','$txtconsignee3','$txtconsignee4','$txtconsignee5','$txtconsignee6','$txtnotify1',
		'$txtnotify2','$txtnotify3','$txtnotify4','$txtnotify5','$txtnotify6','$txtbooking','$txtharmonized_code','$txtams','$txtreferencia','".date("Y-m-d h:i:s")."',
		'REVISION PENDIENTE' WHERE hbl ='$txthbl'");
}


mysql_query("delete from hblexpint_actualizaciones WHERE hbl ='$txthbl'");

mysql_query("insert into hblexpint_actualizaciones hbl='$txthbl',shipper='$txtshipper1',shipper2='$txtshipper2',shipper3='$txtshipper3',shipper4='$txtshipper4',shipper5='$txtshipper5',shipper6='$txtshipper6',consignee='$txtconsignee1',consignee2='$txtconsignee2',consignee3='$txtconsignee3',consignee4='$txtconsignee4',consignee5='$txtconsignee5',consignee6='$txtconsignee6',notify='$txtnotify1',notify2='$txtnotify2',notify3='$txtnotify3',notify4='$txtnotify4',notify5='$txtnotify5',notify6='$txtnotify6',harmonized_code='$txtharmonized_code',transmision_ams='$txtams',hbl_veracruz=1,referencia_veracruz='$txtreferencia',fechaRegistro='".date("Y-m-d h:i:s")."',status ='ACTUALIZACION PENDIENTE' WHERE hbl ='$txthbl' limit 1");
// 11.3.2014
con_ver();
mysql_query("INSERT INTO detailcargaexpint  (files,bookingno,markandnos,bulk,type,cargo,weight,measurement,weight2,measurement2,typeenglish,cargoenglish,netweight,netmeasurement,freeweight,freemeasurement,freebulk,netweight2,imo) Values ('$txtfiles','$txtidbooking','$txtmarks','$txtquantity','$txttype','$txtdescription','$txtgross_weight','$txtvolume','$txtgross_weight','$txtvolume','$txttypeenglish','$txtdescription','$txtnet_weight','$txtvolume','$txtnet_weight','$txtvolume','$txtquantity','$txtnet_weight','$txtimo')");


$action->alert('BL registrado OK');

$action->add_js_code("document.getElementById('forma').reset();unloadin('saving_bl');");

$action->send_response();

return;

?> 

