public function beforesave()
    {
        $student_id = $_REQUEST['student_id'];
        $criteria = new CDbCriteria();
        $stud_trans = StudentTransaction::model()->findByPk($student_id);
        $criteria->condition = 'fees_student_id =' . $student_id . ' AND fees_academic_period_id=' . $stud_trans['student_academic_term_period_tran_id'] . ' AND fees_academic_term_id=' . $stud_trans['student_academic_term_name_id'];
        $listofid = FeesPaymentTransaction::model()->findAll($criteria);
        $total_fees_amount = 0;
        $fees_stru = Yii::app()->db->createCommand()->select('fees.fees_master_id , fees.fees_master_name , fees.fees_branch_id , stud.student_transaction_branch_id , stud.student_transaction_organization_id , fees.fees_organization_id , stud.student_transaction_quota_id , fees.fees_quota_id ,stud.student_academic_term_period_tran_id , fees.fees_academic_term_id, fees.fees_academic_term_name_id, fees.fees_master_total')->from('student_transaction stud')->join('fees_master fees', 'stud.student_transaction_branch_id = fees.fees_branch_id
		AND stud.student_academic_term_period_tran_id = fees.fees_academic_term_id
		AND stud.student_academic_term_name_id = fees.fees_academic_term_name_id 	
		AND stud.student_transaction_organization_id = fees.fees_organization_id
		AND stud.student_transaction_quota_id = fees.fees_quota_id')->where('stud.student_transaction_id=:id', array(':id' => $student_id))->queryRow();
        $student_fees = StudentFeesMaster::model()->findAll('fees_master_table_id = :fees_master_id AND student_fees_master_student_transaction_id = :student_id', array(':fees_master_id' => $fees_stru['fees_master_id'], ':student_id' => $student_id));
        foreach ($student_fees as $fees_data) {
            $total_fees_amount += $fees_data->fees_details_amount;
        }
        $cash_total = 0;
        $cheque_total = 0;
        $total = 0;
        if ($listofid != null) {
            foreach ($listofid as $list) {
                if ($list->fees_payment_method_id == 1) {
                    $cash_total = $cash_total + FeesPaymentCash::model()->findByPk($list->fees_payment_cash_cheque_id)->fees_payment_cash_amount;
                } else {
                    $amount = FeesPaymentCheque::model()->findByAttributes(array('fees_payment_cheque_status' => 0, 'fees_payment_cheque_id' => $list->fees_payment_cash_cheque_id));
                    $cheque_total = $cheque_total + $amount['fees_payment_cheque_amount'];
                }
            }
            echo "<div class='total-amount'><h4>Total Paid Fees : <b>" . ($total = $cash_total + $cheque_total . '</b></h4></div>');
            //$total_fees_amount = FeesMaster::model()->findByPk($list->fees_payment_master_id)->fees_master_total;
            if ($this->isNewRecord) {
                $grand_total = $total + $this->fees_payment_cash_amount;
            } else {
                $update_total = FeesPaymentCash::model()->findByPk($_REQUEST['id'])->fees_payment_cash_amount;
                $grand_total = $total - $update_total + $this->fees_payment_cash_amount;
            }
            if ($total_fees_amount < $grand_total) {
                $this->addError('fees_payment_cash_amount', 'You can not take an advance fees for student.');
                return false;
            } else {
                return true;
            }
        } else {
            if ($this->fees_payment_cash_amount > $total_fees_amount) {
                $this->addError('fees_payment_cash_amount', 'You can not take an advance fees for student.');
                return false;
            } else {
                return true;
            }
        }
    }
			<span class="output"><?php 
        echo $acd_term->academic_term_period;
        ?>
</span></div>
		</div>

      <div class="tablepart1">

      <table>
          <tr>
             <th width="5%">Sr No.</th>
             <th>Particulars</th>
             <th>Amount(Rs.)</th>
	  	</tr>
<?php 
        $student_fees = StudentFeesMaster::model()->findAll('fees_master_table_id = :fees_master_id AND student_fees_master_student_transaction_id = :student_id', array(':fees_master_id' => $data['fees_payment_master_id'], ':student_id' => $data['fees_student_id']));
        $i = 1;
        $total_fees_amount = 0;
        foreach ($student_fees as $list) {
            ?>
		<tr id="purticular">
		<td class="sr-number"><?php 
            echo $i;
            ?>
            	<td id="purticular">
			<?php 
            if (!empty($list)) {
                echo FeesDetailsMaster::model()->findByPk($list->student_fees_master_details_id)->fees_details_master_name;
                ?>
				</td>
          			<td><?php 
 /**
  * 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 = StudentFeesMaster::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
    public function actionMis_report()
    {
        $model = new FeesPaymentTransaction();
        $current_aca_term = AcademicTerm::model()->findAll(array('condition' => 'current_sem=1'));
        if ($current_aca_term) {
            $aca_data = array();
            foreach ($current_aca_term as $aca) {
                $aca_data[] = $aca['academic_term_id'];
                $current_aca_term = $aca->academic_term_period_id;
            }
            $acam_data = implode(",", $aca_data);
            //$current_aca_term = $current_aca_term->academic_term_period_id;
            $fees_data = Yii::app()->db->createCommand()->selectDistinct('fees_master_id, fees_branch_id, fees_academic_term_id,fees_quota_id, fees_academic_term_name_id')->from('fees_master')->where('fees_academic_term_name_id in(' . $acam_data . ') order by fees_branch_id,fees_academic_term_name_id')->queryAll();
            //print count($fees_data); exit;
            if (!empty($fees_data)) {
                foreach ($fees_data as $list) {
                    $ravi_paid = 0;
                    $ravi_total = 0;
                    $my_total = 0;
                    $receive_amount = 0;
                    if (!empty($list)) {
                        $sql = "SELECT COUNT(*) FROM student_transaction where student_transaction_quota_id=" . $list['fees_quota_id'] . " and student_transaction_branch_id = " . $list['fees_branch_id'] . " AND student_academic_term_period_tran_id = " . $list['fees_academic_term_id'] . " AND student_academic_term_name_id = " . $list['fees_academic_term_name_id'];
                        $numStud[] = Yii::app()->db->createCommand($sql)->queryScalar();
                        $ravi_total = Yii::app()->db->createCommand($sql)->queryScalar();
                        $paid_stud = Yii::app()->db->createCommand()->selectDistinct('fees.fees_student_id, stud.student_transaction_id,stud.student_transaction_student_id,stud.student_transaction_quota_id')->from('fees_payment_transaction fees')->join('student_transaction stud', 'fees.fees_student_id = stud.student_transaction_id')->where('stud.student_transaction_branch_id = :branch_id AND stud.student_transaction_quota_id=:quota AND stud.student_academic_term_period_tran_id = :acm_id AND fees.fees_academic_term_id = :acm_name_id', array(':branch_id' => $list['fees_branch_id'], ':acm_id' => $list['fees_academic_term_id'], ':acm_name_id' => $list['fees_academic_term_name_id'], ':quota' => $list['fees_quota_id']))->queryAll();
                        $paid_stud_count[] = count($paid_stud);
                        $ravi_paid = count($paid_stud);
                        $cash_amount = 0;
                        $cheque_amount = 0;
                        foreach ($paid_stud as $stud_id) {
                            $amount_data = FeesPaymentTransaction::model()->findAll('fees_student_id=' . $stud_id['student_transaction_id'] . ' and fees_academic_term_id=' . $list['fees_academic_term_name_id']);
                            foreach ($amount_data as $cash_cheque_list) {
                                if ($cash_cheque_list['fees_payment_method_id'] == 1) {
                                    $cash_amount += FeesPaymentCash::model()->findByPk($cash_cheque_list['fees_payment_cash_cheque_id'])->fees_payment_cash_amount;
                                } else {
                                    $amount = FeesPaymentCheque::model()->findByAttributes(array('fees_payment_cheque_status' => 0, 'fees_payment_cheque_id' => $cash_cheque_list->fees_payment_cash_cheque_id));
                                    $cheque_amount = $cheque_amount + $amount['fees_payment_cheque_amount'];
                                }
                            }
                        }
                        $total_receive_amount[] = $cash_amount + $cheque_amount;
                        $unpaid_stud = Yii::app()->db->createCommand()->selectDistinct('stud.student_transaction_id,stud.student_transaction_student_id,stud.student_transaction_quota_id')->from('student_transaction stud')->where('stud.student_transaction_id NOT IN (SELECT fees_student_id FROM fees_payment_transaction)
				AND stud.student_transaction_branch_id = :branch_id AND stud.student_academic_term_period_tran_id = :acm_id AND stud.student_academic_term_name_id = :acm_name_id', array(':branch_id' => $list['fees_branch_id'], ':acm_id' => $list['fees_academic_term_id'], ':acm_name_id' => $list['fees_academic_term_name_id']))->queryAll();
                        $unpaid_stud_count[] = $ravi_total - $ravi_paid;
                        //$unpaid_stud_count[] = count($unpaid_stud);
                        $total_amount_data = FeesMaster::model()->findAll('fees_branch_id =' . $list['fees_branch_id'] . ' AND
					  fees_academic_term_id =' . $list['fees_academic_term_id'] . ' AND
					  fees_academic_term_name_id =' . $list['fees_academic_term_name_id']);
                        $fees_stru = Yii::app()->db->createCommand()->select('fees.fees_master_id ,  stud.student_transaction_student_id, stud.student_academic_term_period_tran_id, stud.student_academic_term_name_id')->from('student_transaction stud')->join('fees_master fees', 'stud.student_transaction_branch_id = fees.fees_branch_id
		AND stud.student_academic_term_period_tran_id = fees.fees_academic_term_id
		AND stud.student_academic_term_name_id = fees.fees_academic_term_name_id 	

		AND stud.student_transaction_quota_id = fees.fees_quota_id')->where('stud.student_academic_term_period_tran_id = :term_p_id AND stud.student_academic_term_name_id = :term_name_id AND fees.fees_master_id = :fees_id', array(':fees_id' => $list['fees_master_id'], ':term_p_id' => $list['fees_academic_term_id'], ':term_name_id' => $list['fees_academic_term_name_id']))->queryAll();
                        //print_r($fees_stru); exit;
                        $total = 0;
                        foreach ($fees_stru as $fees_data1) {
                            $student_fees = StudentFeesMaster::model()->findAll('fees_master_table_id = :fees_master_id AND student_fees_master_student_transaction_id = :student_id', array(':fees_master_id' => $fees_data1['fees_master_id'], ':student_id' => $fees_data1['student_transaction_student_id']));
                            foreach ($student_fees as $fees_data1) {
                                $total += $fees_data1->fees_details_amount;
                            }
                        }
                        //print $total; exit;
                        $total_amount[] = $total;
                    }
                }
                if (isset($_REQUEST['MISexport'])) {
                    Yii::import('application.extensions.tcpdf.*');
                    require_once 'tcpdf/tcpdf.php';
                    require_once 'tcpdf/config/lang/eng.php';
                    $html = $this->renderPartial('report_view_pdf', array('numStud' => $numStud, 'fees_data' => $fees_data, 'paid_stud_count' => $paid_stud_count, 'unpaid_stud_count' => $unpaid_stud_count, 'total_amount' => $total_amount, 'total_receive_amount' => $total_receive_amount), true);
                    ob_clean();
                    $pdf = new TCPDF();
                    $pdf->SetCreator(PDF_CREATOR);
                    $pdf->SetAuthor(Yii::app()->name);
                    $pdf->SetTitle('MIS Report');
                    $pdf->SetSubject('MIS Report');
                    $pdf->SetKeywords('example, text, report');
                    $pdf->SetHeaderData('', 0, "Fees Summary", '');
                    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, "Example Report by ".Yii::app()->name, "");
                    $pdf->setHeaderFont(array('helvetica', '', 8));
                    $pdf->setFooterFont(array('helvetica', '', 6));
                    $pdf->SetMargins(15, 18, 15);
                    $pdf->SetHeaderMargin(5);
                    $pdf->SetFooterMargin(10);
                    $pdf->SetAutoPageBreak(TRUE, 15);
                    $pdf->SetFont('dejavusans', '', 7);
                    $resolution = array(150, 150);
                    $pdf->AddPage('P', $resolution);
                    $pdf->writeHTML($html, true, false, true, false, '');
                    $pdf->LastPage();
                    $pdf->Output("MIS.pdf", "I");
                }
                if (isset($_REQUEST['MISexportexcel'])) {
                    Yii::app()->request->sendFile(date('YmdHis') . '.xlsx', $this->renderPartial('report_view_pdf', array('numStud' => $numStud, 'fees_data' => $fees_data, 'paid_stud_count' => $paid_stud_count, 'unpaid_stud_count' => $unpaid_stud_count, 'total_amount' => $total_amount, 'total_receive_amount' => $total_receive_amount), true));
                }
                $this->render('create_report', array('numStud' => $numStud, 'fees_data' => $fees_data, 'paid_stud_count' => $paid_stud_count, 'unpaid_stud_count' => $unpaid_stud_count, 'total_amount' => $total_amount, 'total_receive_amount' => $total_receive_amount));
            } else {
                $this->render('error_msg', array());
            }
        } else {
            echo "<font color=\"red\"><center>Data Not Available</center></font>";
        }
    }
?>
</span></div>
		</div>
		


      <div class="tablepart1">

      <table>
          <tr>
             <th width="5%">Sr No.</th>
             <th>Particulars</th>
             <th>Amount(Rs.)</th>
	  	</tr>
<?php 
$student_fees = StudentFeesMaster::model()->findAll('fees_master_table_id = :fees_master_id AND student_fees_master_student_transaction_id = :student_id', array(':fees_master_id' => $fees_payment->fees_payment_master_id, ':student_id' => $model->student_transaction_id));
$i = 1;
$total_fees_amount = 0;
foreach ($student_fees as $list) {
    ?>
		<tr id="purticular">
		<td class="sr-number"><?php 
    echo $i;
    ?>
            	<td id="purticular">
			<?php 
    if (!empty($list)) {
        echo FeesDetailsMaster::model()->findByPk($list->student_fees_master_details_id)->fees_details_master_name;
        ?>
				</td>
          			<td><?php 
 public function actionAssignFeesStudent()
 {
     $student_fees_master = new StudentFeesMaster();
     $org_id = Yii::app()->user->getState('org_id');
     $acdm_terms = AcademicTerm::model()->findAll('current_sem=1 and academic_term_organization_id=' . Yii::app()->user->getState('org_id'));
     $data = array();
     foreach ($acdm_terms as $list) {
         $data[] = $list['academic_term_id'];
     }
     $result = implode(",", $data);
     $data = FeesMaster::model()->findAll('fees_academic_term_name_id in (' . $result . ')');
     foreach ($data as $list) {
         $student_data = StudentTransaction::model()->findAll('student_transaction_quota_id = :quota_id AND student_academic_term_period_tran_id = :acdm_term_p AND student_academic_term_name_id = :acmd_term AND student_transaction_branch_id = :branch_id', array(':quota_id' => $list->fees_quota_id, ':acdm_term_p' => $list->fees_academic_term_id, ':acmd_term' => $list->fees_academic_term_name_id, ':branch_id' => $list->fees_branch_id));
         $fees_data = FeesMasterTransaction::model()->findAll('fees_master_id = ' . $list->fees_master_id);
         foreach ($fees_data as $f) {
             foreach ($student_data as $st) {
                 $fees_details_data = FeesDetailsTable::model()->findByPk($f->fees_desc_id);
                 $stud_fees_data = StudentFeesMaster::model()->findByAttributes(array('student_fees_master_student_transaction_id' => $st->student_transaction_id, 'fees_master_table_id' => $list->fees_master_id, 'student_fees_master_details_id' => $fees_details_data->fees_details_name));
                 if ($stud_fees_data) {
                     StudentFeesMaster::model()->updateAll(array('fees_details_amount' => $fees_details_data->fees_details_amount), 'student_fees_master_id=' . $stud_fees_data['student_fees_master_id']);
                 } else {
                     $student_fees_master->setIsNewRecord(true);
                     $student_fees_master->student_fees_master_id = null;
                     $student_fees_master->student_fees_master_student_transaction_id = $st->student_transaction_id;
                     // $fees_details_data = FeesDetailsTable::model()->findByPk($f->fees_desc_id);
                     $student_fees_master->fees_master_table_id = $list->fees_master_id;
                     $student_fees_master->student_fees_master_details_id = $fees_details_data->fees_details_name;
                     $student_fees_master->fees_details_amount = $fees_details_data->fees_details_amount;
                     $student_fees_master->student_fees_master_org_id = $org_id;
                     $student_fees_master->student_fees_master_created_by = Yii::app()->user->id;
                     $student_fees_master->student_fees_master_creation_date = new CDbExpression('NOW()');
                     $student_fees_master->save();
                 }
             }
         }
     }
     $this->redirect(array('/studentFeesMaster/admin'));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new StudentTransaction();
     $info = new StudentInfo();
     $user = new User();
     $photo = new StudentPhotos();
     $address = new StudentAddress();
     $lang = new LanguagesKnown();
     $auth_assign = new AuthAssignment();
     $student_fees_master = new StudentFeesMaster();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation(array($info, $model, $user));
     if (!empty($_POST['StudentTransaction']) || !empty($_POST['StudentInfo'])) {
         //print_r($_POST['StudentTransaction']); exit;
         $model->attributes = $_POST['StudentTransaction'];
         $info->attributes = $_POST['StudentInfo'];
         $user->attributes = $_POST['User'];
         $info->student_created_by = Yii::app()->user->id;
         $info->student_creation_date = new CDbExpression('NOW()');
         $info->student_email_id_1 = strtolower($user->user_organization_email_id);
         $info->student_adm_date = date('Y-m-d', strtotime($_POST['StudentInfo']['student_adm_date']));
         $user->user_organization_email_id = strtolower($info->student_email_id_1);
         $user->user_password = md5($info->student_email_id_1 . $info->student_email_id_1);
         $user->user_created_by = Yii::app()->user->id;
         $user->user_creation_date = new CDbExpression('NOW()');
         $user->user_organization_id = Yii::app()->user->getState('org_id');
         $user->user_type = "student";
         if ($info->save(false)) {
             $user->save(false);
             $address->save(false);
             $lang->save(false);
             $photo->student_photos_path = "no-images";
             $photo->save();
         }
         if (empty($model->student_transaction_batch_id)) {
             $model->student_transaction_batch_id = 0;
         }
         $model->student_transaction_languages_known_id = $lang->languages_known_id;
         $model->student_transaction_student_id = $info->student_id;
         $model->student_transaction_user_id = $user->user_id;
         $model->student_transaction_student_address_id = $address->student_address_id;
         $model->student_transaction_student_photos_id = $photo->student_photos_id;
         $model->student_transaction_organization_id = Yii::app()->user->getState('org_id');
         $flag = Studentstatusmaster::model()->findByAttributes(array('status_name' => 'Regular'))->id;
         $model->student_transaction_detain_student_flag = $flag;
         $model->save();
         //Fees Assignment to a student=========== By Ravi Bhalodiya=========================================================
         $fees_data = FeesMaster::model()->findByAttributes(array('fees_branch_id' => $model->student_transaction_branch_id, 'fees_academic_term_id' => $model->student_academic_term_period_tran_id, 'fees_academic_term_name_id' => $model->student_academic_term_name_id, 'fees_quota_id' => $model->student_transaction_quota_id));
         if ($fees_data) {
             $fees_master = FeesMasterTransaction::model()->findAll(array('condition' => 'fees_master_id=' . $fees_data->fees_master_id));
             foreach ($fees_master as $list) {
                 $fees_detail = FeesDetailsTable::model()->findByPk($list['fees_desc_id']);
                 $student_fees_master->setIsNewRecord(true);
                 $student_fees_master->student_fees_master_id = null;
                 $student_fees_master->student_fees_master_student_transaction_id = $model->student_transaction_id;
                 $student_fees_master->fees_master_table_id = $fees_data->fees_master_id;
                 $student_fees_master->student_fees_master_details_id = $fees_detail->fees_details_name;
                 $student_fees_master->fees_details_amount = $fees_detail->fees_details_amount;
                 $student_fees_master->student_fees_master_org_id = Yii::app()->user->getState('org_id');
                 $student_fees_master->student_fees_master_created_by = Yii::app()->user->id;
                 $student_fees_master->student_fees_master_creation_date = new CDbExpression('NOW()');
                 $student_fees_master->save();
             }
         }
         //==================================================================================================================
         StudentInfo::model()->updateByPk($model->student_transaction_student_id, array('student_info_transaction_id' => $model->student_transaction_id));
         $auth_assign->itemname = 'Student';
         $auth_assign->userid = $user->user_id;
         $auth_assign->save();
         $this->redirect(array('update', 'id' => $model->student_transaction_id));
     } else {
         $this->render('create', array('model' => $model, 'info' => $info, 'user' => $user));
     }
 }