<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>
<style>
.card {
    margin-bottom: 0.475rem!important;
    border: none!important;
    box-shadow: 0 2px 18px 1px rgb(49 53 72 / 10%)!important;
    border-radius: .45rem!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">GRN </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="#">Purchase Order</a>
                  </li>
                  <li class="breadcrumb-item active">GRN 
                  </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('Maintainance/addGrn');?>" method="post" enctype="multipart/form-data">
	<div class="row justify-content-md-center">
		<div class="col-md-12">
		    	
			<div class="card">
				<div class="card-header">
					<h4 class="card-title" id="basic-layout-form-center">Purchase Order</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="row justify-content-md-left">
					<div class="col-md-2">
    					<div class="form-group">
    						<label>GRN DATE</label>
    						<?php $cur_date = date("d-m-Y"); ?>
							<input class="form-control" type="text" name="grn_date"  id="uk_dp_1" value="<?php echo $cur_date; ?>" readonly >
    					</div>
    				</div>
    				<div class="col-md-2">
    					<div class="form-group">
    						<label>INVOICE NO</label>
							<input class="form-control" type="text" name="grn_invoice" id="grn_invoice" required >
    					</div>
    				</div>
    				<div class="col-md-3">
    					<div class="form-group">
    						<label>INVOICE DATE</label>
							
							<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="grn_inv_date"  id="grn_inv_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date">	
    					</div>
    				</div>
    				<div class="col-md-3">
    					<div class="form-group">
    						<label for="eventInput1">Supplier</label>
							<select name="vender_name" id="vender_name" class="form-control select2" required >
								<option value="0">Select</option>
								<?php  foreach($vendor as $vrow)
									{
										echo '<option value="'.$vrow->company_name.'">'.$vrow->company_name.'</option>';
									} 
								?>
							</select>
    					</div>
    				</div>
    				
    				<div class="col-md-2">
    					<div class="form-group">
    						<label>INVOICE UPLOAD</label>
    						<input type="file" name="in_upload" id="in_upload" class="form-control" onchange="preview_image();" multiple />
    						<div id="errfn2" ></div>
    						<input type="hidden" name="branchname" id="branchname" class="form-control" value="<?php echo $_SESSION['branch_name']?>"/>
    						<input type="hidden" name="branch_id" id="branch_id" class="form-control" value="<?php echo $_SESSION['branch_id']?>"/>
    						<input type="hidden" name="uname" id="uname" class="form-control" value="<?php echo $_SESSION['username']?>"/>
    						<input type="hidden" name="user_name" id="user_name" class="form-control" value="<?php echo $_SESSION['full_name']?>"/>
    					</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-center">
					<div class="text_increment">
						<div>
							<div class="row">
								<div class="col-md-3">
									<div class="form-group">
										
										<select name="item_name[]" id="item_name" class="form-control itm select2" required >
										<option value="0">Select Item</option>
										<?php  foreach($items as $row)
											{
												echo '<option value="'.$row->item_name.'">'.$row->item_name.'</option>';
											} 
										?>
									</select>
										<input class="form-control product_details" type="hidden" name="it_name[]" id="it_name" readonly />
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control product_details" type="text" name="unit_measurements[]" id="unit_measurements"  readonly  placeholder="UOM" />
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control product_details" type="text" name="close_stock[]"  id="close_stock" readonly placeholder="CSTK"/>
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control product_details quantity" type="text"  name="quantity[]"  id="quantity" required placeholder="QTY" />
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control product_details price" type="text" name="price[]"   id="price"  placeholder="PRICE"/>
										<input class="form-control batch_no" type="hidden" name="basic_amount[]"  id="basic_amount" />
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<select name="tax[]" id="tax" class="form-control select2 txt1" required>
											<option value="0">Select Tax</option>
											<?php  foreach($tax as $row)
												{
													echo '<option value="'.$row->tax_percentage.'">'.$row->tax_percentage.'</option>';
												} 
											?>
										</select>
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control batch_no" type="text" name="tax_amount[]"  id="tax_amount" readonly placeholder="TAMT"/>
									</div>
								</div>
								<div class="col-md-1">
									<div class="form-group">
										<input class="form-control batch_no txt" type="text" name="total_amount[]"  id="total_amount" readonly placeholder="AMT"/>
									</div>
								</div>
								<div class="col-md-1 col-md-half-three">
									<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_sid[]" id="item_sid"  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="itm_id[]" id="itm_id" readonly />
										
									</div>
								</div>
								
							</div>
						</div>	
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="card">
		<div class="card-content collapse show">
			<div class="card-body">
				<div class="md-card-content">
					<div class="row">
						<div class="col-md-2">
							<div class="form-group">
								<label>Courier Charge</label>
								<input class="form-control product_details " type="text" name="courier" id="courier" value="0"  />
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Transport Charge</label>
								<input class="form-control product_details " type="text" name="transport" id="transport" value="0"  />
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Insurance</label>
								<input class="form-control product_details " type="text" name="insurance" id="insurance" value="0"  />
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Total Amount</label>
								<input class="form-control product_details " type="text" name="tamt" id="tamt" value="0" readonly />
							</div>
						</div>
						<div class="col-md-1">
							<div class="form-group">
								<label>Round off</label>
								<input class="form-control product_details " type="text" name="roundoff" id="roundoff" value="0" />
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Final Amount</label>
								<input class="form-control product_details " type="text" name="total_amt" id="total_amt" value="0" readonly />
							</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="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit this form?')">
									<i class="la la-check-square-o"></i> Add GRN
								</button>
						</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>

<div id="image_preview"></div>
	</div>
</form>
</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
     <?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

				$(function() {
					$("select.itm option").show();
					$("select.itm").each(function() {
						if (!$(this).val() == "") {
							$("select.itm").not($(this)).find("option").filter("[value='" + $(this).val() + "']").hide();
						}
					});
				});
				$(function() {
					$("select.itm").change(function() {
						$("select.itm option").show();
						$("select.itm").each(function() {
							if (!$(this).val() == "") {
								$("select.itm").not($(this)).find("option").filter("[value='" + $(this).val() + "']").hide();
							}
						});
					});
				});
				if(x < maxField){ //Check maximum number of input fields
					x++; //Increment field counter
					$(wrapper).append('<div><div class="row"><div class="col-md-3"><div class="form-group"><select id="item_name'+counter+'" name="item_name[]" class="form-control  prm itm select2"  required tabindex=""><option value="0">Select Item</option><?php  foreach($items as $row){	echo '<option value="'.$row->item_name.'">'.$row->item_name.'</option>';} ?></select><input class="form-control product_details" type="hidden" name="it_name[]" id="it_name'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control product_details " type="text"  name="unit_measurements[]" Placeholder="UOM" id="unit_measurements'+counter+'" readonly/><input class="form-control product_details " type="hidden"  name="item_sid[]"  id="item_sid'+counter+'"/><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="itm_id[]" id="itm_id'+counter+'" readonly /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control product_details" type="text" name="close_stock[]" placeholder="CSTK" id="close_stock'+counter+'" readonly/></div></div><div class="col-md-1"><div class="form-group"><input class="form-control product_details quantity1" type="text"  name="quantity[]" Placeholder="QTY" id="quantity'+counter+'" required /></div></div><div class="col-md-1"><div class="form-group"><input class="form-control batch_no price1" type="text" name="price[]" id="price'+counter+'" placeholder="PRICE" /><input class="md-input batch_no total_amount" type="hidden" name="basic_amount[]"  id="basic_amount'+counter+'" /></div></div><div class="col-md-1"><div class="form-group"><select id="tax'+counter+'" name="tax[]" class="form-control select2 txt1"   required ><option value="">TAX</option><?php  foreach($tax as $row) { echo '<option value="'.$row->tax_percentage.'">'.$row->tax_percentage.'</option>';	} ?></select></div></div><div class="col-md-1"><div class="form-group"><input class="form-control batch_no total_amount" type="text" name="tax_amount[]"  id="tax_amount'+counter+'" placeholder="TAMT" readonly/></div></div><div class="col-md-1"><div class="form-group"><input class="form-control batch_no total_amount txt" type="text" name="total_amount[]"  id="total_amount'+counter+'" placeholder="AMT" readonly /></div></div><div class="col-md-1 col-md-half-three"><div class="form-group"><input class="form-control batch_no " type="text" name="remarks[]" id="remarks" placeholder="REMARKS" /></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>'); 
					//alert(counter);

					$("select.itm").change(function() {
						$("select.itm option").show();
						$("select.itm").each(function() {
							if (!$(this).val() == "") {
								$("select.itm").not($(this)).find("option").filter("[value='" + $(this).val() + "']").hide();
							}
						});
					});
					$(function() {
						$("select.itm option").show();
						$("select.itm").each(function() {
							if (!$(this).val() == "") {
								$("select.itm").not($(this)).find("option").filter("[value='" + $(this).val() + "']").hide();
							}
						});
					});
					$(function () {
						$(".select2").select2();
						$("select.chzn-select").chosen({allow_single_deselect:true});
						$('#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();
						});
					});
					//item name auto complete
					$('#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/Master/get_Item_Details',
								success: function(data) {
									//alert(data.price);
									
									$('#unit_measurements'+counts).val(data.uom);
									$('#item_sid'+counts).val(data.item_id);
									$('#cat_id'+counts).val(data.category_id);
									$('#price'+counts).val(data.item_price);
									$('#close_stock'+counts).val(data.stock_item);
									$('#it_name'+counts).val(item_name);
									$('#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/Master/get_Item_Details',
								success: function(data) {
									//alert(data.price);
									$('#unit_measurements'+counts).val(data.uom);
									$('#item_sid'+counts).val(data.item_id);
									$('#cat_id'+counts).val(data.category_id);
									$('#price'+counts).val(data.item_price);
									$('#close_stock'+counts).val(data.stock_item);
									$('#it_name'+counts).val(item_name);
									$('#itm_id'+counts).val(data.itm_id);
								}
							});
							//$("#item_name"+ counts).attr('disabled', 'disabled');
						}
					});
					
					$('.prm').change(function() {
						dropdownval = $(this).val();
					   // alert(dropdownval);
						$('.prm').not(this).find('option[value="' + dropdownval + '"]').remove();
					});
					
					//Total amount calculation
					$('#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 stock = $('#pr_stock'+ counts).val();
							var price = $('#price'+ counts).val();
							//alert(stock);
							var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							//var basic = $('#quantity').val() * $('#price').val();
							if (!isNaN(result)) {
								$('#total_amount'+ counts).val(result);
								$('#basic_amount'+ counts).val(result);
							}
							var sum = 0;
                			$('.txt').each(function() {
                				sum += Number($(this).val());
                			});
                			$('#tot').val(sum.toFixed(2));
                			$('#total_amt').val(sum.toFixed(2));
						}
						else{
							counts = id.substr(-2);
							var qty = $('#quantity'+ counts).val();
							var stock = $('#pr_stock'+ counts).val();
							var price = $('#price'+ counts).val();
							//alert(stock);
							//$("div#result").css("display","none");
							var result = (parseFloat(qty) * parseFloat(price)).toFixed(2);
							//var basic = $('#quantity').val() * $('#price').val();
							if (!isNaN(result)) {
								$('#total_amount'+ counts).val(result);
								$('#basic_amount'+ counts).val(result);
							}
							var sum = 0;
                			$('.txt').each(function() {
                				sum += Number($(this).val());
                			});
                			$('#tot').val(sum.toFixed(2));
                			$('#total_amt').val(sum.toFixed(2));
						}
					});
					// tax caluclation 
					$('#tax' +counter).change(function () {
						var id = $(this).attr('id');
						id_length = id.length;
						//alert(id_length);
						if(id_length == 4) {
							//alert(id1);
							counts = id.substr(-1);
							var ba=$('#basic_amount'   + counts).val();
							var tax=$('#tax'   + counts).val();
							var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
							var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
							$('#tax_amount' +counts).val(tax_a);
							$('#total_amount' +counts).val(total);
							var result = (parseFloat(ba));
							if (!isNaN(result)) {
								$('#total_price' +counts).val(result);
							}
						}
						else{
							counts = id.substr(-2);
							var ba=$('#basic_amount'   + counts).val();
							var tax=$('#tax'   + counts).val();
							var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
							var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
							$('#tax_amount' +counts).val(tax_a);
							$('#total_amount' +counts).val(total);
							var result = (parseFloat(ba));
							if (!isNaN(result)) {
								$('#total_price' +counts).val(result);
							}
						}
					});
					
					//total calculation by selecting tax value
						$('.txt1').change(function () {
						//alert($("#tax").val());
						tax = $("#tax").val();
						tt = $("#total_amount").val();
						//alert(tt);
						var ba=$('#basic_amount').val();
						var tax=$('#tax').val();
						var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
						var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
						$('#tax_amount').val(tax_a);
						$('#tax_amount').blur();
						$('#total_amount').val(total);
						$('#total_amount').blur();
						var result = (parseFloat(ba));
						if (!isNaN(result)) {
							$('#total_price').val(result);
							$('#total_price').blur();
						}
						// initialize the sum (total price) to zero
						var sum = 0;
						$('.txt').each(function() {
							sum += Number($(this).val());
						});
						$('#tot').val(sum.toFixed(2));
					    $('#total_amt').val(sum.toFixed(2));
					});
					$('#price'+counter).on('keyup',function() {
						var id = $(this).attr('id');
						id_length = id.length;
						if(id_length == 6) {
							counts = id.substr(-1);
							var qty = $("#quantity"+counts).val();
							var price = $("#price"+counts).val();
							var tax = $("#tax"+counts).val();
							var total = (parseFloat(qty) *  parseFloat(price));
                			var tax_amt = ((parseFloat(total) * parseFloat(tax))/100);
                			var total_price = (parseFloat(total) +  parseFloat(tax_amt)).toFixed(2);
                			//var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
                			$('#tax_amount'+ counts).val(tax_amt);
                			$('#basic_amount'+ counts).val(total);
                            $('#total_amount'+ counts).val(total_price);
							//var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
							//$('#basic_amount' + counts).val(s);
                            //$('#total_amount'+ counts).val(s);
                            var sum = 0;
                			$('.txt').each(function() {
                				sum += Number($(this).val());
                			});
                			$('#tot').val(sum.toFixed(2));
                			$('#total_amt').val(sum.toFixed(2));
						}
						else
						{
							counts = id.substr(-2);
							var qty = $("#quantity"+counts).val();
							var price = $("#price"+counts).val();
							var tax = $("#tax"+counts).val();
							var total = (parseFloat(qty) *  parseFloat(price));
                			var tax_amt = ((parseFloat(total) * parseFloat(tax))/100);
                			var total_price = (parseFloat(total) +  parseFloat(tax_amt)).toFixed(2);
                			//var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
                			$('#tax_amount'+ counts).val(tax_amt);
                			$('#basic_amount'+ counts).val(total);
                            $('#total_amount'+ counts).val(total_price);
                            var sum = 0;
                			$('.txt').each(function() {
                				sum += Number($(this).val());
                			});
                			$('#tot').val(sum.toFixed(2));
                			$('#total_amt').val(sum.toFixed(2));
						}
					});
					$(document).on("change","#price"+counter+",#quantity"+counter,function() {
						var count = counter-1;
						var a = $("#quantity"+count).val();
						var b = $("#price"+count).val();
						//alert(a);
						//alert(b);
						var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
						$('#basic_amount' + count).val(s);
					});
					$(document).on("keyup","#total_amount"+counter+",#tax"+counter,function() {
						var count = counter-1;
						var ba = $("#basic_amount"+count).val();
						var tax = $("#tax"+count).val();
						var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
						var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
						$('#tax_amount' + count).val(tax_a);
						$('#total_amount' + count).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
				var tamount = $(this).parent().find('.txt').val();
				var gamount = $('#tot').val();
				//alert(tamount);
				var bal_amt = (gamount - tamount).toFixed(2);
				$('#tot').val(bal_amt);
				//x--; //Decrement field counter
				//counter--;
			});
		});
	</script>
<script type='text/javascript'>
		$(window).load(function(){
			$("#quantity,#price").keyup(function () {
				//$('#basic_amount').val($('#quantity').val() * $('#price').val());
				var a = $("#quantity").val();
				var b = $("#price").val();
				//alert(a);
				//alert(b);
				var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
				$('#basic_amount').val(s);
			});
			$("#total_amount,#tax").change(function () {
				var ba=$('#basic_amount').val();
				var tax=$('#tax').val();
				var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
				var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
				$('#tax_amount').val(tax_a);
				$('#total_amount').val(total);
				var result = (parseFloat(ba));
				if (!isNaN(result)) {
					$('#total_price').val(result);
				}
			});
		});
	</script>
	<script>
	/*$('#price').on('keyup',function() {
			var a = $("#quantity").val();
			var b = $("#price").val();
			//alert(a);
			//alert(b);
			var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
			$('#basic_amount').val(s);
            $('#total_amount').val(s);
		});*/
		$('#price').on('keyup',function() {
			var qty = $("#quantity").val();
			var price = $("#price").val();
			var tax = $("#tax").val();
			//alert(a);
			//alert(b);
			
			var total = (parseFloat(qty) *  parseFloat(price));
			var tax_amt = ((parseFloat(total) * parseFloat(tax))/100);
			var total_price = (parseFloat(total) +  parseFloat(tax_amt)).toFixed(2);
			//var s = (parseFloat(a) * parseFloat(b)).toFixed(2);
			$('#tax_amount').val(tax_amt);
			$('#basic_amount').val(total);
            $('#total_amount').val(total_price);
            var sum = 0;
			$('.txt').each(function() {
				sum += Number($(this).val());
			});
			$('#tot').val(sum.toFixed(2));
			$('#total_amt').val(sum.toFixed(2));
		});
		///total amount display
		$('#tax').change(function () {
			//alert($("#tax").val());
			tax = $("#tax").val();
			tt = $("#total_amount").val();
			var ba=$('#basic_amount').val();
			var tax=$('#tax').val();
			var tax_a=((parseFloat(ba) *  parseFloat(tax))/ 100).toFixed(2);
			var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
			$('#tax_amount').val(tax_a);
			$('#tax_amount').blur();
			$('#total_amount').val(total);
			$('#total_amount').blur();
			var result = (parseFloat(ba));
			if (!isNaN(result)) {
				$('#total_price').val(result);
				$('#total_price').blur();
			}
			// initialize the sum (total price) to zero
			var sum = 0;
			$('.txt').each(function() {
				sum += Number($(this).val());
			});
			$('#tot').val(sum.toFixed(2));
			$('#total_amt').val(sum.toFixed(2));
		});
	
	</script>
	<script>
		$('#quantity').keyup(function() {
			var qty = $('#quantity').val();
			var price = $('#price').val();
			var tax_amount = $('#tax_amount').val();
			//var stock = $('#stock').val();
			//alert(stock);
			var am=(parseFloat(qty) *  parseFloat(price)).toFixed(2);
			//alert(am);
			$('#basic_amount').val(am);
			$('#total_amount').val(am);
			var sum = 0;
			$('.txt').each(function() {
				sum += Number($(this).val());
			});
			$('#tot').val(sum.toFixed(2));
			$('#total_amt').val(sum.toFixed(2));
		});
	</script>
	<script>
		$(function() {
			$("select.itm").change(function() {
				$("select.itm option").show();
				$("select.itm").each(function() {
					if (!$(this).val() == "") {
						$("select.itm").not($(this)).find("option").filter("[value='" + $(this).val() + "']").hide();
					}
				});
			});
		});

	 $(document).ready(function(){
		$("select.chzn-select").chosen({allow_single_deselect:true});
   });

	</script>
	<script>
		$("#item_name").change(function(){
			var i_name = $('#item_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_Item_Details',
				success: function(data) {
					//alert(data.price);
					$('#unit_measurements').val(data.uom);
					$('#item_sid').val(data.item_id);
					$('#cat_id').val(data.category_id);
				    $('#price').val(data.item_price);
					$('#close_stock').val(data.stock_item);
					$('#it_name').val(item_name);
					$('#itm_id').val(data.itm_id);
				}
			});
			//$("#item_name").attr('disabled', 'disabled');
		});
	</script>
	<script>
	$('.prm').change(function() {
		dropdownval = $(this).val();
	   // alert(dropdownval);
		$('.prm').not(this).find('option[value="' + dropdownval + '"]').remove();
	  });
</script>
	<script type="text/javascript">
		//vendors name autocomplete
		jQuery(document).ready(function(){
			$('#company_name').autocomplete({
				source: '<?php echo 
				base_url();?>index.php/Master/vendor_auto',
				minLength:1,
			});
		});
	</script>
	<script type="text/javascript">
		$('#courier').change(function() {
			var courier = $('#courier').val();
			var tamt = $('#total_amt').val();
			var sum = 0;
			var sum = parseFloat(parseFloat(tamt) + parseFloat(courier));
			if (!isNaN(sum)) {
				$('#total_amt').val(sum.toFixed(2));
				$('#tamt').val(sum.toFixed(2));
			}
		});
		$('#transport').change(function () {
			var transport = $('#transport').val();
			var tamt = $('#total_amt').val();
			var sum = 0;
			var sum = parseFloat(tamt) + parseFloat(transport);
		    $('#total_amt').val(sum.toFixed(2));
			$('#tamt').val(sum.toFixed(2));
		});
		$('#insurance').change(function () {
			var insurance = $('#insurance').val();
			var tamt = $('#total_amt').val();
			var sum = 0;
			var sum = parseFloat(tamt) + parseFloat(insurance);
			$('#total_amt').val(sum.toFixed(2));
			$('#tamt').val(sum.toFixed(2));
		});
	</script>
	<script type="text/javascript">
		$('#roundoff').keyup(function () {
			var rnd = $('#roundoff').val();
			if(rnd == '')
			{
				rnd = 0;
			}
			var tamt = $('#tamt').val();
			var final_amt = (parseFloat(tamt) + parseFloat(rnd)).toFixed();
			$('#total_amt').val(final_amt);
		});
	</script>
	<script>
		$(document).ready(function () {
			$('.image_file').change(function () {
				var val = $(this).val().toLowerCase();
				var regex = new RegExp("(.*?)\.(jpg|png|jpeg|JPG)$");
				if(!(regex.test(val))) {
					$(this).val('');
					//alert('Please select correct file format');
					document.getElementById('errfn2').innerHTML="Please upload only image file";
				} }); });
	</script> 
	 <script type="text/javascript">
		 $(document).ready(function () {
			 $('.image_file').change(function () {
		// function PreviewImage() {
                pdffile=document.getElementById("in_upload").files[0];
                pdffile_url=URL.createObjectURL(pdffile);
                $('#viewer').attr('src',pdffile_url);
           // }
			 });
		 });
      </script>
	  <script>
			function preview_image() 
			{
				var total_file=document.getElementById("in_upload").files.length;
				for(var i=0;i<total_file;i++)
				{
					$('#image_preview').append("<img src='"+URL.createObjectURL(event.target.files[i])+"'><br>");
				}
			}
	  </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>