ocean_order.class.php 142 KB

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