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;
         }
     }
 }
 public function actionmis_feesExportToExcel($id)
 {
     $cash_data = MiscellaneousFeesPaymentCash::model()->findAll('miscellaneous_fees_payment_cash_student_id=' . $id);
     $cheque_data = MiscellaneousFeesPaymentCheque::model()->findAll('miscellaneous_fees_payment_cheque_student_id=' . $id);
     Yii::app()->request->sendFile(date('YmdHis') . '.xlsx', $this->renderPartial('/miscellaneousFeesPaymentTransaction/mis_pdf', array('cash_data' => $cash_data, 'cheque_data' => $cheque_data, 'id' => $id), true));
 }
 /**
  * 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 = MiscellaneousFeesPaymentCheque::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }