ocean_order.class.php 174 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870
  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, "Departed") !== 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($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"=>"Departed","number"=>intval($Departed),"type"=>"departed","checked"=>utils::in_array('Departed', $_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($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"=>"Departed","number"=>intval($Departed),"type"=>"departed","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. COALESCE(oe.import_po_no,po_no) as _po_no,
  1004. (select user_login from public.kln_user_subscribed us
  1005. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  1006. CASE
  1007. 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
  1008. 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
  1009. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departed'::text
  1010. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1011. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1012. ELSE 'Created'
  1013. END AS new_status, ".
  1014. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  1015. from public.kln_ocean
  1016. LEFT JOIN LATERAL ( SELECT loadterm,
  1017. manifest_type,
  1018. volume,
  1019. last_mile_delivery_date,
  1020. container_size,
  1021. import_po_no
  1022. 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 "
  1023. . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.")
  1024. select oo.* ,
  1025. case when oo.transport_mode ='sea'
  1026. then ( SELECT string_agg(DISTINCT code || value,', ' ORDER BY code || value) AS other_refenrence_no FROM public.reference_all temp
  1027. WHERE temp.code <> 'PO'
  1028. AND COALESCE(temp.value,'')<>''
  1029. AND temp.value IS NOT NULL
  1030. AND LENGTH(TRIM(BOTH FROM temp.value)) > 0
  1031. AND temp.serial_no = oo.serial_no)
  1032. when oo.transport_mode ='air'
  1033. then ''
  1034. else ''
  1035. end as \"Other refenrence No.\"
  1036. from oo";
  1037. $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,
  1038. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,piece_count as _piece_count,
  1039. f_vessel as _f_vessel, f_voyage as _f_voyage,
  1040. COALESCE(oe.import_po_no,po_no) as _po_no,
  1041. (select user_login from public.kln_user_subscribed us
  1042. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  1043. CASE
  1044. 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
  1045. 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
  1046. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departed'::text
  1047. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1048. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1049. ELSE 'Created'
  1050. END AS new_status, ".
  1051. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  1052. from public.kln_ocean
  1053. LEFT JOIN LATERAL ( SELECT loadterm,
  1054. manifest_type,
  1055. volume,
  1056. last_mile_delivery_date,
  1057. container_size,
  1058. import_po_no
  1059. 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 "
  1060. . $sqlWhere . " order by $order_by)
  1061. select oo.* ,
  1062. case when oo.transport_mode ='sea'
  1063. then ( SELECT string_agg(DISTINCT code || value,', ' ORDER BY code || value) AS other_refenrence_no FROM public.reference_all temp
  1064. WHERE temp.code <> 'PO'
  1065. AND COALESCE(temp.value,'')<>''
  1066. AND temp.value IS NOT NULL
  1067. AND LENGTH(TRIM(BOTH FROM temp.value)) > 0
  1068. AND temp.serial_no = oo.serial_no)
  1069. when oo.transport_mode ='air'
  1070. then ''
  1071. else ''
  1072. end as \"Other refenrence No.\"
  1073. from oo";
  1074. //$rs = common::excuteListSql($sql);
  1075. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  1076. error_log("online_ocean_search_SQL: ".$sql);
  1077. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  1078. foreach($rs as $index => $val) {
  1079. //返回加密serial_no
  1080. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  1081. //$rs[$index]["mode"] = "Ocean Freight";
  1082. $rs[$index]["Mode"] = $val['transport_mode_extend'] == 'sea' ? "Ocean Freight" : ($val['transport_mode_extend'] == 'air' ? "Air Freight":
  1083. ($val['transport_mode_extend'] == 'rail' ? "Rail Freight":
  1084. ($val['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  1085. $rs[$index]["Vessel/Airline"] = utils::outDisplayForMerge($val['_f_vessel'],$val['Vessel/Airline']);
  1086. $rs[$index]["Voyage/Flight"] = utils::outDisplayForMerge($val['_f_voyage'],$val['Voyage/Flight']);
  1087. //po_no 处理 有import 显示import
  1088. $rs[$index]["PO No."] = $rs[$index]["_po_no"];
  1089. //status 改为ocean_milestone里的信息
  1090. $rs[$index]["Status"] = $rs[$index]["new_status"];
  1091. if($val['transport_mode'] == 'sea'){
  1092. $rs[$index]["Chargeable Weight"] = $rs[$index]["_piece_count"];
  1093. }
  1094. $rs[$index]["Shipment Type"] = $rs[$index]["Shipment Type"] == 'GPE' ? 'LCL' : $rs[$index]["Shipment Type"];
  1095. //订阅的参数
  1096. if(empty($rs[$index]["is_subscribe"])){
  1097. $rs[$index]['is_subscribe'] = false;
  1098. }else{
  1099. $rs[$index]['is_subscribe'] = true;
  1100. }
  1101. //这个不影响,不会deCode两次,取得是临时变量的__serial_no,加这个是为了订阅
  1102. $rs[$index]["a"] = common::deCode($val['__serial_no'], 'E');
  1103. }
  1104. $arrTmp = array('searchData' => $rs,
  1105. 'tagsList' => $tagsList,
  1106. 'TransportList' => $TransportList,
  1107. 'allColums' => $allBookingColumns,
  1108. 'IncotermsList' =>$IncotermsList,
  1109. 'ServiceList' =>$ServiceList,
  1110. 'canEdiVgm' => _canEdiVgm(),
  1111. 'rc' => $search_rc,
  1112. 'ps' => $ps,
  1113. 'cp' => $cp,
  1114. 'tp' => $tp,
  1115. 'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
  1116. 'type' => common::check_input($_POST ['_ntype']));
  1117. } else {
  1118. $arrTmp = array('searchData' => array(),
  1119. 'tagsList' => $tagsList,
  1120. 'TransportList' => $TransportList,
  1121. 'IncotermsList' =>$IncotermsList,
  1122. 'ServiceList' =>$ServiceList,
  1123. 'allColums' => $allBookingColumns,
  1124. 'canEdiVgm' => _canEdiVgm(),
  1125. 'rc' => $search_rc,
  1126. 'ps' => $ps,
  1127. 'cp' => $cp,
  1128. 'tp' => $tp,
  1129. 'tmp_search' => "",
  1130. 'type' => common::check_input($_POST ['_ntype']));
  1131. }
  1132. common::echo_json_encode(200,$arrTmp);
  1133. exit();
  1134. }
  1135. private function _ocean_detail() {
  1136. $serial_no = common::deCode($_GET['a'], 'D');
  1137. $sql = $this->getOceanDetail($serial_no);
  1138. $ocean = common::excuteObjectSql($sql);
  1139. //(本质是是底表ocean 和 kln_oceans数据没有及时同步,详细页面有查询的ocean的时间照成的时间不一致),
  1140. //单独处理一些,用kln_ocean里面的字段,与查询页面保持一致: etd as oo_etd, eta as oo_eta,atd as oo_atd,ata as oo_ata,
  1141. //这样改动最小
  1142. //这个是同步问题,同步是实时的
  1143. //$ocean["f_etd"] = $ocean["oo_etd"];
  1144. //$ocean["m_eta"] = $ocean["oo_eta"];
  1145. //$ocean["atd"] = $ocean["oo_atd"];
  1146. //$ocean["ata"] = $ocean["oo_ata"];
  1147. if (!empty($ocean)) {
  1148. $ocean['_isf_bol'] = $ocean['isf_bol'];
  1149. if (empty($ocean['_isf_bol'])) {
  1150. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  1151. }
  1152. $isf_ss = md5(md5($ocean['_isf_bol']));
  1153. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  1154. //ETA Dest的计算逻辑移除
  1155. // most update status
  1156. $_schemas = $_REQUEST["_schemas"];
  1157. $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 "
  1158. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.kln_ocean "
  1159. . "where serial_no= '" . $ocean["serial_no"] . "'";
  1160. if (!empty($_schemas)) {
  1161. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  1162. }
  1163. $mostStatus = common::excuteObjectSql($mostStatusSql);
  1164. $state = -1;
  1165. if (!empty($mostStatus["last_status_315_code"])) {
  1166. //desc 逻辑处理取消
  1167. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  1168. }
  1169. //请求地图是需要的参数
  1170. $uncode = "'";
  1171. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  1172. $uncode .= $mostStatus["place_of_receipt_un"];
  1173. }
  1174. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  1175. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  1176. $uncode .= $mostStatus["place_of_delivery_un"];
  1177. }
  1178. $uncode .= "'";
  1179. }
  1180. $vueData = $this->returnOceanDetailData($ocean,$state);
  1181. //处理shipment data暂时写死
  1182. $simplexData = $vueData['shipmentData'];
  1183. //处理transportInfo信息数据
  1184. $transportInfo = $vueData['transportInfo'];
  1185. //处理basicInfo信息数据
  1186. $basicInfo = $vueData['basicInfo'];
  1187. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1188. $businessPartners = $vueData['businessPartners'];
  1189. //处理routes 转船可能有多个情况
  1190. $routes = $vueData['routes'];
  1191. //处理marksAndDescription
  1192. $marksAndDescription = $vueData['marksAndDescription'];
  1193. //处理containerStatusData
  1194. $containerStatusData = $vueData['containerStatusData'];
  1195. //处理ocean_reference
  1196. $ref_no = array();
  1197. if(!empty($ocean['_invoice_no'])){
  1198. $ref_no[] = array("label"=>"Invoice No.","value"=>$ocean['_invoice_no']);
  1199. }
  1200. $ref_arr = common::excuteListSql("select code,value from public.reference_all where code <> 'PO'
  1201. and COALESCE(value,'')<>''
  1202. AND value IS NOT NULL
  1203. AND LENGTH(TRIM(BOTH FROM value)) > 0
  1204. and lower(serial_no) = '" . strtolower($serial_no) . "' group by code,value");
  1205. if(!empty($ref_arr)){
  1206. foreach($ref_arr as $ref) {
  1207. $ref_no[] = array("label"=>$ref["code"],"value"=>$ref["value"]);
  1208. }
  1209. }
  1210. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  1211. $ocean_container_column = array();
  1212. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  1213. //特殊处理po_no,配置column在查询的时候,不好
  1214. $container_column[] = array("database_column_name" => "po_no","name"=>"PO No.");
  1215. $container_column_config = array("Quantity" => array("formatter"=>"number","digits"=>0),
  1216. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1217. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1218. "CBM" => array("formatter"=>"number","digits"=>3),
  1219. "CFT" => array("formatter"=>"number","digits"=>3));
  1220. foreach($container_column as $cc){
  1221. $cc['name'] = $cc['database_column_name'] == "grs_kgs" ? "Gross Weight(KGS)" : ($cc['database_column_name'] == "grs_lbs" ? "Gross Weight(LBS)" : $cc['name']);
  1222. if(!empty($container_column_config[$cc['name']])){
  1223. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],
  1224. "formatter" =>$container_column_config[$cc['name']]["formatter"],
  1225. "digits" =>$container_column_config[$cc['name']]["digits"],
  1226. "type" =>"normal");
  1227. }else{
  1228. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  1229. }
  1230. }
  1231. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",
  1232. net_lbs,po_no as oc_po_no,
  1233. (select po_no from oc_container_item where oc_container_id = oc_container.id) as item_po_no
  1234. from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  1235. $rss = common::excuteListSql($sql);
  1236. $quantity_unit = array();
  1237. $g_weight_tolal = 0;
  1238. $ch_weight_tolal = 0;
  1239. $ch_weight_tolal_grs_lbs = 0;
  1240. $cbm_tolal = 0;
  1241. foreach ($rss as $key => $rs) {
  1242. //特殊处理po_no
  1243. $rss[$key]['po_no'] = utils::outDisplayForMergeForDISTINCT($rs['oc_po_no'],$rs['item_po_no']);
  1244. $unit = $rs['unit'];
  1245. if (array_key_exists($unit, $quantity_unit)) {
  1246. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  1247. } else {
  1248. $quantity_unit[$unit] = $rs['qty'];
  1249. }
  1250. $g_weight_tolal += $rs['grs_kgs'];
  1251. $ch_weight_tolal += $rs['net_lbs'];
  1252. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  1253. $cbm_tolal += $rs['cbm'];
  1254. //特殊处理weight
  1255. if(!empty($rss[$key]['grs_kgs'])){
  1256. $rss[$key]['grs_kgs'] = $rs['grs_kgs'];
  1257. }
  1258. if(!empty($rss[$key]['grs_lbs'])){
  1259. $rss[$key]['grs_lbs'] = $rs['grs_lbs'];
  1260. }
  1261. //为每个柜子下面单独加状态信息 ctnr_label content
  1262. $rss[$key]['containerStatusData'] = array();
  1263. foreach($containerStatusData as $_containerStatusData){
  1264. if(trim($_containerStatusData["ctnr_label"]) == trim($rs["ctnr"])){
  1265. $rss[$key]['containerStatusData'] = $_containerStatusData["content"];
  1266. }
  1267. }
  1268. }
  1269. $quantity_tolal = "";
  1270. foreach($quantity_unit as $uk => $uv){
  1271. // 使用substr()截取第一次出现之前的字符串
  1272. $uk = substr($uk, 0, strpos($uk, "-"));
  1273. $quantity_tolal.=$uv." ".$uk." ";
  1274. }
  1275. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  1276. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  1277. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  1278. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  1279. //Containers信息
  1280. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  1281. //Packing信息 ocean G和 Ch Weight 改成一样
  1282. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $g_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  1283. //Milestones info 列名固定
  1284. $Milestones = common::getMilestonesInfo($ocean,"sea",$_schemas,$vueData['EDI315TimeAndLocation']);
  1285. //页面固定写死的信息
  1286. $document_column = array();
  1287. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1288. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1289. $document_data = array();
  1290. $document = _getViewDocType($_REQUEST["_schemas"]);
  1291. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1292. $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'])."'");
  1293. if (!empty($document)) {
  1294. foreach ($document as $v) {
  1295. $file_type = $v['display_name'];
  1296. $file_arr = $this->getOceanFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  1297. $tar = json_decode($ocean_can_view_file,true);
  1298. if(!empty($tar[$v['display_name']])){
  1299. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1300. switch ($v['display_name']) {
  1301. case 'HBL':
  1302. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1303. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1304. from ra_online_doc_upload
  1305. 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']."'
  1306. order by id desc";
  1307. break;
  1308. case 'MBL':
  1309. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1310. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1311. from ra_online_doc_upload
  1312. 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']."'
  1313. order by id desc";
  1314. break;
  1315. case 'Others':
  1316. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1317. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1318. from ra_online_doc_upload
  1319. 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']."'
  1320. order by id desc";
  1321. break;
  1322. default:
  1323. $sql = "";
  1324. break;
  1325. }
  1326. if (!empty($sql)) {
  1327. $rss = common::excuteListSql($sql);
  1328. foreach ($rss as $rs) {
  1329. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1330. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  1331. "file_name" => $rs['file_name'],
  1332. "format_name" => $rs['format_name'],
  1333. "detail"=>$rs['upload_date'],
  1334. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1335. "from_system" =>'TOPOCEAN_KSMART');
  1336. }else{
  1337. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1338. "file_name" => $rs['file_name'],
  1339. "format_name" => $rs['format_name'],
  1340. "detail"=>$rs['upload_date'],
  1341. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1342. "from_system" =>'');
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1349. //按现在的逻辑,有值才会显示
  1350. foreach($file_arr as $f){
  1351. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1352. }
  1353. }
  1354. }
  1355. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1356. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  1357. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  1358. $email = $this->getEmail($ocean["serial_no"]);
  1359. $email['cc_email'] = $cc_email;
  1360. $email['emailRecords'] = $emailRecords;
  1361. global $_COPYRIGHT;
  1362. $data = array('transportInfo' => $transportInfo,
  1363. 'basicInfo' => $basicInfo,
  1364. 'businessPartners' => $businessPartners,
  1365. 'ref_no' => $ref_no,
  1366. 'packing' => $packing,
  1367. 'marksAndDescription' => $marksAndDescription,
  1368. 'containers' => $containers,
  1369. 'simplexData' =>$simplexData,
  1370. 'containerStatusData' => $containerStatusData,
  1371. 'document_info' => $document_info,
  1372. 'Milestones' => $Milestones,
  1373. 'routes' => $routes,
  1374. 'email' => $email,
  1375. 'ams_ss' => md5(md5($ocean['serial_no'])),
  1376. 'isf_ss' => $isf_ss,
  1377. 'transport_mode' =>"sea",
  1378. '_schemas' =>$_schemas,
  1379. 'uncode' =>$uncode,
  1380. 'serial_no' =>$serial_no,
  1381. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1382. 'a' =>common::deCode($serial_no, 'E'),
  1383. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1384. 'canEdiVgm' => _canEdiVgm(),
  1385. 'canViewAMSLog'=>_canViewAMSLog(),
  1386. 'canViewISFLog'=>_canViewISFLog(),
  1387. 'copyright' =>$_COPYRIGHT,
  1388. 'website' =>common::getWebiste($ocean['m_carrier']));
  1389. common::echo_json_encode(200,$data);
  1390. exit();
  1391. }
  1392. private function _air_ocean_detail(){
  1393. $serial_no = common::deCode($_GET['a'], 'D');
  1394. $sql = $this->getAirDetail($serial_no);
  1395. $air = common::excuteObjectSql($sql);
  1396. //根据air_milestone 判断 shipment status的state
  1397. $_schemas = $_REQUEST["_schemas"];
  1398. $air_milestone_status = common::excuteListSql("select code,
  1399. act_date,est_date,timezone
  1400. from air_milestone a
  1401. where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
  1402. order by id");
  1403. $state = -1;
  1404. if (!empty($air_milestone_status)) {
  1405. $state_arr = array();
  1406. foreach($air_milestone_status as $ms){
  1407. if($ms['code'] == "IFFCPU"){
  1408. $state_arr[] = 0;
  1409. }
  1410. if($ms['code'] == "IFFREC" || $ms['code'] == "IFFONB"){
  1411. $state_arr[] = 1;
  1412. }
  1413. if($ms['code'] == "IFFARR"){
  1414. $state_arr[] = 2;
  1415. }
  1416. if($ms['code'] == "IFFDEL"){
  1417. $state_arr[] = 3;
  1418. }
  1419. }
  1420. $state = max($state_arr);
  1421. }
  1422. $vueData = $this->returnAirDetailData($air,$air_milestone_status,$state);
  1423. //处理shipment data暂时写死
  1424. $simplexData = $vueData['shipmentData'];
  1425. //处理transportInfo信息数据
  1426. $transportInfo = $vueData['transportInfo'];
  1427. //处理basicInfo信息数据
  1428. $basicInfo = $vueData['basicInfo'];
  1429. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1430. $businessPartners = $vueData['businessPartners'];
  1431. //处理routes 转船可能有多个情况
  1432. $routes = $vueData['routes'];
  1433. //处理marksAndDescription
  1434. $marksAndDescription = $vueData['marksAndDescription'];
  1435. $quantity_tolal = empty($air['qty']) ? "" : $air['qty'].$air['qty_uom'];
  1436. $g_weight_tolal = empty($air['piece_count']) ? "" : sprintf("%.3f", $air['piece_count'])." KGS";
  1437. $ch_weight_tolal = empty($air['piece_count']) ? "": sprintf("%.3f", $air['weight'])." KGS";
  1438. $cbm_tolal = empty($air['cbm']) ? "" : sprintf("%.4f", $air['cbm'])." CBM";
  1439. //Packing信息
  1440. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
  1441. //Milestones info 列名固定
  1442. $Milestones = common::getMilestonesInfo($air,"air",$_schemas);
  1443. //页面固定写死的信息
  1444. $document_column = array();
  1445. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1446. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1447. $document_data = array();
  1448. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  1449. $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'])."'");
  1450. if (!empty($document)) {
  1451. foreach ($document as $v) {
  1452. $file_type = $v['display_name'];
  1453. $file_arr = $this->getAirFileByHbol($air['_mawb'] . '-' . $air['_mawb_name'], $air['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE);
  1454. $tar = json_decode($air_can_view_file,true);
  1455. if(!empty($tar[$v['display_name']])){
  1456. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1457. switch ($v['display_name']) {
  1458. case 'HBL':
  1459. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1460. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1461. from air_doc_upload
  1462. 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']."'
  1463. order by id desc";
  1464. break;
  1465. case 'MBL':
  1466. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1467. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1468. from air_doc_upload
  1469. 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']."'
  1470. order by id desc";
  1471. break;
  1472. case 'Others':
  1473. $sql = "SELECT
  1474. (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['_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']."'
  1478. order by id desc";
  1479. break;
  1480. default:
  1481. $sql = "";
  1482. break;
  1483. }
  1484. if (!empty($sql)) {
  1485. $rss = common::excuteListSql($sql);
  1486. foreach ($rss as $rs) {
  1487. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1488. "file_name" => $rs['file_name'],
  1489. "detail"=>$rs['upload_date'],
  1490. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1491. "from_system" =>'');
  1492. }
  1493. }
  1494. }
  1495. }
  1496. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1497. //按现在的逻辑,有值才会显示
  1498. foreach($file_arr as $f){
  1499. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1500. }
  1501. }
  1502. }
  1503. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1504. $emailRecords = $this->getCommunicationNew($air["serial_no"]);
  1505. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $air["serial_no"] . "' order by id desc limit 1");
  1506. $email = $this->getEmail($air["serial_no"]);
  1507. $email['cc_email'] = $cc_email;
  1508. $email['emailRecords'] = $emailRecords;
  1509. global $_COPYRIGHT;
  1510. $data = array('transportInfo' => $transportInfo,
  1511. 'basicInfo' => $basicInfo,
  1512. 'businessPartners' => $businessPartners,
  1513. 'ref_no' => array(),
  1514. 'packing' => $packing,
  1515. 'marksAndDescription' => $marksAndDescription,
  1516. 'containers' => array(),
  1517. 'simplexData' =>$simplexData,
  1518. 'containerStatusData' => array(),
  1519. 'document_info' => $document_info,
  1520. 'containers' => array(),
  1521. 'Milestones' => $Milestones,
  1522. 'routes' => $routes,
  1523. 'email' => $email,
  1524. 'ams_ss' =>"",
  1525. 'isf_ss' => "",
  1526. '_schemas' =>$_schemas,
  1527. 'uncode' =>"",
  1528. 'transport_mode' =>"air",
  1529. 'serial_no' =>$serial_no,
  1530. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1531. 'a' =>common::deCode($serial_no, 'E'),
  1532. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1533. 'canEdiVgm' => _canEdiVgm(),
  1534. 'canViewAMSLog'=>_canViewAMSLog(),
  1535. 'canViewISFLog'=>_canViewISFLog(),
  1536. 'copyright' =>$_COPYRIGHT,
  1537. 'website' =>"");
  1538. common::echo_json_encode(200,$data);
  1539. exit();
  1540. }
  1541. private function _ocean_excel() {
  1542. //$ss = "CTsJcU0mEqD3aJmJClY%2F7VDgtwMSlzvZ0XSGJyrsru29di5bQCy%2F96%2BEzjFomfp6tinP89uz1oCrCpnbBt6I%2FEfVv%2FR7Xmb0CJa48I9sgCdMjAxDGDL%2FjdC%2B49sDMhC4QSOjd84JFr6HXw76ONyeXTiOEXE0ehhC2Tr9Ml0in11cD%2B%2Ff7IkTHqEZteC80zS58%2Fa2SJdjTW%2Be%2FrDFIdR2qvdcgGrNuhQf8e%2BaMvs9YF7dsmgQepGnnBUHEzoKOFgJSnQRqgVWWmaPdiKlyDleomDDAmLXKsslkLEbfV%2BdDOopAr03h7OfoCEMICm9AZdmSgZ2TnXqq435OUDXxKlWf8LBmJ9jplEsHswHe0RWqmPyCO%2FcBZFaiM3u2jlA8%2BQN3UD6mcTiBfvvtgoNlSxOEtmxrU9UJ2PToWwHTRDQK4Id57HTaHpKbbmX16aiB0JUDl0YEMgKRYjhElnBbg%2FXIix%2BrWHSEzqRRaLC1yNvrgzzxBM5gO5idWwSH1u%2B8fNCbz8tvNhdcsGJX5cMC%2BsjT3fLKwnJ2wbhOZAXpOnpxZQnXoqa1BP8dODPWGvB4RSTwYYLDXZkgDm8CCSEfyeKZccKUAfxsQla3H7M1YtEXYBf2IISs3apqtUp8%2F3Rh%2BBDxt96GCDMWevfO%2BSRQ5ZFCdTvu1EZJvO%2BBPIrXV9%2BGOayrgbyxD9gzaEozyW7kfOQDcz6fwWmNRScj6BE7aGDibblj3PsOLuAVb9qDqVE7zTq%2B1Q4jFxw%2BW3Emk%2BDonM3nJIEtESu6RDhznH%2Bb88wmk9iayfK32Y9iAbdlEkyVVGOPf8WPCbB%2BTT89iI1yNvSuhx3qFnhflSmS6bFW0wnpsENcy5a7HPbnX8m5JjhSWwE79MNOCVo8%2FittdCN%2FsaMSDQeGdOr%2BxIvlfazwMGJ%2FZ90HZ6i2xWI6NAjlTIgtAoDT26Tw9qg2sBnVLK1a%2Fxk%2B3pqEu3pTLNoFvKxcmGjPscCwmYjxSYtVUvv7LNlJlzcjgMEt486%2BGtX470JhysAyIwvrCW6nmU0rR9Udd5O3TzsEm8O0sd7tmJD8EN%2FEjUXkdI5wlVB53TlS51Dz%2BdSTChZ8tlK8jcCpXPVvXZ%2BqsCunIuKYHPu%2FiZ9PxduYfR%2BoemGOSqA8av4J%2FJQb%2BzUes5maKNMDkb3w5h379rnQyhYlYvGh8Tb4MSmA5yeB2A4w0Ygm5F7MutO3OSIe8sS7eYuW7a43dbgmwE3%2FI4ibAaSnZ1x6VuHYqo56mVXbnjgLqhFSsr9R1q1zMsZZ8da6yWerW8nuZID6SssTZq4%2FFLTXNcABUyis9xZSCdtftYepCtvB3cNL8AbAZ0Ibu6AiuQanRY6gHIT2BXBKNYSf84RCPCY9ZkKdvR50pthG8gqBbJT5MRCGRRa1XQgPKVQIxME4HQoQYscfwRII4KPh3v0N9DplcgGU0magp1FOSW6czD2gL5m0Eoxyyu9%2BRYPxpn78p0ekywTtmOYXH0eo3P1bwgU%2FwBkHoTt1TeSA8C9FiFIEXaIEz9Yns0nlFcl6SQneq%2FkyANLxtg923sp0PguWyC50idW8q3w3Tr8KCIb837B%2B1ChUvXGypWF2bAlhGmvTQBrcygecqxZ5MlpiMSN4m44ksE8yjMi362jlOgGuAN%2FxbfS2Fc3JL0vuiYLtYnQk%2BkibAOD%2FFXfZL%2Ff9ELqsjX9HWx3q%2FzWiqoDz4sw1TZnWi3AN7dn6CRE06PpfyHcenQh60M%2FyeRh18oiKUcWBoBFxMNSkyUWJCy7vyOBeHzYkaov5ykjeqPO4NxyhZG4GPHqJroAqJVBqAKFP%2FYd%2FCl28l1DSBoKAhGCj8nBkOet1M7wfOMK54RVz3MRPVTrlp3C7A5oSI0PBBOkE6ZXnxT9bnoITGPA800X3O104%2FLnFYL%2BXN1xDghMqvOttmHCXPVN8872yfsajdB05%2B%2FagGKXZeFmVoejGDJX8PdPyqxsAv25dMuv2a87BHpx%2BhkKw%2FjThVHSr1U6f2t108E8fz%2BAe5aPzUpjTIhSLu3TFYwhdng0Uz68lHXjujbrHM2pMJ6B4km1wPlPEBiH8OExoDfpITjjDRi%2FnlhSf3rKKunPA7tcXbH51Y2vrs655cJNU%2Bf%2BE2wpj0Zt6vbQv6gcK9vpbM64mXOAjJiG%2BnrbrKpbA4p36jZcQF0Jp5%2Bxhy21syoLwtoVMrrpiuDaYhaqfGXVXOqDkKc2gF78x88OVq%2F8pcYdUQFvoWENSJvsShYaHIWY0NJUuEaRUvVbxj694vVykWL2opXl%2FwDufxZwVCyxvecZ9V5J1diD6m8sGeooQJ4sRh3NbXd6pSIuYsPkFp8T93VSbymR%2BmQUInKITcpmY%2FCUVJGeECZ4fW8TU59VN1LBSJCZXA7HjV38XkWuQfP8sg9Ml9kSVC8myDQILR%2FehW%2BKliI9zzV6pRNhroaal9WH2%2FL%2F9H4K2f4Ppku4LNaAit2wax403L06dzJ8XoiY%2BCXgBB2OJNC1C39PujEYf%2BCPdJd3%2BYoDg%2BC4xeYY5SxoweDFv1JsPBkdSz7ggqgBKFNIyKzvL7KE0XmfoycxXE0zB7J8wLPxTlzwGn3Yud7QZLKZEYrwVw0VhHUoge3CfXBa%2B%2B4tY67V%2BdOSLTIa0iL0k7oXOj4pjWmhzcSYjgn017gCIvlOe2Eh6PYxq8OZ%2FWfZrFK814%2FMMpV36yPLz2gFRses81OJsVFuWwZM4rgXpfvr%2BZ8YeA1K%2Fm%2F0fZ7Irkk0rcyhcIM9BJTsMVdsWJf2FRy6Ok%2F2aAV4U9IBUNIyE%2F43psi9IbgdtemrBWIVX7wWKscxey0g6%2B8t8dLPHHExKezYtZV7MvMqQ63bOJTTDP8gPyg8XHE5eEHtaPBOFhXzzVmSuKmcDTEEkUi2oIeCBBACAR5d1EP89MoInmxEROdZ%2BIhCfJClLiga9lYmU%2BebPJ4ure6SC4VmjqMvtcAjA8OXQZoVDHTZlfZ4Q66x3ebdHYrrXBlknQWLblpgjWiRNGgW3q%2BVJzAbGB1hDRkwOFrZ4BrOWLgI01VqG0s%2Fwe%2FHghkKJHa6ggpmjm8N5vBYa2ovO78li1bQx0hlfg2RRkHVSD3NQUJFVnwABF4QYTNf9xQ4ReZxlaH8JdcTAVFkneEZwDJ%2BpxoNn%2FcHSRucUbNli0lxb6VN%2Fv6OjXzjm3Yt0AtbCbu3HImHSNSX32S9aMPsLHN9i5l9%2BqRrL7U9VgdVg6IHKKpdQ%2FqKLGOdmlgH9JH3aWmJaWoVL0Q3kCyUQpsTPJ07EHGwj443Ij43btXEJIEOzCNw7aLMQvx9DhbhaHSWxQy%2Fk5KQd49LeRKrzkADzTCwnSMfOkejC4zuR5pTRezv5wM9P%2BFakHDwZFViOQbmHKwpPugcZs36qHmwrose9dFODWOiKGPgFLNLHbleCL0SPxJrpA48GYGWp%2BHNDmHlVdVzqIlnwHQHKowzjOqGjQj35mG5p7xZ9CV%2FAdiLJ7EcEei5ayRWjfMfyh%2Fd%2Byc8BL2gqMpT81%2FEwNmk6g2fWD2AOgbHhI5Dwrx%2B%2Fic05K4n9N99uxKl24JF0m2sKiXvZhaFxKXJnkgtnMAsCi%2FWSuGQjRoKa7GJZovPbNNpBtP4Nk%2FYTEnj%2FFG%2BU3Ys8EpcBFdSbTe9RTy4%2FTHlk%2F1TJGDSj2Wxg84UtNzBVsRNY06v6u7o8TtvYRpLlElGwM%2FIH3Bz%2Ba0c5gmoibdxwjuHh3El4%2Fzekk62htm%2B6DvMtPsRxV3eSn%2FygSZa9d7bsIe42M32MllmIvxbI2EWAVpJ%2But%2Bf1Ams%2Fao9NShdpZYGAp9rzWMkXrSloY%2FZMCDiDiX5rmWdyQZOSzm5yjt6rnHjRuf0fO3ewq7zwGt8l4IJzjNN85HTLFTiUglI%2BS%2BistXeX3bemqIlWWNNlbz3VwDLO8ahOQOAHOHpLki9KYsR9rEc9rcHUibfutkCX6u72j5eEWV52OGQYEMtE2SUQqcaQ1Sr1VV4Z5%2F4hQsi0Xyqh5EvqpWKMEbMrrK6EzxFBlJs6UpEbKP7HZ32kb4RTpR5kXXvrJ5cwRKLwnx0aj1IjaHHMTzKMIBhuvt0tsGpBcshvDiZetUdi%2FhfhE1%2BVvVTPhbg0R5jzW7HMMbNUcfTkbTRJZ%2FkMkG%2Fn5tPYPDb96qS5cwnpuONQio89gvGwz4yExuByMYKLmW6dKcLk%2FOvql7FBXgzmDowoXUxUYXfpdgR8qjIdjv1eeroLz%2BXCDc%2BuT4kBgwwzD2P2k1CX2zgekCUSPUNwP1IaE4FGx2dOK2VOKDMgL3ncs3KSdYVOL7Wdk5SWyt33GrKqO8HMHqVNrd12ZK5jnQ8I49OPOXupHLOYtXDxxMx7C67eTaKUGRICxJROqstHI24ST1Z5QyhnA8bFx7Vl1ZS4IuctpMU0hfUJ4lPNETQitSEiuXrokuQAEdbW5CXMU0MsnBR5h6DWPAKb%2BmWzXbGGdq5K89xe4As%2FVTriD8Z6wQRL52Pwt7XJILOtxl7iIzLLs5dz49FyhMyXuj576qw%2BbtMm3F%2F9%2BHQ2Mbn3UY8MoZOGKOKVvBHI8Lm1Zgqu2ncrfIp%2FYy79Ste5ZLi%2BLdpeKeYTH9lStLDvFWeLoKBGvnt6dnUEtJtAY1qbiWoNzNZapw3GGnhn5v%2BeaRTh74vqL1GCnHx9FGILTk9Al7%2F4KT2rWbNsPPY36MxQ3%2B1Zb7SxIwBAcyJw%2BvbO0w%2Fe6ELqy44jKNHkuvbBSTgV0wRecyD%2BK8Ifnrsy61LZi6zifdqffGTbt9Z7iVslpiHz08ZKh8s1KnRxHLBLq31xMufre8sM1MPxXGUqt%2BxFDSReuKQr%2B1xIUTD7inggwWtWhLtXsgykSXO88HriBiGaViFSm9bpI%2BwBygAXqsF6D%2F9wUzWAWuIQ5eKf3SEulENmwpP%2FTYR26hV4EMrv00XygR8prwTDWNr9NEauEQ5FWjnIfG15c5w9w8M4LINFsKUPL3o9OQ4GVcPLkq5qV5zlMmuqJ%2BBEfSKPdAvZowwwC9uWPu0ksqZmBqq9F9wj81T0vnZbneK9uCcJDtWkfbdv%2FpJMQ2TNcilAX5iYL9AUObewgsxNY1Yn5nCbTrcNURbWxf9qxscxdL9js69khPtqkyoG6xPqyHb743eHa7mEs0i09JYdkBkUiFpmBEwNh4kITy9bMSJMTfQcRUKd9RkkkzQajIeZqg4V01VRzJBNhD5Ge16%2FkSTyW3HKiUfy%2B3x18luMVGzmPJu2cuA4rTjd1m4xZPFJPg7mznM4VzDb%2B2TxVwXA3BTtdD6jdM9OqtRMP6%2FQgg2IALwT7f5Kv2b4KoiPGTcGJTHoV88pSt4%2FoQXjvBU7b09Dw4bKGAEmKR%2Bq5I5uPvYkQzpys0u0L5qBW%2BroegR8PFs3Nj0%2FOYoqIG09RcESw8yLkuQW9CwK1SI5zqRWkuBvprXc8nVOmCv%2BKQ%2FcpdHFFMHzwWfjKEAZztIQd%2FAUK1hmGG%2FxWJPyV%2F0g%2BQbw5GZriEIMl%2Bdi8cNWa2fWfl8OZwB4EgGA76YsJZ5wYGpB%2FCrRQxDSzMn6TivHal%2F9N0SILC8s8FvfoUq41qUVDk2Sc4fBiTOHh6G5cSqgLSgboRxLVSpTmfWlcoWuqNes9OUZG%2FMGCgpSwHgUGvw461WFIddB1cWLx0W009e%2FdgLE%2FbWzmEMj3g5Er%2F4TTsrV%2BuMMhtswidUMjL5iPrMcY7ZmqzkzPxZ7r55Ypmmi%2BT0wLgScC%2FctgNTqEurvHnndhbpV%2BQOCnSH2plM57FaREZoEq0%2Bs5VcH38Wg%2FVuqyHlFY8S2E1bnwGpQxamgUvgB63Q%2FAD7hnu3lKme%2B1fkRIO%2BgTwYQqVWzjgsu%2FkZb8D%2FzkjasR3%2FrBVgnph%2FiLxVKfkl42TD5Vt1dAp4iHDWAGFND9J4USM7qmu75ae3BVaZ1ej2gwCQ1X%2F%2F5MC5ii7BFWfX6f3GsspmvsqhLS0CJFXHzyZTF%2BJXCLFGRvUsIcRkx%2BwbpqQBeysJffF3wH3PgFMfbwp5ROzoEw%2FEBE5nHM7QAdU6H8EOVUBdTmGG%2BY0gnV0LaHiVQ4VMznxS3dGQXBmMizN6C2%2BYyR1Rjo4mqlHKRn8a3Q%2FooYs0KyBgrK4Pswa0ImXPXxuhvQCMVE39rke1c%2BHSw62aymCawJ3Py%2FfICV3JkmrikzJ%2BcbZr21ik3bjAeqZVQcLhMNqwabl92R4R9MgIhU1MKd2CNpGJ7Wvpe2Eb3XLcQ";
  1543. //$sql = common::deCode($ss, 'D');
  1544. //error_log($sql);
  1545. $sql = common::deCode($_POST['tmp_search'], 'D');
  1546. //$sql = substr($sql, 0, strripos($sql, " limit"));
  1547. if(!empty($sql)){
  1548. $rs = common::excuteListSql($sql);
  1549. }
  1550. //去除null
  1551. foreach($rs as $index => $val) {
  1552. foreach($val as $index_2 => $_val) {
  1553. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  1554. $rs[$index][$index_2] = "";
  1555. }
  1556. }
  1557. }
  1558. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  1559. foreach($rs as $index => $val) {
  1560. //返回加密serial_no
  1561. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  1562. //$rs[$index]["mode"] = "Ocean Freight";
  1563. $rs[$index]["Mode"] = $val['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  1564. ($val['transport_mode_extend'] == 'air' ? "Air Freight":
  1565. ($val['transport_mode_extend'] == 'rail' ? "Rail Freight":
  1566. ($val['transport_mode_extend'] == 'road'? "Road Freight": "")));
  1567. $rs[$index]["Vessel/Airline"] = utils::outDisplayForMerge($val['_f_vessel'],$val['Vessel/Airline']);
  1568. $rs[$index]["Voyage/Flight"] = utils::outDisplayForMerge($val['_f_voyage'],$val['Voyage/Flight']);
  1569. //status 改为ocean_milestone里的信息
  1570. $rs[$index]["Status"] = $rs[$index]["new_status"];
  1571. //po_no 处理 有import 显示import
  1572. $rs[$index]["PO No."] = $rs[$index]["_po_no"];
  1573. }
  1574. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  1575. exit;
  1576. }
  1577. private function _revenue_download(){
  1578. $r2_cloumn = array();
  1579. $r2_cloumn[] = array("title" => "Month","dataIndex"=>"month");
  1580. $r2_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1581. $r2_cloumn[] = array("title" => "Total Amount","dataIndex"=>"invoice_amount");
  1582. $r3_cloumn = array();
  1583. $r3_cloumn[] = array("title" => "Invoice Issue Date","dataIndex"=>"invoice_date");
  1584. $r3_cloumn[] = array("title" => "Invoice Number","dataIndex"=>"invoice_no");
  1585. $r3_cloumn[] = array("title" => "HBL Number","dataIndex"=>"h_bol");
  1586. $r3_cloumn[] = array("title" => "Amount","dataIndex"=>"ivnoice_amount");
  1587. $r3_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1588. $date_from = null;
  1589. $date_to = null;
  1590. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1591. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1592. $date_from = $date_start."-01";
  1593. }
  1594. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1595. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1596. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1597. }
  1598. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1599. //$sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1600. //$sql = "select * from _test_data_table";
  1601. //$r2_data = common::excuteListSql($sql);
  1602. //只取r3 代码去计总r2 ,避免二次请求数据库
  1603. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r3;";
  1604. //$sql = "select * from _test_data_table_two";
  1605. $r3_data = common::excuteListSql($sql);
  1606. $group_data = array();
  1607. foreach($r3_data as $r3){
  1608. $r3['invoice_date'] = strtoupper(date('M,Y', strtotime($r3['invoice_date'])));
  1609. $group_data[] = $r3;
  1610. }
  1611. //按货币和日期分组
  1612. $groupedItems = array();
  1613. foreach ($group_data as $item) {
  1614. $key = $item['currency']."_".$item['invoice_date'];
  1615. if(array_key_exists($key, $groupedItems)){
  1616. $temp = $groupedItems[$key];
  1617. $temp['invoice_amount'] = $temp['invoice_amount'] + $item['ivnoice_amount'];
  1618. $groupedItems[$key] = $temp;
  1619. }else{
  1620. $groupedItems[$key] = array("month"=>$item['invoice_date'],"currency"=>$item['currency'],"invoice_amount"=>$item['ivnoice_amount']);
  1621. }
  1622. }
  1623. $r2_data = array();
  1624. foreach($groupedItems as $gt){
  1625. $gt['invoice_amount'] = number_format($gt['invoice_amount'], 4, '.', '');
  1626. $r2_data[] = $gt;
  1627. }
  1628. common::echo_json_encode(200,array("msg"=>"success","r2" => $r2_data,"r3"=>$r3_data,"r2_cloumn" => $r2_cloumn,"r3_cloumn" => $r3_cloumn,
  1629. "r2_title"=>"Monthly Summary Data","r3_title"=>"Invoice Detailed Data"));
  1630. exit;
  1631. }
  1632. private function _ams_isf_log(){
  1633. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  1634. $ams_ss = $_POST['ams_ss'];
  1635. $isf_ss = $_POST['isf_ss'];
  1636. $amsLog = array();
  1637. //页面固定写死的信息
  1638. $amsLog_column = array();
  1639. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1640. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1641. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  1642. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  1643. $amsLog["amsLog_column"] = $amsLog_column;
  1644. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1645. $amsLog["data"] = array();
  1646. if (_canViewAMSLog()) {
  1647. $s = $ams_ss;
  1648. //$s = "PDLA200127H";
  1649. if (!empty($s)) {
  1650. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  1651. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  1652. foreach ($cc as $v){
  1653. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  1654. }
  1655. //考虑一个情况
  1656. if (utils::count($amses) > 0) {
  1657. $ams = $amses[0];
  1658. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  1659. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  1660. if (empty($ams[0]['h_bol'])){
  1661. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1662. $amsLog["data"] = array();
  1663. }else{
  1664. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  1665. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  1666. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  1667. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  1668. $amsLog["msg"] = "";
  1669. $amsLog["data"] = $log;
  1670. }
  1671. }
  1672. }
  1673. }
  1674. $isfLog = array();
  1675. //页面固定写死的信息
  1676. $isfLog_column = array();
  1677. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1678. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1679. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  1680. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  1681. $isfLog["isfLog_column"] = $isfLog_column;
  1682. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1683. $isfLog["data"] = array();
  1684. if (_canViewISFLog()) {
  1685. if (!empty($isf_ss)) {
  1686. $ss = $isf_ss;
  1687. $len = strlen($ss);
  1688. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  1689. if (empty($b)){
  1690. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1691. $isfLog["data"] = array();
  1692. }else{
  1693. $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");
  1694. }
  1695. if (!empty($isf)) {
  1696. if (!empty($isf['dob'])){
  1697. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  1698. }
  1699. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  1700. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  1701. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  1702. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  1703. order by cbpreplytime desc, rowid desc");
  1704. $isfLog["msg"] = "";
  1705. $isfLog["data"] = $msg;
  1706. }else{
  1707. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1708. $isfLog["data"] = array();
  1709. }
  1710. }
  1711. }
  1712. $data =array("msg"=>"success",
  1713. "canViewAMSLog" => _canViewAMSLog(),
  1714. "canViewISFLog" => _canViewISFLog(),
  1715. "amsLog" =>$amsLog,
  1716. "isfLog" =>$isfLog);
  1717. common::echo_json_encode(200,$data);
  1718. exit;
  1719. }
  1720. private function getEmail($serial_no) {
  1721. return utils::getEmail($serial_no);
  1722. }
  1723. private function getCommunicationNew($serial_no) {
  1724. $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");
  1725. $emialRecords =array();
  1726. foreach ($list as $k => $v) {
  1727. $msg =array();
  1728. $msg["name"] = $v["add_by"];
  1729. $msg["creatTime"] = $v["add_times"];
  1730. $msg["content"] = urldecode($v["web_content"]);
  1731. $emialRecords[] = $msg;
  1732. }
  1733. return $emialRecords;
  1734. }
  1735. /*
  1736. * get file by hbol/destination
  1737. * H:HBL
  1738. * M: MBL
  1739. * F: FL
  1740. * I: C/I & Packing list
  1741. */
  1742. private function getOceanFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  1743. $_schemas = $_REQUEST['_schemas'];
  1744. $types = strtolower($types);
  1745. $types = explode(";", $types);
  1746. $m_bs = explode(";", $m_bs);
  1747. $otheres = NULL;
  1748. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1749. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1750. $file = array();
  1751. foreach ($types as $k => $type) {
  1752. $m_b = $m_bs[$k];
  1753. if (strtolower($m_b) == 'm')
  1754. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1755. 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";
  1756. if (strtolower($m_b) == 'h')
  1757. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1758. 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";
  1759. if (strtolower($m_b) == 'a')
  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($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";
  1762. if (!empty($sql)) {
  1763. $rss = common::excuteListSql($sql);
  1764. foreach ($rss as $rs) {
  1765. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1766. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1767. "file_name" => $rs['file_name'],
  1768. "format_name" => $rs['format_name'],
  1769. "detail"=>$rs['upload_date'],
  1770. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1771. "from_system" =>'TOPOCEAN_KSMART');
  1772. }else {
  1773. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1774. "file_name" => $rs['file_name'],
  1775. "format_name" => $rs['format_name'],
  1776. "detail"=>$rs['upload_date'],
  1777. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1778. "from_system" =>'');
  1779. }
  1780. }
  1781. }
  1782. }
  1783. return $file;
  1784. }
  1785. /*
  1786. * get file by hbol/destination
  1787. * H:HBL
  1788. * M: MBL
  1789. * F: FL
  1790. * I: C/I & Packing list
  1791. */
  1792. private function getAirFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE) {
  1793. $_schemas = $_REQUEST['_schemas'];
  1794. $types = explode(";", $types);
  1795. $m_bs = explode(";", $m_bs);
  1796. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1797. $file = array();
  1798. foreach ($types as $k => $type) {
  1799. $m_b = $m_bs[$k];
  1800. if (strtolower($m_b) == 'm')
  1801. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1802. 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";
  1803. if (strtolower($m_b) == 'h')
  1804. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1805. 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";
  1806. if (strtolower($m_b) == 'a')
  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) . "' 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";
  1809. if (!empty($sql)) {
  1810. $rss = common::excuteListSql($sql);
  1811. foreach ($rss as $rs) {
  1812. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1813. "file_name" => $rs['file_name'],
  1814. "format_name" => $rs['format_name'],
  1815. "detail"=>$rs['upload_date'],
  1816. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1817. "from_system" =>'');
  1818. }
  1819. }
  1820. }
  1821. return $file;
  1822. }
  1823. /**
  1824. * 批量选着文件下载
  1825. */
  1826. private function _batch_download_load(){
  1827. //ocean的相关配置参数
  1828. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1829. $ocean_can_view_file = common::excuteOneSql("select ocean_can_view_file from ra_online_user where user_login='".$_SESSION['ONLINE_USER']['user_login']."'");
  1830. //$ocean_can_view_file = '{"HBL":[{"type":"TELEX","value":""}],"MBL":[{"type":"TELEX","value":""}]}';
  1831. $tar = json_decode($ocean_can_view_file,true);
  1832. $sqlFiterWhere = "1<>1 ";
  1833. foreach($tar as $_tar){
  1834. foreach($_tar as $dkey => $dvalue){
  1835. $sqlFiterWhere.= " or (lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."')
  1836. and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."')";
  1837. }
  1838. }
  1839. //air的相关配置参数
  1840. $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'])."'");
  1841. $air_tar = json_decode($air_can_view_file,true);
  1842. $air_sqlFiterWhere = "1<>1 ";
  1843. foreach($air_tar as $_air_tar){
  1844. foreach($_air_tar as $air_dkey => $air_dvalue){
  1845. $air_sqlFiterWhere.= " or (lower(format_serailno) in ('".strtolower(str_replace(";","','",$air_dvalue['value']))."')
  1846. and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$air_dvalue['type']."')";
  1847. }
  1848. }
  1849. $vueData = array();
  1850. $serial_no_arr = $_POST['serial_no_arr'];
  1851. $_schemas_arr = $_POST['schemas_arr'];
  1852. foreach($serial_no_arr as $key =>$serial_no){
  1853. $_schemas = $_schemas_arr[$key];
  1854. $ocean = common::excuteObjectSql("select m_bol as _m_bol,
  1855. h_bol as _h_bol,
  1856. transport_mode,
  1857. order_from,
  1858. case when transport_mode = 'sea' and order_from = 'public' then (select job_no from public.ocean o where o.serial_no = oo.serial_no)
  1859. when transport_mode = 'sea' and order_from = 'sfs' then (select job_no from sfs.ocean o where o.serial_no = oo.serial_no)
  1860. else ''::text end as _job_bol
  1861. from public.kln_ocean oo where oo.serial_no = '$serial_no' and order_from = '$_schemas'");
  1862. $i = $key +1;
  1863. if ($ocean["transport_mode"] == 'sea'){
  1864. //ocean 能看的文件类型
  1865. $document = _getViewDocType($_schemas);
  1866. $file_serial_nos = array();
  1867. foreach ($document as $v) {
  1868. $types = $v['serial_no'];
  1869. $types = strtolower($types);
  1870. $types = explode(";", $types);
  1871. foreach ($types as $k => $type) {
  1872. $file_serial_nos[] = $type;
  1873. }
  1874. }
  1875. $file_serial_nos = utils::implode(';',$file_serial_nos);
  1876. $filefilter = " ('TELEX') ";
  1877. $fileSql = "SELECT ff.format_name,ff.standard,
  1878. from_system,doc.serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1879. from $_schemas.ra_online_doc_upload doc
  1880. left join $_schemas.ra_online_file_format ff on ff.serial_no = doc.format_serailno
  1881. where (lower(bol) = '" . strtolower($ocean['_m_bol']) . "' or lower(bol) = '" . strtolower($ocean['_h_bol']) . "' or lower(bol) = '".strtolower($ocean['_job_bol'])."' )
  1882. and (
  1883. (upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter.")
  1884. or ".$sqlFiterWhere."
  1885. ) and lower(format_serailno) " . common::getInNotInSql($file_serial_nos) . " order by ff.format_name ASC,doc.id desc";
  1886. $rss = common::excuteListSql($fileSql);
  1887. $file_arr = array();
  1888. foreach ($rss as $rs) {
  1889. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1890. $file_arr[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1891. "url_param" =>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1892. "file_name" => $rs['file_name'],
  1893. "format_name" => $rs['format_name'],
  1894. "standard" => $rs['standard'],
  1895. "detail"=>$rs['upload_date'],
  1896. "is_topocean" =>true);
  1897. }else {
  1898. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1899. "url_param" => common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E'),
  1900. "file_name" => $rs['file_name'],
  1901. "format_name" => $rs['format_name'],
  1902. "standard" => $rs['standard'],
  1903. "detail"=>$rs['upload_date'],
  1904. "is_topocean" =>false);
  1905. }
  1906. }
  1907. $vueData[] = $this->batch_document_upload_Vue_Data($file_arr,$ocean['_h_bol'],$i);
  1908. }
  1909. if ($ocean["transport_mode"] == 'air'){
  1910. //air能看的文件类型
  1911. $document = _getAirViewDocType($_schemas);
  1912. $file_serial_nos = array();
  1913. foreach ($document as $v) {
  1914. $types = $v['serial_no'];
  1915. $types = strtolower($types);
  1916. $types = explode(";", $types);
  1917. foreach ($types as $k => $type) {
  1918. $file_serial_nos[] = $type;
  1919. }
  1920. }
  1921. $file_serial_nos = utils::implode(';',$file_serial_nos);
  1922. $filefilter = " ('TELEX') ";
  1923. $fileSql = "SELECT ff.format_name,ff.standard,
  1924. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1925. from $_schemas.air_doc_upload
  1926. left join $_schemas.air_file_format ff on ff.serial_no = air_doc_upload.format_serailno
  1927. where (lower(bol) = '" . strtolower($ocean['_m_bol']) . "' or lower(bol) = '" . strtolower($ocean['_h_bol']) . "')
  1928. and (
  1929. (upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter.")
  1930. or ".$sqlFiterWhere."
  1931. ) and lower(format_serailno) " . common::getInNotInSql($file_serial_nos) . " order by ff.format_name ASC,air_doc_upload.id desc";
  1932. $rss = common::excuteListSql($fileSql);
  1933. $file_arr = array();
  1934. foreach ($rss as $rs) {
  1935. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1936. "url_param"=>common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E'),
  1937. "file_name" => $rs['file_name'],
  1938. "format_name" => $rs['format_name'],
  1939. "standard" => $rs['standard'],
  1940. "detail"=>$rs['upload_date'],
  1941. "is_topocean" =>false);
  1942. }
  1943. $vueData[] = $this->batch_document_upload_Vue_Data($file_arr,$ocean['_h_bol'],$i);
  1944. }
  1945. }
  1946. common::echo_json_encode(200, $vueData);
  1947. exit();
  1948. }
  1949. /*
  1950. * download file
  1951. */
  1952. private function _download() {
  1953. $url = common::deCode($_GET['url'], 'D');
  1954. common::download_file($url);
  1955. }
  1956. private function save_vgm() {
  1957. $schemas = $_POST["schemas"];
  1958. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1959. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1960. $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"] . "'");
  1961. $address = $contact["address_1"];
  1962. if (!empty($address)) {
  1963. $address .= "\r\n";
  1964. }
  1965. $address .= $contact["address_2"];
  1966. if (!empty($address)) {
  1967. $address .= "\r\n";
  1968. }
  1969. $address .= $contact["address_3"];
  1970. if (!empty($address)) {
  1971. $address .= "\r\n";
  1972. }
  1973. $address .= $contact["address_4"];
  1974. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1975. global $db;
  1976. $db->StartTrans();
  1977. if (empty($_POST["is_send"])) {
  1978. $_POST["is_send"] = 'f';
  1979. }
  1980. if (empty($exists)) {
  1981. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1982. $value["serial_no"] = $serial_no;
  1983. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1984. $value["modify_user"] = _getLoginName();
  1985. $value["modify_time"] = "now()";
  1986. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1987. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1988. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1989. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1990. $value["is_send"] = $_POST["is_send"];
  1991. $value["action"] = "New";
  1992. $value["type"] = "Shipper";
  1993. $value["m_bol"] = $ocean["m_bol"];
  1994. $value["master_base_number"] = $ocean["master_base_number"];
  1995. $value["shipper_id"] = $ocean["from_station"];
  1996. $value["shipper"] = $contact["company"];
  1997. $value["shipper_address"] = $address;
  1998. $value["shipper_contactname"] = $contact["contactname_1"];
  1999. $value["shipper_email"] = $contact["email_1"];
  2000. $value["shipper_fax"] = $contact["fax"];
  2001. $value["shipper_telephone"] = $contact["phone_1"];
  2002. $value["update_uuid"] = utils::uuid();
  2003. $value["h_bol"] = $ocean["h_bol"];
  2004. $value["from_station"] = $ocean["from_station"];
  2005. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  2006. $db->Execute($sql);
  2007. } else {
  2008. $serial_no = $exists;
  2009. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  2010. $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(),"
  2011. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  2012. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  2013. }
  2014. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  2015. foreach ($_POST["container_no"] as $i => $cv) {
  2016. $value1["serial_no"] = $serial_no;
  2017. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  2018. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  2019. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  2020. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  2021. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  2022. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  2023. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  2024. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  2025. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  2026. $value1["master_base_number"] = $ocean["master_base_number"];
  2027. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  2028. $db->Execute($sql);
  2029. }
  2030. if ($db->CompleteTrans() === FALSE) {
  2031. return "error";
  2032. } else {
  2033. return "success";
  2034. }
  2035. }
  2036. private function getOceanDetail($serial_no) {
  2037. $order_from = $_REQUEST['_schemas'];
  2038. $_schemas = $_REQUEST['_schemas'];
  2039. if($_schemas == 'public'){
  2040. $_schemas = "ocean";
  2041. }
  2042. $sql = "with o as(
  2043. SELECT o.* from $order_from.ocean o where serial_no = '" . $serial_no . "'
  2044. )
  2045. SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  2046. o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,koe.loadterm,
  2047. COALESCE(koe.import_po_no,oo.po_no) as _po_no
  2048. from o
  2049. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  2050. consignee_uncode,consignee_city,incoterms,
  2051. fport_of_loading_un,
  2052. mport_of_discharge_un,
  2053. place_of_receipt_un,
  2054. place_of_delivery_un,
  2055. etd as oo_etd,
  2056. eta as oo_eta,
  2057. atd as oo_atd,
  2058. ata as oo_ata,
  2059. carbon_emission,
  2060. transport_mode_extend,
  2061. port_of_transshipment_un,
  2062. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  2063. (select uncity from $order_from.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  2064. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  2065. (select uncity from $order_from.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  2066. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  2067. (select uncity from $order_from.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  2068. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  2069. (select uncity from $order_from.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  2070. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  2071. (select uncity from $order_from.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  2072. invoice_no as _invoice_no,
  2073. oo.po_no,
  2074. CASE
  2075. 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
  2076. 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
  2077. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departed'::text
  2078. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  2079. WHEN (m_iffdel is not null) THEN 'Completed'::text
  2080. ELSE 'Created'::text
  2081. END AS new_status
  2082. FROM public.kln_ocean oo WHERE oo.serial_no::text = o.serial_no::text and order_from = '$order_from') oo ON true
  2083. LEFT JOIN LATERAL ( SELECT loadterm,import_po_no
  2084. FROM public.kln_ocean_extend koe WHERE koe.serial_no::text = o.serial_no::text and koe.order_from = '$order_from') koe ON true
  2085. LEFT JOIN LATERAL ( SELECT company as cn_company,
  2086. address_1 as cn_address_1,
  2087. address_2 as cn_address_2,
  2088. address_3 as cn_address_3,
  2089. address_4 as cn_address_4,
  2090. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  2091. phone_1 as cn_phone
  2092. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  2093. LEFT JOIN LATERAL ( SELECT company as sh_company,
  2094. address_1 as sh_address_1,
  2095. address_2 as sh_address_2,
  2096. address_3 as sh_address_3,
  2097. address_4 as sh_address_4,
  2098. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  2099. phone_1 as sh_phone
  2100. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  2101. LEFT JOIN LATERAL ( SELECT company as aa_company,
  2102. address_1 as aa_address_1,
  2103. address_2 as aa_address_2,
  2104. address_3 as aa_address_3,
  2105. address_4 as aa_address_4,
  2106. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  2107. phone_1 as aa_phone,
  2108. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  2109. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  2110. LEFT JOIN LATERAL ( SELECT company as dd_company,
  2111. address_1 as dd_address_1,
  2112. address_2 as dd_address_2,
  2113. address_3 as dd_address_3,
  2114. address_4 as dd_address_4,
  2115. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  2116. phone_1 as dd_phone,
  2117. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  2118. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  2119. LEFT JOIN LATERAL ( SELECT
  2120. city as fd_city,
  2121. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  2122. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  2123. //error_log($sql);
  2124. return $sql;
  2125. }
  2126. private function getAirDetail($serial_no) {
  2127. $order_from = $_REQUEST['_schemas'];
  2128. $_schemas = $_REQUEST['_schemas'];
  2129. if($_schemas == 'public'){
  2130. $_schemas = "ocean";
  2131. }
  2132. $sql = "with o as(
  2133. SELECT oo.*,m_bol as _m_bol, h_bol as _h_bol,
  2134. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  2135. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.fport_of_loading_un limit 1) as pol_uncity,
  2136. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  2137. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  2138. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  2139. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_receipt_un limit 1) as por_uncity,
  2140. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  2141. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_delivery_un limit 1) as pod_uncity,
  2142. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  2143. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.final_desination_uncode limit 1) as _pd_uncity,
  2144. CASE
  2145. 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
  2146. 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
  2147. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departed'::text
  2148. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  2149. WHEN (m_iffdel is not null) THEN 'Completed'::text
  2150. ELSE 'Created'::text
  2151. END AS new_status
  2152. from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
  2153. )
  2154. SELECT o.* ,sh.*, cn.*,
  2155. aa.*,dd.*,fd.*,air.*
  2156. from o
  2157. LEFT JOIN LATERAL ( SELECT departure_airport_name as fport_of_loading_exp,
  2158. destination_airport_name as mport_of_discharge_exp,
  2159. mawb as _mawb, mawb_name as _mawb_name, hawb as _hawb
  2160. FROM $order_from.air a WHERE a.serial_no = o.serial_no) air ON true
  2161. LEFT JOIN LATERAL ( SELECT company as cn_company,
  2162. address_1 as cn_address_1,
  2163. address_2 as cn_address_2,
  2164. address_3 as cn_address_3,
  2165. address_4 as cn_address_4,
  2166. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  2167. phone_1 as cn_phone
  2168. FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
  2169. LEFT JOIN LATERAL ( SELECT company as sh_company,
  2170. address_1 as sh_address_1,
  2171. address_2 as sh_address_2,
  2172. address_3 as sh_address_3,
  2173. address_4 as sh_address_4,
  2174. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  2175. phone_1 as sh_phone
  2176. FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
  2177. LEFT JOIN LATERAL ( SELECT company as aa_company,
  2178. address_1 as aa_address_1,
  2179. address_2 as aa_address_2,
  2180. address_3 as aa_address_3,
  2181. address_4 as aa_address_4,
  2182. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  2183. phone_1 as aa_phone,
  2184. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  2185. FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
  2186. LEFT JOIN LATERAL ( SELECT company as dd_company,
  2187. address_1 as dd_address_1,
  2188. address_2 as dd_address_2,
  2189. address_3 as dd_address_3,
  2190. address_4 as dd_address_4,
  2191. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  2192. phone_1 as dd_phone,
  2193. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  2194. FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
  2195. LEFT JOIN LATERAL ( SELECT
  2196. city as fd_city,
  2197. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  2198. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  2199. //error_log($sql);
  2200. return $sql;
  2201. }
  2202. private function returnOceanDetailData($ocean,$state){
  2203. $data = array();
  2204. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  2205. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  2206. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  2207. $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
  2208. $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
  2209. //delivery
  2210. $order_from = $_REQUEST['_schemas'];
  2211. $deliverySql = "with aa as (SELECT o.serial_no, o.master_base_number from $order_from.ocean o WHERE o.serial_no='".$ocean["serial_no"]."'),
  2212. h as (select * from station_data.do_header h where h.serial_no in (select serial_no from aa))
  2213. select h.est_delivery_date,h.est_delivery_time,
  2214. h.consignee_country_code,h.consignee_city_code,
  2215. (select time_zone from public.city_timezone where uncode = CONCAT(h.consignee_country_code, h.consignee_city_code) limit 1) as timezone,
  2216. d.ctnr
  2217. from h inner join station_data.do_detail d on h.id = d.do_header_id and h.from_station = d.from_station
  2218. where h.from_station = '".$ocean["destination_station"]."'
  2219. order by h.est_delivery_date";
  2220. // bb as (select o.serial_no from $order_from.ocean o
  2221. // where exists(select 1 from aa where aa.master_base_number= o.master_base_number)
  2222. // and o.bol_type = 'CONSOL' and o.status::text <> 'Cancelled'::text),
  2223. // $deliverySql = "with aa as (SELECT o.serial_no, o.master_base_number from $order_from.ocean o WHERE o.serial_no='".$ocean["serial_no"]."'),
  2224. // bb as (select o.serial_no from $order_from.ocean o
  2225. // where exists(select 1 from aa where aa.master_base_number= o.master_base_number)
  2226. // and o.bol_type = 'CONSOL' and o.status::text <> 'Cancelled'::text),
  2227. // cc as (select serial_no from aa
  2228. // union all
  2229. // select serial_no from bb
  2230. // ),
  2231. // h as (select * from do_header h where h.serial_no = (select serial_no from cc))
  2232. // select h.est_delivery_date,h.est_delivery_time,
  2233. // h.consignee_country_code,h.consignee_city_code,
  2234. // (select time_zone from public.city_timezone where uncode = CONCAT(h.consignee_country_code, h.consignee_city_code) limit 1) as timezone,
  2235. // d.ctnr
  2236. // from h left join do_detail d on h.do_serial_no = d.do_serial_no order by h.est_delivery_date";
  2237. $delivery = common::excuteListSql($deliverySql);
  2238. /* Container Status */
  2239. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  2240. //记录所有的信息 EDI315TimeAndLocation
  2241. $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
  2242. $deliveredData = array();
  2243. $deliveredChildrenDate = "";
  2244. if(!empty($delivery)){
  2245. foreach($delivery as $_delivery){
  2246. //添加containerStatusData的delivery
  2247. $est_delivery_date = $_delivery["est_delivery_date"];
  2248. if (!empty($_delivery["est_delivery_time"])) {
  2249. $est_delivery_date.= " " . $_delivery["est_delivery_time"];
  2250. }
  2251. $location_code = $_delivery["consignee_country_code"]."".$_delivery["consignee_city_code"];
  2252. foreach($EDIDate['containerStatusData'] as $cskey => $csval){
  2253. if($csval['ctnr_label'] == $_delivery['ctnr']){
  2254. $_uncity = common::excuteObjectSql("select uncity from $order_from.ports where active = true and uncode = '".strtoupper($location_code)."' limit 1");
  2255. $contentTemp = array("title" =>"Last Mile Delivery",
  2256. "code"=>"UN-".$location_code,
  2257. "date"=>$est_delivery_date,
  2258. "country"=>$location_code,
  2259. "uncity"=>$_uncity['uncity'],
  2260. "timezone"=>$_delivery['timezone']);
  2261. $originalArray = $EDIDate['containerStatusData'][$cskey]['content'];
  2262. //$this->insertInDescendingOrder($originalArray, $contentTemp);
  2263. array_unshift($originalArray, $contentTemp);
  2264. //排序后重新赋值
  2265. $EDIDate['containerStatusData'][$cskey]['content'] = $originalArray;
  2266. }
  2267. }
  2268. //添加simplexData的delivery
  2269. $deliveredData[] = array("label" =>"Delivered","date"=>$est_delivery_date,"location"=>$location_code,
  2270. "container"=>$_delivery['ctnr'],'timezone'=>$_delivery['timezone']);
  2271. $deliveredChildrenDate = $_delivery["est_delivery_date"];
  2272. }
  2273. }
  2274. $data['containerStatusData'] = $EDIDate['containerStatusData'];
  2275. $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
  2276. $VD = $EDIDate['VD'];
  2277. $VA = $EDIDate['VA'];
  2278. //处理shipment data
  2279. $ocean_milestone_status = common::excuteListSql("select code,
  2280. act_date,est_date,timezone
  2281. from ocean_milestone a
  2282. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  2283. order by id");
  2284. $ocean_milestone_status_code = array();
  2285. foreach($ocean_milestone_status as $oms){
  2286. $ocean_milestone_status_code[$oms['code']] = $oms;
  2287. }
  2288. if ($state < 1){
  2289. //未发生前
  2290. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  2291. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2292. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  2293. }
  2294. } else{
  2295. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  2296. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2297. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  2298. }
  2299. }
  2300. //先处理一下 ATD 和 ATA,在进行后面的取值
  2301. if(empty($ocean['atd']) && !empty($VD)){
  2302. //$ocean['atd'] = $VD;
  2303. }
  2304. if(empty($ocean['ata']) && !empty($VA)){
  2305. //$ocean['ata'] = $VA;
  2306. }
  2307. $simplexData = array();
  2308. //place_of_Receipt
  2309. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  2310. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  2311. $children = array();
  2312. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  2313. //发生后,未发生前没有
  2314. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  2315. }
  2316. $place_of_Receipt_stauts["children"] = $children;
  2317. $simplexData[] = $place_of_Receipt_stauts;
  2318. //port_of_Loading
  2319. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2320. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2321. $children = array();
  2322. if ($state < 1){
  2323. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  2324. } else{
  2325. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2326. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2327. }
  2328. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  2329. }
  2330. $port_of_Loading_stauts["children"] = $children;
  2331. $simplexData[] = $port_of_Loading_stauts;
  2332. //Port of Discharge
  2333. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2334. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2335. $children = array();
  2336. // if ($state < 2){
  2337. // //未发生前
  2338. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  2339. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  2340. // }else{
  2341. // //没有,取eta
  2342. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2343. // }
  2344. // } else{
  2345. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2346. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2347. // }
  2348. // }
  2349. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  2350. if ($state < 2){
  2351. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2352. }else{
  2353. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2354. }
  2355. $port_of_Discharge_status["children"] = $children;
  2356. $simplexData[] = $port_of_Discharge_status;
  2357. //Place of Delivery
  2358. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2359. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2360. $children = array();
  2361. if ($state < 3){
  2362. //未发生前
  2363. } else{
  2364. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2365. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2366. }
  2367. }
  2368. if(!empty($deliveredChildrenDate)){
  2369. $children[] = array("label" =>"Delivered","date" =>$deliveredChildrenDate);
  2370. }
  2371. $place_of_Delivery_status["children"] = $children;
  2372. $place_of_Delivery_status["deliveredData"] = $deliveredData;
  2373. $simplexData[] = $place_of_Delivery_status;
  2374. $data['shipmentData'] = $simplexData;
  2375. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2376. $_mode = $ocean['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  2377. ($ocean['transport_mode_extend'] == 'air' ? "Air Freight":
  2378. ($ocean['transport_mode_extend'] == 'rail' ? "Rail Freight":
  2379. ($ocean['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  2380. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => $_mode,
  2381. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2382. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  2383. "etd_timezone" =>$ocean['pol_timezone'],
  2384. "atd_timezone" =>$ocean['pol_timezone'],
  2385. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2386. "eta_timezone" =>$ocean['mpod_timezone'],
  2387. "ata_timezone" =>$ocean['mpod_timezone']);
  2388. $data['transportInfo'] = $transportInfo;
  2389. //处理basicInfo信息数据
  2390. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  2391. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  2392. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2393. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2394. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2395. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>$ocean['loadterm'],
  2396. "Shipment Type" =>$ocean['manifest_type'] == "GPE" ? "LCL" : $ocean['manifest_type']);
  2397. $data['basicInfo'] = $basicInfo;
  2398. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2399. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2400. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2401. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2402. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2403. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2404. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2405. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2406. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2407. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2408. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2409. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2410. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2411. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2412. $data['businessPartners'] = $businessPartners;
  2413. //处理routes 转船可能有多个情况
  2414. if ($ocean['is_vessel_direct'] <> "t"){
  2415. //不是直航
  2416. $routes = array(array("mode" =>$_mode,"mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2417. "destination" => $ocean['port_of_transshipment_un'],
  2418. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2419. "eta" =>$ocean['f_eta'],"ata" =>$EDIDate['VA_RELAY'],
  2420. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2421. $routes[] = array("mode" =>$_mode, "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  2422. "destination" => $ocean['consignee_uncode'],
  2423. "etd" => $ocean['m_etd'],"atd" => $EDIDate['VD_RELAY'],
  2424. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2425. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  2426. }else{
  2427. $routes = array(array("mode" =>$_mode,"mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2428. "destination" => $ocean['consignee_uncode'],
  2429. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2430. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  2431. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2432. }
  2433. $data['routes'] = $routes;
  2434. //处理marksAndDescription
  2435. $notes = common::excuteListSql("select notes from station_data.ocean_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2436. $remark = "";
  2437. foreach($notes as $note){
  2438. if(!empty($note['notes'])){
  2439. $remark.=$note['notes']."\r\n";
  2440. }
  2441. }
  2442. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2443. $data['marksAndDescription'] = $marksAndDescription;
  2444. return $data;
  2445. }
  2446. private function returnAirDetailData($ocean,$ocean_milestone_status,$state){
  2447. $data = array();
  2448. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  2449. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  2450. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  2451. //Origin和Destination的展示,能不能Origin of Cargo有值就用Origin of Cargo,Origin of Cargo就放Departure Airport? Destination也一樣?
  2452. $ocean['shippr_uncode'] = !empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  2453. $ocean['consignee_uncode'] = !empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  2454. //处理shipment data
  2455. $ocean_milestone_status_code = array();
  2456. foreach($ocean_milestone_status as $oms){
  2457. $ocean_milestone_status_code[$oms['code']] = $oms;
  2458. }
  2459. if ($state < 1){
  2460. //未发生前
  2461. if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
  2462. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2463. $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
  2464. }
  2465. } else{
  2466. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2467. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2468. //ATD 取值为IFFONB milestone实际发生的时间
  2469. $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
  2470. }
  2471. }
  2472. $simplexData = array();
  2473. //place_of_Receipt
  2474. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  2475. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  2476. $children = array();
  2477. if($state >= 1 && !empty($ocean_milestone_status_code['IFFCPU']['act_date'])){
  2478. //发生后,未发生前没有
  2479. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFCPU']['act_date']);
  2480. }
  2481. $place_of_Receipt_stauts["children"] = $children;
  2482. $simplexData[] = $place_of_Receipt_stauts;
  2483. //port_of_Loading
  2484. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2485. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2486. $children = array();
  2487. if ($state < 1){
  2488. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['etd']);
  2489. } else{
  2490. if(!empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  2491. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  2492. }
  2493. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2494. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2495. }
  2496. }
  2497. $port_of_Loading_stauts["children"] = $children;
  2498. $simplexData[] = $port_of_Loading_stauts;
  2499. //Port of Discharge
  2500. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2501. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2502. $children = array();
  2503. if ($state < 2){
  2504. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['eta']);
  2505. }else{
  2506. if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2507. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2508. $ocean['ata'] = $ocean_milestone_status_code['IFFARR']['act_date'];
  2509. }else{
  2510. //IFFARR 如果同步异常没有值时,去表里的 ata_date AS ata
  2511. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2512. }
  2513. }
  2514. $port_of_Discharge_status["children"] = $children;
  2515. $simplexData[] = $port_of_Discharge_status;
  2516. //Place of Delivery
  2517. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2518. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2519. $children = array();
  2520. if ($state < 3){
  2521. //未发生前
  2522. } else{
  2523. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2524. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2525. }
  2526. }
  2527. $simplexData[] = $place_of_Delivery_status;
  2528. $data['shipmentData'] = $simplexData;
  2529. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2530. $_mode = $ocean['transport_mode_extend'] == 'sea' ? "Ocean Freight" :
  2531. ($ocean['transport_mode_extend'] == 'air' ? "Air Freight":
  2532. ($ocean['transport_mode_extend'] == 'rail' ? "Rail Freight":
  2533. ($ocean['transport_mode_extend'] == 'road' ? "Road Freight": "")));
  2534. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => $_mode,
  2535. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2536. "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
  2537. "etd_timezone" =>$ocean['pol_timezone'],
  2538. "atd_timezone" =>$ocean['pol_timezone'],
  2539. "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
  2540. "eta_timezone" =>$ocean['mpod_timezone'],
  2541. "ata_timezone" =>$ocean['mpod_timezone']);
  2542. $data['transportInfo'] = $transportInfo;
  2543. //处理basicInfo信息数据
  2544. $vessel = $ocean['vessel'];
  2545. $voyage = $ocean['voyage'];
  2546. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2547. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2548. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2549. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>"",
  2550. "Shipment Type" =>"");
  2551. $data['basicInfo'] = $basicInfo;
  2552. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2553. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2554. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2555. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2556. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2557. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2558. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2559. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2560. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2561. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2562. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2563. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2564. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2565. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2566. $data['businessPartners'] = $businessPartners;
  2567. //处理routes air不存在中转的
  2568. $routes = array(array("mode" =>$_mode,"mode_label" =>"Air", "origin" =>$ocean['shippr_uncode'],
  2569. "destination" => $ocean['consignee_uncode'],
  2570. "etd" => $ocean['etd'],"atd" => $ocean['atd'],
  2571. "eta" => $ocean['eta'],"ata" => $ocean['ata'],
  2572. "vessel" =>$ocean['vessel'],"voyageNo" =>$ocean['voyage']));
  2573. $data['routes'] = $routes;
  2574. //处理marksAndDescription
  2575. $notes = common::excuteListSql("select notes from station_data.air_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2576. $remark = "";
  2577. foreach($notes as $note){
  2578. if(!empty($note['notes'])){
  2579. $remark.=$note['notes']."\r\n";
  2580. }
  2581. }
  2582. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2583. $data['marksAndDescription'] = $marksAndDescription;
  2584. return $data;
  2585. }
  2586. private function getUploadFolder() {
  2587. $sql = "SELECT ra_value from ra_online_config where lower(ra_name) = 'upload_document'";
  2588. return common::excuteOneSql($sql);
  2589. }
  2590. private function batch_document_upload_Vue_Data($file_arr,$h_bol,$i){
  2591. // ==================== 开始转换为目标结构 ====================
  2592. $result = [
  2593. 'id' => $i,
  2594. 'isSelect' => false,
  2595. 'no' => 'Shipment No. '.$h_bol, // 可动态传入
  2596. 'typeList' => []
  2597. ];
  2598. // 按 format_name 分组
  2599. $grouped = [];
  2600. foreach ($file_arr as $file) {
  2601. $formatName = $file['format_name'] ?: 'Other'; // 防止 null
  2602. if (!isset($grouped[$formatName])) {
  2603. $grouped[$formatName] = [
  2604. 'label' => $formatName,
  2605. 'attachmentList' => []
  2606. ];
  2607. }
  2608. $grouped[$formatName]['attachmentList'][] = [
  2609. 'name' => $file['file_name'],
  2610. 'isSelect' => false,
  2611. 'url' => $file['url'],
  2612. 'url_param' => $file['url_param'],
  2613. 'detail' => $file['detail'],
  2614. "file_name" => $file['file_name'],
  2615. "standard" => $file['standard'],
  2616. 'h_bol' => $h_bol,
  2617. 'label' => $formatName,
  2618. 'is_topocean'=> $file['is_topocean']
  2619. ];
  2620. }
  2621. // 添加 number 字段,并保持自然顺序(PHP 数组顺序)
  2622. foreach ($grouped as $key => $group) {
  2623. $group['number'] = count($group['attachmentList']);
  2624. $result['typeList'][] = $group;
  2625. }
  2626. return $result;
  2627. }
  2628. private function insertInDescendingOrder(&$array, $newItem) {
  2629. // 标准化并解析新项的日期
  2630. $newDateStr = preg_replace('/\s+/', ' ', trim($newItem['date']));
  2631. $newTimestamp = strtotime($newDateStr);
  2632. if ($newTimestamp === false) {
  2633. // 无效日期,可选择丢弃或抛异常
  2634. return false;
  2635. }
  2636. // 遍历已排序数组(倒序:最新 → 最旧)
  2637. for ($i = 0; $i < count($array); $i++) {
  2638. $existingDateStr = preg_replace('/\s+/', ' ', trim($array[$i]['date']));
  2639. $existingTimestamp = strtotime($existingDateStr);
  2640. // 如果新项比当前项更新(时间戳更大),就插在这里
  2641. if ($newTimestamp > $existingTimestamp) {
  2642. array_splice($array, $i, 0, [$newItem]);
  2643. return true;
  2644. }
  2645. }
  2646. // 如果没找到更旧的位置,说明新项是最旧的,插到末尾
  2647. $array[] = $newItem;
  2648. return true;
  2649. }
  2650. }
  2651. ?>