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
@@ -0,0 +1,45 @@
<?php
namespace Xentral\Modules\FeeReduction;
use Xentral\Core\DependencyInjection\ContainerInterface;
use Xentral\Modules\FeeReduction\Gateway\FeeReductionGateway;
use Xentral\Modules\FeeReduction\Service\FeeReductionService;
final class Bootstrap
{
/**
* @return array
*/
public static function registerServices()
{
return [
'FeeReductionService' => 'onInitFeeReductionService',
'FeeReductionGateway' => 'onInitFeeReductionGateway',
];
}
/**
* @param ContainerInterface $container
*
* @return FeeReductionService
*/
public static function onInitFeeReductionService(ContainerInterface $container)
{
return new FeeReductionService(
$container->get('Database'), $container->get('FeeReductionGateway')
);
}
/**
* @param ContainerInterface $container
*
* @return FeeReductionGateway
*/
public static function onInitFeeReductionGateway(ContainerInterface $container)
{
return new FeeReductionGateway(
$container->get('Database')
);
}
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\FeeReduction\Exception;
use Xentral\Core\Exception\ModuleExceptionInterface;
interface FeeReductionExceptionInterface extends ModuleExceptionInterface
{
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\FeeReduction\Exception;
use InvalidArgumentException as SplInvalidArgumentException;
class InvalidArgumentException extends SplInvalidArgumentException implements FeeReductionExceptionInterface
{
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\FeeReduction\Exception;
use RuntimeException as SplRuntimeException;
class RuntimeException extends SplRuntimeException implements FeeReductionExceptionInterface
{
}
@@ -0,0 +1,78 @@
<?php
namespace Xentral\Modules\FeeReduction\Gateway;
use Xentral\Components\Database\Database;
use Xentral\Modules\FeeReduction\Exception\InvalidArgumentException;
final class FeeReductionGateway
{
/** @var Database */
private $db;
/**
* FeeReductionGateway constructor.
*
* @param Database $db
*/
public function __construct(Database $db)
{
$this->db = $db;
}
/**
* @param string $doctype
* @param int $positionId
*
* @return float
*/
public function getSumByDoctypePosition($doctype, $positionId)
{
return (float)$this->db->fetchValue(
'SELECT SUM(amount * price)
FROM fee_reduction
WHERE doctype = :doctype AND position_id = :position_id',
['doctype' => (String)$doctype, 'position_id' => (int)$positionId]
);
}
/**
* @param string $doctype
* @param int $doctypeId
*
* @return float
*/
public function getSumByDoctype($doctype, $doctypeId)
{
return (float)$this->db->fetchValue(
'SELECT SUM(amount * price)
FROM fee_reduction
WHERE doctype = :doctype AND doctype_id = :doctype_id',
['doctype' => (String)$doctype, 'doctype_id' => (int)$doctypeId]
);
}
/**
* @param string $priceType
* @param int $doctype
* @param int $doctypeId
* @param int $positionId
*
* @return array
*/
public function getFeeByType($priceType, $doctype, $doctypeId, $positionId = 0) {
return $this->db->fetchRow(
'SELECT *
FROM fee_reduction
WHERE doctype = :doctype AND doctype_id = :doctype_id
AND position_id = :position_id AND price_type = :price_type',
[
'price_type' => (String)$priceType,
'doctype' => (String)$doctype,
'doctype_id' => (int)$doctypeId,
'position_id' => (int)$positionId,
]
);
}
}
@@ -0,0 +1,73 @@
<?php
namespace Xentral\Modules\FeeReduction\Service;
use Xentral\Components\Database\Database;
use Xentral\Modules\FeeReduction\Exception\InvalidArgumentException;
use Xentral\Modules\FeeReduction\Gateway\FeeReductionGateway;
final class FeeReductionService
{
/** @var Database */
private $db;
/** @var FeeReductionGateway*/
private $gateway;
/**
* FeeReductionService constructor.
*
* @param Database $db
*/
public function __construct(Database $db, FeeReductionGateway $gateway)
{
$this->db = $db;
$this->gateway = $gateway;
}
/**
* @param string $doctype
* @param int $doctypeId
* @param int $positionId
* @param string $priceType
* @param float $amount
* @param float $price
* @param string $currency
* @param string $comment
*
* @return int
*/
public function create($doctype, $doctypeId, $positionId, $priceType, $amount, $price, $currency = 'EUR', $comment = '')
{
if(empty($doctype)) {
throw new InvalidArgumentException('doctype is empty');
}
if(empty($doctypeId)) {
throw new InvalidArgumentException('doctype_id is empty');
}
if(empty($priceType)) {
throw new InvalidArgumentException('pricetype is empty');
}
if($this->gateway->getFeeByType($priceType, $doctype, $doctypeId, $positionId)) {
throw new InvalidArgumentException('pricetype allready exists');
}
$this->db->perform(
'INSERT INTO fee_reduction (doctype, doctype_id, position_id, price_type, amount, price, comment, currency)
VALUES (:doctype, :doctype_id, :position_id, :price_type, :amount, :price, :comment, :currency)',
[
'doctype' => $doctype,
'doctype_id' => empty($doctypeId)?0:(int)$doctypeId,
'position_id' => empty($positionId)?0:(int)$positionId,
'price_type' => $priceType,
'amount' => empty($amount)?1:(int)$amount,
'price' => (float)$price,
'comment' => (String)$comment,
'currency' => (String)$currency,
]
);
return (int)$this->db->lastInsertId();
}
}