Ejemplo n.º 1
0
Archivo: txn.php Proyecto: jacques/scat
function txn_apply_discounts($db, $id)
{
    $txn = txn_load($db, $id);
    if (!$txn || $txn['paid']) {
        // XXX better error handling
        return false;
    }
    // Not an error, but we don't do anything
    if ($txn['type'] != 'customer') {
        return true;
    }
    // XXX store this somewhere else, obviously
    $discounts = array('MXG-%' => array(12 => '6.99', 36 => '6.49'), 'MXB-%' => array(12 => '5.99', 36 => '5.49'), 'MTEX%' => array(12 => '5.99', 36 => '5.49'), 'SKXSDK%' => array(12 => '2.49'));
    foreach ($discounts as $code => $breaks) {
        $count = $db->get_one("SELECT ABS(SUM(ordered))\n                            FROM txn_line\n                            JOIN item ON txn_line.item = item.id\n                           WHERE txn = {$id}\n                             AND code LIKE '{$code}'\n                             AND NOT discount_manual");
        $new_discount = 0;
        foreach ($breaks as $qty => $discount) {
            if ($count >= $qty && (!$new_discount || $discount < $new_discount)) {
                $new_discount = $discount;
            }
        }
        if ($new_discount) {
            $q = "UPDATE txn_line, item\n              SET txn_line.discount = {$new_discount},\n                  txn_line.discount_type = 'fixed'\n            WHERE txn = {$id} AND txn_line.item = item.id\n              AND code LIKE '{$code}'\n              AND NOT discount_manual";
        } else {
            $q = "UPDATE txn_line, item\n              SET txn_line.discount = item.discount,\n                  txn_line.discount_type = item.discount_type\n            WHERE txn = {$id} AND txn_line.item = item.id\n              AND code LIKE '{$code}'\n              AND NOT discount_manual";
        }
        $db->query($q) or die_query($db, $q);
    }
    return true;
}
Ejemplo n.º 2
0
<?php

require '../scat.php';
require '../lib/txn.php';
$id = (int) $_REQUEST['id'];
if (!$id) {
    die("No transaction specified.");
}
date_default_timezone_set('America/Los_Angeles');
$details = txn_load($db, $id);
?>
<html>
<head>
 <title><?php 
echo 'I' . ashtml($details['formatted_number']);
?>
</title>
 <link href="style.css" rel="stylesheet" type="text/css">
</head>
<?php 
if ($_GET['print']) {
    ?>
<body onload="window.print()">
<?php 
}
?>
<div id="store_name">Raw Materials Art Supplies</div>
<div id="doc_header">
 <div id="doc_info">
  <span id="doc_name"><?php 
echo $details['type'] == 'vendor' ? 'PO' : 'Invoice';
Ejemplo n.º 3
0
<?php

include '../scat.php';
include '../lib/txn.php';
$txn_id = (int) $_REQUEST['txn'];
$id = (int) $_REQUEST['id'];
$admin = (int) $_REQUEST['admin'];
if (!$txn_id || !$id) {
    die_jsonp("No transaction or payment specified.");
}
$txn = new Transaction($db, $txn_id);
try {
    $txn->removePayment($id, $admin);
} catch (Exception $e) {
    die_jsonp($e->getMessage());
}
echo jsonp(array('txn' => txn_load($db, $txn_id), 'payments' => txn_load_payments($db, $txn_id)));
Ejemplo n.º 4
0
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)));
Ejemplo n.º 5
0
<?php

include '../scat.php';
include '../lib/txn.php';
$txn_id = (int) $_REQUEST['txn'];
if (!$txn_id) {
    die_jsonp("No transaction specified.");
}
$txn = txn_load($db, $txn_id);
$person = (int) $_REQUEST['person'];
if (!$person) {
    die_jsonp("No person specified.");
}
$q = "SELECT id FROM person WHERE id = {$person}";
$r = $db->query($q) or die_query($db, $q);
if (!$r->num_rows) {
    die_jsonp("No such person.");
}
$q = "UPDATE txn SET person = {$person} WHERE id = {$txn_id}";
$r = $db->query($q) or die_query($db, $q);
$txn = txn_load($db, $txn_id);
$person = person_load($db, $person);
echo jsonp(array("success" => "Updated person.", "txn" => $txn, "person" => $person));
Ejemplo n.º 6
0
include '../lib/eps-express.php';
$id = (int) $_REQUEST['id'];
$amount = $_REQUEST['amount'];
if (!$id || !$amount) {
    die_jsonp("Either transaction or amount was not specified.");
}
$person_id = (int) $_REQUEST['person'];
$person = $person_id ? person_load($db, $person_id) : false;
$account = $person['payment_account_id'];
if (!$person_id || !$person || !$account) {
    die_jsonp("No person specified or no card stored for person.");
}
$eps = new EPS_Express();
$response = $eps->CreditCardSalePaymentAccount($id, $amount, $account);
$xml = new SimpleXMLElement($response);
if ($xml->Response->ExpressResponseCode != 0) {
    die_jsonp((string) $xml->Response->ExpressResponseMessage);
}
$method = 'credit';
$cc = array();
$cc['cc_txn'] = $xml->Response->Transaction->TransactionID;
$cc['cc_approval'] = $xml->Response->Transaction->ApprovalNumber;
$cc['cc_type'] = $xml->Response->Card->CardLogo;
$txn = new Transaction($db, $id);
try {
    $payment = $txn->addPayment($method, $amount, $cc);
} catch (Exception $e) {
    die_jsonp($e->getMessage());
}
echo jsonp(array('payment' => $payment, 'txn' => txn_load($db, $id), 'payments' => txn_load_payments($db, $id)));
Ejemplo n.º 7
0
<?php

include '../scat.php';
include '../lib/txn.php';
$id = (int) $_REQUEST['id'];
if (!$id) {
    die_jsonp("No transaction specified.");
}
$note = $_REQUEST['note'];
if (!$note) {
    die_jsonp("No note given.");
}
$note = $db->escape($note);
$q = "INSERT INTO txn_note SET entered = NOW(), txn = {$id}, content = '{$note}'";
$db->query($q) or die_query($db, $q);
echo jsonp(array('txn' => txn_load($db, $id), 'notes' => txn_load_notes($db, $id)));
Ejemplo n.º 8
0
<?php

include '../scat.php';
include '../lib/txn.php';
$txn_id = (int) $_REQUEST['txn'];
$txn = txn_load($db, $txn_id);
if (!$txn['paid']) {
    die_jsonp("Can't return an order that hasn't been paid for!");
}
$q = "SELECT 1 + MAX(number) AS number FROM txn WHERE type = 'customer'";
$r = $db->query($q);
if (!$r) {
    die_query($db, $q);
}
$row = $r->fetch_assoc();
$q = "INSERT INTO txn\n        SET created= NOW(),\n            type = 'customer',\n            number = {$row['number']},\n            returned_from = {$txn_id},\n            tax_rate = " . DEFAULT_TAX_RATE;
$r = $db->query($q);
if (!$r) {
    die_query($db, $q);
}
$new_txn_id = $db->insert_id;
$q = "INSERT INTO txn_line (txn, item, ordered, allocated, override_name,\n                           retail_price, discount_type, discount, taxfree)\n     SELECT {$new_txn_id} AS txn,\n            item,\n            -ordered AS ordered,\n            -allocated AS allocated,\n            override_name,\n            retail_price, discount_type, discount,\n            taxfree\n       FROM txn_line WHERE txn = {$txn_id}";
$r = $db->query($q);
if (!$r) {
    die_query($db, $q);
}
echo jsonp(array('txn' => txn_load($db, $new_txn_id), 'items' => txn_load_items($db, $new_txn_id), 'payments' => array(), 'notes' => array()));