if ($sort_option == 'msws') {
    $header['ws'] = 'Weekly Sold';
}
$header['pri3'] = 'DIOH';
$header['pri2'] = 'Total';
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'LOADROW') {
        $id = tep_db_prepare_input($_POST['grabid']);
        $row_class = tep_db_prepare_input($_POST['row_class']);
        $detail = new element($id);
        if (is_null($detail->id)) {
            $row = 'FAILED';
        } else {
            $id = $detail->id;
            $stock_data = $class_es->retrieveOne($whid, $id);
            if ($stock_data['pieces_per_qty_type'] == 0) {
                $stock_text = '<a href="?open=elements-suppliers&amp;id=' . $id . '&amp;hidemenu=true" class="view_webpage red" title="Manage Supplier Data">UNSET Qty/Piece</a>';
            } else {
                $stock = $stock_data['stock'] / $stock_data['pieces_per_qty_type'];
                $stock_text = $stock - floor($stock) == 0 ? $stock : number_format($stock, 1, ',', '');
                $stock_text .= ' ' . $stock_data['qty_type'];
                $stock_text = '<a href="?open=elements-stock-update&amp;id=' . $id . '&amp;hidemenu=true" class="view_webpage" title="Update Stock">' . $stock_text . '</a>';
                if ($stock_data['pieces_per_qty_type'] > 1 && $stock_data['stock'] > 0) {
                    $piece_qty_type = $stock_data['qty_type'] == 'meter' ? ' cm' : ' pieces';
                    $stock_text .= '<br /><span class="notice">(' . $stock_data['stock'] . $piece_qty_type . ')</span>';
                }
            }
            $stock_price = $stock_data['stock'] * $detail->detail['price'];
            $img = webImage($detail->image, '80', '80', $id);
            $name = $detail->detail['name'];
     echo utf8_encode('OK');
     exit;
 } elseif ($_POST['me_action'] == 'LOADROWEPO-STEP1') {
     $eid = tep_db_prepare_input($_POST['eid']);
     $qty = tep_db_prepare_input($_POST['qty']);
     $row = tep_db_prepare_input($_POST['row_class']);
     $firstadd = $_POST['firstadd'];
     $element = new element($eid);
     $element->getSuppliers();
     $suppliers_id = null;
     foreach ($element->suppliers as $es) {
         if ($es['is_default'] == '1') {
             $suppliers_id = $es['etes_id'];
         }
     }
     $stock = $class_es->retrieveOne($whid, $eid);
     $qty_to_qtytype_raw = $stock['pieces_per_qty_type'] > 0 ? $qty / $stock['pieces_per_qty_type'] : 0;
     $qty_to_qtytype = ceil($qty_to_qtytype_raw);
     $d = $firstadd;
     $img = webImageWithDetailLinkStars($element->image, IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, "Element {$id}", '', '', IMAGE_SIZE_BIG_1, IMAGE_SIZE_BIG_1, $element->stars);
     $show_qty_detail = $stock['pieces_per_qty_type'] > 1 ? '' : 'display:none;';
     $id2 = '';
     $id2 .= '<div class="notice" style="' . $show_qty_detail . '"><span class="red"><span id="e' . $eid . 'defqty">' . $qty . '</span> qty</span> &asymp; <span id="e' . $eid . 'unitqtyraw">' . number_format($qty_to_qtytype_raw, 2) . '</span> <span class="e' . $eid . 'unit">' . $stock['qty_type'] . '</span></div>';
     $id2 .= '<div class="smallText notice" style="margin-bottom:10px;' . $show_qty_detail . '"><span id="e' . $eid . 'uqpp">' . $stock['pieces_per_qty_type'] . '</span> qty = 1 <span class="e' . $eid . 'unit">' . $stock['qty_type'] . '</span></div>';
     $id2 .= '<div><input id="e' . $eid . 'unitqty" type="text" name="qty" value="' . $qty_to_qtytype . '" class="time" /><br /><span class="e' . $eid . 'unit">' . $stock['qty_type'] . '</span></div>';
     $id3 = '<div class="eid"><a href="?open=element&amp;id=' . $eid . '&amp;hidemenu=true" class="view_webpage">' . $eid . '</a></div>';
     //$id3 .= $element->displayStockInfoTable($stock['stock']);
     $id3 .= $element->displayStockInfoTablePreordersTemp();
     $r = $element->displayDIOH($stock['stock']);
     if ($stock['pieces_per_qty_type'] > 1) {
         $r .= '<br /><br /><span title="Safety Delivery Time">(SDT: ' . $element->displaySafetyDT($stock['stock'], $element->suppliers[$suppliers_id]['resourcing_day']) . ')</span>';
    if (!isset($merge_use_elements[$eid])) {
        $merge_use_elements[$eid] = $qty;
    } else {
        if ($qty > $merge_use_elements[$eid]) {
            $merge_use_elements[$eid] = $qty;
        }
    }
}
//echo "<h3>After Merged</h3>";
//echo "<pre>";var_dump($merge_use_elements);echo "</pre>";
//echo '<br /><br /><br />';
$new_use_element = array();
echo "<table border='1'>";
echo "<tr><th>Element ID</th><th>Current Stock</th><th>Pre-Ordered</th><th>Ordered</th><th>Total Available</th><th>Min Amount Needed</th></tr>";
foreach ($merge_use_elements as $eid => $qty) {
    $elstock = $class_es->retrieveOne(WAREHOUSE_ID_ELEMENTS, $eid);
    $tot_qty_el_preorder = elements_preorder::openOrdersQuantity($eid);
    $tot_qty_el_order = elements_order::openOrdersQuantity($eid);
    $total = $elstock['stock'] + $tot_qty_el_preorder + $tot_qty_el_order;
    echo "<tr><td>{$eid}</td><td>{$elstock['stock']}</td><td>{$tot_qty_el_preorder}</td><td>{$tot_qty_el_order}</td><td>{$total}</td><td>{$qty}</td></tr>";
    if ($total < $qty) {
        $stock = $qty - $total;
        $new_use_element[] = array('elements_id' => $eid, 'quantity' => $stock);
    }
}
echo "</table>";
echo '<br /><br /><br />';
echo "<h3>New Pre Order to be created</h3>";
echo "<pre>";
var_dump($new_use_element);
echo "</pre>";
Example #4
0
    }
    $selected = $carat == $gck ? 'checked="checked"' : '';
    $goldpure_carat .= '<div style="float:left;margin-right:10px;"><input type="radio" id="el_car_' . $gck . '" class="editable" name="elements_weight_goldpure" value="' . $gck . '" ' . $selected . ' disabled="disabled" />' . $gcv . '</div>';
}
$element_weight_goldpure .= '<input type="text" class="editable" id="weight_goldpure" name="weight_goldpure" value="' . $element->detail['weight_goldpure'] . '" readonly="readonly" />';
$element_suppliers = '<input type="text" id="elements_supplier" value="' . $element->detail['supplier'] . '" readonly="readonly" />';
$el_price = displayCurrency('EUR', $element->detail['price'], true, $element->detail['price'] < ELEMENTS_LOWER_PRICE ? 5 : 2);
$element_price = '<input type="text" id="elements_price" value="' . $el_price . '" readonly="readonly" />';
$element_wax_complexity = '<select id="wax_complexity" name="wax_complexity" disabled="disabled"><option value="">Please select complexity</option>' . loadComboListFromArray(getComplexity(), null, $element->wax_complexity, false) . '</select>';
if (is_null($element->id)) {
    $content .= '<h3 id="newinfo" class="red ui-corner-all" style="background:#ffeeee;padding:5px;margin-bottom:10px;">Specify a name to create New ID</h3>';
}
$content .= '<div id="element-detail">';
use_class('elements_stock');
$el_stock = new elements_stock();
$stock = $element->id > 0 ? $el_stock->retrieveOne(WAREHOUSE_ID_ELEMENTS, $element->id) : null;
$content .= '<div class="ui-corner-all ui-widget-content" style="width:220px;position:absolute;margin:-10px 0 0 650px;padding:5px 10px;">';
//$content .= '<div class="bold" style="margin:0 0 10px 3px;">Daily Log of Element</div>';
$content .= '<table class="form" style="width:100%;" border="0" cellpadding="0" cellspacing="0">';
if ($element->id > 0) {
    $content .= '<tr><td colspan="2" class="bold">Elements DIOH</td></tr>';
    $content .= '<tr><td colspan="2">&nbsp; &raquo; ' . $element->displayDIOH($stock['stock']) . '</td></tr>';
}
$content .= '<tr><td colspan="2" class="bold">Elements Usage</td></tr>';
$content .= '<tr><td>&nbsp; &raquo; <abbr title="Total elements used (reduced from stock) in the Last 30 Days">L30D</title></td><td class="tar">' . $element->log['used_monthly_1'] . ' Qty</td></tr>';
$content .= '<tr><td>&nbsp; &raquo; <abbr title="Maximum usage in Active Products">Max/Product</abbr></td><td class="tar">' . $element->log['usage_max'] . ' Pcs</td></tr>';
$content .= '<tr><td colspan="2">&nbsp; <a href="?open=element-forecasting&amp;id=' . $element->id . '&amp;hidemenu=true" class="view_webpage">&raquo; Forecasting</a></td></tr>';
$content .= '<tr><td colspan="2" class="bold">Sold Last 7 days</td></tr>';
$content .= '<tr><td>&nbsp; &raquo; Elements</td><td class="tar">' . $element->log['weekly_sold'] . ' Qty</td></tr>';
$content .= '<tr><td colspan="2" class="bold">Sold Last 30 days</td></tr>';
$content .= '<tr><td>&nbsp; &raquo; Elements</td><td class="tar">' . $element->log['sold_monthly_1'] . ' Qty</td></tr>';
Example #5
0
 function updateStatus($old_status, $new_status, $username)
 {
     $design_current_status = $this->sub_status != '' ? "{$this->status}-{$this->sub_status}" : $this->status;
     if ($design_current_status == $old_status) {
         $sda = array();
         $temp_new_status = explode('-', $new_status);
         $temp_old_status = explode('-', $old_status);
         $new_main_status = $temp_new_status[0];
         $old_main_status = $temp_old_status[0];
         $new_sub_status = isset($temp_new_status[1]) ? $temp_new_status[1] : 'null';
         $old_sub_status = isset($temp_old_status[1]) ? $temp_old_status[1] : 'null';
         $sda['status'] = $new_main_status;
         $sda['sub_status'] = $new_sub_status;
         //will automatically reset sub_status when its moved to status that have no sub status
         tep_db_perform('designs', $sda, 'update', "designs_id={$this->id}");
         $this->status = $new_main_status;
         $this->sub_status = $new_sub_status == 'null' ? null : $new_sub_status;
         $timestamp = $this->addStatusHistory($new_status, $username);
         $long_timestamp = date('Y-m-d H:i:s');
         if ($old_status == '2' && $new_status == '11') {
             //REQUEST TO PULLEDRACK
             $this->setTargetDateStart($timestamp);
         } elseif ($old_status == '11' && $new_status == '2') {
             //PULLEDRACK BACK TO REQUEST
             $this->setTargetDateStart('CLEAR');
             //            } elseif ($old_status=='3' && $new_status=='5') {   //DRAFTS TO SAMPLINGS
         } elseif ($old_status == '3' && $new_main_status == '5') {
             //DRAFTS TO SAMPLINGS
             //                $drafts = $this->retrieveDrafts("approve_status='A'");
             $drafts = $this->retrieveDrafts("approve_status!='R'");
             if (count($drafts) == 0) {
                 use_class('design_draft');
                 $draft = new design_draft();
                 $draft->create($this->id, $this->name, $this->colors_request, $this->followers->list_raw);
                 $draft->uploadImage('1', DIR_WS_IMAGES . $this->image_1, basename($this->image_1));
                 //$draft->setApproveStatus('A', 'auto-set');
             }
         } elseif ($old_status == '8' && $new_status == '9') {
             //FINALIZE TO DONE
             $this->setTargetDateEnd($timestamp);
             $drafts = $this->retrieveDrafts("approve_status!='R'");
             $drafts_ids = array();
             foreach ($drafts as $d) {
                 $drafts_ids[] = $d['drafts_id'];
             }
             $products = $this->retrieveProducts();
             //ADD TO WATCHLSIT
             $products_ids = array();
             //to be used by ADD ATTRIBUTES
             $products_ids_nosample = array();
             $products_ids_sample = array();
             use_class('minierp_users');
             use_class('elements_preorder');
             use_class('elements_order');
             use_class('products_articles');
             use_class('products_minierp');
             use_class('elements_stock');
             $class_mu = new minierp_users();
             $class_pm = new products_minierp();
             $class_pa = new products_articles();
             $class_es = new elements_stock();
             $use_elements = array();
             $eao = 2;
             //element adjust order
             foreach ($products as $p) {
                 if (in_array($p['drafts_id'], $drafts_ids) && $p['finalized_time'] != '' && $p['finalized_by'] != '') {
                     $products_ids[] = $p['products_id'];
                     if ($p['create_sample'] == '1') {
                         $products_ids_sample[] = $p['products_id'];
                     } else {
                         $products_ids_nosample[] = $p['products_id'];
                     }
                     foreach ($this->watched_by as $wl_user_id) {
                         if ($wl_user_id > 0) {
                             $class_mu->addToWatchlist($wl_user_id, $p['products_id']);
                         }
                     }
                     // #BEGIN CALCULATE NEW ELEMENT SOURCE
                     // first check category
                     $tpdbq_products_use_elements = $class_pm->retrieveElementsUsage($p['products_id']);
                     foreach ($tpdbq_products_use_elements as $row_pue) {
                         $use_elements[] = array('elements_id' => $row_pue['elements_id'], 'quantity' => (int) $row_pue['quantity'] * $eao);
                     }
                     $tpdbq_products_articles = $class_pa->retrieveList($p['products_id'], "active_status='1'");
                     foreach ($tpdbq_products_articles as $row_pa) {
                         $tpdbq_products_articles_use_elements = $class_pm->retrieveElementsUsage($p['products_id'], $row_pa['products_articles_id']);
                         foreach ($tpdbq_products_articles_use_elements as $row_pue) {
                             $use_elements[] = array('elements_id' => $row_pue['elements_id'], 'quantity' => (int) $row_pue['quantity'] * $eao);
                         }
                     }
                     // #END CALCULATE NEW ELEMENT SOURCE
                 }
             }
             // merge same element id
             $merge_use_elements = array();
             foreach ($use_elements as $use_element) {
                 $eid = $use_element['elements_id'];
                 $qty = $use_element['quantity'];
                 if (!isset($merge_use_elements[$eid])) {
                     $merge_use_elements[$eid] = $qty;
                 } else {
                     if ($qty > $merge_use_elements[$eid]) {
                         $merge_use_elements[$eid] = $qty;
                     }
                 }
             }
             // check to stock and
             // insert to element preorder
             //echo "</pre>merge<pre>";var_dump($merge_use_elements);
             // dari sini gk dibaca
             foreach ($merge_use_elements as $eid => $qty) {
                 $epreorder = new elements_preorder($eid);
                 $elstock = $class_es->retrieveOne(WAREHOUSE_ID_ELEMENTS, $eid);
                 $tot_qty_el_preorder = elements_preorder::openOrdersQuantity($eid);
                 $tot_qty_el_order = elements_order::openOrdersQuantity($eid);
                 $total = $elstock['stock'] + $tot_qty_el_preorder + $tot_qty_el_order;
                 if ($total < $qty) {
                     $stock = $qty - $total;
                     $epreorder->addOrder($stock, null, "New Design " . $this->id);
                 }
             }
             //ADD ATTRIBUTES
             if (count($products_ids) > 0 && ($this->styles_id_F > 0 || $this->styles_id_L > 0)) {
                 use_class('styles');
                 $class_s = new styles();
                 if ($this->styles_id_F > 0) {
                     $class_s->addProduct($this->styles_id_F, $products_ids, $username);
                 }
                 if ($this->styles_id_L > 0) {
                     $class_s->addProduct($this->styles_id_L, $products_ids, $username);
                 }
             }
             //FINALLY, ACTIVATE THE PRODUCTS
             if (count($products_ids_nosample) > 0) {
                 $class_pm->activateProducts($products_ids_nosample, true);
             }
             if (count($products_ids_sample) > 0) {
                 $class_pm->activateProducts($products_ids_sample, true, true);
             }
         } elseif ($old_status == '11' && $new_status == '10-0') {
             //PULLRACK TO SOURCING
             $this->updateField('is_sourcing', 1);
             $n_drafts = $this->retrieveDrafts("approve_status!='R'");
             if (count($n_drafts) == 0) {
                 use_class('design_draft');
                 $draft = new design_draft();
                 $draft->create($this->id, $this->name);
                 $draft->uploadImage('1', DIR_WS_IMAGES . $this->image_1, basename($this->image_1));
                 //$element = $draft->createElement('', $this->name, 0, '', 0, date('Y-m-d H:i:s'), 'auto', '0');  //we not auto create this, since we already used sub_status on design level
             }
         } elseif ($old_status == '10-0' && $new_status == '11') {
             //SOURCING BACK TO PULLRACK
             $this->updateField('is_sourcing', 'null');
         }
         //INCREMENT FOR GRAPH DATASOURCE
         //            if($old_status==3 && ($new_status==4||$new_status==5)) {
         if ($old_status == 3 && ($new_status == 4 || $new_main_status == 5)) {
             //COUNT NUMBER OF DESIGN MOVED OUT
             $this->addDataToField($long_timestamp, 'design_drafts', 1);
         }
         //            if($new_status>5){
         if ($new_main_status > 5) {
             //COUNT NUMBER OF PRODUCTS MOVED OUT
             $q = "SELECT COUNT(dp.designs_id) total_products FROM designs_products dp";
             $q .= " INNER JOIN designs_drafts dd ON dd.drafts_id = dp.drafts_id AND dd.approve_status != 'R'";
             $q .= " WHERE dp.designs_id = " . $this->id;
             $q .= " GROUP BY dp.designs_id";
             $dbq = tep_db_query($q);
             $res = tep_db_fetch_array($dbq);
             $total_products = $res['total_products'] > 0 ? $res['total_products'] : 0;
             //                if($old_status==5 && $new_status==6) $this->addDataToField($long_timestamp, 'design_samplings', $total_products);
             if ($old_main_status == 5 && $new_main_status == 14) {
                 $this->addDataToField($long_timestamp, 'design_samplings', $total_products);
             }
             //                if($old_status==6 && $new_status==12) $this->addDataToField($long_timestamp, 'design_graphics', $total_products);
             if ($old_main_status == 14 && $new_status == 12) {
                 $this->addDataToField($long_timestamp, 'design_graphics', $total_products);
             }
             if ($old_status == 12 && $new_status == 7) {
                 $this->addDataToField($long_timestamp, 'design_product_qc', $total_products);
             }
             if ($old_status == 7 && $new_status == 8) {
                 $this->addDataToField($long_timestamp, 'design_details', $total_products);
             }
             if ($old_status == 8 && $new_status == 9) {
                 $this->addDataToField($long_timestamp, 'design_finalize', $total_products);
             }
         }
         /*NO NEED ANYMORE, SINCE WE ALREADY SAVED sub_status ON DESIGN LEVEL
           if($new_status==10) {
               if($old_status=='1' && $this->isSourcingNewElements()) $this->addStatusHistory("10-0", $username);
               elseif($old_status=='6' && $this->isSourcingNewElements()) $this->addStatusHistory("10-0", $username);
               elseif($old_status=='4') $this->addStatusHistory("10-1", $username);
               elseif($old_status=='5') $this->addStatusHistory("10-7", $username);
           }
            */
     }
 }
Example #6
0
 public function retrieveStockQuantity($exlude_active_booking = true)
 {
     use_class('elements_stock');
     $class_es = new elements_stock();
     $stock = $class_es->retrieveOne(WAREHOUSE_ID_ELEMENTS, $this->id);
     return $stock['stock'];
 }