Bladeren bron

Refactoring services #885

refactoring
Guillaume Bourgeois 1 jaar geleden
bovenliggende
commit
9a79f8c0ce
6 gewijzigde bestanden met toevoegingen van 74 en 39 verwijderingen
  1. +5
    -1
      common/logic/BaseManager.php
  2. +1
    -1
      common/logic/Order/Order/OrderBuilder.php
  3. +31
    -3
      common/logic/Order/Order/OrderManager.php
  4. +4
    -26
      common/logic/Order/Order/OrderRepository.php
  5. +31
    -7
      common/logic/Order/Order/OrderSolver.php
  6. +2
    -1
      frontend/controllers/SiteController.php

+ 5
- 1
common/logic/BaseManager.php Bestand weergeven

@@ -2,6 +2,8 @@

namespace common\logic;

use yii\base\ErrorException;

class BaseManager
{
protected ContainerInterface $container;
@@ -16,9 +18,11 @@ class BaseManager
);
}
}

throw new ErrorException('La méthode '.$method.' est introuvable dans les services du container '.get_class($this->container));
}

public function setContainer(ContainerInterface $container): void
protected function setContainer(ContainerInterface $container): void
{
$this->container = $container;
}

+ 1
- 1
common/logic/Order/Order/OrderBuilder.php Bestand weergeven

@@ -598,7 +598,7 @@ class OrderBuilder extends BaseService implements BuilderInterface

// initInvoicePrices
// updateInvoicePrices
public function updateOrderInvoicePrices(Order $order, $params = []): void
public function updateOrderInvoicePrices(Order $order, array $params = []): void
{
foreach ($order->productOrder as $productOrder) {
if ($productOrder->product) {

+ 31
- 3
common/logic/Order/Order/OrderManager.php Bestand weergeven

@@ -3,11 +3,39 @@
namespace common\logic\Order\Order;

use common\logic\BaseManager;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\Product\Product\Product;
use common\logic\User\User\User;

/**
* @method Order instanciateOrder(Distribution $distribution)
* @method bool isStateDelivered(Order $order)
* > Solver
* @method string getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = '')
* @method float getOrderTotalVat(Order $order, string $typeTotal = Order::AMOUNT_TOTAL)
* @method ?string getPaymentStatus(Order $order)
* @method string getPointSaleSummary(Order $order)
* @method string getOrderUsername(Order $order)
* @method bool isLinkedToValidDocument(Order $order)
* @method string getCommentReport(Order $order)
* @method string getDateAsHtml(Order $order)
* @method countProducts(Order $order): int
* @method int getProductQuantityPieces(Product $product, array $orders)
* @method int getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null)
* @method string getHistoryClass(Order $order)
* @method string getHistorySummary(Order $order)
* @method string getLabelOrigin(Order $order, bool $withLabel = false)
* @method float getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false)
* @method float getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false)
* @method bool isOrderStateOpen(Order $order)
* @method bool isOrderStatePreparation(Order $order)
* @method bool isOrderStateDelivered(Order $order)
* @method bool isOrderBelongsToUser(Order $order, User $user = null)
* @method string getDataJson(Order $order)
*
* Repository
*
* Builder
*
* Utils
*
*/
class OrderManager extends BaseManager
{

+ 4
- 26
common/logic/Order/Order/OrderRepository.php Bestand weergeven

@@ -42,7 +42,7 @@ class OrderRepository extends BaseService implements RepositoryInterface
];
}

public function getOneById(int $id)
public function findOneById(int $id)
{
return Order::searchOne(['order.id' => $id]);;
}
@@ -50,7 +50,8 @@ class OrderRepository extends BaseService implements RepositoryInterface
/**
* Recherche et initialise des commandes.
*/
public function searchBy($params = [], $options = [])
// searchBy
public function findBy($params = [], $options = [])
{
$orders = Order::searchBy($params, $options);

@@ -80,7 +81,7 @@ class OrderRepository extends BaseService implements RepositoryInterface
return false;
}

public function getByDistribution(Distribution $distribution, string $conditionAppend = '')
public function findByDistribution(Distribution $distribution, string $conditionAppend = '')
{
return Order::searchAll([
'distribution.date' => $distribution->date,
@@ -115,29 +116,6 @@ class OrderRepository extends BaseService implements RepositoryInterface
return ['incoming' => $queryIncoming, 'passed' => $queryPassed];
}

/**
* Retourne les informations relatives à la commande au format JSON.
*/
public function getDataJson(Order $order): string
{
$jsonOrder = [];
if ($order) {
$jsonOrder = [
'products' => [],
'amount' => $order->amount,
'str_amount' => $order->getAmountWithTax(Order::AMOUNT_TOTAL, true),
'paid_amount' => $order->getAmount(Order::AMOUNT_PAID),
'comment' => $order->comment,
];

foreach ($order->productOrder as $productOrder) {
$jsonOrder['products'][$productOrder->id_product] = $productOrder->quantity;
}
}

return json_encode($jsonOrder);
}

/**
* Retourne le résumé du panier au format HTML.
*/

+ 31
- 7
common/logic/Order/Order/OrderSolver.php Bestand weergeven

@@ -27,7 +27,7 @@ class OrderSolver extends BaseService implements SolverInterface
$this->userSolver = $this->loadService(UserSolver::class);
}

public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, $typeField = ''): string
public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string
{
$fieldName = 'amount';
if ($typeTotal == Order::INVOICE_AMOUNT_TOTAL) {
@@ -43,7 +43,7 @@ class OrderSolver extends BaseService implements SolverInterface
return $fieldName;
}

public function getOrderTotalVat(Order $order, $typeTotal = Order::AMOUNT_TOTAL): float
public function getOrderTotalVat(Order $order, string $typeTotal = Order::AMOUNT_TOTAL): float
{
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat');
$totalVat = 0;
@@ -166,7 +166,7 @@ class OrderSolver extends BaseService implements SolverInterface
/**
* Retourne le nombre de produits commandés.
*/
public function countProducts(Order $order)
public function countProducts(Order $order): int
{
if ($order->productOrder && is_array($order->productOrder)) {
return count($order->productOrder);
@@ -203,7 +203,7 @@ class OrderSolver extends BaseService implements SolverInterface
/**
* Retourne la quantité d'un produit donné de plusieurs commandes.
*/
public function getProductQuantity(Product $product, array $orders, $ignoreCancel = false, $unit = null): int
public function getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null): int
{
$quantity = 0;

@@ -285,7 +285,7 @@ class OrderSolver extends BaseService implements SolverInterface
* Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML.
*/
// getStrOrigin
public function getLabelOrigin(Order $order, $withLabel = false): string
public function getLabelOrigin(Order $order, bool $withLabel = false): string
{
$classLabel = '';
$str = '';
@@ -313,7 +313,7 @@ class OrderSolver extends BaseService implements SolverInterface
* Retourne le montant de la commande (total, payé, restant, ou en surplus).
*/
// getAmount
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false)
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float
{
$amount = $order->amount;
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) {
@@ -324,7 +324,7 @@ class OrderSolver extends BaseService implements SolverInterface
}

// getAmountWithTax
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false)
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float
{
$amount = $order->amount + $this->getOrderTotalVat($order, $type);
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) {
@@ -381,4 +381,28 @@ class OrderSolver extends BaseService implements SolverInterface
{
return $order->id_user == $user->id;
}

/**
* Retourne les informations relatives à la commande au format JSON.
*/
public function getDataJson(Order $order): string
{
$jsonOrder = [];
if ($order) {
$jsonOrder = [
'products' => [],
'amount' => $order->amount,
'str_amount' => $order->getAmountWithTax(Order::AMOUNT_TOTAL, true),
'paid_amount' => $order->getAmount(Order::AMOUNT_PAID),
'comment' => $order->comment,
];

foreach ($order->productOrder as $productOrder) {
$jsonOrder['products'][$productOrder->id_product] = $productOrder->quantity;
}
}

return json_encode($jsonOrder);
}

}

+ 2
- 1
frontend/controllers/SiteController.php Bestand weergeven

@@ -128,7 +128,8 @@ class SiteController extends FrontendController
{
$distribution = $this->getDistributionContainer()->getRepository()->getOneById(1);
$orderManager = $this->getOrderManager();
$orderManager->instanciateOrder($distribution);
$order = $orderManager->instanciateOrder($distribution);
$orderManager->getOrderTotalVat($order);

return $this->render('index', [
'producerDemoAccount' => $this->getLogic()->getProducerContainer()

Laden…
Annuleren
Opslaan