<?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">
			<div class="card">
				
				<div class="card-content collapse show">
					<div class="card-body">

					<?php foreach($req as $rq) ?>
						
							<div class="row justify-content-md-left card_margin">
							<div class="col-7 col-md-2">
								<div class="form-group">
									<label>RO.NO</label>
									<input type="text" name="request_no" id="request_no" class="form-control" value="<?php echo $rq->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 $rq->request_date; ?>"/>
								</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-md-2 d-none d-sm-block">
								<div class="form-group">
									<label>DC NO</label>
									<input type="text" name="dc_no" id="dc_no" class="form-control" required />
								</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 $rq->store; ?>" readonly tabindex="-1" >
									<input class="form-control" type="hidden" name="req_id" id="req_id" value="<?php echo $rq->request_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 class="col-md-2">
								<div class="form-group">
									<label>Invoice Upload</label>
									<input type="file" name="dc_upload[]" id="dc_upload" class="form-control" onchange="preview_image();" multiple />
								</div>
							</div>-->
						</div>
				</div>
			</div>
			</div>		
			<?php
					
					$count = 1;
					foreach($req_item as $rqitem){
					?>
			<div class="row">			
				<div class="col-5 col-md-5">
    				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body"> 
            					<div class="row card_margin">
    							<!--	<div class="col-md-9">
    									<div class="form-group">
    										<input class="form-control" type="text" name="iname[]" id="iname" value="<?php //echo $rqitem->item_name; ?>" readonly tabindex="-1" />
    									</div>
    								</div>
    								<div class="col-md-3">
    									<div class="form-group">
    										<input class="form-control ind_qty" type="text" name="rqty[]"  id="rqty" value="<?php //echo $rqitem->required_qty; ?>" readonly tabindex="-1" />
    									</div>
    								</div>-->
    								
    								<input class="form-control" type="hidden" name="iname[]" id="iname" value="<?php echo $rqitem->item_name; ?>" readonly tabindex="-1" />
    								<span class="col col-md-6" style="word-break: break-all;"><?php echo $rqitem->item_name; ?></span>
    								<input class="form-control col-md-6 d-none d-sm-block ind_qty" type="text" name="rqty[]"  id="rqty" value="<?php echo $rqitem->required_qty; ?>" readonly tabindex="-1" />
    							</div>
        				    </div>
        				</div>
        			</div>
        		</div>
        		
    			<div class="col-7 col-md-7">
    				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body"> 
            					<?php
        							if($rqitem->required_qty == $rqitem->recieved_qty) {
        						?>
        						
        							<div class="row card_margin">
        								<input class="form-control col col-md-2" type="text" name="rqty"  id="rqty[]" value="<?php echo $rqitem->required_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 {
        						?>
        						
        							<div class="row card_margin">
        									<input class="form-control col col-md-2 qty inward_qty" type="text" name="in_quantity[]"  id="in_quantity"  placeholder="Qty" />
        									<input class="form-control col-md-2 d-none d-sm-block grand" type="text" name="received_qty[]" id="received_qty" value="<?php echo $rqitem->recieved_qty; ?>" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" readonly tabindex="-1" />
        									<input class="form-control col col-md-4" type="text" name="remarks[]" id="remarks[]" placeholder="Remarks" tabindex="-1" />
        
        									<input class="grn_balance" type="hidden" name="bal_item_qty[]"   id="bal_item_qty" value="<?php echo $rqitem->item_balance_qty; ?>" />
        									<input class="inward_price" type="hidden" name="inward_price[]" id="inward_price[]" value="<?php echo $rqitem->rate; ?>" />
        									<input class="rcp_tax" type="hidden" name="rcp_tax[]" id="rcp_tax" value="<?php echo $rqitem->tax; ?>" />
        									<input class="tax_amount" type="hidden" name="tax_amount[]"  id="tax_amount" />
        									<input class="total_price" type="hidden" name="total_price[]" id="total_price[]"/>
        									<input class="total_amount" type="hidden" name="total_amount[]" id="total_amount[]"  placeholder="Amount" readonly />
        									<input type="hidden" name="stock[]" id="stock" value="<?php echo $rqitem->stock_item; ?>"/>
        									<input class="form-control" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $rqitem->request_item_id; ?>">
        									<input class="form-control" type="hidden" name="item_name[]" id="item_name" value="<?php echo $rqitem->item_name; ?>" readonly />
        									<input class="form-control" type="hidden" name="uom[]" id="uom" value="<?php echo $rqitem->uom; ?>" readonly />
        									<input class="form-control" type="hidden" name="req_qty[]"  id="req_qty" value="<?php echo $rqitem->required_qty; ?>" readonly />
        									<input class="form-control" type="hidden" name="item_id[]" id="item_id" value="<?php echo $rqitem->item_id; ?>">
        									<input class="form-control" type="hidden" name="itm_id[]" id="itm_id" value="<?php echo $rqitem->itm_id; ?>">
        									<input class="form-control" type="hidden" name="cat_id[]" id="cat_id" value="<?php echo $rqitem->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>
        	</div>
		<?php $count++; } ?>

				<div class="card">
    				    <div class="card-content collapse show">
    					    <div class="card-body"> 
								<div class="row">
								    <div class="col-md-2 d-none d-sm-block">
										<div class="form-group">
											
										</div>
									</div>
									
									<div class="col col-md-2">
										<div class="form-group">
											<label>Req Qty</label>
											<input class="form-control reqqty" type="text" name="reqqty" id="reqqty" value="0" readonly />
										</div>
									</div>
									<div class="col col-md-2">
										<div class="form-group">
											<label>Inward Qty</label>
											<input class="form-control" type="text" name="inwardqty" id="inwardqty" value="0" readonly />
										</div>
									</div>
									<div class="col-md-2 d-none d-sm-block">
										<div class="form-group">
											
										</div>
									</div>
									<div class="col col-md-2">
										<div class="form-group">
											<label>Ttl Amt</label>
											<input class="form-control" type="text" name="total_amt" id="total_amt" value="0" readonly />
										</div>
									</div>
									<div class="col col-md-2 text-right">
										<div class="form-group">
											<a href="#medlist" id="pride_grn_view" class="basic-form-dialog-btn btn btn-info" style="margin-top: 22px;" >Submit</a>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				
			
			<br/>
			
			<div class="col-lg-4 col-sm-4 col-12" >
				<div class="form-group text-left">
					<button class="btn btn-sm btn-success font-medium-1 grid-form-dialog-btn mt-1">Close Manual</button>
					<p class="font-small-3 mt-1"></p>
					</div>
			</div>
					<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 $rq->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 id="image_preview"></div>
			
			<!-- Confirmation Form -->
			<div class="basic-form-dialog" id="" title="DC" >
				<div class="container">
				<form class="form" autocomplete="off" action="<?php echo site_url('MaterialRequest/addPrideInward');?>" method="post" enctype="multipart/form-data">
					<div class="row">
						<div class="col-md-6">
							<div class="form-group">
								<label>DC No.</label>
								<input type="text" class="form-control" name="dcno" id="dcno" readonly >
								<input type="hidden" class="form-control" name="reqid" id="reqid" >
								<input type="hidden" class="form-control" name="brname" id="brname" >
								<input type="hidden" class="form-control" name="rcdate" id="rcdate" >
								<input type="hidden" class="form-control" name="str" id="str" >
								<input type="hidden" class="form-control" name="brid" id="brid" >
							</div>
						</div>
						<div class="col-md-6">
						    <div class="form-group">
								<label>Invoice Upload</label>
						        <input type="file" class="form-control image_file" name="dc_upload[]" id="dc_upload" accept="image/*" multiple />
						        <div id="errfn2" style="color:red;"></div>
						    </div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-4">
							<div class="form-group">
								<label>Item Name</label>
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Qty</label>
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Price</label>
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Tax Amt</label>
							</div>
						</div>
						<div class="col-md-2">
							<div class="form-group">
								<label>Total Price</label>
							</div>
						</div>
					</div>
					<div id="pgrn">
					</div>
					<div class="row">
						<div class="col-md-4">
							<div class="form-group">
								<input type="text" class="form-control" name="gtotal" id="gtotal" style="margin-left: 388px;" readonly >
							</div>
						</div>
					</div>
					<div class=" text-right">
						<button type="reset" class="btn btn-warning mr-1">
							<i class="ft-x"></i> Reset
						</button>
						
						<input type="submit" class="btn btn-primary" value="Confirm" name="submit_grn" id="submit_grn">
					</div>
				</form>
				</div>
			</div>
			
			
			

					</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'>//<![CDATA[
		//calculation
		$('.qty').each(function() { $(this).on( {'keyup': function() {
			var qty = $(this).parent().find('.qty').val();
			var price = $(this).parent().find('.inward_price').val();
			var tax = $(this).parent().find('.rcp_tax').val();
			//alert(price);
			var tot_basic = (parseFloat(qty) * parseFloat(price)).toFixed(2);
			var tot_tax = ((parseFloat(tot_basic) * parseFloat(tax))/100).toFixed(2);
			var total_price = (parseFloat(tot_basic) + parseFloat(tot_tax)).toFixed(2);
			$(this).parent().find('.total_price').val(tot_basic);
			$(this).parent().find('.tax_amount').val(tot_tax);
			$(this).parent().find('.total_amount').val(total_price);
		}
		})
		})
	</script>
	<script type="text/javascript">
		$('.qty').keyup(function () {
			var sum1 = 0;
			// we use jQuery each() to loop through all the textbox with 'price' class
			// and compute the sum for each loop
			$('.total_amount').each(function() {
				sum1 += Number($(this).val());
			});
			var t_sum = (sum1).toFixed(2);
			// set the computed value to 'totalPrice' textbox
			$('#total_amt').val(t_sum);
		});
	</script>
	<script>
	    $(document).ready(function () {
			var sum1 = 0;
			$('.ind_qty').each(function() {
				sum1 += Number($(this).val());
			});
			var t_sum = (sum1).toFixed(2);
			// set the computed value to 'totalPrice' textbox
			$('#reqqty').val(t_sum);
		});
		
		$('.inward_qty').keyup(function () {
    		var sum1 = 0;
    		// we use jQuery each() to loop through all the textbox with 'price' class
    		// and compute the sum for each loop
    		$('.inward_qty').each(function() {
    			sum1 += Number($(this).val());
    		});
    		var t_sum = (sum1).toFixed(2);
    		// set the computed value to 'totalPrice' textbox
    		$('#inwardqty').val(t_sum);
    	});
	</script>
	
	<script type="text/javascript">
		$('#pride_grn_view').click(function() {
		    //$('#dailog1').hide();
		   // $("#dialog1").removeClass("fade").modal("hide");
		   	var dc_no = $('#dc_no').val();
			var reqid = $('#req_id').val();
			var brname = $('#branchname').val();
			var rcdate = $('#inward_date').val();
			var str = $('#store').val();
			var branch_id = $('#branch_id').val();
			var gtotal = $('#total_amt').val();
			//var dc_up = $('input[name="dc_upload[]"]').map(function() { return this.value }).get();
			//var files = $('#dc_upload').prop("files");
			//var names = $.map(files, function(val) { return val.name; });
			//alert(names);
			var iname = $('input[name="item_name[]"]').map(function() { return this.value }).get();
			var iqty = $('input[name="req_qty[]"]').map(function() { return this.value}).get();
			var cid = $('input[name="cat_id[]"]').map(function() { return this.value}).get();
			var in_qty = $('input[name="in_quantity[]"]').map(function() { return this.value }).get();
			var rq_itm_id = $('input[name="req_item_id[]"]').map(function() { return this.value }).get();
			var itm_id = $('input[name="item_id[]"]').map(function() { return this.value }).get();
			var it_id = $('input[name="itm_id[]"]').map(function() { return this.value }).get();
			var uom = $('input[name="uom[]"]').map(function() { return this.value }).get();
			var bal_qty = $('input[name="received_qty[]"]').map(function() { return this.value }).get();
			var stk = $('input[name="stock[]"]').map(function() { return this.value }).get();
			var in_price = $('input[name="inward_price[]"]').map(function() { return this.value }).get();
			var in_tt_amt = $('input[name="total_price[]"]').map(function() { return this.value }).get();
			var rtax = $('input[name="rcp_tax[]"]').map(function() { return this.value }).get();
			var txamt = $('input[name="tax_amount[]"]').map(function() { return this.value }).get();
			var in_grd_amt = $('input[name="total_amount[]"]').map(function() { return this.value }).get();
			var rmk = $('input[name="remarks[]"]').map(function() { return this.value }).get();
			var in_qty_length = in_qty.length;
			//alert(in_tt_amt);
			$('#pgrn').empty();
			for(var i=0;i<in_qty_length;i++)
			{
				if(in_qty[i] != '')
				{
					$('#pgrn').append('<div class="row"><div class="col-md-4"><div class="form-group"><input type="text" class="form-control" name="itm_name[]" id="itm_name" value="'+iname[i]+'" readonly><input type="hidden" class="form-control" name="rq_itm_id[]" id="rq_itm_id" value="'+rq_itm_id[i]+'" ><input type="hidden" class="form-control" name="itmid[]" id="itmid" value="'+itm_id[i]+'" ><input type="hidden" class="form-control" name="it_id[]" id="it_id" value="'+it_id[i]+'" ><input type="hidden" class="form-control" name="iqty[]" id="iqty" value="'+iqty[i]+'" ><input type="hidden" class="form-control" name="bal_qty[]" id="bal_qty" value="'+bal_qty[i]+'" ><input type="hidden" class="form-control" name="stk[]" id="stk" value="'+stk[i]+'" ><input type="hidden" class="form-control" name="in_qty[]" id="in_qty" value="'+in_qty[i]+'" ><input type="hidden" class="form-control" name="in_price[]" id="in_price" value="'+in_price[i]+'" ><input type="hidden" class="form-control" name="in_tt_amt[]" id="in_tt_amt" value="'+in_tt_amt[i]+'" ><input type="hidden" class="form-control" name="rtax[]" id="rtax" value="'+rtax[i]+'" ><input type="hidden" class="form-control" name="txamt[]" id="txamt" value="'+txamt[i]+'" ><input type="hidden" class="form-control" name="in_grd_amt[]" id="in_grd_amt" value="'+in_grd_amt[i]+'" ><input type="hidden" class="form-control" name="rmk[]" id="rmk" value="'+rmk[i]+'" ><input type="hidden" class="form-control" name="uom[]" id="uom" value="'+uom[i]+'" ><input type="hidden" class="form-control" name="cid[]" id="cid" value="'+cid[i]+'" ></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" name="inw_qty[]" id="inw_qty" value="'+in_qty[i]+'" readonly ></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" name="inw_ttl_amt[]" id="inw_ttl_amt" value="'+in_tt_amt[i]+'" readonly ></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" name="inw_tax[]" id="inw_tax" value="'+rtax[i]+'" readonly ></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" name="inw_value[]" id="inw_value" value="'+in_grd_amt[i]+'"  readonly ></div></div></div>');
		        }
			}
			//alert(rcdate);
			$('#dcno').val(dc_no);
			$('#reqid').val(reqid);
			$('#brname').val(brname);
			$('#rcdate').val(rcdate);
			$('#str').val(str);
			$('#brid').val(branch_id);
			$('#gtotal').val(gtotal);
			//$('#dc_upload').val(names);
		});
	</script>
	<script type="text/javascript">
      $(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 proper image format";
            $('#image_preview').empty();
          }
          else
        {
            preview_image();
            document.getElementById('errfn2').innerHTML="";
        }
            
        }); });
    </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");
    });
    
    $(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
</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.href = '<?php echo site_url('MaterialRequest/requestClosedList');?>';
					}, 200);
				}
			});
		}
	});
</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>