Example #1
0
//$logger->write('SIMULATION');
//Include Required Classes (and create object when necessary)
use_class('Product');
use_class('products_minierp');
use_class('depot_orders');
use_class('styles');
$class_pm = new products_minierp();
$class_do = new depot_orders();
$class_s = new styles();
$whid = WAREHOUSE_ID_FOR_HANDLING_ORDERS;
$segment_id = SEGMENT_ID_DEFAULT;
//Grab all data that can be retrieved collectively for the whole products
//stock from below function already exclude active booking
$products_stock = $class_pm->stockRetrieveAll($whid, '', true);
//Grab all required Settings
Product::loadDIOHsettings();
//For now we can not run auto cancel in Manobo Local due to the
//sync issues of Depot Orders with Manobo Central
if (!SERVER_IS_LOCAL) {
    //query all auto refill orders currently open
    //and can still be canceled(grouped by article)
    $logger->write('1) AUTO CANCEL');
    $logger->write('Query orders which can still be canceled:');
    $q = "SELECT products_id, articles_id, SUM(quantity) AS total_qty" . ", GROUP_CONCAT(depot_orders_id) AS order_ids" . ", GROUP_CONCAT(status) AS order_status" . " FROM depot_orders" . " WHERE trans_type = 'AR' AND" . " trans_id = " . depot_orders::AUTO_REFILL_ID_DAILYCRON . " AND (status IN (1,2,3) OR (status = 4 AND prod_status = 'P'))" . " GROUP BY products_id, articles_id";
    " ORDER BY products_id, articles_id";
    $r = tep_db_query($q);
    $total_found = tep_db_num_rows($r);
    $logger->write("{$total_found} article(s) found");
    if ($total_found > 0) {
        $canceled_qty_total = 0;
        while ($row = tep_db_fetch_array($r)) {