<?php
  $page_title = 'Sales Plans';
  require_once('includes/load.php');
  // Checkin What level user has permission to view this page
   page_require_level(2);
  $products = join_salesplan_table();
  //print_r($products);die();
  
  if(isset($_GET['excel'])) {

    $results=join_product_table_excel();

    $tasks = array();
    while( $rows = mysqli_fetch_assoc($results) ) {
    $tasks[] = $rows;
    }

    $filename = "IMS_Product_export_".date('Ymd') . ".xls";
        header("Content-Type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=\"$filename\"");
    ExportFile($tasks);
    //print_r($tasks);
    //echo "yes";die();

  }

  if(isset($_POST['planid'])) {

    $req_fields = array('planid' );
   validate_fields($req_fields);
   if(empty($errors)){
    $planids=$_POST['planid'];
    $products = join_salesplan_table_plan($planids);

   } else {
    $session->msg('d',' Sorry unable to find a valid Plan!');
    redirect('choosesalesplan.php', false);
  }

  } else {
    $session->msg('d',' Sorry unable to find a valid Plan!');
    redirect('choosesalesplan.php', false);
  }

?>
<?php include_once('layouts/header.php'); ?>
  <div class="row">
     <div class="col-md-12">
       <?php echo display_msg($msg); ?>
     </div>
    <div class="col-md-12">
      <div class="panel panel-default">
        <div class="panel-heading clearfix">
         <!--<div class="pull-right">
		   <a href="product.php?excel=1" class="btn btn-primary">Export</a>
           <a href="Product_Add.php" class="btn btn-primary">Add New</a>
         </div>--->
        </div>
        <div class="panel-body">
          <table id="salesplantable" class="table table-bordered table-striped table-hover">
            <thead>
              <tr>
              <th class="text-center" style="width: 10%;">#</th>
                <th class="text-center" style="width: 50px;">Plan Number</th>
                <th class="text-center" style="width: 50px;"> Plan Name </th>
                <!--<th class="text-center" style="width: 10%;"> SBU </th>--->
                <th class="text-center" style="width: 10%;"> Article </th>
                <th class="text-center" style="width: 10%;"> Category </th>
                <th class="text-center" style="width: 10%;"> Colour </th>
                <th class="text-center" style="width: 10%;"> Size </th>
                <th class="text-center" style="width: 10%;"> Initial Plan </th>
                <th class="text-center" style="width: 10%;"> Pair Per Case </th>
                <th class="text-center" style="width: 10%;"> SAPCode </th>
                <!--<th class="text-center" style="width: 100px;"> Actions </th>-->
              </tr>
            </thead>
            <tbody>
              <?php foreach ($products as $product):?>
              <tr>
                <td class="text-center"><?php echo count_id();?></td>
                <!--<td>
                  <?php //if($product['media_id'] === '0'): ?>
                    <img class="img-avatar img-circle" src="uploads/products/no_image.png" alt="">
                  <?php //else: ?>
                  <img class="img-avatar img-circle" src="uploads/products/<?php //echo $product['image']; ?>" alt="">
                <?php //endif; ?>
                </td>-->
                <td class="text-center"> <?php echo remove_junk($product['PlanNumber']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['PlanName']); ?></td>
                <!--<td class="text-center"> <?php //echo remove_junk($product['UnitName']); ?></td>-->
                <td class="text-center"> <?php echo remove_junk($product['ArticleName']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['CategoryName']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['ColorName']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['SizeAssortment']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['CaseCount']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['PairCount']); ?></td>
                <td class="text-center"> <?php echo remove_junk($product['SAPCode']); ?></td>
                <!--<td class="text-center">
                  <div class="btn-group">
                    <a href="edit_product.php?ProductId=<?php echo (int)$product['ProductId'];?>" class="btn btn-info btn-xs"  title="Edit" data-toggle="tooltip">
                      <span class="glyphicon glyphicon-edit"></span>
                    </a>
                    <a href="delete_product.php?id=<?php echo (int)$product['ProductId'];?>" class="btn btn-danger btn-xs"  title="Delete" data-toggle="tooltip">
                      <span class="glyphicon glyphicon-trash"></span>
                    </a>
                  </div>
                </td>-->
              </tr>
             <?php endforeach; ?>
            </tbody>
          </tabel>
        </div>
      </div>
    </div>
  </div>
  <?php include_once('layouts/footer.php'); ?>
