$price = 'item.retail_price'; $discount_manual = 0; } else { die_jsonp("Did not understand price."); } $q = "UPDATE txn_line, item\n SET txn_line.retail_price = {$price},\n txn_line.discount_type = {$discount_type},\n txn_line.discount = {$discount},\n txn_line.discount_manual = {$discount_manual}\n WHERE txn = {$txn_id} AND txn_line.id = {$id} AND txn_line.item = item.id"; $r = $db->query($q) or die_query($db, $q); } if (!empty($_REQUEST['quantity'])) { /* special case: #/# lets us split line with two quantities */ if (preg_match('!^(\\d+)/(\\d+)$!', $_REQUEST['quantity'], $m)) { $quantity = (int) $m[2] * ($txn['type'] == 'customer' ? -1 : 1); $q = "INSERT INTO txn_line (txn, item, ordered, override_name,\n retail_price, discount_type, discount,\n discount_manual, taxfree)\n SELECT txn, item, {$quantity}, override_name,\n retail_price, discount_type, discount, discount_manual, taxfree\n FROM txn_line WHERE txn = {$txn_id} AND txn_line.id = {$id}"; $r = $db->query($q) or die_query($db, $q); $quantity = (int) $m[1]; } else { $quantity = (int) $_REQUEST['quantity']; } $q = "UPDATE txn_line\n SET ordered = -1 * {$quantity}\n WHERE txn = {$txn_id} AND txn_line.id = {$id}"; $r = $db->query($q) or die_query($db, $q); } if (isset($_REQUEST['name'])) { $name = $db->real_escape_string($_REQUEST['name']); $q = "UPDATE txn_line\n SET override_name = IF('{$name}' = '', NULL, '{$name}')\n WHERE txn = {$txn_id} AND txn_line.id = {$id}"; $r = $db->query($q) or die_query($db, $q); } txn_apply_discounts($db, $txn_id) or die_jsonp("Failed to apply discounts."); $db->commit() or die_query($db, "COMMIT"); $items = txn_load_items($db, $txn_id); $txn = txn_load($db, $txn_id); echo jsonp(array('txn' => $txn, 'items' => $items));
<?php include '../scat.php'; include '../lib/txn.php'; $id = (int) $_REQUEST['txn']; if (!$id) { die_jsonp("no transaction specified."); } if (!txn_apply_discounts($db, $id)) { die_jsonp("Unable to apply discounts."); } $txn = txn_load_full($db, $id); echo jsonp($txn);
<?php include '../scat.php'; include '../lib/txn.php'; $details = array(); $txn_id = (int) $_REQUEST['txn']; $id = (int) $_REQUEST['id']; if (!$txn_id || !$id) { die_jsonp('No transaction or item specified'); } $txn = txn_load($db, $txn_id); if ($txn['paid']) { die_jsonp("This order is already paid!"); } $q = "DELETE FROM txn_line WHERE txn = {$txn_id} AND id = {$id}"; $r = $db->query($q); if (!$r) { die_query($db, $q); } if (!$db->affected_rows) { die_jsonp("Unable to delete line."); } // XXX error handling txn_apply_discounts($db, $txn_id); $txn = txn_load_full($db, $txn_id); $txn['removed'] = $id; echo jsonp($txn);