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

fix: fixed inconsistent api

Übergeordneter 89603a36
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -19,10 +19,10 @@ class Article implements ArticleInterface
/**
* @var array
*/
protected $attributes = array(
protected $attributes = [
'control' => '',
'class' => ''
);
];
/**
* @var bool
......@@ -103,9 +103,9 @@ class Article implements ArticleInterface
*
* @param array $attributes - (id, articleNo, title, description, unitPrice, quantity, discount)
*/
public function __construct($attributes = array())
public function __construct($attributes = [])
{
$defaults = array(
$defaults = [
'id',
'articleNo',
'title',
......@@ -113,7 +113,7 @@ public function __construct($attributes = array())
'unitPrice',
'control',
'quantity'
);
];
foreach ($defaults as $key) {
if (isset($attributes[$key])) {
......@@ -220,27 +220,29 @@ public function getDescription()
/**
* Returns the article unit price
*
* @return int|float
* @return QUI\ERP\Money\Price
*/
public function getUnitPrice()
{
$unitPrice = 0;
if (isset($this->attributes['unitPrice'])) {
return $this->attributes['unitPrice'];
$unitPrice = $this->attributes['unitPrice'];
}
return 0;
return new Price($unitPrice, QUI\ERP\Defaults::getCurrency());
}
/**
* Returns the article total sum
*
* @return int|float
* @return QUI\ERP\Money\Price
*/
public function getSum()
{
$this->calc();
return $this->sum;
return new Price($this->sum, QUI\ERP\Defaults::getCurrency());
}
/**
......@@ -426,22 +428,22 @@ public function toArray()
$discount = $this->Discount->toJSON();
}
return array(
return [
// article data
'id' => $this->getId(),
'title' => $this->getTitle(),
'articleNo' => $this->getArticleNo(),
'description' => $this->getDescription(),
'unitPrice' => $this->getUnitPrice(),
'unitPrice' => $this->getUnitPrice()->value(),
'quantity' => $this->getQuantity(),
'sum' => $this->getSum(),
'sum' => $this->getSum()->value(),
'vat' => $vat,
'discount' => $discount,
'control' => $this->attributes['control'],
'class' => self::class,
// calculated data
'calculated' => array(
'calculated' => [
'price' => $this->price,
'basisPrice' => $this->basisPrice,
'sum' => $this->sum,
......@@ -452,7 +454,7 @@ public function toArray()
'vatArray' => $this->vatArray,
'isEuVat' => $this->isEuVat,
'isNetto' => $this->isNetto
)
);
]
];
}
}
......@@ -257,7 +257,7 @@ public function calcArticlePrice(Article $Article, $callback = false)
$isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser());
$isEuVatUser = QUI\ERP\Tax\Utils::isUserEuVatUser($this->getUser());
$nettoPrice = $Article->getUnitPrice();
$nettoPrice = $Article->getUnitPrice()->value();
$vat = $Article->getVat();
$basisNettoPrice = $nettoPrice;
$nettoSubSum = $this->round($nettoPrice * $Article->getQuantity());
......
......@@ -66,7 +66,7 @@ public function __construct($nettoPrice, QUI\ERP\Currency\Currency $Currency, $U
$this->Currency = $Currency;
$this->User = $User;
$this->discounts = array();
$this->discounts = [];
if (!QUI::getUsers()->isUser($User)) {
$this->User = QUI::getUserBySession();
......@@ -79,12 +79,12 @@ public function __construct($nettoPrice, QUI\ERP\Currency\Currency $Currency, $U
*/
public function toArray()
{
return array(
return [
'price' => $this->getNetto(),
'currency' => $this->getCurrency()->getCode(),
'display' => $this->getDisplayPrice(),
'startingprice' => $this->isStartingPrice()
);
];
}
/**
......@@ -111,6 +111,16 @@ public function getPrice()
return $price;
}
/**
* Alias for getPrice
*
* @return float
*/
public function value()
{
return $this->getPrice();
}
/**
* Return the price for the view / displaying
*
......@@ -124,7 +134,7 @@ public function getDisplayPrice()
return $this->User->getLocale()->get(
'quiqqer/erp',
'price.starting.from',
array('price' => $price)
['price' => $price]
);
}
......@@ -156,14 +166,14 @@ public function addDiscount(Discount $Discount)
}
if ($Disc->canCombinedWith($Discount) === false) {
throw new QUI\Exception(array(
throw new QUI\Exception([
'quiqqer/products',
'exception.discount.not.combinable',
array(
[
'id1' => $Disc->getId(),
'id2' => $Discount->getId()
)
));
]
]);
}
}
......
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