public function parse($str) { $ret = $this->default_json(); if (CoreLocal::get('memberID') == '0') { $ret['output'] = DisplayLib::boxMsg(_("Apply member number first"), _('No member selected'), false, array_merge(array('Member Search [ID]' => 'parseWrapper(\'ID\');'), DisplayLib::standardClearButton())); return $ret; } if ($str == 'ACCESS') { if (CoreLocal::get('AccessQuickMenu') != '' && class_exists('QuickMenuLauncher')) { $qm = new QuickMenuLauncher(); return $qm->parse('QM' . CoreLocal::get('AccessQuickMenu')); } else { $str = 'ACCESS0'; } } if ($str !== 'ACCESS6' && CoreLocal::get('AccessSelection') === '') { CoreLocal::set('AccessSelection', $str); $ret['main_frame'] = MiscLib::baseURL() . 'gui-modules/adminlogin.php?class=AccessProgramParser'; return $ret; } else { CoreLocal::set('AccessSelection', ''); } $selection = substr($str, 6); TransRecord::addRecord(array('upc' => 'ACCESS', 'description' => 'ACCESS SIGNUP', 'quantity' => 1, 'ItemQtty' => 1, 'numflag' => $selection)); $ret['output'] = DisplayLib::lastpage(); $ret['receipt'] = 'accessSignupSlip'; return $ret; }
public function testDatabase() { $db = Database::tDataConnect(); $this->assertInstanceOf('\\COREPOS\\pos\\lib\\SQLManager', $db); $this->assertEquals(CoreLocal::get('tDatabase'), $db->default_db); $db = Database::pDataConnect(); $this->assertInstanceOf('\\COREPOS\\pos\\lib\\SQLManager', $db); $this->assertEquals(CoreLocal::get('pDatabase'), $db->default_db); $this->assertEquals(1, Database::gettransno(-1)); // not a real emp_no $db = Database::tDataConnect(); $matches = Database::localMatchingColumns($db, 'localtrans', 'localtemptrans'); $this->assertInternalType('string', $matches); $this->assertRegExp('/(.+)/', $matches); $globals = array('CashierNo' => 9999, 'cashier' => 'TRAINING', 'LoggedIn' => 0, 'TransNo' => 1, 'TTLFlag' => 0, 'FntlFlag' => 0, 'TaxExempt' => 0); Database::setglobalvalues($globals); $this->assertEquals(9999, CoreLocal::get('CashierNo')); $this->assertEquals('TRAINING', CoreLocal::get('cashier')); $this->assertEquals(0, CoreLocal::get('LoggedIn')); $this->assertEquals(1, CoreLocal::get('transno')); $this->assertEquals(0, CoreLocal::get('ttlflag')); $this->assertEquals(0, CoreLocal::get('fntlflag')); $this->assertEquals(0, CoreLocal::get('TaxExempt')); Database::loadglobalvalues(); // reload session from db. shouldn't change. $this->assertEquals(9999, CoreLocal::get('CashierNo')); $this->assertEquals('TRAINING', CoreLocal::get('cashier')); $this->assertEquals(0, CoreLocal::get('LoggedIn')); $this->assertEquals(1, CoreLocal::get('transno')); $this->assertEquals(0, CoreLocal::get('ttlflag')); $this->assertEquals(0, CoreLocal::get('fntlflag')); $this->assertEquals(0, CoreLocal::get('TaxExempt')); Database::setglobalvalue('TTLFlag', 1); Database::loadglobalvalues(); $this->assertEquals(1, CoreLocal::get('ttlflag')); Database::setglobalflags(0); Database::loadglobalvalues(); $this->assertEquals(0, CoreLocal::get('ttlflag')); $this->assertEquals(0, CoreLocal::get('fntlflag')); if (!class_exists('lttLib')) { include dirname(__FILE__) . '/lttLib.php'; } lttLib::clear(); $record = lttLib::genericRecord(); $record['upc'] = '0000000000000'; $record['description'] = uniqid('TEST-'); TransRecord::addRecord($record); SuspendLib::suspendorder(); $db = Database::mDataConnect(); $query = "\n SELECT *\n FROM suspended\n WHERE upc='{$record['upc']}'\n AND description='{$record['description']}'\n AND datetime >= " . $db->curdate(); $result = $db->query($query); $this->assertNotEquals(false, $result, 'Could not query suspended record'); $this->assertEquals(1, $db->num_rows($result), 'Could not find suspended record'); $row = $db->fetch_row($result); $this->assertInternalType('array', $row, 'Invalid suspended record'); foreach ($record as $column => $value) { $this->assertArrayHasKey($column, $row, 'Suspended missing ' . $column); $this->assertEquals($value, $row[$column], 'Suspended mismatch on column ' . $column); } }
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 addItem($row, $quantity, $priceObj) { if ($quantity == 0) { 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['discounttype'] > 0 ? 0 : $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 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; }
function parse($str) { Database::getsubtotals(); $amt = CoreLocal::get('runningTotal') - CoreLocal::get('transDiscount'); $madCoup = number_format($amt * 0.05, 2); if ($madCoup > 2.5) { $madCoup = 2.5; } TransRecord::addRecord(array('upc' => "MAD Coupon", 'description' => "Member Appreciation Coupon", 'trans_type' => "I", 'trans_subtype' => "CP", 'trans_status' => "C", 'quantity' => 1, 'ItemQtty' => 1, 'unitPrice' => -1 * $madCoup, 'total' => -1 * $madCoup, 'regPrice' => -1 * $madCoup, 'voided' => 17)); $ret = $this->default_json(); $ret['output'] = DisplayLib::lastpage(); $ret['redraw_footer'] = true; return $ret; }
function parse($str) { $json = $this->default_json(); CoreLocal::set("memberID", CoreLocal::get('defaultNonMem')); CoreLocal::set("memMsg", "End of Shift"); TransRecord::addRecord(array('upc' => 'ENDOFSHIFT', 'description' => 'End of Shift', 'trans_type' => 'S')); Database::getsubtotals(); $chk = self::ttl(); if ($chk !== true) { $json['main_frame'] = $chk; return $json; } CoreLocal::set("runningtotal", CoreLocal::get("amtdue")); return PrehLib::tender("CA", CoreLocal::get("runningtotal") * 100); }
function parse($str) { $ret = $this->default_json(); if (strlen($str) == 4) { CoreLocal::set('qmInput', $str); $desc = $this->descriptions[$str]; $opts = array($desc . ' (Steak)' => 'M', $desc . ' (Risotto)' => 'V', $desc . ' (Squash V)' => 'S'); if ($str == 1041) { $opts[$desc . ' (Kids)'] = 'K'; } CoreLocal::set('qmNumber', $opts); $plugin_info = new QuickMenus(); $ret['main_frame'] = $plugin_info->pluginUrl() . '/QMDisplay.php'; return $ret; } else { $flag = strtoupper($str[4]); $plu = substr($str, 0, 4); $price = $flag == 'K' ? 5.0 : 20.0; TransRecord::addRecord(array('upc' => str_pad($plu, 13, '0', STR_PAD_LEFT), 'description' => $this->descriptions[$plu] . ' (' . $flag . ')', 'trans_type' => 'I', 'department' => 235, 'quantity' => 1.0, 'ItemQtty' => 1.0, 'unitPrice' => $price, 'total' => $price, 'regPrice' => $price, 'charflag' => $flag)); $ret['output'] = DisplayLib::lastpage(); $ret['redraw_footer'] = True; return $ret; } }
function addItem($row, $quantity, $priceObj) { if ($quantity == 0) { return false; } $pricing = $priceObj->priceInfo($row, $quantity); // enforce limit on discounting sale items $dsi = CoreLocal::get('DiscountableSaleItems'); if ($dsi == 0 && $dsi !== '' && $priceObj->isSale()) { $row['discount'] = 0; } if ($priceObj->isSale()) { $disc = $pricing['unitPrice'] - $row['specialgroupprice'] / $row['specialquantity']; if ($priceObj->isMemberSale() || $priceObj->isStaffSale()) { $pricing['memDiscount'] = MiscLib::truncate2($disc * $quantity); } else { $pricing['discount'] = MiscLib::truncate2($disc * $quantity); } } else { $pricing['unitPrice'] = $row['groupprice'] / $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' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $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 parse($str) { $ret = $this->default_json(); if (substr($str, 0, 8) == 'DROPDROP') { // repeat cashier's input, if any if (strlen($str) > 8) { $json['retry'] = substr($str, 8); } // redraw right side of the screen $json['scale'] = true; return $ret; } else { // add drop record to transaction $amt = 0; if (substr($str, 0, 4) == 'DROP') { $amt = substr($str, 4); } else { $amt = substr($str, 0, strlen($str) - 4); } TransRecord::addRecord(array('upc' => 'CASHDROP', 'description' => 'CASHDROP', 'trans_type' => "L", 'trans_subtype' => 'CA', 'total' => $amt / 100.0)); $ret['main_frame'] = MiscLib::base_url() . "gui-modules/pos2.php"; return $ret; } }
function discountupc($upc, $item_num = -1, $pd = 0) { $lastpageflag = 1; $deliflag = 0; $quantity = 0; if (strpos($upc, "*") && (strpos($upc, "**") || strpos($upc, "*") == 0 || strpos($upc, "*") == strlen($upc) - 1)) { $upc = "stop"; } elseif (strpos($upc, "*")) { $voidupc = explode("*", $upc); if (!is_numeric($voidupc[0])) { $upc = "stop"; } else { $quantity = $voidupc[0]; $upc = $voidupc[1]; $weight = 0; } } elseif (!is_numeric($upc) && !strpos($upc, "DP")) { $upc = "stop"; } else { $quantity = 1; $weight = CoreLocal::get("weight"); } $scaleprice = 0; if (is_numeric($upc)) { $upc = substr("0000000000000" . $upc, -13); if (substr($upc, 0, 3) == "002" && substr($upc, -5) != "00000") { $scaleprice = substr($upc, 10, 4) / 100; $upc = substr($upc, 0, 8) . "0000"; $deliflag = 1; } elseif (substr($upc, 0, 3) == "002" && substr($upc, -5) == "00000") { $deliflag = 1; } } if ($upc == "stop") { return DisplayLib::inputUnknown(); } $db = Database::tDataConnect(); $query = "select sum(ItemQtty) as voidable, sum(quantity) as vquantity, max(scale) as scale, " . "max(volDiscType) as volDiscType from localtemptrans where upc = '" . $upc . "' and unitPrice = " . $scaleprice . " and discounttype <> 3 group by upc"; $result = $db->query($query); $num_rows = $db->num_rows($result); if ($num_rows == 0) { return DisplayLib::boxMsg(_("Item not found: ") . $upc, '', false, DisplayLib::standardClearButton()); } $row = $db->fetch_array($result); if ($row["scale"] == 1 && $weight > 0) { $quantity = $weight - CoreLocal::get("tare"); CoreLocal::set("tare", 0); } $volDiscType = $row["volDiscType"]; $voidable = MiscLib::nullwrap($row["voidable"]); $VolSpecial = 0; $volume = 0; $scale = MiscLib::nullwrap($row["scale"]); //----------------------Void Item------------------ $query_upc = "select ItemQtty,foodstamp,discounttype,mixMatch,cost,\n numflag,charflag,unitPrice,discounttype,regPrice,discount,\n memDiscount,discountable,description,trans_type,trans_subtype,\n department,tax,VolSpecial\n from localtemptrans where upc = '" . $upc . "' and unitPrice = " . $scaleprice . " and trans_id={$item_num}"; $result = $db->query($query_upc); $row = $db->fetch_array($result); $ItemQtty = $row["ItemQtty"]; $foodstamp = MiscLib::nullwrap($row["foodstamp"]); $discounttype = MiscLib::nullwrap($row["discounttype"]); $mixMatch = MiscLib::nullwrap($row["mixMatch"]); $cost = isset($row["cost"]) ? -1 * $row["cost"] : 0; $numflag = isset($row["numflag"]) ? $row["numflag"] : 0; $charflag = isset($row["charflag"]) ? $row["charflag"] : 0; $unitPrice = $row["unitPrice"]; if (CoreLocal::get("isMember") != 1 && $row["discounttype"] == 2 || CoreLocal::get("isStaff") == 0 && $row["discounttype"] == 4) { $unitPrice = $row["regPrice"]; } elseif ((CoreLocal::get("isMember") == 1 && $row["discounttype"] == 2 || CoreLocal::get("isStaff") != 0 && $row["discounttype"] == 4) && $row["unitPrice"] == $row["regPrice"]) { $db_p = Database::pDataConnect(); $query_p = "select special_price from products where upc = '" . $upc . "'"; $result_p = $db_p->query($query_p); $row_p = $db_p->fetch_array($result_p); $unitPrice = $row_p["special_price"]; } $discount = -1 * $row["discount"]; $memDiscount = -1 * $row["memDiscount"]; $discountable = $row["discountable"]; $CardNo = CoreLocal::get("memberID"); $discounttype = MiscLib::nullwrap($row["discounttype"]); if ($discounttype == 3) { $quantity = -1 * $ItemQtty; } elseif ($quantity != 0) { TransRecord::addRecord(array('upc' => $upc, 'description' => $row["description"], 'trans_type' => $row["trans_type"], 'trans_subtype' => $row["trans_subtype"], 'trans_status' => "V", 'department' => $row["department"], 'quantity' => $quantity, 'unitPrice' => $unitPrice, 'total' => $total, 'regPrice' => $row["regPrice"], 'scale' => $scale, 'tax' => $row["tax"], 'foodstamp' => $foodstamp, 'discount' => $discount, 'memDiscount' => $memDiscount, 'discountable' => $discountable, 'discounttype' => $discounttype, 'quantity' => $quantity, 'volDiscType' => $volDiscType, 'volume' => $volume, 'VolSpecial' => $VolSpecial, 'mixMatch' => $mixMatch, 'voided' => 1, 'cost' => $cost, 'numflag' => $numflag, 'charflag' => $charflag)); if ($row["trans_type"] != "T") { CoreLocal::set("ttlflag", 0); } $db = Database::pDataConnect(); $chk = $db->query("SELECT deposit FROM products WHERE upc='{$upc}'"); if ($db->num_rows($chk) > 0) { $dpt = array_pop($db->fetch_row($chk)); if ($dpt > 0) { $dupc = (int) $dpt; return $this->voidupc(-1 * $quantity . "*" . $dupc, True); } } } return ""; }
function addItem($row, $quantity, $priceObj) { if ($quantity == 0) { return false; } $pricing = $priceObj->priceInfo($row, $quantity); $department = $row['department']; // enforce limit on discounting sale items $dsi = CoreLocal::get('DiscountableSaleItems'); if ($dsi == 0 && $dsi !== '' && $priceObj->isSale()) { $row['discount'] = 0; } $mixMatch = $row['mixmatchcode']; /* group definition: number of items that make up a group, price for a full set. Use "special" rows if the item is on sale */ $groupQty = $row['quantity']; $groupPrice = $row['groupprice']; if ($priceObj->isSale()) { $groupQty = $row['specialquantity']; $groupPrice = $row['specialgroupprice']; } /* not straight-up interchangable * ex: buy item A, get $1 off item B * need strict pairs AB * * type 3 tries to split the discount amount * across A & B's departments; type 4 * does not */ $qualMM = abs($mixMatch); $discMM = -1 * abs($mixMatch); $dbt = Database::tDataConnect(); // lookup existing qualifiers (i.e., item As) // by-weight items are rounded down here $q1 = "SELECT floor(sum(ItemQtty)),max(department) \n FROM localtemptrans WHERE mixMatch='{$qualMM}' \n and trans_status <> 'R'"; $r1 = $dbt->query($q1); $quals = 0; $dept1 = 0; if ($dbt->num_rows($r1) > 0) { $rowq = $dbt->fetch_row($r1); $quals = round($rowq[0]); $dept1 = $rowq[1]; } // lookup existing discounters (i.e., item Bs) // by-weight items are counted per-line here // // extra checks to make sure the maximum // discount on scale items is "free" $q2 = "SELECT sum(CASE WHEN scale=0 THEN ItemQtty ELSE 1 END),\n max(department),max(scale),max(total) FROM localtemptrans \n WHERE mixMatch='{$discMM}' \n and trans_status <> 'R'"; $r2 = $dbt->query($q2); $dept2 = 0; $discs = 0; $discountIsScale = false; $scaleDiscMax = 0; if ($dbt->num_rows($r2) > 0) { $rowd = $dbt->fetch_row($r2); $discs = round($rowd[0]); $dept2 = $rowd[1]; if ($rowd[2] == 1) { $discountIsScale = true; } $scaleDiscMax = $rowd[3]; } if ($quantity != (int) $quantity && $mixMatch < 0) { $discountIsScale = true; $scaleDiscMax = $quantity * $unitPrice; } // items that have already been used in an AB set $q3 = "SELECT sum(matched) FROM localtemptrans WHERE\n mixmatch IN ('{$qualMM}','{$discMM}')"; $r3 = $dbt->query($q3); $matches = 0; if ($r3 && $dbt->num_rows($r3) > 0) { $w3 = $dbt->fetch_row($r3); $matches = $w3[0]; } // reduce totals by existing matches // implicit: quantity required for B = 1 // i.e., buy X item A save on 1 item B $matches = $matches / $groupQty; $quals -= $matches * ($groupQty - 1); $discs -= $matches; // where does the currently scanned item go? if ($mixMatch > 0) { $quals = $quals > 0 ? $quals + floor($quantity) : floor($quantity); $dept1 = $department; } else { // again, scaled items count once per line if ($quantity != (int) $quantity) { $discs = $discs > 0 ? $discs + 1 : 1; } else { $discs = $discs > 0 ? $discs + $quantity : $quantity; } $dept2 = $department; } // count up complete sets $sets = 0; while ($discs > 0 && $quals >= $groupQty - 1) { $discs -= 1; $quals -= $groupQty - 1; $sets++; } if ($sets > 0) { $maxDiscount = $sets * $groupPrice; if ($scaleDiscMax != 0 && $maxDiscount > $scaleDiscMax) { $maxDiscount = $scaleDiscMax; } // if the current item is by-weight, quantity // decrement has to be corrected, but matches // should still be an integer $ttlMatches = $sets; if ($quantity != (int) $quantity) { $sets = $quantity; } $quantity = $quantity - $sets; 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' => $sets, 'unitPrice' => $pricing['unitPrice'], 'total' => MiscLib::truncate2($sets * $pricing['unitPrice']), 'regPrice' => $pricing['regPrice'], 'scale' => $row['scale'], 'tax' => $row['tax'], 'foodstamp' => $row['foodstamp'], 'memDiscount' => $priceObj->isMemberSale() || $priceObj->isStaffSale() ? MiscLib::truncate2($maxDiscount) : 0, 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $sets, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $row['groupprice'], 'mixMatch' => $row['mixmatchcode'], 'matched' => $ttlMatches * $groupQty, 'cost' => isset($row['cost']) ? $row['cost'] * $sets * $groupQty : 0.0, 'numflag' => isset($row['numflag']) ? $row['numflag'] : 0, 'charflag' => isset($row['charflag']) ? $row['charflag'] : '')); if (!$priceObj->isMemberSale() && !$priceObj->isStaffSale()) { TransRecord::additemdiscount($dept1, MiscLib::truncate2($maxDiscount / 2.0)); TransRecord::additemdiscount($dept2, MiscLib::truncate2($maxDiscount / 2.0)); } } /* any remaining quantity added without grouping discount */ if ($quantity > 0) { 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'], 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $quantity, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $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; }
private function addDeposit($upc) { $upc = str_pad($upc, 13, '0', STR_PAD_LEFT); $db = Database::pDataConnect(); $query = "select description,scale,tax,foodstamp,discounttype,\n discount,department,normal_price\n from products where upc='" . $upc . "'"; $result = $db->query($query); if ($db->num_rows($result) <= 0) { return; } $row = $db->fetch_array($result); $description = $row["description"]; $description = str_replace("'", "", $description); $description = str_replace(",", "", $description); $scale = 0; if ($row["scale"] != 0) { $scale = 1; } list($tax, $foodstamp, $discountable) = PrehLib::applyToggles($row['tax'], $row['foodstamp'], $row['discount']); $discounttype = MiscLib::nullwrap($row["discounttype"]); $quantity = 1; if (CoreLocal::get("quantity") != 0) { $quantity = CoreLocal::get("quantity"); } $save_refund = CoreLocal::get("refund"); TransRecord::addRecord(array('upc' => $upc, 'description' => $description, 'trans_type' => 'I', 'trans_subtype' => 'AD', 'department' => $row['department'], 'quantity' => $quantity, 'ItemQtty' => $quantity, 'unitPrice' => $row['normal_price'], 'total' => $quantity * $row['normal_price'], 'regPrice' => $row['normal_price'], 'scale' => $scale, 'tax' => $tax, 'foodstamp' => $foodstamp, 'discountable' => $discountable, 'discounttype' => $discounttype)); CoreLocal::set("refund", $save_refund); }
/** Add tender to the transaction */ public function add() { TransRecord::addRecord(array('description' => $this->name_string, 'trans_type' => 'T', 'trans_subtype' => $this->tender_code, 'total' => -1 * $this->amount)); }
function preprocess() { $this->box_color = "coloredArea"; $this->msg = "Undo transaction"; if (isset($_REQUEST['reginput'])) { $trans_num = strtoupper($_REQUEST['reginput']); // clear/cancel undo attempt if ($trans_num == "" || $trans_num == "CL") { $this->change_page($this->page_url . "gui-modules/pos2.php"); return False; } // error: malformed transaction number if (!strpos($trans_num, "-")) { $this->box_color = "errorColoredArea"; $this->msg = "Transaction not found"; return True; } $temp = explode("-", $trans_num); // error: malformed transaction number (2) if (count($temp) != 3) { $this->box_color = "errorColoredArea"; $this->msg = "Transaction not found"; return True; } $emp_no = $temp[0]; $register_no = $temp[1]; $old_trans_no = $temp[2]; // error: malformed transaction number (3) if (!is_numeric($emp_no) || !is_numeric($register_no) || !is_numeric($old_trans_no)) { $this->box_color = "errorColoredArea"; $this->msg = "Transaction not found"; return True; } $db = 0; $query = ""; if ($register_no == CoreLocal::get("laneno")) { // look up transation locally $db = Database::tDataConnect(); $query = "select upc, description, trans_type, trans_subtype,\n trans_status, department, quantity, scale, unitPrice,\n total, regPrice, tax, foodstamp, discount, memDiscount,\n discountable, discounttype, voided, PercentDiscount,\n ItemQtty, volDiscType, volume, VolSpecial, mixMatch,\n matched, card_no, trans_id\n from localtranstoday where register_no = {$register_no}\n and emp_no = {$emp_no} and trans_no = {$old_trans_no}\n and datetime >= " . $db->curdate() . "\n and trans_status <> 'X'\n order by trans_id"; } else { if (CoreLocal::get("standalone") == 1) { // error: remote lookups won't work in standalone $this->box_color = "errorColoredArea"; $this->msg = "Transaction not found"; return True; } else { // look up transaction remotely $db = Database::mDataConnect(); $query = "select upc, description, trans_type, trans_subtype,\n trans_status, department, quantity, scale, unitPrice,\n total, regPrice, tax, foodstamp, discount, memDiscount,\n discountable, discounttype, voided, PercentDiscount,\n ItemQtty, volDiscType, volume, VolSpecial, mixMatch,\n matched, card_no, trans_id\n from dtransactions where register_no = {$register_no}\n and emp_no = {$emp_no} and trans_no = {$old_trans_no}\n and datetime >= " . $db->curdate() . "\n and trans_status <> 'X'\n order by trans_id"; } } $result = $db->query($query); // transaction not found if ($db->num_rows($result) < 1) { $this->box_color = "errorColoredArea"; $this->msg = "Transaction not found"; return True; } /* change the cashier to the original transaction's cashier */ $prevCashier = CoreLocal::get("CashierNo"); CoreLocal::set("CashierNo", $emp_no); CoreLocal::set("transno", Database::gettransno($emp_no)); /* rebuild the transaction, line by line, in reverse */ $card_no = 0; TransRecord::addcomment("VOIDING TRANSACTION {$trans_num}"); while ($row = $db->fetch_array($result)) { $card_no = $row["card_no"]; if ($row["upc"] == "TAX") { //TransRecord::addtax(); } elseif ($row["trans_type"] == "T") { if ($row["description"] == "Change") { TransRecord::addchange(-1 * $row["total"]); } elseif ($row["description"] == "FS Change") { TransRecord::addfsones(-1 * $row["total"]); } else { TransRecord::addtender($row["description"], $row["trans_subtype"], -1 * $row["total"]); } } elseif (strstr($row["description"], "** YOU SAVED")) { $temp = explode("\$", $row["description"]); TransRecord::adddiscount(substr($temp[1], 0, -3), $row["department"]); } elseif ($row["upc"] == "FS Tax Exempt") { TransRecord::addfsTaxExempt(); } elseif (strstr($row["description"], "% Discount Applied")) { $temp = explode("%", $row["description"]); TransRecord::discountnotify(substr($temp[0], 3)); } elseif ($row["description"] == "** Order is Tax Exempt **") { TransRecord::addTaxExempt(); } elseif ($row["description"] == "** Tax Excemption Reversed **") { TransRecord::reverseTaxExempt(); } elseif ($row["description"] == " * Manufacturers Coupon") { TransRecord::addCoupon($row["upc"], $row["department"], -1 * $row["total"]); } elseif (strstr($row["description"], "** Tare Weight")) { $temp = explode(" ", $row["description"]); TransRecord::addTare($temp[3] * 100); } elseif ($row["upc"] == "DISCOUNT") { //TransRecord::addTransDiscount(); } elseif ($row["trans_status"] != "M" && $row["upc"] != "0" && (is_numeric($row["upc"]) || strstr($row["upc"], "DP"))) { $row["trans_status"] = "V"; $row["total"] *= -1; $row["discount"] *= -1; $row["memDiscount"] *= -1; $row["quantity"] *= -1; $row["ItemQtty"] *= -1; TransRecord::addRecord($row); } } PrehLib::setMember($card_no, 1); CoreLocal::set("autoReprint", 0); /* do NOT restore logged in cashier until this transaction is complete */ $this->change_page($this->page_url . "gui-modules/undo_confirm.php"); return False; } return True; }
/** Void the given UPC @param $upc [string] upc to void. Optionally including quantity and asterisk @param $item_num [int] trans_id of record to void. Optional. @param $json parser return value structure */ public function voidupc($upc, $json, $item_num = -1) { $lastpageflag = 1; $deliflag = false; $quantity = 0; /** If UPC contains an asterisk, extract quantity and validate input. Otherwise use quantity 1. */ if (strstr($upc, '*')) { list($quantity, $upc) = explode('*', $upc, 2); if ($quantity === '' || $upc === '' || !is_numeric($quantity) || !is_numeric($upc)) { $json['output'] = DisplayLib::inputUnknown(); return $json; } else { $weight = 0; } } else { $quantity = 1; $weight = CoreLocal::get("weight"); } $scaleprice = 0; if (is_numeric($upc)) { $upc = substr("0000000000000" . $upc, -13); if (substr($upc, 0, 3) == "002" && substr($upc, -5) != "00000") { $scaleprice = substr($upc, 10, 4) / 100; $upc = substr($upc, 0, 8) . "0000"; $deliflag = true; } else { if (substr($upc, 0, 3) == "002" && substr($upc, -5) == "00000") { $scaleprice = $this->scaleprice; $deliflag = true; } } } $db = Database::tDataConnect(); $query = "SELECT SUM(ItemQtty) AS voidable, \n SUM(quantity) AS vquantity,\n MAX(scale) AS scale,\n MAX(volDiscType) AS volDiscType \n FROM localtemptrans \n WHERE upc = '" . $upc . "'"; if ($deliflag) { $query .= ' AND unitPrice = ' . $scaleprice; } $query .= ' GROUP BY upc'; $result = $db->query($query); $num_rows = $db->num_rows($result); if ($num_rows == 0) { $json['output'] = DisplayLib::boxMsg(_("Item not found: ") . $upc, '', false, DisplayLib::standardClearButton()); return $json; } $row = $db->fetch_array($result); if ($row["scale"] == 1 && $weight > 0) { $quantity = $weight - CoreLocal::get("tare"); CoreLocal::set("tare", 0); } $volDiscType = $row["volDiscType"]; $voidable = MiscLib::nullwrap($row["voidable"]); $VolSpecial = 0; $volume = 0; $scale = MiscLib::nullwrap($row["scale"]); if ($voidable == 0 && $quantity == 1) { $json['output'] = DisplayLib::boxMsg(_("Item already voided"), '', false, DisplayLib::standardClearButton()); return $json; } elseif ($voidable == 0 && $quantity > 1) { $json['output'] = DisplayLib::boxMsg(_("Items already voided"), '', false, DisplayLib::standardClearButton()); return $json; } elseif ($scale == 1 && $quantity < 0) { $json['output'] = DisplayLib::boxMsg(_("tare weight cannot be greater than item weight"), '', false, DisplayLib::standardClearButton()); return $json; } elseif ($voidable < $quantity && $row["scale"] == 1) { $message = _("Void request exceeds") . "<br />" . _("weight of item rung in") . "<p><b>" . sprintf(_("You can void up to %.2f lb"), $row['voidable']) . "</b>"; $json['output'] = DisplayLib::boxMsg($message, '', false, DisplayLib::standardClearButton()); return $json; } elseif ($voidable < $quantity) { $message = _("Void request exceeds") . "<br />" . _("number of items rung in") . "<p><b>" . sprintf(_("You can void up to %d"), $row['voidable']) . "</b>"; $json['output'] = DisplayLib::boxMsg($message, '', false, DisplayLib::standardClearButton()); return $json; } //----------------------Void Item------------------ $query_upc = "SELECT \n ItemQtty,\n foodstamp,\n discounttype,\n mixMatch,\n cost,\n numflag,\n charflag,\n unitPrice,\n total,\n discounttype,\n regPrice,\n discount,\n memDiscount,\n discountable,\n description,\n trans_type,\n trans_subtype,\n department,\n tax,\n VolSpecial,\n matched,\n scale,\n trans_id\n FROM localtemptrans \n WHERE upc = '" . $upc . "'"; if ($deliflag) { $query_upc .= ' AND unitPrice = ' . $scaleprice; } if ($item_num != -1) { $query_upc .= ' AND trans_id = ' . $item_num; } else { $query_upc .= ' AND voided=0 ORDER BY total'; } $result = $db->query($query_upc); $row = $db->fetch_array($result); $foodstamp = MiscLib::nullwrap($row["foodstamp"]); $discounttype = MiscLib::nullwrap($row["discounttype"]); $mixMatch = MiscLib::nullwrap($row["mixMatch"]); $matched = -1 * $row['matched']; $item_num = $row['trans_id']; $cost = $row['cost']; $numflag = $row['numflag']; $charflag = $row['charflag']; $unitPrice = $row["unitPrice"]; /** 11Jun14 Andy Convert unitPrice to/from sale price based on member status. I'm not sure this is actually necessary. */ if (CoreLocal::get("isMember") != 1 && $row["discounttype"] == 2 || CoreLocal::get("isStaff") == 0 && $row["discounttype"] == 4) { $unitPrice = $row["regPrice"]; } elseif ((CoreLocal::get("isMember") == 1 && $row["discounttype"] == 2 || CoreLocal::get("isStaff") != 0 && $row["discounttype"] == 4) && $row["unitPrice"] == $row["regPrice"]) { $db_p = Database::pDataConnect(); $query_p = "select special_price from products where upc = '" . $upc . "'"; $result_p = $db_p->query($query_p); $row_p = $db_p->fetch_array($result_p); $unitPrice = $row_p["special_price"]; } $discount = -1 * $row["discount"]; $memDiscount = -1 * $row["memDiscount"]; $discountable = $row["discountable"]; $quantity = -1 * $quantity; $total = $quantity * $unitPrice; if ($row['unitPrice'] == 0) { $total = $quantity * $row['total']; } elseif ($row['total'] != $total && $row['scale'] == 1) { /** If the total does not match quantity times unit price, the cashier probably manually specified a quantity i.e., VD{qty}*{upc}. This is probably OK for non-weight items. Each record should be the same and voiding multiple in one line will usually be fine. */ $total = -1 * $row['total']; } /** Check if the voiding item will exceed the limit. If so, prompt for admin password. */ if (is_numeric(CoreLocal::get('VoidLimit')) && CoreLocal::get('VoidLimit') > 0) { $currentTotal = CoreLocal::get('voidTotal'); if ($currentTotal + -1 * $total > CoreLocal::get('VoidLimit') && CoreLocal::get('voidOverride') != 1) { CoreLocal::set('strRemembered', CoreLocal::get('strEntered')); CoreLocal::set('voidOverride', 0); $json['main_frame'] = MiscLib::base_url() . 'gui-modules/adminlogin.php?class=Void'; return $json; } } $db = Database::tDataConnect(); if (CoreLocal::get("tenderTotal") < 0 && -1 * $total > CoreLocal::get("runningTotal") - CoreLocal::get("taxTotal")) { $cash = $db->query("SELECT total FROM localtemptrans WHERE trans_subtype='CA' AND total <> 0"); if ($db->num_rows($cash) > 0) { $json['output'] = DisplayLib::boxMsg(_("Item already paid for"), '', false, DisplayLib::standardClearButton()); return $json; } } if ($quantity != 0) { $update = "update localtemptrans set voided = 1 where trans_id = " . $item_num; $db->query($update); TransRecord::addRecord(array('upc' => $upc, 'description' => $row["description"], 'trans_type' => $row["trans_type"], 'trans_subtype' => $row["trans_subtype"], 'trans_status' => "V", 'department' => $row["department"], 'quantity' => $quantity, 'unitPrice' => $unitPrice, 'total' => $total, 'regPrice' => $row["regPrice"], 'scale' => $scale, 'tax' => $row["tax"], 'foodstamp' => $foodstamp, 'discount' => $discount, 'memDiscount' => $memDiscount, 'discountable' => $discountable, 'discounttype' => $discounttype, 'ItemQtty' => $quantity, 'volDiscType' => $volDiscType, 'volume' => $volume, 'VolSpecial' => $VolSpecial, 'mixMatch' => $mixMatch, 'matched' => $matched, 'voided' => 1, 'cost' => $cost, 'numflag' => $numflag, 'charflag' => $charflag)); if ($row["trans_type"] != "T") { CoreLocal::set("ttlflag", 0); } $db = Database::pDataConnect(); $chk = $db->query("SELECT deposit FROM products WHERE upc='{$upc}'"); if ($db->num_rows($chk) > 0) { $w = $db->fetch_row($chk); $dpt = $w['deposit']; if ($dpt <= 0) { return $json; // no deposit found } $db = Database::tDataConnect(); $dupc = str_pad((int) $dpt, 13, '0', STR_PAD_LEFT); $id = $db->query(sprintf("SELECT trans_id FROM localtemptrans\n WHERE upc='%s' AND voided=0 AND quantity=%d", $dupc, -1 * $quantity)); if ($db->num_rows($id) > 0) { $w = $db->fetch_row($id); $trans_id = $w['trans_id']; // pass an empty array instead of $json so // voiding the deposit doesn't result in an error // message. $this->voidupc(-1 * $quantity . "*" . $dupc, array(), $trans_id); } } } return $json; }
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; } $pricing = $priceObj->priceInfo($row, $quantity); /* group definition: number of items that make up a group, price for a full set. Use "special" rows if the item is on sale */ $groupQty = $row['quantity']; $groupPrice = $row['groupprice']; if ($priceObj->isSale()) { $groupQty = $row['specialquantity']; $groupPrice = $row['specialgroupprice']; } /* count items in the transaction from the given group Also note the total of items already rung in that did not receive a discount */ $mixMatch = $row["mixmatchcode"]; $queryt = "select sum(ItemQtty) as mmqtty, \n sum(CASE WHEN discount=0 THEN total ELSE 0 END) as unDiscountedTotal,\n mixMatch from localtemptrans \n where trans_status <> 'R' AND \n mixMatch = '" . $mixMatch . "' group by mixMatch"; if (!$mixMatch || $mixMatch == '0') { $mixMatch = 0; $queryt = "select sum(ItemQtty) as mmqtty, \n sum(CASE WHEN discount=0 THEN total ELSE 0 END) as unDiscountedTotal,\n from " . "localtemptrans where trans_status<>'R' AND " . "upc = '" . $row['upc'] . "' group by upc"; } $dbt = Database::tDataConnect(); $resultt = $dbt->query($queryt); $num_rowst = $dbt->num_rows($resultt); $trans_qty = 0; $undisc_ttl = 0; if ($num_rowst > 0) { $rowt = $dbt->fetch_array($resultt); $trans_qty = floor($rowt['mmqtty']); $undisc_ttl = $rowt['unDiscountedTotal']; } /* include the items in this ring */ $trans_qty += $quantity; /* if purchases exceed then requirement, apply the discount */ if ($trans_qty >= $groupQty) { $discountAmt = $pricing['unitPrice'] * $groupPrice; if ($trans_qty - $quantity < $groupQty) { /* this ring puts us over the threshold. extra math to account for discount on previously rung items */ $totalDiscount = $undisc_ttl * $groupPrice + $discountAmt * $quantity; $actualTotal = $pricing['unitPrice'] * $quantity - $totalDiscount; $pricing['discount'] = $totalDiscount; $pricing['unitPrice'] = $actualTotal / $quantity; } else { $pricing['discount'] = $discountAmt * $quantity; $pricing['unitPrice'] -= $discountAmt; } } /* add the item */ 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'], 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $quantity, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $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 add($qty) { TransRecord::addRecord(array('upc' => 'RRR', 'description' => $qty . ' RRR DONATED', 'trans_type' => 'I', 'VolSpecial' => $qty)); }
function addItem($row, $quantity, $priceObj) { if ($quantity == 0) { return false; } $pricing = $priceObj->priceInfo($row, $quantity); // enforce limit on discounting sale items $dsi = CoreLocal::get('DiscountableSaleItems'); if ($dsi == 0 && $dsi !== '' && $priceObj->isSale()) { $row['discount'] = 0; } /* group definition: number of items that make up a group, price for a full set. Use "special" rows if the item is on sale */ $groupQty = $row['quantity']; $groupPrice = $row['groupprice']; if ($priceObj->isSale()) { $groupQty = $row['specialquantity']; $groupPrice = $row['specialgroupprice']; } /* calculate how many complete sets are present in this scan and how many remain after complete sets */ $new_sets = floor($quantity / $groupQty); $remainder = $quantity % $groupQty; /* add complete sets */ if ($new_sets > 0) { $percentDiscount = 0; if (!$priceObj->isSale() && $pricing['unitPrice'] != $row['normal_price']) { $percentDiscount = ($row['normal_price'] - $pricing['unitPrice']) / $row['normal_price']; $groupPrice *= 1 - $percentDiscount; } else { if ($priceObj->isSale() && $pricing['unitPrice'] != $row['special_price']) { $percentDiscount = ($row['special_price'] - $pricing['unitPrice']) / $row['special_price']; $groupPrice *= 1 - $percentDiscount; } } /* discount for complete set */ $discount = $new_sets * ($pricing['unitPrice'] * $groupQty - $groupPrice); $total = $new_sets * $groupQty * $pricing['unitPrice'] - $discount; $unit = $total / ($new_sets * $groupQty); $memDiscount = 0; if ($priceObj->isMemberSale() || $priceObj->isStaffSale()) { $memDiscount = $discount; $discount = 0; } 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' => $new_sets * $groupQty, 'unitPrice' => MiscLib::truncate2($unit), 'total' => MiscLib::truncate2($total), 'regPrice' => $pricing['regPrice'], 'scale' => $row['scale'], 'tax' => $row['tax'], 'foodstamp' => $row['foodstamp'], 'discount' => $discount, 'memDiscount' => $memDiscount, 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $new_sets * $groupQty, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $row['groupprice'], 'mixMatch' => $row['mixmatchcode'], 'matched' => $new_sets * $groupQty, 'cost' => isset($row['cost']) ? $row['cost'] * $new_sets * $groupQty : 0.0, 'numflag' => isset($row['numflag']) ? $row['numflag'] : 0, 'charflag' => isset($row['charflag']) ? $row['charflag'] : '')); if ($percentDiscount != 0) { $discount -= $pricing['discount']; } TransRecord::adddiscount($discount, $row['department']); $quantity = $quantity - $new_sets * $groupQty; if ($quantity < 0) { $quantity = 0; } } /* if potential matches remain, check for sets */ if ($remainder > 0) { /* count items in the transaction from the given group, minus items that have already been used in a grouping */ $mixMatch = $row["mixmatchcode"]; $queryt = "select sum(ItemQtty - matched) as mmqtty, \n mixMatch from localtemptrans \n where trans_status <> 'R' AND \n mixMatch = '" . $mixMatch . "' group by mixMatch"; if (!$mixMatch || $mixMatch == '0') { $mixMatch = 0; $queryt = "select sum(ItemQtty - matched) as mmqtty from " . "localtemptrans where trans_status<>'R' AND " . "upc = '" . $row['upc'] . "' group by upc"; } $dbt = Database::tDataConnect(); $resultt = $dbt->query($queryt); $num_rowst = $dbt->num_rows($resultt); $trans_qty = 0; if ($num_rowst > 0) { $rowt = $dbt->fetch_array($resultt); $trans_qty = floor($rowt['mmqtty']); } /* remainder from current scan plus existing unmatched items complete a new set, so add one item with the group discount */ if ($trans_qty + $remainder >= $groupQty) { /* adjusted price for the "last" item in a set */ $priceAdjust = $groupPrice - ($groupQty - 1) * $pricing['unitPrice']; $discount = $pricing['unitPrice'] - $priceAdjust; $memDiscount = 0; if ($priceObj->isMemberSale() || $priceObj->isStaffSale()) { $memDiscount = $discount; $discount = 0; } 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' => 1, 'unitPrice' => $pricing['unitPrice'] - $discount, 'total' => $pricing['unitPrice'] - $discount, 'regPrice' => $pricing['regPrice'], 'scale' => $row['scale'], 'tax' => $row['tax'], 'foodstamp' => $row['foodstamp'], 'discount' => $discount, 'memDiscount' => $memDiscount, 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => 1, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $row['groupprice'], 'mixMatch' => $row['mixmatchcode'], 'matched' => $groupQty, 'cost' => isset($row['cost']) ? $row['cost'] * $new_sets * $groupQty : 0.0, 'numflag' => isset($row['numflag']) ? $row['numflag'] : 0, 'charflag' => isset($row['charflag']) ? $row['charflag'] : '')); $quantity -= 1; if ($quantity < 0) { $quantity = 0; } } } /* any remaining quantity added without grouping discount */ if ($quantity > 0) { 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'], 'discountable' => $row['discount'], 'discounttype' => $row['discounttype'], 'ItemQtty' => $quantity, 'volDiscType' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $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; }
/** Add foodstamp elgibile total record */ public static function fsEligible() { Database::getsubtotals(); if (CoreLocal::get("fsEligible") < 0 && False) { CoreLocal::set("boxMsg", "Foodstamp eligible amount inapplicable<P>Please void out earlier tender and apply foodstamp first"); CoreLocal::set('boxMsgButtons', array('Dismiss [clear]' => '$(\'#reginput\').val(\'CL\');submitWrapper();')); return MiscLib::baseURL() . "gui-modules/boxMsg2.php"; } else { CoreLocal::set("fntlflag", 1); Database::setglobalvalue("FntlFlag", 1); if (CoreLocal::get("ttlflag") != 1) { return self::ttl(); } else { TransRecord::addRecord(array('description' => 'Foodstamps Eligible', 'trans_type' => '0', 'trans_status' => 'D', 'unitPrice' => MiscLib::truncate2(CoreLocal::get('fsEligible')), 'voided' => 7)); } return true; } }
function addItem($row, $quantity, $priceObj) { if ($quantity == 0) { return false; } $pricing = $priceObj->priceInfo($row, $quantity); // enforce limit on discounting sale items $dsi = CoreLocal::get('DiscountableSaleItems'); if ($dsi == 0 && $dsi !== '' && $priceObj->isSale()) { $row['discount'] = 0; } $stem = substr($mixMatch, 0, 10); $sets = 99; // count up total sets for ($i = 0; $i <= $volume; $i++) { $tmp = $stem . "_q" . $i; if ($volume == $i) { $tmp = $stem . '_d'; } $chkQ = "SELECT sum(CASE WHEN scale=0 THEN ItemQtty ELSE 1 END) \n FROM localtemptrans WHERE mixmatch='{$tmp}' \n and trans_status<>'R'"; $chkR = $dbt->query($chkQ); $tsets = 0; if ($dbt->num_rows($chkR) > 0) { $tsets = array_pop($dbt->fetch_row($chkR)); } if ($tmp == $mixMatch) { $tsets += is_int($quantity) ? $quantity : 1; } if ($tsets < $sets) { $sets = $tsets; } // item not found, no point continuing if ($sets == 0) { break; } } // count existing sets $matches = 0; $mQ = "SELECT sum(matched) FROM localtemptrans WHERE\n left(mixmatch,11)='{$stem}_'"; $mR = $dbt->query($mQ); if ($dbt->num_rows($mR) > 0) { $matches = array_pop($dbt->fetch_row($mR)); } $sets -= $matches; // this means the current item // completes a new set if ($sets > 0) { if ($priceObj->isSale()) { if ($priceObj->isMemberSale() || $priceObj->isStaffSale()) { $pricing['memDiscount'] = MiscLib::truncate2($row['specialgroupprice'] * $quantity); } else { $pricing['discount'] = MiscLib::truncate2($row['specialgroupprice'] * $quantity); } } else { $pricing['unitPrice'] = $pricing['unitPrice'] - $row['specialgroupprice']; } 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' => $priceObj->isSale() ? $row['specialpricemethod'] : $row['pricemethod'], 'volume' => $priceObj->isSale() ? $row['specialquantity'] : $row['quantity'], 'VolSpecial' => $priceObj->isSale() ? $row['specialgroupprice'] : $row['groupprice'], 'mixmatch' => $row['mixmatchcode'], 'matched' => $sets, 'cost' => isset($row['cost']) ? $row['cost'] * $quantity : 0.0, 'numflag' => isset($row['numflag']) ? $row['numflag'] : 0, 'charflag' => isset($row['charflag']) ? $row['charflag'] : '')); } else { // not a new set, treat as a regular item 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; }
private function addscDiscount() { if (CoreLocal::get("scDiscount") != 0) { TransRecord::addRecord(array('upc' => "DISCOUNT", 'description' => "** 10% Deli Discount **", 'trans_type' => "I", 'quantity' => 1, 'ItemQtty' => 1, 'unitPrice' => MiscLib::truncate2(-1 * CoreLocal::get("scDiscount")), 'total' => MiscLib::truncate2(-1 * CoreLocal::get("scDiscount")), 'discountable' => 1, 'voided' => 2)); } }