<?php 
$header_file=APPPATH.'views/include/header.php';
require($header_file);
$sidenav_file=APPPATH.'views/include/sidenav.php';
require($sidenav_file);	?>
<style>
 div.chosen-container {
    width: 100%!important;
}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 400px), only screen and (min-resolution: 1200px) {
  .chosen-rtl .chosen-search input[type="text"],
  .chosen-container-single .chosen-single abbr,
  .chosen-container-single .chosen-single div b,
  .chosen-container-single .chosen-search input[type="text"],
  .chosen-container-multi .chosen-choices .search-choice .search-choice-close,
  .chosen-container .chosen-results-scroll-down span,
  .chosen-container .chosen-results-scroll-up span {
    background-image: url("chosen-sprite@2x.png") !important;
    background-size: 52px 37px !important;
    background-repeat: no-repeat !important;
  }
}

</style>
<!-- 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">Product Request</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="#">Product Request </a>
							</li>
							<li class="breadcrumb-item active">Product Request
							</li>
						</ol>
					</div>
				</div>
			</div>
		</div>
		<div class="content-body"><!-- Basic form layout section start -->
			<section id="basic-form-layouts">
				<form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addPr_RequestIOF');?>" method="post">
					<div class="row justify-content-md-center">
						<div class="col-md-12">
							<div class="card">
								<div class="card-content collapse show">
									<div class="card-body">									
										<div class="row justify-content-md-center">
											<div class="col-md-6 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">Request Date</label>
													<input class="form-control" type="text" name="order_date" id="order_date" value="<?php echo $cur_date ?>" readonly >
													</div>
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-body">
													<div class="form-group">
														<label for="eventInput1">Store</label>
														<!--<select name="store" id="store" class="form-control select2" required>
														<option value="0">Select Store</option>
														<?php /* foreach($store as $st)
														{
														?>
														<option value="<?php echo $st->access_username ?>"><?php echo $st->access_username ?></option>
														<?php
														}*/
														?>
														</select>-->
														<input class="form-control" type="text" name="dept" id="dept" value="Store" readonly >
														<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>
									</div>
								</div>
							</div>
							<div class="card">
								<div class="card-content collapse show">
									<div class="card-body">	
										<div class="row justify-content-md-right">
											<div class="text_increment">
												<div>
													<div class="row">
														<div class="col-6 col-md-4">
															<div class="form-group">
																<select name="product_name[]" id="product_name" class="chosen-select-deselect disabled-select" required>
																<option value="0">Select Product</option>
																<?php  
																	foreach($items as $r1)
																	{
																?>
																<option value="<?php echo $r1->rname ?>"><?php echo $r1->rname ?></option>
																<?php
																	} 
																?>
																</select>
																<input class="form-control" type="hidden" name="it_name[]" id="it_name" readonly />
																<input class="form-control product_details" type="hidden" name="cat_id[]" id="cat_id" readonly />
																<input class="form-control product_details" type="hidden" name="rc_no[]" id="rc_no" readonly />
																<input class="form-control product_details" type="hidden" name="flavour[]" id="flavour" readonly />
															</div>
														</div> 
														<div class="col-md-1 d-none d-sm-block">
															<div class="form-group">
																<input class="form-control" type="text" name="uom[]" id="uom"  readonly  placeholder="UOM" />
															</div>
														</div>
														<div class="col-md-1 d-none d-sm-block">
															<div class="form-group">
																<input class="form-control product_details" type="text" name="prst_stk[]"  id="prst_stk" readonly  placeholder="CSTK"/>
															</div>
														</div>
														<div class="col-5 col-md-1">
															<div class="form-group">
																<input class="form-control quantity" type="text"  name="quantity[]"  id="quantity" required placeholder="QTY" />
															</div>
														</div>
														<div class="col-md-4 col-md-half-three d-none d-sm-block">
															<div class="form-group">
																<input class="form-control batch_no" type="text" name="remarks[]" id="remarks" Placeholder="Remarks"/>
																<input class="form-control product_details" type="hidden" name="item_id[]" id="item_id"  readonly />
															</div>
														</div>
														<a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="<?php echo base_url(); ?>app-assets/images/remove-icon.png" class="image_logo"/></a>
													</div>
												</div>	
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="card">
								<div class="card-content collapse show">
									<div class="card-body">
										<div class="text-right">
											<div class="row">
												<div class="col-md-2 mleft">
													<div class="form-group">
														
													</div>
												</div>
												<div class="col-md-8 mleft">
													<button type="reset" class="btn btn-md btn-warning mr-1"> Cancel</button>
													<input type="submit" class="btn btn-md btn-primary" onclick="return confirm('Are you sure you want to submit this form?')" value="Save">
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="col-md-1 md-fab-wrapper plus">
								<a href="javascript:void(0);" class="add_button" title="Add field"><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>
						</div>
					</div>
				</form>
			</section>
		</div>
	</div>
</div>
<?php //require('include/theme_customizer.php');?>
<?php 
	$footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>app-assets/js/chosen/chosen.css" />
<script src="<?php echo base_url(); ?>app-assets/js/chosen/3.3.1_jquery.min.js"></script>
<script src="<?php echo base_url(); ?>app-assets/js/chosen/chosen.jquery.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>app-assets/js/chosen/prism.js" type="text/javascript" charset="utf-8"></script>
<script src="<?php echo base_url(); ?>app-assets/js/chosen/init.js" type="text/javascript" charset="utf-8"></script> 


<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
	    $('.disabled-select').on('change', function () {
            $('option').prop('disabled', false);
            $('.disabled-select').each(function () {
                var val = this.value;
                $('.disabled-select').not(this).find('option').filter(function () {
                    return this.value === val;
                }).prop('disabled', true);
            });
            $('.disabled-select').chosen().trigger("chosen:updated");
        });
         $(function () {    
             $('option').prop('disabled', false);
                    $('.disabled-select').each(function () {
                        var val = this.value;
                        $('.disabled-select').not(this).find('option').filter(function () {
                            return this.value === val;
                        }).prop('disabled', true);
                    });
                    $('.disabled-select').chosen().trigger("chosen:updated");
         });

		if(x < maxField){ //Check maximum number of input fields
			x++; //Increment field counter
			$(wrapper).append('<div><div class="row"><div class="col-6 col-md-4"><div class="form-group"><select name="product_name[]" id="product_name'+counter+'" class="chosen-select-deselect disabled-select  " required><option value="0">Select Product</option><?php  foreach($items as $r1) { ?><option value="<?php echo $r1->rname ?>"><?php echo $r1->rname ?></option><?php } ?></select><input class="form-control" type="hidden" name="it_name[]" id="it_name'+counter+'" readonly /><input class="form-control product_details" type="hidden" name="cat_id[]" id="cat_id'+counter+'" readonly /><input class="form-control product_details" type="hidden" name="rc_no[]" id="rc_no'+counter+'" readonly /><input class="form-control product_details" type="hidden" name="flavour[]" id="flavour'+counter+'" readonly /></div></div><div class="col-md-1 d-none d-sm-block"><div class="form-group"><input class="form-control" type="text" name="uom[]" id="uom'+counter+'"  readonly  placeholder="UOM" /><input class="md-input product_details " type="hidden"  name="item_id[]"  id="item_id'+counter+'"/></div></div><div class="col-md-1 d-none d-sm-block"><div class="form-group"><input class="form-control product_details" type="text" name="prst_stk[]" placeholder="Cls Stk" id="prst_stk'+counter+'" readonly/></div></div><div class="col-5 col-md-1"><div class="form-group"><input class="form-control quantity" type="text"  name="quantity[]"  id="quantity'+counter+'" required placeholder="QTY" /></div></div><div class="col-md-4 d-none d-sm-block col-md-half-three"><div class="form-group"><input class="form-control" type="text" name="remarks[]" id="remarks'+counter+'" Placeholder="Remarks"/></div></div><div class="col-1 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>'); 
				//alert(counter);
				$('.disabled-select').on('change', function () {
                    $('option').prop('disabled', false);
                    $('.disabled-select').each(function () {
                        var val = this.value;
                        $('.disabled-select').not(this).find('option').filter(function () {
                            return this.value === val;
                        }).prop('disabled', true);
                    });
                    $('.disabled-select').chosen().trigger("chosen:updated");
                });
				$(function () {
				    $('option').prop('disabled', false);
                    $('.disabled-select').each(function () {
                        var val = this.value;
                        $('.disabled-select').not(this).find('option').filter(function () {
                            return this.value === val;
                        }).prop('disabled', true);
                    });
				    $('.disabled-select').chosen().trigger("chosen:updated");
					//$(".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();
					});
				});

				$('#product_name' + counter).change(function(){
					var id = $(this).attr('id');
					//alert(id);
					id_length = id.length;
					//alert(id_length);
					if(id_length == 13) {
						counts = id.substr(-1);
						var i_name = $('#product_name'+counts).val();
						var branch_id = $('#branch_id').val();
						//alert(i_name);
						//alert(branch_id);
						$.ajax({
							type :'POST',
							dataType:'json',
							data : { iname : i_name,br_id : branch_id },
							url : '<?php echo base_url();?>index.php/Master/get_RecipeDetails',
							success: function(data) {
							//alert(data.price);
								$('#uom'+counts).val(data.uom);
								$('#uom'+counts).blur();
								$('#prst_stk'+counts).val(data.stock);
								$('#prst_stk'+counts).blur();
								$('#item_id'+counts).val(data.recipe_id);
								$('#item_id'+counts).blur();
								$('#cat_id'+counts).val(data.pr_cat_id);
								$('#cat_id'+counts).blur();
								$('#flavour'+counts).val(data.flavour);
								$('#flavour'+counts).blur();
								$('#rc_no'+counts).val(data.recipe_no);
							}
						});
					}
					else{
						counts = id.substr(-2);
						var i_name = $('#product_name'+counts).val();
						var branch_id = $('#branch_id').val();
						//alert(i_name);
						//alert(branch_id);
						$.ajax({
							type :'POST',
							dataType:'json',
							data : { iname : i_name,br_id : branch_id },
							url : '<?php echo base_url();?>index.php/Master/get_RecipeDetails',
							success: function(data) {
								//alert(data.price);
								$('#uom'+counts).val(data.uom);
								$('#uom'+counts).blur();
								$('#prst_stk'+counts).val(data.stock);
								$('#prst_stk'+counts).blur();
								$('#item_id'+counts).val(data.recipe_id);
								$('#item_id'+counts).blur();
								$('#cat_id'+counts).val(data.pr_cat_id);
								$('#cat_id'+counts).blur();
								$('#flavour'+counts).val(data.flavour);
								$('#flavour'+counts).blur();
								$('#rc_no'+counts).val(data.recipe_no);
							}
						});
					}
				});

				$('#quantity'+counter).on('keyup',function() {
					var id = $(this).attr('id');
					id_length = id.length;
					//alert(id_length);
					if(id_length == 9) {
						//alert(id1);
						counts = id.substr(-1);
						var qty = $('#quantity'+ 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);
						$('#ttl_price'+ counts).val(result);
						$('#tax_amt'+ counts).val(tax_amt);
						$('#total'+ counts).val(total);
					}
					else{
						counts = id.substr(-1);
						var qty = $('#quantity'+ 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);
						$('#ttl_price'+ counts).val(result);
						$('#tax_amt'+ counts).val(tax_amt);
						$('#total'+ counts).val(total);
					}
				});
			}
		//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>
	$("#product_name").change(function(){
		var i_name = $('#product_name').val();
		var branch_id = $('#branch_id').val();
		//alert(i_name);
		//alert(branch_id);
		$.ajax({
			type :'POST',
			dataType:'json',
			data : { iname : i_name,br_id : branch_id },
			url : '<?php echo base_url();?>index.php/Master/get_RecipeDetails',
			success: function(data) {
				//alert(data.uom);
				$('#uom').val(data.uom);
				$('#uom').blur();
				$('#prst_stk').val(data.stock);
				$('#prst_stk').blur();
				$('#item_id').val(data.recipe_id);
				$('#item_id').blur();
				$('#cat_id').val(data.pr_cat_id);
				$('#cat_id').blur();
				$('#flavour').val(data.flavour);
				$('#flavour').blur();
				$('#rc_no').val(data.recipe_no);
			}
		});
		//$("#item_name").attr('disabled', 'disabled');
	});
$('.disabled-select').on('change', function () {
    $('option').prop('disabled', false);
    $('.disabled-select').each(function () {
        var val = this.value;
        $('.disabled-select').not(this).find('option').filter(function () {
            return this.value === val;
        }).prop('disabled', true);
    });
    $('.disabled-select').chosen().trigger("chosen:updated");
});
</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>