d<?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">Damage Entry</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="#">Damage </a>
                  </li>
                  <li class="breadcrumb-item active">Damage Entry
                  </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('Damage/insertDamage');?>" method="post">
	<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">Damage 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-left cardbody">
								<div class="col-md-6 mleft">
									<div class="form-group">
										<label>Damage Date</label>
										<?php $cur_date = date("d-m-Y");
											$branch_id = $_SESSION['branch_id'];
										?>
										<input type="text" name="damage_date"  id="damage_date" class="form-control" readonly="readonly" value="<?php echo $cur_date; ?>"/>
										<!--<input class="form-control" type="text" name="damage_date"  id="damage_date" placeholder="Date" data-uk-datepicker="{format:'DD-MM-YYYY'}" required >-->
										<input type="hidden" name="damage_id" id="damage_id" class="form-control" value="<?php //echo $cur_auto_id ?>"/>
										<input type="hidden" name="branchname" id="branchname" class="form-control" value="<?php echo $_SESSION['branch_name']?>"/>
										<input type="hidden" name="uname" id="uname" class="form-control" value="<?php echo $_SESSION['full_name']?>"/>
											<input type="hidden" id="branch_id" class="form-control"  name="branch_id" value="<?php echo $branch_id;?>">
									</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-left cardbody">
						<div class="text_increment">
							<div>
								<div class="row">
									
									<div class="col-md-4">
										<div class="form-group">
											
											<select name="item_name[]" id="item_name" class="form-control 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-2">
										<div class="form-group">
											<input class="form-control" type="text" name="unit_measurements[]" id="unit_measurements"  readonly placeholder="UOM" /><input class="form-control" type="hidden" name="prst_stk[]" id="prst_stk"  readonly placeholder="STK" />
										</div>
									</div>
									<div class="col-md-2">
										<div class="form-group">
											<input class="form-control quantity" type="text" name="quantity[]"  id="quantity" required  Placeholder="Dmg Qty"/>
										</div>
									</div>
									<div class="col-md-3">
										<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 />
										</div>
									</div>
									
								</div>
							</div>	
						</div>
						<input class="md-input result" type="hidden" name="products" id="products" />
					</div>
</div>
			</div>
		</div>
			<div class="card">
				<div class="card-content collapse show">
					<div class="card-body">
							<div class="text-right">
								<div class="row cardbody">
									<div class="col-md-2 ">
										<div class="form-group">
											
											
										</div>
									</div>
									<div class="col-md-8 mleft">
										<button type="reset" class="btn btn-warning mr-1">
											<i class="ft-x"></i> Cancel
										</button>
										<button type="submit" class="btn btn-primary">
											<i class="la la-check-square-o"></i> Save
										</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>
				<br/>
			</div>

		</div>
	</div>
</form>	
</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-4"><div class="form-group"><select id="item_name'+counter+'" name="item_name[]" class="form-control select2 prm"  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-2"><div class="form-group"><input class="form-control product_details " type="text"  name="unit_measurements[]" Placeholder="UOM" id="unit_measurements'+counter+'" placeholder="UOM" readonly/><input class="form-control" type="hidden" name="prst_stk[]" id="prst_stk'+counter+'"  readonly placeholder="STK" /></div></div><div class="col-md-2"><div class="form-group"><input class="form-control product_details quantity1" type="text"  name="quantity[]" Placeholder="Dmg Qty" required id="quantity'+counter+'"/></div></div><div class="col-md-3"><div class="form-group"><input class="form-control batch_no" type="text" name="remarks[]" id="remarks'+counter+'" placeholder="Remarks" /><input class="md-input product_details" type="hidden" name="item_sid[]" id="item_sid'+counter+'"  readonly /><input class="form-control product_details" type="hidden" name="cat_id[]" id="cat_id'+counter+'"  readonly /></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);
					$(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();
						});
					});
					//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_PItemDetails',
								success: function(data) {
									//alert(data.uom);
									
									$('#unit_measurements'+counts).val(data.uom);
									$('#unit_measurements'+counts).blur();
									$('#item_sid'+counts).val(data.item_id);
									$('#item_sid'+counts).blur();
									$('#cat_id'+counts).val(data.category_id);
									$('#cat_id'+counts).blur();
									$('#price'+counts).val(data.item_price);
									$('#price'+counts).blur();
									$('#prst_stk'+counts).val(data.stock_item);
									$('#prst_stk'+counts).blur();
									$('#it_name'+counts).val(i_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_PItemDetails',
								success: function(data) {
									//alert(data.uom);
									$('#unit_measurements'+counts).val(data.uom);
									$('#unit_measurements'+counts).blur();
									$('#item_sid'+counts).val(data.item_id);
									$('#item_sid'+counts).blur();
									$('#cat_id'+counts).val(data.category_id);
									$('#cat_id'+counts).blur();
									$('#price'+counts).val(data.item_price);
									$('#price'+counts).blur();
									$('#prst_stk'+counts).val(data.stock_item);
									$('#prst_stk'+counts).blur();
									$('#it_name'+counts).val(i_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 = $('#prst_stk'+ counts).val();
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than stock");
								$('#quantity'+counts).val(lt);
							}
						}
						else{
							counts = id.substr(-2);
							var qty = $('#quantity'+ counts).val();
							var stock = $('#prst_stk'+ counts).val();
							if(parseFloat(qty) > parseFloat(stock))
							{
								var lt = 0;
								alert("you cant enter more than stock");
								$('#quantity'+counts).val(lt);
							}
						}
					});
					// tax caluclation 
					$('#tax'+counter).click(function(){
						var id = $(this).attr('id');
						//alert(id);
						$("#"+id).autocomplete({
							source:'tax_amount_auto.php', 
							minLength:1,
							select:function(evt, ui)
							{
								//counts = counter - 1;
								counts = id.substr(-1);
								//alert(counts);
								// when a item_name_auto is selected, populate related fields in this form
								//this.form.item_price.value = ui.item.item_price;
								//$('#unit_measurements' + counts).val(ui.item.unit_measurements);
								//$('#price' + counts).val(ui.item.price);
								//$('#close_stock' + counts).val(ui.item.close_stock);
							}
						});
					});
					
					$(document).on("keyup","#price"+counter+",#quantity"+counter,function() {
						var count = counter-1;
						var a = $("#quantity"+count).val();
						var b = $("#price"+count).val();
						//alert(a);
						//alert(b);
						$('#basic_amount' + count).val(a * b);
					});
					$(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
						var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
						$('#tax_amount' + count).val(tax_a);
						$('#tax_amount' + count).blur();
						$('#total_amount' + count).val(total);
						$('#total_amount' + count).blur();	
					});
				}
				//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--;
			});
			$(document).on("change",".batch_no",function(){
				var text = "";
				$('.product_details').each(function(){
					text += $(this).val()+' ';
				});
				text = text.substring(0,text.length-1);
				$('#products').val(text);
			});
		});
	</script>
<script type='text/javascript'>
		$(window).load(function(){
			$("#quantity,#price").keyup(function () {
				$('#basic_amount').val($('#quantity').val() * $('#price').val());
			});
			$("#total_amount,#tax").keyup(function () {
				var ba=$('#basic_amount').val();
				var tax=$('#tax').val();
				var tax_a=(parseFloat(ba) *  parseFloat(tax))/ 100
				var total=(parseFloat(ba) + parseFloat(tax_a)).toFixed(2);
				$('#tax_amount').val(tax_a);
				$('#tax_amount').blur();
				$('#total_amount').val(total);
				$('#total_amount').blur();
			});
		});
	</script>
	
	<script>
		$('#quantity').on('keyup',function() {
			var qty = $('#quantity').val();
			var stock = $('#prst_stk').val();
			if(parseFloat(qty) > parseFloat(stock))
			{
				var lt = 0;
				alert("you cant enter more than stock");
				$('#quantity').val(lt);
			}
		});
	</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/Master/get_PItemDetails',
				success: function(data) {
					//alert(data.uom);
					$('#unit_measurements').val(data.uom);
					$('#unit_measurements').blur();
					$('#item_sid').val(data.item_id);
					$('#item_sid').blur();
					$('#cat_id').val(data.category_id);
					$('#cat_id').blur();
					$('#price').val(data.item_price);
					$('#price').blur();
					$('#prst_stk').val(data.stock_item);
					$('#prst_stk').blur();
					$('#it_name').val(i_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>
		$(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>