MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/paytm.php
 <?php
 if(!empty($order_id) && $msg!='Session Expired Failure'){

                    $_order_id=explode('_', $order_id);

                    //print_obj($this->data);

                    //print_obj($_order_id);

                    $_fisrt_sec_order_id=$_order_id[0];

                    $order_prefix = preg_replace("/[^A-Z]+/", "", $_fisrt_sec_order_id);
                    $balance='0';

                    //echo $order_prefix;die;

                    if($order_prefix=='SB'){
                        $order__id=$_order_id[0];
                        $utype=$_order_id[1];
                        //echo 'hi';die;
                        $booking_data=$this->adm->get_seat_bookings_data(array('booking_code'=>$order__id));

                        //print_obj($booking_data);die;
                        $booking_type='seat_booking';
                        if($utype=='stu'){
                            //$student_data=$this->um->get_user(array('user_id'=>$booking_data->booking_stu_id),'student');
                            //print_obj($student_data);die;
                            $user_id=$booking_data->stu_user_id;
                            $stu_id=$booking_data->stu_user_id;
                        }else if($utype=='stuinst'){
                           $user_id=$booking_data->booking_inst_id; 
                        }
                        
                        
                        $booking_id=$booking_data->booking_id;
                        $booking_inst_id=$booking_data->booking_inst_id;
                        $booking_inst_parent_id=$booking_data->booking_inst_parent_id;
                        $session_id=$booking_data->booking_sess_id;
                        $course_id=$booking_data->booking_course_id;
                        $redirect_url=($utype=='stu')?$this->data['base_url'].'/account':$this->data['base_url'].'/admission/bookings?p='.$order__id;
                    }else if($order_prefix=='ADM'){
                        //echo 'hi2';die;
                        $_order_id=explode('_', $order_id);

                        //print_obj($_order_id);die;

                        $order__id=$_order_id[0];
                        $installemnt_unique_code=$_order_id[4];
                        $utype=(isset($_order_id[5]))?$_order_id[5]:'';

                        $booking_data=$this->adm->get_admission_data(array('admission_code'=>$order__id));

                        //print_obj($booking_data);die;
                        $booking_type='new_admission';
                        if($utype=='stu'){
                            $user_id=$booking_data->admission_stu_id;
                        }else if($utype=='stuinst'){
                          $user_id=$booking_data->admission_inst_id;  
                        }
                        
                        $stu_id=$booking_data->admission_stu_id;
                        $admission_id=$booking_data->admission_id;
                        $session_id=$booking_data->admission_sess_id;
                        $course_id=$booking_data->admission_course_id;
                        $session_year=$_order_id[1];
                        $booking_id=$booking_data->admission_id;
                        $booking_inst_id=$booking_data->admission_inst_id;
                        $booking_inst_parent_id=$booking_data->admission_inst_parent_id;
                        if($utype=='stu'){
                            $redirect_url=$this->data['base_url'].'/account/installments';
                        }else if($utype=='stuinst'){
                          $redirect_url=$this->data['base_url'].'/admission/payments/'.encode_data($booking_id).'#'.$txn_id; 
                        }
                        
                    }else if($order_prefix=='ORDHT'){
                        //echo 'hi3';die;

                        //print_obj($_order_id);die;

                        $order__id=$_order_id[4];
                        $utype=(isset($_order_id[5]))?$_order_id[5]:'';

                        //echo $order__id;die;

                        //echo $utype;die;

                        if($utype=='admfee'){
                            $hostel_admission_fees=$this->hm->__get_hostel_admission_fees_assign_data(array('assign_unique_payid'=>$order__id));

                            //print_obj($hostel_admission_fees);die;

                            $hostel_id=$hostel_admission_fees->assign_hostel_id;
                            $booking_type='hostel_fees_payment';
                            $user_id=$hostel_admission_fees->assign_stu_id;
                            $stu_id=$hostel_admission_fees->assign_stu_id;
                            $session_id=$hostel_admission_fees->assign_sess_id;
                            $course_id=$hostel_admission_fees->assign_course_id;
                            $booking_id=$hostel_admission_fees->assigned_id;
                            $booking_inst_id=$hostel_admission_fees->assign_hostel_inst_id;
                            $booking_inst_parent_id='';
                            $redirect_url=$this->data['base_url'].'/account/hostels';
                        }else if($utype=='stu'){
                            $hostel_fees_data=$this->fm->get_hostel_fees_payment(array('payment_unique_code'=>$order__id));
                            $hostel_id=$hostel_fees_data->payment_hostel_id;
                            $booking_type='hostel_fees_payment';
                            $user_id=$hostel_fees_data->payment_hostel_stu_id;
                            $stu_id=$hostel_fees_data->payment_hostel_stu_id;
                            $booking_due_date=$hostel_fees_data->due_at;
                            $session_id=$hostel_fees_data->payment_hostel_sess_id;
                            $course_id=$hostel_fees_data->payment_hostel_course_id;
                            $session_year=$_order_id[1];
                            $booking_id=$hostel_fees_data->payment_id;
                            $booking_inst_id=$hostel_fees_data->payment_hostel_inst_id;
                            $booking_inst_parent_id='';
                            $redirect_url=$this->data['base_url'].'/account/hostels';
                        }else{
                            $hostel_fees_data=$this->fm->get_hostel_fees_payment(array('payment_id'=>$order__id));
                            $hostel_id=$hostel_fees_data->payment_hostel_id;
                            $booking_type='hostel_fees_payment';
                            $user_id=$hostel_fees_data->payment_hostel_inst_id;
                            $stu_id=$hostel_fees_data->payment_hostel_stu_id;
                            $booking_due_date=$hostel_fees_data->due_at;
                            $session_id=$hostel_fees_data->payment_hostel_sess_id;
                            $course_id=$hostel_fees_data->payment_hostel_course_id;
                            $session_year=$_order_id[1];
                            $booking_id=$hostel_fees_data->payment_id;
                            $booking_inst_id=$hostel_fees_data->payment_hostel_inst_id;
                            $booking_inst_parent_id='';
                            $redirect_url=$this->data['base_url'].'/payments/hostels';
                        }


                        

                        //print_obj($hostel_fees_data);die;

                        

                        
                        // $user_id=($utype=='stu')?$hostel_fees_data->payment_hostel_stu_id:$hostel_fees_data->payment_hostel_inst_id;
                        // $stu_id=$hostel_fees_data->payment_hostel_stu_id;

                        // $booking_due_date=$hostel_fees_data->due_at;

                        // $session_id=$hostel_fees_data->payment_hostel_sess_id;
                        // $course_id=$hostel_fees_data->payment_hostel_course_id;
                        // $session_year=$_order_id[1];
                        // $booking_id=$hostel_fees_data->payment_id;
                        // $booking_inst_id=$hostel_fees_data->payment_hostel_inst_id;
                        // $booking_inst_parent_id='';
                        // $redirect_url=($utype=='stu')?$this->data['base_url'].'/account/hostels':$this->data['base_url'].'/payments/hostels';
                    }

                    //echo $stu_id;die;


                    $course_data=$this->cm->get_course(array('course_id'=>$course_id));
                    $session_data=$this->sessm->get_session(array('session_id'=>$session_id));

                    //print_obj($course_data);die;

                    //die;

                    //echo $redirect_url;

                    //echo $status;die;

                    $redirect_error_url=$this->data['base_url'];

                    //echo $order_id;

                    //echo $msg;

                    //echo $status;die;

                    if($status=='TXN_SUCCESS'){
                        $userdata = $this->um->_get_user(array('user_id'=>$user_id));
                        //echo $redirect_url;
                        //print_obj($userdata);die;

                        //print_obj($userdata);die;

                        if($userdata->user_type=='institute'){
                            $inst_id=$userdata->user_id;
                            $student_data=$this->um->get_user(array('user_id'=>$stu_id),'student');
                            $institute_data=$this->um->get_user(array('user_id'=>$inst_id),'institute');
                            $institute_profile_name=$institute_data->user_profile_name;
                            $institute_email=$institute_data->user_email;
                            $institute_phone_no=$institute_data->user_contact_no;
                        }else if($userdata->user_type=='institute_branch'){
                            $inst_id=$userdata->user_id;
                        }else if($userdata->user_type=='agent'){
                            $inst_id=$userdata->user_id;
                        }else if($userdata->user_type=='student'){
                            $student_data=$this->um->get_user(array('user_id'=>$userdata->user_id),'student');
                            $inst_id=$student_data->stu_inst_id;
                            $institute_data=$this->um->get_user(array('user_id'=>$inst_id),'institute');
                            $institute_profile_name=$institute_data->user_profile_name;
                            $institute_email=$institute_data->user_email;
                            $institute_phone_no=$institute_data->user_contact_no;
                        }else{
                            $inst_id='';
                        }

                        $_payment_settings=$this->sm->get_system_settings(array('settings_inst_id'=>$inst_id));

                        //print_obj($_payment_settings);die;

                        if(!empty($_payment_settings)){
                            $payment_settings=unserialize($_payment_settings->settings_value);

                            if($payment_settings['PAYMENT_MODE']=='TEST'){
                                $mkey=$payment_settings['PAYMENT_TEST_MERCHANT_KEY'];
                                $mid=$payment_settings['PAYMENT_TEST_MERCHANT_MID'];
                                //$PAYTM_STATUS_QUERY_URL=$payment_settings['PAYTM_TEST_STATUS_QUERY_URL'];
                                $PAYTM_STATUS_QUERY_NEW_URL=PAYTM_TEST_STATUS_QUERY_NEW_URL;
                            }else if($payment_settings['PAYMENT_MODE']=='PROD'){
                                $mkey=$payment_settings['PAYMENT_PROD_MERCHANT_KEY'];
                                $mid=$payment_settings['PAYMENT_PROD_MERCHANT_MID'];
                                //$PAYTM_STATUS_QUERY_URL=$payment_settings['PAYTM_PROD_STATUS_QUERY_URL'];
                                $PAYTM_STATUS_QUERY_NEW_URL=PAYTM_PROD_STATUS_QUERY_NEW_URL;
                            }

                            $param['mkey']=$mkey;
                            $param['mid']=$mid;
                            //$param['paytm_status_query_url']=$PAYTM_STATUS_QUERY_URL;
                            $param['paytm_status_query_new_url']=$PAYTM_STATUS_QUERY_NEW_URL;

                            $payment_response=pgResponse($param);

                           // print_obj($payment_response);die;

                            if(!empty($payment_response)){

                                $order_id=$payment_response['ORDERID'];
                                $txn_amount=$payment_response['TXNAMOUNT'];
                                $txn_id=$payment_response['TXNID'];

                                //echo $order_prefix;die;

                                if($order_prefix=='SB'){
                                    $this->adm->update_seat_booking_payment_data(array('booking_payment_paid'=>'yes'),array('booking_pk_id'=>$booking_id));

                                    //$this->adm->update_seat_booking_data(array('booking_converted'=>'yes','updated_at'=>date('Y-m-d'),'updated_by'=>$user_id),array('booking_code'=>$order__id));

                                    $payment_details=array(
                                        'details_type'=>$booking_type,
                                        'details_payment_type'=>'seatbooking_fees',
                                        'details_payment_id'=>$booking_data->booking_payment_id,
                                        'details_stu_id'=>$user_id,
                                        'details_type_id'=>$booking_id,
                                        'details_sess_id'=>$session_id,
                                        'details_course_id'=>$course_id,
                                        'details_payment_platform'=>'paytm',
                                        'details_inst_id'=>$booking_inst_id,                                
                                        'details_parent_inst_id'=>$booking_inst_parent_id,
                                        'details_txn_id'=>$txn_id,
                                        'details_order_id'=>$order_id,
                                        'details_amount'=>$txn_amount,
                                        'details_discount_amount'=>'0',
                                        'details_order_code'=>$order__id,
                                        'details_created_by_type'=>($utype=='stu')?'student':'institute',
                                        'details_accounting_type'=>'income',
                                        'details_created_by'=>$user_id,
                                        'details_msg'=>$msg,
                                        'details_status'=>'success',
                                        'details_created_at'=>date('Y-m-d')
                                    );

                                   $this->fm->store_payment_details($payment_details);

                                   $session_course_data=$this->sessm->get_session_courses(array('session_id'=>$session_id,'session_course_id'=>$course_id,'session_inst_id'=>$booking_inst_id));


                                            $mail_subject='Seat Booking Payment for booking no :'.$booking_data->booking_code;

                                            $mail_data['inst_id']=$booking_inst_id;
                                            $mail_data['mail_from']='webmaster';

                                            if(isset($student_data) && !empty($student_data)){

                                                if(!empty($booking_data->stu_mid_name)){
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_mid_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }else{
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }


                                                $mail_data['to_email']=$booking_data->stu_email;
                                            }

                                            if($userdata->user_type=='student'){
                                                $mail_data['mail_from_name']=$institute_profile_name;

                                                $mail_data['mail_subject']=$mail_subject;
                                                
                                                $profile_name=$institute_profile_name;
                                                $college_email=$institute_email;
                                                $college_phone=$institute_phone_no;
                                                $link_logo=$this->data['link_logo'];
                                            }else{

                                                //print_obj($institute_data);die;

                                                $mail_data['mail_from_name']=$institute_data->user_profile_name;
                                                $mail_data['mail_subject']=$mail_subject;
                                                $profile_name=$institute_data->user_profile_name;
                                                $college_email=$institute_data->user_email;
                                                $college_phone=$institute_data->user_contact_no;
                                                $link_logo=$this->data['link_logo'];

                                                //print_obj($mail_data);die;
                                            }
                                            
                                            
                                            $mail_data['mail_type']='html';
                                            $mail_data['mail_custom_type']='html';
                                            $mail_data['mail_data']=array(
                                                'stu_name'=>ucwords($student_name),
                                                'stu_email'=>$student_data->stu_email,
                                                'stu_ph'=>$student_data->stu_ph_no,
                                                'booking_code'=>$booking_data->booking_code,
                                                'course_fees'=>(!empty($session_course_data))?number_format($session_course_data->session_course_fees,2):'',
                                                'booking_data'=>$booking_data,
                                                'payment_details'=>$payment_details,
                                                'session_data'=>$session_data->session_start_year.'-'.$session_data->session_end_year,
                                                'portal_url'=>$this->data['base_url'],
                                                'portal_logo'=>$link_logo,
                                                'portal_inst_name'=>$profile_name,
                                                'college_email'=>$college_email,
                                                'college_phone'=>$college_phone,
                                                'default_logo_small'=>$this->data['default_logo_small'],
                                                'created_at'=>date('d-m-Y')
                                            );


                                            //print_obj($mail_data);die;

                                            
                                            $mail_data['mail_view']='_pages/mails/vw_seatbook_payment_mail';

                                            $this->onSendMail($mail_data);

                                            $mail_data_2=$mail_data;

                                            $mail_data_2['to_email']=$institute_email;
                                            $mail_data_2['mail_subject']=$mail_subject.' [Copy mail]';
                                            
                                            $this->onSendMail($mail_data_2);




                                }else if($order_prefix=='ADM'){

                                    $order_id_exp=explode('_', $order_id);

                                    //print_obj($order_id_exp);

                                    $temp_payment_data=$this->fm->get_temp_payment(array('temp_checksum'=>$order_id));

                                    //print_obj($temp_payment_data);die;

                                    $this->adm->update_admission_data(array('updated_at'=>date('Y-m-d'),'updated_by'=>$user_id),array('admission_id'=>$booking_id));

                                    $total_fees_value=0;

                                    if(isset($order_id_exp[4])){
                                        $installment_data=$this->fm->get_installment(array('installment_unique_code'=>$order_id_exp[4]));
                                        $installment_id=$installment_data->installment_id;
                                        $installment_no=$order_id_exp[2];
                                        //echo $installment_id;die;
                                    }else{
                                        $installment_no=$order_id_exp[2];
                                        $year_data=$this->sessm->get_session_year(array('year_value'=>$session_year,'year_session_id'=>$session_id,'year_session_inst_id'=>$booking_inst_id));

                                        $fees_types=$this->fm->__get_fees_type(array('fees_inst_id'=>$booking_inst_id,'fees_session_id'=>$session_id,'fees_course_id'=>$course_id,'fees_year_id'=>$year_data->year_id));

                                        // print_obj($fees_types);die;

                                        if(!empty($fees_types)){


                                            foreach ($fees_types as $k => $v) {

                                                $_get_fees_details=$this->fm->_get_fees_details(array('payment_stu_id'=>$stu_id,
                                                    'payment_inst_id'=>$booking_inst_id,
                                                    'payment_admission_id'=>$admission_id,
                                                    'payment_sess_id'=>$session_id,
                                                    'payment_course_id'=>$course_id,
                                                    'payment_fees_type_id'=>$v->fees_type_id,
                                                    'payment_fees_value'=>$v->fees_value,
                                                    'payment_sess_year'=>$session_year));

                                                if(empty($_get_fees_details)){
                                                    $total_fees_value+=$v->fees_value;
                                                    $fees_type_data=array(
                                                        'payment_stu_id'=>$stu_id,
                                                        'payment_inst_id'=>$booking_inst_id,
                                                        'payment_admission_id'=>$admission_id,
                                                        'payment_sess_id'=>$session_id,
                                                        'payment_course_id'=>$course_id,
                                                        'payment_fees_type_id'=>$v->fees_type_id,
                                                        'payment_fees_value'=>$v->fees_value,
                                                        'payment_sess_year'=>$session_year,
                                                        'created_by'=>$user_id,
                                                        'created_at'=>date('Y-m-d')
                                                    );

                                                    $this->fm->_store_fees_details($fees_type_data,TRUE);
                                                }

                                                    
                                            }

                                            //print_obj($fees_type_data);die;

                                            
                                        }

                                        $get_installments=$this->fm->get_installments(array('installment_stu_id'=>$stu_id,
                                            'installment_inst_id'=>$booking_inst_id,
                                            'installment_no'=>$installment_no,
                                            'installment_admission_id'=>$admission_id,
                                            'installment_sess_id'=>$session_id,
                                            'installment_sess_year'=>$session_year,
                                            'installment_course_id'=>$course_id));

                                        //print_obj($get_installments);die;

                                        if(!empty($get_installments)){
                                            $installment_id=$get_installments->installment_id;
                                        }else{
                                            $installment_data_to_add=array(
                                                'installment_stu_id'=>$stu_id,
                                                'installment_inst_id'=>$booking_inst_id,
                                                'installment_admission_id'=>$admission_id,
                                                'installment_sess_id'=>$session_id,
                                                'installment_sess_year'=>$session_year,
                                                'installment_course_id'=>$course_id,
                                                'installment_value'=>$txn_amount,
                                                'installment_date'=>date('Y-m-d'),
                                                'created_by'=>$user_id,
                                                'created_at'=>date('Y-m-d')
                                            );

                                            $installment_id=$this->fm->store_installments($installment_data_to_add);
                                        }
                                        
                                    }

                                    //echo $installment_id;  

                                    if($installment_id){

                                        $installment_data=$this->fm->get_installments(array('installment_id'=>$installment_id),TRUE);

                                        //print_obj($installment_data);die;

                                        $_get_fees_details_last=$this->fm->_get_fees_details_last(array('payment_stu_id'=>$installment_data->installment_stu_id,'payment_inst_id'=>$installment_data->installment_inst_id,'payment_installment_id'=>$installment_data->installment_id));

                                        //$balance=$this->fm->get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id));

                                        if(!empty($_get_fees_details_last)){
                                             // $balance_last_data=$this->fm->get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id,'inst_payment_id'=>$_get_fees_details_last->payment_fees_details_id));

                                            $balance_last_data=$this->fm->_get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id,'inst_payment_id'=>$_get_fees_details_last->payment_fees_details_id));
                                        }else{
                                             // $balance_last_data=$this->fm->get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id));

                                            $balance_last_data=$this->fm->_get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id));
                                        }

                                        //print_obj($balance_last_data);die;



                                        //$balance_last_data=$this->fm->_get_installments_balance_last(array('inst_installment_id'=>$installment_data->installment_id,'inst_stu_id'=>$installment_data->installment_stu_id,'inst_session_id'=>$installment_data->installment_sess_id),TRUE);

                                        print_obj($balance_last_data);die;

                                        $date_now = date('Y-m-d');// new DateTime();
                                        $installment_date    = date('Y-m-d',strtotime($installment_data->installment_date));//new DateTime($installment_data->installment_date);

                                        // print_obj($date_now);
                                        // echo '<br>';
                                        // print_obj($installment_date);

                                        // if($date_now>$installment_date){
                                        //     echo 'Date now is greater';
                                        // }else if($date_now==$installment_date){
                                        //     echo 'date now is equal';
                                        // }else{
                                        //     echo 'Date now is smaller';
                                        // }

                                        // die;

                                        if(!empty($balance_last_data) && $balance_last_data->inst_payment_balance>0){
                                            if($date_now>$installment_date){
                                                $penalty_applied=TRUE;  
                                            }else if($date_now==$installment_date){
                                                $penalty_applied=FALSE;
                                            }else{
                                                $penalty_applied=FALSE;
                                            } 
                                            //echo '1';
                                            $balance=$balance_last_data->inst_payment_balance-$txn_amount;
                                        }else{
                                            if($date_now>$installment_date){
                                                $penalty_applied=TRUE;
                                                $total_due=$installment_data->installment_value+$installment_data->installment_value_penalty;  
                                            }else if($date_now==$installment_date){
                                                $penalty_applied=FALSE;
                                                $total_due=$installment_data->installment_value;
                                            }else{
                                                $penalty_applied=FALSE;
                                                $total_due=$installment_data->installment_value;
                                            }                                    

                                            if(!empty($_get_fees_details_last)){
                                                if(isset($_get_fees_details_last->inst_payment_balance) && $_get_fees_details_last->inst_payment_balance>0){
                                                    //echo '2';
                                                    $balance=$_get_fees_details_last->inst_payment_balance-$txn_amount;
                                                }else{
                                                    //echo '3';
                                                    $balance=$total_due-$txn_amount;
                                                }                                        
                                            }else{
                                                //echo '4';
                                                $balance=$total_due-$txn_amount;
                                            }                                    
                                        }

                                        echo $balance;die;
                                        

                                        $pay_data_to_add=array(
                                            'payment_stu_id'=>$stu_id,
                                            'payment_inst_id'=>$booking_inst_id,
                                            'payment_session_id'=>$session_id,
                                            'payment_session_year'=>$session_year,
                                            'payment_admission_id'=>$admission_id,
                                            'payment_course_id'=>$course_id,
                                            'payment_installment_id'=>$installment_id,
                                            'payment_fees_total'=>$total_fees_value,
                                            'payment_fees_scholarship_discount'=>(!empty($temp_payment_data))?$temp_payment_data->temp_scholarship_discount:'0',
                                            'payment_fees_scholarship_discount_reason'=>(!empty($temp_payment_data))?$temp_payment_data->temp_scholarship_discount_reason:null,
                                            'payment_fees_special_discount'=>(!empty($temp_payment_data))?$temp_payment_data->temp_special_discount:'0',
                                            'payment_fees_special_discount_reason'=>(!empty($temp_payment_data))?$temp_payment_data->temp_special_discount_reason:null,
                                            'payment_fees_total_discount'=>(!empty($temp_payment_data))?$temp_payment_data->temp_payment_total_discount:'0',
                                            'payment_fees_grand_total'=>$total_fees_value,
                                            'payment_fees_admission_amount'=>$txn_amount,
                                            'payment_fees_balance_amount'=>$balance,
                                            'payment_late_fee_applied'=>($penalty_applied==TRUE)?'yes':'no',
                                            'payment_late_fee'=>$installment_data->installment_value_penalty,
                                            'pay_mode'=>'online',
                                            'pay_bank_cheque_no'=>null,
                                            'pay_bank_name'=>null,
                                            'pay_deposit_bank'=>null,
                                            'created_by'=>$user_id,
                                            'created_at'=>date('Y-m-d')
                                        );

                                        $payment_id=$this->fm->store_fees_details($pay_data_to_add);

                                        if($payment_id){

                                            if($balance>0){

                                                $balance_data=array(
                                                    'inst_id'=>$booking_inst_id,
                                                    'inst_parent_id'=>$booking_inst_parent_id,
                                                    'inst_stu_id'=>$stu_id,
                                                    'inst_session_id'=>$session_id,
                                                    'inst_course_id'=>$course_id,
                                                    'inst_subject_id'=>$installment_data->installment_subject_id,
                                                    'inst_year'=>$session_year,
                                                    'inst_installment_id'=>$installment_id,
                                                    'inst_payment_id'=>$payment_id,
                                                    'inst_payment_total'=>$txn_amount,
                                                    'inst_payment_balance'=>$balance,
                                                    'created_at'=>date('Y-m-d'),
                                                    'created_by'=>$user_id
                                                );

                                                $this->fm->store_installments_balance($balance_data);
                                            }else if($balance==0){

                                                //print_obj($balance_last_data);die;

                                                if(!empty($balance_last_data)){
                                                    $this->fm->update_installments_balance(array('inst_balance_paid'=>'yes'),array('balance_id'=>$balance_last_data->balance_id));
                                                        $balance_data=array(
                                                            'inst_id'=>$booking_inst_id,
                                                            'inst_parent_id'=>$booking_inst_parent_id,
                                                            'inst_stu_id'=>$stu_id,
                                                            'inst_session_id'=>$session_id,
                                                            'inst_course_id'=>$course_id,
                                                            'inst_subject_id'=>$installment_data->installment_subject_id,
                                                            'inst_year'=>$session_year,
                                                            'inst_installment_id'=>$installment_id,
                                                            'inst_payment_id'=>$payment_id,
                                                            'inst_payment_total'=>$txn_amount,
                                                            'inst_payment_balance'=>$balance,
                                                            'inst_balance_paid'=>'yes',
                                                            'created_at'=>date('Y-m-d'),
                                                            'created_by'=>$user_id
                                                        );

                                                        $this->fm->store_installments_balance($balance_data);

                                                        $this->fm->update_installments_balance(array('inst_balance_paid'=>'yes'),array('inst_id'=>$booking_inst_id,
                                                            'inst_parent_id'=>$booking_inst_parent_id,
                                                            'inst_stu_id'=>$stu_id,
                                                            'inst_session_id'=>$session_id,
                                                            'inst_course_id'=>$course_id,
                                                            'inst_subject_id'=>$installment_data->installment_subject_id,
                                                            'inst_year'=>$session_year,
                                                            'inst_installment_id'=>$installment_id));
                                                }


                                                $this->fm->update_installments(array('installment_paid_full'=>'yes'),array('installment_id'=>$installment_id));
                                            }


                                            if(isset($order_id_exp[6]) && $order_id_exp[6]=='bal'){
                                                $details_payment_type='installment_balance_fees';
                                            }else{
                                                $details_payment_type='installment_fees';
                                            }
                                                                                

                                            $payment_details=array(
                                                'details_order_code'=>$_fisrt_sec_order_id,
                                                'details_payment_platform'=>'paytm',
                                                'details_type'=>$booking_type,
                                                'details_payment_type'=>$details_payment_type,
                                                'details_type_id'=>$booking_id,
                                                'details_payment_id'=>$payment_id,
                                                'details_inst_id'=>$booking_inst_id,
                                                'details_parent_inst_id'=>$booking_inst_parent_id,
                                                'details_stu_id'=>$student_data->stu_user_id,
                                                'details_sess_id'=>$session_id,
                                                'details_course_id'=>$course_id,
                                                'details_sess_year'=>$session_year,
                                                'details_installment_id'=>$installment_id,
                                                'details_txn_id'=>$txn_id,
                                                'details_order_id'=>$order_id,
                                                'details_amount'=>$txn_amount,
                                                'details_discount_amount'=>(!empty($temp_payment_data))?$temp_payment_data->temp_payment_total_discount:'0',
                                                'details_prev_total_amount'=>0,
                                                'details_accounting_type'=>'income',
                                                'details_created_by_type'=>$userdata->user_type,
                                                'details_created_by'=>$user_id,
                                                'details_status'=>'success',
                                                'details_msg'=>$msg,
                                                'details_created_at'=>date('Y-m-d')
                                            );

                                            $payment_details_id=$this->fm->store_payment_details($payment_details);

                                            $prev_payment_data=$this->fm->get_payment_details(array('details_stu_id'=>$stu_id,'details_sess_id'=>$session_id,'details_course_id'=>$course_id,'details_sess_year'=>$session_year,'details_installment_id'=>$installment_id),FALSE);

                                            //print_obj($prev_payment_data);die;

                                            if(!empty($prev_payment_data) && count($prev_payment_data)>1){
                                                $prev_total=$this->fm->_get_payments_total(array('details_stu_id'=>$stu_id,'details_sess_id'=>$session_id,'details_course_id'=>$course_id,'details_sess_year'=>$session_year,'details_installment_id'=>$installment_id,'details_id!='=>$payment_details_id));
                                                $details_prev_total_amount=$prev_total;//+$txn_amount;
                                            }else{
                                                $details_prev_total_amount=0;
                                            }

                                            $this->fm->update_payment_details(array('details_prev_total_amount'=>$details_prev_total_amount),array('details_id'=>$payment_details_id));

                                            $this->fm->delete_temp_payment(array('temp_checksum'=>$order_id));


                                            $payment_details=$this->fm->get_payment_details(array('details_id'=>$payment_details_id));

                                            //print_obj($payment_details);die;

                                            if(!empty($payment_details)){
                                                $payment_data=$this->fm->get_fees_details(array('payment_fees_details_id'=>$payment_id));


                                                //print_obj($this->data);die;

                                                $mail_data['inst_id']=$booking_inst_id;
                                                $mail_data['mail_from']='webmaster';

                                                if(isset($student_data) && !empty($student_data)){

                                                    if(!empty($student_data->stu_mid_name)){
                                                        $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_mid_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                    }else{
                                                        $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                    }


                                                    $mail_data['to_email']=$student_data->stu_email;
                                                }

                                                if($userdata->user_type=='student'){
                                                    $mail_data['mail_from_name']=$institute_profile_name;

                                                    if($payment_details->details_payment_type=='installment_balance_fees'){
                                                        $mail_data['mail_subject']='Admission ['.$booking_data->admission_code.'] Balance Payment Details';
                                                    }else{
                                                        $mail_data['mail_subject']='Admission ['.$booking_data->admission_code.'] Payment Details';
                                                    }


                                                    
                                                    $profile_name=$institute_profile_name;
                                                    $college_email=$institute_email;
                                                    $college_phone=$institute_phone_no;
                                                    $link_logo=$this->data['link_logo'];
                                                }else{
                                                    $mail_data['mail_from_name']=$institute_profile_name;
                                                    $mail_data['mail_subject']=ucwords($institute_profile_name).' Admission ['.$booking_data->admission_code.'] Details';
                                                    $profile_name=$institute_profile_name;
                                                    $college_email=$institute_email;
                                                    $college_phone=$institute_phone_no;
                                                    $link_logo=$this->data['link_logo'];
                                                }
                                                
                                                
                                                $mail_data['mail_type']='html';
                                                $mail_data['mail_custom_type']='html';
                                                $mail_data['mail_data']=array(
                                                    'stu_name'=>ucwords($student_name),
                                                    'stu_email'=>$student_data->stu_email,
                                                    'stu_ph'=>$student_data->stu_ph_no,
                                                    'booking_code'=>$booking_data->admission_code,
                                                    'booking_session'=>$session_data->session_start_year.'-'.$session_data->session_end_year,
                                                    'booking_course'=>$course_data->course_name,
                                                    'booking_subject'=>(!empty($subject_data))?$subject_data->subject_name:'N/A',
                                                    'booking_amount'=>'0',
                                                    'installment_data'=>$installment_data,
                                                    'payment_data'=>$payment_data,
                                                    'payment_details'=>$payment_details,
                                                    'portal_url'=>$this->data['base_url'],
                                                    'portal_logo'=>$link_logo,
                                                    'portal_inst_name'=>$profile_name,
                                                    'college_email'=>$college_email,
                                                    'college_phone'=>$college_phone,
                                                    'default_logo_small'=>$this->data['default_logo_small'],
                                                    'created_at'=>date('d-m-Y')
                                                );

                                                
                                                $mail_data['mail_view']='_pages/mails/vw_admission_installments_payment_mail';

                                                $this->onSendMail($mail_data);

                                                $mail_data_2=$mail_data;

                                                $mail_data_2['to_email']=$institute_email;
                                                if($payment_details->details_payment_type=='installment_balance_fees'){
                                                    $mail_data_2['mail_subject']='Admission ['.$booking_data->admission_code.'] Balance Payment Details [Copy mail]';
                                                }else{
                                                    $mail_data_2['mail_subject']='Admission ['.$booking_data->admission_code.'] Payment Details [Copy mail]';
                                                }
                                                
                                                $this->onSendMail($mail_data_2); 
                                            }
                                        }
                                    }
                                }else if($order_prefix=='ORDHT'){

                                    if($utype=='stu'){
                                        $order_code=$_fisrt_sec_order_id.$order__id;
                                        $date_now = date('Y-m-d');// new DateTime();
                                        $due_date = date('Y-m-d',strtotime($booking_due_date));//new DateTime($booking_due_date);

                                        if($date_now>$due_date){
                                            $penalty_applied='applied';  
                                        }else if($date_now==$due_date){
                                            $penalty_applied='not applied';
                                        }else{
                                            $penalty_applied='not applied';
                                        }

                                        //echo $order_code;die;
                                    

                                        $updated=$this->fm->update_hostel_fees_payment(array('recieved_at'=>date('Y-m-d'),'payment_status'=>'paid','payment_penalty'=>$penalty_applied),array('payment_id'=>$booking_id));

                                        $payment_details=array(
                                            'details_payment_platform'=>'paytm',
                                            'details_type'=>$booking_type,
                                            'details_payment_type'=>'hostel_fees',
                                            'details_type_id'=>$hostel_id,
                                            'details_inst_id'=>$booking_inst_id,
                                            'details_parent_inst_id'=>$booking_inst_parent_id,
                                            'details_stu_id'=>$student_data->stu_user_id,
                                            'details_sess_id'=>$session_id,
                                            'details_course_id'=>$course_id,
                                            'details_sess_year'=>$session_year,
                                            'details_installment_id'=>$booking_id,
                                            'details_txn_id'=>$txn_id,
                                            'details_order_id'=>$order_id,
                                            'details_order_code'=>$order_code,                                 
                                            'details_amount'=>$txn_amount,
                                            'details_discount_amount'=>'0',
                                            'details_accounting_type'=>'income',
                                            'details_created_by_type'=>$userdata->user_type,
                                            'details_created_by'=>$user_id,
                                            'details_created_at'=>date('Y-m-d')
                                        );

                                        //print_obj($payment_details);die;

                                        $payment_id=$this->fm->store_payment_details($payment_details);

                                        if($payment_id){
                                            $hostel_data=$this->hm->get_hostel(array('hostel_inst_id'=>$booking_inst_id,'hostel_id'=>$hostel_id));

                                            //print_obj($hostel_data);die;

                                            $hostel_payment_details=$this->fm->get_payment_details(array('details_type'=>'hostel_fees_payment','details_txn_id'=>$txn_id));

                                            //print_obj($hostel_payment_details);die;

                                            if($utype=='stu'){
                                                $get_hostel_fees_payment=$this->fm->get_hostel_fees_payment(array('payment_hostel_id'=>$hostel_id,'payment_hostel_inst_id'=>$booking_inst_id,'payment_hostel_sess_id'=>$session_id,'payment_hostel_stu_id'=>$user_id,'payment_year'=>$session_year,'payment_id'=>$booking_id));
                                            }else if($utype=='stuinst'){
                                                $get_hostel_fees_payment=$this->fm->get_hostel_fees_payment(array('payment_hostel_id'=>$hostel_id,'payment_hostel_inst_id'=>$booking_inst_id,'payment_hostel_sess_id'=>$session_id,'payment_hostel_stu_id'=>$hostel_fees_data->payment_hostel_stu_id,'payment_year'=>$session_year,'payment_id'=>$booking_id));
                                            }

                                            $session_data=$this->sessm->get_session(array('session_id'=>$session_id));

                                            $mail_subject='Hostel Rent Payment Details for '.ucwords($get_hostel_fees_payment->payment_month).'-'.$get_hostel_fees_payment->payment_year;

                                            $mail_data['inst_id']=$booking_inst_id;
                                            $mail_data['mail_from']='webmaster';

                                            if(isset($student_data) && !empty($student_data)){

                                                if(!empty($student_data->stu_mid_name)){
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_mid_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }else{
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }


                                                $mail_data['to_email']=$student_data->stu_email;
                                            }

                                            if($userdata->user_type=='student'){
                                                $mail_data['mail_from_name']=$institute_profile_name;

                                                $mail_data['mail_subject']=$mail_subject;
                                                
                                                $profile_name=$institute_profile_name;
                                                $college_email=$institute_email;
                                                $college_phone=$institute_phone_no;
                                                $link_logo=$this->data['link_logo'];
                                            }else{

                                                //print_obj($institute_data);die;

                                                $mail_data['mail_from_name']=$institute_data->user_profile_name;
                                                $mail_data['mail_subject']=$mail_subject;
                                                $profile_name=$institute_data->user_profile_name;
                                                $college_email=$institute_data->user_email;
                                                $college_phone=$institute_data->user_contact_no;
                                                $link_logo=$this->data['link_logo'];

                                                //print_obj($mail_data);die;
                                            }
                                            
                                            
                                            $mail_data['mail_type']='html';
                                            $mail_data['mail_custom_type']='html';
                                            $mail_data['mail_data']=array(
                                                'stu_name'=>ucwords($student_name),
                                                'stu_email'=>$student_data->stu_email,
                                                'stu_ph'=>$student_data->stu_ph_no,
                                                'payment_details'=>$get_hostel_fees_payment,
                                                'hostel_data'=>$hostel_data,
                                                'hostel_payment_details'=>$hostel_payment_details,
                                                'session_data'=>$session_data,
                                                'portal_url'=>$this->data['base_url'],
                                                'portal_logo'=>$link_logo,
                                                'portal_inst_name'=>$profile_name,
                                                'college_email'=>$college_email,
                                                'college_phone'=>$college_phone,
                                                'default_logo_small'=>$this->data['default_logo_small'],
                                                'created_at'=>date('d-m-Y')
                                            );

                                            
                                            $mail_data['mail_view']='_pages/mails/vw_hostel_fees_payment_mail';

                                            $this->onSendMail($mail_data);

                                            $mail_data_2=$mail_data;

                                            $mail_data_2['to_email']=$institute_email;
                                            $mail_data_2['mail_subject']=$mail_subject.' [Copy mail]';
                                            
                                            $this->onSendMail($mail_data_2);
                                        }
                                    }else if($utype=='admfee'){

                                        $order_code=$_fisrt_sec_order_id.$order__id;

                                       // echo $booking_type;
                                        $this->hm->update_hostel_admission_fees_assign_data(array('assign_fees_paid'=>'yes','assign_fees_paid_date'=>date('Y-m-d H:i:s')),array('assigned_id'=>$booking_id));

                                        $hpd=$this->hm->__get_hostel_admission_fees_assign_data(array('assigned_id'=>$booking_id));

                                        $session_years=$session_data->session_start_year.'-'.$session_data->session_end_year;                                

                                        //print_obj($hostel_payment_details);die;

                                        $payment_details=array(
                                            'details_payment_platform'=>'paytm',
                                            'details_type'=>$booking_type,
                                            'details_payment_type'=>'hostel_admission_fees_payment',
                                            'details_type_id'=>$hostel_id,
                                            'details_inst_id'=>$booking_inst_id,
                                            'details_parent_inst_id'=>$booking_inst_parent_id,
                                            'details_sess_id'=>$session_id,
                                            'details_course_id'=>$course_id,
                                            'details_stu_id'=>$student_data->stu_user_id,
                                            'details_sess_year'=>'0',
                                            'details_installment_id'=>$booking_id,
                                            'details_txn_id'=>$txn_id,
                                            'details_order_id'=>$order_id,
                                            'details_order_code'=>$order_code,
                                            'details_amount'=>$txn_amount,
                                            'details_discount_amount'=>'0',
                                            'details_accounting_type'=>'income',
                                            'details_msg'=>$msg,
                                            'details_status'=>'success',
                                            'details_created_by_type'=>$userdata->user_type,
                                            'details_created_by'=>$user_id,
                                            'details_created_at'=>date('Y-m-d H:i:s')
                                        );

                                       //print_obj($payment_details);die;

                                        $payment_id=$this->fm->store_payment_details($payment_details);

                                        if($payment_id){
                                            $session_data=$this->sessm->get_session(array('session_id'=>$session_id));

                                            $_hpd=$this->fm->get_payment_details(array('details_type'=>'hostel_fees_payment','details_payment_type'=>'hostel_admission_fees_payment','details_txn_id'=>$txn_id));

                                            $hostel_payment_details=array(
                                                'hostel_name'=>$hpd->hostel_name,
                                                'session_years'=>$session_years,
                                                'admission_fee'=>number_format($hpd->admission_fees_value,2),
                                                'caution_fee'=>number_format($hpd->admission_caution_fees_value,2),
                                                'total_fee'=>number_format(($hpd->admission_fees_value+$hpd->admission_caution_fees_value),2),
                                                'payment_mode'=>ucwords($_hpd->details_payment_platform),
                                                'taxation_no'=>$_hpd->details_txn_id,
                                                'payment_date'=>date('d-m-Y')
                                            );

                                            $session_years=$session_data->session_start_year.'-'.$session_data->session_end_year;

                                            $mail_subject='Hostel Admission Payment Details [Session : '.$session_years.']';

                                            $mail_data['inst_id']=$booking_inst_id;
                                            $mail_data['mail_from']='webmaster';

                                            if(isset($student_data) && !empty($student_data)){

                                                if(!empty($student_data->stu_mid_name)){
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_mid_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }else{
                                                    $student_name=ucwords(strtolower($student_data->stu_first_name)).' '.ucwords(strtolower($student_data->stu_last_name));
                                                }


                                                $mail_data['to_email']=$student_data->stu_email;
                                            }

                                            if($userdata->user_type=='student'){
                                                $mail_data['mail_from_name']=$institute_profile_name;

                                                $mail_data['mail_subject']=$mail_subject;
                                                
                                                $profile_name=$institute_profile_name;
                                                $college_email=$institute_email;
                                                $college_phone=$institute_phone_no;
                                                $link_logo=$this->data['link_logo'];
                                            }else{

                                                //print_obj($institute_data);die;

                                                $mail_data['mail_from_name']=$institute_data->user_profile_name;
                                                $mail_data['mail_subject']=$mail_subject;
                                                $profile_name=$institute_data->user_profile_name;
                                                $college_email=$institute_data->user_email;
                                                $college_phone=$institute_data->user_contact_no;
                                                $link_logo=$this->data['link_logo'];

                                                //print_obj($mail_data);die;
                                            }
                                            
                                            
                                            $mail_data['mail_type']='html';
                                            $mail_data['mail_custom_type']='html';
                                            $mail_data['mail_data']=array(
                                                'stu_name'=>ucwords($student_name),
                                                'stu_email'=>$student_data->stu_email,
                                                'stu_ph'=>$student_data->stu_ph_no,
                                                'hostel_payment_details'=>$hostel_payment_details,
                                                'session_data'=>$session_data,
                                                'portal_url'=>$this->data['base_url'],
                                                'portal_logo'=>$link_logo,
                                                'portal_inst_name'=>$profile_name,
                                                'college_email'=>$college_email,
                                                'college_phone'=>$college_phone,
                                                'default_logo_small'=>$this->data['default_logo_small'],
                                                'created_at'=>date('d-m-Y')
                                            );


                                            //print_obj($mail_data);die;

                                            
                                            $mail_data['mail_view']='_pages/mails/vw_hostel_admission_fees_payment_mail';

                                            $this->onSendMail($mail_data);

                                            $mail_data_2=$mail_data;

                                            $mail_data_2['to_email']=$institute_email;
                                            $mail_data_2['mail_subject']=$mail_subject.' [Copy mail]';
                                            
                                            $this->onSendMail($mail_data_2);
                                        }
                                    }      
                                }
                                    

                                $session_data=array(
                                    'isAdminLoggedin'=>true,
                                    'admin_id'=>encode_data($user_id),
                                    'admin_type'=>$userdata->user_type,
                                    'txn_id'=>$txn_id,
                                    'loggedin_time'=>time()
                                );

                                //print_obj($session_data);die;

                                session_set_userdata($session_data);

                                //echo $redirect_url;die;

                                redirect($redirect_url);

                            }else{
                                redirect($redirect_url);
                            }
                        }else{
                            redirect($redirect_error_url); 
                        }
                    }else if($status=='TXN_FAILURE'){
                        redirect($redirect_error_url);
                    }   

                }else{
                    redirect($this->data['base_url']);
                } 

MMCT - 2023