<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============
$operation=$_POST['operation'];
$branch_id=$_SESSION['LOGIN_BRANCH'];
$time=addslashes(trim($_POST['time']));

if($operation=='update_exam_service_fee_collection_info'){
	$edit_payment_id=trim($_POST['selected_payment_id_for_fee_edit']);
	$edit_school_id=trim($_POST['selected_school_id_for_fee_edit']);
	$edit_total_amount_for_fee=addslashes(trim($_POST['selected_total_amount_for_fee_edit']));
	$edit_due_amount_for_fee=addslashes(trim($_POST['selected_due_amount_for_fee_edit']));
	$edit_paid_amount_for_fee=addslashes(trim($_POST['selected_paid_amount_for_fee_edit']));
	$edit_discount_amount_for_fee=addslashes(trim($_POST['selected_discount_amount_for_fee_edit']));
	$edit_last_paid_amount_for_fee=addslashes(trim($_POST['selected_last_paid_amount_for_fee_edit']));
	$track_receive_amount_for_fee=addslashes(trim($_POST['track_receive_amount']));
	$edit_payment_status_for_fee=addslashes(trim($_POST['selected_payment_status_for_fee_edit']));
	$edit_payment_date_for_fee=addslashes(trim($_POST['selected_payment_date_for_fee_edit']));
	
	$convert_to_date=strtotime($edit_payment_date_for_fee);
	$payment_entry_date=date("Y:m:d h:i:s", $convert_to_date);
	$select_month_from_payment_entry_date = date("m", $convert_to_date);
	$select_year_from_payment_entry_date = date("Y", $convert_to_date);
	
	$form_data1['_total_amount']=$edit_total_amount_for_fee;
	$form_data1['_due_amount']=$edit_due_amount_for_fee;
	$form_data1['_paid_amount']=$edit_paid_amount_for_fee;
	$form_data1['_discount_amount']=$edit_discount_amount_for_fee;
	$form_data1['_last_paid_amount']=$edit_last_paid_amount_for_fee;
	$form_data1['_status']=$edit_payment_status_for_fee;
	$form_data1['_update_by']=$_SESSION['LOGIN_USERID'];
	$form_data1['_last_update']=date("Y:m:d h:i:s");
	
	$table_name1='_exam_service_registration';
	$where_clause1="_id='".$edit_payment_id."'";
	
	$form_data2['_school_id']=$edit_school_id;
	$form_data2['_school_reg_id']=$edit_payment_id;
	$form_data2['_receive_amount']=$track_receive_amount_for_fee;
	$form_data2['_month']=$select_month_from_payment_entry_date;
	$form_data2['_year']=$select_year_from_payment_entry_date;
	$form_data2['_entry_date']=$payment_entry_date;
	$form_data2['_due_amount']=$edit_due_amount_for_fee;
	$form_data2['_status']='A';
	$form_data2['_update_by']=$_SESSION['LOGIN_USERID'];
	$form_data2['_last_update']=date("Y:m:d h:i:s");
	
	$table_name2='_exam_service_payment_collection';
	
	
	$entry1=$obj->Update_Data($table_name1, $form_data1, $where_clause1);
	if($entry1!=NULL){
		$entry2=$obj->Insert_Data($table_name2, $form_data2);
		if($entry2!=NULL){
			echo "fee collection information has been updated";
		}
	}else{
		echo "error occured during updating information!!";
	}
}
if($operation=='rollback_payment_entry'){
	$rollback_payment_id=trim($_POST['payment_id_for_rollback']);
	$rollback_payment_history_id=trim($_POST['payment_history_id_for_rollback']);
	$rollback_total_amount=addslashes(trim($_POST['total_amount_for_rollback']));
	$rollback_due_amount=addslashes(trim($_POST['due_amount_for_rollback']));
	$rollback_paid_amount=addslashes(trim($_POST['paid_amount_for_rollback']));
	$rollback_payment_status=addslashes(trim($_POST['payment_status_for_rollback']));
	
	
	$form_data1['_total_amount']=$rollback_total_amount;
	$form_data1['_due_amount']=$rollback_due_amount;
	$form_data1['_paid_amount']=$rollback_paid_amount;
	$form_data1['_status']=$rollback_payment_status;
	$form_data1['_update_by']=$_SESSION['LOGIN_USERID'];
	$form_data1['_last_update']=date("Y:m:d h:i:s");
	
	$table_name1='_exam_service_registration';
	$where_clause1="_id='".$rollback_payment_id."'";
	

	$form_data2['_status']='R';
	$form_data2['_update_by']=$_SESSION['LOGIN_USERID'];
	$form_data2['_last_update']=date("Y:m:d h:i:s");
	
	$table_name2='_exam_service_payment_collection';
	$where_clause2="_id='".$rollback_payment_history_id."'";
	
	$entry1=$obj->Update_Data($table_name1, $form_data1, $where_clause1);
	if($entry1!=NULL){
		$entry2=$obj->Update_Data($table_name2, $form_data2, $where_clause2);
		if($entry2!=NULL){
			echo "Rollback has completed";
		}
	}else{
		echo "error occured during rollback!!";
	}
}
?>