diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 5c8361c8d4f..4d38e37d315 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1059,6 +1059,7 @@ 20241216190428_update_get_zip_code_function_and_update_pricing_proc.up.sql 20241217163231_update_duty_locations_bad_zips.up.sql 20241217180136_add_AK_zips_to_zip3_distances.up.sql +20241217191012_update_move_to_gbloc_for_ak.up.sql 20241218201833_add_PPPO_BASE_ELIZABETH.up.sql 20241218204620_add_international_nts_service_items.up.sql 20241220171035_add_additional_AK_zips_to_zip3_distances.up.sql @@ -1071,6 +1072,8 @@ 20241230190638_remove_AK_zips_from_zip3.up.sql 20241230190647_add_missing_AK_zips_to_zip3_distances.up.sql 20241231155337_add_payment_params_for_international_shuttle.up.sql +20250103130619_revert_data_change_for_gbloc_for_ak.up.sql +20250103142533_update_postal_codes_and_gblocs_for_ak.up.sql 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 diff --git a/migrations/app/schema/20241217191012_update_move_to_gbloc_for_ak.up.sql b/migrations/app/schema/20241217191012_update_move_to_gbloc_for_ak.up.sql new file mode 100644 index 00000000000..282ad1b0b16 --- /dev/null +++ b/migrations/app/schema/20241217191012_update_move_to_gbloc_for_ak.up.sql @@ -0,0 +1,43 @@ +delete from postal_code_to_gblocs where postal_code in ( +select uspr_zip_id from v_locations where state = 'AK'); + +drop view move_to_gbloc; +CREATE OR REPLACE VIEW move_to_gbloc AS +SELECT move_id, gbloc FROM ( + SELECT DISTINCT ON (sh.move_id) sh.move_id, s.affiliation, + COALESCE(pctg.gbloc, coalesce(pctg_oconus_bos.gbloc, coalesce(pctg_oconus.gbloc, pctg_ppm.gbloc))) AS gbloc + FROM mto_shipments sh + JOIN moves m ON sh.move_id = m.id + JOIN orders o on m.orders_id = o.id + JOIN service_members s on o.service_member_id = s.id + LEFT JOIN ( SELECT a.id AS address_id, + pctg_1.gbloc, pctg_1.postal_code + FROM addresses a + JOIN postal_code_to_gblocs pctg_1 ON a.postal_code::text = pctg_1.postal_code::text) pctg ON pctg.address_id = sh.pickup_address_id + LEFT JOIN ( SELECT ppm.shipment_id, + pctg_1.gbloc + FROM ppm_shipments ppm + JOIN addresses ppm_address ON ppm.pickup_postal_address_id = ppm_address.id + JOIN postal_code_to_gblocs pctg_1 ON ppm_address.postal_code::text = pctg_1.postal_code::text) pctg_ppm ON pctg_ppm.shipment_id = sh.id + LEFT JOIN ( SELECT a.id AS address_id, + cast(jr.code as varchar) AS gbloc, ga.department_indicator + FROM addresses a + JOIN re_oconus_rate_areas ora ON a.us_post_region_cities_id = ora.us_post_region_cities_id + JOIN gbloc_aors ga ON ora.id = ga.oconus_rate_area_id + JOIN jppso_regions jr ON ga.jppso_regions_id = jr.id + ) pctg_oconus_bos ON pctg_oconus_bos.address_id = sh.pickup_address_id + and case when s.affiliation = 'AIR_FORCE' THEN 'AIR_AND_SPACE_FORCE' + when s.affiliation = 'SPACE_FORCE' THEN 'AIR_AND_SPACE_FORCE' + when s.affiliation = 'NAVY' THEN 'NAVY_AND_MARINES' + when s.affiliation = 'MARINES' THEN 'NAVY_AND_MARINES' + else s.affiliation + end = pctg_oconus_bos.department_indicator + LEFT JOIN ( SELECT a.id AS address_id, + cast(pctg_1.code as varchar) AS gbloc, ga.department_indicator + FROM addresses a + JOIN re_oconus_rate_areas ora ON a.us_post_region_cities_id = ora.us_post_region_cities_id + JOIN gbloc_aors ga ON ora.id = ga.oconus_rate_area_id + JOIN jppso_regions pctg_1 ON ga.jppso_regions_id = pctg_1.id + ) pctg_oconus ON pctg_oconus.address_id = sh.pickup_address_id and pctg_oconus.department_indicator is null + WHERE sh.deleted_at IS NULL + ORDER BY sh.move_id, sh.created_at) as m; \ No newline at end of file diff --git a/migrations/app/schema/20250103130619_revert_data_change_for_gbloc_for_ak.up.sql b/migrations/app/schema/20250103130619_revert_data_change_for_gbloc_for_ak.up.sql new file mode 100644 index 00000000000..2ee43e98f43 --- /dev/null +++ b/migrations/app/schema/20250103130619_revert_data_change_for_gbloc_for_ak.up.sql @@ -0,0 +1,840 @@ +drop view move_to_gbloc; +CREATE OR REPLACE VIEW move_to_gbloc AS +SELECT DISTINCT ON (sh.move_id) sh.move_id AS move_id, COALESCE(pctg.gbloc, pctg_ppm.gbloc) AS gbloc +FROM mto_shipments sh + -- try the pickup_address path + LEFT JOIN + ( + SELECT a.id address_id, pctg.gbloc + FROM addresses a + JOIN postal_code_to_gblocs pctg ON a.postal_code = pctg.postal_code + ) pctg ON pctg.address_id = sh.pickup_address_id + -- try the ppm_shipments path + LEFT JOIN + ( + SELECT ppm.shipment_id, pctg.gbloc + FROM ppm_shipments ppm + JOIN addresses ppm_address ON ppm.pickup_postal_address_id = ppm_address.id + JOIN postal_code_to_gblocs pctg ON ppm_address.postal_code = pctg.postal_code + ) pctg_ppm ON pctg_ppm.shipment_id = sh.id +WHERE sh.deleted_at IS NULL +ORDER BY sh.move_id, sh.created_at; + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99501', 'MBFL', now(), now(), 'd8697416-e345-46a8-9767-47b7abbb3c06'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99502', 'MBFL', now(), now(), '0e060122-7cea-4bcd-b636-31c453088a5d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99503', 'MBFL', now(), now(), '1bc710db-3f4f-4177-9656-a99956a8b06e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99504', 'MBFL', now(), now(), 'e35c4fd3-b8d7-46f4-a559-ddfc8e0ad4e9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99505', 'MBFL', now(), now(), 'f2e40ed3-bc7b-428c-9693-3bc1cc1a9c57'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99506', 'MBFL', now(), now(), 'cf3890e6-16df-46a7-aabb-57010b999ee7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99507', 'MBFL', now(), now(), 'c869c7aa-e0fd-4933-a4e9-09bd6191b25a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99508', 'MBFL', now(), now(), 'ca8554c3-d21c-4e26-a77f-6e965c7d31c5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99509', 'MBFL', now(), now(), '54ea9592-d93d-4102-84ce-7a9c57b6aff8'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99510', 'MBFL', now(), now(), 'f8d0e922-ab5d-4871-bd0c-1f7484b13981'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99511', 'MBFL', now(), now(), '7098c10e-edbf-4cf6-82dd-c09dd7a8f226'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99513', 'MBFL', now(), now(), '8f2d3b79-718e-4d96-b5d2-6b0c40487332'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99514', 'MBFL', now(), now(), '8ff6d888-935c-488c-9b62-33b8f4053b4a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99515', 'MBFL', now(), now(), 'e3927bca-6677-49d7-a622-ee20f386c28c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99516', 'MBFL', now(), now(), 'fc5ee3c2-d0b6-4e56-9bcd-e802e14dca7e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99517', 'MBFL', now(), now(), '84c51c78-972a-4714-8218-8169ee541159'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99518', 'MBFL', now(), now(), '7b3e4eed-3584-4036-9da5-9bc6a7163e4e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99519', 'MBFL', now(), now(), '62b97b86-e8e7-410a-a267-d101ce5f9a3c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99520', 'MBFL', now(), now(), 'bce10502-90fb-4f28-8489-f5e6d2ac00ab'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99521', 'MBFL', now(), now(), 'b8c51570-d048-41f8-a1fc-58e6b41d367a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99522', 'MBFL', now(), now(), '6311d142-f02b-4f49-b719-608d78c91489'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99523', 'MBFL', now(), now(), '967028d9-3a7b-4949-b1a4-e94a1aa25a73'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99524', 'MBFL', now(), now(), 'afd3cc8b-2c02-4e63-8fd1-eb81a1a19b5d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99529', 'MBFL', now(), now(), 'f08e218c-e55e-43fc-bbdf-bc57aaa65726'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99530', 'MBFL', now(), now(), '65eeaf36-e786-43dd-a18c-fb470a4468f9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99540', 'MBFL', now(), now(), '2380496a-9087-48bc-a0e2-9cd5ac19f470'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99545', 'MBFL', now(), now(), '6df5025e-e730-427a-8c10-ff6d131d0567'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99546', 'MBFL', now(), now(), '02163620-1da6-4509-b8bb-d8b3336e5c2a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99547', 'MBFL', now(), now(), 'f869b729-88cd-4770-a435-2dfd4b50c330'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99548', 'MBFL', now(), now(), 'db80b48b-25bd-4ef1-8d5a-33d740af6b0e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99549', 'MBFL', now(), now(), '09983e53-ae83-41b1-b459-e0ab411ea87e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99550', 'MAPS', now(), now(), '643db073-5e92-43c0-9b42-a8d9cc800623'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99551', 'MBFL', now(), now(), '9bc29931-880b-42df-a758-017d5abee32d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99552', 'MBFL', now(), now(), 'f6fa0bb7-fd5c-494e-b62c-b7bc509b632f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99553', 'MBFL', now(), now(), 'abcb2cbf-389d-4830-ae16-037c55b7bc2c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99554', 'MBFL', now(), now(), '2d4d9111-f59b-4506-935d-b6601275311a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99555', 'MBFL', now(), now(), '00c2d5ed-2364-490d-86b9-40cbad4679fb'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99556', 'MBFL', now(), now(), 'b5c75c77-59cf-4089-815b-c0d15d9440f0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99557', 'MBFL', now(), now(), '999e2c9e-04ed-47da-aca1-2b320ed52666'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99558', 'MBFL', now(), now(), 'cdc2383c-9ead-4501-a6cc-b736ea72ecef'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99559', 'MBFL', now(), now(), '2ca0657c-c121-41e4-a741-b563dee6838e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99561', 'MBFL', now(), now(), '0c8df634-b6e6-457f-93d7-7d64909bc7cb'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99563', 'MBFL', now(), now(), 'e9a0ebee-3ae3-4d66-b18b-cc3ea417887d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99564', 'MBFL', now(), now(), '77dd08d9-0997-4d16-babd-1ffccc4222d4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99565', 'MBFL', now(), now(), '59b6a797-b2e8-4bd7-affc-a5639308a9b3'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99566', 'MBFL', now(), now(), 'cf5b630e-964a-4389-9fa2-e1ed0e6a3041'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99567', 'MBFL', now(), now(), 'f71a916b-e55f-4230-869e-038c319037ce'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99568', 'MBFL', now(), now(), '9719d0c5-1bd0-42fe-89ab-f4dbddcfa588'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99569', 'MBFL', now(), now(), 'fba4bdcf-7707-4826-bf2a-3e7aaf81f309'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99571', 'MBFL', now(), now(), '75e598ff-6d6c-4a80-80bc-de36bc37a3be'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99572', 'MBFL', now(), now(), 'f7b9b7d5-6730-4e8f-9364-e5b1eb1d2c2b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99573', 'MBFL', now(), now(), '74dcb198-d7c8-4dbc-81ab-33a16559e100'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99574', 'MAPK', now(), now(), '9b9d03a0-e069-48cd-ae65-a66dbd8a3214'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99575', 'MBFL', now(), now(), 'f6ffb9e8-8976-4288-88cd-d10420d1894e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99576', 'MBFL', now(), now(), '0883cf7f-c2f9-4865-91c3-34df59486f01'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99577', 'MBFL', now(), now(), 'a5e58cce-5375-498b-bfdb-d2e4b50ee2b7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99578', 'MBFL', now(), now(), '63113a71-6f32-4531-991b-015d51be0ef7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99579', 'MBFL', now(), now(), 'be2f7dfb-a020-45b5-afa6-0e3b6fd669bf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99580', 'MBFL', now(), now(), '29b1f268-8ad5-400c-8aa6-0b4b851f8588'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99581', 'MBFL', now(), now(), '5e1dee94-93f9-4b7d-8445-7de967031bfa'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99583', 'MBFL', now(), now(), '2ab06e55-ae2b-4c19-b679-81ee89d098a5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99585', 'MBFL', now(), now(), 'd177b210-8362-4073-9862-43333203abfc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99586', 'MBFL', now(), now(), 'c8bdc299-d65d-4b4b-a0ad-0ef6c8ca905d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99587', 'MBFL', now(), now(), '9543c328-16d2-484b-9e62-1965a63f1d2e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99588', 'MBFL', now(), now(), '08d82a7f-8417-407d-b352-9e0f3ef9e9cd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99589', 'MBFL', now(), now(), 'e09e4805-d0a9-4347-8f63-7e221c4b6d7e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99590', 'MBFL', now(), now(), '3022675c-9e50-403e-987c-7e79762274c2'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99591', 'MBFL', now(), now(), '57eebbd9-4b15-4b6f-923a-1d1db65d72bc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99599', 'MBFL', now(), now(), '78a46448-b22a-4da0-a42a-07af993848bc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99602', 'MBFL', now(), now(), '101c94fc-11cf-4317-a63b-c3c903d1f9b3'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99603', 'MBFL', now(), now(), '67ebaf88-8131-4215-b6a4-3b3ecb3862f0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99604', 'MBFL', now(), now(), '45e5dfdd-9dbc-439a-96ac-292b820aa292'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99605', 'MBFL', now(), now(), 'd403b760-8ad8-409b-b8d4-e0ad9dfd3947'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99606', 'MBFL', now(), now(), 'ac7a083e-3300-4881-874b-6bbd206a4e92'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99607', 'MBFL', now(), now(), 'f8d072a2-099d-4767-9b1d-b5dd48a79a19'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99608', 'MAPS', now(), now(), '889e4f60-6352-443c-8705-734ed91dc7a4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99609', 'MBFL', now(), now(), 'da00dfc3-a372-4e9f-8ddb-f0d9c792ab36'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99610', 'MBFL', now(), now(), '53b8b7d8-337a-43fe-9a97-e2f5083210aa'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99611', 'MBFL', now(), now(), 'f7211d4f-8ffb-482f-b268-07b9d79c467e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99612', 'MBFL', now(), now(), 'e7340a1b-3278-42aa-a067-021863d676dd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99613', 'MBFL', now(), now(), '7de673ca-c91d-4bc1-b450-fdaa0c199723'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99614', 'MBFL', now(), now(), 'fd72416c-c88b-4c0f-a3e0-28fd924fd7d7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99615', 'MAPS', now(), now(), 'b0597a99-16d7-4e1e-9820-042971b2551f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99619', 'MAPS', now(), now(), '8d05d190-fda5-4930-838d-76f37892417c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99620', 'MBFL', now(), now(), 'fc2456f7-d2ca-4cb3-b16b-f50388c09a12'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99621', 'MBFL', now(), now(), 'da74789a-b710-4332-a973-cc8ff104f80f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99622', 'MBFL', now(), now(), '52b0c551-7d40-496b-9e5a-3aeb7e68f415'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99623', 'MBFL', now(), now(), '4613c99b-da96-4649-8de5-8e445af78f99'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99624', 'MAPS', now(), now(), '13e0d2ba-852e-4970-b60c-464740975141'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99625', 'MBFL', now(), now(), '772070b7-2029-40cf-82b7-e8b839f2740f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99626', 'MBFL', now(), now(), 'a6a4b405-e1af-455f-89d5-088de0afebfa'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99627', 'MBFL', now(), now(), 'e0778102-5fb8-4366-bbd2-413a96946a6d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99628', 'MBFL', now(), now(), '4dad6942-608b-415b-86b1-4575cbe92b14'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99629', 'MBFL', now(), now(), '534a58f3-e96b-41cd-86f5-d3c3f7553063'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99630', 'MBFL', now(), now(), 'aca18cb8-d348-4dfa-bfce-3508ed050ce2'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99631', 'MBFL', now(), now(), '90fd8694-e43b-49f7-a22b-27f95170069c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99632', 'MBFL', now(), now(), 'b6736f3e-b561-4658-a22a-822b4d141db6'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99633', 'MBFL', now(), now(), 'e622bb3a-8c83-4230-b953-a256a7ed2b50'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99634', 'MBFL', now(), now(), 'a042efbf-24da-489f-ab6d-15179847cec1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99635', 'MBFL', now(), now(), '153a77b9-ae9f-4e3c-8b7e-35631300491d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99636', 'MBFL', now(), now(), '988b8373-ca1d-459f-a0cc-598c20ad1e07'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99637', 'MBFL', now(), now(), 'eb47a507-5f66-4344-bed9-d165d8275fa9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99638', 'MBFL', now(), now(), '0858bd59-a16b-47ca-9cb8-670411737d4d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99639', 'MBFL', now(), now(), '52b0ac8b-3931-47d1-aa66-2283a9a1650a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99640', 'MBFL', now(), now(), '9040a7e0-de08-494b-8d69-27cd4a53bc90'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99641', 'MBFL', now(), now(), '6e1d8641-0448-40cc-88e3-67d4f8466a8e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99643', 'MAPS', now(), now(), '15c1aea9-9b9b-4f6e-93cf-a114ac9175f8'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99644', 'MAPS', now(), now(), '6f294618-1e61-42fc-8d6b-cd870b0b08fc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99645', 'MBFL', now(), now(), '82d2557f-263b-4108-a75b-ff745aea08f0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99647', 'MBFL', now(), now(), 'c432e858-d177-4faa-8d0b-97c5305b61e7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99648', 'MBFL', now(), now(), '273ecc7f-0b37-439e-97e6-86a2f7ea7114'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99649', 'MBFL', now(), now(), '213d21e6-0b04-4f5c-90f8-4ddc9938381d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99650', 'MBFL', now(), now(), 'f2a5f071-205f-4cc1-9448-44058d9af3f5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99651', 'MBFL', now(), now(), 'c16c38b5-eb50-4dc7-8a40-aa9e7e80bf2f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99652', 'MBFL', now(), now(), 'ef17b53b-f840-4b2d-9f66-3f80c413b3c1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99653', 'MBFL', now(), now(), '7307956d-84f3-4c22-ad2f-40b62dc0a0d7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99654', 'MBFL', now(), now(), '47ccb8d8-8df2-4293-9f86-f5703aea0dba'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99655', 'MBFL', now(), now(), '69d0d1e7-8c8e-4cde-82dc-b8374b8b4861'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99656', 'MBFL', now(), now(), 'e0be218f-2d2f-4bac-b8b5-e09ef3f28742'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99657', 'MBFL', now(), now(), 'bd121ed0-6592-427a-9ba9-c06ab3a703dd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99658', 'MBFL', now(), now(), '6acfa9fe-137e-4a92-b21c-39e627cc378a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99659', 'MBFL', now(), now(), 'f131070d-b5d8-453e-bac7-ad436ea124dc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99660', 'MBFL', now(), now(), 'cab88f64-c8c1-42f1-be62-7b4cce31aeb3'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99661', 'MBFL', now(), now(), 'e5a62394-0278-42a3-84e3-57ff2240dc60'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99662', 'MBFL', now(), now(), '8c0d1e5d-6afe-4552-b7cc-3b5a6fbdc3db'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99663', 'MBFL', now(), now(), '44beec24-6856-43f7-ab55-b48286d2829b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99664', 'MBFL', now(), now(), 'c35ed3e5-c3a6-43e2-9794-56709f93620f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99665', 'MBFL', now(), now(), '06b6f8ed-7f4e-4b7a-94b6-def7b619a03d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99666', 'MBFL', now(), now(), '959c959f-b829-471c-a63e-b3cffa15f6c7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99667', 'MBFL', now(), now(), '75ef0a3a-cc89-4a3b-809f-6cdb6753bc25'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99668', 'MBFL', now(), now(), 'c2f65e88-5c6a-4e46-95c6-89e79385c163'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99669', 'MBFL', now(), now(), '6c1d51b0-9213-404a-b7d8-c4fc384bd304'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99670', 'MBFL', now(), now(), '523b6896-d660-42c7-a8f9-e4603e75ccc9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99671', 'MBFL', now(), now(), '2c1d481b-6ef3-49ab-8ae9-a9e6429575fd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99672', 'MBFL', now(), now(), '702c69d2-5231-4267-8d8e-85d5817077d7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99674', 'MBFL', now(), now(), '66b7f4fb-9098-40a8-a018-a5217ed9878d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99675', 'MBFL', now(), now(), '2ab46ff9-9120-48af-ac05-73663dfd1571'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99676', 'MBFL', now(), now(), '488978c8-3c52-4a1a-9966-c04bba23ee37'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99677', 'MBFL', now(), now(), '30ceccbf-25b6-4862-b358-78f12e22ba06'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99678', 'MBFL', now(), now(), 'a4ed1190-85d9-4b20-8390-9a1b9a3bc0c4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99679', 'MBFL', now(), now(), '1c87ddc2-ad88-4607-b826-f37da5fc8762'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99680', 'MBFL', now(), now(), '3b5dca39-d435-413c-9edf-3bb3a2b5005d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99681', 'MBFL', now(), now(), '93acc862-3107-4f22-b270-e0c7d1f5f80b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99682', 'MBFL', now(), now(), 'd5224770-83e3-4dc8-97af-24c147669dcc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99683', 'MBFL', now(), now(), 'b9dcbc66-53d9-4f14-b51d-02171a3fdf5f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99684', 'MBFL', now(), now(), '65a07b11-25cf-4fae-baf4-59d89677cfc2'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99685', 'MBFL', now(), now(), '0cc24afe-3579-41bf-8181-08725b45e3b0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99686', 'MBFL', now(), now(), 'fd40734b-f683-43b2-9e6e-93eeda219aa9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99687', 'MBFL', now(), now(), 'fe3c676b-a3d7-4d58-88d4-5a6ab3dc3aae'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99688', 'MBFL', now(), now(), '83cc5417-31e0-468c-a5b3-0495734e9504'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99689', 'MAPK', now(), now(), '68962696-2ba8-40ae-946d-8ab29dd3cd4b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99690', 'MBFL', now(), now(), '92d71dc8-6601-4cc0-bd76-3584e402ceed'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99691', 'MBFL', now(), now(), '839bfff4-f486-462f-bf2c-560aa95f5b6e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99692', 'MBFL', now(), now(), 'b3e45fb6-3e5f-452e-b355-08fa49e1f52b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99693', 'MBFL', now(), now(), 'd3843234-0168-402a-821d-9a4666a54273'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99694', 'MBFL', now(), now(), '3ca39ea7-1f6d-4112-886e-cd4c6fc07476'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99695', 'MBFL', now(), now(), 'b865dfa9-c1c4-42bd-9253-8fa643ebf582'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99697', 'MAPS', now(), now(), '8e71753d-c45a-4a84-912e-cb6bb8a0ccef'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99701', 'MBFL', now(), now(), '951282d4-0523-450b-a636-c2bdadf2a38a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99702', 'MBFL', now(), now(), 'fcab1e10-4645-4d3e-a4b7-00a9f54a2157'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99703', 'JEAT', now(), now(), '5f47676a-520d-4106-9889-009b0ab29726'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99704', 'MBFL', now(), now(), '328fd045-2e70-4bc2-a466-1319e2425b1f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99705', 'MBFL', now(), now(), '37727f3a-6c6e-4d9e-890c-ec0279c7de0b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99706', 'MBFL', now(), now(), 'c84810a5-660f-4200-a86f-46a17f038adf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99707', 'MBFL', now(), now(), '7d090646-098b-4096-9012-b68182cf2e35'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99708', 'MBFL', now(), now(), '7a16c7b2-e624-4933-9dc4-b3be69849fe5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99709', 'MBFL', now(), now(), 'bd590cc5-a624-4fb2-b37b-4b37a7ac863a'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99710', 'MBFL', now(), now(), '5fab3c20-38ee-44b6-9ae1-384b93462637'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99711', 'MBFL', now(), now(), '1d3a88e9-a0e0-4cce-b20a-9f0b6996b7e1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99712', 'MBFL', now(), now(), 'acec5c52-6709-48cb-a6cb-0e58b05860ec'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99714', 'MBFL', now(), now(), 'ce621370-6656-480d-a071-89de4607d716'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99716', 'MBFL', now(), now(), 'b65f161a-0f33-4360-8905-c716b17943d4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99720', 'MBFL', now(), now(), '19aa130f-0dee-46db-a054-729cddf9a257'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99721', 'MBFL', now(), now(), '715fde06-a1a7-4240-8e59-4b76dffdb144'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99722', 'MBFL', now(), now(), '4be97e0b-4237-4906-bb0d-8e1704e0b65b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99723', 'MBFL', now(), now(), 'aad84c1d-7ba2-40de-92e5-74b2dd558fa9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99724', 'MBFL', now(), now(), '8b8157b2-0c64-477f-a173-e26818caeffd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99725', 'MBFL', now(), now(), '8f258372-966a-4565-9e22-61cdb5f88ef9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99726', 'MBFL', now(), now(), '02f07ef0-ebad-4fb8-a50c-bdd140d87c49'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99727', 'MBFL', now(), now(), '63de42c5-eb6e-4471-9170-8d4d3fd88d87'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99729', 'MBFL', now(), now(), 'c12cf5c5-b3e0-4dff-a88f-39b8a22a950b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99730', 'MBFL', now(), now(), '820b8fe5-2c4c-459a-850a-8326fd50ea57'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99731', 'JEAT', now(), now(), 'dd366219-6c3b-45c1-a59a-e04d0efe1a6d'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99732', 'MBFL', now(), now(), '32e2f9ec-805a-419b-a850-e4868c8eb13f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99733', 'MBFL', now(), now(), '9762e6a0-a2dd-4da7-9cc5-4dfdfd21fad2'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99734', 'MBFL', now(), now(), 'f35587d4-41be-4e7a-8cc3-07e1f2a9e4b9'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99736', 'MBFL', now(), now(), 'a71189c1-784c-4d9c-925b-dcc6432c6a28'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99737', 'MBFL', now(), now(), '80a884f0-058a-46c0-8fdb-90d1d027f002'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99738', 'MBFL', now(), now(), '34cf2f93-66b3-43ab-a428-2cc2e4c6b143'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99739', 'MBFL', now(), now(), 'eadc1ca9-6de2-46ab-a015-acb813599670'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99740', 'MBFL', now(), now(), 'cc3f07af-485b-4256-8703-bf41a5967497'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99741', 'MBFL', now(), now(), '61409776-e0fa-47f4-825e-9c6f91ce2b10'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99742', 'MBFL', now(), now(), 'b46d81ef-9faa-49ec-85a3-4c3734d07126'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99743', 'MBFL', now(), now(), 'acb28741-502a-40c2-aa45-4a9b42d39405'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99744', 'MBFL', now(), now(), 'baf46567-31ea-481d-9ab9-e974ea261c2f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99745', 'MBFL', now(), now(), 'babaac73-1c6b-4209-baf3-1e0c5d41dc7f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99746', 'MBFL', now(), now(), 'ddc32535-73e0-4f13-ad2e-6294700c17cc'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99747', 'MBFL', now(), now(), '40a3c816-79a0-4f26-aa6a-2847835a45d1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99748', 'MBFL', now(), now(), '5a3a2cce-4bc0-4bd2-98fe-7f71bc09c99e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99749', 'MBFL', now(), now(), '212653a0-4a5a-4e48-b301-78b3f294fe16'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99750', 'MBFL', now(), now(), '2013baa1-1f2f-47f7-beb0-98f3171c6bf1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99751', 'MBFL', now(), now(), 'a19e22ef-194e-4b48-858c-59ea04d48fcf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99752', 'MBFL', now(), now(), 'e1ce6564-37d3-4fe4-8c19-f39e31c9d7cd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99753', 'MBFL', now(), now(), '2dd6633b-4a67-4bff-879f-32bf88ec64a5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99754', 'MBFL', now(), now(), '5fe4e773-573e-4052-b4b7-d5686366d03b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99755', 'MBFL', now(), now(), '0383ed06-ff31-4fa7-851a-962dc7adf7d3'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99756', 'MBFL', now(), now(), '61726154-40a0-4f7d-82d0-b09f28a2f209'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99757', 'MBFL', now(), now(), '3bd35ddb-4d89-4e01-8dd1-e938bc5c0388'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99758', 'MBFL', now(), now(), '31c3a401-cc17-4e5a-bf22-d66e00a05528'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99759', 'MBFL', now(), now(), 'cc534b49-e72f-4a19-bbad-4dc5101c1373'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99760', 'MBFL', now(), now(), '56e2c9c0-f914-40f3-988c-7b88593f5513'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99761', 'MBFL', now(), now(), 'ccd849d7-e2ed-40ce-a353-9c93d57b4f92'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99762', 'MBFL', now(), now(), '1981bcff-5f4b-4358-92ea-93177783215f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99763', 'MBFL', now(), now(), '298d0d8a-a19a-4498-937f-1ab233a85730'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99764', 'MBFL', now(), now(), '37352211-832f-4af7-8655-414ac02b8544'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99765', 'MBFL', now(), now(), 'c2dd65ee-9875-4e7d-9d34-46f529f8959b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99766', 'MBFL', now(), now(), 'ad3283f4-74cb-403f-84a2-c14f510f83cd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99767', 'MBFL', now(), now(), 'eb25b5f7-ed3b-4860-b337-5ee68b6c4534'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99768', 'MBFL', now(), now(), '92116116-8a7a-420c-83cd-5f9977401941'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99769', 'MBFL', now(), now(), 'c5a38d76-3bef-4e9d-8244-1741aa20ed10'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99770', 'MBFL', now(), now(), 'e7f0f266-019d-4bce-8921-6804e5e8cb0c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99771', 'MBFL', now(), now(), '74f9319a-0970-4721-8fda-bfe4f777896b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99772', 'MBFL', now(), now(), 'db7dc663-1443-4209-9a01-82f694a4dca1'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99773', 'MBFL', now(), now(), '474d4d25-1314-4bbf-ae04-25ffae18a7d4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99774', 'MBFL', now(), now(), 'ea503792-8747-465c-ad89-c513004e1345'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99775', 'MBFL', now(), now(), 'e33ba93c-8ba2-4a3b-b8bc-f331a989e388'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99776', 'MBFL', now(), now(), 'ffc00def-ec8b-413d-9601-bf5587b510f4'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99777', 'MBFL', now(), now(), 'ce0ff3db-7d59-43af-923d-efdf4feb72cf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99778', 'MBFL', now(), now(), '4235599e-4fd3-46e9-b733-de29dca74700'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99780', 'MBFL', now(), now(), '0aa94d7f-81bb-42f4-be8a-e14b2bc630c8'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99781', 'MBFL', now(), now(), '1b98f0bd-711c-48f0-87ed-9e5bff30ad60'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99782', 'MBFL', now(), now(), 'c7f7dd5b-7674-4b78-b1a5-0013fd979231'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99783', 'MBFL', now(), now(), '20152935-a8c8-45ad-a4cd-af2a945a8a17'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99784', 'MBFL', now(), now(), '58ec9aaa-e2d0-4732-9ffd-3b7563bb1c05'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99785', 'MBFL', now(), now(), '13f3eb0b-1534-4773-9fae-a86d39a829ae'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99786', 'MBFL', now(), now(), 'eeb04da3-f067-469b-8703-c3e9de365ad7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99788', 'MBFL', now(), now(), '224088e2-afba-4b23-8361-9126c00445a8'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99789', 'MBFL', now(), now(), '8c123f36-f68d-461b-bd60-01cbd501ae17'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99790', 'MBFL', now(), now(), '1492fc25-8a4a-4fbc-a9be-433ad03d878e'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99791', 'MBFL', now(), now(), 'fda0d6c4-7a68-425b-9567-da8d368dbfa0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99801', 'MAPK', now(), now(), '095789bc-136f-44e6-bf3f-b5a5a4ffad5c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99802', 'MAPK', now(), now(), '1e73fbe5-0924-42dc-aedd-9c4aab511b90'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99803', 'MAPK', now(), now(), '281f58c0-fe6e-4e77-9035-6f1db1d4a8fd'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99811', 'MAPK', now(), now(), '6dcd4248-9c66-4bf3-8f4b-30dfd4add731'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99812', 'MAPK', now(), now(), '82579769-f363-4d68-b6f4-2586ac3f974c'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99820', 'MAPK', now(), now(), 'aecd46d3-dea5-4d0e-8409-b5b300ddded8'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99821', 'MAPK', now(), now(), '5a3ff675-8c07-4058-b5c6-8c19400f2f07'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99824', 'MAPK', now(), now(), 'e0cd0a98-4c4e-4d21-9adc-416fb4ce2449'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99825', 'MAPK', now(), now(), 'aa515936-aa46-4016-a487-c925b4dc16b2'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99826', 'MAPK', now(), now(), '553f410a-ed32-4517-a766-c665369d9369'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99827', 'MAPK', now(), now(), 'a275e877-48ba-4473-8064-43b3ab7b042b'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99829', 'MAPK', now(), now(), '7cb1babd-df8b-400f-9e5c-6c595bbcaa2f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99830', 'MAPK', now(), now(), 'dcc9dd70-0984-4555-a371-e8f8bf583ecf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99832', 'MAPK', now(), now(), 'a3740468-c12a-465d-b627-fd80bc921eb5'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99833', 'MAPK', now(), now(), '38eecaf7-4c2d-44c5-a8bd-ccde44ec6b89'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99835', 'MAPK', now(), now(), 'c914333a-4c88-404b-a17a-f51b4df9dac7'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99836', 'MAPK', now(), now(), 'fe065064-61f7-4c01-80f4-945fb1d6d26f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99840', 'MAPK', now(), now(), '7c72b250-4d4b-41a2-b548-97a5b1e1c526'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99841', 'MAPK', now(), now(), '1a1c28b2-d5c7-4180-93ea-d66887ce7e26'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99850', 'MAPK', now(), now(), '21f9854e-2a61-4810-a4e3-ea09f1f2c59f'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99901', 'MAPK', now(), now(), '36ef16e6-d9a5-4706-a115-e11691ff1c37'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99903', 'MAPK', now(), now(), '76d5df09-e4f1-4b96-8df4-68bbeee29b00'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99918', 'MAPK', now(), now(), '4b6b34d9-40ec-459a-a337-5fbdde3aaa84'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99919', 'MAPK', now(), now(), 'af79bdf9-f4cf-494e-ad67-ddbb836e98d0'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99921', 'MAPK', now(), now(), '742e78df-6615-406b-b0f2-55deaec1fc09'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99922', 'MAPK', now(), now(), '99701216-788c-41d7-bdbb-98ff0f8e2224'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99923', 'MAPK', now(), now(), '3978cb58-70b6-4c23-a97b-d6e00cf7abcf'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99925', 'MAPK', now(), now(), 'bc7cb635-6287-4ecb-8f8c-9e6f66858441'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99926', 'MAPK', now(), now(), '9abec1b8-3f19-4616-aae2-8c8a54b44e48'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99927', 'MAPK', now(), now(), 'ba7adb39-9897-4e4d-b042-c4360cc25691'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99928', 'MAPK', now(), now(), '4f721fb2-7bcc-4a2a-a24b-cd3d00532311'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99929', 'MAPK', now(), now(), '0ed1ee93-f720-4e4c-b28a-4572e847ad15'); + +INSERT INTO postal_code_to_gblocs(postal_code, gbloc, created_at, updated_at, id) +VALUES ('99950', 'MAPK', now(), now(), '23c0f299-2b5c-44ff-b604-5efd70019f8d'); diff --git a/migrations/app/schema/20250103142533_update_postal_codes_and_gblocs_for_ak.up.sql b/migrations/app/schema/20250103142533_update_postal_codes_and_gblocs_for_ak.up.sql new file mode 100644 index 00000000000..a150e692932 --- /dev/null +++ b/migrations/app/schema/20250103142533_update_postal_codes_and_gblocs_for_ak.up.sql @@ -0,0 +1,159 @@ +delete from postal_code_to_gblocs where postal_code in ( +select uspr_zip_id from v_locations where state = 'AK'); + +drop view move_to_gbloc; +CREATE OR REPLACE VIEW move_to_gbloc AS +SELECT move_id, gbloc FROM ( + SELECT DISTINCT ON (sh.move_id) sh.move_id, s.affiliation, + COALESCE(pctg.gbloc, coalesce(pctg_oconus_bos.gbloc, coalesce(pctg_oconus.gbloc, pctg_ppm.gbloc))) AS gbloc + FROM mto_shipments sh + JOIN moves m ON sh.move_id = m.id + JOIN orders o on m.orders_id = o.id + JOIN service_members s on o.service_member_id = s.id + LEFT JOIN ( SELECT a.id AS address_id, + pctg_1.gbloc, pctg_1.postal_code + FROM addresses a + JOIN postal_code_to_gblocs pctg_1 ON a.postal_code::text = pctg_1.postal_code::text) pctg ON pctg.address_id = sh.pickup_address_id + LEFT JOIN ( SELECT ppm.shipment_id, + pctg_1.gbloc + FROM ppm_shipments ppm + JOIN addresses ppm_address ON ppm.pickup_postal_address_id = ppm_address.id + JOIN postal_code_to_gblocs pctg_1 ON ppm_address.postal_code::text = pctg_1.postal_code::text) pctg_ppm ON pctg_ppm.shipment_id = sh.id + LEFT JOIN ( SELECT a.id AS address_id, + cast(jr.code as varchar) AS gbloc, ga.department_indicator + FROM addresses a + JOIN re_oconus_rate_areas ora ON a.us_post_region_cities_id = ora.us_post_region_cities_id + JOIN gbloc_aors ga ON ora.id = ga.oconus_rate_area_id + JOIN jppso_regions jr ON ga.jppso_regions_id = jr.id + ) pctg_oconus_bos ON pctg_oconus_bos.address_id = sh.pickup_address_id + and case when s.affiliation = 'AIR_FORCE' THEN 'AIR_AND_SPACE_FORCE' + when s.affiliation = 'SPACE_FORCE' THEN 'AIR_AND_SPACE_FORCE' + when s.affiliation = 'NAVY' THEN 'NAVY_AND_MARINES' + when s.affiliation = 'MARINES' THEN 'NAVY_AND_MARINES' + else s.affiliation + end = pctg_oconus_bos.department_indicator + LEFT JOIN ( SELECT a.id AS address_id, + cast(pctg_1.code as varchar) AS gbloc, ga.department_indicator + FROM addresses a + JOIN re_oconus_rate_areas ora ON a.us_post_region_cities_id = ora.us_post_region_cities_id + JOIN gbloc_aors ga ON ora.id = ga.oconus_rate_area_id + JOIN jppso_regions pctg_1 ON ga.jppso_regions_id = pctg_1.id + ) pctg_oconus ON pctg_oconus.address_id = sh.pickup_address_id and pctg_oconus.department_indicator is null + WHERE sh.deleted_at IS NULL + ORDER BY sh.move_id, sh.created_at) as m; + + +DROP FUNCTION IF EXISTS get_address_gbloc; + +CREATE OR REPLACE FUNCTION public.get_address_gbloc( + address_id UUID, + affiliation TEXT, + OUT gbloc TEXT +) +RETURNS TEXT AS $$ +DECLARE + is_oconus BOOLEAN; + v_count INT; + v_bos_count INT; + v_dept_ind TEXT; +BEGIN + is_oconus := get_is_oconus(address_id); + + IF affiliation in ('AIR_FORCE','SPACE_FORCE') THEN + v_dept_ind := 'AIR_AND_SPACE_FORCE'; + ELSIF affiliation in ('MARINES','NAVY') THEN + v_dept_ind := 'NAVY_AND_MARINES'; + ELSE v_dept_ind := affiliation; + END IF; + + IF is_oconus THEN + + SELECT count(*) + INTO v_count + FROM addresses a, + re_oconus_rate_areas o, + jppso_regions j, + gbloc_aors g + WHERE a.us_post_region_cities_id = o.us_post_region_cities_id + and o.id = g.oconus_rate_area_id + and j.id = g.jppso_regions_id + and a.id = address_id; + + IF v_count > 1 THEN + + --check for gbloc by bos + SELECT count(*) + INTO v_bos_count + FROM addresses a, + re_oconus_rate_areas o, + jppso_regions j, + gbloc_aors g + WHERE a.us_post_region_cities_id = o.us_post_region_cities_id + and o.id = g.oconus_rate_area_id + and j.id = g.jppso_regions_id + and a.id = address_id + and g.department_indicator = v_dept_ind; + + IF v_bos_count = 1 THEN + + SELECT j.code + INTO gbloc + FROM addresses a, + re_oconus_rate_areas o, + jppso_regions j, + gbloc_aors g + WHERE a.us_post_region_cities_id = o.us_post_region_cities_id + and o.id = g.oconus_rate_area_id + and j.id = g.jppso_regions_id + and a.id = address_id + and g.department_indicator = v_dept_ind; + + ELSE + + SELECT j.code + INTO gbloc + FROM addresses a, + re_oconus_rate_areas o, + jppso_regions j, + gbloc_aors g + WHERE a.us_post_region_cities_id = o.us_post_region_cities_id + and o.id = g.oconus_rate_area_id + and j.id = g.jppso_regions_id + and a.id = address_id + and g.department_indicator IS NULL; + + END IF; + + ELSE + + SELECT j.code + INTO gbloc + FROM addresses a, + re_oconus_rate_areas o, + jppso_regions j, + gbloc_aors g + WHERE a.us_post_region_cities_id = o.us_post_region_cities_id + and o.id = g.oconus_rate_area_id + and j.id = g.jppso_regions_id + and a.id = address_id; + + END IF; + + ELSE --is conus + + SELECT j.gbloc + INTO gbloc + FROM addresses a, + v_locations o, + postal_code_to_gblocs j + WHERE a.us_post_region_cities_id = o.uprc_id + and o.uspr_zip_id = j.postal_code + and a.id = address_id; + + END IF; + + IF gbloc IS NULL THEN + RAISE EXCEPTION 'GBLOC not found for address ID % for affiliation %', address_id, affiiation; + END IF; +END; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go b/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go index 881ce780a4d..0e7b12109e8 100644 --- a/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go +++ b/pkg/handlers/ghcapi/internal/payloads/model_to_payload.go @@ -2626,9 +2626,11 @@ func SearchMoves(appCtx appcontext.AppContext, moves models.Moves) *ghcmessages. // populates the destination postal code of the move var destinationPostalCode string - destinationPostalCode, err = move.GetDestinationPostalCode(appCtx.DB()) + destinationAddress, err := move.GetDestinationAddress(appCtx.DB()) if err != nil { destinationPostalCode = "" + } else { + destinationPostalCode = destinationAddress.PostalCode } searchMoves[i] = &ghcmessages.SearchMove{ diff --git a/pkg/handlers/ghcapi/move_test.go b/pkg/handlers/ghcapi/move_test.go index 3b9fda47401..68b33148943 100644 --- a/pkg/handlers/ghcapi/move_test.go +++ b/pkg/handlers/ghcapi/move_test.go @@ -597,17 +597,17 @@ func (suite *HandlerSuite) TestSearchMovesHandler() { // Validate outgoing payload without shipment suite.NoError(payload.Validate(strfmt.Default)) - var moveDestinationPostalCode string + var moveDestinationAddress *models.Address var moveDestinationGBLOC string var err error // Get destination postal code and GBLOC based on business logic - moveDestinationPostalCode, err = move.GetDestinationPostalCode(suite.DB()) + moveDestinationAddress, err = move.GetDestinationAddress(suite.DB()) suite.NoError(err) moveDestinationGBLOC, err = move.GetDestinationGBLOC(suite.DB()) suite.NoError(err) - suite.Equal(moveDestinationPostalCode, "62225") + suite.Equal(moveDestinationAddress.PostalCode, "62225") suite.Equal(ghcmessages.GBLOC(moveDestinationGBLOC), ghcmessages.GBLOC("AGFM")) // Set Mock Search settings for move with MTO Shipment @@ -639,12 +639,12 @@ func (suite *HandlerSuite) TestSearchMovesHandler() { suite.NoError(payload.Validate(strfmt.Default)) // Get destination postal code and GBLOC based on business logic - moveDestinationPostalCode, err = moveWithShipment.GetDestinationPostalCode(suite.DB()) + moveDestinationAddress, err = moveWithShipment.GetDestinationAddress(suite.DB()) suite.NoError(err) moveDestinationGBLOC, err = moveWithShipment.GetDestinationGBLOC(suite.DB()) suite.NoError(err) - suite.Equal(moveDestinationPostalCode, "90210") + suite.Equal(moveDestinationAddress.PostalCode, "90210") suite.Equal(ghcmessages.GBLOC(moveDestinationGBLOC), ghcmessages.GBLOC("KKFA")) // Set Mock Search settings for move with PPM Shipment @@ -676,12 +676,12 @@ func (suite *HandlerSuite) TestSearchMovesHandler() { suite.NoError(payload.Validate(strfmt.Default)) // Get destination postal code and GBLOC based on business logic - moveDestinationPostalCode, err = moveWithShipmentPPM.GetDestinationPostalCode(suite.DB()) + moveDestinationAddress, err = moveWithShipmentPPM.GetDestinationAddress(suite.DB()) suite.NoError(err) moveDestinationGBLOC, err = moveWithShipmentPPM.GetDestinationGBLOC(suite.DB()) suite.NoError(err) - suite.Equal(moveDestinationPostalCode, payload.SearchMoves[0].DestinationPostalCode) + suite.Equal(moveDestinationAddress.PostalCode, payload.SearchMoves[0].DestinationPostalCode) suite.Equal(ghcmessages.GBLOC(moveDestinationGBLOC), payload.SearchMoves[0].DestinationGBLOC) }) } diff --git a/pkg/handlers/ghcapi/orders.go b/pkg/handlers/ghcapi/orders.go index f6b559513a2..51fec571935 100644 --- a/pkg/handlers/ghcapi/orders.go +++ b/pkg/handlers/ghcapi/orders.go @@ -219,21 +219,46 @@ func (h CreateOrderHandler) Handle(params orderop.CreateOrderParams) middleware. return orderop.NewCreateOrderUnprocessableEntity(), err } - destinationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) - if err != nil { - err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") - appCtx.Logger().Error(err.Error()) - return orderop.NewCreateOrderUnprocessableEntity(), err + var newDutyLocationGBLOC *string + if *newDutyLocation.Address.IsOconus { + newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), newDutyLocation.Address, serviceMember) + if err != nil { + return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for New Duty Location Oconus GBLOC") + } + newDutyLocationGBLOC = newDutyLocationGBLOCOconus + } else { + newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for New Duty Location PostalCodeToGBLOC") + default: + err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") + appCtx.Logger().Error(err.Error()) + return orderop.NewCreateOrderUnprocessableEntity(), err + } + } + newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC } - originDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if err != nil { - switch err { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") - default: - return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, serviceMember) + if err != nil { + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location Oconus GBLOC") + } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location PostalCodeToGBLOC") + default: + return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + } } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } grade := (internalmessages.OrderPayGrade)(*payload.Grade) @@ -317,9 +342,9 @@ func (h CreateOrderHandler) Handle(params orderop.CreateOrderParams) middleware. &originDutyLocation, &grade, &entitlement, - &originDutyLocationGBLOC.GBLOC, + originDutyLocationGBLOC, packingAndShippingInstructions, - &destinationGBLOC.GBLOC, + newDutyLocationGBLOC, ) if err != nil || verrs.HasAny() { return handlers.ResponseForVErrors(appCtx.Logger(), verrs, err), err diff --git a/pkg/handlers/ghcapi/orders_test.go b/pkg/handlers/ghcapi/orders_test.go index d12d32534b5..68b984f2cef 100644 --- a/pkg/handlers/ghcapi/orders_test.go +++ b/pkg/handlers/ghcapi/orders_test.go @@ -32,6 +32,7 @@ import ( "github.com/transcom/mymove/pkg/services/query" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/swagger/nullable" + "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/trace" "github.com/transcom/mymove/pkg/uploader" ) @@ -110,20 +111,70 @@ func (suite *HandlerSuite) TestCreateOrder() { func (suite *HandlerSuite) TestCreateOrderWithOCONUSValues() { waf := entitlements.NewWeightAllotmentFetcher() - sm := factory.BuildExtendedServiceMember(suite.AppContextForTest().DB(), nil, nil) + customAffiliation := models.AffiliationARMY + sm := factory.BuildExtendedServiceMember(suite.DB(), []factory.Customization{ + { + Model: models.ServiceMember{ + Affiliation: &customAffiliation, + }, + }, + }, nil) officeUser := factory.BuildOfficeUserWithRoles(suite.AppContextForTest().DB(), nil, []roles.RoleType{roles.RoleTypeTOO}) - originDutyLocation := factory.BuildDutyLocation(suite.AppContextForTest().DB(), []factory.Customization{ + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801") + suite.NotNil(usprc) + suite.FatalNoError(err) + + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, + }, + }, + }, nil) + + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ { Model: models.DutyLocation{ - Name: "Not Yuma AFB", + Name: factory.MakeRandomString(8), + AddressID: address.ID, }, }, }, nil) + dutyLocation := factory.FetchOrBuildCurrentDutyLocation(suite.AppContextForTest().DB()) - factory.FetchOrBuildPostalCodeToGBLOC(suite.AppContextForTest().DB(), dutyLocation.Address.PostalCode, "KKFA") - factory.FetchOrBuildDefaultContractor(suite.AppContextForTest().DB(), nil, nil) + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: models.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + + us_country, err := models.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) + + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + factory.FetchOrBuildDefaultContractor(suite.AppContextForTest().DB(), nil, nil) req := httptest.NewRequest("POST", "/orders", nil) req = suite.AuthenticateOfficeRequest(req, officeUser) @@ -175,6 +226,7 @@ func (suite *HandlerSuite) TestCreateOrderWithOCONUSValues() { suite.Assertions.Equal(sm.ID.String(), okResponse.Payload.CustomerID.String()) suite.Assertions.Equal(ordersType, okResponse.Payload.OrderType) suite.Assertions.Equal(handlers.FmtString("123456"), okResponse.Payload.OrderNumber) + suite.Assertions.Equal(ghcmessages.GBLOC("MAPK"), okResponse.Payload.OriginDutyLocationGBLOC) suite.Assertions.Equal(handlers.FmtString("E19A"), okResponse.Payload.Tac) suite.Assertions.Equal(handlers.FmtString("SacNumber"), okResponse.Payload.Sac) suite.Assertions.Equal(&deptIndicator, okResponse.Payload.DepartmentIndicator) diff --git a/pkg/handlers/internalapi/orders.go b/pkg/handlers/internalapi/orders.go index 6e663bff4ea..84c8dfe126f 100644 --- a/pkg/handlers/internalapi/orders.go +++ b/pkg/handlers/internalapi/orders.go @@ -168,9 +168,26 @@ func (h CreateOrdersHandler) Handle(params ordersop.CreateOrdersParams) middlewa return handlers.ResponseForError(appCtx.Logger(), err), err } - newDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) - if err != nil { - return handlers.ResponseForError(appCtx.Logger(), err), err + var newDutyLocationGBLOC *string + if *newDutyLocation.Address.IsOconus { + newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), newDutyLocation.Address, serviceMember) + if err != nil { + return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for New Duty Location Oconus GBLOC") + } + newDutyLocationGBLOC = newDutyLocationGBLOCOconus + } else { + newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for New Duty Location PostalCodeToGBLOC") + default: + err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") + appCtx.Logger().Error(err.Error()) + return handlers.ResponseForError(appCtx.Logger(), err), err + } + } + newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC } var dependentsTwelveAndOver *int @@ -184,14 +201,24 @@ func (h CreateOrdersHandler) Handle(params ordersop.CreateOrdersParams) middlewa dependentsUnderTwelve = models.IntPointer(int(*payload.DependentsUnderTwelve)) } - originDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if err != nil { - switch err { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") - default: - return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, serviceMember) + if err != nil { + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location Oconus GBLOC") } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location PostalCodeToGBLOC") + default: + return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + } + } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } grade := payload.Grade @@ -278,9 +305,9 @@ func (h CreateOrdersHandler) Handle(params ordersop.CreateOrdersParams) middlewa &originDutyLocation, grade, &entitlement, - &originDutyLocationGBLOC.GBLOC, + originDutyLocationGBLOC, packingAndShippingInstructions, - &newDutyLocationGBLOC.GBLOC, + newDutyLocationGBLOC, ) if err != nil || verrs.HasAny() { return handlers.ResponseForVErrors(appCtx.Logger(), verrs, err), err @@ -368,11 +395,26 @@ func (h UpdateOrdersHandler) Handle(params ordersop.UpdateOrdersParams) middlewa return handlers.ResponseForError(appCtx.Logger(), err), err } - newDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), dutyLocation.Address.PostalCode) - if err != nil { - err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") - appCtx.Logger().Error(err.Error()) - return handlers.ResponseForError(appCtx.Logger(), err), err + var newDutyLocationGBLOC *string + if *dutyLocation.Address.IsOconus { + newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), dutyLocation.Address, order.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(dutyLocation.ID, "while looking for New Duty Location Oconus GBLOC") + } + newDutyLocationGBLOC = newDutyLocationGBLOCOconus + } else { + newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), dutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(dutyLocation.ID, "while looking for New Duty Location PostalCodeToGBLOC") + default: + err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") + appCtx.Logger().Error(err.Error()) + return handlers.ResponseForError(appCtx.Logger(), err), err + } + } + newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC } if payload.OriginDutyLocationID != "" { @@ -387,11 +429,26 @@ func (h UpdateOrdersHandler) Handle(params ordersop.UpdateOrdersParams) middlewa order.OriginDutyLocation = &originDutyLocation order.OriginDutyLocationID = &originDutyLocationID - originGBLOC, originGBLOCerr := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if originGBLOCerr != nil { - return handlers.ResponseForError(appCtx.Logger(), originGBLOCerr), originGBLOCerr + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, order.ServiceMember) + if err != nil { + return handlers.ResponseForError(appCtx.Logger(), err), err + } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location PostalCodeToGBLOC") + default: + return handlers.ResponseForError(appCtx.Logger(), err), err + } + } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } - order.OriginDutyLocationGBLOC = &originGBLOC.GBLOC + order.OriginDutyLocationGBLOC = originDutyLocationGBLOC if payload.MoveID != "" { @@ -433,7 +490,7 @@ func (h UpdateOrdersHandler) Handle(params ordersop.UpdateOrdersParams) middlewa order.SpouseHasProGear = *payload.SpouseHasProGear order.NewDutyLocationID = dutyLocation.ID order.NewDutyLocation = dutyLocation - order.DestinationGBLOC = &newDutyLocationGBLOC.GBLOC + order.DestinationGBLOC = newDutyLocationGBLOC order.TAC = payload.Tac order.SAC = payload.Sac diff --git a/pkg/handlers/internalapi/orders_test.go b/pkg/handlers/internalapi/orders_test.go index bf1b4a4303c..c26d5302ecf 100644 --- a/pkg/handlers/internalapi/orders_test.go +++ b/pkg/handlers/internalapi/orders_test.go @@ -22,126 +22,240 @@ import ( "github.com/transcom/mymove/pkg/services/move" orderservice "github.com/transcom/mymove/pkg/services/order" storageTest "github.com/transcom/mymove/pkg/storage/test" + "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/uploader" ) func (suite *HandlerSuite) TestCreateOrder() { - sm := factory.BuildExtendedServiceMember(suite.DB(), nil, nil) - suite.Run("can create conus and oconus orders", func() { - testCases := []struct { - test string - isOconus bool - }{ - {test: "Can create OCONUS order", isOconus: true}, - {test: "Can create CONUS order", isOconus: false}, - } - for _, tc := range testCases { - address := factory.BuildAddress(suite.DB(), []factory.Customization{ - { - Model: models.Address{ - IsOconus: &tc.isOconus, - }, + customAffiliation := models.AffiliationARMY + sm := factory.BuildExtendedServiceMember(suite.DB(), []factory.Customization{ + { + Model: models.ServiceMember{ + Affiliation: &customAffiliation, + }, + }, + }, nil) + suite.Run("can create conus orders", func() { + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(false), }, - }, nil) + }, + }, nil) - originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - { - Model: models.DutyLocation{ - Name: factory.MakeRandomString(8), - }, + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + Name: factory.MakeRandomString(8), + }, + }, + { + Model: address, + LinkOnly: true, + }, + }, nil) + + dutyLocation := factory.FetchOrBuildCurrentDutyLocation(suite.DB()) + factory.FetchOrBuildPostalCodeToGBLOC(suite.DB(), dutyLocation.Address.PostalCode, "KKFA") + factory.FetchOrBuildDefaultContractor(suite.DB(), nil, nil) + req := httptest.NewRequest("POST", "/orders", nil) + req = suite.AuthenticateRequest(req, sm) + + hasDependents := true + spouseHasProGear := true + issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) + reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) + ordersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION + deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE + payload := &internalmessages.CreateUpdateOrders{ + HasDependents: handlers.FmtBool(hasDependents), + SpouseHasProGear: handlers.FmtBool(spouseHasProGear), + IssueDate: handlers.FmtDate(issueDate), + ReportByDate: handlers.FmtDate(reportByDate), + OrdersType: internalmessages.NewOrdersType(ordersType), + OriginDutyLocationID: *handlers.FmtUUIDPtr(&originDutyLocation.ID), + NewDutyLocationID: handlers.FmtUUID(dutyLocation.ID), + ServiceMemberID: handlers.FmtUUID(sm.ID), + OrdersNumber: handlers.FmtString("123456"), + Tac: handlers.FmtString("E19A"), + Sac: handlers.FmtString("SacNumber"), + DepartmentIndicator: internalmessages.NewDeptIndicator(deptIndicator), + Grade: models.ServiceMemberGradeE1.Pointer(), + } + + params := ordersop.CreateOrdersParams{ + HTTPRequest: req, + CreateOrders: payload, + } + + fakeS3 := storageTest.NewFakeS3Storage(true) + handlerConfig := suite.HandlerConfig() + handlerConfig.SetFileStorer(fakeS3) + createHandler := CreateOrdersHandler{handlerConfig} + + response := createHandler.Handle(params) + + suite.Assertions.IsType(&ordersop.CreateOrdersCreated{}, response) + okResponse := response.(*ordersop.CreateOrdersCreated) + orderID := okResponse.Payload.ID.String() + createdOrder, _ := models.FetchOrder(suite.DB(), uuid.FromStringOrNil(orderID)) + var createdEntitlement models.Entitlement + err := suite.DB().Find(&createdEntitlement, createdOrder.EntitlementID) + suite.NoError(err) + suite.NotEmpty(createdEntitlement) + suite.Assertions.Equal(sm.ID.String(), okResponse.Payload.ServiceMemberID.String()) + suite.Assertions.Len(okResponse.Payload.Moves, 1) + suite.Assertions.Equal(ordersType, *okResponse.Payload.OrdersType) + suite.Assertions.Equal(handlers.FmtString("123456"), okResponse.Payload.OrdersNumber) + suite.Assertions.Equal(handlers.FmtString("E19A"), okResponse.Payload.Tac) + suite.Assertions.Equal(handlers.FmtString("SacNumber"), okResponse.Payload.Sac) + suite.Assertions.Equal(&deptIndicator, okResponse.Payload.DepartmentIndicator) + suite.Assertions.Equal(*models.Int64Pointer(8000), *okResponse.Payload.AuthorizedWeight) + suite.NotNil(&createdOrder.Entitlement) + suite.NotEmpty(createdOrder.SupplyAndServicesCostEstimate) + suite.NotEmpty(createdOrder.PackingAndShippingInstructions) + suite.NotEmpty(createdOrder.MethodOfPayment) + suite.NotEmpty(createdOrder.NAICS) + suite.Nil(createdEntitlement.AccompaniedTour) + suite.Nil(createdEntitlement.DependentsTwelveAndOver) + suite.Nil(createdEntitlement.DependentsUnderTwelve) + }) + + suite.Run("can create oconus orders", func() { + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801") + suite.NotNil(usprc) + suite.FatalNoError(err) + + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, }, - { - Model: address, - LinkOnly: true, + }, + }, nil) + + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + Name: factory.MakeRandomString(8), + AddressID: address.ID, }, - }, nil) - - dutyLocation := factory.FetchOrBuildCurrentDutyLocation(suite.DB()) - factory.FetchOrBuildPostalCodeToGBLOC(suite.DB(), dutyLocation.Address.PostalCode, "KKFA") - factory.FetchOrBuildDefaultContractor(suite.DB(), nil, nil) - - req := httptest.NewRequest("POST", "/orders", nil) - req = suite.AuthenticateRequest(req, sm) - - hasDependents := true - spouseHasProGear := true - issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) - reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) - ordersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION - deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE - payload := &internalmessages.CreateUpdateOrders{ - HasDependents: handlers.FmtBool(hasDependents), - SpouseHasProGear: handlers.FmtBool(spouseHasProGear), - IssueDate: handlers.FmtDate(issueDate), - ReportByDate: handlers.FmtDate(reportByDate), - OrdersType: internalmessages.NewOrdersType(ordersType), - OriginDutyLocationID: *handlers.FmtUUIDPtr(&originDutyLocation.ID), - NewDutyLocationID: handlers.FmtUUID(dutyLocation.ID), - ServiceMemberID: handlers.FmtUUID(sm.ID), - OrdersNumber: handlers.FmtString("123456"), - Tac: handlers.FmtString("E19A"), - Sac: handlers.FmtString("SacNumber"), - DepartmentIndicator: internalmessages.NewDeptIndicator(deptIndicator), - Grade: models.ServiceMemberGradeE1.Pointer(), - } + }, + }, nil) - if tc.isOconus { - payload.AccompaniedTour = models.BoolPointer(true) - payload.DependentsTwelveAndOver = models.Int64Pointer(5) - payload.DependentsUnderTwelve = models.Int64Pointer(5) - } + dutyLocation := factory.FetchOrBuildCurrentDutyLocation(suite.DB()) - params := ordersop.CreateOrdersParams{ - HTTPRequest: req, - CreateOrders: payload, - } + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - fakeS3 := storageTest.NewFakeS3Storage(true) - handlerConfig := suite.HandlerConfig() - handlerConfig.SetFileStorer(fakeS3) - createHandler := CreateOrdersHandler{handlerConfig} - - response := createHandler.Handle(params) - - suite.Assertions.IsType(&ordersop.CreateOrdersCreated{}, response) - okResponse := response.(*ordersop.CreateOrdersCreated) - orderID := okResponse.Payload.ID.String() - createdOrder, _ := models.FetchOrder(suite.DB(), uuid.FromStringOrNil(orderID)) - var createdEntitlement models.Entitlement - err := suite.DB().Find(&createdEntitlement, createdOrder.EntitlementID) - suite.NoError(err) - suite.NotEmpty(createdEntitlement) - suite.Assertions.Equal(sm.ID.String(), okResponse.Payload.ServiceMemberID.String()) - suite.Assertions.Len(okResponse.Payload.Moves, 1) - suite.Assertions.Equal(ordersType, *okResponse.Payload.OrdersType) - suite.Assertions.Equal(handlers.FmtString("123456"), okResponse.Payload.OrdersNumber) - suite.Assertions.Equal(handlers.FmtString("E19A"), okResponse.Payload.Tac) - suite.Assertions.Equal(handlers.FmtString("SacNumber"), okResponse.Payload.Sac) - suite.Assertions.Equal(&deptIndicator, okResponse.Payload.DepartmentIndicator) - suite.Assertions.Equal(*models.Int64Pointer(8000), *okResponse.Payload.AuthorizedWeight) - suite.NotNil(&createdOrder.Entitlement) - suite.NotEmpty(createdOrder.SupplyAndServicesCostEstimate) - suite.NotEmpty(createdOrder.PackingAndShippingInstructions) - suite.NotEmpty(createdOrder.MethodOfPayment) - suite.NotEmpty(createdOrder.NAICS) - if tc.isOconus { - suite.NotNil(createdEntitlement.AccompaniedTour) - suite.NotNil(createdEntitlement.DependentsTwelveAndOver) - suite.NotNil(createdEntitlement.DependentsUnderTwelve) - } else { - suite.Nil(createdEntitlement.AccompaniedTour) - suite.Nil(createdEntitlement.DependentsTwelveAndOver) - suite.Nil(createdEntitlement.DependentsUnderTwelve) - } + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: models.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + suite.Nil(err) + + us_country, err := models.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) + + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.Nil(err) + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + factory.FetchOrBuildDefaultContractor(suite.DB(), nil, nil) + req := httptest.NewRequest("POST", "/orders", nil) + req = suite.AuthenticateRequest(req, sm) + + hasDependents := true + spouseHasProGear := true + issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) + reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) + ordersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION + deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE + payload := &internalmessages.CreateUpdateOrders{ + HasDependents: handlers.FmtBool(hasDependents), + SpouseHasProGear: handlers.FmtBool(spouseHasProGear), + IssueDate: handlers.FmtDate(issueDate), + ReportByDate: handlers.FmtDate(reportByDate), + OrdersType: internalmessages.NewOrdersType(ordersType), + OriginDutyLocationID: *handlers.FmtUUIDPtr(&originDutyLocation.ID), + NewDutyLocationID: handlers.FmtUUID(dutyLocation.ID), + ServiceMemberID: handlers.FmtUUID(sm.ID), + OrdersNumber: handlers.FmtString("123456"), + Tac: handlers.FmtString("E19A"), + Sac: handlers.FmtString("SacNumber"), + DepartmentIndicator: internalmessages.NewDeptIndicator(deptIndicator), + Grade: models.ServiceMemberGradeE1.Pointer(), + AccompaniedTour: models.BoolPointer(true), + DependentsTwelveAndOver: models.Int64Pointer(5), + DependentsUnderTwelve: models.Int64Pointer(5), } + + params := ordersop.CreateOrdersParams{ + HTTPRequest: req, + CreateOrders: payload, + } + + fakeS3 := storageTest.NewFakeS3Storage(true) + handlerConfig := suite.HandlerConfig() + handlerConfig.SetFileStorer(fakeS3) + createHandler := CreateOrdersHandler{handlerConfig} + response := createHandler.Handle(params) + + suite.Assertions.IsType(&ordersop.CreateOrdersCreated{}, response) + okResponse := response.(*ordersop.CreateOrdersCreated) + + orderID := okResponse.Payload.ID.String() + createdOrder, _ := models.FetchOrder(suite.DB(), uuid.FromStringOrNil(orderID)) + var createdEntitlement models.Entitlement + err = suite.DB().Find(&createdEntitlement, createdOrder.EntitlementID) + suite.NoError(err) + suite.NotEmpty(createdEntitlement) + suite.Assertions.Equal(sm.ID.String(), okResponse.Payload.ServiceMemberID.String()) + suite.Assertions.Len(okResponse.Payload.Moves, 1) + suite.Assertions.Equal(ordersType, *okResponse.Payload.OrdersType) + suite.Assertions.Equal(handlers.FmtString("123456"), okResponse.Payload.OrdersNumber) + suite.Assertions.Equal(handlers.FmtString("MAPK"), okResponse.Payload.OriginDutyLocationGbloc) + suite.Assertions.Equal(handlers.FmtString("E19A"), okResponse.Payload.Tac) + suite.Assertions.Equal(handlers.FmtString("SacNumber"), okResponse.Payload.Sac) + suite.Assertions.Equal(&deptIndicator, okResponse.Payload.DepartmentIndicator) + suite.Assertions.Equal(*models.Int64Pointer(8000), *okResponse.Payload.AuthorizedWeight) + suite.NotNil(&createdOrder.Entitlement) + suite.NotEmpty(createdOrder.SupplyAndServicesCostEstimate) + suite.NotEmpty(createdOrder.PackingAndShippingInstructions) + suite.NotEmpty(createdOrder.MethodOfPayment) + suite.NotEmpty(createdOrder.NAICS) + suite.NotNil(createdEntitlement.AccompaniedTour) + suite.NotNil(createdEntitlement.DependentsTwelveAndOver) + suite.NotNil(createdEntitlement.DependentsUnderTwelve) + }) suite.Run("properly handles entitlement validation", func() { + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99506") + suite.NotNil(usprc) + suite.FatalNoError(err) + address := factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ - IsOconus: models.BoolPointer(true), + IsOconus: models.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, }, }, }, nil) @@ -149,17 +263,43 @@ func (suite *HandlerSuite) TestCreateOrder() { originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ { Model: models.DutyLocation{ - Name: factory.MakeRandomString(8), + Name: factory.MakeRandomString(8), + AddressID: address.ID, }, }, - { - Model: address, - LinkOnly: true, - }, }, nil) dutyLocation := factory.FetchOrBuildCurrentDutyLocation(suite.DB()) - factory.FetchOrBuildPostalCodeToGBLOC(suite.DB(), dutyLocation.Address.PostalCode, "KKFA") + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: models.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + + us_country, err := models.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) + + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MBFL") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + factory.FetchOrBuildDefaultContractor(suite.DB(), nil, nil) req := httptest.NewRequest("POST", "/orders", nil) @@ -577,144 +717,272 @@ func (suite *HandlerSuite) TestUploadAmendedOrdersHandlerIntegration() { func (suite *HandlerSuite) TestUpdateOrdersHandler() { waf := entitlements.NewWeightAllotmentFetcher() - suite.Run("Can update CONUS and OCONUS orders", func() { - testCases := []struct { - isOconus bool - }{ - {isOconus: true}, - {isOconus: false}, - } - - for _, tc := range testCases { - address := factory.BuildAddress(suite.DB(), []factory.Customization{ - { - Model: models.Address{ - IsOconus: &tc.isOconus, - }, + suite.Run("Can update CONUS orders", func() { + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(false), }, - }, nil) + }, + }, nil) - // Set duty location to either CONUS or OCONUS - dutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - { - Model: models.DutyLocation{ - ProvidesServicesCounseling: false, - }, + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + Name: factory.MakeRandomString(8), }, - { - Model: address, - LinkOnly: true, + }, + { + Model: address, + LinkOnly: true, + }, + }, nil) + order := factory.BuildOrder(suite.DB(), []factory.Customization{ + { + Model: originDutyLocation, + LinkOnly: true, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + }, nil) + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: order, + LinkOnly: true, + }}, nil) + + newDutyLocation := factory.BuildDutyLocation(suite.DB(), nil, nil) + + newOrdersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION + newOrdersNumber := "123456" + issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) + reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) + deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE + + payload := &internalmessages.CreateUpdateOrders{ + OrdersNumber: handlers.FmtString(newOrdersNumber), + OrdersType: &newOrdersType, + NewDutyLocationID: handlers.FmtUUID(newDutyLocation.ID), + OriginDutyLocationID: *handlers.FmtUUID(*order.OriginDutyLocationID), + IssueDate: handlers.FmtDate(issueDate), + ReportByDate: handlers.FmtDate(reportByDate), + DepartmentIndicator: &deptIndicator, + HasDependents: handlers.FmtBool(false), + SpouseHasProGear: handlers.FmtBool(false), + Grade: models.ServiceMemberGradeE4.Pointer(), + MoveID: *handlers.FmtUUID(move.ID), + CounselingOfficeID: handlers.FmtUUID(*newDutyLocation.TransportationOfficeID), + ServiceMemberID: handlers.FmtUUID(order.ServiceMemberID), + } + + path := fmt.Sprintf("/orders/%v", order.ID.String()) + req := httptest.NewRequest("PUT", path, nil) + req = suite.AuthenticateRequest(req, order.ServiceMember) + + params := ordersop.UpdateOrdersParams{ + HTTPRequest: req, + OrdersID: *handlers.FmtUUID(order.ID), + UpdateOrders: payload, + } + + fakeS3 := storageTest.NewFakeS3Storage(true) + handlerConfig := suite.HandlerConfig() + handlerConfig.SetFileStorer(fakeS3) + + handler := UpdateOrdersHandler{handlerConfig} + + response := handler.Handle(params) + + suite.IsType(&ordersop.UpdateOrdersOK{}, response) + okResponse := response.(*ordersop.UpdateOrdersOK) + + suite.NoError(okResponse.Payload.Validate(strfmt.Default)) + suite.Equal(string(newOrdersType), string(*okResponse.Payload.OrdersType)) + suite.Equal(newOrdersNumber, *okResponse.Payload.OrdersNumber) + + updatedOrder, err := models.FetchOrder(suite.DB(), order.ID) + suite.NoError(err) + suite.Equal(payload.Grade, updatedOrder.Grade) + suite.Equal(*okResponse.Payload.AuthorizedWeight, int64(7000)) // E4 authorized weight is 7000, make sure we return that in the response + expectedUpdatedOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*updatedOrder.Grade), updatedOrder.OrdersType) + suite.NoError(err) + expectedUpdatedOrderAuthorizedWeight := expectedUpdatedOrderWeightAllotment.TotalWeightSelf + if *payload.HasDependents { + expectedUpdatedOrderAuthorizedWeight = expectedUpdatedOrderWeightAllotment.TotalWeightSelfPlusDependents + } + + expectedOriginalOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*order.Grade), updatedOrder.OrdersType) + suite.NoError(err) + expectedOriginalOrderAuthorizedWeight := expectedOriginalOrderWeightAllotment.TotalWeightSelf + if *payload.HasDependents { + expectedUpdatedOrderAuthorizedWeight = expectedOriginalOrderWeightAllotment.TotalWeightSelfPlusDependents + } + + suite.Equal(expectedUpdatedOrderAuthorizedWeight, 7000) // Ensure that when GetWeightAllotment is recalculated that it also returns 7000. This ensures that the database stored the correct information + suite.Equal(expectedOriginalOrderAuthorizedWeight, 5000) // The order was created as an E1. Ensure that the E1 authorized weight is 5000. + suite.Equal(string(newOrdersType), string(updatedOrder.OrdersType)) + // Check updated entitlement + var updatedEntitlement models.Entitlement + err = suite.DB().Find(&updatedEntitlement, updatedOrder.EntitlementID) + suite.NoError(err) + suite.NotEmpty(updatedEntitlement) + + suite.Nil(updatedEntitlement.AccompaniedTour) + suite.Nil(updatedEntitlement.DependentsTwelveAndOver) + suite.Nil(updatedEntitlement.DependentsUnderTwelve) + }) + + suite.Run("Can update OCONUS orders", func() { + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801") + suite.NotNil(usprc) + suite.FatalNoError(err) + + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, }, - }, nil) - order := factory.BuildOrder(suite.DB(), []factory.Customization{ - { - Model: dutyLocation, - LinkOnly: true, - Type: &factory.DutyLocations.OriginDutyLocation, + }, + }, nil) + + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + Name: factory.MakeRandomString(8), + AddressID: address.ID, }, - }, nil) - move := factory.BuildMove(suite.DB(), []factory.Customization{ - { - Model: order, - LinkOnly: true, - }}, nil) - - newDutyLocation := factory.BuildDutyLocation(suite.DB(), nil, nil) - newTransportationOffice := factory.BuildTransportationOffice(suite.DB(), nil, nil) - newDutyLocation.TransportationOffice = newTransportationOffice - - newOrdersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION - newOrdersNumber := "123456" - issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) - reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) - deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE - - payload := &internalmessages.CreateUpdateOrders{ - OrdersNumber: handlers.FmtString(newOrdersNumber), - OrdersType: &newOrdersType, - NewDutyLocationID: handlers.FmtUUID(newDutyLocation.ID), - OriginDutyLocationID: *handlers.FmtUUID(*order.OriginDutyLocationID), - IssueDate: handlers.FmtDate(issueDate), - ReportByDate: handlers.FmtDate(reportByDate), - DepartmentIndicator: &deptIndicator, - HasDependents: handlers.FmtBool(false), - SpouseHasProGear: handlers.FmtBool(false), - Grade: models.ServiceMemberGradeE4.Pointer(), - MoveID: *handlers.FmtUUID(move.ID), - CounselingOfficeID: handlers.FmtUUID(*newDutyLocation.TransportationOfficeID), - ServiceMemberID: handlers.FmtUUID(order.ServiceMemberID), - } - // The default move factory does not include OCONUS fields, set these - // new fields conditionally for the update - if tc.isOconus { - payload.AccompaniedTour = models.BoolPointer(true) - payload.DependentsTwelveAndOver = models.Int64Pointer(5) - payload.DependentsUnderTwelve = models.Int64Pointer(5) - } + }, + }, nil) - path := fmt.Sprintf("/orders/%v", order.ID.String()) - req := httptest.NewRequest("PUT", path, nil) - req = suite.AuthenticateRequest(req, order.ServiceMember) + order := factory.BuildOrder(suite.DB(), []factory.Customization{ + { + Model: originDutyLocation, + LinkOnly: true, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + }, nil) - params := ordersop.UpdateOrdersParams{ - HTTPRequest: req, - OrdersID: *handlers.FmtUUID(order.ID), - UpdateOrders: payload, - } + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: order, + LinkOnly: true, + }}, nil) - fakeS3 := storageTest.NewFakeS3Storage(true) - handlerConfig := suite.HandlerConfig() - handlerConfig.SetFileStorer(fakeS3) + newDutyLocation := factory.BuildDutyLocation(suite.DB(), nil, nil) - handler := UpdateOrdersHandler{handlerConfig} + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - response := handler.Handle(params) + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: models.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + suite.Nil(err) - suite.IsType(&ordersop.UpdateOrdersOK{}, response) - okResponse := response.(*ordersop.UpdateOrdersOK) + us_country, err := models.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) - suite.NoError(okResponse.Payload.Validate(strfmt.Default)) - suite.Equal(string(newOrdersType), string(*okResponse.Payload.OrdersType)) - suite.Equal(newOrdersNumber, *okResponse.Payload.OrdersNumber) + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) - updatedOrder, err := models.FetchOrder(suite.DB(), order.ID) - suite.NoError(err) - suite.Equal(payload.Grade, updatedOrder.Grade) - suite.Equal(*okResponse.Payload.AuthorizedWeight, int64(7000)) // E4 authorized weight is 7000, make sure we return that in the response - expectedUpdatedOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*updatedOrder.Grade), updatedOrder.OrdersType) - suite.NoError(err) - expectedUpdatedOrderAuthorizedWeight := expectedUpdatedOrderWeightAllotment.TotalWeightSelf - if *payload.HasDependents { - expectedUpdatedOrderAuthorizedWeight = expectedUpdatedOrderWeightAllotment.TotalWeightSelfPlusDependents - } + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.Nil(err) - expectedOriginalOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*order.Grade), updatedOrder.OrdersType) - suite.NoError(err) - expectedOriginalOrderAuthorizedWeight := expectedOriginalOrderWeightAllotment.TotalWeightSelf - if *payload.HasDependents { - expectedUpdatedOrderAuthorizedWeight = expectedOriginalOrderWeightAllotment.TotalWeightSelfPlusDependents - } + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) - suite.Equal(expectedUpdatedOrderAuthorizedWeight, 7000) // Ensure that when GetWeightAllotment is recalculated that it also returns 7000. This ensures that the database stored the correct information - suite.Equal(expectedOriginalOrderAuthorizedWeight, 5000) // The order was created as an E1. Ensure that the E1 authorized weight is 5000. - suite.Equal(string(newOrdersType), string(updatedOrder.OrdersType)) - // Check updated entitlement - var updatedEntitlement models.Entitlement - err = suite.DB().Find(&updatedEntitlement, updatedOrder.EntitlementID) - suite.NoError(err) - suite.NotEmpty(updatedEntitlement) - - if tc.isOconus { - suite.NotNil(updatedEntitlement.AccompaniedTour) - suite.NotNil(updatedEntitlement.DependentsTwelveAndOver) - suite.NotNil(updatedEntitlement.DependentsUnderTwelve) - } else { - suite.Nil(updatedEntitlement.AccompaniedTour) - suite.Nil(updatedEntitlement.DependentsTwelveAndOver) - suite.Nil(updatedEntitlement.DependentsUnderTwelve) - } + newOrdersType := internalmessages.OrdersTypePERMANENTCHANGEOFSTATION + newOrdersNumber := "123456" + issueDate := time.Date(2018, time.March, 10, 0, 0, 0, 0, time.UTC) + reportByDate := time.Date(2018, time.August, 1, 0, 0, 0, 0, time.UTC) + deptIndicator := internalmessages.DeptIndicatorAIRANDSPACEFORCE + + payload := &internalmessages.CreateUpdateOrders{ + OrdersNumber: handlers.FmtString(newOrdersNumber), + OrdersType: &newOrdersType, + NewDutyLocationID: handlers.FmtUUID(newDutyLocation.ID), + OriginDutyLocationID: *handlers.FmtUUID(*order.OriginDutyLocationID), + IssueDate: handlers.FmtDate(issueDate), + ReportByDate: handlers.FmtDate(reportByDate), + DepartmentIndicator: &deptIndicator, + HasDependents: handlers.FmtBool(false), + SpouseHasProGear: handlers.FmtBool(false), + Grade: models.ServiceMemberGradeE4.Pointer(), + MoveID: *handlers.FmtUUID(move.ID), + CounselingOfficeID: handlers.FmtUUID(*newDutyLocation.TransportationOfficeID), + ServiceMemberID: handlers.FmtUUID(order.ServiceMemberID), + } + + payload.AccompaniedTour = models.BoolPointer(true) + payload.DependentsTwelveAndOver = models.Int64Pointer(5) + payload.DependentsUnderTwelve = models.Int64Pointer(5) + + path := fmt.Sprintf("/orders/%v", order.ID.String()) + req := httptest.NewRequest("PUT", path, nil) + req = suite.AuthenticateRequest(req, order.ServiceMember) + + params := ordersop.UpdateOrdersParams{ + HTTPRequest: req, + OrdersID: *handlers.FmtUUID(order.ID), + UpdateOrders: payload, } + + fakeS3 := storageTest.NewFakeS3Storage(true) + handlerConfig := suite.HandlerConfig() + handlerConfig.SetFileStorer(fakeS3) + + handler := UpdateOrdersHandler{handlerConfig} + + response := handler.Handle(params) + + suite.IsType(&ordersop.UpdateOrdersOK{}, response) + okResponse := response.(*ordersop.UpdateOrdersOK) + + suite.NoError(okResponse.Payload.Validate(strfmt.Default)) + suite.Equal(string(newOrdersType), string(*okResponse.Payload.OrdersType)) + suite.Equal(newOrdersNumber, *okResponse.Payload.OrdersNumber) + + updatedOrder, err := models.FetchOrder(suite.DB(), order.ID) + suite.NoError(err) + suite.Equal(payload.Grade, updatedOrder.Grade) + suite.Equal(*okResponse.Payload.AuthorizedWeight, int64(7000)) // E4 authorized weight is 7000, make sure we return that in the response + expectedUpdatedOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*updatedOrder.Grade), updatedOrder.OrdersType) + suite.NoError(err) + expectedUpdatedOrderAuthorizedWeight := expectedUpdatedOrderWeightAllotment.TotalWeightSelf + if *payload.HasDependents { + expectedUpdatedOrderAuthorizedWeight = expectedUpdatedOrderWeightAllotment.TotalWeightSelfPlusDependents + } + + expectedOriginalOrderWeightAllotment, err := waf.GetWeightAllotment(suite.AppContextForTest(), string(*order.Grade), updatedOrder.OrdersType) + suite.NoError(err) + expectedOriginalOrderAuthorizedWeight := expectedOriginalOrderWeightAllotment.TotalWeightSelf + if *payload.HasDependents { + expectedUpdatedOrderAuthorizedWeight = expectedOriginalOrderWeightAllotment.TotalWeightSelfPlusDependents + } + + suite.Equal(expectedUpdatedOrderAuthorizedWeight, 7000) // Ensure that when GetWeightAllotment is recalculated that it also returns 7000. This ensures that the database stored the correct information + suite.Equal(expectedOriginalOrderAuthorizedWeight, 5000) // The order was created as an E1. Ensure that the E1 authorized weight is 5000. + suite.Equal(string(newOrdersType), string(updatedOrder.OrdersType)) + // Check updated entitlement + var updatedEntitlement models.Entitlement + err = suite.DB().Find(&updatedEntitlement, updatedOrder.EntitlementID) + suite.NoError(err) + suite.NotEmpty(updatedEntitlement) + + suite.NotNil(updatedEntitlement.AccompaniedTour) + suite.NotNil(updatedEntitlement.DependentsTwelveAndOver) + suite.NotNil(updatedEntitlement.DependentsUnderTwelve) }) + } func (suite *HandlerSuite) TestUpdateOrdersHandlerOriginPostalCodeAndGBLOC() { diff --git a/pkg/handlers/primeapi/payloads/model_to_payload.go b/pkg/handlers/primeapi/payloads/model_to_payload.go index 8dc07ccaa32..af39f03827f 100644 --- a/pkg/handlers/primeapi/payloads/model_to_payload.go +++ b/pkg/handlers/primeapi/payloads/model_to_payload.go @@ -35,9 +35,11 @@ func MoveTaskOrder(appCtx appcontext.AppContext, moveTaskOrder *models.Move) *pr if err != nil { destGbloc = "" } - destZip, err = moveTaskOrder.GetDestinationPostalCode(db) + destinationAddress, err := moveTaskOrder.GetDestinationAddress(appCtx.DB()) if err != nil { destZip = "" + } else { + destZip = destinationAddress.PostalCode } payload := &primemessages.MoveTaskOrder{ @@ -92,9 +94,11 @@ func ListMove(move *models.Move, appCtx appcontext.AppContext, moveOrderAmendmen if err != nil { destGbloc = "" } - destZip, err = move.GetDestinationPostalCode(db) + destinationAddress, err := move.GetDestinationAddress(appCtx.DB()) if err != nil { destZip = "" + } else { + destZip = destinationAddress.PostalCode } payload := &primemessages.ListMove{ diff --git a/pkg/handlers/primeapiv2/payloads/model_to_payload.go b/pkg/handlers/primeapiv2/payloads/model_to_payload.go index 0950f80eafe..3a49ba8b5fb 100644 --- a/pkg/handlers/primeapiv2/payloads/model_to_payload.go +++ b/pkg/handlers/primeapiv2/payloads/model_to_payload.go @@ -32,9 +32,11 @@ func MoveTaskOrder(appCtx appcontext.AppContext, moveTaskOrder *models.Move) *pr if err != nil { destGbloc = "" } - destZip, err = moveTaskOrder.GetDestinationPostalCode(db) + destinationAddress, err := moveTaskOrder.GetDestinationAddress(appCtx.DB()) if err != nil { destZip = "" + } else { + destZip = destinationAddress.PostalCode } payload := &primev2messages.MoveTaskOrder{ diff --git a/pkg/handlers/primeapiv3/payloads/model_to_payload.go b/pkg/handlers/primeapiv3/payloads/model_to_payload.go index 6a2848fb5d6..7393e60cf56 100644 --- a/pkg/handlers/primeapiv3/payloads/model_to_payload.go +++ b/pkg/handlers/primeapiv3/payloads/model_to_payload.go @@ -35,9 +35,11 @@ func MoveTaskOrder(appCtx appcontext.AppContext, moveTaskOrder *models.Move) *pr if err != nil { destGbloc = "" } - destZip, err = moveTaskOrder.GetDestinationPostalCode(db) + destinationAddress, err := moveTaskOrder.GetDestinationAddress(appCtx.DB()) if err != nil { destZip = "" + } else { + destZip = destinationAddress.PostalCode } payload := &primev3messages.MoveTaskOrder{ diff --git a/pkg/models/address.go b/pkg/models/address.go index d89a163c9aa..29a6bedbcbb 100644 --- a/pkg/models/address.go +++ b/pkg/models/address.go @@ -211,3 +211,17 @@ func EvaluateIsOconus(address Address) bool { return false } } + +// Fetches the GBLOC for a specific Address (for now this will be used for OCONUS) +func FetchAddressGbloc(db *pop.Connection, address Address, serviceMember ServiceMember) (*string, error) { + var gbloc *string + + err := db.RawQuery("SELECT * FROM get_address_gbloc($1, $2)", address.ID, serviceMember.Affiliation.String()). + First(&gbloc) + + if err != nil { + return nil, err + } + + return gbloc, nil +} diff --git a/pkg/models/address_test.go b/pkg/models/address_test.go index f2fbb5bf45c..9dfe5a7fa1c 100644 --- a/pkg/models/address_test.go +++ b/pkg/models/address_test.go @@ -1,8 +1,13 @@ package models_test import ( + "fmt" + + "github.com/gofrs/uuid" + "github.com/transcom/mymove/pkg/factory" m "github.com/transcom/mymove/pkg/models" + "github.com/transcom/mymove/pkg/testdatagen" ) func (suite *ModelSuite) TestBasicAddressInstantiation() { @@ -190,3 +195,193 @@ func (suite *ModelSuite) TestPartialAddressFormat() { suite.Equal("street 1, city, state 90210", formattedAddress) } + +func (suite *ModelSuite) Test_FetchDutyLocationGblocForAK() { + setupDataForOconusDutyLocation := func(postalCode string) (m.OconusRateArea, m.UsPostRegionCity, m.DutyLocation) { + usprc, err := m.FindByZipCode(suite.AppContextForTest().DB(), postalCode) + suite.NotNil(usprc) + suite.FatalNoError(err) + + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: m.Address{ + IsOconus: m.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, + }, + }, + }, nil) + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: address, + LinkOnly: true, + Type: &factory.Addresses.DutyLocationAddress, + }, + }, nil) + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: m.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + suite.Nil(err) + + us_country, err := m.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + oconusRateArea, err := m.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) + + return *oconusRateArea, *usprc, originDutyLocation + } + + suite.Run("fetches duty location GBLOC for AK address, Zone II AirForce", func() { + oconusRateArea, _, originDutyLocation := setupDataForOconusDutyLocation("99707") + + airForce := m.AffiliationAIRFORCE + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + { + Model: m.ServiceMember{ + Affiliation: &airForce, + }, + }, + }, nil) + + jppsoRegion, err := m.FetchJppsoRegionByCode(suite.DB(), "MBFL") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := m.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, m.DepartmentIndicatorAIRANDSPACEFORCE.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + gbloc, err := m.FetchAddressGbloc(suite.DB(), originDutyLocation.Address, serviceMember) + suite.NoError(err) + suite.NotNil(gbloc) + suite.Equal(string(*gbloc), "MBFL") + }) + + suite.Run("fetches duty location GBLOC for AK address, Zone II Army", func() { + oconusRateArea, _, originDutyLocation := setupDataForOconusDutyLocation("99707") + + army := m.AffiliationARMY + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + { + Model: m.ServiceMember{ + Affiliation: &army, + }, + }, + }, nil) + + jppsoRegion, err := m.FetchJppsoRegionByCode(suite.DB(), "JEAT") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := m.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, m.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + gbloc, err := m.FetchAddressGbloc(suite.DB(), originDutyLocation.Address, serviceMember) + suite.NoError(err) + suite.NotNil(gbloc) + suite.Equal(string(*gbloc), "JEAT") + }) + + suite.Run("fetches duty location GBLOC for AK Cordova address, Zone IV", func() { + usprc, err := m.FindByZipCodeAndCity(suite.AppContextForTest().DB(), "99574", "CORDOVA") + suite.NotNil(usprc) + suite.FatalNoError(err) + + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: m.Address{ + IsOconus: m.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, + }, + }, + }, nil) + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: address, + LinkOnly: true, + Type: &factory.Addresses.DutyLocationAddress, + }, + }, nil) + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: m.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) + + us_country, err := m.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + oconusRateArea, err := m.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) + army := m.AffiliationARMY + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + { + Model: m.ServiceMember{ + Affiliation: &army, + }, + }, + }, nil) + + jppsoRegion, err := m.FetchJppsoRegionByCode(suite.DB(), "MAPS") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := m.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, m.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + gbloc, err := m.FetchAddressGbloc(suite.DB(), originDutyLocation.Address, serviceMember) + suite.NoError(err) + suite.NotNil(gbloc) + suite.Equal(string(*gbloc), "MAPS") + }) + + suite.Run("fetches duty location GBLOC for AK NOT Cordova address, Zone IV", func() { + oconusRateArea, _, originDutyLocation := setupDataForOconusDutyLocation("99803") + + army := m.AffiliationARMY + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + { + Model: m.ServiceMember{ + Affiliation: &army, + }, + }, + }, nil) + + jppsoRegion, err := m.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.Nil(err) + + gblocAors, err := m.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, m.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) + + gbloc, err := m.FetchAddressGbloc(suite.DB(), originDutyLocation.Address, serviceMember) + suite.NoError(err) + suite.NotNil(gbloc) + suite.Equal(string(*gbloc), "MAPK") + }) +} diff --git a/pkg/models/gbloc_aors.go b/pkg/models/gbloc_aors.go index e4fa1612355..132de00bbb1 100644 --- a/pkg/models/gbloc_aors.go +++ b/pkg/models/gbloc_aors.go @@ -3,6 +3,7 @@ package models import ( "time" + "github.com/gobuffalo/pop/v6" "github.com/gofrs/uuid" ) @@ -19,3 +20,17 @@ type GblocAors struct { func (c GblocAors) TableName() string { return "gbloc_aors" } + +func FetchGblocAorsByJppsoCodeRateAreaDept(db *pop.Connection, jppsoRegionId uuid.UUID, oconusRateAreaId uuid.UUID, deptInd string) (*GblocAors, error) { + var gblocAors GblocAors + err := db.Q(). + InnerJoin("jppso_regions jr", "gbloc_aors.jppso_regions_id = jr.id"). + Where("gbloc_aors.oconus_rate_area_id = ?", oconusRateAreaId). + Where("(gbloc_aors.department_indicator = ? or gbloc_aors.department_indicator is null)", deptInd). + Where("jr.id = ?", jppsoRegionId). + First(&gblocAors) + if err != nil { + return nil, err + } + return &gblocAors, nil +} diff --git a/pkg/models/gbloc_aors_test.go b/pkg/models/gbloc_aors_test.go new file mode 100644 index 00000000000..7e35492e58a --- /dev/null +++ b/pkg/models/gbloc_aors_test.go @@ -0,0 +1,22 @@ +package models_test + +import ( + "github.com/transcom/mymove/pkg/models" +) + +func (suite *ModelSuite) TestFetchGblocAorsByJppsoCodeRateAreaDept() { + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801") + suite.NotNil(usprc) + suite.FatalNoError(err) + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.NoError(err) + + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.NoError(err) + + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.NoError(err) +} diff --git a/pkg/models/jppso_regions.go b/pkg/models/jppso_regions.go index 0788c78abb2..aefb3ea106f 100644 --- a/pkg/models/jppso_regions.go +++ b/pkg/models/jppso_regions.go @@ -3,6 +3,7 @@ package models import ( "time" + "github.com/gobuffalo/pop/v6" "github.com/gofrs/uuid" ) @@ -18,3 +19,14 @@ type JppsoRegions struct { func (c JppsoRegions) TableName() string { return "jppso_regions" } + +func FetchJppsoRegionByCode(db *pop.Connection, code string) (*JppsoRegions, error) { + var jppsoRegions JppsoRegions + err := db.Q(). + Where("jppso_regions.code = ?", code). + First(&jppsoRegions) + if err != nil { + return nil, err + } + return &jppsoRegions, nil +} diff --git a/pkg/models/jppso_regions_test.go b/pkg/models/jppso_regions_test.go new file mode 100644 index 00000000000..21da54ea898 --- /dev/null +++ b/pkg/models/jppso_regions_test.go @@ -0,0 +1,12 @@ +package models_test + +import ( + "github.com/transcom/mymove/pkg/models" +) + +func (suite *ModelSuite) TestFetchJppsoRegionByCode() { + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK") + suite.NotNil(jppsoRegion) + suite.NoError(err) + suite.Equal("USCG Base Ketchikan", jppsoRegion.Name) +} diff --git a/pkg/models/move.go b/pkg/models/move.go index f0b3ac49269..e3b1b889bf8 100644 --- a/pkg/models/move.go +++ b/pkg/models/move.go @@ -203,48 +203,63 @@ func FetchMove(db *pop.Connection, session *auth.Session, id uuid.UUID) (*Move, return &move, nil } -// GetDestinationPostalCode returns the postal code for the move. This ensures that business logic is centralized. -func (m Move) GetDestinationPostalCode(db *pop.Connection) (string, error) { +// GetDestinationGBLOC returns the GBLOC for the move. This ensures that business logic is centralized. +func (m Move) GetDestinationGBLOC(db *pop.Connection) (string, error) { // Since this requires looking up the move in the DB, the move must have an ID. This means, the move has to have been created first. if uuid.UUID.IsNil(m.ID) { - return "", errors.WithMessage(ErrInvalidOrderID, "You must created the move in the DB before getting the destination Postal Code.") + return "", errors.WithMessage(ErrInvalidOrderID, "You must created the move in the DB before getting the destination GBLOC.") } - err := db.Load(&m, "Orders") + destinationAddress, err := m.GetDestinationAddress(db) if err != nil { - if err.Error() == RecordNotFoundErrorString { - return "", errors.WithMessage(err, "No Orders found in the DB associated with moveID "+m.ID.String()) - } return "", err } - var gblocsMap map[uuid.UUID]string - gblocsMap, err = m.Orders.GetDestinationPostalCodeForAssociatedMoves(db) - if err != nil { - return "", err + var newGBLOC string + if *destinationAddress.IsOconus { + err := db.Load(&m.Orders, "ServiceMember") + if err != nil { + if err.Error() == RecordNotFoundErrorString { + return "", errors.WithMessage(err, "No Service Member found in the DB associated with moveID "+m.ID.String()) + } + return "", err + } + newGBLOCOconus, err := FetchAddressGbloc(db, *destinationAddress, m.Orders.ServiceMember) + if err != nil { + return "", err + } + newGBLOC = *newGBLOCOconus + } else { + newGBLOCConus, err := FetchGBLOCForPostalCode(db, destinationAddress.PostalCode) + if err != nil { + return "", err + } + newGBLOC = newGBLOCConus.GBLOC } - return gblocsMap[m.ID], nil + + return newGBLOC, err } -// GetDestinationGBLOC returns the GBLOC for the move. This ensures that business logic is centralized. -func (m Move) GetDestinationGBLOC(db *pop.Connection) (string, error) { +// GetDestinationAddress returns the address for the move. This ensures that business logic is centralized. +func (m Move) GetDestinationAddress(db *pop.Connection) (*Address, error) { // Since this requires looking up the move in the DB, the move must have an ID. This means, the move has to have been created first. if uuid.UUID.IsNil(m.ID) { - return "", errors.WithMessage(ErrInvalidOrderID, "You must created the move in the DB before getting the destination GBLOC.") + return nil, errors.WithMessage(ErrInvalidOrderID, "You must created the move in the DB before getting the destination Postal Code.") } - postalCode, err := m.GetDestinationPostalCode(db) + err := db.Load(&m, "Orders") if err != nil { - return "", err + if err.Error() == RecordNotFoundErrorString { + return nil, errors.WithMessage(err, "No Orders found in the DB associated with moveID "+m.ID.String()) + } + return nil, err } - var gblocResult PostalCodeToGBLOC - gblocResult, err = FetchGBLOCForPostalCode(db, postalCode) + destinationAddress, err := m.Orders.GetDestinationAddressForAssociatedMoves(db) if err != nil { - return "", err + return nil, err } - - return gblocResult.GBLOC, err + return destinationAddress, nil } // CreateSignedCertification creates a new SignedCertification associated with this move diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index 66db8cb78d2..b3c69cb52bb 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -294,33 +294,6 @@ func GetCustomerFromShipment(db *pop.Connection, shipmentID uuid.UUID) (*Service return &serviceMember, nil } -func (m *MTOShipment) UpdateOrdersDestinationGBLOC(db *pop.Connection) error { - // Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first. - if uuid.UUID.IsNil(m.ID) { - return fmt.Errorf("error updating orders destination GBLOC for shipment due to no shipment ID provided") - } - - var err error - var order Order - - err = db.Load(&m, "MoveTaskOrder.OrdersID") - if err != nil { - return fmt.Errorf("error loading orders for shipment ID: %s with error %w", m.ID, err) - } - - order, err = FetchOrder(db, m.MoveTaskOrder.OrdersID) - if err != nil { - return fmt.Errorf("error fetching order for shipment ID: %s with error %w", m.ID, err) - } - - err = order.UpdateDestinationGBLOC(db) - if err != nil { - return fmt.Errorf("error fetching GBLOC for postal code with error %w", err) - } - - return nil -} - // Helper function to check that an MTO Shipment contains a PPM Shipment func (m MTOShipment) ContainsAPPMShipment() bool { return m.PPMShipment != nil diff --git a/pkg/models/order.go b/pkg/models/order.go index 476b96b1d43..2b0601f17c7 100644 --- a/pkg/models/order.go +++ b/pkg/models/order.go @@ -482,45 +482,16 @@ func (o Order) FetchAllShipmentsExcludingRejected(db *pop.Connection) (map[uuid. } /* - * GetDestinationGBLOC returns a map of destination GBLOCs for the first shipments from all of - * the moves that are associated with an order. If there are no shipments returned on a particular move, - * it will return the GBLOC of the new duty station address for that move. - */ -func (o Order) GetDestinationGBLOC(db *pop.Connection) (map[uuid.UUID]string, error) { - // Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first. - if uuid.UUID.IsNil(o.ID) { - return nil, errors.WithMessage(ErrInvalidOrderID, "You must created the order in the DB before getting the destination GBLOC.") - } - - destinationPostalCodesMap, err := o.GetDestinationPostalCodeForAssociatedMoves(db) - if err != nil { - return nil, err - } - - destinationGBLOCsMap := make(map[uuid.UUID]string) - for k, v := range destinationPostalCodesMap { - var gblocResult PostalCodeToGBLOC - gblocResult, err = FetchGBLOCForPostalCode(db, v) - if err != nil { - return nil, errors.WithMessage(err, "Could not get GBLOC for postal code "+v+" for move ID "+k.String()) - } - destinationGBLOCsMap[k] = gblocResult.GBLOC - } - - return destinationGBLOCsMap, nil -} - -/* -* GetDestinationPostalCodeForAssociatedMove returns a map of Postal Codes of the destination address for the first shipments from each of +* GetDestinationAddressForAssociatedMoves returns the destination Address for the first shipments from each of * the moves that are associated with an order. If there are no shipments returned, it will return the -* Postal Code of the new duty station addresses. +* Address of the new duty station addresses. */ -func (o Order) GetDestinationPostalCodeForAssociatedMoves(db *pop.Connection) (map[uuid.UUID]string, error) { +func (o Order) GetDestinationAddressForAssociatedMoves(db *pop.Connection) (*Address, error) { if uuid.UUID.IsNil(o.ID) { - return nil, errors.WithMessage(ErrInvalidOrderID, "You must created the order in the DB before getting the destination Postal Code.") + return nil, errors.WithMessage(ErrInvalidOrderID, "You must create the order in the DB before getting the destination Address.") } - err := db.Load(&o, "Moves", "NewDutyLocation.Address.PostalCode") + err := db.Load(&o, "Moves", "NewDutyLocation.Address") if err != nil { if err.Error() == RecordNotFoundErrorString { return nil, errors.WithMessage(err, "No Moves were found for the order ID "+o.ID.String()) @@ -528,8 +499,8 @@ func (o Order) GetDestinationPostalCodeForAssociatedMoves(db *pop.Connection) (m return nil, err } - // zipsMap is a map of key, value pairs where the key is the move id and the value is the destination postal code - zipsMap := make(map[uuid.UUID]string) + // addrMap is a map of key, value pairs where the key is the move id and the value is the destination address + var destinationAddress Address for i, m := range o.Moves { err = db.Load(&o.Moves[i], "MTOShipments") if err != nil { @@ -563,71 +534,23 @@ func (o Order) GetDestinationPostalCodeForAssociatedMoves(db *pop.Connection) (m return shipments[i].CreatedAt.Before(shipments[j].CreatedAt) }) - var addressResult *Address - addressResult, err = shipments[0].GetDestinationAddress(db) + addressResult, err := shipments[0].GetDestinationAddress(db) if err != nil { - if err == ErrMissingDestinationAddress || err == ErrUnsupportedShipmentType { - zipsMap[o.Moves[i].ID] = o.NewDutyLocation.Address.PostalCode - } return nil, err } if addressResult != nil { - zipsMap[o.Moves[i].ID] = addressResult.PostalCode + destinationAddress = *addressResult } else { return nil, errors.WithMessage(ErrMissingDestinationAddress, "No destination address was able to be found for the order ID "+o.ID.String()) } } else { // No valid shipments, use new duty location - zipsMap[o.Moves[i].ID] = o.NewDutyLocation.Address.PostalCode + destinationAddress = o.NewDutyLocation.Address } } - if len(zipsMap) == 0 { - return nil, errors.New("No destination postal codes were found for the order ID " + o.ID.String()) - } - - return zipsMap, nil -} - -// UpdateDestinationGBLOC updates the destination GBLOC for the associated Order in the DB -func (o Order) UpdateDestinationGBLOC(db *pop.Connection) error { - // Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first. - if uuid.UUID.IsNil(o.ID) { - return errors.WithMessage(ErrInvalidOrderID, "You must created the order in the DB before updating the destination GBLOC.") - } - - var dbOrder Order - err := db.Find(&dbOrder, o.ID) - if err != nil { - if err.Error() == RecordNotFoundErrorString { - return errors.WithMessage(err, "No Order was found for the order ID "+o.ID.String()) - } - return err - } - - err = db.Load(&o, "NewDutyLocation.Address.PostalCode") - if err != nil { - if err.Error() == RecordNotFoundErrorString { - return errors.WithMessage(err, "No New Duty Location Address Postal Code was found for the order ID "+o.ID.String()) - } - return err - } - - var gblocResult PostalCodeToGBLOC - gblocResult, err = FetchGBLOCForPostalCode(db, o.NewDutyLocation.Address.PostalCode) - if err != nil { - return errors.WithMessage(err, "Could not get GBLOC for postal code "+o.NewDutyLocation.Address.PostalCode) - } - - dbOrder.DestinationGBLOC = &gblocResult.GBLOC - - err = db.Save(&dbOrder) - if err != nil { - return errors.WithMessage(err, "Could not save the updated destination GBLOC for order ID "+o.ID.String()) - } - - return nil + return &destinationAddress, nil } // IsCompleteForGBL checks if orders have all fields necessary to generate a GBL diff --git a/pkg/models/re_oconus_rate_areas.go b/pkg/models/re_oconus_rate_areas.go index 84def705f95..7003219ba9b 100644 --- a/pkg/models/re_oconus_rate_areas.go +++ b/pkg/models/re_oconus_rate_areas.go @@ -33,3 +33,14 @@ func FetchOconusRateArea(db *pop.Connection, zip string) (*OconusRateArea, error } return &reOconusRateArea, nil } + +func FetchOconusRateAreaByCityId(db *pop.Connection, usprc string) (*OconusRateArea, error) { + var reOconusRateArea OconusRateArea + err := db.Q(). + Where("re_oconus_rate_areas.us_post_region_cities_id = ?", usprc). + First(&reOconusRateArea) + if err != nil { + return nil, err + } + return &reOconusRateArea, nil +} diff --git a/pkg/models/re_oconus_rate_areas_test.go b/pkg/models/re_oconus_rate_areas_test.go new file mode 100644 index 00000000000..366bcff7daf --- /dev/null +++ b/pkg/models/re_oconus_rate_areas_test.go @@ -0,0 +1,14 @@ +package models_test + +import ( + "github.com/transcom/mymove/pkg/models" +) + +func (suite *ModelSuite) TestFetchOconusRateAreaByCityId() { + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801") + suite.NotNil(usprc) + suite.FatalNoError(err) + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.NoError(err) +} diff --git a/pkg/models/us_post_region_city.go b/pkg/models/us_post_region_city.go index 84e9a01941c..7267134f044 100644 --- a/pkg/models/us_post_region_city.go +++ b/pkg/models/us_post_region_city.go @@ -76,3 +76,19 @@ func FindByZipCode(db *pop.Connection, zipCode string) (*UsPostRegionCity, error } return &usprc, nil } + +func FindByZipCodeAndCity(db *pop.Connection, zipCode string, city string) (*UsPostRegionCity, error) { + var usprc UsPostRegionCity + err := db.Where("uspr_zip_id = ?", zipCode). + Where("u_s_post_region_city_nm = ?", city). + First(&usprc) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewEventError("No UsPostRegionCity found for provided zip code "+zipCode+" and city "+city+".", err) + default: + return nil, err + } + } + return &usprc, nil +} diff --git a/pkg/models/us_post_region_city_test.go b/pkg/models/us_post_region_city_test.go index 1654d1a817e..abadd9cdfe6 100644 --- a/pkg/models/us_post_region_city_test.go +++ b/pkg/models/us_post_region_city_test.go @@ -26,3 +26,12 @@ func (suite *ModelSuite) TestFindByZipCode() { suite.NoError(err) suite.Equal("LOS ANGELES", usPostRegionCity.UsprcCountyNm) } + +func (suite *ModelSuite) TestFindByZipCodeAndCity() { + + // Attempt to gather 99677's County from the 99677 zip code and CORDOVA city + usPostRegionCity, err := models.FindByZipCodeAndCity(suite.DB(), "99677", "CORDOVA") + suite.NotNil(usPostRegionCity) + suite.NoError(err) + suite.Equal("CHUGACH", usPostRegionCity.UsprcCountyNm) +} diff --git a/pkg/services/invoice/ghc_payment_request_invoice_generator.go b/pkg/services/invoice/ghc_payment_request_invoice_generator.go index fd111048868..4af73b9e28d 100644 --- a/pkg/services/invoice/ghc_payment_request_invoice_generator.go +++ b/pkg/services/invoice/ghc_payment_request_invoice_generator.go @@ -447,16 +447,26 @@ func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNames return apperror.NewQueryError("MTOShipments", err, fmt.Sprintf("error querying for shipments pickup address gbloc to use in N1*BY segments in PaymentRequest %s: %s", paymentRequestID, err)) } } - pickupPostalCodeToGbloc, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), address.PostalCode) - if gblocErr != nil { - return apperror.NewInvalidInputError(pickupPostalCodeToGbloc.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code") + var pickupPostalCodeToGbloc *string + if *address.IsOconus { + originDutyLocationGBLOCOconus, gblocErr := models.FetchAddressGbloc(appCtx.DB(), address, orders.ServiceMember) + if gblocErr != nil { + return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for Oconus pickup postal code") + } + pickupPostalCodeToGbloc = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if gblocErr != nil { + return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code") + } + pickupPostalCodeToGbloc = &originDutyLocationGBLOCConus.GBLOC } header.BuyerOrganizationName = edisegment.N1{ EntityIdentifierCode: "BY", Name: truncateStr(originDutyLocation.Name, maxLocationlength), IdentificationCodeQualifier: "92", - IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, pickupPostalCodeToGbloc.GBLOC), + IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, *pickupPostalCodeToGbloc), } // seller organization name @@ -482,9 +492,19 @@ func (g ghcPaymentRequestInvoiceGenerator) createOriginAndDestinationSegments(ap return apperror.NewConflictError(orders.ID, "Invalid Order, must have NewDutyLocation") } - destPostalCodeToGbloc, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), destinationDutyLocation.Address.PostalCode) - if gblocErr != nil { - return apperror.NewInvalidInputError(destinationDutyLocation.ID, gblocErr, nil, "unable to determine GBLOC for duty location postal code") + var destPostalCodeToGbloc *string + if *destinationDutyLocation.Address.IsOconus { + destPostalCodeToGblocOconus, gblocErr := models.FetchAddressGbloc(appCtx.DB(), destinationDutyLocation.Address, orders.ServiceMember) + if gblocErr != nil { + return apperror.NewInvalidInputError(destinationDutyLocation.ID, gblocErr, nil, "unable to determine GBLOC for Oconus duty location postal code") + } + destPostalCodeToGbloc = destPostalCodeToGblocOconus + } else { + ddestPostalCodeToGblocConus, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), destinationDutyLocation.Address.PostalCode) + if gblocErr != nil { + return apperror.NewInvalidInputError(destinationDutyLocation.ID, gblocErr, nil, "unable to determine GBLOC for duty location postal code") + } + destPostalCodeToGbloc = &ddestPostalCodeToGblocConus.GBLOC } // destination name @@ -492,7 +512,7 @@ func (g ghcPaymentRequestInvoiceGenerator) createOriginAndDestinationSegments(ap EntityIdentifierCode: "ST", Name: truncateStr(destinationDutyLocation.Name, maxLocationlength), IdentificationCodeQualifier: "10", - IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, destPostalCodeToGbloc.GBLOC), + IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, *destPostalCodeToGbloc), } // destination address diff --git a/pkg/services/move_task_order/move_task_order_fetcher.go b/pkg/services/move_task_order/move_task_order_fetcher.go index e2910fe1f37..b53b8351420 100644 --- a/pkg/services/move_task_order/move_task_order_fetcher.go +++ b/pkg/services/move_task_order/move_task_order_fetcher.go @@ -365,13 +365,23 @@ func (f moveTaskOrderFetcher) FetchMoveTaskOrder(appCtx appcontext.AppContext, s mto.MTOServiceItems = loadedServiceItems if mto.Orders.DestinationGBLOC == nil { - newDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode) - if err != nil { - err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") - appCtx.Logger().Error(err.Error()) - return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "") + var newDutyLocationGBLOC *string + if *mto.Orders.NewDutyLocation.Address.IsOconus { + newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), mto.Orders.NewDutyLocation.Address, mto.Orders.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(mto.Orders.NewDutyLocation.ID, "while looking for Duty Location Oconus GBLOC") + } + newDutyLocationGBLOC = newDutyLocationGBLOCOconus + } else { + newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode) + if err != nil { + err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") + appCtx.Logger().Error(err.Error()) + return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "") + } + newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC } - mto.Orders.DestinationGBLOC = &newDutyLocationGBLOC.GBLOC + mto.Orders.DestinationGBLOC = newDutyLocationGBLOC } return mto, nil diff --git a/pkg/services/order/order_updater.go b/pkg/services/order/order_updater.go index 12821783d7a..e08896380c3 100644 --- a/pkg/services/order/order_updater.go +++ b/pkg/services/order/order_updater.go @@ -730,16 +730,27 @@ func updateOrderInTx(appCtx appcontext.AppContext, order models.Order, checks .. order.OriginDutyLocationID = &originDutyLocation.ID order.OriginDutyLocation = &originDutyLocation - dutyLocationGBLOC, err2 := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if err2 != nil { - switch err2 { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") - default: - return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, order.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location Oconus GBLOC") } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err2 := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err2 != nil { + switch err2 { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") + default: + return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + } + } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } - order.OriginDutyLocationGBLOC = &dutyLocationGBLOC.GBLOC + + order.OriginDutyLocationGBLOC = originDutyLocationGBLOC } if order.Grade != nil || order.OriginDutyLocationID != nil { @@ -762,19 +773,29 @@ func updateOrderInTx(appCtx appcontext.AppContext, order models.Order, checks .. } } - newDestinationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) - if err != nil { - switch err { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(order.NewDutyLocationID, "while looking for DestinationGBLOC") - default: - return nil, apperror.NewQueryError("DestinationGBLOC", err, "") + var newDestinationGBLOC *string + if *newDutyLocation.Address.IsOconus { + newDestinationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), newDutyLocation.Address, order.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for DestinationGBLOC Oconus") + } + newDestinationGBLOC = newDestinationGBLOCOconus + } else { + newDestinationGBLOCConus, err2 := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode) + if err2 != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(order.NewDutyLocationID, "while looking for DestinationGBLOC") + default: + return nil, apperror.NewQueryError("DestinationGBLOC", err, "") + } } + newDestinationGBLOC = &newDestinationGBLOCConus.GBLOC } order.NewDutyLocationID = newDutyLocation.ID order.NewDutyLocation = newDutyLocation - order.DestinationGBLOC = &newDestinationGBLOC.GBLOC + order.DestinationGBLOC = newDestinationGBLOC } // Recalculate UB allowance of order entitlement diff --git a/pkg/services/support/move_task_order/move_task_order_creator.go b/pkg/services/support/move_task_order/move_task_order_creator.go index 85f3500c2de..d0bc162d54c 100644 --- a/pkg/services/support/move_task_order/move_task_order_creator.go +++ b/pkg/services/support/move_task_order/move_task_order_creator.go @@ -132,17 +132,27 @@ func createOrder(appCtx appcontext.AppContext, customer *models.ServiceMember, o order.OriginDutyLocation = originDutyLocation order.OriginDutyLocationID = &originDutyLocationID - var originDutyLocationGBLOC models.PostalCodeToGBLOC - originDutyLocationGBLOC, err = models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if err != nil { - switch err { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(originDutyLocationID, "while looking for Duty Location PostalCodeToGBLOC") - default: - return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, order.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location Oconus GBLOC") + } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") + default: + return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + } } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } - order.OriginDutyLocationGBLOC = &originDutyLocationGBLOC.GBLOC + + order.OriginDutyLocationGBLOC = originDutyLocationGBLOC } // Check that the uploaded orders document exists var uploadedOrders *models.Document diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 9ce5bab765c..cd8345a8aa6 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -3,16 +3,15 @@ package transportationoffice import ( "fmt" "testing" - "time" "github.com/gofrs/uuid" "github.com/stretchr/testify/suite" - "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/auth" "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/services" + "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/testingsuite" ) @@ -190,19 +189,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOffices() { } func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffices() { - testContractName := "Test_findOconusGblocDepartmentIndicator" - testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" - testPostalCode := "99790" - testPostalCode2 := "99701" - testGbloc := "ABCD" - testGbloc2 := "EFGH" - testTransportationName := "TEST - PPO" - testTransportationName2 := "TEST - PPO2" - - serviceAffiliations := []models.ServiceMemberAffiliation{models.AffiliationARMY, - models.AffiliationNAVY, models.AffiliationMARINES, models.AffiliationAIRFORCE, models.AffiliationCOASTGUARD, - models.AffiliationSPACEFORCE} - setupServiceMember := func(serviceMemberAffiliation models.ServiceMemberAffiliation) models.ServiceMember { customServiceMember := models.ServiceMember{ FirstName: models.StringPointer("Gregory"), @@ -234,48 +220,19 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi return serviceMember } - createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { - // See if contract code already exists. - exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) - if err != nil { - return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) - } - if exists { - return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) - } + setupDataForOconusSearchCounselingOffice := func(postalCode string, gbloc string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - // Contract code is new; insert it. - contract := models.ReContract{ - Code: contractCode, - Name: contractName, - } - verrs, err := appCtx.DB().ValidateAndSave(&contract) - if verrs.HasAny() { - return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) - } - if err != nil { - return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) - } - return &contract, nil - } - - setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] - rateArea := models.ReRateArea{ - ID: uuid.Must(uuid.NewV4()), - ContractID: contract.ID, - IsOconus: true, - Code: rateAreaCode, - Name: fmt.Sprintf("Alaska-%s", rateAreaCode), - Contract: contract, - } - verrs, err := suite.DB().ValidateAndCreate(&rateArea) - if verrs.HasAny() { - suite.Fail(verrs.Error()) - } - if err != nil { - suite.Fail(err.Error()) - } + rateArea := testdatagen.FetchOrMakeReRateArea(suite.DB(), testdatagen.Assertions{ + ReRateArea: models.ReRateArea{ + ContractID: contract.ID, + IsOconus: true, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + }, + }) + suite.NotNil(rateArea) us_country, err := models.FetchCountryByCode(suite.DB(), "US") suite.NotNil(us_country) @@ -285,32 +242,18 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi suite.NotNil(usprc) suite.FatalNoError(err) - oconusRateArea := models.OconusRateArea{ - ID: uuid.Must(uuid.NewV4()), - RateAreaId: rateArea.ID, - CountryId: us_country.ID, - UsPostRegionCityId: usprc.ID, - Active: true, - } - verrs, err = suite.DB().ValidateAndCreate(&oconusRateArea) - if verrs.HasAny() { - suite.Fail(verrs.Error()) - } - if err != nil { - suite.Fail(err.Error()) - } + oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String()) + suite.NotNil(oconusRateArea) + suite.Nil(err) - address := models.Address{ - StreetAddress1: "n/a", - City: "SomeCity", - State: "AK", - PostalCode: postalCode, - County: models.StringPointer("SomeCounty"), - IsOconus: models.BoolPointer(true), - UsPostRegionCityID: &usprc.ID, - CountryId: models.UUIDPointer(us_country.ID), - } - suite.MustSave(&address) + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + IsOconus: models.BoolPointer(true), + UsPostRegionCityID: &usprc.ID, + }, + }, + }, nil) origDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ { @@ -321,7 +264,7 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }, { Model: models.TransportationOffice{ - Name: transportationName, + Name: "TEST - PPO", Gbloc: gbloc, ProvidesCloseout: true, }, @@ -331,148 +274,68 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi found_duty_location, _ := models.FetchDutyLocation(suite.DB(), origDutyLocation.ID) - return rateArea, oconusRateArea, *usprc, found_duty_location + return rateArea, *oconusRateArea, *usprc, found_duty_location } - suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) - + suite.Run("success - findOconusGblocDepartmentIndicator - returns default GBLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { const fairbanksAlaskaPostalCode = "99790" - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(fairbanksAlaskaPostalCode, "JEAT") // setup department affiliation to GBLOC mappings - expected_gbloc := "TEST-GBLOC" - jppsoRegion := models.JppsoRegions{ - Code: expected_gbloc, - Name: "TEST PPM", - } - suite.MustSave(&jppsoRegion) - - gblocAors := models.GblocAors{ - JppsoRegionID: jppsoRegion.ID, - OconusRateAreaID: oconusRateArea.ID, - // DepartmentIndicator is nil, - } - suite.MustSave(&gblocAors) - - serviceAffiliations := []models.ServiceMemberAffiliation{models.AffiliationARMY, - models.AffiliationNAVY, models.AffiliationMARINES, models.AffiliationAIRFORCE, models.AffiliationCOASTGUARD, - models.AffiliationSPACEFORCE} - - // loop through and make sure all branches are using expected default GBLOC - for _, affiliation := range serviceAffiliations { - serviceMember := setupServiceMember(affiliation) - appCtx := suite.AppContextWithSessionForTest(&auth.Session{ - ServiceMemberID: serviceMember.ID, - }) - suite.Nil(err) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) - suite.NotNil(departmentIndictor) - suite.Nil(err) - suite.Nil(departmentIndictor.DepartmentIndicator) - suite.Equal(expected_gbloc, departmentIndictor.Gbloc) - } - }) - - suite.Run("success - findOconusGblocDepartmentIndicator - returns specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "JEAT") + suite.NotNil(jppsoRegion) + suite.Nil(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) - departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, - models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, - models.DepartmentIndicatorNAVYANDMARINES, models.DepartmentIndicatorAIRANDSPACEFORCE} + serviceMember := setupServiceMember(models.AffiliationARMY) + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) + suite.NotNil(departmentIndictor) + suite.Nil(err) + suite.Nil(departmentIndictor.DepartmentIndicator) + suite.Equal("JEAT", departmentIndictor.Gbloc) + }) - expectedAffiliationToDepartmentIndicatorMap := make(map[string]string, 0) - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationARMY.String()] = models.DepartmentIndicatorARMY.String() - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationNAVY.String()] = models.DepartmentIndicatorNAVYANDMARINES.String() - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationMARINES.String()] = models.DepartmentIndicatorNAVYANDMARINES.String() - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationAIRFORCE.String()] = models.DepartmentIndicatorAIRANDSPACEFORCE.String() - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationCOASTGUARD.String()] = models.DepartmentIndicatorCOASTGUARD.String() - expectedAffiliationToDepartmentIndicatorMap[models.AffiliationSPACEFORCE.String()] = models.DepartmentIndicatorAIRANDSPACEFORCE.String() + suite.Run("success - findOconusGblocDepartmentIndicator - returns specific GBLOC for departmentAffiliation when a specific departmentAffilation mapping is defined -- simulate Zone 2 scenerio", func() { + const fairbanksAlaskaPostalCode = "99790" + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(fairbanksAlaskaPostalCode, "MBFL") // setup department affiliation to GBLOC mappings - expected_gbloc := "TEST-GBLOC" - jppsoRegion := models.JppsoRegions{ - Code: expected_gbloc, - Name: "TEST PPM", - } - suite.MustSave(&jppsoRegion) + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MBFL") + suite.NotNil(jppsoRegion) + suite.Nil(err) - defaultGblocAors := models.GblocAors{ - JppsoRegionID: jppsoRegion.ID, - OconusRateAreaID: oconusRateArea.ID, - //DepartmentIndicator is nil, - } - suite.MustSave(&defaultGblocAors) - - // setup specific departmentAffiliation mapping for each branch - for _, departmentIndicator := range departmentIndicators { - gblocAors := models.GblocAors{ - JppsoRegionID: jppsoRegion.ID, - OconusRateAreaID: oconusRateArea.ID, - DepartmentIndicator: models.StringPointer(departmentIndicator.String()), - } - suite.MustSave(&gblocAors) - } + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorAIRANDSPACEFORCE.String()) + suite.NotNil(gblocAors) + suite.Nil(err) // loop through and make sure all branches are using it's own dedicated GBLOC and not default - for _, affiliation := range serviceAffiliations { - serviceMember := setupServiceMember(affiliation) - appCtx := suite.AppContextWithSessionForTest(&auth.Session{ - ServiceMemberID: serviceMember.ID, - }) - suite.Nil(err) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) - suite.NotNil(departmentIndictor) - suite.Nil(err) - suite.NotNil(departmentIndictor.DepartmentIndicator) - if match, ok := expectedAffiliationToDepartmentIndicatorMap[affiliation.String()]; ok { - // verify service member's affiliation matches on specific departmentIndicator mapping record - suite.Equal(match, *departmentIndictor.DepartmentIndicator) - } else { - suite.Fail(fmt.Sprintf("key does not exist for %s", affiliation.String())) - } - suite.Equal(expected_gbloc, departmentIndictor.Gbloc) - } - }) - - suite.Run("failure -- returns error when there are default and no department specific GBLOC", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) - - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) - - // No specific departmentAffiliation mapping or default were created. - // Expect an error response when nothing is found. serviceMember := setupServiceMember(models.AffiliationAIRFORCE) appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) - suite.Nil(departmentIndictor) - suite.NotNil(err) + suite.NotNil(departmentIndictor) + suite.Nil(err) + suite.NotNil(departmentIndictor.DepartmentIndicator) + suite.Equal(models.DepartmentIndicatorAIRANDSPACEFORCE.String(), *departmentIndictor.DepartmentIndicator) + suite.Equal("MBFL", departmentIndictor.Gbloc) }) suite.Run("failure - findOconusGblocDepartmentIndicator - returns error when find service member ID fails", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) - - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice("99714", "JEAT") appCtx := suite.AppContextWithSessionForTest(&auth.Session{ // create fake service member ID to raise NOT found error ServiceMemberID: uuid.Must(uuid.NewV4()), }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.Nil(departmentIndictor) suite.NotNil(err) @@ -489,33 +352,16 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - offices using default departmentIndicator mapping", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) - - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice("99619", "MAPS") // setup department affiliation to GBLOC mappings - jppsoRegion := models.JppsoRegions{ - Code: testGbloc, - Name: "TEST PPM", - } - suite.MustSave(&jppsoRegion) - - gblocAors := models.GblocAors{ - JppsoRegionID: jppsoRegion.ID, - OconusRateAreaID: oconusRateArea.ID, - // DepartmentIndicator is nil, - } - suite.MustSave(&gblocAors) + jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPS") + suite.NotNil(jppsoRegion) + suite.Nil(err) - postalCodeToGBLOC := models.PostalCodeToGBLOC{ - PostalCode: testPostalCode, - GBLOC: testGbloc, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - } - suite.MustSave(&postalCodeToGBLOC) + gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String()) + suite.NotNil(gblocAors) + suite.Nil(err) serviceMember := setupServiceMember(models.AffiliationAIRFORCE) appCtx := suite.AppContextWithSessionForTest(&auth.Session{ @@ -527,15 +373,15 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi suite.NotNil(offices) suite.Nil(err) suite.Equal(1, len(offices)) - suite.Equal(testTransportationName, offices[0].Name) + suite.Equal("TEST - PPO", offices[0].Name) // add another transportation office factory.BuildTransportationOffice(suite.DB(), []factory.Customization{ { Model: models.TransportationOffice{ - Name: testTransportationName2, + Name: "TEST - PPO2", ProvidesCloseout: true, - Gbloc: testGbloc, + Gbloc: "MAPS", }, }, }, nil) @@ -545,100 +391,6 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi suite.Equal(2, len(offices)) }) - suite.Run("success - returns correct office based on service affiliation -- simulate Zone 2 scenerio", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) - suite.NotNil(contract) - suite.FatalNoError(err) - - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) - - // ****************************************************************************** - // setup department affiliation to GBLOC mappings for AF/SF - // ****************************************************************************** - jppsoRegion_AFSF := models.JppsoRegions{ - Code: testGbloc, - Name: "TEST PPO", - } - suite.MustSave(&jppsoRegion_AFSF) - - gblocAors_AFSF := models.GblocAors{ - JppsoRegionID: jppsoRegion_AFSF.ID, - OconusRateAreaID: oconusRateArea.ID, - DepartmentIndicator: models.StringPointer(models.DepartmentIndicatorAIRANDSPACEFORCE.String()), - } - suite.MustSave(&gblocAors_AFSF) - - postalCodeToGBLOC_AFSF := models.PostalCodeToGBLOC{ - PostalCode: testPostalCode, - GBLOC: testGbloc, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - } - suite.MustSave(&postalCodeToGBLOC_AFSF) - // ****************************************************************************** - - // ****************************************************************************** - // setup department affiliation to GBLOC mappings for other branches NOT AF/SF - // ****************************************************************************** - jppsoRegion_not_AFSF := models.JppsoRegions{ - Code: testGbloc2, - Name: "TEST PPO 2", - } - suite.MustSave(&jppsoRegion_not_AFSF) - - gblocAors_not_AFSF := models.GblocAors{ - JppsoRegionID: jppsoRegion_not_AFSF.ID, - OconusRateAreaID: oconusRateArea.ID, - } - suite.MustSave(&gblocAors_not_AFSF) - - postalCodeToGBLOC_not_AFSF := models.PostalCodeToGBLOC{ - PostalCode: testPostalCode2, - GBLOC: testGbloc2, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - } - suite.MustSave(&postalCodeToGBLOC_not_AFSF) - - // add transportation office for other branches not AF/SF - factory.BuildTransportationOffice(suite.DB(), []factory.Customization{ - { - Model: models.TransportationOffice{ - Name: testTransportationName2, - ProvidesCloseout: true, - Gbloc: testGbloc2, - }, - }, - }, nil) - // ****************************************************************************** - - for _, affiliation := range serviceAffiliations { - serviceMember := setupServiceMember(affiliation) - if affiliation == models.AffiliationAIRFORCE || affiliation == models.AffiliationSPACEFORCE { - appCtx := suite.AppContextWithSessionForTest(&auth.Session{ - ServiceMemberID: serviceMember.ID, - }) - offices, err := findCounselingOffice(appCtx, dutylocation.ID) - suite.NotNil(offices) - suite.Nil(err) - suite.Equal(1, len(offices)) - // verify expected office is for AF/SF and not for Navy ..etc.. - suite.Equal(testTransportationName, offices[0].Name) - suite.NotEqual(testTransportationName2, offices[0].Name) - } else { - appCtx := suite.AppContextWithSessionForTest(&auth.Session{ - ServiceMemberID: serviceMember.ID, - }) - offices, err := findCounselingOffice(appCtx, dutylocation.ID) - suite.NotNil(offices) - suite.Nil(err) - suite.Equal(1, len(offices)) - // verify expected office is for Navy ..etc.. and not AF/SF - suite.Equal(testTransportationName2, offices[0].Name) - suite.NotEqual(testTransportationName, offices[0].Name) - } - } - }) } func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { diff --git a/scripts/db-truncate b/scripts/db-truncate index b53aa009a51..f1b0d6db10a 100755 --- a/scripts/db-truncate +++ b/scripts/db-truncate @@ -16,7 +16,8 @@ BEGIN 're_zip3s','zip3_distances', 're_contracts', 're_domestic_service_areas', 're_intl_prices', 're_intl_other_prices', 're_domestic_linehaul_prices', 're_domestic_service_area_prices', 're_domestic_other_prices', 'pay_grades', - 'hhg_allowances', 'roles')) LOOP + 'hhg_allowances', + 'jppso_regions', 'jppso_region_state_assignments', 'gbloc_aors', 'roles')) LOOP EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE'; END LOOP; END \$\$;