ocean_order.class.php 176 KB

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