mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { BaseEntity } from '@edr/api-common';
|
|
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
|
|
import { Booking } from './booking.entity';
|
|
|
|
export const CLEARANCE_CHARGE_TYPES = ['PORT_CHARGES', 'MISCELLANEOUS'] as const;
|
|
export type ClearanceChargeType = (typeof CLEARANCE_CHARGE_TYPES)[number];
|
|
|
|
export const CLEARANCE_CHARGE_STATUSES = [
|
|
'DOC_UPLOADED',
|
|
'BILLED',
|
|
'SENT',
|
|
'PAID',
|
|
] as const;
|
|
export type ClearanceChargeStatus = (typeof CLEARANCE_CHARGE_STATUSES)[number];
|
|
|
|
/**
|
|
* Post-finalization clearance charge billed to the customer — at most one
|
|
* PORT_CHARGES and one MISCELLANEOUS row per booking. GL Djibouti uploads the
|
|
* port-charges document (DOC_UPLOADED); GL Ethiopia sets amount + currency
|
|
* (BILLED) and issues the invoice (SENT); the billing `clearance_charge.invoice.paid`
|
|
* event marks it PAID. MISCELLANEOUS is created whole by GL Ethiopia and only
|
|
* after the port charge is paid.
|
|
*/
|
|
@Entity({ schema: 'freight', name: 'booking_clearance_charge' })
|
|
@Index(['bookingId', 'type'], { unique: true })
|
|
export class BookingClearanceCharge extends BaseEntity {
|
|
@Column({ name: 'booking_id', type: 'uuid' })
|
|
bookingId!: string;
|
|
|
|
@ManyToOne(() => Booking, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'booking_id' })
|
|
booking?: Booking;
|
|
|
|
@Column({ name: 'type', type: 'varchar', length: 20 })
|
|
type!: ClearanceChargeType;
|
|
|
|
@Column({ name: 'status', type: 'varchar', length: 20, default: 'DOC_UPLOADED' })
|
|
status!: ClearanceChargeStatus;
|
|
|
|
/** The supporting charge document (FileRecord). */
|
|
@Column({ name: 'file_record_id', type: 'uuid', nullable: true })
|
|
fileRecordId?: string | null;
|
|
|
|
@Column({ name: 'amount', type: 'numeric', precision: 14, scale: 2, nullable: true })
|
|
amount?: string | null;
|
|
|
|
@Column({ name: 'currency', type: 'varchar', length: 8, nullable: true })
|
|
currency?: string | null;
|
|
|
|
/** The payable invoice issued for this charge (null until SENT). */
|
|
@Column({ name: 'invoice_id', type: 'uuid', nullable: true })
|
|
invoiceId?: string | null;
|
|
|
|
@Column({ name: 'uploaded_by_staff_id', type: 'uuid', nullable: true })
|
|
uploadedByStaffId?: string | null;
|
|
|
|
@Column({ name: 'uploaded_at', type: 'timestamptz', nullable: true })
|
|
uploadedAt?: Date | null;
|
|
|
|
@Column({ name: 'billed_by_staff_id', type: 'uuid', nullable: true })
|
|
billedByStaffId?: string | null;
|
|
|
|
@Column({ name: 'billed_at', type: 'timestamptz', nullable: true })
|
|
billedAt?: Date | null;
|
|
|
|
@Column({ name: 'paid_at', type: 'timestamptz', nullable: true })
|
|
paidAt?: Date | null;
|
|
}
|