ocean_order.class.php 132 KB

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