feat(warehouses): allow deleting a warehouse

Soft-delete route guarded by warehouses:delete, refused with 409 while
yards remain — zones and inventory hang off a yard, so cascading would
orphan stock. Backoffice list gets a delete action in both views,
omitted when the user lacks the permission.
This commit is contained in:
Hagernesh
2026-08-28 14:39:34 +00:00
parent 224d46402d
commit 8ef50f9aff
21 changed files with 1264 additions and 7 deletions

View File

@@ -12,6 +12,8 @@ import { FREIGHT_PERMS } from '../../seed/freight-permissions.registry';
interface ItemAttributes {
arrivedAt: Date | null;
/** Backlog-registered box: real arrival on the record, but never billed. */
backlogRegistration: boolean;
gateClearedAt: Date | null;
releaseDate: Date | null;
freightType: string | null;
@@ -260,6 +262,7 @@ export class WarehouseFeeService {
private async loadItem(inventoryId: string): Promise<ItemAttributes> {
const [row] = await this.dataSource.query(
`SELECT inv.arrived_at AS "arrivedAt",
inv.backlog_registration AS "backlogRegistration",
inv.gate_cleared_at AS "gateClearedAt",
inv.release_date AS "releaseDate",
inv.quantity AS "inventoryQuantity",
@@ -777,6 +780,13 @@ export class WarehouseFeeService {
/** Preview demurrage + storage fees for an inventory item using the most specific active rules. */
async previewForInventory(inventoryId: string, billingCurrency = 'USD'): Promise<FeePreview[]> {
const item = await this.loadItem(inventoryId);
// A backlog registration carries a backdated arrival so the record is
// honest about how long the box has sat, but it was never booked through
// EDR and is not billed for that history. No rule applies, so no preview —
// which also keeps it off the invoice, since invoicing reads this same list.
if (item.backlogRegistration) return [];
const rules = await this.feeRuleRepository.findAll({ where: { isActive: true } });
const now = new Date();
@@ -894,6 +904,8 @@ export class WarehouseFeeService {
trucks.map(async (t) => {
const item: ItemAttributes = {
arrivedAt: null,
// Truck detention is a per-truck charge, never a warehouse backlog row.
backlogRegistration: false,
gateClearedAt: null,
releaseDate: null,
freightType: leg.freightType ?? null,