Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAIN B-21416 intl crating tio update for payment request-FE #14765

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@
20250103180420_update_pricing_proc_to_use_local_price_variable.up.sql
20250110001339_update_nts_release_enum_name.up.sql
20250110153428_add_shipment_address_updates_to_move_history.up.sql
20250110201339_add_payment_params_for_intl_crating_uncrating.up.sql
20250110214012_homesafeconnect_cert.up.sql
20250113152050_rename_ubp.up.sql
20250113160816_updating_create_accessorial_service_item_proc.up.sql
Expand All @@ -1082,3 +1083,4 @@
20250116200912_disable_homesafe_stg_cert.up.sql
20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql
20250121153007_update_pricing_proc_to_handle_international_shuttle.up.sql
20250204162411_updating_create_accessorial_service_item_proc_for_crating.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- adding ExternalCrate param key for intl crating
INSERT INTO service_item_param_keys
(id,key,description,type,origin,created_at,updated_at)
VALUES
('7bb4a8eb-7fff-4e02-8809-f2def00af455','ExternalCrate', 'True if this an external crate', 'BOOLEAN', 'PRIME', now(), now());


-- ICRT
INSERT INTO service_params
(id,service_id,service_item_param_key_id,created_at,updated_at,is_optional)
VALUES
('2ee4d131-041f-498e-b921-cc77970341e9', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='ContractCode'), now(), now(), 'false'),
('bd36234a-090e-4c06-a478-8194c3a78f82', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='ContractYearName'), now(), now(), 'false'),
('bdcda078-6007-48d3-9c1a-16a1ae54dc69', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='EscalationCompounded'), now(), now(), 'false'),
('c6f982f5-d603-43e7-94ed-15ae6e703f86', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='PriceRateOrFactor'), now(), now(), 'false'),
('b323a481-3591-4609-84a5-5a1e8a56a51a', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='StandaloneCrate'), now(), now(), 'true'),
('7fb5a389-bfd7-44d5-a8ff-ef784d37a6a1', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='StandaloneCrateCap'), now(), now(), 'true'),
('3ca76951-c612-491f-ac9a-ad73c1129c99', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys WHERE key='UncappedRequestTotal'), now(), now(), 'true'),
('d486a522-3fa3-45b2-9749-827c40b002b0', (SELECT id FROM re_services WHERE code='ICRT'), (SELECT id FROM service_item_param_keys where key='ExternalCrate'), now(), now(), 'true');

-- IUCRT
INSERT INTO service_params
(id,service_id,service_item_param_key_id,created_at,updated_at)
VALUES
('b4619dc8-d1ba-4f85-a198-e985ae80e614', (SELECT id FROM re_services WHERE code='IUCRT'), (SELECT id FROM service_item_param_keys WHERE key='ContractCode'), now(), now()),
('d5d7fc34-2b48-4f99-b053-9d118171f202', (SELECT id FROM re_services WHERE code='IUCRT'), (SELECT id FROM service_item_param_keys WHERE key='ContractYearName'), now(), now()),
('2272b490-ffd0-4b24-8ae1-38019dc5c67d', (SELECT id FROM re_services WHERE code='IUCRT'), (SELECT id FROM service_item_param_keys WHERE key='EscalationCompounded'), now(), now()),
('5fd0739b-695a-4d96-9c5a-f048dfaa8f0c', (SELECT id FROM re_services WHERE code='IUCRT'), (SELECT id FROM service_item_param_keys WHERE key='PriceRateOrFactor'), now(), now());
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
DO '
BEGIN
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = ''mto_service_item_type'') THEN
IF NOT EXISTS (
SELECT 1 FROM pg_attribute
WHERE attrelid = ''mto_service_item_type''::regtype
AND attname = ''external_crate''
) THEN
ALTER TYPE mto_service_item_type ADD ATTRIBUTE "external_crate" bool;
END IF;
END IF;
END
';

-- added external_crate
CREATE OR REPLACE PROCEDURE create_accessorial_service_items_for_shipment (
IN shipment_id UUID,
IN service_items mto_service_item_type[],
INOUT created_service_item_ids text[]
) AS '
DECLARE
s_type mto_shipment_type;
m_code market_code_enum;
move_id UUID;
service_item RECORD;
item mto_service_item_type;
new_service_id text;
BEGIN
-- get the shipment type, market code, and move_id based on shipment_id
SELECT ms.shipment_type, ms.market_code, ms.move_id
INTO s_type, m_code, move_id
FROM mto_shipments ms
WHERE ms.id = shipment_id;

IF s_type IS NULL OR m_code IS NULL THEN
RAISE EXCEPTION ''Shipment with ID % not found or missing required details.'', shipment_id;
END IF;

-- loop through each provided service item object
FOREACH item IN ARRAY service_items
LOOP
FOR service_item IN
SELECT rsi.id,
rs.id AS re_service_id,
rs.service_location,
rsi.is_auto_approved,
rs.code AS service_code
FROM re_service_items rsi
JOIN re_services rs ON rsi.service_id = rs.id
WHERE rsi.shipment_type = s_type
AND rsi.market_code = m_code
AND rs.code = (item.re_service_code)
AND rsi.is_auto_approved = false
LOOP
BEGIN
-- International crating/uncrating will not have the SI update functionality.
-- Prime should to be able to create multiple crating SI for now.
IF service_item.service_code IN (''ICRT'', ''IUCRT'') OR (NOT does_service_item_exist(service_item.re_service_id, shipment_id)) THEN

INSERT INTO mto_service_items (
mto_shipment_id,
move_id,
re_service_id,
service_location,
status,
created_at,
updated_at,
sit_postal_code,
sit_entry_date,
sit_customer_contacted,
reason,
estimated_weight,
actual_weight,
pickup_postal_code,
description,
sit_destination_original_address_id,
sit_destination_final_address_id,
sit_requested_delivery,
sit_departure_date,
sit_origin_hhg_original_address_id,
sit_origin_hhg_actual_address_id,
customer_expense,
customer_expense_reason,
sit_delivery_miles,
standalone_crate,
external_crate
)
VALUES (
shipment_id,
move_id,
service_item.re_service_id,
service_item.service_location,
''SUBMITTED''::service_item_status,
NOW(),
NOW(),
(item).sit_postal_code,
(item).sit_entry_date,
(item).sit_customer_contacted,
(item).reason,
(item).estimated_weight,
(item).actual_weight,
(item).pickup_postal_code,
(item).description,
(item).sit_destination_original_address_id,
(item).sit_destination_final_address_id,
(item).sit_requested_delivery,
(item).sit_departure_date,
(item).sit_origin_hhg_original_address_id,
(item).sit_origin_hhg_actual_address_id,
(item).customer_expense,
(item).customer_expense_reason,
(item).sit_delivery_miles,
(item).standalone_crate,
(item).external_crate
) RETURNING id INTO new_service_id;

created_service_item_ids := array_append(created_service_item_ids, new_service_id);

END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE EXCEPTION ''Error creating accessorial service item with code % for shipment %: %'',
service_item.service_code, shipment_id, SQLERRM;
END;
END LOOP;
END LOOP;

UPDATE moves SET status = ''APPROVALS REQUESTED'' WHERE id = move_id;
END;
'
LANGUAGE plpgsql;
Loading
Loading