|
|
@@ -2026,9 +2026,8 @@ class tools {
|
|
|
$limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
|
}
|
|
|
|
|
|
- $sql = "select *
|
|
|
- from (select ni.*,
|
|
|
- ROW_NUMBER() OVER (
|
|
|
+ $sql = "with aa as (select ni.*,
|
|
|
+ ROW_NUMBER() OVER (
|
|
|
PARTITION BY
|
|
|
CASE
|
|
|
WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
|
|
|
@@ -2054,11 +2053,6 @@ class tools {
|
|
|
else ''
|
|
|
end as first_notifiation_date,
|
|
|
|
|
|
- case when ni.notifiation_type ='Milestone_Update'
|
|
|
- then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
|
|
|
- else ''
|
|
|
- end as milestone_previous_json,
|
|
|
-
|
|
|
case when ni.notifiation_type ='Container_Status_Update'
|
|
|
then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
|
|
|
else ''
|
|
|
@@ -2068,27 +2062,100 @@ class tools {
|
|
|
then (select description
|
|
|
from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
|
|
|
else ''
|
|
|
- end as ctnr_desc,
|
|
|
-
|
|
|
- ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
|
|
|
+ end as ctnr_desc
|
|
|
from public.kln_notifiation_info ni
|
|
|
- inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
|
|
|
- from public.kln_ocean oo
|
|
|
- where oo.serial_no = ni.serial_no limit 1) ccc on true
|
|
|
left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
|
|
|
- left join LATERAL (select case when COALESCE(ni.frequency_type,'') = 'Daily'
|
|
|
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
|
|
|
- when COALESCE(ni.frequency_type,'') = 'Weekly'
|
|
|
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
- || ' - ' ||
|
|
|
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
- else ''
|
|
|
- end as insert_date_format) eee on true
|
|
|
+ left join LATERAL (select
|
|
|
+ case when COALESCE(ni.frequency_type,'') = 'Daily'
|
|
|
+ then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
|
|
|
+ when COALESCE(ni.frequency_type,'') = 'Weekly'
|
|
|
+ then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
+ || ' - ' ||
|
|
|
+ to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
+ else ''
|
|
|
+ end as insert_date_format
|
|
|
+ ) eee on true
|
|
|
where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
|
|
|
and ni.insert_date > NOW() - INTERVAL '3 months'
|
|
|
- and lower(ni.notifiation_type) in ($more_param)
|
|
|
- ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa
|
|
|
- WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
|
|
|
+ and lower(ni.notifiation_type) in ($more_param)
|
|
|
+ ".$sql_where." and ni.notifications_method = true
|
|
|
+ order by ni.insert_date desc),
|
|
|
+
|
|
|
+ bb as (select * from aa where rn = 1)
|
|
|
+ select *,
|
|
|
+ case when bb.notifiation_type ='Milestone_Update'
|
|
|
+ then public.getPreviousMilestone(bb.serial_no,bb.milestone_code,ccc.transport_mode,ccc.order_from)
|
|
|
+ else ''
|
|
|
+ end as milestone_previous_json,
|
|
|
+ ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
|
|
|
+ from bb
|
|
|
+ inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
|
|
|
+ from public.kln_ocean oo
|
|
|
+ where oo.serial_no = bb.serial_no limit 1) ccc on true " .$limit_param;
|
|
|
+
|
|
|
+ // $sql = "select *
|
|
|
+ // from (select ni.*,
|
|
|
+ // ROW_NUMBER() OVER (
|
|
|
+ // PARTITION BY
|
|
|
+ // CASE
|
|
|
+ // WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
|
|
|
+ // WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
|
|
|
+ // WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
|
|
|
+ // WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
|
|
|
+ // END
|
|
|
+ // ORDER BY insert_date DESC
|
|
|
+ // ) AS rn,
|
|
|
+ // case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
|
|
|
+ // then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
|
|
|
+ // when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
|
|
|
+ // then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
|
|
|
+ // else 0
|
|
|
+ // end as _delay_diff,
|
|
|
+ // eee.insert_date_format,
|
|
|
+ // case when COALESCE(ni.frequency_type,'') = 'Instant'
|
|
|
+ // then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
|
|
|
+ // when COALESCE(ni.frequency_type,'') = 'Daily'
|
|
|
+ // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
|
|
|
+ // when COALESCE(ni.frequency_type,'') = 'Weekly'
|
|
|
+ // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
|
|
|
+ // else ''
|
|
|
+ // end as first_notifiation_date,
|
|
|
+
|
|
|
+ // case when ni.notifiation_type ='Milestone_Update'
|
|
|
+ // then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
|
|
|
+ // else ''
|
|
|
+ // end as milestone_previous_json,
|
|
|
+
|
|
|
+ // case when ni.notifiation_type ='Container_Status_Update'
|
|
|
+ // then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
|
|
|
+ // else ''
|
|
|
+ // end as ctnr_previous_json,
|
|
|
+
|
|
|
+ // case when ni.notifiation_type ='Container_Status_Update'
|
|
|
+ // then (select description
|
|
|
+ // from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
|
|
|
+ // else ''
|
|
|
+ // end as ctnr_desc,
|
|
|
+
|
|
|
+ // ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
|
|
|
+ // from public.kln_notifiation_info ni
|
|
|
+ // inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
|
|
|
+ // from public.kln_ocean oo
|
|
|
+ // where oo.serial_no = ni.serial_no limit 1) ccc on true
|
|
|
+ // left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
|
|
|
+ // left join LATERAL (select case when COALESCE(ni.frequency_type,'') = 'Daily'
|
|
|
+ // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
|
|
|
+ // when COALESCE(ni.frequency_type,'') = 'Weekly'
|
|
|
+ // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
+ // || ' - ' ||
|
|
|
+ // to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
|
|
|
+ // else ''
|
|
|
+ // end as insert_date_format) eee on true
|
|
|
+ // where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
|
|
|
+ // and ni.insert_date > NOW() - INTERVAL '3 months'
|
|
|
+ // and lower(ni.notifiation_type) in ($more_param)
|
|
|
+ // ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa
|
|
|
+ // WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
|
|
|
error_log($sql);
|
|
|
|
|
|
$retData = common::excuteListSql($sql);
|