<script>
        function PrintElem(elem)
        {
            Popup($(elem).html());
        }

        function Popup(data) 
        {

            var mywindow = window.open('', 'printReport', 'height=500,width=700');
            mywindow.document.write('<html><head><title></title>');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,700"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Roboto:300,400,700"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Romanesco"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css"  media="print">');
            
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/Data-Table.css" media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/Data-Table1.css" media="print">');
            
            mywindow.document.write('</head><body >');
            mywindow.document.write(data);
            mywindow.document.write('</body></html>');

            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10

            mywindow.print();
            mywindow.close();

            return true;
        }
    </script>
<div role="dialog" tabindex="-1" class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <button type="submit" class="print" onclick="PrintElem('#printReport')" style="padding:5px 20px;color:rgb(1,1,1);">
                    <i class="fa fa-print"></i> Print
                </button>
            </div>
            <div id="printReport">
                <div class="modal-body">
                    <div class="row" style="width:100%;color:black;">
                        <div class="col-md-12 text-center" style="text-align:center;width:100%;">
                            <img src="../../../assets/img/logo.png" style="width:100px;" align="center">
                        </div>
                        <div class="col-md-12 text-center" style="text-align:center;width:100%;">
                            <h2 style="font-weight:bold;;">WAKA CMEC FEE STRUCTURE</h2>
                        </div>

                        <div class="col-md-12">
                            <div class="col-md-8" style="width:70%;font-size:14px;">
                                <p><b>Course:</b> <?php echo $cos;?></p>
                            </div>
                            <div class="col-md-4" style="width:30%;font-size:14px;text-align:right;">
                                <p><b>Date:</b> <?php echo date("D d/M/Y, G:i");?></p>
                            </div>
                        </div>
                        <div class="col-md-12" style="width:100%;">
                            <table border="1" style="width:100%;font-size:12px;color:black;">
                                <thead>
                                    <tr>
                                        <th style="text-align:center;">No</th>
                                        <th>Item Description</th>
                                        <?php for($r=1;$r <= $yrs;$r++){ ?>
                                            <th style="text-align:center;">Year <?php echo $r;?></th>
                                        <?php } ?>   
                                        <th>&nbsp;&nbsp;</th>    
                                    </tr>
                                    <tr>
                                        <th>&nbsp;</th>
                                        <th>&nbsp;</th>
                                        <th style="text-align:center;" colspan="<?php echo $r-1;?>">Fees in Kenya Shillings</th>
                                        <th style="text-align:center;">Total</th>    
                                    </tr>
                                </thead>

                                <tbody>
                                    <?php 
                                        $s=1;

                                        $querys = "SELECT miscellaneousID,name FROM miscellaneous ORDER BY name ASC";
                                        $results = mysql_query($querys);
                                        $rowcounts=  mysql_num_rows($results);
                                        while($rows = mysql_fetch_array($results)) { 
                                            $missID[] = $rows['miscellaneousID'];  
                                            $totalMiscellaneousRecords = $s;
                                    ?>
                                        <tr>
                                            <td style="text-align:center;"><?php echo $s++;?></td>
                                            <td style="padding:0px 5px 0px 5px;"><?php echo $rows['name'];?></td>
                                            <?php 
                                                $fee=array();
                                                for($p=1;$p <= $yrs;$p++){ 
                                                    $queryx = mysql_query("SELECT amount
                                                       FROM misscellanioused_course 
                                                       WHERE miscellaneousID='".$rows['miscellaneousID']."' 
                                                       AND courseID ='".$course."'
                                                       AND year ='$p'");
                                                    $pagex = mysql_fetch_array($queryx);
                                                    $amount = $pagex['amount'];
                                                    $amountx = $pagex['amount'];
                                                    $fee[] = $pagex['amount'];

                                            ?>
                                                <td style="padding:0px 5px 0px 5px;text-align:right;"><?php if($amount==NULL){echo'-';}else{ echo $amount;}?></td>
                                            <?php } $totalMissFee[]=array_sum($fee); ?>
                                                <td style="padding:0px 5px 0px 5px;text-align:right;font-weight:bold;"><?php echo array_sum($fee);?></td>     
                                        </tr>
                                        <?php } ?>


                                        <!--Tuition records-->
                                        <tr>
                                            <td style="text-align:center;"><?php echo $totalMiscellaneousRecords + 1;?></td>
                                            <td style="padding:0px 5px 0px 5px;">Tuition</td>
                                                <?php 
                                                    for($p=1;$p <= $yrs;$p++){ 
                                                        $queryx = mysql_query("SELECT SUM(amount) AS tuition
                                                                                FROM fee
                                                                                WHERE feeID IN(SELECT feeID
                                                                                                FROM (SELECT MAX(feeID) AS feeID
                                                                                                        FROM fee
                                                                                                        WHERE courseID ='$course'
                                                                                                        AND yosID ='$p'
                                                                                                        GROUP BY semisterID) as fee
                                                                                                ORDER BY feeID DESC)");
                                                        $pagex = mysql_fetch_array($queryx);
                                                        $totalTuition = $pagex['tuition'];
                                                        $tuitionAmount[] = $pagex['tuition'];
                                                ?>
                                                    <td style="padding:0px 5px 0px 5px;text-align:right;"><?php if($totalTuition==NULL){echo'-';}else{ echo number_format($totalTuition);}?></td>
                                                <?php } ?>
                                                <td style="padding:0px 5px 0px 5px;text-align:right;font-weight:bold;"><?php echo number_format(array_sum($tuitionAmount));?></td>   
                                        </tr>

                                        <!--Total amounts per year-->
                                        <tr>
                                            <td></td>
                                            <td style="padding:0px 5px 0px 5px;font-weight:bold;">Totals</td>
                                                <?php  
                                                    for($z=1;$z <= $yrs;$z++){ 
                                                        /*annual tution fee(sem1 + sem2 + sem3)*/
                                                        $queryz = mysql_query("SELECT SUM(amount) AS tuition
                                                                                FROM fee
                                                                                WHERE feeID IN(SELECT feeID
                                                                                                FROM (SELECT MAX(feeID) AS feeID
                                                                                                        FROM fee
                                                                                                        WHERE courseID ='$course'
                                                                                                        AND yosID ='$z'
                                                                                                        GROUP BY semisterID) as fee
                                                                                                ORDER BY feeID DESC)");
                                                        $pagez = mysql_fetch_array($queryz);
                                                        $annualTuition = $pagez['tuition'];
                                                        /*end of annual tuition fee*/

                                                        /*Annual miscellaneous fee*/
                                                        $queryg = mysql_query("SELECT SUM(amount) AS annual_amount
                                                                                FROM misscellanioused_course 
                                                                                WHERE miscellaneousID IN (".implode(',',$missID).") 
                                                                                AND courseID ='$course'
                                                                                AND `year` ='$z'");
                                                                             $pageg = mysql_fetch_array($queryg);
                                                                             $Missfee = $pageg['annual_amount'];
                                                        /*end of annual miscellaneous fee*/   

                                                        $annualFee = $annualTuition + $Missfee;   
                                                ?>
                                                    <td style="padding:0px 5px 0px 5px;text-align:right;font-weight:bold;"><?php if($annualFee==NULL){echo'-';}else{ echo number_format($annualFee);}?></td>
                                                <?php } ?>
                                            <td style="padding:0px 5px 0px 5px;text-align:right;font-weight:bold;"><?php echo number_format(array_sum($totalMissFee) + array_sum($tuitionAmount)); ?></td>
                                        </tr>
                                <tbody>    
                            </table>
                        </div>

                        <div class="col-md-12" style="width:100%;text-align:center;margin-top:10px;font-size:12px;">
                            <hr>
                            <p>WAKA Continuing Medical Education Center (CMEC) - P.O Box 188-10100, Nyeri Kenya.</p>
                            <p><b>Email:</b> <a style="text-decoration:none;">wakacmec@gmail.com</a></p>
                            <p><b>Tel:</b> <a style="text-decoration:none;">0707472152</a> / <a style="text-decoration:none;">0788307979</a> / <a style="text-decoration:none;">0722963213</a></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal" style="padding:5px 20px;color:rgb(1,1,1);">Close</button>
            </div>
        </div>
    </div>
</div>
