Browse Source

Paramètre producer non défini (Product::afterFind()) #1254

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
e6a4e114d6
10 changed files with 39 additions and 65 deletions
  1. +3
    -2
      backend/controllers/CronController.php
  2. +5
    -2
      common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php
  3. +6
    -6
      common/logic/Document/Document/Service/DocumentBuilder.php
  4. +1
    -4
      common/logic/Document/Document/Service/DocumentUtils.php
  5. +8
    -20
      common/logic/Order/Order/Repository/OrderRepository.php
  6. +7
    -4
      common/logic/Order/Order/Service/OrderBuilder.php
  7. +4
    -4
      common/logic/Payment/Service/PaymentUtils.php
  8. +0
    -21
      common/logic/Producer/Producer/Repository/ProducerRepository.php
  9. +1
    -1
      common/logic/Product/Product/Model/Product.php
  10. +4
    -1
      common/logic/User/UserProducer/Service/UserProducerBuilder.php

+ 3
- 2
backend/controllers/CronController.php View File



namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam;
use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
'conditions' => 'date_delete IS NULL' 'conditions' => 'date_delete IS NULL'
]); ]);


$configCredit = $producerManager->getConfig('credit', $producer->id);
$configCredit = $producerManager->getConfig('credit');


if ($arrayOrders && is_array($arrayOrders)) { if ($arrayOrders && is_array($arrayOrders)) {
foreach ($arrayOrders as $order) { foreach ($arrayOrders as $order) {
* Envoi des commandes par email au producteur * Envoi des commandes par email au producteur
*/ */


if (!strlen($forceDate) && $producerManager->getConfig('option_notify_producer_order_summary', $producer->id)) {
if (!strlen($forceDate) && $producerManager->getConfig('option_notify_producer_order_summary')) {
$arrayOrders = Order::searchAll([ $arrayOrders = Order::searchAll([
'distribution.date' => $date, 'distribution.date' => $date,
'distribution.id_producer' => $producer->id 'distribution.id_producer' => $producer->id

+ 5
- 2
common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php View File

use common\logic\Order\Order\Service\OrderSolver; use common\logic\Order\Order\Service\OrderSolver;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\Producer\Producer\Repository\ProducerRepository; use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Repository\ProductRepository; use common\logic\Product\Product\Repository\ProductRepository;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;
protected OrderSolver $orderSolver; protected OrderSolver $orderSolver;
protected PointSaleRepository $pointSaleRepository; protected PointSaleRepository $pointSaleRepository;
protected OrderBuilder $orderBuilder; protected OrderBuilder $orderBuilder;
protected ProducerSolver $producerSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class); $this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
$this->orderBuilder = $this->loadService(OrderBuilder::class); $this->orderBuilder = $this->loadService(OrderBuilder::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function generateDistributionReportCsv(Distribution $distribution) public function generateDistributionReportCsv(Distribution $distribution)
$datas = []; $datas = [];
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);
$productsArray = $this->productRepository->findProductsByDistribution($distribution); $productsArray = $this->productRepository->findProductsByDistribution($distribution);
$optionCsvExportAllProducts = $this->producerRepository->getConfig('option_csv_export_all_products');
$optionCsvExportByPiece = $this->producerRepository->getConfig('option_csv_export_by_piece');
$optionCsvExportAllProducts = $this->producerSolver->getConfig('option_csv_export_all_products');
$optionCsvExportByPiece = $this->producerSolver->getConfig('option_csv_export_by_piece');
$pointsSaleArray = $this->pointSaleRepository->findPointSales(); $pointsSaleArray = $this->pointSaleRepository->findPointSales();
foreach ($pointsSaleArray as $pointSale) { foreach ($pointsSaleArray as $pointSale) {
$this->orderBuilder->initPointSaleOrders($pointSale, $ordersArray); $this->orderBuilder->initPointSaleOrders($pointSale, $ordersArray);

+ 6
- 6
common/logic/Document/Document/Service/DocumentBuilder.php View File

use common\logic\Document\Document\Model\Document; use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Model\DocumentInterface; use common\logic\Document\Document\Model\DocumentInterface;
use common\logic\Document\Document\Repository\DocumentRepository; use common\logic\Document\Document\Repository\DocumentRepository;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver;


class DocumentBuilder extends AbstractBuilder class DocumentBuilder extends AbstractBuilder
{ {
protected DocumentSolver $documentSolver; protected DocumentSolver $documentSolver;
protected DocumentRepository $documentRepository; protected DocumentRepository $documentRepository;
protected ProducerRepository $producerRepository;
protected ProducerSolver $producerSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->documentSolver = $this->loadService(DocumentSolver::class); $this->documentSolver = $this->loadService(DocumentSolver::class);
$this->documentRepository = $this->loadService(DocumentRepository::class); $this->documentRepository = $this->loadService(DocumentRepository::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function initDocumentProducer(Document $document): void public function initDocumentProducer(Document $document): void
$classLower = 'delivery_note'; $classLower = 'delivery_note';
} }


$prefix = $this->producerRepository->getConfig('document_' . $classLower . '_prefix');
$prefix = $this->producerSolver->getConfig('document_' . $classLower . '_prefix');
$oneDocumentExist = $classComplete::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']); $oneDocumentExist = $classComplete::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']);


if ($oneDocumentExist) { if ($oneDocumentExist) {


$reference = $prefix . $numReference; $reference = $prefix . $numReference;
} else { } else {
$firstReference = $this->producerRepository->getConfig('document_' . $classLower . '_first_reference');
$firstReference = $this->producerSolver->getConfig('document_' . $classLower . '_first_reference');


if (strlen($firstReference) > 0) { if (strlen($firstReference) > 0) {
$reference = $firstReference; $reference = $firstReference;


public function initTaxCalculationMethod(DocumentInterface $document): void public function initTaxCalculationMethod(DocumentInterface $document): void
{ {
$producerTaxCalculationMethod = $this->producerRepository->getConfig('option_tax_calculation_method');
$producerTaxCalculationMethod = $this->producerSolver->getConfig('option_tax_calculation_method');


if ($producerTaxCalculationMethod) { if ($producerTaxCalculationMethod) {
$document->tax_calculation_method = $producerTaxCalculationMethod; $document->tax_calculation_method = $producerTaxCalculationMethod;

+ 1
- 4
common/logic/Document/Document/Service/DocumentUtils.php View File

use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Document\Document\Model\DocumentInterface; use common\logic\Document\Document\Model\DocumentInterface;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\UtilsInterface; use common\logic\UtilsInterface;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
protected DocumentSolver $documentSolver; protected DocumentSolver $documentSolver;
protected DocumentBuilder $documentBuilder; protected DocumentBuilder $documentBuilder;
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected ProducerRepository $producerRepository;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->documentSolver = $this->loadService(DocumentSolver::class); $this->documentSolver = $this->loadService(DocumentSolver::class);
$this->documentBuilder = $this->loadService(DocumentBuilder::class); $this->documentBuilder = $this->loadService(DocumentBuilder::class);
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
} }


public function generatePdf(DocumentInterface $document, string $destination): ?string public function generatePdf(DocumentInterface $document, string $destination): ?string
$contentFooter .= '</div>'; $contentFooter .= '</div>';


$marginBottom = 10; $marginBottom = 10;
if (strlen($this->producerRepository->getConfig('document_infos_bottom')) > 0) {
if (strlen($this->producerSolver->getConfig('document_infos_bottom')) > 0) {
$marginBottom = 40; $marginBottom = 40;
} }



+ 8
- 20
common/logic/Order/Order/Repository/OrderRepository.php View File

public function getAmountSummary(Order $order): string public function getAmountSummary(Order $order): string
{ {
$html = ''; $html = '';
$creditActive = $this->producerRepository->getConfig('credit');
$creditActive = $this->producerSolver->getConfig('credit');
$html .= $this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true); $html .= $this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true);


if ($creditActive) { if ($creditActive) {
$todayHour = date('G'); $todayHour = date('G');
$dayDistribution = strtolower(date('l', strtotime($order->distribution->date))); $dayDistribution = strtolower(date('l', strtotime($order->distribution->date)));


$orderDelay = $this->producerRepository->getConfig(
'order_delay',
$order->distribution->id_producer
);
$orderDelaySpecific = $this->producerRepository->getConfig(
'order_delay_' . $dayDistribution,
$order->distribution->id_producer
);
$orderDelay = $this->producerSolver->getConfig('order_delay');
$orderDelaySpecific = $this->producerSolver->getConfig('order_delay_' . $dayDistribution,);
if ($orderDelaySpecific) { if ($orderDelaySpecific) {
$orderDelay = $orderDelaySpecific; $orderDelay = $orderDelaySpecific;
} }


$orderDeadline = $this->producerRepository->getConfig(
'order_deadline',
$order->distribution->id_producer
);
$orderDeadlineSpecific = $this->producerRepository->getConfig(
'order_deadline_' . $dayDistribution,
$order->distribution->id_producer
);
$orderDeadline = $this->producerSolver->getConfig('order_deadline',);
$orderDeadlineSpecific = $this->producerSolver->getConfig('order_deadline_' . $dayDistribution,);
if ($orderDeadlineSpecific) { if ($orderDeadlineSpecific) {
$orderDeadline = $orderDeadlineSpecific; $orderDeadline = $orderDeadlineSpecific;
} }
if($pointSale) { if($pointSale) {
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); $creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale);


if ($order->id_user && $this->producerRepository->getConfig('credit') && $pointSale->credit) {
if ($order->id_user && $this->producerSolver->getConfig('credit') && $pointSale->credit) {
if($order->mean_payment == MeanPayment::CREDIT || $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { if($order->mean_payment == MeanPayment::CREDIT || $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
return true; return true;
} }


public function isCreditContext(Order $order) public function isCreditContext(Order $order)
{ {
if(!$this->producerRepository->getConfig('credit')) {
if(!$this->producerSolver->getConfig('credit')) {
return false; return false;
} }




if($pointSale) { if($pointSale) {
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); $creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale);
if ($order->id_user && $this->producerRepository->getConfig('credit') && $pointSale->credit) {
if ($order->id_user && $this->producerSolver->getConfig('credit') && $pointSale->credit) {
if($order->mean_payment == MeanPayment::CREDIT if($order->mean_payment == MeanPayment::CREDIT
|| $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY || $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY
|| $creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { || $creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {

+ 7
- 4
common/logic/Order/Order/Service/OrderBuilder.php View File

use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository; use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Service\SubscriptionBuilder; use common\logic\Subscription\Subscription\Service\SubscriptionBuilder;
protected UserRepository $userRepository; protected UserRepository $userRepository;
protected DeliveryNoteBuilder $deliveryNoteBuilder; protected DeliveryNoteBuilder $deliveryNoteBuilder;
protected DocumentSolver $documentSolver; protected DocumentSolver $documentSolver;
protected ProducerSolver $producerSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->userRepository = $this->loadService(UserRepository::class); $this->userRepository = $this->loadService(UserRepository::class);
$this->deliveryNoteBuilder = $this->loadService(DeliveryNoteBuilder::class); $this->deliveryNoteBuilder = $this->loadService(DeliveryNoteBuilder::class);
$this->documentSolver = $this->loadService(DocumentSolver::class); $this->documentSolver = $this->loadService(DocumentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function instanciateOrder(Distribution $distribution): Order public function instanciateOrder(Distribution $distribution): Order


$order->auto_payment = 0; $order->auto_payment = 0;
if ($subscription->auto_payment == Subscription::AUTO_PAYMENT_DEDUCTED) { if ($subscription->auto_payment == Subscription::AUTO_PAYMENT_DEDUCTED) {
if ($order->id_user && $this->producerRepository->getConfig('credit') && $pointSale->credit) {
if ($order->id_user && $this->producerSolver->getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
$order->auto_payment = 0; $order->auto_payment = 0;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { } elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$this->initOrder($order); $this->initOrder($order);


// delete // delete
if ($this->producerRepository->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
($this->producerRepository->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($order->date_delete))
if ($this->producerSolver->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
($this->producerSolver->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($order->date_delete))
|| $force) { || $force) {


$this->productOrderBuilder->deleteProductOrdersByOrder($order); $this->productOrderBuilder->deleteProductOrdersByOrder($order);
$return = $this->delete($order); $return = $this->delete($order);
} }
// status 'delete' // status 'delete'
elseif ($this->producerRepository->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) {
elseif ($this->producerSolver->getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) {
$order->date_delete = date('Y-m-d H:i:s'); $order->date_delete = date('Y-m-d H:i:s');
$return = $this->update($order); $return = $this->update($order);
} }

+ 4
- 4
common/logic/Payment/Service/PaymentUtils.php View File

use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderSolver; use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Payment\Model\Payment; use common\logic\Payment\Model\Payment;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use common\logic\UtilsInterface; use common\logic\UtilsInterface;
{ {
protected PaymentBuilder $paymentBuilder; protected PaymentBuilder $paymentBuilder;
protected OrderSolver $orderSolver; protected OrderSolver $orderSolver;
protected ProducerRepository $producerRepository;
protected UserRepository $userRepository; protected UserRepository $userRepository;
protected ProducerSolver $producerSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->paymentBuilder = $this->loadService(PaymentBuilder::class); $this->paymentBuilder = $this->loadService(PaymentBuilder::class);
$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->userRepository = $this->loadService(UserRepository::class); $this->userRepository = $this->loadService(UserRepository::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function creditUser(User $user, float $amount, string $meanPayment, User $userAction): void public function creditUser(User $user, float $amount, string $meanPayment, User $userAction): void
$amountRemaining = round($this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_REMAINING), 2); $amountRemaining = round($this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_REMAINING), 2);


if($checkCreditLimit) { if($checkCreditLimit) {
$creditLimit = $this->producerRepository->getConfig('credit_limit');
$creditLimit = $this->producerSolver->getConfig('credit_limit');
$creditUser = $this->userRepository->getCredit($order->user); $creditUser = $this->userRepository->getCredit($order->user);


if (!is_null($creditLimit) && $amountRemaining > $creditUser - $creditLimit) { if (!is_null($creditLimit) && $amountRemaining > $creditUser - $creditLimit) {

+ 0
- 21
common/logic/Producer/Producer/Repository/ProducerRepository.php View File

return $onlinePaymentMinimumAmount; return $onlinePaymentMinimumAmount;
} }


/**
* Retourne une configuration d'un producteur donné
*/
public function getConfig(string $config = '', int $idProducer = 0)
{
if (strlen($config)) {
if (!$idProducer) {
$producer = $this->getProducerContext();
}
else {
$producer = $this->findOneProducerById($idProducer);
}

if ($producer) {
return $this->producerSolver->getConfig($config, $producer);
}
}

return null;
}

public function getNameProducer(User $user): string public function getNameProducer(User $user): string
{ {
$producer = $this->findOneProducerById($user->id_producer); $producer = $this->findOneProducerById($user->id_producer);

+ 1
- 1
common/logic/Product/Product/Model/Product.php View File

public function afterFind() public function afterFind()
{ {
if ($this->taxRate == null) { if ($this->taxRate == null) {
if($this->id_producer == GlobalParam::getCurrentProducerId()) {
if(GlobalParam::getCurrentProducerId() && $this->id_producer == GlobalParam::getCurrentProducerId()) {
$producer = GlobalParam::getCurrentProducer(); $producer = GlobalParam::getCurrentProducer();
} }
else { else {

+ 4
- 1
common/logic/User/UserProducer/Service/UserProducerBuilder.php View File

use common\logic\Payment\Service\PaymentSolver; use common\logic\Payment\Service\PaymentSolver;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository; use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;
protected ProducerRepository $producerRepository; protected ProducerRepository $producerRepository;
protected OrderSolver $orderSolver; protected OrderSolver $orderSolver;
protected UserRepository $userRepository; protected UserRepository $userRepository;
protected ProducerSolver $producerSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->producerRepository = $this->loadService(ProducerRepository::class); $this->producerRepository = $this->loadService(ProducerRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
$this->userRepository = $this->loadService(UserRepository::class); $this->userRepository = $this->loadService(UserRepository::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true) public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true)


public function isCreditLimitCrossed($oldCredit, $newCredit) public function isCreditLimitCrossed($oldCredit, $newCredit)
{ {
$creditLimitReminder = $this->producerRepository->getConfig('credit_limit_reminder');
$creditLimitReminder = $this->producerSolver->getConfig('credit_limit_reminder');


return !is_null($creditLimitReminder) && return !is_null($creditLimitReminder) &&
$oldCredit > $creditLimitReminder $oldCredit > $creditLimitReminder

Loading…
Cancel
Save