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'));
 }
 /**
  * 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 = FeesMasterTransaction::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));
     }
 }