|
- <?php
-
-
-
- use yii\helpers\Html;
- use yii\grid\GridView;
- use common\models\User ;
- use common\models\Producer ;
- use common\models\Distribution ;
-
- $this->setTitle('Producteurs') ;
- $this->addBreadcrumb($this->getTitle()) ;
- $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphicon-plus"></span>', 'url' => 'producer-admin/create', 'class' => 'btn btn-primary']) ;
-
- ?>
-
- <div class="alert alert-info">
- Abonnements mensuels : <strong><?= $sumFreePrice ?> € HT</strong>
- </div>
-
- <?= GridView::widget([
- 'dataProvider' => $dataProviderProducer,
- 'columns' => [
- 'name',
- [
- 'attribute' => 'date_creation',
- 'format' => 'raw',
- 'value' => function($model) {
- return date('d/m/Y', strtotime($model->date_creation)) ;
- }
- ],
- [
- 'attribute' => 'Lieu',
- 'format' => 'raw',
- 'value' => function($model) {
- return Html::encode($model->city.' ('.$model->postcode.')') ;
- }
- ],
- [
- 'attribute' => 'Utilisateurs',
- 'format' => 'raw',
- 'value' => function($model) {
- if(!$model->userProducer || !count($model->userProducer))
- {
- return 'Aucun utilisateur' ;
- }
- else {
- $users = count($model->userProducer).' client' ;
- if(count($model->userProducer) > 1) {
- $users .= 's' ;
- }
- return $users ;
- }
-
- }
- ],
- [
- 'attribute' => 'Contact',
- 'format' => 'raw',
- 'value' => function($model) {
- if(!isset($model->user) || (isset($model->user) && count($model->user) == 0))
- {
- return 'Aucun contact' ;
- }
- else {
- foreach($model->user as $u)
- {
- if($u->status == User::STATUS_PRODUCER)
- {
- return Html::encode($u->lastname.' '.$u->name)
- .'<br />'.Html::encode($u->email)
- .'<br />'.Html::encode($u->phone) ;
- }
- }
-
- }
- }
- ],
- [
- 'attribute' => 'active',
- 'format' => 'raw',
- 'value' => function($model) {
- $html = '' ;
- if($model->active) {
- $html .= '<span class="label label-success">En ligne</span>' ;
- }
- else {
- $html .= '<span class="label label-danger">Hors-ligne</span>' ;
- }
-
- if(strlen($model->code))
- {
- $html .= ' <span class="glyphicon glyphicon-lock" data-toggle="tooltip" data-placement="bottom" data-original-title="'.Html::encode($model->code).'"></span>' ;
- }
-
- return $html ;
- }
- ],
- [
- 'attribute' => 'Prix libre',
- 'label' => 'Prix libre',
- 'format' => 'raw',
- 'value' => function($model) {
- if(is_null($model->free_price)) {
- return '' ;
- }
- else {
- return $model->getFreePrice() ;
- }
-
- }
- ],
- [
- 'label' => 'Dons (mois précédent)',
- 'format' => 'raw',
- 'value' => function($model) {
- $productGift = Product::getProductGift() ;
-
- $res = Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total
- FROM `order`, product_order, distribution
- WHERE distribution.id_producer = :id_producer
- AND `order`.id_distribution = distribution.id
- AND `order`.id = product_order.id_order
- AND distribution.date >= :date_start
- AND distribution.date <= :date_end
- AND product_order.id_product = :id_product_gift
- ")
- ->bindValue(':id_producer', $model->id)
- ->bindValue(':date_start', date('Y-m-01', strtotime("-1 month")))
- ->bindValue(':date_end', date('Y-m-31', strtotime("-1 month")))
- ->bindValue(':id_product_gift', $productGift->id)
- ->queryOne();
-
- return Price::format($res['total']) ;
-
- }
- ],
- ],
- ]); ?>
|