ocean_booking.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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_booking {
  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_booking() {
  25. $operate = utils::_get('operate');
  26. $operate = strtolower($operate);
  27. /*
  28. * index page
  29. */
  30. if (empty($operate)) {
  31. $data = array();
  32. if (_isCustomerLogin())
  33. $data['is_customer'] = "yes";
  34. else
  35. $data['is_customer'] = "no";
  36. //栏位信息
  37. $column = column::getInstance()->getDisplayColumn('Booking_Search');
  38. $BookingTableColumns = column::getInstance()->tableColumns('Booking_Search',$column);
  39. $data['BookingTableColumns'] = $BookingTableColumns;
  40. common::echo_json_encode(200,$data);
  41. exit();
  42. }
  43. /*
  44. * ocean order search
  45. */
  46. if ($operate == "search") {
  47. $this->_booking_search();
  48. }
  49. if ($operate == "setting_display") {
  50. column::getInstance()->settingDisplay('Booking_Search', 'main_new_version.php?action=ocean_booking');
  51. }
  52. if ($operate == "detail") {
  53. $this->_booking_detail();
  54. }
  55. if ($operate == "excel") {
  56. $this->_booking_excel();
  57. }
  58. if ($operate == "save_communication") {
  59. try {
  60. $content = $_POST["content"];
  61. $content = common::check_input($content);
  62. $text = $_POST["text"];
  63. $content = urldecode($content);
  64. $web_content = urldecode($text);
  65. $communication_cc = $_POST["communication_cc"];
  66. $serial_no = common::uuid();
  67. $email_uuid = $_POST["serial_no"];
  68. $add_by = _getLoginName();
  69. $refer_id = 0;
  70. $email = $this->getEmail($email_uuid);
  71. $from_email = "US.KApex.Online@kerryapex.com";
  72. $to_email = $email["email"];
  73. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  74. $communication_cc = trim($communication_cc);
  75. if (!empty($communication_cc)) {
  76. $communication_cc = common::check_input($communication_cc);
  77. $cc_email .= ";" . $communication_cc;
  78. }
  79. $user_from = _getLoginName();
  80. $user_to = $email["name"];
  81. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  82. if (empty($user_cc)) {
  83. $user_cc = _getLoginName();
  84. }
  85. $user_cc .= ";ApexOnlineCommunication";
  86. //邮件发送
  87. $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>@@";
  88. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  89. $key = common::excuteOneSql($emailSql);
  90. $historyEmails = "";
  91. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  92. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  93. 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());");
  94. $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)
  95. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  96. $emailRecords = $this->getCommunicationNew($email_uuid);
  97. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  98. exit();
  99. } catch (Exception $e) {
  100. common::echo_json_encode(500,array("msg" => "Sent Error."));
  101. exit();
  102. }
  103. }
  104. }
  105. private function _booking_search() {
  106. $cp = common::check_input($_POST ['cp']); //current_page
  107. $ps = common::check_input($_POST ['ps']); //ps
  108. if (empty($ps)){
  109. $ps = 100;
  110. }
  111. $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
  112. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  113. //新版要排除type2情况,总数才会对的上
  114. $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))";
  115. //移除掉全文检索 但保留代码
  116. // if (!empty($_POST["_textSearch"])) {
  117. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  118. // }
  119. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  120. if (!empty($_POST["_textSearch"])) {
  121. $textSearch_arr = $_POST['_textSearch'];
  122. if(!is_array($textSearch_arr)){
  123. $textSearch_arr = array($textSearch_arr);
  124. }
  125. // $more_sql = "1<>1";
  126. // foreach($textSearch_arr as $tsv){
  127. // $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  128. // $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  129. // $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  130. // $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  131. // }
  132. // if ($more_sql <> "1<>1"){
  133. // $sqlWhere .= " and ($more_sql)";
  134. // }
  135. $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
  136. //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))";
  137. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
  138. or po_no ilike '%" . common::check_input($_POST["_textSearch"]) . "%')";
  139. }
  140. //为了移除filterTag条件
  141. $sqlWhere_befrom_filterTag = $sqlWhere;
  142. $filterTag_param = "";
  143. //前端提交是数组
  144. if (!empty($_POST['filterTag']) && utils::count($_POST['filterTag']) < 4) {
  145. if (utils::count($_POST['filterTag']) == 1){
  146. $filterTag = $_POST['filterTag'][0];
  147. }else{
  148. $filterTag = utils::implode(",", $_POST['filterTag']);
  149. }
  150. $_sqlwhere = "1<>1";
  151. $filterTag_param = "1<>1";
  152. if(strtolower($filterTag) == "all"){
  153. $filterTag_param = "1=1";
  154. }
  155. if (stripos($filterTag, "Confirmed") !== FALSE) {
  156. $_sqlwhere .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
  157. $filterTag_param .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
  158. }
  159. if (stripos($filterTag, "type2") !== FALSE) {
  160. $_sqlwhere .= " or (bol_type != 'BOOKING' and booking_no is not null and booking_no <> '')";
  161. $filterTag_param .= " or (bol_type != 'BOOKING' and booking_no is not null and booking_no <> '')";
  162. }
  163. if (stripos($filterTag, "Cancelled") !== FALSE) {
  164. $_sqlwhere .= " or (status='Cancelled')";
  165. $filterTag_param .= " or (status='Cancelled')";
  166. }
  167. if (stripos($filterTag, "Created") !== FALSE) {
  168. $_sqlwhere .= " or (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))";
  169. $filterTag_param .= " or (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))";
  170. }
  171. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  172. $sqlWhere .= " and ($_sqlwhere)";
  173. $filterTag_param = " ($filterTag_param)";
  174. }
  175. }
  176. if(empty($filterTag_param)){
  177. $filterTag_param = "1=1";
  178. }
  179. $rc = $_POST ['rc'];
  180. //这里都要查询,除非多传几个参数回来
  181. if ($rc == - 1 || true) {
  182. $sql_all_status = "SELECT count(1) as rc,
  183. sum(case when $filterTag_param then 1 else 0 end) as seach_rc,
  184. sum(case when (1<>1 or (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))) then 1 else 0 end) as creatd,
  185. sum(case when (1<>1 or (bol_type = 'BOOKING' and status!='Cancelled')) then 1 else 0 end) as confirmed,
  186. sum(case when (1<>1 or (status='Cancelled')) then 1 else 0 end) as concelled
  187. from public.online_booking" . $sqlWhere_befrom_filterTag;
  188. $sql_all_status_data = common::excuteObjectSql($sql_all_status);
  189. $seach_rc = $sql_all_status_data['seach_rc'];
  190. $rc = $sql_all_status_data['rc'];
  191. $Creatd = $sql_all_status_data['creatd'];
  192. $Confirmed = $sql_all_status_data['confirmed'];
  193. $Concelled = $sql_all_status_data['concelled'];
  194. //前端数据返回,不管有无数据
  195. if (!empty($_POST["filterTag"])) {
  196. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  197. array("name"=>"Created","number"=>intval($Creatd),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  198. array("name"=>"Confirmed","number"=>intval($Confirmed),"type"=>"confirmed","checked"=>utils::in_array('Confirmed', $_POST["filterTag"])? true : false),
  199. array("name"=>"Cancelled","number"=>intval($Concelled),"type"=>"cancelled","checked"=>utils::in_array('Cancelled', $_POST["filterTag"])? true : false));
  200. }else{
  201. //初始,前端有选择着带入选择
  202. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>true),
  203. array("name"=>"Created","number"=>intval($Creatd),"type"=>"created","checked"=>false),
  204. array("name"=>"Confirmed","number"=>intval($Confirmed),"type"=>"confirmed","checked"=>false),
  205. array("name"=>"Cancelled","number"=>intval($Concelled),"type"=>"cancelled","checked"=>false));
  206. }
  207. if (!isset($_POST["transport_mode"])){
  208. //代表初始
  209. $TransportList = array(
  210. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  211. }else{
  212. if (strtolower($_POST["transport_mode"]) == "all") {
  213. $TransportList = array(
  214. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
  215. } else {
  216. $TransportList = array(
  217. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  218. }
  219. }
  220. //现在下载交给前端,后台预先只返回全部字段的列,
  221. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Booking_Search');
  222. $allBookingColumns = column::getInstance()->tableColumns('Booking_Search',$allColumn);
  223. }
  224. $tp = ceil($rc / $ps);
  225. if ($rc > 0 ) {
  226. $order_by = " f_etd desc";
  227. //TopOcean的不用考虑
  228. $ocean_dest_sql = "";
  229. //合并显示两个特殊字段 voyage_m_voyage/vessel_m_vessel
  230. $sql = "SELECT order_from as _schemas, serial_no as __serial_no, created_time as __created_time, color,
  231. f_voyage as __f_voyage, m_voyage as __m_voyage,f_vessel as __f_vessel, m_vessel as __m_vessel," .
  232. column::getInstance()->getSearchSqlForDisplay('Booking_Search') . " from public.online_booking $ocean_dest_sql " . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  233. $rs = common::excuteListSql($sql);
  234. error_log("online_booking_search_SQL: ".$sql);
  235. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  236. foreach($rs as $index => $val) {
  237. //合并显示 vessel
  238. if(array_key_exists("f_vessel", $val)){
  239. $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['__m_vessel']);
  240. }
  241. //合并显示 voyage
  242. if(array_key_exists("f_voyage", $val)){
  243. $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['__m_voyage']);
  244. }
  245. //返回加密serial_no
  246. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  247. //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
  248. $status = "Created";
  249. if(!($val['color'] == "FFFF0000" || $val['color'] == "FF00FF00" || $val['color'] == "FF0000FF")){
  250. $status = "Confirmed";
  251. }
  252. if ($val['color'] == "FF0000FF"){
  253. $status = "Created";
  254. }
  255. if ($val['color'] == "FFFF0000"){
  256. $status = "Cancelled";
  257. }
  258. $rs[$index]["Status"] = $status;
  259. $rs[$index]["Transportation Mode"] = "Ocean Freight";
  260. }
  261. $arrTmp = array('searchData' => $rs,
  262. 'tagsList' => $tagsList,
  263. 'TransportList' => $TransportList,
  264. 'allColums' => $allBookingColumns,
  265. 'rc' => $seach_rc,
  266. 'ps' => $ps,
  267. 'cp' => $cp,
  268. 'tp' => $tp,
  269. 'tmp_search' => common::deCode($sql, 'E'),
  270. 'type' => common::check_input($_POST ['_ntype']));
  271. } else {
  272. $arrTmp = array('searchData' => array(),
  273. 'tagsList' => $tagsList,
  274. 'TransportList' => $TransportList,
  275. 'allColums' => $allBookingColumns,
  276. 'rc' => $seach_rc,
  277. 'ps' => $ps,
  278. 'cp' => $cp,
  279. 'tp' => $tp,
  280. 'tmp_search' => "",
  281. 'type' => common::check_input($_POST ['_ntype']));
  282. }
  283. common::echo_json_encode(200,$arrTmp);
  284. exit();
  285. }
  286. private function _booking_detail() {
  287. $serial_no = common::deCode($_GET['a'], 'D');
  288. $status = $_GET['status'];
  289. $_schemas = $_GET['_schemas'];
  290. if($_schemas == 'public'){
  291. $_schemas = "ocean";
  292. }
  293. $sql = "SELECT o.booking_no as _booking_no,
  294. o.* ,sh.*, cn.* ,aa.*,dd.*,ob.*
  295. from ocean o
  296. LEFT JOIN LATERAL ( SELECT shippr_uncode,shipper_city,
  297. consignee_uncode,consignee_city,
  298. place_of_receipt_uncode,place_of_delivery_uncode,
  299. fport_of_loading_uncode,mport_of_discharge_uncode,po_no as _po_no
  300. FROM public.online_booking ob WHERE o.serial_no::text = ob.serial_no::text) ob ON true
  301. LEFT JOIN LATERAL ( SELECT company as cn_company,
  302. address_1 as cn_address_1,
  303. address_2 as cn_address_2,
  304. address_3 as cn_address_3,
  305. address_4 as cn_address_4,
  306. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  307. phone_1 as cn_phone
  308. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  309. LEFT JOIN LATERAL ( SELECT company as sh_company,
  310. address_1 as sh_address_1,
  311. address_2 as sh_address_2,
  312. address_3 as sh_address_3,
  313. address_4 as sh_address_4,
  314. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  315. phone_1 as sh_phone
  316. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  317. LEFT JOIN LATERAL ( SELECT company as aa_company,
  318. address_1 as aa_address_1,
  319. address_2 as aa_address_2,
  320. address_3 as aa_address_3,
  321. address_4 as aa_address_4,
  322. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  323. phone_1 as aa_phone
  324. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  325. LEFT JOIN LATERAL ( SELECT company as dd_company,
  326. address_1 as dd_address_1,
  327. address_2 as dd_address_2,
  328. address_3 as dd_address_3,
  329. address_4 as dd_address_4,
  330. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  331. phone_1 as dd_phone
  332. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  333. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  334. $ocean = common::excuteObjectSql($sql);
  335. $vueData = $this->returnBookingDetailData($ocean,$status);
  336. //处理transportInfo信息数据
  337. $transportInfo = $vueData["transportInfo"];
  338. //处理basicInfo信息数据
  339. $basicInfo = $vueData["basicInfo"];
  340. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  341. $businessPartners = $vueData["businessPartners"];
  342. $marksAndDescription = $vueData["marksAndDescription"];
  343. //处理ocean_reference
  344. $ref_no = array();
  345. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  346. if(!empty($ref_arr)){
  347. foreach($ref_arr as $ref) {
  348. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  349. }
  350. }
  351. //处理返回booking的 Container 信息数据
  352. $booking_container_column = array();
  353. $container_column = column::getInstance()->getDisplayColumnAll('Booking_Container');
  354. foreach($container_column as $cc){
  355. $booking_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  356. }
  357. if (!empty($ocean['_booking_no'])) {
  358. $sql = "SELECT " . column::getInstance()->getSearchSql('Booking_Container') . " from ocean_booking_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  359. $rss = common::excuteListSql($sql);
  360. } else {
  361. $sql = "SELECT " . column::getInstance()->getSearchSql('Booking_Container') . " from oc_container_booking_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  362. $rss = common::excuteListSql($sql);
  363. }
  364. $containers = array("container_column"=>$booking_container_column,"container_data" =>$rss);
  365. //packing
  366. $quantity_unit = array();
  367. $packages = "CTN";
  368. $g_weight_tolal = 0;
  369. $ch_weight_tolal = 0;
  370. $cbm_tolal = 0;
  371. foreach($rss as $pk => $pv){
  372. //相同的unit 的合并成一个
  373. $unit = $pv['unit'];
  374. if (array_key_exists($unit, $quantity_unit)) {
  375. $quantity_unit[$unit] = $quantity_unit[$unit] + $pv['qty'];
  376. } else {
  377. $quantity_unit[$unit] = $pv['qty'];
  378. }
  379. $g_weight_tolal += $pv['kgs'];
  380. $ch_weight_tolal += $pv['kgs'];
  381. $cbm_tolal += $pv['cbm'];
  382. }
  383. $quantity_tolal = "";
  384. foreach($quantity_unit as $uk => $uv){
  385. $quantity_tolal.=$uv." ".$uk." ";
  386. }
  387. //$packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
  388. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  389. if (!empty($ocean['_booking_no'])) {
  390. $cbm_tolal = sprintf("%.3f", $cbm_tolal);
  391. }else{
  392. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  393. }
  394. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $g_weight_tolal." KGS","Volume" => $cbm_tolal." CBM");
  395. //处理邮件信息返回
  396. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  397. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  398. $email = $this->getEmail($ocean["serial_no"]);
  399. $email['cc_email'] = $cc_email;
  400. $email['emailRecords'] = $emailRecords;
  401. global $_COPYRIGHT;
  402. $data = array('transportInfo' => $transportInfo,
  403. 'basicInfo' => $basicInfo,
  404. 'businessPartners' => $businessPartners,
  405. 'ref_no' => $ref_no,
  406. 'packing' => $packing,
  407. 'marksAndDescription' => $marksAndDescription,
  408. 'containers' => $containers,
  409. 'email' => $email,
  410. 'serial_no' => $serial_no,
  411. '_schemas' => $_GET['_schemas'],
  412. '__serial_no' => common::deCode($ocean['serial_no'], 'E'),
  413. 'copyright' =>$_COPYRIGHT);
  414. common::echo_json_encode(200,$data);
  415. exit();
  416. }
  417. private function _booking_excel() {
  418. $sql = common::deCode($_POST ['tmp_search'], 'D');
  419. $sql = substr($sql, 0, strripos($sql, " limit"));
  420. if(!empty($sql)){
  421. $rs = common::excuteListSql($sql);
  422. }
  423. //去除null
  424. foreach($rs as $index => $val) {
  425. foreach($val as $index_2 => $_val) {
  426. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  427. $rs[$index][$index_2] = "";
  428. }
  429. }
  430. }
  431. foreach($rs as $index => $val) {
  432. //合并显示 vessel
  433. if(array_key_exists("f_vessel", $val)){
  434. $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['__m_vessel']);
  435. }
  436. //合并显示 voyage
  437. if(array_key_exists("f_voyage", $val)){
  438. $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['__m_voyage']);
  439. }
  440. //返回加密serial_no
  441. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  442. //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
  443. $status = "Created";
  444. if(!($val['color'] == "FFFF0000" || $val['color'] == "FF00FF00" || $val['color'] == "FF0000FF")){
  445. $status = "Confirmed";
  446. }
  447. if ($val['color'] == "FF0000FF"){
  448. $status = "Created";
  449. }
  450. if ($val['color'] == "FFFF0000"){
  451. $status = "Cancelled";
  452. }
  453. $rs[$index]["Status"] = $status;
  454. $rs[$index]["Transportation Mode"] = "Ocean Freight";
  455. }
  456. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  457. exit;
  458. }
  459. private function getEmail($serial_no) {
  460. return utils::getEmail($serial_no);
  461. }
  462. private function getCommunicationNew($serial_no) {
  463. $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");
  464. $emialRecords =array();
  465. foreach ($list as $k => $v) {
  466. $msg =array();
  467. $msg["name"] = $v["add_by"];
  468. $msg["creatTime"] = $v["add_times"];
  469. $msg["content"] = urldecode($v["web_content"]);
  470. $emialRecords[] = $msg;
  471. }
  472. return $emialRecords;
  473. }
  474. private function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  475. $stationInfo = "";
  476. if(!empty($address_1)){
  477. $stationInfo .= $address_1;
  478. }
  479. if(!empty($address_2)){
  480. $stationInfo .= " ".$address_2;
  481. }
  482. if(!empty($address_3)){
  483. $stationInfo .= " ".$address_3;
  484. }
  485. if(!empty($address_4)){
  486. $stationInfo .= " ".$address_4;
  487. }
  488. $temp_str = "";
  489. if(!empty($city)){
  490. $temp_str .= $city." ";
  491. }
  492. if(!empty($state)){
  493. $temp_str .= $state." ";
  494. }
  495. if(!empty($zipcode)){
  496. $temp_str .= $zipcode." ";
  497. }
  498. if(!empty($country)){
  499. $temp_str .= $country." ";
  500. }
  501. if(!empty($temp_str)){
  502. return $stationInfo." ".trim($temp_str);
  503. }
  504. return $stationInfo;
  505. }
  506. private function returnBookingDetailData($ocean,$status){
  507. $data = array();
  508. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  509. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  510. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  511. $ocean['shippr_uncode'] = $ocean['place_of_receipt_uncode'];
  512. $ocean['consignee_uncode'] = $ocean['place_of_delivery_uncode'];
  513. //获取对应uncode 对应的时间
  514. $uncodes = $ocean['fport_of_loading_uncode'].";".$ocean['mport_of_discharge_uncode'];
  515. $codeinfo = common::getCityPortsInfo($uncodes);
  516. //处理transportInfo信息数据
  517. $transportInfo = array("bookingNo." =>$ocean['booking_no'],"status"=>$status,"mode" => "Ocean Freight",
  518. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  519. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  520. "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],
  521. "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],
  522. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  523. "eta_timezone" =>$codeinfo[$ocean['mport_of_discharge_uncode']],
  524. "ata_timezone" =>$codeinfo[$ocean['mport_of_discharge_uncode']]);
  525. $data["transportInfo"] = $transportInfo;
  526. //处理basicInfo信息数据
  527. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  528. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  529. $basicInfo = array("bookingNo." =>$ocean['booking_no'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  530. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  531. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  532. $data["basicInfo"] = $basicInfo;
  533. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  534. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  535. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  536. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  537. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  538. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  539. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  540. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  541. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  542. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  543. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  544. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  545. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  546. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  547. $data["businessPartners"] = $businessPartners;
  548. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  549. $data["marksAndDescription"] = $marksAndDescription;
  550. return $data;
  551. }
  552. }
  553. ?>