ocean_order.class.php 169 KB

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