<?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">
							    <table id="key-table" class="table table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                                    <thead>
                                        <tr>
            								<th>S.No.</th>
            								<th>Product Name</th>
            								<th>Top Cat</th>
            								<th>Mid Cat</th>
            								<th>End Cat</th>
            								<th>Product Size</th>
            								<th>Product Stock</th>
            								<th>Product Min. Stock</th>
            								<th>Action</th>
                                        </tr>
                                    </thead>


                                        <tbody>
                                        
						<?php 
						$i = 0;
						
						if (!empty(count($product))) {
						    foreach ($product as $row) {
						        
                                $p_name = $row['p_name'];
                                $tcat_id = $row['tcat_id'];
                                $mcat_id = $row['mcat_id'];
                                $ecat_id = $row['ecat_id'];
                                
						            if (!empty($product_size)) {
						                foreach ($product_size as $row2) {
						                     if($row['p_id'] == $row2['p_id'] && $row2['p_qty'] <= $row2['p_min_qty']){
						                         
                                                    $size_id = $row2['size_id'];
                                                    $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><?php
            						                    $querys11 = $this->db->query("SELECT * FROM tbl_top_category where  tcat_id='$tcat_id'");
                                                        $rows11 = $querys11->row();
                                                        echo $rows11->tcat_name;
            						                    ?></td>
            						                    
            						                    <td><?php
            						                    $querys11 = $this->db->query("SELECT * FROM tbl_mid_category where  mcat_id='$mcat_id'");
                                                        $rows11 = $querys11->row();
                                                        echo $rows11->mcat_name;
            						                    ?></td>
            						                    
            						                     <td><?php
            						                    $querys11 = $this->db->query("SELECT * FROM tbl_end_category where  ecat_id='$ecat_id'");
                                                        $rows11 = $querys11->row();
                                                        echo $rows11->ecat_name;
            						                    ?></td>
            						                    
            						                  
            						                    <td><?= $size_name;?></td>
            						                    <td><?= $p_qty;?></td>
            						                    <td><?= $p_min_qty;?></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="6" class="text-center">Records Not Found</td>
							</tr>
						<?php
						    }
						?>
							</tbody>
							</table>
							</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'); ?>