Пример #1
0
 function tender_out($asTender)
 {
     $ret = $this->default_json();
     Database::getsubtotals();
     if (CoreLocal::get("amtdue") <= 0.005) {
         CoreLocal::set("change", -1 * CoreLocal::get("amtdue"));
         $cash_return = CoreLocal::get("change");
         if ($asTender != "FS") {
             TransRecord::addchange($cash_return, 'CA');
         }
         CoreLocal::set("End", 1);
         $ret['output'] = DisplayLib::printReceiptFooter();
         $ret['redraw_footer'] = true;
         $ret['receipt'] = 'full';
         TransRecord::finalizeTransaction();
     } else {
         CoreLocal::set("change", 0);
         CoreLocal::set("fntlflag", 0);
         $ttl_result = PrehLib::ttl();
         TransRecord::debugLog('Tender Out (PrehLib): ' . print_r($ttl_result, true));
         TransRecord::debugLog('Tender Out (amtdue): ' . print_r(CoreLocal::get('amtdue'), true));
         $ret['output'] = DisplayLib::lastpage();
     }
     return $ret;
 }
Пример #2
0
 /**
   Add a tender to the transaction
 
   @right tender amount in cents (100 = $1)
   @strl tender code from tenders table
   @return An array see Parser::default_json()
    for format explanation.
 
   This function will automatically end a transaction
   if the amount due becomes <= zero.
 */
 public static function tender($right, $strl)
 {
     $ret = array('main_frame' => false, 'redraw_footer' => false, 'target' => '.baseHeight', 'output' => "");
     $strl = MiscLib::centStrToDouble($strl);
     if (CoreLocal::get('RepeatAgain')) {
         // the default tender prompt utilizes boxMsg2.php to
         // repeat the previous input, plus amount, on confirmation
         // the tender's preReqCheck methods will need to pretend
         // this is the first input rather than a repeat
         CoreLocal::set('msgrepeat', 0);
         CoreLocal::set('RepeatAgain', false);
     }
     $tender_mods = self::getTenderMods($right);
     $tender_object = null;
     foreach ($tender_mods as $class) {
         if (!class_exists($class)) {
             $ret['output'] = DisplayLib::boxMsg(_('tender is misconfigured'), _('Notify Administrator'), false, DisplayLib::standardClearButton());
             return $ret;
         }
         $tender_object = new $class($right, $strl);
         /**
           Do tender-specific error checking and prereqs
         */
         $error = $tender_object->ErrorCheck();
         if ($error !== true) {
             $ret['output'] = $error;
             return $ret;
         }
         $prereq = $tender_object->PreReqCheck();
         if ($prereq !== true) {
             $ret['main_frame'] = $prereq;
             return $ret;
         }
     }
     // add the tender record
     $tender_object->Add();
     Database::getsubtotals();
     // see if transaction has ended
     if (CoreLocal::get("amtdue") <= 0.005) {
         CoreLocal::set("change", -1 * CoreLocal::get("amtdue"));
         $cash_return = CoreLocal::get("change");
         TransRecord::addchange($cash_return, $tender_object->ChangeType(), $tender_object->ChangeMsg());
         CoreLocal::set("End", 1);
         $ret['receipt'] = 'full';
         $ret['output'] = DisplayLib::printReceiptFooter();
         TransRecord::finalizeTransaction();
     } else {
         CoreLocal::set("change", 0);
         CoreLocal::set("fntlflag", 0);
         Database::setglobalvalue("FntlFlag", 0);
         $chk = self::ttl();
         if ($chk === true) {
             $ret['output'] = DisplayLib::lastpage();
         } else {
             $ret['main_frame'] = $chk;
         }
     }
     $ret['redraw_footer'] = true;
     return $ret;
 }
Пример #3
0
 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);
 }