File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,10 +92,12 @@ export default class OrderInvoiceComponent extends Component {
9292 const results = yield this . store . query ( 'ledger-invoice' , {
9393 order_uuid : order . id ,
9494 with : 'items' ,
95- limit : 1 ,
95+ sort : '-created_at' ,
96+ limit : 10 ,
9697 } ) ;
9798
98- this . invoice = results . firstObject ?? null ;
99+ const invoices = results . toArray ( ) ;
100+ this . invoice = invoices . find ( ( invoice ) => ! [ 'void' , 'cancelled' ] . includes ( invoice . status ) ) ?? invoices [ 0 ] ?? null ;
99101 } catch {
100102 this . invoice = null ;
101103 }
Original file line number Diff line number Diff line change 33namespace Fleetbase \Ledger \Observers ;
44
55use Fleetbase \Ledger \Services \InvoiceService ;
6+ use Fleetbase \Ledger \Models \Invoice ;
67use Illuminate \Support \Facades \Log ;
78
89/**
@@ -56,10 +57,7 @@ public function created($purchaseRate): void
5657 return ;
5758 }
5859
59- // Skip if an invoice already exists for this order (idempotency).
60- if ($ this ->invoiceAlreadyExists ($ order ->uuid )) {
61- return ;
62- }
60+ $ this ->supersedeDraftInvoices ($ order ->uuid );
6361
6462 // Resolve currency: prefer the service quote's currency, fall back to
6563 // the company's country-derived currency, then USD.
@@ -124,10 +122,14 @@ private function resolveOrder($purchaseRate): ?object
124122 }
125123
126124 /**
127- * Check whether a Ledger invoice already exists for the given order UUID .
125+ * Void prior draft invoices so the newly created invoice becomes the active revision .
128126 */
129- private function invoiceAlreadyExists (string $ orderUuid ): bool
127+ private function supersedeDraftInvoices (string $ orderUuid ): void
130128 {
131- return \Fleetbase \Ledger \Models \Invoice::where ('order_uuid ' , $ orderUuid )->exists ();
129+ Invoice::where ('order_uuid ' , $ orderUuid )
130+ ->where ('status ' , 'draft ' )
131+ ->update ([
132+ 'status ' => 'void ' ,
133+ ]);
132134 }
133135}
You can’t perform that action at this time.
0 commit comments