Просмотр исходного кода

Refactoring services #885

refactoring
Guillaume 1 год назад
Родитель
Сommit
8e875989af
8 измененных файлов: 328 добавлений и 259 удалений
  1. +19
    -0
      common/logic/Distribution/Distribution/DistributionRepository.php
  2. +33
    -24
      common/logic/Distribution/Distribution/DistributionSolver.php
  3. +27
    -2
      common/logic/Order/Order/OrderRepository.php
  4. +6
    -0
      common/logic/Order/Order/OrderSolver.php
  5. +1
    -1
      common/logic/PointSale/PointSale/PointSaleContainer.php
  6. +10
    -0
      common/logic/Product/Product/ProductRepository.php
  7. +11
    -0
      common/logic/Product/ProductCategory/ProductCategoryRepository.php
  8. +221
    -232
      producer/controllers/OrderController.php

+ 19
- 0
common/logic/Distribution/Distribution/DistributionRepository.php Просмотреть файл

@@ -9,6 +9,13 @@ use common\logic\RepositoryInterface;

class DistributionRepository extends BaseService implements RepositoryInterface
{
protected DistributionSolver $distributionSolver;

public function __construct()
{
$this->distributionSolver = $this->loadService(DistributionSolver::class);
}

public function defaultOptionsSearch(): array
{
return [
@@ -59,4 +66,16 @@ class DistributionRepository extends BaseService implements RepositoryInterface

return $distributionsArray;
}
public function isDateAvailable(Producer $producer, string $date = null): bool
{
if($date && strlen($date)) {
$distribution = $this->getOne($producer, $date);
if($distribution && $this->distributionSolver->isAvailable($distribution)) {
return true;
}
}
return false;
}
}

+ 33
- 24
common/logic/Distribution/Distribution/DistributionSolver.php Просмотреть файл

@@ -47,39 +47,48 @@ class DistributionSolver extends BaseService implements SolverInterface
return false;
}

/**
* Filtre les distributions par délai de commande.
*/
public function filterDistributionsByDateDelay(array $distributionsArray): array
public function isAvailable(Distribution $distribution): bool
{
$producer = GlobalParam::getCurrentProducer();
$dateToday = date('Y-m-d');
$producer = $distribution->producer;
$dateDistribution = $distribution->date;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution)));
$fieldDayDistributionDelay = 'order_delay_' . $dayDistribution;
$fieldDayDistributionDeadline = 'order_deadline_' . $dayDistribution;

foreach ($distributionsArray as $keyDistribution => $distribution) {
$delay = $producer->order_delay;
$deadline = $producer->order_deadline;

$dateDistribution = $distribution->date;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution)));
$fieldDayDistributionDelay = 'order_delay_' . $dayDistribution;
$fieldDayDistributionDeadline = 'order_deadline_' . $dayDistribution;
if ($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay;
}

$delay = $producer->order_delay;
$deadline = $producer->order_deadline;
if ($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline;
}

if ($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay;
}
$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60), 0);

if ($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline;
}
if(date('H') >= $deadline) {
$countDaysTodayDistribution--;
}

$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60), 0);
if ($countDaysTodayDistribution < $delay) {
return false;
}

if (date('H') >= $deadline) {
$countDaysTodayDistribution--;
}
return true;
}

/**
* Filtre les distributions par délai de commande.
*/
public function filterDistributionsByDateDelay(array $distributionsArray): array
{
$producer = GlobalParam::getCurrentProducer();
$dateToday = date('Y-m-d');

if ($countDaysTodayDistribution < $delay) {
foreach ($distributionsArray as $keyDistribution => $distribution) {
if(!$this->isAvailable($distribution)) {
unset($distributionsArray[$keyDistribution]);
}
}

+ 27
- 2
common/logic/Order/Order/OrderRepository.php Просмотреть файл

@@ -10,6 +10,7 @@ use common\logic\Producer\Producer\Producer;
use common\logic\Producer\Producer\ProducerRepository;
use common\logic\Product\Product\Product;
use common\logic\RepositoryInterface;
use common\logic\User\User\User;
use yii\helpers\Html;

class OrderRepository extends BaseService implements RepositoryInterface
@@ -41,9 +42,9 @@ class OrderRepository extends BaseService implements RepositoryInterface
];
}

public function getOneById(Order $order)
public function getOneById(int $id)
{
return Order::searchOne(['order.id' => $order->id]);;
return Order::searchOne(['order.id' => $id]);;
}

/**
@@ -89,6 +90,30 @@ class OrderRepository extends BaseService implements RepositoryInterface
'conditions' => 'date_delete IS NULL ' . $conditionAppend
]);
}
public function queryHistory(Producer $producer, User $user, string $type = 'incoming')
{
$query = Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
->joinWith('distribution', 'distribution.producer')
->where([
'id_user' => $user->id,
'distribution.id_producer' => $producer->id
])
->params([':date_today' => date('Y-m-d')]);

$queryIncoming = clone $query;
$queryIncoming
->andWhere('distribution.date >= :date_today')
->orderBy('distribution.date ASC');

$queryPassed = clone $query;
$queryPassed
->andWhere('distribution.date < :date_today')
->orderBy('distribution.date DESC');

return ['incoming' => $queryIncoming, 'passed' => $queryPassed];
}

/**
* Retourne les informations relatives à la commande au format JSON.

+ 6
- 0
common/logic/Order/Order/OrderSolver.php Просмотреть файл

@@ -11,6 +11,7 @@ use common\logic\Order\ProductOrder\ProductOrder;
use common\logic\Producer\Producer\Producer;
use common\logic\Product\Product\Product;
use common\logic\SolverInterface;
use common\logic\User\User\User;
use yii\helpers\Html;

class OrderSolver extends BaseService implements SolverInterface
@@ -379,4 +380,9 @@ class OrderSolver extends BaseService implements SolverInterface
{
return Order::STATE_DELIVERED == $order->getState();
}

public function belongsToUser(Order $order, User $user): bool
{
return $order->id_user == $user->id;
}
}

+ 1
- 1
common/logic/PointSale/PointSale/PointSaleContainer.php Просмотреть файл

@@ -25,7 +25,7 @@ class PointSaleContainer implements ContainerInterface
return new PointSaleSolver();
}

public function getRepostory(): PointSaleRepository
public function getRepository(): PointSaleRepository
{
return new PointSaleRepository();
}

+ 10
- 0
common/logic/Product/Product/ProductRepository.php Просмотреть файл

@@ -6,6 +6,7 @@ use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Producer\Producer\Producer;
use common\logic\Product\ProductCategory\ProductCategory;
use common\logic\Product\ProductPrice\ProductPriceSolver;
use common\logic\RepositoryInterface;
@@ -136,4 +137,13 @@ class ProductRepository extends BaseService implements RepositoryInterface
'order ASC'
);
}

public function countProductsWithoutCategory(Producer $producer): int
{
return Product::searchCount([
'id_producer' => $producer->id,
'product.active' => 1,
'product.id_product_category' => null
]);
}
}

+ 11
- 0
common/logic/Product/ProductCategory/ProductCategoryRepository.php Просмотреть файл

@@ -23,6 +23,17 @@ class ProductCategoryRepository extends BaseService implements RepositoryInterfa
return ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);
}

public function getAsArray()
{
return ProductCategory::searchAll(
[],
[
'orderby' => 'product_category.position ASC',
'as_array' => true
]
);
}

public function populateDropdownList()
{
$productCategoriesArrayDropdown = ['' => '--'];

+ 221
- 232
producer/controllers/OrderController.php Просмотреть файл

@@ -40,12 +40,15 @@ namespace producer\controllers;

use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\Order\Order\Order;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistory;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;
use DateTime;
use yii\base\UserException;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;

@@ -69,21 +72,13 @@ class OrderController extends ProducerBaseController
);
}

if ($id) {
$order = $this->getOrderContainer()->getRepository()->getOneById($id);
if ($order && $this->getOrderContainer()->getSolver()->isStateOpen($order)) {
$params['order'] = $order;
}
$order = $this->getOrderContainer()->getRepository()->getOneById($id);
if ($order && $this->getOrderContainer()->getSolver()->isStateOpen($order)) {
$params['order'] = $order;
}

if (strlen($date)) {
$distribution = $this->getDistributionContainer()->getRepository()->getOne($producer, $date);
if ($distribution) {
$distributionsArray = $this->getDistributionContainer()->getSolver()->filterDistributionsByDateDelay([$distribution]);
if (count($distributionsArray) == 1) {
$params['date'] = $date;
}
}
if ($this->getDistributionContainer()->getRepository()->isDateAvailable($producer, $date)) {
$params['date'] = $date;
}

return $this->render('order', $params);
@@ -94,25 +89,13 @@ class OrderController extends ProducerBaseController
*/
public function actionHistory($type = 'incoming')
{
$producer = $this->getProducer();

$query = Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
->joinWith('distribution', 'distribution.producer')
->where([
'id_user' => $this->getUserCurrent()->id,
'distribution.id_producer' => $producer->id
])
->params([':date_today' => date('Y-m-d')]);

$queryIncoming = clone $query;
$queryIncoming->andWhere('distribution.date >= :date_today')->orderBy('distribution.date ASC');

$queryPassed = clone $query;
$queryPassed->andWhere('distribution.date < :date_today')->orderBy('distribution.date DESC');
$queryHistoryArray = $this->getOrderContainer()->getRepository()
->queryHistory($this->getProducer(), $this->getUserCurrent(), $type);
$queryHistoryIncoming = $queryHistoryArray['incoming'];
$queryHistoryPassed = $queryHistoryArray['passed'];

$dataProviderOrders = new ActiveDataProvider([
'query' => ($type == 'incoming') ? $queryIncoming : $queryPassed,
'query' => ($type == 'incoming') ? $queryHistoryIncoming : $queryHistoryPassed,
'pagination' => [
'pageSize' => 10,
],
@@ -123,8 +106,8 @@ class OrderController extends ProducerBaseController
'orderOk' => \Yii::$app->getRequest()->get('orderOk', false),
'cancelOk' => \Yii::$app->getRequest()->get('cancelOk', false),
'type' => $type,
'countIncoming' => $queryIncoming->count(),
'countPassed' => $queryPassed->count(),
'countIncoming' => $queryHistoryIncoming->count(),
'countPassed' => $queryHistoryPassed->count(),
]);
}

@@ -569,75 +552,105 @@ class OrderController extends ProducerBaseController

/**
* Annule une commande.
*
* @param integer $id
* @throws \yii\web\NotFoundHttpException
* @throws UserException
*/
public function actionCancel($id)
public function actionCancel(int $id)
{
$order = Order::searchOne([
'id' => $id
]);
$orderContainer = $this->getOrderContainer();
$order = $orderContainer->getRepository()->getOneById($id);

if (!$order) {
throw new \yii\web\NotFoundHttpException('Commande introuvable');
}

if ($order->getState() != Order::STATE_OPEN) {
if ($orderContainer->getSolver()->isStateOpen($order)) {
throw new UserException('Vous ne pouvez plus annuler cette commande.');
}

if ($order && GlobalParam::getCurrentUserId() == $order->id_user) {
$order->delete();
if ($orderContainer->getSolver()->belongsToUser($order, GlobalParam::getCurrentUser())) {
$orderContainer->getBuilder()->delete($order);
\Yii::$app->session->setFlash('success', 'Votre commande a bien été annulée.');
}

$this->redirect(\Yii::$app->urlManager->createUrl(['order/history']));
}

/**
* Page de confirmation de commande.
*/
public function actionConfirm($idOrder, $returnPayment = '')
{
$order = Order::searchOne(['id' => $idOrder]);
$producer = $this->getProducer();

if (!$order || ($order->id_user != GlobalParam::getCurrentUserId() && !$producer->option_allow_order_guest)) {
throw new \yii\base\UserException('Commande introuvable.');
}

return $this->render('confirm', [
'order' => $order,
'returnPayment' => $returnPayment
]);
}

/**
* Vérifie le code saisi pour un point de vente.
*
* @param integer $idPointSale
* @param string $code
* @return boolean
*/
public function actionAjaxValidateCodePointSale($idPointSale, $code)
public function actionAjaxValidateCodePointSale(int $idPointSale, string $code)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$pointSaleContainer = $this->getPointSaleContainer();
$pointSale = $pointSaleContainer->getRepostory()->getOneById($idPointSale);

$pointSale = PointSale::findOne($idPointSale);
if ($pointSale) {
if ($pointSale->validateCode($code)) {
return 1;
}
if ($pointSale && $pointSaleContainer->getSolver()->validateCode($pointSale, $code)) {
return 1;
}

return 0;
}

public function actionAjaxInfos($date = '', $pointSaleId = 0)
public function actionAjaxInfos(string $date = '', int $pointSaleId = 0)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = GlobalParam::getCurrentUser();
$producer = $this->getProducer();
$pointSale = $this->getPointSaleContainer()->getRepository()->getOneById($pointSaleId);
$order = $this->getOrderUser($date, $pointSale);

return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order);
}
public function buildJsonAjaxInfos(
string $date,
Producer $producer,
PointSale $pointSale = null,
User $user = null,
Order $order = null
)
{
$json = [];

$format = 'Y-m-d';
$dateObject = DateTime::createFromFormat($format, $date);

$user = User::getCurrent();
$json['producer'] = $this->ajaxInfosProducer($producer);
$json['distributions'] = $this->ajaxInfosDistributions($producer, $pointSale);
$json['orders'] = $this->ajaxInfosOrders($producer);
$json['user'] = $this->ajaxInfosUser($producer);
$json['points_sale'] = $this->ajaxInfosPointsSale($producer);

// PointSale current
$pointSaleCurrent = PointSale::findOne($pointSaleId);
if ($dateObject && $dateObject->format($format) === $date) {
$distribution = $this->getDistributionContainer()->getBuilder()->createIfNotExist($producer, $date);
$json['distribution'] = $distribution;
$json['points_sale'] = $this->ajaxInfosPointsSale($producer, $distribution);
$json['categories'] = $this->ajaxInfosProductCategories($producer);
$json['products'] = $this->ajaxInfosProducts($producer, $distribution, $pointSale, $user, $order);
}

// Commande de l'utilisateur
$orderUser = $this->_getOrderUser($date, $pointSaleId);
return $json;
}

// Producteur
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
]);
$json['producer'] = [
public function ajaxInfosProducer(Producer $producer)
{
return [
'order_infos' => $producer->order_infos,
'credit' => $producer->credit,
'credit_functioning' => $producer->credit_functioning,
@@ -649,8 +662,10 @@ class OrderController extends ProducerBaseController
'online_payment' => $producer->online_payment,
'option_online_payment_type' => $producer->online_payment
];
}

// Distributions
public function ajaxInfosDistributions(Producer $producer, PointSale $pointSaleCurrent = null)
{
$dateMini = date('Y-m-d');

$distributionsArray = DistributionModel::searchAll([
@@ -684,12 +699,14 @@ class OrderController extends ProducerBaseController
}
}

$json['distributions'] = $distributionsArrayFilterPointSale;
return $distributionsArrayFilterPointSale;
} else {
$json['distributions'] = $distributionsArray;
return $distributionsArray;
}
}

// Commandes de l'utilisateur
public function ajaxInfosOrders(Producer $producer): array
{
$ordersUserArray = [];
if (GlobalParam::getCurrentUserId() && !$producer->isOnlinePaymentActiveAndTypeOrder()) {
$conditionsOrdersUser = [
@@ -720,10 +737,13 @@ class OrderController extends ProducerBaseController
'pointSale' => $order->pointSale->getAttributes()
]);
}
$json['orders'] = $ordersUserArray;
}

// User
return $ordersUserArray;
}

public function ajaxInfosUser(Producer $producer)
{
$userProducer = UserProducer::searchOne([
'id_producer' => $producer->id,
'id_user' => GlobalParam::getCurrentUserId()
@@ -733,167 +753,19 @@ class OrderController extends ProducerBaseController
$userProducer = Producer::addUser($user->id, $producer->id);
}

$json['user'] = false;
$jsonUser = false;
if ($user && $userProducer) {
$json['user'] = [
$jsonUser = [
'address' => $user->address,
'credit' => $userProducer->credit,
'credit_active' => $userProducer->credit_active,
];
}

if ($dateObject && $dateObject->format($format) === $date) {
// distribution
$distribution = DistributionModel::initDistribution($date, $producer->id);
$json['distribution'] = $distribution;

// Points de vente
$json['points_sale'] = $this->_initPointsSale($producer->id, $distribution);

// Commandes totales
$ordersArray = Order::searchAll([
'distribution.date' => $date,
]);

// Catégories
$categoriesArray = ProductCategory::searchAll(
[],
[
'orderby' => 'product_category.position ASC',
'as_array' => true
]
);
$countProductsWithoutCategories = Product::searchCount([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
'product.id_product_category' => null
]);
if ($countProductsWithoutCategories) {
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']);
}
$json['categories'] = $categoriesArray;

// Produits
$productsArray = Product::find()
->where([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
]);

$productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id
);
},
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
'productPrice'
])
->orderBy('product_distribution.active DESC, order ASC')
->all();

$productsArrayFilter = [];

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

$indexProduct = 0;
foreach ($productsArrayFilter as $key => &$product) {
$product = array_merge(
$product->getAttributes(),
[
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($user, $pointSaleCurrent),
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
]
);

$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'];

if (is_null($product['photo'])) {
$product['photo'] = '';
}

$product['quantity_max'] = $product['productDistribution'][0]['quantity_max'];
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray);
$product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true);

if ($orderUser) {
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true);
$product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser;
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit;
foreach ($orderUser->productOrder as $productOrder) {
if ($productOrder->id_product == $product['id']) {
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true);
$product['step'] = $productOrder->step;
}
}
} else {
$product['quantity_form'] = 0;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
}
$product['coefficient_unit'] = $coefficient_unit;

if ($product['quantity_remaining'] < 0) {
$product['quantity_remaining'] = 0;
}
$product['index'] = $indexProduct++;
}

$json['products'] = $productsArrayFilter;
} else {
$json['points_sale'] = $this->_initPointsSale($producer->id);
}

return $json;
}

private function _getOrderUser($date, $pointSaleId = false)
{
$orderUser = false;
if (GlobalParam::getCurrentUserId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => GlobalParam::getCurrentUserId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

return $orderUser;
return $jsonUser;
}

private function _initPointsSale($idProducer, $distribution = false)
private function ajaxInfosPointsSale($idProducer, $distribution = false)
{
$pointsSaleArray = PointSale::find();

@@ -983,20 +855,137 @@ class OrderController extends ProducerBaseController
return $pointsSaleArray;
}

public function actionConfirm($idOrder, $returnPayment = '')
public function ajaxInfosProductCategories(Producer $producer)
{
$order = Order::searchOne(['id' => $idOrder]);
$producer = $this->getProducer();
$categoriesArray = $this->getProductCategoryContainer()->getRepository()
->getAsArray();
$countProductsWithoutCategory = $this->getProductContainer()->getRepository()
->countProductsWithoutCategory($producer);

if (!$order || ($order->id_user != GlobalParam::getCurrentUserId() && !$producer->option_allow_order_guest)) {
throw new \yii\base\UserException('Commande introuvable.');
if ($countProductsWithoutCategory) {
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']);
}

return $this->render('confirm', [
'order' => $order,
'returnPayment' => $returnPayment
]);
return $categoriesArray;
}

public function ajaxInfosProducts(
Producer $producer,
Distribution $distribution,
PointSale $pointSale,
User $user = null,
Order $order = null
)
{
$ordersArray = $this->getOrderContainer()->getRepository()->getByDistribution($distribution);

$productsArray = Product::find()
->where([
'id_producer' => $producer->id,
'product.active' => 1,
]);

$productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id
);
},
'productPrice'
])
->orderBy('product_distribution.active DESC, order ASC')
->all();

$productsArrayFilter = [];

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

$indexProduct = 0;
foreach ($productsArrayFilter as $key => &$product) {
$product = array_merge(
$product->getAttributes(),
[
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($user, $pointSale),
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
]
);

$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'];

if (is_null($product['photo'])) {
$product['photo'] = '';
}

$product['quantity_max'] = $product['productDistribution'][0]['quantity_max'];
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray);
$product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true);

if ($order) {
$quantityOrderUser = Order::getProductQuantity($product['id'], [$order], true);
$product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser;
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit;
foreach ($order->productOrder as $productOrder) {
if ($productOrder->id_product == $product['id']) {
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true);
$product['step'] = $productOrder->step;
}
}
} else {
$product['quantity_form'] = 0;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
}
$product['coefficient_unit'] = $coefficient_unit;

if ($product['quantity_remaining'] < 0) {
$product['quantity_remaining'] = 0;
}
$product['index'] = $indexProduct++;
}

return $productsArrayFilter;
}

private function getOrderUser(string $date, PointSale $pointSale = null)
{
$orderUser = false;
if (GlobalParam::getCurrentUserId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => GlobalParam::getCurrentUserId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

return $orderUser;
}
}


Загрузка…
Отмена
Сохранить