ocean_order.class.php 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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_order {
  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_order() {
  25. $operate = utils::_get('operate');
  26. $operate = strtolower($operate);
  27. if (empty($operate)) {
  28. //search
  29. //栏位信息
  30. $column = column::getInstance()->getDisplayColumn('Ocean_Search');
  31. $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
  32. $data['TrackingTableColumns'] = $BookingTableColumns;
  33. common::echo_json_encode(200,$data);
  34. exit();
  35. }
  36. if ($operate == "search") {
  37. $this->_ocean_search();
  38. }
  39. if ($operate == "detail") {
  40. $this->_ocean_detail();
  41. }
  42. if ($operate == "ams_isf_log"){
  43. $this->_ams_isf_log();
  44. }
  45. /*
  46. * export ocean order to excel
  47. */
  48. if ($operate == "excel") {
  49. $this->_ocean_excel();
  50. }
  51. /*
  52. * download Revenue
  53. */
  54. if ($operate == "revenue") {
  55. $this->_revenue_download();
  56. }
  57. if ($operate == 'setting_ocean_order_display') {
  58. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  59. }
  60. /*
  61. * download document
  62. */
  63. if ($operate == "download") {
  64. $this->_download();
  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. if ($operate == "ocean_vgm") {
  113. if (!_canEdiVgm()) {
  114. $data = array("msg" =>"Vgm Permission Error");
  115. common::echo_json_encode(400, $data);
  116. exit();
  117. }
  118. $serial_no = common::deCode(($_GET["a"]), 'D');
  119. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  120. $column = "*";
  121. $schemas = $_GET["_schemas"];
  122. if (empty($schemas)) {
  123. $schemas = "public";
  124. }
  125. $ocean_info_sql = "select o.from_station as o_from_station, o.h_bol as o_h_bol, o.carrier_booking, o.m_vessel, o.m_voyage, to_char(o.f_etd, 'MM/DD/YYYY') as f_etd, to_char(o.m_eta, 'MM/DD/YYYY') as m_eta, v.*, o.master_base_number from "
  126. . "$schemas.ocean o left join $schemas.ocean_vgm v on o.serial_no=v.serial_no or o.master_base_number=v.master_base_number where 1=1 and o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text" . $sqlWhere;
  127. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  128. $rs_sql = "select o.service, o.ctnr, v.carrier_booking_no, o.ctnr, o.size, v.vgm_weight, v.unit, v.vgm_time, v.vgm_method, o.grs_kgs, o.grs_lbs, ov.id as ocean_vgm_id, v.id as ocean_vgm_container_id from "
  129. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  130. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  131. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  132. . " where 1=1 and oc.status::text <> 'Cancelled'::text AND oc.bol_type::text <> 'BOOKING'::text AND oc.bol_type::text <> 'QUOTE'::text and oc.master_base_number='" . $ocean_info["master_base_number"] . "' and oc.from_station='" . $ocean_info["o_from_station"] . "'";
  133. $rs = common::excuteListSql($rs_sql);
  134. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  135. if (empty($ocean_info["id"])) {
  136. $ocean_info["is_send"] = "t";
  137. }
  138. $err_msg = "";
  139. if (empty($ocean_info["carrier_booking"])) {
  140. $err_msg = "Carrier Booking is empty.";
  141. }
  142. if ($schemas <> "public") {
  143. $err_msg .= "This hbol do not support.";
  144. }
  145. $err_msg_ctnr = "";
  146. $err_msg_CFS = "";
  147. foreach ($rs as $cv) {
  148. if (empty($cv["ctnr"])) {
  149. $err_msg_ctnr = "Container# is empty.";
  150. }
  151. if (substr($cv["service"], 0, 3) == "CFS") {
  152. $err_msg_CFS = "CFS cannot support update.";
  153. }
  154. }
  155. if (!empty($err_msg)) {
  156. $err_msg = "You cant't add this VGM, (" . $err_msg ." ". $err_msg_ctnr." ".$err_msg_CFS.")";
  157. }
  158. $serial_no = common::deCode($serial_no, "E");
  159. //default
  160. if (empty($rs["id"])) {
  161. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  162. }
  163. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  164. //detail information
  165. $detail_information_column = array();
  166. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","edit_type" =>"normal",);
  167. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","edit_type" =>"normal");
  168. $detail_information_column[] = array("title" =>"Container No","field" =>"container_no","formatter" =>"","edit_type" =>"normal");
  169. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","edit_type" =>"number");
  170. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"vgm_kg_lg","formatter" =>"","edit_type" =>"select");
  171. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_date","formatter" =>"","edit_type" =>"dateTime");
  172. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","edit_type" =>"input");
  173. foreach($rs as $rk => $rv){
  174. $rs[$rk]['sn'] = $rk +1;
  175. $rs[$rk]['container_no'] = $rv['ctnr'];
  176. $rs[$rk]['vgm_kg_lg'] = $rv['unit'];
  177. $rs[$rk]['vgm_date'] = $rv['vgm_time'];
  178. }
  179. $detail_information =array("detail_information_column" =>$detail_information_column,
  180. "detail_information_data" =>$rs);
  181. $data = array("msg" =>$err_msg);
  182. $Submitter = $ocean_info["authorized_company"];
  183. if(empty($ocean_info["id"])){
  184. $Submitter = $default["submitter"];
  185. }
  186. $signature = $ocean_info["signature"];
  187. if(empty($ocean_info["id"])){
  188. $signature = $default["signature"];
  189. }
  190. $authorized_email = $ocean_info["authorized_email"];
  191. if(empty($ocean_info["id"])){
  192. $authorized_email = $default["authorized_email"];
  193. }
  194. $authorized_tel = $ocean_info["authorized_tel"];
  195. if(empty($ocean_info["id"])){
  196. $authorized_tel = $default["authorized_tel"];
  197. }
  198. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  199. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  200. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  201. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  202. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  203. "Submitter" =>$Submitter,"signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  204. $data["detail_information"] = $detail_information;
  205. $data["schemas"] = $schemas;
  206. $data["serial_no"] = $serial_no;
  207. common::echo_json_encode(200, $data);
  208. exit();
  209. }
  210. if ($operate == "save_ocean_vgm") {
  211. if (!_canEdiVgm()) {
  212. $data = array("msg" =>"Vgm Permission Error");
  213. common::echo_json_encode(400, $data);
  214. exit();
  215. }
  216. $msg = $this->save_vgm();
  217. if ($msg == "success"){
  218. $data = array("msg" =>$msg);
  219. common::echo_json_encode(200, $data);
  220. } else {
  221. $data = array("msg" =>$msg);
  222. common::echo_json_encode(500, $data);
  223. }
  224. exit();
  225. }
  226. }
  227. /*
  228. * ocean order search
  229. */
  230. private function _ocean_search() {
  231. $cp = common::check_input($_POST ['cp']); //current_page
  232. $ps = common::check_input($_POST ['ps']); //ps
  233. if (empty($ps))
  234. $ps = 100;
  235. if (empty($cp))
  236. $cp = 1;
  237. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  238. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  239. if (!empty($_REQUEST["_reportRef"])) {
  240. $_reportType = $_REQUEST["_reportType"];
  241. $_reportRef = $_REQUEST["_reportRef"];
  242. if ($_reportType == "r3") {
  243. if ($_reportRef == "Previous 7 Days") {
  244. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  245. } else if ($_reportRef == "≤1 Day") {
  246. $sqlWhere .= " and eta=current_date";
  247. } else if ($_reportRef == "1-2 Days") {
  248. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  249. } else if ($_reportRef == "3-6 Days") {
  250. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  251. } else if ($_reportRef == "≥7 Days") {
  252. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  253. } else {
  254. $sqlWhere .= " and 1<>1";
  255. }
  256. } else if ($_reportType == "r4") {
  257. if ($_reportRef == "Previous 7 Days") {
  258. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  259. } else if ($_reportRef == "≤1 Day") {
  260. $sqlWhere .= " and etd=current_date";
  261. } else if ($_reportRef == "1-2 Days") {
  262. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  263. } else if ($_reportRef == "3-6 Days") {
  264. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  265. } else if ($_reportRef == "≥7 Days") {
  266. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  267. } else {
  268. $sqlWhere .= " and 1<>1";
  269. }
  270. } else if ($_reportType == "ata_r3") {
  271. if ($_reportRef == "≤1 Day") {
  272. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  273. } else if ($_reportRef == "1-2 Days") {
  274. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  275. } else if ($_reportRef == "3-6 Days") {
  276. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  277. } else if ($_reportRef == "≥7 Days") {
  278. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  279. } else {
  280. $sqlWhere .= " and 1<>1";
  281. }
  282. } else if ($_reportType == "atd_r4") {
  283. if ($_reportRef == "≤1 Day") {
  284. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  285. } else if ($_reportRef == "1-2 Days") {
  286. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  287. } else if ($_reportRef == "3-6 Days") {
  288. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  289. } else if ($_reportRef == "≥7 Days") {
  290. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  291. } else {
  292. $sqlWhere .= " and 1<>1";
  293. }
  294. } else if ($_reportType == "top") {
  295. if (!empty($_reportRef)) {
  296. $_reportStationType = $_REQUEST["_reportStationType"];
  297. if($_reportStationType == 'shippr_uncode'){
  298. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  299. }
  300. if($_reportStationType == 'fport_of_loading_un'){
  301. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  302. }
  303. if($_reportStationType == 'consignee_uncode'){
  304. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  305. }
  306. if($_reportStationType == 'mport_of_discharge_un'){
  307. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  308. }
  309. } else {
  310. $sqlWhere .= " and 1<>1";
  311. }
  312. } else if ($_reportType == "co2e") {
  313. $_reportDataType = $_REQUEST["_reportDataType"];
  314. //查询sea 其他的为空
  315. if (!empty($_reportRef) && $_reportDataType == "sea") {
  316. $_reportStationType = $_REQUEST["_reportStationType"];
  317. if($_reportStationType == 'origin'){
  318. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  319. }else{
  320. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  321. }
  322. } else {
  323. $sqlWhere .= " and 1<>1";
  324. }
  325. } else {
  326. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  327. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  328. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  329. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  330. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  331. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  332. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  333. $sqlWhere .= " and (eta-etd)>80";
  334. } else {
  335. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  336. }
  337. }
  338. }
  339. //取消全文检索
  340. // if (!empty($_POST["_textSearch"])) {
  341. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  342. // }
  343. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  344. if (!empty($_POST["_textSearch"])) {
  345. $textSearch_arr = $_POST['_textSearch'];
  346. if(!is_array($textSearch_arr)){
  347. $textSearch_arr = array($textSearch_arr);
  348. }
  349. // $more_sql = "1<>1";
  350. // foreach($textSearch_arr as $tsv){
  351. // $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  352. // $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  353. // $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  354. // $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  355. // }
  356. // if ($more_sql <> "1<>1"){
  357. // $sqlWhere .= " and ($more_sql)";
  358. // }
  359. $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
  360. // or text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))
  361. //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
  362. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
  363. or po_no ilike '%" . common::check_input($_POST["_textSearch"]) . "%'
  364. or invoice_no ilike '%" . common::check_input($_POST["_textSearch"]) . "%')";
  365. }
  366. //移除filterTag
  367. $sqlWhere_befrom_filterTag = $sqlWhere;
  368. //查询tag
  369. // IFFBCF Booking Confirmation Created
  370. // IFFCPU Cargo Pickup Cargo Received
  371. // IFFREC Cargo Arrived at Origin Cargo Received
  372. // IFFDEP Departure Departed
  373. // IFFARR Arrived at Final Destination Port Arrived
  374. // IFFAFD Arrived at Final Destination Completed (remove)
  375. // IFFDEL document turnover/delivered Completed
  376. $filterTag_param = "";
  377. if (!empty($_POST["filterTag"])) {
  378. if (utils::count($_POST['filterTag']) == 1){
  379. $filterTag = $_POST['filterTag'][0];
  380. }else{
  381. $filterTag = utils::implode(",", $_POST['filterTag']);
  382. }
  383. $_sqlwhere = "1<>1";
  384. $filterTag_param = "1<>1";
  385. if(strtolower($filterTag) == "all"){
  386. $filterTag_param = "1=1";
  387. }
  388. if (stripos($filterTag, "Created") !== FALSE) {
  389. $_sqlwhere .= " or ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  390. $filterTag_param .= " or ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  391. }
  392. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  393. $_sqlwhere .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  394. $filterTag_param .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  395. }
  396. if (stripos($filterTag, "Departure") !== FALSE) {
  397. $_sqlwhere .= "or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  398. $filterTag_param .= "or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  399. }
  400. if (stripos($filterTag, "Arrived") !== FALSE) {
  401. $_sqlwhere .= " or (m_iffarr is not null and m_iffdel is null)";
  402. $filterTag_param .= " or (m_iffarr is not null and m_iffdel is null)";
  403. }
  404. if (stripos($filterTag, "Completed") !== FALSE) {
  405. $_sqlwhere .= " or (m_iffdel is not null)";
  406. $filterTag_param .= " or (m_iffdel is not null)";
  407. }
  408. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  409. $sqlWhere .= " and ($_sqlwhere)";
  410. $filterTag_param = " ($filterTag_param)";
  411. }
  412. }
  413. if(empty($filterTag_param)){
  414. $filterTag_param = "1=1";
  415. }
  416. $rc = $_POST ['rc'];
  417. //这里都要查询,除非多传几个参数回来
  418. if ($rc == - 1 || true) {
  419. $sql = "select count(1) as rc,
  420. sum(case when $filterTag_param then 1 else 0 end) as seach_rc,
  421. sum(case when (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)
  422. then 1 else 0 end)
  423. as created,
  424. sum(case when ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)
  425. then 1 else 0 end)
  426. as cargo_received,
  427. sum(case when (m_iffdep is not null and m_iffarr is null and m_iffdel is null) then 1 else 0 end) as departed,
  428. sum(case when (m_iffarr is not null and m_iffdel is null) then 1 else 0 end) as arrived,
  429. sum(case when (m_iffdel is not null) then 1 else 0 end) as completed,
  430. string_agg(distinct incoterms, '<$>') as incoterm_str,
  431. string_agg(distinct service, '<$>') as service_str
  432. from online_ocean". $sqlWhere_befrom_filterTag;
  433. error_log("online_ocean_search_All_Status: ".$sql);
  434. $sql_all_status_data = common::excuteObjectSql($sql);
  435. $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
  436. $IncotermsList = array();
  437. foreach($incoterms as $terms){
  438. if(!empty($terms)){
  439. $IncotermsList[] = array("name"=>$terms,"checked"=>false);
  440. }
  441. }
  442. $service = explode("<$>", $sql_all_status_data['service_str']);
  443. $ServiceList = array();
  444. foreach($service as $_service){
  445. if(!empty($_service)){
  446. $ServiceList[] = array("name"=>$_service,"checked"=>false);
  447. }
  448. }
  449. $rc = $sql_all_status_data['rc'];
  450. $search_rc = $sql_all_status_data['seach_rc'];
  451. $Created = $sql_all_status_data['created'];
  452. $Cargo_Received = $sql_all_status_data['cargo_received'];
  453. $Departed = $sql_all_status_data['departed'];
  454. $Arrived = $sql_all_status_data['arrived'];
  455. $Completed = $sql_all_status_data['completed'];
  456. if (!empty($_POST["filterTag"])) {
  457. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  458. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  459. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  460. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  461. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  462. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  463. }else{
  464. //初始,前端有选择着带入选择
  465. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=> true ),
  466. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  467. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  468. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  469. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  470. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  471. }
  472. if (!isset($_POST["transport_mode"])){
  473. //代表初始
  474. $TransportList = array(
  475. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  476. }else{
  477. if (strtolower($_POST["transport_mode"]) == "all") {
  478. $TransportList = array(
  479. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
  480. } else {
  481. $TransportList = array(
  482. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  483. }
  484. }
  485. //现在下载交给前端,后台预先只返回全部字段的列,
  486. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  487. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  488. }
  489. $tp = ceil($rc / $ps);
  490. $order_by = " etd desc";
  491. if (_isCustomerLogin()) {
  492. $order_by = " eta desc";
  493. }
  494. if ($rc > 0) {
  495. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  496. FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
  497. $sql = "with oo as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  498. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  499. CASE
  500. WHEN (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  501. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  502. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  503. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  504. WHEN (m_iffdel is not null) THEN 'Completed'::text
  505. ELSE 'Created'
  506. END AS new_status, ".
  507. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere .
  508. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.")
  509. select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
  510. $tmp_search_without_limit = "with oo as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  511. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  512. CASE
  513. WHEN (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  514. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  515. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  516. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  517. WHEN (m_iffdel is not null) THEN 'Completed'::text
  518. ELSE 'Created'
  519. END AS new_status, ".
  520. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere .
  521. " order by $order_by)
  522. select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
  523. $rs = common::excuteListSql($sql);
  524. error_log("online_ocean_search_SQL: ".$sql);
  525. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  526. foreach($rs as $index => $val) {
  527. //返回加密serial_no
  528. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  529. $rs[$index]["mode"] = "Ocean Freight";
  530. //status 改为ocean_milestone里的信息
  531. $rs[$index]["Status"] = $rs[$index]["new_status"];
  532. }
  533. $arrTmp = array('searchData' => $rs,
  534. 'tagsList' => $tagsList,
  535. 'TransportList' => $TransportList,
  536. 'allColums' => $allBookingColumns,
  537. 'IncotermsList' =>$IncotermsList,
  538. 'ServiceList' =>$ServiceList,
  539. 'canEdiVgm' => _canEdiVgm(),
  540. 'rc' => $search_rc,
  541. 'ps' => $ps,
  542. 'cp' => $cp,
  543. 'tp' => $tp,
  544. 'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
  545. 'type' => common::check_input($_POST ['_ntype']));
  546. } else {
  547. $arrTmp = array('searchData' => array(),
  548. 'tagsList' => $tagsList,
  549. 'TransportList' => $TransportList,
  550. 'IncotermsList' =>$IncotermsList,
  551. 'ServiceList' =>$ServiceList,
  552. 'allColums' => $allBookingColumns,
  553. 'canEdiVgm' => _canEdiVgm(),
  554. 'rc' => $search_rc,
  555. 'ps' => $ps,
  556. 'cp' => $cp,
  557. 'tp' => $tp,
  558. 'tmp_search' => "",
  559. 'type' => common::check_input($_POST ['_ntype']));
  560. }
  561. common::echo_json_encode(200,$arrTmp);
  562. exit();
  563. }
  564. private function _ocean_detail() {
  565. $serial_no = common::deCode($_GET['a'], 'D');
  566. $sql = $this->getOceanDetail($serial_no);
  567. $ocean = common::excuteObjectSql($sql);
  568. if (!empty($ocean)) {
  569. $ocean['_isf_bol'] = $ocean['isf_bol'];
  570. if (empty($ocean['_isf_bol'])) {
  571. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  572. }
  573. $isf_ss = md5(md5($ocean['_isf_bol']));
  574. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  575. //ETA Dest的计算逻辑移除
  576. // most update status
  577. $_schemas = $_REQUEST["_schemas"];
  578. $mostStatusSql = "select last_status_loc, last_status_city, to_char(last_status_315_date, 'MM/DD/YYYY') as last_status_315_date,last_status_315_code "
  579. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  580. . "where serial_no= '" . $ocean["serial_no"] . "'";
  581. if (!empty($_schemas)) {
  582. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  583. }
  584. $mostStatus = common::excuteObjectSql($mostStatusSql);
  585. $state = -1;
  586. if (!empty($mostStatus["last_status_315_code"])) {
  587. //desc 逻辑处理取消
  588. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  589. }
  590. //请求地图是需要的参数
  591. $uncode = "'";
  592. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  593. $uncode .= $mostStatus["place_of_receipt_un"];
  594. }
  595. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  596. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  597. $uncode .= $mostStatus["place_of_delivery_un"];
  598. }
  599. $uncode .= "'";
  600. }
  601. $vueData = $this->returnOceanDetailData($ocean,$state);
  602. //处理shipment data暂时写死
  603. $simplexData = $vueData['shipmentData'];
  604. //处理transportInfo信息数据
  605. $transportInfo = $vueData['transportInfo'];
  606. //处理basicInfo信息数据
  607. $basicInfo = $vueData['basicInfo'];
  608. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  609. $businessPartners = $vueData['businessPartners'];
  610. //处理routes 转船可能有多个情况
  611. $routes = $vueData['routes'];
  612. //处理marksAndDescription
  613. $marksAndDescription = $vueData['marksAndDescription'];
  614. //处理containerStatusData
  615. $containerStatusData = $vueData['containerStatusData'];
  616. //处理ocean_reference
  617. $ref_no = array();
  618. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  619. if(!empty($ref_arr)){
  620. foreach($ref_arr as $ref) {
  621. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  622. }
  623. }
  624. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  625. $ocean_container_column = array();
  626. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  627. foreach($container_column as $cc){
  628. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  629. }
  630. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",net_lbs from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  631. $rss = common::excuteListSql($sql);
  632. $quantity_unit = array();
  633. $g_weight_tolal = 0;
  634. $ch_weight_tolal = 0;
  635. $ch_weight_tolal_grs_lbs = 0;
  636. $cbm_tolal = 0;
  637. foreach ($rss as $key => $rs) {
  638. $unit = $rs['unit'];
  639. if (array_key_exists($unit, $quantity_unit)) {
  640. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  641. } else {
  642. $quantity_unit[$unit] = $rs['qty'];
  643. }
  644. $g_weight_tolal += $rs['grs_kgs'];
  645. $ch_weight_tolal += $rs['net_lbs'];
  646. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  647. $cbm_tolal += $rs['cbm'];
  648. //特殊处理weight
  649. if(!empty($rss[$key]['grs_kgs'])){
  650. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KGS";
  651. }
  652. if(!empty($rss[$key]['grs_lbs'])){
  653. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LBS";
  654. }
  655. }
  656. $quantity_tolal = "";
  657. foreach($quantity_unit as $uk => $uv){
  658. // 使用substr()截取第一次出现之前的字符串
  659. $uk = substr($uk, 0, strpos($uk, "-"));
  660. $quantity_tolal.=$uv." ".$uk." ";
  661. }
  662. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  663. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  664. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  665. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  666. //Containers信息
  667. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  668. //Packing信息
  669. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  670. //Milestones info 列名固定
  671. $Milestones = common::getMilestonesInfo($ocean,$vueData['EDI315TimeAndLocation']);
  672. //页面固定写死的信息
  673. $document_column = array();
  674. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  675. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  676. $document_data = array();
  677. $document = _getViewDocType($_REQUEST["_schemas"]);
  678. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  679. $ocean_can_view_file = common::excuteOneSql("select ocean_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
  680. if (!empty($document)) {
  681. foreach ($document as $v) {
  682. $file_type = $v['display_name'];
  683. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  684. $tar = json_decode($ocean_can_view_file,true);
  685. if(!empty($tar[$v['display_name']])){
  686. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  687. switch ($v['display_name']) {
  688. case 'HBL':
  689. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  690. from ra_online_doc_upload
  691. where lower(bol) = lower('".$ocean['_h_bol']."') and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  692. order by id desc";
  693. break;
  694. case 'MBL':
  695. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  696. from ra_online_doc_upload
  697. where ( lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  698. order by id desc";
  699. break;
  700. case 'Others':
  701. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  702. from ra_online_doc_upload
  703. where (lower(bol) = lower('".strtolower($ocean['_h_bol'])."') or lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  704. order by id desc";
  705. break;
  706. default:
  707. $sql = "";
  708. break;
  709. }
  710. if (!empty($sql)) {
  711. $rss = common::excuteListSql($sql);
  712. foreach ($rss as $rs) {
  713. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  714. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  715. "file_name" => $rs['file_name'],
  716. "detail"=>$rs['upload_date'],
  717. "can_delete"=>_getLoginName() == $rs['upload_by'],
  718. "from_system" =>'TOPOCEAN_KSMART');
  719. }else{
  720. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  721. "file_name" => $rs['file_name'],
  722. "detail"=>$rs['upload_date'],
  723. "can_delete"=>_getLoginName() == $rs['upload_by'],
  724. "from_system" =>'');
  725. }
  726. }
  727. }
  728. }
  729. }
  730. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  731. //按现在的逻辑,有值才会显示
  732. foreach($file_arr as $f){
  733. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  734. }
  735. }
  736. }
  737. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  738. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  739. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  740. $email = $this->getEmail($ocean["serial_no"]);
  741. $email['cc_email'] = $cc_email;
  742. $email['emailRecords'] = $emailRecords;
  743. global $_COPYRIGHT;
  744. $data = array('transportInfo' => $transportInfo,
  745. 'basicInfo' => $basicInfo,
  746. 'businessPartners' => $businessPartners,
  747. 'ref_no' => $ref_no,
  748. 'packing' => $packing,
  749. 'marksAndDescription' => $marksAndDescription,
  750. 'containers' => $containers,
  751. 'simplexData' =>$simplexData,
  752. 'containerStatusData' => $containerStatusData,
  753. 'document_info' => $document_info,
  754. 'containers' => $containers,
  755. 'Milestones' => $Milestones,
  756. 'routes' => $routes,
  757. 'email' => $email,
  758. 'ams_ss' => md5(md5($ocean['serial_no'])),
  759. 'isf_ss' => $isf_ss,
  760. '_schemas' =>$_schemas,
  761. 'uncode' =>$uncode,
  762. 'serial_no' =>$serial_no,
  763. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  764. 'canEdiVgm' => _canEdiVgm(),
  765. 'canViewAMSLog'=>_canViewAMSLog(),
  766. 'canViewISFLog'=>_canViewISFLog(),
  767. 'copyright' =>$_COPYRIGHT);
  768. common::echo_json_encode(200,$data);
  769. exit();
  770. }
  771. private function _ocean_excel() {
  772. $sql = common::deCode($_POST ['tmp_search'], 'D');
  773. //$sql = substr($sql, 0, strripos($sql, " limit"));
  774. if(!empty($sql)){
  775. $rs = common::excuteListSql($sql);
  776. }
  777. //去除null
  778. foreach($rs as $index => $val) {
  779. foreach($val as $index_2 => $_val) {
  780. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  781. $rs[$index][$index_2] = "";
  782. }
  783. }
  784. }
  785. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  786. foreach($rs as $index => $val) {
  787. //返回加密serial_no
  788. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  789. $rs[$index]["mode"] = "Ocean Freight";
  790. //status 改为ocean_milestone里的信息
  791. $rs[$index]["Status"] = $rs[$index]["new_status"];
  792. }
  793. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  794. exit;
  795. }
  796. private function _revenue_download(){
  797. $r2_cloumn = array();
  798. $r2_cloumn[] = array("title" => "Month","dataIndex"=>"month");
  799. $r2_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  800. $r2_cloumn[] = array("title" => "Total Amount","dataIndex"=>"invoice_amount");
  801. $r3_cloumn = array();
  802. $r3_cloumn[] = array("title" => "Invoice Issue Date","dataIndex"=>"invoice_date");
  803. $r3_cloumn[] = array("title" => "Invoice Number","dataIndex"=>"invoice_no");
  804. $r3_cloumn[] = array("title" => "HBL Number","dataIndex"=>"h_bol");
  805. $r3_cloumn[] = array("title" => "Amount","dataIndex"=>"ivnoice_amount");
  806. $r3_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  807. $date_from = null;
  808. $date_to = null;
  809. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  810. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  811. $date_from = $date_start."-01";
  812. }
  813. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  814. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  815. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  816. }
  817. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  818. //$sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  819. //$sql = "select * from _test_data_table";
  820. //$r2_data = common::excuteListSql($sql);
  821. //只取r3 代码去计总r2 ,避免二次请求数据库
  822. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r3;";
  823. //$sql = "select * from _test_data_table_two";
  824. $r3_data = common::excuteListSql($sql);
  825. $group_data = array();
  826. foreach($r3_data as $r3){
  827. $r3['invoice_date'] = strtoupper(date('M,Y', strtotime($r3['invoice_date'])));
  828. $group_data[] = $r3;
  829. }
  830. //按货币和日期分组
  831. $groupedItems = array();
  832. foreach ($group_data as $item) {
  833. $key = $item['currency']."_".$item['invoice_date'];
  834. if(array_key_exists($key, $groupedItems)){
  835. $temp = $groupedItems[$key];
  836. $temp['invoice_amount'] = $temp['invoice_amount'] + $item['ivnoice_amount'];
  837. $groupedItems[$key] = $temp;
  838. }else{
  839. $groupedItems[$key] = array("month"=>$item['invoice_date'],"currency"=>$item['currency'],"invoice_amount"=>$item['ivnoice_amount']);
  840. }
  841. }
  842. $r2_data = array();
  843. foreach($groupedItems as $gt){
  844. $gt['invoice_amount'] = number_format($gt['invoice_amount'], 4, '.', '');
  845. $r2_data[] = $gt;
  846. }
  847. common::echo_json_encode(200,array("msg"=>"success","r2" => $r2_data,"r3"=>$r3_data,"r2_cloumn" => $r2_cloumn,"r3_cloumn" => $r3_cloumn,
  848. "r2_title"=>"Monthly Summary Data","r3_title"=>"Invoice Detailed Data"));
  849. exit;
  850. }
  851. private function _ams_isf_log(){
  852. global $cbpdb;
  853. $ams_ss = $_POST['ams_ss'];
  854. $isf_ss = $_POST['isf_ss'];
  855. $amsLog = array();
  856. //页面固定写死的信息
  857. $amsLog_column = array();
  858. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  859. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  860. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  861. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  862. $amsLog["amsLog_column"] = $amsLog_column;
  863. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  864. $amsLog["data"] = array();
  865. if (_canViewAMSLog()) {
  866. $s = $ams_ss;
  867. //$s = "PDLA200127H";
  868. if (!empty($s)) {
  869. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  870. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  871. foreach ($cc as $v){
  872. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  873. }
  874. //考虑一个情况
  875. if (utils::count($amses) > 0) {
  876. $ams = $amses[0];
  877. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  878. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  879. if (empty($ams[0]['h_bol'])){
  880. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  881. $amsLog["data"] = array();
  882. }else{
  883. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  884. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  885. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  886. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  887. $amsLog["msg"] = "";
  888. $amsLog["data"] = $log;
  889. }
  890. }
  891. }
  892. }
  893. $isfLog = array();
  894. //页面固定写死的信息
  895. $isfLog_column = array();
  896. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  897. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  898. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  899. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  900. $isfLog["isfLog_column"] = $isfLog_column;
  901. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  902. $isfLog["data"] = array();
  903. if (_canViewISFLog()) {
  904. if (!empty($isf_ss)) {
  905. $ss = $isf_ss;
  906. $len = strlen($ss);
  907. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  908. if (empty($b)){
  909. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  910. $isfLog["data"] = array();
  911. }else{
  912. $isf = $cbpdb->GetRow("select * from ocean_isf where md5(md5(bol)) = '" . pg_escape_string($b) . "' or md5(md5(substr(bol, 5))) = '" . pg_escape_string($b) . "' order by id desc limit 1");
  913. }
  914. if (!empty($isf)) {
  915. if (!empty($isf['dob'])){
  916. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  917. }
  918. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  919. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  920. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  921. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  922. order by cbpreplytime desc, rowid desc");
  923. $isfLog["msg"] = "";
  924. $isfLog["data"] = $msg;
  925. }else{
  926. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  927. $isfLog["data"] = array();
  928. }
  929. }
  930. }
  931. $data =array("msg"=>"success",
  932. "canViewAMSLog" => _canViewAMSLog(),
  933. "canViewISFLog" => _canViewISFLog(),
  934. "amsLog" =>$amsLog,
  935. "isfLog" =>$isfLog);
  936. common::echo_json_encode(200,$data);
  937. exit;
  938. }
  939. private function getEmail($serial_no) {
  940. return utils::getEmail($serial_no);
  941. }
  942. private function getCommunicationNew($serial_no) {
  943. $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");
  944. $emialRecords =array();
  945. foreach ($list as $k => $v) {
  946. $msg =array();
  947. $msg["name"] = $v["add_by"];
  948. $msg["creatTime"] = $v["add_times"];
  949. $msg["content"] = urldecode($v["web_content"]);
  950. $emialRecords[] = $msg;
  951. }
  952. return $emialRecords;
  953. }
  954. /*
  955. * get file by hbol/destination
  956. * H:HBL
  957. * M: MBL
  958. * F: FL
  959. * I: C/I & Packing list
  960. */
  961. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  962. $types = strtolower($types);
  963. $types = explode(";", $types);
  964. $m_bs = explode(";", $m_bs);
  965. $otheres = NULL;
  966. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  967. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  968. $file = array();
  969. foreach ($types as $k => $type) {
  970. $m_b = $m_bs[$k];
  971. if (strtolower($m_b) == 'm')
  972. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) ='".strtolower($job_no)."' ) and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  973. if (strtolower($m_b) == 'h')
  974. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where lower(bol) = '" . strtolower($h_bol) . "' and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  975. if (strtolower($m_b) == 'a')
  976. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) = '" . strtolower($h_bol) . "' or lower(bol) ='".strtolower($job_no)."') and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  977. if (!empty($sql)) {
  978. $rss = common::excuteListSql($sql);
  979. foreach ($rss as $rs) {
  980. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  981. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  982. "file_name" => $rs['file_name'],
  983. "detail"=>$rs['upload_date'],
  984. "can_delete"=>_getLoginName() == $rs['upload_by'],
  985. "from_system" =>'TOPOCEAN_KSMART');
  986. }else {
  987. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  988. "file_name" => $rs['file_name'],
  989. "detail"=>$rs['upload_date'],
  990. "can_delete"=>_getLoginName() == $rs['upload_by'],
  991. "from_system" =>'');
  992. }
  993. }
  994. }
  995. }
  996. return $file;
  997. }
  998. /*
  999. * download file
  1000. */
  1001. private function _download() {
  1002. $url = common::deCode($_GET['url'], 'D');
  1003. common::download_file($url);
  1004. }
  1005. private function save_vgm() {
  1006. $schemas = $_POST["schemas"];
  1007. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1008. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1009. $contact = common::excuteObjectSql("select company, city, state, zipcode, phone_1, fax, email_1, contactname_1, address_1, address_2, address_3, address_4 from ocean.contacts where contact_id='" . $ocean["from_station"] . "'");
  1010. $address = $contact["address_1"];
  1011. if (!empty($address)) {
  1012. $address .= "\r\n";
  1013. }
  1014. $address .= $contact["address_2"];
  1015. if (!empty($address)) {
  1016. $address .= "\r\n";
  1017. }
  1018. $address .= $contact["address_3"];
  1019. if (!empty($address)) {
  1020. $address .= "\r\n";
  1021. }
  1022. $address .= $contact["address_4"];
  1023. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1024. global $db;
  1025. $db->StartTrans();
  1026. if (empty($_POST["is_send"])) {
  1027. $_POST["is_send"] = 'f';
  1028. }
  1029. if (empty($exists)) {
  1030. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1031. $value["serial_no"] = $serial_no;
  1032. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1033. $value["modify_user"] = _getLoginName();
  1034. $value["modify_time"] = "now()";
  1035. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1036. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1037. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1038. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1039. $value["is_send"] = $_POST["is_send"];
  1040. $value["action"] = "New";
  1041. $value["type"] = "Shipper";
  1042. $value["m_bol"] = $ocean["m_bol"];
  1043. $value["master_base_number"] = $ocean["master_base_number"];
  1044. $value["shipper_id"] = $ocean["from_station"];
  1045. $value["shipper"] = $contact["company"];
  1046. $value["shipper_address"] = $address;
  1047. $value["shipper_contactname"] = $contact["contactname_1"];
  1048. $value["shipper_email"] = $contact["email_1"];
  1049. $value["shipper_fax"] = $contact["fax"];
  1050. $value["shipper_telephone"] = $contact["phone_1"];
  1051. $value["update_uuid"] = utils::uuid();
  1052. $value["h_bol"] = $ocean["h_bol"];
  1053. $value["from_station"] = $ocean["from_station"];
  1054. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1055. $db->Execute($sql);
  1056. } else {
  1057. $serial_no = $exists;
  1058. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1059. $db->Execute("update $schemas.ocean_vgm set is_send='" . $_POST["is_send"] . "', carrier_booking_no='" . $_POST["all_carrier_booking"] . "', modify_user='" . _getLoginName() . "', modify_time=now(),"
  1060. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1061. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1062. }
  1063. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1064. foreach ($_POST["container_no"] as $i => $cv) {
  1065. $value1["serial_no"] = $serial_no;
  1066. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1067. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1068. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1069. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1070. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1071. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1072. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1073. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1074. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1075. $value1["master_base_number"] = $ocean["master_base_number"];
  1076. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1077. $db->Execute($sql);
  1078. }
  1079. if ($db->CompleteTrans() === FALSE) {
  1080. return "error";
  1081. } else {
  1082. return "success";
  1083. }
  1084. }
  1085. private function getOceanDetail($serial_no) {
  1086. $_schemas = $_REQUEST['_schemas'];
  1087. if($_schemas == 'public'){
  1088. $_schemas = "ocean";
  1089. }
  1090. $sql = "with o as(
  1091. SELECT o.* from ocean o where serial_no = '" . $serial_no . "'
  1092. )
  1093. SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1094. o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
  1095. (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un
  1096. from o
  1097. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  1098. consignee_uncode,consignee_city,incoterms,
  1099. fport_of_loading_un,
  1100. mport_of_discharge_un,
  1101. place_of_receipt_un,
  1102. place_of_delivery_un,
  1103. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1104. (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  1105. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1106. (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1107. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1108. (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  1109. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1110. (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  1111. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1112. (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  1113. po_no as _po_no,
  1114. CASE
  1115. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  1116. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  1117. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1118. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1119. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1120. ELSE 'Created'::text
  1121. END AS new_status
  1122. FROM public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
  1123. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1124. address_1 as cn_address_1,
  1125. address_2 as cn_address_2,
  1126. address_3 as cn_address_3,
  1127. address_4 as cn_address_4,
  1128. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1129. phone_1 as cn_phone
  1130. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1131. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1132. address_1 as sh_address_1,
  1133. address_2 as sh_address_2,
  1134. address_3 as sh_address_3,
  1135. address_4 as sh_address_4,
  1136. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1137. phone_1 as sh_phone
  1138. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1139. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1140. address_1 as aa_address_1,
  1141. address_2 as aa_address_2,
  1142. address_3 as aa_address_3,
  1143. address_4 as aa_address_4,
  1144. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1145. phone_1 as aa_phone,
  1146. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1147. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1148. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1149. address_1 as dd_address_1,
  1150. address_2 as dd_address_2,
  1151. address_3 as dd_address_3,
  1152. address_4 as dd_address_4,
  1153. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1154. phone_1 as dd_phone,
  1155. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1156. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1157. LEFT JOIN LATERAL ( SELECT
  1158. city as fd_city,
  1159. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1160. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1161. //error_log($sql);
  1162. return $sql;
  1163. }
  1164. private function returnOceanDetailData($ocean,$state){
  1165. $data = array();
  1166. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  1167. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  1168. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  1169. $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
  1170. $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
  1171. /* Container Status */
  1172. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1173. //记录所有的信息 EDI315TimeAndLocation
  1174. $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
  1175. $data['containerStatusData'] = $EDIDate['containerStatusData'];
  1176. $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
  1177. $VD = $EDIDate['VD'];
  1178. $VA = $EDIDate['VA'];
  1179. //处理shipment data
  1180. $ocean_milestone_status = common::excuteListSql("select code,
  1181. act_date,est_date,timezone
  1182. from ocean_milestone a
  1183. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1184. order by id");
  1185. $ocean_milestone_status_code = array();
  1186. foreach($ocean_milestone_status as $oms){
  1187. $ocean_milestone_status_code[$oms['code']] = $oms;
  1188. }
  1189. if ($state < 1){
  1190. //未发生前
  1191. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1192. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1193. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  1194. }
  1195. } else{
  1196. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  1197. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1198. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  1199. }
  1200. }
  1201. //先处理一下 ATD 和 ATA,在进行后面的取值
  1202. if(empty($ocean['atd']) && !empty($VD)){
  1203. $ocean['atd'] = $VD;
  1204. }
  1205. if(empty($ocean['ata']) && !empty($VA)){
  1206. $ocean['ata'] = $VA;
  1207. }
  1208. $simplexData = array();
  1209. //place_of_Receipt
  1210. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1211. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  1212. $children = array();
  1213. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1214. //发生后,未发生前没有
  1215. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1216. }
  1217. $place_of_Receipt_stauts["children"] = $children;
  1218. $simplexData[] = $place_of_Receipt_stauts;
  1219. //port_of_Loading
  1220. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  1221. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  1222. $children = array();
  1223. if ($state < 1){
  1224. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  1225. } else{
  1226. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1227. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  1228. }
  1229. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  1230. }
  1231. $port_of_Loading_stauts["children"] = $children;
  1232. $simplexData[] = $port_of_Loading_stauts;
  1233. //Port of Discharge
  1234. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  1235. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  1236. $children = array();
  1237. // if ($state < 2){
  1238. // //未发生前
  1239. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  1240. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  1241. // }else{
  1242. // //没有,取eta
  1243. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1244. // }
  1245. // } else{
  1246. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  1247. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  1248. // }
  1249. // }
  1250. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  1251. if ($state < 2){
  1252. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1253. }else{
  1254. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  1255. }
  1256. $port_of_Discharge_status["children"] = $children;
  1257. $simplexData[] = $port_of_Discharge_status;
  1258. //Place of Delivery
  1259. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  1260. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  1261. $children = array();
  1262. if ($state < 3){
  1263. //未发生前
  1264. } else{
  1265. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  1266. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  1267. }
  1268. }
  1269. $simplexData[] = $place_of_Delivery_status;
  1270. $data['shipmentData'] = $simplexData;
  1271. //处理transportInfo信息数据
  1272. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  1273. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  1274. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  1275. "etd_timezone" =>$ocean['pol_timezone'],
  1276. "atd_timezone" =>$ocean['pol_timezone'],
  1277. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1278. "eta_timezone" =>$ocean['mpod_timezone'],
  1279. "ata_timezone" =>$ocean['mpod_timezone']);
  1280. $data['transportInfo'] = $transportInfo;
  1281. //处理basicInfo信息数据
  1282. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  1283. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  1284. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  1285. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1286. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  1287. $data['basicInfo'] = $basicInfo;
  1288. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1289. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1290. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1291. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1292. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1293. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1294. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1295. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1296. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1297. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1298. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1299. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1300. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1301. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1302. $data['businessPartners'] = $businessPartners;
  1303. //处理routes 转船可能有多个情况
  1304. if ($ocean['is_vessel_direct'] <> "t"){
  1305. //不是直航
  1306. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1307. "destination" => $ocean['port_of_transshipment_un'],
  1308. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1309. "eta" =>$ocean['f_eta'],"ata" =>"",
  1310. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1311. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  1312. "destination" => $ocean['consignee_uncode'],
  1313. "etd" => $ocean['m_etd'],"atd" => "",
  1314. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1315. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  1316. }else{
  1317. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1318. "destination" => $ocean['consignee_uncode'],
  1319. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1320. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  1321. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1322. }
  1323. $data['routes'] = $routes;
  1324. //处理marksAndDescription
  1325. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  1326. $data['marksAndDescription'] = $marksAndDescription;
  1327. return $data;
  1328. }
  1329. }
  1330. ?>