<?php $this->load->view("common/header");
?>
<style>
	p {
		margin: 0 0 0px;
	}
</style>
<body>
	<div class="" style="text-transform: uppercase;"> 
		<div style="page-break-after:always;">
			<div class=" text-center">
				<?php /* ?>
				<br>
				<img src="<?php echo base_url('thems/images/golden_lanka.png'); ?>" width="100px" style="margin-top:-6px;" height="60px"/><br>
				 <?php */ ?>
				<h4>
					<?php $inv_name = $warehouse_details['name'];
					echo $inv_name; ?>
				</h4>
				<!-- 
            <img alt="logo" src="<?php //echo asset_url(); 
									?>images/logo_print.png" style="margin-top: 1px;width: 100px;"> -->
				<p style="font-size:13px ; margin: 0px">
					<?php echo  $warehouse_details['address'] ?>
				</p>
				<?php  //if($get_warehouse[0]->email) echo $get_warehouse[0]->email."<br>"; 
				?>
				<?php if ($warehouse_details['phone']) echo "<span style=\"font-weight:bold; font-size:15px\">" . $warehouse_details['phone'] . "</span><br>"; ?>

				<img style="padding-right:10px" src="<?php echo base_url() . 'products/gen_barcode?code=' . $sale_details['sale_reference_no'] . '&height=30'; ?>" alt='<?php echo $sale_details['sale_reference_no']; ?>' />
			</div>
			<!--col-xs-12-->
			<div>
				<div>
					<div > <?php /* ?>
						<p style="margin-bottom: 0px">Reg.No :
							<?php echo $warehouse_details['reg_no'] ?> </p><?php */ ?>
						<p id="bill_date" style="margin-bottom: 0px">Date:
							<?php echo display_date_time_format($sale_details['sale_datetime']); ?> </p>
					</div>
					<div >
					</div>
				</div>
				<div class="">
					<div class="">
						<p id="bill_no" style="font-weight:bold; margin-bottom: 0px">Bill No: <?php echo $sale_details['sale_reference_no']; ?> </p>
						<p style="margin-bottom:0px;">Cashier :
							<?php echo $sale_details['user_first_name'] ?>
						</p>
					</div>
					<div class="">
					</div>
				</div>
				<div class="">
					<div class="">
						<p style="" id="bill_customer">Customer:
							<?php echo $customer_details['cus_name'] ?>
							| <?php echo $customer_details['cus_phone'] ?>
							<br>
							Delivery Address:<?php echo $customer_details['cus_address'] ?>
						</p>
					</div>
				</div>
			</div>
			<div>
				<!--class="col-md-12"-->
				<table id="bill_table" class="print-table" style="width:100%">
					<thead style="">
						<tr class="report_view_th text-center" style="border-bottom: dashed 1px">
							<th style="width:5%" class="text-center">*</th>
							<th style="width:40%">Item</th>
							<th style="width:15%" class="text-right">Qty</th>
							<th style="width:15%" class="text-right">Price</th>
							<th style="width:15%" class="text-center">Discount</th>
							<th style="text-align:right"> Amount</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$tmpcount = 0;
						$tot_qty = 0;
						$g_total = 0;
						foreach ($sale_item_list as $row) {
							$tmpcount++;
							$tot_qty = $tot_qty + $row['quantity'];
							$g_total += $row['gross_total'] - $row['discount_val'];
						?>
							<!--any exchange should be done within seven days-->
							<tr style="border-top: dashed;">
								<td style="text-align:left; vertical-align:middle; ">
									<?php echo $tmpcount ?>)
								</td>
								<td style="" colspan="5">
									<?php echo $row['product_name']; ?>
								</td>
							</tr>
							<tr style="border-bottom: dashed;">
								<td colspan="3" style="text-align:right; vertical-align:middle; padding-right:10px; ">
									<strong style="font-size:16px">
										<?php echo number_format($row['quantity'], 2, '.', ','); ?>
									</strong>
								</td>
								<td style="text-align:right; width:100px; ">
									<?php echo number_format($row['unit_price'], 2, '.', ','); ?>
								</td>
								<td style="width: 100px; text-align:right; vertical-align:middle; padding-right:10px;">
									<?php echo number_format($row['discount_val'], 2, '.', ',') ?>
								</td>
								<td style="text-align:right; width:120px; ">
									<?php echo $row['gross_total'] - $row['discount_val']; ?> </td>
							</tr>
						<?php } ?>
						<tr style="display:none">
							<td style="text-align:center; width:40px; vertical-align:middle;font-weight:bold; font-size:16px">*</td>
							<td style="vertical-align:middle;font-weight:bold; font-size:15px">&nbsp;</td>
							<td style="width: 80px; text-align:center; vertical-align:middle;font-weight:bold; font-size:15px">&nbsp;</td>
							<td style="text-align:right; width:100px;">&nbsp;</td>
							<td style="text-align:right; width:120px; padding-right:10px;">&nbsp;</td>
						</tr>
						<tr style="border-top: dashed 1px">
							<td style="" colspan="5">SubTotal</td>
							<td style="text-align:right; " class="td_sub_total">
								<?php echo number_format($g_total, 2, '.', ',') ?>
							</td>
						</tr>
						<?php if($sale_details['sale_inv_discount_amount'] > 0){ ?>
						<tr style="text-align:left; font-weight:bold;">
							<td colspan="5">Order Discount</td>
							<td style="text-align:right;  border-bottom:solid 1px #000000" id="td_order_discount">
								<?php echo number_format($sale_details['sale_inv_discount_amount'], 2, '.', ',') ?>
							</td>
						</tr>
						<?php } ?>
						<?php if($sale_details['delivery_charge'] > 0){ ?>
						<tr>
							<td style="text-align:left;" colspan="5">Delivery Charges</td>
							<td style="text-align:right;  border-bottom:solid 1px #000000" id="td_order_discount">
								<?php echo number_format($sale_details['delivery_charge'], 2, '.', ',') ?>
							</td>
						</tr>
						<?php } ?>
						<?php if ($sale_details['cr_interest_amt'] > 0) { ?>
							<tr>
								<td style="text-align:left;" colspan="5">CC Interest Charges</td>
								<td style="text-align:right;  border-bottom:solid 1px #000000" id="td_order_discount">
									<?php echo number_format($sale_details['cr_interest_amt'], 2, '.', ',') ?>
								</td>
							</tr>
						<?php } ?>
						<tr>
							<td style="font-size:16px" colspan="5">Total Amount:</td>
							<td style="text-align:right;  font-size:16px;  border-bottom:4px double #000;" id="print_bill_total">
								<?php echo number_format($g_total - $sale_details['sale_inv_discount_amount'] + $sale_details['delivery_charge'] + $sale_details['cr_interest_amt'], 2, '.', ',') ?>
							</td>
						</tr>
						<tr>
						    <td colspan="5">
						        Paid By
						    </td><td></td>
						</tr>
						    <!--sale_pymnt_date_time-->
						    <!--sale_pymnt_amount-->
						    <?php
    						if(!empty($sale_payments_list)){
    						    echo "";
    						    foreach($sale_payments_list as $pmt){
    						        echo '<tr><td colspan="5">&nbsp;&nbsp;*'.(($pmt->sale_pymnt_paying_by == 'gift_card')?'invoice return':$pmt->sale_pymnt_paying_by).'</td>
    						              <td style="text-align:right;  border-bottom:solid 1px #000000">'.number_format($pmt->sale_pymnt_amount, 2, '.', ',').'</td></tr>';
    						    }
    						    echo "";
    						}
    						?>
						<tr>
						    <td colspan="5">
						        Total Paid Amount
						    </td>
						    <td class="text-right">
						        <?php echo number_format($sale_details['total_paid'],2,'.',','); ?>
						    </td>
						</tr>
						<?php if ($sale_details['sale_given_amount'] > 0) { ?>
							<tr>
								<td colspan="5">Total Given Amount </td>
								<td class="text-right" style="border-bottom:0px double #000;">
									<p style="" id="td_balance_amount"><?php echo number_format($sale_details['sale_given_amount'], 2, '.', ',') ?></p>
								</td>
							</tr>
							<tr style="">
								<td style="font-size:16px;" colspan="5">Balance </td>
								<td style="  border-bottom:0px double #000;text-align:right;">
									<p style="font-size:16px;margin: 0px;" id="td_balance_amount"><?php echo number_format($sale_details['sale_given_amount'] - ($g_total - $sale_details['sale_inv_discount_amount'] + $sale_details['delivery_charge'] + $sale_details['cr_interest_amt']), 2, '.', ',') ?></p>
								</td>
							</tr>
						<?php } else { ?>

							<tr style="">
								<td style="font-size:16px;" colspan="5">Payment Balance </td>
								<td style="  border-bottom:0px double #000;text-align:right;">
									<p style="font-size:16px;margin: 0px;" id="td_balance_amount"><?php echo number_format($g_total + $sale_details['delivery_charge'] - $sale_details['sale_given_amount'] - $sale_details['sale_inv_discount_amount'], 2, '.', ',') ?></p>
								</td>
							</tr>
						<?php } ?>
					</tbody>
				</table>
			</div>
			<?php if ($sale_details['price_type'] == "retail_credit") { ?>
				<!--start carrier details-->
				<div class="col-xs-12 row">
					<div style="text-align: left;" class="carrier_details">
						Driver
						<div class="row">
							<div class="col-xs-3"> On cash:</div>
							<div class="col-xs-9" style="border-bottom:dashed;min-height: 20px;"></div>
						</div>
						<div class="row">
							<div class="col-xs-3"> Name:</div>
							<div class="col-xs-9" style="border-bottom:dashed;min-height: 20px;"></div>
						</div><br />
						<span style="text-align:center">Carrier Details</span>
						<div class="col-md-12">
							<div class="col-xs-2"> Name:</div>
							<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>

							<!--<div class="col-xs-2"> NIC:</div>-->
							<!--<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>-->
							<div class="col-xs-2"> Mobile:</div>
							<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>
							<div class="col-xs-2"> Signature:</div>
							<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>
							<!--<div class="col-xs-2"> Driver Name:</div>-->
							<!--<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>-->
							<!--<div class="col-xs-2"> Driver On Cash:</div>-->
							<!--<div class="col-xs-10" style="border-bottom:dashed;min-height: 20px;"></div>-->
						</div>
					</div>
				</div>
			<?php } ?>
			<div style="text-align: center; font-size: 12px;">භාන්ඩයක් මාරු කරන විට දින 7ක් තුල බිල රැගෙන ඒම අනිවාර්ය වේ.(ආපසු මුදල් ගෙවීමක් සිදු නොකෙරේ) <br />
			</div>
			<div style="text-align: center">
				<h4 style="margin-top: 1px">~~~Thank You~~~</h4>
			</div>
			<!--start stn-->
			<?php
			foreach ($stn_list as $key => $rw) {
				//echo "<pre>";
				//print_r($rw);
				$stni = $this->Store_Notes_Model->get_store_note_items($rw['warehouse_id'], $rw['stn_no']);
				//print_r($stni);
				//echo "</pre>";
			?>
				<div style="page-break-before:always;page-break-after:auto;" class="" id="del_list_div">
					<table id="del_list" class="print-table" style="width:100%;">
						<thead style="border-bottom:dashed 2px;border-top:dashed 2px">
							<tr class="report_view_th text-center">
								<th class="text-center" colspan="4">
									<h4 style="margin-top: 5px; text-align:center"><?php echo $rw['name'] ?></h4>
									<h4><?php echo $rw['stn_code'] ?></h4>
									<p style="text-align:left">Bill No: <?php echo $sale_details['sale_reference_no']; ?></p>
									<p style="text-align:left;font-weight:normal" class="bill_customer">Customer:
										<?php echo $customer_details['cus_name'] ?>
										| <?php echo $customer_details['cus_phone'] ?>
										<br>Date:
										<?php echo display_date_time_format($sale_details['sale_datetime']); ?>
										<br>
										Delivery Address:<?php echo $customer_details['cus_address'] ?>


										<?php if ($sale_details['sale_given_amount'] > 0) { ?>
									<p style="text-align:left;">Balance :<?php echo number_format($sale_details['sale_given_amount'] - ($g_total - $sale_details['sale_inv_discount_amount'] + $sale_details['delivery_charge']), 2, '.', ',') ?>
									<?php } else { ?>
									<p style="text-align:left;">Payment Balance :<?php echo number_format($g_total + $sale_details['delivery_charge'] - $sale_details['sale_given_amount'] - $sale_details['sale_inv_discount_amount'], 2, '.', ',') ?>
									<?php } ?>
									<br>Delivery charges:<?php echo number_format($sale_details['delivery_charge'], 2, '.', ',') ?>
									</p>
									<p style="text-align:left" class="delivery_address_text" style="display:none;text-align:left"></p>
									<p style="text-align:left">Cashier :<?php echo $sale_details['user_first_name'] ?></p>
								</th>
							</tr>
							<tr class="report_view_th text-center">
								<th style="width:5%" class="text-center">*</th>
								<th style="width:30%">Item</th>
								<th style="width:15%" class="text-center">Qty</th>
								<th style="width:15%" class="text-center">Collected</th>
							</tr>
							<?php
							$num = 0;
							foreach ($stni as $stn) {
							?>
								<tr>
									<td>*</td>
									<td><?php echo $stn['product_name']; ?></td>
									<td class="text-center"><?php echo $stn['quantity']; ?></td>
									<td class="text-center"><input type="checkbox" /></td>
								</tr>
							<?php
							}
							?>
						</thead>
					</table>
					<div style="text-align: center; padding-top:100px;">
						<div class="col-md-12" style="padding-top:20px;"> ................<br>Cashier Sign</div>
						<div class="col-md-12" style="padding-top:20px;"> ................<br>Stock Keeper Sign</div>
					</div>
				</div>
			<?php
			}
			?>
		</div>
	</div>
	<script>
		window.onafterprint = window.close;
		<?php if ($this->session->userdata("ss_user_id") != 1) { ?>
			//setTimeout(function(){
			window.print();
			//},200);
		<?php } ?>
	</script>
</body>