function person_load($db, $id) { $q = "SELECT id, \n name,\n role,\n company,\n address,\n email,\n phone,\n tax_id,\n payment_account_id,\n active,\n deleted\n FROM person\n WHERE id = {$id}"; $r = $db->query($q) or die_query($db, $q); $person = $r->fetch_assoc(); return $person; }
<?php include '../scat.php'; include '../lib/eps-express.php'; $person = (int) $_REQUEST['person']; $payment_account_id = $_REQUEST['payment_account_id']; if (!$person) { die_jsonp("Person was not specified."); } $ReturnURL = ($_SERVER['HTTPS'] ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/cc-attach-finish.php'; $eps = new EPS_Express(); if ($payment_account_id) { $response = $eps->PaymentAccountUpdateHosted($person, $payment_account_id, $ReturnURL); } else { $response = $eps->PaymentAccountCreateHosted($person, $ReturnURL); } $payment = $db->escape($response->Transaction->TransactionSetupID); $valid = $db->escape($response->TransactionSetup->ValidationCode); $q = "INSERT INTO hostedpayment_txn\n SET txn = {$person},\n hostedpayment = '{$payment}',\n validationcode = '{$valid}',\n created = NOW()"; $db->query($q) or die_query($db, $q); $url = "https://certtransaction.hostedpayments.com/?TransactionSetupID=" . $response->Transaction->TransactionSetupID; echo jsonp(array('url' => $url, 'response' => $response));
$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));
include '../scat.php'; include '../lib/txn.php'; $type = $_REQUEST['type']; if (!in_array($type, array('correction', 'vendor', 'customer', 'drawer'))) { die_json("Requested type not understood."); } $type = $db->escape($type); $q = "START TRANSACTION;"; $r = $db->query($q); if (!$r) { die_query($db, $q); } $q = "SELECT 1 + MAX(number) AS number FROM txn WHERE type = '{$type}'"; $number = $db->get_one($q); $tax_rate = $type == 'customer' ? DEFAULT_TAX_RATE : 0; $person = (int) $_REQUEST['person']; if (!$person) { $person = 'NULL'; } $q = "INSERT INTO txn\n SET created= NOW(),\n type = '{$type}',\n number = {$number},\n person = {$person},\n tax_rate = {$tax_rate}"; $r = $db->query($q); if (!$r) { die_query($db, $q); } $txn_id = $db->insert_id; $r = $db->commit(); if (!$r) { die_query($db, "COMMIT"); } $txn = txn_load($db, $txn_id); echo jsonp(array('txn' => $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);
public function removePayment($payment, $override) { if ($this->paid && !$override) { throw new Exception("Transaction is fully paid, can't remove payments."); } $this->db->start_transaction() or die_query($this->db, "START TRANSACTION"); // add payment record $q = "DELETE FROM payment WHERE id = {$payment} AND txn = {$this->id}"; $r = $this->db->query($q) or die_query($this->db, $q); if ($this->paid) { $q = "UPDATE txn SET paid = NULL WHERE id = {$this->id}"; $r = $this->db->query($q) or die_query($this->db, $q); } $this->db->commit() or die_query($this->db, "COMMIT"); return true; }