Exemplo n.º 1
0
function retrieveProductionHistory($type, $oiid, $filter = '')
{
    $query = "SELECT * FROM production_status_history WHERE type = '{$type}' AND orders_items_id={$oiid}";
    if ($filter != '') {
        $query .= " AND {$filter}";
    }
    $query .= " ORDER BY status_date ASC";
    $ph_query = tep_db_query($query);
    $ph = array();
    if (tep_db_num_rows($ph_query) > 0) {
        while ($row = tep_db_fetch_array($ph_query)) {
            $ph[] = $row;
        }
    } elseif ($type != 'DP') {
        //CEK DEPOT ORDERS
        use_class('depot_orders');
        $class_do = new depot_orders();
        $do = $class_do->retrieveDetailTransmigran($type, $oiid);
        if (!is_null($do)) {
            $ph = retrieveProductionHistory('DP', $do['depot_orders_id'], $filter);
        }
    }
    return $ph;
}
function oiErrorStatus($item_status)
{
    //STATUS MISMATCH HANDLER
    global $order_type, $item_id, $status_current, $status_new, $user_name, $class_do, $class_jo, $class_o, $status_name;
    $result = '';
    $add_info = '';
    if ($item_status == 'OUTSOURCING-2-PRODUCTION') {
        $result = 'ERROR: Outsourcing Orders, can not set to Production!';
    } else {
        //error when set to production
        if ($item_status == 4 || $status_current == 3 && $status_new == 4 || !is_numeric($status_new)) {
            //get additional information to be displayed on MC error message
            if ($order_type == 'SP') {
                $item = $class_jo->retrieveItemDetail($item_id);
                $item_history = $class_jo->retrieveItemHistory($item_id);
            } elseif ($order_type == 'JG') {
                $item = $class_o->retrieveProductDetail($item_id);
                $item_history = $class_o->retrieveProductHistory($item_id);
            } elseif ($order_type == 'DP') {
                $item = $class_do->retrieveDetail($item_id);
                $item_history = $class_do->retrieveHistory($item_id);
            }
            $last_history = end($item_history);
            $last_production_history = end(retrieveProductionHistory($order_type, $item_id));
            $now = time();
            if ($order_type == 'SP' || $order_type == 'JG') {
                $last_status_time = strtotime($last_production_history['status_date']) > strtotime($last_history['status_date']) ? $last_production_history['status_date'] : $last_history['status_date'];
            } elseif ($order_type == 'DP') {
                $last_status_time = strtotime($last_production_history['update_time']) > strtotime($last_history['update_time']) ? $last_production_history['update_time'] : $last_history['update_time'];
            }
            $time_duration = abs($now - strtotime($last_status_time));
            //if more than 10 minutes
            $timedur = displayDuration($time_duration, 1, 0);
            $add_info = ",\nmoved since{$timedur} ago";
            if (floor($time_duration / 60) > 10 && $item['status'] == '4') {
                //display information on which tab this order processed on production
                $line_status = statusNameProduction($item['prod_status'], false, true);
                if ($line_status != '') {
                    $add_info .= ",\nplease check {$line_status}.";
                }
            }
        }
        if (!is_numeric($item_status)) {
            //Error Message for Production Sub Status
            $result = "ERROR: Status is now " . statusNameProduction($item_status, false, true) . $add_info;
        } else {
            $status_depos_sent_cancel = array('8', '9', '10', '11', '12', '14', '15', '16', '17', '18', '19', '20', '21');
            $status_new_temp = explode('-', $status_new);
            $sub_status = isset($status_new_temp[1]) ? $status_new_temp[1] : '';
            if ($order_type != 'DP' && in_array($item_status, $status_depos_sent_cancel)) {
                //If Not a Depot Order AND Current Product Status is handled by HH
                if ($status_current == '3' && ($status_new == '4' || !is_numeric($status_new))) {
                    //FOR SET2PROD RULE
                    /* Stop process when:
                           1) Real order taken over by HH and already have stock allocated     "set2prod_rule1"
                           2) or Real order already proceed by HH (status >= 9 "sent")         "set2prod_rule2"
                       */
                    $set2prod_rule1 = $item_status == '8' && $item['stock_status'] == 'D';
                    $set2prod_rule2 = $item_status != '8';
                    if ($set2prod_rule1 || $set2prod_rule2) {
                        $ok_for_production = false;
                    } else {
                        $ok_for_production = true;
                    }
                    $item_do = $class_do->retrieveDetailTransmigran($order_type, $item_id);
                    if ($ok_for_production) {
                        if (is_null($item_do)) {
                            if (realOrderIsPossibleToTransferred($order_type, $item_id)) {
                                //Transfer to DP if order is possible to transferred
                                $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, $order_type, $item_id);
                                $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                                $result = "MOVEDTODEPOT";
                            } else {
                                $result = "ERROR: {$order_type}-{$item_id} could not transferred to Depot Orders!\nplease make sure order scanned is correct!";
                            }
                        } else {
                            //If MMO then update Depot Order Status
                            if ($item_do['status'] == $status_current || $item_do['status'] == $status_new_temp[0]) {
                                //SET2PRODSUBSTATUS
                                if (!is_numeric($status_new)) {
                                    //If DP already in same sub status or status in Production or more
                                    if ($item_do['prod_status'] == $sub_status || $item_do['status'] >= 4) {
                                        $result = "ERROR: Status is now " . statusNameProduction($item_do['prod_status'], false, true) . $add_info;
                                    } else {
                                        $class_do->updateStatus($item_do['depot_orders_id'], "{$status_new}", $user_name);
                                        $result = "MOVEDTODEPOT";
                                    }
                                } else {
                                    //If Depot Order Status match OR Depot Order Status already updated
                                    //Update Order Status only if it's match and not already updated
                                    if ($item_do['status'] == $status_current) {
                                        $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                                    }
                                    $result = "MOVEDTODEPOT";
                                }
                            } else {
                                $result = "ERROR: Status is now " . $status_name[$item_do['status']] . $add_info;
                            }
                        }
                    } else {
                        if (!is_null($item_do)) {
                            $class_do->doCancelOrders($item_do['depot_orders_id'], $item_do['status'], 'auto-set');
                        }
                        $result = "(HH) CANCEL PRODUCTION!";
                    }
                } elseif ($status_current == '4' && !is_numeric($status_new)) {
                    //FOR SET2BETWEENPRODSUBSTATUS RULE
                    $item_do = $class_do->retrieveDetailTransmigran($order_type, $item_id);
                    if (is_null($item_do)) {
                        //check from last status on production to decide whether process need to continue or stop
                        $prod_histories = retrieveProductionHistory($order_type, $item_id);
                        $n_histories = count($prod_histories);
                        $ok_for_production = true;
                        if ($n_histories > 0) {
                            $last_status_prod_hist = $prod_histories[$n_histories - 1];
                            $last_status_on_prod = $last_status_prod_hist['status'];
                            //stop process when last status is order still on Pullrack
                            if ($last_status_on_prod == 'P') {
                                $ok_for_production = false;
                            }
                        }
                        if ($ok_for_production) {
                            if (realOrderIsPossibleToTransferred($order_type, $item_id)) {
                                //Transfer to DP if order is possible to transferred
                                $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, $order_type, $item_id);
                                $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                                $result = "MOVEDTODEPOT";
                            } else {
                                $result = "ERROR: {$order_type}-{$item_id} could not transferred to Depot Orders!\nplease make sure order scanned is correct!";
                            }
                        } else {
                            $result = "(HH) CANCEL PRODUCTION!";
                        }
                    } else {
                        /* Stop process when: 
                           *  1) - Depot Orders still in Pullrack                                  "setbetweenprod_rule1"
                           * and:
                              2) Real order taken over by HH and already have stock allocated      "setbetweenprod_rule2"
                              3) or Real order already proceed by HH (status >= 9 "sent")          "setbetweenprod_rule3"
                           */
                        $setbetweenprod_rule1 = $item_do['prod_status'] == 'P';
                        $setbetweenprod_rule2 = $item_status == '8' && $item['stock_status'] == 'D';
                        $setbetweenprod_rule3 = $item_status != '8';
                        if ($setbetweenprod_rule1 && ($setbetweenprod_rule2 || $setbetweenprod_rule3)) {
                            $ok_for_production = false;
                        } else {
                            $ok_for_production = true;
                        }
                        if ($ok_for_production) {
                            if ($item_do['status'] == '4') {
                                //If order moved between sub tab production
                                if ($item_do['prod_status'] == $sub_status) {
                                    //Not updating the status if order is on the same sub status production - including lines
                                    $result = "ERROR: Status is now " . statusNameProduction($sub_status, false, true) . $add_info;
                                } else {
                                    //Order moved to other sub status, then update it's production sub status to the new status
                                    $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                                    $result = 'Updated Successfully';
                                }
                            } else {
                                /*
                                    EXCEPT revived orders, Shows error if order is not from production but tried to set back to production status
                                    NOTES >> revived MTO orders which already have DP and at that moment status of DP was >= Package then manobo will set:
                                    "Real order to status New and let DP status as it is" ...
                                    But then, when real order taken over by HH so we need to used already created DP for status changes...
                                    ...this is actually the reason why we allowed revived orders
                                */
                                if (orderIsRevived($order_type, $item_id)) {
                                    $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                                    $result = 'Updated Successfully';
                                } else {
                                    $result = "ERROR: Status is now " . $status_name[$item_do['status']] . $add_info;
                                }
                            }
                        } else {
                            if (!is_null($item_do)) {
                                $class_do->doCancelOrders($item_do['depot_orders_id'], $item_do['status'], 'auto-set');
                            }
                            $result = "(HH) CANCEL PRODUCTION!";
                        }
                    }
                } elseif ($status_current == '4' && $status_new == '5') {
                    //FOR SET2FINISH RULE
                    if (realOrderIsPossibleToTransferred($order_type, $item_id)) {
                        $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, $order_type, $item_id);
                        $class_do->updateStatus($item_do['depot_orders_id'], $status_new, $user_name);
                        $result = "(HH) PUT PRODUCT TO DEPO BOX";
                    } else {
                        $result = "ERROR: {$order_type}-{$item_id} could not transferred to Depot Orders!\nplease make sure order scanned is correct!";
                    }
                }
            } elseif ($item_status == '4' && $status_new != '' && !is_numeric($status_new) && $item['prod_status'] != $sub_status) {
                if ($sub_status == 'P') {
                    //Production Pullrack only allowed for order moved from ready tab to production, other will be rejected
                    $result = "ERROR: Status is now " . $status_name[$item_status] . $add_info;
                } else {
                    //moved between prod sub status >> $status_new is production sub status (S1..Sn, A, L)
                    if ($order_type == 'SP') {
                        $item = $class_jo->retrieveItemDetail($item_id);
                        $class_jo->updateItemStatus($item_id, $status_new, $user_name);
                    } elseif ($order_type == 'JG') {
                        $item = $class_o->retrieveProductDetail($item_id);
                        $class_o->updateProductStatus($item_id, $status_new, $user_name);
                    } elseif ($order_type == 'DP') {
                        $item = $class_do->retrieveDetail($item_id);
                        $class_do->updateStatus($item_id, $status_new, $user_name);
                    }
                    $result = 'Updated Successfully';
                }
            }
        }
    }
    if ($result == '') {
        $result = "ERROR: Status is now " . $status_name[$item_status] . $add_info;
    }
    return $result;
}
Exemplo n.º 3
0
<?php

use_class('jng_sp_orders');
$class_jo = new jng_sp_orders();
use_class('products_minierp');
$class_pm = new products_minierp();
$oi_id = tep_db_prepare_input($_GET['oi_id']);
$statusName = $class_jo->statusName();
$item = $class_jo->retrieveItemDetail($oi_id);
$product = $class_pm->retrieveDetail($item['products_id'], 'p');
$order = $class_jo->retrieveDetail($item['jng_sp_orders_id']);
$history = $class_jo->retrieveItemHistory($oi_id);
$history_prod = retrieveProductionHistory('SP', $oi_id);
$htable = array();
$ht = array();
$ht['sort'] = 'No';
$ht['date_add'] = 'Date';
$ht['status'] = 'Status';
//$ht['qty'] = 'Qty';
$ht['login'] = '******';
$htable[] = $ht;
$count = 0;
$total_history = count($history);
$prev_info = array();
foreach ($history as $hk => $h) {
    $count++;
    $timestamp = strtotime($h['status_date']);
    $ht = array();
    $ht['sort'] = $count;
    $ht['date_add'] = date('d.m.y H:i:s', $timestamp);
    $ht['status'] = $statusName[$h['status']];
Exemplo n.º 4
0
<?php

use_class('orders');
$class_o = new orders();
use_class('products_minierp');
$class_pm = new products_minierp();
$opid = tep_db_prepare_input($_GET['opid']);
$statusName = $class_o->productStatusName();
$item = $class_o->retrieveProductDetail($opid);
$product = $class_pm->retrieveDetail($item['products_id'], 'p');
$order = $class_o->retrieveDetail($item['orders_id']);
$history = $class_o->retrieveProductHistory($opid);
$history_prod = retrieveProductionHistory('JG', $opid);
$htable = array();
$ht = array();
$ht['sort'] = 'No';
$ht['date_add'] = 'Date';
$ht['status'] = 'Status';
//$ht['qty'] = 'Qty';
$ht['login'] = '******';
$htable[] = $ht;
$count = 0;
$total_history = count($history);
$prev_info = array();
foreach ($history as $hk => $h) {
    $count++;
    $timestamp = strtotime($h['status_date']);
    $ht = array();
    $ht['sort'] = $count;
    $ht['date_add'] = date('d.m.y H:i:s', $timestamp);
    $ht['status'] = $statusName[$h['status']];
Exemplo n.º 5
0
     $otrans = $class_jo->retrieveDetail($itrans['jng_sp_orders_id']);
     $bih_start_date = $otrans['order_date'];
     $order_source = $class_do->translateOrderSource($do['trans_type'], $do['trans_id'], false, $itrans['jng_sp_orders_id'], $do['products_id']);
 } elseif ($do['trans_type'] == 'JG') {
     use_class('orders');
     $class_o = new orders();
     $itrans = $class_o->retrieveProductDetail($do['trans_id']);
     $otrans = $class_o->retrieveDetail($itrans['orders_id']);
     $bih_start_date = $otrans['date_purchased'];
     $order_source = $class_do->translateOrderSource($do['trans_type'], $do['trans_id'], false, $itrans['orders_id'], $do['products_id']);
 } else {
     $order_source = $class_do->translateOrderSource($do['trans_type'], $do['trans_id'], false, null, $do['products_id']);
 }
 $status_date = null;
 $history = $class_do->retrieveHistory($order_id);
 $history_prod = retrieveProductionHistory('DP', $order_id);
 $htable = array();
 $ht = array();
 $ht['sort'] = 'No';
 $ht['date_add'] = 'Date';
 $ht['status'] = 'Status';
 $ht['login'] = '******';
 $htable[] = $ht;
 $hcount = 1;
 $ht = array();
 $ht['sort'] = $hcount;
 $ht['date_add'] = date('d.m.y H:i:s', $do_timestamp);
 $ht['status'] = $statusName[1];
 $ht['login'] = '******';
 $htable[] = $ht;
 $total_history = count($history);