<?php
include './login/connect.php';
$date= date('d-m-Y');
if (isset($_POST['add']))
	{	   
	 		//admission_fee
                $admission_fee= mysqli_real_escape_string($conn,$_POST['admission_fee']);
                $cardID= mysqli_real_escape_string($conn,$_POST['cardID']);
                $EmployeeName= mysqli_real_escape_string($conn,$_POST['EmployeeName']);					
                $father= mysqli_real_escape_string($conn,$_POST['father']);
                $mother= mysqli_real_escape_string($conn,$_POST['mother']);
                $class= mysqli_real_escape_string($conn,$_POST['class']);
                $mobile= mysqli_real_escape_string($conn,$_POST['mobile']);
                $nid_br= mysqli_real_escape_string($conn,$_POST['nid_br']);
                $dob= mysqli_real_escape_string($conn,$_POST['dob']);
                $address= mysqli_real_escape_string($conn,$_POST['address']);
                $designation = $_POST['designation'];
                $gender = $_POST['gender'];
                //$date= date('d-m-Y');
					
		 mysqli_query($conn,"INSERT INTO  employee_details (cardID,EmployeeName,designation,father,mother,class,mobile,nid_br,dob,address,gender,date_in) 
		 VALUES ('$cardID','$EmployeeName','$designation','$father','$mother','$class','$mobile',' $nid_br','$dob','$address','$gender','$date')"); 
		 
                 mysqli_query($conn,"INSERT INTO  admission_fee (EmployeeId, admission_fees, date) 
		 VALUES ('$cardID','$admission_fee','$date')"); 
                 $dddd = date("Y-m-d");
                    mysqli_query($conn,"INSERT INTO transactions (date, description, credit, debit, balance, EmployeeId) 
                                    VALUES ('$dddd', 'ST Admission', '$admission_fee', '0', '$admission_fee', '$cardID')");
		 
				echo '<script>alert("success Admission")</script>';
				header("Location: student.php?cl=$class");
		
	        }if (isset($_POST['teacher']))
                    {	   	
                $EmployeeName= mysqli_real_escape_string($conn,$_POST['EmployeeName']);					
                $father= mysqli_real_escape_string($conn,$_POST['father']);
                $mother= mysqli_real_escape_string($conn,$_POST['mother']);
                $edu= mysqli_real_escape_string($conn,$_POST['edu']);
                $mobile= mysqli_real_escape_string($conn,$_POST['mobile']);
                $sub= mysqli_real_escape_string($conn,$_POST['sub']);
                $salary= mysqli_real_escape_string($conn,$_POST['salary']);
         
                $address= mysqli_real_escape_string($conn,$_POST['address']);
                $designation = $_POST['designation'];
                $gender = $_POST['gender'];
                //$date= date('d-m-Y');
					
		 mysqli_query($conn,"INSERT INTO  employee_details (EmployeeName,designation,father,mother,edu,mobile,sub,full_salary,address,gender,date_in) 
		 VALUES ('$EmployeeName','$designation','$father','$mother','$edu','$mobile',' $sub','$salary','$address','$gender','$date')"); 
		 
				echo '<script>alert("success Admission")</script>';
				header("Location: teacher.php?cl==22");
        }if (isset($_POST['classadd']))
                {
                $class= mysqli_real_escape_string($conn,$_POST['classname']);					
                $class_id= mysqli_real_escape_string($conn,$_POST['class_id']);
                $fees= mysqli_real_escape_string($conn,$_POST['fees']);
                
                mysqli_query($conn,"INSERT INTO  class (classname,class_id,fees) 
		 VALUES ('$class','$class_id','$fees')"); 
		 
				echo '<script>alert("success Add Class")</script>';
				header("Location: student.php");
                
                }if (isset($_POST['fees']))
                {
                $EmployeeId= mysqli_real_escape_string($conn,$_POST['EmployeeId']);					
                $amount= mysqli_real_escape_string($conn,$_POST['amount']);
                $invoice= time();
                
                $date= $_POST['dt'];
                
                $month= date('m-Y');
                $payment_type = '2'; //student fees collect id
                $payment_type2 = '3'; //student exam  collect id
                
                $cardID= mysqli_real_escape_string($conn,$_POST['cardID']);
                
                $examfees = mysqli_real_escape_string($conn,$_POST['examfees']);
                $v=100;
                
                mysqli_query($conn,"INSERT INTO  payments (EmployeeId,amount,month,payment_type,invoice,date) 
		 VALUES ('$EmployeeId','$amount','$month','$payment_type','$invoice','$date')"); 
                $dddd = date("Y-m-d");
                mysqli_query($conn,"INSERT INTO transactions (date, description, credit, debit, balance, EmployeeId) 
                                    VALUES ('$dddd', 'student Fees', '$amount', '0', '$amount', '$cardID')");
		 
                if ($v > $examfees ){
                                echo '<script>alert("success Add Class")</script>';
				header("Location: fees_pay.php");
                } else {
                    ////////////////////////////////////////
                    //mysqli_query($conn,"UPDATE owners SET id ='$id', lname ='$lname',
                    //fname ='$fname',mi='$mi',service_des='$service_des',unit_des='$unit_des', address='$address', contact='$contact',unit_ret='$unit_ret' WHERE id = '$owner_id'");
                            $exam = $conn->query("SELECT * FROM admission_fee where EmployeeId='$cardID'");
                                while($rowx=$exam ->fetch_assoc()):
                                $exam_one = $rowx['exam_one'];$exam_two = $rowx['exam_two'];$exam_three = $rowx['exam_three']; 

                              if(empty($exam_one)){
                                        
                                  mysqli_query($conn,"UPDATE admission_fee SET exam_one ='$examfees' WHERE EmployeeId = '$cardID'");
                                  mysqli_query($conn,"INSERT INTO exam_pay (EmployeeId,exam_fees,date) 
                                    VALUES ('$cardID','$examfees','$date')"); 
                                  
                                  header("Location: fees_pay.php");
                                    } else {
                                        if(empty($exam_two)){
                                            
                                            mysqli_query($conn,"UPDATE admission_fee SET exam_two ='$examfees' WHERE EmployeeId = '$cardID'");
                                            mysqli_query($conn,"INSERT INTO exam_pay (EmployeeId,exam_fees,date) 
                                            VALUES ('$cardID','$examfees','$date')");    
                                        echo '<script>alert("success Add Class")</script>';   
                                        header("Location: fees_pay.php");
                                        } else {
                                            
                                            mysqli_query($conn,"UPDATE admission_fee SET exam_three ='$examfees' WHERE EmployeeId = '$cardID'");
                                            mysqli_query($conn,"INSERT INTO exam_pay (EmployeeId,exam_fees,date) 
                                            VALUES ('$cardID','$examfees','$date')");    
                                            echo '<script>alert("success Add Class")</script>';   
                                            header("Location: fees_pay.php");
                                        }
                                    }
                               endwhile;
                               
                    
                    //header("Location: https://www.google.com/");
                    
                    /////////////////////////////////////////
				
                }
				
                
                }
	
?>