Frontend Changes
This commit is contained in:
@@ -22,7 +22,7 @@ class AdminInvoiceController extends Controller
|
||||
{
|
||||
$query = Invoice::with(['items', 'customer', 'container']);
|
||||
|
||||
// Search (जर पुढे form मधून पाठवलंस तर)
|
||||
// Search
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
@@ -373,7 +373,7 @@ class AdminInvoiceController extends Controller
|
||||
public function storeChargeGroup(Request $request, $invoiceId)
|
||||
{
|
||||
$invoice = Invoice::with('items')->findOrFail($invoiceId);
|
||||
|
||||
|
||||
$data = $request->validate([
|
||||
'group_name' => 'nullable|string|max:255',
|
||||
'basis_type' => 'required|in:ttl_qty,amount,ttl_cbm,ttl_kg',
|
||||
@@ -383,7 +383,7 @@ class AdminInvoiceController extends Controller
|
||||
'item_ids' => 'required|array',
|
||||
'item_ids.*' => 'integer|exists:invoice_items,id',
|
||||
]);
|
||||
|
||||
|
||||
$group = InvoiceChargeGroup::create([
|
||||
'invoice_id' => $invoice->id,
|
||||
'group_name' => $data['group_name'] ?? null,
|
||||
@@ -392,19 +392,53 @@ class AdminInvoiceController extends Controller
|
||||
'rate' => $data['rate'],
|
||||
'total_charge' => $data['auto_total'],
|
||||
]);
|
||||
|
||||
|
||||
foreach ($data['item_ids'] as $itemId) {
|
||||
InvoiceChargeGroupItem::create([
|
||||
'group_id' => $group->id,
|
||||
'invoice_item_id' => $itemId,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if ($request->ajax()) {
|
||||
// load items with invoice item relation
|
||||
$group->load(['items.item']);
|
||||
|
||||
// prepare simple array for JS
|
||||
$itemsPayload = $group->items->map(function ($gi) {
|
||||
$it = $gi->item;
|
||||
return [
|
||||
'description' => $it->description,
|
||||
'qty' => $it->qty,
|
||||
'ttlqty' => $it->ttl_qty,
|
||||
'cbm' => $it->cbm,
|
||||
'ttlcbm' => $it->ttl_cbm,
|
||||
'kg' => $it->kg,
|
||||
'ttlkg' => $it->ttl_kg,
|
||||
'amount' => $it->ttl_amount,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Charge group created successfully.',
|
||||
'group' => [
|
||||
'id' => $group->id,
|
||||
'group_name' => $group->group_name,
|
||||
'basis_type' => $group->basis_type,
|
||||
'basis_value' => $group->basis_value,
|
||||
'rate' => $group->rate,
|
||||
'total_charge'=> $group->total_charge,
|
||||
'items' => $itemsPayload,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', 'Charge group saved successfully.');
|
||||
}
|
||||
|
||||
|
||||
public function download(Invoice $invoice)
|
||||
{
|
||||
if (!$invoice->pdf_path || !Storage::exists($invoice->pdf_path)) {
|
||||
|
||||
Reference in New Issue
Block a user