<?php
	include('my_functions.php');
	$pagetitle = "Cash Sales Register";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h6>POS (WHOLESALE), All prices are <b><?php echo Commission_settings(  2); ?>% </b> off</h6>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 3 || $_SESSION["connectedusergroup"] == 4)
						{
					?>
					<div class="row">
						<div class="col-md-12">
							<div id="servererrormessage">
							</div>
						</div>
					</div>
				
					<div class="row">
						<div class="col-md-8">
							<div class="card card-primary" id="saledetails" style="height: 500px;">
								<div class="card-body">
									<div class="row">
										<div class="form-group col-sm-8">
											<input type="text" name="itemcode" id="itemcode" class="form-control" placeholder="Scan Item Barcode" >
										</div><!-- form-group -->
										<div class="form-group col-sm-4">
											<button id="searchitembtn" onclick="loadsearchform()" class="btn btn-warning"><i class="fa fa-search"></i> Open Item Search</button>
										</div>
									</div>
									
									<div>
											<div id="cartitemslist">
										 <div class="card">
											  <div class="card-header">
											 

												<div class="card-tools">
												  <div class="input-group input-group-sm" style="width: 150px;">
													<input type="text" name="table_search" class="form-control float-right" placeholder="Search">

													<div class="input-group-append">
													  <button type="submit" class="btn btn-default"><i class="fas fa-search"></i></button>
													</div>
												  </div>
												</div>
											  </div>
											  <!-- /.card-header -->
											  <div class="card-body table-responsive p-0" >
												<table class="table table-head-fixed text-nowrap"   id="cartitemstable">
												<thead>
													<tr>
														<th style="display:none;"></th>
														<th>Name</th>
														<th>Srial Number(s)</th>
														<th class="text-right">Price</th>
														<th class="text-right">Quantity</th>
														<th class="text-right">Total</th>
														<th class="text-right">Action</th>
													</tr>
												</thead>
												<tbody>
													
												</tbody>
											</table>
											</div>
											</div>
										</div>
									</div>
								</div><!-- /.card-body -->
							</div><!-- /.card -->
						</div>
						
						<div class="col-md-4">
							<div class="card card-success" id="salesummary" style="height: 700px;">
								<div class="card-body">
									 
									
										<div class="form-group col-md-12">
										<b>Customer Details</b>  <br /> 
										 
											<input type="text" id="search-card" placeholder="Search a customer here" />
										 
										 
										<select class="form-control  " style="width: 100%;"  name="clientname" id="clientname">
										  
										  <option value="0" selected="selected" >No Name</option>
										   
										</select>
										
										<b>Served by</b><br />
										 
										 
										 
										 <select class="form-control  " style="width: 100%;"  name="attendant" id="attendant">
										  
										  <option value="0" selected="selected">No Name</option>
										  
											<?php
												$customers = DB::query("SELECT id, first_name , last_name FROM personnel_details where employee_role  ='2'   "); 
												
												foreach ($customers as $customer)
												{
											?>
											<option value="<?php echo $customer['id']; ?>"><?php  echo $customer['first_name'].' , '.$customer['last_name']; ?></option>
											<?php
												}
											?>
										</select>  
									</div>
									
									 
										 
										
										<input type ='hidden'  value='1' name="mechanic" id="mechanic" />
										 
										 
										 
										 
								 
									
									<div class="form-group col-md-12">
										
										
									
									<label class="col-md-6">Items Count</label><i class="col-md-6" id="itemscount"><b>0</b></i>
									
									<div class="col-md-12" style="margin-top: 25px"></div>
									
									<label class="col-md-6">Amount Due</label><i class="col-md-6" id="cost"><b>0 UGX</b></i>
									
									<div class="col-md-12" style="margin-top: 25px"></div>
									
									<div class="form-group col-md-12">
										<label for="cashpaidin">Paid Amount</label>
										<input type="text" name="cashpaidin" id="cashpaidin" maxlength="100" class="form-control" onfocus="this.select();" onmouseup="return false;">
									</div><!-- form-group -->
									
									<div class="form-group col-md-12">
										<label for="receiptmode">Payment Type</label>
										<select  class="form-control" name="receiptmode" id="receiptmode">
											<?php
												$paymentmodedata = DB::query("SELECT id, payment_name FROM payment_type");
												
												foreach ($paymentmodedata as $paymentmode)
												{
											?>
											<option value="<?php echo $paymentmode['id']; ?>"><?php echo $paymentmode['payment_name']; ?></option>
											<?php
												}
											?>
										</select>
									</div><!-- form-group -->
										
									<label class="col-md-6">Customer Change</label><i class="col-md-6" id="clientbalance"><b>0 UGX</b></i>
									
									<div class="col-md-12" style="margin-top: 25px"></div>
									
									<div class="form-group col-md-12">
										<textarea name="memo" id="memo" rows="3" placeholder="Additional Notes ..." maxlength="100" class="form-control"></textarea>
									</div><!-- form-group -->
									
									<div class="btn-list col-md-12 text-center">
										<button onclick="cancelsale()" class="btn btn-danger"><i class="fa fa-remove"></i> Cancel Sale</button>
										
										<button onclick="processcashsale()" class="btn btn-success"><i class="fa fa-floppy-disk"></i> Process Sale</button>
									</div>
							
								</div><!-- /.card-body -->
							</div><!-- /.card -->
						</div>
					</div>
					<?php
						}
						else
						{
					?>
					<div class="alert alert-danger alert-dismissable">
						<i class="fa fa-ban-circle"></i>
						Limited Access
					</div>
					<?php
						}
					?>
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			 
		</div><!-- ./wrapper -->
		
		<div class="modal" id="waitdialogmodal"  data-backdrop="static">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-body">
					<div class="text-center">
							<img src="<?php echo $base_url . '/images/loaders/loader12.gif'; ?>" />
					</div>
				  </div>
              </div>
            </div>
        </div>
		
		<div class="modal" id="mediummodal">
			<div class="modal-dialog">
				<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 text-center">Cart Item Update</h4>
					</div>
					<div class="modal-body">					
						<div id="itemediterrormessage">
						</div>
						
						<div id="itemrowindex" style="display:none;">
						</div>
						
						<div id="itemnamedisplay" class="text-center" >
							<b>Sample Item Name</b>
						</div>
						
						<div class="col-md-12" style="margin-top: 15px"></div>
						
						<div class="row">
							<div class="col-sm-6">
								<div class="form-group">
									<label for="itemquantity">Item Quantity</label>
									<input type="text" name="itemquantity" id="itemquantity" class="form-control" >
								</div><!-- form-group -->
							</div>
							
							<div class="col-sm-6">
								<div class="form-group">
									<label for="itemsellprice">Item Sell Price</label>
									<input type="text" name="itemsellprice" id="itemsellprice" class="form-control" >
								</div><!-- form-group -->
							</div>
						</div>
						
						<div class="row">
							<div class="col-sm-12">
								<div class="form-group">
									<label for="serialnumbers">Serial Number(s)</label>
									<input type="text" name="serialnumbers" id="serialnumbers" maxlength="195" class="form-control" >
								</div><!-- form-group -->
							</div>
						</div>
						
						<div id="notesfooter" class="modal-footer">
							<a href="" data-dismiss="modal" class="btn btn-danger"><i class="fa fa-times"></i> Close</a>
							<button name="updateitembtn" id="updateitembtn" onclick="cartitemrowupdate()" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>
							
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="modal" id="largemodal">
			<div class="modal-dialog modal-lg">
				<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 text-center">Item Search Form</h4>
					</div>
					<div class="modal-body">
						<div id="searchitemerrormessage">
						</div>
						
						<div class="form-group">
							<div class="input-group">
								<input type="text" name="itemsearchtext" id="itemsearchtext" class="form-control" placeholder="Enter Item Name Or Code" />
								<span class="input-group-btn">
									<button class="btn btn-primary btn-flat" name="getitemsbtn" id="getitemsbtn">Go!</button>
								</span>
							</div>
						</div><!-- form-group -->
						
							<div class="row">
          <div class="col-12">
            <div class="card">
              <div class="card-header">
                

                <div class="card-tools">
                  
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0" style="height: 300px;" id="searchresulthere">
                 
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
        </div>
					</div>
					<div id="notesfooter" class="modal-footer">
						<a href="" data-dismiss="modal" class="btn btn-danger"><i class="fa fa-times"></i> Close</a>
					</div>
				</div>
			</div>
		</div>
		
	<?php include ('includes/general_footer.php')?>
		
		<script src="plugins/bert/jquery.price_format.min.js" type="text/javascript"></script>
		<script src="plugins/bert/storepos_wholesale.js" type="text/javascript"></script>
		<script src="plugins/bert/wholesale.js" type="text/javascript"></script>
		<script src="plugins/js/select2.full.min.js" type="text/javascript"></script>
	<script>
  $(function () {
	  
	  $("#itemsearchtext").keyup(function(){
		 
		$.ajax({
		type: "POST",
		url: "wholesale_search.php",
		data:'itemsearchtext='+$(this).val(),
		beforeSend: function(){
			 
			//$("#clientname").css("background","#FF0");
		},
		success: function(data){ 
			$("#searchresulthere").html(data); 
			  
		}
		});
	});
    //Initialize Select2 Elements
    $('.select2').select2();

	//SelectElement("receiptmode", valueToSelect);
	//alert();
	 
	$('#change_display').hide();

	$("#receiptmode").change(function()
    {
		//$('#change_display').hide();
		var id=$(this).val();
		
		var totalbill = 0.00;
				
			$("#cartitemstable").children("tbody").children("tr").each(function(i) 
			{
				$tr = $(this);
				var useindex = 0;

				$("td", $tr).each(function() 
				{
					 
					
					if(useindex == 4)
					{
						totalbill += parseFloat($(this).text().replace(/[^0-9\.]/g,""));
					}
					
					useindex +=1;
				});
			});

		 
         
         return false;
    });
 
  })
  
  // AJAX call for autocomplete 
$(document).ready(function(){
	$("#search-card").css("background","#ffe6e6");
	
	$("#search-card").keyup(function(){
		 
		$.ajax({
		type: "POST",
		url: "get_customers.php",
		data:'keyword='+$(this).val(),
		beforeSend: function(){
			 
			$("#clientname").css("background","#f39c12");
		},
		success: function(data){ 
			$("#clientname").html(data); 
			 
			$("#clientname").css("background","#FFFF00");
			$("#search-card").css("background","#ffffff");
		}
		});
	});
});
//To select country name
 
</script>
	</body>
</html>