ocean_order.class.php 133 KB

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