public function student_details_fees($id)
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     $criteria = new CDbCriteria();
     /************************************Ravi B************************************************/
     $student_trans = StudentTransaction::model()->findByPk($id);
     $fees_master = FeesMaster::model()->findByAttributes(array('fees_academic_term_name_id' => $student_trans->student_academic_term_name_id, 'fees_quota_id' => $student_trans->student_transaction_quota_id, 'fees_branch_id' => $student_trans->student_transaction_branch_id));
     $criteria->condition = 'student_fees_master_student_transaction_id = :student_id AND fees_master_table_id=:fees_master';
     $criteria->params = array(':student_id' => $id, ':fees_master' => $fees_master->fees_master_id);
     /******************************************************************************************/
     $dp = new CActiveDataProvider($this, array('criteria' => $criteria));
     $dp->setTotalItemCount(count($this->findAll($criteria)));
     return $dp;
 }
 public function actionAddotherfees($id)
 {
     $student_trans = StudentTransaction::model()->findByPk($id);
     $fees_master = FeesMaster::model()->findByAttributes(array('fees_academic_term_name_id' => $student_trans->student_academic_term_name_id, 'fees_quota_id' => $student_trans->student_transaction_quota_id, 'fees_branch_id' => $student_trans->student_transaction_branch_id));
     $model = new StudentFeesMaster();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['amounts'])) {
         foreach ($_POST['amounts'] as $index => $value) {
             if ($value != null) {
                 $model->student_fees_master_student_transaction_id = $id;
                 $model->fees_master_table_id = $fees_master['fees_master_id'];
                 $model->student_fees_master_details_id = $index;
                 $model->fees_details_amount = $value;
                 $model->student_fees_master_org_id = Yii::app()->user->getState('org_id');
                 $model->student_fees_master_created_by = Yii::app()->user->id;
                 $model->student_fees_master_creation_date = new CDbExpression('NOW()');
                 $model->setIsNewRecord(true);
                 $model->student_fees_master_id = null;
                 $model->save();
             }
         }
         $this->redirect(array('view', 'student_id' => $id));
     } else {
         if ($fees_master) {
             $student_fees = StudentFeesMaster::model()->findAll(array('condition' => 'fees_master_table_id=' . $fees_master->fees_master_id . ' and student_fees_master_student_transaction_id=' . $id));
             if (!empty($student_fees)) {
                 $details_array = array();
                 foreach ($student_fees as $fees_data) {
                     $details_array[] = $fees_data['student_fees_master_details_id'];
                 }
                 $details = implode(',', $details_array);
                 $remaining = Yii::app()->db->createCommand()->select('fees_details_master,fees_details_master_name')->from('fees_details_master')->where('fees_details_master not in(' . $details . ')')->queryAll();
                 $this->render('add_other_fees', array('model' => $model, 'fees_head_array' => $remaining));
             } else {
                 $this->redirect(array('/studentFeesMaster/feesassign/' . $id));
             }
         }
     }
 }
 private static function loadItems()
 {
     self::$_items = array();
     $models = self::model()->findAll();
     foreach ($models as $model) {
         self::$_items[$model->fees_master_id] = $model->fees_master_name;
     }
 }
<?php

$this->menu = array(array('label' => '', 'url' => array('paid', 'paidExport' => 'paidpdf', 'branch_id' => $_REQUEST['branch_id'], 'acm_id' => $_REQUEST['acm_id'], 'quota' => $_REQUEST['quota'], 'acm_name_id' => $_REQUEST['acm_name_id']), 'linkOptions' => array('class' => 'export-pdf', 'title' => 'Export to PDF', 'target' => '_blank')), array('label' => '', 'url' => array('paid', 'paidexportexcel' => 'paidexcel', 'branch_id' => $_REQUEST['branch_id'], 'acm_id' => $_REQUEST['acm_id'], 'quota' => $_REQUEST['quota'], 'acm_name_id' => $_REQUEST['acm_name_id']), 'linkOptions' => array('class' => 'export-excel', 'title' => 'Export to Excel', 'target' => '_blank')));
$org_id = Yii::app()->user->getState('org_id');
$data = 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_id AND stud.student_academic_term_period_tran_id = :acm_id AND fees.fees_academic_term_id = :acm_name_id AND stud.student_transaction_organization_id = :org_id', array(':branch_id' => $_REQUEST['branch_id'], ':acm_id' => $_REQUEST['acm_id'], ':acm_name_id' => $_REQUEST['acm_name_id'], ':org_id' => $org_id, ':quota_id' => $_REQUEST['quota']))->queryAll();
$fees_master = FeesMaster::model()->findByAttributes(array('fees_quota_id' => $_REQUEST['quota'], 'fees_branch_id' => $_REQUEST['branch_id'], 'fees_academic_term_name_id' => $_REQUEST['acm_name_id']));
$fees_masterid = $fees_master->fees_master_id;
echo CHtml::link('GO BACK', Yii::app()->createUrl('feesPaymentTransaction/mis_report')) . "</br></br>";
?>

<?php 
/*$_SESSION['branch_id']=$_REQUEST['branch_id'];
$_SESSION['acm_id']=$_REQUEST['acm_id'];
$_SESSION['acm_name_id']=$_REQUEST['acm_name_id'];*/
//echo CHtml::link('Export to pdf',array('paid','paidExport'=>'paidpdf','branch_id'=>$_REQUEST['branch_id'],'acm_id'=>$_REQUEST['acm_id'],'acm_name_id'=>$_REQUEST['acm_name_id']));
if ($data) {
    ?>

<table class="table_data">
<th colspan="11"  style="font-size: 18px; color: rgb(255, 255, 255);">
		Paid/Partialy Paid Student<br/>
<?php 
    echo "Branch : " . Branch::model()->findByPk($_REQUEST['branch_id'])->branch_name . "(" . Quota::model()->findByPk($_REQUEST['quota'])->quota_name . ")<br/>";
    echo "Semester: " . AcademicTerm::model()->findByPk($_REQUEST['acm_name_id'])->academic_term_name . "(" . AcademicTermPeriod::model()->findByPk($_REQUEST['acm_id'])->academic_term_period . ")";
    ?>
        </th>
<tr class="table_header">
	<th>SI.No.</th>
	<th>Enroll No.</th>
	<th>Roll No.</th>
	<th>Name</th>
    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>";
        }
    }
 /**
  * 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 = FeesMaster::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * 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));
     }
 }
$form = $this->beginWidget('CActiveForm', array('id' => 'fees-master-transaction-form', 'enableAjaxValidation' => true, 'clientOptions' => array('validateOnSubmit' => true)));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
//echo $form->errorSummary(array($model,$fees_details));
?>

<!--
	<div class="row">
		<?php 
echo $form->labelEx($model, 'fees_master_id');
?>
	        <?php 
echo $form->dropDownList($model, 'fees_master_id', FeesMaster::items(), array('empty' => 'Select one of the following...'));
?>
		<?php 
echo $form->error($model, 'fees_master_id');
?>
	</div>
-->

	<div class="row">
		<?php 
echo $form->labelEx($fees_details, 'fees_details_name');
?>
		<?php 
echo FeesDetailsMaster::model()->findByPk($fees_details->fees_details_name)->fees_details_master_name;
//echo $form->textField($fees_details,'fees_details_name',array('size'=>40,'maxlength'=>40));
?>