Browse Source

[Administration] Commande > édition commande : correctif point de vente par défaut

feature/souke
Guillaume Bourgeois 10 months ago
parent
commit
69ce4ac46c
8 changed files with 69 additions and 10 deletions
  1. +4
    -2
      backend/controllers/DistributionController.php
  2. +2
    -0
      backend/views/distribution/index.php
  3. +2
    -1
      backend/web/js/vuejs/distribution-index.js
  4. +8
    -2
      common/logic/Order/Order/Repository/OrderRepository.php
  5. +23
    -2
      common/logic/PointSale/PointSale/Service/PointSaleSolver.php
  6. +8
    -0
      common/logic/PointSale/UserPointSale/Module/UserPointSaleModule.php
  7. +12
    -3
      common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php
  8. +10
    -0
      common/logic/PointSale/UserPointSale/Service/UserPointSaleSolver.php

+ 4
- 2
backend/controllers/DistributionController.php View File

return $missingSubscriptionsArray; return $missingSubscriptionsArray;
} }


public function actionAjaxPointSaleFavorite($idUser)
public function actionAjaxPointSaleFavorite($idUser, $idDistribution)
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$distributionModule = $this->getDistributionModule();


$user = $userModule->findOneUserById($idUser); $user = $userModule->findOneUserById($idUser);
$distribution = $distributionModule->getRepository()->findOneDistributionById($idDistribution);
$idFavoritePointSale = 0; $idFavoritePointSale = 0;


if($user) { if($user) {
$favoritePointSale = $orderModule->getUserFavoritePointSale($user);
$favoritePointSale = $orderModule->getUserFavoritePointSale($user, $distribution);
if ($favoritePointSale) { if ($favoritePointSale) {
$idFavoritePointSale = $favoritePointSale->id; $idFavoritePointSale = $favoritePointSale->id;
} }

+ 2
- 0
backend/views/distribution/index.php View File

v-if="showModalFormOrderCreate" v-if="showModalFormOrderCreate"
create="1" create="1"
:date="date" :date="date"
:distribution="distribution"
:order="orderCreate" :order="orderCreate"
:points-sale="pointsSale" :points-sale="pointsSale"
:id-active-point-sale="idActivePointSale" :id-active-point-sale="idActivePointSale"
<order-form <order-form
v-if="showModalFormOrderUpdate && idOrderUpdate == order.id" v-if="showModalFormOrderUpdate && idOrderUpdate == order.id"
create="0" create="0"
:distribution="distribution"
:date="date" :date="date"
:date-format="dateFormat" :date-format="dateFormat"
:points-sale="pointsSale" :points-sale="pointsSale"

+ 2
- 1
backend/web/js/vuejs/distribution-index.js View File

}); });


Vue.component('order-form', { Vue.component('order-form', {
props: ['date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'orders', 'producer', 'loadingUpdateProductOrder', 'create', 'units'],
props: ['distribution', 'date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'orders', 'producer', 'loadingUpdateProductOrder', 'create', 'units'],
emits: ['updateProductPrice', 'updateInvoicePrices'], emits: ['updateProductPrice', 'updateInvoicePrices'],
data: function () { data: function () {
return { return {
axios.get(UrlManager.getBaseUrlAbsolute() + "distribution/ajax-point-sale-favorite", { axios.get(UrlManager.getBaseUrlAbsolute() + "distribution/ajax-point-sale-favorite", {
params: { params: {
idUser: app.order.id_user, idUser: app.order.id_user,
idDistribution: app.distribution.id
} }
}) })
.then(function (response) { .then(function (response) {

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

use common\logic\Payment\Service\PaymentSolver; use common\logic\Payment\Service\PaymentSolver;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\PointSale\PointSale\Service\PointSaleSolver;
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;
protected InvoiceSolver $invoiceSolver; protected InvoiceSolver $invoiceSolver;
protected PaymentSolver $paymentSolver; protected PaymentSolver $paymentSolver;
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected PointSaleSolver $pointSaleSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->invoiceSolver = $this->loadService(InvoiceSolver::class); $this->invoiceSolver = $this->loadService(InvoiceSolver::class);
$this->paymentSolver = $this->loadService(PaymentSolver::class); $this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
} }


public function getDefaultOptionsSearch(): array public function getDefaultOptionsSearch(): array
* Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié, * Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié,
* le point de vente de la dernière commande sinon. * le point de vente de la dernière commande sinon.
*/ */
public function getUserFavoritePointSale(User $user): ?PointSale
public function getUserFavoritePointSale(User $user, Distribution $distribution = null): ?PointSale
{ {
$pointSale = null; $pointSale = null;
$arrayUserPointSale = $this->userPointSaleRepository->findUserPointSalesByUser($user);
$arrayUserPointSale = $this->userPointSaleRepository->findUserPointSalesByUser($user, $distribution);


if (count($arrayUserPointSale) == 1) { if (count($arrayUserPointSale) == 1) {
$pointSale = $this->pointSaleRepository->findOnePointSaleById($arrayUserPointSale[0]->id_point_sale); $pointSale = $this->pointSaleRepository->findOnePointSaleById($arrayUserPointSale[0]->id_point_sale);
$lastOrder = $this->findOneOrderLastByUser($user); $lastOrder = $this->findOneOrderLastByUser($user);
if ($lastOrder) { if ($lastOrder) {
$pointSale = $this->pointSaleRepository->findOnePointSaleById($lastOrder->id_point_sale); $pointSale = $this->pointSaleRepository->findOnePointSaleById($lastOrder->id_point_sale);
if($distribution && !$this->pointSaleSolver->isDelivered($pointSale, $distribution)) {
$pointSale = null;
}
} }
} }



+ 23
- 2
common/logic/PointSale/PointSale/Service/PointSaleSolver.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Order\Order\Model\Order;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\SolverInterface; use common\logic\SolverInterface;
use yii\helpers\Html; use yii\helpers\Html;


class PointSaleSolver extends AbstractService implements SolverInterface class PointSaleSolver extends AbstractService implements SolverInterface
{ {
public function filterUserPointSalesByDistribution(array $userPointSaleArray, Distribution $distribution): array
{
foreach($userPointSaleArray as $key => $userPointSale) {
if(!$this->isDelivered($userPointSale->pointSale, $distribution)) {
unset($userPointSaleArray[$key]);
}
}

return $userPointSaleArray;
}

public function isDelivered(PointSale $pointSale, Distribution $distribution): bool
{
foreach($distribution->pointSaleDistribution as $pointSaleDistribution) {
if($pointSaleDistribution->pointSale->id == $pointSale->id && $pointSaleDistribution->delivery) {
return true;
}
}

return false;
}

/** /**
* Retourne le commentaire de l'utilisateur courant lié au point de vente. * Retourne le commentaire de l'utilisateur courant lié au point de vente.
*/ */

+ 8
- 0
common/logic/PointSale/UserPointSale/Module/UserPointSaleModule.php View File

use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository;
use common\logic\PointSale\UserPointSale\Service\UserPointSaleBuilder; use common\logic\PointSale\UserPointSale\Service\UserPointSaleBuilder;
use common\logic\PointSale\UserPointSale\Service\UserPointSaleDefinition; use common\logic\PointSale\UserPointSale\Service\UserPointSaleDefinition;
use common\logic\PointSale\UserPointSale\Service\UserPointSaleSolver;


/** /**
* @mixin UserPointSaleDefinition * @mixin UserPointSaleDefinition
* @mixin UserPointSaleRepository * @mixin UserPointSaleRepository
* @mixin UserPointSaleBuilder * @mixin UserPointSaleBuilder
* @mixin UserPointSaleSolver
*/ */
class UserPointSaleModule extends AbstractModule class UserPointSaleModule extends AbstractModule
{ {
UserPointSaleDefinition::class, UserPointSaleDefinition::class,
UserPointSaleRepository::class, UserPointSaleRepository::class,
UserPointSaleBuilder::class, UserPointSaleBuilder::class,
UserPointSaleSolver::class
]; ];
} }


{ {
return UserPointSaleBuilder::getInstance(); return UserPointSaleBuilder::getInstance();
} }

public function getSolver(): UserPointSaleSolver
{
return UserPointSaleSolver::getInstance();
}
} }

+ 12
- 3
common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php View File

namespace common\logic\PointSale\UserPointSale\Repository; namespace common\logic\PointSale\UserPointSale\Repository;


use common\logic\AbstractRepository; use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\PointSale\PointSale\Service\PointSaleSolver;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;


class UserPointSaleRepository extends AbstractRepository class UserPointSaleRepository extends AbstractRepository
{ {
protected UserPointSaleRepositoryQuery $query; protected UserPointSaleRepositoryQuery $query;
protected PointSaleSolver $pointSaleSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->loadQuery(UserPointSaleRepositoryQuery::class); $this->loadQuery(UserPointSaleRepositoryQuery::class);
$this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
} }


public function getDefaultOptionsSearch(): array public function getDefaultOptionsSearch(): array
] ; ] ;
} }


public function findUserPointSalesByUser(User $user): array
public function findUserPointSalesByUser(User $user, Distribution $distribution = null): array
{ {
return $this->createDefaultQuery()
$userPointSalesArray = $this->createDefaultQuery()
->joinPointSale() ->joinPointSale()
->filterByUser($user) ->filterByUser($user)
->find(); ->find();

if($distribution) {
$userPointSalesArray = $this->pointSaleSolver->filterUserPointSalesByDistribution($userPointSalesArray, $distribution);
}

return $userPointSalesArray;
} }


public function findOneUserPointSale(User $user = null, PointSale $pointSale = null) public function findOneUserPointSale(User $user = null, PointSale $pointSale = null)

+ 10
- 0
common/logic/PointSale/UserPointSale/Service/UserPointSaleSolver.php View File

<?php

namespace common\logic\PointSale\UserPointSale\Service;

use common\logic\AbstractSolver;

class UserPointSaleSolver extends AbstractSolver
{

}

Loading…
Cancel
Save