use common\models\User ; | use common\models\User ; | ||||
use common\models\Subscription ; | use common\models\Subscription ; | ||||
use common\helpers\Price ; | use common\helpers\Price ; | ||||
use common\models\PointSaleDistribution ; | |||||
use DateTime; | use DateTime; | ||||
class DistributionController extends BackendController | class DistributionController extends BackendController | ||||
$dateObject = DateTime::createFromFormat($format, $date); | $dateObject = DateTime::createFromFormat($format, $date); | ||||
if($dateObject && $dateObject->format($format) === $date) { | if($dateObject && $dateObject->format($format) === $date) { | ||||
$distribution = Distribution::initDistribution($date) ; | $distribution = Distribution::initDistribution($date) ; | ||||
} | } | ||||
if($distribution) { | if($distribution) { | ||||
PointSaleDistribution::setAll($distribution->id, true); | |||||
$distribution->active = (int) $active ; | $distribution->active = (int) $active ; | ||||
$distribution->save() ; | $distribution->save() ; | ||||
use common\models\UserPointSale; | use common\models\UserPointSale; | ||||
use common\models\Order ; | use common\models\Order ; | ||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\Distribution ; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
/** | /** |
* @param boolean $bool_livraison | * @param boolean $bool_livraison | ||||
*/ | */ | ||||
public static function setAll($idDistribution, $boolDelivery) | public static function setAll($idDistribution, $boolDelivery) | ||||
{ | |||||
$countPointSaleDistribution = self::searchCount([ | |||||
'id_distribution' => $idDistribution | |||||
]) ; | |||||
if (!$countPointSaleDistribution) { | |||||
$arrPointsSale = PointSale::searchAll() ; | |||||
foreach ($arrPointsSale as $pointSale) { | |||||
{ | |||||
// liaison PointSale / Distribution | |||||
$arrPointsSale = PointSale::find() | |||||
->with(['pointSaleDistribution' => function($q) use ($idDistribution) { | |||||
$q->where(['id_distribution' => $idDistribution]); | |||||
}]) | |||||
->where([ | |||||
'id_producer' => Producer::getId(), | |||||
]) | |||||
->all(); | |||||
foreach ($arrPointsSale as $pointSale) { | |||||
if(!$pointSale->pointSaleDistribution) { | |||||
$pointSaleDistribution = new PointSaleDistribution(); | $pointSaleDistribution = new PointSaleDistribution(); | ||||
$pointSaleDistribution->id_distribution = $idDistribution; | $pointSaleDistribution->id_distribution = $idDistribution; | ||||
$pointSaleDistribution->id_point_sale = $pointSale->id; | $pointSaleDistribution->id_point_sale = $pointSale->id; |