Procházet zdrojové kódy

Refactoring services #885

refactoring
Guillaume Bourgeois před 1 rokem
rodič
revize
16b7767598
13 změnil soubory, kde provedl 299 přidání a 271 odebrání
  1. +70
    -54
      backend/controllers/DocumentController.php
  2. +12
    -7
      backend/controllers/InvoiceController.php
  3. +158
    -201
      backend/controllers/OrderController.php
  4. +2
    -0
      backend/controllers/PointSaleController.php
  5. +7
    -0
      common/logic/Distribution/Distribution/DistributionRepository.php
  6. +2
    -3
      common/logic/Distribution/ProductDistribution/ProductDistributionBuilder.php
  7. +6
    -0
      common/logic/Document/DeliveryNote/DeliveryNoteRepository.php
  8. +6
    -0
      common/logic/Document/Invoice/InvoiceRepository.php
  9. +11
    -6
      common/logic/Order/Order/OrderBuilder.php
  10. +7
    -0
      common/logic/Order/Order/OrderRepository.php
  11. +7
    -0
      common/logic/Order/ProductOrder/ProductOrderRepository.php
  12. +7
    -0
      common/logic/PointSale/PointSale/PointSaleRepository.php
  13. +4
    -0
      producer/controllers/SubscriptionController.php

+ 70
- 54
backend/controllers/DocumentController.php Zobrazit soubor

@@ -45,6 +45,8 @@ use common\logic\Document\Document\Document;
use common\logic\Document\Invoice\Invoice;
use common\logic\Document\Quotation\Quotation;
use common\logic\Order\Order\Order;
use common\logic\Order\ProductOrder\ProductOrder;
use common\logic\Product\Product\Product;
use kartik\mpdf\Pdf;
use yii\base\UserException;
use yii;
@@ -199,11 +201,14 @@ class DocumentController extends BackendController
}

$this->setFlash('success', $this->getFlashMessage('delete', $model));

$this->redirect([$this->getControllerUrl() . '/index']);
}

public function actionExportCsvEvoliz($id)
public function actionExportCsvEvoliz(int $id)
{
$documentManager = $this->getDocumentManager();

$datas = [];
$document = $this->findModel($id);

@@ -247,11 +252,11 @@ class DocumentController extends BackendController
'Créateur',
];

foreach ($document->getProductsOrders() as $productOrderArray) {
foreach ($documentManager->getProductsOrders($document) as $productOrderArray) {
foreach ($productOrderArray as $productOrder) {

$price = $productOrder->getPrice();
if ($document->isInvoicePrice() && $productOrder->getInvoicePrice()) {
if ($documentManager->isInvoicePrice($document) && $productOrder->getInvoicePrice()) {
$price = $productOrder->getInvoicePrice();
}

@@ -304,7 +309,7 @@ class DocumentController extends BackendController

// status
$status = '';
if ($document->isStatusDraft()) {
if ($documentManager->isStatusDraft($document)) {
$status = 'brouillon_';
}

@@ -324,10 +329,11 @@ class DocumentController extends BackendController
$document = $this->findModel($id);
$document->downloadPdf(true);
$this->setFlash('success', 'Le document PDF a bien été regénéré.');

return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}

public function actionSend($id, $backUpdateForm = false)
public function actionSend(int $id, $backUpdateForm = false)
{
$document = $this->findModel($id);
if ($document->send()) {
@@ -348,16 +354,17 @@ class DocumentController extends BackendController

public function actionAjaxUserInfos($typeAction, $idUser, $classDocument, $idDocument = false)
{
$userManager = $this->getUserManager();
$documentManager = $this->getDocumentManager();

\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if ($idUser > 0) {
$user = User::searchOne([
'id' => $idUser
]);
$user = $userManager->findOneUserById($idUser);

if ($user) {
$document = null;
if (Document::isValidClass($classDocument)) {
if ($documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument,
'id_user' => $idUser
@@ -422,15 +429,17 @@ class DocumentController extends BackendController

public function addDeliveryNoteToArray($deliveryNote, $isCreate = true)
{
$deliveryNoteManager = $this->getDeliveryNoteManager();

$deliveryNoteData = array_merge(
$deliveryNote->getAttributes(),
[
'url' => Yii::$app->urlManager->createUrl(['delivery-note/update', 'id' => $deliveryNote->id]),
'total' => $deliveryNote->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL)
'url' => $this->getUrlManagerBackend()->createUrl(['delivery-note/update', 'id' => $deliveryNote->id]),
'total' => $deliveryNoteManager->getAmountWithTax($deliveryNote, Order::INVOICE_AMOUNT_TOTAL)
]
);

if (($isCreate && !$deliveryNote->isInvoiced()) || !$isCreate) {
if (($isCreate && !$deliveryNoteManager->isInvoiced($deliveryNote)) || !$isCreate) {
return $deliveryNoteData;
}

@@ -439,19 +448,20 @@ class DocumentController extends BackendController

public function actionValidate($id, $backUpdateForm = false)
{
$documentManager = $this->getDocumentManager();
$classDocument = $this->getClass();

if ($id > 0 && Document::isValidClass($classDocument)) {
if ($id > 0 && $documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $id
]);

if ($document) {
$document->changeStatus(Document::STATUS_VALID);
$document->save();
$documentManager->changeStatus($document,Document::STATUS_VALID);
$documentManager->saveUpdate($document);

// génération PDF
$document->generatePdf(Pdf::DEST_FILE);
$documentManager->generatePdf($document, Pdf::DEST_FILE);

$this->setFlash('success', $this->getFlashMessage('validate', $document));

@@ -464,6 +474,7 @@ class DocumentController extends BackendController
}

$this->setFlash('danger', 'Une erreur est survenue lors de la validation du document.');

return $this->redirect([$this->getControllerUrl() . '/index']);
}

@@ -471,14 +482,17 @@ class DocumentController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if ($idDocument > 0 && Document::isValidClass($classDocument)) {
$documentManager = $this->getDocumentManager();

if ($idDocument > 0 && $documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);

if ($document) {
$document->changeStatus(Document::STATUS_VALID);
$document->save();
$documentManager->changeStatus($document,Document::STATUS_VALID);
$documentManager->saveUpdate($document);

return [
'return' => 'success',
'alert' => [
@@ -502,23 +516,29 @@ class DocumentController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if ($idDocument > 0 && Document::isValidClass($classDocument)) {
$orderManager = $this->getOrderManager();
$productManager = $this->getProductManager();
$documentManager = $this->getDocumentManager();
$deliveryNoteManager = $this->getDeliveryNoteManager();
$userProducerManager = $this->getUserProducerManager();
$pointSaleManager = $this->getPointSaleManager();

if ($idDocument > 0 && $documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);

if ($document) {
$productsArray = Product::searchAll([], [
'orderby' => 'product.order ASC'
]);

$ordersArray = [];
$productsArray = $productManager->findProducts();

foreach ($document->orders as $order) {
$order->init();
$orderManager->init($order);
$productsOrderArray = [];

foreach ($order->productOrder as $productOrder) {
$productsOrderArray[$productOrder->id] = array_merge($productOrder->getAttributes(), [
'url_order' => Yii::$app->urlManager->createUrl(['distribution/index', 'idOrderUpdate' => $productOrder->id_order])
'url_order' => $this->getUrlManagerBackend()->createUrl(['distribution/index', 'idOrderUpdate' => $productOrder->id_order])
]);
}
$ordersArray[$order->id] = array_merge(
@@ -537,21 +557,16 @@ class DocumentController extends BackendController
);
}

$userProducer = UserProducer::searchOne([
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
$pointSale = PointSale::searchOne([
'id_user' => $document->user->id
]);
$userProducer = $userProducerManager->findOneUserProducer($document->user, $this->getProducerCurrent());
$pointSale = $pointSaleManager->findOnePointSaleByIdUser($document->user->id);

$productsArray = yii\helpers\ArrayHelper::map(
$productsArray,
'order',
function ($product) use ($document, $userProducer, $pointSale) {
function ($product) use ($document, $userProducer, $pointSale, $productManager) {
return array_merge($product->getAttributes(), [
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($userProducer->user, $pointSale),
'prices' => $productManager->getPriceArray($product, $userProducer->user, $pointSale),
'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value
]);
@@ -562,19 +577,21 @@ class DocumentController extends BackendController
'return' => 'success',
'tax_rate_producer' => GlobalParam::getCurrentProducer()->taxRate->value,
'document' => array_merge($document->getAttributes(), [
'html_label' => $document->getHtmlLabel(),
'class' => $document->getClass()
'html_label' => $documentManager->getHtmlLabel($document),
'class' => $documentManager->getClass($document)
]),
'id_user' => $document->user->id,
'products' => $productsArray,
'orders' => $ordersArray,
'total' => ($document->getClass() == 'Invoice' || $document->getClass() == 'DeliveryNote') ? $document->getAmount(
'total' => ($documentManager->getClass($document) == 'Invoice' || $documentManager->getClass($document) == 'DeliveryNote') ? $documentManager->getAmount(
$document,
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmount(Order::AMOUNT_TOTAL),
'total_with_tax' => ($document->getClass() == 'Invoice' || $document->getClass() == 'DeliveryNote') ? $document->getAmountWithTax(
) : $documentManager->getAmount($document, Order::AMOUNT_TOTAL),
'total_with_tax' => ($documentManager->getClass($document) == 'Invoice' || $documentManager->getClass($document) == 'DeliveryNote') ? $documentManager->getAmountWithTax(
$document,
Order::INVOICE_AMOUNT_TOTAL
) : $document->getAmountWithTax(Order::AMOUNT_TOTAL),
'invoice_url' => ($document->getClass() == 'DeliveryNote' && $document->getInvoice()) ? Yii::$app->urlManager->createUrl(['invoice/update', 'id' => $document->getInvoice()->id]) : null
) : $documentManager->getAmountWithTax($document, Order::AMOUNT_TOTAL),
'invoice_url' => ($documentManager->getClass($document) == 'DeliveryNote' && $deliveryNoteManager->getInvoice($document)) ? $this->getUrlManagerBackend()->createUrl(['invoice/update', 'id' => $deliveryNoteManager->getInvoice($document)->id]) : null
];
}
}
@@ -586,13 +603,14 @@ class DocumentController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if (Document::isValidClass($classDocument)) {
$documentManager = $this->getDocumentManager();
$productManager = $this->getProductManager();

if ($documentManager->isValidClass($classDocument)) {
$document = $classDocument::searchOne([
'id' => $idDocument
]);
$product = Product::searchOne([
'id' => $idProduct
]);
$product = $productManager->findOneProductById($idProduct);

if ($document && $product) {
if (count($document->orders) == 0) {
@@ -611,7 +629,7 @@ class DocumentController extends BackendController
}

if ($order) {
$productOrder = new ProductOrder;
$productOrder = new ProductOrder();
$productOrder->id_order = $order->id;
$productOrder->id_product = $idProduct;
$quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient'];
@@ -646,12 +664,12 @@ class DocumentController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$productOrder = ProductOrder::searchOne([
'id' => $idProductOrder
]);
$productOrderManager = $this->getProductOrderManager();
$productOrder = $productOrderManager->findOneProductOrderById($idProductOrder);

if ($productOrder) {
$productOrder->delete();
$productOrderManager->delete($productOrder);

return [
'return' => 'success',
@@ -698,7 +716,7 @@ class DocumentController extends BackendController
return '';
}

public function getFlashMessage($type = 'create', $model)
public function getFlashMessage(string $type, $model)
{
$class = $this->getClass();

@@ -763,8 +781,6 @@ class DocumentController extends BackendController

$model = $class::searchOne([
'id' => $id
], [
'orderby' => 'teshtygjhtyt'
]);

if ($model) {

+ 12
- 7
backend/controllers/InvoiceController.php Zobrazit soubor

@@ -38,14 +38,14 @@

namespace backend\controllers;

use common\logic\Document\Invoice\InvoiceSearch;
use common\logic\Order\Order\Order;
use Yii;

class InvoiceController extends DocumentController
{
/**
* Liste les modèles Invoice.
*
* @return mixed
* Liste les factures
*/
public function actionIndex()
{
@@ -62,7 +62,9 @@ class InvoiceController extends DocumentController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$invoice = Invoice::searchOne(['id' => $idInvoice]);
$invoiceManager = $this->getInvoiceManager();

$invoice = $invoiceManager->findOneInvoiceById($idInvoice);

if ($invoice && $invoice->isStatusDraft()) {
Order::updateAll([
@@ -91,10 +93,13 @@ class InvoiceController extends DocumentController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$invoice = Invoice::searchOne(['id' => $idInvoice]);
$deliveryNote = DeliveryNote::searchOne(['id' => $idDeliveryNote]);
$invoiceManager = $this->getInvoiceManager();
$deliveryNoteManager = $this->getDeliveryNoteManager();

$invoice = $invoiceManager->findOneInvoiceById($idInvoice);
$deliveryNote = $deliveryNoteManager->findOneDeliveryNoteById($idDeliveryNote);

if ($invoice && $invoice->isStatusDraft() && $deliveryNote) {
if ($invoice && $invoiceManager->isStatusDraft($invoice) && $deliveryNote) {
Order::updateAll([
'id_invoice' => $idInvoice
], [

+ 158
- 201
backend/controllers/OrderController.php Zobrazit soubor

@@ -38,7 +38,21 @@

namespace backend\controllers;

use common\forms\SubscriptionForm;
use common\helpers\CSV;
use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution;
use common\logic\Distribution\ProductDistribution\ProductDistribution;
use common\logic\Order\Order\Order;
use common\logic\Order\ProductOrder\ProductOrder;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\Product\Product;
use common\logic\User\CreditHistory\CreditHistory;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;
use yii\filters\AccessControl;
use yii\helpers\Html;

class OrderController extends BackendController
{
@@ -54,8 +68,8 @@ class OrderController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == User::STATUS_ADMIN
|| User::getCurrentStatus() == User::STATUS_PRODUCER;
return $this->getUserManager()->isCurrentProducer()
|| $this->getUserManager()->isCurrentAdmin();
}
]
],
@@ -65,24 +79,23 @@ class OrderController extends BackendController

/**
* Traite le formulaire d'ajout/modification de commande.
*
* @param Distribution $distribution
* @param string $date
* @param array $points_vente
* @param array $produits
* @param array $users
*/
public function processOrderForm(
$distribution, $date, $pointsSale, $products, $users)
Distribution $distribution,
string $date,
array $pointsSale,
array $products,
array $users
)
{
$orderManager = $this->getOrderManager();
$pointSaleManager = $this->getPointSaleManager();

if ($date != '') {
// commandes
$orders = Order::searchAll([
'distribution.date' => $date
]);
$orders = $orderManager->findOrdersByDistribution($distribution);

foreach ($pointsSale as $point) {
$point->initOrders($orders);
$pointSaleManager->initPointSaleOrders($point, $orders);

if (isset($_POST['submit_pv']) && $_POST['submit_pv']) {
// modifs
@@ -93,7 +106,7 @@ class OrderController extends BackendController

// création des commande_produit modifiés
foreach ($products as $product) {
$quantity = Yii::$app->getRequest()->post('product_' . $point->id . '_' . $product->id, 0);
$quantity = \Yii::$app->getRequest()->post('product_' . $point->id . '_' . $product->id, 0);
if ($quantity) {
$productOrder = new ProductOrder;
$productOrder->id_order = $order->id;
@@ -108,8 +121,8 @@ class OrderController extends BackendController
}
}

$username = Yii::$app->getRequest()->post('username_point_sale_' . $point->id, 0);
$date = Yii::$app->getRequest()->post('date_order_point_sale_' . $point->id, 0);
$username = \Yii::$app->getRequest()->post('username_point_sale_' . $point->id, 0);
$date = \Yii::$app->getRequest()->post('date_order_point_sale_' . $point->id, 0);
$oneProduct = false;
foreach ($products as $product) {
$quantity = Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0);
@@ -119,7 +132,7 @@ class OrderController extends BackendController
}

if (strlen($username) && $date && $oneProduct) {
$order = new Order;
$order = new Order();
$order->id_point_sale = $point->id;
$order->id_production = $distribution->id;
$order->id_user = 0;
@@ -129,7 +142,7 @@ class OrderController extends BackendController
$order->save();

foreach ($products as $product) {
$quantity = Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0);
$quantity = \Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0);
if ($quantity) {
$productOrder = new ProductOrder;
$productOrder->id_order = $order->id;
@@ -143,7 +156,7 @@ class OrderController extends BackendController
}
}

$order->initReference();
$orderManager->generateOrderReference($order);
}
}
}
@@ -152,13 +165,15 @@ class OrderController extends BackendController

/**
* Page principale de la gestion des commandes.
*
* @param string $date
* @param boolean $returnData
* @return string
*/
public function actionIndex($date = '', $returnData = false)
{
$distributionManager = $this->getDistributionManager();
$productManager = $this->getProductManager();
$pointSaleManager = $this->getPointSaleManager();
$orderManager = $this->getOrderManager();
$productDistributionManager = $this->getProductDistributionManager();

if (!Product::searchCount() || !PointSale::searchCount()) {
$this->redirect(['site/index', 'error_products_points_sale' => 1]);
}
@@ -173,10 +188,8 @@ class OrderController extends BackendController
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname;
}

// création du jour de distribution
$distribution = DistributionModel::initDistribution($date);
$distribution = $distributionManager->createDistributionIfNotExist($this->getProducerCurrent(), $date);

// points de vente
if ($distribution) {
$arrayPointsSale = PointSale::find()
->joinWith(['pointSaleDistribution' => function ($q) use ($distribution) {
@@ -187,20 +200,15 @@ class OrderController extends BackendController
])
->all();
} else {
$arrayPointsSale = PointSale::searchAll();
$arrayPointsSale = $pointSaleManager->findPointSales();
}

// produits
$arrayProducts = Product::searchAll();
$arrayProducts = $productManager->findProducts();

// gestion des commandes
$this->processOrderForm($distribution, $date, $arrayPointsSale, $arrayProducts, $users);

// commandes
$arrayOrders = Order::searchAll([
'distribution.date' => $date,
]);

$arrayOrders = $orderManager->findOrdersByDistribution($distribution);
$revenues = 0;
$weight = 0;
$revenuesDelivered = 0;
@@ -221,7 +229,7 @@ class OrderController extends BackendController

// init commandes point de vente
foreach ($arrayPointsSale as $pointSale) {
$pointSale->initOrders($arrayOrders);
$pointSaleManager->initPointSaleOrders($pointSale, $arrayOrders);

$dataSelectOrders = [];
$dataOptionsOrders = [];
@@ -256,10 +264,8 @@ class OrderController extends BackendController
if (isset($_POST['Product'])) {

foreach ($arrayProducts as $product) {
$productDistribution = ProductDistributionModel::searchOne([
'id_distribution' => $distribution->id,
'id_product' => $product->id
]);

$productDistribution = $productDistributionManager->findOneProductDistribution($distribution, $product);

if (!$productDistribution) {
$productDistribution = new ProductDistribution();
@@ -273,8 +279,7 @@ class OrderController extends BackendController
$productDistribution->quantity_max = null;
}


$productDistribution->save();
$productDistributionManager->saveCreate($productDistribution);
}

if (isset($_POST['Product'][$product->id]['active'])) {
@@ -289,20 +294,15 @@ class OrderController extends BackendController
$productDistribution->quantity_max = null;
}

$productDistribution->save();
$productDistributionManager->saveUpdate($productDistribution);
}
}
}

$arrayProductsSelected = [];
if ($distribution) {
// produits selec pour production
$arrayProductsSelected = ProductDistributionModel::searchByDistribution($distribution->id);
}

// produits
if ($distribution) {
$arrayProducts = Product::searchByDistribution($distribution->id);
$arrayProductsSelected = $productDistributionManager->findProductDistributionsByDistribution($distribution);
$arrayProducts = $productManager->findProductsByDistribution($distribution);
}

// poids total de la production et CA potentiel
@@ -319,21 +319,17 @@ class OrderController extends BackendController
}
}

// jours de distribution
$arrayDistributionDays = DistributionModel::searchAll([
'active' => 1
]);
$arrayDistributionDays = $distributionManager->findDistributionsActive();

// commandes auto
$subscriptionForm = new SubscriptionForm;
$subscriptionForm = new SubscriptionForm();

// productions point vente
$pointSaleDistribution = new PointSaleDistribution;

$pointSaleDistribution = new PointSaleDistribution();
$oointsSaleDistribution = [];

if ($distribution) {
$pointsSaleDistribution = PointSaleDistributionModel::searchAll([
$pointsSaleDistribution = PointSaleDistribution::searchAll([
'id_distribution' => $distribution->id
]);
}
@@ -364,7 +360,7 @@ class OrderController extends BackendController
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start));
$dateSunday = date('Y-m-d', strtotime('Sunday', $start));

$weekDistribution = DistributionModel::find()
$weekDistribution = Distribution::find()
->andWhere([
'id_producer' => GlobalParam::getCurrentProducerId(),
'active' => 1,
@@ -419,27 +415,22 @@ class OrderController extends BackendController
*/
public function actionDownload($date = '', $idPointSale = 0, $global = 0)
{
// commandes
$ordersArray = Order::searchAll([
'distribution.date' => $date
]);

// points de vente
$pointsSaleArray = PointSale::searchAll();
$orderManager = $this->getOrderManager();
$distributionManager = $this->getDistributionManager();
$pointSaleManager = $this->getPointSaleManager();
$productManager = $this->getProductManager();
$productDistributionManager = $this->getProductDistributionManager();

$distribution = $distributionManager->findOneDistributionByDate($date);
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution);
$productsArray = $productManager->findProducts();
$ordersArray = $orderManager->findOrdersByDate($date);

$pointsSaleArray = $pointSaleManager->findPointSales();
foreach ($pointsSaleArray as $pointSale) {
$pv->initOrders($ordersArray);
$pointSaleManager->initOrders($pointSale, $ordersArray);
}

// produits
$productsArray = Product::find()->orderBy('order ASC')->all();

$distribution = DistributionModel::find()
->where('date LIKE \':date\'')
->params([':date' => $date])
->one();

$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id);

/*
* export global
*/
@@ -472,7 +463,7 @@ class OrderController extends BackendController
$strProducts = '';
foreach ($productsArray as $product) {
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders);
$strQuantity = '';
if ($quantity) {
$strQuantity = $quantity;
@@ -492,7 +483,7 @@ class OrderController extends BackendController
$strProducts = '';
foreach ($productsArray as $product) {
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) {
$quantity = Order::getProductQuantity($product->id, $ordersArray);
$quantity = $orderManager->getProductQuantity($product, $ordersArray);
$strQuantity = '';
if ($quantity) {
$strQuantity = $quantity;
@@ -547,17 +538,17 @@ class OrderController extends BackendController
* @return array
* @see OrderController::actionDownload()
*/
public function contentRecapCSV($date, $products, $pointsSale, $orders)
public function contentRecapCSV(string $date, array $products, array $pointsSale, array $orders)
{
$orderManager = $this->getOrderManager();
$distributionManager = $this->getDistributionManager();
$productDistributionManager = $this->getProductDistributionManager();

$data = [];
$filename = 'summary_' . $date;

$distribution = DistributionModel::find()
->where('date LIKE \':date\'')
->params([':date' => $date])
->one();

$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id);
$distribution = $distributionManager->findOneDistributionByDate($date);
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution);

// head
$data[0] = ['Lieu'];
@@ -578,7 +569,7 @@ class OrderController extends BackendController
$dataAdd = [$pointSale->name];
foreach ($products as $product) {
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) {
$dataAdd[] = Order::getProductQuantity($product->id, $pointSale->orders);
$dataAdd[] = $orderManager->getProductQuantity($product, $pointSale->orders);
}
}
$data[] = $dataAdd;
@@ -588,7 +579,7 @@ class OrderController extends BackendController
$dataAdd = ['Total'];
foreach ($products as $product) {
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) {
$dataAdd[] = Order::getProductQuantity($product->id, $orders);
$dataAdd[] = $orderManager->getProductQuantity($product, $orders);
}
}
$data[] = $dataAdd;
@@ -611,10 +602,12 @@ class OrderController extends BackendController
*/
public function contentPointSaleCSV($date, $products, $pointsSale, $idPointSale)
{
$data = [];
$distributionManager = $this->getDistributionManager();
$productDistributionManager = $this->getProductDistributionManager();

$distribution = DistributionModel::find()->where('date LIKE \':date\'')->params([':date' => $date])->one();
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id);
$data = [];
$distribution = $distributionManager->findOneDistributionByDate($date);
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution);

// datas
foreach ($pointsSale as $pointSale) {
@@ -668,23 +661,13 @@ class OrderController extends BackendController
}

/**
* Change l'état d'un jour de production (activé, désactivé).
*
* @param string $date
* @param integer $actif
* @param boolean $redirect
* Change l'état d'un jour de distribution (activé, désactivé).
*/
public function actionChangeState($date, $active, $redirect = true)
public function actionChangeState(string $date, bool $active, bool $redirect = true)
{
// changement état
$distribution = DistributionModel::initDistribution($date);
$distribution->active = $active;
$distribution->save();

if ($active) {
// add commandes automatiques
Subscription::addAll($date);
}
$distributionManager = $this->getDistributionManager();
$distribution = $distributionManager->createDistributionIfNotExist($this->getProducerCurrent(), $date);
$distributionManager->activeDistribution($distribution, $active);

if ($redirect) {
$this->redirect(['index', 'date' => $date]);
@@ -693,12 +676,13 @@ class OrderController extends BackendController

/**
* Change l'état d'une semaine de production (activé, désactivé).
*
* @param string $date
* @param integer $actif
*/
public function actionChangeStateWeek($date, $active)
public function actionChangeStateWeek(string $date, bool $active)
{
$pointSaleManager = $this->getPointSaleManager();

$pointsSaleArray = $pointSaleManager->findPointSales();

$week = sprintf('%02d', date('W', strtotime($date)));
$start = strtotime(date('Y', strtotime($date)) . 'W' . $week);
$dateMonday = date('Y-m-d', strtotime('Monday', $start));
@@ -709,8 +693,6 @@ class OrderController extends BackendController
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start));
$dateSunday = date('Y-m-d', strtotime('Sunday', $start));

$pointsSaleArray = PointSale::searchAll();

$activeMonday = false;
$activeTuesday = false;
$activeWednesday = false;
@@ -742,21 +724,16 @@ class OrderController extends BackendController

/**
* Supprime une commande via une requête AJAX.
*
* @param string $date
* @param integer $idOrder
*/
public function actionAjaxDelete($idOrder)
public function actionAjaxDelete(int $idOrder)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$order = Order::searchOne([
'id' => $idOrder
]);
$orderManager = $this->getOrderManager();

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

return ['success'];
@@ -765,29 +742,14 @@ class OrderController extends BackendController

/**
* Supprime une commande.
*
* @param string $date
* @param integer $idOrder
*/
public function actionDelete($date, $idOrder)
public function actionDelete(string $date, int $idOrder)
{
$order = Order::searchOne(['id' => $idOrder]);
$orderManager = $this->getOrderManager();

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

// remboursement de la commande
if ($order->id_user && $order->getAmount(Order::AMOUNT_PAID) && Producer::getConfig('credit')) {
$order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
$order->id_user,
GlobalParam::getCurrentUserId()
);
}

$order->delete();
ProductOrder::deleteAll(['id_order' => $idOrder]);
$orderManager->deleteOrder($order);
}

$this->redirect(['index', 'date' => $date]);
@@ -809,17 +771,24 @@ class OrderController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$distributionManager = $this->getDistributionManager();
$pointSaleManager = $this->getPointSaleManager();
$userPointSaleManager = $this->getUserPointSaleManager();
$userManager = $this->getUserManager();
$userProducerManager = $this->getUserProducerManager();
$producerManager = $this->getProducerManager();
$productManager = $this->getProductManager();
$orderManager = $this->getOrderManager();

$products = json_decode($products);
$pointSale = PointSale::findOne($idPointSale);
$distribution = DistributionModel::searchOne([
'date' => $date
]);
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale);
$distribution = $distributionManager->findOneDistributionByDate($date);

if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date) &&
($idUser || strlen($username)) &&
$pointSale &&
count(get_object_vars($products)) &&
$distribution) {
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date)
&& ($idUser || strlen($username))
&& $pointSale
&& count(get_object_vars($products))
&& $distribution) {

$order = new Order;
$order->date = date('Y-m-d H:i:s');
@@ -834,10 +803,7 @@ class OrderController extends BackendController
$order->id_user = $idUser;

// commentaire du point de vente
$userPointSale = UserPointSale::searchOne([
'id_point_sale' => $idPointSale,
'id_user' => $idUser
]);
$userPointSale = $userPointSaleManager->findOneUserPointSale($userManager->findOneUserById($idUser), $pointSale);

if ($userPointSale && strlen($userPointSale->comment)) {
$order->comment_point_sale = $userPointSale->comment;
@@ -853,14 +819,15 @@ class OrderController extends BackendController
$userProducer = false;
if (isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = UserProducer::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]);

$userProducer = $userProducerManager->findOneUserProducer(
$user,
$producerManager->findOneProducerById($order->distribution->id_producer)
);
}

foreach ($products as $key => $dataProductOrder) {
$product = Product::findOne($key);
$product = $productManager->findOneProductById($key);
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient'];
if ($product && $quantity) {
$productOrder = new ProductOrder;
@@ -872,7 +839,7 @@ class OrderController extends BackendController
if ($dataProductOrder->price) {
$productOrder->price = $dataProductOrder->price;
} else {
$productOrder->price = $product->getPrice([
$productOrder->price = $productManager->getPrice($product, [
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $order->pointSale,
@@ -884,19 +851,19 @@ class OrderController extends BackendController
}
}

$order = Order::searchOne(['id' => $order->id]);
$order = $orderManager->findOneOrderById($order);
if ($order && $processCredit) {
$order->processCredit();
$orderManager->processCredit($order);
}

if ($order) {
$order->initReference();
$order->setTillerSynchronization();
$orderManager->generateOrderReference($order);
$orderManager->updateOrderTillerSynchronization($order);
}

// lien utilisateur / point de vente
if ($idUser && $pointSale) {
$pointSale->linkUser($idUser);
$pointSaleManager->addUser($pointSale, $user);
}
}

@@ -913,8 +880,14 @@ class OrderController extends BackendController
*/
public function actionAjaxUpdate()
{
$request = Yii::$app->request;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$orderManager = $this->getOrderManager();
$userManager = $this->getUserManager();
$pointSaleManager = $this->getPointSaleManager();
$userPointSaleManager = $this->getUserPointSaleManager();

$request = \Yii::$app->request;
$date = $request->post('date');
$idOrder = $request->post('idOrder');
$idPointSale = $request->post('idPointSale');
@@ -925,12 +898,12 @@ class OrderController extends BackendController
$comment = $request->post('comment');
$processCredit = $request->post('processCredit');

\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$order = $orderManager->findOneOrderById($idOrder);
$user = $userManager->findOneUserById($idUser);
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale);

$order = Order::searchOne(['id' => $idOrder]);

if ($order &&
$order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {
if ($order
&& $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {

$oldIdUser = $order->id_user;
if ($idUser) {
@@ -938,11 +911,7 @@ class OrderController extends BackendController
$order->id_user = $idUser;

// commentaire du point de vente
$userPointSale = UserPointSale::searchOne([
'id_point_sale' => $order->id_point_sale,
'id_user' => $idUser
]);

$userPointSale = $userPointSaleManager->findOneUserPointSale($user, $pointSale);
if ($userPointSale && strlen($userPointSale->comment)) {
$order->comment_point_sale = $userPointSale->comment;
}
@@ -1037,10 +1006,8 @@ class OrderController extends BackendController

/**
* Retourne l'état du paiement (historique, crédit) d'une commande donnée.
*
* @param integer $idOrder
*/
public function actionPaymentStatus($idOrder)
public function actionPaymentStatus(int $idOrder)
{
$creditHistoryManager = $this->getCreditHistoryManager();
$order = Order::searchOne(['id' => $idOrder]);
@@ -1116,27 +1083,23 @@ class OrderController extends BackendController

/**
* Effectue le paiement/remboursement d'une commande.
*
* @param integer $idOrder
* @param string $type
* @param float $amount
* @return string
*/
public function actionAjaxPayment($idOrder, $type, $amount)
public function actionAjaxPayment(int $idOrder, string $type, float $amount): array
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$order = Order::searchOne([
'id' => $idOrder
]);
$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();

$order = $orderManager->findOneOrderById($idOrder);

if ($order) {
$order->saveCreditHistory(
$creditHistoryManager->createCreditHistory(
$type,
$amount,
GlobalParam::getCurrentProducerId(),
$order->id_user,
GlobalParam::getCurrentUserId()
GlobalParam::getCurrentProducer(),
$order->user,
GlobalParam::getCurrentUser()
);
}

@@ -1145,22 +1108,16 @@ class OrderController extends BackendController

/**
* Modifie l'état de la synchronisation Tiller d'une commande.
*
* @param int $idOrder
* @param boolean $boolSynchroTiller
* @return array
*/
public function actionAjaxChangeSynchroTiller($idOrder, $boolSynchroTiller)
public function actionAjaxChangeSynchroTiller(int $idOrder, bool $boolSynchroTiller): array
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$order = Order::searchOne([
'id' => (int)$idOrder
]);
$orderManager = $this->getOrderManager();

$order = $orderManager->findOneOrderById($idOrder);
if ($order) {
$order->tiller_synchronization = (int)$boolSynchroTiller;
$res = $order->save();
$orderManager->updateOrderTillerSynchronization($order, (int) $boolSynchroTiller);
return ['success'];
}


+ 2
- 0
backend/controllers/PointSaleController.php Zobrazit soubor

@@ -38,6 +38,8 @@

namespace backend\controllers;

use common\logic\PointSale\PointSale\PointSale;
use common\logic\PointSale\PointSale\PointSaleSearch;
use Yii;
use yii\filters\AccessControl;
use yii\web\NotFoundHttpException;

+ 7
- 0
common/logic/Distribution/Distribution/DistributionRepository.php Zobrazit soubor

@@ -58,6 +58,13 @@ class DistributionRepository extends BaseService implements RepositoryInterface
]);
}

public function findDistributionsActive(): array
{
return Distribution::searchAll([
'active' => 1
]);
}

/**
* Récupère les distributions futures.
*/

+ 2
- 3
common/logic/Distribution/ProductDistribution/ProductDistributionBuilder.php Zobrazit soubor

@@ -35,9 +35,8 @@ class ProductDistributionBuilder extends BaseBuilder implements BuilderInterface
{
$productDistribution = $this->instanciateProductDistribution($distribution, $product);

$this
->initActive($productDistribution)
->initQuantityMax($productDistribution);
$this->initActive($productDistribution);
$this->initQuantityMax($productDistribution);

$this->saveCreate($productDistribution);


+ 6
- 0
common/logic/Document/DeliveryNote/DeliveryNoteRepository.php Zobrazit soubor

@@ -3,6 +3,7 @@
namespace common\logic\PointSale\PointSale;

use common\logic\BaseService;
use common\logic\Document\DeliveryNote\DeliveryNote;
use common\logic\RepositoryInterface;

class DeliveryNoteRepository extends BaseService implements RepositoryInterface
@@ -16,4 +17,9 @@ class DeliveryNoteRepository extends BaseService implements RepositoryInterface
'attribute_id_producer' => 'delivery_note.id_producer'
];
}

public function findOneDeliveryNoteById(int $id): ?DeliveryNote
{
return DeliveryNote::searchOne(['id' => $id]);
}
}

+ 6
- 0
common/logic/Document/Invoice/InvoiceRepository.php Zobrazit soubor

@@ -3,6 +3,7 @@
namespace common\logic\PointSale\PointSale;

use common\logic\BaseService;
use common\logic\Document\Invoice\Invoice;
use common\logic\RepositoryInterface;

class InvoiceRepository extends BaseService implements RepositoryInterface
@@ -16,4 +17,9 @@ class InvoiceRepository extends BaseService implements RepositoryInterface
'attribute_id_producer' => 'invoice.id_producer'
];
}

public function findOneInvoiceById(int $id): ?Invoice
{
return Invoice::searchOne(['id' => $id]);
}
}

+ 11
- 6
common/logic/Order/Order/OrderBuilder.php Zobrazit soubor

@@ -500,14 +500,19 @@ class OrderBuilder extends BaseBuilder implements BuilderInterface

// setTillerSynchronization
// updateTillerSynchronization
public function updateOrderTillerSynchronization(Order $order): void
public function updateOrderTillerSynchronization(Order $order, int $synchroTiller = null): void
{
$paymentStatus = $order->getPaymentStatus();
if(!is_null($synchroTiller)) {
$order->tiller_synchronization = $synchroTiller;
}
else {
$paymentStatus = $order->getPaymentStatus();

if ($paymentStatus == Order::PAYMENT_PAID) {
$order->tiller_synchronization = 1;
} else {
$order->tiller_synchronization = 0;
if ($paymentStatus == Order::PAYMENT_PAID) {
$order->tiller_synchronization = 1;
} else {
$order->tiller_synchronization = 0;
}
}

$this->saveUpdate($order);

+ 7
- 0
common/logic/Order/Order/OrderRepository.php Zobrazit soubor

@@ -51,6 +51,13 @@ class OrderRepository extends BaseService implements RepositoryInterface
return Order::searchOne(['order.id' => $id]);;
}

public function findOrdersByDate(string $date): array
{
return Order::searchAll([
'distribution.date' => $date
]);
}

/**
* Recherche et initialise des commandes.
*/

+ 7
- 0
common/logic/Order/ProductOrder/ProductOrderRepository.php Zobrazit soubor

@@ -18,6 +18,13 @@ class ProductOrderRepository extends BaseService implements RepositoryInterface
];
}

public function findOneProductOrderById(int $id)
{
return $productOrder = ProductOrder::searchOne([
'id' => $id
]);
}

public function findProductOrdersByOrder(Order $order): array
{
return ProductOrder::find()->where(['id_order' => $order->id])->all();

+ 7
- 0
common/logic/PointSale/PointSale/PointSaleRepository.php Zobrazit soubor

@@ -26,6 +26,13 @@ class PointSaleRepository extends BaseService implements RepositoryInterface
return PointSale::searchOne(['id' => $id]);
}

public function findOnePointSaleByIdUser(int $idUser): ?PointSale
{
return PointSale::searchOne([
'id_user' => $idUser
]);
}

public function findPointSalesByDistribution(Distribution $distribution)
{
return PointSale::find()

+ 4
- 0
producer/controllers/SubscriptionController.php Zobrazit soubor

@@ -291,6 +291,10 @@ class SubscriptionController extends ProducerBaseController
]),
]
);

if($product['unit'] == 'piece' && is_null($product['step'])) {
$product['step'] = 1;
}
}

$params['products'] = $productsArray;

Načítá se…
Zrušit
Uložit