mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 08:32:54 +00:00
fix issue
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Controller, Get, Param, ParseUUIDPipe, Res } from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
import type { Response } from "express";
|
||||
|
||||
import { FreightAdmin } from "../../common/booking-guards";
|
||||
@@ -8,6 +8,7 @@ import { BillingService } from "./billing.service";
|
||||
@ApiTags("billing")
|
||||
@Controller("billing")
|
||||
@FreightAdmin()
|
||||
@ApiBearerAuth()
|
||||
export class BillingController {
|
||||
constructor(private readonly billingService: BillingService) { }
|
||||
|
||||
|
||||
@@ -344,6 +344,7 @@ export class BillingService {
|
||||
input: GenerateInvoiceInput,
|
||||
manager?: EntityManager,
|
||||
): Promise<Invoice & { lines: InvoiceLine[] }> {
|
||||
console.log("oooooooooo", input);
|
||||
const run = (mg: EntityManager) => this.createInvoice(input, mg);
|
||||
return manager ? run(manager) : this.dataSource.transaction(run);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ import { AllocateFirstMileContainersDto } from './dto/allocate-containers.dto';
|
||||
import { FirstMileStatus } from './entities/first-mile.entity';
|
||||
import { FirstMileService } from './first-mile.service';
|
||||
import { FirstMileInvoiceService } from './first-mile-invoice.service';
|
||||
import { BillingService } from '../billing/billing.service';
|
||||
import { BookingsService } from '../bookings/bookings.service';
|
||||
import { Freight } from '@edr/types';
|
||||
|
||||
@ApiTags('first-mile')
|
||||
@ApiBearerAuth()
|
||||
@@ -30,7 +33,9 @@ export class FirstMileController {
|
||||
constructor(
|
||||
private readonly firstMileService: FirstMileService,
|
||||
private readonly firstMileInvoiceService: FirstMileInvoiceService,
|
||||
) {}
|
||||
private readonly billingService: BillingService,
|
||||
private readonly bookingsService: BookingsService
|
||||
) { }
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List first-mile legs' })
|
||||
@@ -80,7 +85,34 @@ export class FirstMileController {
|
||||
async update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateFirstMileDto) {
|
||||
const record = await this.firstMileService.update(id, dto);
|
||||
// Auto-generate invoice if distance or payment was updated
|
||||
if (dto.exactKm !== undefined || dto.remainingPayment !== undefined) {
|
||||
const booking = await this.bookingsService.findById(record.bookingId);
|
||||
if (dto.exactKm !== undefined || dto.exactKm != record.exactKm || dto.remainingPayment !== undefined || dto.remainingPayment !== record.remainingPayment) {
|
||||
await this.billingService.generateInvoice({
|
||||
source: Freight.InvoiceSource.FirstMile,
|
||||
sourceId: record.id,
|
||||
type: "FIRST_MILE",
|
||||
companyId: booking.companyId,
|
||||
companyProfileId: booking.companyProfileId,
|
||||
currency: "ETB",
|
||||
|
||||
lines: [
|
||||
{
|
||||
chargeType: "FIRST_MILE",
|
||||
description: "First Mile Transportation Service",
|
||||
quantity: 1,
|
||||
unitRate: record.remainingPayment,
|
||||
amount: record.remainingPayment,
|
||||
currency: "ETB",
|
||||
},
|
||||
],
|
||||
|
||||
subtotalAmount: record.remainingPayment,
|
||||
taxAmount: 0, // Replace if VAT/tax applies
|
||||
totalAmount: record.remainingPayment,
|
||||
|
||||
dueInDays: 7,
|
||||
status: Freight.InvoiceStatus.Pending,
|
||||
});
|
||||
await this.firstMileInvoiceService.ensureInvoiceFor(record);
|
||||
}
|
||||
return record;
|
||||
|
||||
@@ -21,6 +21,9 @@ import { AllocateLastMileContainersDto } from './dto/allocate-containers.dto';
|
||||
import { LastMileStatus } from './entities/last-mile.entity';
|
||||
import { LastMileService } from './last-mile.service';
|
||||
import { LastMileInvoiceService } from './last-mile-invoice.service';
|
||||
import { Freight } from '@edr/types';
|
||||
import { BillingService } from '../billing/billing.service';
|
||||
import { BookingsService } from '../bookings/bookings.service';
|
||||
|
||||
@ApiTags('last-mile')
|
||||
@ApiBearerAuth()
|
||||
@@ -30,6 +33,8 @@ export class LastMileController {
|
||||
constructor(
|
||||
private readonly lastMileService: LastMileService,
|
||||
private readonly lastMileInvoiceService: LastMileInvoiceService,
|
||||
private readonly billingService: BillingService,
|
||||
private readonly bookingsService: BookingsService
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@@ -80,9 +85,36 @@ export class LastMileController {
|
||||
async update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateLastMileDto) {
|
||||
const record = await this.lastMileService.update(id, dto);
|
||||
// Auto-generate invoice if distance or payment was updated
|
||||
if (dto.exactKm !== undefined || dto.remainingPayment !== undefined) {
|
||||
await this.lastMileInvoiceService.ensureInvoiceFor(record);
|
||||
}
|
||||
const booking = await this.bookingsService.findById(record.bookingId);
|
||||
if (dto.exactKm !== undefined || dto.exactKm != record.exactKm || dto.remainingPayment !== undefined || dto.remainingPayment !== record.remainingPayment) {
|
||||
await this.billingService.generateInvoice({
|
||||
source: Freight.InvoiceSource.FirstMile,
|
||||
sourceId: record.id,
|
||||
type: "FIRST_MILE",
|
||||
companyId: booking.companyId,
|
||||
companyProfileId: booking.companyProfileId,
|
||||
currency: "ETB",
|
||||
|
||||
lines: [
|
||||
{
|
||||
chargeType: "FIRST_MILE",
|
||||
description: "First Mile Transportation Service",
|
||||
quantity: 1,
|
||||
unitRate: record.remainingPayment,
|
||||
amount: record.remainingPayment,
|
||||
currency: "ETB",
|
||||
},
|
||||
],
|
||||
|
||||
subtotalAmount: record.remainingPayment,
|
||||
taxAmount: 0, // Replace if VAT/tax applies
|
||||
totalAmount: record.remainingPayment,
|
||||
|
||||
dueInDays: 7,
|
||||
status: Freight.InvoiceStatus.Pending,
|
||||
});
|
||||
await this.lastMileInvoiceService.ensureInvoiceFor(record);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ export enum InvoiceSource {
|
||||
Booking = "booking",
|
||||
Warehouse = "warehouse",
|
||||
Demurrage = "demurrage",
|
||||
FirstMile = "firstmile"
|
||||
}
|
||||
|
||||
export enum SchedulingStatus {
|
||||
|
||||
Reference in New Issue
Block a user