<?php
$values = $_GET['branch'];
  include 'connection.php';
  
  //address
if(isset($_POST['update']))
{
   $id = isset($_POST['address_sno'])?$_POST['address_sno']:null;
    $no = isset($_POST['no'])?$_POST['no']:null;
  $location = isset($_POST['location'])?$_POST['location']:null;
    $landmark = isset($_POST['landmark'])?$_POST['landmark']:null;
    $country =  isset($_POST['country'])?$_POST['country']:null;
     $category = isset($_POST['category'])?$_POST['category']:null;
    $short = isset($_POST['short'])?$_POST['short']:null;
    $duration = isset($_POST['duration'])?$_POST['duration']:null;
    $email = isset($_POST['email'])?$_POST['email']:null;
    $branch = isset($_POST['branch'])?$_POST['branch']:null;
    $loca = isset($_POST['loca'])?$_POST['loca']:null;
    $code = isset($_POST['code'])?$_POST['code']:null;
    $grade = isset($_POST['grade'])?$_POST['grade']:null;
    $img = isset($_POST['img'])?$_POST['img']:null;
    $center = isset($_POST['center'])?$_POST['center']:null;
    $admission = isset($_POST['admission'])?$_POST['admission']:null;
    $paid = isset($_POST['paidfees'])?$_POST['paidfees']:null;
    $due = isset($_POST['duefees'])?$_POST['duefees']:null;
    $branchname = isset($_POST['branchname'])?$_POST['branchname']:null;

  $result = mysqli_query($sql_con,"UPDATE `print_fees` SET `RollNo`='$no',`Name`='$location',`Address`='$landmark',`CourseName`='$country', `BatchTiming`='$category', `AdmissionFees`='$short', `TuitionFees`='$duration', `Latefees`='$email', `LibraryFees`='$branch', `StudyMaterial`='$loca', `OtherCharges`='$code', `DepositDate`='$grade', `Fees`='$img', `Word`='$center', `AdmissionDate`='$admission', `PaidFees`='$paid',`BranchName`='$branchname',`DueFees`='$due' WHERE Sno ='$id'");
}

if(isset($_POST['delete']))
{
  //$sql_con=mysqli_connect('localhost','root','','hospital_management_website');

$id = isset($_POST['address_sno'])?$_POST['address_sno']:null;
$result1 = mysqli_query($sql_con,"DELETE FROM `print_fees` WHERE Sno='$id'");
}
  
?>

  <?php 
                $due = mysqli_query($sql_con, "SELECT sum(BalanceFees) as dues2 From print_fees");
                while($row4 = mysqli_fetch_array($due))
                {
                    $due6 = $row4["dues2"];
                }

                $due = mysqli_query($sql_con, "SELECT sum(BalanceFees) as dates FROM `print_fees` where MONTH(BalanceFees)=MONTH(now()) and YEAR(BalanceFees)=YEAR(now()) and BranchName='Ashram'");
                while($row4 = mysqli_fetch_array($due))
                {
                    $dates = $row4["dates"];
                }

                $due = mysqli_query($sql_con, "SELECT sum(BalanceFees) as dates FROM `print_fees` where MONTH(BalanceFees)=MONTH(now()) and YEAR(BalanceFees)=YEAR(now()) and BranchName='Govindpuri'");
                while($row4 = mysqli_fetch_array($due))
                {
                    $dates2 = $row4["dates"];
                }
                ?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Modi Training Institute</title>

    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">

    <!-- Styles -->
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/data-table/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/helper.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">

     <script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>

</head>

<body>

        <div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
            <div class="nano">
                <div class="nano-content">
<div class="logo"><a href="address.php?BranchName=<?php echo $values; ?>"><!-- <img src="assets/images/logo.png" alt="" /> --><span>Modi Traning Institute</span></a></div>
                   <ul>
                        <li class="label">Main</li>
                        <li><a class="sidebar-sub-toggle"><i class="ti-layout"></i>Website Master <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                               <li><a href="online-exam-course.php?branch=<?php echo $values; ?>">Online Exam Course Master</a></li>
                         <li><a href="contact.php?branch=<?php echo $values; ?>">Contact Form</a></li>
                          <li><a href="demo.php?branch=<?php echo $values; ?>">Demo Form</a></li>
                          <li><a href="register.php?branch=<?php echo $values; ?>">REG by Website</a></li>
                          <li><a href="enquiry.php?branch=<?php echo $values; ?>">Enquiry Form</a></li>
                         <li><a href="idcard.php?branch=<?php echo $values; ?>">Student Id Card Master</a></li>
                        <li><a href="address.php?BranchName=<?php echo $values; ?>">Address Master</a></li>
                        <li><a href="link.php?branch=<?php echo $values; ?>"> Link Master</a></li>
                        <li><a href="testimonial.php?branch=<?php echo $values; ?>">Testimonial Master</a></li>
                        <li><a href="team.php?branch=<?php echo $values; ?>">Team Master</a></li>
                         <li><a href="gallery.php?branch=<?php echo $values; ?>">Gallery Master</a></li>
                        <li><a href="blog.php?branch=<?php echo $values; ?>">Blog Master</a></li>
                        <li><a href="event.php?branch=<?php echo $values; ?>">Event Master</a></li>
                        <li><a href="course.php?branch=<?php echo $values; ?>">Course Master</a></li>
                        <li><a href="course-content.php?branch=<?php echo $values; ?>">Course Content Master</a></li>
                        <li><a href="batch.php?branch=<?php echo $values; ?>">Batch Master</a></li>
                        <li><a href="course-description.php?branch=<?php echo $values; ?>">Course Description Master</a></li>
                        <li><a href="offer.php?branch=<?php echo $values; ?>">Offer Master</a></li>
                        <li><a href="afflication.php?branch=<?php echo $values; ?>">Afflication Master</a></li>
                        <li><a href="placement.php?branch=<?php echo $values; ?>">Placement Master</a></li>
                            </ul>
                        </li>
                        <li><a class="sidebar-sub-toggle"><i class="ti-layout"></i>Admission Master <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="personal.php?branch=<?php echo $values; ?>">Personal Info</a></li>
                                <li><a href="bank.php?branch=<?php echo $values; ?>">Bank Detail</a></li>
                                
                                <li><a href="course-admin.php?branch=<?php echo $values; ?>">Course Detail</a></li>
                                <li><a href="fee.php?branch=<?php echo $values; ?>">Fees Detail</a></li>
                            </ul>
                        </li>
                        <li><a class="sidebar-sub-toggle"><i class="ti-panel"></i>Inquiry <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="inquiry.php?branch=<?php echo $values; ?>">Inquiry Form</a></li>
                                <li><a href="inquiry-report.php?branch=<?php echo $values; ?>">All Inquiry Report</a></li>
                                <li><a href="converted.php?branch=<?php echo $values; ?>">Converted</a></li>
                                <li><a href="not-converted.php?branch=<?php echo $values; ?>">Not Converted</a></li>
                            </ul>
                        </li>
                        <li><a class="sidebar-sub-toggle"><i class="ti-layout-grid4-alt"></i>Fees Master <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="create-fee.php?branch=<?php echo $values; ?>">Fees Form</a></li>
                               
                                <li><a href="print-fees.php?branch=<?php echo $values; ?>">All Fees Detail</a></li>
                                <li><a href="due-fees.php?branch=<?php echo $values; ?>">Due Fees Detail</a></li>
                            </ul>
                        </li>
                        <li><a class="sidebar-sub-toggle"><i class="ti-heart"></i>Document Master <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="document.php?branch=<?php echo $values; ?>">Document</a></li>
                                <li><a href="certificate.php?branch=<?php echo $values; ?>">Certificate</a></li>
                                <li><a href="document-records.php?branch=<?php echo $values; ?>">All Document Records</a></li>
                                <li><a href="Certificate-record.php?branch=<?php echo $values; ?>">All Certificate Records</a></li>
                            </ul>
                        </li>
                         <li><a class="sidebar-sub-toggle"><i class="ti-heart"></i>Certificate Master <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="create-certificate.php?branch=<?php echo $values; ?>">Certificate Create</a></li>
                                <li><a href="print-certificate.php?branch=<?php echo $values; ?>">All Certificate Records</a></li>
                            </ul>
                        </li>
                        <li><a href="../HRMS/HRMS/security.php?branch=<?php echo $values; ?>" target="_blank"><i class="ti-user"></i> HRMS Login</a></li>
                        <li><a href="../admin-dashboard.php"><i class="ti-close"></i> Logout</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- /# sidebar -->


    <div class="header">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="float-left">
                        <div class="hamburger sidebar-toggle">
                            <span class="line"></span>
                            <span class="line"></span>
                            <span class="line"></span>
                        </div>
                    </div>
                   
            </div>
        </div>
    </div>




    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 p-r-0 title-margin-right">
                        <table class="table table-responsive-lg table-bordered table-active"  style="border: 2px solid black;" align="left">
                           <tr>
                               <td style="color: black; font-weight: bolder; text-align: left; text-transform: uppercase;">Total Due Amount: <?php echo $due6; ?></td>
                               <td style="color: black; font-weight: bolder; text-align: left; text-transform: uppercase;">Ashram Total Due Amount : <?php echo $due6; ?></td>
                               <td style="color: black; font-weight: bolder; text-align: left; text-transform: uppercase;">Govindpuri Total Due Amount: <?php echo $dates2; ?></td>
                           </tr>
                       </table>
                    </div>
                </div>
                <!-- /# row -->
                 <section id="main-content">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                              
                                    <div class="table-responsive">
                                          <form method="post">
                                        <div class="row">
                    <div class="col-md-4">
                        <div class="row">
                            <div class="col-12">
                        <input type="text" name="search1" class="form-control" placeholder="Search Here .....">
                    </div>
                   
                </div>
            </div>
                    <div class="col-md-8">
                     &nbsp;&nbsp;<input type="submit" class="btn btn-info" name="search" value="Search"> 
                     <button onclick="ExportToExcel('xlsx')" class="btn btn-success">Excel File</button>
             <input type="button" value="Create PDF" id="btPrint" onclick="createPDF()" class="btn btn-success" />      
                    </div>
                    
                </div>
                 
            </form>
          
                                    
                                       <div id="tab"  id="bootstrap-data-table-export">
                                    <table class="table table-bordered" id="tblData">
    <thead class="thead-light">
      <tr class="d-flex">
        <th class="col-1" style="color: black;">Sno</th>
        <th class="col-2" style="color: black;">Roll No</th>
        <th class="col-2" style="color: black;">Student Name</th>
        <th class="col-2" style="color: black;">Address</th>
        <th class="col-2" style="color: black;">Course Name</th>
        <th class="col-1" style="color: black;">Branch</th>
        <th class="col-2" style="color: black;">Batch Time</th>
        <th class="col-1" style="color: black;">Adm. Date</th>
        <th class="col-1" style="color: black;">Total Fees</th>
        <th class="col-1" style="color: black;">Paid Fees</th>
        <th class="col-1" style="color: black;">Due Fees</th>
        
      </tr>
    </thead>
    <tbody>
     
         <?php
$search = isset($_POST['search1'])?$_POST['search1']:null;
        if(isset($_POST['search']))
        { 
$result2 = mysqli_query($sql_con,"SELECT any_value(Sno) as Snos, any_value(RollNo) as RollNos, any_value(Name) as Names, any_value(Address) as Addresss, any_value(CourseName) as CourseNames, any_value(BatchTiming) as BatchTimings, any_value(AdmissionDate) as AdmissionDates, any_value(Fees) as Fee, any_value(BranchName) as BranchNames, sum(PaidFees) as paids, sum(BalanceFees) as dues From print_fees where RollNo like '%$search%' or Name like '%$search%' or Address like '%$search%' or CourseName like '%$search%' or BatchTiming like '%$search%' or `AdmissionDate` like '%$search%' or Fees like '%$search%' or PaidFees like '%$search%' or BalanceFees like '%$search%' or BranchName like '%$search%' group by RollNo");
   while($sub1 = mysqli_fetch_array($result2))
{
  $no= $sub1["Snos"];
  $numb = $sub1["RollNos"];
  $location = $sub1["Names"];
  $landmark = $sub1["Addresss"];
  $country = $sub1["CourseNames"];
  $category = $sub1["BatchTimings"];
  $add = $sub1["AdmissionDates"];
 
  $image = $sub1["Fee"];
  $paid = $sub1["paids"];
  $due = $sub1["dues"];
  $name = $sub1["BranchNames"];
  ?>
    <tr class="d-flex">
   <td class="col-1" style="color: black;"><?php echo $no;?></td> 
   <td class="col-2" style="color: black;"><?php echo $numb; ?></td>
    <td class="col-2" style="color: black;"><?php echo $location;?></td>
        <td class="col-2" style="color: black;"><?php echo $landmark;?></td>
        <td class="col-2" style="color: black;"><?php echo $country;?></td>
        <td class="col-1" style="color: black;"><?php echo $name; ?></td>
        <td class="col-2" style="color: black;"><?php echo $category;?></td>
        <td class="col-1" style="color: black;"><?php echo $add;?></td>
        <td class="col-1" style="color: black;"><?php echo $image; ?></td>
        <td class="col-1" style="color: black;"><?php echo $paid; ?></td>
        <td class="col-1" style="color: black;"><?php echo $due; ?></td>
        </tr>
  <?php
}
}
else
{
$result = mysqli_query($sql_con,"SELECT any_value(Sno) as Snos, any_value(RollNo) as RollNos, any_value(Name) as Names, any_value(Address) as Addresss, any_value(CourseName) as CourseNames, any_value(BatchTiming) as BatchTimings, any_value(AdmissionDate) as AdmissionDates, any_value(Fees) as Fee, any_value(BranchName) as BranchNames, sum(PaidFees) as paids, sum(BalanceFees) as dues From print_fees group by RollNo");
while($row = mysqli_fetch_array($result))
{
  $no= $row["Snos"];
  $numb = $row["RollNos"];
  $location = $row["Names"];
  $landmark = $row["Addresss"];
  $country = $row["CourseNames"];
  $category = $row["BatchTimings"];
  $add = $row["AdmissionDates"];
  $image = $row["Fee"];
  $paid = $row["paids"];
  $due = $row["dues"];
  $name = $row["BranchNames"];
  ?>
   <tr class="d-flex">
   <td class="col-1" style="color: black;"><?php echo $no;?></td> 
   <td class="col-2" style="color: black;"><?php echo $numb; ?></td>
    <td class="col-2" style="color: black;"><?php echo $location;?></td>
        <td class="col-2" style="color: black;"><?php echo $landmark;?></td>
        <td class="col-2" style="color: black;"><?php echo $country;?></td>
        <td class="col-1" style="color: black;"><?php echo $name; ?></td>
        <td class="col-2" style="color: black;"><?php echo $category;?></td>
        <td class="col-1" style="color: black;"><?php echo $add;?></td>
        <td class="col-1" style="color: black;"><?php echo $image; ?></td>
        <td class="col-1" style="color: black;"><?php echo $paid; ?></td>
        <td class="col-1" style="color: black;"><?php echo $due; ?></td>
        </tr>
  <?php
}
}
       ?>
        
      
      
    </tbody>
  </table></div>

                                   
                                </div>
                            </div>
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                    </div>
                    <!-- /# row -->

                    <div class="row">
                        <div class="col-lg-6">
                            <div class="footer">
                                <p>All right reserved by- <a href="">Modi Training Institute</a> 
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="footer" style="text-align: right;">
                                <p style="text-align: right;">Managed By- <a href="https://www.kiyanchsolutions.com/" target="_blank">Kiyan Ch Solutions</a> 
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>







    
    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.min.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    
    <!-- bootstrap -->

    <script src="assets/js/lib/bootstrap.min.js"></script><script src="assets/js/scripts.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>

   <script>
    function createPDF() {
        var sTable = document.getElementById('tab').innerHTML;

        var style = "<style>";
        style = style + "table {width: 100%;font: 17px Calibri;}";
        style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
        style = style + "padding: 2px 3px;text-align: center;}";
        style = style + "</style>";

        // CREATE A WINDOW OBJECT.
        var win = window.open('', '', 'height=700,width=700');

        win.document.write('<html><head>');
        win.document.write('<title>Profile</title>');   // <title> FOR PDF HEADER.
        win.document.write(style);          // ADD STYLE INSIDE THE HEAD TAG.
        win.document.write('</head>');
        win.document.write('<body>');
        win.document.write(sTable);         // THE TABLE CONTENTS INSIDE THE BODY TAG.
        win.document.write('</body></html>');

        win.document.close();   // CLOSE THE CURRENT WINDOW.

        win.print();    // PRINT THE CONTENTS.
    }
</script>
    
 <script>

        function ExportToExcel(type, fn, dl) {
            var elt = document.getElementById('tblData');
            var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
            return dl ?
                XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
                XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));
        }

    </script>

<script type="text/javascript">
    function Export2Doc(element, filename = ''){
        var html = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta><title>Export HTML To Doc</title></head><body>";
        var footer = "</body></html>";
        var html = html+document.getElementById(element).innerHTML+footer;
    
        
        //link url
        var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
        
        //file name
        filename = filename?filename+'.doc':'document.doc';
        
        // Creates the  download link element dynamically
        var downloadLink = document.createElement("a");
    
        document.body.appendChild(downloadLink);
        
        //Link to the file
        downloadLink.href = url;
            
        //Setting up file name
        downloadLink.download = filename;
            
        //triggering the function
        downloadLink.click();
        //Remove the a tag after donwload starts.
        document.body.removeChild(downloadLink);
    }
</script>

<script>
  
 $(document).ready(function () {
    $("#tblData").table2excel({
        filename: "Students.xls"
    });
 });
  
</script>

</body>

</html>