break;
                 case 'avg_grossprofit_pct_ge':
                     $filter_grossprofit_pct_ge = $fval;
                     break;
                 case 'avg_grossprofit_pct_ge':
                     $filter_grossprofit_pct_le = $fval;
                     break;
             }
         }
     }
 }
 $products_total = count($products);
 if ($products_total == 0) {
     $search_result = '<h3 class="red">No Products/Articles Found</h3>';
 } else {
     $summaries = ReportCOGS::retrieveSummaryByProducts($products, $jng_sp_id, $start_date, $end_date, implode(' AND ', $filters), implode(' AND ', $havings), implode(',', $sorting));
     //need to make sure that all filtered product from products analysis are included even if no report_cogs data is found for the product
     //for that we will loop the products var (from pids) instead of summaries var. But we still need to maintain the order from summaries.
     //so we created a new var products_sorted to manage it. First add all pids from summaries in the same order
     $products_sorted = array_keys($summaries);
     //then loop the products array to add pids which are not queried in summaries
     foreach ($products as $pid) {
         if (!in_array($pid, $products_sorted)) {
             $products_sorted[] = $pid;
         }
     }
     $header = array();
     $header['img tac'] = 'Product';
     $header['i w100 tac'] = 'Info';
     $header['a w080 tac'] = 'Pieces Sold';
     $header['b w150 tac'] = 'Net Sales';
 }
 */
 //TRY SWITCHING TO REPORT COGS TABLE
 if ($spid == 0) {
     $sp_detail = array('package_prefix' => 'JG.DE');
 } else {
     $sp_detail = $class_sp->retrieveDetail($spid);
 }
 if (!is_array($products)) {
     $products = explode(',', $products);
 }
 $ajaxResult = array();
 $ajaxResult['period'] = 'p-' . $period;
 $ajaxResult['period_text'] = $sp_detail['package_prefix'] . '<br />' . substr($period_start_raw, 0, 5) . ' - ' . substr($period_end_raw, 0, 5);
 if ($level == 'p') {
     $cogs_result = ReportCOGS::retrieveSummaryByProducts($products, $spid, $period_start, $period_end);
     foreach ($products as $pid) {
         $ajaxResult['row-' . $pid] = intval($cogs_result[$pid]['total_quantity']);
     }
 } else {
     $cogs_result = ReportCOGS::retrieveSummaryByArticles($products, $spid, $period_start, $period_end);
     $palist = $class_pa->retrieveAllArticlesByProducts($products);
     foreach ($palist as $pid => $pdata) {
         $row_content = '<table align="center" border="0"' . ' cellpadding="0" cellspacing="0">';
         foreach ($pdata as $aid => $adata) {
             if ($level == 'l') {
                 $left = $adata['length'] == 0 ? '<span class="notice">None</span>' : textLength($adata['length']);
             } else {
                 $left = $adata['ean'];
             }
             $row_content .= '<tr><td>' . $left . '</td><td>=</td><td>' . intval($cogs_result[$adata['ean']]['total_quantity']) . '</td></tr>';
         list($year, $week) = explode('-', $week_end);
         $temp_date = getStartAndEndDate($week, $year);
         $report_date_end = $temp_date['end_date'];
         //Validate week filter input
         if (strtotime($report_date_end) < strtotime($report_date_start)) {
             echo utf8_encode('Invalid week range input');
             exit;
         }
         $week_date_start = $report_date_start;
         $week_date_end = date('Y-m-d', strtotime($report_date_start . " + 6 days"));
         $row = 0;
         while (strtotime($week_date_end) <= strtotime($report_date_end)) {
             //echo("$week_date_start | $week_date_end<br/>");
             $row++;
             $week_number = date('W', strtotime($week_date_start));
             $prod_summary = ReportCOGS::retrieveSummaryByProducts($products_id, $spid, $week_date_start, $week_date_end);
             $week_sold = isset($prod_summary[$products_id]['total_quantity_sold']) ? $prod_summary[$products_id]['total_quantity_sold'] : 0;
             $row_class = $row > 0 && $row % 2 == 0 ? 'e' : 'o';
             $info = '<span class="ui-icon ui-icon-info help float-right" title="' . date('d-m-Y', strtotime($week_date_start)) . ' to ' . date('d-m-Y', strtotime($week_date_end)) . '" />';
             $result .= '<div class="tac ' . $row_class . '" style="margin-top:3px;">Week ' . $week_number . ": " . $week_sold . $info . '</div>';
             $week_date_start = date('Y-m-d', strtotime($week_date_end . " + 1 days"));
             $week_date_end = date('Y-m-d', strtotime($week_date_start . " + 6 days"));
         }
     } else {
         $result .= " <br/><br/>{$not_available_text}";
     }
     $result .= ' </div>';
 } else {
     $result .= "Product {$products_id} not found";
 }
 $result .= '</div>';