* @param integer $idPointSale | * @param integer $idPointSale | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionMail($idPointSale = 0, $sectionSubscribers = 0, $sectionInactiveUsers = 0) | |||||
public function actionMail( | |||||
$idPointSale = 0, | |||||
$sectionSubscribers = 0, | |||||
$sectionInactiveUsers = 0, | |||||
$usersPointSaleLink = 0, | |||||
$usersPointSaleHasOrder = 0) | |||||
{ | { | ||||
if($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { | |||||
$usersPointSaleLink = 1 ; | |||||
} | |||||
$users = User::findBy([ | $users = User::findBy([ | ||||
'id_producer' => Producer::getId(), | 'id_producer' => Producer::getId(), | ||||
'id_point_sale' => $idPointSale, | 'id_point_sale' => $idPointSale, | ||||
'users_point_sale_link' => $usersPointSaleLink, | |||||
'users_point_sale_has_order' => $usersPointSaleHasOrder, | |||||
'subscribers' => $sectionSubscribers, | 'subscribers' => $sectionSubscribers, | ||||
'inactive' => $sectionInactiveUsers, | 'inactive' => $sectionInactiveUsers, | ||||
])->all() ; | ])->all() ; | ||||
'incomingDistributionsArray' => $incomingDistributionsArray, | 'incomingDistributionsArray' => $incomingDistributionsArray, | ||||
'sectionSubscribers' => $sectionSubscribers, | 'sectionSubscribers' => $sectionSubscribers, | ||||
'sectionInactiveUsers' => $sectionInactiveUsers, | 'sectionInactiveUsers' => $sectionInactiveUsers, | ||||
'usersPointSaleLink' => $usersPointSaleLink, | |||||
'usersPointSaleHasOrder' => $usersPointSaleHasOrder, | |||||
]); | ]); | ||||
} | } | ||||
<div class="col-md-6"> | <div class="col-md-6"> | ||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
<h3 class="panel-title">Liste des emails <span class="label label-default"><?= count($usersArray); ?></span></h3> | |||||
<h3 class="panel-title"> | |||||
Liste des emails <span class="label label-default"><?= count($usersArray); ?></span> | |||||
</h3> | |||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<?php if($idPointSaleActive): ?> | |||||
<a class="btn btn-xs <?php if($usersPointSaleLink): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale' => $idPointSaleActive, 'usersPointSaleLink' => 1]); ?>">Liés au point de vente</a> | |||||
<a class="btn btn-xs <?php if($usersPointSaleHasOrder): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale' => $idPointSaleActive, 'usersPointSaleHasOrder' => 1]); ?>">Déjà commandés dans ce point de vente</a> | |||||
<br /><br /> | |||||
<?php endif; ?> | |||||
<?= implode(', ', $usersArray); ?> | <?= implode(', ', $usersArray); ?> | ||||
</div> | </div> | ||||
</div> | </div> |
if(isset($params['id_point_sale']) && $params['id_point_sale']) { | if(isset($params['id_point_sale']) && $params['id_point_sale']) { | ||||
$point_sale = PointSale::findOne(['id' => $params['id_point_sale']]) ; | $point_sale = PointSale::findOne(['id' => $params['id_point_sale']]) ; | ||||
if($point_sale->restricted_access) { | |||||
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $params['id_point_sale']]) ; | |||||
$conditionLinkUserPointSale = 'user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale' ; | |||||
$usersPointSaleLink = false; | |||||
$usersPointSaleHasOrder = false; | |||||
if(isset($params['users_point_sale_link']) && $params['users_point_sale_link']) { | |||||
$usersPointSaleLink = true ; | |||||
} | |||||
elseif(isset($params['users_point_sale_has_order']) && $params['users_point_sale_has_order']) { | |||||
$usersPointSaleHasOrder = true ; | |||||
} | |||||
elseif($point_sale->restricted_access) { | |||||
$usersPointSaleLink = true ; | |||||
} | } | ||||
else { | else { | ||||
$usersPointSaleHasOrder = true ; | |||||
} | |||||
if($usersPointSaleLink) { | |||||
$query->innerJoin('user_point_sale', 'user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $params['id_point_sale']]) ; | |||||
} | |||||
elseif($usersPointSaleHasOrder) { | |||||
$query->innerJoin( | $query->innerJoin( | ||||
'order', | 'order', | ||||
'user.id = order.id_user AND order.id_point_sale = :id_point_sale', | 'user.id = order.id_user AND order.id_point_sale = :id_point_sale', |