<table class="invoiceHeader" style="width:100%">
	<tr>
		<td colspan="10" align="center" style="font-size: 20px">Tax Invoice</td>
	</tr>
	<tr>
		<td colspan="5" style="vertical-align: top">
			<div>
				<barcode code="<?php echo str_replace(',', '', $order['customer_order_id']); ?>" type="C39" size="0.5" height="2.0" />
				<br>
				Order No : <?php echo $order['customer_order_id']; ?>
			</div>
		</td>
		<td colspan="5" style="text-align: right">
			<?php if ($order['docket_number'] != '') { ?>
				<div>
					<barcode code="<?php echo $order['docket_number']; ?>" type="C39" size="0.5" height="2.0" />
					<br>
					Docket Number : <?php echo $order['docket_number']; ?>
					<br>
				</div>
			<?php } ?>
			<strong>Invoice No: </strong><?php echo $order['invoice_number']; ?><br />
			<strong>Invoice Date: </strong><?php echo $order['invoice_date']; ?>
		</td>
	</tr>
	<tr>
		<td colspan="10" valign="top" class="">
			<strong><?php echo $company['name']; ?></strong><br />
			<img src="<?php echo $company['logo_img']; ?>" style="max-width: none;max-height: 40px;margin: 7px 0px;" />
		</td>
	</tr>
	<tr>
		<td colspan="5" class="height"><strong>Sold By:</strong><br />
			<?php echo $branch['address']; ?>
			<br />
            <p>
                <?php if(!empty($branch['phone']) || !empty($branch['tel_no'])) { ?>
                    Tel No.: <?php echo !empty($branch['phone']) ? $branch['phone'] : ''; ?><?php echo !empty($branch['tel_no']) ? ', '.$branch['tel_no'] : ''; ?>, <br>
                <?php  } ?>
                <?php if(!empty($branch['email'])) { ?>
                    E-mail: <?php echo $branch['email']; ?>, <br />
                <?php  } ?>    
                <?php if(!empty($company['website'])) { ?>
                    Website: <?php echo $company['website']; ?>
                <?php  } ?>    
			</p>
		</td>
		<td colspan="5" class=" " style="text-align: right; "><strong> Billing Address:</strong><br />
			<?php echo $customer['customer_name']; ?> <br />
			<?php if ($order['same_as_shipping'] == 1) { ?>
				<?php echo $customer['address']; ?>
				<br /> <?php echo $customer['address_city_name']; ?><br />
				<?php echo $customer['address_state_name']; ?> - <?php echo $customer['address_pincode']; ?>
			<?php } else {
				$CustomerBillingAddress = (array) json_decode($order['customer_billing_address']);
				echo (isset($CustomerBillingAddress['billing_address'])) ? $CustomerBillingAddress['billing_address'] : '';
				echo "<br>";
				echo (isset($CustomerBillingAddress['address_city'])) ? $CustomerBillingAddress['address_city'] : '';
				echo "<br>";
				echo (isset($CustomerBillingAddress['address_state'])) ? $CustomerBillingAddress['address_state'] : '';
				echo '-' . (isset($CustomerBillingAddress['billing_pincode'])) ? $CustomerBillingAddress['billing_pincode'] : '';
			} ?>
		</td>
	</tr>
	<tr>
		<td colspan="5" class=" height"><strong>PAN No:</strong> <?php echo $branch['pan_no']; ?><br />
			<strong>GST Registration No:</strong> <?php echo $branch['gstin']; ?><br />
		</td>
		<td colspan="5" class=" " style="text-align: right;"><strong>Shipping Address:</strong><br />
			<?php echo $customer['customer_name']; ?> <br />
			<?php echo $customer['address']; ?>
			<br /> <?php echo $customer['address_city_name']; ?><br />
			<?php echo $customer['address_state_name']; ?> - <?php echo $customer['address_pincode']; ?><br />
			<strong>GST Number:</strong><br /> <?php echo $customer['gst']; ?>
		</td>
	</tr>
	<tr>
		<td colspan="5" class=" " style="font-size: ;"><strong>Order Number:</strong> <?php echo  $order['customer_order_id']; ?><br />
			Order Date: <?php echo  $order['booking_date']; ?>
		</td>
		<td colspan="5" class=" " style="text-align: right;">
			<!-- <strong>Invoice Details: </strong><?php echo $order['customer_order_id']; ?><br/>
		                   <strong>Invoice Date: </strong><?php echo $order['invoice_date']; ?> -->
		</td>
	</tr>
</table>
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>public/css/pdfs.css" />

<table id="invoice" class="invoiceContent" style="width:100%; border-collapse: collapse; border:1px solid">
	<tr>
		<th width="30" rowspan="2">S. No.</th>
		<th rowspan="2" style="text-align:Left;">Description</th>
		<th rowspan="2">Unit Price</th>
		<th rowspan="2">Taxable</th>
		<th width="60" rowspan="2">Qty</th>
		<th width="60" rowspan="2">HSN/SAC</th>

		<?php foreach ($tax_list as $tax) { ?>
			<th colspan="2"><?php echo $tax; ?></th>
		<?php } ?>
		<th width="80" rowspan="2">Total Taxable</th>
		<th width="" rowspan="2">Discount</th>
		<th width="" rowspan="2">Discount Amt</th>
		<th rowspan="2">Net Amount</th>
	</tr>
	<tr>
		<?php foreach ($tax_list as $tax) {
			$tax = 0; ?>
			<th>Rate</th>
			<th>Amount</th>
		<?php } ?>
	</tr>
	<?php $i = 1;
	$ttlQty = 0;
	$totalGrossAount = 0;
	$totalRate = 0;
	$TotalTaxAmount = array();
	foreach ($order_item_list as $item) {

		$totalAmount = $item['amount'];
		$totalRate = $totalRate + $item['rate'];
	?>
		<tr>
			<td><?php echo $i; ?></td>
			<td><strong><?php echo $item['item_name']; ?></strong> </td>
			<td><?php echo $item['mrp']; ?></td>
			<td><?php echo $item['rate']; ?></td>

			<td><?php echo $item['qty'] . ' ' . json_decode($item['item_detail'])->unit; ?></td>
			<td><?php echo $item['hsn_code']; ?></td>

			<?php foreach ($tax_list as $tax_id => $tax) { ?>
				<td class="">
					<?php
					$taxRate = '0.00';
					$taxAmount = '0.00';
					if (isset($tax_item_list[$item['item_id']][$tax_id])) {
						$tax_percentage = $tax_item_list[$item['item_id']][$tax_id]['tax_percentage'];
						$taxRate = $tax_percentage;
						$taxAmount = round($item['amount'] * $tax_percentage / 100, 2);
						$totalAmount = $totalAmount + $taxAmount;
						$taxSin = (isset($TotalTaxAmount[$tax_id])) ? $TotalTaxAmount[$tax_id] : 0;
						$TotalTaxAmount[$tax_id] = $taxAmount + $taxSin;
					}
					echo sprintf("%.2f", $taxRate) ?>%
				</td>
				<td class="">
					<?php echo   sprintf("%.2f", $taxAmount) ?>
				</td>


			<?php } ?>
			<td><?php echo sprintf("%.2f", $item['amount']); ?></td>
			<td class="">
				<?php echo ($item['discount_type'] == 1) ? ("$item[discount] %") : "Rs $item[discount]"; ?>
			</td>
			<td class=""><?php echo $item['discount_amount']; ?></td>

			<td><?php echo $totalAmount; ?></td>
		</tr>
	<?php
		$ttlQty += $item['qty'];
		$i++;
		$totalGrossAount += $totalAmount;
	}
	?>
	<tr>
		<td colspan="3" align="right"><strong>Total</strong></td>
		<td><?php echo sprintf("%.2f", $totalRate); ?></td>
		<td><?php echo sprintf("%.2f", $ttlQty); ?> pcs</td>
		<td></td>
		<?php foreach ($tax_list as $tax_id => $tax) { ?>
			<td></td>
			<td><?php echo sprintf("%.2f", (isset($TotalTaxAmount[$tax_id])) ? $TotalTaxAmount[$tax_id] : 0); ?></td>
		<?php } ?>
		<td><?php echo $order['gross_amt']; ?></td>
		<td></td>
		<td><?php echo $order['discount_amt']; ?></td>
		<td><?php echo  $totalGrossAount; ?></td>

	</tr>
	<tr>
		<?php $colspan  = 9; ?>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Advance Payment</strong></td>
		<td align="right"><strong>- <?php echo $order['advance_payment']; ?></strong></td>
	</tr>
	<tr>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Total Tax</strong></td>
		<td align="right"><strong><?php echo $order['tax_amt']; ?></strong></td>
	</tr>


	<!-- <tr>
							<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Total Discount</strong></td>
							<td align="right"><strong><?php echo $order['discount_amt']; ?></strong></td>
							</tr> -->
	<tr>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong> Discount</strong></td>
		<td align="right">-<strong><?php echo $order['additional_discount']; ?></strong></td>
	</tr>
	<?php if (isset($order['vpp_disc_amt']) && $order['vpp_disc_amt'] > 0) {
		$order['net_amt'] = sprintf('%.2f', $order['net_amt'] + $order['vpp_disc_amt']);

	?>
		<!-- <tr>
			<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong> VPP Discount</strong></td>
			<td align="right">-<strong><?php echo $order['vpp_disc_amt']; ?></strong></td>
		</tr> -->
	<?php } ?>
	<tr>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Round Off</strong></td>
		<td align="right"><strong>+/-<?php echo $order['round_off_amt']; ?></strong></td>
	</tr>
	<tr>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Courier Charges</strong></td>
		<td align="right"><strong>+<?php echo $order['courier_charges']; ?></strong></td>
	</tr>
	<tr>
		<td colspan="<?php echo $colspan + (count($tax_list) * 2); ?>" align="right"><strong>Grand Total</strong></td>
		<td align="right"><strong><?php echo $order['net_amt']; ?></strong></td>
	</tr>
</table>
<table class="invoiceFooter invo" cellspacing="0" style="border-left:1px solid;border-right:1px solid;margin-top:0;">
	<tr>
		<td colspan="8" class="amout">
			<strong style="font-size:10px;">Amount in Words:</strong>
		</td>
	</tr>
	<tr>
		<td colspan="8" class="bbr"> <strong style="font-size:10px;">
				<?php echo getInWordAmnt($order['net_amt']); ?> ONLY
			</strong>
		</td>
	</tr>
	<tr>
		<td colspan="6" class="auth tbr" align="left">
			<?php echo $branch['invoice_remarks']; ?>
		</td>
		<td colspan="2" class="auth tbr">
			<strong>For <?php echo $company['name']; ?>:</strong>
			<br />
			<?php if(!empty($branch['sign_img_path'])) {?>
			<img src="<?php echo base_url($branch['sign_img_path']); ?>" style="float:right;height:30px;vertical-align: middle;padding:10px;max-width: 120px;" />
			<br />
			<?php } ?>
			<strong>Authorized Signatory</strong>
		</td>
	</tr>
</table>