mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 14:08:11 +00:00
feat: add invoice pages and api to the backoffice
This commit is contained in:
@@ -28,6 +28,11 @@ import type {
|
||||
UpdateFileUploadFieldDto,
|
||||
UpdateFileUploadSettingDto,
|
||||
} from "@/types/fileUploadSettings";
|
||||
import type {
|
||||
Invoice,
|
||||
InvoiceListFilter,
|
||||
PaginatedInvoices,
|
||||
} from "@/types/invoice";
|
||||
import type { IOverviewDashboard, OverviewRange } from "@/types/overview";
|
||||
import {
|
||||
RuleEngineListResult,
|
||||
@@ -128,6 +133,7 @@ import {
|
||||
import { containerTypesService } from "./container-types.service";
|
||||
import { containerService, type Container } from "./containerService";
|
||||
import { customersService } from "./customers.service";
|
||||
import { invoicesService } from "./invoices.service";
|
||||
import { dropdownSettingsService } from "./dropdownSettings.service";
|
||||
import { fileUploadSettingsService } from "./fileUploadSettings.service";
|
||||
import {
|
||||
@@ -197,7 +203,10 @@ const TRAIN_SCHEDULING_INVALIDATIONS: ReadonlyArray<readonly unknown[]> = [
|
||||
export const api = {
|
||||
trainScheduling: {
|
||||
// ── Queries ────────────────────────────────────────────────────────────
|
||||
scheduleList: endpoint<{ freightType?: FreightType }, TrainScheduleListItem[]>(
|
||||
scheduleList: endpoint<
|
||||
{ freightType?: FreightType },
|
||||
TrainScheduleListItem[]
|
||||
>(
|
||||
"train-scheduling",
|
||||
"schedules",
|
||||
({ freightType }) => trainSchedulingService.listSchedules(freightType),
|
||||
@@ -211,11 +220,16 @@ export const api = {
|
||||
() => QUERY_KEYS.TRAIN_SCHEDULING.batchBoard(),
|
||||
),
|
||||
|
||||
batchBoardDetail: endpoint<{ scheduleId: string }, BatchBoardScheduleDetail>(
|
||||
batchBoardDetail: endpoint<
|
||||
{ scheduleId: string },
|
||||
BatchBoardScheduleDetail
|
||||
>(
|
||||
"train-scheduling",
|
||||
"batch-board-detail",
|
||||
({ scheduleId }) => trainSchedulingService.getBatchBoardDetail(scheduleId),
|
||||
({ scheduleId }) => QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
|
||||
({ scheduleId }) =>
|
||||
trainSchedulingService.getBatchBoardDetail(scheduleId),
|
||||
({ scheduleId }) =>
|
||||
QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
|
||||
),
|
||||
|
||||
scheduleDetail: endpoint<
|
||||
@@ -344,7 +358,10 @@ export const api = {
|
||||
),
|
||||
|
||||
// ── Mutations ──────────────────────────────────────────────────────────
|
||||
runAllocation: endpoint<{ scheduleId: string }, WagonAllocationAttemptResult>(
|
||||
runAllocation: endpoint<
|
||||
{ scheduleId: string },
|
||||
WagonAllocationAttemptResult
|
||||
>(
|
||||
"train-scheduling",
|
||||
"run-allocation",
|
||||
({ scheduleId }) => trainSchedulingService.runAllocation(scheduleId),
|
||||
@@ -454,7 +471,10 @@ export const api = {
|
||||
() => TRAIN_SCHEDULING_INVALIDATIONS,
|
||||
),
|
||||
|
||||
pinWagons: endpoint<{ id: string; payload: PinWagonsPayload }, TrainScheduleDetail>(
|
||||
pinWagons: endpoint<
|
||||
{ id: string; payload: PinWagonsPayload },
|
||||
TrainScheduleDetail
|
||||
>(
|
||||
"train-scheduling",
|
||||
"pin-wagons",
|
||||
({ id, payload }) => trainSchedulingService.pinWagons(id, payload),
|
||||
@@ -550,8 +570,10 @@ export const api = {
|
||||
({ id }) => warehouseService.getById(id).then((r) => r.data),
|
||||
),
|
||||
|
||||
dashboard: endpoint<void, WarehouseDashboard>("warehouses", "dashboard", () =>
|
||||
warehouseService.dashboard().then((r) => r.data),
|
||||
dashboard: endpoint<void, WarehouseDashboard>(
|
||||
"warehouses",
|
||||
"dashboard",
|
||||
() => warehouseService.dashboard().then((r) => r.data),
|
||||
),
|
||||
|
||||
create: endpoint<SaveWarehousePayload, Warehouse>(
|
||||
@@ -642,10 +664,8 @@ export const api = {
|
||||
listInventory: endpoint<
|
||||
{ filter?: InventoryFilter },
|
||||
WarehouseInventoryItem[]
|
||||
>(
|
||||
"warehouse-inventory",
|
||||
"list",
|
||||
({ filter }) => warehouseService.listInventory(filter).then((r) => r.data),
|
||||
>("warehouse-inventory", "list", ({ filter }) =>
|
||||
warehouseService.listInventory(filter).then((r) => r.data),
|
||||
),
|
||||
|
||||
inquiry: endpoint<
|
||||
@@ -658,11 +678,19 @@ export const api = {
|
||||
({ filter }) => ["warehouse-inventory", "inquiry", filter],
|
||||
),
|
||||
|
||||
eligibleBookings: endpoint<{ direction?: 'IMPORT' | 'EXPORT' } | void, EligibleBooking[]>(
|
||||
eligibleBookings: endpoint<
|
||||
{ direction?: "IMPORT" | "EXPORT" } | void,
|
||||
EligibleBooking[]
|
||||
>(
|
||||
"warehouse-inventory",
|
||||
"eligible-bookings",
|
||||
(input) => warehouseService.eligibleBookings(input?.direction).then((r) => r.data),
|
||||
(input) => ["warehouse-inventory", "eligible-bookings", input?.direction ?? "ALL"],
|
||||
(input) =>
|
||||
warehouseService.eligibleBookings(input?.direction).then((r) => r.data),
|
||||
(input) => [
|
||||
"warehouse-inventory",
|
||||
"eligible-bookings",
|
||||
input?.direction ?? "ALL",
|
||||
],
|
||||
),
|
||||
|
||||
readyToLoadExport: endpoint<void, ReadyToLoadRow[]>(
|
||||
@@ -698,7 +726,11 @@ export const api = {
|
||||
"import-train-items",
|
||||
({ scheduleId }) =>
|
||||
warehouseService.importTrainItems(scheduleId).then((r) => r.data),
|
||||
({ scheduleId }) => ["warehouse-inventory", "import-train-items", scheduleId],
|
||||
({ scheduleId }) => [
|
||||
"warehouse-inventory",
|
||||
"import-train-items",
|
||||
scheduleId,
|
||||
],
|
||||
),
|
||||
|
||||
importUnloadedQueue: endpoint<void, ImportUnloadedItem[]>(
|
||||
@@ -766,8 +798,11 @@ export const api = {
|
||||
"inspection-reports",
|
||||
({ inventoryId }) =>
|
||||
warehouseService.listInspectionReports(inventoryId).then((r) => r.data),
|
||||
({ inventoryId }) =>
|
||||
["warehouse-inventory", inventoryId, "inspection-reports"],
|
||||
({ inventoryId }) => [
|
||||
"warehouse-inventory",
|
||||
inventoryId,
|
||||
"inspection-reports",
|
||||
],
|
||||
),
|
||||
|
||||
allocationRules: endpoint<void, AllocationRule[]>(
|
||||
@@ -784,15 +819,28 @@ export const api = {
|
||||
() => ["warehouse-fee-rules"],
|
||||
),
|
||||
|
||||
feePreview: endpoint<{ inventoryId: string; billingCurrency?: 'ETB' | 'USD' }, FeePreview[]>(
|
||||
feePreview: endpoint<
|
||||
{ inventoryId: string; billingCurrency?: "ETB" | "USD" },
|
||||
FeePreview[]
|
||||
>(
|
||||
"warehouse-inventory",
|
||||
"fee-preview",
|
||||
({ inventoryId, billingCurrency }) =>
|
||||
warehouseService.feePreview(inventoryId, billingCurrency).then((r) => r.data),
|
||||
({ inventoryId, billingCurrency }) => ["warehouse-inventory", inventoryId, "fee-preview", billingCurrency ?? 'USD'],
|
||||
warehouseService
|
||||
.feePreview(inventoryId, billingCurrency)
|
||||
.then((r) => r.data),
|
||||
({ inventoryId, billingCurrency }) => [
|
||||
"warehouse-inventory",
|
||||
inventoryId,
|
||||
"fee-preview",
|
||||
billingCurrency ?? "USD",
|
||||
],
|
||||
),
|
||||
|
||||
invoices: endpoint<{ filter?: WarehouseInvoiceFilter }, WarehouseFeeInvoice[]>(
|
||||
invoices: endpoint<
|
||||
{ filter?: WarehouseInvoiceFilter },
|
||||
WarehouseFeeInvoice[]
|
||||
>(
|
||||
"warehouse-fee-invoices",
|
||||
"list",
|
||||
({ filter }) => warehouseService.listInvoices(filter).then((r) => r.data),
|
||||
@@ -821,7 +869,8 @@ export const api = {
|
||||
receiveInventory: endpoint<ReceiveInventoryPayload, WarehouseInventoryItem>(
|
||||
"warehouse-inventory",
|
||||
"receive",
|
||||
(payload) => warehouseService.receiveInventory(payload).then((r) => r.data),
|
||||
(payload) =>
|
||||
warehouseService.receiveInventory(payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => [["warehouse-inventory"], ["warehouses"]],
|
||||
),
|
||||
@@ -856,7 +905,8 @@ export const api = {
|
||||
>(
|
||||
"warehouse-inventory",
|
||||
"load",
|
||||
({ id, payload }) => warehouseService.load(id, payload).then((r) => r.data),
|
||||
({ id, payload }) =>
|
||||
warehouseService.load(id, payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => INVENTORY_INVALIDATIONS,
|
||||
),
|
||||
@@ -875,7 +925,8 @@ export const api = {
|
||||
>(
|
||||
"warehouse-inventory",
|
||||
"move",
|
||||
({ id, payload }) => warehouseService.move(id, payload).then((r) => r.data),
|
||||
({ id, payload }) =>
|
||||
warehouseService.move(id, payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => INVENTORY_INVALIDATIONS,
|
||||
),
|
||||
@@ -931,7 +982,8 @@ export const api = {
|
||||
bulkMarkInspected: endpoint<BulkInspectPayload, BulkInspectResult>(
|
||||
"warehouse-inventory",
|
||||
"bulk-mark-inspected",
|
||||
(payload) => warehouseService.bulkMarkInspected(payload).then((r) => r.data),
|
||||
(payload) =>
|
||||
warehouseService.bulkMarkInspected(payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => INVENTORY_INVALIDATIONS,
|
||||
),
|
||||
@@ -949,7 +1001,12 @@ export const api = {
|
||||
{
|
||||
scheduleId: string;
|
||||
warehouseId?: string;
|
||||
assignments?: { bookingId: string; warehouseId: string; yardId: string; zoneId: string }[];
|
||||
assignments?: {
|
||||
bookingId: string;
|
||||
warehouseId: string;
|
||||
yardId: string;
|
||||
zoneId: string;
|
||||
}[];
|
||||
},
|
||||
AutoUnloadArrivedResult
|
||||
>(
|
||||
@@ -1021,11 +1078,11 @@ export const api = {
|
||||
),
|
||||
|
||||
// ── Allocation + fee rules ─────────────────────────────────────────────
|
||||
previewAllocation: endpoint<AllocationCriteria, AllocationPreviewResult | null>(
|
||||
"warehouse-allocation-rules",
|
||||
"preview",
|
||||
(criteria) =>
|
||||
warehouseService.previewAllocation(criteria).then((r) => r.data),
|
||||
previewAllocation: endpoint<
|
||||
AllocationCriteria,
|
||||
AllocationPreviewResult | null
|
||||
>("warehouse-allocation-rules", "preview", (criteria) =>
|
||||
warehouseService.previewAllocation(criteria).then((r) => r.data),
|
||||
),
|
||||
|
||||
createAllocationRule: endpoint<SaveAllocationRulePayload, AllocationRule>(
|
||||
@@ -1087,7 +1144,11 @@ export const api = {
|
||||
|
||||
// ── Invoices ───────────────────────────────────────────────────────────
|
||||
generateInvoice: endpoint<
|
||||
{ inventoryId: string; confirmZero?: boolean; billingCurrency?: 'ETB' | 'USD' },
|
||||
{
|
||||
inventoryId: string;
|
||||
confirmZero?: boolean;
|
||||
billingCurrency?: "ETB" | "USD";
|
||||
},
|
||||
WarehouseFeeInvoice
|
||||
>(
|
||||
"warehouse-fee-invoices",
|
||||
@@ -1143,7 +1204,10 @@ export const api = {
|
||||
},
|
||||
|
||||
routes: {
|
||||
list: endpoint<{ status?: import("./routes.service").RouteStatus } | void, RouteRecord[]>(
|
||||
list: endpoint<
|
||||
{ status?: import("./routes.service").RouteStatus } | void,
|
||||
RouteRecord[]
|
||||
>(
|
||||
"routes",
|
||||
"list",
|
||||
(input) =>
|
||||
@@ -1168,7 +1232,10 @@ export const api = {
|
||||
() => [["routes"]],
|
||||
),
|
||||
|
||||
update: endpoint<{ id: string; data: Partial<SaveRoutePayload> }, RouteRecord>(
|
||||
update: endpoint<
|
||||
{ id: string; data: Partial<SaveRoutePayload> },
|
||||
RouteRecord
|
||||
>(
|
||||
"routes",
|
||||
"update",
|
||||
({ id, data }) => routesService.update(id, data).then((r) => r.data),
|
||||
@@ -1281,10 +1348,8 @@ export const api = {
|
||||
({ trainId }) => ["wagons", "train", trainId],
|
||||
),
|
||||
|
||||
getById: endpoint<{ id: string }, Wagon>(
|
||||
"wagons",
|
||||
"getById",
|
||||
({ id }) => wagonService.getById(id).then((r) => r.data),
|
||||
getById: endpoint<{ id: string }, Wagon>("wagons", "getById", ({ id }) =>
|
||||
wagonService.getById(id).then((r) => r.data),
|
||||
),
|
||||
|
||||
assignToTrain: endpoint<
|
||||
@@ -1663,7 +1728,8 @@ export const api = {
|
||||
>(
|
||||
"file-upload-settings",
|
||||
"addField",
|
||||
({ settingId, dto }) => fileUploadSettingsService.addField(settingId, dto),
|
||||
({ settingId, dto }) =>
|
||||
fileUploadSettingsService.addField(settingId, dto),
|
||||
undefined,
|
||||
() => [["file-upload-settings"]],
|
||||
),
|
||||
@@ -1762,7 +1828,8 @@ export const api = {
|
||||
>(
|
||||
"dropdown-settings",
|
||||
"updateOption",
|
||||
({ optionId, dto }) => dropdownSettingsService.updateOption(optionId, dto),
|
||||
({ optionId, dto }) =>
|
||||
dropdownSettingsService.updateOption(optionId, dto),
|
||||
undefined,
|
||||
() => [["dropdown-settings"]],
|
||||
),
|
||||
@@ -1815,11 +1882,10 @@ export const api = {
|
||||
ruleEngineService.update(resource, id, payload),
|
||||
),
|
||||
|
||||
remove: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; id: string },
|
||||
void
|
||||
>("rule-engine", "remove", ({ resource, id }) =>
|
||||
ruleEngineService.remove(resource, id),
|
||||
remove: endpoint<{ resource: RuleEngineResourceSlug; id: string }, void>(
|
||||
"rule-engine",
|
||||
"remove",
|
||||
({ resource, id }) => ruleEngineService.remove(resource, id),
|
||||
),
|
||||
|
||||
submitRate: endpoint<{ id: string }, RuleEngineRecord>(
|
||||
@@ -1842,14 +1908,21 @@ export const api = {
|
||||
),
|
||||
|
||||
reorder: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; payload: { ids: string[]; requiresDirectorApproval?: boolean } },
|
||||
{
|
||||
resource: RuleEngineResourceSlug;
|
||||
payload: { ids: string[]; requiresDirectorApproval?: boolean };
|
||||
},
|
||||
void
|
||||
>("rule-engine", "reorder", ({ resource, payload }) =>
|
||||
ruleEngineService.reorder(resource, payload),
|
||||
),
|
||||
|
||||
moveOrder: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; id: string; direction: "up" | "down" },
|
||||
{
|
||||
resource: RuleEngineResourceSlug;
|
||||
id: string;
|
||||
direction: "up" | "down";
|
||||
},
|
||||
void
|
||||
>("rule-engine", "moveOrder", ({ resource, id, direction }) =>
|
||||
ruleEngineService.moveOrder(resource, id, direction),
|
||||
@@ -1871,10 +1944,8 @@ export const api = {
|
||||
({ id }) => QUERY_KEYS.BOOKINGS.byId(id),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"bookings",
|
||||
"remove",
|
||||
({ id }) => bookingsService.remove(id),
|
||||
remove: endpoint<{ id: string }, void>("bookings", "remove", ({ id }) =>
|
||||
bookingsService.remove(id),
|
||||
),
|
||||
|
||||
staffAccept: endpoint<{ id: string; validityDays: number }, BookingDetail>(
|
||||
@@ -1924,10 +1995,11 @@ export const api = {
|
||||
({ id }) => bookingsService.generateContract(id),
|
||||
),
|
||||
|
||||
getContractView: endpoint<{ id: string }, import("./bookings.service").ContractView>(
|
||||
"bookings",
|
||||
"getContractView",
|
||||
({ id }) => bookingsService.getContractView(id),
|
||||
getContractView: endpoint<
|
||||
{ id: string },
|
||||
import("./bookings.service").ContractView
|
||||
>("bookings", "getContractView", ({ id }) =>
|
||||
bookingsService.getContractView(id),
|
||||
),
|
||||
|
||||
signContract: endpoint<
|
||||
@@ -2011,7 +2083,8 @@ export const api = {
|
||||
>(
|
||||
"customers",
|
||||
"setProfileStatus",
|
||||
({ profileId, status }) => customersService.setProfileStatus(profileId, status),
|
||||
({ profileId, status }) =>
|
||||
customersService.setProfileStatus(profileId, status),
|
||||
undefined,
|
||||
(_input, data) => [
|
||||
QUERY_KEYS.CUSTOMERS.byId(data.companyId),
|
||||
@@ -2032,6 +2105,22 @@ export const api = {
|
||||
),
|
||||
},
|
||||
|
||||
invoices: {
|
||||
list: endpoint<{ filter: InvoiceListFilter }, PaginatedInvoices>(
|
||||
"invoices",
|
||||
"list",
|
||||
({ filter }) => invoicesService.list(filter),
|
||||
({ filter }) => QUERY_KEYS.INVOICES.list(filter),
|
||||
),
|
||||
|
||||
getById: endpoint<{ id: string }, Invoice>(
|
||||
"invoices",
|
||||
"getById",
|
||||
({ id }) => invoicesService.getById(id),
|
||||
({ id }) => QUERY_KEYS.INVOICES.byId(id),
|
||||
),
|
||||
},
|
||||
|
||||
overview: {
|
||||
get: endpoint<{ range?: OverviewRange }, IOverviewDashboard>(
|
||||
"overview",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { api as apiClient } from "@/auth/http";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
import type {
|
||||
Invoice,
|
||||
InvoiceListFilter,
|
||||
PaginatedInvoices,
|
||||
} from "@/types/invoice";
|
||||
|
||||
const cleanParams = (params: object) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(params).filter(
|
||||
([, value]) => value !== undefined && value !== "" && value !== null,
|
||||
),
|
||||
);
|
||||
|
||||
export const invoicesService = {
|
||||
list(filter: InvoiceListFilter): Promise<PaginatedInvoices> {
|
||||
return apiClient
|
||||
.get<PaginatedInvoices>(URL_CONSTANTS.BILLING.INVOICES, {
|
||||
params: cleanParams(filter),
|
||||
})
|
||||
.then((r) => r.data);
|
||||
},
|
||||
|
||||
getById(id: string): Promise<Invoice> {
|
||||
return apiClient
|
||||
.get<Invoice>(URL_CONSTANTS.BILLING.INVOICE_BY_ID(id))
|
||||
.then((r) => r.data);
|
||||
},
|
||||
|
||||
downloadDocument(id: string) {
|
||||
return apiClient.get<Blob>(URL_CONSTANTS.BILLING.INVOICE_DOCUMENT(id), {
|
||||
responseType: "blob",
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user