|
|
@@ -4024,103 +4024,124 @@ class common {
|
|
|
$h_serial_no_arr =json_decode($h_serial_no_json,true);
|
|
|
|
|
|
$ctnr = $delivery_booking['ctnr'];
|
|
|
-
|
|
|
+
|
|
|
//从UI 设计的case来讲,一个hbol就生成成一个wo ID
|
|
|
- //空運我們先不管,不做同步,就只做創建到審批,後面的讓他們自己錄入系統處理吧
|
|
|
foreach($h_serial_no_arr as $serial_no){
|
|
|
- $oceanInfo = common::excuteObjectSql("select (select manifest_type from public.ocean o where o.serial_no = ooc.serial_no limit 1) as manifest_type
|
|
|
- from public.kln_ocean oo where o.serial_no ='".$serial_no."'" );
|
|
|
+ $sql = "";
|
|
|
+
|
|
|
+ $oceanInfo = common::excuteObjectSql("select * from public.kln_ocean oo where oo.serial_no ='".$serial_no."'" );
|
|
|
+ //空運我們先不管,不做同步,就只做創建到審批,後面的讓他們自己錄入系統處理吧
|
|
|
+ if ($oceanInfo['transport_mode'] == "air"){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $biztype = $oceanInfo['ex_im'] == "Export" && $oceanInfo['transport_mode'] == "sea" ? "SE" :(
|
|
|
+ $oceanInfo['ex_im'] == "Import" && $oceanInfo['transport_mode'] == "sea" ? "SI" :(
|
|
|
+ $oceanInfo['ex_im'] == "Export" && $oceanInfo['transport_mode'] == "air" ? "AE" :(
|
|
|
+ $oceanInfo['ex_im'] == "Import" && $oceanInfo['transport_mode'] == "air" ? "AI" : "" )));
|
|
|
+ $mode_type = $delivery_booking['delivery_mode'] == "Truck" ? "Road" : "";
|
|
|
+
|
|
|
+ $consignee = $oceanInfo['consignee_id'];
|
|
|
+ $_schema = $oceanInfo['order_from'];
|
|
|
+ $_schema_contacts = $oceanInfo['order_from'];
|
|
|
+ if($oceanInfo['order_from'] == "public"){
|
|
|
+ $_schema_contacts = "ocean";
|
|
|
+ }
|
|
|
+
|
|
|
+ $delivery_address =json_decode($delivery_booking['delivery_address_detail'],true);
|
|
|
+ $consignee_name = common::excuteOneSql("select company from $_schema_contacts.contacts where contact_id = '$consignee' limit 1");
|
|
|
+ $consignee_exp = common::combineContactInfoString($delivery_address);
|
|
|
+ $consignee_sync_key = $delivery_address['sync_key'];
|
|
|
|
|
|
- $ctnrs = common::excuteListSql("select ctnr,seal_no,size,qty,unit,grs_kgs,cbm,marks,description,is_lcl FROM oc_container oc where oc.serial_no::text = '".$serial_no."'
|
|
|
+ $ctnrs = common::excuteListSql("select * FROM $_schema.oc_container oc where oc.serial_no::text = '".$serial_no."'
|
|
|
and oc.ctnr in (select regexp_split_to_table('".$ctnr."', ','))" );
|
|
|
-
|
|
|
$total_pcs = "";
|
|
|
$total_pcs_unit = "";
|
|
|
$total_weight = "";
|
|
|
- $total_weight_unit = "";
|
|
|
+ $total_weight_unit = "KGS";
|
|
|
$total_volume = "";
|
|
|
- $total_volume_unit = "";
|
|
|
+ $total_volume_unit = "CBM";
|
|
|
foreach($ctnrs as $_ctnr_info){
|
|
|
-
|
|
|
+ $total_pcs_unit = $_ctnr_info['unit'];
|
|
|
+ $total_pcs += $_ctnr_info['qty'];
|
|
|
+ $total_weight += $_ctnr_info['grs_kgs'];
|
|
|
+ $total_volume += $_ctnr_info['cbm'];
|
|
|
}
|
|
|
|
|
|
- $biztype = $oceanInfo['ex_im'] == "Export" && $oceanInfo['transport_mode'] == "sea" ? "SE" :(
|
|
|
- $oceanInfo['ex_im'] == "Import" && $oceanInfo['transport_mode'] == "sea" ? "SI" :(
|
|
|
- $oceanInfo['ex_im'] == "Export" && $oceanInfo['transport_mode'] == "air" ? "AE" :(
|
|
|
- $oceanInfo['ex_im'] == "Import" && $oceanInfo['transport_mode'] == "air" ? "AI" : "" )));
|
|
|
-
|
|
|
- // 记录
|
|
|
- // "INSERT INTO public.do_header(
|
|
|
- // id,air_ocean, station_code, do_no, biztype, delivery_type,mode_type,
|
|
|
- // serial_no, lot_no, awbbl_no, job_no, do_date,
|
|
|
- // consignee, consignee_name, consignee_exp,consignee_pic, consignee_tel, consignee_fax,
|
|
|
- // collect, collect_name,collect_exp, collect_pic, collect_tel, collect_fax,
|
|
|
- // notify, notify_name, shipper, shipper_name,
|
|
|
- // transport_agent, transport_agent_name, transport_agent_exp,transport_agent_pic, transport_agent_tel, transport_agent_fax,
|
|
|
- // truck_no, driver_name,do_release_to, total_pcs, total_pcs_unit, total_weight,
|
|
|
- // est_delivery_date, est_delivery_time,
|
|
|
- // instructions,
|
|
|
- // total_weight_unit, total_volume, total_volume_unit, commodity1, commodity2, remark, create_user, create_time,
|
|
|
- // modify_user, modify_time, booking_no,total_chrgwt_unit,departure_airport,discharge_airport,chrgwt, consignee_addr_type, collect_addr_type, consignee2, consignee2_name,
|
|
|
- // broker, broker_name, broker_exp, broker_pic, broker_tel, broker_fax, broker_addr_type,
|
|
|
- // terminal_code, terminal_name, terminal_signed_by, terminal_reference,terminal_time,terminal_date,terminal_address,terminal_tel,terminal_fax,terminal_pic,
|
|
|
- // delivery_vehicle_type, delivery_fuel_type,
|
|
|
- // delivery_is_refrigerated_shipment,collect_addr_type_id,consignee_addr_type_id,broker_addr_type_id,loadterm,collect_addr_key,consignee_addr_key,
|
|
|
- // broker_addr_key,collect_city_code,collect_country_code,consignee_country_code,consignee_city_code)
|
|
|
- /**
|
|
|
- * 这个id,和no, 我这边应该不生成,每个站点的应该不一样
|
|
|
- * delivery_type 按逻辑来说是 Select code,description,category From kerry_system_code Where category in ('DELIVERYTYPE') and is_active =true order by sno取出来的。
|
|
|
- * online上没有值,暂时取截图里面的值 "Awaiting Confirmation"
|
|
|
- *
|
|
|
- * over_balance,total_chrgwt_unit,chrgwt
|
|
|
- *
|
|
|
- * delivery_vehicle_type, delivery_fuel_type, 如果选择的是road ,会有默认的配置信息,每个站点应该不一样
|
|
|
- */
|
|
|
- $doNo = common::GeneralDoNo($oceanInfo['agent']);
|
|
|
- $Id = common::excuteOneSql("select nextval('do_header_id_seq')");
|
|
|
- "INSERT INTO public.do_header(
|
|
|
- id,air_ocean, station_code, do_no, biztype, delivery_type,mode_type,
|
|
|
+ $doHeaderId = common::excuteOneSql("select nextval('do_header_id_seq')");
|
|
|
+ $sql .="INSERT INTO public.do_header(
|
|
|
+ id,air_ocean, station_code, biztype,delivery_type,mode_type,
|
|
|
serial_no, lot_no, awbbl_no, job_no, do_date,
|
|
|
total_pcs, total_pcs_unit,
|
|
|
total_weight,total_weight_unit,
|
|
|
total_volume, total_volume_unit,
|
|
|
- est_delivery_date, est_delivery_time,
|
|
|
- instructions,
|
|
|
- create_user, create_time,modify_user, modify_time,
|
|
|
- booking_no,delivery_vehicle_type, delivery_fuel_type,
|
|
|
- consignee, consignee_name, consignee_exp,consignee_pic, consignee_tel, consignee_fax)
|
|
|
- VALUES ('".$Id."', '".$oceanInfo['transport_mode']."', '".$oceanInfo['agent']."','".$doNo."','".$biztype."','Awaiting Confirmation','".$delivery_booking['delivery_mode']."',
|
|
|
+ est_delivery_date, est_delivery_time,instructions,
|
|
|
+ create_user, create_time,delivery_vehicle_type,delivery_fuel_type,
|
|
|
+ consignee, consignee_name, consignee_exp)
|
|
|
+ VALUES ('".$doHeaderId."','Ocean', '".$oceanInfo['agent']."','".$biztype."','Awaiting Confirmation','".$mode_type."',
|
|
|
'".$serial_no."','".$oceanInfo['m_bol']."','".$oceanInfo['h_bol']."','".$oceanInfo['job_no']."',now(),
|
|
|
'".$total_pcs."','".$total_pcs_unit."','".$total_weight."','".$total_weight_unit."','".$total_volume."','".$total_volume_unit."',
|
|
|
- '".$delivery_booking['delivery_date']."','".$delivery_booking['delivery_date']."',
|
|
|
+ '".$delivery_booking['_delivery_date']."','".$delivery_booking['_delivery_time']."',
|
|
|
'".$delivery_booking['special_requirements']."',
|
|
|
- '"._getLoginName()."',now(),'"._getLoginName()."',now(),
|
|
|
- '".$oceanInfo['booking_no']."');";
|
|
|
+ 'KLN_Online',now(),'Subcontractor','Diesel','".$consignee."','".$consignee_name."','".$consignee_exp."');";
|
|
|
|
|
|
- /**
|
|
|
- * sno
|
|
|
- */
|
|
|
foreach($ctnrs as $ctnr){
|
|
|
- "INSERT INTO public.do_detail(
|
|
|
+ $qty = empty($ctnr['qty']) ? "null" : "'".$ctnr['qty']."'";
|
|
|
+ $grs_kgs = empty($ctnr['grs_kgs']) ? "null" : "'".$ctnr['grs_kgs']."'";
|
|
|
+ $cbm = empty($ctnr['cbm']) ? "null" : "'".$ctnr['cbm']."'";
|
|
|
+ $l4_length = empty($ctnr['l4_length']) ? "null" : "'".$ctnr['l4_length']."'";
|
|
|
+ $l4_width = empty($ctnr['l4_width']) ? "null" : "'".$ctnr['l4_width']."'";
|
|
|
+ $l4_height = empty($ctnr['l4_height']) ? "null" : "'".$ctnr['l4_height']."'";
|
|
|
+
|
|
|
+ $sql .="INSERT INTO public.do_detail(
|
|
|
do_header_id, pcs, pcs_unit, weight, weight_unit, volume,
|
|
|
- marks, description, create_user, create_time, modify_user, modify_time,
|
|
|
- ctnr, size, seal_no, is_lcl)
|
|
|
- VALUES ('".$Id."','".$ctnr['qty']."', '".$ctnr['unit']."','".$ctnr['grs_kgs']."','KGS','".$ctnr['cbm']."',
|
|
|
- '".$ctnr['marks']."','".$ctnr['description']."','"._getLoginName()."',now(),'"._getLoginName()."',now(),
|
|
|
- '".$ctnr['ctnr']."','".$ctnr['size']."','".$ctnr['seal_no']."','".$ctnr['is_lcl']."');";
|
|
|
+ marks, description, create_user, create_time,
|
|
|
+ ctnr, size, seal_no, is_lcl,
|
|
|
+ length,width,height)
|
|
|
+ VALUES ('".$doHeaderId."',$qty, '".$ctnr['unit']."',$grs_kgs,'KGS',$cbm,
|
|
|
+ '".$ctnr['marks']."','".$ctnr['description']."','KLN_Online',now(),
|
|
|
+ '".$ctnr['ctnr']."','".$ctnr['size']."','".$ctnr['seal_no']."','".$ctnr['is_lcl']."',
|
|
|
+ $l4_length,$l4_width,$l4_height);";
|
|
|
}
|
|
|
-
|
|
|
+ common::excuteUpdateSql($sql);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function GeneralDoNo($agent){
|
|
|
- // 构建前缀:DO- + 站点 + 年(2位) + 月(2位)
|
|
|
- $prefix = 'DO-' . $agent;
|
|
|
- $prefix .= date('y'); // 两位年份
|
|
|
- $prefix .= str_pad(date('m'), 2, '0', STR_PAD_LEFT); // 两位月份
|
|
|
- // 数据库函数调用:gen_serial_no(key, prefix, length, padding)
|
|
|
- $sql = "SELECT * FROM gen_serial_no('invoice_no', :prefix, 1, 4)";
|
|
|
- return common::excuteOneSql($sql);
|
|
|
+ public static function combineContactInfoString($contact){
|
|
|
+ $backString = "";
|
|
|
+ if ($contact !== null) {
|
|
|
+ $address1 = trim($contact['address_1'] ?? '');
|
|
|
+ $address2 = trim($contact['address_2'] ?? '');
|
|
|
+ $address3 = trim($contact['address_3'] ?? '');
|
|
|
+ $address4 = trim($contact['address_4'] ?? '');
|
|
|
+ $city = trim($contact['city'] ?? '');
|
|
|
+ $zipcode = trim($contact['postal_code'] ?? '');
|
|
|
+ $country = trim($contact['country'] ?? '');
|
|
|
+
|
|
|
+ // 拼接非空的地址行
|
|
|
+ if ($address1 !== '') {
|
|
|
+ $backString .= $address1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($address2 !== '') {
|
|
|
+ $backString .= ($backString !== '' ? "\n" : '') . $address2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($address3 !== '') {
|
|
|
+ $backString .= ($backString !== '' ? "\n" : '') . $address3;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($address4 !== '') {
|
|
|
+ $backString .= ($backString !== '' ? "\n" : '') . $address4;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加城市、邮编和国家
|
|
|
+ $location = trim("$city $zipcode $country");
|
|
|
+ if ($location !== '') {
|
|
|
+ $backString .= ($backString !== '' ? "\n" : '') . $location;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return trim($backString);
|
|
|
}
|
|
|
}
|
|
|
?>
|