The following lines contain the word 'select', 'insert', 'update' or 'delete':
select nvl(mp.total_orders,0)
from mst_plans mp
where mp.plan_id = l_plan_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in
(select mdl.delivery_id
from mst_trips t
, mst_trip_stops ts
, mst_delivery_legs mdl
, fte_location_parameters flp
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
and ts.stop_id = mdl.pick_up_stop_id
and ts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and ts.plan_id = t.plan_id
and ts.trip_id = t.trip_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2;
select count(distinct dd.source_header_number)
from (
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in
(select mdl.delivery_id
from mst_delivery_legs mdl
, mst_trip_stops mts
where mdl.plan_id = md.plan_id
and mdl.plan_id = mts.plan_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id))
union all
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and not exists (select 1 from mst_delivery_legs mdl
where mdl.plan_id=md.plan_id
and mdl.delivery_id = md.delivery_id)) dd;
select count(distinct nvl(mdd.split_from_delivery_detail_id, mdd.delivery_detail_id))
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
where mdd.plan_id = l_plan_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from mst_deliveries md
where md.plan_id = l_plan_id;
select count(*)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select count(*)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select count(*)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(mp.total_weight,0)
from mst_plans mp
where mp.plan_id = l_plan_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(mp.total_volume,0)
from mst_plans mp
where mp.plan_id = l_plan_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(mp.total_pieces,0)
from mst_plans mp
where mp.plan_id = l_plan_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select sum(nvl(mdd.unit_price,0)* nvl(mdd.requested_quantity,0))
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
where mdd.plan_id = l_plan_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id;
select sum(nvl(mdd.unit_price,0)* nvl(mdd.requested_quantity,0))
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, fte_location_parameters flp
where mdd.plan_id = l_plan_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select sum(nvl(mdd.unit_price,0)* nvl(mdd.requested_quantity,0))
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
where mdd.plan_id = l_plan_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select sum(nvl(mdd.unit_price,0)* nvl(mdd.requested_quantity,0))
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
where mdd.plan_id = l_plan_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode;
select count(*)
from mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and flp.location_id in (select mts.stop_location_id
from mst_trip_stops mts
where mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id)
and flp.facility_id = l_myfac_id;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = l_mode
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode;
select decode(l_mode,'TRUCK',nvl(mp.total_tl_cost,0)
,'LTL' ,nvl(mp.total_ltl_cost,0)
,nvl(mp.total_parcel_cost,0))
from mst_plans mp
where mp.plan_id = l_plan_id;
select nvl(sum(nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
( select nvl(sum(nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id));
( select nvl(sum(nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode;
select nvl(sum(nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_plans mp
, mst_delivery_legs mdl
where mp.plan_id = mdl.plan_id
and mdl.trip_id in (select mt.trip_id
from mst_trips mt
where mt.plan_id = mp.plan_id
and mt.mode_of_transport = l_mode)
and mdl.plan_id = l_plan_id;
select nvl(sum(nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
( select nvl(sum(nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id));
(select nvl(sum(nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_handling_cost,0))
, (nvl(mt.total_handling_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode;
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_plans mp
, mst_delivery_legs mdl
where mp.plan_id = mdl.plan_id
and mdl.trip_id in (select mt.trip_id
from mst_trips mt
where mt.plan_id = mp.plan_id
and mt.mode_of_transport = l_mode)
and mdl.plan_id = l_plan_id;
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
( select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0)
+ nvl(mt.total_handling_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode;
select count(*)
from mst_trip_stops mts
, mst_trips mt
where mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = l_plan_id;
select count(*)
from mst_trip_stops mts
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.mode_of_transport = 'TRUCK'
and flp.location_id = mts.stop_location_id
and flp.facility_id = l_myfac_id
and mts.plan_id = l_plan_id;
select count(*)
from mst_trip_stops mts
where mts.plan_id = l_plan_id
and mts.trip_id in ( select distinct mt.trip_id
from mst_trips mt
, mst_trip_stops mts1
, fte_location_parameters flp
where mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.mode_of_transport = 'TRUCK'
and mts1.plan_id = mt.plan_id
and mts1.trip_id = mt.trip_id
and flp.facility_id = l_myfac_id
and flp.location_id = mts1.stop_location_id );
select count ( * )
from mst_trips mt
, mst_trip_stops mts
where mts.plan_id = l_plan_id
and mts.trip_id = mt.trip_id
and mt.plan_id= mts.plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in ( select mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, fte_location_parameters flp
where md.plan_id = l_plan_id
and flp.facility_id = l_myfac_id
and ( md.dropoff_location_id = flp.location_id
or md.pickup_location_id = flp.location_id )
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id );
select count(*)
from mst_trip_stops mts
, mst_trips mt
where mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_delivery_legs mdl
, mst_deliveries md
where mdl.plan_id = mt.plan_id
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select count(*)
from mst_trip_stops mts
, mst_trips mt
where mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.mode_of_transport = 'TRUCK'
and mt.carrier_id = l_carrier_id
and mts.plan_id = l_plan_id;
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK';
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in (select distinct mts.trip_id
from mst_trip_stops mts
, fte_location_parameters flp
where mts.plan_id = mt.plan_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id);
select count ( * )
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in ( select mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, fte_location_parameters flp
where md.plan_id = l_plan_id
and flp.facility_id = l_myfac_id
and ( md.dropoff_location_id = flp.location_id
or md.pickup_location_id = flp.location_id )
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id );
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in (select distinct mdl.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select count ( * )
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in ( select mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
where md.plan_id = l_plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and decode ( l_c_s_ident, 2, md.customer_id, md.supplier_id ) = l_cust_supp_id );
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.carrier_id = l_carrier_id;
select nvl(sum(mt.total_trip_distance),0)
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK';
select nvl(sum(mt.total_trip_distance),0)
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in (select distinct mts.trip_id
from mst_trip_stops mts
, fte_location_parameters flp
where mts.plan_id = mt.plan_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id);
select nvl(sum(nvl(mt.total_trip_distance,0)),0)
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in ( select mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, fte_location_parameters flp
where md.plan_id = l_plan_id
and flp.facility_id = l_myfac_id
and ( md.dropoff_location_id = flp.location_id
or md.pickup_location_id = flp.location_id )
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id );
select nvl(sum(mt.total_trip_distance),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in (select distinct mdl.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select nvl(sum(nvl(mt.total_trip_distance,0)),0)
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.trip_id in ( select mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
where md.plan_id = l_plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and decode ( l_c_s_ident, 2, md.customer_id, md.supplier_id ) = l_cust_supp_id );
select nvl(sum(mt.total_trip_distance),0)
from mst_trips mt
where mt.plan_id= l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mt.carrier_id = l_carrier_id;
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id;
select count(*)
from mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id;
select count ( distinct mt.trip_id )
from mst_deliveries md
, fte_location_parameters flp
, mst_delivery_legs mdl
, mst_trips mt
where md.plan_id = l_plan_id
and flp.facility_id = l_myfac_id
and ( md.dropoff_location_id = flp.location_id
or md.pickup_location_id = flp.location_id )
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select count ( distinct mt.trip_id )
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where md.plan_id = l_plan_id
and decode ( l_c_s_ident, 2, md.customer_id, md.supplier_id ) = l_cust_supp_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id;
select nvl(sum(nvl(mdl.allocated_transport_cost,0)),0)
from mst_plans mp
, mst_delivery_legs mdl
where mp.plan_id = mdl.plan_id
and mdl.trip_id in (select mt.trip_id
from mst_trips mt
where mt.plan_id = mp.plan_id
and mt.carrier_id = l_carrier_id)
and mdl.plan_id = l_plan_id;
select nvl(sum(nvl(mdl.allocated_transport_cost,0)),0)
from mst_trips mt
, mst_trip_stops mts
, mst_delivery_legs mdl
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.carrier_id = l_carrier_id
and mts.plan_id = mdl.plan_id
-- and mdl.pick_up_stop_id = mts.stop_id
-- Bug_Fix for 3694008
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id;
select sum ( nvl ( mdl.allocated_transport_cost, 0 ) )
from mst_deliveries md
, fte_location_parameters flp
, mst_delivery_legs mdl
, mst_trips mt
where md.plan_id = l_plan_id
and flp.facility_id = l_myfac_id
and ( md.dropoff_location_id = flp.location_id
or md.pickup_location_id = flp.location_id )
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id;
select nvl(sum(nvl(mdl.allocated_transport_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id;
select sum ( nvl ( mdl.allocated_transport_cost, 0 ) )
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where md.plan_id = l_plan_id
and decode ( l_c_s_ident, 2, md.customer_id, md.supplier_id ) = l_cust_supp_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and flp.location_id = md.pickup_location_id
and flp.facility_id = l_myfac_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id;
select count(distinct mdd.source_header_number)
from mst_delivery_assignments mda
, mst_delivery_details mdd
where mdd.plan_id = l_plan_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state);
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in
(select mdl.delivery_id
from mst_trips t
, mst_trip_stops ts
, mst_delivery_legs mdl
, wsh_locations wl
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
and ts.stop_id = mdl.pick_up_stop_id
and wl.wsh_location_id = md.pickup_location_id
and ts.stop_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and ts.plan_id = t.plan_id
and ts.trip_id = t.trip_id
and t.carrier_id = l_carrier_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and flp.location_id = md.pickup_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state);
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and flp.location_id = md.pickup_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and flp.location_id = md.pickup_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.pick_up_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id)
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.pick_up_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id)
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.pick_up_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.pick_up_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.pick_up_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.pickup_location_id
and wl.state = l_orig_state);
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and md.pickup_location_id = mts.stop_location_id);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and wl.state = l_orig_state
and md.pickup_location_id = wl.wsh_location_id );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and md.pickup_location_id = flp.location_id
and flp.location_id = wl.wsh_location_id
and wl.state = l_orig_state);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and mts.stop_location_id = wl.wsh_location_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
-- and mt.plan_id = mts.plan_id
-- and mt.trip_id = mts.trip_id
and flp.facility_id = l_myfac_id
and md.pickup_location_id = flp.location_id );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state);
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_trips mt
, mst_trip_stops mts
, mst_delivery_legs mdl1
, mst_deliveries md
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_orig_state
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.pickup_location_id = mts.stop_location_id);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and mts.stop_location_id = wl.wsh_location_id
and md.pickup_location_id = wl.wsh_location_id
and wl.state = l_orig_state
-- and mt.plan_id = mts.plan_id
-- and mt.trip_id = mts.trip_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0)
+ nvl(mt.total_handling_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
-- and mt.continuous_move_id is null --check
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mt.plan_id
and mts.plan_id = md.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mts.stop_id = mdl.pick_up_stop_id
and mts.stop_location_id = md.pickup_location_id
and wl.wsh_location_id = mts.stop_location_id
and wl.state = l_orig_state);
select nvl ( sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)
+ nvl(mdl.allocated_transport_cost,0)), 0 )
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, wsh_locations wl
, mst_trip_stops mts
where md.plan_id = l_plan_id
and md.plan_id = mt.plan_id
and md.plan_id = mdl.plan_id
and md.plan_id = mts.plan_id
and md.delivery_id = mdl.delivery_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
and mts.trip_id = mt.trip_id
and mts.stop_location_id = wl.wsh_location_id
and mdl.pick_up_stop_id = mts.stop_id
and wl.state = l_orig_state;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and flp.location_id = md.dropoff_location_id
and flp.facility_id = l_myfac_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id;
select count(distinct mdd.source_header_number)
from mst_delivery_assignments mda
, mst_delivery_details mdd
where mdd.plan_id = l_plan_id
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state);
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_delivery_assignments mda
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and mdd.plan_id = mda.plan_id
and mdd.delivery_detail_id = mda.delivery_detail_id
and mda.parent_delivery_detail_id is null
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in
(select mdl.delivery_id
from mst_trips t
, mst_trip_stops ts
, mst_delivery_legs mdl
, wsh_locations wl
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
and ts.stop_id = mdl.drop_off_stop_id
and wl.wsh_location_id = md.dropoff_location_id
and ts.stop_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and ts.plan_id = t.plan_id
and ts.trip_id = t.trip_id
and t.carrier_id = l_carrier_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and flp.location_id = md.dropoff_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state);
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and flp.location_id = md.dropoff_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and flp.location_id = md.dropoff_location_id
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and md.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, wsh_locations wl
where md.plan_id = l_plan_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.drop_off_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id)
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.drop_off_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id)
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops = 2;
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.drop_off_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'LTL'
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.trip_id in
(select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where mdl.plan_id = mt.plan_id
and mdl.drop_off_stop_id = mts1.stop_id
and mdl.trip_id = mts1.trip_id
and mts1.plan_id = mt.plan_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select count(*)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = 'PARCEL'
and mt.carrier_id = l_carrier_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, wsh_locations wl
where md.plan_id = mt.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
and mts1.stop_id = mdl.drop_off_stop_id
and mts1.stop_location_id = wl.wsh_location_id
and mts1.stop_location_id = md.dropoff_location_id
and wl.state = l_destination_state);
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and md.dropoff_location_id = mts.stop_location_id);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and wl.state = l_destination_state
and md.dropoff_location_id = wl.wsh_location_id );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and md.dropoff_location_id = flp.location_id
and flp.location_id = wl.wsh_location_id
and wl.state = l_destination_state);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.dropoff_location_id = wsh_location_id
-- and mt.plan_id = mts.plan_id
-- and mt.trip_id = mts.trip_id
and flp.facility_id = l_myfac_id
and md.dropoff_location_id = flp.location_id );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.delivery_id in (select mdl.delivery_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
, wsh_locations wl
where mdl.plan_id = l_plan_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id )
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and md.dropoff_location_id = wl.wsh_location_id
and wl.state = l_destination_state);
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_trips mt
, mst_trip_stops mts
, mst_delivery_legs mdl1
, mst_deliveries md
, wsh_locations wl
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.dropoff_location_id = mts.stop_location_id);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
-- , mst_trip_stops mts
, wsh_locations wl
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
-- and mts.stop_location_id = wl.wsh_location_id
and wl.state = l_destination_state
and md.dropoff_location_id = wl.wsh_location_id
-- and mt.plan_id = mts.plan_id
-- and mt.trip_id = mts.trip_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0)
+ nvl(mt.total_handling_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
-- and mt.continuous_move_id is null --check
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
, wsh_locations wl
where md.plan_id = mt.plan_id
and mts.plan_id = md.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mts.stop_id = mdl.drop_off_stop_id
and mts.stop_location_id = md.dropoff_location_id
and wl.wsh_location_id = mts.stop_location_id
and wl.state = l_destination_state);
select nvl ( sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)
+ nvl(mdl.allocated_transport_cost,0)), 0 )
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, wsh_locations wl
, mst_trip_stops mts
where md.plan_id = l_plan_id
and md.plan_id = mt.plan_id
and md.plan_id = mdl.plan_id
and md.plan_id = mts.plan_id
and md.delivery_id = mdl.delivery_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
and mts.trip_id = mt.trip_id
and mts.stop_location_id = wl.wsh_location_id
and mdl.drop_off_stop_id = mts.stop_id
and wl.state = l_destination_state;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in
(select mdl.delivery_id
from -- mst_trips t -- Removing the join with mst_trips
mst_trip_stops ts
, mst_delivery_legs mdl
, fte_location_parameters flp
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
-- and ts.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3693945
and ( ts.stop_id = mdl.pick_up_stop_id
or ts.stop_id = mdl.drop_off_stop_id )
and ts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id ) -- ending the subquery here, with the join with mst_trips removed
-- and ts.plan_id = t.plan_id
-- and ts.trip_id = t.trip_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2;
select count(distinct dd.source_header_number)
from (
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in
(select mdl.delivery_id
from mst_delivery_legs mdl
, mst_trip_stops mts
, fte_location_parameters flp
where mdl.plan_id = md.plan_id
and mdl.plan_id = mts.plan_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id)
and flp.location_id = mts.stop_location_id
and flp.facility_id = l_myfac_id)
union all
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and not exists (select 1 from mst_delivery_legs mdl
where mdl.plan_id=md.plan_id
and mdl.delivery_id = md.delivery_id)) dd;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and md.delivery_id in
(select mdl.delivery_id
from mst_trips t
, mst_trip_stops ts
, mst_delivery_legs mdl
, fte_location_parameters flp
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
-- and ts.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3693945
and ( ts.stop_id = mdl.pick_up_stop_id
or ts.stop_id = mdl.drop_off_stop_id )
and ts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and ts.plan_id = t.plan_id
and ts.trip_id = t.trip_id
and t.carrier_id = l_carrier_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and flp.location_id in (select mts.stop_location_id
from mst_trip_stops mts
where mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id)
and flp.facility_id = l_myfac_id;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
, fte_location_parameters flp
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and flp.location_id = mts.stop_location_id
and flp.facility_id = l_myfac_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = l_mode
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select count(*)
from mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.carrier_id = l_carrier_id
and flp.location_id in (select mts.stop_location_id
from mst_trip_stops mts
where mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0)
+ nvl(mt.total_handling_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
-- and mt.continuous_move_id is null --check
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
, fte_location_parameters flp
where md.plan_id = mt.plan_id
and mts.plan_id = md.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id);
select sum(nvl(mdl.allocated_fac_loading_cost,0) +
nvl(mdl.allocated_transport_cost,0) +
nvl(mdl.allocated_fac_shp_hand_cost,0) )
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1,
mst_deliveries md,
mst_trips mt,
mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.carrier_id = l_carrier_id
and mts.stop_location_id = l_location_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and ( md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id
and mts.stop_location_id = l_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and ( md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id ) );
select sum(nvl(mdl.allocated_fac_loading_cost,0) +
nvl(mdl.allocated_transport_cost,0) +
nvl(mdl.allocated_fac_shp_hand_cost,0) )
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1,
mst_deliveries md,
mst_trips mt,
mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.carrier_id = l_carrier_id
and mts.stop_location_id = l_location_id
and (mts.stop_id = mdl.pick_up_stop_id
or mts.stop_id = mdl.drop_off_stop_id)
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and md.pickup_location_id <> mts.stop_location_id
and md.dropoff_location_id <> mts.stop_location_id);
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id
and mts.stop_location_id = l_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and ( mts.stop_id = mdl.pick_up_stop_id
or mts.stop_id = mdl.drop_off_stop_id )
and md.pickup_location_id <> mts.stop_location_id
and md.dropoff_location_id <> mts.stop_location_id );
select flp.location_id
into l_loc_id
from fte_location_parameters flp
where flp.facility_id = p_myfac_id;
select count(distinct mdd.source_header_number)
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in
(select mdl.delivery_id
from -- mst_trips t -- removing this join
mst_trip_stops ts
, mst_delivery_legs mdl
, fte_location_parameters flp
where mdl.plan_id = md.plan_id
and ts.plan_id = mdl.plan_id
-- and ts.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3694008
and ( ts.stop_id = mdl.pick_up_stop_id
or ts.stop_id = mdl.drop_off_stop_id )
and ts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id ) -- end of subquery, as the join with t has been removed
-- and ts.plan_id = t.plan_id
-- and ts.trip_id = t.trip_id)
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and mdd.container_flag = 2
and mdd.split_from_delivery_detail_id is null;
select count(distinct dd.source_header_number)
from (
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and md.delivery_id in
(select mdl.delivery_id
from mst_delivery_legs mdl
, mst_trip_stops mts
where mdl.plan_id = md.plan_id
and mdl.plan_id = mts.plan_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id))
union all
select mdd.source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and not exists (select 1 from mst_delivery_legs mdl
where mdl.plan_id=md.plan_id
and mdl.delivery_id = md.delivery_id)) dd;
select count(distinct dd.source_header_number)
from (
select mdd.source_header_number source_header_number
from mst_delivery_details mdd
, mst_deliveries md
, mst_delivery_assignments mda
where md.plan_id = mda.plan_id
and md.delivery_id = mda.delivery_id
and mda.plan_id = mdd.plan_id
and mda.delivery_detail_id = mdd.delivery_detail_id
and md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in
(select mdl.delivery_id
from mst_delivery_legs mdl
, mst_trip_stops mts
, mst_trips mt
where mdl.plan_id = md.plan_id
and mdl.plan_id = mts.plan_id
and ( mdl.pick_up_stop_id = mts.stop_id
or mdl.drop_off_stop_id = mts.stop_id)
and mdl.trip_id = mts.trip_id
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mt.carrier_id = l_carrier_id)) dd;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.gross_weight,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.volume,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
, fte_location_parameters flp
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id)
and flp.facility_id = l_myfac_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id;
select nvl(sum(nvl(md.number_of_pieces,0)),0)
from mst_deliveries md
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id in (select distinct mdl.delivery_id
from mst_delivery_legs mdl
, mst_trips mt
where mdl.plan_id = md.plan_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id);
select count(*)
from mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and flp.location_id in (select distinct mts.stop_location_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
and mdl.plan_id = mts.plan_id
and mdl.trip_id = mts.trip_id
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id)
and flp.facility_id = l_myfac_id;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = l_mode
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
-- and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = l_mode
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) >= 2
group by ts.trip_id);
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
, fte_location_parameters flp
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and mts.stop_location_id = flp.location_id
and flp.facility_id = l_myfac_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
, fte_location_parameters flp
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and flp.facility_id = l_myfac_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and ( md.pickup_location_id = flp.location_id
or md.dropoff_location_id = flp.location_id ) );
select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_delivery_legs mdl
where mdl.plan_id = l_plan_id
and mdl.delivery_id in
( select md.delivery_id
from mst_delivery_legs mdl1
, mst_deliveries md
, mst_trips mt
, mst_trip_stops mts
where mt.plan_id = mdl1.plan_id
and mt.trip_id = mdl1.trip_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mts.plan_id
and mt.trip_id = mts.trip_id
and md.plan_id = mdl1.plan_id
and md.delivery_id = mdl1.delivery_id
and md.plan_id = mdl.plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and (md.pickup_location_id = mts.stop_location_id
or md.dropoff_location_id = mts.stop_location_id));
(select nvl(sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_transport_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)),0)
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trips mt
where mt.plan_id = l_plan_id
and mt.mode_of_transport = l_mode
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id );
/* select nvl(sum(decode(mt.mode_of_transport
, 'TRUCK', (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_stop_cost,0)
+ nvl(mt.total_load_unload_cost,0)
+ nvl(mt.total_layover_cost,0)
+ nvl(mt.total_accessorial_cost,0)
+ nvl(mt.total_handling_cost,0))
, (nvl(mt.total_basic_transport_cost,0)
+ nvl(mt.total_accessorial_cost,0)))),0)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode
-- and mt.continuous_move_id is null --check
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and mts.plan_id = md.plan_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
-- and (md.pickup_location_id = mts.stop_location_id
-- or md.dropoff_location_id = mts.stop_location_id)
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id);
select sum(nvl(mdl.allocated_fac_loading_cost,0)
+ nvl(mdl.allocated_fac_unloading_cost,0)
+ nvl(mdl.allocated_fac_shp_hand_cost,0)
+ nvl(mdl.allocated_fac_rec_hand_cost,0)
+ nvl(mdl.allocated_transport_cost,0))
from mst_deliveries md,
mst_delivery_legs mdl,
mst_trips mt
where md.plan_id = l_plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and md.delivery_id = mdl.delivery_id
and mt.plan_id = mdl.plan_id
and mt.trip_id = mdl.trip_id
and mt.carrier_id = l_carrier_id
and mt.mode_of_transport = l_mode;
SELECT count(mt.trip_id) num_stops
FROM mst_trips mt
WHERE mt.plan_id = l_plan_id
AND mt.trip_id IN ( SELECT mdl.trip_id
FROM mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
WHERE mdl.plan_id = mt.plan_id
AND md.plan_id = mdl.plan_id
AND md.delivery_id = mdl.delivery_id
AND decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
AND mts1.plan_id = mdl.plan_id
AND mts1.trip_id = mdl.trip_id
-- and mts1.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3694008
AND ( mts1.stop_id = mdl.pick_up_stop_id
OR mts1.stop_id = mdl.drop_off_stop_id )
AND flp.location_id = mts1.stop_location_id
AND flp.facility_id = l_myfac_id )
AND mt.mode_of_transport = 'TRUCK'
AND EXISTS
( SELECT ts.trip_id
FROM mst_trip_stops ts
WHERE ts.plan_id = mt.plan_id
AND ts.trip_id = mt.trip_id
HAVING COUNT(ts.stop_id) = 2
GROUP BY ts.trip_id );
SELECT COUNT(*)
FROM (SELECT DISTINCT mt.trip_id, count(*) num_stops
FROM mst_trips mt
, mst_trip_stops mts
WHERE mt.plan_id = l_plan_id
AND mt.trip_id in (SELECT DISTINCT mdl.trip_id
FROM mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
WHERE mdl.plan_id = mt.plan_id
AND md.plan_id = mdl.plan_id
AND md.delivery_id = mdl.delivery_id
AND decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
AND mts1.plan_id = mdl.plan_id
AND mts1.trip_id = mdl.trip_id
-- and mts1.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3694008
AND ( mts1.stop_id = mdl.pick_up_stop_id
OR mts1.stop_id = mdl.drop_off_stop_id )
AND flp.location_id = mts1.stop_location_id
AND flp.facility_id = l_myfac_id)
AND mt.mode_of_transport = 'TRUCK'
AND mts.plan_id = mt.plan_id
AND mts.trip_id = mt.trip_id
GROUP BY mt.trip_id) temp
WHERE temp.num_stops = 2;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = 'TRUCK'
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) = 2
group by ts.trip_id);
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
-- and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = 'TRUCK'
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) = 2
group by ts.trip_id);
SELECT count(mt.trip_id) num_stops
FROM mst_trips mt
WHERE mt.plan_id = l_plan_id
AND mt.trip_id IN ( SELECT mdl.trip_id
FROM mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
WHERE mdl.plan_id = mt.plan_id
AND md.plan_id = mdl.plan_id
AND md.delivery_id = mdl.delivery_id
AND decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
AND mts1.plan_id = mdl.plan_id
AND mts1.trip_id = mdl.trip_id
-- and mts1.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3694008
AND ( mts1.stop_id = mdl.pick_up_stop_id
OR mts1.stop_id = mdl.drop_off_stop_id )
AND flp.location_id = mts1.stop_location_id
AND flp.facility_id = l_myfac_id )
AND mt.mode_of_transport = 'TRUCK'
AND EXISTS
( SELECT ts.trip_id
FROM mst_trip_stops ts
WHERE ts.plan_id = mt.plan_id
AND ts.trip_id = mt.trip_id
HAVING COUNT(ts.stop_id) > 2
GROUP BY ts.trip_id );
select count(*)
from (select distinct mt.trip_id, count(*) num_stops
from mst_trips mt
, mst_trip_stops mts
where mt.plan_id = l_plan_id
and mt.trip_id in (select distinct mdl.trip_id
from mst_deliveries md
, mst_delivery_legs mdl
, mst_trip_stops mts1
, fte_location_parameters flp
where mdl.plan_id = mt.plan_id
and md.plan_id = mdl.plan_id
and md.delivery_id = mdl.delivery_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts1.plan_id = mdl.plan_id
and mts1.trip_id = mdl.trip_id
-- and mts1.stop_id = mdl.pick_up_stop_id
-- Bug_Fix for 3694008
and ( mts1.stop_id = mdl.pick_up_stop_id
or mts1.stop_id = mdl.drop_off_stop_id )
and flp.location_id = mts1.stop_location_id
and flp.facility_id = l_myfac_id)
and mt.mode_of_transport = 'TRUCK'
and mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id
group by mt.trip_id) temp
where temp.num_stops > 2;
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode ( l_report_for, 2, md.customer_id, 4, md.supplier_id, 0 ) = decode ( l_report_for, 2, l_report_for_id, 4, l_report_for_id, 0 )
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = 'TRUCK'
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) > 2
group by ts.trip_id);
select count(mt.trip_id)
from mst_trips mt
where mt.plan_id = l_plan_id
and mt.carrier_id = l_carrier_id
and mt.trip_id in
(select distinct mts.trip_id
from mst_trip_stops mts
, mst_delivery_legs mdl
, mst_deliveries md
where md.plan_id = mt.plan_id
and decode(l_c_s_ident, 2, md.customer_id, md.supplier_id) = l_cust_supp_id
and mts.plan_id = md.plan_id
-- and mts.stop_location_id = md.dropoff_location_id
and mdl.plan_id = md.plan_id
and mdl.delivery_id = md.delivery_id
and mdl.trip_id = mts.trip_id
and mdl.drop_off_stop_id = mts.stop_id)
and mt.mode_of_transport = 'TRUCK'
and EXISTS
(select ts.trip_id
from mst_trip_stops ts
where ts.plan_id = mt.plan_id
and ts.trip_id = mt.trip_id
having count(ts.stop_id) > 2
group by ts.trip_id);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, compile_designator
, report_date
, plan_start_date
, plan_end_date
, orders
, order_groups
, weight
, volume
, pieces
, pallets
, allocated_cost ---not used anymore
, plan_value
, total_tl_count
, ltl_count
, parcel_count
, tl_cost
, ltl_cost
, parcel_cost
, transportation_cost
, handling_cost
, total_cost
, tl_stops
, tl_distance
, percent_alloc_cost ---not used anymore
, percent_value
)
(SELECT 1
, mp.plan_id
, mp.compile_designator
, sysdate
, mp.start_date
, mp.cutoff_date
, mst_reports_pkg.get_plan_order_count(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_order_group_count(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_weight(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_volume(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_pieces(p_plan_id, p_report_for, p_report_for_id)
, 0
, 0
, mst_reports_pkg.get_plan_value(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_trips_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
, mst_reports_pkg.get_trips_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
, mst_reports_pkg.get_trips_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
, mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
, mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
, mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
, mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
+mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
+mst_reports_pkg.get_trans_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
, mst_reports_pkg.get_handl_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
+mst_reports_pkg.get_handl_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
+mst_reports_pkg.get_handl_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
, mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
+mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
+mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
, mst_reports_pkg.get_stops_per_load(p_plan_id, p_report_for, p_report_for_id)
, mst_reports_pkg.get_TL_distance(p_plan_id, p_report_for, p_report_for_id)
, 0
, ( ( mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'TRUCK')
+mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'LTL')
+mst_reports_pkg.get_total_cost_per_mode(p_plan_id, p_report_for, p_report_for_id,'PARCEL')
) / decode( mst_reports_pkg.get_plan_value(p_plan_id, p_report_for, p_report_for_id)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id, p_report_for, p_report_for_id)) ) * 100
from mst_plans mp
where mp.plan_id = p_plan_id
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, facility_name
, orders
, weight
, volume
, pieces
, tl_cost
, ltl_cost
, parcel_cost
, total_cost
, cost_per_unit_weight
, cost_per_unit_volume
, percent_value
, percent_alloc_cost
)
(SELECT 2
, temp.plan_id
, fte.facility_code
, mst_reports_pkg.get_orders_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
, mst_reports_pkg.get_weight_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
, mst_reports_pkg.get_volume_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
, mst_reports_pkg.get_pieces_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
, mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'TRUCK',fte.facility_id)
, mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'LTL',fte.facility_id)
, mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'PARCEL',fte.facility_id)
, mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'TRUCK',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'LTL',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'PARCEL',fte.facility_id)
,( mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'TRUCK',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'LTL',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'PARCEL',fte.facility_id)
) / decode( mst_reports_pkg.get_weight_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
,0 ,1
, mst_reports_pkg.get_weight_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id))
,( mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'TRUCK',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'LTL',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'PARCEL',fte.facility_id)
) / decode( mst_reports_pkg.get_volume_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id)
,0 ,1
, mst_reports_pkg.get_volume_myfac(p_plan_id,p_report_for,p_report_for_id,fte.facility_id))
, ( ( mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'TRUCK',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'LTL',fte.facility_id)
+mst_reports_pkg.get_cost_per_mode_myfac(p_plan_id,p_report_for,p_report_for_id,'PARCEL',fte.facility_id)
) / decode( nvl(mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id),0)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id)) ) * 100
, 0
from (select distinct mts.plan_id plan_id, mts.stop_location_id loc_id
from mst_trip_stops mts
, mst_trips mt
where mts.plan_id = mt.plan_id
and mts.trip_id = mt.trip_id) temp,
mst_plans mp,
wsh_location_owners wlo,
wsh_locations wl,
fte_location_parameters fte
where mp.plan_id = temp.plan_id
and temp.loc_id = fte.location_id
and fte.location_id = wl.wsh_location_id
and wl.wsh_location_id = wlo.wsh_location_id
and wlo.owner_type = 1
and mp.plan_id = p_plan_id
and decode ( p_report_for, 1, fte.facility_id, p_report_for_id ) = p_report_for_id
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, carrier_name
, carr_moves
, total_cost
, mode_of_transport
)
(SELECT 3
, mt.plan_id
, wc.freight_code
, mst_reports_pkg.get_carr_movements(p_plan_id,p_report_for,p_report_for_id,mt.carrier_id)
, mst_reports_pkg.get_carr_cost(p_plan_id,p_report_for,p_report_for_id,mt.carrier_id)
, mt.mode_of_transport
from mst_trips mt
, wsh_carriers wc
WHERE mt.carrier_id = wc.carrier_id
and mt.plan_id = p_plan_id
and decode ( p_report_for, 3, mt.carrier_id, p_report_for_id ) = p_report_for_id
group by mt.plan_id
, mt.carrier_id
, wc.freight_code
,mt.mode_of_transport
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, origin_name
, orders
, weight
, volume
, pieces
, mtl_count
, dtl_count
, ltl_count
, parcel_count
, tl_cost
, ltl_cost
, parcel_cost
, total_cost
, cost_per_unit_weight
, cost_per_unit_volume
, percent_value
, percent_alloc_cost
)
(SELECT distinct 4
, mp.plan_id
, wl.state
, mst_reports_pkg.get_orders_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_weight_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_volume_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_pieces_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_MTL_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_DTL_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_LTL_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_PCL_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
, mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
, mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
, mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
, ( mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( mst_reports_pkg.get_weight_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
,0 ,1
,mst_reports_pkg.get_weight_orig(p_plan_id,p_report_for,p_report_for_id,wl.state))
, ( mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( mst_reports_pkg.get_volume_orig(p_plan_id,p_report_for,p_report_for_id,wl.state)
,0 ,1
,mst_reports_pkg.get_volume_orig(p_plan_id,p_report_for,p_report_for_id,wl.state))
,( mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_orig(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( nvl(mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id),0)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id) ) * 100
, 0
from mst_plans mp
,wsh_locations wl
WHERE mp.plan_id = p_plan_id
and wl.wsh_location_id in (select distinct md.pickup_location_id
from mst_deliveries md
where md.plan_id = mp.plan_id)
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, destination_name
, orders
, weight
, volume
, pieces
, mtl_count
, dtl_count
, ltl_count
, parcel_count
, tl_cost
, ltl_cost
, parcel_cost
, total_cost
, cost_per_unit_weight
, cost_per_unit_volume
, percent_value
, percent_alloc_cost
)
(SELECT distinct 5
, mp.plan_id
, wl.state
, mst_reports_pkg.get_orders_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_weight_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_volume_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_pieces_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_MTL_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_DTL_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_LTL_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_PCL_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
, mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
, mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
, mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
, mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
, ( mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( mst_reports_pkg.get_weight_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
,0 ,1
,mst_reports_pkg.get_weight_dest(p_plan_id,p_report_for,p_report_for_id,wl.state))
, ( mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( mst_reports_pkg.get_volume_dest(p_plan_id,p_report_for,p_report_for_id,wl.state)
,0 ,1
,mst_reports_pkg.get_volume_dest(p_plan_id,p_report_for,p_report_for_id,wl.state))
,( mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'TRUCK',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'LTL',wl.state)
+mst_reports_pkg.get_total_cost_mode_dest(p_plan_id,p_report_for,p_report_for_id,'PARCEL',wl.state)
) / decode( nvl(mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id),0)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id) ) * 100
, 0
from mst_plans mp
,wsh_locations wl
WHERE mp.plan_id = p_plan_id
and wl.wsh_location_id in (select distinct md.dropoff_location_id
from mst_deliveries md
where md.plan_id = mp.plan_id)
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, customer_name
, orders
, weight
, volume
, pieces
, mtl_count
, dtl_count
, ltl_count
, parcel_count
, tl_cost
, ltl_cost
, parcel_cost
, total_cost
, cost_per_unit_weight
, cost_per_unit_volume
, percent_value
, percent_alloc_cost
)
(SELECT 6
, mp.plan_id
, hzp.party_name
, mst_reports_pkg.get_orders_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_pieces_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_MTL_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_DTL_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_trips_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_trips_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
, ( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
) / decode( mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
,0 ,1
,mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id))
, ( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
) / decode( mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id)
,0 ,1
,mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,hzc.cust_account_id))
, (( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,hzc.cust_account_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,hzc.cust_account_id)
) / decode( nvl(mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id),0)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id)) ) * 100
,0
from mst_plans mp
, hz_parties hzp
, hz_cust_accounts hzc
WHERE mp.plan_id = p_plan_id
and hzp.party_id = hzc.party_id
and hzc.cust_account_id in (select distinct md.customer_id
from mst_deliveries md
where md.plan_id = mp.plan_id)
and decode ( p_report_for, 2, hzc.cust_account_id, p_report_for_id ) = p_report_for_id
);
insert into mst_mast_sum_report_temp_gt
( view_id
, plan_id
, supplier_name
, orders
, weight
, volume
, pieces
, mtl_count
, dtl_count
, ltl_count
, parcel_count
, tl_cost
, ltl_cost
, parcel_cost
, total_cost
, cost_per_unit_weight
, cost_per_unit_volume
, percent_value
, percent_alloc_cost
)
(SELECT 7
, mp.plan_id
, hz.party_name
, mst_reports_pkg.get_orders_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_pieces_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_MTL_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_DTL_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_trips_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_trips_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
, mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
, ( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
) / decode( mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
,0 ,1
,mst_reports_pkg.get_weight_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id))
, ( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
) / decode( mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id)
,0 ,1
,mst_reports_pkg.get_volume_c_s(p_plan_id,p_report_for,p_report_for_id,l_c_s_ident,pov.vendor_id))
, (( mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'TRUCK',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'LTL',l_c_s_ident,pov.vendor_id)
+mst_reports_pkg.get_cost_per_mode_c_s(p_plan_id,p_report_for,p_report_for_id,'PARCEL',l_c_s_ident,pov.vendor_id)
) / decode( nvl(mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id),0)
, 0, 1
, mst_reports_pkg.get_plan_value(p_plan_id,p_report_for,p_report_for_id)) ) * 100
,0
from mst_plans mp
, po_vendors pov
, hz_relationships hzr
, hz_parties hz
WHERE mp.plan_id = p_plan_id
and pov.vendor_id = hzr.subject_id
and hzr.object_id = hz.party_id
and hzr.relationship_type = 'POS_VENDOR_PARTY'
and pov.vendor_id in (select mdd.supplier_id
from mst_delivery_details mdd
where mdd.plan_id = mp.plan_id)
and decode ( p_report_for, 4, pov.vendor_id , p_report_for_id ) = p_report_for_id
);
select distinct mc.segment2
from mtl_category_sets mcs
, mtl_categories mc
, mst_delivery_details mdd
where mcs.structure_id = mc.structure_id
and UPPER(mcs.category_set_name) = 'WSH_COMMODITY_CODE' --'FREIGHT CLASS'
and mc.category_id = mdd.commodity_code_cat_id --mdd.freight_class_cat_id
and mdd.plan_id = l_plan_id
and mdd.source_header_number = l_source_header_number;
SELECT mts2.planned_arrival_date planned_arrival_date,
mts1.planned_departure_date planned_departure_date,
mts1.drv_time_to_next_stop drv_time_to_next_stop,
mts1.total_layover_duration total_layover_duration
FROM mst_trip_stops mts1
,mst_trip_stops mts2
WHERE mts1.plan_id = l_plan_id
AND mts1.trip_id = l_trip_id
AND mts1.stop_id = l_stop_id
AND mts2.plan_id = mts1.plan_id
AND mts2.trip_id = mts1.trip_id
AND mts2.stop_sequence_number = ( SELECT MIN( mts3.stop_sequence_number )
FROM mst_trip_stops mts3
WHERE mts3.plan_id = mts1.plan_id
AND mts3.trip_id = mts1.trip_id
AND mts3.stop_sequence_number > mts1.stop_sequence_number );