Browse Source

Refactoring services

refactoring
Guillaume Bourgeois 1 year ago
parent
commit
407f294f3e
16 changed files with 58 additions and 49 deletions
  1. +2
    -1
      backend/controllers/CronController.php
  2. +7
    -6
      backend/controllers/DistributionController.php
  3. +4
    -0
      backend/controllers/OrderController.php
  4. +9
    -10
      backend/models/CreditForm.php
  5. +1
    -0
      backend/views/producer-price-range-admin/index.php
  6. +2
    -2
      backend/views/product-category/update.php
  7. +6
    -5
      backend/views/product/update/prices/list.php
  8. +1
    -5
      backend/views/product/update/update.php
  9. +2
    -0
      backend/views/user/_menu.php
  10. +1
    -1
      common/helpers/Opendistrib.php
  11. +2
    -2
      common/logic/Distribution/Distribution/Repository/DistributionRepository.php
  12. +1
    -1
      common/logic/Producer/Producer/Service/ProducerBuilder.php
  13. +1
    -1
      common/logic/Product/Product/Repository/ProductRepository.php
  14. +4
    -4
      common/logic/Product/Product/Service/ProductSolver.php
  15. +0
    -3
      common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php
  16. +15
    -8
      producer/controllers/OrderController.php

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

foreach ($arrayProducers as $producer) { foreach ($arrayProducers as $producer) {
$countOrders = 0; $countOrders = 0;
$mailOrdersSend = false; $mailOrdersSend = false;
$distribution = $distributionManager->findOneDistribution($producer, $date, true);
$distribution = $distributionManager
->findOneDistribution($date, true);


if ($distribution) { if ($distribution) {
if ($hour == $producer->order_deadline || strlen($forceDate)) { if ($hour == $producer->order_deadline || strlen($forceDate)) {

+ 7
- 6
backend/controllers/DistributionController.php View File

use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;
use DateTime; use DateTime;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\User;


class DistributionController extends BackendController class DistributionController extends BackendController
{ {
$weight = 0; $weight = 0;
if ($ordersArray) { if ($ordersArray) {
foreach ($ordersArray as $order) { foreach ($ordersArray as $order) {
$orderManager->initOrder($order);
if (is_null($order->date_delete)) { if (is_null($order->date_delete)) {
$revenues += $orderManager->getOrderAmountWithTax($order); $revenues += $orderManager->getOrderAmountWithTax($order);
$weight += $order->weight; $weight += $order->weight;
'id' => (int)$order->id_delivery_note 'id' => (int)$order->id_delivery_note
]); ]);


if ($deliveryNote && $deliveryNote->isStatusDraft()) {
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) {
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID); $deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID);
$deliveryNoteManager->saveUpdate($deliveryNote); $deliveryNoteManager->saveUpdate($deliveryNote);
} }
} }


// on regénére le document si c'est un brouillon // on regénére le document si c'est un brouillon
if ($deliveryNote && $deliveryNote->isStatusDraft()) {
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) {
$deliveryNote->delete(); $deliveryNote->delete();
$deliveryNote = null; $deliveryNote = null;
} }
$user->name_legal_person = $firstOrder->pointSale->name; $user->name_legal_person = $firstOrder->pointSale->name;
$user->address = $firstOrder->pointSale->address; $user->address = $firstOrder->pointSale->address;
$user->id_producer = 0; $user->id_producer = 0;
$user->setPassword(Password::generate());
$user->generateAuthKey();
$userManager->setPassword($user, Password::generate());
$userManager->generateAuthKey($user);
$user->email = ''; $user->email = '';
if (!strlen($user->email)) { if (!strlen($user->email)) {
$user->username = 'inconnu@opendistrib.net'; $user->username = 'inconnu@opendistrib.net';
$deliveryNote->id_user = $user->id; $deliveryNote->id_user = $user->id;
} }


$deliveryNote->address = $user->getFullAddress();
$deliveryNote->address = $userManager->getFullAddress($user);
$deliveryNote->save(); $deliveryNote->save();
} else { } else {
// réinitialisation des order.id_delivery_note // réinitialisation des order.id_delivery_note

+ 4
- 0
backend/controllers/OrderController.php View File

$orderManager = $this->getOrderManager(); $orderManager = $this->getOrderManager();


$order = $orderManager->findOneOrderById($idOrder); $order = $orderManager->findOneOrderById($idOrder);
$orderManager->initOrder($order);
if ($order) { if ($order) {
$orderManager->deleteOrder($order); $orderManager->deleteOrder($order);
} }
} }


$order = $orderManager->findOneOrderById($order->id); $order = $orderManager->findOneOrderById($order->id);
$orderManager->initOrder($order);
if ($order && $orderManager->isCreditAutoPayment($order)) { if ($order && $orderManager->isCreditAutoPayment($order)) {
$orderManager->processCredit($order); $orderManager->processCredit($order);
} }
$order->save(); $order->save();


$order = Order::searchOne(['id' => $order->id]); $order = Order::searchOne(['id' => $order->id]);
$orderManager->initOrder($order);
if ($order && $orderManager->isCreditAutoPayment($order)) { if ($order && $orderManager->isCreditAutoPayment($order)) {
// Si changement d'user : on rembourse l'ancien user // Si changement d'user : on rembourse l'ancien user
$amountPaid = $orderManager->getOrderAmount($order, Order::AMOUNT_PAID); $amountPaid = $orderManager->getOrderAmount($order, Order::AMOUNT_PAID);
$this->getUserCurrent() $this->getUserCurrent()
); );
$order = Order::searchOne(['id' => $order->id]); $order = Order::searchOne(['id' => $order->id]);
$orderManager->initOrder($order);
} }


$orderManager->processCredit($order); $orderManager->processCredit($order);

+ 9
- 10
backend/models/CreditForm.php View File

$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();


if ($this->validate()) { if ($this->validate()) {
$creditHistory = new CreditHistory();
$creditHistory->id_user = $this->id_user;
$creditHistory->id_user_action = Yii::$app->user->identity->id;
$creditHistory->id_producer = GlobalParam::getCurrentProducerId() ;
$creditHistory->type = $this->type ;
$creditHistory->comment = $this->comment ;
$creditHistory->amount = $this->amount ;
$creditHistory->mean_payment = $this->mean_payment ;

$creditHistoryManager->saveCreate($creditHistory);
$user = $userManager->findOneUserById($this->id_user);
$creditHistoryManager->createCreditHistory(
$this->type,
$this->amount,
GlobalParam::getCurrentProducer(),
$user,
Yii::$app->user->identity,
$this->mean_payment
);
// on prévient l'utilisateur que son compte vient d'être crédité // on prévient l'utilisateur que son compte vient d'être crédité
if($this->send_mail) { if($this->send_mail) {

+ 1
- 0
backend/views/producer-price-range-admin/index.php View File

* termes. * termes.
*/ */


use common\helpers\Price;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;



+ 2
- 2
backend/views/product-category/update.php View File



use yii\helpers\Html; use yii\helpers\Html;


$this->setTitle("Modifier un groupe d'utilisateur") ;
$this->addBreadcrumb(['label' => "Groupes d'utilisateurs", 'url' => ['index']]) ;
$this->setTitle("Modifier une catégorie") ;
$this->addBreadcrumb(['label' => "Catégories", 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => Html::encode($model->name), 'url' => ['update', 'id' => $model->id]]) ; $this->addBreadcrumb(['label' => Html::encode($model->name), 'url' => ['update', 'id' => $model->id]]) ;
$this->addBreadcrumb('Modifier') ; $this->addBreadcrumb('Modifier') ;



+ 6
- 5
backend/views/product/update/prices/list.php View File

* termes. * termes.
*/ */


use common\logic\User\User\Wrapper\UserManager;
use yii\helpers\Html; use yii\helpers\Html;
use common\helpers\Price; use common\helpers\Price;
use yii\grid\GridView; use yii\grid\GridView;
use common\logic\Product\Product\Wrapper\ProductManager; use common\logic\Product\Product\Wrapper\ProductManager;


$productManager = $this->getProductManager();
$productManager = ProductManager::getInstance();
$userManager = UserManager::getInstance();


$this->setTitle('Liste des prix (' . Html::encode($model->name) . ')'); $this->setTitle('Liste des prix (' . Html::encode($model->name) . ')');
$this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); $this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]);
[ [
'attribute' => 'id_user', 'attribute' => 'id_user',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) {
'value' => function ($model) use ($userManager) {
if ($model->user) { if ($model->user) {
return $model->user->getUsername();
return $userManager->getUsername($model->user);
} }
return '<span class="label label-success">Tous</span>'; return '<span class="label label-success">Tous</span>';
} }
], ],
[ [
'attribute' => 'from_quantity', 'attribute' => 'from_quantity',
'value' => function ($productPrice) {
$productManager = ProductManager::getInstance();
'value' => function ($productPrice) use ($productManager) {
if ($productPrice->from_quantity) { if ($productPrice->from_quantity) {
return $productPrice->from_quantity . ' ' . $productManager->strUnit($productManager->getRefUnit($productPrice->product->unit), 'wording'); return $productPrice->from_quantity . ' ' . $productManager->strUnit($productManager->getRefUnit($productPrice->product->unit), 'wording');
} }

+ 1
- 5
backend/views/product/update/update.php View File

* termes. * termes.
*/ */




/* @var $this yii\web\View */
/* @var $model app\models\Produit */
/* @var $form yii\widgets\ActiveForm */
use yii\helpers\Html;


$this->setTitle('Modifier un produit ('.Html::encode($model->name).')'); $this->setTitle('Modifier un produit ('.Html::encode($model->name).')');
$this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); $this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]);

+ 2
- 0
backend/views/user/_menu.php View File

termes. termes.
*/ */


use yii\helpers\Html;

?> ?>


<div id="menu-users"> <div id="menu-users">

+ 1
- 1
common/helpers/Opendistrib.php View File

} }
} }


ksort($versionsArray);
krsort($versionsArray);


return $versionsArray; return $versionsArray;
} }

+ 2
- 2
common/logic/Distribution/Distribution/Repository/DistributionRepository.php View File

} }


// isDateAvailable // isDateAvailable
public function isDistributionDateAvailable(Producer $producer, string $date = null): bool
public function isDistributionDateAvailable(string $date = null): bool
{ {
if($date && strlen($date)) { if($date && strlen($date)) {
$distribution = $this->findOneDistribution($producer, $date);
$distribution = $this->findOneDistribution($date);
if($distribution && $this->distributionSolver->isDistributionAvailable($distribution)) { if($distribution && $this->distributionSolver->isDistributionAvailable($distribution)) {
return true; return true;
} }

+ 1
- 1
common/logic/Producer/Producer/Service/ProducerBuilder.php View File

public function updateOpendistribVersion(Producer $producer): void public function updateOpendistribVersion(Producer $producer): void
{ {
$versionsArray = Opendistrib::getVersions(); $versionsArray = Opendistrib::getVersions();
$producer->latest_version_opendistrib = $versionsArray[0];
$producer->latest_version_opendistrib = reset($versionsArray);


$this->saveUpdate($producer); $this->saveUpdate($producer);
} }

+ 1
- 1
common/logic/Product/Product/Repository/ProductRepository.php View File

]); ]);
} }


public function getPriceArray(Product $product, User $user, PointSale $pointSale): array
public function getPriceArray(Product $product, User $user = null, PointSale $pointSale = null): array
{ {
$priceArray = []; $priceArray = [];
$userProducer = null; $userProducer = null;

+ 4
- 4
common/logic/Product/Product/Service/ProductSolver.php View File

} }
} }


if ($userProducer && $userProducer->product_price_percent) {
/*if ($userProducer && $userProducer->product_price_percent) {
return $product->price * (1 + $userProducer->product_price_percent / 100); return $product->price * (1 + $userProducer->product_price_percent / 100);
}
}*/


if ($pointSale && $pointSale->product_price_percent) {
/*if ($pointSale && $pointSale->product_price_percent) {
return $product->price * (1 + $pointSale->product_price_percent / 100); return $product->price * (1 + $pointSale->product_price_percent / 100);
}
}*/


return $product->price; return $product->price;
} }

+ 0
- 3
common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php View File

$creditHistoryCreateEvent->creditHistory = $creditHistory; $creditHistoryCreateEvent->creditHistory = $creditHistory;
$creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent); $creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent);


print_r($creditHistory);
die('#'.$creditHistory->id);

return $creditHistory; return $creditHistory;
} }
} }

+ 15
- 8
producer/controllers/OrderController.php View File



public function actionOrder(int $id = 0, $date = '') public function actionOrder(int $id = 0, $date = '')
{ {
$orderManager = $this->getOrderManager();
$distributionManager = $this->getDistributionManager();

$params = []; $params = [];
$producer = $this->getProducerCurrent(); $producer = $this->getProducerCurrent();


); );
} }


$order = $this->getOrderManager()->findOneOrderById($id);
if ($order && $this->getOrderManager()->isOrderStateOpen($order)) {
$order = $orderManager->findOneOrderById($id);
if ($order && $orderManager->isOrderStateOpen($order)) {
$params['order'] = $order; $params['order'] = $order;
} }


if ($this->getDistributionManager()->isDistributionDateAvailable($producer, $date)) {
if ($distributionManager->isDistributionDateAvailable($date)) {
$params['date'] = $date; $params['date'] = $date;
} }


} }
} }


$availableProducts = $productManager->findProductsByDistribution($distribution);
$availableProducts = $orderManager->findProductDistributionsByDistribution($distribution);
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
if (isset($availableProducts[$product->id])) { if (isset($availableProducts[$product->id])) {
$productOrder = new ProductOrder(); $productOrder = new ProductOrder();
$creditFunctioning = $producerManager->getPointSaleCreditFunctioning($pointSale); $creditFunctioning = $producerManager->getPointSaleCreditFunctioning($pointSale);
$creditUser = $userManager->getCredit($user, $producer); $creditUser = $userManager->getCredit($user, $producer);
$order = $orderManager->findOneOrderById($order->id); $order = $orderManager->findOneOrderById($order->id);
$orderManager->initOrder($order);
$amountRemaining = $orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING); $amountRemaining = $orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING);


if ($credit && $pointSale->credit && if ($credit && $pointSale->credit &&
public function ajaxInfosProducts( public function ajaxInfosProducts(
Producer $producer, Producer $producer,
Distribution $distribution, Distribution $distribution,
PointSale $pointSale,
PointSale $pointSale = null,
User $user = null, User $user = null,
Order $order = null Order $order = null
) )
$productsArrayFilter = []; $productsArrayFilter = [];


// filtre sur les points de vente // filtre sur les points de vente
foreach ($productsArray as $product) {
if ($productManager->isAvailableOnPointSale($product, $pointSale)) {
$productsArrayFilter[] = $product;
if($pointSale) {
foreach ($productsArray as $product) {
if ($productManager->isAvailableOnPointSale($product, $pointSale)) {
$productsArrayFilter[] = $product;
}
} }
} }



$indexProduct = 0; $indexProduct = 0;
foreach ($productsArrayFilter as $key => &$product) { foreach ($productsArrayFilter as $key => &$product) {
$productObject = $product; $productObject = $product;

Loading…
Cancel
Save