<?php
require_once("dbconnection.php");
session_start();


?>


<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="keywords" content="admin, dashboard">	
	<meta name="robots" content="index, follow">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- PAGE TITLE HERE -->
	<title>پرداخت فیس</title>
	<!-- FAVICONS ICON -->
	<link rel="shortcut icon" type="image/png" href="images/favicon.png">
	
	<link href="vendor/jquery-nice-select/css/nice-select.css" rel="stylesheet">
	<link rel="stylesheet" href="vendor/nouislider/nouislider.min.css">
	<!-- Style css -->
    <link href="css/style.css" rel="stylesheet">
    <link href="vendor/sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">
		<link href="vendor/jquery-nice-select/css/nice-select.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link rel="stylesheet" href="dist/sweetalert.css"> 
    
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
     <script>
  document.addEventListener("keydown", function(event) {
    if (event.key === "Escape") {
      // Use a short delay to ensure smooth behavior
      setTimeout(() => {
        window.history.back();
      }, 100);
    }
  });
</script>
</head>
<body>

    <!--*******************
        Preloader start
    ********************-->
    <div id="preloader">
        <div class="waviy">
        <span style="--i:1">N</span>
		   <span style="--i:2">A</span>
		   <span style="--i:3">I</span>
		   <span style="--i:4">M</span>
		   <span style="--i:5">-</span>
		   <span style="--i:5">A</span>
		   <span style="--i:5">R</span>
		   <span style="--i:6">I</span>
           <span style="--i:6">A</span>
		   <span style="--i:7">-</span>
           <span style="--i:8">E</span>
		   <span style="--i:9">D</span>
           <span style="--i:10">U</span>
		</div>
    </div>
    <!--*******************
        Preloader end
    ********************-->

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

        <!--**********************************
            Nav header start
        ***********************************-->
        <div class="nav-header">
            <a href="index.html" class="brand-logo">
            <img src="images/logo1.png" alt="" height="70" width="70">
            </a>
            <div class="nav-control">
                <div class="hamburger">
                    <span class="line"></span><span class="line"></span><span class="line"></span>
                </div>
            </div>
        </div>
        <!--**********************************
            Nav header end
        ***********************************-->
		
		<!--**********************************
            Header start
        ***********************************-->
        <div class="header">
            <div class="header-content">
                <nav class="navbar navbar-expand">
                    <div class="collapse navbar-collapse justify-content-between">
                        <div class="header-left">
							<div class="dashboard_bar">
                 پرداخت فیس
                            </div>
                        </div>
       
                    </div>
				</nav>
			</div>
		</div>
        <!--**********************************
            Header end ti-comment-alt
        ***********************************-->

        <!--**********************************
            Sidebar start
        ***********************************-->
        		<div class="dlabnav">
            <div class="dlabnav-scroll">
				<ul class="metismenu" id="menu">
					<li class="dropdown header-profile">
						<a class="nav-link" href="javascript:void(0);" role="button" data-bs-toggle="dropdown">
							<img src="images/profile/profile.png" width="20" alt="">
							<div class="header-info ms-3">
								<span class="font-w600 "><?php echo $_SESSION['emp_name']; ?></span>
								<small class="text-end font-w400"><?php echo $_SESSION['emp_email']; ?></small>
							</div>
						</a>
						<div class="dropdown-menu dropdown-menu-end">
							<a href="app-profile.php" class="dropdown-item ai-icon">
								<svg id="icon-user1" xmlns="http://www.w3.org/2000/svg" class="text-primary" width="18" height="18" viewbox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
								<span class="ms-2">پروفایل</span>
							</a>
							<a href="logout.php" class="dropdown-item ai-icon">
								<svg id="icon-logout" xmlns="http://www.w3.org/2000/svg" class="text-danger" width="18" height="18" viewbox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg>
								<span class="ms-2">خروج از سیتم </span>
							</a>
						</div>
					</li>
              
					<li><a class="ai-icon" href="index.php" aria-expanded="false" style='font-size:20px;font-weight: bold;'>
						<i class="flaticon-025-dashboard"></i>
						<span class="nav-text">صفحه اصلی</span>
					</a>
				
				</li>
                 	</li>
                    <li><a class="has-arrow ai-icon" href="javascript:void()" aria-expanded="false" style='font-size:20px;font-weight: bold;'>
						<i class="icon-user"></i>
							<span class="nav-text">لیست محصلین</span>
							
						</a>
                        <ul aria-expanded="false">
                            <li><a href="add_student.php" style='font-size:20px;font-weight: bold;'>اضافه محصل</a></li>
							<li><a href="view_student.php" style='font-size:20px;font-weight: bold;'>مشاهده محصل</a></li>
							<li><a href="view_all_student.php" style='font-size:20px;font-weight: bold;'>مشاهده محصلین</a></li>
							
                        </ul>
                    </li>
                  

  
                    <li><a class="has-arrow ai-icon" href="javascript:void()" aria-expanded="false">
							<i class="fa fa-book"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>بخش صنف</span>
						</a>
                        <ul aria-expanded="false">
							<li><a href="add_course.php" style='font-size:20px;font-weight: bold;'>اضافه صنف جدید </a></li>
							<li><a href="view_course.php" style='font-size:20px;font-weight: bold;'>مشاهده صنوف</a></li>

                        </ul>
                    </li>
					<li><a  class="has-arrow ai-icon" aria-expanded="false">
							<i class="fa fa-file-invoice-dollar"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>بخش پول صیف</span>
						</a>
					<ul aria-expanded="false">
                            
                            <li><a href="view_cash_point_details.php" style='font-size:20px;font-weight: bold;'>راپور صیف</a></li>
                            <li><a href="add_view_expenses.php" style='font-size:20px;font-weight: bold;'>اضافه و مشاهده مصارف</a></li>


							
							
                        </ul>
					</li>

					<li><a  class="has-arrow ai-icon" aria-expanded="false">
							<i class="fa fa-calendar"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>مشاهده راپور ها</span>
						</a>
	<ul aria-expanded="false">
                            
                            <li><a href="cash_point_report.php" style='font-size:20px;font-weight: bold;'>راپور صیف</a></li>
							<li><a href="student_report.php" style='font-size:20px;font-weight: bold;'>راپور محصلین</a></li>

							
                        </ul>
					</li>

                </ul>
			<div class="copyright">
					<p><strong>Student MIS Admin Dashboard</strong> © 2025 All Rights Reserved</p>
					<p class="fs-12">Made with <span class="heart"></span> by Dynamic & Cryptic</p>
				</div>
			</div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->


		
		<!--**********************************
            Content body start
        ***********************************-->
		<div class="content-body">
            <div class="container-fluid">
				<div class="row page-titles">
					<ol class="breadcrumb">
						<li class="breadcrumb-item active"><a href="javascript:void(0)">صفحه</a></li>
						<li class="breadcrumb-item"><a href="javascript:void(0)">پرداخت فیس</a></li>
					</ol>
                </div>
				
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                          
                            <div class="card-body">
                               
							<div class="basic-form">
                                           <form id="form1" name="form1" method="post" class="needs-validation" novalidate="" dir="rtl">
                                      
                                    <div class="row">
                                            <div class="col-xl-6">
                                            
                                                
                                            
												
                                                <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom06" style="font-size:20px;">انتخاب صنف
                                                        <span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                    <?php
                                                    $sql1 = "SELECT * FROM course_type";
                                                    $res1 = mysqli_query($con,$sql1);
                                                    ?>
                                                        <select class="form-control" id="course_s" name="course_s">
                                                            <option>انتخاب کنید</option>
                                                            <?php
                                    while($row = mysqli_fetch_array($res1))
                                    {
                                    ?>
                                <option value="<?php echo $row['c_id'];?>" myTag="<?php echo $row['c_name'];?>"><?php echo $row['c_name']?></option>
                                    <?php
                                    }
                                    ?>
                                                        </select>
                                                        <input type="hidden" name="course_type" id="course_type">
                                                        <input type="hidden" name="course_name" id="course_name">
														
                                                    </div>
                                                </div>

                                                  <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom06" style="font-size:20px;">انتخاب مدرس
                                                        <span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                    <?php
                                                    $sql1 = "SELECT * FROM teacher";
                                                    $res1 = mysqli_query($con,$sql1);
                                                    ?>
                                                        <select class="form-control" id="teacher" name="teacher">
                                                            <option>انتخاب کنید</option>
                                                            <?php
                                    while($row = mysqli_fetch_array($res1))
                                    {
                                    ?>
                                <option value="<?php echo $row['t_id'];?>" myTag="<?php echo $row['t_name'];?>"><?php echo $row['t_name']?></option>
                                    <?php
                                    }
                                    ?>
                                                        </select>
                                                        <input type="hidden" name="t_name" id="t_name">
                                                        
														
                                                    </div>
                                                </div>

                                                <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:20px;">زمان صنف<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                        <input style='font-size:20px;' type="text" style="font-size:20px;" class="form-control" id="class_time" name="class_time" placeholder="" required="">
														
                                                    </div>
                                                </div>
                                               

                                                 <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:20px;">مبلغ فیس<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                        <input style='font-size:20px;' type="text" style="font-size:20px;" class="form-control" id="main_amount" name="main_amount" placeholder="" required="">
														
                                                    </div>
                                                </div>
                                                 <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:20px;">تخفیف<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                        <input style='font-size:20px;' type="text" style="font-size:20px;" class="form-control" id="discount" name="discount" placeholder="" required="">
														
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-xl-6">

                                            <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:18px;">مبلغ فیس بعد از تخفیف<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                                <input type="text" name="amount" id="amount"  class="form-control" placeholder="" style="font-size:25px;" readonly="readonly">
                                                    </div>
                                                </div>
                                                
                                                    
                                                <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:18px;">مبلغ پرداخت<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                                <input type="text" name="receive_amount" id="receive_amount"  class="form-control" placeholder="" style="font-size:25px;">
                                                    </div>
                                                </div>

                                                  <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:18px;">مبلغ باقی<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                                <input type="text" name="borrow_amount" id="borrow_amount"  class="form-control" placeholder="" style="font-size:25px;" readonly="readonly">
                                                    </div>
                                                </div>

                                                <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:18px;">تاریخ ختم ثبت نام<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                                   <input type="date" name="end_date" id="end_date"  class="form-control" placeholder="" style="font-size:20px;">
                                                    </div>
                                                </div>


                                                  <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom07" style="font-size:18px;">حالت پرداخت<span class="text-danger">*</span>
                                                    </label>
                                                    <div class="col-lg-6">
                                                                   <select name="payment_status" id="payment_status" class="form-control"> 
                                                <option value="">انتخاب کنید</option>
                                                <option value="درجریان">درجریان</option>
                                                <option value="تکمیل">تکمیل</option>
                                               </select>
                                               <input type="hidden" name="p_status" id="p_status">
                                                    </div>
                                                </div>
     <input type="hidden" class="form-control" id="bill_no" name="bill_no" readonly="readonly">
                                                        <script>
    
                                                        let now = Math.floor(Math.random()* 1000000000);
                                                        document.getElementById("bill_no").value = now;

                                                        </script>

                                                              <input type="hidden" class="form-control" id="cash_id" name="cash_id" readonly="readonly">
                                                        <script>
    
                                                        let cp = Math.floor(Math.random()* 1000000);
                                                        document.getElementById("cash_id").value = cp;

                                                        </script>
                                        <div class="col-lg-12">
                               <input type="hidden" style='font-size:20px;' name="date" id="date" class="form-control" value=" <?php
                                                    date_default_timezone_set('Asia/Kabul'); 
                                                        $now = new DateTime();
                                                        echo $now->format('Y-m-d');    // MySQL datetime format
                                                    
                                                        ?>" required="">
                    </div>
                                                    <button style="font-size:10px;" type="button" class="btn btn-rounded btn-warning" name="send" id="butsend"><span class="btn-icon-start text-info"><i class="fa fa-plus color-info"></i>
                                                        </span >اضافه به لیست</button>

                                            </div>
                                  
                                     <input type="hidden" id="student_id" name="student_id" value="<?php echo $_GET['id']; ?>">  
                                        <div class="col-lg-9">
                            <div class="card-body">
                                <div class="">
                                    <table class="table header-border table-responsive-sm" id="table1" name="table1">
                                        <thead >  
                                            <tr style="color:black;">
                                              
                                                <th style='font-size:15px;'>نمبر</th>
                                                <th style='font-size:15px;'>صنف</th>
                                                <th style='font-size:15px;'>مدرس</th>
                                                <th style='font-size:15px;'>زمان صنف</th>
                                                <th style='font-size:15px;'>مبلغ فیس</th>
                                                <th style='font-size:15px;'>تخفیف</th>
                                                <th style='font-size:15px;'>مبلغ بعد از تخفیف</th>
                                                <th style='font-size:15px;'> پرداخت</th>
                                                <th style='font-size:15px;'>باقی</th>
                                                <th style='font-size:15px;'>تاریخ ختم</th>
                                                <th style='font-size:15px;'>حالت</th>
                                                <th style='font-size:15px;'>حذف</th>


                                            </tr>
                                        </thead>
                                    <tbody>
                                    </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <br>
                    
                                            <div class="col-xl-4">
                                         
                                         
                                               <div class="mb-3 row">
                                                    <label class="col-lg-4 col-form-label" for="validationCustom03">
                                                        
                                                    </label>
                                                    <div class="col-lg-8">
                                                    <input type="button" value="ثبت سیستم" class="btn btn-primary btn sweet-success" name="save" id="butsave"></input>
														
                                                    </div>
                                                </div>
                                            </div>
                
                        
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
			
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->
		
        <!--**********************************
            Footer start
        ***********************************-->
    <div class="footer">
		
            <div class="copyright">

            </div>
        </div>
        <!--**********************************
            Footer end
        ***********************************-->

		


	</div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="vendor/global/global.min.js"></script>
	<script src="vendor/chart.js/Chart.bundle.min.js"></script>
	<script src="vendor/jquery-nice-select/js/jquery.nice-select.min.js"></script>
	
	
	
	<!-- Dashboard 1 -->
	<script src="js/dashboard/dashboard-1.js"></script>
    <script src="js/custom.min.js"></script>
	<script src="js/dlabnav-init.js"></script>
	<script src="js/demo.js"></script>
    <script src="js/styleSwitcher.js"></script>
    <!--Sweet Alert--->
    <script src="vendor/sweetalert2/dist/sweetalert2.min.js"></script>
    <script src="js/plugins-init/sweetalert.init.js"></script>
    <script src="dist/sweetalert.min.js"></script>
	<script src="vendor/jquery-nice-select/js/jquery.nice-select.min.js"></script>
 
	
</body>
</html>
    <script>



$(document).ready(function() {
   

        
        var course_type1 = new Array(); 
        var course_name1 = new Array(); 
        var t_name1 = new Array(); 
        var class_time1 = new Array(); 
        var main_amount1 = new Array(); 
        var discount1 = new Array(); 
        var amount1 = new Array(); 
        var receive_amount1 = new Array(); 
        var borrow_amount1 = new Array(); 
        var end_date1 = new Array(); 
        var p_status1 = new Array(); 

        


        
    
    var id = 1;  
    
    /* Assigning id and class for tr and td tags for separation. */

    $("#butsend").click(function() {
       
        var course_type=document.form1.course_type.value;
        var t_name=document.form1.t_name.value;
        var class_time=document.form1.class_time.value;
       var main_amount=document.form1.main_amount.value;
       var discount=document.form1.discount.value;
       var amount=document.form1.amount.value;
       var receive_amount=document.form1.receive_amount.value;
       var end_date=document.form1.end_date.value;
       var p_status=document.form1.p_status.value;
        

          if(course_type == null || course_type == "" ){
      sweetAlert("اخطاریه","انتخاب صنف لازمی میباشد","warning");  
      return false;  
      } else 
        if(t_name == null || t_name == ""){
        sweetAlert("اخطاریه","انتخاب مدرس لازمی میباشد","warning");  
        return false;  
      }else 
        if(class_time == null || class_time == ""){
        sweetAlert("اخطاریه","زمان صنف لازمی میباشد","warning");  
        return false;  
      }
        else 
        if(main_amount == null || main_amount == ""){
        sweetAlert("اخطاریه","مبلغ فیس لازمی میباشد","warning");  
        return false;  
      }
      else 
        if(discount == null || discount == ""){
        sweetAlert("اخطاریه","مبلغ تخفیف لازمی میباشد","warning");  
        return false;  
      }
      else 
        if(receive_amount == null || receive_amount == ""){
        sweetAlert("اخطاریه","مبلغ رسید لازمی میباشد","warning");  
        return false;  
      }
    else 
        if(end_date == null || end_date == ""){
        sweetAlert("اخطاریه","انتخاب تاریخ ختم ثبت نام لازمی میباشد","warning");  
        return false;  
      }
      else 
        if(p_status == null || p_status == ""){
        sweetAlert("اخطاریه","انتخاب حالت پرداخت لازمی میباشد","warning");  
        return false;  
      }

    
            course_type1.push({
                course_type,
                id
            })
            course_name1.push({
                course_name,
                id
            })
            t_name1.push({
                t_name,
                id
            })
            class_time1.push({
                class_time,
                id
            })
            main_amount1.push({
                main_amount,
                id
            })
            discount1.push({
                discount,
                id
            })
            amount1.push({
                amount,
                id
            })
            receive_amount1.push({
                receive_amount,
                id
            })
            borrow_amount1.push({
                borrow_amount,
                id
            })
            end_date1.push({
                end_date,
                id
            })
            p_status1.push({
                p_status,
                id
            })

            
        var newid = id++;  
        

        $("#table1").append('<tr valign="top" id="'+newid+'">\n\
        <td width="100px" class="">' + newid + '</td>\n\
            <td style="font-size:20px;display:none;" width="10px" class="course_type'+newid+'">' + $("#course_type").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="course_name'+newid+'">' + $("#course_name").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="t_name'+newid+'">' + $("#t_name").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="class_time'+newid+'">' + $("#class_time").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="main_amount'+newid+'">' + $("#main_amount").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="discount'+newid+'">' + $("#discount").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="amount'+newid+'">' + $("#amount").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="receive_amount'+newid+'">' + $("#receive_amount").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="borrow_amount'+newid+'">' + $("#borrow_amount").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="end_date'+newid+'">' + $("#end_date").val() + '</td>\n\
            <td style="font-size:20px;" width="10px" class="p_status'+newid+'">' + $("#p_status").val() + '</td>\n\
            <td style="font-size:20px;" width="10px"><a href="javascript:void(0);" class="remCF btn btn-danger shadow btn-xs sharp"><i class="fa fa-trash"></i></a></td>\n\
        </tr>');

    
    
    
        $('#course_type').val('');
        $('#course_name').val('');
        $('#t_name').val('');
        $('#class_time').val('');
        $('#main_amount').val('');
        $('#discount').val('');
        $('#amount').val('');
        $('#receive_amount').val('');
        $('#borrow_amount').val('');
        $('#end_date').val('');
        //$('#p_status').val('');

        
      

        
         

    });
    
    

    var serializedData = $('#form1').serialize();

    $.ajax({
        url: "insert_payments.php", 
        type: "post",
        data: serializedData
    });


     


    $("#table1").on('click', '.remCF', function() {
        
        let id =parseInt(this.parentNode.parentNode.id)

        
        course_type1=course_type1.filter((v)=>{
            return v.id !=id;
        })
        course_name1=course_name1.filter((v)=>{
            return v.id !=id;
        })
        t_name1=t_name1.filter((v)=>{
            return v.id !=id;
        })
        class_time1=class_time1.filter((v)=>{
            return v.id !=id;
        })
        main_amount1=main_amount1.filter((v)=>{
            return v.id !=id;
        })
        discount1=discount1.filter((v)=>{
            return v.id !=id;
        })
        amount1=amount1.filter((v)=>{
            return v.id !=id;
        })
        receive_amount1=receive_amount1.filter((v)=>{
            return v.id !=id;
        })
        borrow_amount1=borrow_amount1.filter((v)=>{
            return v.id !=id;
        })
        end_date1=end_date1.filter((v)=>{
            return v.id !=id;
        })
        p_status1=p_status1.filter((v)=>{
            return v.id !=id;
        })

        
        $(this).parent().parent().remove();
        
        
    });

   

    var isSubmitting = false;

$("#butsave").click(function () {
    if (isSubmitting) return;
    isSubmitting = true;
    var $btn = $(this);
    $btn.prop("disabled", true);
        
        
      
        var lastRowId = $('#table1 tr:last').attr("id"); /* finds id of the last row inside table */
        
        var course_type1_send = new Array();
        var t_name1_send = new Array();
        var class_time1_send = new Array();
        var main_amount1_send = new Array();
        var discount1_send = new Array();
        var amount1_send = new Array();
        var receive_amount1_send = new Array();
        var borrow_amount1_send = new Array();
        var end_date1_send = new Array();
        var p_status1_send = new Array();

        
        for ( var i = 1; i <= lastRowId; i++) {
            course_type1_send.push($("#"+i+" .course_type"+i).html());
            t_name1_send.push($("#"+i+" .t_name"+i).html());
            class_time1_send.push($("#"+i+" .class_time"+i).html());
            main_amount1_send.push($("#"+i+" .main_amount"+i).html());
            discount1_send.push($("#"+i+" .discount"+i).html());
            amount1_send.push($("#"+i+" .amount"+i).html());
            receive_amount1_send.push($("#"+i+" .receive_amount"+i).html());
            borrow_amount1_send.push($("#"+i+" .borrow_amount"+i).html());
            end_date1_send.push($("#"+i+" .end_date"+i).html());
            p_status1_send.push($("#"+i+" .p_status"+i).html());   
        }

      
        var sendcourse_type = JSON.stringify(course_type1_send);
        var sendt_name = JSON.stringify(t_name1_send);
        var sendclass_time = JSON.stringify(class_time1_send);
        var sendmain_amount = JSON.stringify(main_amount1_send);
        var senddiscount = JSON.stringify(discount1_send);
        var sendamount = JSON.stringify(amount1_send);
        var sendreceive_amount = JSON.stringify(receive_amount1_send);
        var sendborrow_amount = JSON.stringify(borrow_amount1_send);
        var sendend_date = JSON.stringify(end_date1_send);
        var sendp_status = JSON.stringify(p_status1_send);
        var senddate = document.getElementById('date').value;
        var sendbill_no= document.getElementById('bill_no').value;
        var sendcash_id = document.getElementById('cash_id').value;
        var std_id = document.getElementById('student_id').value;

        
            if(course_type1_send == null || course_type1_send==""){
            sweetAlert("Warining","لیست خالی میباشد","error");  
            return false;  
            } else {
    

        $.ajax({
            url: "insert_payments.php",
            type: "post", 
            data: {
                course_type : sendcourse_type,
                t_name : sendt_name,
                class_time : sendclass_time,
                main_amount : sendmain_amount,
                discount : senddiscount,
                amount : sendamount,
                receive_amount : sendreceive_amount,
                borrow_amount : sendborrow_amount,
                end_date : sendend_date,
                p_status : sendp_status,
                date : senddate,
                bill_no : sendbill_no,
                cash_id : sendcash_id,
                student_id : std_id
            },
          success: function(data) {
                //    alert(data?'success':'failed');
              //console.log(data);
                    
              swal("معلومات شما موفقانه ثبت سیستم شد","","success")
                window.setTimeout(function(){ 
                    window.location = "print2.php?student_id="+std_id+"&bill_no="+sendbill_no;
            } ,1500);
           
                }
              
        }); 
        
    }
    }); 
});

 


$("#course_s").on('change',function(){
    var getValue=$(this).val();
    $("#course_type").val(getValue);
    var optionSelected = $("option:selected", this);
    item = optionSelected.attr("myTag");
    $("#course_name").val(item);

  });
       
$("#payment_status").on('change',function(){
    var getValue=$(this).val();
    $("#p_status").val(getValue);
  });

    $("#teacher").on('change',function(){
    var getValue=$(this).val();
    $("#t_name").val(getValue);
  });




        $(function () {
$("#amount,#receive_amount,#borrow_amount,#main_amount,#discount").keyup(function () {
    
    var main_amount = parseFloat($("#main_amount").val());
    var discount = parseFloat($("#discount").val());

    var result1 = main_amount - discount;
    $("#amount").val(result1);

    var amount = parseFloat($("#amount").val());
    var receive_amount = parseFloat($("#receive_amount").val());
    

    var result = amount - receive_amount;
    $("#borrow_amount").val(result);

    
    

 });
});


  

  
</script>