<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>
  <style>
.card {
    margin-bottom: 0.475rem!important;
    border: none!important;
    box-shadow: 0 2px 18px 1px rgb(49 53 72 / 10%)!important;
    border-radius: .45rem!important;
}
</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">Rejection Note </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="#">Purchase Order</a>
                  </li>
                  <li class="breadcrumb-item active">Rejection Note 
                  </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('Purchase/addRejection');?>" method="post" enctype="multipart/form-data">
			<div class="card">
				<div class="card-header">
					<h4 class="card-title" id="basic-layout-form-center">Rejection Note</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>
				<?php 	foreach($get_rejection as $rejection) 
				?>
							<div class="row justify-content-md-center" style="    margin-top: 7px!important;">
								<div class="col-md-3" style="margin-right:-23px!important;">
								<div class="form-group">
									<label>PO Order No</label>
									<input type="text" name="purchase_no" id="order_no" class="form-control" value="<?php echo $rejection->purchase_no; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>GNR No</label>
									<input type="text" name="purchase_no" id="order_no" class="form-control" value="<?php echo $rejection->grn_no; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group">
									<label>GNR  Date</label>
									<input type="text" name="purchase_date"  id="order_date" class="form-control" readonly="readonly" value="<?php echo $rejection->grn_date; ?>" readonly />
								</div>
							</div>
							<div class="col-md-2">
								<label>Rejection Date</label>
								<?php $cur_date = date("d-m-Y"); ?>
								<input class="form-control" type="text" name="rejection_date" id="uk_dp_1" value="<?php echo $cur_date ?>" readonly >
								<!--<input class="form-control" type="text" name="rejection_date"  id="uk_dp_1" placeholder="Date" data-uk-datepicker="{format:'DD-MM-YYYY'}" required >-->
							</div>
							<div class="col-md-3">
								<label>Supplier Name</label>
								<input type="text" name="vender_name" class="form-control" id="company_name" value="<?php echo $rejection->venders_name; ?>" readonly />
								<input name="gnr_id" type="hidden" class="textbox form-control" id="gnr_id" value="<?php echo $mid ?>">
								<input name="smid" type="hidden" class="textbox form-control" id="smid" value="<?php echo $smid ?>">
								<input type="hidden" name="purchase_id" id="purchase_id" class="form-control" value="<?php echo $rejection->purchase_id; ?>"/>
								<input type="hidden" name="branchname" id="branchname" class="form-control" value="<?php echo $_SESSION['branch_name']?>"/>
								<input type="hidden" name="uname" id="uname" class="form-control" value="<?php echo $_SESSION['full_name']?>"/>
							</div>
						</div>
				</div>	
			</div>
		</div>
						
		<div class="row">						
			<?php
		
		$count = 1;
		foreach($get_rejection_item as $pitem){
		?>
		<div class="col-md-5">
    			<div class="card" style="height: 58px!important;">
    				<div class="card-content collapse show">
    					<div class="card-body" style="height: 80px!important;">
					
						
										<?php if($pitem->grn_item_qty == $pitem->rejected_qty) { ?>
									
											<div class="row" style="margin-top: -12px!important;margin-left: -36px!important;">
												<div class="col-md-5">
													<div class="form-group">
														<input class="form-control product_details stk" type="text" style="width: 232px!important;" name="item_name[]" id="item_name <?php echo $count; ?>" value="<?php echo $pitem->item_name; ?>" disabled />
													</div>
												</div>
												<div class="col-md-2">
													<div class="form-group">
														<input class="form-control product_details quantity" type="text" name="quantity[]" style="width: 80px!important;" id="quantity<?php echo $count; ?>" value="<?php echo $pitem->required_qty; ?>" disabled />
													</div>
												</div>
												<div class="col-md-3">
													<div class="form-group">
														<input class="form-control product_details" type="text" name="grn_qty[]" id="grn_qty <?php echo $count; ?>" style="width: 80px!important;" value="<?php echo $pitem->grn_item_qty; ?>" disabled />
													</div>
												</div>
												<div class="col-md-2">
													<input class="form-control product_details quantity" type="text" name="quantity[]" style="width:70px!important;"  id="quantity<?php echo $count; ?>" value="<?php echo $pitem->grn_item_price; ?>" disabled />
												</div>
											</div>
										
										<?php
											} else {
										?>	
									
											<div class="row" style="margin-top: -12px!important;margin-left: -32px!important;">
												<div class="col-md-6">
													<div class="form-group">
														<input class="form-control product_details" type="text" name="item_name[]" style="width: 232px!important;" id="item_name <?php echo $count; ?>" value="<?php echo $pitem->item_name; ?>" readonly />
													</div>
												</div>
												<div class="col-md-2">
													<div class="form-group">
														<input class="form-control product_details quantity" type="text" name="quantity[]" style="width: 80px!important;" id="quantity<?php echo $count; ?>" value="<?php echo $pitem->required_qty; ?>" readonly />
													</div>
												</div>
												<div class="col-md-2">
													<div class="form-group">
														<input class="form-control product_details" type="text" name="grn_qty[]" style="width: 80px!important;" id="grn_qty <?php echo $count; ?>" value="<?php echo $pitem->grn_item_qty; ?>" readonly />
													</div>
												</div>
												<div class="col-md-2">
													<input class="form-control product_details quantity" type="text" name="quantity[]" style="width: 70px!important;"  id="quantity<?php echo $count; ?>" value="<?php echo $pitem->grn_item_price; ?>" readonly />
												</div>
											</div>										
									
										<?php
										}
									?>	
				
                    </div>
                </div>
            </div>
            </div>
            <div class="col-md-7">
    			<div class="card" style="height: 58px!important;">
    				<div class="card-content collapse show">
    					<div class="card-body">			
						
									<?php if($pitem->grn_item_qty == $pitem->rejected_qty) { ?>
										<div class="row" style="margin-top: -12px!important;">
												<div class="col-md-3">
													<div class="form-group">
														<input type="hidden" name="gnr_po_id[]" id="gnr_po_id" value="<?php echo $pitem->purchase_grn_id; ?>" disabled />
														<input class="rej_qty a form-control" type="text" name="rejected_qty[]" id="rejected_qty[]" data-uk-tooltip="{pos:'bottom'}" title="Rejected Qty" value="<?php echo $pitem->rejected_qty; ?>" disabled />
													</div>
												</div>
												<div class="col-md-1">
													<div class="form-group">
														<img src="<?php echo base_url(); ?>images/right.png" alt="" class="img_main"/>
													</div>
												</div>
												<div class="col-md-2">
													<div class="form-group">
														<span>Rejected</span>
													</div>
												</div>
											</div>
										
										<?php
											} else {
											$item = $pitem->item_name;
											$item_no = $pitem->itm_id;
											$branch = $_SESSION['branch_name'];	
											
											$query = $this->db->query("SELECT stock_item from item_creation where itm_id='$item_no' and branchname='$branch'");
											foreach($query->result_array() as $row2)
										?>
										<div class="row" style="margin-top: -12px!important;">
													<input type="hidden" name="gnr_po_id[]" id="gnr_po_id" value="<?php echo $pitem->purchase_grn_id; ?>" readonly />
												<input class="qty form-control col-md-2" type="text" name="rjn_quantity[]"  id="rjn_quantity[]" placeholder=" QTY" data-uk-tooltip="{pos:'bottom'}" title="Enter Less or Equal : <?php echo $pitem->rejection_bal_qty; ?> Qty" />
												<input class="col-md-2" type="hidden" name="itm_no[]"  id="itm_no[]" value="<?php echo $pitem->itm_id; ?>" />
												<input class="stk " type="hidden" name="stock[]"  id="stock[]" value="<?php echo $row2['stock_item']; ?>" />
							<input style="margin-left:9px!important;" class="rej_qty form-control col-md-1" type="text" name="rejected_qty[]"   id="rejected_qty[]"  placeholder="Rejected Qty" value="<?php echo $pitem->rejected_qty; ?>" readonly data-uk-tooltip="{pos:'bottom'}" title="Rejected Qty" />
												<input class="qty_pending form-control" type="hidden" name="rejection_bal_qty[]"   id="rejection_bal_qty[]"  placeholder="Rejected Balanace" value="<?php echo round($pitem->rejection_bal_qty,2); ?>" readonly />
												<input class="price form-control col-md-2" type="text" name="rjn_price[]"   id="rjn_price[]"  placeholder="Price" value="<?php echo $pitem->grn_item_price; ?>" readonly data-uk-tooltip="{pos:'bottom'}" title="GNR Price"/>
												<input class="tax form-control col-md-1" type="text" name="rjn_tax[]"  id="rjn_tax[]" placeholder="Tax" value="<?php echo $pitem->grn_tax; ?>" readonly  data-uk-tooltip="{pos:'bottom'}" title="GNR Tax(%)"/>
												<input class="taxamount form-control" type="hidden" name="rjn_tax_amount[]"  id="rjn_tax_amount[]" />
												<input class="total form-control" type="hidden" name="rjn_total_amount[]"  id="rjn_total_amount[]"/>
												<input class="grand form-control col-md-2" type="text" name="rjn_inward_grand_amount[]" id="rjn_inward_grand_amount[]"  placeholder="Amt" readonly />
												<input class="remarks form-control col-md-2" type="text" name="rjn_remarks[]" id="rjn_remarks[]" placeholder="Remarks"/>
												
												</div>
										
										<?php
										}
									?>	
								</div>
                    </div>
                </div>
            </div>
            <?php $count++; } ?>
		</div>			

				
			<div class="card">
    				<div class="card-content collapse show">
    					<div class="card-body">
							<div class="form-actions text-right">
								<div class="col-md-2 text-center">
								<div class="form-group">
									
									<input type="hidden" id="rej_amt" name="rej_amt">
								</div>
							</div>
								<button type="reset" class="btn btn-sm btn-warning mr-1">
										<i class="ft-x-circle"></i> Cancel
								</button>
								<button type="submit" class="btn btn-sm btn-primary">
										<i class="ft-save"></i> Save
								</button>
							</div>
							</div>
							</div>
							</div>
						</form>	

					</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[
	 $(document).ready(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() );
				var j2=$(this).nextAll(".taxamount"); 
				j2.val(( j0.val() * j2.prevAll(".tax").val()) / 100 );
				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());
				var sum = 0;
				$('.grand').each(function() {
					sum += Number($(this).val());
				});
				$('#rej_amt').val(sum.toFixed(2));
			}
			})});
		});
		
		
	</script>
	<script>
		 $(document).ready(function() {
			$(".qty").each( function(){ $(this).on( {'change': function() { 
				var q1 = $(this).parent().find('.qty').val();
				var q2 = $(this).parent().find('.qty_pending').val();
				//var grand = $(this).parent().find('.grand').val();
				if(parseFloat(q1) <= parseFloat(q2)){
					//alert("sucess");
				}
				else{
					alert("You cant enter more than GRN balance quantity");
					$(this).parent().find('.qty').val('0');
					$(this).parent().find('.grand').val('0')
				}
					var sum = 0;
				$('.grand').each(function() {
					sum += Number($(this).val());
				});
				$('#rej_amt').val(sum.toFixed(2));
			}
			})
			})
		});
	</script>
	<script>
		 $(document).ready(function() {
			$(".qty").each( function(){ $(this).on( {'change': function() { 
				var q1 = $(this).parent().find('.qty').val();
				var q2 = $(this).parent().find('.stk').val();
				//var grand = $(this).parent().find('.grand').val();
				if(parseFloat(q1) <= parseFloat(q2)){
					//alert("sucess");
				}
				else{
					alert("You cant enter more than the present stock");
					$(this).parent().find('.qty').val('0');
					$(this).parent().find('.grand').val('0')
				}
				var sum = 0;
				$('.grand').each(function() {
					sum += Number($(this).val());
				});
				$('#rej_amt').val(sum.toFixed(2));
			}
			})
			})
		});
	</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>