public function testMiscLib() { chdir(dirname(__FILE__) . '/../../pos/is4c-nf/gui-modules/'); $rel = MiscLib::baseURL(); $this->assertEquals('../', $rel); $this->assertEquals(1, MiscLib::nullwrap(1)); $this->assertEquals(1.5, MiscLib::nullwrap(1.5)); $this->assertEquals('test', MiscLib::nullwrap('test')); $this->assertEquals(0, MiscLib::nullwrap(False)); $this->assertEquals(1, MiscLib::truncate2(1)); $this->assertEquals(1.99, MiscLib::truncate2(1.99)); $this->assertEquals(1.99, MiscLib::truncate2("1.99")); $this->assertEquals(1.35, MiscLib::truncate2("1.345")); $hostCheck = MiscLib::pingport(CoreLocal::get('localhost'), CoreLocal::get('DBMS')); $this->assertInternalType('integer', $hostCheck); $hostCheck = MiscLib::win32(); $this->assertInternalType('integer', $hostCheck); $scale = MiscLib::scaleObject(); if ($scale !== 0) { $this->assertInstanceOf('ScaleDriverWrapper', $scale); } }
/** Prepare the tender report. @return string The report, ready to send to printer. */ public static function get() { global $CORE_LOCAL; /* First, check for anything still in * . localtemptrans * . dtransactions * and for a proper End of Shift. */ $localCheck = ""; $db_a = Database::tDataConnect(); $localQ = "SELECT *\n FROM localtemptrans\n ORDER BY datetime"; $localR = $db_a->query($localQ); $rowCount1 = 0; $transCount1 = 0; $endOfShiftCount1 = 0; $lastUPC1 = ""; while ($localRow = $db_a->fetch_row($localR)) { $rowCount1++; $lastUPC1 = $localRow['upc']; if ($lastUPC1 == 'ENDOFSHIFT') { $endOfShiftCount1++; } if ($localRow['trans_type'] == 'A') { $transCount1++; } } $localQ = "SELECT *\n FROM dtransactions\n ORDER BY datetime"; $localR = $db_a->query($localQ); $rowCount2 = 0; $transCount2 = 0; $endOfShiftCount2 = 0; $lastUPC2 = ""; while ($localRow = $db_a->fetch_row($localR)) { $rowCount2++; $lastUPC2 = $localRow['upc']; if ($lastUPC2 == 'ENDOFSHIFT') { $endOfShiftCount2++; } if ($localRow['trans_type'] == 'A') { $transCount2++; } } /* Ideally, either * . both tables are empty * . there is one record, an upc=ENDOFSHIFT, * in either localtemptrans or dtransactions * and the other table is empty. */ if ($rowCount1 == 0 && $rowCount2 == 0) { $localCheck .= "\n\nThe shift was ended properly, buffers empty. " . "Good!"; } elseif ($lastUPC1 == 'ENDOFSHIFT' && $rowCount1 == 1 && $rowCount2 == 0 || $lastUPC2 == 'ENDOFSHIFT' && $rowCount2 == 1 && $rowCount1 == 0) { $localCheck .= "\n\nThe shift was ended properly, EndOfShift only. " . "Good!"; } elseif ($lastUPC1 == 'ENDOFSHIFT' && ($rowCount1 > 0 || $endOfShiftCount1 > 0)) { $localCheck .= "\n\nThe local transaction-in-progress buffer suggests " . "the shift was ended but perhaps not properly. " . "\n Please SignOff once again and then re-run this report." . "\n If the same problem or another one is reported just use the " . "\n last or best report you have."; } elseif ($rowCount1 > 0) { $localCheck .= "\nThe local transaction-in-progress still contains " . "{$rowCount1} items." . "\nPlease complete or cancel the current transaction " . "and run this " . "\n report again." . "\n If the same problem or another one is reported just use the " . "\n last or best report you have."; } elseif ($lastUPC2 == 'ENDOFSHIFT' && ($rowCount2 > 0 || $endOfShiftCount2 > 0)) { $localCheck .= "\n\nThe local completed-transaction buffer suggests " . "the shift " . "\n was ended but perhaps not properly. " . "\n Please SignOff once again and then re-run this report." . "\n If the same problem or another one is reported just use the " . "\n last or best report you have."; } else { $localCheck .= "\n\nThe local completed-transaction buffer suggests " . "the shift was not " . "\n ended properly. " . "\nPlease SignOff, again if you already have, and then re-run " . "this report." . "\n If the same problem or another one is reported just use the " . "\n last or best report you have."; } if ($transCount2 > 0) { $localCheck .= "\n\nThe local completed-transaction buffer contains " . "{$transCount2} transactions " . "\n that probably will not appear in this report. " . "\n Please alert the shift co-ordinator."; } if (MiscLib::pingport($CORE_LOCAL->get("mServer"), $CORE_LOCAL->get("mDBMS"))) { $db_a = Database::mDataConnect(); $tTable = "dlog"; $tDate = "tdate"; $tSource = "Fannie"; $excl = ""; } else { $db_a = Database::tDataConnect(); $tTable = "localtranstoday"; $tDate = "datetime"; $tSource = "Lane" . $CORE_LOCAL->get('laneno'); $excl = " AND d.trans_status not in ('D','X','Z') AND d.emp_no <> 9999 " . "AND d.register_no <> 99"; } self::$db_a = $db_a; self::$tTable = $tTable; self::$tDate = $tDate; self::$excl = $excl; $shiftCutoff = date('Y-m-d 00:00:00'); self::$shiftCutoff = $shiftCutoff; $DESIRED_TENDERS = $CORE_LOCAL->get("TRDesiredTenders"); self::$dashLine = str_repeat('-', 54); $receipt = ""; $blank = str_repeat(' ', 13); /* Literal spacing from left margin. C a s h ------------------------------------------------------ Time Lane Trans # Emp # Mem # Amount 03:27 PM 1 1 62 484 -6.00 04:14 PM 1 1 63 484 -7.00 ------------------------------------------------------ Count: 2 Total: -13.00 */ $fieldNames = " " . substr("Time" . $blank, 0, 10) . substr("Lane" . $blank, 0, 8) . substr("Trans #" . $blank, 0, 10) . substr("Emp #" . $blank, 0, 8) . substr("Mem #" . $blank, 0, 11) . substr("Amount" . $blank, 0, 14) . "\n"; $ref = ReceiptLib::centerString(trim($CORE_LOCAL->get("CashierNo")) . " " . trim($CORE_LOCAL->get("cashier")) . " " . ReceiptLib::build_time(time())) . "\n"; $cashier_names = ""; $cashierQ = "SELECT CONCAT(SUBSTR(e.FirstName,1,1),SUBSTR(e.Lastname,1,1)) as cashier\n FROM {$tTable} d, " . $CORE_LOCAL->get('pDatabase') . ".employees e\n WHERE d.emp_no = e.emp_no AND d.register_no = " . $CORE_LOCAL->get('laneno') . " AND d.trans_type <> 'L' \n AND d.{$tDate} >= '" . $shiftCutoff . "'{$excl}\n GROUP BY d.emp_no\n ORDER BY d.{$tDate}"; $cashierR = $db_a->query($cashierQ); for ($i = 0; $i < ($row = $db_a->fetch_array($cashierR)); $i++) { $cashier_names .= $row['cashier'] . ", "; } $receipt .= ReceiptLib::centerString("T E N D E R R E P O R T") . "\n"; $receipt .= ReceiptLib::centerString("Data from {$tSource}") . "\n"; $receipt .= $ref; $receipt .= ReceiptLib::centerString("Lane " . $CORE_LOCAL->get('laneno') . " -- Cashiers: " . $cashier_names) . "\n\n"; if ($localCheck) { $receipt .= "{$localCheck}\n\n\n"; } /* NET TOTAL * Does not include tenders such as StoreCharge and Coupons. */ if ($CORE_LOCAL->get('store') == 'WEFC_Toronto') { $netTenderList = "'CA','CK','DC','CC'"; $netTenderMessage = "(Only: Cash, Cheque, Debit, Credit)"; } else { $netTenderList = "'CA','CK','DC','CC','FS','EC'"; $netTenderMessage = "(Only: Cash, Check, Debit, Credit, SNAPs)"; } $netQ = "SELECT -SUM(total) AS net, COUNT(total)\n FROM {$tTable} d\n WHERE register_no=" . $CORE_LOCAL->get('laneno') . " AND trans_subtype IN({$netTenderList})" . " AND {$tDate} >= '{$shiftCutoff}'{$excl}"; $netR = $db_a->query($netQ); $net = $db_a->fetch_row($netR); $receipt .= " " . substr("NET Total: " . $blank . $blank, 0, 20); $receipt .= substr($blank . number_format($net[0], 2), -8) . "\n {$netTenderMessage}\n"; $receipt .= "\n"; /* Total for each of a Tender Type or combination. * Each is listed even if no items. * The PFC version was driven by Desired Tenders. */ $receipt .= self::trTotal('CA', 'CASH'); if ($CORE_LOCAL->get('store') == 'WEFC_Toronto') { $receipt .= self::trTotal('CK', 'CHEQUE'); } else { $receipt .= self::trTotal('CK', 'CHECK'); } $receipt .= self::trTotal(array('CP', 'MC'), 'VENDOR COUPON'); $receipt .= self::trTotal('CC', 'CREDIT CARD'); $receipt .= self::trTotal('DC', 'DEBIT CARD'); if (!$CORE_LOCAL->get('store') == 'WEFC_Toronto') { $receipt .= self::trTotal('FS', 'SNAP - FOOD'); $receipt .= self::trTotal('EC', 'SNAP - CASH'); } $receipt .= self::trTotal('GC', 'GIFT CARD'); $receipt .= self::trTotal('MI', 'INSTORE CHARGE'); $receipt .= self::trTotal('IC', 'INSTORE COUPON'); $receipt .= "\n"; if ($CORE_LOCAL->get('store') == 'WEFC_Toronto') { $receipt .= self::trTotal(array('CA', 'CK'), 'CASH + CHEQUE'); $receipt .= self::trTotal(array('DC', 'CC'), 'DEBIT + CREDIT'); } else { $receipt .= self::trTotal('PT', 'PATRONAGE'); $receipt .= self::trTotal(array('CA', 'CK'), 'CASH + CHECK'); $receipt .= self::trTotal(array('DC', 'CC', 'FS', 'EC'), 'DEB/CRED/SNAP'); } if (!$CORE_LOCAL->get('store') == 'WEFC_Toronto') { $receipt .= self::trTotal(45, 'RCVD. on ACCT.'); $receipt .= self::trTotal(37, 'FRMRS MARKET SNAP'); } $receipt .= ReceiptLib::centerString(self::$dashLine); $receipt .= str_repeat("\n", 5); /* Detail for each Desired Tender Type or combination. * Types with no items are skipped. * The output seems very similar to trTotal(). */ /* If you share a credit/debit-card terminal between cash registers * you might want to list those tenders for all lanes * to help with day-end reconciliation. * Add an item to this array for each tender you want treated that way. */ $allLaneTenders = array(); $allLaneTenders[] = 'CC'; $allLaneTenders[] = 'DC'; foreach (array_keys($DESIRED_TENDERS) as $tender_code) { /* Skip Tender Type if no items of that type. * The first search seems the same as the lower search except for total tests. */ if (in_array($tender_code, $allLaneTenders)) { $registerArg = ''; } else { $registerArg = " AND register_no=" . $CORE_LOCAL->get('laneno'); } $query = "SELECT {$tDate}" . " FROM {$tTable} d" . " WHERE trans_subtype = '" . $tender_code . "'" . $registerArg . " AND {$tDate} >= '{$shiftCutoff}'{$excl}" . " ORDER BY {$tDate}"; $result = $db_a->query($query); $numRows = $db_a->num_rows($result); if ($numRows <= 0) { continue; } $titleStr = ""; $itemize = 1; for ($i = 0; $i < strlen($DESIRED_TENDERS[$tender_code]); $i++) { $titleStr .= $DESIRED_TENDERS[$tender_code][$i] . " "; } $titleStr = substr($titleStr, 0, strlen($titleStr) - 1); $receipt .= ReceiptLib::centerString($titleStr) . "\n"; if ($registerArg == '') { $receipt .= _("The list includes items for all lanes."); } if ($itemize == 1) { $receipt .= ReceiptLib::centerString(self::$dashLine) . "\n"; } $query = "SELECT {$tDate},register_no,emp_no,trans_no,card_no,total" . " FROM {$tTable} d" . " WHERE trans_subtype = '" . $tender_code . "'" . $registerArg . " AND (total <> 0 OR total <> -0) " . " AND {$tDate} >= '{$shiftCutoff}'{$excl}" . " ORDER BY {$tDate}"; $result = $db_a->query($query); $numRows = $db_a->num_rows($result); if ($itemize == 1) { $receipt .= $fieldNames; } $sum = 0; for ($i = 0; $i < $numRows; $i++) { $row = $db_a->fetch_array($result); $timeStamp = self::timeStamp($row["{$tDate}"]); if ($itemize == 1 && $row["total"]) { $receipt .= " " . substr($timeStamp . $blank, 0, 10) . substr($row["register_no"] . $blank, 0, 9) . substr($row["trans_no"] . $blank, 0, 8) . substr($blank . $row['emp_no'], -6) . substr($blank . $row["card_no"], -6) . substr($blank . number_format($row["total"], 2), -14) . "\n"; } $sum += $row["total"]; } $receipt .= ReceiptLib::centerString(self::$dashLine) . "\n"; $receipt .= substr($blank . $blank . $blank . "Count: " . $numRows . " Total: " . number_format($sum, 2), -55) . "\n"; $receipt .= str_repeat("\n", 3); // each desired tender. } /* Each item of purchase of these kinds. * first-param depts are PioneerFoodCoop, not WEFC_Toronto */ $receipt .= self::trTotal(36, 'MEMBER EQUITY', True, False); $receipt .= self::trTotal(45, 'RCVD / ACCOUNT', True, False); $receipt .= self::trTotal(41, 'GIFT CARDS SOLD', True, False); $receipt .= str_repeat("\n", 5); // cut paper? return $receipt . chr(27) . chr(105); // get() }
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *********************************************************************************/ if (!class_exists("AutoLoader")) { include "lib/AutoLoader.php"; } CoreLocal::set("parse_chain", ''); CoreLocal::set("preparse_chain", ''); CoreLocal::set("postparse_chain", ''); AutoLoader::loadMap(); CoreState::initiate_session(); if (CoreLocal::get("SessionFirstRun") == "") { CoreLocal::set("SessionFirstRun", 1); } CoreLocal::migrateSettings(); if (MiscLib::pingport('127.0.0.1:15674', 'not a database')) { CoreLocal::set('MQ', true); } else { CoreLocal::set('MQ', false); } /** Go to login screen if no one is signed in Go to lock screen if someone is signed in */ if (!headers_sent()) { $my_url = MiscLib::base_url(); if (CoreLocal::get('LoggedIn') == 0) { header("Location: {$my_url}gui-modules/login2.php"); } else { header("Location: {$my_url}gui-modules/login3.php"); }
echo InstallUtilities::installTextField('mDatabase', 'core_trans'); ?> </td> </tr> <tr> <td colspan=2> <div class="noteTxt"> Testing server connection: <?php $sql = InstallUtilities::dbTestConnect(CoreLocal::get('mServer'), CoreLocal::get('mDBMS'), CoreLocal::get('mDatabase'), CoreLocal::get('mUser'), CoreLocal::get('mPass')); if ($sql === False) { echo "<span class='fail'>Failed</span>"; echo '<div class="db_hints" style="margin-left:25px;width:350px;">'; if (!function_exists('socket_create')) { echo '<i>Try enabling PHP\'s socket extension in php.ini for better diagnostics</i>'; } elseif (@MiscLib::pingport(CoreLocal::get('mServer'), CoreLocal::get('DBMS'))) { echo '<i>Database found at ' . CoreLocal::get('mServer') . '. Verify username and password and/or database account permissions.</i>'; } else { echo '<i>Database does not appear to be listening for connections on ' . CoreLocal::get('mServer') . '. Verify host is correct, database is running and firewall is allowing connections.</i>'; } echo '</div>'; } else { echo "<span class='success'>Succeeded</span><br />"; //echo "<textarea rows=3 cols=80>"; $sErrors = InstallUtilities::createMinServer($sql, CoreLocal::get('mDatabase')); $sErrors = array_filter($sErrors, function ($x) { return $x['error'] != 0; }); if (!empty($sErrors)) {
/** See if the remote database is available This function calls uploadtoServer() if the initial test works. @return integer - 1 server available - 0 server down */ public static function testremote() { $intConnected = MiscLib::pingport(CoreLocal::get("mServer"), CoreLocal::get("mDBMS")); if ($intConnected == 1) { self::uploadtoServer(); } else { CoreLocal::set("standalone", 1); } return (CoreLocal::get("standalone") + 1) % 2; }