<?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">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('ProductRequest/addPrideInward');?>" method="post" enctype="multipart/form-data">
			<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($req as $rq) ?>
						
							<div class="row justify-content-md-center">
							<div class="col-md-2">
								<div class="form-group">
									<label>RO.NO</label>
									<input type="text" name="order_no" id="order_no" class="form-control" value="<?php echo $rq->pr_req_no; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>RO DATE</label>
									<input type="text" name="order_date"  id="order_date" class="form-control" readonly="readonly" value="<?php echo $rq->request_date; ?>"/>
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>RCP DATE</label>
									<?php $cur_date = date("d-m-Y"); ?>
										<input class="form-control" type="text" name="rcp_date"  id="rcp_date" value="<?php echo $cur_date; ?>" readonly >
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>DC NO</label>
									<input type="text" name="invoice" id="invoice" class="form-control" required />
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>Store</label>
									<input class="form-control" type="text" name="store" id="store" value="<?php echo $rq->dept; ?>" >
									<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 image_file" accept="image/*" multiple  />
									<div id="errfn2" style="color:red;"></div>
								</div>
							</div>
						</div>
							
						
								
						<?php
					
					$count = 1;
					foreach($req_item as $rqitem){
					?>
					<div class="row justify-content-md-center">
						
						<div class="col-md-5">
									<?php
										if($rqitem->required_qty == $rqitem->recieved_qty) {
										?>
										<div class="row">
											<div class="col-md-6">
												<div class="form-group">
													<input class="form-control product_details" type="text" name="item_name[]" id="item_name <?php echo $count; ?>" value="<?php echo $rqitem->item_name; ?>" tabindex="-1"  disabled />
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<input class="form-control product_details quantity" type="text" name="quantity[]"  id="quantity<?php echo $count; ?>" value="<?php echo $rqitem->required_qty; ?>" tabindex="-1" disabled />
												</div>
											</div>
										</div>
										<?php
											} else {
										?>	
										<div class="row">
											<div class="col-md-6">
												<div class="form-group">
													<input class="form-control product_details" type="text" name="item_name[]" id="item_name <?php echo $count; ?>" value="<?php echo $rqitem->item_name; ?>" tabindex="-1" readonly />
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<input class="form-control product_details " type="text" name="quantity[]"  id="quantity<?php echo $count; ?>" value="<?php echo $rqitem->required_qty; ?>" tabindex="-1" readonly />
												</div>
											</div>
										</div>
										<?php
										}
									?>								
								</div>
							
										
						<?php
							if($rqitem->required_qty == $rqitem->recieved_qty) {
						?>
						<div class="col-md-7">
							<div class="row">
							<div class="col-md-2">
								<div class="form-group">
									<input class="item_id" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $rqitem->request_item_id; ?>" disabled>
									<input class="qty form-control product_details" type="text" name="inward_quantity[]"  id="inward_quantity[]" value="<?php echo $row1['required_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"/>
									<span class="col-md-2">Received</span>
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<span>Received</span>
								</div>
							</div>
						</div>
						</div>
						
						
						<?php
							} else {
						?>
						<div class="col-md-7">
							<div class="row">
							        <input class="item_id" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $rqitem->request_item_id?>">	
										<input class="item_id" type="hidden" name="item_sid[]" id="item_sid" value="<?php echo $rqitem->recipe_id; ?>">
										<input class="item_id" type="hidden" name="uom[]" id="uom" value="<?php echo $rqitem->uom; ?>">
										<input class="item_id" type="hidden" name="cat_id[]" id="cat_id" value="<?php echo $rqitem->pr_cat_id; ?>">
										<input type="hidden" name="stock_item[]"   id="stock_item <?php echo $count; ?>" value="<?php echo $rqitem->production_stock; ?>"/>
										<input class="qty form-control col-md-2" type="text" name="inward_quantity[]"  id="inward_quantity"  placeholder="Qty"  />
										<input class="grn_balance form-control col-md-2" type="text" name="received_qty[]" id="received_qty" value="<?php echo $rqitem->recieved_qty; ?>" data-uk-tooltip="{pos:'bottom'}" title="Received Qty" tabindex="-1" readonly />
										<input class="grn_balance" type="hidden" name="bal_item_qty[]" id="bal_item_qty" value="<?php echo $rqitem->item_balance_qty; ?>" />
										<input class="price " type="hidden" name="inward_price[]" id="inward_price[]" value="<?php echo $rqitem->rate; ?>" />
										<input class="tax tax_auto " type="hidden" name="rcp_tax[]"  id="rcp_tax" value="<?php echo $rqitem->tax; ?>" />
										<input class="taxamount" type="hidden" name="tax_amount[]"  id="tax_amount" />
										<input class="total" type="hidden" name="inward_total_amount[]" id="inward_total_amount[]"/>
										<input class="grand grn_grand " type="hidden" name="inward_grand_amount[]" id="inward_grand_amount[]"  placeholder="Amount" readonly />
										<input class="remarks form-control col-md-2 product_details" type="text" name="remarks[]" id="remarks[]" placeholder="Remarks" tabindex="-1" />
										<input class="qty_pending" type="hidden" name="grn_balanace[]"   id="grn_balanace_qty" value="<?php echo $rqitem->item_balance_qty; ?>"/>
												
								</div>
							</div>
						<?php
							}
						?>	
									
								
					</div>	
				<?php $count++; } ?>

				<br/>
				<div class="uk-grid" data-uk-grid-margin="">
					<div class="uk-width-medium-1-1" >
						<div class="md-card">
							<div class="md-card-content">
								<div class="row">
									
									<div class="col-md-12 text-right">
										<div class="form-group">
												<input type="submit" name="submit" id="submit"  class="md-btn md-btn-primary" value="Add Receipt" onclick="return confirm('Are you sure you want to submit this form?')">
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</form>
			<br/>
			
		<!-- Confirmation Form -->
		    <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 $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>
			</div>
		
			
			<div id="image_preview"></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
		$(window).load(function(){
			$(".qty,.price,.tax,.closing")
			.each( function(){ $(this).on( {'keyup': function() { 
				var j0=$(this).nextAll(".total"); 
				j0.val( j0.prevAll(".qty").val() * j0.prevAll(".price").val() );
				//alert(j0.val());
				var j2=$(this).nextAll(".taxamount"); 
				j2.val(((j0.val() * parseFloat(j2.prevAll(".tax").val())) / 100).toFixed(2));
				//$('.tax').blur();
				var j3=$(this).nextAll(".grand"); 
				j3.val(((parseFloat(j0.val()) + parseFloat(j2.val()))).toFixed(2));
				var j1=$(this).nextAll(".final"); 
				j1.val( j1.prevAll(".qty").val() + j1.prevAll(".closing").val());
			}
			})});
		});
	</script>
		<script>
		$('#submit3').click(function() {
			var formData = $('form#invoice_form_validate').serialize();
			var remarks = $('#req_remark').val();
			if(remarks == '')
			{
				alert("Please Enter the Remarks");
				return false;
			}
			else
			{
				$.ajax({
					type: "POST",
					url: "request_of_pride_updation.php",
					data: formData,
					//contentType: false,
					// processData: false,
					success: function(dataz) {
						var dataa = $.trim(dataz); 
						var dataArr = dataa.split('|'); 
						var data = dataArr[0]; 
						var data2 = dataArr[1];
						//alert(data);
						//alert(data2);
						if(data == "success")
						{
							$('.request_updation_success').html( 'Inward Updated Successfully' );
							$('.request_updation_success').css( "display","block" );
						}
						else if(data == "greater")
						{			
							$('.request_updation_error').html('greater!!!' );
							$('.request_updation_error').css( "display","block" );
							$('.request_updation_success').css( "display","none" );
						}
						else
						{
							$('.request_updation_error').html( 'Failed' );
							$('.request_updation_error').css( "display","block" );
							$('.request_updation_success').css( "display","none" );					
						}
						setTimeout(function() {
							window.location.href = "request_closed_list.php?page_id=request-closed-list";
						}, 200);
					}
				});
			}
		});
	</script>
	<script type="text/javascript">
		$(function() {
			$('input.txtNum').blur(function() {
				var amt = parseFloat(this.value);
				//$(this).val('$' + amt.toFixed(2));
				$(this).val((Math.round(amt*100))/100).toFixed(2);
			});
		});
	</script>
	<!-- total amount calculation -->
	<script type="text/javascript">
		$('.tax').change(function () {
			var sum1 = 0;
			// we use jQuery each() to loop through all the textbox with 'price' class
			// and compute the sum for each loop
			$('.grn_grand').each(function() {
				sum1 += Number($(this).val());
			});
			var t_sum = (sum1).toFixed(2);
			// set the computed value to 'totalPrice' textbox
			$('#total_amt').val(t_sum);
			$('#total_amt').blur();
		});
	</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>
  </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>