contrat,booking,global logestic

This commit is contained in:
Marshal
2026-06-26 23:24:48 +00:00
parent f931342f31
commit 01d53c218c
105 changed files with 19573 additions and 909 deletions

View File

@@ -0,0 +1,69 @@
import { Contract } from './entities/contract.entity';
/**
* Resolves which seeded clearance FileUploadSetting applies to a contract during
* the CONTRACT pre-booking phase (Path B). Mirrors clearance.util.ts but emits
* `contract_clearance_*` codes keyed on (tradeDirection, freightType, customs).
*/
type Op = 'import' | 'export';
type Freight = 'container' | 'bulk';
/** Trade direction → clearance operation. DOMESTIC has no customs clearance. */
function operationFor(tradeDirection: string): Op | null {
if (tradeDirection === 'IMPORT') return 'import';
if (tradeDirection === 'EXPORT') return 'export';
return null; // DOMESTIC / intercity — no clearance gate
}
function freightFor(freightType: string): Freight {
return freightType === 'BULK' ? 'bulk' : 'container';
}
/** The customer-input clearance setting code, or null when no gate applies. */
export function contractClearanceSettingCode(
tradeDirection: string,
freightType: string,
includesCustoms: boolean,
): string | null {
if (!includesCustoms) return null;
const op = operationFor(tradeDirection);
if (!op) return null;
const freight = freightFor(freightType);
return `contract_clearance_${op}_${freight}`;
}
/** The GL-output (customs output) setting code; only container customs sets exist. */
export function contractClearanceOutputSettingCode(
tradeDirection: string,
freightType: string,
includesCustoms: boolean,
): string | null {
if (!includesCustoms) return null;
const op = operationFor(tradeDirection);
if (!op) return null;
if (freightFor(freightType) !== 'container') return null;
return `contract_clearance_output_${op}_container`;
}
/** Convenience: resolve both codes for a loaded contract. */
export function contractClearanceCodes(contract: Contract): {
inputCode: string | null;
outputCode: string | null;
includesCustoms: boolean;
} {
const includesCustoms = contract.customsClearingEnabled ?? false;
return {
inputCode: contractClearanceSettingCode(
contract.tradeDirection,
contract.freightType,
includesCustoms,
),
outputCode: contractClearanceOutputSettingCode(
contract.tradeDirection,
contract.freightType,
includesCustoms,
),
includesCustoms,
};
}