<?php
if (is_logged_in()) {
} else {
	redirect(base_url(), 'refresh');
	exit();
}
?>
<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title><?php echo (ENVIRONMENT !== 'production') ? ENVIRONMENT . '-' : '*'; ?>POS Module | Stock Manager Advance</title>
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/css/perfect-scrollbar.min.css" />
	<script src="<?php echo asset_url(); ?>pos/js/moment.min.js"></script>
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/css/bootstrap.min.css">
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/plugins/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/css/style.css" type="text/css" />
	<link rel="stylesheet" href="<?php echo asset_url(); ?>css/bar.1.3.css" type="text/css" />
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/css/jquery-ui.css" type="text/css" />
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/plugins/select2/select2.css">
	<!--<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/plugins/iCheck/skins/all.css">-->
	<!--<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/plugins/gritter/css/jquery.gritter.css" type="text/css">-->
	<link rel="stylesheet" href="<?php echo asset_url(); ?>pos/css/print_pos.css" type="text/css" media="print" />
	<style>
		@font-face {
			font-family: Ubuntu;
			font-style: normal;
			font-weight: 700;
			src: local("Ubuntu Bold"), local("Ubuntu-Bold"),
				url("<?php echo asset_url();	?>fonts/trnbTfqisuuhRVI3i45C5w.woff") format("woff");
		}

		.h1,
		.h2,
		.h3,
		.h4,
		.h5,
		.h6,
		body,
		h1,
		h2,
		h3,
		h4,
		h5,
		h6 {
			font-family: Ubuntu, sans-serif;
		}

		.hide_me {
			visibility: hidden;
		}

		.modal.fade.in {
			top: 4%;
		}

		.btn-round-xs {
			border-radius: 11px;
			padding-left: 10px;
			padding-right: 10px;
		}

		#makeMeScrollable {
			width: 100%;
			position: relative;
			clear: both;
		}

		#add_item {
			background: right no-repeat;
			padding-right: 17px;
		}

		.select2-container .select2-choice .select2-arrow {
			background-image: none !important;
			width: 28px !important;
			text-align: center;
			padding-top: 0;
		}

		.select2-container .select2-choice .select2-arrow b {
			background: 0 0 !important;
			display: block;
			height: 100%;
			width: 100%;
		}

		.select2-container .select2-choice .select2-arrow b:before {
			content: "\f078";
			display: inline;
			font-family: FontAwesome;
			font-weight: 300;
			height: auto;
			text-shadow: none;
		}

		.select2-dropdown-open.select2-container-active .select2-choice .select2-arrow b:before {
			content: "\f077";
		}

		.select2-container-multi .select2-choices {
			background-image: none !important;
			background-color: #fff !important;
		}

		body {
			font-size: 13px;
			min-width: 1300px;
			overflow-x: scroll;
		}

		.input-group-addon {
			text-align: left;
			background-color: inherit;
		}

		#s2id_poscustomer {
			border-left: 0;
			background-color: inherit;
			border-top: 0 none;
		}

		#cpinner {
			width: 100%;
		}

		.tab-green>li.active>a,
		.tab-green>li.active>a:focus,
		.tab-green>li.active>a:hover {
			border-color: #3d9400 #ddd transparent;
			border-top: 2px solid #3d9400;
		}

		.tab-green>li>a:hover {
			color: #3d9400;
		}

		.tab-green>li.dropdown.open.active>a:focus,
		.tab-green>li.dropdown.open.active>a:hover,
		.tab-green>li.open .dropdown-toggle {
			background-color: #3d9400;
			border-color: #3d9400;
			color: #fff;
		}

		.tab-green .active>a,
		.tab-green .active>a:focus,
		.tab-green .active>a:hover,
		.tab-green .dropdown-menu>li>a:focus,
		.tab-green .dropdown-menu>li>a:hover {
			background-color: #3d9400;
		}

		body .modal {
			width: auto !important;
		}

		#ajaxproducts {
			height: 100%;
			width: 100%;
			overflow: hidden;
		}

		#item-list {
			width: 100%;
			height: 100%;
			overflow-y: scroll;
			padding-right: 17px;
			margin-bottom: -17px;
			box-sizing: content-box;
		}

		.home-fer_btn {
			font-weight: 700;
			font-size: 19px;
			height: 120px;
			min-width: 208px;
			max-width: 180px;
			width: 290px;
			text-transform: uppercase;
			font-family: sans-serif;
		}

		.cal-wap button {
			width: 80px;
			height: 80px;
			font-size: 40px;
			margin: 5px;
			background-color: #orange;
			border-radius: 17px;
		}

		.amount-wap button {
			width: 97px;
			height: 55px;
			font-size: 35px;
			margin: 3px;
		}

		.amount-wap {
			margin-top: 20px;
		}

		.form-control {
			padding: 0;
		}

		.form-control.input-sm {
			font-size: 14px;
			height: 47px;
			line-height: 16px;
			padding: 3px;
			font-size: 16px;
		}

		.table-row-input {
			background-color: inherit;
			border: none;
			max-width: 190px;
		}

		.table-condensed>tbody>tr>td,
		.table-condensed>tbody>tr>th,
		.table-condensed>tfoot>tr>td,
		.table-condensed>tfoot>tr>th,
		.table-condensed>thead>tr>td,
		.table-condensed>thead>tr>th {
			padding: 3px;
		}

		.dinmic {
			cursor: pointer;
		}

		.srh {
			float: right;
		}

		.icon img {
			margin-left: 12px;
			margin-right: 12px;
		}
	</style>
	<!--cpinner-->
	<style>
		* {
			box-sizing: border-box;
		}

		#srh_pro_name {
			background-image: url('/css/searchicon.png');
			background-position: 10px 10px;
			background-repeat: no-repeat;
			width: 100%;
			font-size: 16px;
			padding: 12px 20px 12px 40px;
			border: 1px solid #ddd;
			margin-bottom: 12px;
		}

		#products_table {
			border-collapse: collapse;
			width: 100%;
			border: 1px solid #ddd;
			font-size: 13px;
		}

		#products_table th,
		#products_table td {
			text-align: left;
			padding: 2px;
		}

		#products_table tr {
			border-bottom: 1px solid #ddd;
		}

		#products_table tr.header,
		#products_table tr:hover {
			background-color: #f1f1f1;
		}
	</style>
	<!--view bill model-->
	<style>
		p {
			line-height: 0.9;
		}

		p {
			margin: 0 0 2px;
		}
	</style>
</head>

<body>
	<noscript>
		<div class="global-site-notice noscript">
			<div class="notice-inner">
				<p><strong>JavaScript seems to be disabled in your browser.</strong><br>
					You must have JavaScript enabled in
					your browser to utilize the functionality of this website. </p>
			</div>
		</div>
	</noscript>
	<!-- start navigation-->
	<header id="header" <?php /*?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">class="navbar"<?php */ ?>>
		<div class="container" style="background-color:#000">
			<?php /*?><a class="navbar-brand" href="#"><span class="logo">
               <span class="pos-logo-lg">Baker's Choice</span>
               <span class="pos-logo-md">Baker's Choice</span></span></a><?php */ ?>
			<div class="header-nav">
				<ul class="nav nav-tabs navbar-nav tab-green no-print" id="myTab3">
					<!-- <li class="active"> <a data-toggle="tab" href="#Sales" style="padding:10px">
          <?php if ($sale_id) echo 'EDIT SALE :' . $sale_details[0]['sale_reference_no'] . ' [' . $sale_id . ' ]';
			else echo ' NEW SALE' ?>
          </a> </li>
          -->
					<li class=""> <a target="_blank" href="<?php echo base_url("bar"); ?>" style="padding:10px">New Sale
						</a> </li>
					<li class=""> <a target="_blank" href="<?php echo base_url("dashboard"); ?>" style="padding:10px">Dashboard
						</a> </li>
					<li class=""> <a target="_blank" href="<?php echo base_url("products"); ?>" style="padding:10px">List Products
						</a> </li>
					<li class=""> <a target="_blank" href="<?php echo base_url("pos/hw_list"); ?>" style="padding:10px">List Sales
						</a> </li>

					<?php if (!$sale_id) { ?>
						<!-- <li> <a data-toggle="tab" href="#dine_in" style="padding:10px"><i class="fa fa-spoon"></i><i class="fa fa-circle-o"></i> Dine In </a> </li>
        <li> <a data-toggle="tab" href="#take_away" style="padding:10px"><i class="fa fa-money"></i> Take Away </a> </li>
        <li> <a data-toggle="tab" href="#delivery" style="padding:10px"><i class="fa fa-truck"></i> Delivery </a> </li>-->
						<li> <a data-toggle="tab" href="#add_product" style="padding:10px"><i class="fa fa-plus-square"></i> Add Product </a> </li>

						<li class=""> <a target="_blank" href="<?php echo base_url("hw_delivery/hw_list"); ?>" style="padding:10px">List store Note </a> </li>
						<li class=""> <input href="/sales_return/sales_return_pos/" style="margin: 6px 0px 0px 6px;" class="form-control" type="text" id="return_sale_id" placeholder=" Enter barcode here for return" /></li>
				</ul>
			<?php } ?>
			<ul class="nav navbar-nav pull-right">
				<li class="dropdown hidden-xs"> <a class="btn bred pos-tip" title="" data-placement="bottom" id="clearLS" href="#" data-original-title="Clear all locally saved data" tabindex="-1"> <i class="fa fa-eraser"></i> </a> </li>
				<li class="dropdown"> <a class="btn account dropdown-toggle" data-toggle="dropdown" href="#">
						<div class="user">
							<!--<img alt="" src="<?php echo image_url(); ?>/male.png" class="mini_avatar img-rounded">-->
							<span>Welcome! <?php echo $this->session->userdata['ss_user_first_name'] ?></span>
						</div>
					</a>
					<ul class="dropdown-menu pull-right">
						<li style="display:none"> <a href="#"> <i class="fa fa-user"></i> Profile </a> </li>
						<li style="display:none"> <a href="#"> <i class="fa fa-key"></i> Change Password </a> </li>
						<li class="divider" style="display:none"></li>
						<li> <a href="<?php echo base_url('logout'); ?>"> <i class="fa fa-sign-out"></i> Logout </a> </li>
						<li> <a href="<?php echo base_url('app_android/sales_print'); ?>" target="_blank" style="color:red;"> Pos Print </a> </li>
					</ul>
				</li>
			</ul>
			<ul class="nav navbar-nav pull-right">
				<li class="dropdown"> <a class="btn bblack" style="cursor: default;"><span id="display_time"></span></a> </li>
				<li class="dropdown hidden-sm"> <a class="btn pos-tip" title="" data-placement="bottom" href="#" data-toggle="modal" data-target="#sckModal" data-original-title="Shortcuts" tabindex="-1"> <i class="fa fa-key"></i> </a> </li>
				<li class="dropdown" style="display:none"> <a class="btn pos-tip" title="" data-placement="bottom" href="<?php echo base_url('pos/view_bill'); ?>" target="_blank" data-original-title="View Bill Screen" tabindex="-1"> <i class="fa fa-laptop"></i> </a> </li>
				<li class="dropdown"> <a class="btn byellow pos-tip" data-placement="bottom" href="<?php echo base_url('sales_return/custom'); ?>" target="new" data-original-title="Return" tabindex="-1"> <i class="fa fa-file"></i> </a></li>
				<li class="dropdown"> <a class="btn btn-info pos-tip" href="#" style="background:#15900c" data-original-title="STN" tabindex="-1" onClick="myFunction()"> <i class="fa fa-print"></i> </a></li>

				<button type="button" class="btn btn-danger" id="view_bill" tabindex="-1"> </button>

				<li class="dropdown"> <a class="btn bblue pos-tip" title="" data-placement="bottom" href="<?php echo base_url('dashboard'); ?>" target="new" data-original-title="Dashboard" tabindex="-1"> <i class="fa fa-dashboard"></i> </a> </li>
			</ul>
			</div>
		</div>
		<script>
			function myFunction() {
				var myWindow = window.open("<?php echo base_url('store_notes/all'); ?>", "stn", "width=1400,height=600");
			}
		</script>
	</header>

	<!--end navigation-->
	<div class=" panel-scroll" style="height:auto">
		<div class="tabbable tabs-top">
			<div class="tab-content">
				<div id="Sales" class="tab-pane active">
					<div class="table-responsive">
						<!-- panel one -->
						<form action="#" data-toggle="validator" role="form" id="pos-sale-form" name="pos-sale-form" method="post" accept-charset="utf-8">
							<div id="wrapper">
								<div id="loader" style="padding:15%; text-align:center; display:none"> <i class="fa fa-cog fa-spin fa-4x"></i> </div>
								<div id="content" style="background-color:#FFF">
									<div class="c1">
										<div class="pos">
											<div id="pos">
												<input type="hidden" name="token" value="<?php echo date("ydHms") . md5(uniqid(rand(), true)); ?> " style="display:none;" />
												<div id="leftdiv" class="ui-widget quick-menu">
													<div id="printhead">
														<h4 style="text-transform:uppercase;">Stock Manager Advance</h4>
														<h5 style="text-transform:uppercase;">Order List</h5>
														Date 31/12/2015 22:14
													</div>
													<div id="left-top" class="quick-menu">
														<div class="no-print">
															<div style="display:none" id="input_panel" class="form-group">
																<!--<select name="poswarehouse" id="poswarehouse" class="search-select" data-placeholder="Select Warehouse">-->
																<!--<option value="">-select-</option>-->
																<!--  <?php foreach ($get_warehouse as $value) { ?>-->
																<!--  <option value="<?php echo $value->id; ?>" <?php if ($this->session->userdata('ss_warehouse_id') == $value->id) echo 'selected' ?>><?php echo $value->name; ?> | <?php echo $value->code; ?></option>-->
																<!--  <?php } ?>-->
																<!--</select>-->
															</div>
															<!-- start sales term -->
															<div class="col-sm-12" style="padding: 0;">
																<div class="form-group" style="background-color:#FFF">
																	<div class="input-group">
																		<div class="col-sm-12"> <span class="col-sm-1" style="padding: 0;"> Sale Type:</span> <span class="col-sm-11" style="display: table">
																				<?php //print_r($invoice_type_list);
																				$checked = "";
																				foreach ($invoice_type_list as $in_type) {
																					if ($in_type['invoice_type_id'] == 2) continue;
																					$inv_type_name = $in_type['invoice_type_name'];
																					if ($inv_type_name == "CASH") {
																						$inv_type_name = "RETAIL";
																						$checked = "checked";
																					} else $checked = "";

																					echo "<label for=\"tp_" . $in_type['invoice_type_id'] . "\" class=\"" . $in_type['class_name'] . "\"  style=\"display:table-cell\">
														 	<input type=\"radio\" name=\"invoice_type\" id=\"tp_" . $in_type['invoice_type_id'] . "\" value=\"" . $in_type['invoice_type_id'] . "\" " . $checked . ">
																
														                " . $inv_type_name . "</label>";
																				}
																				?>
																			</span>
																		</div>
																		<div class="col-sm-12 pt_list"> <span class="col-sm-1" style="padding: 0;"> Price Type:</span> <span class="col-sm-11" style="display: table">
																				<label for="price_type_1" class="btn btn-success" style="display:table-cell">
																					<input type="radio" class="price_type" checked name="price_type" id="price_type_1" value="retail_cash" lable="cash">
																					CASH </label>
																				<label for="price_type_3" class="btn btn-warning" style="display:table-cell">
																					<input type="radio" class="price_type" name="price_type" id="price_type_3" value="retail_credit" lable="credit">
																					CREDIT </label>
																				<label for="price_type_2" class="btn btn-info" style="display:table-cell">
																					<input type="radio" class="price_type" name="price_type" id="price_type_2" value="retail_wholesale" lable="wholesale">
																					WHOLESALE </label>
																			</span>
																		</div>
																		<label for="credit" class="btn ">
																			<select id="broker_id" name="broker_id" class="form-control search-select" data-placeholder="Select Broker">
																				<option selected value="">Select Broker</option>
																				<?php foreach ($broker_list as $value) { ?>
																					<option value="<?php echo $value->broker_id; ?>"><?php echo $value->broker_name . ' / ' . $value->broker_contact_no; ?></option>
																				<?php } ?>
																			</select>
																		</label>
																	</div>
																</div>
															</div>
															<div class="col-sm-12" style="padding: 0">
																<div class="form-group" style="background-color:#FFF">
																	<div class="input-group">
																		<select style="margin-top:1px" id="poscustomer" name="poscustomer" class="search-select" data-placeholder="Select customer">
																			<!-- onChange="get_cus_tot_credit()"-->
																			<option value="1">walk-in</option>
																			<?php foreach ($get_customer as $value) { ?>
																				<option value="<?php echo $value->cus_id; ?>"><?php echo $value->cus_name . ' / ' . $value->cus_phone; ?></option>
																			<?php } ?>
																		</select>
																		<input name="base_url" type="hidden" id="base_url" value="<?php echo base_url(); ?>">
																		<input type="hidden" id="customer_mobile" value="" />
																		<div class="input-group-addon pos-tip btn" style="padding: 2px 8px; border-left: 0; height:34px" title="Add Customer" data-toggle="modal" data-target="#add_customer_model">
																			<i class="fa fa-plus-circle" id="addIcon" style="font-size: 1.2em;"></i>
																		</div>
																	</div>
																</div>
															</div>
															<div class="form-group" id="ui">
																<div class="input-group">
																	<div class="input-group-addon">
																		<label for="is_barcode">BARCODE</label>
																		<input type="checkbox" name="is_barcode" value="1" id="is_barcode">
																	</div>
																	<input type="text" name="add_item" value="" class="form-control pos-tip keyboard" id="add_item" data-placement="top" data-trigger="focus" style="background-color:#FFF" />
																	<!--title="Please start typing code/name for suggestions"-->
																	<div class="input-group-addon" style="padding: 2px 8px; border-left: 0;"><i class="fa fa-search" style="font-size: 1em;"></i> </div>
																</div>
																<div style="clear:both;"></div>
															</div>
														</div>
													</div>
													<div id="print" class="no-print">
														<div id="left-middle">
															<div id="product-list" class="ps-container ps-active-y">
																<table style="margin-bottom: 0;" id="posTable" class="table items table-striped table-bordered table-condensed table-hover">
																	<thead>
																		<tr>
																			<th style="width:1%">w1</th>
																			<th style="width:1%">w2</th>
																			<th style="width:1%">w3</th>
																			<th style="width:30%">Product</th>
																			<th style="width:10%">Price</th>
																			<th style="width:20%">Qty</th>
																			<th style="width:10%">Discount</th>
																			<th style="width:20%">Subtotal</th>
																			<th style="width: 10%; text-align: center;"><i style="opacity:0.5; filter:alpha(opacity=50);" class="fa fa-trash-o"></i></th>
																		</tr>
																	</thead>
																	<tbody>
																	</tbody>
																</table>
																<div style="clear:both;"></div>
																<div class="ps-scrollbar-x-rail" style="width: 436px; display: none; left: 0px; bottom: 3px;">
																	<div class="ps-scrollbar-x" style="left: 0px; width: 0px;"></div>
																</div>
																<div class="ps-scrollbar-y-rail" style="top: 0px; height: 319px; display: none; right: 3px;">
																	<div class="ps-scrollbar-y" style="top: 0px; height: 0px;"></div>
																</div>
															</div>
														</div>
														<div style="clear:both;"></div>
														<div id="left-bottom">
															<table style="width:100%; float:right; padding:5px; color:#000; background: #FFF;" id="totalTable">
																<tbody>
																	<tr>
																		<td style="padding: 5px 10px;border-top: 1px solid #DDD;">Items</td>
																		<td style="padding: 5px 10px;font-size: 14px; font-weight:bold; border-top: 1px solid #DDD;" class="text-right"><span id="titems">0</span></td>
																		<td style="padding: 5px 10px;border-top: 1px solid #DDD;">Total</td>
																		<td style="padding: 5px 10px;font-size: 14px; font-weight:bold; border-top: 1px solid #DDD;" class="text-right"><span id="total">0.00</span></td>
																	</tr>
																	<tr>
																		<td style="padding: 5px 10px;border-top: 1px solid #DDD;">Discount &nbsp;
																			<div class="pos-tip btn btn-default" title="Order Discount" data-toggle="modal" data-target="#dsModal">
																				<i class="fa fa-percent"></i>
																			</div>
																			<!--<a id="ppdiscount" href="#">  </a>-->
																		</td>
																		<td style="padding: 5px 10px;font-size: 14px; font-weight:bold; border-top: 1px solid #DDD;" class="text-right"><span id="tds">0.00</span></td>
																		<td style="padding: 5px 10px;border-top: 1px solid #DDD;">Delivery &nbsp;
																			<!--old-->
																			<!--<a href="#" id="pshipping"> <i class="fa fa-plus-square"></i> </a>-->
																			<!--new-->
																			<div class="pos-tip btn btn-default" title="Delivery Charges" id="pshipping">
																				<!--data-toggle="modal" data-target="#sModal"-->
																				<i class="fa fa-truck"></i>
																			</div>
																		</td>
																		<td style="padding: 5px 10px;font-size: 14px; font-weight:bold; border-top: 1px solid #DDD;" class="text-right"><span class=""><span id="tship">0.00</span></span></td>
																	</tr>
																	<tr>
																		<td colspan="1" style="padding: 5px 10px; border-top: 1px solid #666; font-weight:bold; background:#333; color:#FFF;">
																			<div>NO BILL</span>
																				<input type="checkbox" name="print_bill" value="1" id="print_bill" style="width:50px; float:left; margin-left:30px;" title="POS Bill ">
																			</div>
																			<div><span>STN</span>
																				<input type="checkbox" name="print_stn" value="1" id="print_stn" style="width:50px; float:left; margin-left:30px;" title="STN" checked>
																			</div>
																			<div><span>Delivery</span>
																				<input type="checkbox" name="print_del" value="1" id="print_del" style="width:50px; float:left; margin-left:30px;" title="DELI">
																			</div>

																			<!--Paying Amount :-->
																			<!--<input onkeyup="grand_total_cal()" type="text" name="cash_en" value="" class="form-control" id="cash_en" style="background-color:#FFF; height: 60px; font-size: 2.5em; width: 208px; text-align: right;" onClick=this.select()>-->
																		</td>
																		<td colspan="3" style="disbplay:none;padding:5px 10px 5px 10px; font-size: 14px;border-top: 1px solid #666; font-weight:bold; background:#333; color:#FFF;">

																			Total &nbsp;:<span id="gtotal" style=" font-size:25px">0.00</span> <br />
																			Balance &nbsp;:<span id="cash_balance" style="font-size:25px"></span>
																		</td>
																	</tr>
																</tbody>
															</table>
														</div>

														<input type="hidden" value="3" id="biller" name="biller">
														<div class="clearfix"></div>
														<div id="botbuttons" class="col-xs-12 text-center">
															<div class="row">
																<div class="col-xs-12" style="padding: 0;">
																	<div class="col-xs-12" style="padding: 0;">
																		<button type="button" class="btn btn-primary btn-block" id="payment" style="height:80px;" tabindex="-1"> <i class="fa fa-hand-paper-o" style="margin-right: 5px;"></i>SAVE INVOICE</button>
																	</div>
																	<div class="col-xs-12" style="padding: 0;">
																		<button type="button" class="btn btn-danger btn-block btn-flat cancel" id="reset" tabindex="-1" style="height:55px;"> Cancel </button>
																	</div>
																	<!--<div class="col-xs-6" style="padding: 0;">-->
																	<!--	<button type="button" class="btn btn-success btn-block" id="payment_" style="height:55px;" tabindex="-1"> <i class="fa fa-money" style="margin-right: 5px;"></i>Change Payment Type </button>-->
																	<!--</div>-->
																	<div class="col-xs-6" id="print_button_container"></div>
																</div>
															</div>
														</div>
														<div style="clear:both; height:5px;"></div>
														<div id="num">
															<div id="icon"></div>
														</div>
														<span id="hidesuspend"></span>
														<?php if ($sale_id) { ?>
															<input type="hidden" name="sale_id" id="sale_id" value="<?php echo $sale_id; ?>">
															<input type="hidden" name="sale_reference_no" id="sale_reference_no" value="<?php echo $sale_details[0]['sale_reference_no']; ?>">
														<?php } ?>
														<input type="hidden" name="posshipping" id="posshipping" value="0">
														<input type="hidden" name="shipping_address" id="shipping_address" value="">
														<input type="hidden" name="rowCount" id="rowCount" value="0">
														<input type="hidden" name="total_paid" id="total_paid" value="0">
														<!--keyboard input-->
														<input type="hidden" id="id-name" value="" />
														<!--end keyboard input-->
														<input type="hidden" name="sale_datetime" id="sale_datetime" value="0">
														<input type="hidden" name="discount" id="posdiscount" value="0">
														<input type="hidden" name="pos_discount_input1" id="pos_discount_input1" value="0">
														<!--<input type="hidden" name="pay_amount" id="pay_amount" value="" />
														<input type="hidden" name="balance_amount" id="balance_amount_1" value="" />-->
														<input type="hidden" name="grand_total" id="grand_total" value="">
														<input type="hidden" name="extra_charges" id="extra_charges" value="" />
														<input type="hidden" name="extra_charges_amount" id="extra_charges_amount" value="" />
														<input type="hidden" name="total_item_discount" id="total_item_discount" value="0" />
														<input type="hidden" name="total_cost_val" id="total_cost_val" value="0" />
														<input type="hidden" name="stnn1" id="stnn1" value="0" />
														<input type="hidden" name="stnn1_code" id="stnn1_code" value="0" />
														<input type="hidden" name="stnn1_wh" id="stnn1_wh" value="0" />
														<input type="hidden" name="stnn2" id="stnn2" value="0" />
														<input type="hidden" name="stnn2_code" id="stnn2_code" value="0" />
														<input type="hidden" name="stnn2_wh" id="stnn2_wh" value="0" />
														<input type="hidden" name="stnn3" id="stnn3" value="0" />
														<input type="hidden" name="stnn3_code" id="stnn3_code" value="0" />
														<input type="hidden" name="stnn3_wh" id="stnn3_wh" value="0" />
														<input type="hidden" name="cc_charges" id="cc_charges" value="0" />
														<?php /**/ ?>
														<input type="hidden" name="poswarehouse" id="poswarehouse" value="<?php echo $this->session->userdata('ss_warehouse_id') ?>" />
														<?php ?>

													</div>
												</div>
											</div>
											<div id="cp" style="float: right;width: 50%;">
												<div id="cpinner">
													<input type="text" id="srh_pro_name" onkeyup="search_products_ajax()" placeholder="Search for product" title="Search product">
													<div style="max-height:780px;overflow-y:scroll">
														<table id="products_table">

														</table>
													</div>
												</div>
												<div style="clear:both;"></div>
											</div>
											<div style="clear:both;"></div>
										</div>
									</div>
								</div>
							</div>
							<!--BILLING PART-->
							<div class="modal fade in" id="paymentModal" tabindex="-1" role="dialog" aria-labelledby="payModalLabel" aria-hidden="true">
								<div class="modal-dialog modal-lg">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" id="close" class="close" data-dismiss="modal" onClick="form_reset();"><span aria-hidden="true"><i class="fa fa-2x">&times;</i></span><span class="sr-only">Close</span></button>
											<h4 class="modal-title" id="payModalLabel">Finalize Sale</h4>
										</div>
										<div class="modal-body" id="payment_content">
											<div class="row">
												<div class="col-md-12 col-sm-12">
													<div class="clearfix"></div>
													<div id="payments">
														<div class="well well-sm well_1">
															<div class="payment">
																<div class="row">
																	<div class="col-sm-5">
																		<div class="form-group">
																			<label for="amount_1">Amount</label>
																			<input name="amount[]" type="text" id="amount_1" class="pa form-control kb-pad1 amount" />
																		</div>
																	</div>
																	<div class="col-sm-5 col-sm-offset-1">
																		<div class="form-group">
																			<label for="paid_by_1">Paying by</label>
																			<select name="paid_by[]" id="paid_by_1" class="form-control paid_by">
																				<option value="cash">Cash</option>
																				<option value="CC">Credit Card</option>
																				<option value="Cheque">Cheque</option>
																				<option value="deposit">Deposit</option>
																				<option value="gift_card">Return</option>
																				<!--<option value="other">Other</option>-->
																				<!--<option value="ppp">Paypal Pro</option>-->
																				<!--<option value="stripe">Stripe</option>-->
																				<!--<option value="authorize">Authorize.net</option>-->
																			</select>
																		</div>
																	</div>
																</div>
																<div class="row">
																	<div class="col-sm-11">
																		<div class="form-group gc_1" style="display: none;">
																			<label for="gift_card_no_1">Return Reference No</label>
																			<input name="paying_gift_card_no[]" type="text" id="gift_card_no_1" class="pa form-control kb-pad gift_card_no" />
																			<div id="gc_details_1"></div>
																		</div>
																		<div class="pcc_1" style="display:none;">
																			<div class="row">
																				<!--<input type="text" id="swipe_1" class="form-control swipe" placeholder="Swipe"/>-->
																				<div class="col-md-12">
																					<div class="form-group">
																						<label for="add_cc_1">Include CC Charges (3%)</label>
																						<input type="checkbox" id="add_cc_1" class="add_cc" style="margin:10px">
																					</div>
																				</div>
																			</div>
																			<div class="row">
																				<div class="col-md-6">
																					<div class="form-group">
																						<input name="cc_no[]" type="text" id="pcc_no_1" class="form-control" placeholder="Credit Card No" />
																					</div>
																				</div>
																				<div class="col-md-6">
																					<div class="form-group">

																						<input name="cc_holder[]" type="text" id="pcc_holder_1" class="form-control" placeholder="Holder Name" />
																					</div>
																				</div>
																				<div class="col-md-3">
																					<div class="form-group">
																						<select name="cc_type[]" id="pcc_type_1" class="form-control pcc_type" placeholder="Card Type">
																							<option value="Visa">Visa</option>
																							<option value="MasterCard">MasterCard</option>
																							<option value="Amex">Amex</option>
																							<option value="Discover">Discover</option>
																						</select>
																						<!-- <input type="text" id="pcc_type_1" class="form-control" placeholder="Card Type" />-->
																					</div>
																				</div>
																				<div class="col-md-3">
																					<div class="form-group">
																						<input name="cc_month[]" type="text" id="pcc_month_1" class="form-control" placeholder="Month" />
																					</div>
																				</div>
																				<div class="col-md-3">
																					<div class="form-group">
																						<input name="cc_year" type="text" id="pcc_year_1" class="form-control" placeholder="Year" />
																					</div>
																				</div>
																				<div class="col-md-3">
																					<div class="form-group">
																						<input name="cc_cvv2" type="text" id="pcc_cvv2_1" class="form-control" placeholder="Security Code" />
																					</div>
																				</div>
																			</div>
																		</div>
																		<div class="pcheque_1" style="display:none;">
																			<div class="form-group">
																				<label for="cheque_no_1">Cheque No</label>
																				<input name="cheque_no[]" type="text" id="cheque_no_1" class="form-control cheque_no" />
																			</div>
																			<div class="form-group">
																				<label for="cheque_date_1">Cheque Date</label>
																				<input name="cheque_date[]" type="date" id="cheque_date_1" class="form-control cheque_date" />
																			</div>
																		</div>
																		<div class="form-group">
																			<label for="payment_note">Payment Note</label> <textarea name="payment_note[]" id="payment_note_1" class="pa form-control kb-text payment_note"></textarea>
																		</div>
																	</div>
																</div>
															</div>
														</div>
													</div>
													<div id="multi-payment">

													</div>
													<button type="button" class="btn btn-warning col-md-12 addButton" style="border:solid 2px #050505;"><i class="fa fa-plus"></i> Add More Payments</button>
													<div style="clear:both; height:15px;"></div>
													<div class="font16">
														<table class="table table-bordered table-condensed table-striped" style="margin-bottom: 0;">
															<tbody>
																<tr>
																	<td width="25%">Total Items</td>
																	<td width="25%" class="text-right"><span id="item_count">0.00</span></td>
																	<td width="25%">Total Payable</td>
																	<td width="25%" class="text-right"><span id="twt">0.00</span></td>
																</tr>
																<tr>
																	<td>Total Paying</td>
																	<td class="text-right"><span id="total_paying">0.00</span></td>
																	<td>Balance</td>
																	<td class="text-right"><span id="balance">0.00</span></td>
																</tr>
															</tbody>
														</table>
														<div class="clearfix"></div>
													</div>
												</div>
											</div>
										</div>

										<!--<div class="modal-footer collapse">
											<button class="btn btn-block btn-lg btn-primary" id="submit-payment">SET</button>
										</div>
										<div class="modal-footer" id="submit_sale">
                                            <button class="btn btn-block btn-lg btn-primary" >SAVE SALE</button>
                                        </div>-->
										<div class="modal-footer">
											<a class="btn btn-block btn-lg btn-primary" id="submit-sale">SAVE SALE</a>
										</div>
									</div>
								</div>
							</div>
						</form>
						<div id="drawer"></div>
						<input type="hidden" id="cash_en_tot" value="0" readonly>
						<input type="hidden" id="qty_en_tot" value="">
						<input type="hidden" id="dis_en_tot" value="">
						<input type="hidden" id="last_qty_en_tot" value="">
						<input type="hidden" id="last_dis_en_tot" value="">
						<!--panel delivery-->
						<div class="modal fade in" id="sModal">
							<div class="modal-dialog modal-sm">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true" tabindex="-1"> <i class="fa fa-2x">×</i> </button>
										<h4 class="modal-title" id="sModalLabel">Delivery</h4>
									</div>
									<div class="modal-body">
										<div class="form-group">Delivery Charges
											<input name="shipping_input" value="" class="form-control kb-pad ui-keyboard-input ui-widget-content ui-corner-all ui-keyboard-autoaccepted" id="shipping_input" aria-haspopup="true" role="textbox" type="text">
										</div>
										<div class="form-group">Address
											<textarea name="address_input" class="form-control kb-pad ui-keyboard-input ui-widget-content ui-corner-all ui-keyboard-autoaccepted" id="address_input" aria-haspopup="true" role="textbox"> </textarea>
										</div>
									</div>
									<div class="modal-footer">
										<button type="button" id="updateShipping" class="btn btn-primary" tabindex="-1">Update</button>
									</div>
								</div>
							</div>
						</div>
						<!--end panel-->
						<!--new model for discount-->
						<div class="modal fade in" id="dsModal">
							<div class="modal-dialog modal-sm">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true" tabindex="-1"> <i class="fa fa-2x">×</i> </button>
										<h4 class="modal-title" id="sModalLabel">Order Discount</h4>
									</div>
									<div class="modal-body">
										<div class="form-group">
											<label for="order_discount_input">Order Discount</label>
											<input type="text" name="order_discount_input" value="" class="form-control" id="order_discount_input" />
										</div>
									</div>
									<div class="modal-footer">
										<button type="button" id="updateOrderDiscount" class="btn btn-primary" tabindex="-1">Update</button>
									</div>
								</div>
							</div>
						</div>
						<!--end new model for discount-->
						<!--start shortcut model-->
						<div class="modal fade in" id="sckModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">
												<i class="fa fa-2x">&times;</i></span><span class="sr-only">Close</span>
										</button>
										<button type="button" class="btn btn-xs btn-default no-print pull-right" style="margin-right:15px;" onclick="window.print();">
											<i class="fa fa-print"></i> Print </button>
										<h4 class="modal-title" id="mModalLabel">Shortcut Keys</h4>
									</div>
									<div class="modal-body" id="pr_popover_content">
										<table class="table table-bordered table-striped table-condensed table-hover" style="margin-bottom: 0px;">
											<thead>
												<tr>
													<th>Shortcut Keys</th>
													<th>Actions</th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td>Alt+1</td>
													<td>Select Dine In</td>
												</tr>
												<tr>
													<td>Alt+2</td>
													<td>Select Take Away</td>
												</tr>
												<tr>
													<td>Alt+3</td>
													<td>Select Delivery</td>
												</tr>
												<tr>
													<td>Alt+4</td>
													<td>Focus Add Items</td>
												</tr>
												<tr>
													<td>Ctrl+1</td>
													<td>Show - NEW SALE (f)</td>
												</tr>
												<tr>
													<td>Ctrl+2</td>
													<td>Show - Delivery (f)</td>
												</tr>
												<tr>
													<td>Ctrl+3</td>
													<td>Show - Take Away (f)</td>
												</tr>
												<tr>
													<td>Ctrl+F12</td>
													<td>Toggle Subcategories Slider (f)</td>
												</tr>
												<tr>
													<td>F4</td>
													<td>Cancel Sale (f)</td>
												</tr>
												<tr>
													<td>F7</td>
													<td>Suspend Sale (f)</td>
												</tr>
												<tr>
													<td>F9</td>
													<td>Print items list</td>
												</tr>
												<tr>
													<td>F8</td>
													<td>Finalize Sale</td>
												</tr>
												<tr>
													<td>Ctrl+F1</td>
													<td>Today's Sale</td>
												</tr>
												<tr>
													<td>Ctrl+F2</td>
													<td>Open Suspended Sales</td>
												</tr>
												<tr>
													<td>Ctrl+F10</td>
													<td>Close Register</td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
						<!--start view bill modal-->
						<div class="modal fade in" id="view_bill_modal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" style="font-family: monospace; font-size: 14px;margin-top:-30px">
							<div class="modal-dialog modal-md">
								<div class="modal-content">
									<div class="modal-header no-print">
										<button type="button" class="close no-print" data-dismiss="modal"><span aria-hidden="true"> <i class="fa fa-2x">&times;</i></span><span class="sr-only">Close</span> </button>
										<button type="button" class="btn btn-xs btn-default no-print pull-right" style="margin-right:15px;" onclick="window.print();"> <i class="fa fa-print"></i> Print </button>
										<h4 class="modal-title no-print" id="vbModalLabel">Title</h4>
									</div>
									<div class="modal-body row" style="margin-top:-23px;margin-left: -20px;padding: 0px 35px 0px 35px;">
										<div style="" class="row" id="main_bill">
											<div class="col-xs-12 text-center">
												<!-- <center>
              <div style="display:none; border:solid 3px; border-radius:50px; width:13%; padding:15px; line-height:1"><span style="font-size:31px;font-weight:bold">SO</span> <span style="font-size:14px;font-weight:bold">Yummy</span></div>
            </center>-->

												<h3 style="font-size:22px; line-height:1.1;margin-bottom: 0px;">RATHNA TRADERS</h3>
												<!-- 
            <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 $get_warehouse[0]->address; ?></p>
												<p>
													<?php
													if ($get_warehouse[0]->email) echo $get_warehouse[0]->email . ""; ?>
												</p>
												<p style="font-weight:; font-size:12px">
													Land: 0112-962726 <br> Whatsapp/Viber : 076-1409403
												</p>
												<?php //if($get_warehouse[0]->phone) echo "<p style=\"font-weight:; font-size:12px\">".$get_warehouse[0]->phone."</p>"; 
												?>
											</div>
											<div>
												<div class="row">
													<div class="col-md-12">
														<p class="bill_type" style="margin-bottom: 0px;display:none">Reg.No :WD6708 </p>
														<p class="bill_date" style="margin-bottom: 0px">Date: <?php echo date("Y-m-d g:i A"); ?> </p>
													</div>
													<div class="col-md-6"> </div>
												</div>
												<div class="row">
													<div class="col-md-12">
														<p class="bill_no" style="font-weight:bold; margin-bottom: 0px">Bill No: </p>
														<p class="sale_type" style="font-weight:bold; margin-bottom: 0px">Sale: </p>
														<p style="margin-bottom:0px;">Cashier :<?php echo $this->session->userdata['ss_user_first_name'] ?></p>
													</div>
													<div class="col-md-7"> </div>
												</div>
												<div class="row">
													<div class="col-md-12">
														<p style="" class="bill_customer">Customer: </p>
														<p class="delivery_address_text" style="display:none;"></p>
													</div>
												</div>
											</div>
											<div>
												<!--class="col-md-12"-->
												<table id="bill_table" class="print-table" style="width:100%">
													<thead style="border-bottom:dashed 2px;border-top:dashed 2px">
														<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">Price</th>
															<th style="width:20%" class="text-center">Discount</th>
															<th style="text-align:right"> Amount</th>
														</tr>
													</thead>
													<tbody>
														<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 2px;display:none;">
															<td style="" colspan="5">SubTotal</td>
															<td style="text-align:right; " class="td_sub_total">&nbsp;</td>
														</tr>
														<tr style="display:none">
															<td style="text-align:left; font-weight:;" colspan="5">Order Discount</td>
															<td style="text-align:right;  border-bottom:solid 0px #000000" id="td_order_discount">()</td>
														</tr>
														<tr style="display:none">
															<td style="text-align:left; font-weight:;" colspan="5">Delivery Charges</td>
															<td style="text-align:right; " id="td_delivery_charges">&nbsp;</td>
														</tr>
														<tr style="display:none">
															<td style="text-align:left; font-weight:;" colspan="5">CC Charges (3%)</td>
															<td style="text-align:right; " id="td_cc_charges">&nbsp;</td>
														</tr>
														<tr>
															<td style=" font-size:16px" colspan="5">Net Total</td>
															<td style="text-align:right;  font-size:16px;  border-top:1px double #000;" id="print_bill_total"></td>
														</tr>
														<tr style="display:none">
															<td style="text-align:right; font-weight:bold;" colspan="5">Service Charges </td>
															<td style="float:right; " id="td_service_charges">&nbsp;</td>
														</tr>
														<tr style="display:none">
															<td style=" font-weight:bold;" colspan="5">Paying </td>
															<td style="text-align:right;  font-weight:bold" id="td_paying_amount">&nbsp;</td>
														</tr>
														<tr style="">
															<td style="font-size:16px;" colspan="5">Paying <span id="td_paying_by">cash</span></td>
															<td style="  border-bottom:0px double #000;text-align:right;">
																<p style="font-size:16px;margin: 0px;" id="td_balance_amount">&nbsp;&nbsp; </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="customer_balance">&nbsp;&nbsp; </p>
															</td>
														</tr>
													</tbody>
												</table>
												<div style="text-align: left;display:none" 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 style="text-align: center; font-size: 12px;">භාන්ඩයක් මාරු කරන විට දින 7ක් තුල බිල රැගෙන ඒම අනිවාර්ය වේ.(ආපසු මුදල් ගෙවීමක් සිදු නොකෙරේ) <br />
												</div>

												<div style="text-align: center; font-size: 11px;" class="collapse"> *** WE ARE CLOSED ON MONDAY *** <br />
													ITEMS WITH PROOF OF PURCHASE WILL BE EXCHANGE WITHIN 7 DAYS. <br />
													<h2 style="margin-top: 5px">~~~Thank You~~~</h2>
												</div>
											</div>
											<div style="page-break-before:always;page-break-after:auto;display:none" class="row" 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">
																<h2 style="margin-top: 5px; text-align:center">RATHNA TRADERS WAREHOUSE 01</h2>
																<h4 id="stn1"></h4>
																<h4 class="bill_no" style="text-align:left">Bill No :</h4>
																<p style="text-align:left" class="bill_customer">Customer: </p>
																<h4 style="text-align:left" class="bill_date"></h4>

																<h4 style="text-align:left" class="cash_balance">Net total: </h4>
																<h4 style="text-align:left" class="td_delivery_charges">Delivery charges: </h4>
																<p class="delivery_address_text" style="display:none;text-align:left"></p>
																<h4 style="text-align:left">Cashier :<?php echo $this->session->userdata['ss_user_first_name'] ?></h4>
															</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>
													</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>
											<div style="display:none;page-break-before:always;" class="row" id="del_list2_div">
												<table id="del_list2" class="print-table" style="width:100%; display:none">
													<thead style="border-bottom:dashed 2px;border-top:dashed 2px">
														<th class="text-center" colspan="4">
															<h2 style="margin-top: 5px; text-align:center">RATHNA TRADERS WAREHOUSE 02</h2>
															<h4 id="stn2"></h4>
															<h4 class="bill_no" style="text-align:left">Bill No :</h4>
															<p style="text-align:left" class="bill_customer">Customer: </p>
															<h4 style="text-align:left" class="bill_date"></h4>
															<h4 style="text-align:left" class="cash_balance">Net total: </h4>
															<h4 style="text-align:left" class="td_delivery_charges">Delivery charges: </h4>
															<p class="delivery_address_text" style="display:none;text-align:left"></p>
															<h4 style="text-align:left">Cashier :<?php echo $this->session->userdata['ss_user_first_name'] ?></h4>
														</th>
														<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>
													</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>

											<div style="display:none;page-break-before:always;" class="row" id="del_list3_div">
												<table id="del_list3" class="print-table" style="width:100%; display:none">
													<thead style="border-bottom:dashed 2px;border-top:dashed 2px">
														<th class="text-center" colspan="4">
															<h2 style="margin-top: 5px; text-align:center">RATHNA TRADERS WAREHOUSE 03</h2>
															<h4 id="stn3"></h4>
															<h4 class="bill_no" style="text-align:left">Bill No :</h4>
															<p style="text-align:left" class="bill_customer">Customer: </p>
															<h4 style="text-align:left" class="bill_date"></h4>
															<h4 style="text-align:left" class="cash_balance">Net total: </h4>
															<h4 style="text-align:left" class="td_delivery_charges">Delivery charges: </h4>
															<p class="delivery_address_text" style="display:none;text-align:left"></p>
															<h4 style="text-align:left">Cashier :<?php echo $this->session->userdata['ss_user_first_name'] ?></h4>
														</th>
														<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>
													</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>
										</div>
									</div>
								</div>
							</div>

							<!--end modal-->
							<div class="rotate btn-cat-con">
								<button type="button" class="btn btn-danger" id="view_bill" tabindex="-1"> <i class="fa fa-print"></i> </button>
								<button type="button" id="open-subcategory" class="btn btn-warning open-subcategory">Subcategories</button>
								<button type="button" id="open-category" class="btn btn-primary open-category">Categories</button>
								<button style="display:none" id="open-keyboard" class="btn btn-success open-keyboard" type="button"><i class="clip-keyboard-2"></i></button>
							</div>


							<div id="order_tbl">
								<span id="order_span"></span>
								<table id="order-table" class="prT table table-striped" style="margin-bottom:0;width:100%">
								</table>
							</div>
							<div id="bill_tbl">
								<span id="bill_span"></span>
								<table id="bill-table" class="prT table table-striped" style="margin-bottom:0; width:100%">
								</table>
								<table id="bill-total-table" class="prT table" style="margin-bottom:0; width:100%">
								</table>
							</div>
							<div class="modal fade in" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
							<div class="modal fade in" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true"></div>
							<div id="modal-loading" style="display: none;">
								<div class="blackbg" style="padding-top:250px">
									<center>
										<i style="color:#FFF;" class="fa fa-spinner fa-spin fa-5x"></i>
									</center>
								</div>
								<div class="loader-"></div>
							</div>
							<div id="ajaxCall"><i class="fa fa-spinner fa-pulse"></i></div>
							<!-- start ajax model -->
							<div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
							<!-- end ajax model -->
							<!-- start popup box-->
							<div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-hidden="true">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
										<h4 class="modal-title">Confirm</h4>
									</div>
									<div class="modal-body">
										<p id="label"> </p>
									</div>
									<div class="modal-footer">
										<input id="sel_id" type="hidden" />
										<input id="page" type="hidden" />
										<input id="count" value="0" type="hidden" />
										<input id="popup_type" type="hidden" />
										<button aria-hidden="true" data-dismiss="modal" class="btn btn-default"> Close </button>
										<button id="conirm" class="btn btn-default" data-dismiss="modal"> Confirm </button>
									</div>
								</div>
							</div>

							<!-- end panel one -->
						</div>
					</div>
					<!-- content here -->
					<?php // $this->load->view("bar/add_product") 
					?>
					<input id="selected_batch" type="hidden" value="" />
					<!--add customer model-->
					<div class="modal fade" id="add_customer_model" tabindex="-1" role="dialog" aria-labelledby="add_customer_modelLabel" aria-hidden="true">
						<div id="error"></div>
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header" style="background-color: #337ab7;color: white; border-radius: 4px 4px 0px 0px;">
									<h5 class="modal-title" id="add_customer_modelLabel">
										<center>Add customer</center>
									</h5>
									<button type="button" class="close" data-dismiss="modal" aria-label="Close">
										<span aria-hidden="true">&times;</span>
									</button>
								</div>
								<div class="modal-body">
									<form role="form" class="form-horizontal" id="create_customer_form" action="#" autocomplete="off">

										<div style="padding: 15px">
											<div class="form-group">
												<h5>Name *</h5>
												<input type="text" class="form-control" name="cus_name" id="cus_name">
											</div>
											<div class="form-group">
												<h5>Phone *</h5>
												<input class="form-control" name="cus_phone" id="cus_phone" type="text">
											</div>
											<div class="form-group">
												<h5>Address *</h5>
												<input class="form-control" name="cus_address" id="cus_address" type="text">
											</div>
											<!--hidden fields-->
											<input name="type" value="A" type="hidden" />
											<input name="location" value="POS" type="hidden" />
											<input name="cus_warehouse_id" value="4" type="hidden" />
											<input name="country_id" value="251" type="hidden" />
										</div>
									</form>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
									<button type="button" class="btn btn-primary" onclick="add_customer()">Save changes</button>
								</div>
							</div>
						</div>
					</div>
					<!--end model-->
					<div class="hover_bkgr_fricc">
						<span class="helper"></span>
						<div>
							<div class="popupCloseButton">&times;</div>
							<form role="form" class="form-horizontal" id="select_price_form" action="#" autocomplete="off" style="text-align:left"></form>
						</div>
					</div>
					<!--end-->
				</div>
			</div>
		</div>
		<!-- end -->
		<input type="hidden" id="fucking_done" value="0">
		<!-- end pop upbox-->
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/jQuery-lib/2.0.3/jquery.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/select2/select2.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/bootstrap/js/bootstrap.min.js"></script>
		<!--<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/bootbox.min.js"></script>-->
		<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/5.5.2/bootbox.min.js" integrity="sha512-RdSPYh1WA6BF0RhpisYJVYkOyTzK4HwofJ3Q7ivt/jkpW6Vc8AurL1R+4AUcvn9IwEKAPm/fk7qFZW3OuiUDeg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/perfect-scrollbar.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/accounting.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/jquery.sendkeys.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>pos/js/bililiteRange.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>js/bar.ajax.5.8.js"> </script>
		<script type="text/javascript">
			function add_customer() {
				var fields = $("#create_customer_form").serialize();
				$.post("<?php echo base_url(); ?>customers/save_customer", fields).done(function(data) {
					var obj = jQuery.parseJSON(data);
					if (obj.status == 0) {
						$('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>' + obj.validation + '</div>');
					} else {
						$('div#error').html('<div class="alert alert-block alert-success fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Saved Successfully !</h4></div>');
						var data = {
							id: obj.id,
							text: $('#cus_name').val() + "/" + $('#cus_phone').val()
						};
						var newOption = new Option(data.text, data.id, true, true);
						$('#poscustomer').append(newOption).trigger('change');
						setTimeout(function() {
							$('#add_customer_model').modal('hide');
							$('#add_item').focus();
						}, 2000);
					}
				});
			}
			$('#product-list, #category-list, #subcategory-list, #brands-list').perfectScrollbar({
				suppressScrollX: true
			});
			var jsonarray = <?php print_r($product_list) ?>;
			var base_url = '<?php echo base_url(); ?>';
			$('#modal-loading').show();

			/*function validate_cash() {
				$(":focus").each(function() {
					focused = this.id;
				});
				var for_fld = "#" + focused;
				var for_val = $(for_fld).val();
				if (for_val > 9999) {
					$(for_fld).val(0);
					displayNotice("page", " Invalid quantity :  " + for_val);
					$('#add_item').focus();
				}
			}*/


			/*function clear_amount() {
				$(":focus").each(function() {
					focused = this.id;
				});
				var focused_fld = "#" + focused;
				$(focused_fld).val(0);
				grand_total_cal();
				$("#qty_en_tot").val('');
				$("#dis_en_tot").val('');
			}
			*/
			/*
			function cal_btn_click(val) {
				var focused = '';
				$(":focus").each(function() {
					focused = this.id;
				});
				var e = jQuery.Event("keydown");
				e.key = val;
				$('#' + focused).trigger(e);
				grand_total_cal();
			}*/

			function form_submit() {
				//$('#submit-sale').text('Loading...').attr('disabled', true);
				var print_stn = ($("#print_stn").prop("checked") == true) ? 1 : 0;
				/*var invoice_type = $("input[name='invoice_type']:checked").val();
				
				if (!invoice_type) {
					alert("please select SALE TYPE");
					return false;
				}*/

				var show_list = false;
				var got_stn1 = false;
				var stn1 = "";
				var show_list2 = false;
				var got_stn2 = false;
				var stn2 = "";
				var show_list3 = false;
				var got_stn3 = false;
				var stn3 = "";
				$("input[class='deliveryList']:checked").each(function() {
					//sList += "(" + $(this).val() + "-" + (this.checked ? "checked" : "not checked") + ")";
					//var c = $(this).val();
					var c = $(this).attr("row_id");
					var product_name = $(this).attr("pd_name");
					var product_qty = $('#quantity_' + c).val(); //$(this).attr("pd_qty");
					console.log($('#quantity_' + c).val());
					add_to_deli_list(c, product_name, product_qty);
					if (c) {
						show_list = true;
					}
				});

				if (show_list) {
					if (print_stn) {
						$('#del_list').css('display', 'block');
						$('#del_list_div').css('display', 'block');
					}
					if (!got_stn1) {
						get_stn(4, "#stn1");
						got_stn1 = true;
					}
				}

				$("input[class='deliveryList2']:checked").each(function() {
					var c = $(this).attr("row_id");
					var product_name = $(this).attr("pd_name");
					var product_qty = $('#quantity_' + c).val(); //$(this).attr("pd_qty");
					//console.log($('#quantity_'+c).val());
					add_to_deli_list2(c, product_name, product_qty);
					if (c) {
						show_list2 = true;
					}
				});

				if (show_list2) {
					if (print_stn) {
						$('#del_list2').css('display', 'block');
						$('#del_list2_div').css('display', 'block');
					}
					if (!got_stn2) {
						get_stn(5, "#stn2");
						got_stn2 = true;
					}
				}
				console.trace("t8");
				$("input[class='deliveryList3']:checked").each(function() {
					var c = $(this).attr("row_id");
					var product_name = $(this).attr("pd_name");
					var product_qty = $('#quantity_' + c).val(); //$(this).attr("pd_qty");
					//console.log($('#quantity_'+c).val());
					add_to_deli_list3(c, product_name, product_qty);
					if (c) {
						show_list3 = true;
					}
				});
				console.trace("t9");
				if (show_list3) {
					if (print_stn) {
						$('#del_list3').css('display', 'block');
						$('#del_list3_div').css('display', 'block');
					}
					if (!got_stn3) {
						get_stn(6, "#stn3");
						got_stn3 = true;
					}
				}

				$('#modal-loading').show();
				/*---- add to bill ----*/
				$('.bill_date').text('Date: ' + $('#sale_datetime').val());
				/*-- end --*/
				var fields = $("#pos-sale-form").serialize();
				$.ajax({
					type: "POST",
					data: fields,
					dataType: 'json',
					url: "pos/pos_submit<?php echo (ENVIRONMENT != 'production') ? "_" . ENVIRONMENT : ""; ?>",
					success: function(data) {
						console.log(data);
						$('#fucking_done').val(1);
						if (data.success) {
							/*if (grand_total < 10000) {
    						save_hw(fields);
    					}*/
							window.open('<?php echo base_url() ?>pos/sale_details_stn?sale_id=' + data.data.sale_id + '&stn=' + print_stn, 'pos_print', 'toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');
							form_reset();
						} else {
							bootbox.alert(data.disMsg);
						}
					},
					error: function(data) {
						bootbox.alert(data.responseText);
						console.log(data.responseText);
					}
				});

				/*
				$.post("<?php echo base_url(); ?>pos/pos_submit", fields).done(function(data) {
					var obj = jQuery.parseJSON(data);
					if (obj.error == 1) {
						$('#modal-loading').hide();
						$('.alert-success').hide();
						$('.alert-danger').show();
						$(".errortxt").text(obj.disMsg);
						window.scrollTo(500, 0);
					}
					if (obj.error == 0) {
						if (grand_total < 10000) {
							save_hw(fields);
						}
						window.scrollTo(500, 0);
						$("#soTable > tbody").empty();
						//$('#bill_no').text('Bill No:' + obj.sale_ref);
						$('.bill_no').text('Bill No:' + obj.sale_ref);
						$('#kot_bill_no').text('Bill No:' + obj.sale_ref);
						$('#fucking_done').val(1);
						if ($("#print_bill").prop("checked") == true) {
							site.settings.printable = false;
						}
						if (site.settings.printable === true) {
							//window.open(URL, obj.sale_ref, "","");
							var mth = 0;
							if (mth == 1) {
								$("#view_bill_modal").modal().on("shown.bs.modal", function() {
									console.log('attempting to print...');
									console.log('printable status :' + site.settings.printable);
									if (site.settings.printable === true) {
										$('#modal-loading').hide();
										window.print();
										console.log('doc printed');
										site.settings.printable = false;
										console.log('print status changed to:' + site.settings.printable);
										$("#view_bill_modal").modal('hide');
									} else {
										console.log('not printed');
									}
								}).on("hidden.bs.modal", function() {
									form_reset();
								});
							} else {
								window.open('<?php echo base_url() ?>pos/sale_details_stn?sale_id=' + obj.sale_id + '&stn=' + print_stn, 'pos_print', 'toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');
								form_reset();
							}
						} else {
							form_reset();
						}
					}
				});*/

			}

			function get_stn(warehouse_id, id) {
				$.ajax({
					type: "post",
					async: false,
					url: "<?php echo base_url('common/get_store_note'); ?>",
					data: {
						warehouse_id: warehouse_id
					},
					//dataType: "html",
					success: function(data) {
						var obj = jQuery.parseJSON(data);
						var stn_no = obj.stn_no;
						var stn_code = obj.stn_code;
						$(id).text(stn_code);
						switch (id) {
							case "#stn1":
								$('#stnn1').val(stn_no);
								$('#stnn1_code').val(stn_code);
								$('#stnn1_wh').val(warehouse_id); //console.log($('#stnn1').val());
								break;
							case "#stn2":
								$('#stnn2').val(stn_no);
								$('#stnn2_code').val(stn_code);
								$('#stnn2_wh').val(warehouse_id); //console.log($('#stnn2').val());
								break;
							case "#stn3":
								$('#stnn3').val(stn_no);
								$('#stnn3_code').val(stn_code);
								$('#stnn3_wh').val(warehouse_id); //console.log($('#stnn3').val());
								break;
							default:
								break;
						}
						//return stn_code;
					},
					error: function() {
						//alert('Error occured while getting data from server.');
						return false;
					}
				});
			}

			/*function getQty(product_id, c) {
			    $.ajax({
			        type: "post",
			        async: false,
			        url: "<?php echo base_url('bar/warehouse_qty'); ?>",
			        data: {
			            product_id: product_id
			        },
			        //dataType: "html",
			        success: function(data) {
			            var obj = jQuery.parseJSON(data);
			            var maxq = obj.quantity;
			            setTimeout(function() {
			                $('#maxq_' + c).text(maxq);
			            }, 1000);
			        },
			        error: function() {
			            alert('Error occured while getting data from server.');
			        }
			    });
			}*/

			function save_hw(formData) {
				<?php
				if ($this->session->userdata('ss_user_id') != 1) {
				?>
					var url = "hw/pos/pos_submit";
					try {
						$.post("<?php echo base_url(); ?>" + url + "", formData).done(function(data) {
							var obj = jQuery.parseJSON(data);
							console.log(obj);
							if (obj.error == 1) {
								console.log("step one: failed");
							}
							if (obj.error == 0) {
								console.log("step one: successfully saved");
							}
						});
					} catch (e) {}
				<?php
				} ?>
			}

			function form_reset() {
				if ($('#fucking_done').val()) {
					if (!$('#sale_id').val())
						form_clear();
					else form_locate();
				}
			}

			function form_clear() {
				$('#pos-sale-form').trigger("reset");
				location.reload();
			}

			function form_locate() {
				<?php
				$location = 'bar';
				if ($order_place == 'rest') $location = 'pos';
				?>
				window.location.href = '<?php echo base_url($location); ?>';
			}
			$('select#category').on('change', function() {
				var v = $(this).val();
				$.ajax({
					type: "get",
					async: false,
					url: "<?php echo base_url('products/get_sub_category_by_id'); ?>",
					data: {
						category_id: v
					},
					dataType: "html",
					success: function(data) {
						if (data != "") {
							$('#subcat_data').empty();
							$('#subcat_data').html(data);
							$("#subcategory").select2({
								allowClear: true
							});
						} else {
							$('#subcat_data').empty();
							var default_data = '<select name="subcategory" id="subcategory" class="form-control search-select" data-placeholder="Select Category to load Subcategories"></select>';
							$('#subcat_data').html(default_data);
							$("#subcategory").select2({
								allowClear: true
							});
							displayNotice("Product Info", "No Subcategory found for the select category.");
						}
					},
					error: function() {
						alert('Error occured while getting data from server.');
					}
				});
			});

			function click_sales_view_btn(sale_id) {
				var $modal = $('#ajax-modal');
				$('body').modalmanager('loading');
				setTimeout(function() {
					$modal.load('<?php echo base_url("sales/sale_details?sale_id="); ?>' + sale_id, '', function() {
						$modal.modal();
						$(".search-select").select2({
							placeholder: "Select a State",
							allowClear: true
						});
					});
				}, 1000);
			}

			function fbs_click(id) {
				u = location.href;
				t = document.title;
				window.open('<?php echo base_url() ?>bar/print_reciept?sale_id=' + id, 'sharer', 'toolbar=0,status=0,width=626,height=700, left=10, top=10,scrollbars=yes');
				return false;
			}

			function fbs_click_pos(id) {
				complete_sale(id);
				u = location.href;
				t = document.title;
				window.open('<?php echo base_url() ?>sales/sale_details_pos?sale_id=' + id, 'sharer', 'toolbar=0,status=0,width=626,height=700, left=10, top=10,scrollbars=yes');
				return false;
				/*console.log(mywindow);*/
			}

			function fbs_click_pos_no_c(id) {
				u = location.href;
				t = document.title;
				window.open('<?php echo base_url() ?>sales/sale_details_pos?sale_id=' + id, 'sharer', 'toolbar=0,status=0,width=626,height=700, left=10, top=10,scrollbars=yes');
				return false;
			}

			function edit_sale(id) {
				window.location = '<?php echo base_url() ?>bar/0/' + id;
				return false;
			}

			function complete_sale(id) {
				jQuery.ajax({
					type: "POST",
					url: "<?php echo base_url() . 'bar/complete_sale' ?>",
					data: {
						sale_id: id,
					},
					cache: false,
					success: function(response) {
						displayNotice('page', 'Sale Completed !!');
					}
				});
			}

			function set_as_paid(sid) {
				var sale_pymnt_date_time = $('#sale_datetime').val();
				var paid_by = $('#paying_by_' + sid).val();
				var given_amount = $('#c_pay_amount_' + sid).val();
				jQuery.ajax({
					type: "POST",
					url: "<?php echo base_url() . 'bar/set_as_paid' ?>",
					data: {
						sale_id: sid,
						paid_by: paid_by,
						sale_pymnt_date_time: sale_pymnt_date_time,
						given_amount: given_amount
					},
					cache: false,
					success: function(response) {
						displayNotice('page', 'Payment Succeed!!');
					}
				});
			}

			function delete_invoice(sid) {
				var group_id = $('#group_id').val();
				/*var confm =	window.confirm("Delete This Invoice ?");*/
				if (group_id != 3) {
					bootbox.confirm('Delete Invoice ' + sid + '?', function(e) {
						if (e) {
							jQuery.ajax({
								type: "POST",
								url: "<?php echo base_url() . 'sales/sales_delete?sale_id=' ?>" + sid,
								cache: false,
								success: function(response) {
									displayNotice('page', 'Successfully Deleted!!');
								}
							});
						}
					});
				}
			}

			function delete_payments(sid) {
				var group_id = $('#group_id').val();
				/*var confm =	window.confirm("Delete Payments ?");*/
				if (group_id != 3) {
					bootbox.confirm('Delete Invoice Payments of Invoice ID: ' + sid + '?', function(e) {
						if (e) {
							jQuery.ajax({
								type: "POST",
								url: "<?php echo base_url() . 'sales/sale_pymnts_delete?sale_id=' ?>" + sid + "&in_type=sale",
								cache: false,
								success: function(response) {
									displayNotice('page', 'Successfully Deleted!!');
								}
							});
						}
					});
				}
			}
			$('button').on('mousedown', function(event) {
				event.preventDefault();
			});

			function search_products_offline() {
				var input, filter, table, tr, td, i, txtValue;
				input = document.getElementById("srh_pro_name");
				filter = input.value.toUpperCase();
				table = document.getElementById("products_table");
				tr = table.getElementsByTagName("tr");
				for (i = 0; i < tr.length; i++) {
					td = tr[i].getElementsByTagName("td")[0];
					if (td) {
						txtValue = td.textContent || td.innerText;
						if (txtValue.toUpperCase().indexOf(filter) > -1) {
							tr[i].style.display = "";
						} else {
							tr[i].style.display = "none";
						}
					}
				}
			}

			function search_products_ajax() {
				var input, filter, table, tr, td, i, txtValue;
				input = document.getElementById("srh_pro_name");
				filter = input.value.toUpperCase();
				table = document.getElementById("products_table");
				tr = table.getElementsByTagName("tr");

				$.ajax({
					url: "<?php echo base_url(); ?>bar/get_prices",
					method: "POST",
					dataType: "JSON",
					data: {
						filter: filter
					},
					success: function(data) {
						if (data.success) {
							$('#products_table > tbody').html(data.data);
						} else {
							$('#products_table > tbody').html("<tr><td>No data</td></tr>");
						}
					},
					error: function(data) {
						console.log(data);
					}
				});
			}

			/*search products on side*/
			$(document).ready(function() {
				var tr = '<tr class="header"><th style="width:40%;">Name</th><th style="width:20%;">Cash</th><th style="width:20%;">Credit</th><th style="width:20%;">Wholesale</th></tr>';
				$.each(jsonarray, function(key, value) {
					var name = "<td>" + value.product_name + "</td>";
					var cash = "<td>" + value.product_price + "</td>";
					var credit = "<td>" + value.retail_credit + "</td>";
					var whlsle = "<td>" + value.retail_wholesale + "</td>";
					tr += "<tr>" + name + cash + credit + whlsle + "</tr>";
				});
				$('#products_table').html(tr);
				var environment = localStorage.getItem("environment");
				if (environment == null) {
					localStorage.setItem("environment", "<?php echo ENVIRONMENT; ?>");
				} else {
					if (environment !== '<?php echo ENVIRONMENT; ?>') {
						alert("WARNING!! Environment has been changed.");
						localStorage.setItem("environment", "<?php echo ENVIRONMENT; ?>");
					}
				}
			});

			function search_p(pc) {
				$('#add_item').val('');
				var e = jQuery.Event("keydown");
				e.key = pc;
				$('#add_item').trigger(e);

				$('#srh_pro_name').val("");
				search_products_ajax();
			}
			$('#return_sale_id').on("keypress", function(e) {
				if (e.key === "Enter") {
					window.open($(this).attr("href") + $(this).val(), "popupWindow", "width=600,height=600,scrollbars=yes");
					$(this).val('');
				}
			});


			/* payment related stuff */
			$(document).on('click', '.addButton', function() {
				var pa = $('#multi-payment > div').length;
				pa = pa + 2;
				if (pa < 5) {
					$('#paid_by_1, #pcc_type_1').select2('destroy');
					var phtml = $('#payments').html(),
						update_html = phtml.replace(/_1/g, '_' + pa);
					pi = 'amount_' + pa;
					$('#multi-payment').append('<button type="button" class="close close-payment" style="margin: -10px 0px 0 0;"><i class="fa fa-2x">&times;</i></button>' + update_html);
					$('#paid_by_' + pa).val('cash').trigger('change');
					$('#amount_' + pa).prop('readonly', false);
					$('#paid_by_1, #pcc_type_1, #paid_by_' + pa + ', #pcc_type_' + pa).select2({
						minimumResultsForSearch: 7
					});
				} else {
					bootbox.alert('Max allowed limit reached.');
					return false;
				}
			});
			$(document).on('click', '.close-payment', function() {
				$(this).next().remove();
				$(this).remove();
				calculateTotals();
			});
			$('#paymentModal').on('shown.bs.modal', function(e) {
				var gtotal = $('#grand_total').val();
				var pt = $("input[name='price_type']:checked").attr("lable");
				if (pt == 'credit') {
					gtotal = 0;
				}
				$('#amount_1').focus();
				/*$('#amount_1').focus().val(gtotal).select();*/
				calculateTotals();
			}).on("hidden.bs.modal", function(e) {
				$('#add_item').focus();
			});

			$(document).on('focus', '.amount', function() {
				pi = $(this).attr('id');
				grand_total_cal();
			}).on('keyup', function() {
				grand_total_cal();
			}).on('blur', '.amount', function() {
				grand_total_cal();
			});

			function calculateTotals() {
				var gtotal = $('#grand_total').val();
				var total_paying = 0;
				var ia = $(".amount");
				$.each(ia, function(i) {
					var this_amount = formatCNum($(this).val() ? $(this).val() : 0);
					total_paying += parseFloat(this_amount);
				});
				console.log(total_paying);
				$('#total_paying').text(formatMoney(total_paying));
				$('#balance').text(formatMoney(total_paying - gtotal));
				//$('#balance_' + pi).val(formatDecimal(total_paying - gtotal));
				$('#twt').text(formatMoney(gtotal));
				$('#total_paid').val(total_paying);
			}

			$(document).on('change', '.paid_by', function() {
				var grand_total = $('#grand_total').val();
				var p_val = $(this).val(),
					id = $(this).attr('id');
				pa_no = id.substr(id.length - 1);
				var total_added = 0;
				for (let index = 1; index < 6; index++) {
					if (pa_no != index) {
						total_added += parseFloat($('#amount_' + index).val() ? $('#amount_' + index).val() : 0);
					}
				}
				var bal = parseFloat(grand_total - total_added);
				if (pa_no > 1)
					$('#amount_' + pa_no).val(bal);
				$('#rpaidby').val(p_val);
				if (p_val == 'cash' || p_val == 'other') {
					$('.pcheque_' + pa_no).hide();
					$('.pcc_' + pa_no).hide();
					$('.pcash_' + pa_no).show();
					$('#amount_' + pa_no).focus();
					if ($("#add_cc_" + pa_no).prop("checked")) {
						var amt = $('#amount_' + pa_no).val();
						if (amt > 0)
							$('#amount_' + pa_no).val(amt / 1.3);
						$('#amount_' + pa_no).prop('readonly', false);
					}
					$("#add_cc_" + pa_no).prop("checked", false);
					grand_total_cal();
				} else if (p_val == 'CC' || p_val == 'stripe' || p_val == 'ppp' || p_val == 'authorize') {
					$('.pcheque_' + pa_no).hide();
					$('.pcash_' + pa_no).hide();
					$('.pcc_' + pa_no).show();
					// $('#swipe_' + pa_no).focus();
				} else if (p_val == 'Cheque') {
					$('.pcc_' + pa_no).hide();
					$('.pcash_' + pa_no).hide();
					$('.pcheque_' + pa_no).show();
					$('#cheque_no_' + pa_no).focus();
				} else {
					$('.pcheque_' + pa_no).hide();
					$('.pcc_' + pa_no).hide();
					$('.pcash_' + pa_no).hide();
				}
				if (p_val == 'gift_card') {
					$('.gc_' + pa_no).show();
					$('.ngc_' + pa_no).hide();
					$('#gift_card_no_' + pa_no).focus();
				} else {
					$('.ngc_' + pa_no).show();
					$('.gc_' + pa_no).hide();
					$('#gc_details_' + pa_no).html('');
				}
			});
			$(document).on('change', '.add_cc', function() {
				var p_val = $(this).val(),
					id = $(this).attr('id');
				pa_no = id.substr(id.length - 1);
				if (this.checked) {
					var amt = $('#amount_' + pa_no).val();
					if (amt > 0)
						$('#amount_' + pa_no).val(amt * 1.3);
					$('#amount_' + pa_no).prop('readonly', true);
				} else {
					var amt = $('#amount_' + pa_no).val();
					if (amt > 0)
						$('#amount_' + pa_no).val(amt / 1.3);
					$('#amount_' + pa_no).prop('readonly', false);
				}
				grand_total_cal();
			});
		</script>
</body>

</html>