<?php
/* **************************************************************************
** This page   collects user id and pass it to invoice generation methods
**
*****************************************************************************/

//here hf is hostel fee
//sf is school fee
//rf is result fee


//collect the  invoice to for school fee
if(isset($_GET['invoice_to']))
{


	//collect what the payment is for
	$payment_for = $_GET['for'];

	//collect pay to
	$invoice_to = $_GET['invoice_to'];

	//invoice type
	$invoice_type = 2;  //2-returning student





	$user = get_user_id();//get user
	$level = get_user_level($user); //get user level
	$programme_type = get_user_programme_type_id($user); //programme type
	$department = get_user_department_id($user); //department
	$programme  = get_user_programme_id($user);//programme


	//get current semester
	$current_semester = get_current_semester($id = 1);


	//get current session
	$current_session = get_current_session_4($id = 4);





	//now check if the payment is school fee let this action happens
	if($payment_for == 'sf')
	{//let tghis happen


		//collect other params
	  $title = "SUMMER APPLICATION FEE"; //get_school_fee_title($level, $current_semester,$programme_type, $department, $programme,$current_session);
	  $description = "SUMMER FEE DESC";//get_school_fee_desc($level, $current_semester, $programme_type, $department, $programme, $current_session);
	  $total_amount = "4480"; //get_school_fee_total_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $amount =  "4480"; //get_school_fee_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $credit = 0; //get_invoice_credit($total_amount, $amount); //pass total anmount , amount paid
	  $pay_to = 'NIGER STATE COLLEGE OF EDUCATION. MINNA. SUMMER <br> '; //<br> SKYE BANK ACCT: 1771647318

	  //set the invoice for to be 2 since we are paying for return school fee
	  $invoice_for  = '22';
	  $payment_mode = '22';
		//invoice type
		$invoice_type = 22;

		//flip the gentleman back if he has not finish application process
		if($total_amount < 4000 || $amount < 4000)
		{
			$msg = "Please Contact the ICT Unit.";
			  //head to same page saying that not successful
			header("Location: dashboard.php?act=payments&error=".urlencode($msg)."&qlk=".md5(8)."");

			exit();
		}






	  //collect other params
	  $title ='SUMMER SCHOOL FEE'; //get_school_fee_title($level, $current_semester,$programme_type, $department, $programme,$current_session);
	  $description = "SUMMER SCHOOL FEE DESC";//get_school_fee_desc($level, $current_semester, $programme_type, $department, $programme, $current_session);
	  $total_amount = "20480"; //get_school_fee_total_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $amount =  "20480"; //get_school_fee_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $credit = 0; //get_invoice_credit($total_amount, $amount); //pass total anmount , amount paid

		$pay_to = 'NIGER STATE COLLEGE OF EDUCATION. MINNA. <br> '; //<br> SKYE BANK ACCT: 1771647318
	  //set the invoice for to be 2 since we are paying for return school fee
	  $invoice_for  = '24';
	  $payment_mode = '1';

		//invoice type

		$invoice_type = 24;
		//flip the gentleman back if he has not finish application process
		if($total_amount < 20000 || $amount < 20000)
		{
			$msg = "Please Contact the ICT Unit.";
			  //head to same page saying that not successful
			header("Location: dashboard.php?act=payments&error=".urlencode($msg)."&qlk=".md5(8)."");

			exit();
		}



	  //insert into the invoice
	  $q = "INSERT INTO `invoices`(`id`, `invoice_type`,`invoice_to`, `pay_to`,`invoice_for`,`session`,`programme_type`,`title`, `description`, `amount`,`total_amount`, `credit`, `date_added`, `due_date`)
		   VALUES (NULL, '$invoice_type','$user','$pay_to','$invoice_for','$current_session','$programme_type','$title','$description','$amount','$total_amount','$credit',NOW(),NOW())";


	  $r = mysqli_query($dbc,$q);


	  if(mysqli_affected_rows($dbc))
	  {

		  //get id of last inserted value
		  $id = mysqli_insert_id($dbc);



		  //generate invoice id and show the invoice
		  $generated = generate_invoice_id($id, $user, $invoice_type);

		  if($generated =='')
		  {
			  $msg = "Invoice not generated due to system error, we are sorry for the inconvenience.";
			  //head to same page saying that not successful
			  header("Location: dashboard.php?act=school_fee_payments&error=".urlencode($msg)."&qlk=".md5(2)."");


		  }
		  else
		  {
			  $msg = "Invoice generated successfully. Thank you!";

			  //head to invoice page
			  header("Location: dashboard.php?act=view_invoices5&is=".urlencode($msg)."&qlk=".md5(2)."&iid=".$generated);

		  }

	  }

	}//end of if for sf


	//now check if the payment is school fee let this action happens
	if($payment_for == 'ssf')
	{//let tghis happen


	  //collect other params
	  $title = "SUMMER APPLICATION FEE"; //get_school_fee_title($level, $current_semester,$programme_type, $department, $programme,$current_session);
	  $description = "SUMMER FEE DESC";//get_school_fee_desc($level, $current_semester, $programme_type, $department, $programme, $current_session);
	  $total_amount = "4480"; //get_school_fee_total_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $amount =  "4480"; //get_school_fee_amount($level, $current_semester, $programme_type, $department, $programme,$current_session);
	  $credit = 0; //get_invoice_credit($total_amount, $amount); //pass total anmount , amount paid
	  $pay_to = 'NIGER STATE COLLEGE OF EDUCATION. MINNA. SUMMER <br> '; //<br> SKYE BANK ACCT: 1771647318

	  //set the invoice for to be 2 since we are paying for return school fee
	  $invoice_for  = '22';
	  $payment_mode = '22';
		//invoice type
		$invoice_type = 22;

		//flip the gentleman back if he has not finish application process
		if($total_amount < 4000 || $amount < 4000)
		{
			$msg = "Please Contact the ICT Unit.";
			  //head to same page saying that not successful
			header("Location: dashboard.php?act=payments&error=".urlencode($msg)."&qlk=".md5(8)."");

			exit();
		}



	  //insert into the invoice
	  $q = "INSERT INTO `invoices`(`id`, `invoice_type`,`invoice_to`, `pay_to`,`invoice_for`,`session`,`programme_type`,`title`, `description`, `amount`,`total_amount`, `credit`, `date_added`, `due_date`)
		   VALUES (NULL, '$invoice_type','$user','$pay_to','$invoice_for','$current_session','$programme_type','$title','$description','$amount','$total_amount','$credit',NOW(),NOW())";


	  $r = mysqli_query($dbc,$q);


	  if(mysqli_affected_rows($dbc))
	  {

		  //get id of last inserted value
		  $id = mysqli_insert_id($dbc);



		  //generate invoice id and show the invoice
		  $generated = generate_invoice_id($id, $user, $invoice_type);

		  if($generated =='')
		  {
			  $msg = "Invoice not generated due to system error, we are sorry for the inconvenience.";
			  //head to same page saying that not successful
			  header("Location: dashboard.php?act=school_fee_payments&error=".urlencode($msg)."&qlk=".md5(2)."");


		  }
		  else
		  {
			  $msg = "Invoice generated successfully. Thank you!";

			  //head to invoice page
			  header("Location: dashboard.php?act=view_invoices4&is=".urlencode($msg)."&qlk=".md5(2)."&iid=".$generated);

		  }

	  }

	}//end of if for sf

	//*************************************** for hostel fee *********************************
//	if($payment_for == 'hf')
//	{//let tghis happen
//
//
//
//
//
//
//	  //collect other params
//	  $title = get_hostel_fee_title($level);
//	  $description = get_hostel_fee_desc($level);
//	  $amount =  get_hostel_fee_amount($level);
//	  $credit = get_invoice_credit($level);
//	  $pay_to = 'IBRAHIM BADAMASI BABANGIDA UNIVERSITY, LAPAI. NIGER STATE. <br> UBA ACCT: 12543172 <br> FIRST BANK ACCT: 7824929';
//
//	   //set the invoice for to be zero since we are paying for hostel fee
//	  $invoice_for  = '1';
//
//	  //insert into the invoice
//	  $q = "INSERT INTO `invoices`(`id`, `invoice_to`, `pay_to`, `invoice_for`,`title`, `description`, `amount`, `credit`, `date_added`, `due_date`)
//		   VALUES (NULL, '$user','$pay_to','$invoice_for','$title','$description','$amount','$credit',NOW(),NOW())";
//
//	  $r = mysqli_query($dbc,$q);
//
//
//	  if(mysqli_affected_rows($dbc))
//	  {
//
//		  //get id of last inserted value
//		  $id = mysqli_insert_id($dbc);
//
//
//
//		  //generate invoice id and show the invoice
//		  $generated = generate_invoice_id($id, $user);
//
//		  if($generated =='')
//		  {
//			  $msg = "Invoice not generated due to system error, we are sorry for the inconvenience.";
//			  //head to same page saying that not successful
//			  header("Location: dashboard.php?act=hostel_fee_payments&error=".urlencode($msg)."&qlk=".md5(2)."");
//
//
//		  }
//		  else
//		  {
//			  $msg = "Invoice generated successfully. Thank you!";
//
//			  //head to invoice page
//			  header("Location: dashboard.php?act=view_invoices&is=".urlencode($msg)."&qlk=".md5(2)."&iid=".$generated);
//
//		  }
//
//	  }
//
//	}//end of if for hf



}//end of if invoice_to has value

?>
