Browse Source

[Backend] Distributions > édition/création commande : bouton unique "Créer" ou "Modifier" #931

refactoring
Guillaume Bourgeois 1 year ago
parent
commit
404a7ac25a
4 changed files with 33 additions and 9 deletions
  1. +3
    -5
      backend/controllers/OrderController.php
  2. +2
    -2
      backend/views/distribution/index.php
  3. +1
    -2
      backend/web/js/vuejs/distribution-index.js
  4. +27
    -0
      common/logic/Order/Order/Repository/OrderRepository.php

+ 3
- 5
backend/controllers/OrderController.php View File

* @param string $username * @param string $username
* @param array $produits * @param array $produits
* @param string $commentaire * @param string $commentaire
* @param string $processCredit
*/ */
public function actionAjaxCreate( public function actionAjaxCreate(
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment, $processCredit = 0)
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment)
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;


} }


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


$meanPayment = $request->post('meanPayment'); $meanPayment = $request->post('meanPayment');
$products = $request->post('products'); $products = $request->post('products');
$comment = $request->post('comment'); $comment = $request->post('comment');
$processCredit = $request->post('processCredit');


$order = $orderManager->findOneOrderById($idOrder); $order = $orderManager->findOneOrderById($idOrder);
$user = $userManager->findOneUserById($idUser); $user = $userManager->findOneUserById($idUser);
$order->save(); $order->save();


$order = Order::searchOne(['id' => $order->id]); $order = Order::searchOne(['id' => $order->id]);
if ($order && $processCredit) {
if ($order && $orderManager->isCreditAutoPayment($order)) {
// Si changement d'user : on rembourse l'ancien user // Si changement d'user : on rembourse l'ancien user
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); $amountPaid = $order->getAmount(Order::AMOUNT_PAID);
if ($oldIdUser != $idUser && $amountPaid > 0) { if ($oldIdUser != $idUser && $amountPaid > 0) {

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

</div> </div>
<div slot="footer"> <div slot="footer">
<div class="actions-form"> <div class="actions-form">
<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id && order.id_user > 0" data-process-credit="1">Créer et payer</button>
<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id && order.id_user > 0" data-process-credit="1">Modifier et payer</button>
<!--<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id && order.id_user > 0" data-process-credit="1">Créer et payer</button>
<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id && order.id_user > 0" data-process-credit="1">Modifier et payer</button>-->


<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id">Modifier</button> <button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id">Modifier</button>
<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id">Créer</button> <button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id">Créer</button>

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

username: this.order.username, username: this.order.username,
meanPayment: this.order.mean_payment, meanPayment: this.order.mean_payment,
products: app.getProductOrderArrayRequest(), products: app.getProductOrderArrayRequest(),
comment: this.order.comment,
processCredit: processCredit
comment: this.order.comment
}}) }})
.then(function(response) { .then(function(response) {
app.order.id_point_sale = 0 ; app.order.id_point_sale = 0 ;

+ 27
- 0
common/logic/Order/Order/Repository/OrderRepository.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\Order\ProductOrder\Repository\ProductOrderRepository; use common\logic\Order\ProductOrder\Repository\ProductOrderRepository;
use common\logic\PointSale\PointSale\Model\PointSale;
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\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use yii\helpers\Html; use yii\helpers\Html;


class OrderRepository extends AbstractRepository class OrderRepository extends AbstractRepository
return $productDistributionArray; return $productDistributionArray;
} }


public function isCreditAutoPayment(Order $order)
{
$pointSale = PointSale::findOne($order->id_point_sale);
$distribution = Distribution::findOne($order->id_distribution);
$creditFunctioning = $pointSale->getCreditFunctioning();

if ($order->id_user && $order->producerRepository->getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
return 0;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
return 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$userProducer = UserProducer::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]);
if ($userProducer) {
return $userProducer->credit_active;
}
}
}

return 0;
}

} }

Loading…
Cancel
Save