<?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">Transfer Inward</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="#">Transfer Inward</a>
							</li>
							<li class="breadcrumb-item active">Transfer Inward 
							</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('Transfer/addTransferInward');?>" method="post" enctype="multipart/form-data">
					<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">
									<?php 	
										foreach($transfer as $tr) ?>
										<div class="row justify-content-md-left card_margin">
											<div class="col col-md-4">
												<div class="form-group">
													<label>TR.NO</label>
													<input type="text" name="trans_no" id="trans_no" class="form-control" value="<?php echo $tr->trans_no; ?>" readonly />
												</div>
											</div>
											<div class="col-md-2 d-none d-sm-block">
												<div class="form-group">
													<label>TR DATE</label>
													<input type="text" name="trans_date"  id="trans_date" class="form-control" readonly="readonly" value="<?php echo $tr->trans_date; ?>"/>
												</div>
											</div>
											<div class="col-md-3 d-none d-sm-block">
												<div class="form-group">
													<label>Inward DATE</label>
													<?php $cur_date = date("d-m-Y"); ?>
													<input class="form-control" type="text" name="inward_date"  id="inward_date" value="<?php echo $cur_date; ?>" readonly >
												</div>
											</div>
											<div class="col col-md-2">
												<div class="form-group">
													<label>From Department</label>
													<input class="form-control" type="text" name="frm_dept" id="frm_dept" value="<?php echo $tr->username; ?>" >
													<input class="form-control" type="hidden" name="tr_id" id="tr_id" value="<?php echo $tr->tr_id; ?>" >
													<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">		
									<?php
									$count = 1;
										foreach($transfer_item as $tritem){
									?>
										<div class="row justify-content-md-center ">
											<div class="col col-md-7">
												<div class="row">
													<div class="col col-md-7">
														<div class="form-group">
															<input class="form-control" type="text" name="item_name[]" id="item_name" value="<?php echo $tritem->item_name; ?>" tabindex="-1" readonly />
														</div>
													</div>
													<div class="col-md-3 d-none d-sm-block">
														<div class="form-group">
															<input class="form-control" type="text" name="uom[]"  id="uom" value="<?php echo $tritem->uom; ?>" tabindex="-1" readonly />
														</div>
													</div>
												</div>
											</div>
											<div class="col col-md-5">
												<div class="row">
													<input class="form-control col-md-2" type="hidden" name="item_type[]" id="item_type" value="<?php echo $tritem->item_type?>">
													<input class="form-control col-md-2" type="hidden" name="tr_item_id[]" id="tr_item_id" value="<?php echo $tritem->tr_item_id?>">
													<input class="form-control col-md-2" type="hidden" name="item_id[]" id="item_id" value="<?php echo $tritem->item_id?>">
													<input class="form-control col-md-2" type="hidden" name="cat_id[]" id="cat_id" value="<?php echo $tritem->cat_id?>">
													<input class="form-control col-md-2" type="hidden" name="itm_id[]" id="itm_id" value="<?php echo $tritem->item_no?>">
													<input class="form-control col-md-2" type="hidden" name="recipe_no[]" id="recipe_no" value="<?php echo $tritem->recipe_no?>">
													<input class="form-control col col-md-3 qty" type="text" name="inward_quantity[]"  id="inward_quantity"  placeholder="Qty"  />
													<input class="form-control col-md-2 grn_balance qty2" type="hidden" name="trans_qty[]" id="trans_qty" value="<?php echo $tritem->quantity; ?>" />
													<input class="form-control col col-md-3 remarks" type="text" name="remarks[]" id="remarks[]" style="margin-left: 15px!important;" placeholder="Remarks" tabindex="-1" />
												</div>
											</div>
										</div>	
									<?php 
										$count++; 
									} ?>
									</div>
								</div>
							</div>
							<div class="card">
								<div class="card-content collapse show">
									<div class="card-body">
										<div class="row text-right card_margin">
											<div class="col-md-12">
												<div class="form-group">
													<button type="submit" id="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit?')">
													<i class="la la-check-square-o"></i> Accept
													</button>
												</div>
											</div>
										</div>
									</div>
								</div>
							</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);
?>
<script>
	$(".qty").each( function(){ $(this).on( {'keyup': function() { 
		var q1 = $(this).parent().find('.qty').val();
		var q2 = $(this).parent().find('.qty2').val();
		if(parseFloat(q1) <= parseFloat(q2)){
		//alert("sucess");
		}
		else{
			alert("You cant enter more than balance issued quantity");
			$(this).parent().find('.qty').val('');
		}
		}
		})
	})
</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");
	});

	$(document).ready(function() {
		$(window).keydown(function(event){
			if(event.keyCode == 13) {
				event.preventDefault();
				return false;
			}
		});
	});
</script>
</body>
</html>