ocean_booking.class.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of ocean
  7. *
  8. * @author Administrator
  9. */
  10. class ocean_booking {
  11. private static $_ocean;
  12. function __construct() {
  13. }
  14. public static function getInstance() {
  15. global $memory_limit;
  16. $memory_limit = ini_get("memory_limit");
  17. ini_set("memory_limit", '2048M');
  18. if (!self::$_ocean) {
  19. $c = __CLASS__;
  20. self::$_ocean = new $c;
  21. }
  22. return self::$_ocean;
  23. }
  24. public function ocean_booking() {
  25. $operate = utils::_get('operate');
  26. $operate = strtolower($operate);
  27. /*
  28. * index page
  29. */
  30. if (empty($operate)) {
  31. $data = array();
  32. if (_isCustomerLogin())
  33. $data['is_customer'] = "yes";
  34. else
  35. $data['is_customer'] = "no";
  36. //栏位信息
  37. $column = column::getInstance()->getDisplayColumn('Booking_Search');
  38. $BookingTableColumns = column::getInstance()->tableColumns('Booking_Search',$column);
  39. $data['BookingTableColumns'] = $BookingTableColumns;
  40. common::echo_json_encode(200,$data);
  41. exit();
  42. }
  43. /*
  44. * ocean order search
  45. */
  46. if ($operate == "search") {
  47. $this->_booking_search();
  48. }
  49. if ($operate == "setting_display") {
  50. column::getInstance()->settingDisplay('Booking_Search', 'main_new_version.php?action=ocean_booking');
  51. }
  52. if ($operate == "detail") {
  53. $serial_no = common::deCode($_GET['a'], 'D');
  54. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_booking ob WHERE ob.serial_no = '$serial_no'");
  55. if ($transport_mode == "sea"){
  56. $this->_booking_detail();
  57. } elseif ($transport_mode == "air"){
  58. $this->_air_booking_detail();
  59. } else {
  60. $this->_booking_detail();
  61. }
  62. }
  63. if ($operate == "excel") {
  64. $this->_booking_excel();
  65. }
  66. if ($operate == "save_communication") {
  67. try {
  68. $content = $_POST["content"];
  69. $content = common::check_input($content);
  70. $text = $_POST["text"];
  71. $content = urldecode($content);
  72. $web_content = urldecode($text);
  73. $communication_cc = $_POST["communication_cc"];
  74. $serial_no = common::uuid();
  75. $email_uuid = $_POST["serial_no"];
  76. $add_by = _getLoginName();
  77. $refer_id = 0;
  78. $email = $this->getEmail($email_uuid);
  79. $from_email = "US.KApex.Online@kerryapex.com";
  80. $to_email = $email["email"];
  81. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  82. $communication_cc = trim($communication_cc);
  83. if (!empty($communication_cc)) {
  84. $communication_cc = common::check_input($communication_cc);
  85. $cc_email .= ";" . $communication_cc;
  86. }
  87. $user_from = _getLoginName();
  88. $user_to = $email["name"];
  89. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  90. if (empty($user_cc)) {
  91. $user_cc = _getLoginName();
  92. }
  93. $user_cc .= ";ApexOnlineCommunication";
  94. //邮件发送
  95. $poKey = "<br><br>Important note: when you reply this email, do not remove ApexOnlineCommunication@apexshipping.com<br>Below is system code, do not delete.<br>@@";
  96. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  97. $key = common::excuteOneSql($emailSql);
  98. $historyEmails = "";
  99. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  100. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  101. common::excuteUpdateSql("insert into public.email_record (type,title,from_email,to_email,cc_email,content,insert_date)values('Communication','$title','$from_email','$to_email','$cc_email','$emailContent',now());");
  102. $rs = common::excuteUpdateSql("INSERT INTO public.online_ocean_communication(serial_no, email_uuid, content,web_content,user_from, user_to, user_cc, refer_id, add_by, add_time, cc_email)
  103. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  104. $emailRecords = $this->getCommunicationNew($email_uuid);
  105. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  106. exit();
  107. } catch (Exception $e) {
  108. common::echo_json_encode(500,array("msg" => "Sent Error."));
  109. exit();
  110. }
  111. }
  112. }
  113. private function _booking_search() {
  114. //分担查询
  115. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  116. $cp = common::check_input($_POST ['cp']); //current_page
  117. $ps = common::check_input($_POST ['ps']); //ps
  118. if (empty($ps)){
  119. $ps = 100;
  120. }
  121. $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
  122. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  123. //移除掉全文检索 但保留代码
  124. // if (!empty($_POST["_textSearch"])) {
  125. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  126. // }
  127. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  128. if (!empty($_POST["_textSearch"])) {
  129. $textSearch_arr = $_POST['_textSearch'];
  130. if(!is_array($textSearch_arr)){
  131. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  132. $textSearch_arr = array($textSearch_arr);
  133. }
  134. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  135. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
  136. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  137. }
  138. //为了移除filterTag条件
  139. $sqlWhere_befrom_filterTag = $sqlWhere;
  140. $filterTag_param = "";
  141. $mode_param = "";
  142. $transport_mode = empty($_POST["transport_mode"]) ? "all" : $_POST["transport_mode"];
  143. if(!is_array($transport_mode)){
  144. $transport_mode = array($transport_mode);
  145. }
  146. if(utils::count($transport_mode) == 1 && strtolower($transport_mode[0]) == 'all'){
  147. $transport_mode = array("sea","air","road");
  148. }
  149. $transport_mode = utils::implode(";",$transport_mode);
  150. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  151. $sqlWhere .= " and transport_mode in ($mode_param)";
  152. $transport_mode_search = " and transport_mode in ($mode_param)";
  153. //前端提交是数组
  154. if (!empty($_POST['filterTag']) && utils::count($_POST['filterTag']) < 4) {
  155. if (utils::count($_POST['filterTag']) == 1){
  156. $filterTag = $_POST['filterTag'][0];
  157. }else{
  158. $filterTag = utils::implode(",", $_POST['filterTag']);
  159. }
  160. $_sqlwhere = "1<>1";
  161. $filterTag_param = "1<>1";
  162. if(strtolower($filterTag) == "all"){
  163. $filterTag_param = "1=1";
  164. }
  165. if (stripos($filterTag, "Confirmed") !== FALSE) {
  166. $_sqlwhere .= " or (bol_type != 'BOOKING')";
  167. $filterTag_param .= " or (bol_type != 'BOOKING')";
  168. }
  169. if (stripos($filterTag, "Cancelled") !== FALSE) {
  170. $_sqlwhere .= " or (status='Cancelled')";
  171. $filterTag_param .= " or (status='Cancelled')";
  172. }
  173. if (stripos($filterTag, "Created") !== FALSE) {
  174. $_sqlwhere .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
  175. $filterTag_param .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
  176. }
  177. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  178. $sqlWhere .= " and ($_sqlwhere)";
  179. $filterTag_param = " ($filterTag_param)";
  180. }
  181. }
  182. if(empty($filterTag_param)){
  183. $filterTag_param = "1=1";
  184. }
  185. $tag_and_mode_param = $filterTag_param.$transport_mode_search;
  186. $rc = $_POST ['rc'];
  187. //这里都要查询,除非多传几个参数回来
  188. if ($rc == - 1 || true) {
  189. $sql_all_status = "SELECT count(1) as rc,
  190. sum(case when (1<>1 or (transport_mode='sea')) then 1 else 0 end) as sea_rc,
  191. sum(case when (1<>1 or (transport_mode='air')) then 1 else 0 end) as air_rc,
  192. sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc,
  193. sum(case when (1<>1 or (bol_type = 'BOOKING' and status!='Cancelled')) then 1 else 0 end) as creatd,
  194. sum(case when (1<>1 or (bol_type != 'BOOKING')) then 1 else 0 end) as confirmed,
  195. sum(case when (1<>1 or (status='Cancelled')) then 1 else 0 end) as concelled
  196. from public.kln_booking" . $sqlWhere_befrom_filterTag;
  197. error_log($sql_all_status );
  198. //$sql_all_status_data = common::excuteObjectSql($sql_all_status);
  199. $sql_all_status_data = $mapdb->GetRow($sql_all_status) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql_all_status), 0));
  200. $seach_rc = $sql_all_status_data['seach_rc'];
  201. $rc = $sql_all_status_data['rc'];
  202. $sea_rc = $sql_all_status_data['sea_rc'];
  203. $air_rc = $sql_all_status_data['air_rc'];
  204. $Creatd = $sql_all_status_data['creatd'];
  205. $Confirmed = $sql_all_status_data['confirmed'];
  206. $Concelled = $sql_all_status_data['concelled'];
  207. //前端数据返回,不管有无数据
  208. if (!empty($_POST["filterTag"])) {
  209. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  210. array("name"=>"Created","number"=>intval($Creatd),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  211. array("name"=>"Confirmed","number"=>intval($Confirmed),"type"=>"confirmed","checked"=>utils::in_array('Confirmed', $_POST["filterTag"])? true : false),
  212. array("name"=>"Cancelled","number"=>intval($Concelled),"type"=>"cancelled","checked"=>utils::in_array('Cancelled', $_POST["filterTag"])? true : false));
  213. }else{
  214. //初始,前端有选择着带入选择
  215. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>true),
  216. array("name"=>"Created","number"=>intval($Creatd),"type"=>"created","checked"=>false),
  217. array("name"=>"Confirmed","number"=>intval($Confirmed),"type"=>"confirmed","checked"=>false),
  218. array("name"=>"Cancelled","number"=>intval($Concelled),"type"=>"cancelled","checked"=>false));
  219. }
  220. $TransportList = array(
  221. array("name"=>"Ocean Freight","sname"=>"Sea","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
  222. array("name"=>"Air Freight","sname"=>"Air","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"));
  223. $transport_mode_arr = explode(";", $transport_mode);
  224. foreach($transport_mode_arr as $mode){
  225. foreach($TransportList as $tkey => $transport){
  226. if(strtolower(trim($mode)) == strtolower($TransportList[$tkey]["sname"])){
  227. $TransportList[$tkey]["checked"] = true;
  228. }
  229. }
  230. }
  231. //现在下载交给前端,后台预先只返回全部字段的列,
  232. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Booking_Search');
  233. $allBookingColumns = column::getInstance()->tableColumns('Booking_Search',$allColumn);
  234. }
  235. $tp = ceil($rc / $ps);
  236. if ($rc > 0 ) {
  237. $order_by = " f_etd desc";
  238. //TopOcean的不用考虑
  239. $ocean_dest_sql = "";
  240. //合并显示两个特殊字段 voyage_m_voyage/vessel_m_vessel
  241. $sql = "SELECT order_from as _schemas, serial_no as __serial_no,
  242. color,transport_mode, bol_type, m_voyage as _m_voyage, m_vessel as _m_vessel," .
  243. column::getInstance()->getSearchSqlForDisplay('Booking_Search') . " from public.kln_booking $ocean_dest_sql " . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  244. //$rs = common::excuteListSql($sql);
  245. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  246. error_log("online_booking_search_SQL: ".$sql);
  247. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  248. foreach($rs as $index => $val) {
  249. //合并显示 vessel
  250. if(array_key_exists("f_vessel", $val)){
  251. $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['_m_vessel']);
  252. }
  253. //合并显示 voyage
  254. if(array_key_exists("f_voyage", $val)){
  255. $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['_m_voyage']);
  256. }
  257. //返回加密serial_no
  258. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  259. //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
  260. // $status = "Created";
  261. // if ($val['color'] == "FF00FF00" || $val['color'] == "FF0000FF"){
  262. // $status = "Confirmed";
  263. // }
  264. // if ($val['color'] == "FFFF0000"){
  265. // $status = "Cancelled";
  266. // }
  267. // $rs[$index]["Status"] = $status;
  268. if($val['bol_type'] == 'BOOKING' and $val['Status']!='Cancelled'){
  269. $status = "Created";
  270. }
  271. if ($val['bol_type'] != 'BOOKING'){
  272. $status = "Confirmed";
  273. }
  274. if ($val['Status']=='Cancelled'){
  275. $status = "Cancelled";
  276. }
  277. $rs[$index]["Status"] = $status;
  278. $rs[$index]["Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  279. }
  280. $arrTmp = array('searchData' => $rs,
  281. 'tagsList' => $tagsList,
  282. 'TransportList' => $TransportList,
  283. 'allColums' => $allBookingColumns,
  284. 'rc' => $seach_rc,
  285. 'ps' => $ps,
  286. 'cp' => $cp,
  287. 'tp' => $tp,
  288. 'tmp_search' => common::deCode($sql, 'E'),
  289. 'type' => common::check_input($_POST ['_ntype']));
  290. } else {
  291. $arrTmp = array('searchData' => array(),
  292. 'tagsList' => $tagsList,
  293. 'TransportList' => $TransportList,
  294. 'allColums' => $allBookingColumns,
  295. 'rc' => $seach_rc,
  296. 'ps' => $ps,
  297. 'cp' => $cp,
  298. 'tp' => $tp,
  299. 'tmp_search' => "",
  300. 'type' => common::check_input($_POST ['_ntype']));
  301. }
  302. common::echo_json_encode(200,$arrTmp);
  303. exit();
  304. }
  305. private function _booking_detail() {
  306. $serial_no = common::deCode($_GET['a'], 'D');
  307. $status = $_GET['status'];
  308. $_schemas = $_GET['_schemas'];
  309. if($_schemas == 'public'){
  310. $_schemas = "ocean";
  311. }
  312. $sql = "with o as(
  313. SELECT o.*,'' as incoterms from ocean o where serial_no = '" .$serial_no . "'
  314. )
  315. SELECT o.booking_no as _booking_no,
  316. o.* ,sh.*, cn.* ,aa.*,dd.*,ob.*
  317. from o
  318. LEFT JOIN LATERAL ( SELECT shippr_uncode,shipper_city,
  319. consignee_uncode,consignee_city,
  320. place_of_receipt_uncode,place_of_delivery_uncode,
  321. fport_of_loading_uncode,mport_of_discharge_uncode,po_no as _po_no,transport_mode
  322. FROM public.kln_booking ob WHERE o.serial_no::text = ob.serial_no::text) ob ON true
  323. LEFT JOIN LATERAL ( SELECT company as cn_company,
  324. address_1 as cn_address_1,
  325. address_2 as cn_address_2,
  326. address_3 as cn_address_3,
  327. address_4 as cn_address_4,
  328. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  329. phone_1 as cn_phone
  330. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  331. LEFT JOIN LATERAL ( SELECT company as sh_company,
  332. address_1 as sh_address_1,
  333. address_2 as sh_address_2,
  334. address_3 as sh_address_3,
  335. address_4 as sh_address_4,
  336. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  337. phone_1 as sh_phone
  338. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  339. LEFT JOIN LATERAL ( SELECT company as aa_company,
  340. address_1 as aa_address_1,
  341. address_2 as aa_address_2,
  342. address_3 as aa_address_3,
  343. address_4 as aa_address_4,
  344. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  345. phone_1 as aa_phone
  346. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  347. LEFT JOIN LATERAL ( SELECT company as dd_company,
  348. address_1 as dd_address_1,
  349. address_2 as dd_address_2,
  350. address_3 as dd_address_3,
  351. address_4 as dd_address_4,
  352. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  353. phone_1 as dd_phone
  354. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true";
  355. $ocean = common::excuteObjectSql($sql);
  356. error_log($sql);
  357. $vueData = $this->returnBookingDetailData($ocean,$status);
  358. //处理transportInfo信息数据
  359. $transportInfo = $vueData["transportInfo"];
  360. //处理basicInfo信息数据
  361. $basicInfo = $vueData["basicInfo"];
  362. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  363. $businessPartners = $vueData["businessPartners"];
  364. $marksAndDescription = $vueData["marksAndDescription"];
  365. //处理ocean_reference
  366. $ref_no = array();
  367. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  368. if(!empty($ref_arr)){
  369. foreach($ref_arr as $ref) {
  370. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  371. }
  372. }
  373. //处理返回booking的 Container 信息数据
  374. $booking_container_column = array();
  375. $container_column = column::getInstance()->getDisplayColumnAll('Booking_Container');
  376. $booking_Container_config = array("QTY" => array("formatter"=>"number","digits"=>0),
  377. "KGS" => array("formatter"=>"number","digits"=>3),
  378. "CBM" => array("formatter"=>"number","digits"=>3));
  379. foreach($container_column as $cc){
  380. if(!empty($booking_Container_config[$cc['name']])){
  381. $booking_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],
  382. "formatter" =>$booking_Container_config[$cc['name']]["formatter"],
  383. "digits" =>$booking_Container_config[$cc['name']]["digits"],
  384. "type" =>"normal");
  385. }else{
  386. $booking_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],
  387. "formatter" =>"",
  388. "digits" =>"",
  389. "type" =>"normal");
  390. }
  391. }
  392. if (!empty($ocean['_booking_no'])) {
  393. $sql = "SELECT " . column::getInstance()->getSearchSql('Booking_Container') . " from ocean_booking_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  394. $rss = common::excuteListSql($sql);
  395. } else {
  396. $sql = "SELECT " . column::getInstance()->getSearchSql('Booking_Container') . " from oc_container_booking_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  397. $rss = common::excuteListSql($sql);
  398. }
  399. $containers = array("container_column"=>$booking_container_column,"container_data" =>$rss);
  400. //packing
  401. $quantity_unit = array();
  402. $packages = "CTN";
  403. $g_weight_tolal = 0;
  404. $ch_weight_tolal = 0;
  405. $cbm_tolal = 0;
  406. foreach($rss as $pk => $pv){
  407. //相同的unit 的合并成一个
  408. $unit = $pv['unit'];
  409. if (array_key_exists($unit, $quantity_unit)) {
  410. $quantity_unit[$unit] = $quantity_unit[$unit] + $pv['qty'];
  411. } else {
  412. $quantity_unit[$unit] = $pv['qty'];
  413. }
  414. $g_weight_tolal += $pv['kgs'];
  415. $ch_weight_tolal += $pv['kgs'];
  416. $cbm_tolal += $pv['cbm'];
  417. }
  418. $quantity_tolal = "";
  419. foreach($quantity_unit as $uk => $uv){
  420. $quantity_tolal.=$uv." ".$uk." ";
  421. }
  422. //$packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
  423. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  424. if (!empty($ocean['_booking_no'])) {
  425. $cbm_tolal = sprintf("%.3f", $cbm_tolal);
  426. }else{
  427. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  428. }
  429. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $g_weight_tolal." KGS","Volume" => $cbm_tolal." CBM");
  430. //处理邮件信息返回
  431. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  432. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  433. $email = $this->getEmail($ocean["serial_no"]);
  434. $email['cc_email'] = $cc_email;
  435. $email['emailRecords'] = $emailRecords;
  436. global $_COPYRIGHT;
  437. $data = array('transportInfo' => $transportInfo,
  438. 'basicInfo' => $basicInfo,
  439. 'businessPartners' => $businessPartners,
  440. 'ref_no' => $ref_no,
  441. 'packing' => $packing,
  442. 'marksAndDescription' => $marksAndDescription,
  443. 'containers' => $containers,
  444. 'email' => $email,
  445. 'serial_no' => $serial_no,
  446. '_schemas' => $_GET['_schemas'],
  447. '__serial_no' => common::deCode($ocean['serial_no'], 'E'),
  448. 'copyright' =>$_COPYRIGHT);
  449. common::echo_json_encode(200,$data);
  450. exit();
  451. }
  452. /**
  453. * 信息从kln_booking表里获取(查询全部数据),信息不够在从对应模式里的air_booking取部分数据。
  454. */
  455. private function _air_booking_detail(){
  456. $serial_no = common::deCode($_GET['a'], 'D');
  457. $status = $_GET['status'];
  458. $_schemas = $_GET['_schemas'];
  459. if($_schemas == 'public'){
  460. $_schemas = "ocean";
  461. }
  462. //air要关联ata_date as ata, atd没有对应字段
  463. $sql = "with o as(
  464. SELECT o.* from public.kln_booking o where serial_no = '" . $serial_no . "'
  465. )
  466. SELECT *, po_no as _po_no,'' as incoterms,null as atd,
  467. sh.*, cn.*, aa.*, dd.*
  468. from o
  469. LEFT JOIN LATERAL ( SELECT company as cn_company,
  470. address_1 as cn_address_1,
  471. address_2 as cn_address_2,
  472. address_3 as cn_address_3,
  473. address_4 as cn_address_4,
  474. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  475. phone_1 as cn_phone
  476. FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
  477. LEFT JOIN LATERAL ( SELECT company as sh_company,
  478. address_1 as sh_address_1,
  479. address_2 as sh_address_2,
  480. address_3 as sh_address_3,
  481. address_4 as sh_address_4,
  482. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  483. phone_1 as sh_phone
  484. FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
  485. LEFT JOIN LATERAL ( SELECT company as aa_company,
  486. address_1 as aa_address_1,
  487. address_2 as aa_address_2,
  488. address_3 as aa_address_3,
  489. address_4 as aa_address_4,
  490. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  491. phone_1 as aa_phone
  492. FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
  493. LEFT JOIN LATERAL ( SELECT company as dd_company,
  494. address_1 as dd_address_1,
  495. address_2 as dd_address_2,
  496. address_3 as dd_address_3,
  497. address_4 as dd_address_4,
  498. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  499. phone_1 as dd_phone
  500. FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true";
  501. $ocean = common::excuteObjectSql($sql);
  502. $vueData = $this->returnBookingDetailData($ocean,$status);
  503. //处理transportInfo信息数据
  504. $transportInfo = $vueData["transportInfo"];
  505. //处理basicInfo信息数据
  506. $basicInfo = $vueData["basicInfo"];
  507. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  508. $businessPartners = $vueData["businessPartners"];
  509. $marksAndDescription = $vueData["marksAndDescription"];
  510. //处理ocean_reference: air没有这个信息
  511. $ref_no = array();
  512. //处理返回booking的 Container 信息数据
  513. $containers = array();
  514. //packing
  515. //$packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
  516. $quantity_tolal = empty($ocean['qty']) ? "" : $ocean['qty'].$ocean['qty_uom'];
  517. $g_weight_tolal = empty($ocean['piece_count']) ? "" : sprintf("%.3f", $ocean['piece_count'])." KGS";
  518. $ch_weight_tolal = empty($ocean['piece_count']) ? "": sprintf("%.3f", $ocean['weight'])." KGS";
  519. $cbm_tolal = empty($ocean['cbm']) ? "" : sprintf("%.4f", $ocean['cbm'])." CBM";
  520. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
  521. //处理邮件信息返回
  522. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  523. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  524. $email = $this->getEmail($ocean["serial_no"]);
  525. $email['cc_email'] = $cc_email;
  526. $email['emailRecords'] = $emailRecords;
  527. global $_COPYRIGHT;
  528. $data = array('transportInfo' => $transportInfo,
  529. 'basicInfo' => $basicInfo,
  530. 'businessPartners' => $businessPartners,
  531. 'ref_no' => $ref_no,
  532. 'packing' => $packing,
  533. 'marksAndDescription' => $marksAndDescription,
  534. 'containers' => $containers,
  535. 'email' => $email,
  536. 'serial_no' => $serial_no,
  537. '_schemas' => $_GET['_schemas'],
  538. '__serial_no' => common::deCode($ocean['serial_no'], 'E'),
  539. 'copyright' =>$_COPYRIGHT);
  540. common::echo_json_encode(200,$data);
  541. exit();
  542. }
  543. private function _booking_excel() {
  544. $sql = common::deCode($_POST ['tmp_search'], 'D');
  545. $sql = substr($sql, 0, strripos($sql, " limit"));
  546. if(!empty($sql)){
  547. $rs = common::excuteListSql($sql);
  548. }
  549. //去除null
  550. foreach($rs as $index => $val) {
  551. foreach($val as $index_2 => $_val) {
  552. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  553. $rs[$index][$index_2] = "";
  554. }
  555. }
  556. }
  557. foreach($rs as $index => $val) {
  558. //合并显示 vessel
  559. if(array_key_exists("f_vessel", $val)){
  560. $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['_m_vessel']);
  561. }
  562. //合并显示 voyage
  563. if(array_key_exists("f_voyage", $val)){
  564. $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['_m_voyage']);
  565. }
  566. //返回加密serial_no
  567. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  568. //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
  569. if($val['bol_type'] == 'BOOKING' and $val['Status']!='Cancelled'){
  570. $status = "Created";
  571. }
  572. if ($val['bol_type'] != 'BOOKING'){
  573. $status = "Confirmed";
  574. }
  575. if ($val['Status']=='Cancelled'){
  576. $status = "Cancelled";
  577. }
  578. $rs[$index]["Status"] = $status;
  579. $rs[$index]["Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  580. }
  581. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  582. exit;
  583. }
  584. private function getEmail($serial_no) {
  585. return utils::getEmail($serial_no);
  586. }
  587. private function getCommunicationNew($serial_no) {
  588. $list = common::excuteListSql("select to_char(add_time, 'MM/dd/yyyy hh24:MI:ss') as add_times, * from public.online_ocean_communication where email_uuid='$serial_no' and refer_id = 0 order by id");
  589. $emialRecords =array();
  590. foreach ($list as $k => $v) {
  591. $msg =array();
  592. $msg["name"] = $v["add_by"];
  593. $msg["creatTime"] = $v["add_times"];
  594. $msg["content"] = urldecode($v["web_content"]);
  595. $emialRecords[] = $msg;
  596. }
  597. return $emialRecords;
  598. }
  599. private function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  600. $stationInfo = "";
  601. if(!empty($address_1)){
  602. $stationInfo .= $address_1;
  603. }
  604. if(!empty($address_2)){
  605. $stationInfo .= " ".$address_2;
  606. }
  607. if(!empty($address_3)){
  608. $stationInfo .= " ".$address_3;
  609. }
  610. if(!empty($address_4)){
  611. $stationInfo .= " ".$address_4;
  612. }
  613. $temp_str = "";
  614. if(!empty($city)){
  615. $temp_str .= $city." ";
  616. }
  617. if(!empty($state)){
  618. $temp_str .= $state." ";
  619. }
  620. if(!empty($zipcode)){
  621. $temp_str .= $zipcode." ";
  622. }
  623. if(!empty($country)){
  624. $temp_str .= $country." ";
  625. }
  626. if(!empty($temp_str)){
  627. return $stationInfo." ".trim($temp_str);
  628. }
  629. return $stationInfo;
  630. }
  631. private function returnBookingDetailData($ocean,$status){
  632. $data = array();
  633. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  634. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  635. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  636. $ocean['shippr_uncode'] = $ocean['place_of_receipt_uncode'];
  637. $ocean['consignee_uncode'] = $ocean['place_of_delivery_uncode'];
  638. //获取对应uncode 对应的时间
  639. $uncodes = $ocean['fport_of_loading_uncode'].";".$ocean['mport_of_discharge_uncode'];
  640. $codeinfo = common::getCityPortsInfo($uncodes);
  641. //处理transportInfo信息数据
  642. $transportInfo = array("bookingNo." =>$ocean['booking_no'],"status"=>$status,"mode" => $ocean['transport_mode'] == 'sea' ? "Ocean Freight" : ($ocean['transport_mode'] == 'air' ? "Air Freight": ""),
  643. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  644. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  645. "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],
  646. "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],
  647. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  648. "eta_timezone" =>$codeinfo[$ocean['mport_of_discharge_uncode']],
  649. "ata_timezone" =>$codeinfo[$ocean['mport_of_discharge_uncode']]);
  650. $data["transportInfo"] = $transportInfo;
  651. //处理basicInfo信息数据
  652. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  653. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  654. $basicInfo = array("bookingNo." =>$ocean['booking_no'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  655. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  656. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  657. $data["basicInfo"] = $basicInfo;
  658. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  659. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  660. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  661. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  662. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  663. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  664. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  665. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  666. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  667. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  668. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  669. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  670. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  671. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  672. $data["businessPartners"] = $businessPartners;
  673. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  674. $data["marksAndDescription"] = $marksAndDescription;
  675. return $data;
  676. }
  677. }
  678. ?>