/**
  * 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');
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateLoanRequest $request)
 {
     //dd($request->loan_id);
     $acc = new Account();
     $acc->loan_id = $request->loan_id;
     $acc->member_id = $request->member_id;
     $acc->terms = $request->terms;
     $acc->amountGranted = $request->amount;
     $acc->comaker = $request->comaker;
     $acc->dateGranted = $request->dateGranted;
     $acc->dueDate = $acc->dateGranted;
     $acc->dueDate->addDays($acc->terms + 1);
     $acc->balance = $acc->amountGranted;
     $acc->save();
     $insurance = 0.0;
     $cbu = 0.0;
     $sfee = 0.0;
     $advint = 0.0;
     switch ($acc->loan_id - 1) {
         case 0:
             $today = \Carbon\Carbon::now();
             $mm = $today->month;
             if ($mm == 12 || $mm == 1) {
                 $insurance = 0;
                 //todo
             } else {
                 if ($mm >= 6 && $mm <= 8) {
                     $insurance = $acc->amountGranted * 0.15;
                 }
             }
             $cbu = 500 * $acc->member->landArea;
             break;
         case 1:
             $cbu = 500;
             break;
         case 2:
         case 3:
         case 4:
         case 5:
             $advint = $acc->amountGranted * $acc->loan->intRate * $acc->terms / 360 / 2;
             break;
         case 6:
             //wala
             break;
     }
     $sfee = $acc->amountGranted * $acc->loan->sFee;
     //$total = $advint+$pcic+$insurance+$sfee+$sdeposit+$mortuary+$cbu+$balance+$penalty;
     $total = $advint + $insurance + $sfee + $cbu;
     $net = $acc->amountGranted - $total;
     $ledger = new Ledger();
     $ledger->account_id = $acc->id;
     $ledger->curDate = date('Y-m-d');
     $ledger->particulars = 'LOAN';
     $ledger->reference = $acc->id;
     $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();
     $inwords = $this->convert_number_to_words($net);
     return \PDF::loadHTML(view('reports.report1', compact('insurance', 'cbu', 'sfee', 'advint', 'total', 'net', 'acc', 'inwords')))->stream('test.pdf');
     //flash()->success("Success!");
     //return redirect('/admin');
 }