<?php 

$this->load->view('master/common/header.php',$data);
$base_name = $data['base_name'];
?>

    <div class="content">
        
        <!-- Start Content-->
        <div class="container-fluid">
            
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box">
                        <div class="page-title-right">
                            <ol class="breadcrumb m-0">
                                <li class="breadcrumb-item"><a href="javascript: void(0);"><?= $base_name;?></a></li>
                                <li class="breadcrumb-item active text-capitalize"><?= $page;?></li>
                            </ol>
                        </div>
                        <h4 class="page-title text-uppercase"><?= $page;?></h4>
                    </div>
                </div>
            </div>     
            <!-- end page title --> 

            <div class="row">
                <div class="col-md-12 col-xl-12">
                    <div class="card-box">
                        <div class="row">
                            <div class="col-sm-12">
							<form method="POST" action="<?=base_url('master/product_stock/all');?>">
							    <table  class="table">
							<tbody>
    						<tr>
    						    <td>Action : </td>
								<td class="text-right">
								    <input type="submit" class="btn btn-success" value="Update All" />
								</td>
							</tr>
							</tbody>
							</table>
							    <table id="datatable" class="table table-bordered table-responsive">
                                    <thead>
                                        <tr>
            								<th>S.No.</th>
            								<th>Product Name</th>
            								<th> Size</th>
            								<th>Product  Old Price</th>
            								<th>Product  Current Price</th>
            								<th>Product PV</th>
            								<th>Product Stock</th>
            								<th>Product Min. Stock</th>
            								<th>Action</th>
                                        </tr>
                                    </thead>


                                        <tbody>
                                        
						<?php 
						$i = 0;
						
						$product = $this->db->query("select * From tbl_product where p_is_active=1");
						$product = $product->result_array();
						if (!empty(count($product))) {
						    foreach ($product as $row) {
						        
                                $p_id = $row['p_id'];
                                $p_name = $row['p_name'];
                                $tcat_id = $row['tcat_id'];
                                $mcat_id = $row['mcat_id'];
                                $ecat_id = $row['ecat_id'];
                                
						$product_size = $this->db->query("select * From tbl_product_size where p_id=$p_id");
						$product_size = $product_size->result_array();
						
						
                                if (!empty($product_size)) {
                                    foreach ($product_size as $row2) {
						                         
                                    $size_id = $row2['size_id'];
                                    $p_old_price = $row2['p_old_price'];
                                    $p_current_price = $row2['p_current_price'];
                                    $p_pv = $row2['p_pv'];
                                    $p_qty = $row2['p_qty'];
                                    $p_min_qty = $row2['p_min_qty'];
                                    
                                    if (!empty($size)) {
                                    foreach ($size as $row3) {
                                        if($size_id == $row3['size_id']){
                                             $size_name = $row3['size_name'];
                                        }
                                    }
                                    }
                                    $i++;
                                    ?>
                                    <tr>
                                    <td><?= $i;?></td>
                                    <td><?= $p_name;?></td>
                                    <td><?= $size_name;?></td>
                                    <td>
                                        <b>
                                        <input type="hidden" name="p_id[]" class="form-control" value="<?=$row2['p_id'];?>" />
                                        <input type="hidden" name="row_id[]" class="form-control" value="<?=$row2['id'];?>" />
                                        <input type="number"  min="0"  name="p_old_price[]" class="form-control" value="<?=$p_old_price;?>" />
                                        </b>
                                    </td>
                                    <td>
                                        <b><input type="number"  min="0" name="p_current_price[]" class="form-control" value="<?=$p_current_price;?>" /></b>
                                    </td>
                                    <td>
                                        <b><input type="number"  min="0" step=".10" name="p_pv[]" class="form-control" value="<?=$p_pv;?>" /></b>
                                    </td>
                                    <td>
                                        <b><input type="number"  min="0" name="p_qty[]" class="form-control" value="<?=$p_qty;?>" /></b>
                                    </td>
                                    <td>
                                        <b><input type="number"  min="0" name="p_min_qty[]" class="form-control" value="<?=$p_min_qty;?>" /></b>
                                    </td>
                                    <td><a href="<?=base_url('master/product_stock/edit/'.$row2['id']);?>" class="btn btn-sm btn-success">Edit</a></td>
                                    </tr>
                                    <?php
                                    }
                                }
						           
						    }
						    
						} else {
						    ?>
							<tr>
								<td colspan="9" class="text-center">Records Not Found</td>
							</tr>
						<?php
						    }
						?>
							</tbody>
							</table>
							
							</form>
							</div>
					    </div>
					</div>
				</div>
				<!-- /.col-md-6 -->
			</div>
			<!-- /.row -->
		</div>
		<!-- /.container-fluid -->
	</div>
	<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php $this->load->view('master/common/footer.php'); ?>
<script>$("#datatable").DataTable();</script>