<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	
	?>

<style>
    .cust_tr{
        line-height: 37px!important;
    }
    .cust_font{
        font: 400 13px/1.42857143 Roboto,sans-serif!important;
    }
    .cust_trv{
        visibility:hidden!important;
    }
    .rwid{
    	height: 48px!important;
    }
    .iwid{
        height: 48px!important;
    }
    .colmd1{
            margin-right: -3px!important;
    }
    .club{
        margin-left: -17px!important;
        width: 104%!important;
    }
    td{
        word-break: break-all!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">Product Issue</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="#">Product Request</a>
                  </li>
                  <li class="breadcrumb-item active">Product Issue
                  </li>
                </ol>
              </div>
            </div>
          </div>
        </div>
        <div class="content-body"><!-- Zero configuration table -->
<section id="configuration">
    <div class="row" style="margin-right: -39px!important;margin-left: -39px!important;">
        <div class="col-md-12">
            <div class="card">
                <!--<div class="card-header">
                    <h4 class="card-title">Request List</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 card-dashboard">
					
						 <form method="post" autocomplete="off" action="<?php echo site_url('ProductRequest/productIssueByDateKitchen/');?>" method="POST">
                        	<div class="row justify-content-md-center">
								<div class="col-md-4">
									<div class="form-group">
										<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="req_date"  id="req_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date" required >
										<input type="hidden" name="sub_mod_id" id="sub_mod_id" value="<?php echo $submod; ?>">
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<select id="department" name="department" class="select2" >
											<option value="">Select Department</option>	
											<option value="Savories Kitchen">Savories Kitchen</option>
											<option value="First Floor Kitchen">First Floor Kitchen</option>
											<option value="Specialty Kitchen">Specialty Kitchen</option>
											<option value="Dry Cake Kitchen">Dry Cake Kitchen</option>
										</select>
									</div>
								</div>
								<div class="col-md-4">
									<div class="form-group">
										<input type="submit" name="submit" class="btn btn-primary" value="REQ Report">
									</div>
								</div>
							</div>
						</form>		
										
                        <div class="table-responsive" style="margin-left: -14px!important;">
						
							<?php
							if(isset($_POST['submit'])) {
								 
								
							?>
						<?php if($_POST['req_date']!="") { ?>
						
						<div class="tabs-default">
							<ul>
			                <?php foreach($access_tab as $act){ ?>
			                    <li><a href="#<?php echo $act->access_id;?>" class="tab-col"> <?php echo $act->access_tab;?></a></li>
			                  <?php } ?>
			                </ul>
							 <?php //echo $_POST['req_date']; //echo $_POST['department']?>
							<br/>
							<?php foreach($access_tab as $act){ ?>
							<div id="<?php echo $act->access_id;?>">
								<?php if($act->access_tab == 'Regular Order') {
								    if(is_array($result_display)) {
								if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
								?>
								<h4>Regular Order On - <?php echo $_POST['req_date']; ?></h4>
								<form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addRegularIssue');?>" method="post">
								<input type="hidden" name="rdate" id="rdate" value="<?php echo $_POST['req_date']; ?>" >
								<?php 
                    				$udept = $_POST['department'];
                    				$udq = $this->db->query("SELECT * from user where username='$udept'");
                    				$udr = $udq->row_array(); ?>
								<input type="hidden" name="uname" id="uname" value="<?php echo $udr['username']; ?>" >
								<input type="hidden" name="branch_id" id="branch_id" value="<?php echo $udr['branch_id']; ?>" >
								<input type="hidden" id="branch_name" class="form-control"  name="branch_name" value="<?php echo $udr['branch_name']; ?>">
								<div class="row club">
									<div class="col-md-3 col-sm-3">
										<table class="table table-striped table-bordered jw-table" id="contact-detail">
											<thead>
											    <tr class="cust_trv" >
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
												<tr class="cust_tr">
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
											</thead>
											<tbody>
											<?php
												foreach($result_display as $itm)
												{
											?>
											<tr class="cust_tr cust_font iwid">
												<td><?php echo $itm['item_name']; ?></td>
												<td><?php echo $itm['production_stock']; ?>
												<input class="prd_item form-control" type="hidden" name="prd_item[]" id="prd_item" value="<?php echo $itm['item_name']; ?>" />
												<input class="recipe_id form-control" type="hidden" name="recipe_id[]" id="recipe_id" value="<?php echo $itm['recipe_id']; ?>" />
												<input class="cat_id form-control" type="hidden" name="cat_id" id="cat_id" value="<?php echo $itm['pr_cat_id']; ?>" />
												<input class="puom form-control" type="hidden" name="puom[]" id="puom" value="<?php echo $itm['uom']; ?>" />
												<input class="yeild form-control" type="hidden" name="yeild[]" id="yeild" value="<?php echo $itm['yeild']; ?>" />
												<input class="yeild form-control prd_stk" type="hidden" name="prd_stk[]" id="prd_stk" value="<?php echo $itm['production_stock']; ?>" />
												</td>
											</tr>
											<?php }
											$i++;
											?>
											<?php else: ?>
											<tr>
												<td colspan="8" align="center" >No Records Found..</td>
											</tr>
											<?php
												endif;
											?>
											</tbody>
										</table>
									</div>
									<?php 
									$i = 0;
									$k = 0;
									foreach($counters as $ctr) {
									$out_branch = $ctr->branchname;
									//echo $out_branch;
									?>
									<input type="hidden" name="outlet_branch[]"  id="outlet_branch<?php echo $i; ?>" class="form-control" readonly="readonly" value="<?php echo $ctr->branchname; ?>"/>
									<input name="req_id[]" id="req_id" type="hidden" class="form-control" value="<?php echo $ctr->request_id; ?>" readonly >
									<?php $q2 = $this->db->query("select * from user where branch_name='$out_branch'");
									$r = $q2->row_array(); ?>
									<?php $q3 = $this->db->query("select * from user where username='$udept'");
									$r2 = $q3->row_array(); ?>
									<input type="hidden" name="dept[]" id="dept" class="form-control" readonly="readonly" value="<?php echo $r['username']; ?>"/>
									
									<div class="col-md-2 col-sm-2 colmd1">
										<table class="table table-striped table-bordered" style="width: 105%!important;" >
											<thead>
												<tr>
													<th colspan="3"><?php echo $ctr->branchname; ?></th>
												</tr>
												<tr class="rwid">
													<th>RQty</th>
													<th>Qty</th>
													<th>IQty</th>
												</tr>
											</thead>
											<tbody>
											<?php 
												$j = 0;
												foreach($result_display as $itm) {
													$branch_id = $_SESSION['branch_id'];
												//	$uname = $_SESSION['username'];
													$iname = $itm['item_name'];
													$r_date = date('Y-m-d',strtotime($_POST['req_date']));
													$department=$_POST['department'];
											$out_branchid=	$r['branch_id']	;
											$kbranch_id = $r2['branch_id'];
													if($department == 'Commissary')
                        			{
                        			    $q1 = $this->db->query("select *, (PI.required_qty-PI.recieved_qty) as item_balance_qty,P.branchname as out_branch from product_request P inner join product_request_item PI on P.request_id=PI.request_id inner join recipe R on PI.item_name=R.rname where P.request_date='$r_date' and P.orders='Regular Order' and P.status='Pending' and P.dept='$department' and P.branchname='$out_branch' and R.branch_id='$out_branchid' order by PI.f_code,PI.pr_cat_id,PI.item_name");
                        			}
                        			else
                        			{
                        			    //$q1 = $this->db->query("select *, (PI.required_qty-PI.recieved_qty) as item_balance_qty,P.branchname as out_branch from product_request P inner join product_request_item PI on P.request_id=PI.request_id inner join recipe R on PI.item_name=R.rname where P.request_date='$r_date' and P.orders='Regular Order' and P.status='Pending' and P.dept='$department' and P.branchname='$out_branch' and R.branch_id='$out_branchid' order by PI.item_name");
                        			    $q1 = $this->db->query("select *,(PI.required_qty-PI.recieved_qty) as item_balance_qty,P.branchname as out_branch from product_request P inner join product_request_item PI on P.request_id=PI.request_id inner join recipe R on PI.recipe_no=R.recipe_no where P.request_date='$r_date' and P.orders='Regular Order' and P.status='Pending' and P.dept='$department' and P.branchname='$out_branch' and PI.item_name='$iname' and R.branch_id='$kbranch_id' order by PI.f_code,PI.pr_cat_id,PI.item_name");
                        			}
												
									if($q1->num_rows() > 0)
									{
														$rgrow = $q1->row_array();
														$req_qty = $rgrow['required_qty'];
														$recv_qty = $rgrow['recieved_qty'];
												?>
												<tr class="cust_tr iwid">
													<td><?php echo $rgrow['required_qty']; ?></td>
													<td>
														<input type="hidden" name="item_index"  id="item_index" class="form-control item_index" readonly="readonly" value="<?php echo $j; ?>"/>
							<?php if($req_qty == $recv_qty) { ?>
															<input class="qty<?php echo $i; ?> form-control" type="hidden" name="inward_quantity[]" id="inward_quantity" placeholder="Qty" />
															<input class="form-control item_id" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="item_name[]" id="item_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="item_id form-control" type="hidden" name="item_id[]" id="item_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="recipe_no form-control" type="hidden" name="recipe_no[]" id="recipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="pr_cat_id form-control" type="hidden" name="pr_cat_id[]" id="pr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control quantity<?php echo $i; ?>" type="hidden" name="quantity[]" id="quantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="item_id form-control" type="hidden" name="uom[]" id="uom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control stk<?php echo $i; ?>" type="hidden" name="stock[]" id="stock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
															
											<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />				<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>
														
															<input class="form-control tot_basic<?php echo $i; ?>" type="hidden" name="tot_basic[]" id="tot_basic" />											<input class="form-control tax_amt<?php echo $i; ?>" type="hidden" name="tax_amt[]" id="tax_amt" />
															<input class="form-control tot_price<?php echo $i; ?>" type="hidden" name="total_price[]"  id="total_price" />
															<input class="form-control" type="hidden" name="received_qty[]" id="received_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="grn_balance qty_pending<?php echo $i; ?>" type="hidden" name="bal_item_qty[]" id="bal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
							<?php } else { ?>
															<input class="qty<?php echo $i; ?> form-control" type="text" name="inward_quantity[]" id="inward_quantity" placeholder="Qty" />
															<input class="form-control item_id" type="hidden" name="req_item_id[]" id="req_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="item_name[]" id="item_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="item_id form-control" type="hidden" name="item_id[]" id="item_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="recipe_no form-control" type="hidden" name="recipe_no[]" id="recipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="pr_cat_id form-control" type="hidden" name="pr_cat_id[]" id="pr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control quantity<?php echo $i; ?>" type="hidden" name="quantity[]"  id="quantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="item_id form-control" type="hidden" name="uom[]" id="uom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control stk<?php echo $i; ?>" type="hidden" name="stock[]" id="stock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
															<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />
															<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]"  id="price" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]"  id="tax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]"  id="basic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>
															
															<input class="form-control tot_basic<?php echo $i; ?>" type="hidden" name="tot_basic[]" id="tot_basic" />											<input class="form-control tax_amt<?php echo $i; ?>" type="hidden" name="tax_amt[]" id="tax_amt" />
															<input class="form-control tot_price<?php echo $i; ?>" type="hidden" name="total_price[]"  id="total_price" />
															<input class="form-control" type="hidden" name="received_qty[]" id="received_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="grn_balance qty_pending<?php echo $i; ?>" type="hidden" name="bal_item_qty[]" id="bal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
								<?php } ?>
													</td>
													<td><?php echo $rgrow['recieved_qty']; ?></td>
													
													
												</tr>
											<?php } else { ?>
												<tr class="cust_tr iwid">
													<td>0</td>
													<td>0</td>
													<td>0</td>
												</tr>
												<input class="qty<?php echo $i; ?> form-control" type="hidden" name="inward_quantity[]" id="inward_quantity" placeholder="Qty" />
												<input class="form-control item_id" type="hidden" name="req_item_id[]" id="req_item_id" >
												<input class="form-control" type="hidden" name="item_name[]" id="item_name" />
												<input class="item_id form-control" type="hidden" name="item_id[]" id="item_id">
												<input class="recipe_no form-control" type="hidden" name="recipe_no[]" id="recipe_no" >
												<input class="pr_cat_id form-control" type="hidden" name="pr_cat_id[]" id="pr_cat_id" >
												<input class="form-control quantity<?php echo $i; ?>" type="hidden" name="quantity[]"  id="quantity" />
												<input class="item_id form-control" type="hidden" name="uom[]" id="uom" >
												<input class="form-control stk<?php echo $i; ?>" type="hidden" name="stock[]" id="stock" />
												<input class="form-control price<?php echo $i; ?>" type="hidden" name="price[]" id="price" />
												<input class="form-control tot_basic<?php echo $i; ?>" type="hidden" name="tot_basic[]" id="tot_basic" />
												<input class="form-control tax<?php echo $i; ?>" type="hidden" name="tax[]" id="tax" />
												<input class="form-control basic_tax<?php echo $i; ?>" type="hidden" name="basic_tax[]" id="basic_tax" />
												<input class="form-control tax_amt<?php echo $i; ?>" type="hidden" name="tax_amt[]" id="tax_amt" />
												<input class="form-control tot_price<?php echo $i; ?>" type="hidden" name="total_price[]" id="total_price" />
												<input class="grn_balance<?php echo $i; ?> form-control" type="hidden" name="received_qty[]" id="received_qty" />
												<input class="grn_balance qty_pending<?php echo $i; ?>" type="hidden" name="bal_item_qty[]" id="bal_item_qty" />
											<?php	} 
											$j++;
											$k++;
											} ?>
											</tbody>
										</table>
										<input class="form-control gt<?php echo $i; ?>" type="hidden" name="grand_total[]" id="grand_total<?php echo $i; ?>" readonly />
										
									</div>
									<?php $i++;
									} ?>
									
									<div class="col-md-1 col-sm-1">
										<table class="table table-striped table-bordered" >
											<thead>
											    <tr class="cust_trv">
											        <th>Iss Qty</th>
											    </tr>
												<tr class="cust_tr">
													<th>Iss Qty</th>
												</tr>
											</thead>
											<tbody>
												<?php
												foreach($result_display as $itm)         {
												?>
														<tr>
															<td>
															<input type="text" name="pr_stock[]" id="pr_stock" class="form-control pr_stock" value="0" readonly /></td>
														</tr>
													<?php
												}
												?>
											</tbody>
										</table>
										</br>
									</div>
									<input class="form-control col-md-1" type="hidden" name="ctrct" id="ctrct" value="<?php echo $i; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="itemct" id="itemct" value="<?php echo $j; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="ttitemct" id="ttitemct" value="<?php echo $k; ?>" readonly />
								</div>
								
								<div class="form-actions text-right">
									<button type="reset" class="btn btn-warning mr-1">
									<i class="ft-x"></i> Cancel
								</button>
								<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit this form?')" >
									<i class="la la-check-square-o"></i> Save
								</button>
								
							</div>
								
								</form>
								<?php } ?>
								<?php } else if($act->access_tab == 'Special Order') { ?>
								<?php foreach($spl_ord as $spl) {
									$uname=$_POST['department'];
									$q2 = $this->db->query("select * from user where username='$uname'");
									$r = $q2->row_array();
									$ubranch=$r['branch_name'];
									$fname=$r['full_name'];
									$r_date = date("Y-m-d", strtotime($_POST['req_date']));
									$branch = $spl->branchname;
									$q3 = $this->db->query("select * from user where branch_name='$branch'");
									$r3 = $q3->row_array();
									$request_id = $spl->request_id;
									$count1 = 0;
									$count2 = 0;
									$q1 = $this->db->query("select * from product_request as P,product_request_item as PI where P.request_id=PI.request_id and P.dept='$uname' and (P.request_date='$r_date') and P.request_id='$request_id'");
									
									$req_res = $q1->result();
									foreach($req_res as $req_row) { 
										if(($req_row->status == 'Closed'))
										{	
											$count2++;	
										}
										$count1++;
									}
								?>
								<div class="row">
									<div class="col-md-2 col-sm-2">
										<div class="form-group">
											<!--<h4><?php //echo $row3['username']; ?></h4>-->
											<input type="text" name="dept"  id="dept" class="form-control" readonly="readonly" value="<?php echo $r['username']; ?> "/>
									</div>
									</div>
									<div class="col-md-3 col-sm-3">
										<div class="form-group">
											<?php if($count1 == $count2) { ?>
											<input type="text" class="form-control" style="width:200px;" value="<?php echo $spl->pr_req_no; ?>" disabled />
											<?php } else { ?>
											<button class="grid-form-dialog-btn btn btn-primary" style="width:200px;" onclick="javascript:load_marks(<?php echo $spl->request_id; ?>)" ><?php echo $spl->pr_req_no; ?></button>
											<?php } ?>
										</div>
									</div>
								</div>
								<?php
								}
								?>	
								<?php } else if($act->access_tab == 'Running Order') { ?>
								<?php foreach($run_ord as $run) {
									$uname=$_POST['department'];
									$q2 = $this->db->query("select * from user where username='$uname'");
									$r = $q2->row_array();
									$ubranch=$r['branch_name'];
									$fname=$r['full_name'];
									$r_date = date("Y-m-d", strtotime($_POST['req_date']));
									$branch = $run->branchname;
									$q3 = $this->db->query("select * from user where branch_name='$branch'");
									$r3 = $q3->row_array();
									$request_id = $run->request_id;
									$count1 = 0;
									$count2 = 0;
									$q1 = $this->db->query("select * from product_request as P,product_request_item as PI where P.request_id=PI.request_id and P.dept='$uname' and (P.request_date='$r_date') and P.request_id='$request_id'");
									$req_res = $q1->result();
									foreach($req_res as $req_row) { 
										if(($req_row->status == 'Closed'))
										{	
											$count2++;	
										}
										$count1++;
									}
								?>
								<div class="row">
									<div class="col-md-2 col-sm-2">
										<div class="form-group">
											<!--<h4><?php //echo $row3['username']; ?></h4>-->
											<input type="text" name="dept"  id="dept" class="form-control" readonly="readonly" value="<?php echo $r3['username']; ?> "/>
										</div>
									</div>
									<div class="col-md-3 col-sm-3">
										<div class="form-group">
											<?php if($count1 == $count2) { ?>
											<input type="text" class="form-control" style="width:200px;" value="<?php echo $run->pr_req_no; ?>" disabled />
											<?php } else { ?>
											<button class="grid-form-dialog-btn btn btn-primary" style="width:200px;" onclick="javascript:load_marks(<?php echo $run->request_id; ?>)" ><?php echo $run->pr_req_no; ?></button>
											<?php } ?>
										</div>
									</div>
								</div>
								<?php
								}
								?>	
								<?php } else if($act->access_tab == 'Santhe') {
								   // if(!empty($st_ord)) {
									$i=1;
								?>
								<h4>Santhe Order On - <?php echo $_POST['req_date']; ?></h4>
								<form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addStRegularIssue');?>" method="post">
								<input type="hidden" name="srdate" id="srdate" value="<?php echo $_POST['req_date']; ?>" >
								<input type="hidden" name="suname" id="suname" value="<?php echo $_SESSION['username']; ?>" >
								<input type="hidden" name="sbranch_id" id="sbranch_id" value="<?php echo $_SESSION['branch_id']; ?>" >
								<input type="hidden" id="sbranch_name" class="form-control"  name="sbranch_name" value="<?php echo $_SESSION['branch_name'];?>">
								<div class="row">
									<div class="col-md-3 col-sm-3">
										<table class="table table-striped table-bordered" >
											<thead>
											    <tr class="cust_trv">
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
												<tr class="cust_tr">
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
											</thead>
											<tbody>
											<?php
												foreach($st_ord as $stitm)
												{
											?>
											<tr class="iwid">
												<td><?php echo $stitm['item_name']; ?></td>
												<td><?php echo $stitm['production_stock']; ?>
												<input class="sprd_item form-control" type="hidden" name="sprd_item[]" id="sprd_item" value="<?php echo $stitm['item_name']; ?>" />
												<input class="srecipe_id form-control" type="hidden" name="srecipe_id[]" id="srecipe_id" value="<?php echo $stitm['recipe_id']; ?>" />
												<input class="scat_id form-control" type="hidden" name="scat_id" id="scat_id" value="<?php echo $stitm['pr_cat_id']; ?>" />
												<input class="spuom form-control" type="hidden" name="spuom[]" id="spuom" value="<?php echo $stitm['uom']; ?>" />
												<input class="syeild form-control" type="hidden" name="syeild[]" id="syeild" value="<?php echo $stitm['yeild']; ?>" />
												<input class="syeild form-control sprd_stk" type="hidden" name="sprd_stk[]" id="sprd_stk" value="<?php echo $stitm['production_stock']; ?>" />
												</td>
											</tr>
											<?php }
											$i++;
											?>
											</tbody>
										</table>
									</div>
									<?php 
									$i = 0;
									$k = 0;
									foreach($stcounters as $sctr) { 
									$out_branch = $sctr->branchname;
									?>
									<input type="hidden" name="soutlet_branch[]"  id="soutlet_branch<?php echo $i; ?>" class="form-control" readonly="readonly" value="<?php echo $sctr->branchname; ?>"/>
									<input name="sreq_id[]" id="sreq_id" type="hidden" class="form-control" value="<?php echo $sctr->request_id; ?>" readonly >
									<?php $q2 = $this->db->query("select * from user where branch_name='$out_branch'");
									$r = $q2->row_array(); ?>
									<input type="hidden" name="sdept[]" id="sdept" class="form-control" readonly="readonly" value="<?php echo $r['username']; ?>"/>
									
									<div class="col-md-1 col-sm-1 colmd1">
										<table class="table table-striped table-bordered" style="width: 145px!important;">
											<thead>
												<tr>
													<th colspan="3"><?php echo $sctr->branchname;  ?></th>
												</tr>
												<tr class="rwid">
													<th>RQty</th>
													<th>Qty</th>
													<th>IQty</th>
												</tr>
											</thead>
											<tbody>
											<?php 
												$j = 0;
												foreach($st_ord as $stitm) {
													$branch_id = $_SESSION['branch_id'];
													$uname = $_SESSION['username'];
													$iname = $stitm['item_name'];
													$r_date = date('Y-m-d',strtotime($_POST['req_date']));
													$q1 = $this->db->query("select *,(PI.required_qty-PI.recieved_qty) as item_balance_qty,P.branchname as out_branch from product_request P inner join product_request_item PI on P.request_id=PI.request_id inner join recipe R on PI.recipe_no=R.recipe_no where P.request_date='$r_date' and P.orders='Santhe' and P.status='Pending' and P.dept='$uname' and P.branchname='$out_branch' and PI.item_name='$iname' and R.branch_id='$branch_id' order by PI.f_code,PI.pr_cat_id,PI.item_name");
													if($q1->num_rows() > 0)
													{
														$rgrow = $q1->row_array();
														$req_qty = $rgrow['required_qty'];
														$recv_qty = $rgrow['recieved_qty'];
												?>
												<tr>
													<td><?php echo $rgrow['required_qty']; ?></td>
													<td>
														<input type="hidden" name="sitem_index"  id="sitem_index" class="form-control sitem_index" readonly="readonly" value="<?php echo $j; ?>"/>
														<?php if($req_qty == $recv_qty) { ?>
															<input class="sqty<?php echo $i; ?> form-control" type="hidden" name="sinward_quantity[]" id="sinward_quantity" placeholder="Qty" />
															<input class="form-control sitem_id" type="hidden" name="sreq_item_id[]" id="sreq_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="sitem_name[]" id="sitem_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="sitem_id form-control" type="hidden" name="sitem_id[]" id="sitem_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="srecipe_no form-control" type="hidden" name="srecipe_no[]" id="srecipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="spr_cat_id form-control" type="hidden" name="spr_cat_id[]" id="spr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control squantity<?php echo $i; ?>" type="hidden" name="squantity[]" id="squantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="sitem_id form-control" type="hidden" name="suom[]" id="suom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control sstk<?php echo $i; ?>" type="hidden" name="sstock[]" id="sstock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
													<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />
															<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>		
															<input class="form-control stot_basic<?php echo $i; ?>" type="hidden" name="stot_basic[]" id="stot_basic" />
														
															<input class="form-control stax_amt<?php echo $i; ?>" type="hidden" name="stax_amt[]" id="stax_amt" />
															<input class="form-control stot_price<?php echo $i; ?>" type="hidden" name="stotal_price[]" id="stotal_price" />
															<input class="form-control" type="hidden" name="sreceived_qty[]" id="sreceived_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="sgrn_balance sqty_pending<?php echo $i; ?>" type="hidden" name="sbal_item_qty[]" id="sbal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
														<?php } else { ?>
															<input class="sqty<?php echo $i; ?> form-control" type="text" name="sinward_quantity[]" id="sinward_quantity" placeholder="Qty" />
															<input class="form-control sitem_id" type="hidden" name="sreq_item_id[]" id="sreq_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="sitem_name[]" id="sitem_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="sitem_id form-control" type="hidden" name="sitem_id[]" id="sitem_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="srecipe_no form-control" type="hidden" name="srecipe_no[]" id="srecipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="spr_cat_id form-control" type="hidden" name="spr_cat_id[]" id="spr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control squantity<?php echo $i; ?>" type="hidden" name="squantity[]"  id="squantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="sitem_id form-control" type="hidden" name="suom[]" id="suom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control sstk<?php echo $i; ?>" type="hidden" name="sstock[]" id="sstock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
															<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />
															<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]"  id="sprice" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]"  id="stax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>
															
															<input class="form-control stot_basic<?php echo $i; ?>" type="hidden" name="stot_basic[]" id="stot_basic" />
															
															<input class="form-control stax_amt<?php echo $i; ?>" type="hidden" name="stax_amt[]" id="stax_amt" />
															<input class="form-control stot_price<?php echo $i; ?>" type="hidden" name="stotal_price[]"  id="stotal_price" />
															<input class="form-control" type="hidden" name="sreceived_qty[]" id="sreceived_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="sgrn_balance sqty_pending<?php echo $i; ?>" type="hidden" name="sbal_item_qty[]" id="sbal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
														<?php } ?>
													</td>
													<td><?php echo $rgrow['recieved_qty']; ?></td>
												
												</tr>
											<?php } else { ?>
												<tr class="cust_tr">
													<td>0</td>
													<td>0</td>
													<td>0</td>
												</tr>
												<input class="sqty<?php echo $i; ?> form-control" type="hidden" name="sinward_quantity[]" id="sinward_quantity" placeholder="Qty" />
												<input class="form-control sitem_id" type="hidden" name="sreq_item_id[]" id="sreq_item_id" >
												<input class="form-control" type="hidden" name="sitem_name[]" id="sitem_name" />
												<input class="sitem_id form-control" type="hidden" name="sitem_id[]" id="sitem_id">
												<input class="srecipe_no form-control" type="hidden" name="srecipe_no[]" id="srecipe_no" >
												<input class="spr_cat_id form-control" type="hidden" name="spr_cat_id[]" id="spr_cat_id" >
												<input class="form-control squantity<?php echo $i; ?>" type="hidden" name="squantity[]"  id="squantity" />
												<input class="sitem_id form-control" type="hidden" name="suom[]" id="suom" >
												<input class="form-control sstk<?php echo $i; ?>" type="hidden" name="sstock[]" id="sstock" />
												<input class="form-control sprice<?php echo $i; ?>" type="hidden" name="sprice[]" id="sprice" />
												<input class="form-control stot_basic<?php echo $i; ?>" type="hidden" name="stot_basic[]" id="stot_basic" />
												<input class="form-control stax<?php echo $i; ?>" type="hidden" name="stax[]" id="stax" />
												<input class="form-control sbasic_tax<?php echo $i; ?>" type="hidden" name="sbasic_tax[]" id="sbasic_tax" />
												<input class="form-control stax_amt<?php echo $i; ?>" type="hidden" name="stax_amt[]" id="stax_amt" />
												<input class="form-control stot_price<?php echo $i; ?>" type="hidden" name="stotal_price[]" id="stotal_price" />
												<input class="sgrn_balance<?php echo $i; ?> form-control" type="hidden" name="sreceived_qty[]" id="sreceived_qty" />
												<input class="sgrn_balance sqty_pending<?php echo $i; ?>" type="hidden" name="sbal_item_qty[]" id="sbal_item_qty" />
											<?php	} 
											$j++;
											$k++;
											} ?>
											</tbody>
										</table>
										<input class="form-control sgt<?php echo $i; ?>" type="hidden" name="sgrand_total[]" id="sgrand_total<?php echo $i; ?>" readonly />
										
									</div>
									<?php $i++;
									} ?>
									
									<div class="col-md-1 col-sm-1">
										<table class="table table-striped table-bordered" >
											<thead>
											    <tr class="cust_trv">
													<th>Iss Qty</th>
												</tr>
												<tr class="cust_tr">
													<th>Iss Qty</th>
												</tr>
											</thead>
											<tbody>
												<?php
													foreach($st_ord as $stitm) {
												?>
														<tr>
															<td>
															<input type="text" name="spr_stock[]" id="spr_stock" class="form-control spr_stock" value="0" readonly /></td>
														</tr>
													<?php
													}
												?>
											</tbody>
										</table>
										</br>
									</div>
									<input class="form-control col-md-1" type="hidden" name="sctrct" id="sctrct" value="<?php echo $i; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="sitemct" id="sitemct" value="<?php //echo $j; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="sttitemct" id="sttitemct" value="<?php echo $k; ?>" readonly />
								</div>
								
								<div class="form-actions text-right">
									<button type="reset" class="btn btn-warning mr-1">
									<i class="ft-x"></i> Cancel
								</button>
								<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit this form?')" >
									<i class="la la-check-square-o"></i> Save
								</button>
								
							</div>
								
								</form>
								<?php //} ?>
								
								<?php } else if($act->access_tab == 'Santhe Special Order') { ?>
								<?php foreach($stspl_ord as $stspl) {
									$uname=$_POST['department'];
									$q2 = $this->db->query("select * from user where username='$uname'");
									$r = $q2->row_array();
									$ubranch=$r['branch_name'];
									$fname=$r['full_name'];
									$r_date = date("Y-m-d", strtotime($_POST['req_date']));
									$branch = $stspl->branchname;
									$q2 = $this->db->query("select * from user where branch_name='$branch'");
									$r = $q2->row_array();
									$request_id = $stspl->request_id;
									$count1 = 0;
									$count2 = 0;
									$q1 = $this->db->query("select * from product_request as P,product_request_item as PI where P.request_id=PI.request_id and P.dept='$uname' and (P.request_date='$r_date') and P.request_id='$request_id'");
									$req_res = $q1->result();
									foreach($req_res as $req_row) { 
										if(($req_row->status == 'Closed'))
										{	
											$count2++;	
										}
										$count1++;
									}
								?>
								<div class="row">
									<div class="col-md-2 col-sm-2">
										<div class="form-group">
											<!--<h4><?php //echo $row3['username']; ?></h4>-->
											<input type="text" name="dept"  id="dept" class="form-control" readonly="readonly" value="<?php echo $r['username']; ?> "/>
										</div>
									</div>
									<div class="col-md-3 col-sm-3">
										<div class="form-group">
											<?php if($count1 == $count2) { ?>
											<input type="text" class="form-control" style="width:200px;" value="<?php echo $stspl->pr_req_no; ?>" disabled />
											<?php } else { ?>
											<button class="grid-form-dialog-btn btn btn-primary" style="width:200px;" onclick="javascript:load_marks(<?php echo $stspl->request_id; ?>)" ><?php echo $stspl->pr_req_no; ?></button>
											<?php } ?>
										</div>
									</div>
								</div>
								<?php
								}
								
								} else if($act->access_tab == 'Carnival Order') {
								    if(is_array($car_ord)) {
								if(isset($car_ord) && is_array($car_ord) && count($car_ord)): $i=1;
								?>
								<h4>Carnival Order On - <?php echo $_POST['req_date']; ?></h4>
								<form class="form" autocomplete="off" action="<?php echo site_url('ProductRequest/addCarnivalIssue');?>" method="post">
								<input type="hidden" name="crdate" id="crdate" value="<?php echo $_POST['req_date']; ?>" >
								<input type="hidden" name="cuname" id="cuname" value="<?php echo $_SESSION['username']; ?>" >
								<input type="hidden" name="cbranch_id" id="cbranch_id" value="<?php echo $_SESSION['branch_id']; ?>" >
								<input type="hidden" id="cbranch_name" class="form-control"  name="cbranch_name" value="<?php echo $_SESSION['branch_name'];?>">
								
								
								<div class="row club">
								   	<div class="col-md-3 col-sm-3">
										<table class="table table-striped table-bordered" >
											<thead>
											    <tr class="cust_trv" >
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
												<tr class="cust_tr">
													<th>Item Name</th>
													<th>Stock</th>
												</tr>
											</thead>
											<tbody>
											<?php
												foreach($car_ord as $citm)
												{
											?>
											<tr class="cust_tr iwid">
												<td><?php echo $citm['item_name']; ?></td>
												<td><?php echo $citm['production_stock']; ?>
												<input class="cprd_item form-control" type="hidden" name="cprd_item[]" id="cprd_item" value="<?php echo $citm['item_name']; ?>" />
												<input class="crecipe_id form-control" type="hidden" name="crecipe_id[]" id="crecipe_id" value="<?php echo $citm['recipe_id']; ?>" />
												<input class="ccat_id form-control" type="hidden" name="ccat_id" id="ccat_id" value="<?php echo $citm['pr_cat_id']; ?>" />
												<input class="cpuom form-control" type="hidden" name="cpuom[]" id="cpuom" value="<?php echo $citm['uom']; ?>" />
												<input class="cyeild form-control" type="hidden" name="cyeild[]" id="cyeild" value="<?php echo $citm['yeild']; ?>" />
												<input class="cyeild form-control cprd_stk" type="hidden" name="cprd_stk[]" id="cprd_stk" value="<?php echo $citm['production_stock']; ?>" />
												</td>
											</tr>
											<?php }
											$i++;
											?>
											<?php else: ?>
											<tr>
												<td colspan="8" align="center" >No Records Found..</td>
											</tr>
											<?php
												endif;
											?>
											</tbody>
										</table>
									</div>
									<?php 
									$i = 0;
									$k = 0;
									foreach($vkitchen as $vkt) { 
									$out_branch = $vkt->to_branch;
									$out_branchc = $vkt->branchname;
									?>
									<input type="hidden" name="coutlet_branch[]"  id="coutlet_branch<?php echo $i; ?>" class="form-control" readonly="readonly" value="<?php echo $vkt->to_branch; ?>"/>
									<input type="hidden" name="coutlet_branchid[]"  id="coutlet_branchid<?php echo $i; ?>" class="form-control" readonly="readonly" value="<?php echo $vkt->to_branchid; ?>"/>
									<input name="creq_id[]" id="creq_id" type="hidden" class="form-control" value="<?php echo $vkt->request_id; ?>" readonly >
									<?php $q2 = $this->db->query("select * from user where branch_name='$out_branch'");
									$r = $q2->row_array(); ?>
									<input type="hidden" name="cdept[]" id="cdept" class="form-control" readonly="readonly" value="<?php echo $r['username']; ?>"/>
									
									<div class="col-md-1 col-sm-1 colmd1">
										<table class="table table-striped table-bordered" style="width: 145px!important;" >
											<thead>
												<tr>
													<th colspan="3"><?php echo $vkt->branchname;  ?></th>
												</tr>
												<tr class="rwid">
													<th>RQty</th>
													<th>Qty</th>
													<th>IQty</th>
												</tr>
											</thead>
											<tbody>
											<?php 
												$j = 0;
												foreach($car_ord as $citm) {
													$branch_id = $_SESSION['branch_id'];
													$uname = $_SESSION['username'];
													$iname = $citm['item_name'];
													$r_date = date('Y-m-d',strtotime($_POST['req_date']));
													$q1 = $this->db->query("select *,(PI.required_qty-PI.recieved_qty) as item_balance_qty,P.branchname as out_branch from product_request P inner join product_request_item PI on P.request_id=PI.request_id inner join recipe R on PI.recipe_no=R.recipe_no where P.request_date='$r_date' and P.orders='Carnival Order' and P.status='Pending' and P.dept='$uname' and P.branchname='$out_branchc' and PI.item_name='$iname' and R.branch_id='$branch_id' order by PI.f_code,PI.pr_cat_id,PI.item_name");
													if($q1->num_rows() > 0)
													{
														$rgrow = $q1->row_array();
														$req_qty = $rgrow['required_qty'];
														$recv_qty = $rgrow['recieved_qty'];
												?>
												<tr class="cust_tr iwid">
													<td><?php echo $rgrow['required_qty']; ?></td>
													<td>
														<input type="hidden" name="citem_index"  id="citem_index" class="form-control citem_index" readonly="readonly" value="<?php echo $j; ?>"/>
														<?php if($req_qty == $recv_qty) { ?>
															<input class="cqty<?php echo $i; ?> form-control" type="hidden" name="cinward_quantity[]" id="cinward_quantity" placeholder="Qty" />
															<input class="form-control citem_id" type="hidden" name="creq_item_id[]" id="creq_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="citem_name[]" id="citem_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="citem_id form-control" type="hidden" name="citem_id[]" id="citem_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="crecipe_no form-control" type="hidden" name="crecipe_no[]" id="crecipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="cpr_cat_id form-control" type="hidden" name="cpr_cat_id[]" id="cpr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control cquantity<?php echo $i; ?>" type="hidden" name="cquantity[]" id="cquantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="citem_id form-control" type="hidden" name="cuom[]" id="cuom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control cstk<?php echo $i; ?>" type="hidden" name="cstock[]" id="cstock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
												<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />
															<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>			
															<input class="form-control ctot_basic<?php echo $i; ?>" type="hidden" name="ctot_basic[]" id="ctot_basic" />
															<input class="form-control ctax_amt<?php echo $i; ?>" type="hidden" name="ctax_amt[]" id="ctax_amt" />
															<input class="form-control ctot_price<?php echo $i; ?>" type="hidden" name="ctotal_price[]"  id="ctotal_price" />
															<input class="form-control" type="hidden" name="creceived_qty[]" id="creceived_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="cgrn_balance cqty_pending<?php echo $i; ?>" type="hidden" name="cbal_item_qty[]" id="cbal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
														<?php } else { ?>
															<input class="cqty<?php echo $i; ?> form-control" type="text" name="cinward_quantity[]" id="cinward_quantity" placeholder="Qty" />
															<input class="form-control citem_id" type="hidden" name="creq_item_id[]" id="creq_item_id" value="<?php echo $rgrow['request_item_id']; ?>">
															<input class="form-control" type="hidden" name="citem_name[]" id="citem_name" value="<?php echo $rgrow['item_name']; ?>" readonly />
															<input class="citem_id form-control" type="hidden" name="citem_id[]" id="citem_id" value="<?php echo $rgrow['recipe_id']; ?>">
															<input class="crecipe_no form-control" type="hidden" name="crecipe_no[]" id="crecipe_no" value="<?php echo $rgrow['recipe_no']; ?>">
															<input class="cpr_cat_id form-control" type="hidden" name="cpr_cat_id[]" id="cpr_cat_id" value="<?php echo $rgrow['pr_cat_id']; ?>">
															<input class="form-control cquantity<?php echo $i; ?>" type="hidden" name="cquantity[]"  id="cquantity" value="<?php echo $rgrow['required_qty']; ?>" readonly />
															<input class="citem_id form-control" type="hidden" name="cuom[]" id="cuom" value="<?php echo $rgrow['uom']; ?>">
															<input class="form-control cstk<?php echo $i; ?>" type="hidden" name="cstock[]" id="cstock" value="<?php echo $rgrow['production_stock']; ?>" readonly />
												<?php if($out_branch == 'CW4-CTR' || $out_branch == 'ST4') { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw4_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw4_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw4_tax_amount']; ?>" />
															<?php } else if($out_branch == 'CW5-CTR' || $out_branch == 'ST5') { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw5_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw5_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw5_tax_amount']; ?>" />
															<?php } else { ?>
															<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]"  id="cprice" value="<?php echo $rgrow['cw_price']; ?>" />
															<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]"  id="ctax" value="<?php echo $rgrow['cw_tax']; ?>" />
															<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]"  id="cbasic_tax" value="<?php echo $rgrow['cw_tax_amount']; ?>" />
															<?php } ?>			
															<input class="form-control ctot_basic<?php echo $i; ?>" type="hidden" name="ctot_basic[]" id="ctot_basic" />
															
															<input class="form-control ctax_amt<?php echo $i; ?>" type="hidden" name="ctax_amt[]" id="ctax_amt" />
															<input class="form-control ctot_price<?php echo $i; ?>" type="hidden" name="ctotal_price[]"  id="ctotal_price" />
															<input class="form-control" type="hidden" name="creceived_qty[]" id="creceived_qty" value="<?php echo $rgrow['recieved_qty']; ?>" readonly />
															<input class="cgrn_balance cqty_pending<?php echo $i; ?>" type="hidden" name="cbal_item_qty[]" id="cbal_item_qty" value="<?php echo $rgrow['item_balance_qty']; ?>" />
														<?php } ?>
													</td>
													<td><?php echo $rgrow['recieved_qty']; ?></td>
													
													
												</tr>
											<?php } else { ?>
												<tr class="cust_tr">
													<td>0</td>
													<td>0</td>
													<td>0</td>
												</tr>
												<input class="cqty<?php echo $i; ?> form-control" type="hidden" name="cinward_quantity[]" id="cinward_quantity" placeholder="Qty" />
												<input class="form-control citem_id" type="hidden" name="creq_item_id[]" id="creq_item_id" >
												<input class="form-control" type="hidden" name="citem_name[]" id="citem_name" />
												<input class="citem_id form-control" type="hidden" name="citem_id[]" id="citem_id">
												<input class="crecipe_no form-control" type="hidden" name="crecipe_no[]" id="crecipe_no" >
												<input class="cpr_cat_id form-control" type="hidden" name="cpr_cat_id[]" id="cpr_cat_id" >
												<input class="form-control cquantity<?php echo $i; ?>" type="hidden" name="cquantity[]"  id="cquantity" />
												<input class="citem_id form-control" type="hidden" name="cuom[]" id="cuom" >
												<input class="form-control cstk<?php echo $i; ?>" type="hidden" name="cstock[]" id="cstock" />
												<input class="form-control cprice<?php echo $i; ?>" type="hidden" name="cprice[]" id="cprice" />
												<input class="form-control ctot_basic<?php echo $i; ?>" type="hidden" name="ctot_basic[]" id="ctot_basic" />
												<input class="form-control ctax<?php echo $i; ?>" type="hidden" name="ctax[]" id="ctax" />
												<input class="form-control cbasic_tax<?php echo $i; ?>" type="hidden" name="cbasic_tax[]" id="cbasic_tax" />
												<input class="form-control ctax_amt<?php echo $i; ?>" type="hidden" name="ctax_amt[]" id="ctax_amt" />
												<input class="form-control ctot_price<?php echo $i; ?>" type="hidden" name="ctotal_price[]" id="ctotal_price" />
												<input class="cgrn_balance<?php echo $i; ?> form-control" type="hidden" name="creceived_qty[]" id="creceived_qty" />
												<input class="cgrn_balance cqty_pending<?php echo $i; ?>" type="hidden" name="cbal_item_qty[]" id="cbal_item_qty" />
											<?php	} 
											$j++;
											$k++;
											} ?>
											</tbody>
										</table>
										<input class="form-control cgt<?php echo $i; ?>" type="hidden" name="cgrand_total[]" id="cgrand_total<?php echo $i; ?>" readonly />
										
									</div>
									<?php $i++;
									} ?>
									
									<div class="col-md-1 col-sm-1">
										<table class="table table-striped table-bordered" >
											<thead>
											    <tr class="cust_trv">
											        <th>Iss Qty</th>
											    </tr>
												<tr class="cust_tr">
													<th>Iss Qty</th>
												</tr>
											</thead>
											<tbody>
												<?php
												foreach($car_ord as $citm)         {
												?>
														<tr>
															<td>
															<input type="text" name="cpr_stock[]" id="cpr_stock" class="form-control cpr_stock" value="0" readonly /></td>
														</tr>
													<?php
												}
												?>
											</tbody>
										</table>
										</br>
									</div>
									<input class="form-control col-md-1" type="hidden" name="cctrct" id="cctrct" value="<?php echo $i; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="citemct" id="citemct" value="<?php echo $j; ?>" readonly />
									<input class="form-control col-md-1" type="hidden" name="cttitemct" id="cttitemct" value="<?php echo $k; ?>" readonly />
								</div>
								
								<div class="form-actions text-right">
									<button type="reset" class="btn btn-warning mr-1">
									<i class="ft-x"></i> Cancel
								</button>
								<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure you want to submit this form?')">
									<i class="la la-check-square-o"></i> Save
								</button>
								
							</div>
								
								</form>
								<?php }
								
								}
								?>	
							</div>
							<?php } ?>
						</div>
							<?php //} ?>
						<?php //}
					}
				} ?>
				
						</div>
						
						
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--/ Zero configuration table -->



<!--/ Language - Comma decimal place table -->

        </div>
      </div>
    </div>
    <!-- END: Content-->

   <?php //require('include/theme_customizer.php');?>
 <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
<script>
	<?php 
		$i = 0;
		if(isset($counters)) {
		foreach($counters as $ctr) {	
	?>
	$(".qty<?php echo $i; ?>").each( function(){ $(this).on( {'keyup': function() {
		var uname = $('#uname').val();
		var j = $(this).parent().find('.item_index').val();
		if(uname == 'Savories Kitchen' || uname == 'Dry Cake Kitchen')
		{
			//alert('success');
		}
		else
		{
			var q1 = $(this).parent().find('.qty<?php echo $i; ?>').val();
			var q2 = $(this).parent().find('.qty_pending<?php echo $i; ?>').val();
			var tot_price = $(this).parent().find('.tot_price<?php echo $i; ?>').val();
			//var tot = $(".gt").eq(j).val();
			var tot = $("#grand_total<?php echo $i; ?>").val();
			var tot_amt = 0;
			var rm_stk = 0;
			
			var pr_stock = $(".pr_stock").eq(j).val();
			//alert($(this).parent().find('.qty').val()); 
			if(q1 != '')
			{
				if(parseFloat(q1) <= parseFloat(q2)){
					//alert("sucess");
				}
				else{
					alert("You cant enter more than Req balance quantity");
					tot_amt = parseFloat(tot) - parseFloat(tot_price);
					rm_stk = parseFloat(pr_stock) - parseFloat(q1);
					$(this).parent().find('.qty<?php echo $i; ?>').val('');
					$(this).parent().find('.tot_basic<?php echo $i; ?>').val('0');
					$(this).parent().find('.tax_amt<?php echo $i; ?>').val('0');
					$(this).parent().find('.tot_price<?php echo $i; ?>').val('0');
					$(".pr_stock").eq(j).val(rm_stk);
					//$(".gt").eq(j).val(tot_amt.toFixed(2));
					$("#grand_total<?php echo $i; ?>").val(tot_amt.toFixed(2));
				}
			}
		}
	}
	})
	})
	<?php 
		$i++;
	} } ?>
			
	//checking entered quantity with the current stock
	<?php 
		$i = 0;
		if(isset($counters)) {
		foreach($counters as $ctr) {	
	?>
	$('.qty<?php echo $i; ?>').change(function() {
		var j = $(this).parent().find('.item_index').val();
		//alert(i);
		var q1 = $(this).parent().find('.qty<?php echo $i; ?>').val();
		var q2 = $(this).parent().find('.qty_pending<?php echo $i; ?>').val();
		var tot_price = $(this).parent().find('.tot_price<?php echo $i; ?>').val();
		//var tot = $(".gt").eq(j).val();
		var tot = $("#grand_total<?php echo $i; ?>").val();
		var tot_amt = 0;
		var rm_stk = 0;
		
		var prd_stk = $(".prd_stk").eq(j).val();
		var pr_stock = $(".pr_stock").eq(j).val();
		var rmn_stk = parseFloat(prd_stk) - parseFloat(pr_stock);
		//alert(rmn_stk);
		if(parseFloat(pr_stock) <= parseFloat(prd_stk)){
			//alert("sucess");
		}
		else
		{
			alert("You cant enter more than the current stock");
			tot_amt = parseFloat(tot) - parseFloat(tot_price);
			rm_stk = parseFloat(pr_stock) - parseFloat(q1);
			$(this).parent().find('.qty<?php echo $i; ?>').val('');
			$(this).parent().find('.tot_basic<?php echo $i; ?>').val('0');
			$(this).parent().find('.tax_amt<?php echo $i; ?>').val('0');
			$(this).parent().find('.tot_price<?php echo $i; ?>').val('0');
			$(".pr_stock").eq(j).val(rm_stk);
			//$(".gt").eq(j).val(tot_amt.toFixed(2));
			$("#grand_total<?php echo $i; ?>").val(tot_amt.toFixed(2));
		}
	});
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($counters)) {
		foreach($counters as $ctr) {	
	?>
	$('.qty<?php echo $i; ?>').each(function() { $(this).on( {'keyup': function() {
		var qty = $(this).parent().find('.qty<?php echo $i; ?>').val();
		var price = $(this).parent().find('.price<?php echo $i; ?>').val();
		var tax = $(this).parent().find('.tax<?php echo $i; ?>').val();
		var basic_tax = $(this).parent().find('.basic_tax<?php echo $i; ?>').val();
		//alert(basic_tax);
		var tot_basic = (parseFloat(qty) * parseFloat(price)).toFixed(2);
		//var tot_tax = ((parseFloat(tot_basic) * parseFloat(tax))/100).toFixed(2);
		var tot_tax = (parseFloat(basic_tax) * parseFloat(qty)).toFixed(2);
		var total_price = (parseFloat(tot_basic) + parseFloat(tot_tax)).toFixed(2);
		//alert(total_price);
		$(this).parent().find('.tot_basic<?php echo $i; ?>').val(tot_basic);
		$(this).parent().find('.tax_amt<?php echo $i; ?>').val(tot_tax);
		$(this).parent().find('.tot_price<?php echo $i; ?>').val(total_price);
		
	}
	})
	})
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($counters)) {
		foreach($counters as $ctr) {	
	?>
	$('.qty<?php echo $i; ?>').keyup(function() {
		var sum = 0;
		$('.tot_price<?php echo $i; ?>').each(function() {
			sum += Number($(this).val());
		});
		$(this).parent().find('.gt<?php echo $i; ?>').val(sum.toFixed());
		$('#grand_total<?php echo $i; ?>').val(sum.toFixed());
	}); 
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($counters)) {
		foreach($counters as $ctr) {	
	?>
	$('.qty<?php echo $i; ?>').keyup(function() {
			var j = $(this).parent().find('.item_index').val();
			//alert(j);
			var qty = $(this).parent().find('.qty<?php echo $i; ?>').val();
			if(!($.isNumeric(qty))) //to check NaN, null, true, Infinity, undefined etc
			{
				qty = 0;
			}
			var ctrstk = 0;
			<?php 
				$k = 0;
				foreach($counters as $ctr) {
				if($k != $i) {
			?>
				var qtyct = $(".qty<?php echo $k; ?>").eq(j).val();
				//alert('.qty<?php echo $k; ?>');
				//alert(j);
				//alert(qtyct);
				if(!($.isNumeric(qtyct)))
				{
					qtyct = 0;
				}
				ctrstk = parseFloat(ctrstk) + parseFloat(qtyct);
				//alert(ctrstk);
			<?php 
				}
			$k++;
			} ?>
			var pr_stk = parseFloat(qty) + parseFloat(ctrstk);
			$(".pr_stock").eq(j).val(pr_stk);
		});
		<?php 
		$i++;
		} } ?>
</script>

<script>
	<?php 
		$i = 0;
		if(isset($stcounters)) {
		foreach($stcounters as $stctr) {	
	?>
	$(".sqty<?php echo $i; ?>").each( function(){ $(this).on( {'keyup': function() {
		var uname = $('#suname').val();
		var j = $(this).parent().find('.sitem_index').val();
		if(uname == 'Savories Kitchen' || uname == 'Dry Cake Kitchen')
		{
			//alert('success');
		}
		else
		{
			var q1 = $(this).parent().find('.sqty<?php echo $i; ?>').val();
			var q2 = $(this).parent().find('.sqty_pending<?php echo $i; ?>').val();
			var tot_price = $(this).parent().find('.stot_price<?php echo $i; ?>').val();
			//var tot = $(".gt").eq(j).val();
			var tot = $("#sgrand_total<?php echo $i; ?>").val();
			var tot_amt = 0;
			var rm_stk = 0;
			
			var pr_stock = $(".spr_stock").eq(j).val();
			//alert($(this).parent().find('.qty').val()); 
			if(q1 != '')
			{
				if(parseFloat(q1) <= parseFloat(q2)){
					//alert("sucess");
				}
				else{
					alert("You cant enter more than Req balance quantity");
					tot_amt = parseFloat(tot) - parseFloat(tot_price);
					rm_stk = parseFloat(pr_stock) - parseFloat(q1);
					$(this).parent().find('.sqty<?php echo $i; ?>').val('');
					$(this).parent().find('.stot_basic<?php echo $i; ?>').val('0');
					$(this).parent().find('.stax_amt<?php echo $i; ?>').val('0');
					$(this).parent().find('.stot_price<?php echo $i; ?>').val('0');
					$(".spr_stock").eq(j).val(rm_stk);
					//$(".gt").eq(j).val(tot_amt.toFixed(2));
					$("#sgrand_total<?php echo $i; ?>").val(tot_amt.toFixed(2));
				}
			}
		}
	}
	})
	})
	<?php 
		$i++;
	} } ?>
			
	//checking entered quantity with the current stock
	<?php 
		$i = 0;
		if(isset($stcounters)) {
		foreach($stcounters as $stctr) {	
	?>
	$('.sqty<?php echo $i; ?>').change(function() {
		var j = $(this).parent().find('.sitem_index').val();
		//alert(i);
		var q1 = $(this).parent().find('.sqty<?php echo $i; ?>').val();
		var q2 = $(this).parent().find('.sqty_pending<?php echo $i; ?>').val();
		var tot_price = $(this).parent().find('.stot_price<?php echo $i; ?>').val();
		//var tot = $(".gt").eq(j).val();
		var tot = $("#sgrand_total<?php echo $i; ?>").val();
		var tot_amt = 0;
		var rm_stk = 0;
		
		var prd_stk = $(".sprd_stk").eq(j).val();
		var pr_stock = $(".spr_stock").eq(j).val();
		var rmn_stk = parseFloat(prd_stk) - parseFloat(pr_stock);
		//alert(rmn_stk);
		if(parseFloat(pr_stock) <= parseFloat(prd_stk)){
			//alert("sucess");
		}
		else
		{
			alert("You cant enter more than the current stock");
			tot_amt = parseFloat(tot) - parseFloat(tot_price);
			rm_stk = parseFloat(pr_stock) - parseFloat(q1);
			$(this).parent().find('.sqty<?php echo $i; ?>').val('');
			$(this).parent().find('.stot_basic<?php echo $i; ?>').val('0');
			$(this).parent().find('.stax_amt<?php echo $i; ?>').val('0');
			$(this).parent().find('.stot_price<?php echo $i; ?>').val('0');
			$(".spr_stock").eq(j).val(rm_stk);
			//$(".gt").eq(j).val(tot_amt.toFixed(2));
			$("#sgrand_total<?php echo $i; ?>").val(tot_amt.toFixed(2));
		}
	});
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($stcounters)) {
		foreach($stcounters as $stctr) {	
	?>
	$('.sqty<?php echo $i; ?>').each(function() { $(this).on( {'keyup': function() {
		var qty = $(this).parent().find('.sqty<?php echo $i; ?>').val();
		var price = $(this).parent().find('.sprice<?php echo $i; ?>').val();
		var tax = $(this).parent().find('.stax<?php echo $i; ?>').val();
		var basic_tax = $(this).parent().find('.sbasic_tax<?php echo $i; ?>').val();
		//alert(basic_tax);
		var tot_basic = (parseFloat(qty) * parseFloat(price)).toFixed(2);
		//var tot_tax = ((parseFloat(tot_basic) * parseFloat(tax))/100).toFixed(2);
		var tot_tax = (parseFloat(basic_tax) * parseFloat(qty)).toFixed(2);
		var total_price = (parseFloat(tot_basic) + parseFloat(tot_tax)).toFixed(2);
		//alert(total_price);
		$(this).parent().find('.stot_basic<?php echo $i; ?>').val(tot_basic);
		$(this).parent().find('.stax_amt<?php echo $i; ?>').val(tot_tax);
		$(this).parent().find('.stot_price<?php echo $i; ?>').val(total_price);
		
	}
	})
	})
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($stcounters)) {
		foreach($stcounters as $stctr) {	
	?>
	$('.sqty<?php echo $i; ?>').keyup(function() {
		var sum = 0;
		$('.stot_price<?php echo $i; ?>').each(function() {
			sum += Number($(this).val());
		});
		$(this).parent().find('.sgt<?php echo $i; ?>').val(sum.toFixed());
		$('#sgrand_total<?php echo $i; ?>').val(sum.toFixed());
	}); 
	<?php 
		$i++;
	} } ?>
	
	<?php 
		$i = 0;
		if(isset($stcounters)) {
		foreach($stcounters as $stctr) {	
	?>
	$('.sqty<?php echo $i; ?>').keyup(function() {
			var j = $(this).parent().find('.sitem_index').val();
			//alert(j);
			var qty = $(this).parent().find('.sqty<?php echo $i; ?>').val();
			if(!($.isNumeric(qty))) //to check NaN, null, true, Infinity, undefined etc
			{
				qty = 0;
			}
			var ctrstk = 0;
			<?php 
				$k = 0;
				foreach($stcounters as $stctr) {
				if($k != $i) {
			?>
				var qtyct = $(".sqty<?php echo $k; ?>").eq(j).val();
				//alert('.qty<?php echo $k; ?>');
				//alert(j);
				//alert(qtyct);
				if(!($.isNumeric(qtyct)))
				{
					qtyct = 0;
				}
				ctrstk = parseFloat(ctrstk) + parseFloat(qtyct);
				//alert(ctrstk);
			<?php 
				}
			$k++;
			} ?>
			var pr_stk = parseFloat(qty) + parseFloat(ctrstk);
			$(".spr_stock").eq(j).val(pr_stk);
		});
		<?php 
		$i++;
		} } ?>
</script>

<script>
function load_marks(req_id)
{
  $.ajax({
      type: "POST",
      url: "<?php echo site_url('ProductRequest/splKitOrder');?>",
      data: "req_id="+req_id,
      success: function (response) {
        // alert(response);
        $(".grid-form-dialog").html(response);
        }
     });
  }
</script>
<div class="grid-form-dialog" id="" title="Special Order Issue">
<?php //include('spl_order.php'); ?>
</div>
  </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>