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

feat: default precision with setting

Übergeordneter 520c7c95
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -19,6 +19,10 @@
<de><![CDATA[Verwendete Seiten]]></de>
<en><![CDATA[Used sites]]></en>
</locale>
<locale name="menu.erp.general.numberRanges.title">
<de><![CDATA[Nummernkreise]]></de>
<en><![CDATA[Number ranges]]></en>
</locale>
<locale name="price.starting.from">
<de><![CDATA[ab [price]]]></de>
......@@ -96,6 +100,18 @@
<en><![CDATA[Revocation policy]]></en>
</locale>
<locale name="shop.settings.general.precision">
<de><![CDATA[Verwendete Nachkommastellen]]></de>
<en><![CDATA[Used decimal digits]]></en>
</locale>
<locale name="shop.settings.general.precision.description">
<de><![CDATA[
Diese Einstellung legt fest mit wieviele Nachkommenstellen das System rechnen soll.
]]></de>
<en><![CDATA[
This setting determines how many decimal places the system should use for calculation.
]]></en>
</locale>
<locale name="shop.settings.businessType">
<de><![CDATA[Vertriebsart]]></de>
<en><![CDATA[Business type]]></en>
......
......@@ -8,6 +8,10 @@
<type>string</type>
<defaultValue>B2C</defaultValue>
</conf>
<conf name="precision">
<type>integer</type>
<defaultValue>8</defaultValue>
</conf>
</section>
<section name="sites">
<conf name="terms_and_conditions">
......@@ -37,7 +41,7 @@
</text>
<icon>fa fa-info</icon>
<settings title="numberRanges" name="numberRanges">
<settings>
<title>
<locale group="quiqqer/erp" var="menu.erp.general.title"/>
</title>
......@@ -64,6 +68,20 @@
</option>
</select>
<input type="number" conf="general.precision">
<text>
<locale group="quiqqer/erp" var="shop.settings.general.precision"/>
</text>
<description>
<locale group="quiqqer/erp" var="shop.settings.general.precision.description"/>
</description>
</input>
</settings>
<settings title="numberRanges" name="numberRanges">
<title>
<locale group="quiqqer/erp" var="menu.erp.general.numberRanges.title"/>
</title>
<input type="hidden"
label="false"
data-qui="package/quiqqer/erp/bin/backend/controls/settings/NumberRange">
......
......@@ -138,6 +138,8 @@ public function getCurrency()
* @param ArticleList $List
* @param callable|boolean $callback - optional, callback function for the data array
* @return ArticleList
*
* @throws QUI\Exception
*/
public function calcArticleList(ArticleList $List, $callback = false)
{
......@@ -154,7 +156,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
$subSum = 0;
$nettoSum = 0;
$vatArray = array();
$vatArray = [];
/* @var $Article Article */
foreach ($articles as $Article) {
......@@ -162,7 +164,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
try {
QUI::getEvents()->fireEvent(
'onQuiqqerErpCalcArticleListArticle',
array($this, $Article)
[$this, $Article]
);
} catch (QUI\Exception $Exception) {
QUI\System\Log::write($Exception->getMessage(), QUI\System\Log::LEVEL_ERROR);
......@@ -193,7 +195,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
try {
QUI::getEvents()->fireEvent(
'onQuiqqerErpCalcArticleList',
array($this, $List, $nettoSum)
[$this, $List, $nettoSum]
);
} catch (QUI\Exception $Exception) {
QUI\System\Log::write($Exception->getMessage(), QUI\System\Log::LEVEL_ERROR);
......@@ -205,8 +207,8 @@ public function calcArticleList(ArticleList $List, $callback = false)
// vat text
$vatLists = array();
$vatText = array();
$vatLists = [];
$vatText = [];
$bruttoSum = $nettoSum;
foreach ($vatArray as $vatEntry) {
......@@ -219,7 +221,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
$vatText[$vat] = self::getVatText($vat, $this->getUser());
}
$callback(array(
$callback([
'sum' => $bruttoSum,
'subSum' => $subSum,
'nettoSum' => $nettoSum,
......@@ -229,7 +231,7 @@ public function calcArticleList(ArticleList $List, $callback = false)
'isEuVat' => $isEuVatUser,
'isNetto' => $isNetto,
'currencyData' => $this->getCurrency()->toArray()
));
]);
return $List;
}
......@@ -240,6 +242,8 @@ public function calcArticleList(ArticleList $List, $callback = false)
* @param Article $Article
* @param bool|callable $callback
* @return mixed
*
* @throws QUI\Exception
*/
public function calcArticlePrice(Article $Article, $callback = false)
{
......@@ -288,18 +292,18 @@ public function calcArticlePrice(Article $Article, $callback = false)
$sum = $isNetto ? $nettoSum : $bruttoSum;
$basisPrice = $isNetto ? $basisNettoPrice : $basisNettoPrice + ($basisNettoPrice * $vat / 100);
$vatArray = array(
$vatArray = [
'vat' => $vat,
'sum' => $this->round($nettoSum * ($vat / 100)),
'text' => $this->getVatText($vat, $this->getUser())
);
];
QUI\ERP\Debug::getInstance()->log(
'Kalkulierter Artikel Preis '.$Article->getId(),
'quiqqer/erp'
);
$data = array(
$data = [
'basisPrice' => $basisPrice,
'price' => $price,
'sum' => $sum,
......@@ -314,7 +318,7 @@ public function calcArticlePrice(Article $Article, $callback = false)
'vatText' => $vatArray['text'],
'isEuVat' => $isEuVatUser,
'isNetto' => $isNetto
);
];
QUI\ERP\Debug::getInstance()->log($data, 'quiqqer/erp');
......@@ -333,7 +337,7 @@ public function round($value)
{
$decimalSeparator = $this->getUser()->getLocale()->getDecimalSeparator();
$groupingSeparator = $this->getUser()->getLocale()->getGroupingSeparator();
$precision = 8; // nachkommstelle beim runden -> @todo in die conf?
$precision = QUI\ERP\Defaults::getPrecision();
if (strpos($value, $decimalSeparator) && $decimalSeparator != ' . ') {
$value = str_replace($groupingSeparator, '', $value);
......@@ -345,11 +349,12 @@ public function round($value)
return $value;
}
/**
* Return the tax message for an user
*
* @return string
*
* @throws QUI\Exception
*/
public function getVatTextByUser()
{
......@@ -375,7 +380,7 @@ public static function getVatText($vat, UserInterface $User)
return $Locale->get(
'quiqqer/tax',
'message.vat.text.netto.EUVAT',
array('vat' => $vat)
['vat' => $vat]
);
}
......@@ -387,7 +392,7 @@ public static function getVatText($vat, UserInterface $User)
return $Locale->get(
'quiqqer/tax',
'message.vat.text.netto',
array('vat' => $vat)
['vat' => $vat]
);
}
......@@ -395,7 +400,7 @@ public static function getVatText($vat, UserInterface $User)
return $Locale->get(
'quiqqer/tax',
'message.vat.text.brutto.EUVAT',
array('vat' => $vat)
['vat' => $vat]
);
}
......@@ -407,7 +412,7 @@ public static function getVatText($vat, UserInterface $User)
return $Locale->get(
'quiqqer/tax',
'message.vat.text.brutto',
array('vat' => $vat)
['vat' => $vat]
);
}
......@@ -449,7 +454,7 @@ public static function calculatePayments($ToCalculate)
$Transactions = QUI\ERP\Accounting\Payments\Transactions\Handler::getInstance();
$transactions = $Transactions->getTransactionsByHash($ToCalculate->getHash());
$paidData = array();
$paidData = [];
$paidDate = 0;
$sum = 0;
$total = $ToCalculate->getAttribute('sum');
......@@ -498,11 +503,11 @@ public static function calculatePayments($ToCalculate)
$sum = $sum + $amount;
$paidData[] = array(
$paidData[] = [
'amount' => $amount,
'date' => $date,
'txid' => $Transaction->getTxId()
);
];
}
$paid = Price::validatePrice($sum);
......@@ -528,22 +533,22 @@ public static function calculatePayments($ToCalculate)
$ToCalculate->setAttribute('paid_status', Invoice::PAYMENT_STATUS_PART);
}
QUI\ERP\Debug::getInstance()->log(array(
QUI\ERP\Debug::getInstance()->log([
'paidData' => $paidData,
'paidDate' => $ToCalculate->getAttribute('paid_date'),
'paid' => $ToCalculate->getAttribute('paid'),
'toPay' => $ToCalculate->getAttribute('toPay'),
'paidStatus' => $ToCalculate->getAttribute('paid_status'),
'sum' => $sum
));
]);
return array(
return [
'paidData' => $paidData,
'paidDate' => $ToCalculate->getAttribute('paid_date'),
'paidStatus' => $ToCalculate->getAttribute('paid_status'),
'paid' => $ToCalculate->getAttribute('paid'),
'toPay' => $ToCalculate->getAttribute('toPay')
);
];
}
public static function isAllowedForCalculation($ToCalculate)
......@@ -571,7 +576,7 @@ public static function calculateTotal(array $invoiceList)
$Currency = QUI\ERP\Defaults::getCurrency();
$display = $Currency->format(0);
return array(
return [
'netto_toPay' => 0,
'netto_paid' => 0,
'netto_total' => 0,
......@@ -592,7 +597,7 @@ public static function calculateTotal(array $invoiceList)
'display_brutto_toPay' => $display,
'display_brutto_paid' => $display,
'display_brutto_total' => $display
);
];
}
try {
......@@ -629,7 +634,7 @@ public static function calculateTotal(array $invoiceList)
$vatToPay = $bruttoToPay - $nettoToPay;
$vatPaid = $bruttoPaid - $nettoPaid;
return array(
return [
'netto_toPay' => $nettoToPay,
'netto_paid' => $nettoPaid,
'netto_total' => $nettoTotal,
......@@ -650,7 +655,7 @@ public static function calculateTotal(array $invoiceList)
'display_brutto_toPay' => $Currency->format($bruttoToPay),
'display_brutto_paid' => $Currency->format($bruttoPaid),
'display_brutto_total' => $Currency->format($bruttoTotal)
);
];
}
/**
......
......@@ -45,22 +45,12 @@ public function __construct($number, $Currency = null, $precision = false)
}
$this->number = $number;
// precision
if (is_numeric($precision)) {
$this->precision = $precision;
} else {
try {
$Package = QUI::getPackage('quiqqer/erp');
$Config = $Package->getConfig();
$precision = $Config->get('general', 'precision');
if ($precision) {
$this->precision = $precision;
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
$this->precision = QUI\ERP\Defaults::getPrecision();
}
// currency
......
......@@ -26,11 +26,6 @@ class Calculations
*/
protected $Currency;
/**
* @var integer
*/
protected $defaultPrecision = 8;
/**
* Calculations constructor.
*
......@@ -67,18 +62,6 @@ public function __construct($attributes)
} catch (QUI\Exception $Exception) {
$this->Currency = QUI\ERP\Defaults::getCurrency();
}
try {
$Package = QUI::getPackage('quiqqer/erp');
$Config = $Package->getConfig();
$precision = $Config->get('general', 'precision');
if ($precision) {
$this->defaultPrecision = $precision;
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
/**
......@@ -91,7 +74,7 @@ public function getSum()
return new CalculationValue(
$this->attributes['sum'],
$this->Currency,
$this->defaultPrecision
QUI\ERP\Defaults::getPrecision()
);
}
......@@ -105,7 +88,7 @@ public function getSubSum()
return new CalculationValue(
$this->attributes['subSum'],
$this->Currency,
$this->defaultPrecision
QUI\ERP\Defaults::getPrecision()
);
}
......@@ -126,7 +109,7 @@ public function getVatSum()
return new CalculationValue(
$sum,
$this->Currency,
$this->defaultPrecision
QUI\ERP\Defaults::getPrecision()
);
}
}
......@@ -76,4 +76,26 @@ public static function getBruttoNettoStatus()
return QUI\ERP\Utils\User::IS_BRUTTO_USER;
}
/**
* Return the system calculation precision
*
* @return array|int|string
*/
public static function getPrecision()
{
try {
$Package = QUI::getPackage('quiqqer/erp');
$Config = $Package->getConfig();
$precision = $Config->get('general', 'precision');
if ($precision) {
return $precision;
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
return 8;
}
}
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren