/** Implementation function @return SQL result object */ public function fetch($empNo = false, $laneNo = false, $transNo = false) { $op_db = CoreLocal::get('pDatabase'); $sql = Database::tDataConnect(); $join_table = $op_db . $sql->sep() . 'MasterSuperDepts'; $column = 's.super_name'; if (!$sql->table_exists($join_table)) { $join_table = $op_db . $sql->sep() . 'subdepts'; $column = 's.subdept_name'; } $query = 'SELECT l.upc,l.trans_type,l.description, l.total,l.percentDiscount,l.trans_status, l.charflag,l.scale,l.quantity,l.unitPrice, l.ItemQtty,l.matched,l.numflag,l.tax, l.foodstamp,l.trans_id,l.department, l.trans_subtype,l.regPrice, ' . $column . ' AS category FROM localtemptrans AS l LEFT JOIN ' . $join_table . ' AS s ON l.department=s.dept_ID WHERE trans_type <> \'L\' ORDER BY trans_id DESC'; if ($empNo && $laneNo && $transNo) { $query = sprintf("SELECT l.upc,l.trans_type,l.description,\n l.total,l.percentDiscount,l.trans_status,\n l.charflag,l.scale,l.quantity,l.unitPrice,\n l.ItemQtty,l.matched,l.numflag,l.tax,\n l.foodstamp,l.trans_id,l.department,\n l.trans_subtype,l.regPrice,\n " . $column . " AS category \n FROM localtranstoday as l \n LEFT JOIN " . $join_table . " AS s ON l.department=s.dept_ID\n WHERE trans_type <> 'L' AND\n emp_no=%d AND register_no=%d AND trans_no=%d\n AND datetime >= " . $sql->curdate() . "\n ORDER BY trans_id DESC", $empNo, $laneNo, $transNo); } $result = $sql->query($query); return $result; }
function addItem($row, $quantity, $priceObj) { if ($quantity == 0) { return False; } // enforce limit on discounting sale items $dsi = CoreLocal::get('DiscountableSaleItems'); if ($dsi == 0 && $dsi !== '' && $priceObj->isSale()) { $row['discount'] = 0; } /* Use "quantity" field in products record as a per-transaction limit. This is analogous to a similar feature with sale items. */ if (!$priceObj->isSale() && $row['quantity'] > 0) { $db = Database::tDataConnect(); $query = "SELECT SUM(quantity) as qty FROM localtemptrans\n WHERE upc='{$row['upc']}'"; $result = $db->query($query); if ($db->num_rows($result) > 0) { $chkRow = $db->fetch_row($result); if ($chkRow['qty'] + $quantity > $row['quantity']) { $this->error_msg = _("item only allows ") . $row['quantity'] . _(" per transaction"); return False; } } } $pricing = $priceObj->priceInfo($row, $quantity); TransRecord::addRecord(array('upc' => $row['upc'], 'description' => $row['description'], 'trans_type' => 'I', 'trans_subtype' => isset($row['trans_subtype']) ? $row['trans_subtype'] : '', 'department' => $row['department'], 'quantity' => $quantity, 'unitPrice' => $pricing['unitPrice'], 'total' => MiscLib::truncate2($pricing['unitPrice'] * $quantity), 'regPrice' => $pricing['regPrice'], 'scale' => $row['scale'], 'tax' => $row['tax'], 'foodstamp' => $row['foodstamp'], 'discount' => $pricing['discount'], 'memDiscount' => $pricing['memDiscount'], 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $quantity, 'volDiscType' => $row['pricemethod'], 'volume' => $row['quantity'], 'VolSpecial' => $row['groupprice'], 'mixMatch' => $row['mixmatchcode'], 'cost' => isset($row['cost']) ? $row['cost'] * $quantity : 0.0, 'numflag' => isset($row['numflag']) ? $row['numflag'] : 0, 'charflag' => isset($row['charflag']) ? $row['charflag'] : '')); return true; }
function body_content() { $db = Database::tDataConnect(); $query = "\n SELECT register_no, \n emp_no, \n trans_no, \n SUM(CASE \n WHEN trans_type='T' AND department=0 THEN -1 * total \n ELSE 0 \n END) AS total \n FROM localtranstoday \n WHERE register_no = ?\n AND emp_no = ?\n AND datetime >= " . $db->curdate() . "\n GROUP BY register_no, \n emp_no, \n trans_no \n ORDER BY trans_no DESC"; $args = array(CoreLocal::get('laneno'), CoreLocal::get('CashierNo')); $prep = $db->prepare($query); $result = $db->execute($prep, $args); $num_rows = $db->num_rows($result); ?> <div class="baseHeight"> <div class="listbox"> <form name="selectform" method="post" id="selectform" action="<?php echo $_SERVER['PHP_SELF']; ?> " > <select name="selectlist" size="15" id="selectlist" onblur="$('#selectlist').focus()" > <?php $selected = "selected"; for ($i = 0; $i < $num_rows; $i++) { $row = $db->fetch_array($result); echo "<option value='" . $row["register_no"] . "::" . $row["emp_no"] . "::" . $row["trans_no"] . "'"; echo $selected; echo ">lane " . substr(100 + $row["register_no"], -2) . " Cashier " . substr(100 + $row["emp_no"], -2) . " #" . $row["trans_no"] . " -- \$" . sprintf('%.2f', $row["total"]); $selected = ""; } ?> </select> </div> <?php if (CoreLocal::get('touchscreen')) { echo '<div class="listbox listboxText">' . DisplayLib::touchScreenScrollButtons('#selectlist') . '</div>'; } ?> <div class="listboxText coloredText centerOffset"> <?php echo _("use arrow keys to navigate"); ?> <br /> <p> <button type="submit" class="pos-button wide-button coloredArea"> Reprint <span class="smaller">[enter]</span> </button> </p> <p> <button type="submit" class="pos-button wide-button errorColoredArea" onclick="$('#selectlist').append($('<option>').val(''));$('#selectlist').val('');"> Cancel <span class="smaller">[clear]</span> </button></p> </div> </form> <div class="clear"></div> </div> <?php }
public function savingsMessage($trans_num) { if (preg_match('/^(\\d+)\\D+(\\d+)\\D+(\\d+)$/', $trans_num, $matches)) { $emp = $matches[1]; $reg = $matches[2]; $trans = $matches[3]; } else { return ''; } $db = Database::tDataConnect(); $query = "\n SELECT\n SUM(CASE WHEN discounttype IN (1) THEN discount ELSE 0 END) AS sales,\n SUM(CASE WHEN trans_status='M' THEN -total ELSE 0 END) AS memSales,\n SUM(CASE WHEN discounttype IN (2) THEN discount ELSE 0 END) AS availableMemSales,\n SUM(CASE WHEN upc='DISCOUNT' THEN -total ELSE 0 END) AS transDiscount,\n SUM(CASE WHEN trans_subtype IN ('CP','IC') THEN -total ELSE 0 END) as coupons,\n MAX(percentDiscount) AS percentDiscount\n FROM localtranstoday\n WHERE emp_no=" . (int) $emp . " AND register_no=" . (int) $reg . " AND trans_no=" . (int) $trans; $result = $db->query($query); if (!$result || $db->num_rows($result) == 0) { return ''; } $row = $db->fetch_row($result); $msg = ''; if ($row['transDiscount'] > 0) { $msg .= $row['percentDiscount'] . _('% DISCOUNT SAVINGS = $') . number_format($row['transDiscount'], 2) . "\n"; } if ($row['sales'] + $row['memSales'] > 0) { $msg .= _('SALE SAVINGS = $') . number_format($row['sales'] + $row['memSales'], 2) . "\n"; } if ($row['coupons'] > 0) { $msg .= _('COUPONS = $') . number_format($row['coupons'], 2) . "\n"; } return $msg; }
/** New function: log rows don't appear in screendisplay so scrolling by simplying incrementing trans_id can land on a "blank" line. It still works if you keep scrolling but the cursor disappears from the screen. This function finds the next visible line instead. @param $id the current id @param $up bool [True] => scroll towards top of screen [False] => scroll towards bottom of screen */ function next_valid($id, $up = True) { $db = Database::tDataConnect(); $next = $id; while (True) { $prev = $next; $next = $up ? $next - 1 : $next + 1; if ($next <= 0) { return $prev; } $r = $db->query("SELECT MAX(trans_id) as max,\n SUM(CASE WHEN trans_id={$next} THEN 1 ELSE 0 END) as present\n FROM screendisplay"); if ($db->num_rows($r) == 0) { return 1; } $w = $db->fetch_row($r); if ($w['max'] == '') { return 1; } if ($w['present'] > 0) { return $next; } if ($w['max'] <= $next) { return $w['max']; } // failsafe; shouldn't happen if ($next > 1000) { break; } } return $id; }
function parse($str) { $json = $this->default_json(); $arg = $this->left; CoreLocal::set("sc", 1); $staffID = substr($arg, 0, 4); $pQuery = "select staffID,chargecode,blueLine from chargecodeview where chargecode = '" . $arg . "'"; $pConn = Database::pDataConnect(); $result = $pConn->query($pQuery); $num_rows = $pConn->num_rows($result); $row = $pConn->fetch_array($result); if ($num_rows == 0) { $json['output'] = DisplayLib::xboxMsg(_("unable to authenticate staff ") . $staffID, DisplayLib::standardClearButton()); CoreLocal::set("isStaff", 0); // apbw 03/05/05 SCR return $json; } else { CoreLocal::set("isStaff", 1); // apbw 03/05/05 SCR CoreLocal::set("memMsg", $row["blueLine"]); $tQuery = "update localtemptrans set card_no = '" . $staffID . "', percentDiscount = 15"; $tConn = Database::tDataConnect(); $this->addscDiscount(); TransRecord::discountnotify(15); $tConn->query($tQuery); Database::getsubtotals(); $chk = self::ttl(); if ($chk !== True) { $json['main_frame'] = $chk; return $json; } CoreLocal::set("runningTotal", CoreLocal::get("amtdue")); return self::tender("MI", CoreLocal::get("runningTotal") * 100); } }
/** localtranstoday used to be a view; recreate it as a table if needed. */ public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False) { if ($db_name == CoreLocal::get('pDatabase')) { $this->connection = Database::pDataConnect(); } else { if ($db_name == CoreLocal::get('tDatabase')) { $this->connection = Database::tDataConnect(); } else { echo "Error: Unknown database ({$db_name})"; return false; } } if ($this->connection->isView($this->name)) { if ($mode == BasicModel::NORMALIZE_MODE_CHECK) { echo "View {$this->name} should be a table!\n"; echo "==========================================\n"; printf("%s table %s\n", "Check complete. Need to drop view & create replacement table.", $this->name); echo "==========================================\n\n"; return 999; } else { $drop = $this->connection->query('DROP VIEW ' . $this->name); echo "==========================================\n"; printf("Dropping view %s %s\n", $this->name, $drop ? "OK" : "failed"); if ($drop) { $cResult = $this->create(); printf("Update complete. Creation of table %s %s\n", $this->name, $cResult ? "OK" : "failed"); } echo "==========================================\n"; return true; } } else { return parent::normalize($db_name, $mode, $doCreate); } }
public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False) { if ($db_name == CoreLocal::get('pDatabase')) { $this->connection = Database::pDataConnect(); } else { if ($db_name == CoreLocal::get('tDatabase')) { $this->connection = Database::tDataConnect(); } else { echo "Error: Unknown database ({$db_name})"; return false; } } $viewSQL = $this->connection->getViewDefinition($this->name); echo "==========================================\n"; printf("%s view %s\n", $mode == BasicModel::NORMALIZE_MODE_CHECK ? "Checking" : "Updating", "{$db_name}.{$this->name}"); echo "==========================================\n"; if (strstr($viewSQL, '0 AS memType') || strstr($viewSQL, '0 AS ' . $this->connection->identifier_escape('memType'))) { /** Structure-check 27Dec2013 Make sure memType is calcluated instead of hardcoded to zero */ echo "==========================================\n"; if ($mode == BasicModel::NORMALIZE_MODE_CHECK) { echo "View needs to be rebuild to calculate memType correctly\n"; } else { echo "Rebuilding view to calculate memType correctly... "; $this->connection->query('DROP VIEW ' . $this->connection->identifier_escape($this->name)); $success = $this->create(); echo ($success ? 'succeeded' : 'failed') . "\n"; } } return 0; }
function parse($str) { $curID = CoreLocal::get("currentid"); $dbc = Database::tDataConnect(); $query = "SELECT trans_type,tax,foodstamp FROM localtemptrans WHERE trans_id={$curID}"; $res = $dbc->query($query); if ($dbc->num_rows($res) == 0) { return True; } // shouldn't ever happen $item = $dbc->fetch_row($res); $query = "SELECT MAX(id) FROM taxrates"; $res = $dbc->query($query); $tax_cap = 0; if ($dbc->num_rows($res) > 0) { $taxID = $dbc->fetch_row($res); $max = $taxID[0]; if (!empty($max)) { $tax_cap = $max; } } $dbc->query($query); $next_tax = $item['tax'] + 1; $next_fs = 0; if ($next_tax > $max) { $next_tax = 0; $next_fs = 1; } $query = "UPDATE localtemptrans \n set tax={$next_tax},foodstamp={$next_fs} \n WHERE trans_id={$curID}"; $dbc->query($query); $ret = $this->default_json(); $ret['output'] = DisplayLib::listItems(CoreLocal::get("currenttopid"), $curID); return $ret; // maintain item cursor position }
public function standalone_receipt($ref, $reprint = false) { list($emp, $reg, $trans) = explode('-', $ref, 3); $ret = 'Date of Application: ' . date('M d, Y') . "\n"; $ret .= 'Owner Name: ' . CoreLocal::get('fname') . ' ' . CoreLocal::get('lname') . ', Owner No.: ' . CoreLocal::get('memberID') . "\n"; $ret .= "\n"; $ret .= ReceiptLib::centerString(str_repeat('_', 30)) . "\n"; $ret .= ReceiptLib::centerString('Owner Signature') . "\n"; if (CoreLocal::get('standalone') == 0) { $ret .= $this->memAddress(); } $ret .= "\n"; $ret .= ReceiptLib::centerString(str_repeat('_', 30)) . "\n"; $ret .= ReceiptLib::centerString('Employee Signature') . "\n"; $ret .= "\n"; $ret .= ReceiptLib::centerString(str_repeat('_', 30)) . "\n"; $ret .= ReceiptLib::centerString('Manager Signature') . "\n"; $dbc = Database::tDataConnect(); $query = sprintf('SELECT MAX(numflag) FROM localtemptrans WHERE upc=\'ACCESS\' AND emp_no=%d AND register_no=%d AND trans_no=%d', $emp, $reg, $trans); if ($reprint) { $query = str_replace('localtemptrans', 'localtranstoday', $query); } $result = $dbc->query($query); if ($dbc->num_rows($result) > 0) { $row = $dbc->fetch_row($result); if ($row[0] != 0) { $ret .= 'Program No: ' . $row[0] . "\n"; } } return $ret; }
public function message($val, $ref, $reprint = false) { $date = ReceiptLib::build_time(time()); list($emp, $reg, $trans) = explode('-', $ref); $slip = ''; // query database for receipt info $db = Database::tDataConnect(); if ($reprint) { $db = Database::mDataConnect(); } $query = "SELECT q.amount, q.name, q.PAN, q.refNum,\n CASE \n WHEN q.mode = 'EBTFOOD_Sale' THEN 'Ebt FS Sale'\n WHEN q.mode = 'EBTFOOD_Return' THEN 'Ebt FS Refund'\n WHEN q.mode = 'EBTCASH_Sale' THEN 'Ebt Cash Sale'\n WHEN q.mode = 'EBTCASH_Return' THEN 'Ebt Cash Refund'\n ELSE q.mode\n END as ebtMode,\n r.xResultMessage, r.xTransactionID\n FROM efsnetRequest AS q\n LEFT JOIN efsnetResponse AS r ON\n q.date = r.date AND\n q.laneNo = r.laneNo AND\n q.transNo = r.transNo AND\n q.transID = r.transID AND\n q.cashierNo = r.cashierNo\n WHERE r.xResultMessage LIKE '%Approve%'\n AND q.mode LIKE 'EBT%'\n AND r.validResponse=1\n AND q.date=" . date('Ymd') . "\n AND q.transNo=" . (int) $trans . "\n ORDER BY q.refNum, q.datetime"; if ($db->table_exists('PaycardTransactions')) { $trans_type = $db->concat('p.cardType', "' '", 'p.transType', ''); $query = "SELECT p.amount,\n p.name,\n p.PAN,\n p.refNum,\n {$trans_type} AS ebtMode,\n p.xResultMessage,\n p.xTransactionID,\n p.xBalance,\n p.requestDatetime AS datetime\n FROM PaycardTransactions AS p\n WHERE dateID=" . date('Ymd') . "\n AND empNo=" . $emp . "\n AND registerNo=" . $reg . "\n AND transNo=" . $trans . "\n AND p.validResponse=1\n AND p.xResultMessage LIKE '%APPROVE%'\n AND p.cardType LIKE 'EBT%'\n ORDER BY p.requestDatetime"; } $result = $db->query($query); $prevRefNum = false; while ($row = $db->fetch_row($result)) { // failover to mercury's backup server can // result in duplicate refnums. this is // by design (theirs, not CORE's) if ($row['refNum'] == $prevRefNum) { continue; } $slip .= ReceiptLib::centerString("................................................") . "\n"; // store header for ($i = 1; $i <= CoreLocal::get('chargeSlipCount'); $i++) { $slip .= ReceiptLib::centerString(CoreLocal::get("chargeSlip" . $i)) . "\n"; } $slip .= "\n"; $col1 = array(); $col2 = array(); $col1[] = $row['ebtMode']; $col2[] = "Entry Method: swiped\n"; $col1[] = "Sequence: " . $row['xTransactionID']; $col2[] = "Card: " . $row['PAN']; $col1[] = "Authorization: " . $row['xResultMessage']; $col2[] = ReceiptLib::boldFont() . "Amount: " . $row['amount'] . ReceiptLib::normalFont(); $balance = 'unknown'; $ebt_type = substr(strtoupper($row['ebtMode']), 0, 5); if ($ebt_type == 'EBT F' || $ebt_type == 'EBTFO') { if (is_numeric(CoreLocal::get('EbtFsBalance'))) { $balance = sprintf('%.2f', CoreLocal::get('EbtFsBalance')); } } else { if ($ebt_type == 'EBT C' || $ebt_type == 'EBTCA') { if (is_numeric(CoreLocal::get('EbtCaBalance'))) { $balance = sprintf('%.2f', CoreLocal::get('EbtCaBalance')); } } } $col1[] = "New Balance: " . $balance; $col2[] = ''; $slip .= ReceiptLib::twoColumns($col1, $col2); $slip .= ReceiptLib::centerString("................................................") . "\n"; $prevRefNum = $row['refNum']; } return $slip; }
public function priceInfo($row, $quantity = 1) { if (is_array($this->savedInfo)) { return $this->savedInfo; } $ret = array(); $ret["regPrice"] = $row['normal_price']; $ret["unitPrice"] = $row['special_price']; /* if not by weight, just use the sticker price (for scaled items, the UPC parse module calculates a weight estimate and sets a quantity so normal_price can be used. This could be done for all items, but typically the deli doesn't keep good track of whether their items are marked scale correctly since it only matters when an item goes on sale */ if (isset($row['stickerprice']) && $row['scale'] == 0) { $ret['regPrice'] = $row['stickerprice']; } $ret['discount'] = ($ret['regPrice'] - $row['special_price']) * $quantity; $ret['memDiscount'] = 0; if ($row['line_item_discountable'] == 1 && CoreLocal::get("itemPD") > 0) { $discount = $row['special_price'] * (CoreLocal::get("itemPD") / 100); $ret["unitPrice"] = $row['special_price'] - $discount; $ret["discount"] += $discount * $quantity; } // enforce per-transaction limit if ($row['specialpricemethod'] == 0 && $row['specialquantity'] > 0) { $tdb = Database::tDataConnect(); $chkQ = "SELECT sum(ItemQtty) FROM\n localtemptrans WHERE upc='{$row['upc']}'"; if (strlen($row['mixmatchcode']) > 0 && $row['mixmatchcode'][0] == 'b') { $chkQ .= " OR mixMatch='{$row['mixmatchcode']}'"; } $chkR = $tdb->query($chkQ); $prevSales = 0; if ($tdb->num_rows($chkR) > 0) { $prevSales = array_pop($tdb->fetch_row($chkR)); } if ($prevSales >= $row['specialquantity']) { // already sold the limit; use non-sale price $ret['unitPrice'] = $row['normal_price']; $ret['discount'] = 0; } else { if ($prevSales + $quantity > $row['specialquantity']) { // this multiple qty ring will pass the limit // set discount based on appropriate quantity // and adjust unitPrice so total comes out correctly $discountQty = $row['specialquantity'] - $prevSales; $ret['discount'] = ($ret['regPrice'] - $row['special_price']) * $discountQty; $total = $ret['regPrice'] * $quantity - $ret['discount']; $ret['unitPrice'] = MiscLib::truncate2($total / $quantity); } } } $this->savedRow = $row; $this->savedInfo = $ret; return $ret; }
public static function dumpRecord($trans_id) { $db = Database::tDataConnect(); $p = $db->prepare_statement('SELECT * FROM localtemptrans WHERE trans_id=?'); ob_start(); var_dump($db->getRow($p, array($trans_id))); return ob_get_clean(); }
/** Determine whether to open the drawer @param $trans_num [string] transaction identifier @return boolean */ public function doKick($trans_num) { if (CoreLocal::get('training') == 1) { return false; } $db = Database::tDataConnect(); $query = "SELECT trans_id \n FROM localtranstoday \n WHERE \n (trans_subtype = 'CA' and total <> 0)\n AND " . $this->refToWhere($trans_num); $result = $db->query($query); $num_rows = $db->num_rows($result); return $num_rows > 0 ? true : false; }
protected function varied_message($ref, $reprint = false, $sigSlip = false) { if (CoreLocal::get('autoReprint') == 1) { $sigSlip = true; } $date = ReceiptLib::build_time(time()); list($emp, $reg, $trans) = explode('-', $ref); $slip = ''; // query database for gc receipt info $db = Database::tDataConnect(); if ($reprint) { $db = Database::mDataConnect(); } $order = $sigSlip ? 'DESC' : 'ASC'; $trans_type = $db->concat('p.cardType', "' '", 'p.transType', ''); $sql = "SELECT {$trans_type} AS tranType,\n CASE WHEN p.transType = 'Return' THEN -1*p.amount ELSE p.amount END as amount,\n p.registerNo as terminalID,\n p.PAN,\n CASE WHEN p.manual=1 THEN 'Manual' ELSE 'Swiped' END as entryMethod,\n CASE WHEN transType='VOID' THEN '' ELSE p.xApprovalNumber END AS xAuthorizationCode,\n p.xBalance,\n CASE WHEN transType='VOID' THEN p.xApprovalNumber ELSE '' END AS xVoidCode,\n p.transID,\n p.requestDatetime AS datetime\n FROM PaycardTransactions AS p\n WHERE dateID=" . date('Ymd') . "\n AND empNo=" . $emp . "\n AND registerNo=" . $reg . "\n AND transNo=" . $trans . "\n AND p.validResponse=1\n AND p.xResultMessage LIKE '%Appro%'\n AND p.cardType = 'Gift'\n ORDER BY p.requestDatetime " . $order; $result = $db->query($sql); $num = $db->num_rows($result); while ($row = $db->fetch_row($result)) { $slip .= ReceiptLib::centerString("................................................") . "\n"; // store header for ($i = 1; $i <= CoreLocal::get('chargeSlipCount'); $i++) { $slip .= ReceiptLib::centerString(CoreLocal::get("chargeSlip" . $i)) . "\n"; } $slip .= "\n"; $col1 = array(); $col2 = array(); $col1[] = $row['tranType']; $col2[] = "Date: " . date('m/d/y h:i a', strtotime($row['datetime'])); $col1[] = "Terminal ID: " . $row['terminalID']; $col2[] = "Reference: " . $ref . "-" . $row['transID']; $col1[] = "Card: " . $row['PAN']; $col2[] = "Entry Method: " . $row['entryMethod']; if ((int) $row['xVoidCode'] > 0) { $col1[] = "Void Auth: " . $row['xVoidCode']; $col2[] = "Orig Auth: " . $row['xAuthorizationCode']; } else { $col1[] = "Authorization: " . $row['xAuthorizationCode']; $col2[] = ""; } $col1[] = ReceiptLib::boldFont() . "Amount: " . PaycardLib::paycard_moneyFormat($row['amount']) . ReceiptLib::normalFont(); // bold ttls apbw 11/3/07 $col2[] = "New Balance: " . PaycardLib::paycard_moneyFormat($row['xBalance']); $slip .= ReceiptLib::twoColumns($col1, $col2); // name/phone on activation only if (($row['tranType'] == 'Gift Card Activation' || $row['tranType'] == 'Gift Card Issue') && $sigSlip) { $slip .= "\n" . ReceiptLib::centerString("Name: ___________________________________") . "\n" . "\n" . ReceiptLib::centerString("Phone: ___________________________________") . "\n"; } $slip .= ReceiptLib::centerString("................................................") . "\n"; } return $slip; }
function parse($str) { $ret = $this->default_json(); $query = "select upc,description,VolSpecial,quantity,\n total,discount,memDiscount,discountable,\n unitPrice,scale,foodstamp,voided,discounttype,\n trans_type,trans_status,department,regPrice,\n tax,volume,volDiscType\n from localtemptrans where \n trans_id = " . CoreLocal::get("currentid"); $connection = Database::tDataConnect(); $result = $connection->query($query); $num_rows = $connection->num_rows($result); if ($num_rows > 0) { $row = $connection->fetch_array($result); $strUPC = $row["upc"]; $strDescription = $row["description"]; $dblVolSpecial = $row["VolSpecial"]; $dblquantity = -0.5 * $row["quantity"]; $dblTotal = MiscLib::truncate2(-1 * 0.5 * $row["total"]); // invoked truncate2 rounding function to fix half-penny errors apbw 3/7/05 $strCardNo = CoreLocal::get("memberID"); $dblDiscount = $row["discount"]; $dblmemDiscount = $row["memDiscount"]; $intDiscountable = $row["discountable"]; $dblUnitPrice = $row["unitPrice"]; $intScale = MiscLib::nullwrap($row["scale"]); if ($row["foodstamp"] != 0) { $intFoodStamp = 1; } else { $intFoodStamp = 0; } $intdiscounttype = MiscLib::nullwrap($row["discounttype"]); if ($row["voided"] == 20) { $ret['output'] = DisplayLib::boxMsg(_("Discount already taken"), '', false, DisplayLib::standardClearButton()); } elseif ($row["trans_type"] == "T" or $row["trans_status"] == "D" or $row["trans_status"] == "V" or $row["trans_status"] == "C") { $ret['output'] = DisplayLib::boxMsg(_("Item cannot be discounted"), '', false, DisplayLib::standardClearButton()); } elseif (strncasecmp($strDescription, "Club Card", 9) == 0) { //----- edited by abpw 2/15/05 ----- $ret['output'] = DisplayLib::boxMsg(_("Item cannot be discounted"), '', false, DisplayLib::standardClearButton()); } elseif (CoreLocal::get("tenderTotal") < 0 and $intFoodStamp == 1 and -1 * $dblTotal > CoreLocal::get("fsEligible")) { $ret['output'] = DisplayLib::boxMsg(_("Item already paid for"), '', false, DisplayLib::standardClearButton()); } elseif (CoreLocal::get("tenderTotal") < 0 and -1 * $dblTotal > CoreLocal::get("runningTotal") - CoreLocal::get("taxTotal")) { $ret['output'] = DisplayLib::boxMsg(_("Item already paid for"), '', false, DisplayLib::standardClearButton()); } else { // --- added partial item desc to club card description - apbw 2/15/05 --- TransRecord::addRecord(array('upc' => $strUPC, 'description' => "Club Card: " . substr($strDescription, 0, 19), 'trans_type' => "I", 'trans_status' => "J", 'department' => $row["department"], 'quantity' => $dblquantity, 'unitPrice' => $dblUnitPrice, 'total' => $dblTotal, 'regPrice' => 0.5 * $row["regPrice"], 'scale' => $intScale, 'tax' => $row["tax"], 'foodstamp' => $intFoodStamp, 'discount' => $dblDiscount, 'memDiscount' => $dblmemDiscount, 'discountable' => $intDiscountable, 'discounttype' => $intdiscounttype, 'ItemQtty' => $dblquantity, 'volDiscType' => $row["volDiscType"], 'volume' => $row["volume"], 'VolSpecial' => $dblVolSpecial)); $update = "update localtemptrans set voided = 20 where trans_id = " . CoreLocal::get("currentid"); $connection = Database::tDataConnect(); $connection->query($update); CoreLocal::set("TTLflag", 0); CoreLocal::set("TTLRequested", 0); $ret['output'] = DisplayLib::lastpage(); } } return $ret; }
/** Print message as its own receipt @param $ref a transaction reference (emp-lane-trans) @param $reprint boolean @return [string] message to print */ public function standalone_receipt($ref, $reprint = false) { $date = ReceiptLib::build_time(time()); list($emp, $reg, $trans) = explode('-', $ref); $sort = 'asc'; $db = Database::tDataConnect(); $emvP = $db->prepare(' SELECT content FROM EmvReceipt WHERE dateID=? AND empNo=? AND registerNo=? AND transNo=? AND transID=? ORDER BY tdate DESC '); $emvR = $db->execute($emvP, array(date('Ymd'), $emp, $reg, $trans, CoreLocal::get('paycard_id'))); $slip = ''; while ($emvW = $db->fetchRow($emvR)) { $slip .= ReceiptLib::centerString("................................................") . "\n"; $lines = explode("\n", $emvW['content']); for ($i = 0; $i < count($lines); $i++) { if (isset($lines[$i + 1]) && strlen($lines[$i]) + strlen($lines[$i + 1]) < 56) { // don't columnize the amount lines if (strstr($lines[$i], 'AMOUNT') || strstr($lines[$i + 1], 'AMOUNT')) { $slip .= ReceiptLib::centerString($lines[$i]) . "\n"; } elseif (strstr($lines[$i], 'TOTAL') || strstr($lines[$i + 1], 'TOTAL')) { $slip .= ReceiptLib::centerString($lines[$i]) . "\n"; } else { $spacer = 56 - strlen($lines[$i]) - strlen($lines[$i + 1]); $slip .= $lines[$i] . str_repeat(' ', $spacer) . $lines[$i + 1] . "\n"; $i++; } } else { if (strstr($lines[$i], 'x___')) { if ($sigSlip) { $slip .= "\n\n\n"; } else { $i++; continue; } } $slip .= ReceiptLib::centerString($lines[$i]) . "\n"; } } $slip .= "\n" . ReceiptLib::centerString(_('(Customer Copy)')) . "\n"; break; } return $slip; }
function preprocess() { $line_id = CoreLocal::get("currentid"); $db = Database::tDataConnect(); $q = "SELECT description,total,department FROM localtemptrans\n WHERE trans_type IN ('I','D') AND trans_status IN ('', ' ', '0')\n AND trans_id=" . (int) $line_id; $r = $db->query($q); if ($db->num_rows($r) == 0) { // current record cannot be repriced $this->change_page($this->page_url . "gui-modules/pos2.php"); return False; } $w = $db->fetch_row($r); $this->description = $w['description']; $this->price = sprintf('$%.2f', $w['total']); if (isset($_REQUEST['reginput'])) { $input = strtoupper($_REQUEST['reginput']); if ($input == "CL") { if ($this->price == "\$0.00") { $q = sprintf("UPDATE localtemptrans SET trans_type='L',\n trans_subtype='OG',charflag='PO',total=0\n WHERE trans_id=" . (int) $line_id); $r = $db->query($q); } // override canceled; go home $this->change_page($this->page_url . "gui-modules/pos2.php"); return False; } else { if (is_numeric($input) && $input != 0) { $cents = 0; $dollars = 0; if (strlen($input) == 1 || strlen($input) == 2) { $cents = $input; } else { $cents = substr($input, -2); $dollars = substr($input, 0, strlen($input) - 2); } $ttl = (int) $dollars + (int) $cents / 100.0; $ttl = number_format($ttl, 2); if ($w['department'] == CoreLocal::get("BottleReturnDept")) { $ttl = $ttl * -1; } $q = sprintf("UPDATE localtemptrans SET unitPrice=%.2f, regPrice=%.2f,\n total = quantity*%.2f, charflag='PO'\n WHERE trans_id=%d", $ttl, $ttl, $ttl, $line_id); $r = $db->query($q); $this->change_page($this->page_url . "gui-modules/pos2.php"); return False; } } } return True; }
public function doKick($trans_num) { $db = Database::tDataConnect(); $query = "SELECT trans_id \n FROM localtranstoday \n WHERE ( \n (trans_subtype = 'CA' and total <> 0) \n OR upc='0000000001065'\n ) AND " . $this->refToWhere($trans_num); $result = $db->query($query); $num_rows = $db->num_rows($result); $ret = $num_rows > 0 ? true : false; // use session to override default behavior // based on specific cashier actions rather // than transaction state $override = CoreLocal::get('kickOverride'); CoreLocal::set('kickOverride', false); if ($override === true) { $ret = true; } return $ret; }
public function doKick($trans_num) { $db = Database::tDataConnect(); $query = "select trans_id from localtemptrans where \n (trans_subtype = 'CA' and total <> 0)\n OR (trans_subtype IN('DC','CC','EF'))"; $result = $db->query($query); $num_rows = $db->num_rows($result); $ret = $num_rows > 0 ? true : false; // use session to override default behavior // based on specific cashier actions rather // than transaction state $override = CoreLocal::get('kickOverride'); CoreLocal::set('kickOverride', false); if ($override === true) { $ret = true; } return $ret; }
public function testFilter() { $mods = AutoLoader::listModules('DefaultReceiptFilter'); foreach ($mods as $filter_class) { $obj = new $filter_class(); $db = Database::tDataConnect(); $db->setTestData($this->test_records); $resultset = $obj->filter($this->test_records); $this->assertInternalType('array', $resultset); foreach ($resultset as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('upc', $result); $this->assertArrayHasKey('trans_type', $result); } $this->record_sets[] = $resultset; } }
public function testTranslog() { $db = Database::tDataConnect(); $errors = InstallUtilities::createTransDBs($db, CoreLocal::get('tDatabase')); $this->assertInternalType('array', $errors); $this->assertInternalType('array', $errors); foreach ($errors as $error) { $this->assertInternalType('array', $error, 'Invalid status entry'); $this->assertArrayHasKey('error', $error, 'Status entry missing key: error'); $this->assertEquals(0, $error['error'], 'Error creating ' . $error['struct'] . ', ' . print_r($error, true)); if (isset($error['query']) && stristr($error['query'], 'DROP VIEW')) { // don't check for existence on DROP VIEW queries continue; } $exists = $db->table_exists($error['struct']); $this->assertEquals(true, $exists, 'Failed to create ' . $error['struct'] . ', ' . print_r($error, true)); } }
/** Check whether there are suspended transactions @return - 1 Yes - 0 No This function ignores any transactions that are not from the current day. */ public static function checksuspended() { $db_a = Database::tDataConnect(); $query_local = "SELECT upc \n FROM suspended\n WHERE datetime >= " . date("'Y-m-d 00:00:00'"); $result = ""; if (CoreLocal::get("standalone") == 1) { $result = $db_a->query($query_local); } else { $db_a = Database::mDataConnect(); $result = $db_a->query($query_local); } $num_rows = $db_a->num_rows($result); if ($num_rows == 0) { return 0; } else { return 1; } }
function parse($str) { $ret = $this->default_json(); // this is the currently selected item $transID = CoreLocal::get("currentid"); $row = PrehLib::peekItem(true, $transID); if ($row === false) { // this shouldn't happen unless there's some weird session problem $ret['output'] = DisplayLib::boxMsg(_("Item not found"), '', false, DisplayLib::standardClearButton()); } else { if ($row['trans_type'] != 'I' && $row['trans_type'] != 'D') { // only items & open rings are discountable $ret['output'] = DisplayLib::boxMsg(_("Line is not discountable"), '', false, DisplayLib::standardClearButton()); } elseif ($row['discounttype'] != 0) { // for simplicity, sale items cannot be discounted // this also prevents using this function more than // once on a single item $ret['output'] = DisplayLib::boxMsg(_("Item already discounted"), '', false, DisplayLib::standardClearButton()); } else { // discount is simply the total times the // non-member discount percentage // total is discounted immediately using // the non-member percentage // memDiscount is the difference between total // member discount and the non-member discount // since the non-member discount is applied // immediately // setting discounttype=2 makes the member discount // apply when a [valid] member number is entered $discQ = sprintf("UPDATE localtemptrans SET\n discount=(regPrice * quantity * %f), \n total=(total-(regPrice*quantity*%f)),\n memDiscount=((regPrice*quantity*%f) - (regPrice*quantity*%f)),\n discounttype=2\n WHERE trans_id=%d", CoreLocal::get("LineItemDiscountNonMem"), CoreLocal::get("LineItemDiscountNonMem"), CoreLocal::get("LineItemDiscountMem"), CoreLocal::get("LineItemDiscountNonMem"), $transID); $dbc = Database::tDataConnect(); $discR = $dbc->query($discQ); // add notification line for nonMem discount TransRecord::adddiscount($row['regPrice'] * $row['quantity'] * CoreLocal::get("LineItemDiscountNonMem"), $row['department']); // footer should be redrawn since savings and totals // have changed. Output is the list of items $ret['redraw_footer'] = true; $ret['output'] = DisplayLib::lastpage(); } } return $ret; }
public function handle($upc, $json) { /** Adjust string index of pieces based on whether check digits have been included */ $man_id_start = 3; $fam_start = 8; $val_start = 11; if ($this->ean && CoreLocal::get('EanIncludeCheckDigits') == 1 || !$this->ean && CoreLocal::get('UpcIncludeCheckDigits') == 1) { $man_id_start = 2; $fam_start = 9; $val_start = 10; } $man_id = substr($upc, $man_id_start, 5); $fam = substr($upc, $fam_start, 3); $val = substr($upc, $val_start, 2); $db = Database::pDataConnect(); $query = "select Value,Qty from couponcodes where Code = '" . $val . "'"; $result = $db->query($query); $num_rows = $db->num_rows($result); if ($num_rows == 0) { $json['output'] = DisplayLib::boxMsg(_("coupon type unknown") . "<br />" . _("enter coupon manually"), '', false, DisplayLib::standardClearButton()); return $json; } $query2 = "SELECT reason, threshold FROM disableCoupon WHERE upc='{$upc}'"; $result2 = $db->query($query2); if ($result2 && $db->num_rows($result2) > 0) { $row = $db->fetch_row($result2); if ($row['threshold'] <= 0) { $json['output'] = DisplayLib::boxMsg($row['reason'], _("coupon disabled"), false, DisplayLib::standardClearButton()); return $json; } else { $transDB = Database::tDataConnect(); $q = "SELECT SUM(quantity) FROM localtemptrans WHERE upc='{$upc}'"; $r = $transDB->query($q); if ($transDB->num_rows($r) > 0) { $w = $transDB->fetch_row($r); $qty = $w[0]; if ($qty >= $row['threshold']) { $json['output'] = DisplayLib::boxMsg(_('coupon already applied'), '', false, DisplayLib::standardClearButton()); return $json; } } } } $row = $db->fetch_array($result); $value = $row["Value"]; $qty = $row["Qty"]; if ($fam == "992") { // 992 basically means blanket accept // Old method of asking cashier to assign a department // just creates confusion // Instead I just try to guess, otherwise use zero // (since that's what would happen anyway when the // confused cashier does a generic coupon tender) $value = MiscLib::truncate2($value); CoreLocal::set("couponupc", $upc); CoreLocal::set("couponamt", $value); $dept = 0; $db = Database::tDataConnect(); // SQL strings are indexed starting w/ one instead of zero // hence $man_id_start+1 $query = "select department from localtemptrans \n WHERE substring(upc," . ($man_id_start + 1) . ",5)='{$man_id}' \n GROUP BY department\n ORDER BY count(*) desc"; $result = $db->query($query); if ($db->num_rows($result) > 0) { $row = $db->fetch_row($result); $dept = $row['department']; } TransRecord::addCoupon($upc, $dept, $value); $json['output'] = DisplayLib::lastpage(); return $json; } // validate coupon $db = Database::tDataConnect(); $fam = substr($fam, 0, 2); /* the idea here is to track exactly which items in the transaction a coupon was previously applied to SQL strings are indexed starting w/ one instead of zero hence $man_id_start+1 */ $query = "select max(t.unitPrice) as unitPrice,\n max(t.department) as department,\n max(t.ItemQtty) as itemQtty,\n sum(case when c.quantity is null then 0 else c.quantity end) as couponQtty,\n max(case when c.quantity is not null then 0 else t.foodstamp end) as foodstamp,\n max(case when c.quantity is not null then 0 else t.tax end) as tax,\n max(t.emp_no) as emp_no,\n max(t.trans_no) as trans_no,\n t.trans_id from\n localtemptrans as t left join couponApplied as c\n on t.emp_no=c.emp_no and t.trans_no=c.trans_no\n and t.trans_id=c.trans_id\n where (substring(t.upc," . ($man_id_start + 1) . ",5)='{$man_id}'"; /* not right per the standard, but organic valley doesn't * provide consistent manufacturer ids in the same goddamn * coupon book */ if ($this->ean) { $query .= " or substring(t.upc," . $man_id_start . ",5)='{$man_id}'"; } $query .= ") and t.trans_status <> 'C'\n group by t.trans_id\n order by t.unitPrice desc"; $result = $db->query($query); $num_rows = $db->num_rows($result); /* no item w/ matching manufacturer */ if ($num_rows == 0) { $json['output'] = DisplayLib::boxMsg(_("product not found") . "<br />" . _("in transaction"), '', false, DisplayLib::standardClearButton()); return $json; } /* count up per-item quantites that have not yet had a coupon applied to them */ $available = array(); $emp_no = $transno = $dept = $foodstamp = $tax = -1; $act_qty = 0; while ($row = $db->fetch_array($result)) { if ($row["itemQtty"] - $row["couponQtty"] > 0) { $id = $row["trans_id"]; $available["{$id}"] = array(0, 0); $available["{$id}"][0] = $row["unitPrice"]; $available["{$id}"][1] += $row["itemQtty"]; $available["{$id}"][1] -= $row["couponQtty"]; $act_qty += $available["{$id}"][1]; } if ($emp_no == -1) { $emp_no = $row["emp_no"]; $transno = $row["trans_no"]; $dept = $row["department"]; $foodstamp = $row["foodstamp"]; $tax = $row['tax']; } } /* every line has maximum coupons applied */ if (count($available) == 0) { $json['output'] = DisplayLib::boxMsg(_("Coupon already applied") . "<br />" . _("for this item"), '', false, DisplayLib::standardClearButton()); return $json; } /* insufficient number of matching items */ if ($qty > $act_qty) { $msg = sprintf(_("coupon requires %d items"), $qty) . "<br />" . sprintf(_("there are only %d item(s)"), $act_qty) . "<br />" . _("in this transaction"); $json['output'] = DisplayLib::boxMsg($msg, '', false, DisplayLib::standardClearButton()); return $json; } /* free item, multiple choices needs work, obviously */ if ($value == 0 && count($available) > 1) { // decide which item(s) // manually by cashier maybe? } /* log the item(s) this coupon is being applied to */ $applied = 0; foreach (array_keys($available) as $id) { if ($value == 0) { $value = -1 * $available["{$id}"][0]; } if ($qty <= $available["{$id}"][1]) { $q = "INSERT INTO couponApplied \n (emp_no,trans_no,quantity,trans_id)\n VALUES (\n {$emp_no},{$transno},{$qty},{$id})"; $r = $db->query($q); $applied += $qty; } else { $q = "INSERT INTO couponApplied \n (emp_no,trans_no,quantity,trans_id)\n VALUES (\n {$emp_no},{$transno}," . $available["{$id}"][1] . ",{$id})"; $r = $db->query($q); $applied += $available["{$id}"][1]; } if ($applied >= $qty) { break; } } $value = MiscLib::truncate2($value); $json['udpmsg'] = 'goodBeep'; TransRecord::addCoupon($upc, $dept, $value, $foodstamp, $tax); $json['output'] = DisplayLib::lastpage(); $json['redraw_footer'] = True; return $json; }
function preprocess() { $this->hide_input(true); $dbc = Database::tDataConnect(); $q = ' SELECT MAX(paycardTransactionID) FROM PaycardTransactions WHERE transID=' . (int) CoreLocal::get('paycard_id'); $r = $dbc->query($q); if ($r && $dbc->numRows($r)) { $w = $dbc->fetchRow($r); $this->id = $w[0]; } if (!$this->id) { CoreLocal::set('boxMsg', 'Cannot locate transaction to void'); $this->change_page(MiscLib::baseURL() . 'gui-modules/boxMsg2.php'); return false; } CoreLocal::set('paycard_mode', PaycardLib::PAYCARD_MODE_VOID); // check for posts before drawing anything, so we can redirect if (isset($_REQUEST['reginput'])) { $input = strtoupper(trim($_REQUEST['reginput'])); // CL always exits if ($input == "CL") { PaycardLib::paycard_reset(); CoreLocal::set("msgrepeat", 1); CoreLocal::set("strRemembered", 'TO'); CoreLocal::set("toggletax", 0); CoreLocal::set("togglefoodstamp", 0); $this->change_page($this->page_url . "gui-modules/pos2.php"); return false; } elseif (Authenticate::checkPassword($input)) { $this->action = "onsubmit=\"return false;\""; $this->add_onload_command("emvSubmit();"); $this->run_transaction = true; } // if we're still here, we haven't accepted a valid amount yet; display prompt again } elseif (isset($_REQUEST['xml-resp'])) { $xml = $_REQUEST['xml-resp']; $e2e = new MercuryE2E(); $json = array(); $plugin_info = new Paycards(); $json['main_frame'] = $plugin_info->pluginUrl() . '/gui/PaycardEmvSuccess.php'; $json['receipt'] = false; $success = $e2e->handleResponseDataCap($xml); if ($success === PaycardLib::PAYCARD_ERR_OK) { $json = $e2e->cleanup($json); CoreLocal::set("strEntered", ""); CoreLocal::set("strRemembered", ""); CoreLocal::set("msgrepeat", 0); if ($json['receipt']) { $json['main_frame'] .= '?receipt=' . $json['receipt']; } } else { CoreLocal::set("msgrepeat", 0); $json['main_frame'] = MiscLib::base_url() . 'gui-modules/boxMsg2.php'; } header('Location: ' . $json['main_frame']); return false; } return true; }
private function handleResponseAuth($authResult) { $xml = new xmlData($authResult["response"]); $request = $this->last_request; $this->last_paycard_transaction_id = $request->last_paycard_transaction_id; $response = new PaycardResponse($request, $authResult); // initialize $dbTrans = Database::tDataConnect(); $program = 'Gift'; $validResponse = $xml->isValid() ? 1 : 0; $errorMsg = $xml->get_first("ERRORMSG"); $balance = $xml->get("BALANCE"); if ($validResponse) { /* tendering more than the available balance returns an "NSF" error message, but no Balance field however, the available balance is buried in the RawOutput field, so we can dig it out and fill in the missing Balance field -- as of 1/22/08, valutec appears to now be returning the Balance field normally (in its own XML field, not in RawOutput), but we still need to append it to the Message so the cashier can see it */ if ($errorMsg && substr($errorMsg, 0, 3) == "NSF") { if (!$balance || $balance === "") { $rawOutput = $xml->get("RAWOUTPUT"); $begin = strpos($rawOutput, "%1cBAL%3a"); if ($begin !== false) { $end = strpos($rawOutput, "%1c", $begin + 1); if ($end !== false && $end > $begin) { $balance = trim(urldecode(substr($rawOutput, $begin + 9, $end - $begin - 9))); } } } else { if ($balance && $balance !== "") { $errorMsg = "NSF, BAL: " . PaycardLib::paycard_moneyFormat($balance); } } } // verify that echo'd fields match our request if ($xml->get('TRANSACTIONTYPE') && $xml->get('TRANSACTIONTYPE') == $program && $xml->get('IDENTIFIER') && $xml->get('IDENTIFIER') == $identifier && $xml->get('AUTHORIZED')) { $validResponse = 1; // response was parsed normally, echo'd fields match, and other required fields are present } else { $validResponse = 4; // response was parsed as XML but fields didn't match } } $response->setBalance($balance); $resultCode = 0; $apprNumber = $xml->get('AUTHORIZATIONCODE'); $response->setApprovalNum($apprNumber); $rMsg = ''; if ($apprNumber != '' && $xml->get('AUTHORIZED') == 'true') { $validResponse = 1; $resultCode = 1; $rMsg = 'Approved'; } else { $rMsg = substr($xml->get_first('ERRORMSG'), 0, 100); } $response->setResultMsg($rMsg); $response->setResultCode($resultCode); $response->setResponseCode($resultCode); $response->setNormalizedCode($resultCode); $response->setValid($validResponse); try { $response->saveResponse(); } catch (Exception $ex) { } // check for communication errors (any cURL error or any HTTP code besides 200) if ($authResult['curlErr'] != CURLE_OK || $authResult['curlHTTP'] != 200) { if ($authResult['curlHTTP'] == '0') { CoreLocal::set("boxMsg", "No response from processor<br />\n The transaction did not go through"); return PaycardLib::PAYCARD_ERR_PROC; } return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_COMM); } // check for data errors (any failure to parse response XML or echo'd field mismatch if ($validResponse != 1) { // invalid server response, we don't know if the transaction was processed (use carbon) return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_DATA); } $amtUsed = $xml->get('CARDAMOUNTUSED'); if ($amtUsed) { $request->changeAmount($amtUsed); } // put the parsed response into session so the caller, receipt printer, etc can get the data they need CoreLocal::set("paycard_response", array()); CoreLocal::set("paycard_response", $xml->array_dump()); $temp = CoreLocal::get("paycard_response"); $temp["Balance"] = $temp["BALANCE"]; CoreLocal::set("paycard_response", $temp); // comm successful, check the Authorized, AuthorizationCode and ErrorMsg fields if ($xml->get('AUTHORIZED') == 'true' && $xml->get('AUTHORIZATIONCODE') != '' && $xml->get_first('ERRORMSG') == '') { return PaycardLib::PAYCARD_ERR_OK; // authorization approved, no error } // the authorizor gave us some failure code // authorization failed, response fields in $_SESSION["paycard_response"] CoreLocal::set("boxMsg", "Processor error: " . $errorMsg); return PaycardLib::PAYCARD_ERR_PROC; }
/** Add a percent discount notification @param $strl discount percentage @param $json keyed array @return An array see Parser::default_json() @deprecated Use discountnotify() instead. This just adds hard-coded percentages and PLUs that likely aren't applicable anywhere but the Wedge. */ public static function percentDiscount($strl, $json = array()) { if ($strl == 10.01) { $strl = 10; } if (!is_numeric($strl) || $strl > 100 || $strl < 0) { $json['output'] = DisplayLib::boxMsg(_("discount invalid"), '', false, DisplayLib::standardClearButton()); } else { if ($strl != 0) { TransRecord::discountnotify($strl); } $dbc = Database::tDataConnect(); $dbc->query("update localtemptrans set percentDiscount = " . $strl); $chk = self::ttl(); if ($chk !== true) { $json['main_frame'] = $chk; } $json['output'] = DisplayLib::lastpage(); } return $json; }
*********************************************************************************/ ini_set('display_errors', 'Off'); include_once dirname(__FILE__) . '/../lib/AutoLoader.php'; /* * Mark items as shrink/unsellable. * * DDD is WFC lingo for unsaleable goods (dropped, dented, damaged, * etc) Functionally this works like canceling a transaction, but * marks items with a different trans_status (Z) so these items can be * pulled out in later reports. A mappable reason code is stored in * localtemptrans.numflag. */ $shrinkReason = 0; if (CoreLocal::get('shrinkReason') > 0) { $shrinkReason = CoreLocal::get('shrinkReason'); } $db = Database::tDataConnect(); $query = "UPDATE localtemptrans SET trans_status='Z', numflag=" . (int) $shrinkReason; $db->query($query); CoreLocal::set("plainmsg", "items marked as shrink/unsellable"); CoreLocal::set("End", 2); CoreLocal::set('shrinkReason', 0); $_REQUEST['receiptType'] = 'ddd'; $_REQUEST['ref'] = ReceiptLib::receiptNumber(); TransRecord::finalizeTransaction(true); ob_start(); include realpath(dirname(__FILE__) . '/ajax-end.php'); ob_end_clean(); if (!headers_send()) { header("Location: " . MiscLib::base_url() . "gui-modules/pos2.php"); }
/** Add or update a discount module in the current transaction. Automatically subtotals if the discount changes. */ public static function updateDiscount(DiscountModule $mod, $do_subtotal = true) { $changed = true; // serialize/unserialize before saving to avoid // auto-session errors w/ undefined classes $current_discounts = unserialize(CoreLocal::get('CurrentDiscounts')); if (!is_array($current_discounts)) { $current_discounts = array(); } /** Examine current discounts to see if this one has already applied */ foreach ($current_discounts as $class => $obj) { if ($mod->name == $obj->name) { if ($mod->percentage() == $obj->percentage()) { $changed = false; } break; } } if ($changed) { /** Add object to the list of active discounts Then loop through to see whether it changes the effective discount with stacking settings taken into account */ $current_discounts[$mod->name] = $mod; $old_effective_discount = CoreLocal::get('percentDiscount'); $new_effective_discount = 0; foreach ($current_discounts as $obj) { if (CoreLocal::get('NonStackingDiscounts') && $obj->percentage() > $new_effective_discount) { $new_effective_discount = $obj->percentage(); } elseif (CoreLocal::get('NonStackingDiscounts') == 0) { $new_effective_discount += $obj->percentage(); } } /** When discount changes: 1. Update the session value 2. Update the localtemptrans.percentDiscount value 3. Subtotal the transaction */ if ($old_effective_discount != $new_effective_discount) { CoreLocal::set('percentDiscount', $new_effective_discount); $dbc = Database::tDataConnect(); $dbc->query('UPDATE localtemptrans SET percentDiscount=' . (int) $new_effective_discount); if ($do_subtotal) { PrehLib::ttl(); } } // serialize/unserialize before saving to avoid // auto-session errors w/ undefined classes CoreLocal::set('CurrentDiscounts', serialize($current_discounts)); } }