コード例 #1
0
ファイル: txn-allocate.php プロジェクト: jacques/scat
include '../scat.php';
include '../lib/txn.php';
include '../lib/pole.php';
$id = (int) $_REQUEST['txn'];
if (!$id) {
    die_jsonp("no transaction specified.");
}
$txn = txn_load($db, $id);
if ($txn['paid']) {
    die_jsonp("This order is already paid!");
}
$line = (int) $_REQUEST['line'];
if ($line) {
    $q = "UPDATE txn_line SET allocated = ordered WHERE txn = {$id} AND id = {$line}";
    $r = $db->query($q) or die_jsonp($db->error);
    $lines = $db->affected_rows;
} else {
    $q = "UPDATE txn_line SET allocated = ordered WHERE txn = {$id}";
    $r = $db->query($q) or die_jsonp($db->error);
    $lines = $db->affected_rows;
    if ($lines || !$txn['filled']) {
        $q = "UPDATE txn SET filled = NOW() WHERE id = {$id}";
        $r = $db->query($q) or die_jsonp($db->error);
    }
}
$txn = txn_load($db, $id);
if ($txn['total']) {
    pole_display_price('Total Due', $txn['total']);
}
echo jsonp(array("success" => "Allocated all lines.", "txn" => $txn, "lines" => $lines, "items" => txn_load_items($db, $id)));
コード例 #2
0
ファイル: txn-add-item.php プロジェクト: jacques/scat
        $items[0]['line_id'] = $row['id'];
        /* if found via barcode, we may have better quantity */
        $quantity = 1;
        if ($items[0]['barcode'][$search]) {
            $quantity = $items[0]['barcode'][$search];
        }
        $items[0]['quantity'] = -1 * ($row['ordered'] - $quantity);
        $q = "UPDATE txn_line SET ordered = -1 * {$items[0]['quantity']}\n          WHERE id = {$items[0]['line_id']}";
        $r = $db->query($q);
        if (!$r) {
            die_query($db, $q);
        }
    } else {
        $q = "INSERT INTO txn_line (txn, item, ordered,\n                               retail_price, discount, discount_type, taxfree)\n         SELECT {$txn_id} AS txn, {$items[0]['id']} AS item, -1 AS ordered,\n                retail_price, discount, discount_type, taxfree\n           FROM item WHERE id = {$items[0]['id']}";
        $r = $db->query($q);
        if (!$r) {
            die_query($db, $q);
        }
        $items[0]['line_id'] = $db->insert_id;
    }
    // XXX error handling
    txn_apply_discounts($db, $txn_id);
    if ($txn['type'] == 'customer' && $items[0]['sale_price']) {
        pole_display_price($items[0]['name'], $items[0]['sale_price']);
    }
    $txn = txn_load($db, $txn_id);
    $items = txn_load_items($db, $txn_id);
    echo jsonp(array('txn' => $txn, 'items' => $items));
} else {
    echo jsonp(array('matches' => $items));
}