<?php
if(isset($_GET['order_id']))
{
	$order_id      = $_GET['order_id'];
	$sqlInvoice     = mysqli_query($cn,"select * from `tbl_order` where `order_id`='".$order_id."'");
	$sqlInvoiceData = mysqli_fetch_array($sqlInvoice); 
		  		
	$sqltDistributor     = mysqli_query($cn,"select * from `tbl_retailer` where `id`='".$sqlInvoiceData['shop_id']."'");
	$sqltDistributorData = mysqli_fetch_array($sqltDistributor); 
}
?>
<div class="col-lg-12 grid-margin stretch-card">
<div class="card">
<div class="card-header bg-transparent header-elements-inline">
<h6 class="card-title">Order Invoice</h6>
	<div class="header-elements">    
    	<button type="button" class="btn btn-light btn-sm ml-3" onclick='printDiv();'><i class="icon-printer mr-2"></i> Print</button>
	</div>
</div>

<div class="card-body" id="DivIdToPrint">
	<style type="text/css" media="all">
       @import "css/style.css";
    </style>
    <style>
    .table thead th {
        vertical-align: bottom;
        border: 1px solid #000;        
    }
    .table th, .table td {
        padding: 10px 3px;
        vertical-align: top;
        border: 1px solid #000;
    }
    </style>
    <div class="row">
        <div class="col-sm-6">
            <div class="mb-4">
                <img src="images/faces/logo.jpg" class="mb-3 mt-2" style="height:70px !important;width: auto !important;" alt="logo">
                <ul class="list list-unstyled mb-0">
                    <p><strong>Apartment No.C-1st Ground Floor Chittora Apartments, Plot No. A-4 Tilak Marg, C-scheme, Jaipur - 302001</strong></p>
                    <li><strong>Contact :</strong> 98280600653</li>
                	<li><strong>GST :</strong> 08AADCL2969H1Z8</li>
                </ul>
            </div>
        </div>
    
        <div class="col-sm-6">
            <div class="mb-4">
                <div class="text-sm-right">
                    <h4 class="text-primary mb-2 mt-md-2">Invoice #<?php echo $order_id;?></h4>
                    <ul class="list list-unstyled mb-0">
                        <li>Invoice Date: <span class="font-weight-semibold"><?php echo date('F d, Y',strtotime($sqlInvoiceData['date']));?></span></li>                                
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="d-md-flex flex-md-wrap">
        <div class="mb-4 mb-md-2">
            <span class="text-muted">Customer Detail</span>
            <ul class="list list-unstyled mb-0">
                <li><h5 class="my-2"><?php echo $sqltDistributorData['shop_name'];?></h5></li>
                <p style="width:60%;margin:0;"><?php echo $sqltDistributorData['address'];?></p>
                <li><strong>Mobile :</strong> +91-<?php echo $sqltDistributorData['mobile'];?></li>                
            </ul>
        </div>    
    </div>
<div class="table-responsive">
<table class="table table-lg">
    <thead>
        <tr>
            <th width="5%">S.NO</th>
            <th>Description</th>
            <th>SKU</th>            
			<th>UNIT</th>
            <th class="text-right">QTY</th>
            <th class="text-right">RATE</th>
            <th class="text-right">Total</th
        ></tr>
    </thead>
    <tbody>
    <?php 
	$sr = 1;
    $sqlInvoice2     = mysqli_query($cn,"select * from `tbl_order` where `order_id`='".$order_id."'");        
    while($sqlInvoiceData2 = mysqli_fetch_array($sqlInvoice2))
	{																 				
		?>
        <tr>
            <td width="5%">#<?php echo $sr++;?></td>
            <td width="30%"><?php echo productName($sqlInvoiceData2['product_id']);?></td>
            <td width="7%"><?php echo $sqlInvoiceData2['sku'];?></td>
            <td width="7%"><?php echo $sqlInvoiceData2['unit'];?></td>
            <td class="text-right" width="5%"><?php echo $sqlInvoiceData2['qty'];?></td>
            <td class="text-right" width="5%"><?php echo $sqlInvoiceData2['price'];?></td>            
            <td class="text-right" width="7%">&#x20B9;<?php echo number_format($sqlInvoiceData2['total'],2);?></td>
        </tr>
     <?php 	 	
	 }	 
	 $roundTotal     = round($sqlInvoiceData['order_total']);
	 $roundOff       = $roundTotal-$sqlInvoiceData['order_total'];           	 	   	 
     ?>
     <tr>
        <td colspan="3"></td>            
        <td colspan="3" class="text-right"><strong>Subtotal</strong></td>        
        <td class="text-right"><span class="font-weight-semibold">&#x20B9;<?php echo number_format($sqlInvoiceData['order_total'],2);?></span></td>
    </tr>
    
	<tr>
        <td colspan="3">&nbsp;</td>                
        <td colspan="3" class="text-right">Round OFF</td>        
        <td class="text-right"><?php echo number_format(abs($roundOff),2);?></td>        
    </tr> 
    <tr>
        <td colspan="3">&nbsp;</td>       
        <td colspan="3" class="text-right"><strong>Grand Total </strong></td> 
        <td class="text-right"><strong>&#x20B9;<?php echo number_format($roundTotal,2);?></strong></td>
    </tr>
	</tbody>
</table>

</div>
<br />
<!--<div class="row">
    <div class="col-sm-6"> 
        <table class="table table-lg">    
            <tr>
                <td style="border: none !important;">
                <div class="d-md-flex flex-md-wrap">
                    <div class="mb-4 mb-md-2">
                        <span class="text-muted" style="font-size:16px;">Our Bank Detail</span>
                        <ul class="list list-unstyled mb-0">            
                            <li><strong>Account Holder Name :</strong> Lapaya Luggage Pvt. Ltd.</li>
                            <li><strong>Bank Name :</strong> Kotak bank</li>
                            <li><strong>Bank Branch :</strong> Sardar Patel Marg, Jaipur</li>
                            <li><strong>Account Number :</strong> 9512875212 </li>
                            <li><strong>IFSC :</strong> KKBK0000271 </li>
                        </ul>
                    </div>
                </div>    
                </td>
            </tr>
            <tr>
                <td style="border: none !important;">
                <span class="text-muted" style="font-size:16px;">Term & Conditions</span>
                <ul class="list list-unstyled mb-0">            
                    <li>Subject to Jaipur Jurisdiction.</li>
                    <li>Goods once sold will not taken back.</li>
                    <li>Interest @ 18% will be charged if will is not paid with 3 days.</li>
                </ul>
                </td>
            </tr> 
        </table>
    </div>
    <div class="col-sm-6">
        <table class="table table-lg">               
            <tr>
                <td style="border:none;">                
                <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
                <ul class="list list-unstyled mb-0">            
                    <li style="text-align:right;">For Reva Consultent LLP</li>
                    <li><br /><br /></li>
                    <li></li>
                    <li style="text-align:right;"><strong>Autorised Signature</strong></li>
                </ul>
                </td>
            </tr> 
        </table>
    </div>          
</div>-->
<div class="text-center">		
    <span>Thank you for order with us.</span>
</div>
</div>
</div>
</div>
<style>
.text-muted, .preview-list .preview-item .preview-item-content p .content-category {
    color: #000 !important;
    font-weight: 600;
}
</style>

<script>
function printDiv() 
{
  var divToPrint=document.getElementById('DivIdToPrint');
  var newWin=window.open('','Print-Window');
  newWin.document.open();
  newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
  newWin.document.close();
  setTimeout(function(){newWin.close();},10);
}
</script>