@@ -81,7 +81,7 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord | |||
$pk = $class::tableName() . '.' . $pk[0]; | |||
if (isset($options['attribute_id_producer']) && strlen($options['attribute_id_producer']) | |||
&& !isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest) { | |||
&& !isset($params[$options['attribute_id_producer']]) && !\Yii::$app->user->isGuest) { | |||
$params[$options['attribute_id_producer']] = GlobalParam::getCurrentProducerId(); | |||
} | |||
@@ -8,6 +8,7 @@ use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContain | |||
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | |||
use common\logic\Document\Document\DocumentContainer; | |||
use common\logic\Order\Order\OrderContainer; | |||
use common\logic\Order\Order\OrderManager; | |||
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | |||
use common\logic\Order\ProductOrder\ProductOrderContainer; | |||
use common\logic\PointSale\PointSale\PointSaleContainer; | |||
@@ -28,6 +29,8 @@ use yii\base\ErrorException; | |||
class BusinessLogic | |||
{ | |||
use BusinessLogicContainerTrait; | |||
public function getContainers() | |||
{ | |||
return [ | |||
@@ -46,6 +49,8 @@ class BusinessLogic | |||
$this->getProductOrderContainer(), | |||
$this->getProductPriceContainer(), | |||
$this->getProductSubscriptionContainer(), | |||
$this->getUserPointSaleContainer(), | |||
$this->getPointSaleContainer(), | |||
$this->getUserContainer(), | |||
$this->getSubscriptionContainer(), | |||
$this->getProductContainer(), | |||
@@ -55,116 +60,6 @@ class BusinessLogic | |||
]; | |||
} | |||
public function getUserContainer(): UserContainer | |||
{ | |||
return new UserContainer(); | |||
} | |||
public function getProducerContainer(): ProducerContainer | |||
{ | |||
return new ProducerContainer(); | |||
} | |||
public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer | |||
{ | |||
return new ProducerPriceRangeContainer(); | |||
} | |||
public function getUserProducerContainer(): UserProducerContainer | |||
{ | |||
return new UserProducerContainer(); | |||
} | |||
public function getCreditHistoryContainer(): CreditHistoryContainer | |||
{ | |||
return new CreditHistoryContainer(); | |||
} | |||
public function getDocumentContainer(): DocumentContainer | |||
{ | |||
return new DocumentContainer(); | |||
} | |||
public function getUserGroupContainer(): UserGroupContainer | |||
{ | |||
return new UserGroupContainer(); | |||
} | |||
public function getUserUserGroupContainer(): UserUserGroupContainer | |||
{ | |||
return new UserUserGroupContainer(); | |||
} | |||
public function getDistributionContainer(): DistributionContainer | |||
{ | |||
return new DistributionContainer(); | |||
} | |||
public function getTaxRateContainer(): TaxRateContainer | |||
{ | |||
return new TaxRateContainer(); | |||
} | |||
public function getOrderContainer(): OrderContainer | |||
{ | |||
return new OrderContainer(); | |||
} | |||
public function getOrderSatusHistoryContainer(): OrderStatusHistoryContainer | |||
{ | |||
return new OrderStatusHistoryContainer(); | |||
} | |||
public function getPointSaleContainer(): PointSaleContainer | |||
{ | |||
return new PointSaleContainer(); | |||
} | |||
public function getProductOrderContainer(): ProductOrderContainer | |||
{ | |||
return new ProductOrderContainer(); | |||
} | |||
public function getProductContainer(): ProductContainer | |||
{ | |||
return new ProductContainer(); | |||
} | |||
public function getProductCategoryContainer(): ProductCategoryContainer | |||
{ | |||
return new ProductCategoryContainer(); | |||
} | |||
public function getProductPointSaleContainer(): ProductPointSaleContainer | |||
{ | |||
return new ProductPointSaleContainer(); | |||
} | |||
public function getProductPriceContainer(): ProductPriceContainer | |||
{ | |||
return new ProductPriceContainer(); | |||
} | |||
public function getSubscriptionContainer(): SubscriptionContainer | |||
{ | |||
return new SubscriptionContainer(); | |||
} | |||
public function getProductSubscriptionContainer(): ProductSubscriptionContainer | |||
{ | |||
return new ProductSubscriptionContainer(); | |||
} | |||
public function getPointSaleDistributionContainer(): PointSaleDistributionContainer | |||
{ | |||
return new PointSaleDistributionContainer(); | |||
} | |||
public function getProductDistributionContainer(): ProductDistributionContainer | |||
{ | |||
return new ProductDistributionContainer(); | |||
} | |||
/* | |||
* Hiérarchie des apps | |||
*/ |
@@ -8,9 +8,11 @@ use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContain | |||
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | |||
use common\logic\Document\Document\DocumentContainer; | |||
use common\logic\Order\Order\OrderContainer; | |||
use common\logic\Order\Order\OrderManager; | |||
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | |||
use common\logic\Order\ProductOrder\ProductOrderContainer; | |||
use common\logic\PointSale\PointSale\PointSaleContainer; | |||
use common\logic\PointSale\UserPointSale\UserPointSaleContainer; | |||
use common\logic\Producer\Producer\ProducerContainer; | |||
use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer; | |||
use common\logic\Product\Product\ProductContainer; | |||
@@ -27,6 +29,11 @@ use common\logic\User\UserUserGroup\UserUserGroupContainer; | |||
trait BusinessLogicContainerTrait | |||
{ | |||
public function getOrderManager(): OrderManager | |||
{ | |||
return new OrderManager(); | |||
} | |||
public function getUserContainer(): UserContainer | |||
{ | |||
return new UserContainer(); | |||
@@ -87,6 +94,11 @@ trait BusinessLogicContainerTrait | |||
return new OrderStatusHistoryContainer(); | |||
} | |||
public function getUserPointSaleContainer(): UserPointSaleContainer | |||
{ | |||
return new UserPointSaleContainer(); | |||
} | |||
public function getPointSaleContainer(): PointSaleContainer | |||
{ | |||
return new PointSaleContainer(); |
@@ -0,0 +1,25 @@ | |||
<?php | |||
namespace common\logic; | |||
class BaseManager | |||
{ | |||
protected ContainerInterface $container; | |||
public function __call($method, $args) | |||
{ | |||
foreach($this->container->getServices() as $serviceClass) { | |||
if(method_exists($serviceClass, $method)) { | |||
return call_user_func_array( | |||
[new $serviceClass, $method], | |||
$args | |||
); | |||
} | |||
} | |||
} | |||
public function setContainer(ContainerInterface $container): void | |||
{ | |||
$this->container = $container; | |||
} | |||
} |
@@ -26,7 +26,7 @@ class DistributionRepository extends BaseService implements RepositoryInterface | |||
]; | |||
} | |||
public function getOneById($id): ?Distribution | |||
public function getOneById(int $id): ?Distribution | |||
{ | |||
return Distribution::searchOne([ | |||
'id' => $id |
@@ -3,6 +3,7 @@ | |||
namespace common\logic\Order\Order; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Price; | |||
use common\logic\BaseService; | |||
use common\logic\BuilderInterface; | |||
@@ -16,7 +17,7 @@ use common\logic\Order\ProductOrder\ProductOrderBuilder; | |||
use common\logic\Order\ProductOrder\ProductOrderSolver; | |||
use common\logic\PointSale\PointSale\PointSaleBuilder; | |||
use common\logic\PointSale\PointSale\PointSaleRepository; | |||
use common\logic\PointSale\PointSale\UserPointSaleRepository; | |||
use common\logic\PointSale\UserPointSale\UserPointSaleRepository; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\logic\Producer\Producer\ProducerRepository; | |||
use common\logic\Subscription\Subscription\Subscription; | |||
@@ -72,7 +73,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
$this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); | |||
} | |||
public function instanciate(Distribution $distribution): Order | |||
public function instanciateOrder(Distribution $distribution): Order | |||
{ | |||
$order = new Order(); | |||
$order->populateDistribution($distribution); | |||
@@ -82,13 +83,13 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
return $order; | |||
} | |||
public function create(Distribution $distribution): Order | |||
public function createOrder(Distribution $distribution): Order | |||
{ | |||
$order = $this->instanciate($distribution); | |||
$order = $this->instanciateOrder($distribution); | |||
$this->addUserPointSale($order); | |||
$this->initCommentPointSale($order); | |||
$this->generateReference($order); | |||
$this->initOrderCommentPointSale($order); | |||
$this->generateOrderReference($order); | |||
$order->save(); | |||
@@ -99,7 +100,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
* Ajoute l'abonnement' pour une date donnée. | |||
*/ | |||
// add | |||
public function createFromSubscription(Subscription $subscription, string $date, $force = false) | |||
public function createOrderFromSubscription(Subscription $subscription, string $date, $force = false) | |||
{ | |||
$now = date('Y-m-d'); | |||
$distributionDate = date('Y-m-d', strtotime($date)); | |||
@@ -111,8 +112,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
&& count($subscription->productSubscription) | |||
&& $subscription->pointSale) { | |||
$order = $this->create($distribution); | |||
$this->updateFromSubscription($order, $subscription); | |||
$order = $this->createOrder($distribution); | |||
$this->updateOrderFromSubscription($order, $subscription); | |||
} | |||
} | |||
@@ -120,7 +121,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
* Ajoute les commandes pour une date donnée à partir des abonnements. | |||
*/ | |||
// addAll | |||
public function createAllFromSubscriptions(string $date, $force = false): void | |||
// createAllFromSubscriptions | |||
public function createAllOrdersFromSubscriptions(string $date, $force = false): void | |||
{ | |||
$distribution = $this->distributionRepository->getOneByDate(date('Y-m-d', strtotime($date))); | |||
@@ -135,7 +137,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function updateIncomingDistributions(Subscription $subscription, $update = false): void | |||
// updateIncomingDistributions | |||
public function updateOrdersIncomingDistributionsFromSubscription(Subscription $subscription, $update = false): void | |||
{ | |||
$matchedDistributionsArray = $this->distributionRepository->searchMatchedIncomingDistributions($subscription); | |||
@@ -145,12 +148,12 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
if (count($matchedDistributionsArray)) { | |||
foreach ($matchedDistributionsArray as $distribution) { | |||
$this->createFromSubscription($subscription, $distribution->date); | |||
$this->createOrderFromSubscription($subscription, $distribution->date); | |||
} | |||
} | |||
} | |||
public function deleteOrdersIncomingDistributions(Subscription $subscription, $deleteAfterDateEnd = false) | |||
public function deleteOrdersIncomingDistributionsFromSubscription(Subscription $subscription, $deleteAfterDateEnd = false) | |||
{ | |||
$dateStart = $subscription->date_begin; | |||
$comparatorDateStart = '>='; | |||
@@ -238,14 +241,15 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function updateFromSubscription(Order $order, Subscription $subscription): void | |||
// updateFromSubscription | |||
public function updateOrderFromSubscription(Order $order, Subscription $subscription): void | |||
{ | |||
$this->initBaseFromSubscription($order, $subscription); | |||
$this->initAutoPaymentFromSubscription($order, $subscription); | |||
$this->initOrderBaseFromSubscription($order, $subscription); | |||
$this->initOrderAutoPaymentFromSubscription($order, $subscription); | |||
$this->addProductOrdersFromSubscription($order, $subscription); | |||
} | |||
public function initBaseFromSubscription(Order $order, Subscription $subscription): void | |||
public function initOrderBaseFromSubscription(Order $order, Subscription $subscription): void | |||
{ | |||
$order->origin = Order::ORIGIN_AUTO; | |||
$order->populatePointSale($subscription->pointSale); | |||
@@ -263,7 +267,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function initAutoPaymentFromSubscription(Order $order, Subscription $subscription): void | |||
public function initOrderAutoPaymentFromSubscription(Order $order, Subscription $subscription): void | |||
{ | |||
$pointSale = $subscription->pointSale; | |||
if($pointSale) { | |||
@@ -278,7 +282,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
$order->auto_payment = 1; | |||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | |||
$userProducer = $this->userProducerRepository->getOne($user, $distribution->producer); | |||
$userProducer = $this->userProducerRepository->getOne($order->user, $order->producer); | |||
if ($userProducer) { | |||
$order->auto_payment = $userProducer->credit_active; | |||
@@ -295,14 +299,16 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
$order->tiller_synchronization = $order->auto_payment; | |||
} | |||
public function addUserPointSale(Order $order) | |||
// addUserPointSale | |||
public function createUserPointSale(Order $order): void | |||
{ | |||
if($order->user) { | |||
$this->pointSaleBuilder->addUser($order->user, $order->pointSale); | |||
} | |||
} | |||
public function initCommentPointSale(Order $order): void | |||
// initCommentPointSale | |||
public function initOrderCommentPointSale(Order $order): void | |||
{ | |||
if($order->user && $order->pointSale) { | |||
$userPointSale = $this->userPointSaleRepository->getOne($order->user, $order->pointSale); | |||
@@ -316,10 +322,11 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
/** | |||
* Initialise le montant total, le montant déjà payé et le poids de la commande. | |||
*/ | |||
public function init(Order $order, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||
// init | |||
public function initOrder(Order $order, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||
{ | |||
$this->initAmount($order, $taxCalculationMethod); | |||
$this->initPaidAmount($order); | |||
$this->initOrderAmount($order, $taxCalculationMethod); | |||
$this->initOrderPaidAmount($order); | |||
return $this; | |||
} | |||
@@ -327,7 +334,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
/** | |||
* Initialise le montant de la commande. | |||
*/ | |||
public function initAmount(Order $order, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||
// initAmount | |||
public function initOrderAmount(Order $order, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||
{ | |||
$order->amount = 0; | |||
$order->amount_with_tax = 0; | |||
@@ -346,7 +354,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function addWeight(Order $order, ProductOrder $productOrder): void | |||
public function addProductOrderWeight(Order $order, ProductOrder $productOrder): void | |||
{ | |||
if ($productOrder->unit == 'piece') { | |||
if (isset($productOrder->product)) { | |||
@@ -357,7 +365,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function addAmount(Order $order, string $typeTotal, ProductOrder $productOrder, string $taxCalculationMethod): void | |||
public function addProductOrderAmount(Order $order, string $typeTotal, ProductOrder $productOrder, string $taxCalculationMethod): void | |||
{ | |||
$fieldNameAmount = $this->orderSolver->getFieldNameAmount($typeTotal); | |||
$fieldNameAmountWithTax = $this->orderSolver->getFieldNameAmount($typeTotal, 'with_tax'); | |||
@@ -368,10 +376,11 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
$productOrder->taxRate->value, | |||
$taxCalculationMethod | |||
) * $productOrder->quantity; | |||
$this->addVat($order, $typeTotal, $price * $productOrder->quantity, $productOrder->taxRate, $taxCalculationMethod); | |||
$this->addProductOrderVat($order, $typeTotal, $price * $productOrder->quantity, $productOrder->taxRate, $taxCalculationMethod); | |||
} | |||
public function addVat( | |||
// addVat | |||
public function addProductOrderVat( | |||
Order $order, | |||
string $typeTotal, | |||
float $priceTotalWithoutTax, | |||
@@ -380,17 +389,17 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
{ | |||
$fieldName = $this->orderSolver->getFieldNameAmount($typeTotal, 'vat'); | |||
if (!isset($this->$fieldName[$taxRate->id])) { | |||
$this->$fieldName[$taxRate->id] = 0; | |||
if (!isset($order->$fieldName[$taxRate->id])) { | |||
$order->$fieldName[$taxRate->id] = 0; | |||
} | |||
$this->$fieldName[$taxRate->id] += Price::getVat($priceTotalWithoutTax, $taxRate->value, $taxCalculationMethod); | |||
$order->$fieldName[$taxRate->id] += Price::getVat($priceTotalWithoutTax, $taxRate->value, $taxCalculationMethod); | |||
} | |||
/** | |||
* Initialise le montant payé de la commande et le retourne. | |||
*/ | |||
public function initPaidAmount(Order $order): void | |||
public function initOrderPaidAmount(Order $order): void | |||
{ | |||
if (isset($order->creditHistory)) { | |||
$history = $order->creditHistory; | |||
@@ -411,10 +420,11 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
public function delete(Order $order, $force = false) | |||
// delete | |||
public function deleteOrder(Order $order, $force = false) | |||
{ | |||
// remboursement si l'utilisateur a payé pour cette commande | |||
$amountPaid = $this->orderSolver->getAmount(Order::AMOUNT_PAID); | |||
$amountPaid = $this->orderSolver->getAmount($order, Order::AMOUNT_PAID); | |||
if ($amountPaid > 0.01) { | |||
$this->creditHistoryBuilder->create( | |||
@@ -423,6 +433,7 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
GlobalParam::getCurrentProducer(), | |||
$order->user, | |||
$this->userSolver->getCurrent(), | |||
MeanPayment::CREDIT, | |||
$order | |||
); | |||
} | |||
@@ -468,13 +479,15 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
GlobalParam::getCurrentProducer(), | |||
$order->user, | |||
$this->userSolver->getCurrent(), | |||
MeanPayment::CREDIT, | |||
$order | |||
); | |||
} | |||
} | |||
// setTillerSynchronization | |||
public function updateTillerSynchronization(Order $order) | |||
// updateTillerSynchronization | |||
public function updateOrderTillerSynchronization(Order $order) | |||
{ | |||
$paymentStatus = $order->getPaymentStatus(); | |||
@@ -492,7 +505,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
/** | |||
* Changement de statut d'une commande. | |||
*/ | |||
public function changeOrderStatus(Order $order, string $newStatus, string $origin): void | |||
// changeOrderStatus | |||
public function updateOrderStatus(Order $order, string $newStatus, string $origin): void | |||
{ | |||
$orderStatusArray = GlobalParam::get('orderStatus'); | |||
$userCurrent = $this->userSolver->getCurrent(); | |||
@@ -558,13 +572,13 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
// initReference | |||
public function generateReference(Order $order) | |||
// generateReference | |||
public function generateOrderReference(Order $order) | |||
{ | |||
$idProducer = GlobalParam::getCurrentProducerId(); | |||
$producer = $this->producerRepository->getOneById($idProducer); | |||
$producer = $order->producer; | |||
if (!$order->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) { | |||
$lastOrder = $this->orderRepository->getOneLastOfYear(); | |||
$lastOrder = $this->orderRepository->getOneLastOfYear($producer); | |||
if ($lastOrder && $lastOrder->reference && strlen($lastOrder->reference) > 0) { | |||
$pattern = '#A([0-9]+)C([0-9]+)#'; | |||
@@ -583,7 +597,8 @@ class OrderBuilder extends BaseService implements BuilderInterface | |||
} | |||
// initInvoicePrices | |||
public function updateInvoicePrices(Order $order, $params = []): void | |||
// updateInvoicePrices | |||
public function updateOrderInvoicePrices(Order $order, $params = []): void | |||
{ | |||
foreach ($order->productOrder as $productOrder) { | |||
if ($productOrder->product) { |
@@ -0,0 +1,18 @@ | |||
<?php | |||
namespace common\logic\Order\Order; | |||
use common\logic\BaseManager; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
/** | |||
* @method Order instanciateOrder(Distribution $distribution) | |||
* @method bool isStateDelivered(Order $order) | |||
*/ | |||
class OrderManager extends BaseManager | |||
{ | |||
public function __construct() | |||
{ | |||
$this->setContainer(new OrderContainer()); | |||
} | |||
} |
@@ -5,7 +5,7 @@ namespace common\logic\Order\Order; | |||
use common\logic\BaseService; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Order\ProductOrder\ProductOrder; | |||
use common\logic\PointSale\PointSale\ProductOrderRepository; | |||
use common\logic\Order\ProductOrder\ProductOrderRepository; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\logic\Producer\Producer\ProducerRepository; | |||
use common\logic\Product\Product\Product; |
@@ -12,15 +12,19 @@ use common\logic\Producer\Producer\Producer; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\SolverInterface; | |||
use common\logic\User\User\User; | |||
use common\logic\User\User\UserSolver; | |||
use yii\helpers\Html; | |||
class OrderSolver extends BaseService implements SolverInterface | |||
{ | |||
protected UserSolver $userSolver; | |||
protected DocumentSolver $documentSolver; | |||
public function __construct() | |||
{ | |||
$this->documentSolver = $this->loadService(DocumentSolver::class); | |||
$this->userSolver = $this->loadService(UserSolver::class); | |||
} | |||
public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, $typeField = ''): string | |||
@@ -39,7 +43,7 @@ class OrderSolver extends BaseService implements SolverInterface | |||
return $fieldName; | |||
} | |||
public function getTotalVat(Order $order, $typeTotal = Order::AMOUNT_TOTAL): float | |||
public function getOrderTotalVat(Order $order, $typeTotal = Order::AMOUNT_TOTAL): float | |||
{ | |||
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat'); | |||
$totalVat = 0; | |||
@@ -101,17 +105,14 @@ class OrderSolver extends BaseService implements SolverInterface | |||
/** | |||
* Retourne une chaine de caractère décrivant l'utilisateur lié à la commande. | |||
*/ | |||
public function getStrUser(Order $order): string | |||
// getStrUser | |||
public function getOrderUsername(Order $order): string | |||
{ | |||
if (isset($order->user)) { | |||
if (isset($order->user->name_legal_person) && strlen($order->user->name_legal_person)) { | |||
return Html::encode($order->user->name_legal_person); | |||
} else { | |||
$strUser = $order->user->lastname; | |||
if ($order->user->lastname && $order->user->name) { | |||
$strUser .= ' ' . $order->user->name; | |||
} | |||
return Html::encode($strUser); | |||
return Html::encode($this->userSolver->getUsername($order->user)); | |||
} | |||
} elseif (strlen($order->username)) { | |||
return Html::encode($order->username); | |||
@@ -149,22 +150,11 @@ class OrderSolver extends BaseService implements SolverInterface | |||
return $comment; | |||
} | |||
public function getUsername(Order $order): string | |||
{ | |||
$username = ''; | |||
if ($order->user) { | |||
$username = $order->user->getUsername(); | |||
} | |||
if (strlen($order->username)) { | |||
$username = $order->username; | |||
} | |||
return $username; | |||
} | |||
/** | |||
* Retourne un bloc html présentant une date. | |||
*/ | |||
public function getBlockDate(Order $order): string | |||
// getBlockDate | |||
public function getDateAsHtml(Order $order): string | |||
{ | |||
return '<div class="block-date"> | |||
<div class="day">' . strftime('%A', strtotime($order->distribution->date)) . '</div> | |||
@@ -239,7 +229,8 @@ class OrderSolver extends BaseService implements SolverInterface | |||
* Retourne une classe identifiant l'historique de la commande (ajoutée, | |||
* modifiée, supprimée). | |||
*/ | |||
public function getClassHistory(Order $order): string | |||
// getClassHistory | |||
public function getHistoryClass(Order $order): string | |||
{ | |||
if (!is_null($order->date_delete)) { | |||
return 'commande-delete'; | |||
@@ -255,7 +246,8 @@ class OrderSolver extends BaseService implements SolverInterface | |||
/** | |||
* Retourne l'historique de la commande (ajoutée, modifiée, supprimée) au format HTML. | |||
*/ | |||
public function getStrHistory(Order $order): string | |||
//getStrHistory | |||
public function getHistorySummary(Order $order): string | |||
{ | |||
$arr = [ | |||
'class' => 'create', | |||
@@ -292,7 +284,8 @@ class OrderSolver extends BaseService implements SolverInterface | |||
/** | |||
* Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML. | |||
*/ | |||
public function getStrOrigin(Order $order, $withLabel = false): string | |||
// getStrOrigin | |||
public function getLabelOrigin(Order $order, $withLabel = false): string | |||
{ | |||
$classLabel = ''; | |||
$str = ''; | |||
@@ -319,7 +312,8 @@ class OrderSolver extends BaseService implements SolverInterface | |||
/** | |||
* Retourne le montant de la commande (total, payé, restant, ou en surplus). | |||
*/ | |||
public function getAmount(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||
// getAmount | |||
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||
{ | |||
$amount = $order->amount; | |||
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | |||
@@ -329,11 +323,12 @@ class OrderSolver extends BaseService implements SolverInterface | |||
return $this->_getAmountGeneric($order, $type, $amount, $format); | |||
} | |||
public function getAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||
// getAmountWithTax | |||
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||
{ | |||
$amount = $order->amount + $this->getTotalVat($order, $type); | |||
$amount = $order->amount + $this->getOrderTotalVat($order, $type); | |||
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | |||
$amount = $order->invoice_amount + $this->getTotalVat($order, $type); | |||
$amount = $order->invoice_amount + $this->getOrderTotalVat($order, $type); | |||
} | |||
return $this->_getAmountGeneric($order, $type, $amount, $format); | |||
@@ -366,22 +361,23 @@ class OrderSolver extends BaseService implements SolverInterface | |||
} | |||
} | |||
public function isStateOpen(Order $order): bool | |||
public function isOrderStateOpen(Order $order): bool | |||
{ | |||
return Order::STATE_OPEN == $order->getState(); | |||
} | |||
public function isStatePreparation(Order $order): bool | |||
public function isOrderStatePreparation(Order $order): bool | |||
{ | |||
return Order::STATE_PREPARATION == $order->getState(); | |||
} | |||
public function isStateDelivered(Order $order): bool | |||
public function isOrderStateDelivered(Order $order): bool | |||
{ | |||
return Order::STATE_DELIVERED == $order->getState(); | |||
} | |||
public function belongsToUser(Order $order, User $user): bool | |||
// belongsToUser | |||
public function isOrderBelongsToUser(Order $order, User $user = null): bool | |||
{ | |||
return $order->id_user == $user->id; | |||
} |
@@ -3,7 +3,7 @@ | |||
namespace common\logic\Order\ProductOrder; | |||
use common\logic\ContainerInterface; | |||
use common\logic\PointSale\PointSale\ProductOrderRepository; | |||
use common\logic\Order\ProductOrder\ProductOrderRepository; | |||
class ProductOrderContainer implements ContainerInterface | |||
{ |
@@ -1,10 +1,9 @@ | |||
<?php | |||
namespace common\logic\PointSale\PointSale; | |||
namespace common\logic\Order\ProductOrder; | |||
use common\logic\BaseService; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\Order\ProductOrder\ProductOrder; | |||
use common\logic\RepositoryInterface; | |||
class ProductOrderRepository extends BaseService implements RepositoryInterface | |||
@@ -21,6 +20,6 @@ class ProductOrderRepository extends BaseService implements RepositoryInterface | |||
public function getByOrder(Order $order) | |||
{ | |||
return ProductOrder::find()->where(['id_order' => $order->id])->all() | |||
return ProductOrder::find()->where(['id_order' => $order->id])->all(); | |||
} | |||
} |
@@ -4,11 +4,9 @@ namespace common\logic\PointSale\PointSale; | |||
use common\logic\BaseService; | |||
use common\logic\BuilderInterface; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\PointSale\UserPointSale\UserPointSale; | |||
use common\logic\PointSale\UserPointSale\UserPointSaleBuilder; | |||
use common\logic\PointSale\UserPointSale\UserPointSaleRepository; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\logic\SolverInterface; | |||
use common\logic\User\User\User; | |||
use common\logic\User\User\UserRepository; | |||
@@ -3,7 +3,7 @@ | |||
namespace common\logic\PointSale\UserPointSale; | |||
use common\logic\ContainerInterface; | |||
use common\logic\PointSale\PointSale\UserPointSaleRepository; | |||
use common\logic\PointSale\UserPointSale\UserPointSaleRepository; | |||
class UserPointSaleContainer implements ContainerInterface | |||
{ |
@@ -1,9 +1,10 @@ | |||
<?php | |||
namespace common\logic\PointSale\PointSale; | |||
namespace common\logic\PointSale\UserPointSale; | |||
use common\logic\BaseService; | |||
use common\logic\BuilderInterface; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\PointSale\UserPointSale\UserPointSale; | |||
use common\logic\RepositoryInterface; | |||
use common\logic\User\User\User; |
@@ -12,12 +12,10 @@ use common\logic\User\UserProducer\UserProducerBuilder; | |||
class CreditHistoryBuilder extends BaseService implements BuilderInterface | |||
{ | |||
protected CreditHistorySolver $creditHistorySolver; | |||
protected UserProducerBuilder $userProducerBuilder; | |||
public function __construct() | |||
{ | |||
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class); | |||
$this->userProducerBuilder = $this->loadService(UserProducerBuilder::class); | |||
} | |||
public function instanciate( | |||
@@ -76,7 +74,8 @@ class CreditHistoryBuilder extends BaseService implements BuilderInterface | |||
$creditHistory->save(); | |||
// Mise à jour du crédit au niveau de UserProducer | |||
$this->userProducerBuilder->updateCredit($creditHistory); | |||
// @TODO : à gérer avec les événements | |||
//$this->userProducerBuilder->updateCredit($creditHistory); | |||
return $creditHistory; | |||
} |
@@ -126,6 +126,10 @@ class SiteController extends FrontendController | |||
*/ | |||
public function actionIndex() | |||
{ | |||
$distribution = $this->getDistributionContainer()->getRepository()->getOneById(1); | |||
$orderManager = $this->getOrderManager(); | |||
$orderManager->instanciateOrder($distribution); | |||
return $this->render('index', [ | |||
'producerDemoAccount' => $this->getLogic()->getProducerContainer() | |||
->getRepository()->getOneDemoAccount(), |
@@ -577,12 +577,13 @@ class OrderController extends ProducerBaseController | |||
/** | |||
* Page de confirmation de commande. | |||
*/ | |||
public function actionConfirm($idOrder, $returnPayment = '') | |||
public function actionConfirm(int $idOrder, string $returnPayment = '') | |||
{ | |||
$order = Order::searchOne(['id' => $idOrder]); | |||
$orderContainer = $this->getOrderContainer(); | |||
$order = $orderContainer->getRepository()->getOneById($idOrder); | |||
$producer = $this->getProducer(); | |||
if (!$order || ($order->id_user != GlobalParam::getCurrentUserId() && !$producer->option_allow_order_guest)) { | |||
if (!$order || (!$orderContainer->getSolver()->belongsToUser($order, GlobalParam::getCurrentUser()) && !$producer->option_allow_order_guest)) { | |||
throw new \yii\base\UserException('Commande introuvable.'); | |||
} | |||
@@ -599,7 +600,7 @@ class OrderController extends ProducerBaseController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$pointSaleContainer = $this->getPointSaleContainer(); | |||
$pointSale = $pointSaleContainer->getRepostory()->getOneById($idPointSale); | |||
$pointSale = $pointSaleContainer->getRepository()->getOneById($idPointSale); | |||
if ($pointSale && $pointSaleContainer->getSolver()->validateCode($pointSale, $code)) { | |||
return 1; |