This commit is contained in:
natib21
2026-07-06 12:23:25 +00:00
parent 6b0db45be2
commit fb4ffa5d67
7 changed files with 75 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from "typeorm";
/**
* Per-km haulage rate on a vehicle (mainly trucks) plus the currency it's
* quoted in (ETB | USD, default ETB).
*/
export class AddVehiclePricePerKm1990000000000 implements MigrationInterface {
name = "AddVehiclePricePerKm1990000000000";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE freight.vehicles
ADD COLUMN IF NOT EXISTS price_per_km numeric(14,2),
ADD COLUMN IF NOT EXISTS currency varchar(8) NOT NULL DEFAULT 'ETB'
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE freight.vehicles
DROP COLUMN IF EXISTS price_per_km,
DROP COLUMN IF EXISTS currency
`);
}
}

View File

@@ -65,4 +65,12 @@ export class CreateVehicleDto {
@IsOptional()
@IsUUID()
locationId?: string;
@IsOptional()
@IsNumber()
pricePerKm?: number;
@IsOptional()
@IsString()
currency?: string;
}

View File

@@ -89,6 +89,14 @@ export class Vehicle extends BaseEntity {
@Column({ name: 'location_id', type: 'uuid', nullable: true })
locationId?: string;
// --- Haulage pricing ---
@Column({ name: 'price_per_km', type: 'numeric', precision: 14, scale: 2, nullable: true })
pricePerKm?: number;
/** Currency for pricePerKm: ETB | USD */
@Column({ name: 'currency', type: 'varchar', length: 8, default: 'ETB' })
currency?: string;
// --- Compliance / expiry tracking ---
@Column({ name: 'vin', type: 'varchar', nullable: true })
vin?: string;

View File

@@ -7,6 +7,7 @@ import {
Group,
Modal,
NumberInput,
Radio,
Select,
MultiSelect,
SimpleGrid,
@@ -293,6 +294,26 @@ const FleetFormDialog = ({
// only by verification and never hand-edited.
const isDisabled = Boolean(field.disabled || field.faydaLocked);
if (field.type === "radio") {
return (
<Radio.Group
key={field.name}
label={field.label}
value={value == null ? "" : String(value)}
onChange={(next) =>
setValues((current) => ({ ...current, [field.name]: next }))
}
error={error}
>
<Group gap="lg" mt={6}>
{(field.options ?? []).map((o) => (
<Radio key={o.value} value={o.value} label={o.label} disabled={isDisabled} />
))}
</Group>
</Radio.Group>
);
}
if (field.type === "select") {
return (
<Select

View File

@@ -29,6 +29,11 @@ const VEHICLE_AVAILABILITY_OPTIONS = [
{ label: "Busy", value: "BUSY" },
];
const CURRENCY_OPTIONS = [
{ label: "ETB", value: "ETB" },
{ label: "USD", value: "USD" },
];
export const vehiclesConfig: FleetResourceConfig = {
slug: "vehicles",
label: "Vehicles",
@@ -84,6 +89,8 @@ export const vehiclesConfig: FleetResourceConfig = {
{ name: "locationId", label: "Location", type: "select", dynamicOptions: "yards" },
{ name: "estimatedDistanceKm", label: "Estimated Distance (KM)", type: "number" },
{ name: "actualDistanceKm", label: "Actual Distance (KM)", type: "number" },
{ name: "pricePerKm", label: "Price per KM", type: "number" },
{ name: "currency", label: "Currency", type: "radio", options: CURRENCY_OPTIONS },
{ name: "status", label: "Status", type: "select", required: true, options: VEHICLE_STATUS_OPTIONS },
{ name: "availability", label: "Availability", type: "select", required: true, options: VEHICLE_AVAILABILITY_OPTIONS },
{ name: "description", label: "Description", type: "textarea" },
@@ -102,6 +109,8 @@ export const vehiclesConfig: FleetResourceConfig = {
locationId: null,
estimatedDistanceKm: "",
actualDistanceKm: "",
pricePerKm: "",
currency: "ETB",
status: "ACTIVE",
availability: "FREE",
description: "",

View File

@@ -15,7 +15,7 @@ export type ColumnFormat =
| "entityLabel"
| "rateLabel";
export type FormFieldType = "text" | "number" | "boolean" | "date" | "email" | "select" | "multiselect" | "textarea";
export type FormFieldType = "text" | "number" | "boolean" | "date" | "email" | "select" | "multiselect" | "textarea" | "radio";
export interface ResourceColumn {
id: string;

View File

@@ -38,6 +38,9 @@ export interface Vehicle {
/** Odometer-derived distances (API sends numeric strings; coerce with Number). */
estimatedDistanceKm?: number | null;
actualDistanceKm?: number | null;
/** Haulage rate per km + its currency (ETB | USD). */
pricePerKm?: number | null;
currency?: string | null;
createdAt: string;
updatedAt: string;
}