2025-11-12 11:56:43 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Models\Order;
|
2025-11-13 13:05:17 +05:30
|
|
|
use App\Models\OrderItem;
|
|
|
|
|
use App\Models\MarkList;
|
2025-12-01 10:38:52 +05:30
|
|
|
use App\Models\Invoice;
|
|
|
|
|
use App\Models\InvoiceItem;
|
|
|
|
|
use App\Models\User;
|
2026-02-27 10:51:26 +05:30
|
|
|
use App\Models\Container;
|
|
|
|
|
use App\Models\Admin;
|
|
|
|
|
use App\Models\Shipment;
|
2025-12-22 22:38:35 +05:30
|
|
|
use PDF;
|
2025-12-03 10:35:20 +05:30
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
|
use App\Exports\OrdersExport;
|
2025-12-23 12:22:35 +05:30
|
|
|
use App\Imports\OrderItemsPreviewImport;
|
|
|
|
|
use Illuminate\Validation\ValidationException;
|
2026-02-27 10:51:26 +05:30
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use App\Exports\InvoicesExport;
|
2025-12-03 10:35:20 +05:30
|
|
|
|
2025-11-12 11:56:43 +05:30
|
|
|
class AdminOrderController extends Controller
|
|
|
|
|
{
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
2026-02-27 10:51:26 +05:30
|
|
|
* DASHBOARD (old UI: stats + recent orders)
|
2025-12-22 22:38:35 +05:30
|
|
|
* ---------------------------*/
|
2026-02-27 10:51:26 +05:30
|
|
|
public function dashboard()
|
2025-11-12 11:56:43 +05:30
|
|
|
{
|
2026-03-13 23:06:19 +05:30
|
|
|
// ── Order counts (from Invoice Management / Orders table) ──
|
|
|
|
|
$totalOrders = Order::count();
|
|
|
|
|
|
|
|
|
|
// "Pending" म्हणजे delivered नसलेले सर्व orders
|
|
|
|
|
// Order तयार होतो तेव्हा status = 'order_placed' असतो, 'pending' नाही
|
|
|
|
|
$deliveredStatuses = ['delivered'];
|
|
|
|
|
$pendingOrders = Order::whereNotIn('status', $deliveredStatuses)->count();
|
|
|
|
|
|
|
|
|
|
// ── Invoice counts ──
|
|
|
|
|
$totalContainers = Container::count();
|
|
|
|
|
$totalInvoices = Invoice::count();
|
|
|
|
|
$paidInvoices = Invoice::where('status', 'paid')->count();
|
|
|
|
|
$pendingInvoices = Invoice::where('status', 'pending')->count();
|
|
|
|
|
$overdueInvoices = Invoice::where('status', 'overdue')->count();
|
2026-02-27 10:51:26 +05:30
|
|
|
$totalRevenue = Invoice::sum('final_amount_with_gst');
|
2026-03-13 23:06:19 +05:30
|
|
|
|
|
|
|
|
// ── User / Staff counts ──
|
2026-02-27 10:51:26 +05:30
|
|
|
$activeCustomers = User::where('status', 'active')->count();
|
|
|
|
|
$inactiveCustomers = User::where('status', 'inactive')->count();
|
|
|
|
|
$totalStaff = Admin::where('type', 'staff')->count();
|
|
|
|
|
|
2025-11-13 13:05:17 +05:30
|
|
|
$markList = MarkList::where('status', 'active')->get();
|
2026-02-27 10:51:26 +05:30
|
|
|
$orders = Order::latest()->get();
|
2025-11-12 11:56:43 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
return view('admin.dashboard', compact(
|
|
|
|
|
'totalOrders',
|
|
|
|
|
'pendingOrders',
|
2026-03-13 23:06:19 +05:30
|
|
|
'totalContainers',
|
|
|
|
|
'totalInvoices',
|
|
|
|
|
'paidInvoices',
|
|
|
|
|
'pendingInvoices',
|
|
|
|
|
'overdueInvoices',
|
2026-02-27 10:51:26 +05:30
|
|
|
'totalRevenue',
|
|
|
|
|
'activeCustomers',
|
|
|
|
|
'inactiveCustomers',
|
|
|
|
|
'totalStaff',
|
|
|
|
|
'orders',
|
|
|
|
|
'markList'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ---------------------------
|
|
|
|
|
* LIST (new: Invoices Management for Orders page)
|
|
|
|
|
* ---------------------------*/
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$invoices = DB::table('invoices')
|
|
|
|
|
->leftJoin('containers', 'containers.id', '=', 'invoices.container_id')
|
|
|
|
|
->leftJoin('mark_list', 'mark_list.mark_no', '=', 'invoices.mark_no')
|
|
|
|
|
->select(
|
|
|
|
|
'invoices.id',
|
|
|
|
|
'invoices.invoice_number',
|
|
|
|
|
'invoices.invoice_date',
|
|
|
|
|
'invoices.final_amount',
|
|
|
|
|
'invoices.final_amount_with_gst',
|
|
|
|
|
'invoices.status as invoice_status',
|
|
|
|
|
'invoices.mark_no',
|
2026-03-09 10:24:44 +05:30
|
|
|
'invoices.container_id', // <<< हे नक्की घाल
|
2026-02-27 10:51:26 +05:30
|
|
|
'containers.container_number',
|
|
|
|
|
'containers.container_date',
|
|
|
|
|
DB::raw('COALESCE(invoices.company_name, mark_list.company_name) as company_name'),
|
|
|
|
|
DB::raw('COALESCE(invoices.customer_name, mark_list.customer_name) as customer_name')
|
|
|
|
|
)
|
2026-03-09 10:24:44 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
->when($request->filled('search'), function ($q) use ($request) {
|
|
|
|
|
$search = trim($request->search);
|
|
|
|
|
$q->where(function ($qq) use ($search) {
|
|
|
|
|
$qq->where('invoices.invoice_number', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('containers.container_number', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('invoices.mark_no', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('mark_list.company_name', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('mark_list.customer_name', 'like', "%{$search}%");
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
->when($request->filled('status'), function ($q) use ($request) {
|
|
|
|
|
$q->where('invoices.status', $request->status);
|
|
|
|
|
})
|
2026-03-13 23:06:19 +05:30
|
|
|
->orderByDesc('invoices.invoice_date')
|
|
|
|
|
->orderByDesc('invoices.id')
|
2026-02-27 10:51:26 +05:30
|
|
|
->get();
|
2026-03-13 23:06:19 +05:30
|
|
|
|
|
|
|
|
// ── Real DB counts (filter-independent) ──
|
|
|
|
|
$totalInvoices = \App\Models\Invoice::count();
|
|
|
|
|
$paidInvoices = \App\Models\Invoice::where('status', 'paid')->count();
|
|
|
|
|
$pendingInvoices = \App\Models\Invoice::where('status', 'pending')->count();
|
|
|
|
|
$overdueInvoices = \App\Models\Invoice::where('status', 'overdue')->count();
|
|
|
|
|
|
|
|
|
|
return view('admin.orders', compact(
|
|
|
|
|
'invoices',
|
|
|
|
|
'totalInvoices',
|
|
|
|
|
'paidInvoices',
|
|
|
|
|
'pendingInvoices',
|
|
|
|
|
'overdueInvoices'
|
|
|
|
|
));
|
2025-11-12 11:56:43 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* CREATE NEW ORDER (simple page)
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
public function create()
|
2025-11-13 13:05:17 +05:30
|
|
|
{
|
2025-12-01 10:38:52 +05:30
|
|
|
$markList = MarkList::where('status', 'active')->get();
|
|
|
|
|
return view('admin.orders_create', compact('markList'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* SHOW / POPUP
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
public function show($id)
|
|
|
|
|
{
|
|
|
|
|
$order = Order::with('items', 'markList')->findOrFail($id);
|
2025-12-22 22:38:35 +05:30
|
|
|
$user = $this->getCustomerFromOrder($order);
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return view('admin.orders_show', compact('order', 'user'));
|
2025-11-13 13:05:17 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
public function popup($id)
|
|
|
|
|
{
|
|
|
|
|
$order = Order::with(['items', 'markList'])->findOrFail($id);
|
|
|
|
|
|
|
|
|
|
$user = null;
|
|
|
|
|
if ($order->markList && $order->markList->customer_id) {
|
|
|
|
|
$user = User::where('customer_id', $order->markList->customer_id)->first();
|
|
|
|
|
}
|
2025-12-01 10:38:52 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
return view('admin.popup', compact('order', 'user'));
|
|
|
|
|
}
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* ORDER ITEM MANAGEMENT (existing orders)
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
public function addItem(Request $request, $orderId)
|
2026-02-27 10:51:26 +05:30
|
|
|
{
|
|
|
|
|
$order = Order::findOrFail($orderId);
|
|
|
|
|
|
|
|
|
|
$data = $request->validate([
|
|
|
|
|
'description' => 'required|string',
|
|
|
|
|
'ctn' => 'nullable|numeric',
|
|
|
|
|
'qty' => 'nullable|numeric',
|
|
|
|
|
'unit' => 'nullable|string',
|
|
|
|
|
'price' => 'nullable|numeric',
|
|
|
|
|
'cbm' => 'nullable|numeric',
|
|
|
|
|
'kg' => 'nullable|numeric',
|
|
|
|
|
'shop_no' => 'nullable|string',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$ctn = (float) ($data['ctn'] ?? 0);
|
|
|
|
|
$qty = (float) ($data['qty'] ?? 0);
|
|
|
|
|
$price = (float) ($data['price'] ?? 0);
|
|
|
|
|
$cbm = (float) ($data['cbm'] ?? 0);
|
|
|
|
|
$kg = (float) ($data['kg'] ?? 0);
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$data['ttl_qty'] = $ctn * $qty;
|
|
|
|
|
$data['ttl_amount'] = $data['ttl_qty'] * $price;
|
|
|
|
|
$data['ttl_cbm'] = $cbm * $ctn;
|
|
|
|
|
$data['ttl_kg'] = $ctn * $kg;
|
|
|
|
|
|
|
|
|
|
$data['order_id'] = $order->id;
|
|
|
|
|
|
|
|
|
|
OrderItem::create($data);
|
|
|
|
|
|
|
|
|
|
$this->recalcTotals($order);
|
|
|
|
|
|
|
|
|
|
return redirect()->back()->with('success', 'Item added and totals updated.');
|
|
|
|
|
}
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
public function deleteItem($id)
|
|
|
|
|
{
|
2025-12-22 22:38:35 +05:30
|
|
|
$item = OrderItem::findOrFail($id);
|
2025-12-01 10:38:52 +05:30
|
|
|
$order = $item->order;
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$item->delete();
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$this->recalcTotals($order);
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return redirect()->back()->with('success', 'Item deleted and totals updated.');
|
2025-11-17 10:33:11 +05:30
|
|
|
}
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
public function restoreItem($id)
|
|
|
|
|
{
|
2025-12-22 22:38:35 +05:30
|
|
|
$item = OrderItem::withTrashed()->findOrFail($id);
|
2025-12-01 10:38:52 +05:30
|
|
|
$order = Order::findOrFail($item->order_id);
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$item->restore();
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$this->recalcTotals($order);
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return redirect()->back()->with('success', 'Item restored and totals updated.');
|
2025-11-17 10:33:11 +05:30
|
|
|
}
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* ORDER CRUD: update / destroy
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
$order = Order::findOrFail($id);
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$data = $request->validate([
|
2025-12-22 22:38:35 +05:30
|
|
|
'mark_no' => 'required|string',
|
|
|
|
|
'origin' => 'nullable|string',
|
2025-12-01 10:38:52 +05:30
|
|
|
'destination' => 'nullable|string',
|
|
|
|
|
]);
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$order->update([
|
2025-12-22 22:38:35 +05:30
|
|
|
'mark_no' => $data['mark_no'],
|
|
|
|
|
'origin' => $data['origin'] ?? null,
|
2025-12-01 10:38:52 +05:30
|
|
|
'destination' => $data['destination'] ?? null,
|
|
|
|
|
]);
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$this->recalcTotals($order);
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return redirect()->route('admin.orders.show', $order->id)
|
2025-12-22 22:38:35 +05:30
|
|
|
->with('success', 'Order updated successfully.');
|
2025-12-01 10:38:52 +05:30
|
|
|
}
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
|
|
|
|
$order = Order::findOrFail($id);
|
2025-11-17 10:33:11 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
OrderItem::where('order_id', $order->id)->delete();
|
|
|
|
|
$order->delete();
|
2025-11-12 19:44:04 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return redirect()->route('admin.orders.index')
|
2025-12-22 22:38:35 +05:30
|
|
|
->with('success', 'Order deleted successfully.');
|
2025-12-01 10:38:52 +05:30
|
|
|
}
|
2025-11-12 19:44:04 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* HELPERS
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
private function recalcTotals(Order $order)
|
|
|
|
|
{
|
|
|
|
|
$items = $order->items()->get();
|
|
|
|
|
|
|
|
|
|
$order->update([
|
2026-02-27 10:51:26 +05:30
|
|
|
'ctn' => (int) $items->sum(fn($i) => (int) ($i->ctn ?? 0)),
|
|
|
|
|
'qty' => (int) $items->sum(fn($i) => (int) ($i->qty ?? 0)),
|
|
|
|
|
'ttl_qty' => (int) $items->sum(fn($i) => (int) ($i->ttl_qty ?? 0)),
|
|
|
|
|
'ttl_amount'=> (float) $items->sum(fn($i) => (float) ($i->ttl_amount ?? 0)),
|
|
|
|
|
'cbm' => (float) $items->sum(fn($i) => (float) ($i->cbm ?? 0)),
|
|
|
|
|
'ttl_cbm' => (float) $items->sum(fn($i) => (float) ($i->ttl_cbm ?? 0)),
|
|
|
|
|
'kg' => (float) $items->sum(fn($i) => (float) ($i->kg ?? 0)),
|
|
|
|
|
'ttl_kg' => (float) $items->sum(fn($i) => (float) ($i->ttl_kg ?? 0)),
|
2025-12-01 10:38:52 +05:30
|
|
|
]);
|
2025-11-13 13:05:17 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
private function generateOrderId()
|
2025-11-15 10:08:43 +05:30
|
|
|
{
|
2025-12-22 22:38:35 +05:30
|
|
|
$year = date('y');
|
2025-12-01 10:38:52 +05:30
|
|
|
$prefix = "KNT-$year-";
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$lastOrder = Order::latest('id')->first();
|
2025-12-01 10:38:52 +05:30
|
|
|
$nextNumber = $lastOrder ? intval(substr($lastOrder->order_id, -8)) + 1 : 1;
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return $prefix . str_pad($nextNumber, 8, '0', STR_PAD_LEFT);
|
2025-11-15 10:08:43 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* INVOICE CREATION HELPERS
|
|
|
|
|
* ---------------------------*/
|
2025-12-01 10:38:52 +05:30
|
|
|
private function createInvoice(Order $order)
|
|
|
|
|
{
|
|
|
|
|
$invoiceNumber = $this->generateInvoiceNumber();
|
2025-12-22 22:38:35 +05:30
|
|
|
$customer = $this->getCustomerFromMarkList($order->mark_no);
|
|
|
|
|
$totalAmount = $order->ttl_amount;
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
$invoice = Invoice::create([
|
2025-12-22 22:38:35 +05:30
|
|
|
'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' => $totalAmount,
|
|
|
|
|
'gst_percent' => 0,
|
|
|
|
|
'gst_amount' => 0,
|
2025-12-01 10:38:52 +05:30
|
|
|
'final_amount_with_gst' => $totalAmount,
|
2025-12-22 22:38:35 +05:30
|
|
|
'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,
|
|
|
|
|
'pdf_path' => null,
|
2025-12-01 10:38:52 +05:30
|
|
|
]);
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
foreach ($order->items as $item) {
|
|
|
|
|
InvoiceItem::create([
|
2025-12-22 22:38:35 +05:30
|
|
|
'invoice_id' => $invoice->id,
|
2025-12-01 10:38:52 +05:30
|
|
|
'description' => $item->description,
|
2025-12-22 22:38:35 +05:30
|
|
|
'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,
|
2025-12-01 10:38:52 +05:30
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
private function generateInvoiceNumber()
|
2025-11-13 13:05:17 +05:30
|
|
|
{
|
2025-12-01 10:38:52 +05:30
|
|
|
$lastInvoice = Invoice::latest()->first();
|
|
|
|
|
$nextInvoice = $lastInvoice ? $lastInvoice->id + 1 : 1;
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
return 'INV-' . date('Y') . '-' . str_pad($nextInvoice, 6, '0', STR_PAD_LEFT);
|
2025-11-12 11:56:43 +05:30
|
|
|
}
|
2025-11-12 19:44:04 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
private function getCustomerFromMarkList($markNo)
|
2025-11-26 23:07:12 +05:30
|
|
|
{
|
2025-12-01 10:38:52 +05:30
|
|
|
$markList = MarkList::where('mark_no', $markNo)->first();
|
2025-11-26 23:07:12 +05:30
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
if ($markList && $markList->customer_id) {
|
|
|
|
|
return User::where('customer_id', $markList->customer_id)->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2025-11-26 23:07:12 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-01 10:38:52 +05:30
|
|
|
private function getCustomerFromOrder($order)
|
|
|
|
|
{
|
|
|
|
|
if ($order->markList && $order->markList->customer_id) {
|
|
|
|
|
return User::where('customer_id', $order->markList->customer_id)->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-11-13 13:05:17 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* SEE (detailed)
|
|
|
|
|
* ---------------------------*/
|
2025-12-19 11:12:06 +05:30
|
|
|
public function see($id)
|
|
|
|
|
{
|
|
|
|
|
$order = Order::with([
|
|
|
|
|
'markList',
|
|
|
|
|
'items',
|
|
|
|
|
'shipments' => function ($q) use ($id) {
|
|
|
|
|
$q->whereHas('orders', function ($oq) use ($id) {
|
|
|
|
|
$oq->where('orders.id', $id)
|
2025-12-22 22:38:35 +05:30
|
|
|
->whereNull('orders.deleted_at');
|
2025-12-19 11:12:06 +05:30
|
|
|
})->with([
|
|
|
|
|
'orders' => function ($oq) use ($id) {
|
|
|
|
|
$oq->where('orders.id', $id)
|
2025-12-22 22:38:35 +05:30
|
|
|
->whereNull('orders.deleted_at')
|
|
|
|
|
->with('items');
|
2025-12-19 11:12:06 +05:30
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
])->findOrFail($id);
|
|
|
|
|
|
|
|
|
|
$orderData = [
|
|
|
|
|
'order_id' => $order->order_id,
|
|
|
|
|
'status' => $order->status,
|
|
|
|
|
'totals' => [
|
2026-02-27 10:51:26 +05:30
|
|
|
'ctn' => $order->ctn,
|
|
|
|
|
'qty' => $order->qty,
|
|
|
|
|
'ttl_qty' => $order->ttl_qty,
|
|
|
|
|
'cbm' => $order->cbm,
|
|
|
|
|
'ttl_cbm' => $order->ttl_cbm,
|
|
|
|
|
'kg' => $order->kg,
|
|
|
|
|
'ttl_kg' => $order->ttl_kg,
|
|
|
|
|
'amount' => $order->ttl_amount,
|
2025-12-19 11:12:06 +05:30
|
|
|
],
|
|
|
|
|
'items' => $order->items,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$shipmentsData = [];
|
|
|
|
|
foreach ($order->shipments as $shipment) {
|
|
|
|
|
$shipmentOrders = [];
|
|
|
|
|
$totals = [
|
|
|
|
|
'ctn' => 0, 'qty' => 0, 'ttl_qty' => 0,
|
|
|
|
|
'cbm' => 0, 'ttl_cbm' => 0,
|
2025-12-22 22:38:35 +05:30
|
|
|
'kg' => 0, 'ttl_kg' => 0,
|
2025-12-19 11:12:06 +05:30
|
|
|
'amount' => 0,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($shipment->orders as $shipOrder) {
|
|
|
|
|
foreach ($shipOrder->items as $item) {
|
|
|
|
|
$shipmentOrders[] = [
|
|
|
|
|
'order_id' => $shipOrder->order_id,
|
|
|
|
|
'origin' => $shipOrder->origin,
|
|
|
|
|
'destination' => $shipOrder->destination,
|
|
|
|
|
'description' => $item->description,
|
|
|
|
|
'ctn' => $item->ctn,
|
|
|
|
|
'qty' => $item->qty,
|
|
|
|
|
'ttl_qty' => $item->ttl_qty,
|
|
|
|
|
'amount' => $item->ttl_amount,
|
|
|
|
|
];
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$totals['ctn'] += $item->ctn;
|
|
|
|
|
$totals['qty'] += $item->qty;
|
|
|
|
|
$totals['ttl_qty'] += $item->ttl_qty;
|
|
|
|
|
$totals['cbm'] += $item->cbm;
|
|
|
|
|
$totals['ttl_cbm'] += $item->ttl_cbm;
|
|
|
|
|
$totals['kg'] += $item->kg;
|
|
|
|
|
$totals['ttl_kg'] += $item->ttl_kg;
|
|
|
|
|
$totals['amount'] += $item->ttl_amount;
|
2025-12-19 11:12:06 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($shipmentOrders)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$shipmentsData[] = [
|
|
|
|
|
'shipment_id' => $shipment->shipment_id,
|
|
|
|
|
'status' => $shipment->status,
|
|
|
|
|
'date' => $shipment->shipment_date,
|
|
|
|
|
'total_orders' => 1,
|
|
|
|
|
'orders' => $shipmentOrders,
|
|
|
|
|
'totals' => $totals,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$invoiceData = null;
|
|
|
|
|
|
|
|
|
|
return view('admin.see_order', compact(
|
|
|
|
|
'order',
|
|
|
|
|
'orderData',
|
|
|
|
|
'shipmentsData',
|
|
|
|
|
'invoiceData'
|
|
|
|
|
));
|
|
|
|
|
}
|
2025-11-15 10:08:43 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
2026-02-27 10:51:26 +05:30
|
|
|
* FILTERED LIST + EXPORTS (old orders listing)
|
2025-12-22 22:38:35 +05:30
|
|
|
* ---------------------------*/
|
2025-12-19 16:15:18 +05:30
|
|
|
public function orderShow()
|
|
|
|
|
{
|
|
|
|
|
$orders = Order::with([
|
2025-12-22 22:38:35 +05:30
|
|
|
'markList',
|
|
|
|
|
'shipments',
|
|
|
|
|
])->latest('id')->get();
|
2025-12-19 11:12:06 +05:30
|
|
|
|
2025-12-19 16:15:18 +05:30
|
|
|
return view('admin.orders', compact('orders'));
|
|
|
|
|
}
|
2025-12-01 10:34:27 +05:30
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
private function buildOrdersQueryFromRequest(Request $request)
|
2025-12-22 22:38:35 +05:30
|
|
|
{
|
|
|
|
|
$query = Order::query()
|
2026-02-27 10:51:26 +05:30
|
|
|
->with(['markList', 'shipments']);
|
2025-12-19 11:12:06 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
if ($request->filled('search')) {
|
|
|
|
|
$search = trim($request->search);
|
2025-12-19 11:12:06 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$query->where(function ($q) use ($search) {
|
|
|
|
|
$q->where('orders.order_id', 'like', "%{$search}%")
|
2025-12-19 11:12:06 +05:30
|
|
|
->orWhereHas('markList', function ($q2) use ($search) {
|
|
|
|
|
$q2->where('company_name', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('customer_id', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('origin', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('destination', 'like', "%{$search}%");
|
|
|
|
|
})
|
|
|
|
|
->orWhereHas('shipments', function ($q4) use ($search) {
|
|
|
|
|
$q4->where('shipments.shipment_id', 'like', "%{$search}%");
|
|
|
|
|
});
|
2025-12-22 22:38:35 +05:30
|
|
|
});
|
2025-12-05 17:16:02 +05:30
|
|
|
}
|
2025-12-03 10:35:20 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
if ($request->filled('shipment')) {
|
|
|
|
|
$query->where(function ($q) use ($request) {
|
|
|
|
|
$q->whereHas('shipments', function ($q2) use ($request) {
|
|
|
|
|
$q2->where('status', $request->shipment);
|
|
|
|
|
})->orWhereDoesntHave('shipments');
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-03 10:35:20 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
if ($request->filled('from_date')) {
|
|
|
|
|
$query->whereDate('orders.created_at', '>=', $request->from_date);
|
|
|
|
|
}
|
2025-11-26 23:07:12 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
if ($request->filled('to_date')) {
|
|
|
|
|
$query->whereDate('orders.created_at', '<=', $request->to_date);
|
|
|
|
|
}
|
2025-12-19 11:12:06 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
return $query->latest('orders.id');
|
|
|
|
|
}
|
2025-12-03 10:35:20 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
public function downloadPdf(Request $request)
|
|
|
|
|
{
|
2026-02-27 10:51:26 +05:30
|
|
|
$invoices = DB::table('invoices')
|
|
|
|
|
->leftJoin('containers', 'containers.id', '=', 'invoices.container_id')
|
|
|
|
|
->leftJoin('mark_list', 'mark_list.mark_no', '=', 'invoices.mark_no')
|
|
|
|
|
->select(
|
|
|
|
|
'invoices.invoice_number',
|
|
|
|
|
'invoices.invoice_date',
|
|
|
|
|
'invoices.mark_no',
|
|
|
|
|
'containers.container_number',
|
|
|
|
|
'containers.container_date',
|
|
|
|
|
DB::raw('COALESCE(invoices.company_name, mark_list.company_name) as company_name'),
|
|
|
|
|
DB::raw('COALESCE(invoices.customer_name, mark_list.customer_name) as customer_name'),
|
|
|
|
|
'invoices.final_amount',
|
|
|
|
|
'invoices.final_amount_with_gst',
|
|
|
|
|
'invoices.status as invoice_status'
|
|
|
|
|
)
|
|
|
|
|
->when($request->filled('search'), function ($q) use ($request) {
|
|
|
|
|
$search = trim($request->search);
|
|
|
|
|
$q->where(function ($qq) use ($search) {
|
|
|
|
|
$qq->where('invoices.invoice_number', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('invoices.mark_no', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('containers.container_number', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('mark_list.company_name', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('mark_list.customer_name', 'like', "%{$search}%");
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
->when($request->filled('status'), function ($q) use ($request) {
|
|
|
|
|
$q->where('invoices.status', $request->status);
|
|
|
|
|
})
|
|
|
|
|
->when($request->filled('from_date'), function ($q) use ($request) {
|
|
|
|
|
$q->whereDate('invoices.invoice_date', '>=', $request->from_date);
|
|
|
|
|
})
|
|
|
|
|
->when($request->filled('to_date'), function ($q) use ($request) {
|
|
|
|
|
$q->whereDate('invoices.invoice_date', '<=', $request->to_date);
|
|
|
|
|
})
|
|
|
|
|
->orderByDesc('containers.container_date')
|
|
|
|
|
->orderByDesc('invoices.id')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
$pdf = PDF::loadView('admin.pdf.invoices_report', compact('invoices'))
|
2025-12-22 22:38:35 +05:30
|
|
|
->setPaper('a4', 'landscape');
|
2026-02-27 10:51:26 +05:30
|
|
|
|
2025-12-19 11:12:06 +05:30
|
|
|
return $pdf->download(
|
2026-02-27 10:51:26 +05:30
|
|
|
'invoices-report-' . now()->format('Y-m-d') . '.pdf'
|
2025-12-19 11:12:06 +05:30
|
|
|
);
|
2025-12-22 22:38:35 +05:30
|
|
|
}
|
2026-02-27 10:51:26 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
public function downloadExcel(Request $request)
|
|
|
|
|
{
|
|
|
|
|
return Excel::download(
|
2026-02-27 10:51:26 +05:30
|
|
|
new InvoicesExport($request),
|
|
|
|
|
'invoices-report-' . now()->format('Y-m-d') . '.xlsx'
|
2025-12-19 11:12:06 +05:30
|
|
|
);
|
2025-12-01 12:45:25 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* --------------------------------------------------
|
|
|
|
|
* NEW: Create Order + Invoice directly from popup
|
|
|
|
|
* --------------------------------------------------*/
|
|
|
|
|
public function addTempItem(Request $request)
|
2025-12-05 17:16:02 +05:30
|
|
|
{
|
|
|
|
|
$request->validate([
|
2025-12-22 22:38:35 +05:30
|
|
|
'mark_no' => 'required',
|
2026-02-27 10:51:26 +05:30
|
|
|
'origin' => 'nullable',
|
|
|
|
|
'destination' => 'nullable',
|
2025-12-05 17:16:02 +05:30
|
|
|
]);
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$items = $request->validate([
|
|
|
|
|
'items' => 'required|array',
|
|
|
|
|
'items.*.description' => 'required|string',
|
|
|
|
|
'items.*.ctn' => 'nullable|numeric',
|
|
|
|
|
'items.*.qty' => 'nullable|numeric',
|
|
|
|
|
'items.*.unit' => 'nullable|string',
|
|
|
|
|
'items.*.price' => 'nullable|numeric',
|
|
|
|
|
'items.*.cbm' => 'nullable|numeric',
|
|
|
|
|
'items.*.kg' => 'nullable|numeric',
|
|
|
|
|
'items.*.shop_no' => 'nullable|string',
|
|
|
|
|
])['items'];
|
|
|
|
|
|
|
|
|
|
$items = array_filter($items, function ($row) {
|
|
|
|
|
return trim($row['description'] ?? '') !== '';
|
|
|
|
|
});
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
if (empty($items)) {
|
2025-12-22 22:38:35 +05:30
|
|
|
return back()->with('error', 'Add at least one item.');
|
2025-12-05 17:16:02 +05:30
|
|
|
}
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-23 14:15:03 +05:30
|
|
|
foreach ($items as &$item) {
|
|
|
|
|
$ctn = (float) ($item['ctn'] ?? 0);
|
|
|
|
|
$qty = (float) ($item['qty'] ?? 0);
|
|
|
|
|
$price = (float) ($item['price'] ?? 0);
|
|
|
|
|
$cbm = (float) ($item['cbm'] ?? 0);
|
|
|
|
|
$kg = (float) ($item['kg'] ?? 0);
|
|
|
|
|
|
|
|
|
|
$item['ttl_qty'] = $ctn * $qty;
|
|
|
|
|
$item['ttl_amount'] = $item['ttl_qty'] * $price;
|
|
|
|
|
$item['ttl_cbm'] = $cbm * $ctn;
|
|
|
|
|
$item['ttl_kg'] = $ctn * $kg;
|
|
|
|
|
}
|
2026-02-27 10:51:26 +05:30
|
|
|
unset($item);
|
2025-12-23 14:15:03 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$total_ctn = array_sum(array_column($items, 'ctn'));
|
|
|
|
|
$total_qty = array_sum(array_column($items, 'qty'));
|
|
|
|
|
$total_ttl_qty = array_sum(array_column($items, 'ttl_qty'));
|
|
|
|
|
$total_amount = array_sum(array_column($items, 'ttl_amount'));
|
|
|
|
|
$total_cbm = array_sum(array_column($items, 'cbm'));
|
|
|
|
|
$total_ttl_cbm = array_sum(array_column($items, 'ttl_cbm'));
|
|
|
|
|
$total_kg = array_sum(array_column($items, 'kg'));
|
|
|
|
|
$total_ttl_kg = array_sum(array_column($items, 'ttl_kg'));
|
2025-12-23 14:15:03 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$orderId = $this->generateOrderId();
|
2025-12-05 17:16:02 +05:30
|
|
|
|
|
|
|
|
$order = Order::create([
|
2025-12-22 22:38:35 +05:30
|
|
|
'order_id' => $orderId,
|
|
|
|
|
'mark_no' => $request->mark_no,
|
|
|
|
|
'origin' => $request->origin,
|
|
|
|
|
'destination'=> $request->destination,
|
|
|
|
|
'ctn' => $total_ctn,
|
|
|
|
|
'qty' => $total_qty,
|
|
|
|
|
'ttl_qty' => $total_ttl_qty,
|
2025-12-05 17:16:02 +05:30
|
|
|
'ttl_amount' => $total_amount,
|
2025-12-22 22:38:35 +05:30
|
|
|
'cbm' => $total_cbm,
|
|
|
|
|
'ttl_cbm' => $total_ttl_cbm,
|
|
|
|
|
'kg' => $total_kg,
|
|
|
|
|
'ttl_kg' => $total_ttl_kg,
|
2025-12-23 00:36:15 +05:30
|
|
|
'status' => 'order_placed',
|
2025-12-03 15:36:04 +05:30
|
|
|
]);
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
foreach ($items as $item) {
|
|
|
|
|
OrderItem::create([
|
2025-12-22 22:38:35 +05:30
|
|
|
'order_id' => $order->id,
|
|
|
|
|
'description'=> $item['description'],
|
|
|
|
|
'ctn' => $item['ctn'],
|
|
|
|
|
'qty' => $item['qty'],
|
|
|
|
|
'ttl_qty' => $item['ttl_qty'],
|
|
|
|
|
'unit' => $item['unit'],
|
|
|
|
|
'price' => $item['price'],
|
2025-12-05 17:16:02 +05:30
|
|
|
'ttl_amount' => $item['ttl_amount'],
|
2025-12-22 22:38:35 +05:30
|
|
|
'cbm' => $item['cbm'],
|
|
|
|
|
'ttl_cbm' => $item['ttl_cbm'],
|
|
|
|
|
'kg' => $item['kg'],
|
|
|
|
|
'ttl_kg' => $item['ttl_kg'],
|
|
|
|
|
'shop_no' => $item['shop_no'],
|
2025-12-05 17:16:02 +05:30
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$invoiceNumber = $this->generateInvoiceNumber();
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
$markList = MarkList::where('mark_no', $order->mark_no)->first();
|
|
|
|
|
$customer = null;
|
|
|
|
|
if ($markList && $markList->customer_id) {
|
2025-12-22 22:38:35 +05:30
|
|
|
$customer = User::where('customer_id', $markList->customer_id)->first();
|
2025-12-05 17:16:02 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
$invoice = 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,
|
2025-12-05 17:16:02 +05:30
|
|
|
'final_amount_with_gst' => $total_amount,
|
2025-12-22 22:38:35 +05:30
|
|
|
'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,
|
|
|
|
|
'pdf_path' => null,
|
2025-12-01 12:45:25 +05:30
|
|
|
]);
|
|
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
foreach ($order->items as $item) {
|
2025-12-22 22:38:35 +05:30
|
|
|
InvoiceItem::create([
|
|
|
|
|
'invoice_id' => $invoice->id,
|
2025-12-05 17:16:02 +05:30
|
|
|
'description' => $item->description,
|
2025-12-22 22:38:35 +05:30
|
|
|
'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,
|
2025-12-05 17:16:02 +05:30
|
|
|
]);
|
|
|
|
|
}
|
2025-12-01 12:45:25 +05:30
|
|
|
|
2025-12-05 17:16:02 +05:30
|
|
|
return redirect()->route('admin.orders.index')
|
2025-12-22 22:38:35 +05:30
|
|
|
->with('success', 'Order + Invoice created successfully.');
|
2025-12-05 17:16:02 +05:30
|
|
|
}
|
2025-12-03 15:36:04 +05:30
|
|
|
|
2025-12-22 22:38:35 +05:30
|
|
|
/* ---------------------------
|
|
|
|
|
* UPDATE ORDER ITEM (existing orders)
|
|
|
|
|
* ---------------------------*/
|
2025-12-05 17:16:02 +05:30
|
|
|
public function updateItem(Request $request, $id)
|
|
|
|
|
{
|
2026-02-27 10:51:26 +05:30
|
|
|
$item = OrderItem::findOrFail($id);
|
|
|
|
|
$order = $item->order;
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$request->validate([
|
|
|
|
|
'description' => 'required|string',
|
|
|
|
|
'ctn' => 'nullable|numeric',
|
|
|
|
|
'qty' => 'nullable|numeric',
|
|
|
|
|
'unit' => 'nullable|string',
|
|
|
|
|
'price' => 'nullable|numeric',
|
|
|
|
|
'cbm' => 'nullable|numeric',
|
|
|
|
|
'kg' => 'nullable|numeric',
|
|
|
|
|
'shop_no' => 'nullable|string',
|
|
|
|
|
]);
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$ctn = (float) ($request->ctn ?? 0);
|
|
|
|
|
$qty = (float) ($request->qty ?? 0);
|
|
|
|
|
$price = (float) ($request->price ?? 0);
|
|
|
|
|
$cbm = (float) ($request->cbm ?? 0);
|
|
|
|
|
$kg = (float) ($request->kg ?? 0);
|
|
|
|
|
|
|
|
|
|
$item->update([
|
|
|
|
|
'description' => $request->description,
|
|
|
|
|
'ctn' => $ctn,
|
|
|
|
|
'qty' => $qty,
|
|
|
|
|
'ttl_qty' => $ctn * $qty,
|
|
|
|
|
'unit' => $request->unit,
|
|
|
|
|
'price' => $price,
|
|
|
|
|
'ttl_amount' => ($ctn * $qty) * $price,
|
|
|
|
|
'cbm' => $cbm,
|
|
|
|
|
'ttl_cbm' => $cbm * $ctn,
|
|
|
|
|
'kg' => $kg,
|
|
|
|
|
'ttl_kg' => $ctn * $kg,
|
|
|
|
|
'shop_no' => $request->shop_no,
|
|
|
|
|
]);
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$this->recalcTotals($order);
|
2025-12-05 17:16:02 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
return back()->with('success', 'Item updated successfully');
|
2025-12-03 16:13:37 +05:30
|
|
|
}
|
2025-12-23 12:22:35 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
public function uploadExcelPreview(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$request->validate([
|
|
|
|
|
'excel' => 'required|file|mimes:xlsx,xls'
|
|
|
|
|
]);
|
2025-12-23 12:22:35 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
$import = new OrderItemsPreviewImport();
|
|
|
|
|
Excel::import($import, $request->file('excel'));
|
2025-12-23 12:22:35 +05:30
|
|
|
|
2026-02-27 10:51:26 +05:30
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'items' => $import->rows
|
|
|
|
|
]);
|
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'Invalid Excel file format'
|
|
|
|
|
], 422);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
\Log::error($e);
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'Server error'
|
|
|
|
|
], 500);
|
|
|
|
|
}
|
2025-12-23 12:22:35 +05:30
|
|
|
}
|
2026-03-13 23:06:19 +05:30
|
|
|
}
|