Exemplo n.º 1
0
 /**
  * Show the form for creating a new loanrepayment
  *
  * @return Response
  */
 public function create($id)
 {
     $loanaccount = Loanaccount::findOrFail($id);
     $loanbalance = Loantransaction::getLoanBalance($loanaccount);
     $principal_due = Loantransaction::getPrincipalDue($loanaccount);
     $interest = Loanaccount::getInterestAmount($loanaccount);
     $interest_due = Loantransaction::getInterestDue($loanaccount);
     return View::make('loanrepayments.create', compact('loanaccount', 'principal_due', 'interest_due', 'loanbalance', 'interest'));
 }
Exemplo n.º 2
0
 public static function repayLoan($data)
 {
     $loanaccount_id = array_get($data, 'loanaccount_id');
     $loanaccount = Loanaccount::findorfail($loanaccount_id);
     $amount = array_get($data, 'amount');
     $date = array_get($data, 'date');
     $principal_due = Loantransaction::getPrincipalDue($loanaccount);
     $interest_due = Loantransaction::getInterestDue($loanaccount);
     $total_due = $principal_due + $interest_due;
     $payamount = $amount;
     if ($payamount < $total_due) {
         //pay interest first
         Loanrepayment::payInterest($loanaccount, $date, $interest_due);
         $payamount = $payamount - $interest_due;
         if ($payamount > 0) {
             Loanrepayment::payPrincipal($loanaccount, $date, $payamount);
         }
     }
     if ($payamount >= $total_due) {
         //pay interest first
         Loanrepayment::payInterest($loanaccount, $date, $interest_due);
         $payamount = $payamount - $interest_due;
         //pay principal with the remaining amount
         Loanrepayment::payPrincipal($loanaccount, $date, $payamount);
     }
     /*
     		do {
     		if($payamount >= $principal_due ){
     			Loanrepayment::payPrincipal($loanaccount, $date, $principal_due);
     				$payamount = $payamount - $principal_due;
     
     			if($payamount >= $interest_due ){
     			Loanrepayment::payInterest($loanaccount, $date, $interest_due);
     				$payamount = $payamount - $interest_due;
     			} 
     			elseif($payamount > 0 && $payamount < $interest_due) {
     				Loanrepayment::payInterest($loanaccount, $date, $payamount);
     					$payamount = $payamount - $payamount;
     				}
     		}
     		elseif(($payamount > 0) and ($payamount < $principal_due) ) {
     			Loanrepayment::payInterest($loanaccount, $date, $interest_due);
     				$payamount = $payamount - $interest_due;
     
     			if($payamount > 0) {
     				Loanrepayment::payPrincipal($loanaccount, $date, $payamount);
     					$payamount = $payamount - $payamount;
     			}
     			}
     		
     			
     
     	} while($payamount > 0);
     */
     Loantransaction::repayLoan($loanaccount, $amount, $date);
 }
Exemplo n.º 3
0
 public static function getTotalDue($loanaccount)
 {
     $balance = Loantransaction::getLoanBalance($loanaccount);
     if ($balance > 1) {
         $principal = Loantransaction::getPrincipalDue($loanaccount);
         $interest = Loantransaction::getInterestDue($loanaccount);
         $total = $principal + $interest;
         return $total;
     } else {
         return 0;
     }
 }