common.class.php 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of common
  7. *
  8. * @author Administrator
  9. */
  10. class common {
  11. /*
  12. * mysql check input
  13. */
  14. public static function check_input($value, $boolean = FALSE, $toupper = FALSE) {
  15. if ($boolean !== FALSE) {
  16. if ($value == "t")
  17. return "'t'";
  18. else
  19. return "'f'";
  20. }
  21. $value = trim($value);
  22. if ($toupper !== FALSE)
  23. $value = mb_strtoupper($value);
  24. if (!is_numeric($value)) {
  25. $value = pg_escape_string($value);
  26. }
  27. return $value;
  28. }
  29. public static function excuteOneSql($sql, $exception = FALSE) {
  30. if ($exception) {
  31. global $db;
  32. $result = $db->GetOne($sql);
  33. return $result === FALSE ? null : $result;
  34. } else {
  35. if (empty($sql))
  36. exit(json_encode("Program encountered an error."));
  37. global $db;
  38. $result = $db->GetOne($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  39. return $result === FALSE ? null : $result;
  40. }
  41. }
  42. public static function excuteObjectSql($sql) {
  43. if (empty($sql))
  44. exit(json_encode("Program encountered an error."));
  45. global $db;
  46. $result = $db->GetRow($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  47. return $result === FALSE ? null : $result;
  48. }
  49. public static function excuteUpdateSql($sql, $req_id = FALSE) {
  50. if (empty($sql))
  51. exit(json_encode("Program encountered an error."));
  52. global $db;
  53. $rs = $db->Execute($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  54. if ($rs && $req_id !== FALSE)
  55. return $db->PO_Insert_ID();
  56. else
  57. return $rs;
  58. }
  59. public static function excuteListSql($sql, $exception = FALSE) {
  60. if ($exception) {
  61. global $db;
  62. $result = $db->GetAll($sql);
  63. return $result === FALSE ? null : $result;
  64. } else {
  65. if (empty($sql))
  66. exit(json_encode("Program encountered an error."));
  67. global $db;
  68. $result = $db->GetAll($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  69. return $result === FALSE ? null : $result;
  70. }
  71. }
  72. /*
  73. * Database log output
  74. */
  75. public static function dbLog($db, $sql) {
  76. $backMsg = $db->errorMsg() . ' sql=' . $sql;
  77. return $backMsg;
  78. }
  79. /*
  80. * get IP
  81. */
  82. public static function ip() {
  83. if (getenv("HTTP_X_FORWARDED_FOR"))
  84. return getenv("HTTP_X_FORWARDED_FOR");
  85. if (getenv("HTTP_CLIENT_IP"))
  86. return getenv("HTTP_CLIENT_IP");
  87. if (getenv("REMOTE_ADDR"))
  88. return getenv("REMOTE_ADDR");
  89. if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
  90. return $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
  91. if ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
  92. return $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
  93. if ($HTTP_SERVER_VARS["REMOTE_ADDR"])
  94. return $HTTP_SERVER_VARS["REMOTE_ADDR"];
  95. return "Unknown";
  96. }
  97. public static function getDBUuid() {
  98. global $db;
  99. $sql = "select uuid_generate_v1()";
  100. $uuid = $db->GetOne($sql);
  101. return $uuid;
  102. }
  103. public static function securityCheckHandNew($action) {
  104. if (strpos($action, "handset") === 0) {
  105. } elseif (strpos($action, "hand") === 0) {
  106. } else {
  107. common::sessionVerify();
  108. $httpAccept = $_SERVER['HTTP_ACCEPT']; // ajax request,is json or html
  109. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER
  110. ['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; // is ajax request?
  111. //暂时这么写,放开action = main的查询是为了在没有登录时获取信息。
  112. //tools是为了避免查询的用户,没有配置tools权限,但是新版mark_save需要进入
  113. if($action == "main" || $action == "tools" || $action == "save_layout"){
  114. return;
  115. }
  116. if (!isset($_SESSION['ONLINE_USER'])) {
  117. self::timeoutPrintInfor($httpAccept, $ajax, 'no');
  118. } else {
  119. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  120. $set_session_timeout = $_SESSION['SESSION_TIMEOUT'];
  121. if (_getLoginName() == "ra.admin") {
  122. $set_session_timeout = 4 * 3600;
  123. }
  124. if ($time > $set_session_timeout) {
  125. self::timeoutPrintInfor($httpAccept, $ajax, 'yes');
  126. } else {
  127. $_SESSION["LAST_OPERATE_TIME"] = time();
  128. if (!_isAdmin() && $_GET["action"] != "linkcrm") {
  129. if (!utils::checkExist($_SESSION['ONLINE_USER']['permission'], $action)
  130. && !(stripos($action, "main") === 0)
  131. && !(stripos($action, "ajax") === 0)
  132. && !(stripos($action, "opreation_log") === 0)) {
  133. $data = array("msg"=>"Permission Denied");
  134. common::echo_json_encode(500, $data);
  135. exit();
  136. }
  137. }
  138. }
  139. }
  140. session_write_close();
  141. }
  142. }
  143. public static function getCompanySearch() {
  144. $sc_list = _get_schemas();
  145. if (count($sc_list) == 1) {
  146. return "";
  147. }
  148. if (_isCustomerLogin()) {
  149. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  150. } else {
  151. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  152. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  153. $msg .= '<option value="public">Apex</option>';
  154. } else {
  155. $msg .= '<option value="public">Apex</option>';
  156. }
  157. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  158. $msg .= '<option value="sfs">SFS</option>';
  159. } else {
  160. $msg .= '<option value="sfs">SFS</option>';
  161. }
  162. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  163. $msg .= '<option value="kyiff">Kerry</option>';
  164. } else {
  165. $msg .= '<option value="kyiff">Kerry</option>';
  166. }
  167. $msg .= '</select></div>';
  168. }
  169. return $msg;
  170. }
  171. public static function sessionVerify() {
  172. if (!isset($_SESSION['user_agent'])) {
  173. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  174. . $_SERVER['HTTP_USER_AGENT']);
  175. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  176. . $_SERVER['HTTP_USER_AGENT'])) {
  177. session_regenerate_id();
  178. }
  179. }
  180. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  181. if (_isAdminHandNew($user)) {
  182. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  183. {
  184. return "1=1";
  185. }
  186. //return " (schem_not_display is null or schem_not_display=false)";
  187. return " (COALESCE(schem_not_display,false) = false)";
  188. }
  189. if (_isDocAdmin($user["user_login"])) {
  190. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  191. {
  192. return "1=1";
  193. }
  194. //return ' (schem_not_display is null or schem_not_display=false)';
  195. return ' (COALESCE(schem_not_display,false) = false)';
  196. }
  197. if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
  198. return " 1<>1";
  199. }
  200. if (empty($user["schemas_list"])) {
  201. $user["schemas_list"] = $_SESSION["schemas_list"];
  202. }
  203. $schemas_list = $user["schemas_list"];
  204. if ($user["is_kerry_shipment"] == "t") {
  205. $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
  206. } else if ($user["is_kerry_shipment"] == "f") {
  207. //$sqlWhere = " (is_kerry_shipment is null or is_kerry_shipment=false)";
  208. $sqlWhere = " (COALESCE(is_kerry_shipment,false) = false)";
  209. } else {
  210. $sqlWhere = " 1=1";
  211. }
  212. if (!empty($_POST["_apex_or_sfs"])) {
  213. $sqlWhere .= " and order_from='" . $_POST["_apex_or_sfs"] . "'";
  214. }
  215. if (count($schemas_list) == 1) {
  216. $schames = $schemas_list[0]["schemas_name"];
  217. if(strtolower($type) == "air_booking" ||strtolower($type) == "air")
  218. {
  219. }
  220. else
  221. $sqlWhere .= " and order_from='$schames'";
  222. if ($schames == "sfs" && empty($user["sfs_ONLINE_USER"])) {
  223. $user = $_SESSION["sfs_ONLINE_USER"];
  224. }
  225. if (strtolower($type) == "ocean") {
  226. $sqlWhere .= self::_oceanHandNew($user, $schames);
  227. if ($company_name == "doc") {
  228. if (empty($user["view_file_format"])) {
  229. if (strtolower($user["user_type"]) == "customer") {
  230. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  231. } else {
  232. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  233. }
  234. } else {
  235. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  236. }
  237. }
  238. }
  239. if (strtolower($type) == "booking") {
  240. $sqlWhere .= self::_bookingHandNew($user, $schames);
  241. }
  242. if (strtolower($type) == "air_booking") {
  243. $sqlWhere .= self::_airHandNew($user, $schames);
  244. }
  245. if (strtolower($type) == "air") {
  246. $sqlWhere .= self::_airHandNew($user, $schames);
  247. if ($company_name == "doc") {
  248. if (empty($user["view_file_format"])) {
  249. if (strtolower($user["user_type"]) == "customer") {
  250. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  251. } else {
  252. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  253. }
  254. } else {
  255. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  256. }
  257. }
  258. }
  259. } elseif (count($schemas_list) == 2) {
  260. if(strtolower($type) == "air_booking" )//|| strtolower($type) == "air"
  261. {
  262. // $sqlWhere .= " and 1=1";
  263. }
  264. else{
  265. //$sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  266. $sqlWhere .= " and (COALESCE(schem_not_display,false) = false)";
  267. }
  268. if (strtolower($type) == "ocean") {
  269. $sqlWhere .= " and ((order_from='public' ";
  270. $sqlWhere .= self::_oceanHandNew($user, "public");
  271. if ($company_name == "doc") {
  272. if (empty($user["view_file_format"])) {
  273. if (strtolower($user["user_type"]) == "customer") {
  274. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  275. } else {
  276. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  277. }
  278. } else {
  279. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  280. }
  281. }
  282. $sqlWhere .= ") or (order_from='sfs' ";
  283. if (empty($user["sfs_ONLINE_USER"])) {
  284. $user = $_SESSION["sfs_ONLINE_USER"];
  285. }
  286. $sqlWhere .= self::_oceanHandNew($user, "sfs");
  287. if ($company_name == "doc") {
  288. if (empty($user["view_file_format"])) {
  289. if (strtolower($user["user_type"]) == "customer") {
  290. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  291. } else {
  292. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  293. }
  294. } else {
  295. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  296. }
  297. }
  298. $sqlWhere .= ") )";
  299. }
  300. if (strtolower($type) == "booking") {
  301. $sqlWhere .= " and ((order_from='public' ";
  302. $sqlWhere .= self::_bookingHandNew($user, "public");
  303. $sqlWhere .= ") or (order_from='sfs' ";
  304. if (empty($user["sfs_ONLINE_USER"])) {
  305. $user = $_SESSION["sfs_ONLINE_USER"];
  306. }
  307. $sqlWhere .= self::_bookingHandNew($user, "sfs");
  308. $sqlWhere .= "))";
  309. }
  310. if (strtolower($type) == "air_booking") {
  311. $sqlWhere .= " and ((order_from='public' ";
  312. $sqlWhere .= self::_airHandNew($user, "public");
  313. $sqlWhere .= ") or (order_from='sfs' ";
  314. if (empty($user["sfs_ONLINE_USER"])) {
  315. $user = $_SESSION["sfs_ONLINE_USER"];
  316. }
  317. $sqlWhere .= self::_airHandNew($user, "sfs");
  318. $sqlWhere .= "))";
  319. // $sqlWhere .= self::_airHandNew($user, $schames);
  320. }
  321. if (strtolower($type) == "air") {
  322. $sqlWhere .= " and ((order_from='public' ";
  323. $sqlWhere .= self::_airHandNew($user, "public");
  324. if ($company_name == "doc") {
  325. if (empty($user["view_file_format"])) {
  326. if (strtolower($user["user_type"]) == "customer") {
  327. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  328. } else {
  329. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  330. }
  331. } else {
  332. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  333. }
  334. }
  335. $sqlWhere .= ") or (order_from='sfs' ";
  336. if (empty($user["sfs_ONLINE_USER"])) {
  337. $user = $_SESSION["sfs_ONLINE_USER"];
  338. }
  339. $sqlWhere .= self::_airHandNew($user, "sfs");
  340. if ($company_name == "doc") {
  341. if (empty($user["view_file_format"])) {
  342. if (strtolower($user["user_type"]) == "customer") {
  343. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  344. } else {
  345. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  346. }
  347. } else {
  348. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  349. }
  350. }
  351. $sqlWhere .= ") )";
  352. }
  353. } else {
  354. $sqlWhere = " 1<>1";
  355. }
  356. return $sqlWhere;
  357. }
  358. public static function getStatusStage($status) {
  359. if ($status == "EE" || $status == "I") {
  360. return 0;
  361. }
  362. if ($status == "AE" || $status == "VD" || $status == "VA_RELAY" || $status == "UV_RELAY" || $status == "AE_RELAY" || $status == "VD_RELAY") {
  363. return 1;
  364. }
  365. if ($status == "VA" || $status == "UV" || $status == "AL" || $status == "AR" || $status == "CU" || $status == "CT" || $status == "CR" || $status == "OA") {
  366. return 2;
  367. }
  368. if ($status == "AV" || $status == "D" || $status == "RD") {
  369. return 3;
  370. }
  371. return -1;
  372. }
  373. public static function getInNotInSql($contact_id, $type = 'in') {
  374. if (empty($contact_id))
  375. return " =''";
  376. $contact_id = trim($contact_id);
  377. $contact_id = trim($contact_id, ";");
  378. $contact_id = trim($contact_id);
  379. $contact_id = strtolower($contact_id);
  380. if ($type == 'in') {
  381. if (utils::checkExist($contact_id, ";")) {
  382. $ss = "";
  383. $aa = explode(";", $contact_id);
  384. foreach ($aa as $k => $v) {
  385. $v = trim($v);
  386. if (empty($ss))
  387. $ss = "'" . common::check_input($v) . "'";
  388. else
  389. $ss .= ",'" . common::check_input($v) . "'";
  390. }
  391. return " in (" . $ss . ")";
  392. } else {
  393. return " = '" . common::check_input($contact_id) . "'";
  394. }
  395. } else {
  396. if (utils::checkExist($contact_id, ";")) {
  397. $ss = "";
  398. $aa = explode(";", $contact_id);
  399. foreach ($aa as $k => $v) {
  400. $v = trim($v);
  401. if (empty($ss))
  402. $ss = "'" . common::check_input($v) . "'";
  403. else
  404. $ss .= ",'" . common::check_input($v) . "'";
  405. }
  406. return " in (" . $ss . ")";
  407. } else {
  408. return " != '" . common::check_input($contact_id) . "'";
  409. }
  410. }
  411. }
  412. public static function getInNotInSqlForSearch($contact_id, $type = 'in') {
  413. if (empty($contact_id))
  414. return " =''";
  415. $contact_id = trim($contact_id);
  416. $contact_id = trim($contact_id, ";");
  417. $contact_id = trim($contact_id);
  418. $contact_id = strtolower($contact_id);
  419. if ($type == 'in') {
  420. if (utils::checkExist($contact_id, ";")) {
  421. $ss = "";
  422. $aa = explode(";", $contact_id);
  423. foreach ($aa as $k => $v) {
  424. $v = trim($v);
  425. if (empty($ss))
  426. $ss = "'" . common::check_input($v) . "'";
  427. else
  428. $ss .= ",'" . common::check_input($v) . "'";
  429. }
  430. return $ss;
  431. } else {
  432. return "'" . common::check_input($contact_id) . "'";
  433. }
  434. }
  435. }
  436. /*
  437. * Encrypt a SQL query statement used to be passed as a parameter to get excel output
  438. encode :DeCode('str','E');
  439. decode :DeCode('enstr','D');
  440. */
  441. public static function deCode($string, $operation = "E") {
  442. $key = md5("uls_webwms");
  443. $key_length = strlen($key);
  444. if ($operation == "D")
  445. $string = rawurldecode($string);
  446. $string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
  447. $string_length = strlen($string);
  448. $rndkey = $box = array();
  449. $result = '';
  450. for ($i = 0; $i <= 255; $i++) {
  451. $rndkey [$i] = ord($key [$i % $key_length]);
  452. $box [$i] = $i;
  453. }
  454. for ($j = $i = 0; $i < 256; $i++) {
  455. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  456. $tmp = $box [$i];
  457. $box [$i] = $box [$j];
  458. $box [$j] = $tmp;
  459. }
  460. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  461. $a = ($a + 1) % 256;
  462. $j = ($j + $box [$a]) % 256;
  463. $tmp = $box [$a];
  464. $box [$a] = $box [$j];
  465. $box [$j] = $tmp;
  466. $result .= chr(ord($string [$i]) ^ ($box [($box [$a] + $box [$j]) % 256]));
  467. }
  468. if ($operation == 'D') {
  469. if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
  470. return substr($result, 8);
  471. } else {
  472. return '';
  473. }
  474. } else {
  475. return rawurlencode(str_replace('=', '', base64_encode($result)));
  476. }
  477. }
  478. public static function getStatusDesc($code) {
  479. if (strtoupper($code) == "EE") {
  480. return "Empty Equipment Dispatched";
  481. }
  482. if (strtoupper($code) == "I") {
  483. return "Gate in full for a booking";
  484. }
  485. if (strtoupper($code) == "AE") {
  486. return "Container loaded on vessel";
  487. }
  488. if (strtoupper($code) == "VD") {
  489. return "Vessel Departure";
  490. }
  491. if (strtoupper($code) == "VA_RELAY") {
  492. return "Arrive Relay Port";
  493. }
  494. if (strtoupper($code) == "VD_RELAY") {
  495. return "Depart Relay Port";
  496. }
  497. if (strtoupper($code) == "AE_RELAY") {
  498. return "Loaded at Relay Port";
  499. }
  500. if (strtoupper($code) == "UV_RELAY") {
  501. return "Unloaded at Relay Port";
  502. }
  503. if (strtoupper($code) == "VA") {
  504. return "Vessel Arrival";
  505. }
  506. if (strtoupper($code) == "UV") {
  507. return "Unloaded From Vessel";
  508. }
  509. if (strtoupper($code) == "AL") {
  510. return "Container loaded on Rail";
  511. }
  512. if (strtoupper($code) == "AR") {
  513. return "Container unloaded from Rail";
  514. }
  515. if (strtoupper($code) == "CU") {
  516. return "Carrier and Customs Release";
  517. }
  518. if (strtoupper($code) == "CT") {
  519. return "Customs release";
  520. }
  521. if (strtoupper($code) == "CR") {
  522. return "Carrier release";
  523. }
  524. if (strtoupper($code) == "OA") {
  525. return "Gate out full from final discharge port";
  526. }
  527. if (strtoupper($code) == "AV") {
  528. return "Shipment available for pickup or delivery";
  529. }
  530. if (strtoupper($code) == "RD") {
  531. return "Container returned empty";
  532. }
  533. if (strtoupper($code) == "D") {
  534. return "Gate out for delivery to customer";
  535. }
  536. }
  537. public static function _toString($msg) {
  538. if ($msg == "" || $msg == NULL) {
  539. return "";
  540. }
  541. return $msg . "";
  542. }
  543. /*
  544. * timeout output
  545. */
  546. public static function timeoutPrintInfor($httpAccept, $ajax, $login) {
  547. //记录系统因session过期 退出登录
  548. $data = array("msg"=>"session_time_out");
  549. self::echo_json_encode(403,$data);
  550. exit();
  551. }
  552. private static function _oceanHandNew($user, $schemas = "public") {
  553. $o = $user['ocean_station'];
  554. $o_or = $user['ocean_station_or'];
  555. $d = $user['ocean_agent'];
  556. $d_or = $user['ocean_agent_or'];
  557. $sales = $user['ocean_sales'];
  558. $sales_or = $user['ocean_sales_or'];
  559. $op = $user['ocean_dest_op'];
  560. $op_or = $user['ocean_dest_op_or'];
  561. $follow = $user['ocean_following_sales'];
  562. $follow_or = $user['ocean_following_sales_or'];
  563. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  564. return " and 1=1";
  565. }
  566. $sqlWhere = "";
  567. if (_isCustomerLoginHandNew($user)) {
  568. //error_log("_oceanHandNew".$schemas);
  569. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  570. } else {
  571. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  572. return " and 1<>1";
  573. }
  574. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  575. } else {
  576. $sql = "1=1";
  577. if (!empty($o) && strtolower($o) != 'all') {
  578. $sql .= " and lower(origin)";
  579. $sql .= utils::getInSql($o);
  580. }
  581. if (!empty($d) && strtolower($d) != 'all') {
  582. $sql .= " and lower(agent)";
  583. $sql .= utils::getInSql($d);
  584. }
  585. $sqlWhere .= " and (" . $sql . ")";
  586. }
  587. if (strtolower($sales) == 'all' || empty($sales)) {
  588. } else {
  589. if (utils::checkExist($sales, ";")) {
  590. $sql = "1!=1";
  591. $tt = explode(";", $sales);
  592. foreach ($tt as $t) {
  593. $t = trim($t);
  594. if (!empty($t))
  595. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  596. }
  597. $sqlWhere .= " and ($sql)";
  598. } else
  599. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  600. }
  601. if (strtolower($op) == 'all' || empty($op)) {
  602. } else {
  603. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  604. }
  605. if (strtolower($follow) == 'all' || empty($follow)) {
  606. } else {
  607. if (utils::checkExist($follow, ";")) {
  608. $sql = "1!=1";
  609. $tt = explode(";", $follow);
  610. foreach ($tt as $t) {
  611. $t = trim($t);
  612. if (!empty($t))
  613. $sql .= " or following_sales ilike '" . $t . "'";
  614. }
  615. $sqlWhere .= " and ($sql)";
  616. } else
  617. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  618. }
  619. $sqlWhere = " (1=1 $sqlWhere)";
  620. if (!empty($o_or)) {
  621. $sqlWhere .= " or lower(origin)";
  622. $sqlWhere .= utils::getInSql($o_or);
  623. }
  624. if (!empty($d_or)) {
  625. $sqlWhere .= " or lower(agent)";
  626. $sqlWhere .= utils::getInSql($d_or);
  627. }
  628. if (!empty($sales_or)) {
  629. if (utils::checkExist($sales_or, ";")) {
  630. $sql = "1!=1";
  631. $tt = explode(";", $sales_or);
  632. foreach ($tt as $t) {
  633. $t = trim($t);
  634. if (!empty($t))
  635. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  636. }
  637. $sqlWhere .= " or ($sql)";
  638. } else
  639. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  640. }
  641. if (!empty($op_or)) {
  642. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  643. }
  644. if (!empty($follow_or)) {
  645. if (utils::checkExist($follow_or, ";")) {
  646. $sql = "1!=1";
  647. $tt = explode(";", $follow_or);
  648. foreach ($tt as $t) {
  649. $t = trim($t);
  650. if (!empty($t))
  651. $sql .= " or following_sales ilike '" . $t . "'";
  652. }
  653. $sqlWhere .= " or ($sql)";
  654. }else {
  655. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  656. }
  657. }
  658. $sqlWhere = " and ($sqlWhere)";
  659. }
  660. return $sqlWhere;
  661. }
  662. private static function _bookingHandNew($user, $schames) {
  663. // if (_isDemo())
  664. // return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
  665. $o = $user['ocean_station'];
  666. $o_or = $user['ocean_station_or'];
  667. $d = $user['ocean_agent'];
  668. $d_or = $user['ocean_agent_or'];
  669. $sales = $user['ocean_sales'];
  670. $sales_or = $user['ocean_sales_or'];
  671. $op = $user['ocean_dest_op'];
  672. $op_or = $user['ocean_dest_op_or'];
  673. $follow = $user['ocean_following_sales'];
  674. $follow_or = $user['ocean_following_sales_or'];
  675. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  676. return " and 1=1";
  677. }
  678. // $sc_list = $user['schemas_list'];
  679. // if (empty($sc_list)) {
  680. // $sc_list = $_SESSION["schemas_list"];
  681. // }
  682. // if (empty($sc_list)) {
  683. // return " and 1<>1";
  684. // }
  685. // $sqlWhere = " and 1=1";
  686. // if ($user["is_kerry_shipment"] == "t") {
  687. // $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
  688. // } else if ($user["is_kerry_shipment"] == "f") {
  689. // $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
  690. // }
  691. // if (count($sc_list) == 1) {
  692. // $sch = $sc_list[0]['schemas_name'];
  693. // $sqlWhere .= " and order_from='$sch'";
  694. // } else {
  695. // $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  696. // }
  697. $sqlWhere = "";
  698. if (_isCustomerLoginHandNew($user)) {
  699. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  700. } else {
  701. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  702. return " and 1<>1";
  703. }
  704. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  705. } else {
  706. $sql = "1=1";
  707. if (!empty($o) && strtolower($o) != 'all') {
  708. $sql .= " and lower(origin)";
  709. $sql .= utils::getInSql($o);
  710. }
  711. if (!empty($d) && strtolower($d) != 'all') {
  712. $sql .= " and lower(agent)";
  713. $sql .= utils::getInSql($d);
  714. }
  715. $sqlWhere .= " and (" . $sql . ")";
  716. }
  717. if (strtolower($sales) == 'all' || empty($sales)) {
  718. } else {
  719. if (utils::checkExist($sales, ";")) {
  720. $sql = "1!=1";
  721. $tt = explode(";", $sales);
  722. foreach ($tt as $t) {
  723. $t = trim($t);
  724. if (!empty($t))
  725. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  726. }
  727. $sqlWhere .= " and ($sql)";
  728. } else
  729. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  730. }
  731. if (strtolower($follow) == 'all' || empty($follow)) {
  732. } else {
  733. if (utils::checkExist($follow, ";")) {
  734. $sql = "1!=1";
  735. $tt = explode(";", $follow);
  736. foreach ($tt as $t) {
  737. $t = trim($t);
  738. if (!empty($t))
  739. $sql .= " or following_sales ilike '" . $t . "%'";
  740. }
  741. $sqlWhere .= " and ($sql)";
  742. } else
  743. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  744. }
  745. $sqlWhere = " (1=1 $sqlWhere)";
  746. if (!empty($o_or)) {
  747. $sqlWhere .= " or lower(origin)";
  748. $sqlWhere .= utils::getInSql($o_or);
  749. }
  750. if (!empty($d_or)) {
  751. $sqlWhere .= " or lower(agent)";
  752. $sqlWhere .= utils::getInSql($d_or);
  753. }
  754. if (!empty($sales_or)) {
  755. if (utils::checkExist($sales_or, ";")) {
  756. $sql = "1!=1";
  757. $tt = explode(";", $sales_or);
  758. foreach ($tt as $t) {
  759. $t = trim($t);
  760. if (!empty($t))
  761. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  762. }
  763. $sqlWhere .= " or ($sql)";
  764. } else
  765. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  766. }
  767. if (!empty($follow_or)) {
  768. if (utils::checkExist($follow_or, ";")) {
  769. $sql = "1!=1";
  770. $tt = explode(";", $follow_or);
  771. foreach ($tt as $t) {
  772. $t = trim($t);
  773. if (!empty($t))
  774. $sql .= " or following_sales ilike '" . $t . "%'";
  775. }
  776. $sqlWhere .= " or ($sql)";
  777. } else
  778. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  779. }
  780. $sqlWhere = " and ($sqlWhere)";
  781. }
  782. return $sqlWhere;
  783. }
  784. private static function _airHandNew($user, $schemas = "public")
  785. {
  786. if($schemas=="public")
  787. {
  788. $station = $user['air_station'];
  789. $station_or = $user['air_station_or'];
  790. $sales = $user['air_sales'];
  791. $sales_or = $user['air_sales_or'];
  792. }
  793. else
  794. {
  795. $station = $user[$schemas."_ONLINE_USER"]['air_station'];
  796. $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
  797. $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
  798. $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
  799. }
  800. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
  801. {
  802. return " and 1=1";
  803. }
  804. $sqlWhere = "";
  805. if (_isCustomerLoginHandNew($user)) {
  806. //error_log("_oceanHandNew".$schemas);
  807. $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
  808. }
  809. else
  810. {
  811. if (empty($station) && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
  812. {
  813. return " and 1<>1";
  814. }
  815. if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
  816. {
  817. }
  818. else
  819. {
  820. $sql = "1=1";
  821. if (!empty($station) && strtolower($station) != 'all') {
  822. $sql .= " and (lower(origin)";
  823. $sql .= utils::getInSql($station);
  824. $sql .= " or lower(destination_station)";
  825. $sql .= utils::getInSql($station);
  826. $sql .= ")";
  827. }
  828. $sqlWhere .= " and (" . $sql . ")";
  829. }
  830. if (strtolower($sales) == 'all' || empty($sales)) {
  831. } else
  832. {
  833. if (utils::checkExist($sales, ";")) {
  834. $sql = "1!=1";
  835. $tt = explode(";", $sales);
  836. foreach ($tt as $t) {
  837. $t = trim($t);
  838. if (!empty($t))
  839. {
  840. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  841. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  842. }
  843. }
  844. $sqlWhere .= " and ($sql)";
  845. } else
  846. {
  847. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
  848. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
  849. }
  850. }
  851. $sqlWhere = " (1=1 $sqlWhere)";
  852. if (!empty($station_or)) {
  853. $sqlWhere .= " or lower(origin)";
  854. $sqlWhere .= utils::getInSql($station_or);
  855. $sqlWhere .= " or lower(destination_station)";
  856. $sqlWhere .= utils::getInSql($station_or);
  857. }
  858. if (!empty($sales_or)) {
  859. if (utils::checkExist($sales_or, ";")) {
  860. $sql = "1!=1";
  861. $tt = explode(";", $sales_or);
  862. foreach ($tt as $t) {
  863. $t = trim($t);
  864. if (!empty($t))
  865. {
  866. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  867. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  868. }
  869. }
  870. $sqlWhere .= " or ($sql)";
  871. } else
  872. {
  873. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  874. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
  875. }
  876. }
  877. $sqlWhere = " and ($sqlWhere)";
  878. }
  879. return $sqlWhere;
  880. }
  881. public static function isNewVersion() {
  882. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  883. return "_new";
  884. }
  885. return "";
  886. }
  887. public static function removeTopOceanOldVersionSpecialField($rss){
  888. $rss_bk = $rss;
  889. $new_arr = array();
  890. foreach ($rss_bk as $k => $v) {
  891. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  892. //unset($rss[$k]);
  893. }else{
  894. $new_arr[] = $v;
  895. }
  896. }
  897. return $new_arr;
  898. }
  899. public static function echo_json_encode($code,$data){
  900. $resData = array();
  901. $resData["code"] = $code;
  902. $resData["data"] =$data;
  903. //echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  904. echo json_encode($resData);
  905. }
  906. /*
  907. * MM/DD/YYYY To YYYY-MM-DD
  908. */
  909. public static function usDate2sqlDate($timestr) {
  910. if (empty($timestr))
  911. return '';
  912. $datearray = explode("/", $timestr);
  913. $m = $datearray [0];
  914. $d = $datearray [1];
  915. $y = $datearray [2];
  916. return $y . "-" . $m . "-" . $d;
  917. }
  918. public static function uuid() {
  919. return md5(uniqid("", TRUE) . mt_rand());
  920. }
  921. /*
  922. * YYYYMMDD To MM/DD/YYYY
  923. */
  924. public static function date2usdate($datestr) {
  925. if (empty($datestr))
  926. return '';
  927. $y = substr($datestr, 0, 4);
  928. $m = substr($datestr, 4, 2);
  929. $d = substr($datestr, 6, 2);
  930. return $m . "/" . $d . "/" . $y;
  931. }
  932. /*
  933. * date add some days
  934. */
  935. public static function addDays($date, $days) {
  936. $time = strtotime($date) + $days * 24 * 3600;
  937. return date('m/d/Y', $time);
  938. }
  939. /*
  940. * download file from file system
  941. */
  942. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  943. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  944. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  945. if (!file_exists($filename))
  946. exit('File Not Exist');
  947. if (empty($display_name))
  948. $display_name = basename($filename);
  949. //$file = fopen($filename, "r");
  950. header_remove("Content-type");
  951. header("Content-type:" . self::getContentType($filename));
  952. header("Expires: 0");
  953. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  954. header("Pragma: can-cache");
  955. header("Accept-ranges:bytes");
  956. header("Accept-length:" . filesize($filename));
  957. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  958. //echo fread($file, filesize($filename));
  959. //fclose($file);
  960. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  961. $read_buffer = 4096;
  962. $handle = fopen($filename, 'rb');
  963. //总的缓冲的字节数
  964. $sum_buffer = 0;
  965. $filesize = filesize($filename);
  966. //只要没到文件尾,就一直读取
  967. while (!feof($handle) && $sum_buffer < $filesize) {
  968. echo fread($handle, $read_buffer);
  969. $sum_buffer += $read_buffer;
  970. }
  971. //关闭句柄
  972. fclose($handle);
  973. if ($delete !== FALSE) {
  974. unlink($filename);
  975. }
  976. if (!empty($files)) {
  977. foreach ($files as $f) {
  978. unlink($f);
  979. }
  980. }
  981. }
  982. public static function getContentType($filename) {
  983. $extend = self::getExtendFilename($filename);
  984. $filetype = array(
  985. 'xls' => 'application/vnd.ms-excel',
  986. 'doc' => 'application/msword',
  987. 'gif' => 'image/gif',
  988. 'jpg' => 'image/jpeg',
  989. 'jpeg' => 'image/jpeg',
  990. 'jpe' => 'image/jpeg',
  991. 'bmp' => 'image/bmp',
  992. 'png' => 'image/png',
  993. 'tif' => 'image/tiff',
  994. 'pdf' => 'application/pdf',
  995. 'zip' => 'application/zip'
  996. );
  997. return $filetype[$extend];
  998. }
  999. /*
  1000. * Get the file extension
  1001. */
  1002. public static function getExtendFilename($file_name) {
  1003. $extend = pathinfo($file_name);
  1004. $extend = strtolower($extend["extension"]);
  1005. return $extend;
  1006. }
  1007. public static function getManagement(){
  1008. //Management 自己配置需要创建表保存
  1009. $user_management_data = common::excuteObjectSql("select management,dashboard_filter from ra_online_user where user_login = '"._getLoginName()."'");
  1010. //为空,配置使用默认值
  1011. $user_management = $user_management_data['management'];
  1012. if(empty($user_management)){
  1013. $Management = common::getdefaultManagement();
  1014. }else{
  1015. $Management = json_decode($user_management,true);
  1016. foreach($Management as $key =>$val){
  1017. $Management[$key]['id'] = intval($val['id']);
  1018. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  1019. }
  1020. }
  1021. $user_dashboard_filter = $user_management_data['dashboard_filter'];
  1022. $dashboard_filter =array();
  1023. if(!empty($user_dashboard_filter)){
  1024. $dashboard_filter = json_decode($user_dashboard_filter,true);
  1025. }else{
  1026. $threeMonthsAgoTimestamp = strtotime('-3 months');
  1027. $date_start = date('Y-m-d', $threeMonthsAgoTimestamp);
  1028. $date_end = date('Y-m-d');
  1029. $date_start_two = date('m/d/Y', $threeMonthsAgoTimestamp);
  1030. $date_end_two = date('m/d/Y');
  1031. //ETD
  1032. $_12MonthsAgoTimestamp = strtotime('-11 months');
  1033. $etd_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  1034. $etd_date_end = date('Y-m');
  1035. $etd_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  1036. $etd_date_end_two = date('m/Y');
  1037. //柜子
  1038. $ctnr_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  1039. $ctnr_date_end = date('Y-m');
  1040. $ctnr_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  1041. $ctnr_date_end_two = date('m/Y');
  1042. //Top
  1043. $top_date_start = date('Y-m-d', $_12MonthsAgoTimestamp);
  1044. $top_date_end = date('Y-m-d');
  1045. $top_date_start_two = date('m/d/Y', $_12MonthsAgoTimestamp);
  1046. $top_date_end_two = date('m/d/Y');
  1047. //KPIDefaulteData
  1048. $dashboard_filter['KPIDefaulteData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  1049. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  1050. //PendingDefaultData
  1051. $dashboard_filter['PendingDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>"","date_start_two"=>"",
  1052. "date_end"=>"","date_end_two"=>"");
  1053. //RecentDefaultData
  1054. $dashboard_filter['RecentDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  1055. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  1056. //ETDDefaultData
  1057. $dashboard_filter['ETDDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$etd_date_start_two,"date_start_two"=>$etd_date_start,
  1058. "date_end"=>$etd_date_end_two,"date_end_two"=>$etd_date_end);
  1059. //ContainerefaultData
  1060. $dashboard_filter['ContainerefaultData'] = array("transportation" =>array('Sea'),"date_type"=>"ETA","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  1061. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  1062. //RevenueDefaultData
  1063. if(_isRevenueDisplay()){
  1064. $dashboard_filter['RevenueDefaultData'] = array("transportation" =>array('All'),"date_type"=>"Invoice Issue Date","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  1065. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  1066. }
  1067. //Top10faultData
  1068. $dashboard_filter['Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1069. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1070. //OriginCo2Top10faultData
  1071. $dashboard_filter['OriginCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1072. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1073. //DestinationCo2Top10faultData
  1074. $dashboard_filter['DestinationCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1075. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1076. }
  1077. return array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
  1078. }
  1079. public static function getItemStyle($type,$code){
  1080. if($type == 'r1'){
  1081. $data = array("0-20 Days" =>"#ffc594",
  1082. "20-40 Days" =>"#ff9e4c",
  1083. "40-60 Days" =>"#ff7500",
  1084. "60-80 Days" =>"#ff3d00",
  1085. "Over 80 Days" =>"#d50000");
  1086. return $data[$code];
  1087. }
  1088. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  1089. $data = array("0 Day" =>"#ffc594",
  1090. "Today" =>"#ffc594",
  1091. "1-2 Days" =>"#ff9e4c",
  1092. "3-6 Days" =>"#ff7500",
  1093. "7 Days" =>"#ff3d00");
  1094. return $data[$code];
  1095. }
  1096. if($type == 'r2' || utils::startWith($type,"co2e")){
  1097. $data = array("45" =>"#FFE3CC",
  1098. "40" =>"#FFAC66",
  1099. "20" =>"#FF7500",
  1100. "air" =>"#FFE3CC",
  1101. "sea" =>"#FFAC66",
  1102. "road" =>"#FF7500");
  1103. return $data[$code];
  1104. }
  1105. if($type == "top"){
  1106. $data = array("1" =>"#FF7500",
  1107. "2" =>"#ff9033",
  1108. "3" =>"#ff9e4d",
  1109. "4" =>"#ffac66",
  1110. "5" =>"#ffba80",
  1111. "6" =>"#ffc899",
  1112. "7" =>"#ffd6b3",
  1113. "8" =>"#ffe3cc",
  1114. "9" =>"#fff1e6",
  1115. "10" =>"#fff1e6");
  1116. return $data[$code];
  1117. }
  1118. }
  1119. //处理返回原表数据格式
  1120. public static function mian_repot_do($value,$type,$totalValue){
  1121. $data = array();
  1122. $value_arr = json_decode($value,true);
  1123. //r1 是 ETD to ETA (Days)圆形图表数据结构返回
  1124. if($type == 'r1'){
  1125. $ETDList = array();
  1126. foreach($value_arr as $arr){
  1127. $color = common::getItemStyle($type,$arr['name']);
  1128. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1129. }
  1130. $ETDList = array_reverse($ETDList);
  1131. $ETD_Title = "Total: $totalValue";
  1132. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title,"download_name" => "ETD to ETA (Days)");
  1133. }
  1134. if($type == 'r4' || $type == 'r3'){
  1135. //重新整理一下数据,给UI一致
  1136. $data_kd = array();
  1137. foreach($value_arr as $arr){
  1138. if(stripos("Today", $arr['name']) !== false){
  1139. $color = common::getItemStyle($type,"Today");
  1140. if(empty($data_kd["0"])){
  1141. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"≤1 Day","itemStyle" =>array("color" =>$color));
  1142. }else{
  1143. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1144. }
  1145. }
  1146. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1147. $color = common::getItemStyle($type,"1-2 Days");
  1148. if(empty($data_kd["1"])){
  1149. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1150. }else{
  1151. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1152. }
  1153. }
  1154. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1155. $color = common::getItemStyle($type,"3-6 Days");
  1156. if(empty($data_kd["2"])){
  1157. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1158. }else{
  1159. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1160. }
  1161. }
  1162. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1163. $color = common::getItemStyle($type,"7 Days");
  1164. if(empty($data_kd["3"])){
  1165. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"≥7 Days","itemStyle" =>array("color" =>$color));
  1166. }else{
  1167. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1168. }
  1169. }
  1170. }
  1171. if($type == 'r4'){
  1172. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"","download_name" => "Pending Departure");
  1173. }
  1174. if($type == 'r3'){
  1175. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"","download_name" => "Pending Arrival");
  1176. }
  1177. }
  1178. return $data;
  1179. }
  1180. //单独处理co2e bar
  1181. public static function getCo2eBar(){
  1182. //新UI air sea road 目前只有sea
  1183. $type = $_REQUEST["r_type"];
  1184. $shipment_mode_arr = array("air","sea","road");
  1185. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1186. $sqlWhere = " " . $sqlWhere;
  1187. $date_type = strtolower($_REQUEST["date_type"]);
  1188. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1189. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1190. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1191. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1192. $ContainerCount_Title = array();
  1193. //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
  1194. //这里的问题跟 top 一样 。总的排放量查询有问题。目前是总的排放量 暂时等于 sea的排放量
  1195. if ($type == "co2e_orgin"){
  1196. $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
  1197. shippr_uncode as station from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by shippr_uncode order by catnum desc limit 10";
  1198. $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
  1199. }
  1200. if ($type == "co2e_destination"){
  1201. $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
  1202. consignee_uncode as station from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by consignee_uncode order by catnum desc limit 10";
  1203. $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
  1204. }
  1205. //最大Y值
  1206. $maxY = 0;
  1207. $stations = array();
  1208. foreach($co2e_aLL as $val){
  1209. $ContainerCount_Title[] = $val['station'];
  1210. $maxY = $maxY > $val['catnum'] ? $maxY : $val['catnum'];
  1211. if(!empty($val['station'])){
  1212. $stations[] = $val['station'];
  1213. }
  1214. }
  1215. $station_str = utils::implode(',',$stations);
  1216. $ContainerCounSeries = array();
  1217. foreach($shipment_mode_arr as $_shipment_mode){
  1218. //类型有 sea air road,目前之类只查询sea的,其他为空
  1219. $shipment_mode = $_shipment_mode;
  1220. $co2e = array();
  1221. if ($type == "co2e_orgin"){
  1222. $co2e_shippr_sql_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1223. if(!empty($co2e_shippr_sql_union)){
  1224. $co2e = common::excuteListSql($co2e_shippr_sql_union);
  1225. }
  1226. $download_name = "CO2e Emission by Origin (Top 10)";
  1227. }
  1228. if ($type == "co2e_destination"){
  1229. $co2e_consignee_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1230. if(!empty($co2e_consignee_union)){
  1231. $co2e = common::excuteListSql($co2e_consignee_union);
  1232. }
  1233. $download_name = "CO2e Emission by Destination (Top 10)";
  1234. }
  1235. $total = 0;
  1236. $max = 0;
  1237. $data = array();
  1238. foreach($co2e as $val){
  1239. $data[] = empty($val['catnum'])? 0 : round($val['catnum'], 4);
  1240. $total = $total + $val['catnum'];
  1241. $max = $max < $val['catnum'] ? $val['catnum'] : $max;
  1242. }
  1243. $transportation = $_REQUEST["transportation"];
  1244. if(!is_array($transportation)){
  1245. $transportation = array($transportation);
  1246. }
  1247. if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1248. }else{
  1249. //这里不用处理,只有sea的数据
  1250. if (!in_array("Sea", $transportation)){
  1251. $data = array_fill_keys(array_keys($data), 0);
  1252. $total = 0;
  1253. $max = 0;
  1254. }
  1255. }
  1256. $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1257. }
  1258. //处理返回时数据格式 其实不太需要计算最大值,在最开始总量查询的时候以及查询出来
  1259. $ContainerCounSeries_return = array();
  1260. foreach($ContainerCounSeries as $k =>$v){
  1261. $color = common::getItemStyle($type,$k);
  1262. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1263. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color),'barWidth'=>'40');
  1264. }
  1265. //处理返回原表数据格式
  1266. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1267. $interval = utils::calculateTicks(0,$maxY,10);
  1268. if($interval == 0){
  1269. //处理返回默认值
  1270. $interval = 1;
  1271. }
  1272. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1273. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,"download_name" => $download_name);
  1274. return $returnData;
  1275. }
  1276. public static function getTopBar(){
  1277. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1278. $sqlWhere = " " . $sqlWhere;
  1279. $date_type = strtolower($_REQUEST["date_type"]);
  1280. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1281. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1282. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1283. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1284. $toporiginType = "shippr_uncode";
  1285. $shippr_uncode_10_sql ="with aa as (select count(shippr_uncode) as num,shippr_uncode,
  1286. (array_agg(shipper_city))[1] AS shipper_city from online_ocean
  1287. where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
  1288. select aa.*,dd.* from aa
  1289. left join LATERAL ( select lon as lng, lat as lat,
  1290. '' as label, '' as infor, 3 as sort,
  1291. null::timestamp without time zone as stime,''::text as ptype
  1292. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
  1293. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1294. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1295. if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
  1296. $toporiginType = "fport_of_loading_un";
  1297. $shippr_uncode_10_sql = "with aa as (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode
  1298. from online_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
  1299. select aa.*,dd.* from aa
  1300. left join LATERAL ( select lon as lng, lat as lat,
  1301. '' as label, '' as infor, 3 as sort,
  1302. null::timestamp without time zone as stime,''::text as ptype
  1303. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.fport_of_loading_un ) dd on true";
  1304. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1305. }
  1306. //$toporiginType = "fport_of_loading_un";
  1307. $topdestinationinType = "consignee_uncode";
  1308. $consignee_uncode_10_sql = "with aa as (select count(consignee_uncode) as num,consignee_uncode,
  1309. (array_agg(consignee_city))[1] AS consignee_city
  1310. from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by num desc limit 10)
  1311. select aa.*,dd.* from aa
  1312. left join LATERAL ( select lon as lng, lat as lat,
  1313. '' as label, '' as infor, 3 as sort,
  1314. null::timestamp without time zone as stime,''::text as ptype
  1315. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.consignee_uncode ) dd on true";
  1316. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1317. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1318. if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
  1319. $topdestinationinType = "mport_of_discharge_un";
  1320. $consignee_uncode_10_sql = "with aa as (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
  1321. select aa.*,dd.* from aa
  1322. left join LATERAL ( select lon as lng, lat as lat,
  1323. '' as label, '' as infor, 3 as sort,
  1324. null::timestamp without time zone as stime,''::text as ptype
  1325. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.mport_of_discharge_un ) dd on true";
  1326. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1327. }
  1328. //Top查询有点问题,暂时这样查询: 理论上查询air sea road 所有数据的top 10,在更加这个top的站点,分别去查询对于mode的数据计总。
  1329. //但是目前只有sea, 所有模式计总 = sea计总(以后这里是要改的)
  1330. $transportation = $_REQUEST["transportation"];
  1331. if(!is_array($transportation)){
  1332. $transportation = array($transportation);
  1333. }
  1334. if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1335. }else{
  1336. //这里不用处理,只有sea的数据
  1337. if (!in_array("Sea", $transportation)){
  1338. $shippr_uncode_10 = array();
  1339. $consignee_uncode_10 = array();
  1340. }
  1341. }
  1342. $toporigin = array();
  1343. $toporiginMap = array();
  1344. $i = 0;
  1345. $origiNunMax = 0;
  1346. foreach($shippr_uncode_10 as $orgin){
  1347. $i = $i + 1;
  1348. $map = array();
  1349. if(!empty($orgin['lat'])&&!empty($orgin['lng'])){
  1350. $map = array("lat" =>$orgin['lat'],"lng" =>$orgin['lng']);
  1351. }
  1352. //$json = '{"lng":121.8525,"lat":29.926545,"label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1353. //$map = json_decode($json,true);
  1354. if(!empty($map)){
  1355. $toporiginMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1356. "divIcon" => array("iconSize"=>0),
  1357. "name" =>$orgin['shippr_uncode'],
  1358. "color" =>common::getItemStyle("top",$i),
  1359. "value" =>$orgin['num'],
  1360. "textcolor" =>"#FFF");
  1361. }
  1362. //查询uncode,对应的city
  1363. $city = "";
  1364. if($toporiginType == "shippr_uncode"){
  1365. $city = $orgin['shipper_city'];
  1366. }
  1367. //$city 做假数据
  1368. $toporigin[] = array("name"=>$orgin['shippr_uncode'],"city_name"=>$city,"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i));
  1369. $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
  1370. }
  1371. $topdestination = array();
  1372. $topdestinationinMap = array();
  1373. $i = 0;
  1374. $agentiNunMax = 0;
  1375. foreach($consignee_uncode_10 as $agent){
  1376. $i = $i + 1;
  1377. $map = array();
  1378. if(!empty($agent['lat'])&&!empty($agent['lng'])){
  1379. $map = array("lat" =>$agent['lat'],"lng" =>$agent['lng']);
  1380. }
  1381. // $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1382. // $map = json_decode($json,true);
  1383. if(!empty($map)){
  1384. $topdestinationinMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1385. "divIcon" => array("iconSize"=>0),
  1386. "name" =>$agent['consignee_uncode'],
  1387. "color" =>common::getItemStyle("top",$i),
  1388. "value" =>$agent['num'],
  1389. "textcolor" =>"#FFF");
  1390. }
  1391. //查询uncode,对应的city
  1392. $city = "";
  1393. if($topdestinationinType == "consignee_uncode"){
  1394. $city = $agent['consignee_city'];
  1395. }
  1396. //$city 做假数据
  1397. $topdestination[] = array("name"=>$agent['consignee_uncode'],"city_name"=>$city,"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i));
  1398. $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
  1399. }
  1400. //处理返回原表数据格式
  1401. $interval = utils::calculateTicks(0,$origiNunMax,10);
  1402. if($interval == 0){
  1403. //处理返回默认值
  1404. $interval = 1;
  1405. }
  1406. $dest_interval = utils::calculateTicks(0,$agentiNunMax,10);
  1407. if($dest_interval == 0){
  1408. //处理返回默认值
  1409. $dest_interval = 1;
  1410. }
  1411. $returnData = array("seller_data_list_origin"=>$toporigin,"toporiginMap"=>array_reverse($toporiginMap),"toporiginType"=>$toporiginType,
  1412. "seller_data_list_destination"=>$topdestination,"topdestinationinMap"=>array_reverse($topdestinationinMap),"topdestinationinType"=>$topdestinationinType,
  1413. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,
  1414. "dest_min" => 0,"dest_Max" =>$dest_interval*10,"dest_interval" =>$dest_interval);
  1415. return $returnData;
  1416. }
  1417. public static function getRevenue(){
  1418. $data = '{"bar_title":"Total: 0","barList":["DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24","NOV,24"],"barSeries":[{"name":"USD","type":"bar","data":[1,1,1,1,1,1,1,1,1,1,1,1],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FF7500","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"THB","type":"bar","data":[2,2,2,2,2,2,2,2,2,2,2,2],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFAC66","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"SGD","type":"bar","data":[3,3,3,3,3,3,3,3,3,3,3,3],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFE3CC","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}}],"Max":5,"interval":1,"download_name":"Rvenue","isShowTooltips":true}';
  1419. //return json_decode($data,true);
  1420. $date_from = null;
  1421. $date_to = null;
  1422. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1423. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1424. $date_from = $date_start."-01";
  1425. }
  1426. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1427. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1428. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1429. }
  1430. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1431. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1432. error_log("Revenue_sql:".$sql);
  1433. $r2_data = common::excuteListSql($sql);
  1434. //$r2_data = common::excuteListSql("select * from _test_data_table");
  1435. $barList = array();
  1436. $groupedItems = array();
  1437. foreach ($r2_data as $item) {
  1438. if(!in_array($item['month'],$barList)){
  1439. $barList[] = $item['month'];
  1440. }
  1441. $groupedItems[$item['currency']][] = $item;
  1442. }
  1443. //补齐所有货币的月份
  1444. foreach($groupedItems as $ckey =>$cvalueArr){
  1445. $currency = array();
  1446. foreach($barList as $month){
  1447. $currency[] = common::findCurrencyByMonth($month,$ckey,$cvalueArr);
  1448. }
  1449. $groupedItems[$ckey] = $currency;
  1450. }
  1451. //处理barSeries
  1452. $barSeries = array();
  1453. //先准备4种颜色
  1454. $color = array("#FF7500","#FFAC66","#FFE3CC");
  1455. $index = 0;
  1456. $max = 0;
  1457. foreach($groupedItems as $currency => $series){
  1458. $series_max = 0;
  1459. $num = $index % 3;
  1460. $index = $index +1;
  1461. $tem_series = array();
  1462. $tem_series["name"] = $currency;
  1463. $tem_series["type"] = "bar";
  1464. $tem_series["emphasis"] = array("disabled"=>true,"focus"=>"none");
  1465. $tem_series["itemStyle"] = array("color"=>$color[$num],"borderRadius"=>6);
  1466. $tem_series["label"] = array("show"=>false,"color"=>"#646A73","position"=>"top","fontFamily"=>"Lato-Light","hideWhenMouseLeave"=>false);
  1467. //准备series data
  1468. $data = array();
  1469. $total = 0;
  1470. foreach($series as $_series){
  1471. $invoice_amount = empty($_series['invoice_amount'])? 0 : round($_series['invoice_amount'], 4);
  1472. $data[]=$invoice_amount;
  1473. $total = $total + $invoice_amount;
  1474. $max = $max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $max;
  1475. $series_max = $series_max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $series_max;
  1476. }
  1477. //计算Y坐标的间隔 每种货币的
  1478. $interval = utils::calculateTicks(0,$series_max,5);
  1479. if($interval == 0){
  1480. //处理返回默认值
  1481. $interval = 2;
  1482. }
  1483. $tem_series["Max"] = $interval*5;
  1484. $tem_series["interval"] = $interval;
  1485. $tem_series["data"] = $data;
  1486. $tem_series["total"] = floatval(number_format($total, 4, '.', ''));
  1487. $barSeries[] = $tem_series;
  1488. }
  1489. //计算Y坐标的间隔
  1490. $interval = utils::calculateTicks(0,$max,5);
  1491. if($interval == 0){
  1492. //处理返回默认值
  1493. $interval = 2;
  1494. }
  1495. $revenueBarData = array("bar_title" =>"Total:","barList" => $barList,
  1496. "barSeries" =>$barSeries,"download_name"=>"Rvenue","isShowTooltips"=>true,"Max" =>$interval*5,"interval" =>$interval);
  1497. return $revenueBarData;
  1498. }
  1499. public static function findCurrencyByMonth($month,$ckey,$cvalueArr){
  1500. $data = array("month" =>$month,"currency"=>$ckey,"invoice_amount"=>0,"sort_month"=>"");
  1501. foreach($cvalueArr as $realmonth){
  1502. if($realmonth['month'] == $month){
  1503. $data = $realmonth;
  1504. }
  1505. }
  1506. return $data;
  1507. }
  1508. public static function getdefaultManagement(){
  1509. $Management = array();
  1510. $Management[] = array("id"=>1 ,
  1511. "title"=>"KPI",
  1512. "switchValue"=>true,
  1513. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1514. $Management[] = array("id"=>2 ,
  1515. "title"=>"Pending",
  1516. "switchValue"=>true,
  1517. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1518. $Management[] = array("id"=>3 ,
  1519. "title"=>"ETD to ETA (Days)",
  1520. "switchValue"=>true,
  1521. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1522. $Management[] = array("id"=>4 ,
  1523. "title"=>"Container Count",
  1524. "switchValue"=>true,
  1525. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1526. if(_isRevenueDisplay()){
  1527. $Management[] = array("id"=>5 ,
  1528. "title"=>"Revenue Spent",
  1529. "switchValue"=>true,
  1530. "text"=>"Revenue data for the past 12 months.");
  1531. }
  1532. $Management[] = array("id"=>6 ,
  1533. "title"=>"Top 10 Origin/Destination",
  1534. "switchValue"=>true,
  1535. "text"=>"Figure of the top 10 origin/destination.",
  1536. "title1"=>"Top 10 Origin",
  1537. "title2"=>"Top 10 Destination");
  1538. $Management[] = array("id"=>7 ,
  1539. "title"=>"CO2e Emission by Origin (Top 10)",
  1540. "switchValue"=>true,
  1541. "text"=>"Figure of the CO2e Emission by origin.");
  1542. $Management[] = array("id"=>8 ,
  1543. "title"=>"CO2e Emission by Destination (Top 10)",
  1544. "switchValue"=>true,
  1545. "text"=>"Figure of the CO2e Emission by destination.");
  1546. $Management[] = array("id"=>9 ,
  1547. "title"=>"Recent Status",
  1548. "switchValue"=>true,
  1549. "text"=>"A shipment list with latest status update on top.");
  1550. return $Management;
  1551. }
  1552. /**
  1553. * Destroy Session
  1554. */
  1555. public static function sessionDestroy() {
  1556. session_destroy();
  1557. setcookie(session_name(), '', time() - 3600);
  1558. $_SESSION = array();
  1559. }
  1560. public static function dateFormatToYM($dateString){
  1561. $date = DateTime::createFromFormat('m/Y', $dateString);
  1562. $formattedDate = $date->format('Y-m'); // YYYY-MM
  1563. return $formattedDate;
  1564. }
  1565. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1566. $stationInfo = "";
  1567. if(!empty($address_1)){
  1568. $stationInfo .= $address_1;
  1569. }
  1570. if(!empty($address_2)){
  1571. $stationInfo .= " ".$address_2;
  1572. }
  1573. if(!empty($address_3)){
  1574. $stationInfo .= " ".$address_3;
  1575. }
  1576. if(!empty($address_4)){
  1577. $stationInfo .= " ".$address_4;
  1578. }
  1579. $temp_str = "";
  1580. if(!empty($city)){
  1581. $temp_str .= $city." ";
  1582. }
  1583. if(!empty($state)){
  1584. $temp_str .= $state." ";
  1585. }
  1586. if(!empty($zipcode)){
  1587. $temp_str .= $zipcode." ";
  1588. }
  1589. if(!empty($country)){
  1590. $temp_str .= $country." ";
  1591. }
  1592. if(!empty($temp_str)){
  1593. return $stationInfo." ".trim($temp_str);
  1594. }
  1595. return $stationInfo;
  1596. }
  1597. public static function getInsertSqlNull($table_name, $values) {
  1598. $field = "";
  1599. $value = "";
  1600. foreach ($values as $k => $v) {
  1601. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1602. continue;
  1603. }
  1604. if (is_array($v)) {
  1605. $v = utils::implode(",", $v);
  1606. }
  1607. if (empty($field)) {
  1608. $field = $k;
  1609. if (utils::checkExist($v, 'now()')) {
  1610. $value = $v;
  1611. } elseif ($v == null) {
  1612. $value .= 'null';
  1613. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1614. $value .= $v;
  1615. } else {
  1616. $value = '\'' . common::check_input($v) . '\'';
  1617. }
  1618. } else {
  1619. $field .= ',' . $k;
  1620. if (utils::checkExist($v, 'now()'))
  1621. $value .= ', now()';
  1622. elseif ($v == null) {
  1623. $value .= ',null';
  1624. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1625. $value .= ',' . $v;
  1626. } else {
  1627. $value .= ', \'' . common::check_input($v) . '\'';
  1628. }
  1629. }
  1630. }
  1631. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1632. }
  1633. //密码规则验证
  1634. public static function checkPasswordRule($login, $new_password){
  1635. $sql="select item_value from config where item='passwordCheckRules'";
  1636. $rs = common::excuteObjectSql($sql);
  1637. $str = "";
  1638. if (!empty($rs)) {
  1639. $passwordCheckRules = json_decode($rs["item_value"],true);
  1640. //校验使用次数
  1641. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  1642. $sql = "select password from public.ra_online_user_password_history where lower(user_login)='".common::check_input(strtolower($login))."' order by id desc limit ".$passwordCheckRules["pastPasswordCheckNum"];
  1643. $passwords = common::excuteListSql($sql);
  1644. foreach ($passwords as $pwd) {
  1645. if ($pwd['password'] == $new_password) {
  1646. $str = "This password has been recently used";
  1647. }
  1648. }
  1649. }
  1650. if(empty($str)){
  1651. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  1652. }
  1653. }else{
  1654. $str = utils::checkPassword($new_password);
  1655. }
  1656. return $str;
  1657. }
  1658. public static function getMilestonesInfo($ocean,$EDI315TimeAndLocation){
  1659. //Milestones info列名固定
  1660. $Milestones_column = array();
  1661. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
  1662. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
  1663. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
  1664. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
  1665. //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
  1666. $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($ocean);
  1667. //Milestones 数据信息待定
  1668. $Milestones_data = array();
  1669. $Milestones_data_arr = common::excuteListSql("select sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
  1670. remark,timezone,a.code
  1671. from ocean_milestone a
  1672. inner join customer_service_milestone_sno sn on sn.code=a.code
  1673. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by sn.sno asc");
  1674. foreach($Milestones_data_arr as $mda){
  1675. $timezone = "";
  1676. if(!empty($EDI315TimeAndLocation[$mda['code']])){
  1677. $edi315Info = $EDI315TimeAndLocation[$mda['code']];
  1678. if(!empty($edi315Info)){
  1679. $timezone = $edi315Info['timezone'];
  1680. }
  1681. //IFFICC 比较特殊用EDI的locations
  1682. if($mda['code'] == "IFFICC"){
  1683. $IFFICC_locations = $edi315Info['location'];
  1684. }
  1685. }else{
  1686. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1687. if(!empty($edi315Info)){
  1688. $timezone = $edi315Info['timezone'];
  1689. }
  1690. }
  1691. //locations 以配置的信息为准
  1692. $locations = "";
  1693. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1694. if(!empty($edi315Info)){
  1695. $locations = $edi315Info['location'];
  1696. if($mda['code'] == "IFFICC" && !empty($IFFICC_locations)){
  1697. $locations = $IFFICC_locations;
  1698. }
  1699. }
  1700. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
  1701. "locations" => $locations, "remarks" =>$mda['remark']);
  1702. }
  1703. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  1704. return $Milestones;
  1705. }
  1706. /**
  1707. * 查询uncode 对应的时区
  1708. */
  1709. public static function getCityPortsInfo($uncodes){
  1710. $data =array();
  1711. $sql = "select time_zone as timezonecode,uncode as ctrycitycode from public.city_timezone where lower(uncode) ". common::getInNotInSql($uncodes);
  1712. $uncode_rs = common::excuteListSql($sql);
  1713. foreach($uncode_rs as $value){
  1714. $data[$value['ctrycitycode']] = $value['timezonecode'];
  1715. }
  1716. return $data;
  1717. }
  1718. /**
  1719. * EDI315 有关联查询,以那个为准。但是如果是手工录入或者没有对应的情况,这以这个为准
  1720. */
  1721. public static function getMilestones_NO_Mapping_Data($ocean){
  1722. $Milestones_NO_Mapping = array();
  1723. //取origin $ocean['aa_city'] 不是必需,对应文件里未提location来源
  1724. $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1725. $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1726. $Milestones_NO_Mapping['IFFCPU'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1727. $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1728. $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1729. $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1730. //Place of Receipt
  1731. $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1732. $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1733. //Port of loading
  1734. $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1735. $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1736. //取destination $ocean['dd_city']不是必需
  1737. $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1738. $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1739. //取Port of discharge
  1740. $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1741. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1742. $Milestones_NO_Mapping['IFFICC'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1743. //Place of Delivery
  1744. $Milestones_NO_Mapping['IFFAFD'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1745. $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1746. $Milestones_NO_Mapping['IFFADW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1747. $Milestones_NO_Mapping['IFFDDW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1748. $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1749. $Milestones_NO_Mapping['IFFECR'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1750. //final_destination $ocean['fd_city']不是必需
  1751. $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1752. $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1753. return $Milestones_NO_Mapping;
  1754. }
  1755. public static function getEDI315StatusForDetail($serial_no){
  1756. $data = array();
  1757. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no
  1758. WHERE o.serial_no='$serial_no'";
  1759. $ctnr_data = common::excuteListSql($ctnr_sql);
  1760. $containerStatusData = array();
  1761. $VD = "";
  1762. $VA = "";
  1763. foreach ($ctnr_data as $cd){
  1764. //存在柜号为空的数据情况
  1765. if(empty($cd['ctnr'])){
  1766. continue;
  1767. }
  1768. //(select uncity from public.ports where uncode = s.event_code) as uncity, 按新版的逻辑这个先取消掉
  1769. $ctnr_status_sql = "select s.source_id, s.event_base as event,
  1770. to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
  1771. to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
  1772. e.description,s.event_type as eventtype,
  1773. s.event_code as eventcode, s.event_city as eventcity,
  1774. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1775. '' as uncity,
  1776. case when event ='I' or event ='TR' then 'IFFREC'::text
  1777. when event ='AE' then 'IFFONB'::text
  1778. when event ='VD' then 'IFFDEP'::text
  1779. when event ='EB' or event ='VA' then 'IFFARR'::text
  1780. when event ='UV' then 'IFFUND'::text
  1781. when event ='VA' then 'IFFAFD'::text
  1782. when event ='AV' then 'IFFCTA'::text
  1783. when event ='CT' then 'IFFICC'::text
  1784. when event ='OA' or event ='D' then 'IFFPPD'::text
  1785. when event ='RD' then 'IFFECR'::text
  1786. when event ='EE' then 'IFFECP'::text
  1787. else '' ::text
  1788. end as milestone_code
  1789. from public.ra_online_container_status_v s
  1790. left join ra_online_edi_event e on s.event_base = e.ra_name
  1791. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1792. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1793. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  1794. to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
  1795. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1796. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1797. $container_status_column = array("EE","I","AE","VD","VA");
  1798. $containerStatusDataTemp = array();
  1799. $content = array();
  1800. //按顺序处理 新版只显示几个状态
  1801. //foreach($container_status_column as $status){
  1802. foreach($ctnr_status as $event){
  1803. //if(strtolower($event['event']) == strtolower($status)){
  1804. $eventdate = $event["eventdate"];
  1805. if (empty($event["source_id"]) || $event["source_id"]==0) {
  1806. $eventdate.= " " . $event["eventtime"];
  1807. }
  1808. $location_code = $event["eventcode"];
  1809. $content[] = array("code" =>$event['event'],"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone']);
  1810. if(strtolower($event['event']) == "vd" && !empty($eventdate)){
  1811. $VD = $eventdate;
  1812. }
  1813. if(strtolower($event['event']) == "va" && !empty($eventdate)){
  1814. $VA = $eventdate;
  1815. }
  1816. //}
  1817. }
  1818. //}
  1819. //记录所有的信息
  1820. $EDI315TimeAndLocation = array();
  1821. foreach($ctnr_status as $event){
  1822. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1823. //如果存在EB 的EB 的优先级最高
  1824. continue;
  1825. }
  1826. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1827. //如果存在OA 的OA 的优先级最高
  1828. continue;
  1829. }
  1830. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
  1831. }
  1832. $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
  1833. $containerStatusDataTemp['content'] = $content;
  1834. $containerStatusData[] = $containerStatusDataTemp;
  1835. }
  1836. $data['containerStatusData'] = $containerStatusData;
  1837. $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
  1838. $data['VD'] = $VD;
  1839. $data['VA'] = $VA;
  1840. return $data;
  1841. }
  1842. public static function getEDI315Time($serial_no){
  1843. //Timezone From 来自于EDI315
  1844. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no
  1845. WHERE o.serial_no='$serial_no'";
  1846. $ctnr_data = common::excuteListSql($ctnr_sql);
  1847. $EDI315TimeAndLocation = array();
  1848. foreach ($ctnr_data as $cd){
  1849. //存在柜号为空的数据情况
  1850. if(empty($cd['ctnr'])){
  1851. continue;
  1852. }
  1853. $ctnr_status_sql = "select
  1854. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1855. case when event ='I' or event ='TR' then 'IFFREC'::text
  1856. when event ='AE' then 'IFFONB'::text
  1857. when event ='VD' then 'IFFDEP'::text
  1858. when event ='EB' or event ='VA' then 'IFFARR'::text
  1859. when event ='UV' then 'IFFUND'::text
  1860. when event ='VA' then 'IFFAFD'::text
  1861. when event ='AV' then 'IFFCTA'::text
  1862. when event ='CT' then 'IFFICC'::text
  1863. when event ='OA' or event ='D' then 'IFFPPD'::text
  1864. when event ='RD' then 'IFFECR'::text
  1865. when event ='EE' then 'IFFECP'::text
  1866. else '' ::text
  1867. end as milestone_code
  1868. from public.ra_online_container_status_v s
  1869. left join ra_online_edi_event e on s.event_base = e.ra_name
  1870. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1871. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1872. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  1873. to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
  1874. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1875. //记录所有的信息、替换最后一个柜子
  1876. $EDI315TimeAndLocation = array();
  1877. foreach($ctnr_status as $event){
  1878. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1879. //如果存在EB 的EB 的优先级最高
  1880. continue;
  1881. }
  1882. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1883. //如果存在OA 的OA 的优先级最高
  1884. continue;
  1885. }
  1886. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone']);
  1887. }
  1888. }
  1889. return $EDI315TimeAndLocation;
  1890. }
  1891. }
  1892. ?>