Skip to content
Code-Schnipsel Gruppen Projekte
Commit 70d9b885 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: Price Factors for order articles

Übergeordneter f2077356
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -237,6 +237,8 @@ public function getUnitPrice()
* Returns the article total sum
*
* @return QUI\ERP\Money\Price
*
* @throws QUI\Exception
*/
public function getSum()
{
......@@ -307,6 +309,8 @@ public function getQuantity()
* Return the price from the article
*
* @return Price
*
* @throws QUI\Exception
*/
public function getPrice()
{
......@@ -367,6 +371,8 @@ public function hasDiscount()
/**
* @param null|Calc|QUI\ERP\User $Instance
* @return self
*
* @throws QUI\Exception
*/
public function calc($Instance = null)
{
......
......@@ -26,7 +26,7 @@
</tr>
{foreach $articles as $Article}
{$Article->toHTML()}
{$Article->toHTML()}
{/foreach}
</table>
......@@ -45,23 +45,22 @@
</td>
</tr>
{*if count($data.attributes)}
{if count($priceFactors)}
<tr>
<td colspan="2"><br/></td>
</tr>
{/if*}
{/if}
{*foreach $data.attributes as $attribute}
{foreach $priceFactors as $priceFactor}
<tr>
<td class="articles-sum-row-firstCell">
{$attribute.title}
{$priceFactor.title}
</td>
<td class="articles-sum-row-sndCell">
{$attribute.valueText}<br/>
{$attribute.value}
{$priceFactor.valueText}
</td>
</tr>
{/foreach*}
{/foreach}
{foreach $vatArray as $vat}
<tr>
......
......@@ -55,7 +55,7 @@ class ArticleList extends ArticleListUnique
* key 19% value[sum] = sum value[text] = text value[display_sum] formatiert
* @var array
*/
protected $vatArray = array();
protected $vatArray = [];
/**
* key 19% value[sum] = sum value[text] = text value[display_sum] formatiert
......@@ -79,12 +79,12 @@ class ArticleList extends ArticleListUnique
* Currency information
* @var array
*/
protected $currencyData = array(
protected $currencyData = [
'currency_sign' => '',
'currency_code' => '',
'user_currency' => '',
'currency_rate' => ''
);
];
/**
* ArticleList constructor.
......@@ -92,14 +92,18 @@ class ArticleList extends ArticleListUnique
* @param array $attributes
* @throws QUI\ERP\Exception
*/
public function __construct(array $attributes = array())
public function __construct(array $attributes = [])
{
if (!isset($attributes['calculations'])) {
$attributes['calculations'] = array();
$attributes['calculations'] = [];
}
if (!isset($attributes['articles'])) {
$attributes['articles'] = array();
$attributes['articles'] = [];
}
if (!isset($attributes['priceFactors'])) {
$attributes['priceFactors'] = [];
}
parent::__construct($attributes);
......@@ -110,6 +114,8 @@ public function __construct(array $attributes = array())
* User for calculation
*
* @param QUI\Interfaces\Users\User $User
*
* @throws QUI\Exception
*/
public function setUser(QUI\Interfaces\Users\User $User)
{
......@@ -204,6 +210,19 @@ public function toArray()
$data['articles'] = $articles;
$data['calculations'] = $calculations;
/* @var $Factor QUI\ERP\Products\Utils\PriceFactor */
foreach ($this->PriceFactors->sort() as $Factor) {
if (!$Factor->isVisible()) {
continue;
}
$result['attributes'][] = [
'title' => $Factor->getTitle(),
'value' => $Factor->getNettoSumFormatted(),
'valueText' => $Factor->getValueText(),
];
}
return $data;
}
......@@ -213,6 +232,7 @@ public function toArray()
* @return ArticleListUnique
*
* @throws QUI\ERP\Exception
* @throws QUI\Exception
*/
public function toUniqueList()
{
......@@ -224,6 +244,8 @@ public function toUniqueList()
/**
* @param null|Calc $Calc
* @return $this
*
* @throws QUI\Exception
*/
public function calc($Calc = null)
{
......@@ -252,7 +274,7 @@ public function calc($Calc = null)
$self->isNetto = $data['isNetto'];
$self->currencyData = $data['currencyData'];
$this->calculations = array(
$this->calculations = [
'sum' => $self->sum,
'subSum' => $self->subSum,
'nettoSum' => $self->nettoSum,
......@@ -262,7 +284,7 @@ public function calc($Calc = null)
'isEuVat' => $self->isEuVat,
'isNetto' => $self->isNetto,
'currencyData' => $self->currencyData
);
];
$self->calculated = true;
});
......@@ -315,7 +337,7 @@ public function replaceArticle(Article $Article, $index)
*/
public function clear()
{
$this->articles = array();
$this->articles = [];
}
/**
......@@ -329,4 +351,18 @@ public function count()
}
//endregion
//region Price Factors
/**
* Import a price factor list
*
* @param QUI\ERP\Products\Utils\PriceFactors $PriceFactors
*/
public function importPriceFactors($PriceFactors)
{
$this->PriceFactors = $PriceFactors;
}
//endregion
}
......@@ -19,37 +19,44 @@ class ArticleListUnique
/**
* @var array
*/
protected $articles = array();
protected $articles = [];
/**
* @var array
*/
protected $calculations = array();
protected $calculations = [];
/**
* @var bool|mixed
*/
protected $showHeader;
/**
* PriceFactor List
*
* @var QUI\ERP\Products\Utils\PriceFactors
*/
protected $PriceFactors = false;
/**
* ArticleList constructor.
*
* @param array $attributes
* @throws QUI\ERP\Exception
*/
public function __construct($attributes = array())
public function __construct($attributes = [])
{
$needles = array('articles', 'calculations');
$needles = ['articles', 'calculations'];
foreach ($needles as $needle) {
if (!isset($attributes[$needle])) {
throw new QUI\ERP\Exception(
'Missing needle for ArticleListUnique',
400,
array(
[
'class' => 'ArticleListUnique',
'missing' => $needle
)
]
);
}
}
......@@ -62,6 +69,14 @@ public function __construct($attributes = array())
$this->calculations = $attributes['calculations'];
$this->showHeader = isset($attributes['showHeader']) ? $attributes['showHeader'] : true;
// price factors
$this->PriceFactors = new QUI\ERP\Products\Utils\PriceFactors();
if (isset($attributes['priceFactors'])) {
$this->PriceFactors->importList($attributes['priceFactors']);
}
}
/**
......@@ -144,10 +159,13 @@ public function toArray()
return $Article->toArray();
}, $this->articles);
return array(
$this->PriceFactors->sort();
return [
'articles' => $articles,
'calculations' => $this->calculations
);
'calculations' => $this->calculations,
'priceFactors' => $this->PriceFactors->toArray()
];
}
/**
......@@ -177,7 +195,7 @@ public function hideHeader()
public function toHTML($template = false)
{
$Engine = QUI::getTemplateManager()->getEngine();
$vatArray = array();
$vatArray = [];
$Currency = QUI\ERP\Currency\Handler::getCurrency(
$this->calculations['currencyData']['code']
......@@ -210,14 +228,21 @@ public function toHTML($template = false)
return $View;
}, $this->articles);
// price factors
$priceFactors = $this->PriceFactors->sort();
$priceFactors = array_map(function ($Factor) {
return $Factor->toArray();
}, $priceFactors);
// output
$Engine->assign(array(
$Engine->assign([
'priceFactors' => $priceFactors,
'showHeader' => $this->showHeader,
'this' => $this,
'articles' => $articles,
'calculations' => $this->calculations,
'vatArray' => $vatArray
));
]);
if ($template && file_exists($template)) {
return $Engine->fetch($template);
......@@ -253,4 +278,18 @@ public function render()
{
return $this->toHTMLWithCSS();
}
//region Price Factors
/**
* Return the price factors list (list of price indicators)
*
* @return QUI\ERP\Products\Utils\PriceFactors
*/
public function getPriceFactors()
{
return $this->PriceFactors;
}
//endregion
}
......@@ -152,7 +152,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
$articles = $List->getArticles();
$isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser());
$isEuVatUser = QUI\ERP\Tax\Utils::isUserEuVatUser($this->getUser());
// $Area = QUI\ERP\Utils\User::getUserArea($this->getUser());
$Area = QUI\ERP\Utils\User::getUserArea($this->getUser());
$subSum = 0;
$nettoSum = 0;
......@@ -201,10 +201,75 @@ public function calcArticleList(ArticleList $List, $callback = false)
QUI\System\Log::write($Exception->getMessage(), QUI\System\Log::LEVEL_ERROR);
}
// @todo Preisfaktoren hier
/**
* Calc price factors
*/
$priceFactors = $List->getPriceFactors()->sort();
$priceFactorSum = 0;
// nur wenn wir welche benötigen, für ERP Artikel ist dies im Moment nicht wirklich nötig
$nettoSubSum = $nettoSum;
/* @var $PriceFactor QUI\ERP\Products\Utils\PriceFactor */
foreach ($priceFactors as $PriceFactor) {
switch ($PriceFactor->getCalculation()) {
// einfache Zahl, Währung --- kein Prozent
case self::CALCULATION_COMPLEMENT:
$nettoSum = $nettoSum + $PriceFactor->getValue();
$priceFactorSum = $priceFactorSum + $PriceFactor->getValue();
$PriceFactor->setNettoSum($PriceFactor->getValue());
break;
// Prozent Angabe
case self::CALCULATION_PERCENTAGE:
switch ($PriceFactor->getCalculationBasis()) {
default:
case self::CALCULATION_BASIS_NETTO:
$percentage = $PriceFactor->getValue() / 100 * $nettoSubSum;
break;
case self::CALCULATION_BASIS_BRUTTO:
case self::CALCULATION_BASIS_CURRENTPRICE:
$percentage = $PriceFactor->getValue() / 100 * $nettoSum;
break;
}
$PriceFactor->setNettoSum($percentage);
$nettoSum = $this->round($nettoSum + $percentage);
$priceFactorSum = $priceFactorSum + $percentage;
break;
default:
continue;
}
// add pricefactor VAT
if (!($PriceFactor instanceof QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface)) {
continue;
}
/* @var $PriceFactor QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface */
$VatType = $PriceFactor->getVatType();
$Vat = QUI\ERP\Tax\Utils::getTaxEntry($VatType, $Area);
$vatSum = $PriceFactor->getNettoSum() * ($Vat->getValue() / 100);
$vat = $Vat->getValue();
$PriceFactor->setBruttoSum($vatSum + $PriceFactor->getNettoSum());
if (!isset($vatArray[$vat])) {
$vatArray[$vat] = [
'vat' => $vat,
'text' => self::getVatText($Vat->getValue(), $this->getUser())
];
$vatArray[$vat]['sum'] = 0;
}
$vatArray[$vat]['sum'] = $vatArray[$vat]['sum'] + $vatSum;
}
// vat text
$vatLists = [];
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren