@@ -191,7 +191,7 @@ class DistributionController extends BackendController | |||
if ($ordersArray) { | |||
foreach ($ordersArray as $order) { | |||
if (is_null($order->date_delete)) { | |||
$revenues += $orderManager->getAmountWithTax($order); | |||
$revenues += $orderManager->getOrderAmountWithTax($order); | |||
$weight += $order->weight; | |||
} | |||
} |
@@ -41,6 +41,7 @@ namespace backend\controllers; | |||
use common\forms\SubscriptionForm; | |||
use common\helpers\CSV; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\Price; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; | |||
use common\logic\Distribution\ProductDistribution\Model\ProductDistribution; | |||
@@ -783,6 +784,7 @@ class OrderController extends BackendController | |||
$products = json_decode($products); | |||
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); | |||
$distribution = $distributionManager->findOneDistributionByDate($date); | |||
$producerCurrent = $this->getProducerCurrent(); | |||
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)) | |||
@@ -851,7 +853,7 @@ class OrderController extends BackendController | |||
} | |||
} | |||
$order = $orderManager->findOneOrderById($order); | |||
$order = $orderManager->findOneOrderById($order->id); | |||
if ($order && $processCredit) { | |||
$orderManager->processCredit($order); | |||
} | |||
@@ -863,7 +865,7 @@ class OrderController extends BackendController | |||
// lien utilisateur / point de vente | |||
if ($idUser && $pointSale) { | |||
$pointSaleManager->addUser($pointSale, $user); | |||
$pointSaleManager->addUser($user, $pointSale); | |||
} | |||
} | |||
@@ -1009,8 +1011,10 @@ class OrderController extends BackendController | |||
*/ | |||
public function actionPaymentStatus(int $idOrder) | |||
{ | |||
$orderManager = $this->getOrderManager(); | |||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||
$order = Order::searchOne(['id' => $idOrder]); | |||
$order = $orderManager->findOneOrderById($idOrder); | |||
if ($order) { | |||
$html = ''; | |||
@@ -1027,7 +1031,7 @@ class OrderController extends BackendController | |||
if (abs($order->amount - $amountPaid) < 0.0001) { | |||
$html .= '<span class="label label-success">Payé</span>'; | |||
$buttonsCredit = Html::a('Rembourser ' . $order->getAmountWithTax(Order::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']); | |||
$buttonsCredit = Html::a('Rembourser ' . $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']); | |||
} elseif ($order->amount > $amountPaid) { | |||
$amountToPay = $order->amount - $amountPaid; | |||
$html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($amountToPay, 2) . ' €</strong> à payer'; | |||
@@ -1059,8 +1063,8 @@ class OrderController extends BackendController | |||
. '<td>' . date('d/m/Y H:i:s', strtotime($creditHistoryManager->getDate($creditHistory))) . '</td>' | |||
. '<td>' . Html::encode($creditHistoryManager->getStrUserAction($creditHistory)) . '</td>' | |||
. '<td>' . $creditHistoryManager->getStrWording($creditHistory) . '</td>' | |||
. '<td>' . ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||
. '<td>' . ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryManager->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||
. '<td>' . ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>' | |||
. '<td>' . ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>' | |||
. '</tr>'; | |||
} | |||
} else { |
@@ -59,7 +59,7 @@ class PointSaleDistributionBuilder extends AbstractBuilder | |||
// setAll | |||
public function createAllPointSaleDistributions(Distribution $distribution, bool $delivery): void | |||
{ | |||
$pointSaleArray = $this->pointSaleDistributionRepository->findPointSaleDistributionsByDistribution($distribution); | |||
$pointSaleArray = $this->pointSaleRepository->findPointSalesByDistribution($distribution); | |||
foreach ($pointSaleArray as $pointSale) { | |||
if (!$pointSale->pointSaleDistribution) { | |||
$this->createPointSaleDistribution($distribution, $pointSale); |
@@ -52,7 +52,7 @@ class ProductDistributionBuilder extends AbstractBuilder | |||
public function initActive(ProductDistribution $productDistribution): ProductDistribution | |||
{ | |||
$productDistribution->active = $this->productSolver->isProductActiveByDay( | |||
$productDistribution->active = (int) $this->productSolver->isProductActiveByDay( | |||
$productDistribution->product, | |||
$this->distributionSolver->getDistributionDayAsString($productDistribution->distribution) | |||
); |
@@ -7,6 +7,7 @@ use common\helpers\MeanPayment; | |||
use common\helpers\Price; | |||
use common\logic\AbstractBuilder; | |||
use common\logic\Config\TaxRate\Model\TaxRate; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\Distribution\Repository\DistributionRepository; | |||
use common\logic\Document\Document\Model\Document; | |||
use common\logic\Order\Order\Model\Order; | |||
@@ -20,6 +21,7 @@ use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | |||
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\Producer\Producer\Repository\ProducerRepository; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
use common\logic\Subscription\Subscription\Model\Subscription; | |||
use common\logic\Subscription\Subscription\Service\SubscriptionBuilder; | |||
use common\logic\Subscription\Subscription\Repository\SubscriptionRepository; | |||
@@ -50,6 +52,7 @@ class OrderBuilder extends AbstractBuilder | |||
protected ProductOrderSolver $productOrderSolver; | |||
protected SubscriptionRepository $subscriptionRepository; | |||
protected SubscriptionSolver $subscriptionSolver; | |||
protected ProductSolver $productSolver; | |||
public function loadDependencies(): void | |||
{ | |||
@@ -70,21 +73,22 @@ class OrderBuilder extends AbstractBuilder | |||
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class); | |||
$this->subscriptionRepository = $this->loadService(SubscriptionRepository::class); | |||
$this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); | |||
$this->productSolver = $this->loadService(ProductSolver::class); | |||
} | |||
public function instanciateOrder(): Order | |||
public function instanciateOrder(Distribution $distribution): Order | |||
{ | |||
$order = new Order(); | |||
//$order->populateDistribution($distribution); | |||
$order->populateDistribution($distribution); | |||
$order->date = date('Y-m-d H:i:s'); | |||
$order->status = 'tmp-order'; | |||
return $order; | |||
} | |||
public function createOrder(): Order | |||
public function createOrder(Distribution $distribution): Order | |||
{ | |||
$order = $this->instanciateOrder(); | |||
$order = $this->instanciateOrder($distribution); | |||
$this->createUserPointSale($order); | |||
$this->initOrderCommentPointSale($order); | |||
@@ -236,7 +240,7 @@ class OrderBuilder extends AbstractBuilder | |||
$order, | |||
$productSubscription->product, | |||
$productSubscription->quantity, | |||
$productSubscription->product->getPrice([ | |||
$this->productSolver->getPrice($productSubscription->product, [ | |||
'user' => $user, | |||
'point_sale' => $subscription->pointSale, | |||
'quantity' => $productSubscription->quantity | |||
@@ -504,7 +508,7 @@ class OrderBuilder extends AbstractBuilder | |||
$order->tiller_synchronization = $synchroTiller; | |||
} | |||
else { | |||
$paymentStatus = $order->getPaymentStatus(); | |||
$paymentStatus = $this->orderSolver->getPaymentStatus($order); | |||
if ($paymentStatus == Order::PAYMENT_PAID) { | |||
$order->tiller_synchronization = 1; | |||
@@ -553,7 +557,8 @@ class OrderBuilder extends AbstractBuilder | |||
// generateReference | |||
public function generateOrderReference(Order $order): void | |||
{ | |||
$producer = $this->producerRepository->findOneProducerById($order->id_producer); | |||
$distribution = $this->distributionRepository->findOneDistributionById($order->id_distribution); | |||
$producer = $this->producerRepository->findOneProducerById($distribution->id_producer); | |||
if (!$order->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) { | |||
$lastOrder = $this->orderRepository->findOneOrderLastOfYear($producer); |
@@ -7,9 +7,17 @@ use common\logic\PointSale\PointSale\Model\PointSale; | |||
use common\logic\Product\ProductPrice\Model\ProductPrice; | |||
use common\logic\SolverInterface; | |||
use common\logic\User\User\Model\User; | |||
use common\logic\User\User\Service\UserSolver; | |||
class ProductPriceSolver extends AbstractService implements SolverInterface | |||
{ | |||
protected UserSolver $userSolver; | |||
public function loadDependencies(): void | |||
{ | |||
$this->userSolver = $this->loadService(UserSolver::class); | |||
} | |||
// getSpecificPricesFilterByPriorityMatch | |||
public function filterByPriorityMatch( | |||
array $specificPrices, | |||
@@ -20,8 +28,8 @@ class ProductPriceSolver extends AbstractService implements SolverInterface | |||
$specificPricesFilter = []; | |||
foreach ($specificPrices as $keySpecificPrice => $specificPrice) { | |||
if (($priorityMatchSpecificPrice && $specificPrice->$priorityMatchSpecificPrice($user, $pointSale)) | |||
|| $specificPrice->matchFromQuantityOnly()) { | |||
if (($priorityMatchSpecificPrice && $this->$priorityMatchSpecificPrice($specificPrice, $user, $pointSale)) | |||
|| $this->matchFromQuantityOnly($specificPrice)) { | |||
$specificPricesFilter[] = $specificPrice; | |||
} | |||
@@ -60,7 +68,7 @@ class ProductPriceSolver extends AbstractService implements SolverInterface | |||
PointSale $pointSale = null): bool | |||
{ | |||
foreach($specificPriceArray as $specificPrice) { | |||
if($specificPrice->$typeMatch($user, $pointSale)) { | |||
if($this->$typeMatch($specificPrice, $user, $pointSale)) { | |||
return true; | |||
} | |||
} | |||
@@ -83,7 +91,7 @@ class ProductPriceSolver extends AbstractService implements SolverInterface | |||
&& $productPrice->id_user_group | |||
&& !$productPrice->id_point_sale | |||
&& !$productPrice->id_user | |||
&& $user->belongsToUserGroup($productPrice->id_user_group); | |||
&& $this->userSolver->isUserBelongsToUserGroup($user, $productPrice->userGroup); | |||
} | |||
public function matchPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool | |||
@@ -111,7 +119,7 @@ class ProductPriceSolver extends AbstractService implements SolverInterface | |||
&& $productPrice->id_user_group | |||
&& $productPrice->id_point_sale | |||
&& !$productPrice->id_user | |||
&& $user->belongsToUserGroup($productPrice->id_user_group) | |||
&& $this->userSolver->isUserBelongsToUserGroup($user, $productPrice->userGroup) | |||
&& $productPrice->id_point_sale == $pointSale->id; | |||
} | |||
@@ -48,26 +48,6 @@ class UserRepository extends AbstractRepository | |||
return User::searchOne(['id' => $id]); | |||
} | |||
// belongsToUserGroup | |||
public function isUserbelongsToUserGroup(User $user, UserGroup $userGroup): bool | |||
{ | |||
if (!$user->userUserGroup) { | |||
$user->populateRelation('userUserGroup', UserUserGroup::searchAll([ | |||
'id_user' => $user->id | |||
])); | |||
} | |||
if ($user->userUserGroup) { | |||
foreach ($user->userUserGroup as $userUserGroup) { | |||
if ($userUserGroup->id_user_group == $userGroup->id) { | |||
return true; | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
public function findUsers(): array | |||
{ | |||
return $this->queryUsersBy()->all(); |
@@ -5,6 +5,8 @@ namespace common\logic\User\User\Service; | |||
use common\logic\AbstractService; | |||
use common\logic\SolverInterface; | |||
use common\logic\User\User\Model\User; | |||
use common\logic\User\UserGroup\Model\UserGroup; | |||
use common\logic\User\UserUserGroup\Model\UserUserGroup; | |||
class UserSolver extends AbstractService implements SolverInterface | |||
{ | |||
@@ -185,4 +187,24 @@ class UserSolver extends AbstractService implements SolverInterface | |||
|| $userCurrentStatus == User::STATUS_PRODUCER; | |||
} | |||
// belongsToUserGroup | |||
public function isUserBelongsToUserGroup(User $user, UserGroup $userGroup): bool | |||
{ | |||
if (!$user->userUserGroup) { | |||
$user->populateRelation('userUserGroup', UserUserGroup::searchAll([ | |||
'id_user' => $user->id | |||
])); | |||
} | |||
if ($user->userUserGroup) { | |||
foreach ($user->userUserGroup as $userUserGroup) { | |||
if ($userUserGroup->id_user_group == $userGroup->id) { | |||
return true; | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
} |