Example #1
0
 /**
   localtranstoday used to be a view; recreate
   it as a table if needed.
 */
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False)
 {
     if ($db_name == CoreLocal::get('pDatabase')) {
         $this->connection = Database::pDataConnect();
     } else {
         if ($db_name == CoreLocal::get('tDatabase')) {
             $this->connection = Database::tDataConnect();
         } else {
             echo "Error: Unknown database ({$db_name})";
             return false;
         }
     }
     if ($this->connection->isView($this->name)) {
         if ($mode == BasicModel::NORMALIZE_MODE_CHECK) {
             echo "View {$this->name} should be a table!\n";
             echo "==========================================\n";
             printf("%s table %s\n", "Check complete. Need to drop view & create replacement table.", $this->name);
             echo "==========================================\n\n";
             return 999;
         } else {
             $drop = $this->connection->query('DROP VIEW ' . $this->name);
             echo "==========================================\n";
             printf("Dropping view %s %s\n", $this->name, $drop ? "OK" : "failed");
             if ($drop) {
                 $cResult = $this->create();
                 printf("Update complete. Creation of table %s %s\n", $this->name, $cResult ? "OK" : "failed");
             }
             echo "==========================================\n";
             return true;
         }
     } else {
         return parent::normalize($db_name, $mode, $doCreate);
     }
 }
Example #2
0
 function parse($str)
 {
     $json = $this->default_json();
     $arg = $this->left;
     CoreLocal::set("sc", 1);
     $staffID = substr($arg, 0, 4);
     $pQuery = "select staffID,chargecode,blueLine from chargecodeview where chargecode = '" . $arg . "'";
     $pConn = Database::pDataConnect();
     $result = $pConn->query($pQuery);
     $num_rows = $pConn->num_rows($result);
     $row = $pConn->fetch_array($result);
     if ($num_rows == 0) {
         $json['output'] = DisplayLib::xboxMsg(_("unable to authenticate staff ") . $staffID, DisplayLib::standardClearButton());
         CoreLocal::set("isStaff", 0);
         // apbw 03/05/05 SCR
         return $json;
     } else {
         CoreLocal::set("isStaff", 1);
         // apbw 03/05/05 SCR
         CoreLocal::set("memMsg", $row["blueLine"]);
         $tQuery = "update localtemptrans set card_no = '" . $staffID . "', percentDiscount = 15";
         $tConn = Database::tDataConnect();
         $this->addscDiscount();
         TransRecord::discountnotify(15);
         $tConn->query($tQuery);
         Database::getsubtotals();
         $chk = self::ttl();
         if ($chk !== True) {
             $json['main_frame'] = $chk;
             return $json;
         }
         CoreLocal::set("runningTotal", CoreLocal::get("amtdue"));
         return self::tender("MI", CoreLocal::get("runningTotal") * 100);
     }
 }
Example #3
0
 /**
   Check for errors
   @return True or an error message string
 */
 public function errorCheck()
 {
     $clearButton = array('OK [clear]' => 'parseWrapper(\'CL\');');
     if (CoreLocal::get("isMember") != 0 && $this->amount - CoreLocal::get("amtdue") - 0.005 > CoreLocal::get("dollarOver") && CoreLocal::get("cashOverLimit") == 1) {
         return DisplayLib::boxMsg(_("member check tender cannot exceed total purchase by over \$") . CoreLocal::get("dollarOver"), '', false, $clearButton);
     } elseif (CoreLocal::get("store") == "wfc" && CoreLocal::get("isMember") != 0 && $this->amount - CoreLocal::get("amtdue") - 0.005 > 0) {
         // This should really be a separate tender
         // module for store-specific behavior
         $db = Database::pDataConnect();
         $q = sprintf("SELECT card_no FROM custReceiptMessage\n                WHERE card_no=%d AND modifier_module='WfcEquityMessage'", CoreLocal::get('memberID'));
         $r = $db->query($q);
         if ($db->num_rows($r) > 0) {
             return DisplayLib::xboxMsg(_("member check tender cannot exceed total purchase if equity is owed"), $clearButton);
         }
         // multi use
         if (CoreLocal::get('standalone') == 0) {
             $chkQ = "select trans_num from dlog \n                    where trans_type='T' and trans_subtype in ('CA','CK') \n                    and card_no=" . (int) CoreLocal::get('memberID') . "\n                    group by trans_num \n                    having sum(case when trans_subtype='CK' then total else 0 end) < 0 \n                    and sum(Case when trans_subtype='CA' then total else 0 end) > 0";
             $db = Database::mDataConnect();
             $chkR = $db->query($chkQ);
             if ($db->num_rows($chkR) > 0) {
                 return DisplayLib::xboxMsg(_("already used check over benefit today"), $clearButton);
             }
         }
     } elseif (CoreLocal::get("isMember") == 0 && $this->amount - CoreLocal::get("amtdue") - 0.005 > 0) {
         $msg = _('Non-members may not write checks for more than the total purchase.');
         return DisplayLib::xboxMsg($msg, $clearButton);
     }
     return true;
 }
Example #4
0
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False)
 {
     if ($db_name == CoreLocal::get('pDatabase')) {
         $this->connection = Database::pDataConnect();
     } else {
         if ($db_name == CoreLocal::get('tDatabase')) {
             $this->connection = Database::tDataConnect();
         } else {
             echo "Error: Unknown database ({$db_name})";
             return false;
         }
     }
     $viewSQL = $this->connection->getViewDefinition($this->name);
     echo "==========================================\n";
     printf("%s view %s\n", $mode == BasicModel::NORMALIZE_MODE_CHECK ? "Checking" : "Updating", "{$db_name}.{$this->name}");
     echo "==========================================\n";
     if (strstr($viewSQL, '0 AS memType') || strstr($viewSQL, '0 AS ' . $this->connection->identifier_escape('memType'))) {
         /**
           Structure-check 27Dec2013
           Make sure memType is calcluated instead of hardcoded to zero
         */
         echo "==========================================\n";
         if ($mode == BasicModel::NORMALIZE_MODE_CHECK) {
             echo "View needs to be rebuild to calculate memType correctly\n";
         } else {
             echo "Rebuilding view to calculate memType correctly... ";
             $this->connection->query('DROP VIEW ' . $this->connection->identifier_escape($this->name));
             $success = $this->create();
             echo ($success ? 'succeeded' : 'failed') . "\n";
         }
     }
     return 0;
 }
Example #5
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 #6
0
 /**
   Build a <select> form that submits
   back to this script
 */
 function body_content()
 {
     $db = Database::pDataConnect();
     $q = "SELECT dept_no,dept_name FROM departments ORDER BY dept_name";
     $r = $db->query($q);
     echo "<div class=\"baseHeight\">" . "<div class=\"listbox\">" . "<form name=\"selectform\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\"" . " id=\"selectform\">" . "<select name=\"search\" id=\"search\" " . ' style="min-height: 200px; min-width: 220px;" ' . "size=\"15\" onblur=\"\$('#search').focus();\">";
     $selected = "selected";
     while ($row = $db->fetch_row($r)) {
         echo "<option value='" . $row["dept_no"] . "' " . $selected . ">";
         // &shy; prevents the cursor from moving out of
         // step with filter-as-you-type
         echo '&shy; ' . $row['dept_name'];
         echo '</option>';
         $selected = "";
     }
     echo "</select>" . '<div id="filter-div"></div>' . "</div>";
     if (CoreLocal::get('touchscreen')) {
         echo '<div class="listbox listboxText">' . DisplayLib::touchScreenScrollButtons() . '</div>';
     }
     echo "<div class=\"listboxText coloredText centerOffset\">" . _("use arrow keys to navigate") . '<p><button type="submit" class="pos-button wide-button coloredArea">
             OK <span class="smaller">[enter]</span>
             </button></p>' . '<p><button type="submit" class="pos-button wide-button errorColoredArea"
             onclick="$(\'#search\').append($(\'<option>\').val(\'\'));$(\'#search\').val(\'\');">
             Cancel <span class="smaller">[clear]</span>
             </button></p>' . "</div><!-- /.listboxText coloredText .centerOffset -->" . "</form>" . "<div class=\"clear\"></div>";
     echo "</div>";
     $this->add_onload_command("selectSubmit('#search', '#selectform', '#filter-div')\n");
     $this->add_onload_command("\$('#search').focus();\n");
 }
Example #7
0
 /**
   Build a <select> form that submits
   back to this script
 */
 function body_content()
 {
     $db = Database::pDataConnect();
     $q = "SELECT TenderCode,TenderName FROM tenders \n            WHERE MaxAmount > 0\n            ORDER BY TenderName";
     $r = $db->query($q);
     echo "<div class=\"baseHeight\">" . "<div class=\"listbox\">" . "<form name=\"selectform\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\"" . " id=\"selectform\">" . "<select name=\"search\" id=\"search\" " . "size=\"15\" onblur=\"\$('#search').focus();\">";
     $selected = "selected";
     while ($row = $db->fetch_row($r)) {
         echo "<option value='" . $row["TenderCode"] . "' " . $selected . ">";
         echo $row['TenderName'];
         echo '</option>';
         $selected = "";
     }
     echo "</select>" . "</div>";
     if (CoreLocal::get('touchscreen')) {
         echo '<div class="listbox listboxText">' . DisplayLib::touchScreenScrollButtons() . '</div>';
     }
     echo "<div class=\"listboxText coloredText centerOffset\">";
     if (CoreLocal::get("tenderTotal") >= 0) {
         echo _("tendering") . ' $';
     } else {
         echo _("refunding") . ' $';
     }
     printf('%.2f', abs(CoreLocal::get("tenderTotal")) / 100);
     echo '<br />';
     echo _("use arrow keys to navigate") . '<p><button type="submit" class="pos-button wide-button coloredArea">
             OK <span class="smaller">[enter]</span>
             </button></p>' . '<p><button type="submit" class="pos-button wide-button errorColoredArea"
             onclick="$(\'#search\').append($(\'<option>\').val(\'\'));$(\'#search\').val(\'\');">
             Cancel <span class="smaller">[clear]</span>
             </button></p>' . "</div><!-- /.listboxText coloredText .centerOffset -->" . "</form>" . "<div class=\"clear\"></div>";
     echo "</div>";
     $this->add_onload_command("selectSubmit('#search', '#selectform')\n");
     $this->add_onload_command("\$('#search').focus();\n");
 }
Example #8
0
 function preprocess()
 {
     // check for posts before drawing anything, so we can redirect
     if (isset($_REQUEST['reginput'])) {
         $input = strtoupper(trim($_REQUEST['reginput']));
         // CL always exits
         if ($input == "CL") {
             PaycardLib::paycard_reset();
             CoreLocal::set("msgrepeat", 1);
             CoreLocal::set("strRemembered", 'TO');
             CoreLocal::set("toggletax", 0);
             CoreLocal::set("togglefoodstamp", 0);
             $this->change_page($this->page_url . "gui-modules/pos2.php");
             return False;
         }
         $continue = false;
         // when voiding tenders, the input must be an FEC's passcode
         if (CoreLocal::get("paycard_mode") == PaycardLib::PAYCARD_MODE_VOID && $input != "" && substr($input, -2) != "CL") {
             $db = Database::pDataConnect();
             if (Authenticate::checkPermission($input, 11)) {
                 CoreLocal::set("adminP", $input);
                 $continue = true;
             }
         }
         // when voiding items, no code is necessary, only confirmation
         if (CoreLocal::get("paycard_mode") != PaycardLib::PAYCARD_MODE_VOID && $input == "") {
             $continue = true;
         }
         // go?
         if ($continue) {
             // send the request, then disable the form
             $this->add_onload_command('paycard_submitWrapper();');
             $this->action = "onsubmit=\"return false;\"";
         }
         // if we're still here, display prompt again
     } else {
         if (CoreLocal::get("paycard_mode") == PaycardLib::PAYCARD_MODE_AUTH) {
             // call paycard_void on first load to set up
             // transaction and check for problems
             $id = CoreLocal::get("paycard_id");
             foreach (CoreLocal::get("RegisteredPaycardClasses") as $rpc) {
                 $myObj = new $rpc();
                 if ($myObj->handlesType(CoreLocal::get("paycard_type"))) {
                     $ret = $myObj->paycard_void($id);
                     if (isset($ret['output']) && !empty($ret['output'])) {
                         CoreLocal::set("boxMsg", $ret['output']);
                         $this->change_page($this->page_url . "gui-modules/boxMsg2.php");
                         return False;
                     }
                     break;
                 }
             }
         }
     }
     return True;
 }
Example #9
0
 public function parse($str)
 {
     $my_url = MiscLib::base_url();
     $split = explode("DP", $str);
     $dept = $split[1];
     $amt = $split[0];
     if (strstr($amt, '.')) {
         $amt = round($amt * 100);
     }
     $ret = $this->default_json();
     /**
       This "if" is the new addition to trigger the
       department select screen
     */
     if (empty($split[1])) {
         // no department specified, just amount followed by DP
         // maintain refund if needed
         if (CoreLocal::get("refund")) {
             $amt = "RF" . $amt;
         }
         // save entered amount
         CoreLocal::set("departmentAmount", $amt);
         // go to the department select screen
         $ret['main_frame'] = $my_url . 'gui-modules/deptlist.php';
     } else {
         if (CoreLocal::get("refund") == 1 && CoreLocal::get("refundComment") == "") {
             if (CoreLocal::get("SecurityRefund") > 20) {
                 $ret['main_frame'] = $my_url . "gui-modules/adminlogin.php?class=RefundAdminLogin";
             } else {
                 $ret['main_frame'] = $my_url . 'gui-modules/refundComment.php';
             }
             CoreLocal::set("refundComment", CoreLocal::get("strEntered"));
         }
     }
     /* apply any appropriate special dept modules */
     $deptmods = CoreLocal::get('SpecialDeptMap');
     $db = Database::pDataConnect();
     if (!is_array($deptmods) && $db->table_exists('SpecialDeptMap')) {
         $model = new \COREPOS\pos\lib\models\op\SpecialDeptMapModel($db);
         $deptmods = $model->buildMap();
         CoreLocal::set('SpecialDeptMap', $deptmods);
     }
     $index = (int) ($dept / 10);
     if (is_array($deptmods) && isset($deptmods[$index])) {
         foreach ($deptmods[$index] as $mod) {
             $obj = new $mod();
             $ret = $obj->handle($dept, $amt / 100, $ret);
         }
     }
     if (!$ret['main_frame']) {
         $ret = PrehLib::deptkey($amt, $dept, $ret);
     }
     return $ret;
 }
Example #10
0
 public function search($str)
 {
     $ret = array();
     $sql = Database::pDataConnect();
     $query = "select upc, description, normal_price, special_price, " . "scale from products where " . "description like '%" . $str . "%' " . "and inUse='1' " . "order by description";
     $result = $sql->query($query);
     while ($row = $sql->fetch_row($result)) {
         $ret[$row['upc']] = $row;
     }
     return $ret;
 }
Example #11
0
 public function lookup_by_text($text)
 {
     $dbc = Database::pDataConnect();
     $query = $dbc->prepare_statement('SELECT CardNo, personNum,
         LastName, FirstName FROM custdata
         WHERE LastName LIKE ? 
         AND Type = \'INACT\'
         ORDER BY LastName, FirstName');
     $result = $dbc->exec_statement($query, array($text . '%'));
     return $this->resultToArray($dbc, $result);
 }
Example #12
0
 private function overlayKeys($number)
 {
     $db = Database::pDataConnect();
     $my_keys = array();
     if ($db->table_exists('QuickLookups')) {
         $prep = $db->prepare('
             SELECT label,
                 action
             FROM QuickLookups
             WHERE lookupSet = ?
             ORDER BY sequence');
         $res = $db->execute($prep, array($number));
         while ($row = $db->fetch_row($res)) {
             $my_keys[] = new quickkey($row['label'], $row['action']);
         }
     }
     if (count($my_keys) == 0) {
         include dirname(__FILE__) . '/quickkeys/keys/' . $number . '.php';
     }
     if (count($my_keys) == 0) {
         return DisplayLib::boxMsg('Menu not found', '', false, DisplayLib::standardClearButton());
     }
     $clearButton = false;
     $ret = '';
     for ($i = 0; $i < count($my_keys); $i++) {
         if ($i % 3 == 0) {
             if ($i != 0) {
                 $ret .= ' </div>';
             }
             $ret .= '<div class="qkRow">';
         }
         $ret .= sprintf('
             <div class="qkBox">
                 <div id="qkDiv%d">
                     <button type="button" class="quick_button pos-button coloredBorder"
                         onclick="$(\'#reginput\').val($(\'#reginput\').val()+\'%s\');submitWrapper();">
                     %s
                     </button>
                 </div>
             </div>', $i, $my_keys[$i]->output_text, $my_keys[$i]->title);
     }
     if (!$clearButton) {
         $ret .= '<div class="qkBox">
             <div>
                 <button type="button" class="quick_button pos-button errorColoredArea"
                     onclick="$(\'#reginput\').val(\'CL\');submitWrapper();">
                     Clear <span class="smaller">[clear]</span>
                 </button>
             </div>
             </div>';
     }
     $ret .= '</div>';
     return $ret;
 }
Example #13
0
 /**
   Apply action
   @return [boolean] true if the action
     completes successfully (or is not
     necessary at all) or [string] url
     to redirect to another page for
     further decisions/input.
 */
 public function apply()
 {
     $db = Database::pDataConnect();
     $repeat = CoreLocal::get('msgrepeat');
     $coupons = array();
     $hc_table = $db->table_definition('houseCoupons');
     if ($db->table_exists('autoCoupons')) {
         $autoR = $db->query('SELECT coupID, description FROM autoCoupons');
         while ($autoW = $db->fetch_row($autoR)) {
             $coupons[$autoW['coupID']] = $autoW['description'];
         }
     }
     if (isset($hc_table['description']) && isset($hc_table['auto'])) {
         $autoR = $db->query('SELECT coupID, description FROM houseCoupons WHERE auto=1');
         while ($autoW = $db->fetch_row($autoR)) {
             $coupons[$autoW['coupID']] = $autoW['description'];
         }
     }
     $hc = new HouseCoupon();
     $prefix = CoreLocal::get('houseCouponPrefix');
     if ($prefix == '') {
         $prefix = '00499999';
     }
     foreach ($coupons as $id => $description) {
         if ($hc->checkQualifications($id, true) !== true) {
             // member or transaction does not meet requirements
             // for auto-coupon purposes, this isn't really an
             // error. no feedback necessary
             continue;
         }
         // get value of coupon AND value
         // of any previous applications of this coupon
         $add = $hc->getValue($id);
         $upc = $prefix . str_pad($id, 5, '0', STR_PAD_LEFT);
         $upc = str_pad($upc, 13, '0', STR_PAD_LEFT);
         $current = $db->query('SELECT SUM(-total) AS ttl FROM ' . CoreLocal::get('tDatabase') . $db->sep() . 'localtemptrans
                        WHERE upc=\'' . $upc . '\'');
         $val = 0;
         if ($db->num_rows($current) > 0) {
             $currentW = $db->fetch_row($current);
             $val = $currentW['ttl'];
         }
         $next_val = $add['value'] - $val;
         if ($next_val == 0) {
             // no need to add another line item
             // previous one(s) sum to correct total
             continue;
         }
         TransRecord::addhousecoupon($upc, $add['department'], -1 * $next_val, $description);
     }
     CoreLocal::set('msgrepeat', $repeat);
     return true;
 }
Example #14
0
 public function testSampleData()
 {
     $samples = array('couponcodes', 'custdata', 'departments', 'employees', 'globalvalues', 'houseCoupons', 'houseCouponItems', 'MasterSuperDepts', 'parameters', 'products', 'subdepts', 'tenders');
     $dbc = Database::pDataConnect();
     foreach ($samples as $sample) {
         ob_start();
         $dbc->query('TRUNCATE TABLE ' . $dbc->identifier_escape($sample));
         $loaded = InstallUtilities::loadSampleData($dbc, $sample, false);
         $output = ob_get_clean();
         $this->assertEquals(true, $loaded, 'Error with sample data for ' . $sample . ' (' . $output . ')');
     }
 }
Example #15
0
 /**
   Check for errors
   @return True or an error message string
 */
 public function errorCheck()
 {
     if (MiscLib::truncate2(CoreLocal::get("amtdue")) < MiscLib::truncate2($this->amount)) {
         return DisplayLib::xboxMsg(_("store transfer exceeds purchase amount"), DisplayLib::standardClearButton());
     }
     $db = Database::pDataConnect();
     $query = 'SELECT chargeOk FROM custdata WHERE chargeOk=1 AND CardNo=' . CoreLocal::get('memberID');
     $result = $db->query($query);
     if ($db->num_rows($result) == 0) {
         return DisplayLib::xboxMsg(_("member cannot make transfers"), DisplayLib::standardClearButton());
     }
     return true;
 }
Example #16
0
 function check($str)
 {
     if (!is_numeric(substr($str, -2)) && is_numeric(substr($str, 0, strlen($str) - 2))) {
         return True;
     } elseif (strlen($str) == 2 && !is_numeric($str)) {
         $db = Database::pDataConnect();
         $q = "SELECT TenderCode FROM tenders WHERE TenderCode='{$str}'";
         $r = $db->query($q);
         if ($db->num_rows($r) > 0) {
             return True;
         }
     }
     return False;
 }
Example #17
0
 public function search($str)
 {
     $ret = array();
     $sql = Database::pDataConnect();
     if (!$sql->table_exists('productUser')) {
         return array();
     }
     $query = "\n            SELECT p.upc,\n                CASE \n                    WHEN u.description IS NULL THEN p.description\n                    WHEN u.description = '' THEN p.description\n                    ELSE u.description \n                END as description,\n                p.normal_price,\n                p.special_price, \n                p.scale\n            FROM products AS p\n                LEFT JOIN productUser AS u ON p.upc=u.upc\n            WHERE (p.description LIKE '%{$str}%' OR\n                u.description LIKE '%{$str}%')\n                AND p.upc LIKE ('0000000%')\n                AND p.inUse=1\n            ORDER BY description";
     $result = $sql->query($query);
     while ($row = $sql->fetch_row($result)) {
         $ret[$row['upc']] = $row;
     }
     return $ret;
 }
Example #18
0
 public function handle($upc, $json)
 {
     $db = Database::pDataConnect();
     $query = "select card_no from memberCards where upc='{$upc}'";
     $result = $db->query($query);
     if ($db->num_rows($result) < 1) {
         $json['output'] = DisplayLib::boxMsg(_("Card not assigned"), '', false, DisplayLib::standardClearButton());
         return $json;
     }
     $row = $db->fetch_array($result);
     CoreLocal::set("memberCardUsed", 1);
     $json = PrehLib::memberID($row[0]);
     return $json;
 }
Example #19
0
 public function pluginDisable()
 {
     $db = Database::pDataConnect();
     // always remove view
     if ($db->table_exists('chargecodeview')) {
         $db->query('DROP VIEW chargecodeview');
     }
     // only remove table if it's empty
     if ($db->table_exists('chargecode')) {
         $chk = $db->query('SELECT staffID FROM chargecode');
         if ($db->num_rows($chk) == 0) {
             $db->query('DROP TABLE chargecode');
         }
     }
 }
Example #20
0
 function body_content()
 {
     global $CORE_LOCAL;
     $db = Database::pDataConnect();
     /* Only tenders the member may actually use. */
     $q = "SELECT t.TenderCode, p.tenderKeyCap, p.tenderName\n            FROM opdata.tenders t\n            JOIN coop_cred_lane.CCredPrograms p ON t.TenderCode = p.tenderType\n            JOIN coop_cred_lane.CCredMemberships m ON p.programID = m.programID\n            WHERE t.MaxAmount >0\n            AND m.cardNo =" . $CORE_LOCAL->get("memberID") . " AND m.creditOK =1\n            ORDER BY p.programID";
     $r = $db->query($q);
     echo "<div class=\"baseHeight\">" . "<div class=\"listbox\">";
     echo "<form name=\"selectform\" method=\"post\" " . "action=\"{$_SERVER['PHP_SELF']}\" " . "id=\"selectform\">";
     if ($db->num_rows($r) > 0) {
         $selectSize = $db->num_rows($r) < 15 ? $db->num_rows($r) : 15;
         $paddingDepth = sprintf("%.1f", $selectSize / 2);
         echo "<select name=\"search\" id=\"search\" " . "size=\"" . $selectSize . "\" " . "onblur=\"\$('#search').focus();\">";
         $selected = "selected";
         while ($row = $db->fetch_row($r)) {
             echo "<option value='" . $row["TenderCode"] . "' " . $selected . ">";
             echo $row['tenderKeyCap'] . " &nbsp; " . $row['TenderCode'] . " &nbsp; " . $row['tenderName'] . "";
             echo '</option>';
             $selected = "";
         }
         echo "</select>" . "</form>" . "</div><!-- /.listbox -->";
         /* Text to the right of the list. */
         echo "<div class=\"listboxText coloredText\" " . "style='padding-top:{$paddingDepth}em;'>";
         if ($CORE_LOCAL->get("tenderTotal") >= 0) {
             echo _("Tendering") . ' $';
         } else {
             echo _("Refunding") . ' $';
         }
         printf('%.2f', abs($CORE_LOCAL->get("tenderTotal")) / 100);
         echo '<br /><span style="font-weight:400;">' . _("[Clear] to exit") . "<br />or Browser Back and use the Q-tender" . "</span>";
         echo "</div><!-- /.listbox coloredText -->";
     } else {
         echo "<select name=\"search\" id=\"search\" " . "size=\"1\" " . "onblur=\"\$('#search').focus();\">" . "<option value='CL' SELECTED>" . _("No Coop Cred available") . "</option>" . "</select>";
         echo "</div><!-- /.listbox -->";
         /* Message under the listbox */
         echo "<div class=\"coloredText\" " . "style='clear:both; text-align:left; font-weight:bold;'>";
         echo _("There are no active Coop Cred tenders") . '<br /> &nbsp; ' . _("available to the Member.");
         echo '<br /><span style="font-weight:400;">' . _("[Enter] or [Clear] to exit") . "</span>";
         echo "</div><!-- /.coloredText -->";
         echo "</form>";
     }
     echo "<div class=\"clear\"></div>";
     echo "</div><!-- /.baseHeight -->";
     $this->add_onload_command("selectSubmit('#search', '#selectform')\n");
     $this->add_onload_command("\$('#search').focus();\n");
 }
Example #21
0
 /**
   Build a <select> form that submits
   back to this script
 */
 function body_content()
 {
     $db = Database::pDataConnect();
     $q = "SELECT TenderCode,TenderName FROM tenders WHERE TenderName LIKE '%check%' ORDER BY TenderName";
     $r = $db->query($q);
     echo "<div class=\"baseHeight\">" . "<div class=\"listbox\">" . "<form name=\"selectform\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\"" . " id=\"selectform\">" . "<select name=\"search\" id=\"search\" " . "size=\"15\" onblur=\"\$('#search').focus();\">";
     $selected = "selected";
     while ($row = $db->fetch_row($r)) {
         echo "<option value='" . $row["TenderCode"] . "' " . $selected . ">";
         echo $row['TenderName'];
         echo '</option>';
         $selected = "";
     }
     echo "</select>" . "</form>" . "</div>" . "<div class=\"listboxText coloredText centerOffset\">" . "[Clear] to Cancel</div>" . "<div class=\"clear\"></div>";
     echo "</div>";
     $this->add_onload_command("selectSubmit('#search', '#selectform')\n");
     $this->add_onload_command("\$('#search').focus();\n");
 }
Example #22
0
 /**
   Find member by membercards.upc
   @param $num the upc
   @return array. See default_value().
 */
 public function lookup_by_number($num)
 {
     $dbc = Database::pDataConnect();
     $upc = str_pad($num, 13, '0', STR_PAD_LEFT);
     $query = $dbc->prepare_statement('SELECT CardNo, personNum,
         LastName, FirstName FROM custdata
         AS c LEFT JOIN memberCards AS m
         ON c.CardNo=m.card_no
         WHERE m.upc=?
         AND Type IN (\'PC\',\'REG\')
         ORDER BY personNum');
     $result = $dbc->exec_statement($query, array($upc));
     $ret = $this->default_value();
     while ($w = $dbc->fetch_row($result)) {
         $key = $w['CardNo'] . '::' . $w['personNum'];
         $val = $w['CardNo'] . ' ' . $w['LastName'] . ', ' . $w['FirstName'];
         $ret['results'][$key] = $val;
     }
     return $ret;
 }
Example #23
0
 public function lookup_by_number($num)
 {
     $db = Database::pDataConnect();
     $ret = $this->default_value();
     // need table for lookup
     if (!$db->table_exists('meminfo')) {
         return $ret;
     }
     $query = 'SELECT CardNo,personNum,
         LastName,FirstName,phone
         FROM custdata AS c LEFT JOIN
         meminfo AS m ON c.CardNo=m.card_no
         WHERE m.phone=' . (int) $num;
     $result = $db->query($query);
     while ($row = $db->fetch_row($result)) {
         $key = $row['CardNo'] . '::' . $row['personNum'];
         $label = $row['LastName'] . ', ' . $row['FirstName'] . ' (' . $row['phone'] . ')';
         $ret['results'][$key] = $label;
     }
     return $ret;
 }
Example #24
0
 public function preprocess()
 {
     // pre-emptively lookup available reasons
     $db = Database::pDataConnect();
     $result = $db->query('SELECT shrinkReasonID, description
                           FROM ShrinkReasons');
     if ($db->num_rows($result) == 0) {
         // no reasons configured. skip the
         // this page and continue to next step.
         CoreLocal::set('shrinkReason', 0);
         $this->change_page($this->page_url . "gui-modules/adminlogin.php?class=DDDAdminLogin");
         return false;
     } else {
         if ($db->num_rows($result) == 1) {
             // exactly one reason configured.
             // just use that reason and continue
             // to next step
             $row = $db->fetch_row($result);
             CoreLocal::set('shrinkReason', $row['shrinkReasonID']);
             $this->change_page($this->page_url . "gui-modules/adminlogin.php?class=DDDAdminLogin");
             return false;
         } else {
             while ($row = $db->fetch_row($result)) {
                 $this->reasons[$row['shrinkReasonID']] = $row['description'];
             }
         }
     }
     if (isset($_REQUEST["selectlist"])) {
         $input = $_REQUEST["selectlist"];
         if ($input == "CL" || $input == '') {
             CoreLocal::set("shrinkReason", 0);
             $this->change_page($this->page_url . "gui-modules/pos2.php");
         } else {
             CoreLocal::set("shrinkReason", (int) $input);
             $this->change_page($this->page_url . "gui-modules/adminlogin.php?class=DDDAdminLogin");
         }
         return false;
     }
     return true;
 }
Example #25
0
 public function search($str)
 {
     $ret = array();
     $sql = Database::pDataConnect();
     $args = array('%' . $str . '%');
     $table = $sql->table_definition('products');
     $string_search = "(description LIKE ?)";
     // new coluumns 16Apr14
     // search in products.brand and products.formatted_name
     // if those columns are available
     if (isset($table['brand']) && isset($table['formatted_name'])) {
         $string_search = "(\n                                description LIKE ?\n                                OR brand LIKE ?\n                                OR formatted_name LIKE ?\n                              )";
         $args = array('%' . $str . '%', '%' . $str . '%', '%' . $str . '%');
     }
     $query = "SELECT upc, \n                    description, \n                    normal_price, \n                    special_price,\n                    scale \n                  FROM products \n                  WHERE {$string_search}\n                    AND upc LIKE '0000000%'\n                    AND inUse=1\n                  ORDER BY description";
     $prep = $sql->prepare($query);
     $result = $sql->execute($prep, $args);
     while ($row = $sql->fetch_row($result)) {
         $ret[$row['upc']] = $row;
     }
     return $ret;
 }
Example #26
0
 /**
   Constructor
   @param $code two letter tender code
   @param $amt tender amount
 
   If you override this, be sure to call the
   parent constructor
 */
 public function __construct($code, $amt)
 {
     $this->tender_code = $code;
     $this->amount = $amt;
     $db = Database::pDataConnect();
     $query = "select TenderID,TenderCode,TenderName,TenderType,\n            ChangeMessage,MinAmount,MaxAmount,MaxRefund from \n            tenders where tendercode = '" . $this->tender_code . "'";
     $result = $db->query($query);
     if ($db->num_rows($result) > 0) {
         $row = $db->fetch_array($result);
         $this->name_string = $row['TenderName'];
         $this->change_type = $row['TenderType'];
         $this->change_string = $row['ChangeMessage'];
         $this->min_limit = $row['MinAmount'];
         $this->max_limit = $row['MaxAmount'];
     } else {
         $this->name_string = '';
         $this->change_string = 'Change';
         $this->min_limit = 0;
         $this->max_limit = 0;
         $this->change_type = 'CA';
     }
 }
Example #27
0
 function preprocess()
 {
     /**
       Handle user input
     
       If input is blank or clear, return to the main page
     
       If input is numeric, build an appropriate coupon UPC
        and set that to repeat as the next pos2 input
     */
     if (isset($_REQUEST['search'])) {
         $input = strtoupper($_REQUEST['search']);
         if ($input === "" || $input === "CL") {
             $this->change_page($this->page_url . "gui-modules/pos2.php");
             return False;
         } else {
             if (is_numeric($input)) {
                 $upc = "00499999" . str_pad((int) $input, 5, '0', STR_PAD_LEFT);
                 CoreLocal::set("msgrepeat", 1);
                 CoreLocal::set("strRemembered", $upc);
                 $this->change_page($this->page_url . "gui-modules/pos2.php");
                 return False;
             }
         }
     }
     /**
       Lookup coupons by member number
     */
     $memberID = CoreLocal::get("memberID");
     $sql = Database::pDataConnect();
     $query = "select coupID,description FROM houseVirtualCoupons\n            WHERE card_no=" . $memberID . " AND " . $sql->now() . " > start_date AND " . $sql->now() . " < end_date";
     $result = $sql->query($query);
     $num_rows = $sql->num_rows($result);
     $this->temp_result = $result;
     $this->temp_num_rows = $num_rows;
     $this->db = $sql;
     return True;
 }
Example #28
0
 /**
   helper - lookup coupon record
 */
 private function lookupCoupon($id)
 {
     $dbc = Database::pDataConnect();
     $hctable = $dbc->table_definition('houseCoupons');
     $infoQ = "SELECT endDate," . $dbc->identifier_escape('limit') . ",\n                    discountType, \n                    department,\n                    discountValue, \n                    minType, \n                    minValue, \n                    memberOnly, \n                    CASE \n                        WHEN endDate IS NULL THEN 0 \n                        ELSE " . $dbc->datediff('endDate', $dbc->now()) . " \n                    END AS expired";
     // new(ish) columns 16apr14
     if (isset($hctable['description'])) {
         $infoQ .= ', description';
     } else {
         $infoQ .= ', \'\' AS description';
     }
     if (isset($hctable['startDate'])) {
         $infoQ .= ", CASE \n                          WHEN startDate IS NULL THEN 0 \n                          ELSE " . $dbc->datediff('startDate', $dbc->now()) . " \n                        END as preStart";
     } else {
         $infoQ .= ', 0 AS preStart';
     }
     $infoQ .= " FROM  houseCoupons \n                    WHERE coupID=" . (int) $id;
     $infoR = $dbc->query($infoQ);
     if ($dbc->num_rows($infoR) == 0) {
         return false;
     }
     return $dbc->fetch_row($infoR);
 }
 public function search($str)
 {
     $ret = array();
     $sql = Database::pDataConnect();
     if (!$sql->table_exists('productUser')) {
         return $ret;
     }
     //               CASE WHEN u.description IS NOT NULL THEN u.description
     //                   ELSE p.description END as description,
     //            u.description,
     $query = "SELECT p.upc,\n               CASE WHEN u.description IS NOT NULL THEN u.description\n                   ELSE p.description END as description,\n                p.normal_price, p.special_price, p.scale\n               FROM products AS p\n                LEFT JOIN productUser AS u ON p.upc=u.upc\n             WHERE (p.description LIKE '%{$str}%' OR\n                 u.description LIKE '%{$str}%')\n            AND p.inUse='1'\n            ORDER BY description";
     //     $query .= " AND p.upc LIKE ('0000000%')";
     // 'listAllProducts'
     /*
      if (CoreLocal::get("store") != "WEFC_Toronto") {
          $query .= " AND p.upc LIKE ('0000000%')";
      }
     */
     $result = $sql->query($query);
     while ($row = $sql->fetch_row($result)) {
         $ret[$row['upc']] = $row;
     }
     return $ret;
 }
 public function search($str)
 {
     $ret = array();
     $sql = Database::pDataConnect();
     if (!$sql->table_exists('productUser')) {
         return $ret;
     }
     /*
      * description formatted: BRAND | item | sizeUnitOfMeasure
      * - prefer productUser.description for item
      * - ?prefer productUser.description for brand
      * - ?prefer productUser.sizing, without space separator,
      *     for sizeUnitOfMeasure
      */
     $query = "SELECT p.upc,\n            CONCAT(\n            CASE WHEN COALESCE(u.brand, '') != ''\n                THEN CONCAT(UPPER(u.brand), ' | ')\n            WHEN COALESCE(p.brand, '') != ''\n                THEN CONCAT(UPPER(p.brand), ' | ')\n            ELSE '' END,\n            CASE WHEN COALESCE(u.description, '') != ''\n                THEN u.description\n                ELSE p.description END,\n            CASE WHEN COALESCE(p.size,p.unitofmeasure) != ''\n            THEN CONCAT(' | ',p.size,p.unitofmeasure) ELSE '' END\n            )\n                AS description,\n                p.normal_price, p.special_price, p.scale\n               FROM products AS p\n                LEFT JOIN productUser AS u ON p.upc=u.upc\n                WHERE (\n                    u.description LIKE ? OR\n                    p.description LIKE ? OR\n                    p.formatted_name LIKE ? OR\n                    p.brand LIKE ? OR\n                    u.brand LIKE ?\n                 )\n            AND p.inUse='1'\n            ORDER BY description";
     $args = array('%' . $str . '%', '%' . $str . '%', '%' . $str . '%', '%' . $str . '%', '%' . $str . '%');
     $prep = $sql->prepare($query);
     $result = $sql->execute($prep, $args);
     while ($row = $sql->fetch_row($result)) {
         $ret[$row['upc']] = $row;
     }
     $this->this_mod_only = !empty($ret) ? 1 : 0;
     return $ret;
 }