/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $acc = Account::find($id); $ledgers = Ledger::where('account_id', $acc->id)->get(); //dd($ledgers); return view('regular.show', compact('ledgers'), compact('acc')); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(LoanApprovalRequest $request) { $appli = LoanApplication::findOrFail($request->id); //$appli->accepted = $request::get('accept'); //$appli->save(); //if($appli->accepted=='true'){ if ($request->accept == 'true') { $acc = new Account(); $acc->loan_id = $appli->loan_id; $acc->member_id = $appli->member_id; $acc->terms = $appli->terms; $acc->amountGranted = $appli->amountGranted; $acc->comaker = $appli->comaker; $acc->dateGranted = $request->date; $acc->dueDate = $acc->dateGranted; $acc->dueDate->addDays($acc->terms); $acc->balance = $acc->amountGranted; $acc->save(); $ledger = new Ledger(); $ledger->account_id = $acc->id; $ledger->curDate = $acc->dateGranted; $ledger->particulars = $request->particular; $ledger->reference = $request->reference; $ledger->avaiment = $acc->amountGranted; $ledger->amountPayed = 0; $ledger->interestDue = 0.0; $ledger->penaltyDue = 0.0; $ledger->principal = 0.0; $ledger->interestPayed = 0.0; $ledger->penaltyPayed = 0.0; $ledger->balance = $acc->amountGranted; $acc->balance = $acc->amountGranted; //toodo $ledger->save(); } $appli->delete(); flash()->success("Success!"); return redirect('/admin'); }
/** * Display ledger of individual client * Created by smartrahat Date: 08.12.2015 Time: 09:36PM * @param Request $request * @return \Illuminate\View\View */ public function ledger(Request $request) { $title = 'Ledger'; $ledgers = Ledger::all()->where('client', $request['client']); return view('cashIn.ledger', compact('title', 'ledgers')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function destroy($id) { $invoice = Invoice::query()->findOrFail($id); $countInvoice = $invoice->where('invoiceNumber', $invoice['invoiceNumber'])->count(); $ledger = Ledger::query()->where('reference', $invoice['invoiceNumber'])->first(); //dd($invoice['invoiceNumber']); //dd($ledger); if ($countInvoice <= 1) { $ledger->delete(); } else { $data = ['debit' => $ledger->debit - ($invoice->bill + $invoice->ot_bill)]; $ledger->update($data); } $invoice->delete(); Session::flash('success_message', 'Entry has been deleted successfully'); return redirect('invoice'); }
public function printLedger(Request $request) { $acc = Account::find($request->id); $ledgers = Ledger::where('account_id', $acc->id)->get(); return \PDF::loadHTML(view('reports.ledger', compact('acc', 'ledgers')))->stream('ledger.pdf'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(LedgerRequest $request) { $acc = Account::find($request->id); $ledger = new Ledger(); //set default values.. $ledger->account_id = $request->id; $ledger->curDate = date('Y-m-d'); $ledger->particulars = $request->particulars; $ledger->reference = $request->reference; $ledger->penaltyDue = 0.0; $ledger->interestPayed = 0.0; $ledger->penaltyPayed = 0.0; /* removed this part for accepting just payment in updating the ledger. can be restored back to accepting loaning by uncommenting this code and the corresponting code on it's view. */ // if($request->actn=='true'){ // $ledger->avaiment = $request->cash; // $ledger->principal = 0; // $acc->balance += $request->cash; // $ledger->balance = $acc->balance; // } // else{ $interest = 0; //check if due if due give penalty $diff = \Carbon\Carbon::now()->diffInDays($acc->dueDate->copy(), false); if ($diff < 0) { $ledger->penaltyDue = $acc->amountGranted * $acc->loan->penalty * abs($diff) / 360; $ledger->penaltyPayed = $ledger->penaltyDue; } //compute normal interest if (count($acc->ledgers) == 1) { // $interest = ($acc->amountGranted * $acc->loan->intRate * $acc->terms)/360; // $interestDue = $interest*($acc->dateGranted->diffInDays(\Carbon\Carbon::now())); //dd($acc->dateGranted->diffInDays(\Carbon\Carbon::now())); //ditoo $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->dateGranted->diffInDays(\Carbon\Carbon::now()) / 360; //dd($ledger->interestDue); //dd($interestDue); } //interest if past due and with partial.. if ($diff < 0 && count($acc->ledgers) > 1) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->dateGranted->diffInDays(\Carbon\Carbon::now()) / 360; // $interest = ($acc->amountGranted * $acc->loan->intRate * $acc->terms)/360; // $interestDue = $interest*($acc->dueDate->diffInDays(\Carbon\Carbon::now())); } //loan specific actions.. switch ($acc->loan_id - 1) { case 0: if (count($acc->ledgers) == 1) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->terms / 360; $ledger->interestPayed = $ledger->interestDue; } break; case 1: //by default is already working how it should break; case 2: case 3: case 4: case 5: $half = \Carbon\Carbon::now()->diffInDays($acc->dateGranted->copy()->addDays($acc->terms / 2), false); $ledger->interestDue = 0; if ($half == 0 || $half < 0) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * abs($half) / 360; } break; case 6: $penaltyDue = 0; $penaltyPayed = 0; if ($diff < 0) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * abs($diff) / 360; $ledger->interestPayed = $ledger->interestDue; } break; } $ledger->principal = $request->cash - ($ledger->penaltyDue + $ledger->interestDue); $ledger->avaiment = 0; $acc->balance -= $ledger->principal; $ledger->balance = $acc->balance; $ledger->amountPayed = $request->cash; //} $ledger->save(); $acc->save(); flash()->success('Updated Ledger'); return redirect('admin/accounts/' . $request->id); }