<?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">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="#">Request Pending List</a>
                  </li>
                  <li class="breadcrumb-item active">Inward 
                  </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">
			<div class="card">
				<!--<div class="card-header">
					<h4 class="card-title" id="basic-layout-form-center">Inward</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">

						
					<?php 	foreach($issue as $iss) ?>
						<form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addInward');?>" method="post" enctype="multipart/form-data">
							<div class="row justify-content-md-center card_margin">
							<div class="col-md-2 d-none d-sm-block">
								<div class="form-group">
									<label>RO.NO</label>
									<input type="text" name="request_no" id="request_no" class="form-control" value="<?php echo $iss->pr_req_no; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2 d-none d-sm-block">
								<div class="form-group">
									<label>RO DATE</label>
									<input type="text" name="req_date"  id="req_date" class="form-control" readonly="readonly" value="<?php echo $iss->request_date; ?>"/>
								</div>
							</div>
							<div class="col-7 col-md-3">
								<div class="form-group">
									<label>Issue NO</label>
									<input type="text" name="issue_no" id="issue_no" class="form-control" value="<?php echo $iss->issue_no; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2 d-none d-sm-block">
								<div class="form-group">
									<label>Issue DATE</label>
										<input class="form-control" type="text" name="issue_date"  id="issue_date" value="<?php echo $iss->issue_date; ?>" readonly >
								</div>
							</div>
							<div class="col-md-1 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 style="width:114px!important;">
								</div>
							</div>
							<div class="col-5 col-md-2">
								<div class="form-group">
									<label>Department</label>
									<input class="form-control" type="text" name="dept" id="dept" value="<?php echo $iss->dept; ?>" readonly >
									<input class="form-control" type="hidden" name="req_id" id="req_id" value="<?php echo $iss->request_id; ?>" >
									<input class="form-control" type="hidden" name="iss_id" id="iss_id" value="<?php echo $iss->issue_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>
			<?php
					
				$count = 1;
				foreach($issue_item as $issitem){
			?>
			<div class="row">			
				<div class="col-7 col-md-6">
    				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body">    	
        					    <div class="row card_margin">
								<!--	<div class="col-md-8">
										<div class="form-group">
											<input class="form-control" type="text" name="iname[]" id="iname" value="<?php // echo $issitem->item_name; ?>" readonly />
										</div>
									</div>
									<div class="col-md-3">
										<div class="form-group">
											<input class="form-control" type="text" name="rqty[]"  id="rqty" value="<?php // echo $issitem->required_qty; ?>" readonly />
										</div>
									</div>-->
									
									<input class="form-control" type="hidden" name="iname[]" id="iname" value="<?php echo $issitem->item_name; ?>" readonly />
									<span class="col col-md-8" style="word-break: break-all;"><?php echo $issitem->item_name; ?></span>
									<input class="form-control col-md-3 d-none d-sm-block" type="text" name="rqty[]"  id="rqty" value="<?php echo $issitem->required_qty; ?>" readonly />
								</div>
    					    </div>
    					</div>
    				</div>
    			</div>
    			<div class="col-5 col-md-6">
    				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body"> 
        					    
            					    <?php
										if($issitem->issued_qty == $issitem->rec_issue_qty && $issitem->rcv_status == 'Closed') {
									?>
									<div class="row card_margin">
										<!--<div class="col-md-3">
											<div class="form-group">
												<input class="form-control" type="text" name="rqty"  id="rqty[]" value="<?php // echo $issitem->receipt_qty; ?>" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" disabled />
											</div>
										</div>
										<div class="col-md-2">
											<div class="form-group">
												<img src="<?php // echo base_url(); ?>app-assets/images/right.png" alt="" class="img_main"/>
											</div>
										</div>
										<div class="col-md-2">
											<div class="form-group">
												<span>Received</span>
											</div>
										</div>-->
										
										<input class="form-control col col-md-3" type="text" name="rqty"  id="rqty[]" value="<?php echo $issitem->receipt_qty; ?>" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" disabled />
										<img src="<?php echo base_url(); ?>app-assets/images/right.png" alt="" class="img_main" style="margin-left: 10px!important;width: auto;"/>
										<span class="col-md-2 d-none d-sm-block">Received</span>
									</div>
									
								<?php
									} else if($issitem->rcv_status == 'Pending') {
								?>
								    <div class="row card_margin">
								        <input class="form-control col col-md-3 qty" type="text" name="in_quantity[]"  id="in_quantity"  placeholder="Qty" />
												<input class="form-control qty1" type="hidden" name="issued_qty[]" id="issued_qty" value="<?php echo $issitem->issued_qty; ?>" />
												<input class="form-control " type="hidden" name="received_qty[]" id="received_qty" value="<?php echo $issitem->receipt_qty; ?>" />
												<input class="form-control col-md-2 d-none d-sm-block" type="text" name="rec_issue_qty[]" id="rec_issue_qty" value="<?php echo $issitem->rec_issue_qty; ?>" style="margin-left: 14px;" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" readonly />
												<input class="form-control qty2" type="hidden" name="bal_iss_qty[]" id="bal_iss_qty" value="<?php echo $issitem->issued_qty - $issitem->rec_issue_qty; ?>" />
												
											
												<input class="form-control price" type="hidden" name="price[]"  id="price" value="<?php echo $issitem->price; ?>" />
											
												
												<input class="form-control tot_price" type="hidden" name="total_price[]" id="total_price" >
												<input class="form-control" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $issitem->request_item_id; ?>">
												<input class="form-control" type="hidden" name="issue_item_id[]" id="issue_item_id" value="<?php echo $issitem->issue_order_id; ?>">
												<input class="form-control" type="hidden" name="item_name[]" id="item_name" value="<?php echo $issitem->item_name; ?>" readonly />
												<input class="form-control" type="hidden" name="uom[]" id="uom" value="<?php echo $issitem->uom; ?>" readonly />
												<input class="form-control" type="hidden" name="req_qty[]"  id="req_qty" value="<?php echo $issitem->required_qty; ?>" readonly />
												<input class="form-control" type="hidden" name="item_id[]" id="item_id" value="<?php echo $issitem->itm_id; ?>">
												<input class="form-control" type="hidden" name="itm_id[]" id="itm_id" value="<?php echo $issitem->recipe_no; ?>">
												<input class="form-control" type="hidden" name="cat_id[]" id="cat_id" value="<?php echo $issitem->pr_cat_id; ?>">
												<img src="<?php echo base_url(); ?>app-assets/images/wrong.png" alt="" class="img_main" style="margin-left: 10px!important;width: auto;" />
									</div>
									<?php
								}
							?>		    	
                    					
    					    </div>
    					</div>
    				</div>
    			</div>
    		</div>
    	<?php $count++; } ?>	
				<br/>
				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body"> 
							
									<div class="col-md-12 text-right">
										<div class="form-group">
											<input class="form-control gt" type="hidden" name="grand_total" id="grand_total" readonly />
											<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>
			</form>
			<br/>
			
			<?php
			$req_id = $iss->request_id;
			$q1 = $this->db->query("SELECT *,M.status as store_status FROM material_request M left join material_request_item MI on M.request_id=MI.request_id where M.request_id='$req_id'");
			$count1 = 0;
			$count2 = 0;
			$status;
			$store_status;
			$result3 = $q1->result();
			foreach($result3 as $row3)
			{
				$status = $row3->mclose_status;
				$store_status = $row3->store_status;
				if(($row3->recieved_qty == $row3->receipt_qty))
				{	
					$count2++;	
				}
				$count1++;
			}
			?>
			 
			<?php
			
			if($count1 == $count2) {
				
			?>
			<div class="card">
				    <div class="card-content collapse show">
					    <div class="card-body">
			 <div class="col-md-12 ">
				<div class="form-group text-left">
					<button class="btn btn-lg btn-success font-medium-1 grid-form-dialog-btn mt-1">Close Manual</button>
					<p class="font-small-3 mt-1"></p>
					<div class="grid-form-dialog" title="Manual Request Close">
						<div class="container">
							<form action="" class="uk-form-stacked"  method="post" autocomplete="off">
								<div class="form-group row">
									<label for="inputEmail3" class="col-sm-2 col-form-label">Enter Remarks</label>
									<div class="col-sm-10">
									<input name="request_id" id="request_id" type="hidden" class="textbox" value="<?php echo $iss->request_id; ?>" >
										<input type="text" class="form-control"name="req_remark" id="req_remark">
									</div>
								</div>
								
								<div class="form-group row">
									<div class="offset-sm-2 col-sm-10">
										<button type="button" class="md-btn md-btn-flat uk-modal-close">Close</button>
										<input type="button" class="md-btn md-btn-flat md-btn-flat-primary" value="Confirm" name="submit3" id="submit3">
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
				</div>
			</div>

					</div>
			<?php  } else if(($status == 'Approved') && ($store_status == 'Closed')) { ?>
			<div class="card">
				    <div class="card-content collapse show">
					    <div class="card-body">
			 <div class="col-md-12 ">
				<div class="form-group text-left">
					<button class="btn btn-lg btn-success font-medium-1 grid-form-dialog-btn mt-1">Close Manual</button>
					<p class="font-small-3 mt-1"></p>
					<div class="grid-form-dialog" title="Manual Request Close">
						<div class="container">
							<form action="" class="uk-form-stacked"  method="post" autocomplete="off">
								<div class="form-group row">
									<label for="inputEmail3" class="col-sm-2 col-form-label">Enter Remarks</label>
									<div class="col-sm-10">
									<input name="request_id" id="request_id" type="hidden" class="textbox" value="<?php echo $iss->request_id; ?>" >
										<input type="text" class="form-control"name="req_remark" id="req_remark">
									</div>
								</div>
								
								<div class="form-group row">
									<div class="offset-sm-2 col-sm-10">
										<button type="button" class="md-btn md-btn-flat uk-modal-close">Close</button>
										<input type="button" class="md-btn md-btn-flat md-btn-flat-primary" value="Confirm" name="submit3" id="submit3">
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
				</div>
			</div>

					</div>
			<?php } ?>			
		
				</div>
			</div>
		</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>
	
		$(".qty").each( function(){ $(this).on( {'change': 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('');
				$(this).parent().find('.tot_price').val('0');
			}
		}
		})
		})

	
	//calculation
	$('.qty').each(function() { $(this).on( {'keyup': function() {
		var qty = $(this).parent().find('.qty').val();
		var price = $(this).parent().find('.price').val();
		//alert(price);
		var tot_price = (parseFloat(qty) * parseFloat(price)).toFixed(2);
		$(this).parent().find('.tot_price').val(tot_price);
	}
	})
	})
	
	//$('.qty').keyup(function() {
	$('#submit').click(function() {
		var sum = 0;
		$('.tot_price').each(function() {
			sum += Number($(this).val());
		});
		$('#grand_total').val(sum.toFixed());
	});
</script>
	
<script>
	$('#submit3').click(function() {
		var req_remark = $('#req_remark').val();
		var req_id = $('#request_id').val();
		if(req_remark == '')
		{
			alert("Please Enter Remarks");
			return false;
		}
		else
		{
			$.ajax({
				type: "POST",
				dataType:'json',
				data : { req_id : req_id, req_remark : req_remark },
				url: "<?php echo base_url();?>index.php/MaterialRequest/requestRmkissUpdate",
				success: function(dataz) { 
					setTimeout(function() {
						window.location = '<?php echo site_url('MaterialRequest/issuePendingList');?>';
					}, 200);
				}
			});
		}
	});
</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>
  <!-- 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>