Przeglądaj źródła

Refactoring services

refactoring
Guillaume Bourgeois 1 rok temu
rodzic
commit
407f294f3e
16 zmienionych plików z 58 dodań i 49 usunięć
  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 Wyświetl plik

@@ -177,7 +177,8 @@ class CronController extends BackendController
foreach ($arrayProducers as $producer) {
$countOrders = 0;
$mailOrdersSend = false;
$distribution = $distributionManager->findOneDistribution($producer, $date, true);
$distribution = $distributionManager
->findOneDistribution($date, true);

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

+ 7
- 6
backend/controllers/DistributionController.php Wyświetl plik

@@ -50,11 +50,11 @@ use common\logic\Document\Document\Model\Document;
use common\logic\Order\Order\Model\Order;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Product\Product\Model\Product;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use DateTime;
use kartik\mpdf\Pdf;
use yii\filters\AccessControl;
use yii\web\User;

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

if ($deliveryNote && $deliveryNote->isStatusDraft()) {
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) {
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID);
$deliveryNoteManager->saveUpdate($deliveryNote);
}
@@ -1596,7 +1597,7 @@ class DistributionController extends BackendController
}

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

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

+ 4
- 0
backend/controllers/OrderController.php Wyświetl plik

@@ -734,6 +734,7 @@ class OrderController extends BackendController
$orderManager = $this->getOrderManager();

$order = $orderManager->findOneOrderById($idOrder);
$orderManager->initOrder($order);
if ($order) {
$orderManager->deleteOrder($order);
}
@@ -854,6 +855,7 @@ class OrderController extends BackendController
}

$order = $orderManager->findOneOrderById($order->id);
$orderManager->initOrder($order);
if ($order && $orderManager->isCreditAutoPayment($order)) {
$orderManager->processCredit($order);
}
@@ -987,6 +989,7 @@ class OrderController extends BackendController
$order->save();

$order = Order::searchOne(['id' => $order->id]);
$orderManager->initOrder($order);
if ($order && $orderManager->isCreditAutoPayment($order)) {
// Si changement d'user : on rembourse l'ancien user
$amountPaid = $orderManager->getOrderAmount($order, Order::AMOUNT_PAID);
@@ -999,6 +1002,7 @@ class OrderController extends BackendController
$this->getUserCurrent()
);
$order = Order::searchOne(['id' => $order->id]);
$orderManager->initOrder($order);
}

$orderManager->processCredit($order);

+ 9
- 10
backend/models/CreditForm.php Wyświetl plik

@@ -107,16 +107,15 @@ class CreditForm extends Model
$producerManager = ProducerManager::getInstance();

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é
if($this->send_mail) {

+ 1
- 0
backend/views/producer-price-range-admin/index.php Wyświetl plik

@@ -36,6 +36,7 @@
* termes.
*/

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


+ 2
- 2
backend/views/product-category/update.php Wyświetl plik

@@ -38,8 +38,8 @@ termes.

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('Modifier') ;


+ 6
- 5
backend/views/product/update/prices/list.php Wyświetl plik

@@ -36,12 +36,14 @@
* termes.
*/

use common\logic\User\User\Wrapper\UserManager;
use yii\helpers\Html;
use common\helpers\Price;
use yii\grid\GridView;
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->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]);
@@ -79,9 +81,9 @@ $this->render('../_nav', [
[
'attribute' => 'id_user',
'format' => 'raw',
'value' => function ($model) {
'value' => function ($model) use ($userManager) {
if ($model->user) {
return $model->user->getUsername();
return $userManager->getUsername($model->user);
}
return '<span class="label label-success">Tous</span>';
}
@@ -108,8 +110,7 @@ $this->render('../_nav', [
],
[
'attribute' => 'from_quantity',
'value' => function ($productPrice) {
$productManager = ProductManager::getInstance();
'value' => function ($productPrice) use ($productManager) {
if ($productPrice->from_quantity) {
return $productPrice->from_quantity . ' ' . $productManager->strUnit($productManager->getRefUnit($productPrice->product->unit), 'wording');
}

+ 1
- 5
backend/views/product/update/update.php Wyświetl plik

@@ -36,11 +36,7 @@
* 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->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]);

+ 2
- 0
backend/views/user/_menu.php Wyświetl plik

@@ -36,6 +36,8 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use yii\helpers\Html;

?>

<div id="menu-users">

+ 1
- 1
common/helpers/Opendistrib.php Wyświetl plik

@@ -56,7 +56,7 @@ class Opendistrib
}
}

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

return $versionsArray;
}

+ 2
- 2
common/logic/Distribution/Distribution/Repository/DistributionRepository.php Wyświetl plik

@@ -140,10 +140,10 @@ class DistributionRepository extends AbstractRepository
}

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

+ 1
- 1
common/logic/Producer/Producer/Service/ProducerBuilder.php Wyświetl plik

@@ -80,7 +80,7 @@ class ProducerBuilder extends AbstractBuilder
public function updateOpendistribVersion(Producer $producer): void
{
$versionsArray = Opendistrib::getVersions();
$producer->latest_version_opendistrib = $versionsArray[0];
$producer->latest_version_opendistrib = reset($versionsArray);

$this->saveUpdate($producer);
}

+ 1
- 1
common/logic/Product/Product/Repository/ProductRepository.php Wyświetl plik

@@ -111,7 +111,7 @@ class ProductRepository extends AbstractRepository
]);
}

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

+ 4
- 4
common/logic/Product/Product/Service/ProductSolver.php Wyświetl plik

@@ -48,13 +48,13 @@ class ProductSolver extends AbstractService implements SolverInterface
}
}

if ($userProducer && $userProducer->product_price_percent) {
/*if ($userProducer && $userProducer->product_price_percent) {
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;
}

+ 0
- 3
common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php Wyświetl plik

@@ -74,9 +74,6 @@ class CreditHistoryBuilder extends AbstractBuilder
$creditHistoryCreateEvent->creditHistory = $creditHistory;
$creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent);

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

return $creditHistory;
}
}

+ 15
- 8
producer/controllers/OrderController.php Wyświetl plik

@@ -66,6 +66,9 @@ class OrderController extends ProducerBaseController

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

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

@@ -75,12 +78,12 @@ class OrderController extends ProducerBaseController
);
}

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

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

@@ -389,7 +392,7 @@ class OrderController extends ProducerBaseController
}
}

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

if ($credit && $pointSale->credit &&
@@ -861,7 +865,7 @@ class OrderController extends ProducerBaseController
public function ajaxInfosProducts(
Producer $producer,
Distribution $distribution,
PointSale $pointSale,
PointSale $pointSale = null,
User $user = null,
Order $order = null
)
@@ -892,12 +896,15 @@ class OrderController extends ProducerBaseController
$productsArrayFilter = [];

// 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;
foreach ($productsArrayFilter as $key => &$product) {
$productObject = $product;

Ładowanie…
Anuluj
Zapisz