Merge pull request #942 from Tria-plc/freight_feature/usermanagement

revert back the clerance payment
This commit is contained in:
marshal
2026-07-23 16:56:56 +03:00
committed by GitHub
54 changed files with 1222 additions and 712 deletions

View File

@@ -165,6 +165,64 @@ WHERE NOT EXISTS (
SELECT 1 FROM freight.wagons w WHERE w.wagon_number = 'ECW' || lpad(g::text, 4, '0')
);
-- 5b3. Ledger-day rolling stock: wheat may also ride PW2 box wagons, and the
-- GRAIN train is a BUILT Train-Builder consist — 37 PW2 wagons coupled at
-- KALITY behind two dedicated locos. A built train's physical wagon count IS
-- its schedule capacity (37), immune to the loco-length slot recompute.
INSERT INTO freight.cargo_type_wagon_types (cargo_type_id, wagon_type_id)
SELECT ct.id, wt.id
FROM freight.cargo_types ct
JOIN freight.wagon_types wt ON wt.code = 'PW2'
WHERE ct.code IN ('E2E_IMP_GRAINS', 'E2E_IMP_WHEAT')
AND NOT EXISTS (
SELECT 1 FROM freight.cargo_type_wagon_types x
WHERE x.cargo_type_id = ct.id AND x.wagon_type_id = wt.id
);
INSERT INTO freight.locomotives
(id, code, max_pull_weight_tons, max_train_length_meters, current_yard_id)
SELECT gen_random_uuid(), v.code, 9000, 760, y.id
FROM (VALUES ('LOCO-LED-1'), ('LOCO-LED-2')) AS v(code)
JOIN freight.yards y ON y.code = 'KALITY'
WHERE NOT EXISTS (SELECT 1 FROM freight.locomotives l WHERE l.code = v.code);
INSERT INTO freight.trains
(id, code, train_name, capacity_tons, current_yard_id,
import_train_number, export_train_number)
SELECT gen_random_uuid(), 'TRN-LEDGER-PW2', 'Ledger Grain Carrier', 2600, y.id,
'9102', '9101'
FROM freight.yards y
WHERE y.code = 'KALITY'
AND NOT EXISTS (SELECT 1 FROM freight.trains t WHERE t.code = 'TRN-LEDGER-PW2');
INSERT INTO freight.train_locomotives (id, train_id, locomotive_id, sequence_no)
SELECT gen_random_uuid(), t.id, l.id,
row_number() OVER (ORDER BY l.code) - 1
FROM freight.trains t
JOIN freight.locomotives l ON l.code IN ('LOCO-LED-1', 'LOCO-LED-2')
WHERE t.code = 'TRN-LEDGER-PW2'
AND NOT EXISTS (
SELECT 1 FROM freight.train_locomotives tl
WHERE tl.train_id = t.id AND tl.locomotive_id = l.id
);
UPDATE freight.wagons w
SET train_id = t.id,
sequence_number = sub.rn,
current_yard_id = (SELECT id FROM freight.yards WHERE code = 'KALITY')
FROM freight.trains t,
LATERAL (
SELECT w2.id, row_number() OVER (ORDER BY w2.wagon_number) AS rn
FROM freight.wagons w2
JOIN freight.wagon_types wt ON wt.id = w2.wagon_type_id AND wt.code = 'PW2'
WHERE w2.train_id IS NULL AND w2.deleted_at IS NULL
ORDER BY w2.wagon_number
LIMIT 37
) sub
WHERE t.code = 'TRN-LEDGER-PW2'
AND w.id = sub.id
AND NOT EXISTS (SELECT 1 FROM freight.wagons wx WHERE wx.train_id = t.id);
-- 5c. Approved exporter profile — export contracts bill against it
-- (seed-company.sql only creates the importer).
INSERT INTO freight.company_profiles (id, company_id, type, status, reference)