public function findInvoiceItem($id) { return InvoiceItem::findOrFail($id); }
public function destroy($id) { $invoiceItem = InvoiceItem::find($id); $salesId = $invoiceItem->salesInvoice->id; $invoice = SalesInvoice::find($salesId); $invoice->update(['total_amount' => $invoice->total_amount - $invoiceItem->total_price]); $invoiceItem->delete(); return redirect()->action('SalesInvoicesController@edit', [$salesId]); }
public function creation(Requests\CreateSalesInvoiceRequest $request) { $input = Request::all(); $salesInvoice = SalesInvoice::find($input['invoice_no']); $items = InvoiceItem::where('sales_invoice_id', $salesInvoice->id)->get(); $output = $salesInvoice->Client->currentCredit(); $creditOutput = $output[0]->credit; if ($creditOutput == null) { $creditOutput = 0; } $remaining = $salesInvoice->Client->credit_limit - $creditOutput; foreach ($items as $item) { $invoiceItem = InvoiceItem::find($item->id); $creditOutput += $input['quantity' . $item->id] * $input['unit_price' . $item->id]; } if ($creditOutput > $salesInvoice->Client->credit_limit) { Flash::error('Cannot add the invoice, client would exceed the credit limit. The remaining allowable credit is only Php ' . $remaining . '.'); return redirect()->back()->withInput(); //return redirect()->back()->withInput()->with('message','Cannot add the invoice, client would exceed the credit limit. The remaining allowable credit is only Php ' . $remaining . '.'); } $salesInvoice->update(['si_no' => $input['si_no'], 'po_number' => $input['po_number'], 'dr_number' => $input['dr_number'], 'date' => Carbon::now()]); $total_amount = 0; $items = InvoiceItem::where('sales_invoice_id', $salesInvoice->id)->get(); //$items = $input(['items']); foreach ($items as $item) { $invoiceItem = InvoiceItem::find($item->id); $invoiceItem->update(['quantity' => $input['quantity' . $item->id], 'unit_price' => $input['unit_price' . $item->id], 'total_price' => $input['quantity' . $item->id] * $input['unit_price' . $item->id]]); $total_amount += $invoiceItem->total_price; } $salesInvoice->update(['total_amount' => $total_amount, 'status' => "Pending"]); if ($salesInvoice->Client->vat_exempt == 'VAT Exclusive') { $salesInvoice->update(['total_amount' => $salesInvoice->total_amount + $salesInvoice->total_amount * 0.12]); } Activity::log('Sales Invoice ' . $salesInvoice['si_no'] . ' was completed'); return redirect()->action('SalesInvoicesController@show', [$salesInvoice->id]); }
/** * Ajax delete * @param $id */ public function delete_item($id) { $objInvoiceItem = \App\InvoiceItem::find($id); if (!$this->objLoggedInUser->HasPermission("Edit/{$objInvoiceItem->Invoice->type}")) { abort('404'); } $objInvoiceItem->status = \App\InvoiceItem::STATUS_DELETED; if ($objInvoiceItem->save()) { exit('success'); } exit('error'); }