public function penalty($occurence, $penalty, $app_id, $payment_type_id) { $payment_type = PaymentType::model()->findByPk($payment_type_id); $due_date = DueDate::model()->find('applicant_id=:aid AND payment_type_id=:pid', array(':aid' => $app_id, ':pid' => $payment_type_id)); $date_now = DateTime::createFromFormat(Yii::app()->user->getDateFormat(false), date(Yii::app()->user->getDateFormat(false))); $due_date = DateTime::createFromFormat(Yii::app()->user->getDateFormat(false), $due_date->date); $date_diff = date_diff($date_now, $due_date); if ($occurence == 'permonth') { return $payment_type->amount * $penalty / 100 / 30 * $date_diff->d; } else { return $payment_type->amount * $penalty / 100 / 12 / 30 * $date_diff->d; } return false; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = DueDate::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }