mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
fix problem with ei and edo duplicate
This commit is contained in:
@@ -312,13 +312,28 @@ class InvoiceController extends Controller
|
||||
|
||||
$booking = Booking::find($id);
|
||||
|
||||
$monthlycount = Invoice::where('ei', 'like', 'EI-'.Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'%')->count() + 1;
|
||||
$generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount);
|
||||
|
||||
// Generate EI and EDO only if not exist
|
||||
$invoice = Invoice::where('booking_id', $id)->first();
|
||||
$invoice->ei = 'EI-'.$generatednumber;
|
||||
$invoice->edo = 'EDO-'.$generatednumber;
|
||||
$invoice->save();
|
||||
var_dump($invoice->ei);
|
||||
|
||||
if (!$invoice->ei && !$invoice->edo) {
|
||||
|
||||
|
||||
|
||||
$monthlycount = Invoice::where('ei', 'like', 'EI-'.Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'%')->count() + 1;
|
||||
$generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount);
|
||||
$invoice->ei = 'EI-'.$generatednumber;
|
||||
$invoice->edo = 'EDO-'.$generatednumber;
|
||||
|
||||
// Skip to next count if already exist
|
||||
while (Invoice::where('ei', $invoice->ei)->exists() || Invoice::where('edo', $invoice->edo)->exists()) {
|
||||
$monthlycount = $monthlycount + 1;
|
||||
$generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount);
|
||||
$invoice->ei = 'EI-'.$generatednumber;
|
||||
$invoice->edo = 'EDO-'.$generatednumber;
|
||||
}
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
if(!$status) {
|
||||
return response()->json(['message' => 'Unable to Update Status'], 500);
|
||||
|
||||
Reference in New Issue
Block a user