Example #1
0
        $carat = element::getMaterialFromToCarat('', $element->attributes['material']['id']);
    }
    $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>';
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
require_once DIR_WS_FUNCTIONS . 'html_output.php';
tep_db_connect();
$eao = 2;
//element adjust order
use_class('design');
use_class('elements_preorder');
use_class('elements_order');
use_class('elements_stock');
use_class('products_articles');
use_class('products_minierp');
$class_es = new elements_stock();
$class_pm = new products_minierp();
$class_pa = new products_articles();
$ean_eu_collection = array();
$max_el_per_article = 0;
$use_elements = array();
$class_d = new design($_GET['d']);
$products = $class_d->retrieveProducts();
foreach ($products as $p) {
    $query_products_categories = "SELECT * FROM products_to_categories ptc WHERE products_id={$p['products_id']}";
    $tpdbq_products_categories = tep_db_query($query_products_categories);
    $products_categories = tep_db_fetch_array($tpdbq_products_categories);
    // find what use element in this product
    $ean_eu_collection[$p['products_id'] . '-0'] = '';
    $tpdbq_products_use_elements = $class_pm->retrieveElementsUsage($p[products_id]);
    foreach ($tpdbq_products_use_elements as $row_pue) {
Example #3
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);
           }
            */
     }
 }
<?php

use_class('element');
use_class('products_minierp');
use_class('elements_stock');
use_class('elements_order');
$class_pm = new products_minierp();
$class_es = new elements_stock();
//WAREHOUSE OPTIONS
$session_page = 'elements-stock';
$wo = warehouse_options($session_page);
$whid = $_SESSION[$session_page]['whid'];
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'SEARCHFILTER') {
        $days = $_POST['days'];
        $day_filter = date('Y-m-d', strtotime("-{$days} days"));
        $q = "SELECT * FROM (";
        $q .= " SELECT joi.jng_sp_orders_items_id, joi.leadtime_start_date, joi.products_id, joi.products_articles_id as articles_id, joi.stock_status, FLOOR(joi.order_quantity) as quantity";
        $q .= " FROM jng_sp_orders jo";
        $q .= " INNER JOIN jng_sp_orders_items joi ON joi.jng_sp_orders_id = jo.jng_sp_orders_id";
        $q .= " WHERE joi.leadtime_start_date IS NOT NULL";
        $q .= " AND joi.leadtime_start_date < '{$day_filter}' AND joi.status = 2";
        $q .= " UNION";
        $q .= " SELECT op.orders_products_id, op.leadtime_start_date, op.products_id, op.products_articles_id as articles_id, op.stock_status, FLOOR(op.products_quantity) as quantity";
        $q .= " FROM orders o";
        $q .= " INNER JOIN orders_products op ON op.orders_id = o.orders_id";
        $q .= " WHERE op.leadtime_start_date IS NOT NULL";
        $q .= " AND op.leadtime_start_date < '{$day_filter}' AND op.status = 2";
        $q .= " UNION";
        $q .= " SELECT do.depot_orders_id, do.leadtime_start_date, do.products_id, do.articles_id as articles_id, do.stock_status, FLOOR(do.quantity) as quantity";
        $q .= " FROM depot_orders do";
Example #5
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'];
 }
 //in minutes
 $duration_hold_not_zalando_orders = $duration_hold_not_zalando_orders * 60;
 //change to seconds
 use_class('orders');
 use_class('depot_orders');
 use_class('jng_sp_orders');
 use_class('products_minierp');
 use_class('elements_stock');
 use_class('products_ean');
 use_class('element');
 use_class('stock_booking');
 $class_o = new orders();
 $class_do = new depot_orders();
 $class_jo = new jng_sp_orders();
 $class_pm = new products_minierp();
 $class_es = new elements_stock();
 $class_ean = new products_ean();
 $elements_collection = array();
 $temp_order_date = array();
 $temp_jng_sp_id = array();
 $temp_import_timestamp = array();
 $otto_prepayment = strtoupper(PAYMENT_METHOD_PREPAYMENT);
 $oi_status_to_reset_stock_status = array('1', '2');
 //CLEAR IDLE BINS
 use_class('bins');
 $class_bin = new bins();
 $class_bin->clearIdleBins();
 //INIT FULL ORDERS VARIABLE
 $orders = array();
 $orders_type = array();
 $orders_total = array();
<?php

use_class('elements_stock');
$class_es = new elements_stock();
$max_rows_limit = 300;
//WAREHOUSE OPTIONS
$session_page = 'elements-stock';
$wo = warehouse_options($session_page);
$whid = $_SESSION[$session_page]['whid'];
//DEFAULT FILTER
$fday = isset($_SESSION[$session_page]['fday']) ? $_SESSION[$session_page]['fday'] : '';
$fmonth = isset($_SESSION[$session_page]['fmonth']) ? $_SESSION[$session_page]['fmonth'] : date('n');
$fyear = isset($_SESSION[$session_page]['fyear']) ? $_SESSION[$session_page]['fyear'] : date('Y');
//SUBMIT ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'CONFIRM_CHANGES') {
        if (isset($_POST['confirm']) && is_array($_POST['confirm']) && count($_POST['confirm']) > 0) {
            $confirmed_date = date('Y-m-d H:i:s');
            $class_es->elements_transaction_confirm($_POST['confirm'], $session_userinfo['username'], $confirmed_date);
        }
    } elseif ($_POST['me_action'] == 'SUBMIT_FILTERS') {
        $fday = tep_db_prepare_input($_POST['fdays']);
        $fmonth = tep_db_prepare_input($_POST['fmonths']);
        $fyear = tep_db_prepare_input($_POST['fyears']);
        $_SESSION[$session_page]['fday'] = $fday;
        $_SESSION[$session_page]['fmonth'] = $fmonth;
        $_SESSION[$session_page]['fyear'] = $fyear;
    }
}
//START TEMPLATE
if ($fday != '') {
<?php

use_class('element');
use_class('elements_stock');
element::loadDIOHsettings();
$class_es = new elements_stock();
$show_amount = 10;
$whid = 1;
$sort_options = array('total DESC' => 'MAX Total', 'es.stock DESC' => 'MAX Stock', 'dioh DESC' => 'MAX DIOH', 'total ASC' => 'MIN Total', 'es.stock ASC' => 'MIN Stock', 'dioh ASC' => 'MIN DIOH', 'msws' => 'MIN Stock vs Weekly Sold', 'e.elements_id' => 'Elements ID');
if (isset($_POST['sort_option'])) {
    $sort_option = tep_db_prepare_input($_POST['sort_option']);
} else {
    $sort_option = 'total DESC';
}
if (isset($_POST['elcat-filter'])) {
    $elcatfiltered = tep_db_prepare_input($_POST['elcat-filter']);
    if ($elcatfiltered != '') {
        $_SESSION[$session_page]['elcat-filter'] = $elcatfiltered;
    } else {
        unset($_SESSION[$session_page]['elcat-filter']);
    }
} elseif (isset($_SESSION[$session_page]['elcat-filter'])) {
    $elcatfiltered = $_SESSION[$session_page]['elcat-filter'];
}
$header = array();
$header['img'] = 'Image';
$header['id'] = 'ID';
$header['name'] = 'Name';
$header['info'] = 'Supplier';
$header['pri'] = 'Price per Piece';
$header['info2'] = 'Stock Available';
Example #9
0
 function updateStatus($items_id, $new_status, $updater = '', $add_to_prod_target = true)
 {
     use_class('production_target');
     $pt = new production_target();
     list($new_status, $sub_status) = explode('-', $new_status);
     $item = $this->retrieveDetail($items_id);
     $is_outsourced = $this->isOutsourceOrder($item['trans_type'], $item['trans_id']);
     $timestamp = date('Y-m-d H:i:s');
     $sub_status = trim(strtoupper($sub_status));
     if ($new_status == '10') {
         $this->doCancelOrders($items_id, $item['status'], $updater);
     } else {
         if ($add_to_prod_target) {
             if (!$is_outsourced) {
                 //outsourcing orders should never affect the Finish KPI Graphs
                 if ($new_status == '5') {
                     $pt->addDataToField($timestamp, 'finish', $item['quantity']);
                 }
             }
             if ($new_status == '6') {
                 $pt->addDataToField($timestamp, 'package', $item['quantity']);
             }
             if ($new_status == '7') {
                 $pt->addDataToField($timestamp, 'sent', $item['quantity']);
             }
         }
         if ($new_status == '4' && $sub_status != '') {
             $set_prod_status = ", prod_status = '" . $sub_status . "'";
         }
         //PS: please don't set empty prod_status when it updated to status > 4,...
         //...since this will used for check whether order could transferred to DP or not...
         //...when real order taken over by HH while order still on production
         tep_db_query("UPDATE depot_orders SET status='{$new_status}' {$set_prod_status} WHERE depot_orders_id={$items_id}");
         $save_main_status_history = true;
         //if ( ( in_array($item['status'], array('1','3','4','5')) && $new_status=='4' ) && ( $sub_status!='' && ( trim(strtoupper($item['prod_status'])) != $sub_status ) ) ) {
         /*
         $item['status'] = 1 is included here to also save prod. status history when there's real order cancelled/taken over by hh caused using depot hh stock
         while real order is already processed in production, finish, or in package. The first status created was 1.
         */
         //replace using below, allowing all process which set to production to have a chance saving the prod. status history
         if ($new_status == '4' && $sub_status != '' && trim(strtoupper($item['prod_status'])) != $sub_status) {
             $psh = array();
             $psh['orders_items_id'] = $items_id;
             $psh['type'] = 'DP';
             $psh['status'] = $sub_status;
             $psh['status_quantity'] = $item['quantity'];
             $psh['status_date'] = $timestamp;
             $psh['update_by'] = $updater;
             saveProductionStatusHistory($psh);
             if ($item['status'] == '4') {
                 $save_main_status_history = false;
             }
         }
         if ($save_main_status_history) {
             $sda = array();
             $sda['depot_orders_id'] = $items_id;
             $sda['status'] = $new_status;
             $sda['update_time'] = $timestamp;
             $sda['update_by'] = $updater;
             tep_db_perform('depot_orders_status_history', $sda);
         }
         if (!$is_outsourced) {
             if ($new_status == '2' && $item['stock_status'] != 'S' && $item['stock_status'] != 'W') {
                 $this->updateStockStatus($items_id, false);
                 $this->prodStatusReset($items_id);
                 $this->eanPrintedReset($items_id);
                 //$this->printCountReset($items_id);    //now we don't need to reset print_count for reprint pi when move to ready again.
             } elseif ($new_status == '3' && $item['stock_status'] == 'S' || $new_status == '4' && $item['stock_status'] == 'W') {
                 $eu = $this->countElementsUsage($item['products_id'], $item['articles_id']);
                 if (count($eu) > 0) {
                     $jng_warehouses_id = '1';
                     use_class('elements_stock');
                     $class_es = new elements_stock();
                     foreach ($eu as $elements_id => $euqty) {
                         $reduce_amount = $item['quantity'] * $euqty;
                         $class_es->reduceStockByPieces($jng_warehouses_id, $elements_id, $reduce_amount, 'RED DP-' . $items_id);
                     }
                 }
                 $this->updateStockStatus($items_id, 'R');
             }
         }
     }
     switch ($item['trans_type']) {
         case 'SP':
             use_class('jng_sp_orders');
             $class_jo = new jng_sp_orders();
             $item_sp = $class_jo->retrieveItemDetail($item['trans_id']);
             if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
                 $class_jo->productionTargetIn($timestamp, $item_sp);
             } elseif ($new_status == '6') {
                 $class_jo->productionTargetOut($timestamp, $item_sp);
             } elseif ($new_status == '12') {
                 $class_jo->productionTargetInReset($item_sp);
             }
             break;
         case 'JG':
             use_class('orders');
             $class_o = new orders();
             $item_jg = $class_o->retrieveProductDetail($item['trans_id']);
             if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
                 $class_o->productionTargetIn($timestamp, $item_jg);
             } elseif ($new_status == '6') {
                 $class_o->productionTargetOut($timestamp, $item_jg);
             } elseif ($new_status == '12') {
                 $class_o->productionTargetInReset($item_jg);
             }
             break;
         default:
             if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
                 $this->productionTargetIn($timestamp, $item);
             } elseif ($new_status == '6') {
                 $this->productionTargetOut($timestamp, $item);
             } elseif ($new_status == '12') {
                 $this->productionTargetInReset($item);
             }
     }
     if ($new_status == '3' && !$is_outsourced) {
         //use_class('production_instruction_pdf');
         //$class_pi = new production_instruction_pdf();
         if ($item['print_count'] > 0 && $item['print_confirmed'] > 0) {
             //SECOND OR MORE PI PRINTED, could happen when there product by stock_status is "OK" but in real stock is "0" so this will set back to "NS". And when ready this will reprinted by using this block
             $this->printConfirmReset($items_id);
             $this->printCountReset($items_id);
         }
         /*
         $class_pi->addOrder('DP', $items_id);
         $add_to_daily_statistic = $item['print_count']==0 ? true : false;
         $class_pi->createPDF(false, 'F', $add_to_daily_statistic);
         */
     }
     return $new_status;
 }
Example #10
0
 function updateProductStatus($items_id, $new_status, $updater = '', $cancelby = 'J', $add_to_prod_target = true)
 {
     /*==============================================================
       * PURPOSE  :   TO CHANGE PROCESS STATUS ORDER OF PRODUCTS
       * PARAMS   :   $items_id (NUMBER) >> e.g: 1234
       *              $new_status (NUMBER) >> e.g: 1
       *              $updater (STRING) "OPTIONAL" >> e.g: 'mbosse'
       *              $cancelby (STRING) "OPTIONAL" >> e.g: 'S'
       ===============================================================*/
     use_class('production_target');
     $pt = new production_target();
     list($new_status, $sub_status) = explode('-', $new_status);
     $item = $this->retrieveProductDetail($items_id);
     $itemMode = modeName($item['mode']);
     $timestamp = date('Y-m-d H:i:s');
     $is_reviving = statusIsCancelled($item['status']) && !statusIsCancelled($new_status);
     //Revive Item should move to in HH directly if other items are already in HH
     if ($is_reviving) {
         $item_others = $this->retrieveProducts($item['orders_id']);
         $others_in_hh = false;
         //If there's other items are already in HH set new status directly to HH
         foreach ($item_others as $io) {
             if ($io['status'] == '8') {
                 $new_status = '8';
                 $others_in_hh = true;
                 break;
             }
         }
         //If there's no items are already in HH (Full MTO)
         if (!$others_in_hh) {
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->retrieveDetailTransmigran('JG', $items_id);
             if (!is_null($item_do)) {
                 if ($item_do['status'] < 6) {
                     /*  Order status is before in Package, do below steps:
                            1) Set real status same with last status of DP
                            2) Consider also set sub production status "only" when main status is in production
                            3) Cancel "directly" DP order, means we not use doCancelOrder
                         */
                     $new_status = $item_do['status'];
                     $sub_status = $new_status == '4' ? $item_do['prod_status'] : '';
                     $class_do->updateStatus($item_do['depot_orders_id'], '12', 'auto-set');
                     $reviving_need_next_update = true;
                     $revived_stock_status = $item_do['stock_status'];
                     $revived_mode = 'MTO';
                 } else {
                     /* Order status is >= "in Package"
                           1) Set real status to New
                        */
                     $new_status = '1';
                 }
             }
         }
     }
     //Only "Sent" and "Complete" status can be updated to "Returned"
     if ($new_status == '14' && !($item['status'] == '9' || $item['status'] == '11')) {
         return false;
     }
     //KPI Logging
     if ($add_to_prod_target) {
         if ($new_status == '5') {
             $pt->addDataToField($timestamp, 'finish', $item['products_quantity']);
         }
         if ($new_status == '6') {
             $pt->addDataToField($timestamp, 'package', $item['products_quantity']);
         }
         if ($new_status == '7') {
             $pt->addDataToField($timestamp, 'sent', $item['products_quantity']);
         }
         if ($new_status == '16') {
             $pt->addDataToField($timestamp, 'log_return_to_bali', $item['products_quantity']);
         }
         if ($new_status == '19') {
             $pt->addDataToField($timestamp, 'log_return_missing', $item['products_quantity']);
         }
         if ($new_status == '20') {
             $pt->addDataToField($timestamp, 'log_return_to_bin_in', $item['products_quantity']);
         }
         if ($new_status == '9') {
             $pt->addDataToField($timestamp, 'log_products_sent_b2c', $item['products_quantity']);
             if ($itemMode == 'DSO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_dso', $item['products_quantity']);
             } elseif ($itemMode == 'MTO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_mto', $item['products_quantity']);
             } elseif ($itemMode == 'WMO' || $itemMode == 'MMO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_mo', $item['products_quantity']);
             }
         }
     }
     //Update Status and create Status History
     $sda_op = array('status' => $new_status);
     $sda_op['status'] = $new_status;
     if ($new_status == '10') {
         $sda_op['products_problem'] = $cancelby;
     } elseif ($this->productStatusIsCancelled($item['status']) && !$this->productStatusIsCancelled($new_status)) {
         $sda_op['products_problem'] = '0';
     }
     $sub_status = trim(strtoupper($sub_status));
     if ($new_status == '4' && $sub_status != '') {
         $sda_op['prod_status'] = $sub_status;
     }
     //PS: please don't set empty prod_status when it updated to status > 4,
     //since this will used for check whether order could transferred to DP or not
     //when real order taken over by HH when it from production
     tep_db_perform('orders_products', $sda_op, 'update', "orders_products_id={$items_id}");
     $save_main_status_history = true;
     if (in_array($item['status'], array('3', '4', '5')) && $new_status == '4' && ($sub_status != '' && trim(strtoupper($item['prod_status'])) != $sub_status) || $is_reviving && $new_status == '4') {
         $psh = array();
         $psh['orders_items_id'] = $items_id;
         $psh['type'] = 'JG';
         $psh['status'] = $sub_status;
         $psh['status_quantity'] = $item['products_quantity'];
         $psh['status_date'] = $timestamp;
         $psh['update_by'] = $updater;
         saveProductionStatusHistory($psh);
         if ($item['status'] == '4') {
             $save_main_status_history = false;
         }
     }
     if ($save_main_status_history) {
         $sda = array();
         $sda['orders_products_id'] = $items_id;
         $sda['status'] = $new_status;
         $sda['status_quantity'] = $item['products_quantity'];
         $sda['status_date'] = $timestamp;
         $sda['update_by'] = $updater;
         tep_db_perform('orders_products_status_history', $sda);
     }
     //Revive Additional Action
     if ($is_reviving) {
         //Revive Items from Cancel Request Status
         $this->recalcProductsCounter($item['orders_id']);
         if ($new_status == '8') {
             $this->printCountReset($items_id);
             $this->updateOrderItemMode($items_id, 'MMO');
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, 'JG', $items_id);
             if ($item_do['status'] > 7) {
                 $class_do->updateStatus($item_do['depot_orders_id'], '1');
                 $class_do->printCountReset($item_do['depot_orders_id']);
             }
         }
         if ($reviving_need_next_update) {
             $this->updateProductStockStatus($items_id, $revived_stock_status);
             if ($revived_mode != '') {
                 $this->updateOrderItemMode($items_id, $revived_mode);
             }
         }
         //Set need repackaging flag if needed
         use_class('products_minierp');
         $class_pm = new products_minierp();
         $p_data = $class_pm->retrieveDetail($item['products_id'], 'p');
         if ($p_data['p']['need_repackaging'] == 1) {
             $this->setNeedRepackaging($item['orders_id']);
         }
     }
     //Check other available products of this order which need repackage "nr" on cancel
     if ($new_status == '10') {
         use_class('products_minierp');
         $class_pm = new products_minierp();
         $need_repackaging = false;
         $nr_q = "SELECT products_id FROM orders_products WHERE orders_id = {$item['orders_id']} AND status NOT IN (10, 12)" . " AND orders_products_id != {$items_id}";
         $nr_dbq = tep_db_query($nr_q);
         while ($nr_r = tep_db_fetch_array($nr_dbq)) {
             $p_data = $class_pm->retrieveDetail($nr_r['products_id'], 'p');
             if ($p_data['p']['need_repackaging'] == 1) {
                 $need_repackaging = true;
                 break;
             }
         }
         if (!$need_repackaging) {
             $this->resetNeedRepackaging($item['orders_id']);
         }
     }
     //Recalculate Orders Total, Products Counter on cancellation and reviving
     if ($new_status == '10' || $is_reviving) {
         $this->recalcTotals($item['orders_id']);
         $this->recalcProductsCounter($item['orders_id']);
         $this->recalcVouchersAndShippingCost($item['orders_id'], false);
     }
     //Update Stock Status and Elements Stock if necessary
     if ($new_status == '2' && $item['stock_status'] != 'S') {
         $this->updateProductStockStatus($items_id, false);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         //$this->printCountReset($items_id);    //now we don't need to reset print_count for reprint pi when move to ready again.
     } elseif ($new_status == '3' && $item['stock_status'] == 'S' || $new_status == '4' && $item['stock_status'] == 'W') {
         $eu = $this->countElementsUsage($item['products_id'], $item['products_articles_id']);
         $jng_warehouses_id = '1';
         use_class('elements_stock');
         $class_es = new elements_stock();
         foreach ($eu as $elements_id => $euqty) {
             $reduce_amount = $item['products_quantity'] * $euqty;
             $class_es->reduceStockByPieces($jng_warehouses_id, $elements_id, $reduce_amount, 'RED JG-' . $items_id);
         }
         $this->updateProductStockStatus($items_id, 'R');
     } elseif ($new_status == '1') {
         //IF THERES ORDERS NEEDS RESET BACK TO NEW
         $this->printCountReset($items_id);
         $this->printConfirmReset($items_id);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         $this->updateProductStockStatus($items_id, 0);
         $this->updateOrderItemMode($items_id, 'UNSET');
     }
     //Production Target Flag Counter
     if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
         $this->productionTargetIn($timestamp, $item);
     } elseif ($new_status == '6') {
         $this->productionTargetOut($timestamp, $item);
     } elseif ($new_status == '10') {
         $this->productionTargetInReset($item);
     }
     //Auto Print PI rules
     if ($new_status == '3' || $new_status == '12') {
         $orders_id = $item['orders_id'];
         //$q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM orders_products WHERE orders_id = $orders_id AND status = 3 AND print_count = 0 GROUP BY orders_id");
         //ALSO CONSIDER GIFT/VOUCHER THAT DIRECTLY SET AS "SENT TO CUSTOMER" BUT print_count still zero
         $q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM orders_products WHERE orders_id = {$orders_id} AND status IN (3, 9) AND print_count = 0 GROUP BY orders_id");
         $pi_status = tep_db_fetch_array($q_pi_status);
         if ($pi_status['pi_ready_to_print'] == 1) {
             //PI PRINTED FOR THE FIRST TIME
             /* HANDLED BY BATCH PRINTING CRON cron/print-pi.php
                use_class('production_instruction_pdf');
                $class_pi = new production_instruction_pdf();
                $class_pi->addOrder('JG', $orders_id);
                $class_pi->createPDF(false, 'F', true);
                 */
         } else {
             if ($item['print_count'] > 0 && $item['print_confirmed'] > 0) {
                 //SECOND OR MORE PI PRINTED, could happen when there product by stock_status is "OK" but in real stock is "0" so this will set back to "NS". And when ready this will reprinted by using this block
                 $this->printConfirmReset($item['orders_products_id']);
                 $this->printCountReset($item['orders_products_id']);
                 /*
                                         use_class('production_instruction_pdf');
                                         $class_pi = new production_instruction_pdf();
                                         $class_pi->addItem('JG', $item['orders_products_id']);
                                         $class_pi->createPDF(false, 'F', false);    //not add to daily statistic, we consider this as not "NEW"
                 */
             }
         }
     }
     $q = tep_db_query("SELECT o.orders_id, o.orders_status, o.payment_method FROM orders_products op LEFT JOIN orders o ON o.orders_id=op.orders_id WHERE op.orders_products_id={$items_id}");
     $order = tep_db_fetch_array($q);
     if ($new_status == '12' || $item['products_problem'] == '0') {
         $status_to_update_orders = array('2' => '6', '4' => '5', '13' => '6', '5' => '7', '7' => '8', '9' => '10', '12' => '12');
         //cancelled
         if (array_key_exists($new_status, $status_to_update_orders)) {
             $changeorderstatus = true;
             if ($new_status == '12') {
                 //dont update order status if not all products are cancelled
                 if (!$this->isAllProductsCancelled($order['orders_id'])) {
                     $changeorderstatus = false;
                 }
             }
             if ($changeorderstatus) {
                 $order_new_status = $status_to_update_orders[$new_status];
                 if ($order['orders_status'] < $order_new_status) {
                     $this->updateOrderStatus($order['orders_id'], $order_new_status);
                 }
             }
         }
         if ($new_status == '12' && (strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_BANK_TRANSFER) || strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PAYPAL))) {
             /*----------------------------------------------------------------------------------------
               * MAKE RETURN ENTRY FOR "PREPAYMENT ONLY" ON "CANCEL CONFIRM", SINCE FOR NON-PREPAYMENT, 
               * PAYONE INVOICE WILL CREATED WHEN PRODUCTS IS SENT, 
               * SO NO NEED TO ADJUST IT OR CREATE RETURN CONTAINER WHEN CANCEL CONFIRM PROCESS
               -----------------------------------------------------------------------------------------*/
             use_class('payone');
             use_class('payone_invoice');
             $class_payone = new payone();
             $payi = new payone_invoice('invoice_order_id', $order['orders_id'], "invoice_order_type = 'J'");
             if ($payi->isUncapturedPrePayment()) {
                 //UNCAPTURED PREAUTH VORKASSE NEED TO RECALCULATE INVOICE
                 $payi->recalculate();
                 //SET AS PAID WHEN OPEN BALANCE LEAVE SMALL AMOUNT OR THIS CANCEL PROCESS MAKES UNDERPAID BALANCE BECOMES PAID/OVERPAID
                 if ($payi->getBalance() * 100 <= PAYONE_MAX_RETURNED_OPEN_PAYMENT) {
                     $this->updatePaymentStatus($item['orders_id'], '1', 'auto-set');
                 }
             } else {
                 //AUTH VORKASSE, CAPTURED PREAUTH VORKASSE, PAYPAL ORDER WILL ADD TO RETURN CONTAINER
                 $class_payone->createReturnContainer('NULL', $item['products_quantity'], $items_id);
             }
         }
     }
     //NEED TO RECALCULATE INVOICE WHEN REVIVING UNCAPTURED PREAUTH VORKASSE
     if ($is_reviving && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             $payi->recalculate();
         }
     }
     //SET READY TO CAPTURED FOR PREPAYMENT PREAUTH THAT ALREADY SENT
     if ($new_status == '9' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_BANK_TRANSFER)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $item['orders_id'], "invoice_order_type = 'J'");
         $payi->setIsCaptured('2');
     }
     return $new_status;
 }
Example #11
0
        while ($row = tep_db_fetch_array($q)) {
            $result .= '<tr><td>' . statusName($row['status']) . '</td><td class="tac">' . $row['total_order'] . '</td></tr>';
        }
        $result .= '</table>';
        echo utf8_encode($result);
        exit;
    }
    if (isset($preorder)) {
        $preorder->comments->processPostAction($preorder->create_by_id, $preorder->followers);
        $preorder->followers->processPostAction();
    }
}
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>';
set_time_limit(0);
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('logger');
$logger = new logger('cron', 'elements-sourcing');
//$logger->write('SIMULATION');
//Include Required Classes (and create object when necessary)
use_class('products_minierp');
use_class('element');
use_class('elements_stock');
use_class('elements_preorder');
use_class('elements_order');
$class_es = new elements_stock();
$class_pm = new products_minierp();
//Grab all required Settings
//Send email notification if missing quantity is > 0.2 * target stock
$tolerance_email_notification = 0.2;
$bgst = $class_pm->retrieveBestGoodSettings();
//REMOVE ANY OPEN EXISTING SUGGESTIONS BEFORE MAKING NEW ONES
elements_preorder::clearAllExistingOpenedSuggestion();
$logger->write('Existing Opened Suggestion is cleared!');
elements_preorder::clearPreordersTemp();
$logger->write('Existing Preorders temporary data is cleared!');
//Grab all existing elements, let's grab the data per element as an object
$r = tep_db_query("SELECT e.elements_id FROM element e " . "WHERE e.is_finalized='1' ORDER BY elements_id");
$elements = array();
while ($row = tep_db_fetch_array($r)) {
    $elements[] = $row['elements_id'];
Example #13
0
 function updateItemStatus($items_id, $new_status, $updater = '', $cancelby = 'J', $add_to_prod_target = true)
 {
     use_class('production_target');
     $pt = new production_target();
     list($new_status, $sub_status) = explode('-', $new_status);
     $item = $this->retrieveItemDetail($items_id);
     $itemMode = modeName($item['mode']);
     $timestamp = date('Y-m-d H:i:s');
     $is_reviving = statusIsCancelled($item['status']) && !statusIsCancelled($new_status);
     $reviving_need_next_update = false;
     //Revive Item should move to in HH directly if other items are already in HH
     if ($is_reviving) {
         $item_others = $this->retrieveItems($item['jng_sp_orders_id']);
         $others_in_hh = false;
         //If there's other items are already in HH set new status directly to HH
         foreach ($item_others as $io) {
             if ($io['status'] == '8') {
                 $new_status = '8';
                 $others_in_hh = true;
                 break;
             }
         }
         //If there's no items are already in HH (Full MTO)
         if (!$others_in_hh) {
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->retrieveDetailTransmigran('SP', $items_id);
             if (!is_null($item_do)) {
                 if ($item_do['status'] < 6) {
                     /*  Order status is before in Package, do below steps:
                            1) Set real status same with last status of DP
                            2) Consider also set sub production status "only" when main status is in production
                            3) Cancel "directly" DP order, means we not use doCancelOrder
                         */
                     $new_status = $item_do['status'];
                     $sub_status = $new_status == '4' ? $item_do['prod_status'] : '';
                     $class_do->updateStatus($item_do['depot_orders_id'], '12', 'auto-set');
                     $reviving_need_next_update = true;
                     $revived_stock_status = $item_do['stock_status'];
                     $revived_mode = 'MTO';
                 } else {
                     /* Order status is >= "in Package"
                           1) Set real status to New
                        */
                     $new_status = '1';
                 }
             }
         }
     }
     //Only "Sent" and "Complete" status can be updated to "Returned"
     if ($new_status == '14' && !($item['status'] == '9' || $item['status'] == '11')) {
         return false;
     }
     //KPI Logging
     if ($add_to_prod_target) {
         if ($new_status == '5') {
             $pt->addDataToField($timestamp, 'finish', $item['order_quantity']);
         }
         if ($new_status == '6') {
             $pt->addDataToField($timestamp, 'package', $item['order_quantity']);
         }
         if ($new_status == '7') {
             $pt->addDataToField($timestamp, 'sent', $item['order_quantity']);
         }
         if ($new_status == '16') {
             $pt->addDataToField($timestamp, 'log_return_to_bali', $item['order_quantity']);
         }
         if ($new_status == '19') {
             $pt->addDataToField($timestamp, 'log_return_missing', $item['order_quantity']);
         }
         if ($new_status == '20') {
             $pt->addDataToField($timestamp, 'log_return_to_bin_in', $item['order_quantity']);
         }
         if ($new_status == '9') {
             use_class('jng_sp');
             $class_jsp = new jng_sp();
             //Get Sales Partner B2B
             $sp_b2b = array_keys($class_jsp->retrieveList("sp_type = 1"));
             $item_orders = $this->retrieveDetail($item['jng_sp_orders_id']);
             if (in_array($item_orders['jng_sp_id'], $sp_b2b)) {
                 $pt->addDataToField($timestamp, 'log_products_sent_b2b', $item['order_quantity']);
             } else {
                 $pt->addDataToField($timestamp, 'log_products_sent_b2c', $item['order_quantity']);
             }
             if ($itemMode == 'DSO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_dso', $item['order_quantity']);
             } elseif ($itemMode == 'MTO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_mto', $item['order_quantity']);
             } elseif ($itemMode == 'WMO' || $itemMode == 'MMO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_mo', $item['order_quantity']);
             }
         }
     }
     $sub_status = trim(strtoupper($sub_status));
     if ($updater != 'new-import') {
         $setcancelation = $item['status'] == '10' && $new_status != '12' ? ", cancel_status=NULL" : '';
         if ($new_status == '10') {
             $setcancelation = ", cancel_status='{$cancelby}'";
         }
         $set_prod_status = $new_status == '4' && $sub_status != '' ? ", prod_status = '" . $sub_status . "'" : '';
         //PS: please don't set empty prod_status when it updated to status > 4,
         //since this will used for check whether order could transferred to DP or not
         //when real order taken over by HH when it from production
         tep_db_query("UPDATE jng_sp_orders_items SET status='{$new_status}' {$setcancelation} {$set_prod_status} WHERE jng_sp_orders_items_id={$items_id}");
     }
     $save_main_status_history = true;
     if (in_array($item['status'], array('3', '4', '5')) && $new_status == '4' && ($sub_status != '' && trim(strtoupper($item['prod_status'])) != $sub_status) || $is_reviving && $new_status == '4') {
         $psh = array();
         $psh['orders_items_id'] = $items_id;
         $psh['type'] = 'SP';
         $psh['status'] = $sub_status;
         $psh['status_quantity'] = $item['order_quantity'];
         $psh['status_date'] = $timestamp;
         $psh['update_by'] = $updater;
         saveProductionStatusHistory($psh);
         if ($item['status'] == '4') {
             $save_main_status_history = false;
         }
     }
     if ($save_main_status_history) {
         $sda = array();
         $sda['jng_sp_orders_items_id'] = $items_id;
         $sda['status'] = $new_status;
         $sda['status_quantity'] = $item['order_quantity'];
         $sda['status_date'] = $timestamp;
         $sda['update_by'] = $updater;
         tep_db_perform('jng_sp_orders_items_status_history', $sda);
     }
     if ($is_reviving) {
         //Revive Items from Cancel Request Status
         $this->recalculateOrderItemCount(null, $items_id);
         if ($new_status == '8') {
             $this->printCountReset($items_id);
             $this->updateOrderItemMode($items_id, 'MMO');
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, 'SP', $items_id);
             $do_close_status = explode(',', depot_orders::FILTER_STATUS_CLOSE);
             if (in_array($item_do['status'], $do_close_status)) {
                 $class_do->updateStatus($item_do['depot_orders_id'], '1');
                 $class_do->printCountReset($item_do['depot_orders_id']);
             }
         }
         if ($reviving_need_next_update) {
             $this->updateItemStockStatus($items_id, $revived_stock_status);
             if ($revived_mode != '') {
                 $this->updateOrderItemMode($items_id, $revived_mode);
             }
         }
         //Set need repackaging flag if needed
         $class_pm = new products_minierp();
         $p_data = $class_pm->retrieveDetail($item['products_id'], 'p');
         if ($p_data['p']['need_repackaging'] == 1) {
             $this->setNeedRepackaging($item['jng_sp_orders_id']);
         }
     }
     //Check other available products of this order which need repackage "nr" on cancel
     if ($new_status == '10') {
         $class_pm = new products_minierp();
         $need_repackaging = false;
         $nr_q = "SELECT products_id FROM jng_sp_orders_items WHERE jng_sp_orders_id = {$item['jng_sp_orders_id']} AND status NOT IN (10, 12)" . " AND jng_sp_orders_items_id != {$items_id}";
         $nr_dbq = tep_db_query($nr_q);
         while ($nr_r = tep_db_fetch_array($nr_dbq)) {
             $p_data = $class_pm->retrieveDetail($nr_r['products_id'], 'p');
             if ($p_data['p']['need_repackaging'] == 1) {
                 $need_repackaging = true;
                 break;
             }
         }
         if (!$need_repackaging) {
             $this->resetNeedRepackaging($item['jng_sp_orders_id']);
         }
     }
     //Update Stock Status and Elements Stock if necessary
     if ($new_status == '2' && $item['stock_status'] != 'S' && $item['stock_status'] != 'W') {
         //Set stock status to need sourcing if item is move to sourcing tab
         $this->updateItemStockStatus($items_id, false);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         //$this->printCountReset($items_id);    //now we don't need to reset print_count for reprint pi when move to ready again.
         //TODO: Ceck if above statement is still true with new batch pi printing
     } elseif ($new_status == '3' && $item['stock_status'] == 'S' || $new_status == '4' && $item['stock_status'] == 'W') {
         //Reduce elements stock when products are forced to move to ready/production before approved by elements stock check
         $eu = $this->countElementsUsage($item['products_id'], $item['products_articles_id']);
         if (count($eu) > 0) {
             $jng_warehouses_id = '1';
             use_class('elements_stock');
             $class_es = new elements_stock();
             foreach ($eu as $elements_id => $euqty) {
                 $reduce_amount = $item['order_quantity'] * $euqty;
                 $class_es->reduceStockByPieces($jng_warehouses_id, $elements_id, $reduce_amount, 'RED SP-' . $items_id);
             }
         }
         $this->updateItemStockStatus($items_id, 'R');
     } elseif ($new_status == '1') {
         //IF THERES ORDERS NEEDS RESET BACK TO NEW
         $this->printCountReset($items_id);
         $this->printConfirmReset($items_id);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         $this->updateItemStockStatus($items_id, 0);
         $this->updateOrderItemMode($items_id, 'UNSET');
     }
     //Production Target Flag Counter
     if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
         //TODO: Move TARGET IN TO WHEN PI IS CONFIRMED BY SCANNING IT FOR EAN LABEL
         $this->productionTargetIn($timestamp, $item);
     } elseif ($new_status == '6') {
         $this->productionTargetOut($timestamp, $item);
     } elseif ($new_status == '10') {
         $this->productionTargetInReset($item);
     }
     //Auto Print PI rules
     if ($new_status == '3' || $new_status == '12') {
         /* e.g. :
                    5 items ordered > 4 to ready, 1 to sourcing ( PI not printed yet )
                    so this block is for handling PI not printed when "1 sourcing" is cancelled, while print_count flag is still "0"
             * !!!ABOVE SAMPLE PROCESS ISN'T RELIABLE AGAIN, SINCE WE NOW CHANGE PRINT PI DIRECTLY WHEN IT MOVES TO READY TAB VIA CRON cron/print-pi.php!!!
            */
         $jng_sp_orders_id = $item['jng_sp_orders_id'];
         $q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM jng_sp_orders_items WHERE jng_sp_orders_id = {$jng_sp_orders_id} AND status = 3 AND print_count = 0 GROUP BY jng_sp_orders_id");
         $pi_status = tep_db_fetch_array($q_pi_status);
         if ($pi_status['pi_ready_to_print'] == 1) {
             //PI PRINTED FOR THE FIRST TIME
             /* HANDLED BY BATCH PRINTING CRON cron/print-pi.php
                use_class('production_instruction_pdf');
                $class_pi = new production_instruction_pdf();
                $class_pi->addOrder('SP', $jng_sp_orders_id);
                $class_pi->createPDF(false, 'F', true);
                 */
         } else {
             if ($item['print_count'] > 0 && $item['print_confirmed'] > 0) {
                 //SECOND OR MORE PI PRINTED, could happen when there product by stock_status is "OK" but in real stock is "0" so this will set back to "NS". And when ready this will reprinted by using this block
                 //reset print_count and print_confirmed to include this order again on next print-pi scheduler
                 $this->printConfirmReset($item['jng_sp_orders_items_id']);
                 $this->printCountReset($item['jng_sp_orders_items_id']);
                 /*
                                     use_class('production_instruction_pdf');
                                     $class_pi = new production_instruction_pdf();
                                     $class_pi->addItem('SP', $item['jng_sp_orders_items_id']);
                                     $class_pi->createPDF(false, 'F', false);    //not add to daily statistic, we consider this as not "NEW"
                 */
             }
         }
     }
     $q = tep_db_query("SELECT jo.jng_sp_orders_id, UPPER(jo.payment_method) AS payment_method FROM jng_sp_orders_items joi LEFT JOIN jng_sp_orders jo ON jo.jng_sp_orders_id=joi.jng_sp_orders_id WHERE joi.jng_sp_orders_items_id={$items_id}");
     $order = tep_db_fetch_array($q);
     if ($new_status == '12' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         /*----------------------------------------------------------------------------------------
           * MAKE RETURN ENTRY FOR "PREPAYMENT ONLY" ON "CANCEL CONFIRM", SINCE FOR NON-PREPAYMENT, 
           * PAYONE INVOICE WILL CREATED WHEN PRODUCTS IS SENT, 
           * SO NO NEED TO ADJUST IT OR CREATE RETURN CONTAINER WHEN CANCEL CONFIRM PROCESS
           -----------------------------------------------------------------------------------------*/
         use_class('payone');
         use_class('payone_invoice');
         $class_payone = new payone();
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             //UNCAPTURED PREAUTH PREPAYMENT NEED TO RECALCULATE INVOICE
             $payi->recalculate();
             //SET AS PAID WHEN OPEN BALANCE LEAVE SMALL AMOUNT OR THIS CANCEL PROCESS MAKES UNDERPAID BALANCE BECOMES PAID/OVERPAID
             if ($payi->getBalance() * 100 <= PAYONE_MAX_RETURNED_OPEN_PAYMENT) {
                 $this->updatePaymentStatus($item['jng_sp_orders_id'], '1', 'auto-set');
             }
         } else {
             //AUTH PREPAYMENT, CAPTURED PREAUTH PREPAYMENT (ADD TO RETURN CONTAINER)
             $class_payone->createReturnContainerSP('NULL', $item['order_quantity'], $items_id);
         }
     }
     //NEED TO RECALCULATE INVOICE WHEN REVIVING UNCAPTURED PREAUTH PREPAYMENT
     if ($is_reviving && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             $payi->recalculate();
         }
     }
     //SET READY TO CAPTURED FOR PREPAYMENT PREAUTH THAT ALREADY SENT
     if ($new_status == '9' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $item['jng_sp_orders_id'], "invoice_order_type = 'S'");
         $payi->setIsCaptured('2');
     }
     return $new_status;
 }
<?php

global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('products_minierp');
$class_pm = new products_minierp();
use_class('elements_stock');
$class_es = new elements_stock();
use_class('minierp_stock');
$class_ms = new minierp_stock();
$period = date('Ym');
//PRODUCTS
$total_products = array();
foreach ($class_ms->whid_by_status as $status => $jng_warehouses_id) {
    if ($status != '20') {
        if (!isset($total_products[$jng_warehouses_id])) {
            $total_products[$jng_warehouses_id] = array();
        }
        //JNG
        $q = tep_db_query("SELECT products_id, products_articles_id, products_quantity FROM orders_products WHERE status={$status}");
        while ($row = tep_db_fetch_array($q)) {
            $products_id = $row['products_id'];
            $articles_id = $row['products_articles_id'];
            if (!isset($total_products[$jng_warehouses_id][$products_id])) {
                $total_products[$jng_warehouses_id][$products_id] = array();
            }
            if (!isset($total_products[$jng_warehouses_id][$products_id][$articles_id])) {
                $total_products[$jng_warehouses_id][$products_id][$articles_id] = 0;
<?php

use_class('elements_stock');
use_class('elements_minierp');
use_class('elements_preorder');
$class_es = new elements_stock();
//WAREHOUSE OPTIONS
$session_page = 'elements-stock-update';
$whid = '1';
$history_options = array();
$history_options[] = '2 Weeks';
$history_options[] = '4 Weeks';
$history_options[] = '1 Month';
$history_options[] = '2 Months';
$history_options[] = '3 Months';
$history_options[] = '6 Months';
$history_options[] = '1 Year';
$history_options[] = '2 Years';
$history_options_2 = array();
$history_options_2[0] = 'in Details';
$history_options_2[1] = 'Daily Summary';
$reduce_reason = array();
$reduce_reason[] = 'You must select a reason';
$reduce_reason[] = 'Reject';
$reduce_reason[] = 'Replace Broken';
$reduce_reason[] = 'Sampling';
$reduce_reason[] = 'Manual Order';
$reduce_reason[] = 'Fix Wrong Entry';
$reduce_reason[] = 'Melting';
$reduce_reason[] = 'Need more than PI Qty';
$reduce_reason[] = 'Missing at Production';
<?php

$whid = 1;
$em_stch_reconfirm = 'Stock Suggestion has changed since you last access it, please reload tab and reconfirm request';
$currencies = array('IDR' => 'IDR', 'USD' => 'USD', 'EUR' => 'EUR');
use_class('element');
use_class('elements_attributes');
use_class('elements_suppliers');
use_class('elements_preorder');
use_class('elements_order');
use_class('elements_stock');
$class_es = new elements_stock();
$class_ea = new elements_attributes();
$session_page = 'sp-products-manage';
if (!isset($_SESSION[$session_page])) {
    $_SESSION[$session_page] = array();
    $_SESSION[$session_page]['ef-category'] = '0';
    $_SESSION[$session_page]['ef-supplier'] = '0';
}
$tabs = array();
$tabs['H'] = 'Scheduled Elements';
$tabs['M'] = 'Supermarkt Elements';
//$tabs['W'] = 'Inhouse Wax';
$tabs['R'] = 'Elements Request';
$tabs['P'] = 'PO New';
$tabs['O'] = 'PO Open';
$tabs['U'] = 'PO Unpaid';
$tabs['F'] = 'PO Closed';
$header_epo = array();
$header_epo['d w080 tac'] = 'First Added Date';
$header_epo['img'] = 'Image';
use_class('styles');
use_class('minierp_users');
use_class('production_instruction_manual');
use_class('jng_sp_catalog');
use_class('jng_sp_catalog_params');
use_class('depot_orders');
use_class('elements_stock');
$class_pm = new products_minierp();
$class_pa = new products_articles();
$class_pb = new products_brand();
$class_s = new styles();
$class_mu = new minierp_users();
$class_jc = new jng_sp_catalog();
$class_jcp = new jng_sp_catalog_params();
$class_do = new depot_orders();
$class_es = new elements_stock();
$ebay_name_max_chars = 80;
$ebay_language_id = '2';
function delete_extra_image($pei_id, $pei_name = '')
{
    global $uploaddir;
    $deletion = false;
    $del_image_query = tep_db_query("SELECT * FROM products_extra_images WHERE products_extra_images_id = {$pei_id}");
    $del_image = tep_db_fetch_array($del_image_query);
    $check_double_query = tep_db_query("SELECT * FROM products_extra_images WHERE products_extra_image = '{$del_image['products_extra_image']}'");
    if (tep_db_num_rows($check_double_query) <= 1) {
        if ($pei_name != $del_image['products_extra_image']) {
            $delete_file = $uploaddir . $del_image['products_extra_image'];
            if (file_exists($delete_file)) {
                $deletion = unlink($delete_file);
            } else {
Example #18
0
function cancelOrderStockHandler($type, $oiid, $stock_status, $status, $print_count, $print_confirmed, $products_id, $articles_id, $quantity, $is_promotion_order = false)
{
    global $STOCKLESS_ELEMENTS_CATEGORY;
    use_class('products_minierp');
    use_class('elements_stock');
    use_class('element');
    $class_pm = new products_minierp();
    $class_es = new elements_stock();
    $timestamp = date('Y-m-d H:i:s');
    if (in_array($status, array('1', '2', '3')) && $print_confirmed == 0 || $status == '8' && $print_count == 0) {
        switch ($stock_status) {
            case 'D':
                //DEPOT STOCK
                $class_pm->stockAdd(WAREHOUSE_ID_FOR_HANDLING_ORDERS, $products_id, $articles_id, $quantity, 'ADD CANCEL ' . $type . '-' . $oiid);
                break;
            case 'P':
                //FG STOCK
                $class_pm->stockAdd(WAREHOUSE_ID_PRODUCTS_BALI, $products_id, $articles_id, $quantity, 'ADD CANCEL ' . $type . '-' . $oiid);
                break;
            case 'R':
                //ELEMENTS STOCK
                $elements_used = array();
                $el_usage = $class_pm->retrieveElementsUsage($products_id, $articles_id);
                foreach ($el_usage as $e) {
                    $elements_used[$e['elements_id']] = $e['quantity'];
                }
                foreach ($elements_used as $eid => $el_qty) {
                    $el = new element($eid);
                    $el_cat_id = !is_null($el->attributes['category']['id']) ? $el->attributes['category']['id'] : '';
                    if (!in_array($el_cat_id, $STOCKLESS_ELEMENTS_CATEGORY)) {
                        $stock_qty = $quantity * $el_qty;
                        $current_stock = $class_es->addStockByPieces(WAREHOUSE_ID_ELEMENTS, $eid, $stock_qty, 'ADD CANCEL ' . $type . '-' . $oiid, $is_promotion_order);
                    }
                }
                break;
        }
    }
}
Example #19
0
                 $hcount++;
                 $htp = array();
                 $htp['sort'] = $hcount;
                 $htp['date_add'] = date('d.m.y H:i:s', $tsproductionstatus);
                 $htp['status'] = 'Production: ' . statusNameProduction($hp['status']);
                 $htp['login'] = $hp['update_by'];
                 $htable[] = $htp;
                 unset($history_prod[$hpk]);
             }
         }
     }
 }
 if ($do['status'] == '2') {
     use_class('element');
     use_class('elements_stock');
     $class_es = new elements_stock();
     $estock = $class_es->retrieveAll($whid_material);
     $sourcing_table = array();
     $eused = $class_pm->retrieveElementsUsage($do['products_id'], $do['articles_id']);
     $sourcing_info = '<div style="margin-top:20px;">';
     $sourcing_info .= '<h3>Sourcing Information</h3>';
     if (count($eused) > 0) {
         $sourcing_table = array();
         $st = array();
         $st['d'] = 'Image';
         $st['id1'] = 'Element ID';
         $st['a'] = 'Qty Required';
         $st['o'] = 'Stock Available';
         $sourcing_table[] = $st;
         foreach ($eused as $eid => $eu) {
             $colclass = '';