function parse($str) { $curID = CoreLocal::get("currentid"); $dbc = Database::tDataConnect(); $query = "SELECT trans_type,tax,foodstamp FROM localtemptrans WHERE trans_id={$curID}"; $res = $dbc->query($query); if ($dbc->num_rows($res) == 0) { return True; } // shouldn't ever happen $item = $dbc->fetch_row($res); $query = "SELECT MAX(id) FROM taxrates"; $res = $dbc->query($query); $tax_cap = 0; if ($dbc->num_rows($res) > 0) { $taxID = $dbc->fetch_row($res); $max = $taxID[0]; if (!empty($max)) { $tax_cap = $max; } } $dbc->query($query); $next_tax = $item['tax'] + 1; $next_fs = 0; if ($next_tax > $max) { $next_tax = 0; $next_fs = 1; } $query = "UPDATE localtemptrans \n set tax={$next_tax},foodstamp={$next_fs} \n WHERE trans_id={$curID}"; $dbc->query($query); $ret = $this->default_json(); $ret['output'] = DisplayLib::listItems(CoreLocal::get("currenttopid"), $curID); return $ret; // maintain item cursor position }
function parse($str) { $lines = CoreLocal::get('screenLines'); if (!$lines === '' || !is_numeric($lines)) { $lines = 11; } $ret = $this->default_json(); if ($str == "U") { $ret["output"] = DisplayLib::listItems(CoreLocal::get("currenttopid"), $this->next_valid(CoreLocal::get("currentid"), True)); } elseif ($str == "D") { $ret["output"] = DisplayLib::listItems(CoreLocal::get("currenttopid"), $this->next_valid(CoreLocal::get("currentid"), False)); } else { $change = (int) substr($str, 1); $curID = CoreLocal::get("currenttopid"); $newID = CoreLocal::get("currentid"); if ($str[0] == "U") { $newID -= $change; } else { $newID += $change; } if ($newID == $curID || $newID == $curID + $lines) { $curID = $newID - 5; } if ($curID < 1) { $curID = 1; } $ret["output"] = DisplayLib::listItems($curID, $newID); } return $ret; }
public function testDisplayLib() { $footer = DisplayLib::printfooter(); $this->assertInternalType('string', $footer); $this->assertNotEmpty($footer); $pmsg = DisplayLib::plainmsg('test message'); $this->assertInternalType('string', $pmsg); $this->assertNotEmpty($pmsg); $this->assertContains('test message', $pmsg); $mbox = DisplayLib::msgbox('test msgbox', '', True); $this->assertInternalType('string', $mbox); $this->assertNotEmpty($mbox); $this->assertContains('test msgbox', $mbox); $xbox = DisplayLib::xboxMsg('test xboxMsg'); $this->assertInternalType('string', $xbox); $this->assertNotEmpty($xbox); $this->assertContains('test xboxMsg', $xbox); $bmsg = DisplayLib::boxMsg('test boxMsg', '', True); $this->assertInternalType('string', $bmsg); $this->assertNotEmpty($bmsg); $this->assertContains('test boxMsg', $bmsg); $unk = DisplayLib::inputUnknown(); $this->assertInternalType('string', $unk); $this->assertNotEmpty($unk); $headerb = DisplayLib::printheaderb(); $this->assertInternalType('string', $headerb); $this->assertNotEmpty($headerb); $item = DisplayLib::printItem('name', 'weight', '1.99', 'T', 1); $this->assertInternalType('string', $item); $this->assertNotEmpty($item); $itemC = DisplayLib::printItemColor('004080', 'name', 'weight', '1.99', 'T', 2); $this->assertInternalType('string', $itemC); $this->assertNotEmpty($itemC); $itemH = DisplayLib::printItemColorHilite('004080', 'name', 'weight', '1.99', 'T'); $this->assertInternalType('string', $itemH); $this->assertNotEmpty($itemH); CoreLocal::set('weight', 0); CoreLocal::set('scale', 0); CoreLocal::set('SNR', 0); $basic = DisplayLib::scaledisplaymsg(); $this->assertInternalType('string', $basic); $this->assertEquals('0.00 lb', $basic); $scale_in_out = array('S11000' => '0.00 lb', 'S11001' => '0.01 lb', 'S11' => '_ _ _ _', 'S141' => '_ _ _ _', 'S143' => '0.00 lb', 'S145' => 'err -0', 'S142' => 'error', 'ASDF' => '? ? ? ?', 'S144000' => '0.00 lb', 'S144002' => '0.02 lb'); foreach ($scale_in_out as $input => $output) { $test = DisplayLib::scaledisplaymsg($input); $this->assertInternalType('array', $test); $this->assertArrayHasKey('display', $test); $this->assertEquals($output, $test['display']); } $this->assertEquals(1, CoreLocal::get('scale')); $this->assertEquals(0.02, CoreLocal::get('weight')); CoreLocal::set('SNR', '4011'); $both = DisplayLib::scaledisplaymsg('S11050'); $this->assertInternalType('array', $both); $this->assertArrayHasKey('display', $both); $this->assertArrayHasKey('upc', $both); $this->assertEquals('0.50 lb', $both['display']); $this->assertEquals('4011', $both['upc']); $list = DisplayLib::listItems(0, 0); $this->assertInternalType('string', $list); $rf = DisplayLib::printReceiptFooter(); $this->assertInternalType('string', $rf); $draw = DisplayLib::drawItems(0, 11, 0); $this->assertInternalType('string', $draw); $lp = DisplayLib::lastpage(); $this->assertInternalType('string', $lp); $this->assertEquals($lp, $list); }