/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     //exit;
     $model = new MiscellaneousFeesPaymentCash();
     $receipt = new MiscellaneousFeesReceipt();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['MiscellaneousFeesPaymentCash'])) {
         $model->attributes = $_POST['MiscellaneousFeesPaymentCash'];
         $model->miscellaneous_fees_payment_organization_id = Yii::app()->user->getState('org_id');
         $last_receipt_id = Yii::app()->db->createCommand()->select('MAX(miscellaneous_fees_receipt_number) as lastid')->from('miscellaneous_fees_receipt')->where('miscellaneous_fees_receipt_org_id=:id', array(':id' => Yii::app()->user->getState('org_id')))->queryRow();
         $receipt->miscellaneous_fees_receipt_number = $last_receipt_id['lastid'] + 1;
         $receipt->miscellaneous_fees_receipt_org_id = Yii::app()->user->getState('org_id');
         $receipt->save();
         $model->miscellaneous_fees_payment_cash_student_id = $_REQUEST['id'];
         $model->miscellaneous_fees_payment_cash_receipt_id = $receipt->miscellaneous_fees_receipt_id;
         $model->miscellaneous_fees_payment_cash_created_by = Yii::app()->user->id;
         //$model->miscellaneous_fees_payment_cash_creation_date=new CDbExpression('NOW()');
         $date = $_POST['MiscellaneousFeesPaymentCash']['miscellaneous_fees_payment_cash_creation_date'];
         $new_date = date("Y-m-d", strtotime($date));
         $model->miscellaneous_fees_payment_cash_creation_date = $new_date;
         if ($model->save()) {
             $this->redirect(array('/miscellaneousFeesPaymentTransaction/create', 'id' => $model->miscellaneous_fees_payment_cash_student_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MiscellaneousFeesReceipt();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MiscellaneousFeesReceipt'])) {
         $model->attributes = $_POST['MiscellaneousFeesReceipt'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->miscellaneous_fees_receipt_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function beforesave()
 {
     //echo Yii::app()->user->getState('student_id');
     $my_date = date("Y-m-d");
     $receipt = new MiscellaneousFeesReceipt();
     if ($this->isNewRecord) {
         if ($this->miscellaneous_fees_payment_cheque_date > $my_date) {
             $last_receipt_id = Yii::app()->db->createCommand()->select('MAX(miscellaneous_fees_receipt_number) as lastid')->from('miscellaneous_fees_receipt')->where('miscellaneous_fees_receipt_org_id=:id', array(':id' => Yii::app()->user->getState('org_id')))->queryRow();
             $receipt->miscellaneous_fees_receipt_number = $last_receipt_id['lastid'] + 1;
             $receipt->miscellaneous_fees_receipt_org_id = Yii::app()->user->getState('org_id');
             $receipt->save();
             $this->miscellaneous_fees_payment_cheque_receipt_id = $receipt->miscellaneous_fees_receipt_id;
             return true;
         } else {
             $this->addError("miscellaneous_fees_payment_cheque_date", "Cheque Date Must Be After Current Date");
             return false;
         }
     } else {
         $result = MiscellaneousFeesPaymentCheque::model()->findByPk($this->miscellaneous_fees_payment_cheque_id);
         if ($this->miscellaneous_fees_payment_cheque_date == $result['miscellaneous_fees_payment_cheque_date']) {
             return true;
         } else {
             if ($this->miscellaneous_fees_payment_cheque_date > $my_date) {
                 return true;
             } else {
                 $this->addError("miscellaneous_fees_payment_cheque_date", "Cheque Date Must Be After Current Date");
                 return false;
             }
             return false;
         }
     }
 }