mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 15:30:56 +00:00
Reject lease start/end and monthly payment on PURCHASE acquisitions (create and update, validated against the resulting record). Add asset_acquisitions.item_name column + migration. Enforce warehouse/yard/zone capacity on bulk receive and apply capacity-counter deltas on save. Adds acquisition-guard spec. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { BaseEntity } from '@edr/api-common';
|
|
import { Entity, Column, ManyToOne, JoinColumn, Index } from 'typeorm';
|
|
import { Vehicle } from '../../vehicles/entities/vehicle.entity';
|
|
import { Vendor } from './vendor.entity';
|
|
|
|
export enum AcquisitionType {
|
|
PURCHASE = 'PURCHASE',
|
|
LEASE = 'LEASE',
|
|
RENTAL = 'RENTAL',
|
|
}
|
|
|
|
export enum AcquisitionStatus {
|
|
ACTIVE = 'ACTIVE',
|
|
LEASE_EXPIRING = 'LEASE_EXPIRING',
|
|
DISPOSED = 'DISPOSED',
|
|
}
|
|
|
|
@Entity({ name: 'asset_acquisitions', schema: 'freight' })
|
|
@Index(['vehicleId', 'acquisitionDate'])
|
|
export class AssetAcquisition extends BaseEntity {
|
|
/** WHAT was acquired (vehicle, parts, equipment…) — the asset itself. */
|
|
@Column({ name: 'item_name', type: 'varchar', length: 200, nullable: true })
|
|
itemName?: string;
|
|
|
|
/** Optional link — only when the acquisition IS a fleet vehicle. Parts and
|
|
* general procurement stay unlinked so reports don't misattribute them. */
|
|
@Column({ name: 'vehicle_id', type: 'uuid', nullable: true })
|
|
vehicleId?: string;
|
|
|
|
@ManyToOne(() => Vehicle, { eager: false, nullable: true, onDelete: 'SET NULL' })
|
|
@JoinColumn({ name: 'vehicle_id' })
|
|
vehicle?: Vehicle;
|
|
|
|
@Column({ name: 'vendor_id', type: 'uuid', nullable: true })
|
|
vendorId?: string;
|
|
|
|
@ManyToOne(() => Vendor, { eager: false, nullable: true, onDelete: 'SET NULL' })
|
|
@JoinColumn({ name: 'vendor_id' })
|
|
vendor?: Vendor;
|
|
|
|
@Column({ name: 'acquisition_type', type: 'varchar' })
|
|
acquisitionType!: AcquisitionType;
|
|
|
|
@Column({ name: 'acquisition_date', type: 'date' })
|
|
acquisitionDate!: string;
|
|
|
|
@Column({ name: 'cost', type: 'numeric', precision: 14, scale: 2, nullable: true })
|
|
cost?: number;
|
|
|
|
@Column({ name: 'useful_life_months', type: 'int', nullable: true })
|
|
usefulLifeMonths?: number;
|
|
|
|
@Column({ name: 'salvage_value', type: 'numeric', precision: 14, scale: 2, nullable: true })
|
|
salvageValue?: number;
|
|
|
|
@Column({ name: 'lease_start', type: 'date', nullable: true })
|
|
leaseStart?: string;
|
|
|
|
@Column({ name: 'lease_end', type: 'date', nullable: true })
|
|
leaseEnd?: string;
|
|
|
|
@Column({ name: 'monthly_payment', type: 'numeric', precision: 14, scale: 2, nullable: true })
|
|
monthlyPayment?: number;
|
|
|
|
@Column({ name: 'status', type: 'varchar', default: AcquisitionStatus.ACTIVE })
|
|
status!: AcquisitionStatus;
|
|
|
|
@Column({ name: 'notes', type: 'text', nullable: true })
|
|
notes?: string;
|
|
}
|