/** * */ public function testCalcPrice() { bcscale(6); $serviceManager = new ServiceManager(); $serviceManager->setFactory('db', function () { return null; }); HelperConfig::$shop = ['vat' => ['full' => 0, 'reduced' => 0]]; HelperConfig::$lang = 'de'; $items = new Items($serviceManager); // regular price, no rebate, vat disabled $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full']; $aPrice = $items->calcPrice($aData); $this->assertEquals('11.11', $aPrice['netto_use']); $this->assertEquals('11.11', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_sale', $aPrice); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // set vat to normal values HelperConfig::$shop = ['vat' => ['full' => 19, 'reduced' => 7], 'rebate_groups' => ['01' => ['grosskunde' => 7]]]; $items = new Items($serviceManager); // regular price, no rebate, reduced vat $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'reduced']; $aPrice = $items->calcPrice($aData); $this->assertEquals('11.11', $aPrice['netto_use']); $this->assertEquals('11.8877', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_sale', $aPrice); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // regular price, no rebate, full vat $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full']; $aPrice = $items->calcPrice($aData); $this->assertEquals('11.11', $aPrice['netto_use']); $this->assertEquals('13.2209', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_sale', $aPrice); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // item sale $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full', 'itm_data' => ['sale' => ['start' => date("Ymd") - 1, 'end' => date("Ymd") + 1, 'price' => '9.10']]]; $aPrice = $items->calcPrice($aData); $this->assertEquals('9.1', $aPrice['netto_use']); $this->assertEquals('9.1', $aPrice['netto_sale']); $this->assertEquals('10.829', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // item sale too late $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full', 'itm_data' => ['sale' => ['start' => date("Ymd") - 5, 'end' => date("Ymd") - 1, 'price' => '9.10']]]; $aPrice = $items->calcPrice($aData); $this->assertEquals('11.11', $aPrice['netto_use']); $this->assertEquals('13.2209', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_sale', $aPrice); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // test item sale too early $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full', 'itm_data' => ['sale' => ['start' => date("Ymd") + 1, 'end' => date("Ymd") + 5, 'price' => '9.10']]]; $aPrice = $items->calcPrice($aData); $this->assertEquals('11.11', $aPrice['netto_use']); $this->assertEquals('13.2209', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertArrayNotHasKey('netto_sale', $aPrice); $this->assertArrayNotHasKey('netto_rebated', $aPrice); // init session for rebate testing $_SESSION["user"] = ['cust_group' => 'grosskunde']; // test rebate group $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full']; $aPrice = $items->calcPrice($aData); $this->assertEquals('10.3323', $aPrice['netto_use']); $this->assertEquals('12.295437', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertEquals('10.3323', $aPrice['netto_rebated']); $this->assertArrayNotHasKey('netto_sale', $aPrice); // test sale/rebate group best price finding // rebate best price $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full', 'itm_data' => ['sale' => ['start' => date("Ymd") - 1, 'end' => date("Ymd") + 1, 'price' => '10.99']]]; $aPrice = $items->calcPrice($aData); $this->assertEquals('10.3323', $aPrice['netto_use']); $this->assertEquals('12.295437', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertEquals('10.3323', $aPrice['netto_rebated']); $this->assertEquals('10.99', $aPrice['netto_sale']); // sale best price $aData = ['itm_price' => '11.11', 'itm_rg' => '01', 'itm_vatid' => 'full', 'itm_data' => ['sale' => ['start' => date("Ymd") - 1, 'end' => date("Ymd") + 1, 'price' => '9.10']]]; $aPrice = $items->calcPrice($aData); $this->assertEquals('9.1', $aPrice['netto_use']); $this->assertEquals('10.829', $aPrice['brutto_use']); $this->assertEquals('11.11', $aPrice['netto_list']); $this->assertEquals('10.3323', $aPrice['netto_rebated']); $this->assertEquals('9.1', $aPrice['netto_sale']); // non valid price $aData = ['itm_price' => 'asdf', 'itm_rg' => '01', 'itm_vatid' => 'full']; $aPrice = $items->calcPrice($aData); $this->assertFalse($aPrice); }
$connectionParams = ['url' => HelperConfig::$secrets['db_type'] . '://' . HelperConfig::$secrets['db_user'] . ':' . HelperConfig::$secrets['db_password'] . '@' . HelperConfig::$secrets['db_server'] . '/' . HelperConfig::$secrets['db_name'], 'charset' => 'UTF8', 'driverOptions' => [\PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]]; return Doctrine\ORM\EntityManager::create($connectionParams, $doctrineconfig); }); $serviceManager->setFactory('db', function (ServiceManager $serviceManager) { return $serviceManager->get('entitymanager')->getConnection()->getWrappedConnection(); }); // ---------------------------------------------------------------------------- // more init stuff // ---------------------------------------------------------------------------- $serviceManager->setFactory('textcats', function (ServiceManager $serviceManager) { $langavailable = HelperConfig::$core["lang_available"]; $textcats = new \HaaseIT\Textcat(HelperConfig::$lang, $serviceManager->get('db'), key($langavailable), HelperConfig::$core['textcatsverbose'], PATH_LOGS); $textcats->loadTextcats(); return $textcats; }); HelperConfig::loadNavigation($serviceManager); } // ---------------------------------------------------------------------------- // Begin Twig loading and init // ---------------------------------------------------------------------------- $serviceManager->setFactory('twig', function (ServiceManager $serviceManager) { $loader = new Twig_Loader_Filesystem([PATH_BASEDIR . 'customviews', PATH_BASEDIR . 'src/views/']); $twig_options = ['autoescape' => false, 'debug' => HelperConfig::$core["debug"] ? true : false]; if (HelperConfig::$core["templatecache_enable"] && is_dir(PATH_TEMPLATECACHE) && is_writable(PATH_TEMPLATECACHE)) { $twig_options["cache"] = PATH_TEMPLATECACHE; } $twig = new Twig_Environment($loader, $twig_options); if (HelperConfig::$core['allow_parsing_of_page_content']) { $twig->addExtension(new Twig_Extension_StringLoader()); } else { // make sure, template_from_string is callable