mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +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 { LastMileStatus } from './entities/last-mile.entity';
|
||||||
import { LastMileService } from './last-mile.service';
|
import { LastMileService } from './last-mile.service';
|
||||||
import { LastMileInvoiceService } from './last-mile-invoice.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')
|
@ApiTags('last-mile')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@@ -35,8 +32,6 @@ export class LastMileController {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly lastMileService: LastMileService,
|
private readonly lastMileService: LastMileService,
|
||||||
private readonly lastMileInvoiceService: LastMileInvoiceService,
|
private readonly lastMileInvoiceService: LastMileInvoiceService,
|
||||||
private readonly billingService: BillingService,
|
|
||||||
private readonly bookingsService: BookingsService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@@ -85,40 +80,9 @@ export class LastMileController {
|
|||||||
@TrainSchedulingManage()
|
@TrainSchedulingManage()
|
||||||
@ApiOperation({ summary: 'Update a last-mile leg' })
|
@ApiOperation({ summary: 'Update a last-mile leg' })
|
||||||
async update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateLastMileDto) {
|
async update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateLastMileDto) {
|
||||||
const record = await this.lastMileService.update(id, dto);
|
// No invoice side-effects here — invoices are generated only via the
|
||||||
// Auto-generate invoice if distance or payment was updated
|
// explicit POST :id/invoice endpoint (the "Generate Invoice" action).
|
||||||
const booking = await this.bookingsService.findById(record.bookingId);
|
return this.lastMileService.update(id, dto);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
|||||||
Reference in New Issue
Block a user