@@ -0,0 +1,73 @@ | |||
<?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.'); | |||
} | |||
} | |||
} |
@@ -34,7 +34,7 @@ class EtablissementController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'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; | |||
} | |||
] | |||
@@ -75,6 +75,11 @@ class EtablissementController extends BackendController | |||
} | |||
public function actionFacturation() | |||
{ | |||
return $this->render('facturation') ; | |||
} | |||
protected function findModel($id) | |||
{ | |||
if (($model = Etablissement::findOne($id)) !== null) { |
@@ -0,0 +1,6 @@ | |||
<?php | |||
?> | |||
<h1>Facturation</h1> | |||
@@ -0,0 +1,101 @@ | |||
<?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 '' ; | |||
} | |||
], | |||
], | |||
]); ?> |
@@ -0,0 +1,5 @@ | |||
<?php | |||
?> | |||
<h1>Facturation</h1> |
@@ -109,12 +109,12 @@ AppAsset::register($this); | |||
'items' => [ | |||
[ | |||
'label' => '<span class="glyphicon glyphicon-th-list"></span> Boulangeries', | |||
'url' => ['/etablissement/index'], | |||
'url' => ['etablissement-admin/index'], | |||
'visible'=> !Yii::$app->user->isGuest, | |||
], | |||
[ | |||
'label' => '<span class="glyphicon glyphicon-euro"></span> Facturation', | |||
'url' => ['/etablissement/facturation-admin'], | |||
'url' => ['etablissement-admin/facturation'], | |||
'visible'=> !Yii::$app->user->isGuest, | |||
], | |||
] |
@@ -79,10 +79,21 @@ class Etablissement extends \yii\db\ActiveRecord | |||
'delai_commande' => 'Délai de commande', | |||
'solde_negatif' => 'Solde négatif', | |||
'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() | |||
{ | |||