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

feat: Calc, ERP Artikel und Artikel Liste, Grundklassen umgesetzt

Übergeordneter f3728fd9
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -21,6 +21,12 @@
<de><![CDATA[Kunden]]></de>
<en><![CDATA[Customer]]></en>
</locale>
<locale name="price.starting.from">
<de><![CDATA[ab [price]]]></de>
<en><![CDATA[starting from [price]]]></en>
</locale>
</groups>
</locales>
\ No newline at end of file
<?php
/**
* This file contains QUI\ERP\Accounting\Article
*/
namespace QUI\ERP\Accounting;
use QUI;
use QUI\ERP\Money\Price;
/**
* Class Article
*
* @package QUI\ERP\Accounting
*/
class Article implements ArticleInterface
{
/**
* @var array
*/
protected $attributes = array();
/**
* @var bool
*/
protected $calculated = false;
/**
* @var
*/
protected $price;
/**
* @var
*/
protected $basisPrice;
/**
* @var
*/
protected $sum;
/**
* @var
*/
protected $nettoSum;
/**
* @var
*/
protected $vatArray;
/**
* @var
*/
protected $isEuVat;
/**
* @var
*/
protected $isNetto;
/**
* Article constructor.
*
* @param array $attributes - (id, articleNo, title, description, unitPrice, quantity)
*/
public function __construct($attributes = array())
{
if (isset($attributes['id'])) {
$this->attributes['id'] = $attributes['id'];
}
if (isset($attributes['articleNo'])) {
$this->attributes['articleNo'] = $attributes['articleNo'];
}
if (isset($attributes['title'])) {
$this->attributes['title'] = $attributes['title'];
}
if (isset($attributes['description'])) {
$this->attributes['description'] = $attributes['description'];
}
if (isset($attributes['unitPrice'])) {
$this->attributes['unitPrice'] = $attributes['unitPrice'];
}
if (isset($attributes['quantity'])) {
$this->attributes['quantity'] = $attributes['quantity'];
}
if (isset($attributes['vat'])) {
$this->attributes['vat'] = $attributes['vat'];
}
if (isset($attributes['calculated'])) {
$calc = $attributes['calculated'];
$this->price = $calc['price'];
$this->basisPrice = $calc['basisPrice'];
$this->sum = $calc['sum'];
$this->nettoSum = $calc['nettoSum'];
$this->vatArray = $calc['vatArray'];
$this->isEuVat = $calc['isEuVat'];
$this->isNetto = $calc['isNetto'];
}
}
/**
* Return the Article ID
*
* @return mixed|string
*/
public function getId()
{
if (isset($this->attributes['id'])) {
return $this->attributes['id'];
}
return '';
}
/**
* Return the Article Number
*
* @return mixed|string
*/
public function getArticleNo()
{
if (isset($this->attributes['articleNo'])) {
return $this->attributes['articleNo'];
}
return '';
}
/**
* Returns the article title
*
* @return string
*/
public function getTitle()
{
if (isset($this->attributes['title'])) {
return $this->attributes['title'];
}
return '';
}
/**
* Returns the article description
*
* @return string
*/
public function getDescription()
{
if (isset($this->attributes['description'])) {
return $this->attributes['description'];
}
return '';
}
/**
* Returns the article unit price
*
* @return int|float
*/
public function getUnitPrice()
{
if (isset($this->attributes['unitPrice'])) {
return $this->attributes['unitPrice'];
}
return 0;
}
/**
* Returns the article total sum
*
* @return int|float
*/
public function getSum()
{
$this->calc();
return $this->sum;
}
/**
* @return int
*/
public function getVat()
{
if (isset($this->attributes['vat'])) {
return (int)$this->attributes['vat'];
}
if ($this->getUser()) {
return QUI\ERP\Tax\Utils::getTaxByUser($this->getUser())->getValue();
}
// return default vat
$Area = QUI\ERP\Defaults::getArea();
$TaxType = QUI\ERP\Tax\Utils::getTaxTypeByArea($Area);
$TaxEntry = QUI\ERP\Tax\Utils::getTaxEntry($TaxType, $Area);
return $TaxEntry->getValue();
}
/**
* @return null
* @todo implement
*/
public function getUser()
{
return null;
}
/**
* Returns the article quantity
*
* @return int
*/
public function getQuantity()
{
if (isset($this->attributes['quantity'])) {
return $this->attributes['quantity'];
}
return 1;
}
/**
* Return the price from the article
*
* @return Price
*/
public function getPrice()
{
$this->calc();
return new Price(
$this->sum,
QUI\ERP\Currency\Handler::getDefaultCurrency()
);
}
/**
* @param null|Calc $Calc
* @return self
*/
public function calc($Calc = null)
{
if ($this->calculated) {
return $this;
}
$self = $this;
if (!$Calc) {
$Calc = Calc::getInstance($this->getUser());
}
$Calc->calcArticlePrice($this, function ($data) use ($self) {
$self->price = $data['price'];
$self->basisPrice = $data['basisPrice'];
$self->sum = $data['sum'];
$self->nettoSum = $data['nettoSum'];
$self->vatArray = $data['vatArray'];
$self->isEuVat = $data['isEuVat'];
$self->isNetto = $data['isNetto'];
$self->calculated = true;
});
return $this;
}
/**
* Return the article as an array
*
* @return array
*/
public function toArray()
{
return array(
'title' => $this->getTitle(),
'articleNo' => $this->getArticleNo(),
'description' => $this->getDescription(),
'unitPrice' => $this->getUnitPrice(),
'quantity' => $this->getQuantity(),
'sum' => $this->getSum(),
'calculated_basisPrice' => $this->basisPrice,
'calculated_price' => $this->price,
'calculated_sum' => $this->sum,
'calculated_nettoSum' => $this->nettoSum,
'calculated_isEuVat' => $this->isEuVat,
'calculated_isNetto' => $this->isNetto,
'calculated_vatArray' => $this->vatArray
);
}
}
<?php
/**
* This file contains QUI\ERP\Accounting\ArticleInterface
*/
namespace QUI\ERP\Accounting;
use QUI;
/**
* Article
* An temporary invoice article
*
* @package QUI\ERP\Accounting\Invoice
*/
interface ArticleInterface
{
/**
* Article constructor.
*
* @param array $attributes - article attributes
* @throws \QUI\Exception
*/
public function __construct($attributes = array());
/**
* @return string
*/
public function getTitle();
/**
* @return string
*/
public function getDescription();
/**
* @return integer|float
*/
public function getUnitPrice();
/**
* @return integer|float
*/
public function getSum();
/**
* @return integer|float
*/
public function getQuantity();
/**
* @return array
*/
public function toArray();
}
<?php
/**
* This file contains QUI\ERP\Accounting\ArticleList
*/
namespace QUI\ERP\Accounting;
/**
* Class ArticleList
*
* @package QUI\ERP\Accounting
*/
class ArticleList extends ArticleListUnique
{
/**
* Add an article to the list
*
* @param Article $Article
*/
public function addArticle(Article $Article)
{
$this->articles[] = $Article;
}
/**
* Remove an article by its index position
*
* @param integer $index
*/
public function removeArticle($index)
{
if (isset($this->articles[$index])) {
unset($this->articles[$index]);
}
}
/**
* Replace an article at a specific position
*
* @param Article $Article
* @param integer $index
*/
public function replaceArticle(Article $Article, $index)
{
$this->articles[$index] = $Article;
}
/**
* Clears the list
*/
public function clear()
{
$this->articles = array();
}
/**
* Parse this ArticleList to an ArticleListUnique
*
* @return ArticleListUnique
*/
public function toUniqueList()
{
return new ArticleListUnique($this->toArray());
}
}
<?php
/**
* This file contains QUI\ERP\Accounting\ArticleList
*/
namespace QUI\ERP\Accounting;
/**
* Class ArticleListUnique
* Nicht änderbare Artikel Liste
*
* @package QUI\ERP\Accounting
*/
class ArticleListUnique
{
/**
* @var array
*/
protected $articles = array();
/**
* ArticleList constructor.
*
* @param array $attributes
*/
public function __construct($attributes = array())
{
$articles = $attributes['articles'];
foreach ($articles as $article) {
$this->articles[] = new Article($article);
}
}
/**
* Creates a list from a stored representation
*
* @param string $data
* @return ArticleListUnique
*/
public static function unserialize($data)
{
if (is_string($data)) {
$data = json_decode($data, true);
}
return new self($data);
}
/**
* Generates a storable representation of the list
*
* @return string
*/
public function serialize()
{
return json_encode($this->toArray());
}
/**
* Return the list as an array
*
* @return array
*/
public function toArray()
{
$articles = array_map(function ($Article) {
/* @var $Article Article */
return $Article->toArray();
}, $this->articles);
return array(
'articles' => $articles
);
}
/**
* Generates a storable json representation of the list
* Alias for serialize()
*
* @return string
*/
public function toJSON()
{
return $this->serialize();
}
}
......@@ -3,6 +3,7 @@
/**
* This file contains QUI\ERP\Accounting\Calc
*/
namespace QUI\ERP\Accounting;
use QUI;
......@@ -12,10 +13,42 @@
* Class Calc
* Calculations for Accounting
*
* @info Produkt Berechnungen sind zu finden unter: QUI\ERP\Products\Utils\Calc
*
* @package QUI\ERP\Accounting
*/
class Calc
{
/**
* Percentage calculation
*/
const CALCULATION_PERCENTAGE = 1; // @todo raus und in product calc lassen
/**
* Standard calculation
*/
const CALCULATION_COMPLEMENT = 2; // @todo raus und in product calc lassen
/**
* Basis calculation -> netto
*/
const CALCULATION_BASIS_NETTO = 1; // @todo raus und in product calc lassen
/**
* Basis calculation -> from current price
*/
const CALCULATION_BASIS_CURRENTPRICE = 2; // @todo raus und in product calc lassen
/**
* Basis brutto
* include all price factors (from netto calculated price)
* warning: its not brutto VAT
*
* geht vnn der netto basis aus, welche alle price faktoren schon beinhaltet
* alle felder sind in diesem price schon enthalten
*/
const CALCULATION_BASIS_BRUTTO = 3; // @todo raus und in product calc lassen
/**
* @var UserInterface
*/
......@@ -117,30 +150,195 @@ public function getCurrency()
return $this->Currency;
}
// /**
// * @param $Product
// * @return array
// */
// public function getProductPrice($Product)
// {
// if (class_exists('QUI\ERP\Products\Product\Product')
// && $Product instanceof QUI\ERP\Products\Product\Product
// ) {
// $Calc = QUI\ERP\Products\Utils\Calc::getInstance($this->getUser());
// $Price = $Calc->getProductPrice($Product->createUniqueProduct());
//
// return $Price->toArray();
// }
//
// if (class_exists('QUI\ERP\Products\Product\UniqueProduct')
// && $Product instanceof QUI\ERP\Products\Product\UniqueProduct
// ) {
// $Calc = QUI\ERP\Products\Utils\Calc::getInstance($this->getUser());
// $Price = $Calc->getProductPrice($Product);
//
// return $Price->toArray();
// }
//
// if ($Product instanceof InvoiceProduct) {
// return self::calcArticlePrice($Product)->toArray();
// }
//
// }
/**
* @param $Product
* @return array
* Calculate the price of an article
*
* @param Article $Article
* @param bool|callable $callback
* @return mixed
*/
public function getProductPrice($Product)
public function calcArticlePrice(Article $Article, $callback = false)
{
if (class_exists('QUI\ERP\Products\Product\Product')
&& $Product instanceof QUI\ERP\Products\Product\Product
) {
$Calc = QUI\ERP\Products\Utils\Calc::getInstance($this->getUser());
$Price = $Calc->getProductPrice($Product->createUniqueProduct());
// calc data
if (!is_callable($callback)) {
$Article->calc($this);
return $Price->toArray();
return $Article->getPrice();
}
if (class_exists('QUI\ERP\Products\Product\UniqueProduct')
&& $Product instanceof QUI\ERP\Products\Product\UniqueProduct
) {
$Calc = QUI\ERP\Products\Utils\Calc::getInstance($this->getUser());
$Price = $Calc->getProductPrice($Product);
$isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser());
$isEuVatUser = QUI\ERP\Tax\Utils::isUserEuVatUser($this->getUser());
$nettoPrice = $Article->getUnitPrice();
$vat = $Article->getVat();
$basisNettoPrice = $nettoPrice;
$vatSum = $nettoPrice * ($vat / 100);
$bruttoPrice = $this->round($nettoPrice + $vatSum);
// sum
$nettoSum = $this->round($nettoPrice * $Article->getQuantity());
$vatSum = $nettoSum * ($vat / 100);
$bruttoSum = $this->round($nettoSum + $vatSum);
$price = $isNetto ? $nettoPrice : $bruttoPrice;
$sum = $isNetto ? $nettoSum : $bruttoSum;
$basisPrice = $isNetto ? $basisNettoPrice : $basisNettoPrice + ($basisNettoPrice * $vat / 100);
$vatArray = array(
'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'
);
QUI\ERP\Debug::getInstance()->log(array(
'basisPrice' => $basisPrice,
'price' => $price,
'sum' => $sum,
'nettoSum' => $nettoSum,
'vatArray' => $vatArray,
'isEuVat' => $isEuVatUser,
'isNetto' => $isNetto,
'currencyData' => $this->getCurrency()->toArray()
), 'quiqqer/erp');
$callback(array(
'basisPrice' => $basisPrice,
'price' => $price,
'sum' => $sum,
'nettoSum' => $nettoSum,
'vatArray' => $vatArray,
'vatText' => $vatArray['text'],
'isEuVat' => $isEuVatUser,
'isNetto' => $isNetto,
'currencyData' => $this->getCurrency()->toArray()
));
return $Article->getPrice();
}
/**
* Rounds the value via shop config
*
* @param string $value
* @return float|mixed
*/
public function round($value)
{
$decimalSeparator = $this->getUser()->getLocale()->getDecimalSeparator();
$groupingSeparator = $this->getUser()->getLocale()->getGroupingSeparator();
$precision = 8; // nachkommstelle beim runden -> @todo in die conf?
if (strpos($value, $decimalSeparator) && $decimalSeparator != ' . ') {
$value = str_replace($groupingSeparator, '', $value);
}
$value = str_replace(',', ' . ', $value);
$value = round($value, $precision);
return $value;
}
/**
* Return the tax message for an user
*
* @return string
*/
public function getVatTextByUser()
{
$Tax = QUI\ERP\Tax\Utils::getTaxByUser($this->getUser());
return $this->getVatText($Tax->getValue(), $this->getUser());
}
/**
* Return tax text
* eq: incl or zzgl
*
* @param integer $vat
* @param UserInterface $User
* @return array|string
*/
public static function getVatText($vat, UserInterface $User)
{
$Locale = $User->getLocale();
if (QUI\ERP\Utils\User::isNettoUser($User)) {
if (QUI\ERP\Tax\Utils::isUserEuVatUser($User)) {
return $Locale->get(
'quiqqer/tax',
'message.vat.text.netto.EUVAT',
array('vat' => $vat)
);
}
// vat ist leer und kein EU vat user
if (!$vat) {
return '';
}
return $Locale->get(
'quiqqer/tax',
'message.vat.text.netto',
array('vat' => $vat)
);
}
if (QUI\ERP\Tax\Utils::isUserEuVatUser($User)) {
return $Locale->get(
'quiqqer/tax',
'message.vat.text.brutto.EUVAT',
array('vat' => $vat)
);
}
return $Price->toArray();
// vat ist leer und kein EU vat user
if (!$vat) {
return '';
}
return array();
return $Locale->get(
'quiqqer/tax',
'message.vat.text.brutto',
array('vat' => $vat)
);
}
}
<?php
/**
* This file contains QUI\ERP\Defaults
*/
namespace QUI\ERP;
use QUI;
/**
* Class Defaults
*
* @package QUI\ERP
*/
class Defaults
{
/**
* Return the default area for the ERP system
*
* @return QUI\ERP\Areas\Area
* @throws QUI\Exception
*/
public static function getArea()
{
$Areas = new QUI\ERP\Areas\Handler();
$Package = QUI::getPackage('quiqqer/tax');
$Config = $Package->getConfig();
$standardArea = $Config->getValue('shop', 'area');
$Area = $Areas->getChild($standardArea);
/* @var $Area QUI\ERP\Areas\Area */
return $Area;
}
}
\ No newline at end of file
<?php
/**
* This file contains QUI\ERP\Exception
*/
namespace QUI\ERP;
use QUI;
/**
* Class Exception
* @package QUI\ERP
*/
class Exception extends QUI\Exception
{
}
<?php
/**
* This file contains QUI\ERP\Money\Price
*/
namespace QUI\ERP\Money;
use QUI;
use QUI\ERP\Discount\Discount;
/**
* Class Price
* @package QUI\ERP\Products\Price
*/
class Price
{
/**
* Netto Price
* @var float
*/
protected $netto;
/**
* Price currency
* @var QUI\ERP\Currency\Currency
*/
protected $Currency;
/**
* @var bool
*/
protected $startingPrice = false;
/**
* @var array
*/
protected $discounts;
/**
* User
* @var bool|QUI\Users\User
*/
protected $User;
/**
* @var string
*/
protected $decimalSeparator = ',';
/**
* @var string
*/
protected $thousandsSeparator = '.';
/**
* Price constructor.
*
* @param float|int|double|string $nettoPrice
* @param QUI\ERP\Currency\Currency $Currency
* @param QUI\Users\User|boolean $User - optional, if no user, session user are used
*/
public function __construct($nettoPrice, QUI\ERP\Currency\Currency $Currency, $User = false)
{
$this->netto = $nettoPrice;
$this->Currency = $Currency;
$this->User = $User;
$this->discounts = array();
if (!QUI::getUsers()->isUser($User)) {
$this->User = QUI::getUserBySession();
}
}
/**
* Return the price as array notation
* @return array
*/
public function toArray()
{
return array(
'price' => $this->getNetto(),
'currency' => $this->getCurrency()->getCode(),
'display' => $this->getDisplayPrice(),
'startingprice' => $this->isStartingPrice()
);
}
/**
* Return the netto price
*
* @return float
*/
public function getNetto()
{
return $this->validatePrice($this->netto);
}
/**
* Return the real price, brutto or netto
*
* @return float
* @todo must be implemented
*/
public function getPrice()
{
$netto = $this->getNetto();
$price = $this->validatePrice($netto);
return $price;
}
/**
* Return the price for the view / displaying
*
* @return string
*/
public function getDisplayPrice()
{
$price = $this->Currency->format($this->getPrice());
if ($this->isStartingPrice()) {
return $this->User->getLocale()->get(
'quiqqer/erp',
'price.starting.from',
array('price' => $price)
);
}
return $price;
}
/**
* Change the price to a starting price
* The price display is like (ab 30€, start at 30$)
*/
public function changeToStartingPrice()
{
$this->startingPrice = true;
}
/**
* Add a discount to the price
*
* @param QUI\ERP\Discount\Discount $Discount
* @throws QUI\Exception
*/
public function addDiscount(Discount $Discount)
{
/* @var $Disc Discount */
foreach ($this->discounts as $Disc) {
// der gleiche discount kann nur einmal enthalten sein
if ($Disc->getId() == $Discount->getId()) {
return;
}
if ($Disc->canCombinedWith($Discount) === false) {
throw new QUI\Exception(array(
'quiqqer/products',
'exception.discount.not.combinable',
array(
'id1' => $Disc->getId(),
'id2' => $Discount->getId()
)
));
}
}
$this->discounts[] = $Discount;
}
/**
* Return the assigned discounts
*
* @return array [Discount, Discount, Discount]
*/
public function getDiscounts()
{
return $this->discounts;
}
/**
* Return the currency from the price
*
* @return QUI\ERP\Currency\Currency
*/
public function getCurrency()
{
return $this->Currency;
}
/**
* @return bool
*/
public function isStartingPrice()
{
return $this->startingPrice;
}
/**
* calculation
*/
/**
* Validates a price value
*
* @param number|string $value
* @return float|double|int|null
*/
protected function validatePrice($value)
{
if (is_float($value)) {
return round($value, 4);
}
$value = (string)$value;
$value = preg_replace('#[^\d,.]#i', '', $value);
if (trim($value) === '') {
return null;
}
$decimal = mb_strpos($value, $this->decimalSeparator);
$thousands = mb_strpos($value, $this->thousandsSeparator);
if ($thousands === false && $decimal === false) {
return round(floatval($value), 4);
}
if ($thousands !== false && $decimal === false) {
if (mb_substr($value, -4, 1) === $this->thousandsSeparator) {
$value = str_replace($this->thousandsSeparator, '', $value);
}
}
if ($thousands === false && $decimal !== false) {
$value = str_replace(
$this->decimalSeparator,
'.',
$value
);
}
if ($thousands !== false && $decimal !== false) {
$value = str_replace($this->thousandsSeparator, '', $value);
$value = str_replace($this->decimalSeparator, '.', $value);
}
return round(floatval($value), 4);
}
}
......@@ -3,6 +3,7 @@
/**
* This file contains QUI\ERP\Packages\Installer
*/
namespace QUI\ERP\Packages;
use QUI;
......@@ -45,7 +46,10 @@ class Installer extends QUI\Utils\Singleton
'quiqqer/order' => array(
'server' => array(
'git@dev.quiqqer.com:quiqqer/order.git'
'git@dev.quiqqer.com:quiqqer/order.git',
'git@dev.quiqqer.com:quiqqer/products.git',
'git@dev.quiqqer.com:quiqqer/areas.git',
'git@dev.quiqqer.com:quiqqer/discount.git'
)
),
......
<?php
/**
* This file contains QUI\ERP\User
*/
namespace QUI\ERP;
use QUI;
use QUI\Interfaces\Users\User as UserInterface;
/**
* Class User
* ERP User, an user object compatible to the QUIQQER User Interface
*
* @package QUI\ERP
*/
class User extends QUI\QDOM implements UserInterface
{
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $firstName;
/**
* @var string
*/
protected $lastName;
/**
* @var string
*/
protected $lang;
/**
* @var string
*/
protected $country;
/**
* @var bool
*/
protected $isCompany;
/**
* @var array
*/
protected $data = array();
/**
* Address data
*
* @var array
*/
protected $address = array();
/**
* User constructor.
*
* @param array $attributes
* @throws QUI\ERP\Exception
*/
public function __construct(array $attributes)
{
$needle = array(
'id',
'country',
'username',
'firstname',
'lastname',
'lang',
'isCompany'
);
foreach ($needle as $attribute) {
if (!isset($attributes[$attribute])) {
throw new QUI\ERP\Exception(
'Missing attribute:' . $attribute
);
}
}
$this->id = (int)$attributes['id'];
$this->isCompany = (bool)$attributes['isCompany'];
$this->lang = $attributes['lang'];
$this->username = $attributes['username'];
$this->firstName = $attributes['firstname'];
$this->lastName = $attributes['lastname'];
$this->country = $attributes['country'];
if (isset($attributes['data']) && is_array($attributes['data'])) {
$this->data = $attributes['data'];
}
if (isset($attributes['address']) && is_array($attributes['address'])) {
$this->address = $attributes['address'];
}
}
/**
* Convert a User to an ERP user
*
* @param QUI\Users\User $User
* @return self
*/
public static function convertUserToErpUser(QUI\Users\User $User)
{
$Country = $User->getCountry();
$country = '';
if ($Country) {
$country = $Country->getCode();
}
return new self(array(
'id' => $User->getId(),
'country' => $country,
'username' => $User->getUsername(),
'firstname' => $User->getAttribute('firstname'),
'lastname' => $User->getAttribute('lastname'),
'lang' => $User->getLang(),
'isCompany' => $User->isCompany(),
'data' => $User->getAttributes()
));
}
/**
* Convert user data to an ERP user
*
* @param array $user {{$user.uid, $user.aid}}
* @return self
*
* @throws QUI\ERP\Exception
*/
public static function convertUserDataToErpUser($user)
{
if (!isset($user['uid'])) {
throw new QUI\ERP\Exception('Need uid param');
}
if (!isset($user['aid'])) {
throw new QUI\ERP\Exception('Need aid param');
}
try {
$User = QUI::getUsers()->get($user['uid']);
$Address = $User->getAddress($user['aid']);
} catch (QUI\Exception $Exception) {
throw new QUI\ERP\Exception(
$Exception->getMessage(),
$Exception->getCode()
);
}
$ERPUser = self::convertUserToErpUser($User);
$ERPUser->setAddress($Address);
return $ERPUser;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->firstName . ' ' . $this->lastName;
}
/**
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* @return string
*/
public function getLang()
{
return $this->lang;
}
/**
* @return mixed
*/
public function getLocale()
{
$Locale = new QUI\Locale();
$Locale->setCurrent($this->getLang());
return $Locale;
}
/**
* @return mixed
*/
public function getType()
{
return get_class($this);
}
/**
* @return mixed
*/
public function getStatus()
{
return 0;
}
/**
* Return the current address data
*
* @param int $id - only for the interface, has no effect
* @return array
*/
public function getAddress($id = 0)
{
return $this->address;
}
/**
* @param QUI\Users\Address $Address
*/
public function setAddress(QUI\Users\Address $Address)
{
$this->address = json_decode($Address->toJSON(), true);
}
/**
* @return mixed
* @throws QUI\Exception
*/
public function getCountry()
{
return QUI\Countries\Manager::get($this->country);
}
/**
* @return bool
*/
public function isCompany()
{
return $this->isCompany;
}
/**
* @return mixed
*/
public function isSU()
{
return false;
}
/**
* @param int $groupId
* @return mixed
*/
public function isInGroup($groupId)
{
return false;
}
/**
* @return mixed
*/
public function canUseBackend()
{
return false;
}
/**
* Does nothing
*/
public function logout()
{
}
/**
* @param string $code
* @return mixed
*/
public function activate($code)
{
return true;
}
/**
* @return mixed
*/
public function deactivate()
{
return true;
}
/**
* @param bool|\QUI\Users\User $ParentUser
* @return mixed
*/
public function disable($ParentUser = false)
{
return true;
}
/**
* Does nothing
* @param bool|\QUI\Users\User $ParentUser
*/
public function save($ParentUser = false)
{
}
/**
* @return mixed
*/
public function delete()
{
return false;
}
/**
* This user has nowhere permissions
*
* @param string $right
* @param array|bool $ruleset
* @return bool
*/
public function getPermission($right, $ruleset = false)
{
return false;
}
/**
* @return array
*/
public function getStandardAddress()
{
return $this->getAddress();
}
/**
* Does nothing
* @param array|string $groups
*/
public function setGroups($groups)
{
}
/**
* @param bool $array
* @return array
*/
public function getGroups($array = true)
{
return array();
}
/**
* This user has no avatar, it returned the default placeholder image
*
* @return QUI\Projects\Media\Image|false
*/
public function getAvatar()
{
return QUI::getProjectManager()
->getStandard()
->getMedia()
->getPlaceholderImage();
}
/**
* Does nothing
* @param string $new
* @param bool|\QUI\Users\User $ParentUser
*/
public function setPassword($new, $ParentUser = false)
{
}
/**
* Does nothing
* @param string $pass
* @param bool $encrypted
*/
public function checkPassword($pass, $encrypted = false)
{
}
/**
* @return bool
*/
public function isDeleted()
{
return false;
}
/**
* @return bool
*/
public function isActive()
{
return true;
}
/**
* @return bool
*/
public function isOnline()
{
return false;
}
/**
* Does nothing
* @param bool $status
*/
public function setCompanyStatus($status)
{
}
/**
* Does nothing
* @param int $groupId
*/
public function addToGroup($groupId)
{
}
/**
* Does nothing
* @param int|\QUI\Groups\Group $Group
*/
public function removeGroup($Group)
{
}
/**
* Does nothing
*/
public function refresh()
{
}
}
<?php
/**
* This file contains QUI\ERP\Utils\User
*/
namespace QUI\ERP\Utils;
use QUI;
use QUI\Interfaces\Users\User as UserInterface;
/**
* Class User Utils
*
* @package QUI\ERP\Utils
* @author www.pcsg.de (Henning Leutz)
*/
class User
{
/**
* netto flag
*/
const IS_NETTO_USER = 1;
/**
* brutto flag
*/
const IS_BRUTTO_USER = 2;
/**
* Return the brutto netto status
* is the user a netto or brutto user
*
* @param UserInterface $User
* @return bool
*/
public static function getBruttoNettoUserStatus(UserInterface $User)
{
if (QUI::getUsers()->isSystemUser($User)) {
return self::IS_NETTO_USER;
}
$nettoStatus = $User->getAttribute('quiqqer.erp.isNettoUser');
if (is_numeric($nettoStatus)) {
$nettoStatus = (int)$nettoStatus;
}
switch ($nettoStatus) {
case self::IS_NETTO_USER:
case self::IS_BRUTTO_USER:
return $nettoStatus;
}
if ($User->getAttribute('quiqqer.erp.euVatId')
|| $User->getAttribute('quiqqer.erp.taxNumber')
) {
return self::IS_NETTO_USER;
}
$Package = QUI::getPackage('quiqqer/tax');
$Config = $Package->getConfig();
try {
$Address = self::getUserERPAddress($User);
if (is_object($Address)
&& $Address
&& $Address->getAttribute('company')
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
}
return self::IS_NETTO_USER;
}
if (is_array($Address)
&& isset($Address['company'])
&& $Address['company'] == 1
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
}
return self::IS_NETTO_USER;
}
} catch (QUI\Exception $Exception) {
// no address found
}
$isNetto = $Config->getValue('shop', 'isNetto');
if ($isNetto) {
return self::IS_NETTO_USER;
}
try {
$Tax = QUI\ERP\Tax\Utils::getTaxByUser($User);
if ($Tax->getValue() == 0) {
return self::IS_NETTO_USER;
}
} catch (QUI\Exception $Exception) {
return self::IS_NETTO_USER;
}
return self::IS_BRUTTO_USER;
}
/**
* Is the user a netto user?
*
* @param UserInterface $User
* @return bool
*/
public static function isNettoUser(UserInterface $User)
{
return self::getBruttoNettoUserStatus($User) === self::IS_NETTO_USER;
}
/**
* Return the area of the user
* if user is in no area, the default one of the shop would be used
*
* @param UserInterface $User
* @return bool|QUI\ERP\Areas\Area
*/
public static function getUserArea(UserInterface $User)
{
$Country = $User->getCountry();
$Area = QUI\ERP\Areas\Utils::getAreaByCountry($Country);
if ($Area) {
return $Area;
}
return QUI\ERP\Defaults::getArea();
}
/**
* Return the user ERP address (Rechnungsaddresse, Accounting Address)
*
* @param UserInterface $User
* @return false|QUI\Users\Address
* @throws QUI\Exception
*/
public static function getUserERPAddress(UserInterface $User)
{
if (!QUI::getUsers()->isUser($User)) {
throw new QUI\Exception(array(
'quiqqer/erp',
'exception.no.user'
));
}
/* @var $User QUI\Users\User */
if (!$User->getAttribute('quiqqer.erp.address')) {
return $User->getStandardAddress();
}
$erpAddress = $User->getAttribute('quiqqer.erp.address');
try {
return $User->getAddress($erpAddress);
} catch (QUI\Exception $Exception) {
}
return $User->getStandardAddress();
}
/**
* Return the area of the shop
*
* @return QUI\ERP\Areas\Area
* @throws QUI\Exception
* @deprecated use QUI\ERP\Defaults::getShopArea()
*/
public static function getShopArea()
{
return QUI\ERP\Defaults::getArea();
}
}
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