<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>

<!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
          <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-inline-block">Issues</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">Issues</a>
                  </li>
                  <li class="breadcrumb-item active">Issue Entry
                  </li>
                </ol>
              </div>
            </div>
          </div>
          
        </div>
        <div class="content-body"><!-- Basic form layout section start -->
<section id="basic-form-layouts">
	<div class="row justify-content-md-center">
		<div class="col-md-12">
		    <form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addPrCCarnivalIssue');?>" method="post">
			<div class="card">
				<!--<div class="card-header">
				<h4 class="card-title" id="basic-layout-form-center">Issue Entry</h4>
					<a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
					<div class="heading-elements">
						<ul class="list-inline mb-0">
							<li><a data-action="collapse"><i class="ft-minus"></i></a></li>
							<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
							<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
							<li><a data-action="close"><i class="ft-x"></i></a></li>
						</ul>
					</div>
				</div>-->
				<div class="card-content collapse show">
					<div class="card-body">
						
							<div class="row justify-content-md-center">
								<div class="col-md-4 column mleft">
									<div class="form-body">
										<div class="form-group">
										<?php $cur_date = date("d-m-Y"); 
										$branch_id = $_SESSION['branch_id'];
										$branch_name = $_SESSION['branch_name'];
										$full_name = $_SESSION['full_name']; ?>
											<label for="eventInput1">Issue Date</label>
											<input class="form-control" type="text" name="issue_date" id="issue_date" value="<?php echo $cur_date ?>" readonly >
										</div>
									</div>
								</div>
								<div class="col-md-4 column">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Kitchen</label>
											<select name="branch_id" id="branch_id" class="form-control select2" required>
												<option value="">Select Kitchen</option>
											<?php  foreach($vnk as $vk)
														{
														?>
														<option value="<?php echo $vk->branch_id ?>"><?php echo $vk->branch_name ?></option>
														<?php
														}
														?>
											</select>
											
										<!--	<input type="hidden" id="branch_id" class="form-control"  name="branch_id" value="<?php //echo $branch_id;?>">
											<input type="hidden" id="branch_name" class="form-control"  name="branch_name" value="<?php //echo $branch_name;?>">
											<input type="hidden" id="full_name" class="form-control"  name="full_name" value="<?php //echo $full_name;?>">-->
											
										</div>
									</div>
								</div>
								<div class="col-md-4 column">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Outlet</label>
											<select name="outlet" id="outlet" class="form-control select2" required>
												<option value="">Select Outlet</option>
											<?php  foreach($ctr as $ct)
														{
														?>
														<option value="<?php echo $ct->branch_name ?>"><?php echo $ct->branch_name ?></option>
														<?php
														}
														?>
											</select>
											<?php //foreach($cdept as $dept) ?>
										<!--	<input class="form-control" type="text" name="outlet" id="outlet" value="<?php //echo $dept->access_branch; ?>" readonly >-->
										</div>
									</div>
								</div>
							</div>
						</div>
		</div>
	</div>
		<div class="card">
			
				<div class="card-content collapse show">
					<div class="card-body">
					   
					    
					<div class="row">
						<div class="text_increment">
							<div>
									<div class="row">
    									<div class="col-md-6">
    										<div class="form-group">
    											<select name="item_name[]" id="item_name" class="form-control select2" required>
    												<option value="">Select Item</option>
    												<?php  foreach($items as $row)
    													{
    												?>
    													<option value="<?php echo $row->rname ?>"><?php echo $row->rname ?></option>
    												<?php
    													} 
    												?>
    											</select>
    										
    										</div>
    									</div>
								
    								
    									<div class="col-md-5">
    									    
    										<div class="form-group">
    											<input class="form-control quantity" type="text"  name="quantity[]"  id="quantity" required style="    margin-left: 15px!important;" placeholder="QTY" />
    												<input class="form-control" type="hidden" name="it_name[]" id="it_name" readonly />
    											<input class="form-control" type="hidden" name="uom[]" id="uom"  readonly  placeholder="UOM" />
    											<input class="form-control" type="hidden" name="price[]" id="price" readonly />
    											<input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price" readonly />
    											<input class="form-control" type="hidden" name="tax[]" id="tax" readonly />
    											<input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt" readonly />
    											<input class="form-control t_amt" type="hidden" name="total[]" id="total" readonly />
    											<input class="form-control" type="hidden" name="remarks[]" id="remarks" Placeholder="Remarks"/>
    											<input class="form-control" type="hidden" name="item_id[]" id="item_id"  readonly />
    											<input class="form-control" type="hidden" name="cat_id[]" id="cat_id" readonly />
    											<input class="form-control" type="hidden" name="itm_id[]" id="itm_id" readonly />
    											<input class="form-control" type="hidden" name="close_stock[]"  id="close_stock" readonly placeholder="CSTK"/>
    										</div>
    										
    									</div>
									
									
								</div>
							</div>	
						</div>
					</div>
						<input class="form-control" type="hidden" name="total_amt" id="total_amt" readonly placeholder="Total Amount"/>
</div>
		</div>
	</div>
		<div class="card">
			
				<div class="card-content collapse show">
					<div class="card-body">
							<div class=" ">
								<div class="row">
        							<div class="col-md-12">
        								<button type="reset form-control" class="btn btn-warning mr-1">
        									<i class="ft-x"></i> Cancel
        								</button>
        								<button type="submit form-control" class="btn btn-primary">
        									<i class="la la-check-square-o"></i> Save
        								</button>
        									
        							</div>
							</div>
						</div>
						</div>
					</div>
				</div>
				<div class="col-md-1 md-fab-wrapper plus mleft">
				    <a href="javascript:void(0);" class="add_button" title="Add field" id="addprouct"><i class="la la1 la-plus-circle"></i>
					<!--<img src="<?php //echo base_url(); ?>app-assets/images/add-icon.png" class="image_logo"/>-->
					</a>
				
				</div>
				<br/>
			</div>
			</form>	
		</div>
	</div>

</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <?php //require('include/theme_customizer.php');?>

   <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
<script type="text/javascript">
		$(document).ready(function(){
			var maxField = 100; //Input fields increment limitation
			var addButton = $('.add_button'); //Add button selector
			var wrapper = $('.text_increment'); //Input field wrapper
			var x = 1; //Initial field counter is 1
			var counter = 1;
			//$(addButton).click(function(){ 
			$(document).on("click",".add_button",function() {  //Once add button is clicked
				if(x < maxField){ //Check maximum number of input fields
					x++; //Increment field counter
					$(wrapper).append('<div><div class="row"><div class="col-md-6"><div class="form-group"><select name="item_name[]" id="item_name'+counter+'" class="form-control select2" required><option value="">Select Item</option><?php  foreach($items as $row) { ?><option value="<?php echo $row->rname ?>"><?php echo $row->rname ?></option><?php } ?></select><input class="form-control" type="hidden" name="it_name[]" id="it_name'+counter+'" readonly /><input class="form-control" type="hidden" name="uom[]" id="uom'+counter+'"  readonly  placeholder="UOM" /></div></div><div class="col-md-5 "><div class="form-group"><input class="form-control quantity" type="text"  name="quantity[]"  id="quantity'+counter+'" required style="    margin-left: 15px!important;" placeholder="QTY" /><input class="form-control price" type="hidden" name="price[]" id="price'+counter+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+counter+'" readonly /><input class="form-control" type="hidden" name="tax[]" id="tax'+counter+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+counter+'" readonly /><input class="form-control t_amt" type="hidden" name="total[]" id="total'+counter+'" readonly /><input class="form-control" type="hidden" name="remarks[]" id="remarks'+counter+'" Placeholder="Remarks"/><input class="form-control" type="hidden" name="item_id[]" id="item_id'+counter+'"  readonly /><input class="form-control" type="hidden" name="cat_id[]" id="cat_id'+counter+'" readonly /><input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+counter+'" readonly /><input class="form-control" type="hidden" name="close_stock[]" id="close_stock'+counter+'" readonly placeholder="CSTK"/></div></div><div class="col-md-1 remove_button"><a href="javascript:void(0);" class="" title="Remove field"><img src="<?php echo base_url(); ?>app-assets/images/remove-icon.png" class="image_logo"/></a></div></div></div>'); 
				//	$(wrapper).append('<div><div class="row"><div class="col-md-3"><div class="form-group"><select name="item_name[]" id="item_name'+counter+'" class="form-control select2" required><option value="0">Select Item</option><?php  //foreach($items as $row) { ?><option value="<?php //echo $row->rname ?>"><?php //echo $row->rname ?></option><?php //} ?></select><input class="form-control" type="hidden" name="it_name[]" id="it_name'+counter+'" readonly /><input class="form-control" type="hidden" name="uom[]" id="uom'+counter+'"  readonly  placeholder="UOM" /></div></div><div class="col-md-3"><div class="form-group"><input class="form-control quantity" type="text"  name="quantity[]"  id="quantity'+counter+'" required placeholder="QTY" /><input class="form-control price" type="hidden" name="price[]" id="price'+counter+'" readonly /><input class="form-control" type="hidden" name="ttl_price[]" id="ttl_price'+counter+'" readonly /><input class="form-control" type="hidden" name="tax[]" id="tax'+counter+'" readonly /><input class="form-control" type="hidden" name="tax_amt[]" id="tax_amt'+counter+'" readonly /><input class="form-control t_amt" type="hidden" name="total[]" id="total'+counter+'" readonly /><input class="form-control" type="hidden" name="remarks[]" id="remarks'+counter+'" Placeholder="Remarks"/><input class="form-control" type="hidden" name="item_id[]" id="item_id'+counter+'"  readonly /><input class="form-control" type="hidden" name="cat_id[]" id="cat_id'+counter+'" readonly /><input class="form-control" type="hidden" name="itm_id[]" id="itm_id'+counter+'" readonly /></div></div><div class="col-md-1 remove_button remove_bt"><a href="javascript:void(0);" class="" title="Remove field"><img src="<?php //echo base_url(); ?>app-assets/images/remove-icon.png" class="image_logo"/></a></div></div></div>'); 
					//alert(counter);
					$(function () {
						$(".select2").select2();
						$('#quantity' + counter).keypress(function(e) {
							var a = [];
							var k = e.which;
							for (i = 46; i < 58; i++)
							a.push(i);
							if (!($.inArray(k,a)>=0))
							e.preventDefault();
						});
					});
					
				//	$("#addprouct").click(function() {
				/*        var id = $(this).attr('id');
				        //alert(id);
				        id_length = id.length;
				        //alert(id_length);
				     //   counts = 1;
				     //   if(id_length == 9) {
				            //counts = id.substr(-1);
				           // alert(counts);
				            var vbranch_id = $('#vkitchen').val();
				            //alert(vbranch_id);
				            $('#item_name'+counter).val('');
				            $.ajax({
								type :'POST',
								dataType:'json',
								data : { branch_id : vbranch_id },
            				    url: '<?php //echo base_url();?>index.php/ProductRequest/getVkitchenProduct',
								success: function(data) {
									$('#item_name'+counter).empty();
									$('#item_name'+counter).append('<option value="">Select Product</option>');
									for(var j=0;j<data.length;j++) {
										var iname = data[j].rname;
										$('#item_name'+counter).append('<option value="'+data[j].rname+'">'+data[j].rname+'</option>');
										//alert(iname);
									}
								}
							});
						//	counts = counts + 1;
				     //   }
				        else
				        {
				            counts = id.substr(-2);
				            var vbranch_id = $('#vkitchen').val();
				            $('#item_name'+counts).val('');
				            $.ajax({
								type :'POST',
								dataType:'json',
								data : { branch_id : vbranch_id },
            				    url: '<?php //echo base_url();?>index.php/ProductRequest/getVkitchenProduct',
								success: function(data) {
									$('#item_name'+counts).empty();
									$('#item_name'+counts).append('<option value="">Select Product</option>');
									for(var j=0;j<data.length;j++) {
										var iname = data[j].rname;
										$('#item_name'+counts).append('<option value="'+data[j].rname+'">'+data[j].rname+'</option>');
										//alert(iname);
									}
								}
							});
							counts = counts + 1;
				        } */
            			
            		$('#item_name' + counter).change(function(){
						var id = $(this).attr('id');
						// alert(id);
						id_length = id.length;
						if(id_length == 10) {
							counts = id.substr(-1);
							var i_name = $('#item_name'+counts).val();
							var branch_id = $('#branch_id').val();
							$.ajax({
								type :'POST',
								dataType:'json',
								data : { iname : i_name,br_id : branch_id },
								url : '<?php echo base_url();?>index.php/ProductRequest/get_ProductDetails',
								success: function(data) {
									//alert(data.price);
									$('#uom'+counts).val(data.uom);
									$('#item_id'+counts).val(data.item_id);
									$('#cat_id'+counts).val(data.category_id);
									$('#price'+counts).val(data.dc_price);
									$('#tax'+counts).val(data.dc_tax);
									$('#close_stock'+counts).val(data.stock_item);
									$('#itm_id'+counts).val(data.itm_id);
									
								}
							});
							//$("#item_name"+ counts).attr('disabled', 'disabled');
						}
						else{
							counts = id.substr(-2);
							var i_name = $('#item_name'+counts).val();
							var branch_id = $('#branch_id').val();
							//alert(i_name);
							//alert(brname);
							$.ajax({
								type :'POST',
								dataType:'json',
								data : { iname : i_name,br_id : branch_id },
								url : '<?php echo base_url();?>index.php/ProductRequest/get_ProductDetails',
								success: function(data) {
									//alert(data.price);
									$('#uom'+counts).val(data.uom);
									$('#item_id'+counts).val(data.item_id);
									$('#cat_id'+counts).val(data.category_id);
									$('#price'+counts).val(data.dc_price);
									$('#tax'+counts).val(data.dc_tax);
									$('#close_stock'+counts).val(data.stock_item);
									$('#itm_id'+counts).val(data.itm_id);
								}
							});
							//$("#item_name"+ counts).attr('disabled', 'disabled');
						}
					});
															
					$('#quantity'+counter).on('keyup',function() {
						var id = $(this).attr('id');
						id_length = id.length;
						if(id_length == 9) {
							counts = id.substr(-1);
							var qty = $('#quantity'+ counts).val();
							var stock = $('#close_stock'+ counts).val();
							var price = $('#price'+ counts).val();
							var tax = $('#tax'+ counts).val();
							var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than the stock");
								$('#quantity'+counts).val(lt);
								$('#ttl_price'+ counts).val(lt);
								$('#tax_amt'+ counts).val(lt);
								$('#total'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(result)) {
									$('#ttl_price'+ counts).val(result);
									$('#tax_amt'+ counts).val(tax_amt);
									$('#total'+ counts).val(total);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
						else
						{
							counts = id.substr(-2);
							var qty = $('#quantity'+ counts).val();
							var stock = $('#close_stock'+ counts).val();
							var price = $('#price'+ counts).val();
							var tax = $('#tax'+ counts).val();
							var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
							var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than stock");
								$('#quantity'+counts).val(lt);
								$('#ttl_price'+ counts).val(lt);
								$('#tax_amt'+ counts).val(lt);
								$('#total'+ counts).val(lt);
							}
							else
							{
								if (!isNaN(result)) {
									$('#ttl_price'+ counts).val(result);
									$('#tax_amt'+ counts).val(tax_amt);
									$('#total'+ counts).val(total);
								}
								var sum = 0;
								$('.t_amt').each(function() {
									sum += Number($(this).val());
								});
								$('#total_amt').val(sum.toFixed(2));
							}
						}
					});
				}
				//alert(counter);
				counter++;
			});
			$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
				e.preventDefault();
				$(this).parent('div').remove(); //Remove field html
				x--; //Decrement field counter
				counter--;
			});
		});
	</script>
	<script>
	 /*   $("#vkitchen").change(function() {
			var vbranch_id = $('#vkitchen').val();
			$('#item_name').val('');
			//alert(vbranch_id); 
			$.ajax({
				type :'POST',
				dataType:'json',
				data : { branch_id : vbranch_id },
				url: '<?php //echo base_url();?>index.php/ProductRequest/getVkitchenProduct', 
				success: function(data) {
					$('#item_name').empty();
				//	alert(data.rname);
					$('#item_name').append('<option value="">Select Product</option>');
					for(var j=0;j<data.length;j++) {
						var iname = data[j].rname;
						$('#item_name').append('<option value="'+data[j].rname+'">'+data[j].rname+'</option>');
						//alert(iname);
					}
				}
			});
		}); */
	</script>
	<script>
		$("#item_name").change(function(){
			var i_name = $('#item_name').val();
			var branch_id = $('#branch_id').val();
			//alert(i_name);
			//alert(brname);
			$.ajax({
				type :'POST',
				dataType:'json',
				data : { iname : i_name,br_id : branch_id },
				url : '<?php echo base_url();?>index.php/ProductRequest/get_ProductDetails',
				success: function(data) {
					//alert(data.price);
					$('#uom').val(data.uom);
					$('#item_id').val(data.item_id);
					$('#cat_id').val(data.category_id);
				    $('#price').val(data.dc_price);
					$('#tax').val(data.dc_tax);
					$('#close_stock').val(data.stock_item);
					$('#itm_id').val(data.itm_id);
				}
			});
			//$("#item_name").attr('disabled', 'disabled');
		});
	</script>
	<script>
		$('#quantity').on('keyup',function() {
			var qty = $('#quantity').val();
			var stock = $('#close_stock').val();
			var price = $('#price').val();
			var tax = $('#tax').val();
			var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
			var tax_amt = ((parseFloat(result) * parseFloat(tax)) / 100).toFixed(2);
			var total = (parseFloat(result) + parseFloat(tax_amt)).toFixed(2);
			if(parseFloat(qty) > parseFloat(stock))
			{
				var lt = 0;
				alert("you cant enter more than the stock");
				$('#quantity').val(lt);
				$('#ttl_price').val(lt);
				$('#tax_amt').val(lt);
				$('#total').val(lt);
			}
			else
			{
				if (!isNaN(result)) {
					$('#ttl_price').val(result);
					$('#tax_amt').val(tax_amt);
					$('#total').val(total);
				}
				var sum = 0;
				$('.t_amt').each(function() {
					sum += Number($(this).val());
				});
				//alert(sum);
				$('#total_amt').val(sum.toFixed(2));
			}
		});
	</script>
	<script>
		$(window).on('beforeunload', function () {
			//$("input[type=submit], input[type=button]").prop("disabled", "disabled");
			$("input[type=submit]").prop("disabled", "disabled");
			$("#submit").css("background-color","#dcdcdc");
		});
	</script>
	
  </body>
  <!-- END: Body-->

<!-- Mirrored from pixinvent.com/modern-admin-clean-bootstrap-4-dashboard-html-template/html/ltr/vertical-modern-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Apr 2020 09:38:02 GMT -->
</html>