<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>
<style>
   .col-md-5{
       /*padding-right: 0px;*/
    padding-left: 14px;
   } 
      .col-md-2{
       padding-right: 0px;
    padding-left: 14px;
   } 
</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">Material 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">-->
		    <form class="form" autocomplete="off" action="<?php echo site_url('MaterialRequest/addInward');?>" method="post" enctype="multipart/form-data">
			<div class="card">
				
				<div class="card-content collapse show">
					<div class="card-body">

						
					<?php 	foreach($issue as $iss) ?>
						
							<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->mat_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-2">
								<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-2 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-5 col-md-2">
								<div class="form-group">
									<label>Store</label>
									<input class="form-control" type="text" name="store" id="store" value="<?php echo $iss->store; ?>" 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>
			
				<div class="row">			
								
						<?php
					
					$count = 1;
					foreach($issue_item as $issitem){
					?>
					<div class="col-6 col-md-5">
				<div class="card">
				
				<div class="card-content collapse show">
					<div class="card-body">
										<div class="row card_margin">
										<!--	<div class="col col-md-6">
												<div class="form-group">
													<input type="hidden" class="form-control" name="iname[]" id="iname" value="<?php //echo $issitem->item_name; ?>" readonly tabindex="-1" />
													<span style="word-break: break-all;"><?php //echo $issitem->item_name; ?></span>
												</div>
											</div>
											<div class="col-md-6 d-none d-sm-block">
												<div class="form-group">
													<input class="form-control" type="text" name="rqty[]"  id="rqty" value="<?php //echo $issitem->required_qty; ?>" readonly tabindex="-1" />
													<input class="form-control" type="hidden" name="rmk[]" id="rmk" value="<?php //echo $issitem->remarks; ?>" disabled tabindex="-1" />
												</div>
											</div>-->
											
											<input type="hidden" class="form-control" name="iname[]" id="iname" value="<?php echo $issitem->item_name; ?>" readonly tabindex="-1" />
											<span class="col col-md-6" style="word-break: break-all;"><?php echo $issitem->item_name; ?></span>
											<input class="form-control col-md-6 d-none d-sm-block" type="text" name="rqty[]"  id="rqty" value="<?php echo $issitem->required_qty; ?>" readonly tabindex="-1" />
											<input class="form-control" type="hidden" name="rmk[]" id="rmk" value="<?php echo $issitem->remarks; ?>" disabled tabindex="-1" />
										</div>
									</div>
                    </div>
                </div>
            </div>
            <div class="col-6 col-md-7">
    			<div class="card">
    				<div class="card-content collapse show">
    					<div class="card-body">	
										<?php
											if($issitem->indent_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>
										</div>-->
										
										<div class="row card_margin">
										    <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 />
										  <!--  <div class="col col-md-1">
												<div class="form-group">-->
										    <img src="<?php echo base_url(); ?>app-assets/images/right.png" alt="" class="img_main" style="margin-left: 10px!important;width: auto;" />
										  <!--  </div>
										    </div>-->
										    <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->indent_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; ?>" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" readonly tabindex="-1" />
													<input class="form-control  qty2" type="hidden" name="bal_iss_qty[]" id="bal_iss_qty" value="<?php echo $issitem->indent_qty - $issitem->rec_issue_qty; ?>" />
													
													<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="text" name="item_id[]" id="item_id" value="<?php //echo $issitem->item_id; ?>">-->
													<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="cat_id[]" id="cat_id" value="<?php echo $issitem->category_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>
            <?php $count++; } ?>
		</div>		

				<br/>
				<div class="card">
					<div class="card-content collapse show">
						<div class="card-body">
							<div class="text-right">
								<div class="row card_margin">
									<div class="col-md-2 mleft">
									</div>
									<div class="col-md-8 mleft">
										<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>
			</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++;
			}
			
			if($count1 == $count2) {
				
			?>
			 <div class="col-lg-4 col-sm-4 col-12">
				<div class="form-group text-center">
					<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>
			<?php  } else if(($status == 'Approved') && ($store_status == 'Closed')) { ?>
			 <div class="col-lg-4 col-sm-4 col-12">
				<div class="form-group text-center">
					<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>
			<?php } ?>			
						

				<!--	</div>-->
				</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 type='text/javascript'>
		$(".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");
				//$(".qty").eq(i).focus();
			}
			else{
			    if(q1 != '')
			    {
    				alert("You cant enter more than balance issued quantity");
    				$(this).parent().find('.qty').val('');
    				//$(".qty").eq(this_index).focus();
			    }
			}
		}
		})
		})
	</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>