Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace Xentral\Modules\ScanArticle;
use Xentral\Core\DependencyInjection\ContainerInterface;
use Xentral\Modules\ScanArticle\Service\ScanArticleService;
use Xentral\Modules\ScanArticle\Wrapper\PriceWrapper;
use Xentral\Modules\ScanArticle\Wrapper\SavePositionWrapper;
final class Bootstrap
{
/**
* @return array
*/
public static function registerServices()
{
return [
'ScanArticleService' => 'onInitScanArticleService'
];
}
/**
* @param ContainerInterface $container
*
* @return ScanArticleService
*/
public static function onInitScanArticleService(ContainerInterface $container)
{
return new ScanArticleService(
$container->get('ArticleGateway'),
$container->get('Session'),
self::onInitPriceWrapper($container),
self::onInitSavePositionWrapper($container)
);
}
/**
* @param ContainerInterface $container
*
* @return PriceWrapper
*/
public static function onInitPriceWrapper(ContainerInterface $container)
{
/** @var \ApplicationCore $app */
$app = $container->get('LegacyApplication');
return new PriceWrapper(
$app->erp,
$container->get('Database')
);
}
/**
* @param ContainerInterface $container
*
* @return SavePositionWrapper
*/
public static function onInitSavePositionWrapper(ContainerInterface $container)
{
/** @var \ApplicationCore $app */
$app = $container->get('LegacyApplication');
return new SavePositionWrapper(
$app->erp,
$container->get('Database')
);
}
}
@@ -0,0 +1,8 @@
<?php
namespace Xentral\Modules\ScanArticle\Exception;
use InvalidArgumentException;
class ArticleNotFoundException extends InvalidArgumentException implements ScanArticleExceptionInterface
{
}
@@ -0,0 +1,8 @@
<?php
namespace Xentral\Modules\ScanArticle\Exception;
use InvalidArgumentException as SplInvalidArgumentException;
class InvalidArgumentException extends SplInvalidArgumentException implements ScanArticleExceptionInterface
{
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\ScanArticle\Exception;
use Xentral\Core\Exception\ModuleExceptionInterface;
interface ScanArticleExceptionInterface extends ModuleExceptionInterface
{
}
@@ -0,0 +1,172 @@
<?php
namespace Xentral\Modules\ScanArticle\Service;
use Xentral\Components\Http\Session\Session;
use Xentral\Modules\Article\Gateway\ArticleGateway;
use Xentral\Components\Http\Session\SessionHandler;
use Xentral\Modules\ScanArticle\Exception\ArticleNotFoundException;
use Xentral\Modules\ScanArticle\Exception\InvalidArgumentException;
use Xentral\Modules\ScanArticle\Wrapper\PriceWrapper;
use Xentral\Modules\ScanArticle\Wrapper\SavePositionWrapper;
class ScanArticleService
{
/** @var ArticleGateway $articleGateway */
private $articleGateway;
/** @var Session $session */
private $session;
/** @var PriceWrapper $priceWrapper */
private $priceWrapper;
/** @var SavePositionWrapper $savePositionWrapper */
private $savePositionWrapper;
private $segmentPrefix = 'scan_artikel_';
private $key = 'article';
/**
* @param ArticleGateway $articleGateway
* @param Session $session
* @param PriceWrapper $priceWrapper
* @param SavePositionWrapper $savePositionWrapper
*/
public function __construct(
ArticleGateway $articleGateway,
Session $session,
PriceWrapper $priceWrapper,
SavePositionWrapper $savePositionWrapper
) {
$this->articleGateway = $articleGateway;
$this->session = $session;
$this->priceWrapper = $priceWrapper;
$this->savePositionWrapper = $savePositionWrapper;
}
/**
* @param string $modul
* @param string $number
* @param float $amount
* @param int $documentId
*/
public function writeArticleToSession($modul, $number, $amount, $documentId)
{
if ($modul === 'auftrag') {
$articleData = $this->articleGateway->findScannableArticle($number);
if(empty($articleData)) {
$articleData = $this->articleGateway->findUniqueArticleBySerial($number);
}
} elseif ($modul === 'bestellung') {
$articleData = $this->articleGateway->findScannableOrderPurchaseArticle($number,$documentId);
} else {
throw new InvalidArgumentException('modul can not be: ' . $modul);
}
if (empty($articleData)) {
throw new ArticleNotFoundException('Article with number ' . $number . ' not found.');
}
$articleId = $articleData['id'];
$articleName = $articleData['name_de'];
$price=0;
if ($modul === 'auftrag') {
$price = $this->priceWrapper->getOrderSellingPrice($articleId, $amount, $documentId);
} elseif ($modul === 'bestellung') {
try{
$price = $this->priceWrapper->getPurchaseOrderPurchasePrice($articleId, $amount, $documentId);
}
catch(InvalidArgumentException $e){
$price = 0;
}
}
$sessionArticles = $this->getAllArticleDataFromSession($modul);
$index = count($sessionArticles) + 1;
$sessionArticles[] = [
'index' => $index,
'articleId' => $articleId,
'number' => $number,
'name' => $articleName,
'amount' => $amount,
'price' => $price,
];
$this->session->setValue($this->segmentPrefix . $modul, $this->key, $sessionArticles);
SessionHandler::commitSession($this->session);
}
public function getAllArticleDataFromSession($modul)
{
$data = $this->session->getValue($this->segmentPrefix . $modul, $this->key);
if (!empty($data)) {
return $data;
}
return [];
}
/**
* @param string $modul
*/
public function clearAllArticleDataInSession($modul)
{
$this->session->setValue($this->segmentPrefix . $modul, $this->key, []);
SessionHandler::commitSession($this->session);
}
/**
* @param string $modul
* @param int $documentId
*/
public function saveSumedPositions($modul, $documentId)
{
$sessionArticlesFull = $this->getAllArticleDataFromSession($modul);
$sessionArticles = [];
$lastArticleId = 0;
foreach($sessionArticlesFull as $sa) {
if($sa['articleId'] !== $lastArticleId) {
$sessionArticles[] = $sa;
$lastArticleId = $sa['articleId'];
}
else {
$sessionArticles[count($sessionArticles) - 1]['amount'] += $sa['amount'];
}
}
if (!empty($sessionArticles)) {
foreach ($sessionArticles as $sa) {
if ($modul === 'auftrag') {
$this->savePositionWrapper->saveOrderPosition($sa['articleId'], $documentId, $sa['amount']);
} elseif ($modul === 'bestellung') {
$this->savePositionWrapper->savePurchaseOrderPosition($sa['articleId'], $documentId, $sa['amount']);
} else {
throw new InvalidArgumentException('modul can not be: ' . $modul);
}
}
$this->clearAllArticleDataInSession($modul);
}
}
/**
* @param string $modul
* @param int $documentId
*/
public function savePositions($modul, $documentId)
{
$sessionArticles = $this->getAllArticleDataFromSession($modul);
if (!empty($sessionArticles)) {
foreach ($sessionArticles as $sa) {
if ($modul === 'auftrag') {
$this->savePositionWrapper->saveOrderPosition($sa['articleId'], $documentId, $sa['amount']);
} elseif ($modul === 'bestellung') {
$this->savePositionWrapper->savePurchaseOrderPosition($sa['articleId'], $documentId, $sa['amount']);
} else {
throw new InvalidArgumentException('modul can not be: ' . $modul);
}
}
$this->clearAllArticleDataInSession($modul);
}
}
}
@@ -0,0 +1,125 @@
<?php
namespace Xentral\Modules\ScanArticle\Wrapper;
use Xentral\Components\Database\Database;
use erpAPI;
use Xentral\Modules\ScanArticle\Exception\InvalidArgumentException;
class PriceWrapper
{
/** @var erpAPI $erp */
private $erp;
/** @var Database $db */
private $db;
/**
* @param erpAPI $erp
* @param Database $database
*/
public function __construct(erpAPI $erp, Database $database)
{
$this->erp = $erp;
$this->db = $database;
}
/**
* @param int $articleId
* @param float $amount
* @param int $adressId
* @param string $currency
*
* @return int|mixed|null
*/
private function getSellingPrice(
$articleId,
$amount,
$adressId = 0,
$currency = ''
) {
$returnCurrencyRef = '';
return $this->erp->GetVerkaufspreis(
$articleId,
$amount,
$adressId,
$currency,
$returnCurrencyRef,
false,
false
);
}
/**
* @param int $articleId
* @param float $amount
* @param int $orderId
* @param string $currency
*
* @return int|mixed|null
*/
public function getOrderSellingPrice(
$articleId,
$amount,
$orderId,
$currency = ''
) {
$adressId = $this->db->fetchValue(
"SELECT `adresse` FROM `auftrag` WHERE id = :orderId",
['orderId' => $orderId]
);
return $this->getSellingPrice(
$articleId,
$amount,
$adressId,
$currency
);
}
/**
* @param int $articleId
* @param float $amount
* @param int $purchaseOrderId
*
* @return int | null
*/
private function getPurchasePriceId($articleId, $amount, $purchaseOrderId)
{
$supplierId = $this->db->fetchValue(
"SELECT `adresse` FROM `bestellung` WHERE id = :purchaseOrderId",
['purchaseOrderId' => $purchaseOrderId]
);
if (!empty($supplierId)) {
$purchasePriceId = $this->erp->Einkaufspreis($articleId, $amount, $supplierId);
if (!empty($purchasePriceId)) {
return $purchasePriceId;
}
}
return null;
}
/**
* @param int $articleId
* @param float $amount
* @param int $purchaseOrderId
*
* @return float | null
*/
public function getPurchaseOrderPurchasePrice($articleId, $amount, $purchaseOrderId)
{
$purchasePriceId = $this->getPurchasePriceId($articleId, $amount, $purchaseOrderId);
if (!empty($purchasePriceId)) {
return (float)$this->db->fetchValue(
"SELECT `preis` FROM `einkaufspreise` WHERE id = :purchasePriceId",
['purchasePriceId' => $purchasePriceId]
);
} else {
throw new InvalidArgumentException('Purchase-Order-Id can not be empty');
}
}
}
@@ -0,0 +1,51 @@
<?php
namespace Xentral\Modules\ScanArticle\Wrapper;
use erpAPI;
use Xentral\Components\Database\Database;
class SavePositionWrapper
{
/** @var erpAPI $erp */
private $erp;
/** @var Database $db */
private $db;
/**
* @param erpAPI $erp
* @param Database $database
*/
public function __construct(erpAPI $erp, Database $database)
{
$this->erp = $erp;
$this->db = $database;
}
/**
* @param int $articleId
* @param int $orderId
* @param float $amount
*/
public function saveOrderPosition($articleId, $orderId, $amount)
{
$this->erp->AddArtikelAuftrag($articleId, $orderId, $amount);
}
/**
* @param $articleId
* @param $purchaseOrderId
* @param $amount
*/
public function savePurchaseOrderPosition($articleId, $purchaseOrderId, $amount)
{
$supplierId = $this->db->fetchValue(
"SELECT `adresse` FROM `bestellung` WHERE `id` = :purchaseOrderId",
['purchaseOrderId' => $purchaseOrderId]
);
$purchasePriceId = $this->erp->Einkaufspreis($articleId, $amount, $supplierId);
$this->erp->AddBestellungPosition($purchaseOrderId, $purchasePriceId, $amount, '0000-00-00');
}
}