예제 #1
0
use_class('logger');
$logger = new logger('cron', 'depot-refill');
//$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) {
            $result .= writeXMLopen('P_PRODUCT_LINK', 1, 'type="' . $type . '"');
            $result .= writeXMLline('P_ID', $plt['links_id'], 2);
            if ($total_links > 1) {
                $pl_sort++;
                $result .= writeXMLline('LINK_SORT', $pl_sort, 2);
            }
            $result .= writeXMLclose('P_PRODUCT_LINK', 1);
        }
    }
    return $result;
}
if ($hour_now >= $HOURSTART && $hour_now <= $HOUREND) {
    $last_process_status = 'wait';
    //wait, doupload
    if (file_exists($upload_settings_file)) {
        $products_stock = $class_pm->stockRetrieveAll(WAREHOUSE_ID_PRODUCTS_HAMBURG);
        /* CONTENT OF $upload_settings_file (customizeable, please dont forget update also when writing to this file)
         * row 1 => total pid taken per next run
         * row 2 => upload status "OPEN, DONE"
         */
        $handle = fopen($upload_settings_file, "r+");
        $sf_contents = fread($handle, filesize($upload_settings_file));
        $sf_contents = explode("\n", $sf_contents);
        if (isset($sf_contents[0])) {
            $total_pids_taken_per_run = $sf_contents[0];
        }
        if (isset($sf_contents[1])) {
            $upload_status = $sf_contents[1];
        }
        if (isset($sf_contents[2])) {
            $process_runned = $sf_contents[2];
             echo implode("\t", array_keys($oi));
             echo "\n";
             $first = false;
         }
         echo implode("\t", $oi);
         echo "\n";
     }
 }
 echo '</pre>';
 exit;
 */
 $whid_depot = WAREHOUSE_ID_FOR_HANDLING_ORDERS;
 $whid_prod = WAREHOUSE_ID_PRODUCTS_BALI;
 $whid_elements = WAREHOUSE_ID_ELEMENTS;
 //LOAD PRODUCTS STOCK FROM DEPOT FROM DEFAULT WAREHOUSE
 $products_stock = $class_pm->stockRetrieveAll($whid_depot);
 $products_stock_booked = stock_booking::getBookedQuantityAll($whid_depot);
 //$products_stock_booked_instock:
 //this variable contains total products actually in stock (including the booked ones)
 //it is used for special orders allowed to override the booking status
 $products_stock_booked_instock = array();
 //Remove booked quantity from stock
 foreach ($products_stock as $k => $v) {
     if (isset($products_stock_booked[$k])) {
         $products_stock_booked_instock[$k] = $products_stock[$k];
         $products_stock[$k] = $products_stock_booked[$k] >= $products_stock[$k] ? 0 : $products_stock[$k] - $products_stock_booked[$k];
     }
 }
 //WE STOP CHECKING FOR BALI STOCK UNTIL FURTHER DISCUSSION
 //WE ARE NOW USING IT FOR KEEPING STOCK FOR LAZADA
 //16.10.2014 updated by Sahat
 $logger->write('OT.DE Stock Update Cron');
 $jng_sp_id = '2';
 use_class('jng_sp');
 use_class('jng_sp_catalog');
 use_class('jng_sp_upload');
 use_class('products_minierp');
 use_class('products_articles');
 use_class('stock_booking');
 $class_sp = new jng_sp();
 $class_jc = new jng_sp_catalog();
 $class_ju = new jng_sp_upload();
 $class_pm = new products_minierp();
 $class_pa = new products_articles();
 $sp_detail = $class_sp->retrieveDetail($jng_sp_id);
 $excluded_booked_qty = true;
 $products_stock = $class_pm->stockRetrieveAll(WAREHOUSE_ID_PRODUCTS_HAMBURG, '', $excluded_booked_qty);
 $o_products = $class_jc->retrieveCatalogForUpload($jng_sp_id, true);
 if (count($o_products) == 0) {
     $logger->write('No Products found');
 } else {
     $ean_format = false;
     //use "EAN" or "Product Code + Length" as ID
     //GRAB ALREADY REPORTED EAN
     $deleted_eans_reported = retrieveOTDEremovedEANList();
     $export_date = ottodeDateFormat(date('Y-m-d H:i:s'));
     $xml_content = '<?xml version="1.0" encoding="UTF-8"?>';
     $xml_content .= writeXMLopen('ottopartner', 0, 'xmlns="http://www.ottogroupb2b.com/ottopartner"');
     $xml_content .= writeXMLline('LKZ', $sp_detail['jng_id']);
     $xml_content .= writeXMLopen('Inventories');
     //CREATE XML ON SERVER
     $xml_filename = $sp_detail['jng_id'] . 'bestand' . ($ean_format ? '-per-ean' : 'daten') . '-' . date('YmdHi') . '.xml';