<?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;
if(empty($_SESSION['branch'])):
header('Location:../index.php');
endif;
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Receipt | <?php include('../dist/includes/title.php');?></title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="../plugins/select2/select2.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    
    <style type="text/css">
      tr td{
        padding-top:-10px!important;
        border: 1px solid #000;
      }
      @media print {
          .btn-print {
            display:none !important;
          }
      }
    </style>
 </head>
  <!-- ADD THE CLASS layout-top-nav TO REMOVE THE SIDEBAR. -->
  <body class="hold-transition skin-blue layout-top-nav">
    <div class="wrapper">
      
      <!-- Full Width Column -->
      <div class="content-wrapper">
        <div class="container">

          <section class="content">
            <div class="row">
	      <div class="col-md-12">
              <div class="col-md-12">

              </div>
                
                <div class="box-body">

                  <!-- Date range -->
                  <form >
<?php
include('../dist/includes/dbcon.php');
$id=$_SESSION['id'];    
?>			
                 
<?php

    $branch=$_SESSION['branch'];
	$sales_id=$_REQUEST['sales_id'];
    $query=mysqli_query($con,"select * from sales where sales_id='$sales_id'")or die(mysqli_error($con));
        $row=mysqli_fetch_array($query);
        $branch=$row['branch_id'];
        $sales_id=$row['sales_id'];
		$cust_id=$row['cust_id'];
		$delivery=$row['delivery'];
			$ratedelivery=$row['ratedelivery'];
		  $queryb=mysqli_query($con,"select * from branch where branch_id='$branch'")or die(mysqli_error());
  
        $rowb=mysqli_fetch_array($queryb);
		
		 $queryk=mysqli_query($con,"select * from customer where cust_id='$cust_id'")or die(mysqli_error($con));
        $rowk=mysqli_fetch_array($queryk);
		
		
        $last=$rowk['cust_last'];
        $first=$rowk['cust_first'];
        $address=$rowk['cust_address'];
        $contact=$rowk['cust_contact'];
        $sid=$row['sales_id'];
        $due=$row['amount_due'];
       $discount=$row['discko'];
		$discounttotal=$row['discount'];
        $grandtotal=$due-$discount;
        $tendered=$row['cash_tendered'];
        $change=$row['cash_change'];

        $query1=mysqli_query($con,"select * from payment where sales_id='$sales_id'")or die(mysqli_error($con));
      
        $row1=mysqli_fetch_array($query1);

?>    
                   <table class="table">
                    <thead>
					
					 <tr style="padding:0;margin:0;">
            
				  <th colspan="15"><p style="font-size:20px;">CITIBUILDERS AND SUPPLY </p>
				  <p style="font-size:10px;padding:0;margin:0;">0168 PUROK 1 DIVERSION RD. BRGY KINAMALIGAN MASBATE CITY </p>
				   <p style="font-size:10px;padding:0;margin:0;">TM: 0967-937-2550 / SMART 0919-839-4967 </p>
				    <p style="font-size:10px;padding:0;margin:0;">Email Address: citibuilders42@yahoo.com </p>
				   </th>
				  
				  
				       <th colspan="2" style="width:400px;"></th>
					     </tr>
					  <div style="position:fixed;">
				     <img src="logo.jpg" alt="logo" style="min-width:260px;margin-top:-20px;margin-left:400px;height:130px;border-radius:20%;"/>
                             </div>      
					
                      <tr>
                        <th colspan="12" style="padding:0;margin:0;"><p>QUOTATION SLIP <?php echo $rowb['branch_name'];?> &nbsp <?php echo $cashnote ?? null; ?></p></th>
						  <th colspan="6"><label style="font-size: 20px;padding:0;margin:0;color: red;width:400px;"> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Receipt#:SN0<?php echo $sales_id;?></label></th>
                      </tr>
                  
                      <tr>
                        <th colspan="18" style="font-weight: bold;width:600px;font-family: Arial, Helvetica, sans-serif;font-size:12px;margin:0;padding:0;" >  CUSTOMER: <u><?php echo $last.", ".$first;?></u>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp CP #: <?php echo $contact;?></th>
                        
                      </tr>
                      <tr>
					   
                        <th colspan="18" style="font-size:12px;">Address: <?php echo $address;?>  / &nbsp  &nbsp DATE: <?php echo date("M d, Y");?> &nbsp Time <?php echo date("h:i A");?> </th>
                        
                      </tr>
                      
                    </thead>
                  </table>
				  
                  <table class="table" style="margin-top:-30px;">
                    <thead>
                     
                      <tr style="padding:0;margin:0;">
					   <center>   <th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;">No.</th>
                        <th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;">Qty</th>
                        <th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;">Unit</th>
                        <th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;">Description</th>
						<th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;"><?php if($branch == 1){ ?> H Pic <?php }else{ ?>Product/Length<?php } ?></th>
						<th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;"><?php if($branch == 1){ ?> Variation/Glass Color <?php }else{ ?> Color <?php } ?></th>
            			<th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;min-width:90px;"><?php if($branch == 1){ ?> Unit Price <?php }else{ ?>Unit Price <?php } ?></th>
						<th style="border: solid 1px #000;font-size:12px;padding:0;margin:0;" class="text-left">Total Amount</th> </center>
                      </tr>  
                    </thead>
                    <tbody>
<?php
		$query=mysqli_query($con,"select * from sales_details natural join product where sales_id='$sid'")or die(mysqli_error($con));
			$grand=0;
			$rowNo = 0;
		while($row=mysqli_fetch_array($query)){
			
			$rowNo++;
			$mystatus= $row['status'];
				//$id=$row['temp_trans_id'];
				$total= $row['qty']*$row['price'];
				$totalpo= $row['hh']*$row['ww'];
				$grand=$due;
				$dd=1;
				
        
?>
                      <tr>
					  <td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" ><?php echo  $rowNo; ?></td>
            			<td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" ><?php echo $row['qty'];?></td>
                        <td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" > <?php if(!empty($mystatus)){ ?> Sheets <?php }else{ ?> Pcs<?php } ?></td>
                        <td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" class="record"><?php echo $row['prod_name'];?></td>
						<td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" ><img style="width:35px;height:20px" src="../dist/uploads/<?php echo $row['prod_pic'];?>"><?php if($row['hh'] == 1 ){ } else { echo $row['hh']; echo $row['thick'];?> <?php } ?></td>
							<td style="border: solid 1px #000;font-size:12px;padding:0;margin:0;text-align:center;font-weight:bold;" ><?php if($branch == 1){ ?> <?php echo $row['variation'];?>/<?php echo $row['color'];?> <?php }else{ ?> <?php echo $row['color'];?> <?php } ?>       </td>
            						
								<!--	<td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:center;font-weight:bold;" ><?php if($branch == 1){ ?> <?php echo number_format($row['ww']);?> <?php }else{ ?> <?php echo number_format($row['ww']);?>  <?php } ?>    </td> -->
								<td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:center;font-weight:bold;" ><?php if($branch == 1){ ?> <?php echo number_format($totalpo,2);?> <?php }else{ ?>  <?php echo number_format($totalpo,2);?> <?php } ?>    </td>
            						<td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:right;font-weight:bold;" ><?php echo number_format($total,2);?></td>
                                    
                      </tr>
					  

<?php }?>	

</tbody>
</table>



<?php
    $query=mysqli_query($con,"select * from user where user_id='$id'")or die(mysqli_error($con));
    $row=mysqli_fetch_array($query);
	
	
	
	$dodo=$discount/100;
	$dodokoko=$dodo * $grand + $discounttotal;
	
	
	
	
	$cashchange=$grand-$dodokoko;
	
	$changenew=$cashchange - $tendered;
	
	
 //
?>     
  <?php 
						 $query1=mysqli_query($con,"SELECT * FROM customer where cust_id=''")or die(mysqli_error($con));
			$row1=mysqli_fetch_array($query1);
						 ?>
						 
						 <div style="display:flex;">
						  <table style="margin-top:-20px;margin-left:0px;">					 
								<tbody>			 
							<tr>
                        <td style="min-width:500px;font-size:14px;border:none;">
						
						<h5 style="font-weight:bold;">PAYMENT: <?php echo number_format($tendered,2);?> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp BALANCE: <?php echo number_format($rowk['balance'] + $changenew,2);?> </h5>
<p style="text-align:justify;">Terms and condition :<br>I agree that the maximum lead time for roof production will be 2 – 3 days.<br> In case of any revision such as hold, changes in size/color or other special <br>instructions of this quotation, Job order revisions form has to be signed and <br> acknowledge to confirm the validity. It is important that the customer <br>keep copy of JO revision form which is signed by our company represen- <br>tative and  our client.</p> 
					  

						</td>
                     
                      </tr>

 </tbody>
                    
                  </table>
						 
	 <table style="margin-top:-20px;margin-left:45px;">					 
								<tbody>			 
							<tr>
							<?php
 $query16=mysqli_query($con,"SELECT SUM(total) as dadakol FROM sales_details where sales_id='$sid'")or die(mysqli_error($con));
			$row16=mysqli_fetch_array($query16);
			$dadakolpol=$row16['dadakol'];
			$gomezkol=$dadakolpol - $grand - $dodokoko ;
							?>
                        <td style="font-size:12px;padding:0;text-align:left;font-weight:bold;min-width:100px;" class="text-left">SUBTOTAL</td>
                        <td   style="border: solid 1px #000;font-size:14px;padding:0;min-width:100px;margin:0;text-align:right;font-weight:bold;"><?php echo number_format($dadakolpol,2);?></td>
                      </tr>
			
                      <tr>
                       
                     <td style="font-size:12px;padding:0;margin:0;text-align:left;font-weight:bold;max-width:140px;" class="text-left">DISCOUNT <?php echo $discount;?>%</td>
                        <td  style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:right;font-weight:bold;" ><?php echo $gomezkol; ?></td>
                      </tr>
                      <tr>
                      
                          <td style="font-size:12px;padding:0;margin:0;text-align:left;font-weight:bold;max-width:140px;" class="text-left"><b>AMOUNT DUE</b></td>
                        <td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:right;font-weight:bold;"><b><?php echo number_format($grand-$dodokoko,2);?></b></td>
                      </tr>
                      <tr>
					  <td style="font-size:12px;padding:0;margin:0;text-align:left;font-weight:bold;max-width:140px;"class="text-left">DOWNPAYMENT <?php echo $ratedelivery;?></td>
                      <td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:right;font-weight:bold;"><?php echo number_format($tendered,2);?></td>
					</tr>
						<tr>
						 <td style="font-size:12px;padding:0;margin:0;text-align:left;font-weight:bold;max-width:150px;"class="text-left"><b><?php $dulas=number_format($grand-$dodokoko,2); if($tendered >= $dulas){ ?> CHANGE <?php }else {?> BALANCE <?php } ?></b></td>
                        <td style="border: solid 1px #000;font-size:14px;padding:0;margin:0;text-align:right;font-weight:bold;"><b><?php echo number_format($changenew,2);?></b></td>
						</tr>


 </tbody>  </table>
                </div>    
                
					
					
					 
					  <div style="margin-top:-5px;width:100%;text-align:justify;">
						  
						  <p>Hence, items order shall be claims 30 days by the dated of the down payment has been made otherwise roof ordered will be automatically for disposal without need further notice due to quality and storage concerned. Further, PAYMENT made will be automatically forfeited. </p>
						 <h6 style="font-weight:bold; color:#DAA520	">Important: Items for free delivery are subject for the availability of transport delivery vehicle, if not available clients must agree to pick-up their purchase items.</h6>
			  		
						 
						 
						 
						 </div>   </th>
                      <th></th>
					  <th>
						</th>
	
                      </tr> 
				
				<tr>
                       <th>  _________________________________</th>
                       </tr>
					   <br>
					  <tr>
			
                     <th>   Customer Signature over printed name              </th>
                          
                      </tr>
				
				
				
						  <h6 style="font-weight:bold;color:#DAA520	">BANK NAME: METROBANK  &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp   &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp GCASH</h6>
						  <h6 style="font-weight:bold; color:#DAA520	">ACCOUNT # 369-7369-010-766 &nbsp &nbsp &nbsp &nbsp &nbsp  &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp     &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ACCOUNT NAME: ERROL JOHNSON SIA</h6>
						   <h6 style="font-weight:bold; color:#DAA520	">ACCOUNT NAME:  CITIBUILDERS AND SUPPLY &nbsp &nbsp     &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ACCOUNT NO: 0947-243-9867</h6>
						  
					
				
				 <tr>
                      <th style="min-width:400px;" >Prepared By: <?php echo $row['name'];?></th>
                    
					  <th> </th>
					  <th></th>
                      <th>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Check By: ________________________</th>
                      
                      </tr>
                      <tr colspan="18" >
                       <th><br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  &nbsp &nbsp &nbsp   Delivered by:___________________</th>
                       <th></th>
                      <th></th>
			
                     <th>&nbsp &nbsp &nbsp &nbsp  Delivery Date: _____________-_____- 2025   </th>
                          
                      </tr>
                    <tr colspan="18" >
                       <th>Received By:____________________________________</th>
                       <th></th>
                      <th></th>
                     <th></th>
                          
                      </tr>
					  <tr colspan="18" >
                       <th><h2><?php echo $delivery;?> </h2></th>
                       <th></th>
                      <th></th>
                     <th></th>
                          
                      </tr>
					 
						 
						  	
                </div><!-- /.box-body -->
				</div>  
				</form>	
                </div><!-- /.box-body -->
                <a class = "btn btn-success btn-print" href = "" onclick = "window.print()"><i class ="glyphicon glyphicon-print"></i> Print</a>
                <a class = "btn btn-primary btn-print" href = "home.php"><i class ="glyphicon glyphicon-arrow-left"></i> Back to Homepage</a>
              </div><!-- /.box -->
            </div><!-- /.col (right) -->
           
          </div><!-- /.row -->
	  
             
          </section><!-- /.content -->
        </div><!-- /.container -->
      </div><!-- /.content-wrapper -->
     
    </div><!-- ./wrapper -->
	
	
	<script type="text/javascript" src="autosum.js"></script>
    <!-- jQuery 2.1.4 -->
    <script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
	<script src="../dist/js/jquery.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../plugins/select2/select2.full.min.js"></script>
    <!-- SlimScroll -->
    <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../dist/js/demo.js"></script>
    <script src="../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
   
  </body>
</html>
