|
@@ -335,7 +335,7 @@ class report {
|
|
|
$_value_type = $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
|
|
$_value_type = $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
|
|
|
$_fixed_value = common::check_input($_tempFieldsList['value']);
|
|
$_fixed_value = common::check_input($_tempFieldsList['value']);
|
|
|
//这两个不能配置查询和过滤
|
|
//这两个不能配置查询和过滤
|
|
|
- if($_field_group_name == 'Container info' || $_field_group_name == 'Milestone'
|
|
|
|
|
|
|
+ if($_field_group_name == 'Container Status' || $_field_group_name == 'Milestone'
|
|
|
||$_field_code == 'Other reference No.' || $_field_code == 'Shipper Zip Code' || $_field_code == 'Consignee Zip Code' ){
|
|
||$_field_code == 'Other reference No.' || $_field_code == 'Shipper Zip Code' || $_field_code == 'Consignee Zip Code' ){
|
|
|
$_is_filter_enabled = "false";
|
|
$_is_filter_enabled = "false";
|
|
|
} else {
|
|
} else {
|
|
@@ -464,21 +464,26 @@ class report {
|
|
|
$dataReturn['sortBy'] = array("field"=>"","options"=>[],"order"=>"asc");
|
|
$dataReturn['sortBy'] = array("field"=>"","options"=>[],"order"=>"asc");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $reportFiled = common::excuteObjectSql("select report_sql,count_sql,level from public.kln_report_template where serial_no = '".$serial_no."'");
|
|
|
|
|
|
|
+ $reportFiled = common::excuteObjectSql("select name,report_sql,count_sql,level from public.kln_report_template where serial_no = '".$serial_no."'");
|
|
|
$sqlManage = common::excuteObjectSql("select sql,count_sql,level from public.kln_report_sql_manage where level = '".$reportFiled['level']."'");
|
|
$sqlManage = common::excuteObjectSql("select sql,count_sql,level from public.kln_report_sql_manage where level = '".$reportFiled['level']."'");
|
|
|
$report_sql = $sqlManage["sql"];
|
|
$report_sql = $sqlManage["sql"];
|
|
|
- $count_sql = $sqlManage["count_sql"];
|
|
|
|
|
|
|
+ //$count_sql = $sqlManage["count_sql"];
|
|
|
|
|
|
|
|
- $filterSQLArr = $this->returnFilterSql($filtersList);
|
|
|
|
|
|
|
+ $filterSQLArr = $this->returnFilterSql_v1($filtersList);
|
|
|
|
|
+ $count_sql = common::buildCountSql($filterSQLArr['filterFields'],$reportFiled['level']);
|
|
|
//return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
//return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
|
$count_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $count_sql);
|
|
$count_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $count_sql);
|
|
|
$count_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $count_sql);
|
|
$count_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $count_sql);
|
|
|
$count_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $count_sql);
|
|
$count_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $count_sql);
|
|
|
|
|
+ $count_sql = str_replace('<{orderby}>', "", $count_sql);
|
|
|
|
|
+ error_log($reportFiled['name'].": report_detail_count, ".$count_sql);
|
|
|
|
|
|
|
|
$report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
|
|
$report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
|
|
|
$report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
|
|
$report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
|
|
|
$report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
|
|
$report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
|
|
|
$report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
|
|
$report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
|
|
|
|
|
+ $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
|
|
|
|
|
+ error_log($reportFiled['name'].": report_detail_search, ".$report_sql);
|
|
|
|
|
|
|
|
//查询data
|
|
//查询data
|
|
|
$cp = common::check_input($_POST ['cp']); //current_page
|
|
$cp = common::check_input($_POST ['cp']); //current_page
|
|
@@ -490,16 +495,12 @@ class report {
|
|
|
|
|
|
|
|
$rc = $_POST ['rc'];
|
|
$rc = $_POST ['rc'];
|
|
|
if ($rc == -1) {
|
|
if ($rc == -1) {
|
|
|
- $count_sql = str_replace('<{orderby}>', "", $count_sql);
|
|
|
|
|
- error_log($count_sql);
|
|
|
|
|
$rc = common::excuteOneSql($count_sql);
|
|
$rc = common::excuteOneSql($count_sql);
|
|
|
}
|
|
}
|
|
|
$tp = ceil($rc / $ps);
|
|
$tp = ceil($rc / $ps);
|
|
|
if ($rc > 0) {
|
|
if ($rc > 0) {
|
|
|
- $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
|
|
|
|
|
$tmp_search_without_limit = $report_sql;
|
|
$tmp_search_without_limit = $report_sql;
|
|
|
$report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
$report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
|
- error_log($report_sql);
|
|
|
|
|
|
|
|
|
|
$rs = common::excuteListSql($report_sql);
|
|
$rs = common::excuteListSql($report_sql);
|
|
|
$arrTmp = array('searchData' => $rs,
|
|
$arrTmp = array('searchData' => $rs,
|
|
@@ -682,14 +683,17 @@ class report {
|
|
|
|
|
|
|
|
|
|
|
|
|
//形成sql
|
|
//形成sql
|
|
|
- $schedule_search = common::excuteObjectSql("select schedule_order_field,data_reference_field,data_range_type,
|
|
|
|
|
|
|
+ $schedule_search = common::excuteObjectSql("select name,level,schedule_order_field,data_reference_field,data_range_type,
|
|
|
dynamic_start_offset,dynamic_end_offset,
|
|
dynamic_start_offset,dynamic_end_offset,
|
|
|
fixed_start_date,fixed_end_date,
|
|
fixed_start_date,fixed_end_date,
|
|
|
report_sql,count_sql
|
|
report_sql,count_sql
|
|
|
from public.kln_report_template where serial_no = '$serial_no'");
|
|
from public.kln_report_template where serial_no = '$serial_no'");
|
|
|
|
|
|
|
|
$report_sql = $schedule_search["report_sql"];
|
|
$report_sql = $schedule_search["report_sql"];
|
|
|
- $count_sql = $schedule_search["count_sql"];
|
|
|
|
|
|
|
+ //$count_sql = $schedule_search["count_sql"];
|
|
|
|
|
+
|
|
|
|
|
+ $filterFields = [];
|
|
|
|
|
+ $count_sql = common::buildCountSql($filterFields,$schedule_search['level']);
|
|
|
|
|
|
|
|
//$klnOceanSearchKLN = " where " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
//$klnOceanSearchKLN = " where " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
|
$klnOceanSearchKLN = " where created_time > CURRENT_DATE - INTERVAL '1 years' and " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
$klnOceanSearchKLN = " where created_time > CURRENT_DATE - INTERVAL '1 years' and " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
@@ -736,11 +740,15 @@ class report {
|
|
|
$count_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $count_sql);
|
|
$count_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $count_sql);
|
|
|
$count_sql = str_replace('<{ocItemSearchKLN}>', " ", $count_sql);
|
|
$count_sql = str_replace('<{ocItemSearchKLN}>', " ", $count_sql);
|
|
|
$count_sql = str_replace('<{vvSearchKLN}>', " ", $count_sql);
|
|
$count_sql = str_replace('<{vvSearchKLN}>', " ", $count_sql);
|
|
|
|
|
+ $count_sql = str_replace('<{orderby}>', "", $count_sql);
|
|
|
|
|
+ error_log($schedule_search['name'].": report_schedule_count, ".$count_sql);
|
|
|
|
|
|
|
|
$report_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $report_sql);
|
|
$report_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $report_sql);
|
|
|
$report_sql = str_replace('<{ocItemSearchKLN}>', " ", $report_sql);
|
|
$report_sql = str_replace('<{ocItemSearchKLN}>', " ", $report_sql);
|
|
|
$report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
|
|
$report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
|
|
|
$report_sql = str_replace('<{vvSearchKLN}>', " ", $report_sql);
|
|
$report_sql = str_replace('<{vvSearchKLN}>', " ", $report_sql);
|
|
|
|
|
+ $report_sql = str_replace('<{orderby}>', $orderby, $report_sql);
|
|
|
|
|
+ error_log($schedule_search['name'].": report_schedule_search, ".$report_sql);
|
|
|
|
|
|
|
|
//查询sql
|
|
//查询sql
|
|
|
$cp = common::check_input($_POST ['cp']); //current_page
|
|
$cp = common::check_input($_POST ['cp']); //current_page
|
|
@@ -752,16 +760,12 @@ class report {
|
|
|
|
|
|
|
|
$rc = $_POST ['rc'];
|
|
$rc = $_POST ['rc'];
|
|
|
if ($rc == -1) {
|
|
if ($rc == -1) {
|
|
|
- $count_sql = str_replace('<{orderby}>', "", $count_sql);
|
|
|
|
|
- error_log($count_sql);
|
|
|
|
|
$rc = common::excuteOneSql($count_sql);
|
|
$rc = common::excuteOneSql($count_sql);
|
|
|
}
|
|
}
|
|
|
$tp = ceil($rc / $ps);
|
|
$tp = ceil($rc / $ps);
|
|
|
if ($rc > 0) {
|
|
if ($rc > 0) {
|
|
|
- $report_sql = str_replace('<{orderby}>', $orderby, $report_sql);
|
|
|
|
|
$tmp_search_without_limit = $report_sql;
|
|
$tmp_search_without_limit = $report_sql;
|
|
|
$report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
$report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
|
- error_log($report_sql);
|
|
|
|
|
|
|
|
|
|
$rs = common::excuteListSql($report_sql);
|
|
$rs = common::excuteListSql($report_sql);
|
|
|
$arrTmp = array('searchData' => $rs,
|
|
$arrTmp = array('searchData' => $rs,
|
|
@@ -987,6 +991,97 @@ class report {
|
|
|
return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据提交的参数动态的拼接Count sql
|
|
|
|
|
+ */
|
|
|
|
|
+ public function returnFilterSql_v1($filtersList){
|
|
|
|
|
+ $klnVipDb = common::getReportRealDBFiled();
|
|
|
|
|
+
|
|
|
|
|
+ $vvSearchKLN = " where 1=1 ";
|
|
|
|
|
+ $klnOceanSearchKLN = " where created_time > CURRENT_DATE - INTERVAL '1 years' and " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
|
|
|
+ //$klnOceanSearchKLN = " where " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
|
|
|
+ $ocItemSearchKLN = " where 1=1 ";
|
|
|
|
|
+
|
|
|
|
|
+ $filterFields = array();
|
|
|
|
|
+ foreach($filtersList as $fiter){
|
|
|
|
|
+ if(!empty($_POST[$fiter['field']])){
|
|
|
|
|
+ //这里其实可以改成field_real
|
|
|
|
|
+ $key = array_search($fiter['field'], $klnVipDb);
|
|
|
|
|
+ $filterFields[] = $fiter['field_real'];
|
|
|
|
|
+ if($key !== false){
|
|
|
|
|
+ //找到给key
|
|
|
|
|
+ $temp_sql_where = "";
|
|
|
|
|
+ if ($fiter['data_type'] == "string"){
|
|
|
|
|
+ $temp_sql_where .= " and ".$key." ilike '%". common::check_input($_POST[$fiter['field']])."%'";
|
|
|
|
|
+ } elseif ($fiter['data_type'] == "number"){
|
|
|
|
|
+ $temp_arr = $_POST [$fiter['field']];
|
|
|
|
|
+ if(!empty($temp_arr[0])){
|
|
|
|
|
+ $temp_sql_where .= " and ".$key."::numeric >= '". common::check_input($temp_arr[0])."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!empty($temp_arr[1])){
|
|
|
|
|
+ $temp_sql_where .= " and ".$key."::numeric <= '". common::check_input($temp_arr[1])."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ } elseif ($fiter['data_type'] == "date"){
|
|
|
|
|
+ $temp_arr = $_POST [$fiter['field']];
|
|
|
|
|
+ if(!empty($temp_arr[0])){
|
|
|
|
|
+ $date_from = common::check_input(common::usDate2sqlDate($temp_arr[0]) . ' 00:00:00');
|
|
|
|
|
+ $temp_sql_where .= " and ".$key." >= '". $date_from."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!empty($temp_arr[1])){
|
|
|
|
|
+ $date_to = common::check_input(common::usDate2sqlDate($temp_arr[1]) . ' 23:59:59');
|
|
|
|
|
+ $temp_sql_where .= " and ".$key." <= '". $date_to."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (utils::startWith($key,"oc") || utils::startWith($key,"oi") || utils::startWith($key,"oe") || utils::startWith($key,"co2_r")
|
|
|
|
|
+ || $fiter['field'] == "total_distance"
|
|
|
|
|
+ || $fiter['field'] == "last_mile_delivery"
|
|
|
|
|
+ || $key == "COALESCE(oe.import_po_no,oo.po_no)"
|
|
|
|
|
+ || $key == "oo._voyage"
|
|
|
|
|
+ || $key == "oo._vessel"
|
|
|
|
|
+ || $key == "oo.new_status"){
|
|
|
|
|
+ $ocItemSearchKLN .= $temp_sql_where;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $klnOceanSearchKLN .= $temp_sql_where;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //获取POST name 用户去别名得字段,放在vvSearchKLN上
|
|
|
|
|
+ $_post_field = $fiter['field'];
|
|
|
|
|
+ $_post_field = strtolower($_post_field);
|
|
|
|
|
+ $_post_field = preg_replace('/[^a-z0-9]+/', '_', $_post_field); // 非字母数字 → _
|
|
|
|
|
+ $_post_field = trim($_post_field, '_');
|
|
|
|
|
+
|
|
|
|
|
+ if ($fiter['data_type'] == "string"){
|
|
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field_real']."\" ilike '%". common::check_input($_POST [$_post_field])."%'";
|
|
|
|
|
+ } elseif ($fiter['data_type'] == "number"){
|
|
|
|
|
+ $temp_arr = $_POST [$_post_field];
|
|
|
|
|
+ if(!empty($temp_arr[0])){
|
|
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field_real']."\"::numeric >= '". common::check_input($temp_arr[0])."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!empty($temp_arr[1])){
|
|
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field_real']."\"::numeric <= '". common::check_input($temp_arr[1])."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ } elseif ($fiter['data_type'] == "date"){
|
|
|
|
|
+ $temp_arr = $_POST [$_post_field];
|
|
|
|
|
+ //先判断日期字符串是否为空,这里则有做 是因为sql 整合了柜子315时间,和 milestone的时间, 只能text转date
|
|
|
|
|
+ if(!empty($temp_arr[0])){
|
|
|
|
|
+ $date_from = common::check_input(common::usDate2sqlDate($temp_arr[0]) . ' 00:00:00');
|
|
|
|
|
+ $vvSearchKLN .= " and COALESCE(\"".$fiter['field_real']."\",''::text)<> ''::text ";
|
|
|
|
|
+ $vvSearchKLN .= " and to_timestamp(\"".$fiter['field_real']."\", 'MM/DD/YYYY HH24:MI:SS') >= '". $date_from."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!empty($temp_arr[1])){
|
|
|
|
|
+ $date_to = common::check_input(common::usDate2sqlDate($temp_arr[1]) . ' 23:59:59');
|
|
|
|
|
+ $vvSearchKLN .= " and COALESCE(\"".$fiter['field_real']."\",''::text)<> ''::text ";
|
|
|
|
|
+ $vvSearchKLN .= " and to_timestamp(\"".$fiter['field_real']."\", 'MM/DD/YYYY HH24:MI:SS') <= '". $date_to."'";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN,"filterFields"=>$filterFields);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 根据提交的参数动态的拼接sort by sql
|
|
* 根据提交的参数动态的拼接sort by sql
|
|
|
*/
|
|
*/
|