<?php 
include ("kfunctions.php");
adminall("overadmin","priaccount","secaccount");
?>

<html>
<head>
<?php kheader(); ?>
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link href="css/receipt_css.css" rel="stylesheet" media="screen">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">

<script src="js/sorttable.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
   <script src=
"https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js">
    </script>
<script src="js/printreceipt.js"></script>

</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

      <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                           Receipt
                        
                        </h1>
                    </div>
                </div>

                <!-- /.row -->
<?php 
include ("connect.php");
$cid8 = $_GET["cid"];
$transactionid = $_GET["transactionid"];

$result_scrapaddress = $dbh->query("select * from scrap where item2='title1'");
$row_scrapaddress= $result_scrapaddress->fetchObject();
$count_scrapaddress = $result_scrapaddress->rowCount();

$headie=$row_scrapaddress->item;


$result70 = $dbh->query("select * from children where cid='$cid8'");
$row70 = $result70->fetchObject();
$count70 = $result70->rowCount();
$termtotake=$_GET['t']; 

$cid=$_GET['cid'];
$tid=$_GET['t'];
$schoolyear=$_GET['schoolyear'];
$schoolclass=$row70->schoolclass;
 
$result_clo = $dbh->query("select * from clo where cid='$cid' and transactionid='$transactionid' order by autoid desc");
$row_clo = $result_clo->fetchObject(); $count_clo = $result_clo->rowCount();

$result_scrapterm = $dbh->query("select * from scrap where item='$row_clo->termid' and type='term_year'");
$row_scrapterm = $result_scrapterm->fetchObject();

$result_homelandClass = $dbh->query("select * from homeland where schoolyear='$row_scrapterm->item3' and transactionid='$transactionid'");
$row_homelandClass = $result_homelandClass->fetchObject();
$count_homelandClass = $result_homelandClass->rowCount();



$result_bravos = $dbh->query("select * from bravos where cid='$cid' and fsitemid='fullpay'");
$row_bravos = $result_bravos->fetchObject();
$count_bravos = $result_bravos->rowCount();

$result_scrappri = $dbh->query("select * from scrap where item='$row_homelandClass->schoolclass' and type='priclas'");
$row_scrappri = $result_scrappri->fetchObject();

if(empty($row_clo->paydate)){
    $exp=explode(" ",$row_clo->autodate);
    $ddate=$exp[0];
    $ttime=$exp[1];
} elseif(!empty($row_clo->paydate)) {
    $ddate=$row_clo->paydate;
    $ttime=$row_clo->time_received;
}
 ?>


<div id='myDiv'>
<div class="row">
		<div class="col-sm-10 col-sm-offset-1">
			<div class="widget-box">
				<div class="widget-header widget-header-large">
					
                    <div class="widget-toolbar no-border invoice-info" style="float:left;">
						<span class="invoice-info-label">                            					
                            <b style='font-size:17px;'>NEW JERUSALEM MIXED DAY & BOARDING SCHOOL</b>                           
                        </span><br>				
						<span class="invoice-info-label"> 
                            Bulamu - Kasangati
                        </span>
						
					</div>

					<div class="widget-toolbar no-border invoice-info">
						<span class="invoice-info-label">Receipt ID:</span>
						<span class="red"><?php echo substr($row_clo->transactionid,2); ?></span>

						<br>
						<span class="invoice-info-label">Date:</span>
						<span class="blue"><?php echo $ddate; ?></span>
					</div>

					<div class="widget-toolbar hidden-480">
                        <a style='cursor:pointer;' onClick="PrintDiv('myDiv','<?php echo $row70->fname." ".$row70->sname; ?> - <?php echo $cid8;?>')">						
							<i class="ace-icon fa fa-print"></i>
						</a>
					</div>
				</div>

				<div class="widget-body">
					<div class="widget-main padding-24">
						<div class="row">
							<div class="col-sm-6">
								<div class="row">
									<div class="col-xs-11 label label-lg label-info arrowed-in arrowed-right">
										<b>School Info</b>
									</div>
								</div>

								<div>
									<ul class="list-unstyled spaced">
										<li>
											<i class="ace-icon fa fa-caret-right blue"></i> P.O. Box 8589, Kampala
										</li>								
									
                                        <li>
											<i class="ace-icon fa fa-caret-right blue"></i>
                                                Phone:
											<b class="green">0700-547893/ 0772-690679</b>
										</li>

										<li>
											<i class="ace-icon fa fa-caret-right blue"></i>
                                                Email:
											<b class="green">newjerusalemujuniorschool@gmail.com</b>
										</li>
                                        
										<li class="divider"></li>
                                        

										
									</ul>
								</div>
							</div><!-- /.col -->

							<div class="col-sm-6">
								<div class="row">
									<div class="col-xs-11 label label-lg label-success arrowed-in arrowed-right">										
                                        <b>Payment Received For:</b>
									</div>
								</div>

								<div>
									<ul class="list-unstyled  spaced">
                                        
										<li>
											<i class="ace-icon fa fa-caret-right green"></i> <?php echo $row70->fname." ".$row70->sname; ?> - <?php echo $cid8;?>
										</li>

										<li>
											<i class="ace-icon fa fa-caret-right green"></i> <?php  echo $row_scrappri->item2; ?>
										</li>

										<li>
											<i class="ace-icon fa fa-caret-right green"></i> Term  <?php echo $row_scrapterm->item2; ?>
										</li>

										<li class="divider"></li>

										
									</ul>
								</div>
							</div><!-- /.col -->
						</div><!-- /.row -->

						<div class="space"></div>
                                            <center>
                                                <h4>
                                                <b>Receipt</b>
                                                </h4>
                                            </center>

						<div>
                        <table border='0' style='margin-top:20px;width:100%;' class='table table-bordered table-hover table-striped sortable'>
                            <thead>
                            <tr>
                            <th><span style='float:left;'>Item</span></th>
                            <th><span style='float:left;'>Structure</span></th>
                            <th><span style='float:left;'>Paid so far</span></th>
                            <th><span style='float:left;'>Balance</span></th>
                            </tr>
                            </thead>
                            <tbody>

                            <?php 
                            $resultfsi = $dbh->query("select * from bravos where cid='$cid' and fsitemid!='fullpay'");
                            $rowfsi = $resultfsi->fetchObject();
                            $countfsi = $resultfsi->rowCount();

                            if($countfsi>0){ $r=1; do 
                            {$y=$r++;
                            $resultfsiname = $dbh->query("select * from fsitems where fsid='$rowfsi->fsid' and newitemclass='$row70->schoolclass'");
                            $rowfsiname= $resultfsiname->fetchObject();
                            $countfsiame = $resultfsiname->rowCount();

                            $result_scrap = $dbh->query("select * from scrap where item='$rowfsi->fsitemid'");
                            $row_scrap= $result_scrap->fetchObject();
                            $count_scrap = $result_scrap->rowCount();

                                echo "
                            <tr>
                            <td style='text-transform:capitalize;'>"; if($count_scrap>0){echo $row_scrap->item2;}else
                            {echo $rowfsiname->newitemname;} echo "</td>
                            <td>".number_format($rowfsi->payable)."</td>
                            <td>".number_format($rowfsi->paid)."</td>
                            <td>".number_format($rowfsi->balance)."</td>
                            </tr>
                            ";} while ($rowfsi = $resultfsi->fetchObject());}

                            $resultfsi = $dbh->query("select * from bravos where cid='$cid' and fsitemid='fullpay'");
                            $rowfsi = $resultfsi->fetchObject(); $countfsi = $resultfsi->rowCount();
                            if($countfsi>0){
                            echo "<tr>
                            <th><span style='float:left;'>Total</span></th>
                            <th><span style='float:left;'>".number_format($rowfsi->payable)."</span></th>
                            <th><span style='float:left;'>".number_format($rowfsi->paid)."</span></th>
                            <th><span style='float:left;'>".number_format($rowfsi->balance)."</span></th>
                            </tr>";}

                            ?>

                            </tbody>
                            </table>
                            <table border='0' style='margin-top:20px;width:100%;' class='table table-bordered table-hover table-striped sortable'>
                            <thead>
                            <th width="35%"><span style='float:left;'>Payment method</span></th>
                            <th width="35%"><span style='float:left;'>ID</span></th>
                            <th width="35%"><span style='float:left;'>Amount</span></th>
                            </thead>
                            <tbody>
                            <?php

                            $result_trans = $dbh->query("select * from transactions where cid='$cid' and transactionid='$row_clo->transactionid'");
                            $row_trans = $result_trans->fetchObject(); $count_trans = $result_trans->rowCount();

                            if($count_trans>0){ do{
                                echo "<tr>    
                                <td style='text-transform:uppercase;'>".$row_trans->paymethod."</td>
                                <td>".$row_trans->externalid."</td>
                                <td>".number_format($row_trans->amount)."</td>
                                </tr>";
                            }while($row_trans = $result_trans->fetchObject());}
                            ?>
                            </tbody>
                        </table>
						</div>

						<div class="hr hr8 hr-double hr-dotted"></div>

						<div class="row">
							<div class="col-sm-5 pull-right">
								<h4 class="pull-right">
									.
								</h4>
							</div>
							<div class="col-sm-7 pull-left"> <?php echo "<div class='col-lg-12'>Prepared by : ".$_SESSION["firstname"]." ".$_SESSION["lastname"].", ".$ttime."</div>"; ?> </div>
						</div>

						<div class="space-6"></div>
						<div class="well" style="text-transform:uppercase; text-align:center;">
							Thank you for choosing NEW JERUSALEM MIXED DAY & BOARDING SCHOOL.
We believe you will be satisfied by our services.
						</div>
                        
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<div id="output"></div>

                <!-- /.row -->





                 
    <!-- /#wrapper -->

    <!-- jQuery -->
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript">
    $('.form_datetime').datetimepicker({
        //language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });
    $('.form_date').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    $('.form_time').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    });
</script>

    <!-- Bootstrap Core JavaScript -->

    

</body>

</html>