UserPointSale::deleteAll(['id_point_sale' => $id]); | UserPointSale::deleteAll(['id_point_sale' => $id]); | ||||
// Suppression du lien PointSaleDistribution pour toutes les distributions à venir | // Suppression du lien PointSaleDistribution pour toutes les distributions à venir | ||||
$incomingDistributions = $distributionManager->findDistributionsIncoming(); | |||||
$incomingDistributions = $distributionManager->findDistributionsIncoming(true); | |||||
foreach ($incomingDistributions as $distribution) { | foreach ($incomingDistributions as $distribution) { | ||||
PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | ||||
} | } |
/** | /** | ||||
* Récupère les distributions futures. | * 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() | $distributionsArray = Distribution::find() | ||||
->where('date > \'' . date('Y-m-d') . '\'') | ->where('date > \'' . date('Y-m-d') . '\'') | ||||
->andWhere([ | |||||
'id_producer' => $this->getProducerContext()->id, | |||||
'active' => 1 | |||||
]) | |||||
->andWhere($paramsWhere) | |||||
->orderBy('date ASC') | ->orderBy('date ASC') | ||||
->all(); | ->all(); | ||||
*/ | */ | ||||
public function addProductIncomingDistributions(Product $product): void | public function addProductIncomingDistributions(Product $product): void | ||||
{ | { | ||||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(); | |||||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(true); | |||||
foreach ($distributionArray as $distribution) { | foreach ($distributionArray as $distribution) { | ||||
$this->addProduct($distribution, $product); | $this->addProduct($distribution, $product); | ||||
} | } | ||||
*/ | */ | ||||
public function addPointSaleIncomingDistributions(PointSale $pointSale): void | public function addPointSaleIncomingDistributions(PointSale $pointSale): void | ||||
{ | { | ||||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(); | |||||
$distributionArray = $this->distributionRepository->findDistributionsIncoming(true); | |||||
foreach ($distributionArray as $distribution) { | foreach ($distributionArray as $distribution) { | ||||
$this->addPointSale($distribution, $pointSale); | $this->addPointSale($distribution, $pointSale); | ||||
} | } |