ocean_order.class.php 133 KB

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