Example #1
0
 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);
     }
 }
Example #2
0
 /**
   Populates session with default values.
   Short-hand for calling every other function
   in this file. Normally called once on
   startup.
 */
 public static function initiate_session()
 {
     self::systemInit();
     self::memberReset();
     self::transReset();
     self::printReset();
     PaycardLib::paycard_reset();
     Database::getsubtotals();
     Database::loadglobalvalues();
     self::loadData();
     self::customReceipt();
     self::loadParams();
 }
Example #3
0
 /**
   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);
 }
Example #4
0
 /**
   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;
 }
Example #5
0
 function preprocess()
 {
     $this->msg = "";
     if (isset($_REQUEST['reginput'])) {
         switch (strtoupper($_REQUEST['reginput'])) {
             case 'CL':
                 // cancel the transaction instead
                 CoreLocal::set("msgrepeat", 1);
                 CoreLocal::set("strRemembered", "CN");
                 /**
                   Unify emp_no & trans_no records in the
                   database. Logging records from authentication
                   may have different values. This step normalizes
                   the transaction. In this case I'm restoring
                   the logged in cashier's info immediately
                   and assigning the entire transaction to that
                   cashier. This is simpler than the case below
                   and since it's canceled it doesn't matter if
                   the tender records are assigned to the original
                   cashier or the current cashier.
                 */
                 Database::loadglobalvalues();
                 $db = Database::tDataConnect();
                 $emp_no = CoreLocal::get('CashierNo');
                 $trans_no = CoreLocal::get('transno');
                 $db->query('UPDATE localtemptrans SET
                         emp_no=' . (int) $emp_no . ',
                         trans_no=' . (int) $trans_no . '
                         WHERE
                         emp_no<>' . (int) $emp_no . ' OR
                         trans_no<>' . (int) $trans_no);
                 $this->change_page($this->page_url . "gui-modules/pos2.php");
                 return False;
                 break;
             case '':
                 // use zero cash to finish transaction
                 CoreLocal::set("msgrepeat", 1);
                 CoreLocal::set("strRemembered", "0CA");
                 /**
                   Unify emp_no & trans_no records in the
                   database. Logging records from authentication
                   may have different values. This step
                   normalizes the transaction. When ajax-end.php
                   runs to close the transaction, the actual
                   logged in cashier's values will be restored
                   via Database::loadglobalvalues().
                 */
                 $db = Database::tDataConnect();
                 $emp_no = CoreLocal::get('CashierNo');
                 $trans_no = CoreLocal::get('transno');
                 $db->query('UPDATE localtemptrans SET
                         emp_no=' . (int) $emp_no . ',
                         trans_no=' . (int) $trans_no . '
                         WHERE
                         emp_no<>' . (int) $emp_no . ' OR
                         trans_no<>' . (int) $trans_no);
                 $this->change_page($this->page_url . "gui-modules/pos2.php");
                 return False;
                 break;
             case 'U':
             case 'U11':
             case 'D':
             case 'D11':
                 // just use the parser module here
                 // for simplicity; all its really
                 // doing is updating a couple session vars
                 $si = new ScrollItems();
                 $json = $si->parse($_REQUEST['reginput']);
                 $this->msg = $json['output'];
                 break;
             default:
                 break;
         }
     }
     return True;
 }