<?php | |||||
namespace backend\controllers; | |||||
use Yii; | |||||
use common\models\User; | |||||
use yii\web\NotFoundHttpException; | |||||
use yii\filters\VerbFilter; | |||||
use yii\filters\AccessControl; | |||||
use common\helpers\Upload ; | |||||
use common\models\Etablissement ; | |||||
use yii\data\ActiveDataProvider ; | |||||
/** | |||||
* UserController implements the CRUD actions for User model. | |||||
*/ | |||||
class EtablissementAdminController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
return [ | |||||
'verbs' => [ | |||||
'class' => VerbFilter::className(), | |||||
'actions' => [ | |||||
'delete' => ['post'], | |||||
], | |||||
], | |||||
'access' => [ | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; | |||||
} | |||||
] | |||||
], | |||||
], | |||||
]; | |||||
} | |||||
public function actionIndex() | |||||
{ | |||||
$datas_etablissements = new ActiveDataProvider([ | |||||
'query' => Etablissement::find() | |||||
->with('userEtablissement','user') | |||||
->orderBy('date_creation DESC'), | |||||
'pagination' => [ | |||||
'pageSize' => 1000, | |||||
], | |||||
]); | |||||
return $this->render('index', [ | |||||
'datas_etablissements' => $datas_etablissements, | |||||
]); | |||||
} | |||||
public function actionFacturation() | |||||
{ | |||||
return $this->render('facturation') ; | |||||
} | |||||
protected function findModel($id) | |||||
{ | |||||
if (($model = Etablissement::findOne($id)) !== null) { | |||||
return $model; | |||||
} else { | |||||
throw new NotFoundHttpException('The requested page does not exist.'); | |||||
} | |||||
} | |||||
} |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | ||||
} | } | ||||
] | ] | ||||
} | } | ||||
public function actionFacturation() | |||||
{ | |||||
return $this->render('facturation') ; | |||||
} | |||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = Etablissement::findOne($id)) !== null) { | if (($model = Etablissement::findOne($id)) !== null) { |
<?php | |||||
?> | |||||
<h1>Facturation</h1> | |||||
<?php | |||||
use yii\helpers\Html; | |||||
use yii\grid\GridView; | |||||
use common\models\User ; | |||||
$this->title = 'Boulangeries'; | |||||
$this->params['breadcrumbs'][] = 'Administration' ; | |||||
$this->params['breadcrumbs'][] = $this->title; | |||||
?> | |||||
<h1>Boulangeries</h1> | |||||
<?= GridView::widget([ | |||||
'dataProvider' => $datas_etablissements, | |||||
'columns' => [ | |||||
'nom', | |||||
[ | |||||
'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->ville.' ('.$model->code_postal.')') ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'Clients', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
if(!$model->userEtablissement || !count($model->userEtablissement)) | |||||
{ | |||||
return 'Aucun client' ; | |||||
} | |||||
else { | |||||
$clients = count($model->userEtablissement).' client' ; | |||||
if(count($model->userEtablissement) > 1) | |||||
$clients .= 's' ; | |||||
return $clients ; | |||||
} | |||||
} | |||||
], | |||||
[ | |||||
'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_BOULANGER) | |||||
{ | |||||
return Html::encode($u->prenom.' '.$u->nom) | |||||
.'<br />'.Html::encode($u->email) | |||||
.'<br />'.Html::encode($u->telephone) ; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'actif', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
$html = '' ; | |||||
if($model->actif) | |||||
$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' => 'Gratuit', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
if($model->gratuit) | |||||
return '<span class="label label-success">Compte gratuit</span>' ; | |||||
else | |||||
return '' ; | |||||
} | |||||
], | |||||
], | |||||
]); ?> |
<?php | |||||
?> | |||||
<h1>Facturation</h1> |
'items' => [ | 'items' => [ | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-th-list"></span> Boulangeries', | 'label' => '<span class="glyphicon glyphicon-th-list"></span> Boulangeries', | ||||
'url' => ['/etablissement/index'], | |||||
'url' => ['etablissement-admin/index'], | |||||
'visible'=> !Yii::$app->user->isGuest, | 'visible'=> !Yii::$app->user->isGuest, | ||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-euro"></span> Facturation', | 'label' => '<span class="glyphicon glyphicon-euro"></span> Facturation', | ||||
'url' => ['/etablissement/facturation-admin'], | |||||
'url' => ['etablissement-admin/facturation'], | |||||
'visible'=> !Yii::$app->user->isGuest, | 'visible'=> !Yii::$app->user->isGuest, | ||||
], | ], | ||||
] | ] |
'delai_commande' => 'Délai de commande', | 'delai_commande' => 'Délai de commande', | ||||
'solde_negatif' => 'Solde négatif', | 'solde_negatif' => 'Solde négatif', | ||||
'credit_pain' => 'Crédit pain', | 'credit_pain' => 'Crédit pain', | ||||
'actif' => 'Actif' | |||||
'actif' => 'Actif', | |||||
'date_creation' => 'Date de création' | |||||
]; | ]; | ||||
} | } | ||||
public function getUserEtablissement() | |||||
{ | |||||
return $this->hasMany(UserEtablissement::className(), ['id_etablissement' => 'id']) ; | |||||
} | |||||
public function getUser() | |||||
{ | |||||
return $this->hasMany(User::className(), ['id_etablissement' => 'id']) ; | |||||
} | |||||
public static function getEtablissementsPopulateDropdown() | public static function getEtablissementsPopulateDropdown() | ||||
{ | { | ||||