ocean_order.class.php 134 KB

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