fixes
This commit is contained in:
@@ -92,7 +92,7 @@ class AdminOrderController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
//If you want to auto-create an invoice at order creation, uncomment:
|
//If you want to auto-create an invoice at order creation, uncomment:
|
||||||
// $this->createInvoice($order);
|
$this->createInvoice($order);
|
||||||
|
|
||||||
return redirect()->route('admin.orders.show', $order->id)
|
return redirect()->route('admin.orders.show', $order->id)
|
||||||
->with('success', 'Order created successfully.');
|
->with('success', 'Order created successfully.');
|
||||||
@@ -500,9 +500,14 @@ public function addTempItem(Request $request)
|
|||||||
session()->push('temp_order_items', $item);
|
session()->push('temp_order_items', $item);
|
||||||
|
|
||||||
return redirect()->to(route('admin.orders.index') . '#createOrderForm')
|
return redirect()->to(route('admin.orders.index') . '#createOrderForm')
|
||||||
|
|
||||||
->with('success', 'Item added.');
|
->with('success', 'Item added.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// STEP 3 : FINISH ORDER
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
public function finishOrder(Request $request)
|
public function finishOrder(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
@@ -518,7 +523,9 @@ public function finishOrder(Request $request)
|
|||||||
->with('error', 'Add at least one item before finishing.');
|
->with('error', 'Add at least one item before finishing.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Order ID
|
// =======================
|
||||||
|
// GENERATE ORDER ID
|
||||||
|
// =======================
|
||||||
$year = date('y');
|
$year = date('y');
|
||||||
$prefix = "KNT-$year-";
|
$prefix = "KNT-$year-";
|
||||||
|
|
||||||
@@ -527,7 +534,9 @@ public function finishOrder(Request $request)
|
|||||||
|
|
||||||
$orderId = $prefix . str_pad($nextNumber, 8, '0', STR_PAD_LEFT);
|
$orderId = $prefix . str_pad($nextNumber, 8, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
// =======================
|
||||||
// TOTAL SUMS
|
// TOTAL SUMS
|
||||||
|
// =======================
|
||||||
$total_ctn = array_sum(array_column($items, 'ctn'));
|
$total_ctn = array_sum(array_column($items, 'ctn'));
|
||||||
$total_qty = array_sum(array_column($items, 'qty'));
|
$total_qty = array_sum(array_column($items, 'qty'));
|
||||||
$total_ttl_qty = array_sum(array_column($items, 'ttl_qty'));
|
$total_ttl_qty = array_sum(array_column($items, 'ttl_qty'));
|
||||||
@@ -537,7 +546,9 @@ public function finishOrder(Request $request)
|
|||||||
$total_kg = array_sum(array_column($items, 'kg'));
|
$total_kg = array_sum(array_column($items, 'kg'));
|
||||||
$total_ttl_kg = array_sum(array_column($items, 'ttl_kg'));
|
$total_ttl_kg = array_sum(array_column($items, 'ttl_kg'));
|
||||||
|
|
||||||
|
// =======================
|
||||||
// CREATE ORDER
|
// CREATE ORDER
|
||||||
|
// =======================
|
||||||
$order = Order::create([
|
$order = Order::create([
|
||||||
'order_id' => $orderId,
|
'order_id' => $orderId,
|
||||||
'mark_no' => $request->mark_no,
|
'mark_no' => $request->mark_no,
|
||||||
@@ -554,7 +565,7 @@ public function finishOrder(Request $request)
|
|||||||
'status' => 'pending',
|
'status' => 'pending',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// SAVE ALL SUB-ITEMS
|
// SAVE ORDER ITEMS
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
OrderItem::create([
|
OrderItem::create([
|
||||||
'order_id' => $order->id,
|
'order_id' => $order->id,
|
||||||
@@ -573,11 +584,86 @@ public function finishOrder(Request $request)
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
// INVOICE CREATION START
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
// 1. Auto-generate invoice number
|
||||||
|
$lastInvoice = \App\Models\Invoice::latest()->first();
|
||||||
|
$nextInvoice = $lastInvoice ? $lastInvoice->id + 1 : 1;
|
||||||
|
$invoiceNumber = 'INV-' . date('Y') . '-' . str_pad($nextInvoice, 6, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
// 2. Fetch customer (using mark list → customer_id)
|
||||||
|
$markList = MarkList::where('mark_no', $order->mark_no)->first();
|
||||||
|
$customer = null;
|
||||||
|
|
||||||
|
if ($markList && $markList->customer_id) {
|
||||||
|
$customer = \App\Models\User::where('customer_id', $markList->customer_id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Create Invoice Record
|
||||||
|
$invoice = \App\Models\Invoice::create([
|
||||||
|
'order_id' => $order->id,
|
||||||
|
'customer_id' => $customer->id ?? null,
|
||||||
|
'mark_no' => $order->mark_no,
|
||||||
|
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'invoice_date' => now(),
|
||||||
|
'due_date' => now()->addDays(10),
|
||||||
|
|
||||||
|
'payment_method' => null,
|
||||||
|
'reference_no' => null,
|
||||||
|
'status' => 'pending',
|
||||||
|
|
||||||
|
'final_amount' => $total_amount,
|
||||||
|
'gst_percent' => 0,
|
||||||
|
'gst_amount' => 0,
|
||||||
|
'final_amount_with_gst' => $total_amount,
|
||||||
|
|
||||||
|
// snapshot customer fields
|
||||||
|
'customer_name' => $customer->customer_name ?? null,
|
||||||
|
'company_name' => $customer->company_name ?? null,
|
||||||
|
'customer_email' => $customer->email ?? null,
|
||||||
|
'customer_mobile' => $customer->mobile_no ?? null,
|
||||||
|
'customer_address' => $customer->address ?? null,
|
||||||
|
'pincode' => $customer->pincode ?? null,
|
||||||
|
|
||||||
|
'notes' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 4. Clone order items into invoice_items
|
||||||
|
foreach ($order->items as $item) {
|
||||||
|
\App\Models\InvoiceItem::create([
|
||||||
|
'invoice_id' => $invoice->id,
|
||||||
|
'description' => $item->description,
|
||||||
|
'ctn' => $item->ctn,
|
||||||
|
'qty' => $item->qty,
|
||||||
|
'ttl_qty' => $item->ttl_qty,
|
||||||
|
'unit' => $item->unit,
|
||||||
|
'price' => $item->price,
|
||||||
|
'ttl_amount' => $item->ttl_amount,
|
||||||
|
'cbm' => $item->cbm,
|
||||||
|
'ttl_cbm' => $item->ttl_cbm,
|
||||||
|
'kg' => $item->kg,
|
||||||
|
'ttl_kg' => $item->ttl_kg,
|
||||||
|
'shop_no' => $item->shop_no,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. TODO: PDF generation (I will add this later)
|
||||||
|
$invoice->pdf_path = null; // placeholder for now
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
// END INVOICE CREATION
|
||||||
|
// =======================
|
||||||
|
|
||||||
// CLEAR TEMP DATA
|
// CLEAR TEMP DATA
|
||||||
session()->forget(['temp_order_items', 'mark_no', 'origin', 'destination']);
|
session()->forget(['temp_order_items', 'mark_no', 'origin', 'destination']);
|
||||||
|
|
||||||
return redirect()->route('admin.orders.index')
|
return redirect()->route('admin.orders.index')
|
||||||
->with('success', 'Order saved successfully.');
|
->with('success', 'Order + Invoice created successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,8 +87,22 @@ class UserProfileController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'Profile image updated successfully',
|
'message' => 'Profile image updated successfully',
|
||||||
|
'data' => [
|
||||||
|
'customer_id' => $user->customer_id,
|
||||||
|
'customer_name' => $user->customer_name,
|
||||||
|
'company_name' => $user->company_name,
|
||||||
|
'designation' => $user->designation,
|
||||||
|
'email' => $user->email,
|
||||||
|
'mobile' => $user->mobile_no,
|
||||||
|
'address' => $user->address,
|
||||||
|
'pincode' => $user->pincode,
|
||||||
|
'status' => $user->status,
|
||||||
|
'customer_type' => $user->customer_type,
|
||||||
'profile_image' => url($user->profile_image),
|
'profile_image' => url($user->profile_image),
|
||||||
|
'date' => $user->date,
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB |
BIN
public/profile_upload/profile_1764743106.jpg
Normal file
BIN
public/profile_upload/profile_1764743106.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
Reference in New Issue
Block a user