<!-- Content Wrapper. Contains page content -->

  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header mb_6">
      <h1>Items</h1>
    </section>
    <?php
   	if(!empty($_SESSION['USERS_DATA']) && $_SESSION['USERS_DATA']['userType'] ==1){ ?>
    <section class="content-header">
        <div class="wholeSaleSearch_wrap">
            <form id="" class="wholesalerName" method="post" action="dashboard/items_master/">
              <div class="d_inline_flex searchField">
                     <label> Wholesaler name </label>
                    <select name="wholesaler_a" class="wholesaler_a form-control select2_wholesaler">
                        <option></option>
                     <?php
                      if(!empty($wholesaler)){
                          foreach($wholesaler as $value){
                            ?>
                            <option <?php if(!empty($userId) && $userId==$value['userId']){ echo "selected";} ?> value="<?php echo $value['userId']?>"> <?php echo $value['userName']?></option>
                            <?php
                          }
                      }
                      ?>
                    </select>
                    <input type="submit" value="search" class="btn btn-primary" />
              </div>
            </form>
         </div>
    </section>
    <?php } ?>
    <!-- Main content -->
    <section class="content">
        <?php if(!empty($userId)) { ?>
		<div class="row">			
			<div class="col-lg-12 pad <?php if($_SESSION['USERS_DATA']['userType'] ==1){ echo 'wholesalerinfo';}?>">
			<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddItem" id="ItemCreateItemBtn" data-backdrop="static" data-keyboard="false"> 
					Add Item
			</button>
			</div>
		</div>
		
		<div class="modal fade" id="AddItem">
          <div class="modal-dialog modal-lg">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close mfwPopUpClose" data-dismiss="modal" aria-label="Close">
                  <i class="fa fa-remove" class="remover"></i></button>
                <h4 class="modal-title">Item Details</h4>
              </div>
              <div class="modal-body"> 
						<form role="form" id="mfwItemFormId" data-target="dashboard/create_item">
						  <div class="box-body padder0">
						
							<div class="row">
								<div class="col-md-6"> 							
									<div class="form-group">
									  <label for="ItemName">Item Name</label>
									  <input type ="hidden" id="farm_action" value="dashboard/create_item">
									  <input type="text" class="form-control" id="ItemName" name="ItemName" placeholder="Item Name" required autocomplete="off">
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
    									  <label for="ItemImage">Item Image</label>
    									  <div class="priview_thumb">
        									  <input class="form-control" type="file" id="ItemImage" name="ItemImage" autocomplete="off">
        									  <div id="ItemImageDiv">
        									  </div> 
        								</div> 
									</div>
								</div> 
							</div>
							<div class="row">
							    <div class="col-md-6">
									<div class="form-group">
									  <label for="ItemWeight">Weight</label>
									  <input type="text" class="form-control" id="ItemWeight" name="ItemWeight" placeholder="Weight" autocomplete="off">
									</div>
								</div>
								
								<div class="col-md-6">
									<div class="form-group">
										<label for="stock_unit">Quantity Unit</label>
										<select class="form-control select2" id="stock_unit" name="stock_unit"> 
										 <option value disabled selected>Select Quantity Unit</option>
										 <?php
										 foreach($item_unit as $itemkey){
										     $item_name = $itemkey['unitName'];
										     echo"<option value='$item_name'>$item_name</option>";
										 }
										 ?>
										</select>
									</div>
								</div>
                                
							</div> 
							<div class="row">
							    <div class="col-md-6">
									<div class="form-group">
									  <label for="ItemMinStock">Stock</label>
									  <input type="text" class="form-control" id="ItemMinStock" name="ItemMinStock" placeholder="Stock" autocomplete="off">
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
									  <label for="retailRate">Offer Price</label>
									  <input type="text" class="form-control" id="retailRate" name="retailRate" placeholder="Offer Price" autocomplete="off"> 
									</div>
								</div>
								
								
							</div>
							<div class="row">
							    <div class="col-md-6">
									<div class="form-group">
										<label>Category</label>
										<select class="form-control select2" id="categoryId" name="categoryId"> 
										 <option value disabled selected>Select Category Name</option>
										 <?php
										 if($categories){
    										 foreach($categories as $catvalue){
    										   ?>
    										   <option value="<?php echo $catvalue['catId'] ;?>" ><?php echo $catvalue['catName'];?></option>
    										   <?php
    										 }
										 }
										 ?>
										 
										</select>
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
									  <label for="retaiMrplRate">MRP</label>
									  <input type="text" class="form-control" id="retaiMrplRate" name="retaiMrplRate" placeholder="Retail MRP" autocomplete="off"> 
									</div>
								</div>
							</div>
							 
						  </div>
						  <!-- /.box-body -->
                          <input type="hidden" id="wholesalerId" value="<?php echo $userId ;?>" name="wholesalerId"> 
						  <div class="box-footer text-center">
						  <input type="hidden" id="ItemUpdateId" name="ItemUpdateId">
							<button type="submit" class="btn btn-primary" id="CreateItem">Submit</button>
						  </div>
						  
						</form>  

              </div> 
              
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
	<div class="row">
	<div class="col-lg-12">
		<div class="box wholeSaleWrapper">
            <div class="box-body">
			<div class="table-responsive">
              <table id="mfw_ItemsTable" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Sr No.</th>
                  <th>Image</th>
                  <th>Item Name</th>
                  <th>Category</th>
                  <th>Offer Price</th>
                  <th>MRP</th>
                  <th>Stock</th>
                  <th>Weight</th>
                  <th>Stock Unit</th>
                  <?php
                  if(!empty($_SESSION['USERS_DATA']) && $_SESSION['USERS_DATA']['userType'] !=1){ ?>
                  <th>Action</th>
                   <?php }?>
                </tr>
                </thead>
                <tbody>
				<?php 
				if(!empty($allitems)){
					$countItem = count($allitems);
					 $i = $countItem;
					 $a=1;
					foreach($allitems as $item){ 
				?>
                <tr>
                  <td><?php echo $a; ?></td>
					<td><?php 
						if(isset($item['image']) && !empty($item['image'])){
							$ItemImage = base_url().'assets/uploads/'.$item['image'];
							echo '<img src="'.$ItemImage.'" class="img_thumb" alt="Image">';
						} 
					?></td>
					<td><?php if(!empty($item['subCatName'])){echo $item['subCatName']; }?></td>
					<td><?php if(!empty($item['catName'])){ echo $item['catName']; } ?></td>
				
					<td><?php echo $item['rate']; ?></td>
					<td><?php if(!empty($item['itemMrp'])){echo $item['itemMrp'];} ?></td>
					<td><?php echo $item['stockQnt']; ?></td>
					<td><?php echo $item['itemStockWeight']; ?></td>
					<td><?php echo $item['qntUnit']; ?></td>
					<?php
                  if(!empty($_SESSION['USERS_DATA']) && $_SESSION['USERS_DATA']['userType'] !=1){ ?>
					<td><button class="btn-primary icon_btn item_edit_btn" data-id="<?php echo $item['subCatId']; ?>" title="Edit"><i class="fa fa-pencil-square-o"></i></button>
					<button class="btn-danger icon_btn item_delete_btn" data-id="<?php echo $item['subCatId']; ?>" title="Delete"><i class="fa fa-trash-o"></i></button>
					</td> 
					<? }?>
                </tr>
				<?php 
				$a++;
				$i--;
				}
				} ?> 
                </tbody>
                <tfoot> 
                <tr>
                  <th>Sr No.</th>
                  <th>Image</th>
                  <th>Item Name</th>
                  <th>Category</th>
                  <th>Offer Price</th>
                  <th>MRP</th>
                  <th>Stock</th>
                  <th>Weight</th>
                  <th>Stock Unit</th>
                  <?php
                  if(!empty($_SESSION['USERS_DATA']) && $_SESSION['USERS_DATA']['userType'] !=1){ ?>
                  <th>Action</th>
                  <? } ?>
                </tr>
                </tfoot> 
              </table>
            </div>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
		</div>
		</div>
    <?php } ?>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  