ocean_order.class.php 152 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  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. $serial_no = common::deCode($_GET['a'], 'D');
  41. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ob WHERE ob.serial_no = '$serial_no'");
  42. if ($transport_mode == "sea"){
  43. $this->_ocean_detail();
  44. } elseif ($transport_mode == "air"){
  45. $this->_air_ocean_detail();
  46. } else {
  47. $this->_ocean_detail();
  48. }
  49. }
  50. if ($operate == "ams_isf_log"){
  51. $this->_ams_isf_log();
  52. }
  53. /*
  54. * export ocean order to excel
  55. */
  56. if ($operate == "excel") {
  57. $this->_ocean_excel();
  58. }
  59. /*
  60. * download Revenue
  61. */
  62. if ($operate == "revenue") {
  63. $this->_revenue_download();
  64. }
  65. if ($operate == 'setting_ocean_order_display') {
  66. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  67. }
  68. /*
  69. * download document
  70. */
  71. if ($operate == "download") {
  72. $this->_download();
  73. }
  74. /*
  75. * document upload
  76. */
  77. if ($operate == "document_upload"){
  78. //只查询public,两边数据一样,不用去同步更新新加的Client_Upload ,Notify Station,Auto-sync to Station
  79. $transport_mode = $_POST['transport_mode'];
  80. if($transport_mode == 'sea'){
  81. $document = _getViewDocType($_REQUEST["_schemas"]);
  82. }else{
  83. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  84. }
  85. $file_serial_nos = array();
  86. foreach ($document as $v) {
  87. $types = $v['serial_no'];
  88. $types = strtolower($types);
  89. $types = explode(";", $types);
  90. foreach ($types as $k => $type) {
  91. $file_serial_nos[] = $type;
  92. }
  93. }
  94. $file_serial_nos = utils::implode(';',$file_serial_nos);
  95. if($transport_mode == 'sea'){
  96. $sql = "select display_name,format_name as file_type,serial_no,m_h from public.ra_online_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . "
  97. and active = true and client_upload = true";
  98. }else{
  99. $sql = "select display_name,format_name as file_type,serial_no,m_h from public.air_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . "
  100. and active = true and client_upload = true";
  101. }
  102. $display_name = common::excuteListSql($sql);
  103. $data['File Type'] = $display_name;
  104. common::echo_json_encode(200,$data);
  105. exit();
  106. }
  107. /*
  108. * document upload do
  109. */
  110. if ($operate == "document_upload_do"){
  111. //checked from
  112. if(empty($_POST['file_type']) || empty($_FILES['file']["name"])){
  113. $data = array(
  114. 'msg' => 'File Type or File must select.'
  115. );
  116. common::echo_json_encode(500,$data);
  117. exit();
  118. }
  119. $_schemas = $_REQUEST["_schemas"];
  120. $transport_mode = $_POST['transport_mode'];
  121. $bol = $_POST['h_bol'];
  122. if ($transport_mode == "sea") {
  123. $count = common::excuteObjectSql("select * from ocean where lower(h_bol) = '" . strtolower($bol) . "'");
  124. } elseif ($transport_mode == "air") {
  125. $count = common::excuteObjectSql("select * from air where lower(hawb) = '" . strtolower($bol) . "'");
  126. }
  127. if (empty($count) || utils::count($count) <= 0){
  128. $data = array(
  129. 'msg' => 'HBOL does not exist.'
  130. );
  131. common::echo_json_encode(500,$data);
  132. exit();
  133. }
  134. $file_type = $_POST['file_type'];
  135. $_table = $transport_mode == "sea" ? "ra_online_doc_upload" : "air_doc_upload";
  136. $_table_format = $transport_mode == "sea" ? "ra_online_file_format" : "air_file_format";
  137. //格式配置只查询public
  138. $format = common::excuteObjectSql("select serial_no,standard,client_upload,notify_station,auto_sync_to_station from public.$_table_format where format_name = '$file_type'");
  139. //查询存在的文件类型最大序号
  140. $num = common::excuteOneSql("select count(*) from $_table where lower(bol) = '" . strtolower($bol) . "' and format_serailno = '".$format['serial_no']."'");
  141. try {
  142. //$allow_extend = "|.pdf|.xlsx|.docx|";
  143. $allow_extend = "|.pdf|";
  144. $file_name = $_FILES['file']["name"];
  145. $errorMsg = "";
  146. $sql = "";
  147. foreach ($file_name as $i => $v) {
  148. if (empty($v)) {
  149. continue;
  150. }
  151. $size = floor($_FILES ["file"]['size'][$i] / 1024 / 1024);
  152. if ($size > 5) {
  153. $errorMsg = $_FILES['file']["name"][$i] ." is larger than 5M.";
  154. continue;
  155. }
  156. if ($_FILES["file"]["error"][$i] > 0) {
  157. $errorMsg = " File Upload Error(". $_FILES ["file"]["error"][$i] .")";
  158. continue;
  159. }
  160. $path_parts = pathinfo($file_name[$i]);
  161. $exten = $path_parts['extension'];
  162. if (stristr($allow_extend, "|." . $exten . "|") === FALSE) {
  163. $errorMsg = $_FILES['file']["name"][$i].', File type error.';
  164. //continue;
  165. }
  166. $filename = $bol."_".$format['standard']."_V".($i+1+$num). "." . $exten;
  167. $file_size = floor($_FILES ["file"]['size'][$i] / 1024) . "KB";
  168. $order_type = $transport_mode == "sea" ? "ocean" : "air";
  169. $origin_station = $count["origin_station"];
  170. $destination_station = $count["destination_station"];
  171. $format_serialno = $format['serial_no'];
  172. $serial_no = utils::uuid();
  173. $from_station = $count["from_station"];
  174. if (strtolower($_schemas) == "public") {
  175. if ($transport_mode == "sea")
  176. $folder = DOCUMENT_OCEAN_UPLOAD_PATH . $from_station;
  177. elseif ($transport_mode == "air")
  178. $folder = DOCUMENT_AIR_UPLOAD_PATH . $from_station;
  179. }else {
  180. if ($transport_mode == "sea")
  181. $folder = DOCUMENT_SFSOCEAN_UPLOAD_PATH . $from_station;
  182. elseif ($transport_mode == "air")
  183. $folder = DOCUMENT_SFSAIR_UPLOAD_PATH . $from_station;
  184. }
  185. $save_path = $folder . DS . date("Ymd") . DS;
  186. if (common::mkdirs($save_path) === FALSE){
  187. $errorMsg = "Save Folder create error.";
  188. continue;
  189. }
  190. //pdf文件不需要处理宏,直接保存
  191. if($exten == "pdf"){
  192. if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $save_path . $filename)) {
  193. $sql .= "insert into $_schemas.$_table (file_name, file_path, upload_date, upload_ip, upload_by, bol, file_type, file_size, online_upload,
  194. origin, destination, from_station, serial_no,
  195. online_format,format_serailno,source_filename)
  196. values ('" . common::check_input($filename) . "','" . common::check_input($save_path) . "', now(), '" . common::ip() . "',
  197. '" . common::check_input(_getLoginName()) . "','" . common::check_input(strtoupper($bol)) . "', '$order_type', '" . common::check_input($file_size) . "',
  198. 't', '" . common::check_input($origin_station) . "', '" .common::check_input($destination_station) . "',
  199. '" . common::check_input($from_station) . "', '" . $serial_no . "',
  200. '" . common::check_input($file_type) . "','" . common::check_input($format_serialno) . "','" . common::check_input($filename) . "');";
  201. } else {
  202. $errorMsg = "Upload Filed Failed.";
  203. continue;
  204. }
  205. } else {
  206. $outputFileName = $save_path . $filename;
  207. if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$outputFileName)){
  208. //判断文件时候待宏,如果则这删除
  209. if(utils::hasMacros($outputFileName)){
  210. unlink($outputFileName);
  211. $errorMsg = "Upload Filed Has Macros,Please remove and re-upload.";
  212. continue;
  213. }
  214. $sql .= "insert into $_schemas.$_table (file_name, file_path, upload_date, upload_ip, upload_by, bol, file_type, file_size, online_upload,
  215. origin, destination, from_station, serial_no,
  216. online_format,format_serailno,source_filename)
  217. values ('" . common::check_input($filename) . "','" . common::check_input($save_path) . "', now(), '" . common::ip() . "',
  218. '" . common::check_input(_getLoginName()) . "','" . common::check_input(strtoupper($bol)) . "', '$order_type', '" . common::check_input($file_size) . "',
  219. 't', '" . common::check_input($origin_station) . "', '" .common::check_input($destination_station) . "',
  220. '" . common::check_input($from_station) . "', '" . $serial_no . "',
  221. '" . common::check_input($file_type) . "','" . common::check_input($format_serialno) . "','" . common::check_input($filename) . "');";
  222. } else {
  223. $errorMsg = "Upload Filed Failed.";
  224. continue;
  225. }
  226. }
  227. //根据配置,看需要同步文件,
  228. $doc_upload_log_table = $transport_mode == "sea" ? "ra_online_doc_upload_log" : "air_doc_upload_log";
  229. if(!empty($format['auto_sync_to_station'])){
  230. if($format['auto_sync_to_station'] == "Origin Station"){
  231. $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
  232. VALUES ('".$serial_no."', '" .common::check_input($destination_station) . "', now());";
  233. }
  234. if($format['auto_sync_to_station'] == "Destination Station"){
  235. $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
  236. VALUES ('".$serial_no."', '" .common::check_input($origin_station) . "', now());";
  237. }
  238. if($format['auto_sync_to_station'] == "Origin and Destination Stations"){
  239. //这个都同步,不需要手动补充记录去阻止文件的同步
  240. }
  241. } else {
  242. //如果没有配置。这代表不同步文件
  243. $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
  244. VALUES ('".$serial_no."', '" .common::check_input($destination_station) . "', now());";
  245. $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
  246. VALUES ('".$serial_no."', '" .common::check_input($origin_station) . "', now());";
  247. }
  248. }
  249. //根据配置发送通知邮件 相同文件类型只提醒一次
  250. if(!empty($format['notify_station']) && empty($errorMsg)){
  251. $origin_op_email = common::excuteOneSql("select email from employee where employee_id = '".$count["origin_op_id"]."' limit 1");
  252. $dest_op_email = common::excuteOneSql("select email from employee where employee_id = '".$count["dest_op"]."' limit 1");
  253. $ks_from = common::excuteOneSql("select ksmart_station from public.contract_region_mapping where overeas = '".$count["from_station"]."' limit 1");
  254. $ks_to = common::excuteOneSql("select ksmart_station from public.contract_region_mapping where overeas = '".$count["destination_station"]."' limit 1");
  255. $ks_from = empty($ks_from)? 'f' : $ks_from;
  256. $ks_to = empty($ks_to)? 'f' : $ks_to;
  257. if($ks_from == "f" && $ks_to == "f"){
  258. $errorMsg = "Both Non Ksmart,Please checked.";
  259. }
  260. $curr_date_config = common::excuteObjectSql("SELECT to_char(now()::date,'Mon_DD_YYYY') as d1_day,to_char(now()::date,'Mon_DD_YYYY HH:MM') as d2_day");
  261. $subject = "External Documentation Upload Notification"."_".$curr_date_config['d1_day'];
  262. $email_from = "US.KApex.Online@kerryapex.com";
  263. $upload_user_name = _getLoginName();
  264. $upload_user_email = _getLoginEamil();
  265. //如果有多個就留空,給Email信息就行
  266. if ($transport_mode == "sea") {
  267. $company =utils::getConpanyForNotify($_schemas,'ocean');
  268. }else{
  269. $company =utils::getConpanyForNotify($_schemas,'air');
  270. }
  271. //Ksmart--> Ksmart
  272. if ($ks_from == "t" && $ks_to == "t"){
  273. if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
  274. if(!empty($origin_op_email)){
  275. //立即发送
  276. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  277. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  278. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  279. pg_escape_string($origin_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  280. }else{
  281. //加入队列状态
  282. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  283. is_send, checked_time, checked_type,origin_op,dest_op)
  284. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  285. false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  286. //做好加入队列时的日志记录
  287. $user_type = _isApexLogin() ? "Employee" : "Customer";
  288. $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";
  289. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  290. }
  291. }
  292. if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
  293. if(!empty($dest_op_email)){
  294. //立即发送
  295. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  296. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  297. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  298. pg_escape_string($dest_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  299. }else{
  300. //加入队列状态
  301. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  302. is_send, checked_time, checked_type,origin_op,dest_op)
  303. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  304. false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  305. //做好加入队列时的日志记录
  306. $user_type = _isApexLogin() ? "Employee" : "Customer";
  307. $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";
  308. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  309. }
  310. }
  311. }
  312. //Ksmart-->non Ksmart
  313. if ($ks_from == "t" && $ks_to == "f"){
  314. if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
  315. //避免重复邮件发给origin_op, dest_op信息缺失的话,会发送给origin_op
  316. $dest_op_email_temp = empty($dest_op_email)? $origin_op_email:$dest_op_email;
  317. if(!empty($dest_op_email_temp)){
  318. //立即发送
  319. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  320. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  321. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  322. pg_escape_string($dest_op_email_temp) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  323. }else{
  324. //加入队列状态 如果缺失,用origin_op_email
  325. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  326. is_send, checked_time, checked_type,origin_op,dest_op)
  327. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  328. false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  329. //做好加入队列时的日志记录
  330. $user_type = _isApexLogin() ? "Employee" : "Customer";
  331. $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";
  332. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  333. }
  334. }
  335. if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
  336. if(empty($dest_op_email) && $format['notify_station'] == "Origin and Destination Stations"){
  337. }else{
  338. if(!empty($origin_op_email)){
  339. //立即发送
  340. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  341. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  342. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  343. pg_escape_string($origin_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  344. }else{
  345. //加入队列状态
  346. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  347. is_send, checked_time, checked_type,origin_op,dest_op)
  348. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  349. false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  350. //做好加入队列时的日志记录
  351. $user_type = _isApexLogin() ? "Employee" : "Customer";
  352. $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";
  353. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  354. }
  355. }
  356. }
  357. }
  358. //Non Ksmart-->Ksmart
  359. if ($ks_from == "f" && $ks_to == "t"){
  360. if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
  361. $origin_op_email_temp = empty($origin_op_email)? $dest_op_email:$origin_op_email;
  362. if(!empty($origin_op_email_temp)){
  363. //立即发送
  364. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  365. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  366. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  367. pg_escape_string($origin_op_email_temp) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  368. }else{
  369. //加入队列状态
  370. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  371. is_send, checked_time, checked_type,origin_op,dest_op)
  372. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  373. false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  374. //做好加入队列时的日志记录
  375. $user_type = _isApexLogin() ? "Employee" : "Customer";
  376. $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";
  377. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  378. }
  379. }
  380. if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
  381. //避免重复邮件发给dest_op, origin_op信息缺失的话,会发送给dest_op
  382. if(empty($origin_op_email) && $format['notify_station'] == "Origin and Destination Stations"){
  383. }else{
  384. if(!empty($dest_op_email)){
  385. //立即发送
  386. $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
  387. $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
  388. VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
  389. pg_escape_string($dest_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
  390. }else{
  391. //加入队列状态
  392. $sql .= "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company,
  393. is_send, checked_time, checked_type,origin_op,dest_op)
  394. VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company',
  395. false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
  396. //做好加入队列时的日志记录
  397. $user_type = _isApexLogin() ? "Employee" : "Customer";
  398. $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";
  399. utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);
  400. }
  401. }
  402. }
  403. }
  404. }
  405. //代表前面有错误发生,终止SQL的执行
  406. if (!empty($errorMsg)) {
  407. $data = array(
  408. 'msg' => $errorMsg
  409. );
  410. common::echo_json_encode(500,$data);
  411. exit();
  412. }
  413. common::excuteUpdateSql($sql);
  414. $data = array(
  415. 'msg' => "success"
  416. );
  417. common::echo_json_encode(200,$data);
  418. exit();
  419. } catch (Exception $e) {
  420. error_log($e->getTraceAsString());
  421. $data = array(
  422. 'msg' => "Upload Filed Failed."
  423. );
  424. common::echo_json_encode(500,$data);
  425. }
  426. }
  427. if ($operate == "save_communication") {
  428. try {
  429. $content = $_POST["content"];
  430. $content = common::check_input($content);
  431. $text = $_POST["text"];
  432. $content = urldecode($content);
  433. $web_content = urldecode($text);
  434. $communication_cc = $_POST["communication_cc"];
  435. $serial_no = common::uuid();
  436. $email_uuid = $_POST["serial_no"];
  437. $add_by = _getLoginName();
  438. $refer_id = 0;
  439. $email = $this->getEmail($email_uuid);
  440. $from_email = "US.KApex.Online@kerryapex.com";
  441. $to_email = $email["email"];
  442. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  443. $communication_cc = trim($communication_cc);
  444. if (!empty($communication_cc)) {
  445. $communication_cc = common::check_input($communication_cc);
  446. $cc_email .= ";" . $communication_cc;
  447. }
  448. $user_from = _getLoginName();
  449. $user_to = $email["name"];
  450. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  451. if (empty($user_cc)) {
  452. $user_cc = _getLoginName();
  453. }
  454. $user_cc .= ";ApexOnlineCommunication";
  455. //邮件发送
  456. $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>@@";
  457. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  458. $key = common::excuteOneSql($emailSql);
  459. $historyEmails = "";
  460. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  461. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  462. 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());");
  463. $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)
  464. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  465. $emailRecords = $this->getCommunicationNew($email_uuid);
  466. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  467. exit();
  468. } catch (Exception $e) {
  469. common::echo_json_encode(500,array("msg" => "Sent Error."));
  470. exit();
  471. }
  472. }
  473. if ($operate == "ocean_vgm") {
  474. if (!_canEdiVgm()) {
  475. $data = array("msg" =>"Vgm Permission Error");
  476. common::echo_json_encode(400, $data);
  477. exit();
  478. }
  479. $serial_no = common::deCode(($_GET["a"]), 'D');
  480. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  481. $column = "*";
  482. $schemas = $_GET["_schemas"];
  483. if (empty($schemas)) {
  484. $schemas = "public";
  485. }
  486. $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 "
  487. . "$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;
  488. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  489. $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 "
  490. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  491. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  492. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  493. . " 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"] . "'";
  494. $rs = common::excuteListSql($rs_sql);
  495. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  496. if (empty($ocean_info["id"])) {
  497. $ocean_info["is_send"] = "t";
  498. }
  499. $err_msg = "";
  500. if (empty($ocean_info["carrier_booking"])) {
  501. $err_msg = "Carrier Booking is empty.";
  502. }
  503. if ($schemas <> "public") {
  504. $err_msg .= "This hbol do not support.";
  505. }
  506. $err_msg_ctnr = "";
  507. $err_msg_CFS = "";
  508. foreach ($rs as $cv) {
  509. if (empty($cv["ctnr"])) {
  510. $err_msg_ctnr = "Container# is empty.";
  511. }
  512. if (substr($cv["service"], 0, 3) == "CFS") {
  513. $err_msg_CFS = "CFS cannot support update.";
  514. }
  515. }
  516. if (!empty($err_msg)) {
  517. $err_msg = "You cant't add this VGM, (" . $err_msg ." ". $err_msg_ctnr." ".$err_msg_CFS.")";
  518. }
  519. $serial_no = common::deCode($serial_no, "E");
  520. //default
  521. if (empty($rs["id"])) {
  522. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  523. }
  524. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  525. //detail information
  526. $detail_information_column = array();
  527. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","edit_type" =>"normal",);
  528. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","edit_type" =>"normal");
  529. $detail_information_column[] = array("title" =>"Container No","field" =>"container_no","formatter" =>"","edit_type" =>"normal");
  530. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","edit_type" =>"number");
  531. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"vgm_kg_lg","formatter" =>"","edit_type" =>"select");
  532. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_date","formatter" =>"","edit_type" =>"dateTime");
  533. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","edit_type" =>"input");
  534. foreach($rs as $rk => $rv){
  535. $rs[$rk]['sn'] = $rk +1;
  536. $rs[$rk]['container_no'] = $rv['ctnr'];
  537. $rs[$rk]['vgm_kg_lg'] = $rv['unit'];
  538. $rs[$rk]['vgm_date'] = $rv['vgm_time'];
  539. $rs[$rk]['cargo_weight_kg'] = $rv['grs_kgs'];
  540. $rs[$rk]['cargo_weight_lb'] = $rv['grs_lbs'];
  541. //这个是前端逻辑,carrier_booking_no为空的话,取carrier_booking
  542. if(empty($rs[$rk]['carrier_booking_no'])){
  543. $rs[$rk]['carrier_booking_no'] = $ocean_info["carrier_booking"];
  544. }
  545. }
  546. $detail_information =array("detail_information_column" =>$detail_information_column,
  547. "detail_information_data" =>$rs);
  548. $data = array("msg" =>$err_msg);
  549. $Submitter = $ocean_info["authorized_company"];
  550. if(empty($ocean_info["id"])){
  551. $Submitter = $default["submitter"];
  552. }
  553. $signature = $ocean_info["signature"];
  554. if(empty($ocean_info["id"])){
  555. $signature = $default["signature"];
  556. }
  557. $authorized_email = $ocean_info["authorized_email"];
  558. if(empty($ocean_info["id"])){
  559. $authorized_email = $default["authorized_email"];
  560. }
  561. $authorized_tel = $ocean_info["authorized_tel"];
  562. if(empty($ocean_info["id"])){
  563. $authorized_tel = $default["authorized_tel"];
  564. }
  565. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  566. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  567. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  568. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  569. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  570. "submitter" =>$Submitter,"signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  571. $data["detail_information"] = $detail_information;
  572. $data["schemas"] = $schemas;
  573. $data["serial_no"] = $serial_no;
  574. common::echo_json_encode(200, $data);
  575. exit();
  576. }
  577. if ($operate == "save_ocean_vgm") {
  578. if (!_canEdiVgm()) {
  579. $data = array("msg" =>"Vgm Permission Error");
  580. common::echo_json_encode(400, $data);
  581. exit();
  582. }
  583. $msg = $this->save_vgm();
  584. if ($msg == "success"){
  585. $data = array("msg" =>$msg);
  586. common::echo_json_encode(200, $data);
  587. } else {
  588. $data = array("msg" =>$msg);
  589. common::echo_json_encode(500, $data);
  590. }
  591. exit();
  592. }
  593. if ($operate == "default_vgm"){
  594. $vgm = array();
  595. $isvgm = false;
  596. if (_canEdiVgm()) {
  597. $isvgm = true;
  598. }
  599. if ($isvgm) {
  600. $vgm = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  601. }
  602. $data = array("isvgm" =>$isvgm,"vgm" => $vgm);
  603. common::echo_json_encode(200,$data);
  604. exit();
  605. }
  606. if ($operate == "default_vgm_update"){
  607. $vgm = array();
  608. if (_canEdiVgm()) {
  609. $submitter = $_POST['submitter'];
  610. $signature = $_POST['signature'];
  611. $authorized_email = $_POST['authorized_email'];
  612. $authorized_tel = $_POST['authorized_tel'];
  613. $count = common::excuteOneSql("select count(*) from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  614. if($count > 0){
  615. $rs = common::excuteUpdateSql("update ocean_vgm_setting set submitter = '" . common::check_input($submitter) . "', "
  616. . "signature = '" . common::check_input($signature) . "', authorized_email = '" . common::check_input($authorized_email) . "', "
  617. . "authorized_tel = '" . common::check_input($authorized_tel) . "' where login_name ilike '" . _getLoginName() . "'");
  618. }else{
  619. $rs =common::excuteUpdateSql("INSERT INTO ocean_vgm_setting(login_name, submitter, signature, authorized_email, authorized_tel) "
  620. . "VALUES ('" . _getLoginName() . "', '" . common::check_input($submitter) . "', "
  621. . "'" . common::check_input($signature) . "', '" . common::check_input($authorized_email) . "', "
  622. . "'" . common::check_input($authorized_tel) . "');");
  623. }
  624. $vgm["submitter"] = $submitter;
  625. $vgm["signature"] = $signature;
  626. $vgm["authorized_email"] = $authorized_email;
  627. $vgm["authorized_tel"] = $authorized_tel;
  628. }
  629. $data = array("msg" =>"Save Successful","vgm" => $vgm);
  630. common::echo_json_encode(200,$data);
  631. exit();
  632. }
  633. /*
  634. * share_shipment 这个提交的意义,是为了留下记录用户信息
  635. */
  636. if ($operate == "share_shipment") {
  637. $data = array("msg" =>"share_shipment");
  638. common::echo_json_encode(200,$data);
  639. exit();
  640. }
  641. }
  642. /*
  643. * ocean order search
  644. */
  645. private function _ocean_search() {
  646. //分担查询
  647. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  648. $cp = common::check_input($_POST ['cp']); //current_page
  649. $ps = common::check_input($_POST ['ps']); //ps
  650. if (empty($ps))
  651. $ps = 100;
  652. if (empty($cp))
  653. $cp = 1;
  654. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  655. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  656. if (!empty($_REQUEST["_reportRef"])) {
  657. $_reportType = $_REQUEST["_reportType"];
  658. $_reportRef = $_REQUEST["_reportRef"];
  659. if ($_reportType == "r3") {
  660. if ($_reportRef == "Previous 7 Days") {
  661. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  662. } else if ($_reportRef == "≤1 Day") {
  663. $sqlWhere .= " and eta=current_date";
  664. } else if ($_reportRef == "1-2 Days") {
  665. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  666. } else if ($_reportRef == "3-6 Days") {
  667. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  668. } else if ($_reportRef == "≥7 Days") {
  669. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  670. } else {
  671. $sqlWhere .= " and 1<>1";
  672. }
  673. } else if ($_reportType == "r4") {
  674. if ($_reportRef == "Previous 7 Days") {
  675. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  676. } else if ($_reportRef == "≤1 Day") {
  677. $sqlWhere .= " and etd=current_date";
  678. } else if ($_reportRef == "1-2 Days") {
  679. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  680. } else if ($_reportRef == "3-6 Days") {
  681. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  682. } else if ($_reportRef == "≥7 Days") {
  683. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  684. } else {
  685. $sqlWhere .= " and 1<>1";
  686. }
  687. } else if ($_reportType == "ata_r3") {
  688. if ($_reportRef == "≤1 Day") {
  689. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  690. } else if ($_reportRef == "1-2 Days") {
  691. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  692. } else if ($_reportRef == "3-6 Days") {
  693. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  694. } else if ($_reportRef == "≥7 Days") {
  695. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  696. } else {
  697. $sqlWhere .= " and 1<>1";
  698. }
  699. } else if ($_reportType == "atd_r4") {
  700. if ($_reportRef == "≤1 Day") {
  701. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  702. } else if ($_reportRef == "1-2 Days") {
  703. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  704. } else if ($_reportRef == "3-6 Days") {
  705. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  706. } else if ($_reportRef == "≥7 Days") {
  707. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  708. } else {
  709. $sqlWhere .= " and 1<>1";
  710. }
  711. } else if ($_reportType == "top") {
  712. if (!empty($_reportRef)) {
  713. $_reportStationType = $_REQUEST["_reportStationType"];
  714. if($_reportStationType == 'shippr_uncode'){
  715. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  716. }
  717. if($_reportStationType == 'fport_of_loading_un'){
  718. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  719. }
  720. if($_reportStationType == 'consignee_uncode'){
  721. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  722. }
  723. if($_reportStationType == 'mport_of_discharge_un'){
  724. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  725. }
  726. } else {
  727. $sqlWhere .= " and 1<>1";
  728. }
  729. } else if ($_reportType == "co2e") {
  730. $_reportDataType = $_REQUEST["_reportDataType"];
  731. //查询sea 其他的为空
  732. if (!empty($_reportRef) && $_reportDataType == "sea") {
  733. $_reportStationType = $_REQUEST["_reportStationType"];
  734. if($_reportStationType == 'origin'){
  735. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  736. }else{
  737. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  738. }
  739. } else {
  740. $sqlWhere .= " and 1<>1";
  741. }
  742. } else {
  743. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  744. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  745. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  746. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  747. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  748. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  749. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  750. $sqlWhere .= " and (eta-etd)>80";
  751. } else {
  752. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  753. }
  754. }
  755. }
  756. //取消全文检索
  757. // if (!empty($_POST["_textSearch"])) {
  758. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  759. // }
  760. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  761. if (!empty($_POST["_textSearch"])) {
  762. $textSearch_arr = $_POST['_textSearch'];
  763. if(!is_array($textSearch_arr)){
  764. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  765. $textSearch_arr = array($textSearch_arr);
  766. }
  767. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  768. //$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)],''))";
  769. $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))
  770. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
  771. or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  772. }
  773. //移除filterTag
  774. $sqlWhere_befrom_filterTag = $sqlWhere;
  775. $mode_param = "";
  776. $transport_mode = empty($_POST["transport_mode"]) ? "all" : $_POST["transport_mode"];
  777. if(!is_array($transport_mode)){
  778. $transport_mode = array($transport_mode);
  779. }
  780. if((utils::count($transport_mode) == 1 && strtolower($transport_mode[0]) == 'all')){
  781. $transport_mode = array("sea","air","road","rail");
  782. }
  783. $transport_mode = utils::implode(";",$transport_mode);
  784. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  785. $sqlWhere .= " and transport_mode_extend in ($mode_param)";
  786. $transport_mode_search = " and transport_mode_extend in ($mode_param)";
  787. //查询tag
  788. // IFFBCF Booking Confirmation Created
  789. // IFFCPU Cargo Pickup Cargo Received
  790. // IFFREC Cargo Arrived at Origin Cargo Received
  791. // IFFDEP Departure Departed
  792. // IFFARR Arrived at Final Destination Port Arrived
  793. // IFFAFD Arrived at Final Destination Completed (remove)
  794. // IFFDEL document turnover/delivered Completed
  795. $filterTag_param = "";
  796. if (!empty($_POST["filterTag"])) {
  797. if (utils::count($_POST['filterTag']) == 1){
  798. $filterTag = $_POST['filterTag'][0];
  799. }else{
  800. $filterTag = utils::implode(",", $_POST['filterTag']);
  801. }
  802. $_sqlwhere = "1<>1";
  803. $filterTag_param = "1<>1";
  804. if(strtolower($filterTag) == "all"){
  805. $filterTag_param = "1=1";
  806. }
  807. if (stripos($filterTag, "Created") !== FALSE) {
  808. $_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)";
  809. $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)";
  810. }
  811. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  812. $_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)";
  813. $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)";
  814. }
  815. if (stripos($filterTag, "Departure") !== FALSE) {
  816. $_sqlwhere .= " or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  817. $filterTag_param .= " or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  818. }
  819. if (stripos($filterTag, "Arrived") !== FALSE) {
  820. $_sqlwhere .= " or (m_iffarr is not null and m_iffdel is null)";
  821. $filterTag_param .= " or (m_iffarr is not null and m_iffdel is null)";
  822. }
  823. if (stripos($filterTag, "Completed") !== FALSE) {
  824. $_sqlwhere .= " or (m_iffdel is not null)";
  825. $filterTag_param .= " or (m_iffdel is not null)";
  826. }
  827. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  828. $sqlWhere .= " and ($_sqlwhere)";
  829. $filterTag_param = " ($filterTag_param)";
  830. }
  831. }
  832. if(empty($filterTag_param)){
  833. $filterTag_param = "1=1";
  834. }
  835. $tag_and_mode_param = $filterTag_param.$transport_mode_search;
  836. $mode_param_search = "1=1 ".$transport_mode_search;
  837. $rc = $_POST ['rc'];
  838. //这里都要查询,除非多传几个参数回来
  839. if ($rc == - 1 || true) {
  840. $sql = "select count(1) as rc,
  841. sum(case when (1<>1 or (transport_mode_extend='sea')) then 1 else 0 end) as sea_rc,
  842. sum(case when (1<>1 or (transport_mode_extend='air')) then 1 else 0 end) as air_rc,
  843. sum(case when (1<>1 or (transport_mode_extend='road')) then 1 else 0 end) as road_rc,
  844. sum(case when (1<>1 or (transport_mode_extend='rail')) then 1 else 0 end) as rail_rc,
  845. sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc,
  846. sum(case when ($mode_param_search 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)
  847. then 1 else 0 end)
  848. as created,
  849. sum(case when ($mode_param_search and (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)
  850. then 1 else 0 end)
  851. as cargo_received,
  852. sum(case when ($mode_param_search and m_iffdep is not null and m_iffarr is null and m_iffdel is null) then 1 else 0 end) as departed,
  853. sum(case when ($mode_param_search and m_iffarr is not null and m_iffdel is null) then 1 else 0 end) as arrived,
  854. sum(case when ($mode_param_search and m_iffdel is not null) then 1 else 0 end) as completed,
  855. string_agg(distinct incoterms, '<$>') as incoterm_str,
  856. string_agg(distinct service, '<$>') as service_str
  857. from public.kln_ocean". $sqlWhere_befrom_filterTag;
  858. error_log("online_ocean_search_All_Status: ".$sql);
  859. //$sql_all_status_data = common::excuteObjectSql($sql);
  860. $sql_all_status_data = $mapdb->GetRow($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  861. $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
  862. $IncotermsList = array();
  863. foreach($incoterms as $terms){
  864. if(!empty($terms)){
  865. $IncotermsList[] = array("name"=>$terms,"checked"=>false);
  866. }
  867. }
  868. $service = explode("<$>", $sql_all_status_data['service_str']);
  869. $ServiceList = array();
  870. foreach($service as $_service){
  871. if(!empty($_service)){
  872. $ServiceList[] = array("name"=>$_service,"checked"=>false);
  873. }
  874. }
  875. $rc = $sql_all_status_data['rc'];
  876. $search_rc = $sql_all_status_data['seach_rc'];
  877. $sea_rc = $sql_all_status_data['sea_rc'];
  878. $air_rc = $sql_all_status_data['air_rc'];
  879. $road_rc = $sql_all_status_data['road_rc'];
  880. $rail_rc = $sql_all_status_data['rail_rc'];
  881. $Created = $sql_all_status_data['created'];
  882. $Cargo_Received = $sql_all_status_data['cargo_received'];
  883. $Departed = $sql_all_status_data['departed'];
  884. $Arrived = $sql_all_status_data['arrived'];
  885. $Completed = $sql_all_status_data['completed'];
  886. if (!empty($_POST["filterTag"])) {
  887. $tagsList = array(array("name"=>"All","number"=>intval($search_rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  888. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  889. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  890. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  891. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  892. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  893. }else{
  894. //初始,前端有选择着带入选择
  895. $tagsList = array(array("name"=>"All","number"=>intval($search_rc),"type"=>"all","checked"=> true ),
  896. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  897. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  898. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  899. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  900. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  901. }
  902. $TransportList = array(
  903. array("name"=>"Ocean Freight","sname"=>"Sea","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
  904. array("name"=>"Air Freight","sname"=>"Air","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"),
  905. array("name"=>"Rail Freight","sname"=>"Rail","number"=>intval($rail_rc),"checked"=>false,"icon"=>"#icon-icon_railway_b"),
  906. array("name"=>"Road Freight","sname"=>"Road","number"=>intval($road_rc),"checked"=>false,"icon"=>"#icon-icon_truck_b"));
  907. $transport_mode_arr = explode(";", $transport_mode);
  908. foreach($transport_mode_arr as $mode){
  909. foreach($TransportList as $tkey => $transport){
  910. if(strtolower(trim($mode)) == strtolower($TransportList[$tkey]["sname"])){
  911. $TransportList[$tkey]["checked"] = true;
  912. }
  913. }
  914. }
  915. //现在下载交给前端,后台预先只返回全部字段的列,
  916. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  917. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  918. }
  919. $tp = ceil($rc / $ps);
  920. $order_by = " etd desc";
  921. if (_isCustomerLogin()) {
  922. $order_by = " eta desc";
  923. }
  924. if ($rc > 0) {
  925. // $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  926. // FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
  927. $sql = "with oo as (SELECT oe.*, order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,transport_mode_extend,
  928. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  929. (select user_login from public.kln_user_subscribed us
  930. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  931. CASE
  932. 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
  933. 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
  934. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  935. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  936. WHEN (m_iffdel is not null) THEN 'Completed'::text
  937. ELSE 'Created'
  938. END AS new_status, ".
  939. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  940. from public.kln_ocean
  941. LEFT JOIN LATERAL ( SELECT loadterm,
  942. manifest_type,
  943. volume
  944. FROM public.kln_ocean_extend oe WHERE oe.serial_no::text = kln_ocean.serial_no::text and oe.order_from::text = kln_ocean.order_from::text) oe ON true "
  945. . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.")
  946. select oo.* ,
  947. case when oo.transport_mode ='sea' and oo._schemas ='public'
  948. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  949. when oo.transport_mode ='sea' and oo._schemas ='sfs'
  950. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM sfs.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  951. when oo.transport_mode ='air'
  952. then ''
  953. else ''
  954. end as \"Other refenrence No.\"
  955. from oo";
  956. $tmp_search_without_limit = "with oo as (SELECT oe.*, order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,transport_mode_extend,
  957. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  958. (select user_login from public.kln_user_subscribed us
  959. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  960. CASE
  961. 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
  962. 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
  963. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  964. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  965. WHEN (m_iffdel is not null) THEN 'Completed'::text
  966. ELSE 'Created'
  967. END AS new_status, ".
  968. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  969. from public.kln_ocean
  970. LEFT JOIN LATERAL ( SELECT loadterm,
  971. manifest_type,
  972. volume
  973. FROM public.kln_ocean_extend oe WHERE oe.serial_no::text = kln_ocean.serial_no::text and oe.order_from::text = kln_ocean.order_from::text) oe ON true "
  974. . $sqlWhere . " order by $order_by)
  975. select oo.* ,
  976. case when oo.transport_mode ='sea' and oo._schemas ='public'
  977. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  978. when oo.transport_mode ='sea' and oo._schemas ='sfs'
  979. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM sfs.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  980. when oo.transport_mode ='air'
  981. then ''
  982. else ''
  983. end as \"Other refenrence No.\"
  984. from oo";
  985. //$rs = common::excuteListSql($sql);
  986. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  987. error_log("online_ocean_search_SQL: ".$sql);
  988. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  989. foreach($rs as $index => $val) {
  990. //返回加密serial_no
  991. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  992. //$rs[$index]["mode"] = "Ocean Freight";
  993. $rs[$index]["Mode"] = $val['transport_mode_extend'] == 'sea' ? "Ocean Freight" : ($val['transport_mode_extend'] == 'air' ? "Air Freight":
  994. ($val['transport_mode_extend'] == 'rail' ? "Rail Freight":
  995. ($val['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  996. //status 改为ocean_milestone里的信息
  997. $rs[$index]["Status"] = $rs[$index]["new_status"];
  998. $rs[$index]["Shipment Type"] = $rs[$index]["Shipment Type"] == 'GPE' ? 'LCL' : $rs[$index]["Shipment Type"];
  999. //订阅的参数
  1000. if(empty($rs[$index]["is_subscribe"])){
  1001. $rs[$index]['is_subscribe'] = false;
  1002. }else{
  1003. $rs[$index]['is_subscribe'] = true;
  1004. }
  1005. //这个不影响,不会deCode两次,取得是临时变量的__serial_no,加这个是为了订阅
  1006. $rs[$index]["a"] = common::deCode($val['__serial_no'], 'E');
  1007. }
  1008. $arrTmp = array('searchData' => $rs,
  1009. 'tagsList' => $tagsList,
  1010. 'TransportList' => $TransportList,
  1011. 'allColums' => $allBookingColumns,
  1012. 'IncotermsList' =>$IncotermsList,
  1013. 'ServiceList' =>$ServiceList,
  1014. 'canEdiVgm' => _canEdiVgm(),
  1015. 'rc' => $search_rc,
  1016. 'ps' => $ps,
  1017. 'cp' => $cp,
  1018. 'tp' => $tp,
  1019. 'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
  1020. 'type' => common::check_input($_POST ['_ntype']));
  1021. } else {
  1022. $arrTmp = array('searchData' => array(),
  1023. 'tagsList' => $tagsList,
  1024. 'TransportList' => $TransportList,
  1025. 'IncotermsList' =>$IncotermsList,
  1026. 'ServiceList' =>$ServiceList,
  1027. 'allColums' => $allBookingColumns,
  1028. 'canEdiVgm' => _canEdiVgm(),
  1029. 'rc' => $search_rc,
  1030. 'ps' => $ps,
  1031. 'cp' => $cp,
  1032. 'tp' => $tp,
  1033. 'tmp_search' => "",
  1034. 'type' => common::check_input($_POST ['_ntype']));
  1035. }
  1036. common::echo_json_encode(200,$arrTmp);
  1037. exit();
  1038. }
  1039. private function _ocean_detail() {
  1040. $serial_no = common::deCode($_GET['a'], 'D');
  1041. $sql = $this->getOceanDetail($serial_no);
  1042. $ocean = common::excuteObjectSql($sql);
  1043. //(本质是是底表ocean 和 kln_oceans数据没有及时同步,详细页面有查询的ocean的时间照成的时间不一致),
  1044. //单独处理一些,用kln_ocean里面的字段,与查询页面保持一致: etd as oo_etd, eta as oo_eta,atd as oo_atd,ata as oo_ata,
  1045. //这样改动最小
  1046. //这个是同步问题,同步是实时的
  1047. //$ocean["f_etd"] = $ocean["oo_etd"];
  1048. //$ocean["m_eta"] = $ocean["oo_eta"];
  1049. //$ocean["atd"] = $ocean["oo_atd"];
  1050. //$ocean["ata"] = $ocean["oo_ata"];
  1051. if (!empty($ocean)) {
  1052. $ocean['_isf_bol'] = $ocean['isf_bol'];
  1053. if (empty($ocean['_isf_bol'])) {
  1054. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  1055. }
  1056. $isf_ss = md5(md5($ocean['_isf_bol']));
  1057. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  1058. //ETA Dest的计算逻辑移除
  1059. // most update status
  1060. $_schemas = $_REQUEST["_schemas"];
  1061. $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 "
  1062. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.kln_ocean "
  1063. . "where serial_no= '" . $ocean["serial_no"] . "'";
  1064. if (!empty($_schemas)) {
  1065. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  1066. }
  1067. $mostStatus = common::excuteObjectSql($mostStatusSql);
  1068. $state = -1;
  1069. if (!empty($mostStatus["last_status_315_code"])) {
  1070. //desc 逻辑处理取消
  1071. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  1072. }
  1073. //请求地图是需要的参数
  1074. $uncode = "'";
  1075. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  1076. $uncode .= $mostStatus["place_of_receipt_un"];
  1077. }
  1078. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  1079. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  1080. $uncode .= $mostStatus["place_of_delivery_un"];
  1081. }
  1082. $uncode .= "'";
  1083. }
  1084. $vueData = $this->returnOceanDetailData($ocean,$state);
  1085. //处理shipment data暂时写死
  1086. $simplexData = $vueData['shipmentData'];
  1087. //处理transportInfo信息数据
  1088. $transportInfo = $vueData['transportInfo'];
  1089. //处理basicInfo信息数据
  1090. $basicInfo = $vueData['basicInfo'];
  1091. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1092. $businessPartners = $vueData['businessPartners'];
  1093. //处理routes 转船可能有多个情况
  1094. $routes = $vueData['routes'];
  1095. //处理marksAndDescription
  1096. $marksAndDescription = $vueData['marksAndDescription'];
  1097. //处理containerStatusData
  1098. $containerStatusData = $vueData['containerStatusData'];
  1099. //处理ocean_reference
  1100. $ref_no = array();
  1101. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  1102. if(!empty($ref_arr)){
  1103. foreach($ref_arr as $ref) {
  1104. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  1105. }
  1106. }
  1107. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  1108. $ocean_container_column = array();
  1109. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  1110. //特殊处理po_no,配置column在查询的时候,不好
  1111. $container_column[] = array("database_column_name" => "po_no","name"=>"PO_NO");
  1112. $container_column_config = array("Quantity" => array("formatter"=>"number","digits"=>0),
  1113. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1114. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1115. "CBM" => array("formatter"=>"number","digits"=>3),
  1116. "CFT" => array("formatter"=>"number","digits"=>3));
  1117. foreach($container_column as $cc){
  1118. $cc['name'] = $cc['database_column_name'] == "grs_kgs" ? "Gross Weight(KGS)" : ($cc['database_column_name'] == "grs_lbs" ? "Gross Weight(LBS)" : $cc['name']);
  1119. if(!empty($container_column_config[$cc['name']])){
  1120. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],
  1121. "formatter" =>$container_column_config[$cc['name']]["formatter"],
  1122. "digits" =>$container_column_config[$cc['name']]["digits"],
  1123. "type" =>"normal");
  1124. }else{
  1125. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  1126. }
  1127. }
  1128. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",
  1129. net_lbs,po_no as oc_po_no,
  1130. (select po_no from oc_container_item where oc_container_id = oc_container.id) as item_po_no
  1131. from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  1132. $rss = common::excuteListSql($sql);
  1133. $quantity_unit = array();
  1134. $g_weight_tolal = 0;
  1135. $ch_weight_tolal = 0;
  1136. $ch_weight_tolal_grs_lbs = 0;
  1137. $cbm_tolal = 0;
  1138. foreach ($rss as $key => $rs) {
  1139. //特殊处理po_no
  1140. $rss[$key]['po_no'] = utils::outDisplayForMergeForDISTINCT($rs['oc_po_no'],$rs['item_po_no']);
  1141. $unit = $rs['unit'];
  1142. if (array_key_exists($unit, $quantity_unit)) {
  1143. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  1144. } else {
  1145. $quantity_unit[$unit] = $rs['qty'];
  1146. }
  1147. $g_weight_tolal += $rs['grs_kgs'];
  1148. $ch_weight_tolal += $rs['net_lbs'];
  1149. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  1150. $cbm_tolal += $rs['cbm'];
  1151. //特殊处理weight
  1152. if(!empty($rss[$key]['grs_kgs'])){
  1153. $rss[$key]['grs_kgs'] = $rs['grs_kgs'];
  1154. }
  1155. if(!empty($rss[$key]['grs_lbs'])){
  1156. $rss[$key]['grs_lbs'] = $rs['grs_lbs'];
  1157. }
  1158. //为每个柜子下面单独加状态信息 ctnr_label content
  1159. $rss[$key]['containerStatusData'] = array();
  1160. foreach($containerStatusData as $_containerStatusData){
  1161. if(trim($_containerStatusData["ctnr_label"]) == trim($rs["ctnr"])){
  1162. $rss[$key]['containerStatusData'] = $_containerStatusData["content"];
  1163. }
  1164. }
  1165. }
  1166. $quantity_tolal = "";
  1167. foreach($quantity_unit as $uk => $uv){
  1168. // 使用substr()截取第一次出现之前的字符串
  1169. $uk = substr($uk, 0, strpos($uk, "-"));
  1170. $quantity_tolal.=$uv." ".$uk." ";
  1171. }
  1172. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  1173. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  1174. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  1175. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  1176. //Containers信息
  1177. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  1178. //Packing信息
  1179. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  1180. //Milestones info 列名固定
  1181. $Milestones = common::getMilestonesInfo($ocean,"sea",$_schemas,$vueData['EDI315TimeAndLocation']);
  1182. //页面固定写死的信息
  1183. $document_column = array();
  1184. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1185. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1186. $document_data = array();
  1187. $document = _getViewDocType($_REQUEST["_schemas"]);
  1188. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1189. $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'])."'");
  1190. if (!empty($document)) {
  1191. foreach ($document as $v) {
  1192. $file_type = $v['display_name'];
  1193. $file_arr = $this->getOceanFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  1194. $tar = json_decode($ocean_can_view_file,true);
  1195. if(!empty($tar[$v['display_name']])){
  1196. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1197. switch ($v['display_name']) {
  1198. case 'HBL':
  1199. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1200. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1201. from ra_online_doc_upload
  1202. 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']."'
  1203. order by id desc";
  1204. break;
  1205. case 'MBL':
  1206. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1207. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1208. from ra_online_doc_upload
  1209. 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']."'
  1210. order by id desc";
  1211. break;
  1212. case 'Others':
  1213. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1214. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1215. from ra_online_doc_upload
  1216. 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']."'
  1217. order by id desc";
  1218. break;
  1219. default:
  1220. $sql = "";
  1221. break;
  1222. }
  1223. if (!empty($sql)) {
  1224. $rss = common::excuteListSql($sql);
  1225. foreach ($rss as $rs) {
  1226. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1227. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  1228. "file_name" => $rs['file_name'],
  1229. "format_name" => $rs['format_name'],
  1230. "detail"=>$rs['upload_date'],
  1231. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1232. "from_system" =>'TOPOCEAN_KSMART');
  1233. }else{
  1234. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1235. "file_name" => $rs['file_name'],
  1236. "format_name" => $rs['format_name'],
  1237. "detail"=>$rs['upload_date'],
  1238. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1239. "from_system" =>'');
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1246. //按现在的逻辑,有值才会显示
  1247. foreach($file_arr as $f){
  1248. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1249. }
  1250. }
  1251. }
  1252. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1253. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  1254. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  1255. $email = $this->getEmail($ocean["serial_no"]);
  1256. $email['cc_email'] = $cc_email;
  1257. $email['emailRecords'] = $emailRecords;
  1258. global $_COPYRIGHT;
  1259. $data = array('transportInfo' => $transportInfo,
  1260. 'basicInfo' => $basicInfo,
  1261. 'businessPartners' => $businessPartners,
  1262. 'ref_no' => $ref_no,
  1263. 'packing' => $packing,
  1264. 'marksAndDescription' => $marksAndDescription,
  1265. 'containers' => $containers,
  1266. 'simplexData' =>$simplexData,
  1267. 'containerStatusData' => $containerStatusData,
  1268. 'document_info' => $document_info,
  1269. 'Milestones' => $Milestones,
  1270. 'routes' => $routes,
  1271. 'email' => $email,
  1272. 'ams_ss' => md5(md5($ocean['serial_no'])),
  1273. 'isf_ss' => $isf_ss,
  1274. 'transport_mode' =>"sea",
  1275. '_schemas' =>$_schemas,
  1276. 'uncode' =>$uncode,
  1277. 'serial_no' =>$serial_no,
  1278. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1279. 'a' =>common::deCode($serial_no, 'E'),
  1280. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1281. 'canEdiVgm' => _canEdiVgm(),
  1282. 'canViewAMSLog'=>_canViewAMSLog(),
  1283. 'canViewISFLog'=>_canViewISFLog(),
  1284. 'copyright' =>$_COPYRIGHT,
  1285. 'website' =>common::getWebiste($ocean['m_carrier']));
  1286. common::echo_json_encode(200,$data);
  1287. exit();
  1288. }
  1289. private function _air_ocean_detail(){
  1290. $serial_no = common::deCode($_GET['a'], 'D');
  1291. $sql = $this->getAirDetail($serial_no);
  1292. $air = common::excuteObjectSql($sql);
  1293. //根据air_milestone 判断 shipment status的state
  1294. $_schemas = $_REQUEST["_schemas"];
  1295. $air_milestone_status = common::excuteListSql("select code,
  1296. act_date,est_date,timezone
  1297. from air_milestone a
  1298. where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
  1299. order by id");
  1300. $state = -1;
  1301. if (!empty($air_milestone_status)) {
  1302. $state_arr = array();
  1303. foreach($air_milestone_status as $ms){
  1304. if($ms['code'] == "IFFCPU"){
  1305. $state_arr[] = 0;
  1306. }
  1307. if($ms['code'] == "IFFREC" || $ms['code'] == "IFFONB"){
  1308. $state_arr[] = 1;
  1309. }
  1310. if($ms['code'] == "IFFARR"){
  1311. $state_arr[] = 2;
  1312. }
  1313. if($ms['code'] == "IFFDEL"){
  1314. $state_arr[] = 3;
  1315. }
  1316. }
  1317. $state = max($state_arr);
  1318. }
  1319. $vueData = $this->returnAirDetailData($air,$air_milestone_status,$state);
  1320. //处理shipment data暂时写死
  1321. $simplexData = $vueData['shipmentData'];
  1322. //处理transportInfo信息数据
  1323. $transportInfo = $vueData['transportInfo'];
  1324. //处理basicInfo信息数据
  1325. $basicInfo = $vueData['basicInfo'];
  1326. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1327. $businessPartners = $vueData['businessPartners'];
  1328. //处理routes 转船可能有多个情况
  1329. $routes = $vueData['routes'];
  1330. //处理marksAndDescription
  1331. $marksAndDescription = $vueData['marksAndDescription'];
  1332. $quantity_tolal = empty($air['qty']) ? "" : $air['qty'].$air['qty_uom'];
  1333. $g_weight_tolal = empty($air['piece_count']) ? "" : sprintf("%.3f", $air['piece_count'])." KGS";
  1334. $ch_weight_tolal = empty($air['piece_count']) ? "": sprintf("%.3f", $air['weight'])." KGS";
  1335. $cbm_tolal = empty($air['cbm']) ? "" : sprintf("%.4f", $air['cbm'])." CBM";
  1336. //Packing信息
  1337. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
  1338. //Milestones info 列名固定
  1339. $Milestones = common::getMilestonesInfo($air,"air",$_schemas);
  1340. //页面固定写死的信息
  1341. $document_column = array();
  1342. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1343. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1344. $document_data = array();
  1345. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  1346. $air_can_view_file = common::excuteOneSql("select air_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
  1347. if (!empty($document)) {
  1348. foreach ($document as $v) {
  1349. $file_type = $v['display_name'];
  1350. $file_arr = $this->getAirFileByHbol($air['_mawb'] . '-' . $air['_mawb_name'], $air['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE);
  1351. $tar = json_decode($air_can_view_file,true);
  1352. if(!empty($tar[$v['display_name']])){
  1353. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1354. switch ($v['display_name']) {
  1355. case 'HBL':
  1356. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1357. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1358. from air_doc_upload
  1359. where lower(bol) = lower('".$air['_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']."'
  1360. order by id desc";
  1361. break;
  1362. case 'MBL':
  1363. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1364. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1365. from air_doc_upload
  1366. where lower(bol) = lower('".strtolower($air['_mawb'] . '-' . $air['_mawb_name'])."') and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  1367. order by id desc";
  1368. break;
  1369. case 'Others':
  1370. $sql = "SELECT
  1371. (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1372. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1373. from air_doc_upload
  1374. where (lower(bol) = lower('".strtolower($air['_h_bol'])."') or lower(bol) = lower('".strtolower($air['_mawb'] . '-' . $air['_mawb_name'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  1375. order by id desc";
  1376. break;
  1377. default:
  1378. $sql = "";
  1379. break;
  1380. }
  1381. if (!empty($sql)) {
  1382. $rss = common::excuteListSql($sql);
  1383. foreach ($rss as $rs) {
  1384. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1385. "file_name" => $rs['file_name'],
  1386. "detail"=>$rs['upload_date'],
  1387. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1388. "from_system" =>'');
  1389. }
  1390. }
  1391. }
  1392. }
  1393. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1394. //按现在的逻辑,有值才会显示
  1395. foreach($file_arr as $f){
  1396. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1397. }
  1398. }
  1399. }
  1400. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1401. $emailRecords = $this->getCommunicationNew($air["serial_no"]);
  1402. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $air["serial_no"] . "' order by id desc limit 1");
  1403. $email = $this->getEmail($air["serial_no"]);
  1404. $email['cc_email'] = $cc_email;
  1405. $email['emailRecords'] = $emailRecords;
  1406. global $_COPYRIGHT;
  1407. $data = array('transportInfo' => $transportInfo,
  1408. 'basicInfo' => $basicInfo,
  1409. 'businessPartners' => $businessPartners,
  1410. 'ref_no' => array(),
  1411. 'packing' => $packing,
  1412. 'marksAndDescription' => $marksAndDescription,
  1413. 'containers' => array(),
  1414. 'simplexData' =>$simplexData,
  1415. 'containerStatusData' => array(),
  1416. 'document_info' => $document_info,
  1417. 'containers' => array(),
  1418. 'Milestones' => $Milestones,
  1419. 'routes' => $routes,
  1420. 'email' => $email,
  1421. 'ams_ss' =>"",
  1422. 'isf_ss' => "",
  1423. '_schemas' =>$_schemas,
  1424. 'uncode' =>"",
  1425. 'transport_mode' =>"air",
  1426. 'serial_no' =>$serial_no,
  1427. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1428. 'a' =>common::deCode($serial_no, 'E'),
  1429. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1430. 'canEdiVgm' => _canEdiVgm(),
  1431. 'canViewAMSLog'=>_canViewAMSLog(),
  1432. 'canViewISFLog'=>_canViewISFLog(),
  1433. 'copyright' =>$_COPYRIGHT,
  1434. 'website' =>"");
  1435. common::echo_json_encode(200,$data);
  1436. exit();
  1437. }
  1438. private function _ocean_excel() {
  1439. // $ss = "AT4JLRp5E%2FP3aJmJClY%2F7VDgtwMSlzvZ0XSGJyrsru29di5bQCy%2F96%2BEzjFomfp6tinP89uz1oCrCpnbBt6I%2FEfVv%2FR7Xmb0CJa48I9sgCdMjAxDGDL%2FjdC%2B49sDMhC4QSOjd84JFr6HXw76ONyeXTiOEXE0ehhC2Tr9Ml0in11cD%2Bj17IkTHqEZteC80zS58%2Fa2SJdjTSepw73GbZVk%2BYhrimfO%2BhhW6%2FqjD%2FY%2BLB%2FP4RcmYISjkRZHH3kGOUUTRH0aqj9qUHuCL2O3m0ZirmHeGGzeIcsfrLsGcAq7XKNsQfhIxPzK7nUMYXq9fscvD0U7YnPpu4D5NTiugfspM42G0dFj4ANjU8xXLgYa4yC6PPXXKZdMgZ%2FQ2mx95tgJ0VHsmIi7Vr2QykVU1GsLEpjirTASWDWc%2BC1ACBz9AYId5%2BabLSgPbfXYgOPwDxcHAAhLNvUUZaLVOHLAIVfZbCh67HLIKDOJb%2BuNmj1k0Rfvw0Atkb1ed2ovFFDNj5wQJn5hw5YSctyJFNtCdKRgCjaFJVLfzAPlNrtZvrOs1rhrWJ6syUb4dezQEXnRr3LagohAQTgb1Wr5WlvXKmXZJpVDEiHUwjkj9X7h%2F4ttXYBf2IISs3apqtUphJW06eBLi6AzXjHHTOyacvveWoZbTYH9%2B0BKLt6IDvs%2BUVJ3Uaiy5xrqhn5vx7x%2F113ylvuQSMmpOAXzORKTkelH5qH8l4z%2BgHThFafPHPFqC7xG3Hvo8FF2z3B87WLBk3zNpCk3k5RIsR7Rzi3G8zKrRd8w1zYNLyDQxTJ40FL3lEkyVVGOPf8WPCaimEeZ2wgcyNvSujV33zGEEFSuQ%2Bu6EgoWjfQ2c29Ek3TSjzw45NTkGiMYutI%2BcSJg5b2jytCYuNqGXzQZH5%2Bpp14i2%2FP9yb6NxJB2HornwkbB9YUhjH4t%2Bg9NRhGX%2BtWnztM1T%2BH8dqlm4jZnXOinRcxsL%2F2zcWnmO5RL3zMh3GNhKCP%2B6tYMRRrtmwlFkY89ujgb8rxWyRx%2BjdR7hiW6nmU0rR9Udd5O3TzsEm8O0sd7wQomnjQffxZo0NkAyENSo3jmS5pfm6lTTWRbp9pU8jszqDXekHp77MivzsWMZ3Pu%2FiZ9NlZha7Azk9%2BJOSiB%2BPuxPaEedPXUP85TToIiQz7awI5379yyWD5fwcTejpzOhICmTuPXQSZ8hgog0sJ7fL4CkO2ID6N3g5FBXZnqktSfoAIy%2BJUmKQvGh8lq%2BAOdGsx16iQZKnitUeEDDI64C1r8n8tXMosW4iWdrW8nuZ0vxDAjXZu5q0iAW5IWHjKi%2FYkVBCcsMJIe6VQmQTFMfZIbSM4IILu7roE101p3skQc2BfAIZpbZZ1fCfHU98VGTpUcyPMDEY19J69K8cwAV0tKlzZuRcoIdzkt4HQoQaIcfwRII4KPh3v0N9CM%2BbsUOyuX0NBJEim4MluN%2B74vg0p%2FhH%2B9t0NDivzU2Nl%2FrVMUtXKjSmVfvnWmLV1Y%2FnYmJaCI%2BmSVYP%2BNMBsCOBDla2tziZcIsldtlmZoNq%2BlmwNJrrpSt3RBsY9MW0723FIyl4CkmyXQYSUOtznutFemE%2FLH28fL4rNnj2XbbCtTPGY%2BeJ5H54x8noCIkTo6mNArohllkKOhmMFE90w0jPmVpxl4JPwZ1lcM%2BsH4iOIkOCiI9Xr5TcaQiwylsnSuHW4HxPzdq8ABovhhzjxkYAHaOeNz6ChGorfyb2SdRzstiDtbiKkzxsI1OXcaNopDxN5G2isLJG%2BL%2FnOwXiuK9IUp%2BzEje6rMgpMwyNz8D%2Fv2P%2BgAuMFDhR7EeZUm9y9psRIXBTULRVXL3Njmu%2FewkY%2FiL%2BFt7MN18jxYc0mloYvG7F4pG9sBG0brP%2BhVg0C6SngXGyKFohVW2Pd1t8z7U%2F%2FZWt1rCAgG76Ozu2bGc%2F5evsqliKppx%2Blr5f6IzSiXQvtuSISuAx1T8blam6BuN%2Fy8YeSkxK8TM3h%2FnBMJyKv0jRGV5lUoaTkh%2Bc03LDeUNdG5ihQ1RoRZfdDNC4xmBTE9LD2g2HfBpni6OOiIGdTs6lrVzJdOUU7CtvAxsjn3dSCwTEnX%2FllxJFvtBIu%2FLKYGBr%2F1lpeuqNT%2F%2Fe4dENblBEchgghp6%2Fa8nulKbp35Iui2gmSc87%2Bt%2BDeI7uF%2BAYh3ozRKQDEk4NHxhxu1%2Fm1Cy88lKaWWhfKXJXSkYC6edf%2FMq7g47BOx0oJ9GK%2BurdJUHXFB8g9AKcupDQ4BU7Ca6tJPugvCE7Bv3SXp5qYc3Aix%2FcHv8BPofxxsKw%2B5t%2BIEuRVJ0M7QvHMiG7ggVswuQBfRcnd6o3YJYoPmdc8V6npScjrQomQGMD7Pffp6cvLVVpaefBo3MyZAE9wZGErZW5DmUhu43XrQdwyKTNz86FNMk9JtHxJqyCRNLzXginSi12t01i875kd0s5md6NuSpLzZ%2B3kMw%2Fxdqku6IqacjMjkcQs08aF7MQhmWN7Bq3ejVhq5IsaaCmQcuCpZL9SCPYZ0vNpxwLK%2FjeAOtQ1z7erJ%2FkF4eRliAyf8k64WV3VqteSqILScx2KBkicsDAwhVLAd%2F7HjRF6%2BEH7a0ZvfYqqPCpS8HkgpjGN6ifuQf1JGtb8HZbLC9ZapSzwWhCPihrQUYwAqzDmD252Ymkz537sfLPdDeR1g7Oc7%2BorVs2ne5RaT7YzeJY0h9SPdg2AYA8fOvFCFskNuahQetJZSidTr%2BZ8bfBJ5%2BXS1aJibrGou4YLAZ6kyZYWrEEx4XL3rVl3%2Fc13sO0EfQM5UArsPUtoBwsaxbqUWvt%2B2QHdGHu15euEUXhxT79xqs4aOQjQxOuzSntdjYbJ7J%2BrrPpjcGe4tcCRlPzp8Z0G2ZLFZU0TT%2FUKD9Oi%2BeUpi2BukoIWGLxcCT19hhATI%2FNICzAAHSrYUtJ5YWYfgP3tbpyVteuPVdc1l9auPOIpqy50z870YEsWfCKQOfTONxbV4Qvr849XSEc%2BqQF9mjAGaf1x%2B2QTSOjpVjKyvITEsAC1uBlA%2FLFqaxF%2BFb79a6RorX0dTyOfPjlcMdXq4tAx4nxJOoNxZcG8lMLt3jUDQhGggLiuXV1DVcyKdYAkaFXEVEhkUMD9dwiwdBK8On7PCYdMMSAVEu9lkiWpt9R4fy7Azeg6WWfYqjBoVKIpW7fqInTGhm0ElzxwQQOn2CZuHC%2BTWj1eATJPiIDFkiL9o5LEubqduVHN4tY9AGfxrSrHBZHTexBoe%2F73hYWzae3BaYzIzkH%2FTbftgdao6EGymxM15d3dyaZrEM9VJ6Ss15%2FPAQNF%2FHC2ySHCQ3V2z0ozRO6duWUySoBQpyTTkiSMdNDSiEZXwRNRGFpi03hU%2FWpJs3S6kVFhoOQHxCeI7PqBXWeLTmV6qlMhfsJJdGyL0HWjNAuoEGuoqWJ8OKRt2sQd5FYyWp%2BHKFXSwWcNz664olkMEZqgKsOqGjRnq5yK9i%2F8UwB9PA5XYdPsyE%2Fevaltige4BggqM9yUEE72gqdBRvgyHjfS%2F4hiWWDm9NQqTqstL1vQomG5n%2FaYn%2FM1xpwjYn8Ba1yiuPFquRAKF2ePNnhwvk%2FAMNX7aPfCLixwNOfLbZbHLZN94BtP4Nk%2FWS0z0uRj%2FRWgos3ZQA1dld3qxBCL5sQzxl%2B1MEmbXwEf%2BzJ8YtuLJQsgLZ0776PXDxBJvYRpWkk1F7NHITWVftOAx90yk2tk8oXbPwjBosfzDnXKzgJe4xHWB1%2FsQkRDkGFD%2BxG0Ysonwts7yjLKSfVkncfxZVCRfRhJJlKRwfRp0uvLk4YGiad8ZcAh9pEjP0nzclvh%2BLY7G2kfEr%2BPTd2VKOS6FqGa5q5zsrj2fyNWEUAjbrjmJ02sbanmBAdRvbJ5u30E4O9%2Bujs1fdRaIemjk1DbZNju6kRkDSKpWzbJLUiqHwPg78OppAdrDY6XJFxjcF7UAC3Kuqjy4eATG52HjNeAOuE3RA0%2FdPUhAn01J4Z5Vo0csiSag718Q9%2BUYKLVSf%2F%2FI5EzWMjck8qZ8UZ%2ByznowllvPQylE4lnXuKN5b0pPfEa2opfUFxSnTovVb8Ud1q6s3esGuERxnPD%2FTqgAIj2tcT16uH3bTKVBgVh1i3mnG9hYLRNaOzjTBdg7kIZD8DE%2FecaREJj4Qohlyc%2BbOB7kp5tqHA7J%2BEBoAyxYSsHSrIDjaB2B87NhQFC4mmnojcDUqkRyTLE1aKXKGJDG5tbO2tXGDmmS2tHbpy87jjP9Oy18S3y7zMMoEG2QNwP9Qs5ZeAkFF4e%2BB6HLd0%2BI04RjGyJfTvTyS9RKW3SxyTiPAL68WoCmB5%2FU3mYFtDnYpNx8dqDH9cOfRpBXBwwBn7vWjrbdKQDfZCxJTInD1R5TkkeQb8dxzjVxE151UXZiT5gye%2BRRGkJXSogybK5KAzlWUlX4p4AnQEBTKW5TQdQ0c4eFR90uSWPeNL%2BhCmqHWSszsud%2Fq71Z%2BapPkxDsd6sQBfAyP04vGJIXJ9xi%2FDIhObYoZjNmSngRiDXJruvAlK7AWSOB%2F4vVAi1IzzpKpLVUdybLVh6ZLrgqslZ5sa%2FjPKeDrb1wl9qnbNAJ8%2FXKsOPXKTbgkWJwYZ0kUugBBDe0sKwuEUJivklr9r%2BQ8YjneKo7kC%2FYyT0quKjMWBfvtLe5KCiG18seT%2Byw9Eg1u4Lcn7vUZIeKMQGJ1hH2z9vnSwRkS1U8OBGgXfEj9%2F2eX66l4jLffAquZhiOmwk0U%2Fc7QOL3XsXG%2Bz%2BqOY6603fFuefPBPByGerU%2FAkyUG9oG%2BUz9xenWhaYQfuw11JgOuP0%2FeAjVnnQRKR%2Br3eRXvqVdL%2B977sQAeOliwsw%2BmFOvCg5nxbPffYQoz9yVaBiXXe9Yc9s4CHzHmG2Bo3N6gQwHVb7JQlPa4LdE60iRAsnUMXhYFGLcYcQrvAwXCgN%2BIjKWjmQvNoFZ6gb9RmHseu0r5crx90%2FeNiEbxIKUsm5%2Fc6c4Gtdduoq4Kg4nDFo8rlEFlLfOedNrYsw0xCnqXP0wlstZiFzp5R2ljR6XQK1I%2BWdaYLdNP6tBRqeZPH0YphtXs4llAX5iYLmHAyqexsr088LfDE%2BS5joe4Z%2BIyhfv%2BJsexAYs3o9%2Bk8O%2F%2Fs1rGnjce3DPPp1ZDf61D9Y52V4UZwAxViV6Cd%2B1ds%2F3JPk8MVRRqqaQZgIe5oX7R9yDa7IOd%2FkuV19ExKid9Qhmi%2FwuYZACmPyUvrRMWzyuBFq%2B%2BJn5A6eoGQzDYrfxsh63QpZApng%2F13pOcFiSO%2FhHCdZPlKOToMGp2dCp6%2F%2FDYK2gkZv2J0LjnHRt%2B6kcouhub%2FUeRE2cuA1hpT%2Bt6hZEHy%2BEvGz%2FH93KOSATj6Q86dTo6Cgaxxh4Wxnin6rsz67pJGaFZuEt3Rjkb3x591InNQ6Y0NRyOl7AyMLg6MAZtqvFyxgEfdRUoNsU5fH8rKQ0OBdHFFMHzwWfjKEAZztIUIzUge1gWaG1RWJPyV%2F0g%2BQbw5GZrjzSKxJXWtIMXjmcUv%2B%2FOYiG81lWTvbN4c6jkMGylDMrz4xDSzMn6TivHal%2F9MyGs2P8oBK";
  1440. // $sql = common::deCode($ss, 'D');
  1441. // error_log($sql);
  1442. $sql = common::deCode($_POST['tmp_search'], 'D');
  1443. //$sql = substr($sql, 0, strripos($sql, " limit"));
  1444. if(!empty($sql)){
  1445. $rs = common::excuteListSql($sql);
  1446. }
  1447. //去除null
  1448. foreach($rs as $index => $val) {
  1449. foreach($val as $index_2 => $_val) {
  1450. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  1451. $rs[$index][$index_2] = "";
  1452. }
  1453. }
  1454. }
  1455. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  1456. foreach($rs as $index => $val) {
  1457. //返回加密serial_no
  1458. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  1459. //$rs[$index]["mode"] = "Ocean Freight";
  1460. $rs[$index]["Mode"] = $val['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  1461. ($val['transport_mode_extend'] == 'air' ? "Air Freight":
  1462. ($val['transport_mode_extend'] == 'rail' ? "Rail Freight":
  1463. ($val['transport_mode_extend'] == 'road'? "Road Freight": "")));
  1464. //status 改为ocean_milestone里的信息
  1465. $rs[$index]["Status"] = $rs[$index]["new_status"];
  1466. }
  1467. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  1468. exit;
  1469. }
  1470. private function _revenue_download(){
  1471. $r2_cloumn = array();
  1472. $r2_cloumn[] = array("title" => "Month","dataIndex"=>"month");
  1473. $r2_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1474. $r2_cloumn[] = array("title" => "Total Amount","dataIndex"=>"invoice_amount");
  1475. $r3_cloumn = array();
  1476. $r3_cloumn[] = array("title" => "Invoice Issue Date","dataIndex"=>"invoice_date");
  1477. $r3_cloumn[] = array("title" => "Invoice Number","dataIndex"=>"invoice_no");
  1478. $r3_cloumn[] = array("title" => "HBL Number","dataIndex"=>"h_bol");
  1479. $r3_cloumn[] = array("title" => "Amount","dataIndex"=>"ivnoice_amount");
  1480. $r3_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1481. $date_from = null;
  1482. $date_to = null;
  1483. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1484. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1485. $date_from = $date_start."-01";
  1486. }
  1487. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1488. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1489. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1490. }
  1491. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1492. //$sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1493. //$sql = "select * from _test_data_table";
  1494. //$r2_data = common::excuteListSql($sql);
  1495. //只取r3 代码去计总r2 ,避免二次请求数据库
  1496. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r3;";
  1497. //$sql = "select * from _test_data_table_two";
  1498. $r3_data = common::excuteListSql($sql);
  1499. $group_data = array();
  1500. foreach($r3_data as $r3){
  1501. $r3['invoice_date'] = strtoupper(date('M,Y', strtotime($r3['invoice_date'])));
  1502. $group_data[] = $r3;
  1503. }
  1504. //按货币和日期分组
  1505. $groupedItems = array();
  1506. foreach ($group_data as $item) {
  1507. $key = $item['currency']."_".$item['invoice_date'];
  1508. if(array_key_exists($key, $groupedItems)){
  1509. $temp = $groupedItems[$key];
  1510. $temp['invoice_amount'] = $temp['invoice_amount'] + $item['ivnoice_amount'];
  1511. $groupedItems[$key] = $temp;
  1512. }else{
  1513. $groupedItems[$key] = array("month"=>$item['invoice_date'],"currency"=>$item['currency'],"invoice_amount"=>$item['ivnoice_amount']);
  1514. }
  1515. }
  1516. $r2_data = array();
  1517. foreach($groupedItems as $gt){
  1518. $gt['invoice_amount'] = number_format($gt['invoice_amount'], 4, '.', '');
  1519. $r2_data[] = $gt;
  1520. }
  1521. common::echo_json_encode(200,array("msg"=>"success","r2" => $r2_data,"r3"=>$r3_data,"r2_cloumn" => $r2_cloumn,"r3_cloumn" => $r3_cloumn,
  1522. "r2_title"=>"Monthly Summary Data","r3_title"=>"Invoice Detailed Data"));
  1523. exit;
  1524. }
  1525. private function _ams_isf_log(){
  1526. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  1527. $ams_ss = $_POST['ams_ss'];
  1528. $isf_ss = $_POST['isf_ss'];
  1529. $amsLog = array();
  1530. //页面固定写死的信息
  1531. $amsLog_column = array();
  1532. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1533. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1534. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  1535. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  1536. $amsLog["amsLog_column"] = $amsLog_column;
  1537. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1538. $amsLog["data"] = array();
  1539. if (_canViewAMSLog()) {
  1540. $s = $ams_ss;
  1541. //$s = "PDLA200127H";
  1542. if (!empty($s)) {
  1543. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  1544. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  1545. foreach ($cc as $v){
  1546. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  1547. }
  1548. //考虑一个情况
  1549. if (utils::count($amses) > 0) {
  1550. $ams = $amses[0];
  1551. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  1552. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  1553. if (empty($ams[0]['h_bol'])){
  1554. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1555. $amsLog["data"] = array();
  1556. }else{
  1557. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  1558. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  1559. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  1560. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  1561. $amsLog["msg"] = "";
  1562. $amsLog["data"] = $log;
  1563. }
  1564. }
  1565. }
  1566. }
  1567. $isfLog = array();
  1568. //页面固定写死的信息
  1569. $isfLog_column = array();
  1570. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1571. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1572. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  1573. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  1574. $isfLog["isfLog_column"] = $isfLog_column;
  1575. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1576. $isfLog["data"] = array();
  1577. if (_canViewISFLog()) {
  1578. if (!empty($isf_ss)) {
  1579. $ss = $isf_ss;
  1580. $len = strlen($ss);
  1581. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  1582. if (empty($b)){
  1583. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1584. $isfLog["data"] = array();
  1585. }else{
  1586. $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");
  1587. }
  1588. if (!empty($isf)) {
  1589. if (!empty($isf['dob'])){
  1590. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  1591. }
  1592. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  1593. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  1594. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  1595. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  1596. order by cbpreplytime desc, rowid desc");
  1597. $isfLog["msg"] = "";
  1598. $isfLog["data"] = $msg;
  1599. }else{
  1600. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1601. $isfLog["data"] = array();
  1602. }
  1603. }
  1604. }
  1605. $data =array("msg"=>"success",
  1606. "canViewAMSLog" => _canViewAMSLog(),
  1607. "canViewISFLog" => _canViewISFLog(),
  1608. "amsLog" =>$amsLog,
  1609. "isfLog" =>$isfLog);
  1610. common::echo_json_encode(200,$data);
  1611. exit;
  1612. }
  1613. private function getEmail($serial_no) {
  1614. return utils::getEmail($serial_no);
  1615. }
  1616. private function getCommunicationNew($serial_no) {
  1617. $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");
  1618. $emialRecords =array();
  1619. foreach ($list as $k => $v) {
  1620. $msg =array();
  1621. $msg["name"] = $v["add_by"];
  1622. $msg["creatTime"] = $v["add_times"];
  1623. $msg["content"] = urldecode($v["web_content"]);
  1624. $emialRecords[] = $msg;
  1625. }
  1626. return $emialRecords;
  1627. }
  1628. /*
  1629. * get file by hbol/destination
  1630. * H:HBL
  1631. * M: MBL
  1632. * F: FL
  1633. * I: C/I & Packing list
  1634. */
  1635. private function getOceanFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  1636. $_schemas = $_REQUEST['_schemas'];
  1637. $types = strtolower($types);
  1638. $types = explode(";", $types);
  1639. $m_bs = explode(";", $m_bs);
  1640. $otheres = NULL;
  1641. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1642. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1643. $file = array();
  1644. foreach ($types as $k => $type) {
  1645. $m_b = $m_bs[$k];
  1646. if (strtolower($m_b) == 'm')
  1647. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1648. 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";
  1649. if (strtolower($m_b) == 'h')
  1650. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1651. 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";
  1652. if (strtolower($m_b) == 'a')
  1653. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1654. 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";
  1655. if (!empty($sql)) {
  1656. $rss = common::excuteListSql($sql);
  1657. foreach ($rss as $rs) {
  1658. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1659. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1660. "file_name" => $rs['file_name'],
  1661. "format_name" => $rs['format_name'],
  1662. "detail"=>$rs['upload_date'],
  1663. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1664. "from_system" =>'TOPOCEAN_KSMART');
  1665. }else {
  1666. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1667. "file_name" => $rs['file_name'],
  1668. "format_name" => $rs['format_name'],
  1669. "detail"=>$rs['upload_date'],
  1670. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1671. "from_system" =>'');
  1672. }
  1673. }
  1674. }
  1675. }
  1676. return $file;
  1677. }
  1678. /*
  1679. * get file by hbol/destination
  1680. * H:HBL
  1681. * M: MBL
  1682. * F: FL
  1683. * I: C/I & Packing list
  1684. */
  1685. private function getAirFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE) {
  1686. $_schemas = $_REQUEST['_schemas'];
  1687. $types = explode(";", $types);
  1688. $m_bs = explode(";", $m_bs);
  1689. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1690. $file = array();
  1691. foreach ($types as $k => $type) {
  1692. $m_b = $m_bs[$k];
  1693. if (strtolower($m_b) == 'm')
  1694. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1695. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where lower(bol) = '" . strtolower($m_bol) . "' and lower(format_serailno) " . common::getInNotInSql($type) . " and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1696. if (strtolower($m_b) == 'h')
  1697. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1698. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where lower(bol) = '" . strtolower($h_bol) . "' and lower(format_serailno) " . common::getInNotInSql($type) . " and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1699. if (strtolower($m_b) == 'a')
  1700. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1701. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) = '" . strtolower($h_bol) . "') and lower(format_serailno) " . common::getInNotInSql($type) . "and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1702. if (!empty($sql)) {
  1703. $rss = common::excuteListSql($sql);
  1704. foreach ($rss as $rs) {
  1705. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1706. "file_name" => $rs['file_name'],
  1707. "format_name" => $rs['format_name'],
  1708. "detail"=>$rs['upload_date'],
  1709. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1710. "from_system" =>'');
  1711. }
  1712. }
  1713. }
  1714. return $file;
  1715. }
  1716. /*
  1717. * download file
  1718. */
  1719. private function _download() {
  1720. $url = common::deCode($_GET['url'], 'D');
  1721. common::download_file($url);
  1722. }
  1723. private function save_vgm() {
  1724. $schemas = $_POST["schemas"];
  1725. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1726. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1727. $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"] . "'");
  1728. $address = $contact["address_1"];
  1729. if (!empty($address)) {
  1730. $address .= "\r\n";
  1731. }
  1732. $address .= $contact["address_2"];
  1733. if (!empty($address)) {
  1734. $address .= "\r\n";
  1735. }
  1736. $address .= $contact["address_3"];
  1737. if (!empty($address)) {
  1738. $address .= "\r\n";
  1739. }
  1740. $address .= $contact["address_4"];
  1741. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1742. global $db;
  1743. $db->StartTrans();
  1744. if (empty($_POST["is_send"])) {
  1745. $_POST["is_send"] = 'f';
  1746. }
  1747. if (empty($exists)) {
  1748. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1749. $value["serial_no"] = $serial_no;
  1750. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1751. $value["modify_user"] = _getLoginName();
  1752. $value["modify_time"] = "now()";
  1753. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1754. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1755. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1756. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1757. $value["is_send"] = $_POST["is_send"];
  1758. $value["action"] = "New";
  1759. $value["type"] = "Shipper";
  1760. $value["m_bol"] = $ocean["m_bol"];
  1761. $value["master_base_number"] = $ocean["master_base_number"];
  1762. $value["shipper_id"] = $ocean["from_station"];
  1763. $value["shipper"] = $contact["company"];
  1764. $value["shipper_address"] = $address;
  1765. $value["shipper_contactname"] = $contact["contactname_1"];
  1766. $value["shipper_email"] = $contact["email_1"];
  1767. $value["shipper_fax"] = $contact["fax"];
  1768. $value["shipper_telephone"] = $contact["phone_1"];
  1769. $value["update_uuid"] = utils::uuid();
  1770. $value["h_bol"] = $ocean["h_bol"];
  1771. $value["from_station"] = $ocean["from_station"];
  1772. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1773. $db->Execute($sql);
  1774. } else {
  1775. $serial_no = $exists;
  1776. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1777. $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(),"
  1778. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1779. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1780. }
  1781. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1782. foreach ($_POST["container_no"] as $i => $cv) {
  1783. $value1["serial_no"] = $serial_no;
  1784. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1785. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1786. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1787. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1788. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1789. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1790. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1791. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1792. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1793. $value1["master_base_number"] = $ocean["master_base_number"];
  1794. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1795. $db->Execute($sql);
  1796. }
  1797. if ($db->CompleteTrans() === FALSE) {
  1798. return "error";
  1799. } else {
  1800. return "success";
  1801. }
  1802. }
  1803. private function getOceanDetail($serial_no) {
  1804. $order_from = $_REQUEST['_schemas'];
  1805. $_schemas = $_REQUEST['_schemas'];
  1806. if($_schemas == 'public'){
  1807. $_schemas = "ocean";
  1808. }
  1809. $sql = "with o as(
  1810. SELECT o.* from ocean o where serial_no = '" . $serial_no . "'
  1811. )
  1812. SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1813. o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,koe.loadterm
  1814. from o
  1815. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  1816. consignee_uncode,consignee_city,incoterms,
  1817. fport_of_loading_un,
  1818. mport_of_discharge_un,
  1819. place_of_receipt_un,
  1820. place_of_delivery_un,
  1821. etd as oo_etd,
  1822. eta as oo_eta,
  1823. atd as oo_atd,
  1824. ata as oo_ata,
  1825. carbon_emission,
  1826. transport_mode_extend,
  1827. port_of_transshipment_un,
  1828. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1829. (select uncity from $order_from.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  1830. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1831. (select uncity from $order_from.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1832. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1833. (select uncity from $order_from.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  1834. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1835. (select uncity from $order_from.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  1836. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1837. (select uncity from $order_from.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  1838. po_no as _po_no,
  1839. CASE
  1840. 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
  1841. 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
  1842. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1843. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1844. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1845. ELSE 'Created'::text
  1846. END AS new_status
  1847. FROM public.kln_ocean oo WHERE oo.serial_no::text = o.serial_no::text and order_from = '$order_from') oo ON true
  1848. LEFT JOIN LATERAL ( SELECT loadterm
  1849. FROM public.kln_ocean_extend koe WHERE koe.serial_no::text = o.serial_no::text and koe.order_from = '$order_from') koe ON true
  1850. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1851. address_1 as cn_address_1,
  1852. address_2 as cn_address_2,
  1853. address_3 as cn_address_3,
  1854. address_4 as cn_address_4,
  1855. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1856. phone_1 as cn_phone
  1857. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1858. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1859. address_1 as sh_address_1,
  1860. address_2 as sh_address_2,
  1861. address_3 as sh_address_3,
  1862. address_4 as sh_address_4,
  1863. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1864. phone_1 as sh_phone
  1865. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1866. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1867. address_1 as aa_address_1,
  1868. address_2 as aa_address_2,
  1869. address_3 as aa_address_3,
  1870. address_4 as aa_address_4,
  1871. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1872. phone_1 as aa_phone,
  1873. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1874. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1875. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1876. address_1 as dd_address_1,
  1877. address_2 as dd_address_2,
  1878. address_3 as dd_address_3,
  1879. address_4 as dd_address_4,
  1880. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1881. phone_1 as dd_phone,
  1882. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1883. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1884. LEFT JOIN LATERAL ( SELECT
  1885. city as fd_city,
  1886. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1887. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1888. //error_log($sql);
  1889. return $sql;
  1890. }
  1891. private function getAirDetail($serial_no) {
  1892. $order_from = $_REQUEST['_schemas'];
  1893. $_schemas = $_REQUEST['_schemas'];
  1894. if($_schemas == 'public'){
  1895. $_schemas = "ocean";
  1896. }
  1897. $sql = "with o as(
  1898. SELECT oo.*,m_bol as _m_bol, h_bol as _h_bol,
  1899. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1900. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.fport_of_loading_un limit 1) as pol_uncity,
  1901. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1902. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1903. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1904. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_receipt_un limit 1) as por_uncity,
  1905. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1906. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_delivery_un limit 1) as pod_uncity,
  1907. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1908. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.final_desination_uncode limit 1) as _pd_uncity,
  1909. CASE
  1910. 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
  1911. 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
  1912. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1913. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1914. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1915. ELSE 'Created'::text
  1916. END AS new_status
  1917. from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
  1918. )
  1919. SELECT o.* ,sh.*, cn.*,
  1920. aa.*,dd.*,fd.*,air.*
  1921. from o
  1922. LEFT JOIN LATERAL ( SELECT departure_airport_name as fport_of_loading_exp,
  1923. destination_airport_name as mport_of_discharge_exp,
  1924. mawb as _mawb, mawb_name as _mawb_name, hawb as _hawb
  1925. FROM $order_from.air a WHERE a.serial_no = o.serial_no) air ON true
  1926. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1927. address_1 as cn_address_1,
  1928. address_2 as cn_address_2,
  1929. address_3 as cn_address_3,
  1930. address_4 as cn_address_4,
  1931. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1932. phone_1 as cn_phone
  1933. FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
  1934. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1935. address_1 as sh_address_1,
  1936. address_2 as sh_address_2,
  1937. address_3 as sh_address_3,
  1938. address_4 as sh_address_4,
  1939. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1940. phone_1 as sh_phone
  1941. FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
  1942. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1943. address_1 as aa_address_1,
  1944. address_2 as aa_address_2,
  1945. address_3 as aa_address_3,
  1946. address_4 as aa_address_4,
  1947. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1948. phone_1 as aa_phone,
  1949. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1950. FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
  1951. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1952. address_1 as dd_address_1,
  1953. address_2 as dd_address_2,
  1954. address_3 as dd_address_3,
  1955. address_4 as dd_address_4,
  1956. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1957. phone_1 as dd_phone,
  1958. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1959. FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
  1960. LEFT JOIN LATERAL ( SELECT
  1961. city as fd_city,
  1962. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1963. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1964. //error_log($sql);
  1965. return $sql;
  1966. }
  1967. private function returnOceanDetailData($ocean,$state){
  1968. $data = array();
  1969. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  1970. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  1971. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  1972. $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
  1973. $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
  1974. /* Container Status */
  1975. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1976. //记录所有的信息 EDI315TimeAndLocation
  1977. $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
  1978. $data['containerStatusData'] = $EDIDate['containerStatusData'];
  1979. $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
  1980. $VD = $EDIDate['VD'];
  1981. $VA = $EDIDate['VA'];
  1982. //处理shipment data
  1983. $ocean_milestone_status = common::excuteListSql("select code,
  1984. act_date,est_date,timezone
  1985. from ocean_milestone a
  1986. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1987. order by id");
  1988. $ocean_milestone_status_code = array();
  1989. foreach($ocean_milestone_status as $oms){
  1990. $ocean_milestone_status_code[$oms['code']] = $oms;
  1991. }
  1992. if ($state < 1){
  1993. //未发生前
  1994. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1995. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1996. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  1997. }
  1998. } else{
  1999. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  2000. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2001. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  2002. }
  2003. }
  2004. //先处理一下 ATD 和 ATA,在进行后面的取值
  2005. if(empty($ocean['atd']) && !empty($VD)){
  2006. $ocean['atd'] = $VD;
  2007. }
  2008. if(empty($ocean['ata']) && !empty($VA)){
  2009. $ocean['ata'] = $VA;
  2010. }
  2011. $simplexData = array();
  2012. //place_of_Receipt
  2013. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  2014. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  2015. $children = array();
  2016. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  2017. //发生后,未发生前没有
  2018. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  2019. }
  2020. $place_of_Receipt_stauts["children"] = $children;
  2021. $simplexData[] = $place_of_Receipt_stauts;
  2022. //port_of_Loading
  2023. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2024. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2025. $children = array();
  2026. if ($state < 1){
  2027. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  2028. } else{
  2029. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2030. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2031. }
  2032. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  2033. }
  2034. $port_of_Loading_stauts["children"] = $children;
  2035. $simplexData[] = $port_of_Loading_stauts;
  2036. //Port of Discharge
  2037. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2038. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2039. $children = array();
  2040. // if ($state < 2){
  2041. // //未发生前
  2042. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  2043. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  2044. // }else{
  2045. // //没有,取eta
  2046. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2047. // }
  2048. // } else{
  2049. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2050. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2051. // }
  2052. // }
  2053. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  2054. if ($state < 2){
  2055. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2056. }else{
  2057. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2058. }
  2059. $port_of_Discharge_status["children"] = $children;
  2060. $simplexData[] = $port_of_Discharge_status;
  2061. //Place of Delivery
  2062. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2063. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2064. $children = array();
  2065. if ($state < 3){
  2066. //未发生前
  2067. } else{
  2068. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2069. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2070. }
  2071. }
  2072. $simplexData[] = $place_of_Delivery_status;
  2073. $data['shipmentData'] = $simplexData;
  2074. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2075. $_mode = $ocean['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  2076. ($ocean['transport_mode_extend'] == 'air' ? "Air Freight":
  2077. ($ocean['transport_mode_extend'] == 'rail' ? "Rail Freight":
  2078. ($ocean['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  2079. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => $_mode,
  2080. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2081. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  2082. "etd_timezone" =>$ocean['pol_timezone'],
  2083. "atd_timezone" =>$ocean['pol_timezone'],
  2084. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2085. "eta_timezone" =>$ocean['mpod_timezone'],
  2086. "ata_timezone" =>$ocean['mpod_timezone']);
  2087. $data['transportInfo'] = $transportInfo;
  2088. //处理basicInfo信息数据
  2089. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  2090. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  2091. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2092. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2093. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2094. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>$ocean['loadterm'],
  2095. "Shipment Type" =>$ocean['manifest_type'] == "GPE" ? "LCL" : $ocean['manifest_type']);
  2096. $data['basicInfo'] = $basicInfo;
  2097. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2098. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2099. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2100. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2101. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2102. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2103. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2104. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2105. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2106. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2107. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2108. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2109. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2110. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2111. $data['businessPartners'] = $businessPartners;
  2112. //处理routes 转船可能有多个情况
  2113. if ($ocean['is_vessel_direct'] <> "t"){
  2114. //不是直航
  2115. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2116. "destination" => $ocean['port_of_transshipment_un'],
  2117. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2118. "eta" =>$ocean['f_eta'],"ata" =>$EDIDate['VA_RELAY'],
  2119. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2120. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  2121. "destination" => $ocean['consignee_uncode'],
  2122. "etd" => $ocean['m_etd'],"atd" => $EDIDate['VD_RELAY'],
  2123. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2124. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  2125. }else{
  2126. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2127. "destination" => $ocean['consignee_uncode'],
  2128. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2129. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  2130. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2131. }
  2132. $data['routes'] = $routes;
  2133. //处理marksAndDescription
  2134. $notes = common::excuteListSql("select notes from station_data.ocean_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2135. $remark = "";
  2136. foreach($notes as $note){
  2137. if(!empty($note['notes'])){
  2138. $remark.=$note['notes']."\r\n";
  2139. }
  2140. }
  2141. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2142. $data['marksAndDescription'] = $marksAndDescription;
  2143. return $data;
  2144. }
  2145. private function returnAirDetailData($ocean,$ocean_milestone_status,$state){
  2146. $data = array();
  2147. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  2148. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  2149. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  2150. //Origin和Destination的展示,能不能Origin of Cargo有值就用Origin of Cargo,Origin of Cargo就放Departure Airport? Destination也一樣?
  2151. $ocean['shippr_uncode'] = !empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  2152. $ocean['consignee_uncode'] = !empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  2153. //处理shipment data
  2154. $ocean_milestone_status_code = array();
  2155. foreach($ocean_milestone_status as $oms){
  2156. $ocean_milestone_status_code[$oms['code']] = $oms;
  2157. }
  2158. if ($state < 1){
  2159. //未发生前
  2160. if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
  2161. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2162. $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
  2163. }
  2164. } else{
  2165. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2166. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2167. //ATD 取值为IFFONB milestone实际发生的时间
  2168. $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
  2169. }
  2170. }
  2171. $simplexData = array();
  2172. //place_of_Receipt
  2173. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  2174. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  2175. $children = array();
  2176. if($state >= 1 && !empty($ocean_milestone_status_code['IFFCPU']['act_date'])){
  2177. //发生后,未发生前没有
  2178. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFCPU']['act_date']);
  2179. }
  2180. $place_of_Receipt_stauts["children"] = $children;
  2181. $simplexData[] = $place_of_Receipt_stauts;
  2182. //port_of_Loading
  2183. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2184. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2185. $children = array();
  2186. if ($state < 1){
  2187. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['etd']);
  2188. } else{
  2189. if(!empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  2190. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  2191. }
  2192. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2193. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2194. }
  2195. }
  2196. $port_of_Loading_stauts["children"] = $children;
  2197. $simplexData[] = $port_of_Loading_stauts;
  2198. //Port of Discharge
  2199. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2200. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2201. $children = array();
  2202. if ($state < 2){
  2203. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['eta']);
  2204. }else{
  2205. if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2206. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2207. $ocean['ata'] = $ocean_milestone_status_code['IFFARR']['act_date'];
  2208. }else{
  2209. //IFFARR 如果同步异常没有值时,去表里的 ata_date AS ata
  2210. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2211. }
  2212. }
  2213. $port_of_Discharge_status["children"] = $children;
  2214. $simplexData[] = $port_of_Discharge_status;
  2215. //Place of Delivery
  2216. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2217. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2218. $children = array();
  2219. if ($state < 3){
  2220. //未发生前
  2221. } else{
  2222. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2223. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2224. }
  2225. }
  2226. $simplexData[] = $place_of_Delivery_status;
  2227. $data['shipmentData'] = $simplexData;
  2228. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2229. $_mode = $ocean['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  2230. ($ocean['transport_mode_extend'] == 'air' ? "Air Freight":
  2231. ($ocean['transport_mode_extend'] == 'rail' ? "Rail Freight":
  2232. ($ocean['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  2233. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => $_mode,
  2234. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2235. "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
  2236. "etd_timezone" =>$ocean['pol_timezone'],
  2237. "atd_timezone" =>$ocean['pol_timezone'],
  2238. "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
  2239. "eta_timezone" =>$ocean['mpod_timezone'],
  2240. "ata_timezone" =>$ocean['mpod_timezone']);
  2241. $data['transportInfo'] = $transportInfo;
  2242. //处理basicInfo信息数据
  2243. $vessel = $ocean['vessel'];
  2244. $voyage = $ocean['voyage'];
  2245. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2246. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2247. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2248. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>"",
  2249. "Shipment Type" =>"");
  2250. $data['basicInfo'] = $basicInfo;
  2251. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2252. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2253. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2254. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2255. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2256. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2257. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2258. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2259. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2260. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2261. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2262. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2263. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2264. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2265. $data['businessPartners'] = $businessPartners;
  2266. //处理routes air不存在中转的
  2267. $routes = array(array("mode" =>"Air Freight","mode_label" =>"Air", "origin" =>$ocean['shippr_uncode'],
  2268. "destination" => $ocean['consignee_uncode'],
  2269. "etd" => $ocean['etd'],"atd" => $ocean['atd'],
  2270. "eta" => $ocean['eta'],"ata" => $ocean['ata'],
  2271. "vessel" =>$ocean['vessel'],"voyageNo" =>$ocean['voyage']));
  2272. $data['routes'] = $routes;
  2273. //处理marksAndDescription
  2274. $notes = common::excuteListSql("select notes from station_data.air_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2275. $remark = "";
  2276. foreach($notes as $note){
  2277. if(!empty($note['notes'])){
  2278. $remark.=$note['notes']."\r\n";
  2279. }
  2280. }
  2281. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2282. $data['marksAndDescription'] = $marksAndDescription;
  2283. return $data;
  2284. }
  2285. private function getUploadFolder() {
  2286. $sql = "SELECT ra_value from ra_online_config where lower(ra_name) = 'upload_document'";
  2287. return common::excuteOneSql($sql);
  2288. }
  2289. }
  2290. ?>