|
@@ -1098,7 +1098,22 @@ class utils {
|
|
|
|
|
|
|
|
public static function getDmoeSqlForAi($type){
|
|
public static function getDmoeSqlForAi($type){
|
|
|
$data= array();
|
|
$data= array();
|
|
|
- $data["Shipments arriving in the next 7 days."] = "select serial_no,h_bol,place_of_receipt_exp,place_of_delivery_exp,description,eta,order_from,cargo_type
|
|
|
|
|
|
|
+ $data["Shipments arriving in the next 7 days."] = "select count(*)
|
|
|
|
|
+ from (
|
|
|
|
|
+ SELECT oo.serial_no,h_bol, place_of_receipt_exp, place_of_delivery_exp,m.description,eta,order_from, o.cargo_type
|
|
|
|
|
+ FROM public.kln_ocean oo
|
|
|
|
|
+ inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
+ from public.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
+ left join LATERAL (select a.code,a.description
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ inner join public.customer_service_milestone_sno s
|
|
|
|
|
+ on a.code = s.code
|
|
|
|
|
+ and s.type = 'sea'
|
|
|
|
|
+ and a.serial_no = oo.serial_no
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ order by s.sno desc limit 1) m on true
|
|
|
|
|
+ WHERE <{ExtendHand_KLN}> and oo.transport_mode = 'sea' and order_from = 'public' and m.code <> '' limit 20
|
|
|
|
|
+ ) t;select serial_no,h_bol,place_of_receipt_exp,place_of_delivery_exp,description,eta,order_from,cargo_type
|
|
|
from (
|
|
from (
|
|
|
SELECT oo.serial_no,h_bol, place_of_receipt_exp, place_of_delivery_exp,m.description,eta,order_from, o.cargo_type
|
|
SELECT oo.serial_no,h_bol, place_of_receipt_exp, place_of_delivery_exp,m.description,eta,order_from, o.cargo_type
|
|
|
FROM public.kln_ocean oo
|
|
FROM public.kln_ocean oo
|
|
@@ -1115,187 +1130,338 @@ class utils {
|
|
|
WHERE <{ExtendHand_KLN}> and oo.transport_mode = 'sea' and order_from = 'public' and m.code <> '' limit 20
|
|
WHERE <{ExtendHand_KLN}> and oo.transport_mode = 'sea' and order_from = 'public' and m.code <> '' limit 20
|
|
|
) t order by eta";
|
|
) t order by eta";
|
|
|
|
|
|
|
|
- $data["List shipments with milestone updates in the last 7 days."] = "select serial_no,order_from,h_bol, description,update_date_format,update_date,timezone,locations
|
|
|
|
|
|
|
+ $data["List shipments with milestone updates in the last 7 days."] = "select count(*)
|
|
|
|
|
+ from (
|
|
|
|
|
+ select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date,public.getTimeAndLocationForKln(oo.serial_no,a.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ inner join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ inner join public.kln_ocean oo on oo.serial_no = a.serial_no
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ and a.update_date is not null
|
|
|
|
|
+ and a.update_date > '2025-04-06') po
|
|
|
|
|
+ )t;select serial_no,order_from,h_bol, description,update_date_format,update_date,timezone,locations
|
|
|
|
|
+ from (
|
|
|
|
|
+ select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date,public.getTimeAndLocationForKln(oo.serial_no,a.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ inner join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ inner join public.kln_ocean oo on oo.serial_no = a.serial_no
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ and a.update_date is not null
|
|
|
|
|
+ and a.update_date > '2025-04-06') po
|
|
|
|
|
+ )t;select aa.update_date_format, COUNT(*) AS total_count
|
|
|
|
|
+ from (
|
|
|
|
|
+ select DISTINCT ON (h_bol) h_bol, update_date_format
|
|
|
|
|
+ from (
|
|
|
|
|
+ select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date
|
|
|
|
|
+ from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ inner join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ inner join public.kln_ocean oo on oo.serial_no = a.serial_no
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ and a.update_date > '2025-04-06') po
|
|
|
|
|
+
|
|
|
|
|
+ )t order by h_bol
|
|
|
|
|
+ ) aa
|
|
|
|
|
+ group by aa.update_date_format order by aa.update_date_format ";
|
|
|
|
|
+ $data["What is the current status of my active shipments?"] ="SELECT count(*)
|
|
|
|
|
+ FROM public.kln_ocean oo
|
|
|
|
|
+ WHERE <{ExtendHand_KLN}> and ((oo.ata is not null and oo.ata >= CURRENT_DATE - INTERVAL '3 months' AND oo.ata < CURRENT_DATE)
|
|
|
|
|
+ or not exists( select 1 from public.ocean_milestone a where a.serial_no = oo.serial_no and a.act_date is not null and a.code = 'IFFDEL')) and oo.transport_mode = 'sea' and order_from = 'public';with oo as(
|
|
|
|
|
+ SELECT h_bol, place_of_receipt_exp, place_of_delivery_exp,serial_no,transport_mode,order_from
|
|
|
|
|
+ FROM public.kln_ocean oo
|
|
|
|
|
+ WHERE <{ExtendHand_KLN}> and ((oo.ata is not null and oo.ata >= CURRENT_DATE - INTERVAL '3 months' AND oo.ata < CURRENT_DATE)
|
|
|
|
|
+ or not exists( select 1 from public.ocean_milestone a where a.serial_no = oo.serial_no and a.act_date is not null and a.code = 'IFFDEL')) and oo.transport_mode = 'sea' and order_from = 'public' order by id limit 10
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from oo
|
|
|
|
|
+ inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
+ from public.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
+ left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ and s.type = 'sea'
|
|
|
|
|
+ and a.serial_no = oo.serial_no
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ order by s.sno desc limit 1) mil on true
|
|
|
|
|
+ left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
+ where oo.transport_mode = 'sea' and order_from = 'public'
|
|
|
|
|
+ union all
|
|
|
|
|
+ SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from oo
|
|
|
|
|
+ inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
+ from sfs.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
+ left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ and s.type = 'air'
|
|
|
|
|
+ and a.serial_no = oo.serial_no
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ order by s.sno desc limit 1) mil on true
|
|
|
|
|
+ left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
+ where oo.transport_mode = 'sea' and order_from = 'sfs'
|
|
|
|
|
+ union all
|
|
|
|
|
+ SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from oo
|
|
|
|
|
+ inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
+ from public.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
+ left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
+ from public.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ and s.type = 'air'
|
|
|
|
|
+ and a.serial_no = oo.serial_no
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ order by s.sno desc limit 1) mil on true
|
|
|
|
|
+ left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
+ where oo.transport_mode = 'air' and order_from = 'public'
|
|
|
|
|
+ union all
|
|
|
|
|
+ SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from oo
|
|
|
|
|
+ inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
+ from sfs.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
+ left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
+ from sfs.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ and s.type = 'air'
|
|
|
|
|
+ and a.serial_no = oo.serial_no
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ order by s.sno desc limit 1) mil on true
|
|
|
|
|
+ left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
+ where oo.transport_mode = 'air' and order_from = 'sfs'";
|
|
|
|
|
+
|
|
|
|
|
+ $data["List shipments with container status updates in the last 7 days."] = "select count(*)
|
|
|
|
|
+ FROM ra_online_container_status s
|
|
|
|
|
+ LEFT JOIN oc_container oc ON s.status_id = oc.status_id
|
|
|
|
|
+ LEFT JOIN ocean o ON o.serial_no::text = oc.serial_no::text
|
|
|
|
|
+ LEFT JOIN public.ra_online_edi_event e on s.event_base = e.ra_name
|
|
|
|
|
+ WHERE o.status::text <> 'Cancelled'::text
|
|
|
|
|
+ and is_display = true
|
|
|
|
|
+ and s.insert_date <= CURRENT_DATE AND s.insert_date >='2023-02-23'
|
|
|
|
|
+ and exists(select 1 from kln_ocean oo where <{ExtendHand_KLN}> and oo.serial_no = o.serial_no);select oo.serial_no,oo.order_from,s.event_base as event,s.container_no,
|
|
|
|
|
+ to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
|
|
|
|
|
+ to_char(to_timestamp(s.event_date, 'YYYYMMDD'),'Mon DD') as _eventdate,
|
|
|
|
|
+ to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
|
|
|
|
|
+ (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
|
|
|
|
|
+ e.description,
|
|
|
|
|
+ s.event_city as uncity
|
|
|
|
|
+ FROM ra_online_container_status s
|
|
|
|
|
+ LEFT JOIN oc_container oc ON s.status_id = oc.status_id
|
|
|
|
|
+ LEFT JOIN ocean o ON o.serial_no::text = oc.serial_no::text
|
|
|
|
|
+ LEFT JOIN public.ra_online_edi_event e on s.event_base = e.ra_name
|
|
|
|
|
+ LEFT JOIN public.kln_ocean oo ON oo.serial_no::text = o.serial_no::text
|
|
|
|
|
+ WHERE o.status::text <> 'Cancelled'::text
|
|
|
|
|
+ and is_display = true
|
|
|
|
|
+ and s.insert_date <= CURRENT_DATE AND s.insert_date >='2023-02-23'
|
|
|
|
|
+ and exists(select 1 from kln_ocean oo where <{ExtendHand_KLN}> and oo.serial_no = o.serial_no) limit 10;select aa._eventdate, COUNT(*) AS total_count
|
|
|
|
|
+ from (select DISTINCT ON (s.container_no) s.container_no,
|
|
|
|
|
+ to_char(to_timestamp(s.event_date, 'YYYYMMDD'),'Mon DD') as _eventdate
|
|
|
|
|
+ FROM ra_online_container_status s
|
|
|
|
|
+ LEFT JOIN oc_container oc ON s.status_id = oc.status_id
|
|
|
|
|
+ LEFT JOIN ocean o ON o.serial_no::text = oc.serial_no::text
|
|
|
|
|
+ LEFT JOIN public.ra_online_edi_event e on s.event_base = e.ra_name
|
|
|
|
|
+ WHERE o.status::text <> 'Cancelled'::text
|
|
|
|
|
+ and is_display = true
|
|
|
|
|
+ and s.insert_date <= CURRENT_DATE AND s.insert_date >='2023-02-23'
|
|
|
|
|
+ and exists(select 1 from kln_ocean oo where <{ExtendHand_KLN}> and oo.serial_no = o.serial_no)
|
|
|
|
|
+ order by s.container_no
|
|
|
|
|
+ )aa group by _eventdate order by _eventdate";
|
|
|
|
|
+
|
|
|
|
|
+ $data["Today's shipments summary."] = "select count(*)
|
|
|
|
|
+ from (
|
|
|
|
|
+ select oo.serial_no
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) po inner join public.kln_ocean oo on oo.serial_no = po.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
+ union all
|
|
|
|
|
+ select oo.serial_no
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ a.code,a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) pa inner join public.kln_ocean oo on oo.serial_no = pa.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
+ union all
|
|
|
|
|
+ select oo.serial_no
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from sfs.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) sa inner join public.kln_ocean oo on oo.serial_no = sa.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
+ )t;select *
|
|
|
from (
|
|
from (
|
|
|
- select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,
|
|
|
|
|
|
|
+ select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from (
|
|
|
|
|
+ select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
+ from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.update_date,a.code,a.serial_no,
|
|
|
|
|
+ to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
+ to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
+ a.act_time,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) po inner join public.kln_ocean oo on oo.serial_no = po.serial_no
|
|
|
|
|
+ union all
|
|
|
|
|
+ select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
+ COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
+ from (
|
|
|
|
|
+ select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
+ from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.update_date,a.code,a.serial_no,
|
|
|
|
|
+ to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
+ to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
+ a.act_time,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) pa inner join public.kln_ocean oo on oo.serial_no = pa.serial_no
|
|
|
|
|
+ union all
|
|
|
|
|
+ select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
- from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date,public.getTimeAndLocationForKln(oo.serial_no,a.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
- from public.ocean_milestone a
|
|
|
|
|
- inner join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
- where s.type = 'sea'
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- and a.update_date is not null
|
|
|
|
|
- and a.update_date > '2025-04-06') po
|
|
|
|
|
|
|
+ from (
|
|
|
|
|
+ select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
+ from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.update_date,a.code,a.serial_no,
|
|
|
|
|
+ to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
+ to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
+ a.act_time,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from sfs.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) sa inner join public.kln_ocean oo on oo.serial_no = sa.serial_no
|
|
|
|
|
+ )t limit 10;select sum(case when (action_type='Departure') then 1 else 0 end) as dep,
|
|
|
|
|
+ sum(case when (action_type='Arrived') then 1 else 0 end) as arr,
|
|
|
|
|
+ sum(case when (action_type='Delivered') then 1 else 0 end) as del
|
|
|
|
|
+ from (
|
|
|
|
|
+ select action_type
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.action_type,t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.ocean_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) po inner join public.kln_ocean oo on oo.serial_no = po.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
+ union all
|
|
|
|
|
+ select action_type
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.action_type,t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from public.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) pa inner join public.kln_ocean oo on oo.serial_no = pa.serial_no and (<{ExtendHand_KLN}>)
|
|
|
|
|
+ union all
|
|
|
|
|
+ select action_type
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.action_type,t.serial_no from (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
+ when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
+ when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
+ else s.description end as action_type,
|
|
|
|
|
+ a.serial_no,
|
|
|
|
|
+ ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
+ from sfs.air_milestone a
|
|
|
|
|
+ left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
+ where s.type = 'sea'
|
|
|
|
|
+ and a.act_date is not null
|
|
|
|
|
+ --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
+ )t WHERE rn = 1
|
|
|
|
|
+ ) sa inner join public.kln_ocean oo on oo.serial_no = sa.serial_no and (<{ExtendHand_KLN}>)
|
|
|
)t";
|
|
)t";
|
|
|
- $data["What is the current status of my active shipments?"] ="with oo as(
|
|
|
|
|
- SELECT h_bol, place_of_receipt_exp, place_of_delivery_exp,serial_no,transport_mode,order_from
|
|
|
|
|
- FROM public.kln_ocean oo
|
|
|
|
|
- WHERE <{ExtendHand_KLN}> and ((oo.ata is not null and oo.ata >= CURRENT_DATE - INTERVAL '3 months' AND oo.ata < CURRENT_DATE)
|
|
|
|
|
- or not exists( select 1 from public.ocean_milestone a where a.serial_no = oo.serial_no and a.act_date is not null and a.code = 'IFFDEL')) and oo.transport_mode = 'sea' and order_from = 'public' order by id limit 10
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from oo
|
|
|
|
|
- inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
- from public.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
- left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
- from public.ocean_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- and s.type = 'sea'
|
|
|
|
|
- and a.serial_no = oo.serial_no
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- order by s.sno desc limit 1) mil on true
|
|
|
|
|
- left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
- where oo.transport_mode = 'sea' and order_from = 'public'
|
|
|
|
|
- union all
|
|
|
|
|
- SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from oo
|
|
|
|
|
- inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
- from sfs.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
- left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
- from public.ocean_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- and s.type = 'air'
|
|
|
|
|
- and a.serial_no = oo.serial_no
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- order by s.sno desc limit 1) mil on true
|
|
|
|
|
- left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
- where oo.transport_mode = 'sea' and order_from = 'sfs'
|
|
|
|
|
- union all
|
|
|
|
|
- SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from oo
|
|
|
|
|
- inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
- from public.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
- left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
- from public.air_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- and s.type = 'air'
|
|
|
|
|
- and a.serial_no = oo.serial_no
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- order by s.sno desc limit 1) mil on true
|
|
|
|
|
- left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
- where oo.transport_mode = 'air' and order_from = 'public'
|
|
|
|
|
- union all
|
|
|
|
|
- SELECT oo.*,mil.description,mil.act_date,mil.act_time,o.cargo_type,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from oo
|
|
|
|
|
- inner join LATERAL (select case when is_hazardous = 't' then 'Dangerous Goods'::text else 'General'::text end as cargo_type
|
|
|
|
|
- from sfs.ocean o where o.serial_no = oo.serial_no) o on true
|
|
|
|
|
- left join LATERAL (select a.code,s.description,to_char(a.act_date, 'YYYY-MM-DD') as act_date ,a.act_time
|
|
|
|
|
- from sfs.air_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- and s.type = 'air'
|
|
|
|
|
- and a.serial_no = oo.serial_no
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- order by s.sno desc limit 1) mil on true
|
|
|
|
|
- left join LATERAL (select public.getTimeAndLocationForKln(oo.serial_no,mil.code,''::text)::jsonb as jsonb_data) lt on true
|
|
|
|
|
- where oo.transport_mode = 'air' and order_from = 'sfs'";
|
|
|
|
|
-
|
|
|
|
|
- $data["List shipments with container status updates in the last 7 days."] = "select oo.serial_no,oo.order_from,s.event_base as event,s.container_no,
|
|
|
|
|
- to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
|
|
|
|
|
- to_char(to_timestamp(s.event_date, 'YYYYMMDD'),'Mon DD') as _eventdate,
|
|
|
|
|
- to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
|
|
|
|
|
- (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
|
|
|
|
|
- e.description,
|
|
|
|
|
- s.event_city as uncity
|
|
|
|
|
- FROM ra_online_container_status s
|
|
|
|
|
- LEFT JOIN oc_container oc ON s.status_id = oc.status_id
|
|
|
|
|
- LEFT JOIN ocean o ON o.serial_no::text = oc.serial_no::text
|
|
|
|
|
- LEFT JOIN public.ra_online_edi_event e on s.event_base = e.ra_name
|
|
|
|
|
- LEFT JOIN public.kln_ocean oo ON oo.serial_no::text = o.serial_no::text
|
|
|
|
|
- WHERE o.status::text <> 'Cancelled'::text
|
|
|
|
|
- and is_display = true
|
|
|
|
|
- --and s.insert_date BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL '7 days')
|
|
|
|
|
- and exists(select 1 from kln_ocean oo where <{ExtendHand_KLN}> and oo.serial_no = o.serial_no) limit 10";
|
|
|
|
|
-
|
|
|
|
|
- $data["Today's shipments summary."] = "select *
|
|
|
|
|
-from (
|
|
|
|
|
-select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from (
|
|
|
|
|
- select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
- from (
|
|
|
|
|
- SELECT
|
|
|
|
|
- case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
- when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
- when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
- else s.description end as action_type,
|
|
|
|
|
- a.update_date,a.code,a.serial_no,
|
|
|
|
|
- to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
- to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
- a.act_time,
|
|
|
|
|
- ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
- from public.ocean_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- where s.type = 'sea'
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
- )t WHERE rn = 1
|
|
|
|
|
- ) po inner join public.kln_ocean oo on oo.serial_no = po.serial_no
|
|
|
|
|
-union all
|
|
|
|
|
-select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from (
|
|
|
|
|
- select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
- from (
|
|
|
|
|
- SELECT
|
|
|
|
|
- case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
- when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
- when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
- else s.description end as action_type,
|
|
|
|
|
- a.update_date,a.code,a.serial_no,
|
|
|
|
|
- to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
- to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
- a.act_time,
|
|
|
|
|
- ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
- from public.air_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- where s.type = 'sea'
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
- )t WHERE rn = 1
|
|
|
|
|
- ) pa inner join public.kln_ocean oo on oo.serial_no = pa.serial_no
|
|
|
|
|
-union all
|
|
|
|
|
-select *,oo.serial_no,oo.order_from,oo.h_bol,oo.transport_mode,oo.place_of_receipt_exp, oo.place_of_delivery_exp,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
|
|
|
|
|
- COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations
|
|
|
|
|
- from (
|
|
|
|
|
- select *,public.getTimeAndLocationForKln(t.serial_no,t.code,''::text)::jsonb as jsonb_data
|
|
|
|
|
- from (
|
|
|
|
|
- SELECT
|
|
|
|
|
- case when a.code = 'IFFDEP' then 'Departure'
|
|
|
|
|
- when a.code = 'IFFARR' then 'Arrived'
|
|
|
|
|
- when a.code = 'IFFDEL' then 'Delivered'
|
|
|
|
|
- else s.description end as action_type,
|
|
|
|
|
- a.update_date,a.code,a.serial_no,
|
|
|
|
|
- to_char(a.update_date, 'Mon_DD_YYYY') as _update_date,
|
|
|
|
|
- to_char(a.act_date, 'YYYY-MM-DD') as act_date ,
|
|
|
|
|
- a.act_time,
|
|
|
|
|
- ROW_NUMBER() OVER(PARTITION BY a.serial_no ORDER BY s.sno DESC) AS rn
|
|
|
|
|
- from sfs.air_milestone a
|
|
|
|
|
- left join public.customer_service_milestone_sno s on a.code = s.code
|
|
|
|
|
- where s.type = 'sea'
|
|
|
|
|
- and a.act_date is not null
|
|
|
|
|
- --and a.update_date >= CURRENT_DATE AND a.update_date < CURRENT_DATE + INTERVAL '1 day'
|
|
|
|
|
- )t WHERE rn = 1
|
|
|
|
|
- ) sa inner join public.kln_ocean oo on oo.serial_no = sa.serial_no
|
|
|
|
|
-)t limit 10";
|
|
|
|
|
-
|
|
|
|
|
-$data["Sort my active shipments by earliest arrival date."] = "select to_char(oo.eta,'DD-Mon') as eta, oo.h_bol,oo.transport_mode, oo.place_of_receipt_exp, oo.place_of_delivery_exp,oo.serial_no,oo.order_from,
|
|
|
|
|
- case when oo.eta - CURRENT_DATE <= 0 then '< 1 days'::text
|
|
|
|
|
- else (oo.eta - CURRENT_DATE)||' days'::text end as day_to_arr
|
|
|
|
|
-from public.kln_ocean oo where 1=1 order by eta limit 10";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $data["Sort my active shipments by earliest arrival date."] = "select to_char(oo.eta,'DD-Mon') as eta, oo.h_bol,oo.transport_mode, oo.place_of_receipt_exp, oo.place_of_delivery_exp,oo.serial_no,oo.order_from,
|
|
|
|
|
+ case when oo.eta - CURRENT_DATE <= 0 then '< 1 days'::text
|
|
|
|
|
+ else (oo.eta - CURRENT_DATE)||' days'::text end as day_to_arr
|
|
|
|
|
+ from public.kln_ocean oo where 1=1 order by eta limit 10";
|
|
|
|
|
|
|
|
return $data[$type];
|
|
return $data[$type];
|
|
|
}
|
|
}
|