Пример #1
0
function printBatches($pid, $batches, $suffix_counter, $use_red_paper = false)
{
    global $logger, $output, $ignoreStockStatusDepot, $add_to_daily_statistic, $max_item_per_pi, $pi_batches_path, $file_prefix, $pi_created;
    $logger->write('PREPARING PRODUCT ID ' . $pid . ' - Suffix ' . $suffix_counter . ' - ' . ($use_red_paper ? 'Red' : 'Normal') . ' Paper');
    $file_suffix = "_{$suffix_counter}";
    $filename = 'batches-' . ($use_red_paper ? 'RED' : '') . $file_prefix . $pid . $file_suffix;
    $logger->write("PREPARING PI FILE: {$filename}.pdf");
    $pi_pdf = new production_instruction_pdf(false);
    $pi_pdf->filename = $pi_batches_path . $filename;
    $n_item = 0;
    foreach ($batches as $key => $dt) {
        $n_item++;
        list($type, $oiid) = explode('|', $dt);
        //$pi_pdf->addOrder($type, $oid);
        $pi_pdf->addItem($type, $oiid);
        $logger->write("{$type}-{$oiid} ADDED");
        $pi_created++;
        unset($batches[$key]);
        if ($n_item >= $max_item_per_pi && $n_item % $max_item_per_pi == 0) {
            $suffix_counter--;
            printBatches($pid, $batches, $suffix_counter, $use_red_paper);
            break 1;
        }
    }
    //asort($pi_pdf->orders);
    //$pi_pdf->createPDF(true, $output, true, false);
    $pi_pdf->createPDF($ignoreStockStatusDepot, $output, $add_to_daily_statistic, false);
    $logger->write("PI FILE CREATED:  {$filename}.pdf");
    echo ". ";
}
        $class_pi = new production_instruction();
        $orders_id = explode(',', $id);
        $class_pi->loadOrders($type, $orders_id);
        if (count($class_pi->orders_products) > 0) {
            echo $class_pi->printProductionInstruction();
        } else {
            echo '<h1>There is no product to print</h1>';
        }
    }
} elseif (isset($_GET['opid']) && $_GET['opid'] != '') {
    if ($method == '') {
        use_class('jng_sp_orders');
        use_class('orders');
        use_class('depot_orders');
        use_class('production_instruction_pdf');
        $class_pi = new production_instruction_pdf();
        $opids = explode(',', $_GET['opid']);
        foreach ($opids as $opid) {
            $type = strtoupper($type);
            $orders = array();
            $orders_id = '';
            if ($type == 'SP') {
                $class_jo = new jng_sp_orders();
                $orders = $class_jo->retrieveItemDetail($opid);
                $orders_id = $orders['jng_sp_orders_id'];
            } elseif ($type == 'JG') {
                $class_o = new orders();
                $orders = $class_o->retrieveProductDetail($opid);
                $orders_id = $orders['orders_id'];
            } elseif ($type == 'DP') {
                $class_do = new depot_orders();
$q .= " HAVING SUM(op.products_quantity) = op.order_item_total";
$q .= " ORDER BY o.date_purchased ,o.orders_id";
$dbq = tep_db_query($q);
$type = 'JG';
$njg = 0;
while ($r = tep_db_fetch_array($dbq)) {
    $orders_id = $r['orders_id'];
    $class_pi = new production_instruction_pdf();
    $class_pi->addOrder($type, $orders_id);
    $class_pi->createPDF(false, $output, $add_to_daily_statistic);
    echo "create {$type}-PI {$orders_id}<br/>";
    $njg++;
}
echo "<h3>{$njg} JG-PI created</h3>";
//DP
$q = "SELECT depot_orders_id FROM depot_orders";
$q .= " WHERE order_date BETWEEN DATE('{$start_date}') AND DATE('{$end_date}')";
$q .= " and status = 3";
$q .= " ORDER BY depot_orders_id";
$dbq = tep_db_query($q);
$type = 'DP';
$ndp = 0;
while ($r = tep_db_fetch_array($dbq)) {
    $orders_id = $r['depot_orders_id'];
    $class_pi = new production_instruction_pdf();
    $class_pi->addOrder($type, $orders_id);
    $class_pi->createPDF(false, $output, $add_to_daily_statistic);
    echo "create {$type}-PI {$orders_id}<br/>";
    $ndp++;
}
echo "<h3>{$ndp} DP-PI created</h3>";
Пример #4
0
<?php

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();
$allowed_type = array('DP', 'SP', 'JG');
$order_type = strtoupper($_GET['type']);
$order_id = intval($_GET['id']);
if (in_array($order_type, $allowed_type) && $order_id > 0) {
    use_class('production_instruction_pdf');
    $class_pi = new production_instruction_pdf();
    $class_pi->addOrder($order_type, $order_id);
    $class_pi->createPDF(false, 'F');
    $message = 'PI Printed!';
} else {
    $message = 'BAD REQUEST:';
}
echo '<strong>' . $message . ':</strong><br />';
echo 'Order Type = ' . $order_type . '<br />';
echo 'Order ID = ' . $order_id . '<br />';
tep_db_close();
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
require_once DIR_WS_FUNCTIONS . 'html_output.php';
tep_db_connect();
$type = $_GET['type'];
$orders_id = $_GET['oid'];
$orders_items_id = $_GET['oiid'];
if ($orders_items_id == '') {
    $orders_items_id = null;
}
$output = isset($_GET['output']) && $_GET['output'] != '' ? $_GET['output'] : 'D';
$add_to_daily_statistic = isset($_GET['atds']) && $_GET['atds'] != '' ? $_GET['atds'] : false;
$ignoreStockStatusDepot = false;
if ($type != '') {
    use_class('production_instruction_pdf');
    $class_pi = new production_instruction_pdf(false);
    //ADD ITEMS OR ORDER
    if ($orders_id == '' && !is_null($orders_items_id)) {
        $oiids = !is_array($orders_items_id) ? explode(',', $orders_items_id) : $orders_items_id;
        foreach ($oiids as $oiid) {
            $class_pi->addItem($type, $oiid);
        }
    } else {
        $class_pi->addOrder($type, $orders_id, $orders_items_id);
    }
    //PRODUCE PDF
    $class_pi->createPDF($ignoreStockStatusDepot, $output, $add_to_daily_statistic);
}
tep_db_close();
//$type_settings['KEY'] = 'ID-COLUMNNAME|TABLE-NAME';
$type_settings['DP'] = 'depot_orders_id|depot_orders';
$type_settings['SP'] = 'jng_sp_orders_items_id|jng_sp_orders_items';
$type_settings['JG'] = 'orders_products_id|orders_products';
//Prepare union query for all tables
$query = array();
foreach ($type_settings as $type => $settings) {
    list($colname, $table) = explode('|', $settings);
    $q = "SELECT '{$type}' AS type, {$colname} AS item_id FROM {$table} WHERE status=3 AND print_count>0 AND print_confirmed=0";
    //Exclude Outsourcing Orders
    if ($type == 'DP') {
        $q .= " AND NOT (trans_type='' AND trans_id=" . depot_orders::MANUAL_REFILL_OUTSOURCED . ")";
    }
    $query[] = $q;
}
//Run query
$r = tep_db_query(implode(' UNION ALL ', $query));
$total_found = tep_db_num_rows($r);
$logger->write("{$total_found} items found for reprint");
//TODO: should we prevent reprint if number is too big???
while ($row = tep_db_fetch_array($r)) {
    //Rerint PI for each item
    $pi = new production_instruction_pdf();
    $pi->addItem($row['type'], $row['item_id']);
    $pi->createPDF($ignoreStockStatusDepot, $output, $add_to_daily_statistic);
    $logger->write("{$row['type']}-{$row['item_id']} recreated");
    //keep alive
    echo '. ';
}
$logger->close();
echo 'Done!';