Ejemplo n.º 1
0
 public function actionEmi()
 {
     $emi = '';
     $loan = new Loan();
     $emiData = array('amount' => '', 'interest' => '', 'year' => '', 'month' => '', 'type' => '');
     if (isset($_POST['emi'])) {
         $year = '';
         $months = '';
         $amount = $_POST['amt'];
         $interest = $_POST['interest'];
         $year = $_POST['years'];
         $month = $year * 12;
         $interest_div = $interest / 1200;
         $top = $amount * $interest_div * pow(1 + $interest_div, $month);
         $bottom = pow(1 + $interest_div, $month) - 1;
         $emi = $top / $bottom;
         $emi = round($emi, 2);
         if ($_POST['type'] == 'years') {
             $emi = 12 * $emi;
         }
         $emiData = array('amount' => $amount, 'interest' => $interest, 'year' => $year, 'type' => $_POST['type']);
     }
     if (isset($_POST['loan'])) {
         $loan->attributes = $_POST['Loan'];
         if ($loan->validate()) {
             if ($loan->save()) {
                 Yii::app()->user->setFlash('success', 'Your Request For Loan has been submitted');
                 $this->redirect('/emi');
             } else {
                 Yii::app()->user->setFlash('error', 'Your Request For Loan not submitted.Please <a href="/emi">retry</a>');
             }
         }
     }
     $this->render('emi', array('emi' => $emi, 'loan' => $loan, 'emiData' => $emiData));
 }