<?php
    session_start();
    include ('../common/library.php');  
    include ('../common/helper.php');
	  include ('../common/class.numbertoword.php'); 
    $sale_no = $_REQUEST['sale_no'];
    
    $sql = $conn->query("select * from sales_master where group_for=".$_SESSION['group_for']."  and s_no='".$sale_no."'");
    $s_data = $sql->fetch_assoc();
    
    if($s_data['dealer_code'] > 0){
        $dealer_name=find_a_field('customer_info','business_name','id='.$s_data['dealer_code']);
        $dealer_mobile=find_a_field('customer_info','mobile_no','id='.$s_data['dealer_code']); 
        $dealer_address=find_a_field('customer_info','customer_address','id='.$s_data['dealer_code']);
    }
    else {
        $dealer_name=$s_data['dealer_name'];
        $dealer_mobile=$s_data['dealer_address'];
        $dealer_address=$s_data['contact'];
    }
    
?>

<!DOCTYPE html>
<html>
<head>
		<meta charset="utf-8">
  		<meta name="viewport" content="width=device-width, initial-scale=1">
  		<title>Busicus</title>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>

<style>
body{margin-top:20px;
    color: #2e323c;
    background: #f5f6fa;
    position: relative;
    height: 100%;
}
.invoice-container {
    padding: 1rem;
}
.invoice-container .invoice-header .invoice-logo {
    margin: 0.8rem 0 0 0;
    display: inline-block;
    font-size: 1.6rem;
    font-weight: 700;
    color: #2e323c;
}
.invoice-container .invoice-header .invoice-logo img {
    max-width: 130px;
}
.invoice-container .invoice-header address {
    font-size: 0.8rem;
    color: #9fa8b9;
    margin: 0;
}
.invoice-container .invoice-details {
    margin: 1rem 0 0 0;
    padding: 1rem;
    line-height: 180%;
    background: #f5f6fa;
}
.invoice-container .invoice-details .invoice-num {
    text-align: right;
    font-size: 0.8rem;
}
.invoice-container .invoice-body {
    padding: 1rem 0 0 0;
}
.invoice-container .invoice-footer {
    text-align: center;
    font-size: 0.7rem;
    margin: 5px 0 0 0;
}

.invoice-status {
    text-align: center;
    padding: 1rem;
    background: #ffffff;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    margin-bottom: 1rem;
}
.invoice-status h2.status {
    margin: 0 0 0.8rem 0;
}
.invoice-status h5.status-title {
    margin: 0 0 0.8rem 0;
    color: #9fa8b9;
}
.invoice-status p.status-type {
    margin: 0.5rem 0 0 0;
    padding: 0;
    line-height: 150%;
}
.invoice-status i {
    font-size: 1.5rem;
    margin: 0 0 1rem 0;
    display: inline-block;
    padding: 1rem;
    background: #f5f6fa;
    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    border-radius: 50px;
}
.invoice-status .badge {
    text-transform: uppercase;
}

@media (max-width: 767px) {
    .invoice-container {
        padding: 1rem;
    }
}


.custom-table {
    border: 1px solid #e0e3ec;
}

.custom-table thead th {
    border: 1px solid #e6e9f0;
    color: #000;
}
.custom-table > tbody tr:hover {
    background: #fafafa;
}
.custom-table > tbody tr:nth-of-type(even) {
    background-color: #ffffff;
}
.custom-table > tbody td {
    border: 1px solid #e6e9f0;
}


.card {
    background: #ffffff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 0;
    margin-bottom: 1rem;
}

.text-success {
    color: #00bb42 !important;
}

.text-muted {
    color: #9fa8b9 !important;
}

.custom-actions-btns {
    margin: auto;
    display: flex;
    justify-content: flex-end;
}

.custom-actions-btns .btn {
    margin: .3rem 0 .3rem .3rem;
}
</style>





<script>
		
		function printpage() {
       
        var printButton = document.getElementById("printpagebutton");
       
        printButton.style.visibility = 'hidden';
        
        window.print()
        printButton.style.visibility = 'visible';
    }
				
	</script>

</head>

<body>



<div class="container">
<div class="row gutters">
		<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
			<div class="card">
				<div class="card-body p-0">
					<div class="invoice-container">
						<div class="invoice-header">
							<!-- Row start -->
							<div class="row gutters">
								<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
									<div class="custom-actions-btns mb-5">
										<!--<a href="#" class="btn btn-primary">
											<i class="icon-download"></i> Download
										</a>-->
										<input  id="printpagebutton" class="btn btn-primary" type="button" value="print" onClick="printpage()"/>
									</div>
								</div>
							</div>
							<!-- Row end -->
							<!-- Row start -->
							<div class="row gutters">
								<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6">
									<img src="../images/logo.png" alt="Apple Service Center BD" style="height:60px;">
								</div>
								<div class="col-lg-6 col-md-6 col-sm-6">
									<h1 style="float:right">INVOICE</h1>
								</div>
							</div>

							<div class="row gutters">
								<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6">
								<div class="text-left">
									<br>
								<div>819/A, Section 2 </div>
								<div>Mirpur, Dhaka - 1216.</div>
								<div>Contact : +8801620615052</div>
																		
									</div>
								</div>
								<div class="col-lg-6 col-md-6 col-sm-6">
								<div class="text-right">
											<div>Invoice No - APSCBD-<?php echo $s_data['s_no'];?></div>
											<div>Invoice Date - <?php echo $s_data['sales_date'];?></div>
											<div>Delivery Date - <?php echo $s_data['sales_date'];?></div>
										</div>
								</div>
							</div>

							<hr>
							<!-- Row end -->
							<!-- Row start -->
							<div class="row gutters">
								<div class="col-xl-9 col-lg-9 col-md-12 col-sm-12 col-12">
									<div class="invoice-details">
										<address>
											Customer Name : <?php echo $dealer_name;?><br>
											Address : <?php echo $dealer_address;?>
										</address>
									</div>
								</div>
								<div class="col-xl-3 col-lg-3 col-md-12 col-sm-12 col-12">
									<div class="invoice-details">
										<div class="invoice-num">
											<div></div>
											<div></div>
										</div>
									</div>													
								</div>
							</div>
							<!-- Row end -->
						</div>
						<div class="invoice-body">
							<!-- Row start -->
							<div class="row gutters">
								<div class="col-lg-12 col-md-12 col-sm-12">
									<div class="table-responsive">
										<table class="table custom-table m-0">
											<thead>
												<tr>
													<th>Item Code</th>
													<th>Item Details</th>
													<th>Warranty</th>													
													<th>Unit</th>
													<th>Rate</th>
													<th>Quantity</th>
													<th>Sub Total</th>
												</tr>
											</thead>
											<tbody>
											<? $s_details = $conn->query("select * from sales_order where group_for=".$_SESSION['group_for']."  and  s_no=".$sale_no."");
                	while($data = $s_details->fetch_assoc()){
                		?>										
												<tr>
													<td>
														<?php echo find_a_field('item_info','item_code','item_id='.$data['item_id']) ?>
													</td>
													<td><?php echo find_a_field('item_info','item_name','item_id='.$data['item_id']) ?></td>
													<td><?php echo $data['warranty']?></td>
													<td><?php echo $data['unit']?></td>
													<td><?php echo $data['rate']?></td>
													<td><?php echo $data['qty']?></td>
													<td class="text-right"><?php echo $data['amount']; $tot_amt += $data['amount'];  ?></td>
												</tr>
												<?php } ?>
												
											</tbody>
										</table>

<table width="99%" border="0" cellpadding="0" cellspacing="0" align="center" class="fullTable" bgcolor="#e1e1e1">
  <tbody>
    <tr>
      <td>
        <table width="99%" border="0" cellpadding="0" cellspacing="0" align="center" class="fullTable" bgcolor="#ffffff">
          <tbody>
            <tr>
              <td>

                <!-- Table Total -->
                <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" >
                  <tbody>
                    <tr>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                        Subtotal
                      </td>
                      <td style=" line-height: 22px; vertical-align: top; text-align:right; " width="150">
                      <?php echo number_format($tot_amt,2);?>
                      </td>
                    </tr>
                    <tr>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                        VAT
                      </td>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                        0%
                      </td>
                    </tr>
                    <tr>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                      Discount
                      </td>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                      <?php $discount_amt = find_a_field('sales_master','discount','s_no='.$sale_no);
                    echo number_format($discount_amt,2);?>
                      </td>
                    </tr>
                    <tr>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                        <strong>Grand Total</strong>
                      </td>
                      <td style="line-height: 22px; vertical-align: top; text-align:right; ">
                        <strong><?php echo number_format($sales_amt = $tot_amt-$discount_amt,2);?></strong>
                      </td>
                    </tr>
                   
                  </tbody>
                </table>
                <!-- /Table Total -->

              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>

										<div class="">
							<p>Amount in Word : (<? echo convertNumberMhafuz($sales_amt)?>)</p>
									</div>
									</div>
								</div>
							</div>
							<!-- Row end -->
						</div>
						<br>
						
						<hr>
						<div>
<p><strong>TERMS & CONDITION:</strong></p>
<p style="font-size:12px">1. The warranty will be void if there is any physical damage or the warranty sticker removed.<br>
2. At least 7 days have to give us time for warranty product.<br>
3. Burn, Broken and Software don't have any warranty.<br>
4. Swollen, water damage & burn batteries are void of warranty. <br>
5. Products once sold are not refundable.<br>
6. Advance Payment Non-refundable
</p>

</div>

						
					</div>
					
				</div>
			</div>
		</div>
	</div>
						
</div>




 <div class="row pt-5 text-center">
					<div class="col-4">
						<br><br><br><br><br>
						<hr class="w-50">
						<p>Order Received By</p>
					</div>
					<div class="col-4">
						
						<br><br><br><br><br>
						<hr class="w-50">
						<p>Order Placed By</p>
					</div>
					<div class="col-4">
						
						<br><br><br><br><br>
						<hr class="w-50">
						<p>Order Authorized By</p>
					</div>
 </div>

</body>
</html>