public static function getVersions() | public static function getVersions() | ||||
{ | { | ||||
$versionsArray = []; | $versionsArray = []; | ||||
$pathVersions = Yii::getAlias('@common/versions'); | |||||
$pathVersions = \Yii::getAlias('@common/versions'); | |||||
if(is_dir($pathVersions)) | if(is_dir($pathVersions)) | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
krsort($versionsArray); | |||||
ksort($versionsArray); | |||||
return $versionsArray; | return $versionsArray; | ||||
} | } |
return Order::STATE_PREPARATION; | return Order::STATE_PREPARATION; | ||||
} | } | ||||
public function isOrderStateOpen(Order $order): bool | |||||
{ | |||||
return Order::STATE_OPEN == $this->getState($order); | |||||
} | |||||
public function isOrderStatePreparation(Order $order): bool | |||||
{ | |||||
return Order::STATE_PREPARATION == $this->getState($order); | |||||
} | |||||
public function isOrderStateDelivered(Order $order): bool | |||||
{ | |||||
return Order::STATE_DELIVERED == $this->getState($order); | |||||
} | |||||
public function findOneOrderLastOfYear(Producer $producer) | public function findOneOrderLastOfYear(Producer $producer) | ||||
{ | { | ||||
return Order::find()->innerJoinWith('distribution', true) | return Order::find()->innerJoinWith('distribution', true) |
} | } | ||||
} | } | ||||
public function isOrderStateOpen(Order $order): bool | |||||
{ | |||||
return Order::STATE_OPEN == $order->getState(); | |||||
} | |||||
public function isOrderStatePreparation(Order $order): bool | |||||
{ | |||||
return Order::STATE_PREPARATION == $order->getState(); | |||||
} | |||||
public function isOrderStateDelivered(Order $order): bool | |||||
{ | |||||
return Order::STATE_DELIVERED == $order->getState(); | |||||
} | |||||
// belongsToUser | // belongsToUser | ||||
public function isOrderBelongsToUser(Order $order, User $user = null): bool | public function isOrderBelongsToUser(Order $order, User $user = null): bool | ||||
{ | { |
public function updateOpendistribVersion(Producer $producer): void | public function updateOpendistribVersion(Producer $producer): void | ||||
{ | { | ||||
$versionsArray = Opendistrib::getVersions(); | $versionsArray = Opendistrib::getVersions(); | ||||
$producer->latest_version_opendistrib = array_values($versionsArray)[0]; | |||||
$producer->latest_version_opendistrib = $versionsArray[0]; | |||||
$this->saveUpdate($producer); | $this->saveUpdate($producer); | ||||
} | } |
// getByDistribution | // getByDistribution | ||||
public function findProductsByDistribution(Distribution $distribution) | public function findProductsByDistribution(Distribution $distribution) | ||||
{ | { | ||||
return Product::find() | |||||
$productArray = Product::find() | |||||
->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
]) | ]) | ||||
->orderBy('product_distribution.active DESC, product.order ASC') | ->orderBy('product_distribution.active DESC, product.order ASC') | ||||
->all(); | ->all(); | ||||
$productArrayById = []; | |||||
foreach($productArray as $product) { | |||||
$productArrayById[$product->id] = $product; | |||||
} | |||||
return $productArrayById; | |||||
} | } | ||||
// queryByProductCategory | // queryByProductCategory |
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use common\logic\User\User\Service\UserSolver; | use common\logic\User\User\Service\UserSolver; | ||||
use common\logic\User\UserGroup\Model\UserGroup; | |||||
class ProductPriceSolver extends AbstractService implements SolverInterface | class ProductPriceSolver extends AbstractService implements SolverInterface | ||||
{ | { | ||||
public function matchUserGroup(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool | public function matchUserGroup(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool | ||||
{ | { | ||||
// @TODO : trouver une solution pour hydrater autrement cette donnée | |||||
if($productPrice->id_user_group && !$productPrice->userGroup) { | |||||
$userGroup = UserGroup::searchOne(['id' => $productPrice->id_user_group]); | |||||
if($userGroup) { | |||||
$productPrice->populateUserGroup($userGroup); | |||||
} | |||||
} | |||||
return $user | return $user | ||||
&& $productPrice->id_user_group | && $productPrice->id_user_group | ||||
&& $productPrice->userGroup | |||||
&& !$productPrice->id_point_sale | && !$productPrice->id_point_sale | ||||
&& !$productPrice->id_user | && !$productPrice->id_user | ||||
&& $this->userSolver->isUserBelongsToUserGroup($user, $productPrice->userGroup); | && $this->userSolver->isUserBelongsToUserGroup($user, $productPrice->userGroup); | ||||
public function matchUserGroupPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool | public function matchUserGroupPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool | ||||
{ | { | ||||
// @TODO : trouver une solution pour hydrater autrement cette donnée | |||||
if($productPrice->id_user_group && !$productPrice->userGroup) { | |||||
$userGroup = UserGroup::searchOne(['id' => $productPrice->id_user_group]); | |||||
if($userGroup) { | |||||
$productPrice->populateUserGroup($userGroup); | |||||
} | |||||
} | |||||
return $user | return $user | ||||
&& $pointSale | && $pointSale | ||||
&& $productPrice->id_user_group | && $productPrice->id_user_group |
public function actionHistory($type = 'incoming') | public function actionHistory($type = 'incoming') | ||||
{ | { | ||||
$queryHistoryArray = $this->getOrderManager() | $queryHistoryArray = $this->getOrderManager() | ||||
->queryOrdersHistory($this->getProducerCurrent(), $this->getUserCurrent(), $type); | |||||
->queryOrdersHistory($this->getProducerCurrent(), $this->getUserCurrent()); | |||||
$queryHistoryIncoming = $queryHistoryArray['incoming']; | $queryHistoryIncoming = $queryHistoryArray['incoming']; | ||||
$queryHistoryPassed = $queryHistoryArray['passed']; | $queryHistoryPassed = $queryHistoryArray['passed']; | ||||
$quantity = $availableProducts[$product->id]['quantity_remaining']; | $quantity = $availableProducts[$product->id]['quantity_remaining']; | ||||
} | } | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = $product->getPrice([ | |||||
$productOrder->price = $productManager->getPrice($product, [ | |||||
'user' => GlobalParam::getCurrentUser(), | 'user' => GlobalParam::getCurrentUser(), | ||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
'point_sale' => $pointSale, | 'point_sale' => $pointSale, | ||||
throw new \yii\web\NotFoundHttpException('Commande introuvable'); | throw new \yii\web\NotFoundHttpException('Commande introuvable'); | ||||
} | } | ||||
if ($orderManager->isOrderStateOpen($order)) { | |||||
if (!$orderManager->isOrderStateOpen($order)) { | |||||
throw new UserException('Vous ne pouvez plus annuler cette commande.'); | throw new UserException('Vous ne pouvez plus annuler cette commande.'); | ||||
} | } | ||||
return $jsonUser; | return $jsonUser; | ||||
} | } | ||||
private function ajaxInfosPointsSale($idProducer, $distribution = false) | |||||
private function ajaxInfosPointsSale($producer, $distribution = false) | |||||
{ | { | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
]); | ]); | ||||
} | } | ||||
$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer]) | |||||
$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $producer->id]) | |||||
->andWhere( | ->andWhere( | ||||
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))' | 'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))' | ||||
) | ) |