@@ -183,7 +183,7 @@ class PointSaleController extends BackendController | |||
UserPointSale::deleteAll(['id_point_sale' => $id]); | |||
// Suppression du lien PointSaleDistribution pour toutes les distributions à venir | |||
$incomingDistributions = $distributionManager->findDistributionsIncoming(); | |||
$incomingDistributions = $distributionManager->findDistributionsIncoming(true); | |||
foreach ($incomingDistributions as $distribution) { | |||
PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | |||
} |
@@ -87,14 +87,19 @@ class DistributionRepository extends AbstractRepository | |||
/** | |||
* Récupère les distributions futures. | |||
*/ | |||
public function findDistributionsIncoming(): array | |||
public function findDistributionsIncoming($ignoreActive = false): array | |||
{ | |||
$paramsWhere = [ | |||
'id_producer' => $this->getProducerContext()->id, | |||
]; | |||
if(!$ignoreActive) { | |||
$paramsWhere['active'] = 1; | |||
} | |||
$distributionsArray = Distribution::find() | |||
->where('date > \'' . date('Y-m-d') . '\'') | |||
->andWhere([ | |||
'id_producer' => $this->getProducerContext()->id, | |||
'active' => 1 | |||
]) | |||
->andWhere($paramsWhere) | |||
->orderBy('date ASC') | |||
->all(); | |||
@@ -113,7 +113,7 @@ class DistributionBuilder extends AbstractBuilder | |||
*/ | |||
public function addProductIncomingDistributions(Product $product): void | |||
{ | |||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(); | |||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(true); | |||
foreach ($distributionArray as $distribution) { | |||
$this->addProduct($distribution, $product); | |||
} | |||
@@ -144,7 +144,7 @@ class DistributionBuilder extends AbstractBuilder | |||
*/ | |||
public function addPointSaleIncomingDistributions(PointSale $pointSale): void | |||
{ | |||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(); | |||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(true); | |||
foreach ($distributionArray as $distribution) { | |||
$this->addPointSale($distribution, $pointSale); | |||
} |