ocean_order.class.php 173 KB

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