ocean_order.class.php 149 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440
  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","rail");
  782. }
  783. $transport_mode = utils::implode(";",$transport_mode);
  784. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  785. $sqlWhere .= " and transport_mode_extend in ($mode_param)";
  786. $transport_mode_search = " and transport_mode_extend 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_extend='sea')) then 1 else 0 end) as sea_rc,
  841. sum(case when (1<>1 or (transport_mode_extend='air')) then 1 else 0 end) as air_rc,
  842. sum(case when (1<>1 or (transport_mode_extend='road')) then 1 else 0 end) as road_rc,
  843. sum(case when (1<>1 or (transport_mode_extend='rail')) then 1 else 0 end) as rail_rc,
  844. sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc,
  845. 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)
  846. then 1 else 0 end)
  847. as created,
  848. 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)
  849. then 1 else 0 end)
  850. as cargo_received,
  851. 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,
  852. sum(case when (m_iffarr is not null and m_iffdel is null) then 1 else 0 end) as arrived,
  853. sum(case when (m_iffdel is not null) then 1 else 0 end) as completed,
  854. string_agg(distinct incoterms, '<$>') as incoterm_str,
  855. string_agg(distinct service, '<$>') as service_str
  856. from public.kln_ocean". $sqlWhere_befrom_filterTag;
  857. error_log("online_ocean_search_All_Status: ".$sql);
  858. //$sql_all_status_data = common::excuteObjectSql($sql);
  859. $sql_all_status_data = $mapdb->GetRow($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  860. $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
  861. $IncotermsList = array();
  862. foreach($incoterms as $terms){
  863. if(!empty($terms)){
  864. $IncotermsList[] = array("name"=>$terms,"checked"=>false);
  865. }
  866. }
  867. $service = explode("<$>", $sql_all_status_data['service_str']);
  868. $ServiceList = array();
  869. foreach($service as $_service){
  870. if(!empty($_service)){
  871. $ServiceList[] = array("name"=>$_service,"checked"=>false);
  872. }
  873. }
  874. $rc = $sql_all_status_data['rc'];
  875. $search_rc = $sql_all_status_data['seach_rc'];
  876. $sea_rc = $sql_all_status_data['sea_rc'];
  877. $air_rc = $sql_all_status_data['air_rc'];
  878. $road_rc = $sql_all_status_data['road_rc'];
  879. $rail_rc = $sql_all_status_data['rail_rc'];
  880. $Created = $sql_all_status_data['created'];
  881. $Cargo_Received = $sql_all_status_data['cargo_received'];
  882. $Departed = $sql_all_status_data['departed'];
  883. $Arrived = $sql_all_status_data['arrived'];
  884. $Completed = $sql_all_status_data['completed'];
  885. if (!empty($_POST["filterTag"])) {
  886. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  887. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  888. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  889. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  890. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  891. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  892. }else{
  893. //初始,前端有选择着带入选择
  894. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=> true ),
  895. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  896. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  897. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  898. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  899. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  900. }
  901. $TransportList = array(
  902. array("name"=>"Ocean Freight","sname"=>"Sea","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
  903. array("name"=>"Air Freight","sname"=>"Air","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"));
  904. $transport_mode_arr = explode(";", $transport_mode);
  905. foreach($transport_mode_arr as $mode){
  906. foreach($TransportList as $tkey => $transport){
  907. if(strtolower(trim($mode)) == strtolower($TransportList[$tkey]["sname"])){
  908. $TransportList[$tkey]["checked"] = true;
  909. }
  910. }
  911. }
  912. //现在下载交给前端,后台预先只返回全部字段的列,
  913. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  914. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  915. }
  916. $tp = ceil($rc / $ps);
  917. $order_by = " etd desc";
  918. if (_isCustomerLogin()) {
  919. $order_by = " eta desc";
  920. }
  921. if ($rc > 0) {
  922. // $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  923. // FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
  924. $sql = "with oo as (SELECT oe.*, order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
  925. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  926. (select user_login from public.kln_user_subscribed us
  927. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  928. CASE
  929. 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
  930. 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
  931. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  932. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  933. WHEN (m_iffdel is not null) THEN 'Completed'::text
  934. ELSE 'Created'
  935. END AS new_status, ".
  936. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  937. from public.kln_ocean
  938. LEFT JOIN LATERAL ( SELECT loadterm,
  939. manifest_type,
  940. volume
  941. FROM public.kln_ocean_extend oe WHERE oe.serial_no::text = kln_ocean.serial_no::text and oe.order_from::text = kln_ocean.order_from::text) oe ON true "
  942. . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.")
  943. select oo.* ,
  944. case when oo.transport_mode ='sea'
  945. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  946. when oo.transport_mode ='air'
  947. then ''
  948. else ''
  949. end as \"Other refenrence No.\"
  950. from oo";
  951. $tmp_search_without_limit = "with oo as (SELECT oe.*, order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
  952. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  953. (select user_login from public.kln_user_subscribed us
  954. where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
  955. CASE
  956. 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
  957. 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
  958. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  959. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  960. WHEN (m_iffdel is not null) THEN 'Completed'::text
  961. ELSE 'Created'
  962. END AS new_status, ".
  963. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . "
  964. from public.kln_ocean
  965. LEFT JOIN LATERAL ( SELECT loadterm,
  966. manifest_type,
  967. volume
  968. FROM public.kln_ocean_extend oe WHERE oe.serial_no::text = kln_ocean.serial_no::text and oe.order_from::text = kln_ocean.order_from::text) oe ON true "
  969. . $sqlWhere . " order by $order_by)
  970. select oo.* ,
  971. case when oo.transport_mode ='sea'
  972. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  973. when oo.transport_mode ='air'
  974. then ''
  975. else ''
  976. end as \"Other refenrence No.\"
  977. from oo";
  978. //$rs = common::excuteListSql($sql);
  979. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  980. error_log("online_ocean_search_SQL: ".$sql);
  981. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  982. foreach($rs as $index => $val) {
  983. //返回加密serial_no
  984. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  985. //$rs[$index]["mode"] = "Ocean Freight";
  986. $rs[$index]["Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  987. //status 改为ocean_milestone里的信息
  988. $rs[$index]["Status"] = $rs[$index]["new_status"];
  989. $rs[$index]["Shipment Type"] = $rs[$index]["Shipment Type"] == 'GPE' ? 'LCL' : $rs[$index]["Shipment Type"];
  990. //订阅的参数
  991. if(empty($rs[$index]["is_subscribe"])){
  992. $rs[$index]['is_subscribe'] = false;
  993. }else{
  994. $rs[$index]['is_subscribe'] = true;
  995. }
  996. //这个不影响,不会deCode两次,取得是临时变量的__serial_no,加这个是为了订阅
  997. $rs[$index]["a"] = common::deCode($val['__serial_no'], 'E');
  998. }
  999. $arrTmp = array('searchData' => $rs,
  1000. 'tagsList' => $tagsList,
  1001. 'TransportList' => $TransportList,
  1002. 'allColums' => $allBookingColumns,
  1003. 'IncotermsList' =>$IncotermsList,
  1004. 'ServiceList' =>$ServiceList,
  1005. 'canEdiVgm' => _canEdiVgm(),
  1006. 'rc' => $search_rc,
  1007. 'ps' => $ps,
  1008. 'cp' => $cp,
  1009. 'tp' => $tp,
  1010. 'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
  1011. 'type' => common::check_input($_POST ['_ntype']));
  1012. } else {
  1013. $arrTmp = array('searchData' => array(),
  1014. 'tagsList' => $tagsList,
  1015. 'TransportList' => $TransportList,
  1016. 'IncotermsList' =>$IncotermsList,
  1017. 'ServiceList' =>$ServiceList,
  1018. 'allColums' => $allBookingColumns,
  1019. 'canEdiVgm' => _canEdiVgm(),
  1020. 'rc' => $search_rc,
  1021. 'ps' => $ps,
  1022. 'cp' => $cp,
  1023. 'tp' => $tp,
  1024. 'tmp_search' => "",
  1025. 'type' => common::check_input($_POST ['_ntype']));
  1026. }
  1027. common::echo_json_encode(200,$arrTmp);
  1028. exit();
  1029. }
  1030. private function _ocean_detail() {
  1031. $serial_no = common::deCode($_GET['a'], 'D');
  1032. $sql = $this->getOceanDetail($serial_no);
  1033. $ocean = common::excuteObjectSql($sql);
  1034. //(本质是是底表ocean 和 kln_oceans数据没有及时同步,详细页面有查询的ocean的时间照成的时间不一致),
  1035. //单独处理一些,用kln_ocean里面的字段,与查询页面保持一致: etd as oo_etd, eta as oo_eta,atd as oo_atd,ata as oo_ata,
  1036. //这样改动最小
  1037. //这个是同步问题,同步是实时的
  1038. //$ocean["f_etd"] = $ocean["oo_etd"];
  1039. //$ocean["m_eta"] = $ocean["oo_eta"];
  1040. //$ocean["atd"] = $ocean["oo_atd"];
  1041. //$ocean["ata"] = $ocean["oo_ata"];
  1042. if (!empty($ocean)) {
  1043. $ocean['_isf_bol'] = $ocean['isf_bol'];
  1044. if (empty($ocean['_isf_bol'])) {
  1045. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  1046. }
  1047. $isf_ss = md5(md5($ocean['_isf_bol']));
  1048. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  1049. //ETA Dest的计算逻辑移除
  1050. // most update status
  1051. $_schemas = $_REQUEST["_schemas"];
  1052. $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 "
  1053. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.kln_ocean "
  1054. . "where serial_no= '" . $ocean["serial_no"] . "'";
  1055. if (!empty($_schemas)) {
  1056. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  1057. }
  1058. $mostStatus = common::excuteObjectSql($mostStatusSql);
  1059. $state = -1;
  1060. if (!empty($mostStatus["last_status_315_code"])) {
  1061. //desc 逻辑处理取消
  1062. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  1063. }
  1064. //请求地图是需要的参数
  1065. $uncode = "'";
  1066. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  1067. $uncode .= $mostStatus["place_of_receipt_un"];
  1068. }
  1069. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  1070. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  1071. $uncode .= $mostStatus["place_of_delivery_un"];
  1072. }
  1073. $uncode .= "'";
  1074. }
  1075. $vueData = $this->returnOceanDetailData($ocean,$state);
  1076. //处理shipment data暂时写死
  1077. $simplexData = $vueData['shipmentData'];
  1078. //处理transportInfo信息数据
  1079. $transportInfo = $vueData['transportInfo'];
  1080. //处理basicInfo信息数据
  1081. $basicInfo = $vueData['basicInfo'];
  1082. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1083. $businessPartners = $vueData['businessPartners'];
  1084. //处理routes 转船可能有多个情况
  1085. $routes = $vueData['routes'];
  1086. //处理marksAndDescription
  1087. $marksAndDescription = $vueData['marksAndDescription'];
  1088. //处理containerStatusData
  1089. $containerStatusData = $vueData['containerStatusData'];
  1090. //处理ocean_reference
  1091. $ref_no = array();
  1092. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  1093. if(!empty($ref_arr)){
  1094. foreach($ref_arr as $ref) {
  1095. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  1096. }
  1097. }
  1098. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  1099. $ocean_container_column = array();
  1100. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  1101. $container_column_config = array("Quantity" => array("formatter"=>"number","digits"=>0),
  1102. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1103. "Gross Weight" => array("formatter"=>"number","digits"=>3),
  1104. "CBM" => array("formatter"=>"number","digits"=>3),
  1105. "CFT" => array("formatter"=>"number","digits"=>3));
  1106. foreach($container_column as $cc){
  1107. if(!empty($container_column_config[$cc['name']])){
  1108. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],
  1109. "formatter" =>$container_column_config[$cc['name']]["formatter"],
  1110. "digits" =>$container_column_config[$cc['name']]["digits"],
  1111. "type" =>"normal");
  1112. }else{
  1113. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  1114. }
  1115. }
  1116. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",net_lbs from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  1117. $rss = common::excuteListSql($sql);
  1118. $quantity_unit = array();
  1119. $g_weight_tolal = 0;
  1120. $ch_weight_tolal = 0;
  1121. $ch_weight_tolal_grs_lbs = 0;
  1122. $cbm_tolal = 0;
  1123. foreach ($rss as $key => $rs) {
  1124. $unit = $rs['unit'];
  1125. if (array_key_exists($unit, $quantity_unit)) {
  1126. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  1127. } else {
  1128. $quantity_unit[$unit] = $rs['qty'];
  1129. }
  1130. $g_weight_tolal += $rs['grs_kgs'];
  1131. $ch_weight_tolal += $rs['net_lbs'];
  1132. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  1133. $cbm_tolal += $rs['cbm'];
  1134. //特殊处理weight
  1135. if(!empty($rss[$key]['grs_kgs'])){
  1136. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KGS";
  1137. }
  1138. if(!empty($rss[$key]['grs_lbs'])){
  1139. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LBS";
  1140. }
  1141. //为每个柜子下面单独加状态信息 ctnr_label content
  1142. $rss[$key]['containerStatusData'] = array();
  1143. foreach($containerStatusData as $_containerStatusData){
  1144. if(trim($_containerStatusData["ctnr_label"]) == trim($rs["ctnr"])){
  1145. $rss[$key]['containerStatusData'] = $_containerStatusData["content"];
  1146. }
  1147. }
  1148. }
  1149. $quantity_tolal = "";
  1150. foreach($quantity_unit as $uk => $uv){
  1151. // 使用substr()截取第一次出现之前的字符串
  1152. $uk = substr($uk, 0, strpos($uk, "-"));
  1153. $quantity_tolal.=$uv." ".$uk." ";
  1154. }
  1155. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  1156. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  1157. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  1158. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  1159. //Containers信息
  1160. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  1161. //Packing信息
  1162. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  1163. //Milestones info 列名固定
  1164. $Milestones = common::getMilestonesInfo($ocean,"sea",$_schemas,$vueData['EDI315TimeAndLocation']);
  1165. //页面固定写死的信息
  1166. $document_column = array();
  1167. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1168. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1169. $document_data = array();
  1170. $document = _getViewDocType($_REQUEST["_schemas"]);
  1171. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1172. $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'])."'");
  1173. if (!empty($document)) {
  1174. foreach ($document as $v) {
  1175. $file_type = $v['display_name'];
  1176. $file_arr = $this->getOceanFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  1177. $tar = json_decode($ocean_can_view_file,true);
  1178. if(!empty($tar[$v['display_name']])){
  1179. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1180. switch ($v['display_name']) {
  1181. case 'HBL':
  1182. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1183. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1184. from ra_online_doc_upload
  1185. 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']."'
  1186. order by id desc";
  1187. break;
  1188. case 'MBL':
  1189. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1190. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1191. from ra_online_doc_upload
  1192. 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']."'
  1193. order by id desc";
  1194. break;
  1195. case 'Others':
  1196. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1197. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1198. from ra_online_doc_upload
  1199. 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']."'
  1200. order by id desc";
  1201. break;
  1202. default:
  1203. $sql = "";
  1204. break;
  1205. }
  1206. if (!empty($sql)) {
  1207. $rss = common::excuteListSql($sql);
  1208. foreach ($rss as $rs) {
  1209. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1210. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  1211. "file_name" => $rs['file_name'],
  1212. "format_name" => $rs['format_name'],
  1213. "detail"=>$rs['upload_date'],
  1214. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1215. "from_system" =>'TOPOCEAN_KSMART');
  1216. }else{
  1217. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1218. "file_name" => $rs['file_name'],
  1219. "format_name" => $rs['format_name'],
  1220. "detail"=>$rs['upload_date'],
  1221. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1222. "from_system" =>'');
  1223. }
  1224. }
  1225. }
  1226. }
  1227. }
  1228. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1229. //按现在的逻辑,有值才会显示
  1230. foreach($file_arr as $f){
  1231. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1232. }
  1233. }
  1234. }
  1235. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1236. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  1237. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  1238. $email = $this->getEmail($ocean["serial_no"]);
  1239. $email['cc_email'] = $cc_email;
  1240. $email['emailRecords'] = $emailRecords;
  1241. global $_COPYRIGHT;
  1242. $data = array('transportInfo' => $transportInfo,
  1243. 'basicInfo' => $basicInfo,
  1244. 'businessPartners' => $businessPartners,
  1245. 'ref_no' => $ref_no,
  1246. 'packing' => $packing,
  1247. 'marksAndDescription' => $marksAndDescription,
  1248. 'containers' => $containers,
  1249. 'simplexData' =>$simplexData,
  1250. 'containerStatusData' => $containerStatusData,
  1251. 'document_info' => $document_info,
  1252. 'Milestones' => $Milestones,
  1253. 'routes' => $routes,
  1254. 'email' => $email,
  1255. 'ams_ss' => md5(md5($ocean['serial_no'])),
  1256. 'isf_ss' => $isf_ss,
  1257. 'transport_mode' =>"sea",
  1258. '_schemas' =>$_schemas,
  1259. 'uncode' =>$uncode,
  1260. 'serial_no' =>$serial_no,
  1261. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1262. 'a' =>common::deCode($serial_no, 'E'),
  1263. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1264. 'canEdiVgm' => _canEdiVgm(),
  1265. 'canViewAMSLog'=>_canViewAMSLog(),
  1266. 'canViewISFLog'=>_canViewISFLog(),
  1267. 'copyright' =>$_COPYRIGHT,
  1268. 'website' =>common::getWebiste($ocean['m_carrier']));
  1269. common::echo_json_encode(200,$data);
  1270. exit();
  1271. }
  1272. private function _air_ocean_detail(){
  1273. $serial_no = common::deCode($_GET['a'], 'D');
  1274. $sql = $this->getAirDetail($serial_no);
  1275. $air = common::excuteObjectSql($sql);
  1276. //根据air_milestone 判断 shipment status的state
  1277. $_schemas = $_REQUEST["_schemas"];
  1278. $air_milestone_status = common::excuteListSql("select code,
  1279. act_date,est_date,timezone
  1280. from air_milestone a
  1281. where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
  1282. order by id");
  1283. $state = -1;
  1284. if (!empty($air_milestone_status)) {
  1285. $state_arr = array();
  1286. foreach($air_milestone_status as $ms){
  1287. if($ms['code'] == "IFFCPU"){
  1288. $state_arr[] = 0;
  1289. }
  1290. if($ms['code'] == "IFFREC" || $ms['code'] == "IFFONB"){
  1291. $state_arr[] = 1;
  1292. }
  1293. if($ms['code'] == "IFFARR"){
  1294. $state_arr[] = 2;
  1295. }
  1296. if($ms['code'] == "IFFDEL"){
  1297. $state_arr[] = 3;
  1298. }
  1299. }
  1300. $state = max($state_arr);
  1301. }
  1302. $vueData = $this->returnAirDetailData($air,$air_milestone_status,$state);
  1303. //处理shipment data暂时写死
  1304. $simplexData = $vueData['shipmentData'];
  1305. //处理transportInfo信息数据
  1306. $transportInfo = $vueData['transportInfo'];
  1307. //处理basicInfo信息数据
  1308. $basicInfo = $vueData['basicInfo'];
  1309. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1310. $businessPartners = $vueData['businessPartners'];
  1311. //处理routes 转船可能有多个情况
  1312. $routes = $vueData['routes'];
  1313. //处理marksAndDescription
  1314. $marksAndDescription = $vueData['marksAndDescription'];
  1315. $quantity_tolal = empty($air['qty']) ? "" : $air['qty'].$air['qty_uom'];
  1316. $g_weight_tolal = empty($air['piece_count']) ? "" : sprintf("%.3f", $air['piece_count'])." KGS";
  1317. $ch_weight_tolal = empty($air['piece_count']) ? "": sprintf("%.3f", $air['weight'])." KGS";
  1318. $cbm_tolal = empty($air['cbm']) ? "" : sprintf("%.4f", $air['cbm'])." CBM";
  1319. //Packing信息
  1320. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
  1321. //Milestones info 列名固定
  1322. $Milestones = common::getMilestonesInfo($air,"air",$_schemas);
  1323. //页面固定写死的信息
  1324. $document_column = array();
  1325. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  1326. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  1327. $document_data = array();
  1328. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  1329. $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'])."'");
  1330. if (!empty($document)) {
  1331. foreach ($document as $v) {
  1332. $file_type = $v['display_name'];
  1333. $file_arr = $this->getAirFileByHbol($air['_mawb'] . '-' . $air['_mawb_name'], $air['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE);
  1334. $tar = json_decode($air_can_view_file,true);
  1335. if(!empty($tar[$v['display_name']])){
  1336. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  1337. switch ($v['display_name']) {
  1338. case 'HBL':
  1339. $sql = "SELECT (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('".$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']."'
  1343. order by id desc";
  1344. break;
  1345. case 'MBL':
  1346. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1347. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1348. from air_doc_upload
  1349. 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']."'
  1350. order by id desc";
  1351. break;
  1352. case 'Others':
  1353. $sql = "SELECT
  1354. (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1355. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  1356. from air_doc_upload
  1357. 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']."'
  1358. order by id desc";
  1359. break;
  1360. default:
  1361. $sql = "";
  1362. break;
  1363. }
  1364. if (!empty($sql)) {
  1365. $rss = common::excuteListSql($sql);
  1366. foreach ($rss as $rs) {
  1367. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1368. "file_name" => $rs['file_name'],
  1369. "detail"=>$rs['upload_date'],
  1370. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1371. "from_system" =>'');
  1372. }
  1373. }
  1374. }
  1375. }
  1376. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1377. //按现在的逻辑,有值才会显示
  1378. foreach($file_arr as $f){
  1379. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  1380. }
  1381. }
  1382. }
  1383. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1384. $emailRecords = $this->getCommunicationNew($air["serial_no"]);
  1385. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $air["serial_no"] . "' order by id desc limit 1");
  1386. $email = $this->getEmail($air["serial_no"]);
  1387. $email['cc_email'] = $cc_email;
  1388. $email['emailRecords'] = $emailRecords;
  1389. global $_COPYRIGHT;
  1390. $data = array('transportInfo' => $transportInfo,
  1391. 'basicInfo' => $basicInfo,
  1392. 'businessPartners' => $businessPartners,
  1393. 'ref_no' => array(),
  1394. 'packing' => $packing,
  1395. 'marksAndDescription' => $marksAndDescription,
  1396. 'containers' => array(),
  1397. 'simplexData' =>$simplexData,
  1398. 'containerStatusData' => array(),
  1399. 'document_info' => $document_info,
  1400. 'containers' => array(),
  1401. 'Milestones' => $Milestones,
  1402. 'routes' => $routes,
  1403. 'email' => $email,
  1404. 'ams_ss' =>"",
  1405. 'isf_ss' => "",
  1406. '_schemas' =>$_schemas,
  1407. 'uncode' =>"",
  1408. 'transport_mode' =>"air",
  1409. 'serial_no' =>$serial_no,
  1410. 'is_subscribe' =>common::checkedSubscribe($serial_no),
  1411. 'a' =>common::deCode($serial_no, 'E'),
  1412. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1413. 'canEdiVgm' => _canEdiVgm(),
  1414. 'canViewAMSLog'=>_canViewAMSLog(),
  1415. 'canViewISFLog'=>_canViewISFLog(),
  1416. 'copyright' =>$_COPYRIGHT,
  1417. 'website' =>"");
  1418. common::echo_json_encode(200,$data);
  1419. exit();
  1420. }
  1421. private function _ocean_excel() {
  1422. // $ss = "Am9TL0p6E%2FT3aJmJClY%2F7VDgtwMSlzvZ0XSGJyrsru29di5bQCy%2F96%2BEzjFomfp6tinP89uz1oCrCpnbBt6I%2FEfVv%2FR7Xmb0CJa48I9sgCdMjAxDGDL%2FjdC%2B49sDMhC4QSOjd84JFr6HXw76Ro7fE2veXiNgBVUNnX%2BCdwV22hMYS723o8UTX%2FIZyqj%2BnHi187%2FlDughAiPWwKGKEp1kv7VshCSCtVdR6%2FWbA%2Fw3Ux3VtTFvcpHhoRkEUWkAMFgfRkwcphRwFQXbLyLkmzkh4S%2BNUSuQZI5g7%2FJSKQ7CGe8pAqxIka%2BPvApALj30MMdpXQp%2BMWbwvI%2FkdmO2iOcpKpGEyuAw8xN%2FXZ5OOQESqjbnd7mzVsIfxM2viTk%2FtZtbmBOp3IjuBb2Q4EVUgyNOQN3i4X9FHWeUrX5OXU%2B4U%2F1RqPaaJnNKcLmQnvKsRgwQVwpNdKcqZ6mSJG%2FHch%2BbOCJ8q3HDKBWNf77Emj9fnw280BMzn6BiamAoEFq8j5wQJn5hw5YSe8HIDJdFWJRwGjWYaFPT3A%2BoUMQX8bqsl%2BtrEc3TmhO6Jq%2BCWDuUwDmp56JpQTgb1UP5WlvXKmXZJpVDEkLC2Tln3HasgMICG8MPjYJb4Hbn%2F5ll87yfw%2BAOuZY8XiXBX7nTaKiQQZ9bAcDy8QQHHOiHDvkpRBE%2BS%2Fv8%2FAPqyj9gzfgy5Wv9lvyGX5ngIla9IguT3ahI7OWxpbrxgHblC%2FWGBqIkEKVGmXvd1nAYgghW%2BWHEgnWJ6mAtiYRcqT3RukWjnTKsJo11lmJIayfK32Y9iAbdlElFPTTgPfcecVnr3gHai10cgYjS9HojqBe0MhimBPTFFjMZiOIxNmUX2mmdlXMisdb9ViBDut4PfGRryLGmjN2O6JSAWDQZH5%2Bprh8t0bew%2B4iCxJdgCdqu2BWP7pwhwD8i8EsAdCeY%2Btej0IF8VbKybbBmpzZSesnJCLRGKOmweyWUN4QO2DAo1G17Rh%2Fe3IIhJlu%2F3EZF48p%2B%2F3FNt%2FhR0wYqyIwvrCW66Q1Rwx9cOKEHm3qoVz8Om5R7j0Vyng0iVjRomdo7gUhrrnvwCoFem65PGSpAvtoYszQ57HjspnV77syxnIyWND315yY4NmNHSt5%2B6%2FKKLy2W4K6qK6ZKO%2B3dbpoNJudMQzm%2Bhd42vYjnCntY296Ky8SaroCmOYuyLyZ0y3VplIQ6LuwC2b6IQewjg6h8dLvq29ek6QkL8IEybQfZh852rE2GA8ww6hE%2FCxbgKckXGIOrAh6y1tFNIp8OwSXpxQpJuZpOlmJqC979rFKaD9dOShii%2Ff59YUksON9hoBJgBXQAfdtISIBHdLuCk6gX2lJOpWg0nlTmItdCethFA%2BHTo4peR8RIlrJmf416beAHoYBFAw4OkCx0Eeo8UHYE5xd6BMpIOkBPCaumh3v0N9DplchxOyz05%2FtsRg2PNT%2FhhcF81wsr0Syxt0MC3t26%2FYoe3DIulCfQGXJfuGK6byId%2FkA3OaXH9TfUMZLtPBgfVRTfQDhOj9ZEvFslpWtmPvuhmk5Lh4s92RdmkbwuL2Xrn1Iyl46xmz7FJDcJyG%2FUq1zyE%2BiJnOaDxawkyCePJRFcI2p%2FMeFf58BogMWKuSds1e8nq0xGmq%2BvlJFJ6lcAivGtjAV2au4Znhw%2B%2BMv9ldMteQuC%2BzmmTZSvuxC%2Bsnq7HRgl6rLgrIdT471%2Bz3E8JTjdOqZN9WdEkrG9OUfUZTEj5HhVyeRhx84iPUEbPMVJ3pADqS8KciSr%2BiGWTj6d9utm%2BQUoeqHMrY8%2ByL2eI9i3Bts2mZUti0PGd%2FYhxjl0vFECVltGIzWosJLWpcmfkaD%2BIeEElI9I0WwHc0G44sbx5kIwCZIODRTpOOkYzhj%2FUXsSVmfGtD5Zw6Jn5I2qOrP8QdV8GFtqrK3i%2Fy%2FUbPRH98Wx9%2BZVj%2BFotbm4gGvcWP1gGLqkX2AWtelUt%2B4jRPWmMbaR%2Ba8UGHRxkFAX07fpjyCe7FUoaTkh69c2KzvTFdvyihQ1RopFfNDPF7ZhNTcyZTK02DTx6TSKMP2UFdS%2Bg1yYj9xJUF2LnuZA4HSlYjb%2BWUiWv2M%2BMUGrX%2BiAI6AAHv6tlreu8p%2B1pNMCHfvlBGgtxkl7uPTcn8oeU4LwZ5r70HWdjJ%2BE%2BnrbrKpXNdNRzncVQHoI6tLpwj23r2ED351oFbuqhOefMjm2MSKcQfnCqr1rghOvl4ICTKGoscYfX3FT6UYSFtyySgYcU9Ou59VL6EKQUPsqwDmg96VZjBO96pXn7VK%2BRRtrez67oKw53xtFlMjMpl8kDPYkQMxtd1KARXF6sWsHY4ijGJNQ%2B3RIbiGV4CEQDjvOLsR7N6C2WIvNNy44OiYTeLQbRAbWV4HQWwS4337BZhzaWfC5sm0DhsgrRGJWyDVcdniqikiowGd73wRpqxVwpbSA05SViPCU1HIRxP0E62j7coKK3vWAPEE036d2ORVnH52eqyWOTQKKbfSqTCFPvDBXKMO4c4Zq%2BdhA3ODp6v0H4Dk60OjM%2BhEzPFQ8SjD5nO0SezoupfKmK7SEglGfqCwgXgBgRvdawamiRki%2BXVyf5oraZb2eEYLwEiktiH98wrLCO1ZG4cIrdODR79P5LXVFhiX1hqcYLA95o2uwxoWNklv0tfcFKvNSKG4y%2F%2FJo6JyZsVvMqVG2qtONMI1v1y%2FwgG8pFICB%2BU6Qo3crcxce97IXzu%2BltNwfMQ5AqlKxf4iB%2FH9%2F7YDxS55rd9vtHFR2SazxGhb%2Fe12landQU8lUT5RcPvwz4I3zKehY8vCqV3c5EPgGPMclcSth2O8tv8eeEHMAIfvC4dp8YZdhdKvALY%2FaCKllcDZwfHU5SVqpG7RPHw%2Fx90Sbx62XXTMhhxvgmYWCExxNAFgy4EPi%2FMgCnjdKSLRb9Z9DSoeyfmkIpVRHYfSFMIh%2Bo%2BLCEYt8ipsl8%2F4iRoKkR5MANHSOo7pwV%2Bbnr6acCIq4QBoo7wGbKxFGnDnOcXRW7bK4JD8qEVAsSQc7OhGY8knMKoAfwh4nUUsSw%2F38mAMMci%2Fp0gRn2hIjw%2BoRTyhsAKo2mEaDhBdlNS6XR1PVRijNJ2JFFV0yMBtZY3Ad6ycqQ%2FcOm7SDY%2F09JHhSqsxkiWpt9R4fy7AzehiGFPJ5zUt2eKxF%2FP6Y1Dy2mTls0w1LTKjkXdjzBeOXwTaFWejsLHN7jYV%2F%2BJ4oIbNzAHFbieNCCvd0XODNE3LW0RAFs86ke2DAb3FBLXMhw32yRtUgMoo2G3OwjfVyPDw6cdeJd8xN9S9z4%2FOUPfVyEiWyfWbCkjL%2BnIjWML18HHeksCxylXGwmjFTZRelCpHCTNVWU%2Bys3VA%2FO9141378K0N8BxboAeIvEqZRCe7F1wihiMhRvttSDyKYIimdWuoYFbAbCp8TelFMqBB5WdSU4rXZF0erW4Yy%2Bf0q%2FWEOZ%2F0puuaIgVj94nCol7Fp7yQrQMrYJdA6EfOldiRPh7RajkuIsm4sCaCYrtFT81%2FEwM2p4hiQHRKNeEHL841DybEqvXg0q4kg8dw65EaJ24lazii%2FBmakXw7LzLCMz3N%2FveUKKC%2FWSvaNggcQfLCed4vBasN1BtP4Nk%2FRRl7ytxP%2FU20i%2FQMZSlV5Z3j8V2%2B6mjHT0LIYKHrUj0qtjc59wO6KAIEOcFjuvNjl1CokIF8CgV8LveLVWnB0sOA7sjisxJw8wDnK03Nk8PuR3lCMqNv%2FuxHO17pDkRKQShG9jyRW9Ymev5K%2FwbLoKBtrOL9XH2gROV0K0eU%2BV1wm9b%2FksdTgJZZafkMx6jeAkTmdtLcYWY6stS6qr4%2ByAwA4WEKFoGbKzpzsqz2f7vWselzynQDgiwp3anGBcrEDCf0a3w13epv6y58SeTyIeiWlmn%2Bfc2ju7k1aGO9a57JLUiqHwPh2saQgR5%2BQN9qdTkiZG58ACyTh5mn1PS7G52HjNeAOuE3RA0%2FdPUgW0AEcrL0NzCos2XPioxZT%2Ba5UZsodPLqJqjP1GAwMvLIpXJb7%2BhweqHCwQy8P8FL6tLphVUpEZhOn57jocnvCBYjeHtkbwaajn8cNpRcqhMrpVbIHdjO5a0s1tH2abcUSkFhpjzXYAt8HZQIfa2SHFtcxw5lJrCoScMyHKt63CpY6kpzeIQSgupspMy%2FX22ZeIQdeVtDerJ%2FjYACawe0yR0WsjznkhMSYlm97GP5ga%2BSGHJ2KvZOBgN2aCHqdx9LEuikQvDH2OmhhUSi%2FxJYvUWKacwP1KcJXdQATB4HTXLHAeke64oV4MBlSVPfuRswfEXO81i7DCaOhHIerGImY3m9D5nietI4sJeKX%2B9%2BPOZhMB0kfn7yQ1fTIPEyBOCFZVeq8pGgm8T7ld5Myxz54bFVuQQk6G8tlJbUaAwkHF9ZnfK5FEGUCBxyot44uAU9ZbWZKPbdGU7C6QMtoGHPZOKq2CGqMS1sjrOxv%2B%2B8bqOkgwlqsIuJUTN8ETWoCJ95EbZk35mB8Y%2FBwOXkLFDcZgXuZ76XcgamMVzqArdfPPCFU028CpI9BbGuCKReOLbg2%2FhtPveCnMvjGoPUr1cnmfZZXpu7Ao9iSan75mWV7b5gkUfUSBDe8o6BhRUJJtAYmv%2Byft9%2BIKqJvwm6bgnRk%2F9fRUlLXq7%2FqMzXBk4xtMaPPtRpn%2BtvU0%2FSDIdWCclWExRG6w4ujCUNoBB01dlm1VvonsabgIOPqpnffYQ39I1mJmwl1HfxpD%2BG2dtPXuyqoB5P1x3DZpe7GTbRwYPjB7BAjRX94C%2Fw28D2nWhaYQfuw11JgOre8uK4jESujbYdMiVGZROCRcri51YUZCeL3ggQE%2FC4N%2FHt31lSTKpxW8mM%2BFatrWjrzIsY40xO9AmWxEYvN9Q4yHRjgLkcEKa7WHapIMSUDApK4JU%2BNc81Y5LU%2BQBMa787NUXzeustBM6kT9lr52aTGypd%2FgpBvdovBPQgOUvO05s7OryoYeLVFsuF50E4mvbBuFlLfOedNrchxgFWn%2FjuxjFtiKS9wvZB2xSt6AQKYL%2BSKfM2SZ9KlC1nbTuzzMd0sWc4llES3zYKpUwLVKFhjloJKL2VrCYWuIIEnRkQ63JZsKERK%2BjR6hQ5JuPNn6S%2BcMqKHLbJsdmW3kjNrykxOYJBTlgbcoWkB9e94m5Xp8%2BhtW6uZBIoGbJES1zZ9DvvrR7COtQ0vWF6KR9ohjSL0pYZACmPyTu3aPGq3kxpoq4Ri4wbsliI0RojMjdpx8BFdCKP89RO3fI55A%2FH0ThlwF1%2BlAd5p6jdM9OqtRMP6%2FQgg2IALwT7f5Kuhc4%2Bjxr7UfkVkM65M1tus49cUXzj7Euy0vTYlL%2BSqTj7Hu%2BIdo%2B%2FvZUgzoCI02jH550H269XfQc7GuD02kZfb591InNQ6Y0NRyOl7AyMLg6MAZp%2FjRGlgQrgUNoNrVL3H8rKQ0OBdHFFMHzxTMHaEQM%2FtI2grSQfnhjPDuVDHbWAxkUqQAUFIZJLzSKwMEy9IcCvmcyTs5uw9G9Bv";
  1423. // $sql = common::deCode($ss, 'D');
  1424. // error_log($sql);
  1425. $sql = common::deCode($_POST['tmp_search'], 'D');
  1426. //$sql = substr($sql, 0, strripos($sql, " limit"));
  1427. if(!empty($sql)){
  1428. $rs = common::excuteListSql($sql);
  1429. }
  1430. //去除null
  1431. foreach($rs as $index => $val) {
  1432. foreach($val as $index_2 => $_val) {
  1433. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  1434. $rs[$index][$index_2] = "";
  1435. }
  1436. }
  1437. }
  1438. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  1439. foreach($rs as $index => $val) {
  1440. //返回加密serial_no
  1441. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  1442. //$rs[$index]["mode"] = "Ocean Freight";
  1443. $rs[$index]["Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  1444. //status 改为ocean_milestone里的信息
  1445. $rs[$index]["Status"] = $rs[$index]["new_status"];
  1446. }
  1447. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  1448. exit;
  1449. }
  1450. private function _revenue_download(){
  1451. $r2_cloumn = array();
  1452. $r2_cloumn[] = array("title" => "Month","dataIndex"=>"month");
  1453. $r2_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1454. $r2_cloumn[] = array("title" => "Total Amount","dataIndex"=>"invoice_amount");
  1455. $r3_cloumn = array();
  1456. $r3_cloumn[] = array("title" => "Invoice Issue Date","dataIndex"=>"invoice_date");
  1457. $r3_cloumn[] = array("title" => "Invoice Number","dataIndex"=>"invoice_no");
  1458. $r3_cloumn[] = array("title" => "HBL Number","dataIndex"=>"h_bol");
  1459. $r3_cloumn[] = array("title" => "Amount","dataIndex"=>"ivnoice_amount");
  1460. $r3_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1461. $date_from = null;
  1462. $date_to = null;
  1463. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1464. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1465. $date_from = $date_start."-01";
  1466. }
  1467. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1468. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1469. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1470. }
  1471. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1472. //$sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1473. //$sql = "select * from _test_data_table";
  1474. //$r2_data = common::excuteListSql($sql);
  1475. //只取r3 代码去计总r2 ,避免二次请求数据库
  1476. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r3;";
  1477. //$sql = "select * from _test_data_table_two";
  1478. $r3_data = common::excuteListSql($sql);
  1479. $group_data = array();
  1480. foreach($r3_data as $r3){
  1481. $r3['invoice_date'] = strtoupper(date('M,Y', strtotime($r3['invoice_date'])));
  1482. $group_data[] = $r3;
  1483. }
  1484. //按货币和日期分组
  1485. $groupedItems = array();
  1486. foreach ($group_data as $item) {
  1487. $key = $item['currency']."_".$item['invoice_date'];
  1488. if(array_key_exists($key, $groupedItems)){
  1489. $temp = $groupedItems[$key];
  1490. $temp['invoice_amount'] = $temp['invoice_amount'] + $item['ivnoice_amount'];
  1491. $groupedItems[$key] = $temp;
  1492. }else{
  1493. $groupedItems[$key] = array("month"=>$item['invoice_date'],"currency"=>$item['currency'],"invoice_amount"=>$item['ivnoice_amount']);
  1494. }
  1495. }
  1496. $r2_data = array();
  1497. foreach($groupedItems as $gt){
  1498. $gt['invoice_amount'] = number_format($gt['invoice_amount'], 4, '.', '');
  1499. $r2_data[] = $gt;
  1500. }
  1501. common::echo_json_encode(200,array("msg"=>"success","r2" => $r2_data,"r3"=>$r3_data,"r2_cloumn" => $r2_cloumn,"r3_cloumn" => $r3_cloumn,
  1502. "r2_title"=>"Monthly Summary Data","r3_title"=>"Invoice Detailed Data"));
  1503. exit;
  1504. }
  1505. private function _ams_isf_log(){
  1506. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  1507. $ams_ss = $_POST['ams_ss'];
  1508. $isf_ss = $_POST['isf_ss'];
  1509. $amsLog = array();
  1510. //页面固定写死的信息
  1511. $amsLog_column = array();
  1512. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1513. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1514. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  1515. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  1516. $amsLog["amsLog_column"] = $amsLog_column;
  1517. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1518. $amsLog["data"] = array();
  1519. if (_canViewAMSLog()) {
  1520. $s = $ams_ss;
  1521. //$s = "PDLA200127H";
  1522. if (!empty($s)) {
  1523. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  1524. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  1525. foreach ($cc as $v){
  1526. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  1527. }
  1528. //考虑一个情况
  1529. if (utils::count($amses) > 0) {
  1530. $ams = $amses[0];
  1531. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  1532. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  1533. if (empty($ams[0]['h_bol'])){
  1534. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1535. $amsLog["data"] = array();
  1536. }else{
  1537. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  1538. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  1539. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  1540. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  1541. $amsLog["msg"] = "";
  1542. $amsLog["data"] = $log;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. $isfLog = array();
  1548. //页面固定写死的信息
  1549. $isfLog_column = array();
  1550. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1551. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1552. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  1553. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  1554. $isfLog["isfLog_column"] = $isfLog_column;
  1555. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1556. $isfLog["data"] = array();
  1557. if (_canViewISFLog()) {
  1558. if (!empty($isf_ss)) {
  1559. $ss = $isf_ss;
  1560. $len = strlen($ss);
  1561. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  1562. if (empty($b)){
  1563. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1564. $isfLog["data"] = array();
  1565. }else{
  1566. $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");
  1567. }
  1568. if (!empty($isf)) {
  1569. if (!empty($isf['dob'])){
  1570. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  1571. }
  1572. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  1573. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  1574. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  1575. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  1576. order by cbpreplytime desc, rowid desc");
  1577. $isfLog["msg"] = "";
  1578. $isfLog["data"] = $msg;
  1579. }else{
  1580. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1581. $isfLog["data"] = array();
  1582. }
  1583. }
  1584. }
  1585. $data =array("msg"=>"success",
  1586. "canViewAMSLog" => _canViewAMSLog(),
  1587. "canViewISFLog" => _canViewISFLog(),
  1588. "amsLog" =>$amsLog,
  1589. "isfLog" =>$isfLog);
  1590. common::echo_json_encode(200,$data);
  1591. exit;
  1592. }
  1593. private function getEmail($serial_no) {
  1594. return utils::getEmail($serial_no);
  1595. }
  1596. private function getCommunicationNew($serial_no) {
  1597. $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");
  1598. $emialRecords =array();
  1599. foreach ($list as $k => $v) {
  1600. $msg =array();
  1601. $msg["name"] = $v["add_by"];
  1602. $msg["creatTime"] = $v["add_times"];
  1603. $msg["content"] = urldecode($v["web_content"]);
  1604. $emialRecords[] = $msg;
  1605. }
  1606. return $emialRecords;
  1607. }
  1608. /*
  1609. * get file by hbol/destination
  1610. * H:HBL
  1611. * M: MBL
  1612. * F: FL
  1613. * I: C/I & Packing list
  1614. */
  1615. private function getOceanFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  1616. $_schemas = $_REQUEST['_schemas'];
  1617. $types = strtolower($types);
  1618. $types = explode(";", $types);
  1619. $m_bs = explode(";", $m_bs);
  1620. $otheres = NULL;
  1621. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1622. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1623. $file = array();
  1624. foreach ($types as $k => $type) {
  1625. $m_b = $m_bs[$k];
  1626. if (strtolower($m_b) == 'm')
  1627. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1628. 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";
  1629. if (strtolower($m_b) == 'h')
  1630. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1631. 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";
  1632. if (strtolower($m_b) == 'a')
  1633. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1634. 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";
  1635. if (!empty($sql)) {
  1636. $rss = common::excuteListSql($sql);
  1637. foreach ($rss as $rs) {
  1638. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1639. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1640. "file_name" => $rs['file_name'],
  1641. "format_name" => $rs['format_name'],
  1642. "detail"=>$rs['upload_date'],
  1643. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1644. "from_system" =>'TOPOCEAN_KSMART');
  1645. }else {
  1646. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1647. "file_name" => $rs['file_name'],
  1648. "format_name" => $rs['format_name'],
  1649. "detail"=>$rs['upload_date'],
  1650. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1651. "from_system" =>'');
  1652. }
  1653. }
  1654. }
  1655. }
  1656. return $file;
  1657. }
  1658. /*
  1659. * get file by hbol/destination
  1660. * H:HBL
  1661. * M: MBL
  1662. * F: FL
  1663. * I: C/I & Packing list
  1664. */
  1665. private function getAirFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE) {
  1666. $_schemas = $_REQUEST['_schemas'];
  1667. $types = explode(";", $types);
  1668. $m_bs = explode(";", $m_bs);
  1669. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1670. $file = array();
  1671. foreach ($types as $k => $type) {
  1672. $m_b = $m_bs[$k];
  1673. if (strtolower($m_b) == 'm')
  1674. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1675. 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";
  1676. if (strtolower($m_b) == 'h')
  1677. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1678. 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";
  1679. if (strtolower($m_b) == 'a')
  1680. $sql = "SELECT (SELECT format_name from $_schemas.air_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1681. 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";
  1682. if (!empty($sql)) {
  1683. $rss = common::excuteListSql($sql);
  1684. foreach ($rss as $rs) {
  1685. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1686. "file_name" => $rs['file_name'],
  1687. "format_name" => $rs['format_name'],
  1688. "detail"=>$rs['upload_date'],
  1689. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1690. "from_system" =>'');
  1691. }
  1692. }
  1693. }
  1694. return $file;
  1695. }
  1696. /*
  1697. * download file
  1698. */
  1699. private function _download() {
  1700. $url = common::deCode($_GET['url'], 'D');
  1701. common::download_file($url);
  1702. }
  1703. private function save_vgm() {
  1704. $schemas = $_POST["schemas"];
  1705. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1706. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1707. $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"] . "'");
  1708. $address = $contact["address_1"];
  1709. if (!empty($address)) {
  1710. $address .= "\r\n";
  1711. }
  1712. $address .= $contact["address_2"];
  1713. if (!empty($address)) {
  1714. $address .= "\r\n";
  1715. }
  1716. $address .= $contact["address_3"];
  1717. if (!empty($address)) {
  1718. $address .= "\r\n";
  1719. }
  1720. $address .= $contact["address_4"];
  1721. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1722. global $db;
  1723. $db->StartTrans();
  1724. if (empty($_POST["is_send"])) {
  1725. $_POST["is_send"] = 'f';
  1726. }
  1727. if (empty($exists)) {
  1728. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1729. $value["serial_no"] = $serial_no;
  1730. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1731. $value["modify_user"] = _getLoginName();
  1732. $value["modify_time"] = "now()";
  1733. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1734. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1735. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1736. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1737. $value["is_send"] = $_POST["is_send"];
  1738. $value["action"] = "New";
  1739. $value["type"] = "Shipper";
  1740. $value["m_bol"] = $ocean["m_bol"];
  1741. $value["master_base_number"] = $ocean["master_base_number"];
  1742. $value["shipper_id"] = $ocean["from_station"];
  1743. $value["shipper"] = $contact["company"];
  1744. $value["shipper_address"] = $address;
  1745. $value["shipper_contactname"] = $contact["contactname_1"];
  1746. $value["shipper_email"] = $contact["email_1"];
  1747. $value["shipper_fax"] = $contact["fax"];
  1748. $value["shipper_telephone"] = $contact["phone_1"];
  1749. $value["update_uuid"] = utils::uuid();
  1750. $value["h_bol"] = $ocean["h_bol"];
  1751. $value["from_station"] = $ocean["from_station"];
  1752. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1753. $db->Execute($sql);
  1754. } else {
  1755. $serial_no = $exists;
  1756. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1757. $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(),"
  1758. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1759. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1760. }
  1761. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1762. foreach ($_POST["container_no"] as $i => $cv) {
  1763. $value1["serial_no"] = $serial_no;
  1764. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1765. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1766. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1767. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1768. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1769. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1770. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1771. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1772. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1773. $value1["master_base_number"] = $ocean["master_base_number"];
  1774. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1775. $db->Execute($sql);
  1776. }
  1777. if ($db->CompleteTrans() === FALSE) {
  1778. return "error";
  1779. } else {
  1780. return "success";
  1781. }
  1782. }
  1783. private function getOceanDetail($serial_no) {
  1784. $order_from = $_REQUEST['_schemas'];
  1785. $_schemas = $_REQUEST['_schemas'];
  1786. if($_schemas == 'public'){
  1787. $_schemas = "ocean";
  1788. }
  1789. $sql = "with o as(
  1790. SELECT o.* from ocean o where serial_no = '" . $serial_no . "'
  1791. )
  1792. SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1793. o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,koe.loadterm
  1794. from o
  1795. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  1796. consignee_uncode,consignee_city,incoterms,
  1797. fport_of_loading_un,
  1798. mport_of_discharge_un,
  1799. place_of_receipt_un,
  1800. place_of_delivery_un,
  1801. etd as oo_etd,
  1802. eta as oo_eta,
  1803. atd as oo_atd,
  1804. ata as oo_ata,
  1805. carbon_emission,
  1806. port_of_transshipment_un,
  1807. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1808. (select uncity from $order_from.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  1809. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1810. (select uncity from $order_from.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1811. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1812. (select uncity from $order_from.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  1813. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1814. (select uncity from $order_from.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  1815. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1816. (select uncity from $order_from.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  1817. po_no as _po_no,
  1818. CASE
  1819. 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
  1820. 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
  1821. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1822. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1823. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1824. ELSE 'Created'::text
  1825. END AS new_status
  1826. FROM public.kln_ocean oo WHERE oo.serial_no::text = o.serial_no::text and order_from = '$order_from') oo ON true
  1827. LEFT JOIN LATERAL ( SELECT loadterm
  1828. FROM public.kln_ocean_extend koe WHERE koe.serial_no::text = o.serial_no::text and koe.order_from = '$order_from') koe ON true
  1829. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1830. address_1 as cn_address_1,
  1831. address_2 as cn_address_2,
  1832. address_3 as cn_address_3,
  1833. address_4 as cn_address_4,
  1834. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1835. phone_1 as cn_phone
  1836. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1837. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1838. address_1 as sh_address_1,
  1839. address_2 as sh_address_2,
  1840. address_3 as sh_address_3,
  1841. address_4 as sh_address_4,
  1842. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1843. phone_1 as sh_phone
  1844. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1845. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1846. address_1 as aa_address_1,
  1847. address_2 as aa_address_2,
  1848. address_3 as aa_address_3,
  1849. address_4 as aa_address_4,
  1850. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1851. phone_1 as aa_phone,
  1852. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1853. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1854. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1855. address_1 as dd_address_1,
  1856. address_2 as dd_address_2,
  1857. address_3 as dd_address_3,
  1858. address_4 as dd_address_4,
  1859. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1860. phone_1 as dd_phone,
  1861. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1862. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1863. LEFT JOIN LATERAL ( SELECT
  1864. city as fd_city,
  1865. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1866. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1867. //error_log($sql);
  1868. return $sql;
  1869. }
  1870. private function getAirDetail($serial_no) {
  1871. $order_from = $_REQUEST['_schemas'];
  1872. $_schemas = $_REQUEST['_schemas'];
  1873. if($_schemas == 'public'){
  1874. $_schemas = "ocean";
  1875. }
  1876. $sql = "with o as(
  1877. SELECT oo.*,m_bol as _m_bol, h_bol as _h_bol,
  1878. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1879. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.fport_of_loading_un limit 1) as pol_uncity,
  1880. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1881. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1882. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1883. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_receipt_un limit 1) as por_uncity,
  1884. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1885. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_delivery_un limit 1) as pod_uncity,
  1886. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1887. (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.final_desination_uncode limit 1) as _pd_uncity,
  1888. CASE
  1889. 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
  1890. 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
  1891. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1892. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1893. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1894. ELSE 'Created'::text
  1895. END AS new_status
  1896. from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
  1897. )
  1898. SELECT o.* ,sh.*, cn.*,
  1899. aa.*,dd.*,fd.*,air.*
  1900. from o
  1901. LEFT JOIN LATERAL ( SELECT departure_airport_name as fport_of_loading_exp,
  1902. destination_airport_name as mport_of_discharge_exp,
  1903. mawb as _mawb, mawb_name as _mawb_name, hawb as _hawb
  1904. FROM $order_from.air a WHERE a.serial_no = o.serial_no) air ON true
  1905. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1906. address_1 as cn_address_1,
  1907. address_2 as cn_address_2,
  1908. address_3 as cn_address_3,
  1909. address_4 as cn_address_4,
  1910. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1911. phone_1 as cn_phone
  1912. FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
  1913. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1914. address_1 as sh_address_1,
  1915. address_2 as sh_address_2,
  1916. address_3 as sh_address_3,
  1917. address_4 as sh_address_4,
  1918. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1919. phone_1 as sh_phone
  1920. FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
  1921. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1922. address_1 as aa_address_1,
  1923. address_2 as aa_address_2,
  1924. address_3 as aa_address_3,
  1925. address_4 as aa_address_4,
  1926. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1927. phone_1 as aa_phone,
  1928. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1929. FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
  1930. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1931. address_1 as dd_address_1,
  1932. address_2 as dd_address_2,
  1933. address_3 as dd_address_3,
  1934. address_4 as dd_address_4,
  1935. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1936. phone_1 as dd_phone,
  1937. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1938. FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
  1939. LEFT JOIN LATERAL ( SELECT
  1940. city as fd_city,
  1941. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1942. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1943. //error_log($sql);
  1944. return $sql;
  1945. }
  1946. private function returnOceanDetailData($ocean,$state){
  1947. $data = array();
  1948. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  1949. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  1950. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  1951. $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
  1952. $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
  1953. /* Container Status */
  1954. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1955. //记录所有的信息 EDI315TimeAndLocation
  1956. $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
  1957. $data['containerStatusData'] = $EDIDate['containerStatusData'];
  1958. $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
  1959. $VD = $EDIDate['VD'];
  1960. $VA = $EDIDate['VA'];
  1961. //处理shipment data
  1962. $ocean_milestone_status = common::excuteListSql("select code,
  1963. act_date,est_date,timezone
  1964. from ocean_milestone a
  1965. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1966. order by id");
  1967. $ocean_milestone_status_code = array();
  1968. foreach($ocean_milestone_status as $oms){
  1969. $ocean_milestone_status_code[$oms['code']] = $oms;
  1970. }
  1971. if ($state < 1){
  1972. //未发生前
  1973. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1974. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1975. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  1976. }
  1977. } else{
  1978. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  1979. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1980. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  1981. }
  1982. }
  1983. //先处理一下 ATD 和 ATA,在进行后面的取值
  1984. if(empty($ocean['atd']) && !empty($VD)){
  1985. $ocean['atd'] = $VD;
  1986. }
  1987. if(empty($ocean['ata']) && !empty($VA)){
  1988. $ocean['ata'] = $VA;
  1989. }
  1990. $simplexData = array();
  1991. //place_of_Receipt
  1992. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1993. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  1994. $children = array();
  1995. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1996. //发生后,未发生前没有
  1997. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1998. }
  1999. $place_of_Receipt_stauts["children"] = $children;
  2000. $simplexData[] = $place_of_Receipt_stauts;
  2001. //port_of_Loading
  2002. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2003. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2004. $children = array();
  2005. if ($state < 1){
  2006. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  2007. } else{
  2008. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2009. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2010. }
  2011. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  2012. }
  2013. $port_of_Loading_stauts["children"] = $children;
  2014. $simplexData[] = $port_of_Loading_stauts;
  2015. //Port of Discharge
  2016. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2017. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2018. $children = array();
  2019. // if ($state < 2){
  2020. // //未发生前
  2021. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  2022. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  2023. // }else{
  2024. // //没有,取eta
  2025. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2026. // }
  2027. // } else{
  2028. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2029. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2030. // }
  2031. // }
  2032. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  2033. if ($state < 2){
  2034. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  2035. }else{
  2036. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2037. }
  2038. $port_of_Discharge_status["children"] = $children;
  2039. $simplexData[] = $port_of_Discharge_status;
  2040. //Place of Delivery
  2041. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2042. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2043. $children = array();
  2044. if ($state < 3){
  2045. //未发生前
  2046. } else{
  2047. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2048. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2049. }
  2050. }
  2051. $simplexData[] = $place_of_Delivery_status;
  2052. $data['shipmentData'] = $simplexData;
  2053. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2054. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  2055. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2056. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  2057. "etd_timezone" =>$ocean['pol_timezone'],
  2058. "atd_timezone" =>$ocean['pol_timezone'],
  2059. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2060. "eta_timezone" =>$ocean['mpod_timezone'],
  2061. "ata_timezone" =>$ocean['mpod_timezone']);
  2062. $data['transportInfo'] = $transportInfo;
  2063. //处理basicInfo信息数据
  2064. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  2065. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  2066. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2067. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2068. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2069. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>$ocean['loadterm'],
  2070. "Shipment Type" =>$ocean['manifest_type'] == "GPE" ? "LCL" : $ocean['manifest_type']);
  2071. $data['basicInfo'] = $basicInfo;
  2072. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2073. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2074. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2075. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2076. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2077. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2078. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2079. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2080. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2081. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2082. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2083. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2084. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2085. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2086. $data['businessPartners'] = $businessPartners;
  2087. //处理routes 转船可能有多个情况
  2088. if ($ocean['is_vessel_direct'] <> "t"){
  2089. //不是直航
  2090. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2091. "destination" => $ocean['port_of_transshipment_un'],
  2092. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2093. "eta" =>$ocean['f_eta'],"ata" =>$EDIDate['VA_RELAY'],
  2094. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2095. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  2096. "destination" => $ocean['consignee_uncode'],
  2097. "etd" => $ocean['m_etd'],"atd" => $EDIDate['VD_RELAY'],
  2098. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  2099. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  2100. }else{
  2101. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  2102. "destination" => $ocean['consignee_uncode'],
  2103. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  2104. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  2105. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  2106. }
  2107. $data['routes'] = $routes;
  2108. //处理marksAndDescription
  2109. $notes = common::excuteListSql("select notes from station_data.ocean_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2110. $remark = "";
  2111. foreach($notes as $note){
  2112. if(!empty($note['notes'])){
  2113. $remark.=$note['notes']."\r\n";
  2114. }
  2115. }
  2116. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2117. $data['marksAndDescription'] = $marksAndDescription;
  2118. return $data;
  2119. }
  2120. private function returnAirDetailData($ocean,$ocean_milestone_status,$state){
  2121. $data = array();
  2122. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  2123. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  2124. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  2125. //Origin和Destination的展示,能不能Origin of Cargo有值就用Origin of Cargo,Origin of Cargo就放Departure Airport? Destination也一樣?
  2126. $ocean['shippr_uncode'] = !empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  2127. $ocean['consignee_uncode'] = !empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  2128. //处理shipment data
  2129. $ocean_milestone_status_code = array();
  2130. foreach($ocean_milestone_status as $oms){
  2131. $ocean_milestone_status_code[$oms['code']] = $oms;
  2132. }
  2133. if ($state < 1){
  2134. //未发生前
  2135. if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
  2136. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2137. $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
  2138. }
  2139. } else{
  2140. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2141. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  2142. //ATD 取值为IFFONB milestone实际发生的时间
  2143. $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
  2144. }
  2145. }
  2146. $simplexData = array();
  2147. //place_of_Receipt
  2148. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  2149. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  2150. $children = array();
  2151. if($state >= 1 && !empty($ocean_milestone_status_code['IFFCPU']['act_date'])){
  2152. //发生后,未发生前没有
  2153. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFCPU']['act_date']);
  2154. }
  2155. $place_of_Receipt_stauts["children"] = $children;
  2156. $simplexData[] = $place_of_Receipt_stauts;
  2157. //port_of_Loading
  2158. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  2159. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  2160. $children = array();
  2161. if ($state < 1){
  2162. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['etd']);
  2163. } else{
  2164. if(!empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  2165. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  2166. }
  2167. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  2168. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  2169. }
  2170. }
  2171. $port_of_Loading_stauts["children"] = $children;
  2172. $simplexData[] = $port_of_Loading_stauts;
  2173. //Port of Discharge
  2174. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  2175. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  2176. $children = array();
  2177. if ($state < 2){
  2178. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['eta']);
  2179. }else{
  2180. if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  2181. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  2182. $ocean['ata'] = $ocean_milestone_status_code['IFFARR']['act_date'];
  2183. }else{
  2184. //IFFARR 如果同步异常没有值时,去表里的 ata_date AS ata
  2185. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  2186. }
  2187. }
  2188. $port_of_Discharge_status["children"] = $children;
  2189. $simplexData[] = $port_of_Discharge_status;
  2190. //Place of Delivery
  2191. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  2192. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  2193. $children = array();
  2194. if ($state < 3){
  2195. //未发生前
  2196. } else{
  2197. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  2198. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  2199. }
  2200. }
  2201. $simplexData[] = $place_of_Delivery_status;
  2202. $data['shipmentData'] = $simplexData;
  2203. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  2204. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Air Freight",
  2205. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  2206. "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
  2207. "etd_timezone" =>$ocean['pol_timezone'],
  2208. "atd_timezone" =>$ocean['pol_timezone'],
  2209. "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
  2210. "eta_timezone" =>$ocean['mpod_timezone'],
  2211. "ata_timezone" =>$ocean['mpod_timezone']);
  2212. $data['transportInfo'] = $transportInfo;
  2213. //处理basicInfo信息数据
  2214. $vessel = $ocean['vessel'];
  2215. $voyage = $ocean['voyage'];
  2216. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  2217. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  2218. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service'],
  2219. "CO2 Emission" =>$ocean['carbon_emission'],"Load Terms" =>"",
  2220. "Shipment Type" =>"");
  2221. $data['basicInfo'] = $basicInfo;
  2222. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  2223. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  2224. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  2225. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  2226. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  2227. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  2228. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  2229. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  2230. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  2231. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  2232. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  2233. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  2234. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  2235. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  2236. $data['businessPartners'] = $businessPartners;
  2237. //处理routes air不存在中转的
  2238. $routes = array(array("mode" =>"Air Freight","mode_label" =>"Air", "origin" =>$ocean['shippr_uncode'],
  2239. "destination" => $ocean['consignee_uncode'],
  2240. "etd" => $ocean['etd'],"atd" => $ocean['atd'],
  2241. "eta" => $ocean['eta'],"ata" => $ocean['ata'],
  2242. "vessel" =>$ocean['vessel'],"voyageNo" =>$ocean['voyage']));
  2243. $data['routes'] = $routes;
  2244. //处理marksAndDescription
  2245. $notes = common::excuteListSql("select notes from station_data.air_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  2246. $remark = "";
  2247. foreach($notes as $note){
  2248. if(!empty($note['notes'])){
  2249. $remark.=$note['notes']."\r\n";
  2250. }
  2251. }
  2252. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  2253. $data['marksAndDescription'] = $marksAndDescription;
  2254. return $data;
  2255. }
  2256. private function getUploadFolder() {
  2257. $sql = "SELECT ra_value from ra_online_config where lower(ra_name) = 'upload_document'";
  2258. return common::excuteOneSql($sql);
  2259. }
  2260. }
  2261. ?>