<?php
	include("includes/dbconfig.php");
	$pagetitle = "Receive Store Stock";
	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">
					<h1>Receive Store Stock</h1>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] == 2)
						{
					?>
					<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-primary"><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: 500px;">
								<div class="card-body">
									<div class="form-group col-md-12">
										<div class="form-group">
											<label for="supplier">Supplier</label>
											<select  class="form-control" name="supplier" id="supplier" data-placeholder="Choose One">
												<option value="">Choose One</option>
												<?php
													$supplierdata = DB::query("SELECT id, supplier_name FROM supplier WHERE supplier_status = 1");
													
													foreach($supplierdata as $supplier)
													{
												?>
													<option value="<?php echo $supplier['id']; ?>"><?php echo $supplier['supplier_name']; ?></option>';
												<?php
													}
												?>
											</select>
										</div><!-- form-group -->
									</div><!-- form-group -->
									
									<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>
									
									<div class="form-group col-md-12">
										<textarea name="memo" id="memo" rows="12" placeholder="Additional Notes ..." maxlength="195" class="form-control"></textarea>
									</div><!-- form-group -->
									
									<div class="btn-list col-md-12 text-center">
										<button onclick="cancelreceive()" class="btn btn-danger"><i class="fa fa-remove"></i> Cancel Stock</button>
										
										<button onclick="processreceive()" class="btn btn-success"><i class="fa fa-floppy-disk"></i> Process Stock</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 -->

			<footer class="main-footer text-center">
				<strong>Copyright &copy; <?php echo date("Y"); ?> BSMPOS.</strong> All rights reserved.
			</footer>
		</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 . $ajax_loading_image; ?>" />
					</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>
						
						 
						<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>
        <!-- /.row -->
						 
					</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.js" type="text/javascript"></script>
		<script src="plugins/bert/receivestorestock.js" type="text/javascript"></script>
		
		<script src="plugins/js/select2.full.min.js" type="text/javascript"></script>
		
		<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2();

	//SelectElement("receiptmode", valueToSelect);
	//alert();
	function test(){
		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","#FF0");
		},
		success: function(data){ 
			$("#clientname").html(data); 
			 
			$("#clientname").css("background","#ffcccc");
			$("#search-card").css("background","#ffffff");
		}
		});
	});
	
	//search for items here
	
	$("#itemsearchtext").keyup(function(){
		 
		$.ajax({
		type: "POST",
		url: "items_search2.php",
		data:'itemsearchtext='+$(this).val(),
		beforeSend: function(){
			 
			//$("#clientname").css("background","#FF0");
		},
		success: function(data){ 
			$("#searchresulthere").html(data); 
			  
		}
		});
	});
});
//To select country name
 
</script>
	</body>
</html>