mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
mile
This commit is contained in:
@@ -23,9 +23,6 @@ import { SetDistancesDto } from './dto/set-distances.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()
|
||||
@@ -35,8 +32,6 @@ export class LastMileController {
|
||||
constructor(
|
||||
private readonly lastMileService: LastMileService,
|
||||
private readonly lastMileInvoiceService: LastMileInvoiceService,
|
||||
private readonly billingService: BillingService,
|
||||
private readonly bookingsService: BookingsService
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@@ -85,40 +80,9 @@ export class LastMileController {
|
||||
@TrainSchedulingManage()
|
||||
@ApiOperation({ summary: 'Update a last-mile leg' })
|
||||
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
|
||||
const booking = await this.bookingsService.findById(record.bookingId);
|
||||
const currency = booking.paymentCurrency || "ETB";
|
||||
if (dto.exactKm !== undefined || dto.exactKm != record.exactKm || dto.remainingPayment !== undefined || dto.remainingPayment !== record.remainingPayment) {
|
||||
await this.billingService.generateInvoice({
|
||||
source: Freight.InvoiceSource.LastMile,
|
||||
sourceId: record.id,
|
||||
type: "LAST_MILE",
|
||||
companyId: booking.companyId,
|
||||
companyProfileId: booking.companyProfileId,
|
||||
currency,
|
||||
|
||||
lines: [
|
||||
{
|
||||
chargeType: "LAST_MILE",
|
||||
description: "Last Mile Transportation Service",
|
||||
quantity: 1,
|
||||
unitRate: record.remainingPayment,
|
||||
amount: record.remainingPayment,
|
||||
currency,
|
||||
},
|
||||
],
|
||||
|
||||
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;
|
||||
// No invoice side-effects here — invoices are generated only via the
|
||||
// explicit POST :id/invoice endpoint (the "Generate Invoice" action).
|
||||
return this.lastMileService.update(id, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
|
||||
Reference in New Issue
Block a user