예제 #1
0
파일: ItemsTest.php 프로젝트: haaseit/hcsf
 /**
  *
  */
 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);
 }
예제 #2
0
파일: Helper.php 프로젝트: haaseit/hcsf
 /**
  * @param string $sSetSuggestions
  * @param array $aPossibleSuggestions
  * @param Items $oItem
  * @return array
  */
 public static function prepareSuggestions($sSetSuggestions, $aPossibleSuggestions, Items $oItem)
 {
     $sSetSuggestions = trim($sSetSuggestions);
     $aDefinedSuggestions = [];
     if (!empty($sSetSuggestions)) {
         $aDefinedSuggestions = explode('|', $sSetSuggestions);
     }
     $aSuggestionsToLoad = [];
     // iterate all defined suggestions and put those not loaded yet into array
     foreach ($aDefinedSuggestions as $defisugsval) {
         if (!isset($aPossibleSuggestions[$defisugsval])) {
             $aSuggestionsToLoad[] = $defisugsval;
         }
     }
     // if there are not yet loaded suggestions, load them
     if (isset($aSuggestionsToLoad)) {
         $aItemsNotInCategory = $oItem->sortItems('', $aSuggestionsToLoad, false);
         // merge loaded and newly loaded items
         if (!empty($aItemsNotInCategory)) {
             $aPossibleSuggestions = array_merge($aPossibleSuggestions, $aItemsNotInCategory["item"]);
         }
     }
     $suggestions = ['default' => [], 'additional' => []];
     foreach ($aPossibleSuggestions as $posssugskey => $posssugsval) {
         // iterate through all possible suggestions
         if (in_array($posssugskey, $aDefinedSuggestions)) {
             // if this suggestion is a defined one, put into this array
             $suggestions['default'][$posssugskey] = $posssugsval;
             continue;
         }
         // if not, put into this one
         $suggestions['additional'][$posssugskey] = $posssugsval;
     }
     return $suggestions;
 }