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 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; }
/** Finish the current transaction @param $incomplete [boolean] optional, default false This method: 1) Adds tax and discount lines if transaction is complete (i.e., $incomplete == false) 2) Rotates data out of localtemptrans 3) Advances trans_no variable to next available value This method replaces older ajax-end.php / end.php operations where the receipt was printed first and then steps 1-3 above happened. This method should be called BEFORE printing a receipt. Receipts are now always printed via localtranstoday. */ public static function finalizeTransaction($incomplete = false) { if (!$incomplete) { self::addtransDiscount(); self::addTax(); $taxes = Database::LineItemTaxes(); foreach ($taxes as $tax) { if (CoreLocal::get('TaxExempt') == 1) { $tax['amount'] = 0.0; } self::addLogRecord(array('upc' => 'TAXLINEITEM', 'description' => $tax['description'], 'numflag' => $tax['rate_id'], 'amount2' => $tax['amount'])); } DiscountModule::lineItems(); } if (Database::rotateTempData()) { // rotate data Database::clearTempTables(); } // advance trans_no value Database::loadglobalvalues(); $nextTransNo = Database::gettransno(CoreLocal::get('CashierNo')); CoreLocal::set('transno', $nextTransNo); Database::setglobalvalue('TransNo', $nextTransNo); }
/** Authenticate an employee by password @param $password password from employee table @param $activity activity identifier to log @return True or False If no one is currently logged in, any valid password will be accepted. If someone is logged in, then only passwords for that user <i>or</i> a user with frontendsecurity >= 30 in the employee table will be accepted. */ public static function checkPassword($password, $activity = 1) { $password = strtoupper($password); $password = str_replace("'", "", $password); $password = str_replace(",", "", $password); $paswword = str_replace("+", "", $password); if ($password == "TRAINING") { $password = 9999; // if password is training, change to '9999' } $query_g = "select LoggedIn,CashierNo from globalvalues"; $db_g = Database::pDataConnect(); $result_g = $db_g->query($query_g); $row_g = $db_g->fetch_array($result_g); if ($row_g["LoggedIn"] == 0) { $query_q = ' SELECT emp_no, FirstName, LastName, ' . $db_g->yeardiff($db_g->now(), 'birthdate') . ' AS age FROM employees WHERE EmpActive = 1 AND CashierPassword = ?'; $prep_q = $db_g->prepare($query_q); $result_q = $db_g->execute($prep_q, array($password)); $num_rows_q = $db_g->num_rows($result_q); if ($num_rows_q > 0) { $row_q = $db_g->fetch_array($result_q); Database::loadglobalvalues(); $transno = Database::gettransno($row_q["emp_no"]); $globals = array("CashierNo" => $row_q["emp_no"], "Cashier" => $row_q["FirstName"] . " " . substr($row_q["LastName"], 0, 1) . ".", "TransNo" => $transno, "LoggedIn" => 1); Database::setglobalvalues($globals); CoreState::cashierLogin($transno, $row_q['age']); } elseif ($password == 9999) { Database::loadglobalvalues(); $transno = Database::gettransno(9999); $globals = array("CashierNo" => 9999, "Cashier" => "Training Mode", "TransNo" => $transno, "LoggedIn" => 1); Database::setglobalvalues($globals); CoreState::cashierLogin($transno, 0); } else { return False; } } else { // longer query but simpler. since someone is logged in already, // only accept password from that person OR someone with a high // frontendsecurity setting $query_a = ' SELECT emp_no, FirstName, LastName, ' . $db_g->yeardiff($db_g->now(), 'birthdate') . ' AS age FROM employees WHERE EmpActive = 1 AND (frontendsecurity >= 30 OR emp_no = ?) AND (CashierPassword = ? OR AdminPassword = ?)'; $args = array($row_g['CashierNo'], $password, $password); $prep_a = $db_g->prepare($query_a); $result_a = $db_g->execute($prep_a, $args); $num_rows_a = $db_g->num_rows($result_a); if ($num_rows_a > 0) { Database::loadglobalvalues(); $row = $db_g->fetch_row($result_a); CoreState::cashierLogin(False, $row['age']); } elseif ($row_g["CashierNo"] == "9999" && $password == "9999") { Database::loadglobalvalues(); CoreState::cashierLogin(False, 0); } else { return false; } } return true; }