$alternate_main_image_key = null;
 $x = 0;
 while ($row = tep_db_fetch_array($extra_images_query)) {
     $extra_images[$x] = $row;
     if ($row['alternate_main_image'] == 1) {
         $add_have_set_to_default = true;
         $alternate_main_image_key = $x;
     }
     $x++;
 }
 $depot_stock = $class_pm->stockRetrieve(WAREHOUSE_ID_FOR_HANDLING_ORDERS, $products_id, '*');
 $depot_refill = $class_do->refillOpenOrdersQuantity(SEGMENT_ID_DEFAULT, $products_id, '*');
 $elements_status_raw = true;
 $elements_usage = $class_pm->retrieveElementsUsage($products_id);
 if (count($elements_usage) > 0) {
     $elements_stock = $class_es->retrieveList(WAREHOUSE_ID_ELEMENTS, 'elements_id IN (' . implode(',', array_keys($elements_usage)) . ')');
     foreach ($elements_usage as $eid => $eu) {
         if ($eu['quantity'] > $elements_stock[$eid]) {
             $elements_status_raw = false;
             break;
         }
     }
 } else {
     $elements_status_raw = '<span class="green" title="No Element used Found for this product">NEF</span>';
 }
 $elements_status = is_bool($elements_status_raw) ? '<span class="' . ($elements_status_raw ? 'green">OK</span>' : 'red">NS') . '</span>' : $elements_status_raw;
 $products_agegroup_options = $class_pm->productAgeGroupName();
 $products_brand = $products['products_brand_id'] > 0 ? $class_pb->retrieveDetail($products['products_brand_id']) : '';
 $date_added = date('Y-m-d', strtotime($products['products_date_added']));
 $date_added_time = date('H:i:s', strtotime($products['products_date_added']));
 $last_modified = date('Y-m-d', strtotime($products['products_last_modified']));
}
if (isset($_GET['sourcing-overview']) && $_GET['sourcing-overview'] == 'true') {
    use_class('element');
    use_class('elements_stock');
    $class_es = new elements_stock();
    //$overview  = '<h1>Sourcing Overview for Preorder: '.$preorder->name.'</h1>'; //todo: change below version to this version for live
    $overview = '<h1>Sourcing Overview: ' . $preorder->name . '</h1>';
    $overview .= '<div style="margin:20px 0">Pre-Produce Products will be created as normal Depot Orders and will be using normal PO suggestion. Only On Demand Products needs extra Sourcing process, please use the "Create Sourcing PO" button below the products list in Preorder Detail. You can only use this button after the Preorder is confirmed (no more change can be made to Preorder).</div>';
    //LIST FOR PRE PRODUCE PRODUCTS
    $elements_needed = $preorder->getElemetnsNeededForPreProduce();
    $elements_id = array_keys($elements_needed);
    $elements = array();
    foreach ($elements_id as $eid) {
        $elements[$eid] = new element($eid);
    }
    $elements_stock = $class_es->retrieveList(WAREHOUSE_ID_ELEMENTS, 'elements_id IN (' . implode(',', $elements_id) . ')');
    $overview .= '<div style="width:400px;float:left;">';
    $overview .= '<h3 style="margin:0;">Pre-Produce Products</h3>';
    $overview .= '<table border="0" cellpadding="5" cellspacing="0">';
    $overview .= '<tr>';
    $overview .= '<th>Element</th>';
    $overview .= '<th>Element ID</th>';
    $overview .= '<th>On Stock</th>';
    $overview .= '<th>Qty Needed</th>';
    $overview .= '</tr>';
    foreach ($elements_needed as $eid => $qty) {
        $overview .= '<tr>';
        $overview .= '<td>' . webImage($elements[$eid]->image, IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, 'Element ' . $eid, '', 'style="border:1px solid #ccc;"') . '</td>';
        $overview .= '<td><h3>' . $eid . '</h3></td>';
        $overview .= '<td><h3>' . $elements_stock[$eid] . '</h3></td>';
        $overview .= '<td><h3>' . $qty . '</h3></td>';