 
 <?php $security_id = get_security_id($user_id);//collect security id ?>
 <ul class="breadcrumb">
      <li><a href="gateway.php?act=view_students_payments_b">Students Confirmation Menu</a> <span class="divider"></span></li>
      <li><a href="gateway.php?act=view_search_students_b">Search Student Invoice ID </a>  <span class="divider"></span></li>
      <li class="active"> Confirmed Payments</li>
  </ul>
<div class="well">

      <ul class="tabs"> 
        <li><a href="#view1">Student Info</a></li> 
      </ul> 
      <div class="tabcontents"> 
        <div id="view1"  style="background-image:images/background.png;">
        
        	<!-- this is the search button -->
            
        	 <div class="row">
                    
              </div>
       
         <div class="row alert alert-success">
            	 
                <div style="float:left; width:90%">
                   
                        <img src="images/coe.png"   class="pull-left"/>
                   
                        <p class="text-center"> <span style="font-size:20px;font-weight:bold;"><br/>Students' Payment Confirmation Slip </span> </p> <br/>
                        <p class="text-center">
                        <span align="center" style="font-size:20px;font-weight:bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NIGER STATE COLLEGE OF EDUCATION MINNA  </span>  <br/>
                        <span align="center"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--(Office of the Vice Chancellor)  --></span>  <br/>
                        <span align="center" style="font-size:20px;font-weight:bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NCE, STUDENT PORTAL  </span> 
                        </p><br/> 
                       
                        <!--<p class="info text-center">Please visit the portal to continue application</p>-->
                    
            	</div>
            
            
            	<div style="float:left; width:10%">
                 <img src="images/payments.png" />
    				 
                
                </div>
                
                
            </div><!-- /alert info -->
        	                   
              <?php 
			  
			  //colllect the id to generate the password for candidate
			  
			  
			  //check the action passed
			  if(($_POST['act']== 'confirm_students_payments_b')) 
			  {
				  //************************ special case *********************/
				  
				  $id_array = $_POST['invoice']; // return array
				  $id_count = count($_POST['invoice']); // count array
				  
				  for($i=0; $i < $id_count; $i++) {
					  
					  //collect the id through aray
					  $id = $id_array[$i];
					  
					  
					  
					  
					  //get invoice to
					 $invoice_to  = get_invoice_invoice_to($id);
					 
					 //get invoice type 
					 $invoice_type = get_invoice_type($id);
					 
					 //get invoice title
					 $invoice_title = get_invoice_title($id);
					 
					 
					 //get invoice desc
					 $invoice_desc = get_invoice_desc($id);
					 
					 //get invoice amount
					 $invoice_amount = get_invoice_amount($id);
					 
					 
					  //get programme type
					 $programme_type = get_invoice_programme_type($id);
					 
					 
					  //get invoice instalment or fulpayment
					 $payment_mode = get_invoice_payment_mode($id);
					 
					 
					 //show payment mode
					 $show_payment_mode = show_payment_mode($payment_mode);
					 
					
					 
					 
					 //get current session 
					 $current_session = get_current_session(1);
					 
					 //get current semester 
					 $current_semester = get_current_semester(1);
					  
					  
					  if($programme_type == 1)
					  {
						  //if pre nce
						  ################################## pre nce
						  							  //check invoice type
									if($invoice_type == '1')//if invoice is fresh student
									{
										
										
										//aplicant programme type
										$applicant_programme_type = get_applicant_programme_type_admitted_to($invoice_to);//get applicant pt
										
									   
										//applicant school
									   $applicant_school = get_applicant_school_admitted_to($invoice_to); 
									   
									   
										//applicant department
									   $applicant_department = get_applicant_department_admitted_to($invoice_to); 
										
										
										
										//applicant department
										$applicant_programme = get_applicant_programme_admitted_to($invoice_to);
										
										
										$applicant_level = 'PRE'; //aplicant level 
										
										$application_number = get_applicant_application_number($invoice_to);
										
										
										//insert school id and show school id, 
										
										//payment method 3 manual microfinance bank
									
									
									
								   
											  $q = "SELECT  `type_id`, `school_id`, `department_id`, `programme_id`, `programme_type_applied_for`, `school_applied_for`,
												   `department_applied_for`, `programme_applied_for`, `application_number`, `country_id`, `state_id`,
												   `lga_id`, `first_name`, `other_names`, `phone_no`, `pdf_file`, `gender`, `religion`, `nationality`, `day`, `month`, `year`,
													`marital_status`, `email`, `place_of_birth`,  `address`, `permanent_address`, `image`, `H_status`, 
													`blood_type`, `disability`, `mode_of_entry`, `medi`,  `town`,  `guardian_name`, `guardian_tel`, `guardian_address`, 
													`guardian_relationship`, `sponsorship_type`, `sponsorship_name`, `sponsorship_address`, 
													`admission_status`, `admission_criteria`, `date_admitted`, `admission_serial_no`
													 
												   FROM `applicants_nce` 
													 
												   WHERE application_number = '$application_number'";
													 
											  $r = mysqli_query($dbc,$q);
							
											  if(mysqli_num_rows($r) > 0)
											  {//if succesfully fetch applicant recor
											  
											  
											  
												   
													//$initial = 0 ;
													
													 $total_in_programme = get_total_programme_students_prence($applicant_programme_type,$applicant_school,$applicant_programme,$applicant_level);
													 
													 $total_in_programme = $total_in_programme + 1; 
											  
													//generate matric number
													$applicant_matric_number = generate_matric_number_prence($applicant_programme_type, $applicant_school, $applicant_programme, $applicant_level, $total_in_programme);
													  
													  
													
											
												  while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))//fetch data to be migrated
												  {
													  
													  //chedk if student has been added already an collect info if added //review this dont depend on this function
													  if(!application_number_exist_prence($application_number, $applicant_level))
													  {
															 //collect the variables for inserting and check for special string using 
															 $fn = mysqli_real_escape_string($dbc,$row['first_name']); //first name
															 $on = mysqli_real_escape_string($dbc,$row['other_names']);
															 $pn = mysqli_real_escape_string($dbc,$row['phone_no']);
															  $e = mysqli_real_escape_string($dbc,$row['email']);
															  $add = mysqli_real_escape_string($dbc,$row['address']);
															  $padd = mysqli_real_escape_string($dbc,$row['permanent_address']);
															  $pob = mysqli_real_escape_string($dbc,$row['place_of_birth']);
															  $gn = mysqli_real_escape_string($dbc,$row['guardian_name']);
															  $gr = mysqli_real_escape_string($dbc,$row['guardian_relationship']);
															  $gt = mysqli_real_escape_string($dbc,$row['guardian_tel']);
															  $ga = mysqli_real_escape_string($dbc,$row['guardian_address']);
															  $sn = mysqli_real_escape_string($dbc,$row['sponsorship_name']);
															  $sa = mysqli_real_escape_string($dbc,$row['sponsorship_address']);
															  $ac = mysqli_real_escape_string($dbc,$row['admission_criteria']);
															  $med = mysqli_real_escape_string($dbc,$row['medi']);
															  $spt = mysqli_real_escape_string($dbc,$row['sponsorship_type']);

															  
															  
											
											
															  //get applicants info
															  $qq = "INSERT INTO `students_prence`(`id`,`type_id`, `school_id`, `department_id`, `programme_id`, `programme_type_applied_for`, `school_applied_for`,`department_applied_for`, 
															  `programme_applied_for`, `country_id`, `state_id`, `lga_id`,  `first_name`, `other_names`, `phone_no`, `pdf_file`, `gender`, 
															  `nationality`, `medi`,  `day`, `month`, `year`, `marital_status`, `number`, `application_number`, `username`, `password`, `email`,
															   `phone_number`,  `address`, `permanent_address`, `image`, `blood_type`, `disability`, `mode_of_entry`, `entry_year`, `award_in_view`,
																`user_status`, `place_of_birth`, `religion`, `level`, `H_status`, 
															   `date_added`, `guardian_name`, `guardian_relationship`, `guardian_tel`, `guardian_address`, 
															   `sponsorship_type`, `sponsorship_name`, `sponsorship_address`, `admission_criteria`, `date_admitted`, `admission_serial_no`) 
															   VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."','".$row['programme_type_applied_for']."',
															   '".$row['school_applied_for']."','".$row['department_applied_for']."','".$row['programme_applied_for']."','".$row['country_id']."','".$row['state_id']."',
															   '".$row['lga_id']."','".$fn."','".$on."','".$pn."',
															   '".$row['pdf_file']."','".$row['gender']."','".$row['nationality']."','".$med."','".$row['day']."','".$row['month']."',
															   '".$row['year']."','".$row['marital_status']."',('$applicant_matric_number'),'".$row['application_number']."', ('$applicant_matric_number'),
															   '".md5('0000')."','".$e."',
															   '".$pn."','".$add."','".$padd."','".$row['image']."','".$row['blood_type']."',
															   '".$row['disability']."','".$row['mode_of_entry']."','2017','1','1','".$pob."','".$row['religion']."',
															   '$applicant_level','".$row['H_status']."',NOW(),'".$gn."','".$gr."',
															   '".$gt."','".$ga."','".$row['sponsorship_type']."','".$sn."',
															   '".$sa."', '".$ac."', '".$row['date_admitted']."', '".$row['admission_serial_no']."')";
														
															   $rr = mysqli_query($dbc,$qq);
											  
											  
																if(mysqli_affected_rows($dbc))//mysqli_affected_rows($dbc)
																{
																	
																	 $latest_student_id =  mysqli_insert_id($dbc); //do something like inserting in school fee payment for the latest student added
																	 
																	 if(!student_id_exist_payments_prence($latest_student_id, $current_session, $current_semester))
																	 {
																		 
																		 
																		 //detect semester by 2 payments
																		 
																		 
																		 if($payment_mode == 1)
																		 {
																			 
																			  $qqq = "INSERT INTO `school_fee_payments_prence`(`id`, `programme_type_id`,`school_id`, `department_id`, `programme_id`, 
																				   `session`, `semester`, `student_id`, `payment_status`,`payment_mode`,`payment_method`, `invoice_id`,`sponsorship_type`,
																				   `title`, `description`, `amount`, `date_added`, `added_by`) 
																				   VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																				  '$current_session','$current_semester','$latest_student_id','1','$payment_mode','3',
																				  '$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')";
																			 
																		 }
																		 else
																		 {
																			  $qqq = "INSERT INTO `school_fee_payments_prence`(`id`, `programme_type_id`,`school_id`, `department_id`, `programme_id`, 
																				   `session`, `semester`, `student_id`, `payment_status`,`payment_mode`,`payment_method`, `invoice_id`,`sponsorship_type`,
																				   `title`, `description`, `amount`, `date_added`, `added_by`) 
																				   VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																				  '$current_session','1','$latest_student_id','1','$payment_mode','3',
																				  '$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id'),
																				  (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																				  '$current_session','2','$latest_student_id','1','$payment_mode','3',
																				  '$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')
																				  ";
																			 
																		 }//else of mode of payment is full
																	 
																		   
																			 
																			$rrr = mysqli_query($dbc,$qqq);
																	 
																			if($rrr)//mysqli_affected_rows($dbc)
																			{
																			  //if done finally collect all info for receipt
																			  
																			  //update invoice status to paid
																			  mysql_query("UPDATE invoices SET payment_status = '1' WHERE invoice_id = '$id'");
																			  
																			  
																			  $output = '';
																			  
																			  $output .= '<ul class="list-group">';
																			  
																			  $output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
																			 
																			 
																			  $output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname_prence($latest_student_id).'</b></li> <hr/>';
																			  
																			  $output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">School:<b>'.get_school_title(get_student_school_id_prence($latest_student_id)).'</b><strong> </strong> </span></li>';
																			  
																			  
																			  $output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number_prence($latest_student_id).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id_prence($latest_student_id)).'</b> </span></li> <hr/>';
																			  
																			  $output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
																			 
																			  $output .= '<li class="list-group-item help-block" >Description of Items: 
																			  
																			  
																								<br/>
																								<span>'.$invoice_title.' 
																								  </span> 
																								<br/>
																			  
																								  <span>'.$invoice_desc.' 
																								  </span> 
																						  </li>'; 
																						  
																			   $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																						  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																						  </li>';
																						  
																						  
																			   $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																						   Please visit students portal via "www.coeminna.edu.ng/eportal" with login  details, matric number and default password  "0000" to continue your registration process 
																						  </li>';
																			   
																				
																			 
																						  
																			  $output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
											
																						  
																						  
																						  
																						  
																			  $output .= '</ul>';
																			  
																			  echo $output;
																			  
																			  
																			}
																			else
																			{
																			   //else tell the admin to reprint
																				$errors['error'] =  'System Error!. We are sorry for inconvinience.Please Retry again. Thank you.';
																				header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
																			}
																			
																	 }//end of if student doesnt exist
																	
																			 
																	
																	 
																}
																else
																{
																	//show 
																	$errors['error'] =  'System Error in Entering!. We are sorry for inconvinience. Please Retry again. Thank you.';
																	header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
														
																}//end of if insert doesent work
													
													
													  }//end of if applicant doesnt exist system
													  else
													  {//but if applicant exist
													  
														  //check for the applicant id in students table
														  $student_id = get_student_id_application_number_prence($application_number, $applicant_level);
														  
														  
														  
														  //check if he /she has made payment
														  
														  if(student_id_exist_payments_prence($student_id, $current_session, $current_semester))
														  {
																			  $output = '';
																			  
																			  $output .= '<ul class="list-group">';
																			  
																			  $output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
																			 
																			 
																			  $output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname_prence($student_id).'</b></li> <hr/>';
																			  
																			  $output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">School:<b>'.get_school_title(get_student_school_id_prence($student_id)).'</b><strong> </strong> </span></li>';
																			  
																			  
																			  $output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number_prence($student_id).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id_prence($student_id)).'</b> </span></li> <hr/>';
																			  
																			  $output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
																			 
																			  $output .= '<li class="list-group-item help-block" >Description of Items: 
																						 <br/><span>'.$invoice_title.'</span> <br/>
																						 <span>'.$invoice_desc.'</span> </li>'; 
																						  
																			   $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																						  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																						  </li>';
																			   $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																						   Please visit students portal "www.coeminna.edu.ng/eportal" with login  details, matric number and default password  "0000" to continue your registration process 
																						  </li>';
																			   $output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
											
																						  
																						  
																						  
																						  
																			  $output .= '</ul>';
																			  
																			  echo $output;
															  
														  }
														  else
														  {//if appicant is in students table and hant made payment tell the banker to retry
															  
															   $errors['error'] =  'Not successful!. We are sorry for inconvinience.Please Retry again. Thank you.';
															   header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
															  
														  }
														  
														  //if not pay
														  
														  
													  
													  
													  }//take infor mation to display only
													
												  }//end of while row fetching
													
											}//end if applicant record exist
											else
											{
												//show 
												$errors['error'] =  'System Error!. We are sorry for inconvinience.Please Retry again. Thank you.';
												header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
											}
											
											//get applicant id and get all information from application table
											
									
									
									}//end of if invoice type is fresh student
									else if($invoice_type == '2') //end if invoice type is student
									{
										//insert the candidate as a student
										
										//get student details to make payment
										//student programme type
										$student_programme_type = get_student_programme_type_id($invoice_to);//get student pt
										
										//student department
										$student_department = get_student_department_id($invoice_to); 
										
										
										
										//student department
										$student_programme = get_student_programme_id($invoice_to);
										
										
										//$student_level = '100'; //aplicant level 
										
														   
									   if(!student_id_exist_payments($invoice_to, $current_session, $current_semester))
									   {
									   
											  $qqq1 = "INSERT INTO `school_fee_payments`(`id`, `programme_type_id`, `department_id`, `programme_id`, 
													 `session`, `semester`, `student_id`, `payment_status`, `invoice_id`,
													   `title`, `description`, `amount`, `date_added`, `added_by`) 
													   VALUES (NULL,'$student_programme_type','$student_department','$student_programme',
													  '$current_session','$current_semester','$invoice_to','1',
													  '$id','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')";
											   
											  $rrr1 = mysqli_query($dbc,$qqq1);
									   
											  if($rrr1)//mysqli_affected_rows($dbc)
											  {
												//if done finally collect all info for receipt
												
												
												//update invoice status to paid
												 mysql_query("UPDATE invoices SET payment_status = '1' WHERE invoice_id = '$id'");
																			  
												
												
													$output = '';
													
													$output .= '<ul class="list-group">';
													
													$output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
												   
												   
													$output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($invoice_to).'</b></li> <hr/>';
													
													$output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">Semester:<b>'.get_semester_title($current_semester).'</b><strong> </strong> </span></li>';
													
													
													$output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($invoice_to).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($invoice_to)).'</b> </span></li> <hr/>';
													
													$output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
												   
													$output .= '<li class="list-group-item help-block" >Description of Items: 
													
													
																	  <br/>
																	  <span>'.$invoice_title.' 
																		</span> 
																	  <br/>
													
																		<span>'.$invoice_desc.' 
																		</span> 
																</li>'; 
																
													 $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																<span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																</li>';
																
																
													 $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																 Please visit "www.students.ndp.coeminna.edu.ng" with login  details matric number and default password  "0000" to continue your registration process 
																</li>';
													 
													  
												   
																
													$output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
				  
																
																
																
																
													$output .= '</ul>';
													
													echo $output;
												
												
											  }
											  else
											  {
												 //else tell the admin to reprint
											  }
											  
									   }//end of if student doesnt exist
									   else
									   {//if student exist
									   
													$output = '';
													
													$output .= '<ul class="list-group">';
													
													$output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
												   
												   
													$output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($invoice_to).'</b></li> <hr/>';
													
													$output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">Semester:<b>'.get_semester_title($current_semester).'</b><strong> </strong> </span></li>';
													
													
													$output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($invoice_to).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($invoice_to)).'</b> </span></li> <hr/>';
													
													$output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
												   
													$output .= '<li class="list-group-item help-block" >Description of Items: 
													
													
																	  <br/>
																	  <span>'.$invoice_title.' 
																		</span> 
																	  <br/>
													
																		<span>'.$invoice_desc.' 
																		</span> 
																</li>'; 
																
													 $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																<span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																</li>';
																
																
													 $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																 Please visit "www.students.nce.coeminna.edu.ng" with login  details matric number and default password  "0000" to continue your registration process 
																</li>';
													 
													  
												   
																
													$output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
				  
																
																
																
																
													$output .= '</ul>';
													
													echo $output;		
										   
									   }//end of if student already exist
									  
																	   
															  
														  
													
										
										
										
										
										
									}//end of if invoice type is student
									else
									{
									  //do nothing for now  
									}

						  
						  
						  
						  
						  
					  }
					  else
					  { //if nce /////////////////////////////////////////////////////////##############################
					  	###################################nce
					  
					  
							  //check invoice type
							  if($invoice_type == '1')//if invoice is fresh student
							  {
								  
								  
								  //aplicant programme type
								  $applicant_programme_type = get_applicant_programme_type_admitted_to($invoice_to);//get applicant pt
								  
								 
								  //applicant school
								 $applicant_school = get_applicant_school_admitted_to($invoice_to); 
								 
								 
								  //applicant department
								 $applicant_department = get_applicant_department_admitted_to($invoice_to); 
								  
								  
								  
								  //applicant department
								  $applicant_programme = get_applicant_programme_admitted_to($invoice_to);
								  
								  
								  $applicant_level = 'I'; //aplicant level 
								  
								  $application_number = get_applicant_application_number($invoice_to);
								  
								  
								  //insert school id and show school id, 
								  
								  //payment method 3 manual microfinance bank
							  
							  
							  
							 
										$q = "SELECT  `type_id`, `school_id`, `department_id`, `programme_id`, `programme_type_applied_for`, `school_applied_for`,
											 `department_applied_for`, `programme_applied_for`, `application_number`, `country_id`, `state_id`,
											 `lga_id`, `first_name`, `other_names`, `phone_no`, `pdf_file`, `gender`, `religion`, `nationality`, `day`, `month`, `year`,
											  `marital_status`, `email`, `place_of_birth`,  `address`, `permanent_address`, `image`, `H_status`, 
											  `blood_type`, `disability`, `mode_of_entry`, `medi`,  `town`,  `guardian_name`, `guardian_tel`, `guardian_address`, 
											  `guardian_relationship`, `sponsorship_type`, `sponsorship_name`, `sponsorship_address`, 
											  `admission_status`, `admission_criteria`, `date_admitted`, `admission_serial_no`
											   
											 FROM `applicants_nce` 
											   
											 WHERE application_number = '$application_number'";
											   
										$r = mysqli_query($dbc,$q);
					  
										if(mysqli_num_rows($r) > 0)
										{//if succesfully fetch applicant recor
										
										
										
											 
											  //$initial = 0 ;
											  
											   $total_in_programme = get_total_programme_students($applicant_programme_type,$applicant_school,$applicant_programme,$applicant_level);
											   
											   $total_in_programme = $total_in_programme + 1; 
										
											  //generate matric number
											  $applicant_matric_number = generate_matric_number($applicant_programme_type, $applicant_school, $applicant_programme, $applicant_level, $total_in_programme);
												
												
											  
									  
											while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))//fetch data to be migrated
											{
												
												//chedk if student has been added already an collect info if added //review this dont depend on this function
												if(!application_number_exist($application_number, $applicant_level))
												{
													   //collect the variables for inserting and check for special string using 
													   $fn = mysqli_real_escape_string($dbc,$row['first_name']); //first name
													   $on = mysqli_real_escape_string($dbc,$row['other_names']);
													   $pn = mysqli_real_escape_string($dbc,$row['phone_no']);
														$e = mysqli_real_escape_string($dbc,$row['email']);
														$add = mysqli_real_escape_string($dbc,$row['address']);
														$padd = mysqli_real_escape_string($dbc,$row['permanent_address']);
														$pob = mysqli_real_escape_string($dbc,$row['place_of_birth']);
														$gn = mysqli_real_escape_string($dbc,$row['guardian_name']);
														$gr = mysqli_real_escape_string($dbc,$row['guardian_relationship']);
														$gt = mysqli_real_escape_string($dbc,$row['guardian_tel']);
														$ga = mysqli_real_escape_string($dbc,$row['guardian_address']);
														$sn = mysqli_real_escape_string($dbc,$row['sponsorship_name']);
														$sa = mysqli_real_escape_string($dbc,$row['sponsorship_address']);
														$ac = mysqli_real_escape_string($dbc,$row['admission_criteria']);
														$med = mysqli_real_escape_string($dbc,$row['medi']);
														$spt = mysqli_real_escape_string($dbc,$row['sponsorship_type']);
														
														
									  
									  
														//get applicants info
														$qq = "INSERT INTO `students_nce`(`id`,`type_id`, `school_id`, `department_id`, `programme_id`, `programme_type_applied_for`, `school_applied_for`,`department_applied_for`, 
														`programme_applied_for`, `country_id`, `state_id`, `lga_id`,  `first_name`, `other_names`, `phone_no`, `pdf_file`, `gender`, 
														`nationality`, `medi`,  `day`, `month`, `year`, `marital_status`, `number`, `application_number`, `username`, `password`, `email`,
														 `phone_number`,  `address`, `permanent_address`, `image`, `blood_type`, `disability`, `mode_of_entry`, `entry_year`, `award_in_view`,
														  `user_status`, `place_of_birth`, `religion`, `level`, `H_status`, 
														 `date_added`, `guardian_name`, `guardian_relationship`, `guardian_tel`, `guardian_address`, 
														 `sponsorship_type`, `sponsorship_name`, `sponsorship_address`, `admission_criteria`, `date_admitted`, `admission_serial_no`) 
														 VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."','".$row['programme_type_applied_for']."',
														 '".$row['school_applied_for']."','".$row['department_applied_for']."','".$row['programme_applied_for']."','".$row['country_id']."','".$row['state_id']."',
														 '".$row['lga_id']."','".$fn."','".$on."','".$pn."',
														 '".$row['pdf_file']."','".$row['gender']."','".$row['nationality']."','".$med."','".$row['day']."','".$row['month']."',
														 '".$row['year']."','".$row['marital_status']."',('$applicant_matric_number'),'".$row['application_number']."', ('$applicant_matric_number'),
														 '".md5('0000')."','".$e."',
														 '".$pn."','".$add."','".$padd."','".$row['image']."','".$row['blood_type']."',
														 '".$row['disability']."','".$row['mode_of_entry']."','2017','1','1','".$pob."','".$row['religion']."',
														 '$applicant_level','".$row['H_status']."',NOW(),'".$gn."','".$gr."',
														 '".$gt."','".$ga."','".$row['sponsorship_type']."','".$sn."',
														 '".$sa."', '".$ac."', '".$row['date_admitted']."', '".$row['admission_serial_no']."')";
												  
														 $rr = mysqli_query($dbc,$qq);
										
										
														  if(mysqli_affected_rows($dbc))//mysqli_affected_rows($dbc)
														  {
															  
															   $latest_student_id =  mysqli_insert_id($dbc); //do something like inserting in school fee payment for the latest student added
															   
															   if(!student_id_exist_payments($latest_student_id, $current_session, $current_semester))
															   {
																   
																   
																   //detect semester by 2 payments
																   
																   
																   if($payment_mode == 1)
																   {
																	   
																		$qqq = "INSERT INTO `school_fee_payments_nce`(`id`, `programme_type_id`,`school_id`, `department_id`, `programme_id`, 
																			 `session`, `semester`, `student_id`, `payment_status`,`payment_mode`,`payment_method`, `invoice_id`,`sponsorship_type`,
																			 `title`, `description`, `amount`, `date_added`, `added_by`) 
																			 VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																			'$current_session','$current_semester','$latest_student_id','1','$payment_mode','3',
																			'$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')";
																	   
																   }
																   else
																   {
																		$qqq = "INSERT INTO `school_fee_payments_nce`(`id`, `programme_type_id`,`school_id`, `department_id`, `programme_id`, 
																			 `session`, `semester`, `student_id`, `payment_status`,`payment_mode`,`payment_method`, `invoice_id`,`sponsorship_type`,
																			 `title`, `description`, `amount`, `date_added`, `added_by`) 
																			 VALUES (NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																			'$current_session','1','$latest_student_id','1','$payment_mode','3',
																			'$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id'),
																			(NULL,'".$row['type_id']."','".$row['school_id']."','".$row['department_id']."','".$row['programme_id']."',
																			'$current_session','2','$latest_student_id','1','$payment_mode','3',
																			'$id','$spt','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')";
																	   
																   }//else of mode of payment is full
															   
																	 
																	   
																	  $rrr = mysqli_query($dbc,$qqq);
															   
																	  if($rrr)//mysqli_affected_rows($dbc)
																	  {
																		//if done finally collect all info for receipt
																		
																		//update invoice status to paid
																		mysql_query("UPDATE invoices SET payment_status = '1' WHERE invoice_id = '$id'");
																		
																		
																		$output = '';
																		
																		$output .= '<ul class="list-group">';
																		
																		$output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
																	   
																	   
																		$output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($latest_student_id).'</b></li> <hr/>';
																		
																		$output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">School:<b>'.get_school_title(get_student_school_id($latest_student_id)).'</b><strong> </strong> </span></li>';
																		
																		
																		$output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($latest_student_id).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($latest_student_id)).'</b> </span></li> <hr/>';
																		
																		$output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
																	   
																		$output .= '<li class="list-group-item help-block" >Description of Items: 
																		
																		
																						  <br/>
																						  <span>'.$invoice_title.' 
																							</span> 
																						  <br/>
																		
																							<span>'.$invoice_desc.' 
																							</span> 
																					</li>'; 
																					
																		 $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																					<span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																					</li>';
																					
																					
																		 $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																					 Please visit students portal via "www.coeminna.edu.ng/eportal" with login  details, matric number and default password  "0000" to continue your registration process 
																					</li>';
																		 
																		  
																	   
																					
																		$output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
									  
																					
																					
																					
																					
																		$output .= '</ul>';
																		
																		echo $output;
																		
																		
																	  }
																	  else
																	  {
																		 //else tell the admin to reprint
																		  $errors['error'] =  'System Error!. We are sorry for inconvinience.Please Retry again. Thank you.';
																		  header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
																	  }
																	  
															   }//end of if student doesnt exist
															  
																	   
															  
															   
														  }
														  else
														  {
															  //show 
															  $errors['error'] =  'System Error in Entering!. We are sorry for inconvinience. Please Retry again. Thank you.';
															  header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
												  
														  }//end of if insert doesent work
											  
											  
												}//end of if applicant doesnt exist system
												else
												{//but if applicant exist
												
													//check for the applicant id in students table
													$student_id = get_student_id_application_number($application_number, $applicant_level);
													
													
													
													//check if he /she has made payment
													
													if(student_id_exist_payments($student_id, $current_session, $current_semester))
													{
																		$output = '';
																		
																		$output .= '<ul class="list-group">';
																		
																		$output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
																	   
																	   
																		$output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($student_id).'</b></li> <hr/>';
																		
																		$output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">School:<b>'.get_school_title(get_student_school_id($student_id)).'</b><strong> </strong> </span></li>';
																		
																		
																		$output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($student_id).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($student_id)).'</b> </span></li> <hr/>';
																		
																		$output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
																	   
																		$output .= '<li class="list-group-item help-block" >Description of Items: 
																				   <br/><span>'.$invoice_title.'</span> <br/>
																				   <span>'.$invoice_desc.'</span> </li>'; 
																					
																		 $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
																					<span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
																					</li>';
																		 $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
																					 Please visit students portal "www.coeminna.edu.ng/eportal" with login  details, matric number and default password  "0000" to continue your registration process 
																					</li>';
																		 $output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
									  
																					
																					
																					
																					
																		$output .= '</ul>';
																		
																		echo $output;
														
													}
													else
													{//if appicant is in students table and hant made payment tell the banker to retry
														
														 $errors['error'] =  'Not successful!. We are sorry for inconvinience.Please Retry again. Thank you.';
														 header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
														
													}
													
													//if not pay
													
													
												
												
												}//take infor mation to display only
											  
											}//end of while row fetching
											  
									  }//end if applicant record exist
									  else
									  {
										  //show 
										  $errors['error'] =  'System Error!. We are sorry for inconvinience.Please Retry again. Thank you.';
										  header("Location: gateway.php?act=view_students_payments_b&error=".urlencode($errors['error'])."");
									  }
									  
									  //get applicant id and get all information from application table
									  
							  
							  
							  }//end of if invoice type is fresh student
							  else if($invoice_type == '2') //end if invoice type is student
							  {
								  //insert the candidate as a student
								  
								  //get student details to make payment
								  //student programme type
								  $student_programme_type = get_student_programme_type_id($invoice_to);//get student pt
								  
								  //student department
								  $student_department = get_student_department_id($invoice_to); 
								  
								  
								  
								  //student department
								  $student_programme = get_student_programme_id($invoice_to);
								  
								  
								  //$student_level = '100'; //aplicant level 
								  
													 
								 if(!student_id_exist_payments($invoice_to, $current_session, $current_semester))
								 {
								 
										$qqq1 = "INSERT INTO `school_fee_payments`(`id`, `programme_type_id`, `department_id`, `programme_id`, 
											   `session`, `semester`, `student_id`, `payment_status`, `invoice_id`,
												 `title`, `description`, `amount`, `date_added`, `added_by`) 
												 VALUES (NULL,'$student_programme_type','$student_department','$student_programme',
												'$current_session','$current_semester','$invoice_to','1',
												'$id','$invoice_title','$invoice_desc','$invoice_amount',NOW(),'$security_id')";
										 
										$rrr1 = mysqli_query($dbc,$qqq1);
								 
										if($rrr1)//mysqli_affected_rows($dbc)
										{
										  //if done finally collect all info for receipt
										  
										  
										  //update invoice status to paid
										   mysql_query("UPDATE invoices SET payment_status = '1' WHERE invoice_id = '$id'");
																		
										  
										  
											  $output = '';
											  
											  $output .= '<ul class="list-group">';
											  
											  $output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
											 
											 
											  $output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($invoice_to).'</b></li> <hr/>';
											  
											  $output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">Semester:<b>'.get_semester_title($current_semester).'</b><strong> </strong> </span></li>';
											  
											  
											  $output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($invoice_to).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($invoice_to)).'</b> </span></li> <hr/>';
											  
											  $output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
											 
											  $output .= '<li class="list-group-item help-block" >Description of Items: 
											  
											  
																<br/>
																<span>'.$invoice_title.' 
																  </span> 
																<br/>
											  
																  <span>'.$invoice_desc.' 
																  </span> 
														  </li>'; 
														  
											   $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
														  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
														  </li>';
														  
														  
											   $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
														   Please visit "www.students.ndp.coeminna.edu.ng" with login  details matric number and default password  "0000" to continue your registration process 
														  </li>';
											   
												
											 
														  
											  $output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
			
														  
														  
														  
														  
											  $output .= '</ul>';
											  
											  echo $output;
										  
										  
										}
										else
										{
										   //else tell the admin to reprint
										}
										
								 }//end of if student doesnt exist
								 else
								 {//if student exist
								 
											  $output = '';
											  
											  $output .= '<ul class="list-group">';
											  
											  $output .= '<li class="list-group-item help-block">Date / Time: '.date('Y-m-d-His').'  <span class="pull-right">ID:<strong>'.$id.' </strong> </span></li>  <hr/>';
											 
											 
											  $output .= '<li class="list-group-item help-block" >Name: <b>'.get_student_fullname($invoice_to).'</b></li> <hr/>';
											  
											  $output .= '<li class="list-group-item help-block" >Session:<b>'.get_session_title($current_session).'</b> <span class="pull-right">Semester:<b>'.get_semester_title($current_semester).'</b><strong> </strong> </span></li>';
											  
											  
											  $output .= '<li class="list-group-item help-block" >Matric No.:<b>'.get_student_matric_number($invoice_to).'</b> <span class="pull-right">Course :<b>'.get_programme_title(get_student_programme_id($invoice_to)).'</b> </span></li> <hr/>';
											  
											  $output .= '<li class="list-group-item help-block" >The Sum of N'.number_format($invoice_amount ,2).'K </li>';
											 
											  $output .= '<li class="list-group-item help-block" >Description of Items: 
											  
											  
																<br/>
																<span>'.$invoice_title.' 
																  </span> 
																<br/>
											  
																  <span>'.$invoice_desc.' 
																  </span> 
														  </li>'; 
														  
											   $output .= '<li class="list-group-item help-block" style="min-height:60px;" >
														  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total Paid: N'.number_format($invoice_amount ,2).'K </span>
														  </li>';
														  
														  
											   $output .= '<li class="list-group-item help-block" style="min-height:20px;color:#foo;" >
														   Please visit "www.students.nce.coeminna.edu.ng" with login  details matric number and default password  "0000" to continue your registration process 
														  </li>';
											   
												
											 
														  
											  $output .= '<li class="list-group-item"> <a href="javascript:doit()"><img src="images/print_big.png" border=0 align="middle" class="pull-right" title="Print" data-toggle="tooltip"> </a> </li>';
			
														  
														  
														  
														  
											  $output .= '</ul>';
											  
											  echo $output;		
									 
								 }//end of if student already exist
								
																 
														
													
											  
								  
								  
								  
								  
								  
							  }//end of if invoice type is student
							  else
							  {
								//do nothing for now  
							  }
					  
					  
					  
					  
					  }//end of invoice is nce
					  
					  
				?>
                
                
                
                
                
                <?php
					  
					  
					  
					  
				  
				  
				  
				  }//end of for loop for collecting the id
				 
				 
			   }//end of if act is confirm payment
			 
			 
			 
			 //display the information
			 

			  
			  		
					
			  ?>
              
              
              <!--<img src="images/background.png" border=0 align="middle"  title="Print"> -->

        
        </div> 
        
      </div>
</div>

</form>



