namespace backend\controllers; | namespace backend\controllers; | ||||
use yii ; | |||||
use common\controllers\CommonController ; | |||||
use yii; | |||||
use common\controllers\CommonController; | |||||
class BackendController extends CommonController | |||||
{ | |||||
class BackendController extends CommonController { | |||||
} | } | ||||
use common\models\PointVente; | use common\models\PointVente; | ||||
use common\models\Produit; | use common\models\Produit; | ||||
use common\models\User; | use common\models\User; | ||||
use common\models\CommandeAutoForm ; | |||||
use common\models\CommandeAutoForm; | |||||
use common\models\ProductionProduit; | use common\models\ProductionProduit; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use common\models\CommandeAuto ; | |||||
use common\models\CommandeAutoProduit ; | |||||
use common\models\CommandeAuto; | |||||
use common\models\CommandeAutoProduit; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
class CommandeautoController extends BackendController { | class CommandeautoController extends BackendController { | ||||
var $enableCsrfValidation = false; | var $enableCsrfValidation = false; | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | 'class' => AccessControl::className(), | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | ] | ||||
], | ], | ||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => CommandeAuto::find() | 'query' => CommandeAuto::find() | ||||
->with(['user','etablissement', 'pointVente','commandeAutoProduit']) | |||||
->joinWith(['user']) | |||||
->where(['commande_auto.id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('commande_auto.id_point_vente ASC, CASE `commande_auto`.`username` WHEN "" THEN `user`.`nom` ELSE `commande_auto`.`username` END ASC'), | |||||
->with(['user', 'etablissement', 'pointVente', 'commandeAutoProduit']) | |||||
->joinWith(['user']) | |||||
->where(['commande_auto.id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('commande_auto.id_point_vente ASC, CASE `commande_auto`.`username` WHEN "" THEN `user`.`nom` ELSE `commande_auto`.`username` END ASC'), | |||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 1000, | 'pageSize' => 1000, | ||||
], | ], | ||||
]); | ]); | ||||
return $this->render('index',[ | |||||
'dataProvider' => $dataProvider | |||||
]) ; | |||||
return $this->render('index', [ | |||||
'dataProvider' => $dataProvider | |||||
]); | |||||
} | } | ||||
public function actionCreate() | |||||
{ | |||||
public function actionCreate() { | |||||
// form | // form | ||||
$model = new CommandeAutoForm ; | |||||
$model->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$model = new CommandeAutoForm; | |||||
$model->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
// produits | // produits | ||||
$produits = Produit::find() | $produits = Produit::find() | ||||
->where(['id_etablissement' => $model->id_etablissement]) | |||||
->orderBy('order ASC') | |||||
->all(); | |||||
if($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) | |||||
{ | |||||
$this->redirect(['commandeauto/index']) ; | |||||
->where(['id_etablissement' => $model->id_etablissement]) | |||||
->orderBy('order ASC') | |||||
->all(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) { | |||||
$this->redirect(['commandeauto/index']); | |||||
} | } | ||||
return $this->render('create',[ | |||||
'model' => $model, | |||||
'produits' => $produits | |||||
]) ; | |||||
return $this->render('create', [ | |||||
'model' => $model, | |||||
'produits' => $produits | |||||
]); | |||||
} | } | ||||
public function actionUpdate($id) | |||||
{ | |||||
public function actionUpdate($id) { | |||||
// form | // form | ||||
$model = new CommandeAutoForm ; | |||||
$commandeauto = CommandeAuto::findOne($id) ; | |||||
if($commandeauto) | |||||
{ | |||||
$model->id = $id ; | |||||
$model->id_etablissement = $commandeauto->id_etablissement ; | |||||
$model->id_user = $commandeauto->id_user ; | |||||
$model->username = $commandeauto->username ; | |||||
$model->id_point_vente = $commandeauto->id_point_vente ; | |||||
$model->date_debut = date('d/m/Y',strtotime($commandeauto->date_debut)) ; | |||||
if(strlen($commandeauto->date_fin)) | |||||
$model->date_fin = date('d/m/Y',strtotime($commandeauto->date_fin)) ; | |||||
$model->lundi = $commandeauto->lundi ; | |||||
$model->lundi = $commandeauto->lundi ; | |||||
$model->mardi = $commandeauto->mardi ; | |||||
$model->mercredi = $commandeauto->mercredi ; | |||||
$model->jeudi = $commandeauto->jeudi ; | |||||
$model->vendredi = $commandeauto->vendredi ; | |||||
$model->samedi = $commandeauto->samedi ; | |||||
$model->dimanche = $commandeauto->dimanche ; | |||||
$model->paiement_automatique = $commandeauto->paiement_automatique ; | |||||
$model->periodicite_semaine = $commandeauto->periodicite_semaine ; | |||||
$model = new CommandeAutoForm; | |||||
$commandeauto = CommandeAuto::findOne($id); | |||||
if ($commandeauto) { | |||||
$model->id = $id; | |||||
$model->id_etablissement = $commandeauto->id_etablissement; | |||||
$model->id_user = $commandeauto->id_user; | |||||
$model->username = $commandeauto->username; | |||||
$model->id_point_vente = $commandeauto->id_point_vente; | |||||
$model->date_debut = date('d/m/Y', strtotime($commandeauto->date_debut)); | |||||
if (strlen($commandeauto->date_fin)) | |||||
$model->date_fin = date('d/m/Y', strtotime($commandeauto->date_fin)); | |||||
$model->lundi = $commandeauto->lundi; | |||||
$model->lundi = $commandeauto->lundi; | |||||
$model->mardi = $commandeauto->mardi; | |||||
$model->mercredi = $commandeauto->mercredi; | |||||
$model->jeudi = $commandeauto->jeudi; | |||||
$model->vendredi = $commandeauto->vendredi; | |||||
$model->samedi = $commandeauto->samedi; | |||||
$model->dimanche = $commandeauto->dimanche; | |||||
$model->paiement_automatique = $commandeauto->paiement_automatique; | |||||
$model->periodicite_semaine = $commandeauto->periodicite_semaine; | |||||
// produits | // produits | ||||
$commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all() ; | |||||
foreach($commandeauto_produits as $commandeauto_produit) | |||||
{ | |||||
$model->produits['produit_'.$commandeauto_produit->id_produit] = $commandeauto_produit->quantite ; | |||||
$commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all(); | |||||
foreach ($commandeauto_produits as $commandeauto_produit) { | |||||
$model->produits['produit_' . $commandeauto_produit->id_produit] = $commandeauto_produit->quantite; | |||||
} | } | ||||
} | |||||
else { | |||||
} else { | |||||
throw new NotFoundHttpException('La commande récurrente est introuvable.', 404); | throw new NotFoundHttpException('La commande récurrente est introuvable.', 404); | ||||
} | } | ||||
// produits | // produits | ||||
$produits = Produit::find() | $produits = Produit::find() | ||||
->where(['id_etablissement' => $model->id_etablissement]) | |||||
->orderBy('order ASC') | |||||
->all(); | |||||
if($model->load(Yii::$app->request->post()) && $model->validate()) | |||||
{ | |||||
if(!strlen($model->date_fin)){ | |||||
$model->date_fin = null ; | |||||
->where(['id_etablissement' => $model->id_etablissement]) | |||||
->orderBy('order ASC') | |||||
->all(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||||
if (!strlen($model->date_fin)) { | |||||
$model->date_fin = null; | |||||
} | } | ||||
if($model->save()) | |||||
{ | |||||
$this->redirect(['commandeauto/index']) ; | |||||
if ($model->save()) { | |||||
$this->redirect(['commandeauto/index']); | |||||
} | } | ||||
} | } | ||||
return $this->render('update',[ | |||||
'model' => $model, | |||||
'produits' => $produits | |||||
]) ; | |||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
'produits' => $produits | |||||
]); | |||||
} | } | ||||
public function actionDelete($id) | |||||
{ | |||||
CommandeAutoProduit::deleteAll(['id_commande_auto' => $id]) ; | |||||
CommandeAuto::findOne($id)->delete() ; | |||||
$this->redirect(['commandeauto/index']) ; | |||||
public function actionDelete($id) { | |||||
CommandeAutoProduit::deleteAll(['id_commande_auto' => $id]); | |||||
CommandeAuto::findOne($id)->delete(); | |||||
$this->redirect(['commandeauto/index']); | |||||
} | } | ||||
} | |||||
} |
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class CommuniquerController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class CommuniquerController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() | |||||
{ | |||||
$etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]) ; | |||||
public function actionIndex() { | |||||
$etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'etablissement' => $etablissement, | |||||
]) ; | |||||
'etablissement' => $etablissement, | |||||
]); | |||||
} | } | ||||
public function actionModeemploi() | |||||
{ | |||||
$etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]) ; | |||||
public function actionModeemploi() { | |||||
$etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]); | |||||
// get your HTML raw content without any layouts or scripts | // get your HTML raw content without any layouts or scripts | ||||
$content = $this->renderPartial('mode_emploi_multi',[ | |||||
$content = $this->renderPartial('mode_emploi_multi', [ | |||||
'pdf' => true, | 'pdf' => true, | ||||
'etablissement' => $etablissement | 'etablissement' => $etablissement | ||||
]); | |||||
]); | |||||
$pdf = new Pdf([ | $pdf = new Pdf([ | ||||
// set to use core fonts only | // set to use core fonts only | ||||
'mode' => Pdf::MODE_UTF8, | |||||
'mode' => Pdf::MODE_UTF8, | |||||
// A4 paper format | // A4 paper format | ||||
'format' => Pdf::FORMAT_A4, | |||||
'format' => Pdf::FORMAT_A4, | |||||
// portrait orientation | // portrait orientation | ||||
'orientation' => Pdf::ORIENT_PORTRAIT, | |||||
'orientation' => Pdf::ORIENT_PORTRAIT, | |||||
// stream to browser inline | // stream to browser inline | ||||
'destination' => Pdf::DEST_BROWSER, | |||||
'destination' => Pdf::DEST_BROWSER, | |||||
// your html content input | // your html content input | ||||
'content' => $content, | |||||
'content' => $content, | |||||
'marginRight' => 0, | 'marginRight' => 0, | ||||
'marginLeft' => 0, | 'marginLeft' => 0, | ||||
'marginTop' => 0, | 'marginTop' => 0, | ||||
// enhanced bootstrap css built by Krajee for mPDF formatting | // enhanced bootstrap css built by Krajee for mPDF formatting | ||||
//'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', | //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', | ||||
'cssFile' => '@app/web/css/screen.css', | 'cssFile' => '@app/web/css/screen.css', | ||||
// any css to be embedded if required | |||||
//'cssInline' => '.kv-heading-1{font-size:18px}', | |||||
// set mPDF properties on the fly | |||||
//'options' => ['title' => 'Krajee Report Title'], | |||||
// call mPDF methods on the fly | |||||
/*'methods' => [ | |||||
'SetHeader'=>['Commandes du '.$date_str], | |||||
'SetFooter'=>['{PAGENO}'], | |||||
]*/ | |||||
// any css to be embedded if required | |||||
//'cssInline' => '.kv-heading-1{font-size:18px}', | |||||
// set mPDF properties on the fly | |||||
//'options' => ['title' => 'Krajee Report Title'], | |||||
// call mPDF methods on the fly | |||||
/* 'methods' => [ | |||||
'SetHeader'=>['Commandes du '.$date_str], | |||||
'SetFooter'=>['{PAGENO}'], | |||||
] */ | |||||
]); | ]); | ||||
// return the pdf output as per the destination setting | // return the pdf output as per the destination setting | ||||
return $pdf->render(); | |||||
return $pdf->render(); | |||||
} | } | ||||
} | } |
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use common\models\Etablissement; | use common\models\Etablissement; | ||||
use common\models\Commande ; | |||||
use common\models\CommandeAuto ; | |||||
use common\models\Production ; | |||||
use common\models\Commande; | |||||
use common\models\CommandeAuto; | |||||
use common\models\Production; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class CronController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class CronController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['?'], | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['?'], | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionInitBddDemo($key = '') | |||||
{ | |||||
if($key == '45432df6e842ac71aa0b5bb6b9f25d44' && YII_ENV == 'demo') | |||||
{ | |||||
public function actionInitBddDemo($key = '') { | |||||
if ($key == '45432df6e842ac71aa0b5bb6b9f25d44' && YII_ENV == 'demo') { | |||||
$arr_noms = [ | $arr_noms = [ | ||||
'Martin', 'Bernard', 'Thomas','Petit','Robert', 'Richard','Durand','Dubois', | |||||
'Martin', 'Bernard', 'Thomas', 'Petit', 'Robert', 'Richard', 'Durand', 'Dubois', | |||||
'Moreau', 'Laurent', 'Simon', 'Michel', 'Lefebvre', 'Leroy', 'Roux', 'David', | 'Moreau', 'Laurent', 'Simon', 'Michel', 'Lefebvre', 'Leroy', 'Roux', 'David', | ||||
'Bertrand', 'Morel', 'Fournier', 'Girard', 'Bonnet', 'Dupont','Lambert', 'Fontaine', | |||||
'Rousseau', 'Vincent', 'Muller','Lefevre', 'Faure', 'Andre', 'Mercier', 'Blanc', 'Guerin', | |||||
'Boyer', 'Garnier', 'Chevalier', 'François','Legrand','Gauthier','Garcia','Perrin', | |||||
'Robin','Clement','Morin','Nicolas','Henry','Roussel','Mathieu','Gautier','Masson', | |||||
'Marchand','Duval','Denis','Dumont','Marie','Lemaire','Noël','Meyer','Dufour', | |||||
'Meunier','Brun','Blanchard','Giraud','Joly','Rivière','Lucas','Brunet','Gaillard','Barbier', | |||||
'Arnaud','Martinez','Gerard','Roche','Renard','Schmitt','Roy','Leroux','Colin','Vidal', | |||||
'Caron','Picard','Roger','Fabre','Aubert','Lemoine','Renaud','Dumas','Lacroix','Olivier', | |||||
'Philippe','Bourgeois','Pierre','Benoit','Rey','Leclerc','Payet','Rolland','Lecomte','Lopez', | |||||
'Jean','Dupuis','Guillot','Hubert','Berger','Carpentier','Sanchez','Dupuis','Moulin', | |||||
'Louis','Deschamps','Huet','Vasseur','Perez','Trouillot','Fusillier','Massenot','Boucher','Fleury', | |||||
'Royer','Klein','Jacquet','Jaquin','Adam','Paris','Poirier','Aubry','Guyot','Carré','Charles', | |||||
'Charpentier','Menard','Bailly','Bertin','Le Gall','Collet','Leger','Bouvier','Millet','Daniel', | |||||
'Langlois','Pelletier','Perrier','Leblanc','Lebrun','Monnier','Michaud','Laporte','Carlier', | |||||
'Pasquier','Delaunay','Lamy','Gilbert','Lejeune','Pichon','Cordier','Barthelemy','Perret','Reynaud', | |||||
'Humbert','Marechal','Bernard','Lemaitre','Gay','Bouchet','Da Silva','Chauvin','Chevalier','Tessier', | |||||
'Poulain','Girondin','Gillet','Guichard' | |||||
'Bertrand', 'Morel', 'Fournier', 'Girard', 'Bonnet', 'Dupont', 'Lambert', 'Fontaine', | |||||
'Rousseau', 'Vincent', 'Muller', 'Lefevre', 'Faure', 'Andre', 'Mercier', 'Blanc', 'Guerin', | |||||
'Boyer', 'Garnier', 'Chevalier', 'François', 'Legrand', 'Gauthier', 'Garcia', 'Perrin', | |||||
'Robin', 'Clement', 'Morin', 'Nicolas', 'Henry', 'Roussel', 'Mathieu', 'Gautier', 'Masson', | |||||
'Marchand', 'Duval', 'Denis', 'Dumont', 'Marie', 'Lemaire', 'Noël', 'Meyer', 'Dufour', | |||||
'Meunier', 'Brun', 'Blanchard', 'Giraud', 'Joly', 'Rivière', 'Lucas', 'Brunet', 'Gaillard', 'Barbier', | |||||
'Arnaud', 'Martinez', 'Gerard', 'Roche', 'Renard', 'Schmitt', 'Roy', 'Leroux', 'Colin', 'Vidal', | |||||
'Caron', 'Picard', 'Roger', 'Fabre', 'Aubert', 'Lemoine', 'Renaud', 'Dumas', 'Lacroix', 'Olivier', | |||||
'Philippe', 'Bourgeois', 'Pierre', 'Benoit', 'Rey', 'Leclerc', 'Payet', 'Rolland', 'Lecomte', 'Lopez', | |||||
'Jean', 'Dupuis', 'Guillot', 'Hubert', 'Berger', 'Carpentier', 'Sanchez', 'Dupuis', 'Moulin', | |||||
'Louis', 'Deschamps', 'Huet', 'Vasseur', 'Perez', 'Trouillot', 'Fusillier', 'Massenot', 'Boucher', 'Fleury', | |||||
'Royer', 'Klein', 'Jacquet', 'Jaquin', 'Adam', 'Paris', 'Poirier', 'Aubry', 'Guyot', 'Carré', 'Charles', | |||||
'Charpentier', 'Menard', 'Bailly', 'Bertin', 'Le Gall', 'Collet', 'Leger', 'Bouvier', 'Millet', 'Daniel', | |||||
'Langlois', 'Pelletier', 'Perrier', 'Leblanc', 'Lebrun', 'Monnier', 'Michaud', 'Laporte', 'Carlier', | |||||
'Pasquier', 'Delaunay', 'Lamy', 'Gilbert', 'Lejeune', 'Pichon', 'Cordier', 'Barthelemy', 'Perret', 'Reynaud', | |||||
'Humbert', 'Marechal', 'Bernard', 'Lemaitre', 'Gay', 'Bouchet', 'Da Silva', 'Chauvin', 'Chevalier', 'Tessier', | |||||
'Poulain', 'Girondin', 'Gillet', 'Guichard' | |||||
]; | ]; | ||||
$arr_prenoms = [ | $arr_prenoms = [ | ||||
'Adel','Antonin','Armand','Arnaud','Aymeric','Baptiste','Barnabé','Bernard','Brice','Baudouin', | |||||
'Camille','Cassandre','Célestin','Christian','Clément','Cyril','Claude','Damien','Daniel','David', | |||||
'Delphin','Denis','Didier','Dimitri','Dorothée','Désiré','Edgard','Etienne','Eugène','Eudes','Eric', | |||||
'Fabien','Fabrice','Flavien','Florent','Francois','Frédéric','Gabin','Gabriel','Gautier','Gilles','Guy', | |||||
'Hervé','Huvert','Hugues','Hector','Jacques','Jason','Jean','Jeannot','Johan','Julien','Léon','Lionel','Loïc', | |||||
'Lucas','Luc','Lucien','Maurice','Maxence','Maxime','Michel','Morgan','Nicolas','Normand','Norbert','Olivier,', | |||||
'Pascal','Patrice','Pierrick','Raphael','Roland','Stéphane','Sylvain','Sylvestre','Timothée','Thomas','Tristan', | |||||
'Ulysse','Vincent','Victor','Vivien', | |||||
'Adeline','Albane','Alix','Amélie','Arielle','Aurelle','Blandine','Blanche','Brigitte','Berthe','Camille','Capucine', | |||||
'Catherine','Cécile','Charlotte','Chloé','Claudine','Clémenence','Constance','Cyrielle','Corinne','Danielle', | |||||
'Delphine','Denise','Dominique','Diane','Édith','Éliane','Éléonore','Émilie','Emmanuelle','Ève','Évelyne', | |||||
'Fanny','Flavie','Flore','Françoise', 'Gabrielle','Gaëlle','Geneviève','Georgette','Germaine','Gertrude','Gisèle', | |||||
'Gwenaëlle','Hélène','Héloïse','Henriette','Huguette','Inès','Isabelle','Jacqueline','Jeanne','Joëlle','Joséphine', | |||||
'Juliette','Justine','Julie','Laura','Laure','Léa','Léonie','Lucie','Lucienne','Lorraine','Lucille','Ludivine','Lydie', | |||||
'Margot','Marion','Marlène','Marthe','Mélodie','Monique','Noémie','Nadine','Nadège','Océane','Odette','Odile','Paulette', | |||||
'Rose','Roseline','Renée','Sabine','Sophie','Suzanne','Sylvie','Thérèse', | |||||
'Adel', 'Antonin', 'Armand', 'Arnaud', 'Aymeric', 'Baptiste', 'Barnabé', 'Bernard', 'Brice', 'Baudouin', | |||||
'Camille', 'Cassandre', 'Célestin', 'Christian', 'Clément', 'Cyril', 'Claude', 'Damien', 'Daniel', 'David', | |||||
'Delphin', 'Denis', 'Didier', 'Dimitri', 'Dorothée', 'Désiré', 'Edgard', 'Etienne', 'Eugène', 'Eudes', 'Eric', | |||||
'Fabien', 'Fabrice', 'Flavien', 'Florent', 'Francois', 'Frédéric', 'Gabin', 'Gabriel', 'Gautier', 'Gilles', 'Guy', | |||||
'Hervé', 'Huvert', 'Hugues', 'Hector', 'Jacques', 'Jason', 'Jean', 'Jeannot', 'Johan', 'Julien', 'Léon', 'Lionel', 'Loïc', | |||||
'Lucas', 'Luc', 'Lucien', 'Maurice', 'Maxence', 'Maxime', 'Michel', 'Morgan', 'Nicolas', 'Normand', 'Norbert', 'Olivier,', | |||||
'Pascal', 'Patrice', 'Pierrick', 'Raphael', 'Roland', 'Stéphane', 'Sylvain', 'Sylvestre', 'Timothée', 'Thomas', 'Tristan', | |||||
'Ulysse', 'Vincent', 'Victor', 'Vivien', | |||||
'Adeline', 'Albane', 'Alix', 'Amélie', 'Arielle', 'Aurelle', 'Blandine', 'Blanche', 'Brigitte', 'Berthe', 'Camille', 'Capucine', | |||||
'Catherine', 'Cécile', 'Charlotte', 'Chloé', 'Claudine', 'Clémenence', 'Constance', 'Cyrielle', 'Corinne', 'Danielle', | |||||
'Delphine', 'Denise', 'Dominique', 'Diane', 'Édith', 'Éliane', 'Éléonore', 'Émilie', 'Emmanuelle', 'Ève', 'Évelyne', | |||||
'Fanny', 'Flavie', 'Flore', 'Françoise', 'Gabrielle', 'Gaëlle', 'Geneviève', 'Georgette', 'Germaine', 'Gertrude', 'Gisèle', | |||||
'Gwenaëlle', 'Hélène', 'Héloïse', 'Henriette', 'Huguette', 'Inès', 'Isabelle', 'Jacqueline', 'Jeanne', 'Joëlle', 'Joséphine', | |||||
'Juliette', 'Justine', 'Julie', 'Laura', 'Laure', 'Léa', 'Léonie', 'Lucie', 'Lucienne', 'Lorraine', 'Lucille', 'Ludivine', 'Lydie', | |||||
'Margot', 'Marion', 'Marlène', 'Marthe', 'Mélodie', 'Monique', 'Noémie', 'Nadine', 'Nadège', 'Océane', 'Odette', 'Odile', 'Paulette', | |||||
'Rose', 'Roseline', 'Renée', 'Sabine', 'Sophie', 'Suzanne', 'Sylvie', 'Thérèse', | |||||
]; | ]; | ||||
$arr_noms_checked = [] ; | |||||
$arr_prenoms_checked = [] ; | |||||
$arr_noms_checked = []; | |||||
$arr_prenoms_checked = []; | |||||
$users = User::find() | $users = User::find() | ||||
->joinWith('userEtablissement') | ->joinWith('userEtablissement') | ||||
->where('user_etablissement.id_etablissement = 1') | ->where('user_etablissement.id_etablissement = 1') | ||||
->all() ; | |||||
foreach($users as $u) | |||||
{ | |||||
if($u->email != 'boulanger@laboiteapain.net') | |||||
{ | |||||
->all(); | |||||
foreach ($users as $u) { | |||||
if ($u->email != 'boulanger@laboiteapain.net') { | |||||
do { | do { | ||||
$i_nom = rand(0, count($arr_noms)-1) ; | |||||
$i_prenom = rand(0, count($arr_prenoms)-1) ; | |||||
} while(isset($arr_noms_checked[$i_nom]) || isset($arr_prenoms_checked[$i_prenom])) ; | |||||
$i_nom = rand(0, count($arr_noms) - 1); | |||||
$i_prenom = rand(0, count($arr_prenoms) - 1); | |||||
} while (isset($arr_noms_checked[$i_nom]) || isset($arr_prenoms_checked[$i_prenom])); | |||||
$arr_noms_checked[$i_nom] = true ; | |||||
$arr_prenoms_checked[$i_prenom] = true ; | |||||
$arr_noms_checked[$i_nom] = true; | |||||
$arr_prenoms_checked[$i_prenom] = true; | |||||
$nom = $arr_noms[$i_nom] ; | |||||
$prenom = $arr_prenoms[$i_prenom] ; | |||||
$nom = $arr_noms[$i_nom]; | |||||
$prenom = $arr_prenoms[$i_prenom]; | |||||
$u->nom = $nom ; | |||||
$u->prenom = $prenom ; | |||||
$email = strtolower($prenom).'.'.strtolower($nom).'@yopmail.com' ; | |||||
$u->nom = $nom; | |||||
$u->prenom = $prenom; | |||||
$email = strtolower($prenom) . '.' . strtolower($nom) . '@yopmail.com'; | |||||
$email = htmlentities($email, ENT_NOQUOTES, 'utf-8'); | $email = htmlentities($email, ENT_NOQUOTES, 'utf-8'); | ||||
$email = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $email); | $email = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $email); | ||||
$email = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $email); // pour les ligatures e.g. 'œ' | $email = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $email); // pour les ligatures e.g. 'œ' | ||||
$email = preg_replace('#&[^;]+;#', '', $email); // supprime les autres caractères | $email = preg_replace('#&[^;]+;#', '', $email); // supprime les autres caractères | ||||
$email = str_replace(' ','',$email) ; | |||||
$u->email = $email ; | |||||
$u->telephone = '0600000000' ; | |||||
} | |||||
else { | |||||
$email = str_replace(' ', '', $email); | |||||
$u->email = $email; | |||||
$u->telephone = '0600000000'; | |||||
} else { | |||||
/* | /* | ||||
* Le hash du mot de passe en production est volontairement corrompu | * Le hash du mot de passe en production est volontairement corrompu | ||||
* pour empêcher la connexion des utilisateurs via ce compte en prod. | * pour empêcher la connexion des utilisateurs via ce compte en prod. | ||||
* Lors de l'initialisation des utilisateurs sur l'espace de démo, | * Lors de l'initialisation des utilisateurs sur l'espace de démo, | ||||
* on remet le bon hash pour que ce compte soit disponible. | * on remet le bon hash pour que ce compte soit disponible. | ||||
*/ | */ | ||||
$u->password_hash = '$2y$13$2D5T3Eo0pySmtlAuEGcfmOdTR5mleog8Y6YPGhop/ych6pbj6aN2y' ; | |||||
$u->password_hash = '$2y$13$2D5T3Eo0pySmtlAuEGcfmOdTR5mleog8Y6YPGhop/ych6pbj6aN2y'; | |||||
} | } | ||||
$u->save(); | $u->save(); | ||||
} | } | ||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->where('username IS NOT NULL') | ->where('username IS NOT NULL') | ||||
->all() ; | |||||
foreach($commandes as $c) | |||||
{ | |||||
$nom = $arr_noms[rand(0, count($arr_noms)-1)] ; | |||||
$prenom = $arr_prenoms[rand(0, count($arr_prenoms)-1)] ; | |||||
$c->username = $prenom.' '.$nom ; | |||||
$c->save() ; | |||||
->all(); | |||||
foreach ($commandes as $c) { | |||||
$nom = $arr_noms[rand(0, count($arr_noms) - 1)]; | |||||
$prenom = $arr_prenoms[rand(0, count($arr_prenoms) - 1)]; | |||||
$c->username = $prenom . ' ' . $nom; | |||||
$c->save(); | |||||
} | } | ||||
$commandes_auto = CommandeAuto::find() | $commandes_auto = CommandeAuto::find() | ||||
->where('username IS NOT NULL') | ->where('username IS NOT NULL') | ||||
->all() ; | |||||
foreach($commandes_auto as $c) | |||||
{ | |||||
$nom = $arr_noms[rand(0, count($arr_noms)-1)] ; | |||||
$prenom = $arr_prenoms[rand(0, count($arr_prenoms)-1)] ; | |||||
$c->username = $prenom.' '.$nom ; | |||||
$c->save() ; | |||||
->all(); | |||||
foreach ($commandes_auto as $c) { | |||||
$nom = $arr_noms[rand(0, count($arr_noms) - 1)]; | |||||
$prenom = $arr_prenoms[rand(0, count($arr_prenoms) - 1)]; | |||||
$c->username = $prenom . ' ' . $nom; | |||||
$c->save(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public function actionSendCommandes($key = '') | |||||
{ | |||||
if($key == '64ac0bdab7e9f5e48c4d991ec5201d57') | |||||
{ | |||||
$heure = date('H') ; | |||||
if($heure == '00') | |||||
{ | |||||
$date = date('Y-m-d') ; | |||||
} | |||||
else { | |||||
$date = date('Y-m-d', time()+24*60*60) ; | |||||
public function actionSendCommandes($key = '') { | |||||
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | |||||
$heure = date('H'); | |||||
if ($heure == '00') { | |||||
$date = date('Y-m-d'); | |||||
} else { | |||||
$date = date('Y-m-d', time() + 24 * 60 * 60); | |||||
} | } | ||||
$etablissements = Etablissement::find()->all() ; | |||||
$etablissements = Etablissement::find()->all(); | |||||
foreach($etablissements as $e) | |||||
{ | |||||
foreach ($etablissements as $e) { | |||||
$production = Production::findOne([ | $production = Production::findOne([ | ||||
'date' => $date, | |||||
'actif' => 1, | |||||
'id_etablissement' => $e['id'], | |||||
]) ; | |||||
'date' => $date, | |||||
'actif' => 1, | |||||
'id_etablissement' => $e['id'], | |||||
]); | |||||
if($production && $heure == $e['heure_limite_commande']) | |||||
{ | |||||
if ($production && $heure == $e['heure_limite_commande']) { | |||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->with('commandeProduits', 'user') | |||||
->joinWith('production') | |||||
->where(['production.date' => $date]) | |||||
->andWhere(['production.id_etablissement' => $e['id']]) | |||||
->orderBy('date ASC') | |||||
->all(); | |||||
->with('commandeProduits', 'user') | |||||
->joinWith('production') | |||||
->where(['production.date' => $date]) | |||||
->andWhere(['production.id_etablissement' => $e['id']]) | |||||
->orderBy('date ASC') | |||||
->all(); | |||||
$user = User::findOne([ | $user = User::findOne([ | ||||
'id_etablissement' => $e['id'], | |||||
'status' => User::STATUS_BOULANGER | |||||
]) ; | |||||
'id_etablissement' => $e['id'], | |||||
'status' => User::STATUS_BOULANGER | |||||
]); | |||||
$mail = Yii::$app->mailer->compose( | $mail = Yii::$app->mailer->compose( | ||||
[ | |||||
'html' => 'cronRecapCommandes-html', | |||||
'text' => 'cronRecapCommandes-text', | |||||
], | |||||
[ | |||||
'date' => $date, | |||||
'commandes' => $commandes | |||||
] | |||||
[ | |||||
'html' => 'cronRecapCommandes-html', | |||||
'text' => 'cronRecapCommandes-text', | |||||
], [ | |||||
'date' => $date, | |||||
'commandes' => $commandes | |||||
] | |||||
) | ) | ||||
->setTo($user->email) | ->setTo($user->email) | ||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) ; | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']); | |||||
if(count($commandes)) | |||||
{ | |||||
$sujet = '[La boîte à pain] Commandes du '.date('d/m',strtotime($date)) ; | |||||
if (count($commandes)) { | |||||
$sujet = '[La boîte à pain] Commandes du ' . date('d/m', strtotime($date)); | |||||
// génération du pdf de commande | // génération du pdf de commande | ||||
Yii::$app->runAction('commande/report-cron', [ | Yii::$app->runAction('commande/report-cron', [ | ||||
'date' => $date, | |||||
'date' => $date, | |||||
'save' => true, | 'save' => true, | ||||
'id_etablissement' => $e['id'] , | |||||
'id_etablissement' => $e['id'], | |||||
'key' => '64ac0bdab7e9f5e48c4d991ec5201d57' | 'key' => '64ac0bdab7e9f5e48c4d991ec5201d57' | ||||
]); | ]); | ||||
$mail->attach(Yii::getAlias('@app/web/pdf/Commandes-'.$date.'-'.$e['id'].'.pdf')) ; | |||||
} | |||||
else { | |||||
$sujet = '[La boîte à pain] Aucune commande' ; | |||||
$mail->attach(Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $e['id'] . '.pdf')); | |||||
} else { | |||||
$sujet = '[La boîte à pain] Aucune commande'; | |||||
} | } | ||||
$mail->setSubject($sujet) | $mail->setSubject($sujet) | ||||
->send(); | |||||
->send(); | |||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
} | } |
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | 'class' => AccessControl::className(), | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | ] | ||||
], | ], | ||||
], | ], | ||||
*/ | */ | ||||
public function actionIndex() { | public function actionIndex() { | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']), | |||||
'query' => Developpement::find()->with(['developpementPriorite', 'developpementPrioriteCurrentEtablissement']), | |||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'dataProvider' => $dataProvider, | |||||
'dataProvider' => $dataProvider, | |||||
]); | ]); | ||||
} | } | ||||
*/ | */ | ||||
public function actionCreate() { | public function actionCreate() { | ||||
$model = new Developpement(); | $model = new Developpement(); | ||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
$model->date = date('Y-m-d H:i:s') ; | |||||
$model->setDateLivraison() ; | |||||
if($model->save()) { | |||||
Yii::$app->getSession()->setFlash('success','Développement ajouté') ; | |||||
$model->date = date('Y-m-d H:i:s'); | |||||
$model->setDateLivraison(); | |||||
if ($model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Développement ajouté'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
$model->setDateLivraison() ; | |||||
if($model->save()) { | |||||
Yii::$app->getSession()->setFlash('success','Développement modifié') ; | |||||
$model->setDateLivraison(); | |||||
if ($model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Développement modifié'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public function actionDelete($id) { | public function actionDelete($id) { | ||||
$this->findModel($id)->delete(); | $this->findModel($id)->delete(); | ||||
Yii::$app->getSession()->setFlash('success','Développement supprimé') ; | |||||
Yii::$app->getSession()->setFlash('success', 'Développement supprimé'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
public function actionPriorite($id_developpement, $priorite = null) { | public function actionPriorite($id_developpement, $priorite = null) { | ||||
$developpement_priorite = DeveloppementPriorite::find() | $developpement_priorite = DeveloppementPriorite::find() | ||||
->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->one() ; | |||||
if(in_array($priorite, | |||||
[DeveloppementPriorite::PRIORITE_HAUTE, | |||||
DeveloppementPriorite::PRIORITE_NORMALE, | |||||
DeveloppementPriorite::PRIORITE_BASSE])) { | |||||
if($developpement_priorite) { | |||||
$developpement_priorite->priorite = $priorite ; | |||||
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
} | |||||
else { | |||||
$developpement_priorite = new DeveloppementPriorite ; | |||||
$developpement_priorite->id_developpement = $id_developpement ; | |||||
$developpement_priorite->priorite = $priorite ; | |||||
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->one(); | |||||
if (in_array($priorite, [DeveloppementPriorite::PRIORITE_HAUTE, | |||||
DeveloppementPriorite::PRIORITE_NORMALE, | |||||
DeveloppementPriorite::PRIORITE_BASSE])) { | |||||
if ($developpement_priorite) { | |||||
$developpement_priorite->priorite = $priorite; | |||||
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
} else { | |||||
$developpement_priorite = new DeveloppementPriorite; | |||||
$developpement_priorite->id_developpement = $id_developpement; | |||||
$developpement_priorite->priorite = $priorite; | |||||
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
} | } | ||||
$developpement_priorite->save() ; | |||||
} | |||||
else { | |||||
if($developpement_priorite) { | |||||
$developpement_priorite->delete() ; | |||||
$developpement_priorite->save(); | |||||
} else { | |||||
if ($developpement_priorite) { | |||||
$developpement_priorite->delete(); | |||||
} | } | ||||
} | } | ||||
$this->redirect(['index']) ; | |||||
$this->redirect(['index']); | |||||
} | } | ||||
/** | /** | ||||
* Finds the Developpement model based on its primary key value. | * Finds the Developpement model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\helpers\Upload ; | |||||
use common\models\Etablissement ; | |||||
use yii\data\ActiveDataProvider ; | |||||
use common\models\Facture ; | |||||
use common\helpers\Upload; | |||||
use common\models\Etablissement; | |||||
use yii\data\ActiveDataProvider; | |||||
use common\models\Facture; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class EtablissementAdminController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class EtablissementAdminController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$datas_etablissements = new ActiveDataProvider([ | $datas_etablissements = new ActiveDataProvider([ | ||||
'query' => Etablissement::find() | 'query' => Etablissement::find() | ||||
->with('userEtablissement','user') | |||||
->orderBy('date_creation DESC'), | |||||
->with('userEtablissement', 'user') | |||||
->orderBy('date_creation DESC'), | |||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 1000, | 'pageSize' => 1000, | ||||
], | ], | ||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'datas_etablissements' => $datas_etablissements, | |||||
'datas_etablissements' => $datas_etablissements, | |||||
]); | ]); | ||||
} | } | ||||
public function actionFacturer($id_etablissement) | |||||
{ | |||||
$etablissement = Etablissement::findOne($id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
$periode = date('Y-m', strtotime('-1 month')) ; | |||||
$last_facture = Facture::getLastFacture() ; | |||||
if(!$last_facture) | |||||
{ | |||||
$reference = 'BAP000001' ; | |||||
} | |||||
else { | |||||
$reference = str_replace('BAP','',$last_facture->reference) ; | |||||
$reference ++ ; | |||||
$reference = 'BAP'.$reference ; | |||||
public function actionFacturer($id_etablissement) { | |||||
$etablissement = Etablissement::findOne($id_etablissement); | |||||
if ($etablissement) { | |||||
$periode = date('Y-m', strtotime('-1 month')); | |||||
$last_facture = Facture::getLastFacture(); | |||||
if (!$last_facture) { | |||||
$reference = 'BAP000001'; | |||||
} else { | |||||
$reference = str_replace('BAP', '', $last_facture->reference); | |||||
$reference ++; | |||||
$reference = 'BAP' . $reference; | |||||
} | } | ||||
$facture = new Facture ; | |||||
$facture->id_etablissement = $id_etablissement ; | |||||
$facture->date = date('Y-m-d H:i:s') ; | |||||
$facture->reference = $reference ; | |||||
$facture->ca = $etablissement->getCA($periode) ; | |||||
$facture->montant_ht = $etablissement->getMontantFacturer($periode) ; | |||||
$facture->libelle = 'Facture '.date('m/Y', strtotime('-1 month')) ; | |||||
$facture->texte = 'Utilisation de la plateforme <strong>La boîte à pain</strong> pour le mois : '.date('m/Y', strtotime('-1 month')).'<br />' | |||||
. 'Chiffre d\'affaire réalisé sur la plateforme : <strong>'.number_format($facture->ca,2).' €</strong> commissionné à <strong>1%</strong>.' ; | |||||
$facture->paye = 0 ; | |||||
$facture->periode = $periode ; | |||||
$facture->save() ; | |||||
$facture = new Facture; | |||||
$facture->id_etablissement = $id_etablissement; | |||||
$facture->date = date('Y-m-d H:i:s'); | |||||
$facture->reference = $reference; | |||||
$facture->ca = $etablissement->getCA($periode); | |||||
$facture->montant_ht = $etablissement->getMontantFacturer($periode); | |||||
$facture->libelle = 'Facture ' . date('m/Y', strtotime('-1 month')); | |||||
$facture->texte = 'Utilisation de la plateforme <strong>La boîte à pain</strong> pour le mois : ' . date('m/Y', strtotime('-1 month')) . '<br />' | |||||
. 'Chiffre d\'affaire réalisé sur la plateforme : <strong>' . number_format($facture->ca, 2) . ' €</strong> commissionné à <strong>1%</strong>.'; | |||||
$facture->paye = 0; | |||||
$facture->periode = $periode; | |||||
$facture->save(); | |||||
} | } | ||||
$this->redirect(['etablissement-admin/index']) ; | |||||
$this->redirect(['etablissement-admin/index']); | |||||
} | } | ||||
public function actionFacturation() | |||||
{ | |||||
public function actionFacturation() { | |||||
$datas_factures = new ActiveDataProvider([ | $datas_factures = new ActiveDataProvider([ | ||||
'query' => Facture::find() | 'query' => Facture::find() | ||||
->with('etablissement') | |||||
->orderBy('reference DESC'), | |||||
->with('etablissement') | |||||
->orderBy('reference DESC'), | |||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 1000, | 'pageSize' => 1000, | ||||
], | ], | ||||
]); | ]); | ||||
return $this->render('facturation', [ | return $this->render('facturation', [ | ||||
'datas_factures' => $datas_factures, | |||||
'datas_factures' => $datas_factures, | |||||
]); | ]); | ||||
} | } | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = Etablissement::findOne($id)) !== null) { | if (($model = Etablissement::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\helpers\Upload ; | |||||
use common\models\Etablissement ; | |||||
use common\models\Facture ; | |||||
use common\helpers\Upload; | |||||
use common\models\Etablissement; | |||||
use common\models\Facture; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class EtablissementController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class EtablissementController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionUpdate() | |||||
{ | |||||
$request = Yii::$app->request ; | |||||
public function actionUpdate() { | |||||
$request = Yii::$app->request; | |||||
$model = $this->findModel(Yii::$app->user->identity->id_etablissement); | $model = $this->findModel(Yii::$app->user->identity->id_etablissement); | ||||
$logo_filename_old = $model->logo ; | |||||
$photo_filename_old = $model->photo ; | |||||
$logo_filename_old = $model->logo; | |||||
$photo_filename_old = $model->photo; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
Upload::uploadFile($model, 'logo', $logo_filename_old) ; | |||||
Upload::uploadFile($model, 'photo', $photo_filename_old) ; | |||||
$delete_logo = $request->post('delete_logo',0) ; | |||||
if($delete_logo) { | |||||
$model->logo = '' ; | |||||
$model->save() ; | |||||
Upload::uploadFile($model, 'logo', $logo_filename_old); | |||||
Upload::uploadFile($model, 'photo', $photo_filename_old); | |||||
$delete_logo = $request->post('delete_logo', 0); | |||||
if ($delete_logo) { | |||||
$model->logo = ''; | |||||
$model->save(); | |||||
} | } | ||||
$delete_photo = $request->post('delete_photo',0) ; | |||||
if($delete_photo) { | |||||
$model->photo = '' ; | |||||
$model->save() ; | |||||
$delete_photo = $request->post('delete_photo', 0); | |||||
if ($delete_photo) { | |||||
$model->photo = ''; | |||||
$model->save(); | |||||
} | } | ||||
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public function actionFacturation() | |||||
{ | |||||
public function actionFacturation() { | |||||
$datas_factures = new ActiveDataProvider([ | $datas_factures = new ActiveDataProvider([ | ||||
'query' => Facture::find() | 'query' => Facture::find() | ||||
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('reference DESC'), | |||||
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('reference DESC'), | |||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 1000, | 'pageSize' => 1000, | ||||
], | ], | ||||
]); | ]); | ||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; | |||||
if ($etablissement->load(Yii::$app->request->post())) | |||||
{ | |||||
$etablissement->save() ; | |||||
if(!is_null($etablissement->prix_libre)) | |||||
$alert_prix_libre = true ; | |||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); | |||||
if ($etablissement->load(Yii::$app->request->post())) { | |||||
$etablissement->save(); | |||||
if (!is_null($etablissement->prix_libre)) | |||||
$alert_prix_libre = true; | |||||
} | } | ||||
return $this->render('facturation', [ | return $this->render('facturation', [ | ||||
'datas_factures' => $datas_factures, | 'datas_factures' => $datas_factures, | ||||
'etablissement' => $etablissement, | 'etablissement' => $etablissement, | ||||
'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false | 'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false | ||||
]); | ]); | ||||
} | } | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = Etablissement::findOne($id)) !== null) { | if (($model = Etablissement::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
/** | /** | ||||
* ProduitController implements the CRUD actions for Produit model. | * ProduitController implements the CRUD actions for Produit model. | ||||
*/ | */ | ||||
class PaiementController extends BackendController | |||||
{ | |||||
var $enableCsrfValidation = false ; | |||||
public function behaviors() | |||||
{ | |||||
class PaiementController extends BackendController { | |||||
var $enableCsrfValidation = false; | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'actions' => ['ipn'], | |||||
'allow' => true, | |||||
'roles' => ['?'], | |||||
], | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'actions' => ['ipn'], | |||||
'allow' => true, | |||||
'roles' => ['?'], | |||||
], | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* Lists all Produit models. | * Lists all Produit models. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
]); | ]); | ||||
} | } | ||||
public function actionAnnuler() | |||||
{ | |||||
return $this->render('annuler', [ | |||||
public function actionAnnuler() { | |||||
return $this->render('annuler', [ | |||||
]); | ]); | ||||
} | } | ||||
public function actionSucces() | |||||
{ | |||||
return $this->render('succes', [ | |||||
public function actionSucces() { | |||||
return $this->render('succes', [ | |||||
]); | ]); | ||||
} | } | ||||
public function beforeAction($action) | |||||
{ | |||||
if(Yii::$app->controller->action->id=="ipn") | |||||
public function beforeAction($action) { | |||||
if (Yii::$app->controller->action->id == "ipn") | |||||
$this->enableCsrfValidation = false; | $this->enableCsrfValidation = false; | ||||
return parent::beforeAction($action); | return parent::beforeAction($action); | ||||
} | } | ||||
public function actionIpn() | |||||
{ | |||||
public function actionIpn() { | |||||
if (isset($_POST)) { | if (isset($_POST)) { | ||||
$ipn = new PayPal_Ipn(false); | $ipn = new PayPal_Ipn(false); | ||||
if ($ipn->init()) | |||||
{ | |||||
if ($ipn->init()) { | |||||
$custom = $ipn->getKeyValue('custom'); | $custom = $ipn->getKeyValue('custom'); | ||||
$txn_type = $ipn->getKeyValue('txn_type'); | $txn_type = $ipn->getKeyValue('txn_type'); | ||||
if($txn_type == 'subscr_payment' && $custom) | |||||
{ | |||||
$user = User::findOne($custom) ; | |||||
if($user) | |||||
{ | |||||
$etablissement = Etablissement::findOne($user->id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
$etablissement->date_paiement = date('Y-m-d H:i:s',time()) ; | |||||
$etablissement->save() ; | |||||
if ($txn_type == 'subscr_payment' && $custom) { | |||||
$user = User::findOne($custom); | |||||
if ($user) { | |||||
$etablissement = Etablissement::findOne($user->id_etablissement); | |||||
if ($etablissement) { | |||||
$etablissement->date_paiement = date('Y-m-d H:i:s', time()); | |||||
$etablissement->save(); | |||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
/* Enable again if you use it */ | /* Enable again if you use it */ | ||||
Yii::$app->request->enableCsrfValidation = true; | Yii::$app->request->enableCsrfValidation = true; | ||||
} | } | ||||
} | } |
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\models\User; | use common\models\User; | ||||
use common\models\PointVenteUser ; | |||||
use common\models\PointVenteUser; | |||||
/** | /** | ||||
* PointVenteController implements the CRUD actions for PointVente model. | * PointVenteController implements the CRUD actions for PointVente model. | ||||
*/ | */ | ||||
class PointVenteController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class PointVenteController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
], | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
], | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* Lists all PointVente models. | * Lists all PointVente models. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => PointVente::find()->where(['id_etablissement'=>Yii::$app->user->identity->id_etablissement]) | |||||
'query' => PointVente::find()->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'dataProvider' => $dataProvider, | |||||
'dataProvider' => $dataProvider, | |||||
]); | ]); | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionView($id) | |||||
{ | |||||
public function actionView($id) { | |||||
return $this->render('view', [ | return $this->render('view', [ | ||||
'model' => $this->findModel($id), | |||||
'model' => $this->findModel($id), | |||||
]); | ]); | ||||
} | } | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionCreate() | |||||
{ | |||||
public function actionCreate() { | |||||
$model = new PointVente(); | $model = new PointVente(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$model->gestionPointFabrication() ; | |||||
$model->gestionAccesRestreint() ; | |||||
$model->gestionPointFabrication(); | |||||
$model->gestionAccesRestreint(); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', array_merge($this->initForm(),[ | |||||
'model' => $model, | |||||
return $this->render('update', array_merge($this->initForm(), [ | |||||
'model' => $model, | |||||
])); | ])); | ||||
} | } | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionUpdate($id) | |||||
{ | |||||
public function actionUpdate($id) { | |||||
$model = PointVente::find() | $model = PointVente::find() | ||||
->with('pointVenteUser') | |||||
->where(['id' => $id]) | |||||
->one() ; | |||||
foreach($model->pointVenteUser as $u) | |||||
{ | |||||
$model->users[] = $u->id_user ; | |||||
$model->users_commentaire[$u->id_user] = $u->commentaire ; | |||||
->with('pointVenteUser') | |||||
->where(['id' => $id]) | |||||
->one(); | |||||
foreach ($model->pointVenteUser as $u) { | |||||
$model->users[] = $u->id_user; | |||||
$model->users_commentaire[$u->id_user] = $u->commentaire; | |||||
} | } | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$model->gestionPointFabrication() ; | |||||
$model->gestionAccesRestreint() ; | |||||
$model->gestionPointFabrication(); | |||||
$model->gestionAccesRestreint(); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', array_merge($this->initForm($id),[ | |||||
'model' => $model, | |||||
return $this->render('update', array_merge($this->initForm($id), [ | |||||
'model' => $model, | |||||
])); | ])); | ||||
} | } | ||||
} | } | ||||
public function initForm($id = 0) | |||||
{ | |||||
public function initForm($id = 0) { | |||||
$users = User::findBy() | $users = User::findBy() | ||||
->orderBy('nom ASC') | ->orderBy('nom ASC') | ||||
->all() ; | |||||
->all(); | |||||
return [ | return [ | ||||
'users' => $users | 'users' => $users | ||||
] ; | |||||
]; | |||||
} | } | ||||
/** | /** | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionDelete($id) | |||||
{ | |||||
public function actionDelete($id) { | |||||
$this->findModel($id)->delete(); | $this->findModel($id)->delete(); | ||||
PointVenteUser::deleteAll(['id_point_vente' => $id]) ; | |||||
PointVenteUser::deleteAll(['id_point_vente' => $id]); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
* @return PointVente the loaded model | * @return PointVente the loaded model | ||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = PointVente::findOne($id)) !== null) { | if (($model = PointVente::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\ProductionProduit; | use common\models\ProductionProduit; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\models\Produit; | use common\models\Produit; | ||||
use yii\web\UploadedFile; | use yii\web\UploadedFile; | ||||
use common\helpers\Upload; | use common\helpers\Upload; | ||||
/** | /** | ||||
* ProduitController implements the CRUD actions for Produit model. | * ProduitController implements the CRUD actions for Produit model. | ||||
*/ | */ | ||||
class ProduitController extends BackendController | |||||
{ | |||||
var $enableCsrfValidation = false ; | |||||
public function behaviors() | |||||
{ | |||||
class ProduitController extends BackendController { | |||||
var $enableCsrfValidation = false; | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* Lists all Produit models. | * Lists all Produit models. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => Produit::find() | 'query' => Produit::find() | ||||
->where('(vrac IS NULL OR vrac = 0)') | |||||
->andWhere(['id_etablissement'=>Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('order ASC'), | |||||
->where('(vrac IS NULL OR vrac = 0)') | |||||
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('order ASC'), | |||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 1000, | 'pageSize' => 1000, | ||||
], | ], | ||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'dataProvider' => $dataProvider, | |||||
'dataProvider' => $dataProvider, | |||||
]); | ]); | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionView($id) | |||||
{ | |||||
public function actionView($id) { | |||||
return $this->render('view', [ | return $this->render('view', [ | ||||
'model' => $this->findModel($id), | |||||
'model' => $this->findModel($id), | |||||
]); | ]); | ||||
} | } | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionCreate() | |||||
{ | |||||
public function actionCreate() { | |||||
$model = new Produit(); | $model = new Produit(); | ||||
$model->actif = 1 ; | |||||
$model->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$model->saison = 'all' ; | |||||
$model->actif = 1; | |||||
$model->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
$model->saison = 'all'; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
Upload::uploadFile($model, 'illustration') ; | |||||
Upload::uploadFile($model, 'photo') ; | |||||
$model->save() ; | |||||
// on ajoute un enregistrement ProductionProduit pour chaque production | |||||
$productions = Production::find() | |||||
->where('date > '.date('Y-m-d')) | |||||
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->all() ; | |||||
foreach($productions as $prod) { | |||||
$production_produit = new ProductionProduit ; | |||||
$production_produit->id_production = $prod->id ; | |||||
$production_produit->id_produit = $model->id ; | |||||
$production_produit->actif = 0 ; | |||||
$production_produit->save() ; | |||||
} | |||||
Upload::uploadFile($model, 'illustration'); | |||||
Upload::uploadFile($model, 'photo'); | |||||
$model->save(); | |||||
// on ajoute un enregistrement ProductionProduit pour chaque production | |||||
$productions = Production::find() | |||||
->where('date > ' . date('Y-m-d')) | |||||
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->all(); | |||||
foreach ($productions as $prod) { | |||||
$production_produit = new ProductionProduit; | |||||
$production_produit->id_production = $prod->id; | |||||
$production_produit->id_produit = $model->id; | |||||
$production_produit->actif = 0; | |||||
$production_produit->save(); | |||||
} | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionUpdate($id) | |||||
{ | |||||
$request = Yii::$app->request ; | |||||
public function actionUpdate($id) { | |||||
$request = Yii::$app->request; | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$illustration_filename_old = $model->illustration ; | |||||
$photo_filename_old = $model->photo ; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
Upload::uploadFile($model, 'illustration', $illustration_filename_old) ; | |||||
Upload::uploadFile($model, 'photo', $photo_filename_old) ; | |||||
$delete_illustration = $request->post('delete_illustration',0) ; | |||||
if($delete_illustration) { | |||||
$model->illustration = '' ; | |||||
$model->save() ; | |||||
} | |||||
$delete_photo = $request->post('delete_photo',0) ; | |||||
if($delete_photo) { | |||||
$model->photo = '' ; | |||||
$model->save() ; | |||||
} | |||||
$illustration_filename_old = $model->illustration; | |||||
$photo_filename_old = $model->photo; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
Upload::uploadFile($model, 'illustration', $illustration_filename_old); | |||||
Upload::uploadFile($model, 'photo', $photo_filename_old); | |||||
$delete_illustration = $request->post('delete_illustration', 0); | |||||
if ($delete_illustration) { | |||||
$model->illustration = ''; | |||||
$model->save(); | |||||
} | |||||
$delete_photo = $request->post('delete_photo', 0); | |||||
if ($delete_photo) { | |||||
$model->photo = ''; | |||||
$model->save(); | |||||
} | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionDelete($id) | |||||
{ | |||||
public function actionDelete($id) { | |||||
$this->findModel($id)->delete(); | $this->findModel($id)->delete(); | ||||
$productions_produits = ProductionProduit::find()->where(['id_produit'=>$id])->all() ; | |||||
foreach($productions_produits as $pp) | |||||
{ | |||||
$pp->delete() ; | |||||
$productions_produits = ProductionProduit::find()->where(['id_produit' => $id])->all(); | |||||
foreach ($productions_produits as $pp) { | |||||
$pp->delete(); | |||||
} | } | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
public function actionOrdre($tab) | |||||
{ | |||||
public function actionOrdre($tab) { | |||||
$tab_ordre = json_decode(stripslashes($tab)); | $tab_ordre = json_decode(stripslashes($tab)); | ||||
foreach($tab_ordre as $id => $o) | |||||
{ | |||||
$produit = $this->findModel($id) ; | |||||
$produit->order = $o ; | |||||
$produit->save() ; | |||||
foreach ($tab_ordre as $id => $o) { | |||||
$produit = $this->findModel($id); | |||||
$produit->order = $o; | |||||
$produit->save(); | |||||
} | } | ||||
} | } | ||||
* @return Produit the loaded model | * @return Produit the loaded model | ||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = Produit::findOne($id)) !== null) { | if (($model = Produit::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace backend\controllers; | namespace backend\controllers; | ||||
use Yii; | use Yii; | ||||
use common\models\Production; | use common\models\Production; | ||||
use common\models\Commande; | use common\models\Commande; | ||||
/** | /** | ||||
* Site controller | * Site controller | ||||
*/ | */ | ||||
class SiteController extends BackendController | |||||
{ | |||||
class SiteController extends BackendController { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | 'class' => AccessControl::className(), | ||||
'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; | ||||
} | } | ||||
], | ], | ||||
'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; | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function actions() | |||||
{ | |||||
public function actions() { | |||||
return [ | return [ | ||||
'error' => [ | 'error' => [ | ||||
'class' => 'yii\web\ErrorAction', | 'class' => 'yii\web\ErrorAction', | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
// commandes | // commandes | ||||
$productions = Production::find() | $productions = Production::find() | ||||
->with('commande') | ->with('commande') | ||||
->where(['>=','production.date',date('Y-m-d')]) | |||||
->where(['>=', 'production.date', date('Y-m-d')]) | |||||
->andWhere([ | ->andWhere([ | ||||
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement, | 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement, | ||||
'production.actif' => 1 | 'production.actif' => 1 | ||||
]) | ]) | ||||
->orderBy('date ASC') | ->orderBy('date ASC') | ||||
->limit(5) | |||||
->all() ; | |||||
->limit(5) | |||||
->all(); | |||||
// dernières commandes | // dernières commandes | ||||
$commandes = Commande::findBy([ | $commandes = Commande::findBy([ | ||||
'orderby' => 'date DESC', | |||||
'limit' => 15, | |||||
'condition' => 'production.date > \''.date('Y-m-d 00:00:00').'\' AND (type = \''.Commande::TYPE_USER.'\' OR type = \''.Commande::TYPE_ADMIN.'\')' | |||||
]) ; | |||||
foreach($commandes as $c) | |||||
$c->init() ; | |||||
'orderby' => 'date DESC', | |||||
'limit' => 15, | |||||
'condition' => 'production.date > \'' . date('Y-m-d 00:00:00') . '\' AND (type = \'' . Commande::TYPE_USER . '\' OR type = \'' . Commande::TYPE_ADMIN . '\')' | |||||
]); | |||||
foreach ($commandes as $c) | |||||
$c->init(); | |||||
// clients | // clients | ||||
$nb_clients = User::findBy()->count(); | $nb_clients = User::findBy()->count(); | ||||
$clients = User::findBy() | $clients = User::findBy() | ||||
->orderBy('created_at DESC') | ->orderBy('created_at DESC') | ||||
->limit(5) | ->limit(5) | ||||
$clients_credit_pain_negatif = User::findBy(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | $clients_credit_pain_negatif = User::findBy(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | ||||
->andWhere('user_etablissement.credit < 0') | ->andWhere('user_etablissement.credit < 0') | ||||
->all(); | ->all(); | ||||
// paramètres | // paramètres | ||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; | |||||
return $this->render('index',[ | |||||
'productions' => $productions, | |||||
'commandes' => $commandes, | |||||
'clients' => $clients, | |||||
'nb_clients' => $nb_clients, | |||||
'clients_credit_pain_negatif' => $clients_credit_pain_negatif, | |||||
'etablissement' => $etablissement, | |||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); | |||||
return $this->render('index', [ | |||||
'productions' => $productions, | |||||
'commandes' => $commandes, | |||||
'clients' => $clients, | |||||
'nb_clients' => $nb_clients, | |||||
'clients_credit_pain_negatif' => $clients_credit_pain_negatif, | |||||
'etablissement' => $etablissement, | |||||
]); | ]); | ||||
} | } | ||||
public function actionLogin() | |||||
{ | |||||
public function actionLogin() { | |||||
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return $this->goHome(); | return $this->goHome(); | ||||
} | } | ||||
$model = new LoginForm(); | $model = new LoginForm(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->login()) | |||||
{ | |||||
if ($model->load(Yii::$app->request->post()) && $model->login()) { | |||||
return $this->goBack(); | return $this->goBack(); | ||||
} | |||||
else { | |||||
} else { | |||||
return $this->render('login', [ | return $this->render('login', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public function actionLogout() | |||||
{ | |||||
public function actionLogout() { | |||||
Yii::$app->user->logout(); | Yii::$app->user->logout(); | ||||
return $this->goHome(); | return $this->goHome(); | ||||
} | } | ||||
public function actionChangeEtablissement($id) | |||||
{ | |||||
Yii::$app->user->identity->id_etablissement = $id ; | |||||
Yii::$app->user->identity->save() ; | |||||
$this->redirect(['site/index']) ; | |||||
public function actionChangeEtablissement($id) { | |||||
Yii::$app->user->identity->id_etablissement = $id; | |||||
Yii::$app->user->identity->save(); | |||||
$this->redirect(['site/index']); | |||||
} | } | ||||
} | } |
use Yii; | use Yii; | ||||
use common\models\User; | use common\models\User; | ||||
use common\models\Commande; | use common\models\Commande; | ||||
use DateTime; | |||||
use DateInterval; | |||||
use DatePeriod; | |||||
use DateTime; | |||||
use DateInterval; | |||||
use DatePeriod; | |||||
class StatsController extends BackendController { | class StatsController extends BackendController { | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() { | public function actionIndex() { | ||||
/* | /* | ||||
* Volume de commande de l'année passée (par mois) | * Volume de commande de l'année passée (par mois) | ||||
*/ | */ | ||||
$date_start = date('Y-m-d',time() - 60 * 60 * 24 * 365) ; | |||||
$date_end = date('Y-m-d'); | |||||
$data_pain = [] ; | |||||
$date_start = date('Y-m-d', time() - 60 * 60 * 24 * 365); | |||||
$date_end = date('Y-m-d'); | |||||
$data_pain = []; | |||||
// labels | // labels | ||||
$data_labels = [] ; | |||||
$data_labels = []; | |||||
$start = new DateTime($date_start); | $start = new DateTime($date_start); | ||||
$interval = new DateInterval('P1M'); | $interval = new DateInterval('P1M'); | ||||
$end = new DateTime($date_end); | $end = new DateTime($date_end); | ||||
$period = new DatePeriod($start, $interval, $end); | $period = new DatePeriod($start, $interval, $end); | ||||
foreach($period as $date) { | |||||
$mois = date('m/Y',$date->getTimestamp()) ; | |||||
$data_labels[] = $mois ; | |||||
$data_pain[$mois] = 0 ; | |||||
foreach ($period as $date) { | |||||
$mois = date('m/Y', $date->getTimestamp()); | |||||
$data_labels[] = $mois; | |||||
$data_pain[$mois] = 0; | |||||
} | } | ||||
// commandes | // commandes | ||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->with('commandeProduits') | ->with('commandeProduits') | ||||
->joinWith('production') | ->joinWith('production') | ||||
->where('production.date > '.$date_start) | |||||
->andWhere('production.id_etablissement = '.Yii::$app->user->identity->id_etablissement) | |||||
->all() ; | |||||
foreach($commandes as $c) { | |||||
$c->init(); | |||||
$mois = date('m/Y',strtotime($c->production->date)) ; | |||||
if(isset($data_pain[$mois])) | |||||
{ | |||||
$data_pain[$mois] += $c->montant_pain ; | |||||
->where('production.date > ' . $date_start) | |||||
->andWhere('production.id_etablissement = ' . Yii::$app->user->identity->id_etablissement) | |||||
->all(); | |||||
foreach ($commandes as $c) { | |||||
$c->init(); | |||||
$mois = date('m/Y', strtotime($c->production->date)); | |||||
if (isset($data_pain[$mois])) { | |||||
$data_pain[$mois] += $c->montant_pain; | |||||
} | } | ||||
} | } | ||||
// création d'un tableau sans index car chart.js n'accepte pas les index | // création d'un tableau sans index car chart.js n'accepte pas les index | ||||
$data_pain_noindex = [] ; | |||||
foreach($data_pain as $key => $val) | |||||
{ | |||||
$data_pain_noindex[] = $val ; | |||||
$data_pain_noindex = []; | |||||
foreach ($data_pain as $key => $val) { | |||||
$data_pain_noindex[] = $val; | |||||
} | } | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'data_labels' => $data_labels, | 'data_labels' => $data_labels, | ||||
'data_pain' => $data_pain_noindex, | 'data_pain' => $data_pain_noindex, | ||||
]); | |||||
]); | |||||
} | } | ||||
} | |||||
} | |||||
?> | ?> |
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\helpers\Upload ; | |||||
use common\helpers\Password ; | |||||
use common\models\UserEtablissement ; | |||||
use common\models\Etablissement ; | |||||
use yii\base\UserException ; | |||||
use common\models\CreditHistorique; | |||||
use common\models\Commande; | |||||
use common\helpers\Upload; | |||||
use common\helpers\Password; | |||||
use common\models\UserEtablissement; | |||||
use common\models\Etablissement; | |||||
use yii\base\UserException; | |||||
use common\models\CreditHistorique; | |||||
use common\models\Commande; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class UserController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class UserController extends BackendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
if($action->actionMethod == 'actionIndex' || | |||||
$action->actionMethod == 'actionCreate' || | |||||
$action->actionMethod == 'actionUpdate' || | |||||
$action->actionMethod == 'actionCredit' || | |||||
$action->actionMethod == 'actionMail' || | |||||
$action->actionMethod == 'actionCommandes') | |||||
{ | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER ; | |||||
} | |||||
else { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; | |||||
} | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
if ($action->actionMethod == 'actionIndex' || | |||||
$action->actionMethod == 'actionCreate' || | |||||
$action->actionMethod == 'actionUpdate' || | |||||
$action->actionMethod == 'actionCredit' || | |||||
$action->actionMethod == 'actionMail' || | |||||
$action->actionMethod == 'actionCommandes') { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} else { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN; | |||||
} | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* Lists all User models. | * Lists all User models. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$params = Yii::$app->request->queryParams; | $params = Yii::$app->request->queryParams; | ||||
$query = User::findBy($params) ; | |||||
$query = User::findBy($params); | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => $query | 'query' => $query | ||||
]); | ]); | ||||
$etablissement = Etablissement::find() | $etablissement = Etablissement::find() | ||||
->where(['id' => Yii::$app->user->identity->id_etablissement]) | ->where(['id' => Yii::$app->user->identity->id_etablissement]) | ||||
->one() ; | |||||
->one(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'etablissement' => $etablissement | 'etablissement' => $etablissement | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionView($id) | |||||
{ | |||||
public function actionView($id) { | |||||
return $this->render('view', [ | return $this->render('view', [ | ||||
'model' => $this->findModel($id), | |||||
'model' => $this->findModel($id), | |||||
]); | ]); | ||||
} | } | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionCreate() | |||||
{ | |||||
public function actionCreate() { | |||||
$model = new User(); | $model = new User(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | ||||
// save use | // save use | ||||
$password = Password::generate() ; | |||||
$password = Password::generate(); | |||||
$model->setPassword($password); | $model->setPassword($password); | ||||
$model->generateAuthKey(); | $model->generateAuthKey(); | ||||
$model->username = $model->email ; | |||||
$model->confiance = 1 ; | |||||
if(!strlen($model->email)) | |||||
$model->username = 'inconnu@laboiteapain.net' ; | |||||
$model->save() ; | |||||
$model->username = $model->email; | |||||
$model->confiance = 1; | |||||
if (!strlen($model->email)) | |||||
$model->username = 'inconnu@laboiteapain.net'; | |||||
$model->save(); | |||||
// liaison etablissement / user | // liaison etablissement / user | ||||
$user_etablissement = new UserEtablissement() ; | |||||
$user_etablissement->id_user = $model->id ; | |||||
$user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$user_etablissement->credit = 0 ; | |||||
$user_etablissement->actif = 1 ; | |||||
$user_etablissement->save() ; | |||||
$user_etablissement = new UserEtablissement(); | |||||
$user_etablissement->id_user = $model->id; | |||||
$user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
$user_etablissement->credit = 0; | |||||
$user_etablissement->actif = 1; | |||||
$user_etablissement->save(); | |||||
// send mail | // send mail | ||||
if(strlen($model->email)) | |||||
{ | |||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; | |||||
Yii::$app->mailer->compose() ; | |||||
if (strlen($model->email)) { | |||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); | |||||
Yii::$app->mailer->compose(); | |||||
$mail = Yii::$app->mailer->compose( | $mail = Yii::$app->mailer->compose( | ||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], | |||||
['user' => $model, 'etablissement' => $etablissement, 'password' => $password]) | |||||
->setTo($model->email) | |||||
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send() ; | |||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $model, 'etablissement' => $etablissement, 'password' => $password]) | |||||
->setTo($model->email) | |||||
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send(); | |||||
} | } | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionUpdate($id) | |||||
{ | |||||
public function actionUpdate($id) { | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one() ; | |||||
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' =>$id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) ; | |||||
if(($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) | |||||
{ | |||||
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one(); | |||||
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); | |||||
if (($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
return $this->redirect(['index']); | |||||
return $this->redirect(['index']); | |||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | |||||
else { | |||||
} else { | |||||
throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs boulangeries, soit parce qu'il n'est pas lié à la votre."); | throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs boulangeries, soit parce qu'il n'est pas lié à la votre."); | ||||
} | } | ||||
} | } | ||||
public function actionMail() { | public function actionMail() { | ||||
$users = (new \yii\db\Query()) | $users = (new \yii\db\Query()) | ||||
->select('*') | ->select('*') | ||||
->from('user, user_etablissement') | ->from('user, user_etablissement') | ||||
->where('user.id = user_etablissement.id_user') | ->where('user.id = user_etablissement.id_user') | ||||
->andWhere('user_etablissement.actif = 1') | ->andWhere('user_etablissement.actif = 1') | ||||
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) | |||||
->all() ; | |||||
$arr_users = [] ; | |||||
foreach($users as $u) { | |||||
if(isset($u['email'])) | |||||
$arr_users[] = $u['email'] ; | |||||
->andWhere('user_etablissement.id_etablissement = ' . Yii::$app->user->identity->id_etablissement) | |||||
->all(); | |||||
$arr_users = []; | |||||
foreach ($users as $u) { | |||||
if (isset($u['email'])) | |||||
$arr_users[] = $u['email']; | |||||
} | } | ||||
return $this->render('liste_mails', [ | return $this->render('liste_mails', [ | ||||
//'model' => $model, | |||||
'users' => $arr_users | |||||
]); | |||||
//'model' => $model, | |||||
'users' => $arr_users | |||||
]); | |||||
} | } | ||||
public function actionCredit($id) | |||||
{ | |||||
$user = User::find()->with('userEtablissement')->where(['id' => $id])->one() ; | |||||
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' =>$id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) ; | |||||
if(($user_appartient_etablissement) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) | |||||
{ | |||||
$credit_historique = new CreditHistorique; | |||||
if ($credit_historique->load(Yii::$app->request->post()) && $credit_historique->validate()) | |||||
{ | |||||
$credit_historique->id_user = $user->id ; | |||||
$credit_historique->id_user_action = Yii::$app->user->identity->id ; | |||||
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
if($credit_historique->type == CreditHistorique::TYPE_DEBIT && $credit_historique->montant > 0) | |||||
$credit_historique->montant = - $credit_historique->montant ; | |||||
$credit_historique->save() ; | |||||
$this->redirect(['user/index']) ; | |||||
public function actionCredit($id) { | |||||
$user = User::find()->with('userEtablissement')->where(['id' => $id])->one(); | |||||
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); | |||||
if (($user_appartient_etablissement) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||||
$credit_historique = new CreditHistorique; | |||||
if ($credit_historique->load(Yii::$app->request->post()) && $credit_historique->validate()) { | |||||
$credit_historique->id_user = $user->id; | |||||
$credit_historique->id_user_action = Yii::$app->user->identity->id; | |||||
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
if ($credit_historique->type == CreditHistorique::TYPE_DEBIT && $credit_historique->montant > 0) | |||||
$credit_historique->montant = - $credit_historique->montant; | |||||
$credit_historique->save(); | |||||
$this->redirect(['user/index']); | |||||
} | } | ||||
$historique = CreditHistorique::find() | $historique = CreditHistorique::find() | ||||
->with(['commande','userAction']) | |||||
->with(['commande', 'userAction']) | |||||
->where([ | ->where([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | 'id_etablissement' => Yii::$app->user->identity->id_etablissement, | ||||
]) | ]) | ||||
->orderBy('date DESC') | ->orderBy('date DESC') | ||||
->all() ; | |||||
->all(); | |||||
return $this->render('credit', [ | return $this->render('credit', [ | ||||
'user' => $user, | 'user' => $user, | ||||
'credit_historique' => $credit_historique, | 'credit_historique' => $credit_historique, | ||||
'historique' => $historique | 'historique' => $historique | ||||
]) ; | |||||
]); | |||||
} | } | ||||
else { | else { | ||||
throw new UserException("Vous ne pouvez pas créditer un utilisateur qui n'est pas associé à votre boulangerie."); | throw new UserException("Vous ne pouvez pas créditer un utilisateur qui n'est pas associé à votre boulangerie."); | ||||
} | } | ||||
} | } | ||||
public function actionCommandes($id) | |||||
{ | |||||
$user = User::findOne($id) ; | |||||
public function actionCommandes($id) { | |||||
$user = User::findOne($id); | |||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->with('commandeProduits', 'pointVente', 'creditHistorique') | |||||
->joinWith('production','production.etablissement') | |||||
->where([ | |||||
'id_user' => $id, | |||||
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->orderBy('production.date DESC') | |||||
->all(); | |||||
->with('commandeProduits', 'pointVente', 'creditHistorique') | |||||
->joinWith('production', 'production.etablissement') | |||||
->where([ | |||||
'id_user' => $id, | |||||
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->orderBy('production.date DESC') | |||||
->all(); | |||||
foreach ($commandes as $c) | foreach ($commandes as $c) | ||||
$c->init(); | $c->init(); | ||||
return $this->render('commandes', [ | return $this->render('commandes', [ | ||||
'commandes' => $commandes, | 'commandes' => $commandes, | ||||
'user' => $user | 'user' => $user | ||||
]) ; | |||||
]); | |||||
} | } | ||||
/** | /** | ||||
* Finds the User model based on its primary key value. | * Finds the User model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
* @return User the loaded model | * @return User the loaded model | ||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = User::findOne($id)) !== null) { | if (($model = User::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\ProductionProduit; | use common\models\ProductionProduit; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\models\Produit; | use common\models\Produit; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\web\UploadedFile; | use yii\web\UploadedFile; | ||||
/** | /** | ||||
* ProduitController implements the CRUD actions for Produit model. | * ProduitController implements the CRUD actions for Produit model. | ||||
*/ | */ | ||||
class VracController extends BackendController | |||||
{ | |||||
var $enableCsrfValidation = false ; | |||||
public function behaviors() | |||||
{ | |||||
class VracController extends BackendController { | |||||
var $enableCsrfValidation = false; | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
} | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* Lists all Produit models. | * Lists all Produit models. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex() | |||||
{ | |||||
public function actionIndex() { | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => Produit::find()->where('vrac = 1')->orderBy('order ASC'), | 'query' => Produit::find()->where('vrac = 1')->orderBy('order ASC'), | ||||
]); | ]); | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionView($id) | |||||
{ | |||||
public function actionView($id) { | |||||
return $this->render('view', [ | return $this->render('view', [ | ||||
'model' => $this->findModel($id), | 'model' => $this->findModel($id), | ||||
]); | ]); | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionCreate() | |||||
{ | |||||
public function actionCreate() { | |||||
$model = new Produit(); | $model = new Produit(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
self::uploadFile($model, 'illustration') ; | |||||
self::uploadFile($model, 'photo') ; | |||||
$model->vrac = 1 ; | |||||
$model->lundi = 1 ; | |||||
$model->mardi = 1 ; | |||||
$model->mercredi = 1 ; | |||||
$model->jeudi = 1 ; | |||||
$model->vendredi = 1 ; | |||||
$model->samedi = 1 ; | |||||
$model->dimanche = 1 ; | |||||
$model->save() ; | |||||
// on ajoute un enregistrement ProductionProduit pour chaque production | |||||
$productions = Production::find()->where('date > '.date('Y-m-d'))->all() ; | |||||
foreach($productions as $prod) { | |||||
$production_produit = new ProductionProduit ; | |||||
$production_produit->id_production = $prod->id ; | |||||
$production_produit->id_produit = $model->id ; | |||||
$production_produit->actif = 0 ; | |||||
$production_produit->save() ; | |||||
} | |||||
self::uploadFile($model, 'illustration'); | |||||
self::uploadFile($model, 'photo'); | |||||
$model->vrac = 1; | |||||
$model->lundi = 1; | |||||
$model->mardi = 1; | |||||
$model->mercredi = 1; | |||||
$model->jeudi = 1; | |||||
$model->vendredi = 1; | |||||
$model->samedi = 1; | |||||
$model->dimanche = 1; | |||||
$model->save(); | |||||
// on ajoute un enregistrement ProductionProduit pour chaque production | |||||
$productions = Production::find()->where('date > ' . date('Y-m-d'))->all(); | |||||
foreach ($productions as $prod) { | |||||
$production_produit = new ProductionProduit; | |||||
$production_produit->id_production = $prod->id; | |||||
$production_produit->id_produit = $model->id; | |||||
$production_produit->actif = 0; | |||||
$production_produit->save(); | |||||
} | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionUpdate($id) | |||||
{ | |||||
$request = Yii::$app->request ; | |||||
public function actionUpdate($id) { | |||||
$request = Yii::$app->request; | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$illustration_filename_old = $model->illustration ; | |||||
$photo_filename_old = $model->photo ; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
self::uploadFile($model, 'illustration', $illustration_filename_old) ; | |||||
self::uploadFile($model, 'photo', $photo_filename_old) ; | |||||
$delete_illustration = $request->post('delete_illustration',0) ; | |||||
if($delete_illustration) { | |||||
$model->illustration = '' ; | |||||
$model->save() ; | |||||
} | |||||
$delete_photo = $request->post('delete_photo',0) ; | |||||
if($delete_photo) { | |||||
$model->photo = '' ; | |||||
$model->save() ; | |||||
} | |||||
$illustration_filename_old = $model->illustration; | |||||
$photo_filename_old = $model->photo; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
self::uploadFile($model, 'illustration', $illustration_filename_old); | |||||
self::uploadFile($model, 'photo', $photo_filename_old); | |||||
$delete_illustration = $request->post('delete_illustration', 0); | |||||
if ($delete_illustration) { | |||||
$model->illustration = ''; | |||||
$model->save(); | |||||
} | |||||
$delete_photo = $request->post('delete_photo', 0); | |||||
if ($delete_photo) { | |||||
$model->photo = ''; | |||||
$model->save(); | |||||
} | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public static function uploadFile($model, $champs, $filename_old = '') { | public static function uploadFile($model, $champs, $filename_old = '') { | ||||
$file = UploadedFile::getInstance($model, $champs); | |||||
if($file) { | |||||
$file_name = $file->baseName.'-'.uniqid().'.' . $file->extension ; | |||||
$file->saveAs('../../frontend/web/uploads/' . $file_name); | |||||
$model->$champs = $file_name ; | |||||
} | |||||
else { | |||||
$model->$champs = $filename_old ; | |||||
} | |||||
$model->save() ; | |||||
$file = UploadedFile::getInstance($model, $champs); | |||||
if ($file) { | |||||
$file_name = $file->baseName . '-' . uniqid() . '.' . $file->extension; | |||||
$file->saveAs('../../frontend/web/uploads/' . $file_name); | |||||
$model->$champs = $file_name; | |||||
} else { | |||||
$model->$champs = $filename_old; | |||||
} | |||||
$model->save(); | |||||
} | } | ||||
/** | /** | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionDelete($id) | |||||
{ | |||||
public function actionDelete($id) { | |||||
$this->findModel($id)->delete(); | $this->findModel($id)->delete(); | ||||
$productions_produits = ProductionProduit::find()->where(['id_produit'=>$id])->all() ; | |||||
foreach($productions_produits as $pp) { | |||||
$pp->delete() ; | |||||
$productions_produits = ProductionProduit::find()->where(['id_produit' => $id])->all(); | |||||
foreach ($productions_produits as $pp) { | |||||
$pp->delete(); | |||||
} | } | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
* @return Produit the loaded model | * @return Produit the loaded model | ||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = Produit::findOne($id)) !== null) { | if (($model = Produit::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
/** | /** | ||||
* ContactForm is the model behind the contact form. | * ContactForm is the model behind the contact form. | ||||
*/ | */ | ||||
class MailForm extends Model | |||||
{ | |||||
class MailForm extends Model { | |||||
public $subject; | public $subject; | ||||
public $body; | public $body; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
// name, email, subject and body are required | // name, email, subject and body are required | ||||
[['subject', 'body'], 'required', 'message' => 'Champs obligatoire'], | [['subject', 'body'], 'required', 'message' => 'Champs obligatoire'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'subject' => 'Sujet', | |||||
'body' => 'Message', | |||||
'subject' => 'Sujet', | |||||
'body' => 'Message', | |||||
]; | ]; | ||||
} | } | ||||
* @param string $email the target email address | * @param string $email the target email address | ||||
* @return boolean whether the email was sent | * @return boolean whether the email was sent | ||||
*/ | */ | ||||
public function sendEmail($email) | |||||
{ | |||||
public function sendEmail($email) { | |||||
return Yii::$app->mailer->compose() | return Yii::$app->mailer->compose() | ||||
->setTo($email) | ->setTo($email) | ||||
->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes']) | ->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes']) | ||||
->setTextBody($this->body) | ->setTextBody($this->body) | ||||
->send(); | ->send(); | ||||
} | } | ||||
} | } |
namespace common\controllers; | namespace common\controllers; | ||||
use yii ; | |||||
use yii; | |||||
class CommonController extends \yii\web\Controller | |||||
{ | |||||
public function beforeAction($event) | |||||
{ | |||||
if(!Yii::$app->user->isGuest) | |||||
{ | |||||
Yii::$app->user->identity->updateDerniereConnexion() ; | |||||
class CommonController extends \yii\web\Controller { | |||||
public function beforeAction($event) { | |||||
if (!Yii::$app->user->isGuest) { | |||||
Yii::$app->user->identity->updateDerniereConnexion(); | |||||
} | } | ||||
return parent::beforeAction($event); | return parent::beforeAction($event); | ||||
} | } | ||||
} | } | ||||
?> | ?> |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use yii\helpers\Html ; | |||||
use common\models\Etablissement ; | |||||
use yii\helpers\Html; | |||||
use common\models\Etablissement; | |||||
/** | /** | ||||
* This is the model class for table "commande". | * This is the model class for table "commande". | ||||
* @property integer $id_point_vente | * @property integer $id_point_vente | ||||
* @property integer $id_production | * @property integer $id_production | ||||
*/ | */ | ||||
class Commande extends \yii\db\ActiveRecord | |||||
{ | |||||
var $montant = 0 ; | |||||
var $montant_pain = 0 ; | |||||
var $montant_vrac = 0 ; | |||||
var $montant_paye = 0 ; | |||||
var $poids_pain = 0 ; | |||||
var $poids_vrac = 0 ; | |||||
const TYPE_AUTO = 'auto' ; | |||||
const TYPE_USER = 'user' ; | |||||
const TYPE_ADMIN = 'admin' ; | |||||
const STATUT_PAYEE = 'payee' ; | |||||
const STATUT_IMPAYEE = 'impayee' ; | |||||
const STATUT_SURPLUS = 'surplus' ; | |||||
const ETAT_MODIFIABLE = 'ouverte' ; | |||||
const ETAT_PREPARATION = 'preparation' ; | |||||
const ETAT_LIVREE = 'livree' ; | |||||
class Commande extends \yii\db\ActiveRecord { | |||||
var $montant = 0; | |||||
var $montant_pain = 0; | |||||
var $montant_vrac = 0; | |||||
var $montant_paye = 0; | |||||
var $poids_pain = 0; | |||||
var $poids_vrac = 0; | |||||
const TYPE_AUTO = 'auto'; | |||||
const TYPE_USER = 'user'; | |||||
const TYPE_ADMIN = 'admin'; | |||||
const STATUT_PAYEE = 'payee'; | |||||
const STATUT_IMPAYEE = 'impayee'; | |||||
const STATUT_SURPLUS = 'surplus'; | |||||
const ETAT_MODIFIABLE = 'ouverte'; | |||||
const ETAT_PREPARATION = 'preparation'; | |||||
const ETAT_LIVREE = 'livree'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'commande'; | return 'commande'; | ||||
} | } | ||||
public function init() { | public function init() { | ||||
if(isset($this->commandeProduits)) | |||||
{ | |||||
foreach($this->commandeProduits as $p) | |||||
{ | |||||
if($p->mode_vente == 'unite') | |||||
{ | |||||
$this->montant_pain += $p->prix * $p->quantite ; | |||||
} | |||||
elseif($p->mode_vente == 'poids') | |||||
{ | |||||
$this->montant_pain += $p->prix * $p->quantite/1000 ; | |||||
} | |||||
} | |||||
$this->montant = $this->montant_vrac + $this->montant_pain ; | |||||
} | |||||
if(isset($this->creditHistorique) && !$this->montant_paye) | |||||
{ | |||||
foreach($this->creditHistorique as $ch) | |||||
{ | |||||
if($ch->type == CreditHistorique::TYPE_PAIEMENT) | |||||
$this->montant_paye += $ch->montant ; | |||||
elseif($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) | |||||
$this->montant_paye -= $ch->montant ; | |||||
if (isset($this->commandeProduits)) { | |||||
foreach ($this->commandeProduits as $p) { | |||||
if ($p->mode_vente == 'unite') { | |||||
$this->montant_pain += $p->prix * $p->quantite; | |||||
} elseif ($p->mode_vente == 'poids') { | |||||
$this->montant_pain += $p->prix * $p->quantite / 1000; | |||||
} | |||||
} | |||||
$this->montant = $this->montant_vrac + $this->montant_pain; | |||||
} | |||||
if (isset($this->creditHistorique) && !$this->montant_paye) { | |||||
foreach ($this->creditHistorique as $ch) { | |||||
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) | |||||
$this->montant_paye += $ch->montant; | |||||
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) | |||||
$this->montant_paye -= $ch->montant; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public static function getQuantiteProduit($id_produit, $commandes) { | public static function getQuantiteProduit($id_produit, $commandes) { | ||||
$quantite = 0 ; | |||||
if(isset($commandes) && is_array($commandes) && count($commandes)) { | |||||
foreach($commandes as $c) { | |||||
foreach($c->commandeProduits as $cp) { | |||||
if($cp->id_produit == $id_produit) | |||||
$quantite += $cp->quantite ; | |||||
} | |||||
} | |||||
} | |||||
return $quantite ; | |||||
$quantite = 0; | |||||
if (isset($commandes) && is_array($commandes) && count($commandes)) { | |||||
foreach ($commandes as $c) { | |||||
foreach ($c->commandeProduits as $cp) { | |||||
if ($cp->id_produit == $id_produit) | |||||
$quantite += $cp->quantite; | |||||
} | |||||
} | |||||
} | |||||
return $quantite; | |||||
} | } | ||||
/* | /* | ||||
* relations | * relations | ||||
*/ | */ | ||||
public function getUser() { | public function getUser() { | ||||
return $this->hasOne(User::className(), ['id'=>'id_user']) ; | |||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getCommandeProduits() { | public function getCommandeProduits() { | ||||
return $this->hasMany(CommandeProduit::className(), ['id_commande'=>'id'])->with('produit') ; | |||||
return $this->hasMany(CommandeProduit::className(), ['id_commande' => 'id'])->with('produit'); | |||||
} | } | ||||
public function getProduction() { | public function getProduction() { | ||||
return $this->hasOne(Production::className(), ['id'=>'id_production'])->with('etablissement') ; | |||||
return $this->hasOne(Production::className(), ['id' => 'id_production'])->with('etablissement'); | |||||
} | } | ||||
public function getPointVente() { | public function getPointVente() { | ||||
return $this->hasOne(PointVente::className(), ['id'=>'id_point_vente'])->with('pointVenteUser') ; | |||||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente'])->with('pointVenteUser'); | |||||
} | } | ||||
public function getCreditHistorique() | |||||
{ | |||||
return $this->hasMany(CreditHistorique::className(), ['id_commande'=>'id']) ; | |||||
public function getCreditHistorique() { | |||||
return $this->hasMany(CreditHistorique::className(), ['id_commande' => 'id']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_user', 'date', 'id_point_vente','id_production'], 'required','message'=>''], | |||||
[['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''], | |||||
[['id_user', 'id_point_vente', 'id_production'], 'integer'], | [['id_user', 'id_point_vente', 'id_production'], 'integer'], | ||||
[['date', 'date_update','commentaire', 'commentaire_point_vente'], 'safe'] | |||||
[['date', 'date_update', 'commentaire', 'commentaire_point_vente'], 'safe'] | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_user' => 'Id User', | 'id_user' => 'Id User', | ||||
'id_production' => 'Date de production', | 'id_production' => 'Date de production', | ||||
]; | ]; | ||||
} | } | ||||
public function strListeVrac() | |||||
{ | |||||
$str = '' ; | |||||
foreach($this->commandeProduits as $cp) { | |||||
if($cp->produit->vrac) { | |||||
$str .= $cp->quantite.' '.Html::encode($cp->produit->diminutif).', ' ; | |||||
} | |||||
} | |||||
return substr($str, 0, strlen($str) - 2) ; | |||||
} | |||||
public function getMontantPaye() | |||||
{ | |||||
if($this->montant_paye) | |||||
{ | |||||
return $this->montant_paye ; | |||||
public function strListeVrac() { | |||||
$str = ''; | |||||
foreach ($this->commandeProduits as $cp) { | |||||
if ($cp->produit->vrac) { | |||||
$str .= $cp->quantite . ' ' . Html::encode($cp->produit->diminutif) . ', '; | |||||
} | |||||
} | } | ||||
else { | |||||
return substr($str, 0, strlen($str) - 2); | |||||
} | |||||
public function getMontantPaye() { | |||||
if ($this->montant_paye) { | |||||
return $this->montant_paye; | |||||
} else { | |||||
$historique = CreditHistorique::find() | $historique = CreditHistorique::find() | ||||
->where(['id_commande' => $this->id]) | |||||
->all() ; | |||||
$montant = 0 ; | |||||
foreach($historique as $ch) | |||||
{ | |||||
if($ch->type == CreditHistorique::TYPE_PAIEMENT) | |||||
$montant += $ch->montant ; | |||||
elseif($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) | |||||
$montant -= $ch->montant ; | |||||
->where(['id_commande' => $this->id]) | |||||
->all(); | |||||
$montant = 0; | |||||
foreach ($historique as $ch) { | |||||
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) | |||||
$montant += $ch->montant; | |||||
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) | |||||
$montant -= $ch->montant; | |||||
} | } | ||||
return $montant ; | |||||
return $montant; | |||||
} | } | ||||
} | } | ||||
public function getMontant($format = false) | |||||
{ | |||||
if($format) | |||||
return number_format($this->getMontant(),2).' €' ; | |||||
public function getMontant($format = false) { | |||||
if ($format) | |||||
return number_format($this->getMontant(), 2) . ' €'; | |||||
else | else | ||||
return $this->montant ; | |||||
return $this->montant; | |||||
} | } | ||||
public function getMontantFormat() | |||||
{ | |||||
return number_format($this->getMontant(),2).' €' ; | |||||
public function getMontantFormat() { | |||||
return number_format($this->getMontant(), 2) . ' €'; | |||||
} | } | ||||
public function getMontantRestant($format = false) | |||||
{ | |||||
$montant_restant = $this->getMontant() - $this->getMontantPaye() ; | |||||
if($format) | |||||
return number_format($montant_restant, 2).' €'; | |||||
public function getMontantRestant($format = false) { | |||||
$montant_restant = $this->getMontant() - $this->getMontantPaye(); | |||||
if ($format) | |||||
return number_format($montant_restant, 2) . ' €'; | |||||
else | else | ||||
return $montant_restant ; | |||||
return $montant_restant; | |||||
} | } | ||||
public function getMontantSurplus($format = false) | |||||
{ | |||||
$montant_surplus = $this->getMontantPaye() - $this->getMontant() ; | |||||
if($format) | |||||
return number_format($montant_surplus, 2).' €'; | |||||
public function getMontantSurplus($format = false) { | |||||
$montant_surplus = $this->getMontantPaye() - $this->getMontant(); | |||||
if ($format) | |||||
return number_format($montant_surplus, 2) . ' €'; | |||||
else | else | ||||
return $montant_surplus ; | |||||
return $montant_surplus; | |||||
} | } | ||||
public function getDataJson() | |||||
{ | |||||
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one() ; | |||||
$commande->init() ; | |||||
public function getDataJson() { | |||||
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one(); | |||||
$commande->init(); | |||||
$json_commande = [ | $json_commande = [ | ||||
'produits'=> [], | |||||
'produits' => [], | |||||
'montant' => $commande->montant, | 'montant' => $commande->montant, | ||||
'str_montant' => $commande->getMontantFormat(), | |||||
'str_montant' => $commande->getMontantFormat(), | |||||
'montant_paye' => $commande->getMontantPaye(), | 'montant_paye' => $commande->getMontantPaye(), | ||||
'commentaire' => $commande->commentaire, | 'commentaire' => $commande->commentaire, | ||||
] ; | |||||
foreach($commande->commandeProduits as $commande_produit) | |||||
{ | |||||
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite ; | |||||
]; | |||||
foreach ($commande->commandeProduits as $commande_produit) { | |||||
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite; | |||||
} | } | ||||
return json_encode($json_commande) ; | |||||
return json_encode($json_commande); | |||||
} | } | ||||
public function creditHistorique($type, $montant, $id_etablissement, $id_user) | |||||
{ | |||||
$credit_historique = new CreditHistorique ; | |||||
$credit_historique->id_user = $this->id_user ; | |||||
$credit_historique->id_commande = $this->id ; | |||||
$credit_historique->montant = $montant ; | |||||
$credit_historique->type = $type ; | |||||
$credit_historique->id_etablissement = $id_etablissement ; | |||||
$credit_historique->id_user_action = $id_user ; | |||||
$credit_historique->save() ; | |||||
public function creditHistorique($type, $montant, $id_etablissement, $id_user) { | |||||
$credit_historique = new CreditHistorique; | |||||
$credit_historique->id_user = $this->id_user; | |||||
$credit_historique->id_commande = $this->id; | |||||
$credit_historique->montant = $montant; | |||||
$credit_historique->type = $type; | |||||
$credit_historique->id_etablissement = $id_etablissement; | |||||
$credit_historique->id_user_action = $id_user; | |||||
$credit_historique->save(); | |||||
} | } | ||||
public function getStatutPaiement() | |||||
{ | |||||
public function getStatutPaiement() { | |||||
// à rembourser | // à rembourser | ||||
if($this->getMontant() - $this->getMontantPaye() < 0) | |||||
{ | |||||
return self::STATUT_SURPLUS ; | |||||
if ($this->getMontant() - $this->getMontantPaye() < 0) { | |||||
return self::STATUT_SURPLUS; | |||||
} | } | ||||
// payé | // payé | ||||
elseif($this->getMontant() - $this->getMontantPaye() < 0.001) | |||||
{ | |||||
return self::STATUT_PAYEE ; | |||||
elseif ($this->getMontant() - $this->getMontantPaye() < 0.001) { | |||||
return self::STATUT_PAYEE; | |||||
} | } | ||||
// reste à payer | // reste à payer | ||||
elseif($this->getMontant() - $this->getMontantPaye() > 0.01) | |||||
{ | |||||
return self::STATUT_IMPAYEE ; | |||||
elseif ($this->getMontant() - $this->getMontantPaye() > 0.01) { | |||||
return self::STATUT_IMPAYEE; | |||||
} | } | ||||
} | } | ||||
public function getResumePanier() | |||||
{ | |||||
if(!isset($this->commandeProduits)) | |||||
$this->commandeProduits = CommandeProduit::find()->where(['id_commande' => $this->id])->all() ; | |||||
$html = '' ; | |||||
public function getResumePanier() { | |||||
if (!isset($this->commandeProduits)) | |||||
$this->commandeProduits = CommandeProduit::find()->where(['id_commande' => $this->id])->all(); | |||||
$html = ''; | |||||
$count = count($this->commandeProduits); | $count = count($this->commandeProduits); | ||||
$i = 0; | $i = 0; | ||||
foreach($this->commandeProduits as $p) | |||||
{ | |||||
if(isset($p->produit)) | |||||
{ | |||||
$html .= $p->quantite.' x '.Html::encode($p->produit->nom) ; | |||||
if(++$i != $count) $html .= '<br />' ; | |||||
foreach ($this->commandeProduits as $p) { | |||||
if (isset($p->produit)) { | |||||
$html .= $p->quantite . ' x ' . Html::encode($p->produit->nom); | |||||
if (++$i != $count) | |||||
$html .= '<br />'; | |||||
} | } | ||||
} | } | ||||
return $html ; | |||||
return $html; | |||||
} | } | ||||
public function getResumePointVente() | |||||
{ | |||||
$html = '' ; | |||||
if(isset($this->pointVente)) | |||||
{ | |||||
$html .= '<span class="nom-point-vente">'.Html::encode($this->pointVente->nom) .'</span>' | |||||
. '<br /><span class="localite">'.Html::encode($this->pointVente->localite).'</span>' ; | |||||
if(strlen($this->commentaire_point_vente)) | |||||
{ | |||||
$html .= '<div class="commentaire"><span>'.Html::encode($this->commentaire_point_vente).'</span></div>' ; | |||||
} | |||||
public function getResumePointVente() { | |||||
$html = ''; | |||||
if (isset($this->pointVente)) { | |||||
$html .= '<span class="nom-point-vente">' . Html::encode($this->pointVente->nom) . '</span>' | |||||
. '<br /><span class="localite">' . Html::encode($this->pointVente->localite) . '</span>'; | |||||
if (strlen($this->commentaire_point_vente)) { | |||||
$html .= '<div class="commentaire"><span>' . Html::encode($this->commentaire_point_vente) . '</span></div>'; | |||||
} | |||||
} else { | |||||
$html .= 'Point de vente supprimé'; | |||||
} | } | ||||
else { | |||||
$html .= 'Point de vente supprimé' ; | |||||
} | |||||
return $html ; | |||||
return $html; | |||||
} | } | ||||
public function getStrMontant() | |||||
{ | |||||
return number_format($this->montant,2).' €' ; | |||||
public function getStrMontant() { | |||||
return number_format($this->montant, 2) . ' €'; | |||||
} | } | ||||
public function getResumeMontant() | |||||
{ | |||||
$html = '' ; | |||||
$html .= $this->getStrMontant().'<br />' ; | |||||
if($this->montant_paye) | |||||
{ | |||||
if($this->getStatutPaiement() == Commande::STATUT_PAYEE) | |||||
{ | |||||
$html .= '<span class="label label-success">Payée</span>' ; | |||||
} | |||||
elseif($this->getStatutPaiement() == Commande::STATUT_IMPAYEE) | |||||
{ | |||||
public function getResumeMontant() { | |||||
$html = ''; | |||||
$html .= $this->getStrMontant() . '<br />'; | |||||
if ($this->montant_paye) { | |||||
if ($this->getStatutPaiement() == Commande::STATUT_PAYEE) { | |||||
$html .= '<span class="label label-success">Payée</span>'; | |||||
} elseif ($this->getStatutPaiement() == Commande::STATUT_IMPAYEE) { | |||||
$html .= '<span class="label label-danger">Non payée</span><br /> | $html .= '<span class="label label-danger">Non payée</span><br /> | ||||
Reste <strong>'.$this->getMontantRestant(true).'</strong> à payer' ; | |||||
Reste <strong>' . $this->getMontantRestant(true) . '</strong> à payer'; | |||||
} elseif ($this->getStatutPaiement() == Commande::STATUT_SURPLUS) { | |||||
$html .= '<span class="label label-success">Payée</span>'; | |||||
} | } | ||||
elseif($this->getStatutPaiement() == Commande::STATUT_SURPLUS) | |||||
{ | |||||
$html .= '<span class="label label-success">Payée</span>' ; | |||||
} | |||||
} | |||||
else { | |||||
$html .= '<span class="label label-default">À régler sur place</span>' ; | |||||
} else { | |||||
$html .= '<span class="label label-default">À régler sur place</span>'; | |||||
} | } | ||||
return $html ; | |||||
return $html; | |||||
} | } | ||||
public function getStrUser() | |||||
{ | |||||
if(isset($this->user)) | |||||
{ | |||||
return Html::encode($this->user->prenom.' '.$this->user->nom) ; | |||||
} | |||||
elseif(strlen($this->username)) { | |||||
return Html::encode($this->username) ; | |||||
} | |||||
else { | |||||
return 'Client introuvable' ; | |||||
public function getStrUser() { | |||||
if (isset($this->user)) { | |||||
return Html::encode($this->user->prenom . ' ' . $this->user->nom); | |||||
} elseif (strlen($this->username)) { | |||||
return Html::encode($this->username); | |||||
} else { | |||||
return 'Client introuvable'; | |||||
} | } | ||||
} | } | ||||
public static function findBy($params = []) | |||||
{ | |||||
if(!isset($params['id_etablissement'])) | |||||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement ; | |||||
public static function findBy($params = []) { | |||||
if (!isset($params['id_etablissement'])) | |||||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; | |||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->with('commandeProduits', 'creditHistorique', 'pointVente') | ->with('commandeProduits', 'creditHistorique', 'pointVente') | ||||
->joinWith(['production','user']) | |||||
->where(['production.id_etablissement' => $params['id_etablissement']]) ; | |||||
if(isset($params['condition'])) | |||||
->joinWith(['production', 'user']) | |||||
->where(['production.id_etablissement' => $params['id_etablissement']]); | |||||
if (isset($params['condition'])) | |||||
$commandes = $commandes->andWhere($params['condition']); | $commandes = $commandes->andWhere($params['condition']); | ||||
if(isset($params['date'])) | |||||
if (isset($params['date'])) | |||||
$commandes = $commandes->andWhere(['production.date' => $params['date']]); | $commandes = $commandes->andWhere(['production.date' => $params['date']]); | ||||
if(isset($params['type'])) | |||||
if (isset($params['type'])) | |||||
$commandes = $commandes->andWhere(['commande.type' => $params['type']]); | $commandes = $commandes->andWhere(['commande.type' => $params['type']]); | ||||
if(isset($params['orderby'])) | |||||
if (isset($params['orderby'])) | |||||
$commandes = $commandes->orderBy($params['orderby']); | $commandes = $commandes->orderBy($params['orderby']); | ||||
else | |||||
else | |||||
$commandes = $commandes->orderBy('date ASC'); | $commandes = $commandes->orderBy('date ASC'); | ||||
if(isset($params['limit'])) | |||||
$commandes = $commandes->limit($params['limit']) ; | |||||
$commandes = $commandes->all() ; | |||||
return $commandes ; | |||||
if (isset($params['limit'])) | |||||
$commandes = $commandes->limit($params['limit']); | |||||
$commandes = $commandes->all(); | |||||
return $commandes; | |||||
} | } | ||||
public function getEtat() | |||||
{ | |||||
$delai_commande = Etablissement::getConfig('delai_commande',$this->production->id_etablissement) ; | |||||
$heure_limite = Etablissement::getConfig('heure_limite_commande',$this->production->id_etablissement) ; | |||||
$date_commande = strtotime($this->production->date) ; | |||||
public function getEtat() { | |||||
$delai_commande = Etablissement::getConfig('delai_commande', $this->production->id_etablissement); | |||||
$heure_limite = Etablissement::getConfig('heure_limite_commande', $this->production->id_etablissement); | |||||
$date_commande = strtotime($this->production->date); | |||||
$date_today = strtotime(date('Y-m-d')); | $date_today = strtotime(date('Y-m-d')); | ||||
$heure_today = date('G') ; | |||||
$nb_jours = (int) (($date_commande - $date_today) / (24 * 60 * 60)) ; | |||||
if($nb_jours <= 0) | |||||
{ | |||||
return self::ETAT_LIVREE ; | |||||
} | |||||
elseif($nb_jours >= $delai_commande && | |||||
($nb_jours != $delai_commande || | |||||
($nb_jours == $delai_commande && $heure_today < $heure_limite))) | |||||
{ | |||||
return self::ETAT_MODIFIABLE ; | |||||
$heure_today = date('G'); | |||||
$nb_jours = (int) (($date_commande - $date_today) / (24 * 60 * 60)); | |||||
if ($nb_jours <= 0) { | |||||
return self::ETAT_LIVREE; | |||||
} elseif ($nb_jours >= $delai_commande && | |||||
($nb_jours != $delai_commande || | |||||
($nb_jours == $delai_commande && $heure_today < $heure_limite))) { | |||||
return self::ETAT_MODIFIABLE; | |||||
} | } | ||||
return self::ETAT_PREPARATION ; | |||||
return self::ETAT_PREPARATION; | |||||
} | } | ||||
public function getStrType($with_label = false) { | public function getStrType($with_label = false) { | ||||
$class_label = '' ; | |||||
$str = '' ; | |||||
if($this->type == self::TYPE_USER) { | |||||
$class_label = 'success' ; | |||||
$str = 'Client' ; | |||||
} | |||||
elseif($this->type == self::TYPE_AUTO) { | |||||
$class_label = 'default' ; | |||||
$str = 'Auto' ; | |||||
} | |||||
elseif($this->type == self::TYPE_ADMIN) { | |||||
$class_label = 'warning' ; | |||||
$str = 'Vous' ; | |||||
$class_label = ''; | |||||
$str = ''; | |||||
if ($this->type == self::TYPE_USER) { | |||||
$class_label = 'success'; | |||||
$str = 'Client'; | |||||
} elseif ($this->type == self::TYPE_AUTO) { | |||||
$class_label = 'default'; | |||||
$str = 'Auto'; | |||||
} elseif ($this->type == self::TYPE_ADMIN) { | |||||
$class_label = 'warning'; | |||||
$str = 'Vous'; | |||||
} | } | ||||
if($with_label) | |||||
return '<span class="label label-'.$class_label.'">'.$str.'</span>' ; | |||||
if ($with_label) | |||||
return '<span class="label label-' . $class_label . '">' . $str . '</span>'; | |||||
else | else | ||||
return $str ; | |||||
return $str; | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\Etablissement ; | |||||
use common\models\PointVente ; | |||||
use common\models\PointVenteUser ; | |||||
use common\models\Commande ; | |||||
use common\models\CommandeProduit ; | |||||
use common\models\Etablissement; | |||||
use common\models\PointVente; | |||||
use common\models\PointVenteUser; | |||||
use common\models\Commande; | |||||
use common\models\CommandeProduit; | |||||
/** | /** | ||||
* This is the model class for table "commande_auto". | * This is the model class for table "commande_auto". | ||||
* @property string $username | * @property string $username | ||||
* @property string $paiement_automatique | * @property string $paiement_automatique | ||||
*/ | */ | ||||
class CommandeAuto extends \yii\db\ActiveRecord | |||||
{ | |||||
class CommandeAuto extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'commande_auto'; | return 'commande_auto'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_etablissement', 'id_point_vente'], 'required'], | [['id_etablissement', 'id_point_vente'], 'required'], | ||||
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], | [['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], | ||||
[['paiement_automatique'], 'boolean'], | [['paiement_automatique'], 'boolean'], | ||||
[['date_debut', 'date_fin','username'], 'safe'], | |||||
[['date_debut', 'date_fin', 'username'], 'safe'], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_user' => 'Utilisateur', | 'id_user' => 'Utilisateur', | ||||
'paiement_automatique' => 'Paiement automatique' | 'paiement_automatique' => 'Paiement automatique' | ||||
]; | ]; | ||||
} | } | ||||
public function getUser() | |||||
{ | |||||
return $this->hasOne(User::className(), ['id'=>'id_user']) ; | |||||
public function getUser() { | |||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getEtablissement() | |||||
{ | |||||
return $this->hasOne(Etablissement::className(), ['id'=>'id_etablissement']) ; | |||||
public function getEtablissement() { | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||||
} | } | ||||
public function getPointVente() | |||||
{ | |||||
return $this->hasOne(PointVente::className(), ['id'=>'id_point_vente']) ; | |||||
public function getPointVente() { | |||||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); | |||||
} | } | ||||
public function getCommandeAutoProduit() | |||||
{ | |||||
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto'=>'id'])->with('produit') ; | |||||
public function getCommandeAutoProduit() { | |||||
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto' => 'id'])->with('produit'); | |||||
} | } | ||||
public static function getAll($date) | |||||
{ | |||||
$date = date('Y-m-d', strtotime($date)) ; | |||||
public static function getAll($date) { | |||||
$date = date('Y-m-d', strtotime($date)); | |||||
// commandes auto | // commandes auto | ||||
$commandes_auto = self::find() | $commandes_auto = self::find() | ||||
->with('commandeAutoProduit') | ->with('commandeAutoProduit') | ||||
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | ||||
->all() ; | |||||
$arr_commandes_auto = [] ; | |||||
foreach($commandes_auto as $c) | |||||
{ | |||||
->all(); | |||||
$arr_commandes_auto = []; | |||||
foreach ($commandes_auto as $c) { | |||||
// vérif dates | // vérif dates | ||||
if($date >= $c->date_debut && | |||||
(!$c->date_fin || $date <= $c->date_fin)) | |||||
{ | |||||
if ($date >= $c->date_debut && | |||||
(!$c->date_fin || $date <= $c->date_fin)) { | |||||
// périodicite | // périodicite | ||||
$nb_jours = (strtotime($date) - strtotime($c->date_debut)) / (24*60*60) ; | |||||
if($nb_jours % ($c->periodicite_semaine * 7) < 7 ) | |||||
{ | |||||
$nb_jours = (strtotime($date) - strtotime($c->date_debut)) / (24 * 60 * 60); | |||||
if ($nb_jours % ($c->periodicite_semaine * 7) < 7) { | |||||
// jour de la semaine | // jour de la semaine | ||||
$jour = date('N', strtotime($date)) ; | |||||
switch($jour) | |||||
{ | |||||
case 1 : $jour = 'lundi' ; break ; | |||||
case 2 : $jour = 'mardi' ; break ; | |||||
case 3 : $jour = 'mercredi' ; break ; | |||||
case 4 : $jour = 'jeudi' ; break ; | |||||
case 5 : $jour = 'vendredi' ; break ; | |||||
case 6 : $jour = 'samedi' ; break ; | |||||
case 7 : $jour = 'dimanche' ; break ; | |||||
$jour = date('N', strtotime($date)); | |||||
switch ($jour) { | |||||
case 1 : $jour = 'lundi'; | |||||
break; | |||||
case 2 : $jour = 'mardi'; | |||||
break; | |||||
case 3 : $jour = 'mercredi'; | |||||
break; | |||||
case 4 : $jour = 'jeudi'; | |||||
break; | |||||
case 5 : $jour = 'vendredi'; | |||||
break; | |||||
case 6 : $jour = 'samedi'; | |||||
break; | |||||
case 7 : $jour = 'dimanche'; | |||||
break; | |||||
} | } | ||||
if($c->$jour) | |||||
{ | |||||
$arr_commandes_auto[] = $c ; | |||||
if ($c->$jour) { | |||||
$arr_commandes_auto[] = $c; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $arr_commandes_auto ; | |||||
return $arr_commandes_auto; | |||||
} | } | ||||
public static function addAll($date) | |||||
{ | |||||
public static function addAll($date) { | |||||
// production | // production | ||||
$production = Production::findOne([ | $production = Production::findOne([ | ||||
'date' => date('Y-m-d',strtotime($date)), | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) ; | |||||
if($production) | |||||
{ | |||||
'date' => date('Y-m-d', strtotime($date)), | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]); | |||||
if ($production) { | |||||
$count_commandes_prod = Commande::find() | $count_commandes_prod = Commande::find() | ||||
->where(['id_production' => $production->id]) | |||||
->count() ; | |||||
if(!$count_commandes_prod) | |||||
{ | |||||
$commandes_auto = self::getAll($date) ; | |||||
foreach($commandes_auto as $c) | |||||
{ | |||||
$c->add($date) ; | |||||
->where(['id_production' => $production->id]) | |||||
->count(); | |||||
if (!$count_commandes_prod) { | |||||
$commandes_auto = self::getAll($date); | |||||
foreach ($commandes_auto as $c) { | |||||
$c->add($date); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function add($date) | |||||
{ | |||||
public function add($date) { | |||||
// production | // production | ||||
$production = Production::find() | $production = Production::find() | ||||
->where([ | |||||
'date' => date('Y-m-d',strtotime($date)), | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->with('productionProduit') | |||||
->one() ; | |||||
if($production && count($this->commandeAutoProduit)) | |||||
{ | |||||
->where([ | |||||
'date' => date('Y-m-d', strtotime($date)), | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->with('productionProduit') | |||||
->one(); | |||||
if ($production && count($this->commandeAutoProduit)) { | |||||
// commande | // commande | ||||
$commande = new Commande ; | |||||
if(strlen($this->username)) | |||||
{ | |||||
$commande->username = $this->username ; | |||||
$commande->id_user = 0 ; | |||||
} | |||||
else { | |||||
$commande->id_user = $this->id_user ; | |||||
$commande = new Commande; | |||||
if (strlen($this->username)) { | |||||
$commande->username = $this->username; | |||||
$commande->id_user = 0; | |||||
} else { | |||||
$commande->id_user = $this->id_user; | |||||
} | } | ||||
$commande->date = date('Y-m-d H:i:s') ; | |||||
$commande->type = Commande::TYPE_AUTO ; | |||||
$commande->id_point_vente = $this->id_point_vente ; | |||||
$commande->id_production = $production->id ; | |||||
$commande->date = date('Y-m-d H:i:s'); | |||||
$commande->type = Commande::TYPE_AUTO; | |||||
$commande->id_point_vente = $this->id_point_vente; | |||||
$commande->id_production = $production->id; | |||||
$point_vente_user = PointVenteUser::find() | $point_vente_user = PointVenteUser::find() | ||||
->where(['id_point_vente' => $this->id_point_vente, 'id_user' => $this->id_user]) | ->where(['id_point_vente' => $this->id_point_vente, 'id_user' => $this->id_user]) | ||||
->one() ; | |||||
if($point_vente_user && strlen($point_vente_user->commentaire)) { | |||||
$commande->commentaire_point_vente = $point_vente_user->commentaire ; | |||||
->one(); | |||||
if ($point_vente_user && strlen($point_vente_user->commentaire)) { | |||||
$commande->commentaire_point_vente = $point_vente_user->commentaire; | |||||
} | } | ||||
$commande->save() ; | |||||
$commande->save(); | |||||
// produits | // produits | ||||
$montant_total = 0 ; | |||||
$produits_add = false ; | |||||
foreach($this->commandeAutoProduit as $commande_auto_produit) | |||||
{ | |||||
if($production->produitActif($commande_auto_produit->produit->id)) | |||||
{ | |||||
$commande_produit = new CommandeProduit ; | |||||
$commande_produit->id_commande = $commande->id ; | |||||
$commande_produit->id_produit = $commande_auto_produit->produit->id ; | |||||
$commande_produit->quantite = $commande_auto_produit->quantite ; | |||||
$commande_produit->prix = $commande_auto_produit->produit->prix ; | |||||
$commande_produit->save() ; | |||||
$produits_add = true; | |||||
$montant_total = 0; | |||||
$produits_add = false; | |||||
foreach ($this->commandeAutoProduit as $commande_auto_produit) { | |||||
if ($production->produitActif($commande_auto_produit->produit->id)) { | |||||
$commande_produit = new CommandeProduit; | |||||
$commande_produit->id_commande = $commande->id; | |||||
$commande_produit->id_produit = $commande_auto_produit->produit->id; | |||||
$commande_produit->quantite = $commande_auto_produit->quantite; | |||||
$commande_produit->prix = $commande_auto_produit->produit->prix; | |||||
$commande_produit->save(); | |||||
$produits_add = true; | |||||
} | } | ||||
} | } | ||||
if(!$produits_add) | |||||
{ | |||||
$commande->delete() ; | |||||
} | |||||
else { | |||||
if (!$produits_add) { | |||||
$commande->delete(); | |||||
} else { | |||||
// on débite automatiquement le crédit pain du client | // on débite automatiquement le crédit pain du client | ||||
if($commande->id_user && | |||||
$this->paiement_automatique && | |||||
Etablissement::getConfig('credit_pain')) | |||||
{ | |||||
if ($commande->id_user && | |||||
$this->paiement_automatique && | |||||
Etablissement::getConfig('credit_pain')) { | |||||
$commande = Commande::find() | $commande = Commande::find() | ||||
->with('commandeProduits') | ->with('commandeProduits') | ||||
->where(['id' => $commande->id]) | ->where(['id' => $commande->id]) | ||||
->one() ; | |||||
->one(); | |||||
$commande->init() ; | |||||
$commande->init(); | |||||
$user_action = User::find()->where([ | $user_action = User::find()->where([ | ||||
'id_etablissement' => $production->id_etablissement, | |||||
'status' => 11 | |||||
])->one() ; | |||||
'id_etablissement' => $production->id_etablissement, | |||||
'status' => 11 | |||||
])->one(); | |||||
if($user_action) | |||||
if ($user_action) | |||||
$id_user_action = $user_action->id; | $id_user_action = $user_action->id; | ||||
else | else | ||||
$id_user_action = NULL ; | |||||
$id_user_action = NULL; | |||||
if($commande->getMontant() > 0) | |||||
{ | |||||
if ($commande->getMontant() > 0) { | |||||
$commande->creditHistorique( | $commande->creditHistorique( | ||||
CreditHistorique::TYPE_PAIEMENT, | |||||
$commande->getMontant(), | |||||
$production->id_etablissement, | |||||
$id_user_action | |||||
) ; | |||||
CreditHistorique::TYPE_PAIEMENT, $commande->getMontant(), $production->id_etablissement, $id_user_action | |||||
); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\CommandeAuto ; | |||||
use common\models\CommandeAutoProduit ; | |||||
use common\models\CommandeAuto; | |||||
use common\models\CommandeAutoProduit; | |||||
/** | /** | ||||
* Login form | * Login form | ||||
*/ | */ | ||||
class CommandeAutoForm extends Model | |||||
{ | |||||
public $id ; | |||||
public $id_user ; | |||||
public $username ; | |||||
public $id_etablissement ; | |||||
public $id_point_vente ; | |||||
class CommandeAutoForm extends Model { | |||||
public $id; | |||||
public $id_user; | |||||
public $username; | |||||
public $id_etablissement; | |||||
public $id_point_vente; | |||||
public $date_debut; | public $date_debut; | ||||
public $date_fin ; | |||||
public $lundi ; | |||||
public $mardi ; | |||||
public $mercredi ; | |||||
public $jeudi ; | |||||
public $vendredi ; | |||||
public $samedi ; | |||||
public $dimanche ; | |||||
public $periodicite_semaine ; | |||||
public $produits ; | |||||
public $paiement_automatique ; | |||||
public $date_fin; | |||||
public $lundi; | |||||
public $mardi; | |||||
public $mercredi; | |||||
public $jeudi; | |||||
public $vendredi; | |||||
public $samedi; | |||||
public $dimanche; | |||||
public $periodicite_semaine; | |||||
public $produits; | |||||
public $paiement_automatique; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | [['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | ||||
[['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'], | [['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'], | ||||
[['lundi','mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche','paiement_automatique'], 'boolean'], | |||||
[['id_point_vente', 'id_etablissement', 'date_debut'],'required', 'message' => 'Champs obligatoire'], | |||||
[['produits','id_user','username'], 'safe'], | |||||
[['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'paiement_automatique'], 'boolean'], | |||||
[['id_point_vente', 'id_etablissement', 'date_debut'], 'required', 'message' => 'Champs obligatoire'], | |||||
[['produits', 'id_user', 'username'], 'safe'], | |||||
['id_user', function ($attribute, $params) { | ['id_user', function ($attribute, $params) { | ||||
if(!$this->id_user && !strlen($this->username)) | |||||
{ | |||||
$this->addError($attribute,'Vous devez sélectionner ou saisir un utilisateur.') ; | |||||
} | |||||
},'skipOnEmpty' => false], | |||||
if (!$this->id_user && !strlen($this->username)) { | |||||
$this->addError($attribute, 'Vous devez sélectionner ou saisir un utilisateur.'); | |||||
} | |||||
}, 'skipOnEmpty' => false], | |||||
]; | ]; | ||||
} | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'id_user' => 'Utilisateur', | |||||
'id_etablissement' => 'ID Etablissement', | |||||
'id_point_vente' => 'Point de vente', | |||||
'date_debut' => 'Date de début', | |||||
'date_fin' => 'Date de fin', | |||||
'lundi' => 'Lundi', | |||||
'mardi' => 'Mardi', | |||||
'mercredi' => 'Mercredi', | |||||
'jeudi' => 'Jeudi', | |||||
'vendredi' => 'Vendredi', | |||||
'samedi' => 'Samedi', | |||||
'dimanche' => 'Dimanche', | |||||
'periodicite_semaine' => 'Périodicité (semaines)', | |||||
'username' => 'Nom d\'utilisateur', | |||||
'paiement_automatique' => 'Paiement automatique' | |||||
]; | |||||
} | } | ||||
public function save() | |||||
{ | |||||
if($this->id) | |||||
{ | |||||
$commandeauto = CommandeAuto::findOne($this->id) ; | |||||
} | |||||
else { | |||||
$commandeauto = new CommandeAuto ; | |||||
public function attributeLabels() { | |||||
return [ | |||||
'id' => 'ID', | |||||
'id_user' => 'Utilisateur', | |||||
'id_etablissement' => 'ID Etablissement', | |||||
'id_point_vente' => 'Point de vente', | |||||
'date_debut' => 'Date de début', | |||||
'date_fin' => 'Date de fin', | |||||
'lundi' => 'Lundi', | |||||
'mardi' => 'Mardi', | |||||
'mercredi' => 'Mercredi', | |||||
'jeudi' => 'Jeudi', | |||||
'vendredi' => 'Vendredi', | |||||
'samedi' => 'Samedi', | |||||
'dimanche' => 'Dimanche', | |||||
'periodicite_semaine' => 'Périodicité (semaines)', | |||||
'username' => 'Nom d\'utilisateur', | |||||
'paiement_automatique' => 'Paiement automatique' | |||||
]; | |||||
} | |||||
public function save() { | |||||
if ($this->id) { | |||||
$commandeauto = CommandeAuto::findOne($this->id); | |||||
} else { | |||||
$commandeauto = new CommandeAuto; | |||||
} | } | ||||
if($commandeauto) | |||||
{ | |||||
$commandeauto->id_user = $this->id_user ; | |||||
$commandeauto->username = $this->username ; | |||||
$commandeauto->id_etablissement = $this->id_etablissement ; | |||||
$commandeauto->id_point_vente = $this->id_point_vente ; | |||||
$commandeauto->date_debut = date('Y-m-d',strtotime(str_replace('/','-',$this->date_debut))) ; | |||||
if(strlen($this->date_fin)) | |||||
{ | |||||
$commandeauto->date_fin = date('Y-m-d',strtotime(str_replace('/','-',$this->date_fin))) ; | |||||
if ($commandeauto) { | |||||
$commandeauto->id_user = $this->id_user; | |||||
$commandeauto->username = $this->username; | |||||
$commandeauto->id_etablissement = $this->id_etablissement; | |||||
$commandeauto->id_point_vente = $this->id_point_vente; | |||||
$commandeauto->date_debut = date('Y-m-d', strtotime(str_replace('/', '-', $this->date_debut))); | |||||
if (strlen($this->date_fin)) { | |||||
$commandeauto->date_fin = date('Y-m-d', strtotime(str_replace('/', '-', $this->date_fin))); | |||||
} | } | ||||
$commandeauto->lundi = $this->lundi ; | |||||
$commandeauto->mardi = $this->mardi ; | |||||
$commandeauto->mercredi = $this->mercredi ; | |||||
$commandeauto->jeudi = $this->jeudi ; | |||||
$commandeauto->vendredi = $this->vendredi ; | |||||
$commandeauto->samedi = $this->samedi ; | |||||
$commandeauto->dimanche = $this->dimanche ; | |||||
$commandeauto->periodicite_semaine = $this->periodicite_semaine ; | |||||
$commandeauto->paiement_automatique = $this->paiement_automatique ; | |||||
$commandeauto->save() ; | |||||
$commandeauto->lundi = $this->lundi; | |||||
$commandeauto->mardi = $this->mardi; | |||||
$commandeauto->mercredi = $this->mercredi; | |||||
$commandeauto->jeudi = $this->jeudi; | |||||
$commandeauto->vendredi = $this->vendredi; | |||||
$commandeauto->samedi = $this->samedi; | |||||
$commandeauto->dimanche = $this->dimanche; | |||||
$commandeauto->periodicite_semaine = $this->periodicite_semaine; | |||||
$commandeauto->paiement_automatique = $this->paiement_automatique; | |||||
$commandeauto->save(); | |||||
// produits | // produits | ||||
if($this->id) | |||||
{ | |||||
CommandeAutoProduit::deleteAll(['id_commande_auto' => $this->id]) ; | |||||
if ($this->id) { | |||||
CommandeAutoProduit::deleteAll(['id_commande_auto' => $this->id]); | |||||
} | } | ||||
foreach($this->produits as $name_input => $quantite) | |||||
{ | |||||
if($quantite) | |||||
{ | |||||
$id_produit = str_replace('produit_', '', $name_input) ; | |||||
$commandeauto_produit = new CommandeAutoProduit ; | |||||
$commandeauto_produit->id_commande_auto = $commandeauto->id ; | |||||
$commandeauto_produit->id_produit = $id_produit ; | |||||
$commandeauto_produit->quantite = $quantite ; | |||||
$commandeauto_produit->save() ; | |||||
} | |||||
foreach ($this->produits as $name_input => $quantite) { | |||||
if ($quantite) { | |||||
$id_produit = str_replace('produit_', '', $name_input); | |||||
$commandeauto_produit = new CommandeAutoProduit; | |||||
$commandeauto_produit->id_commande_auto = $commandeauto->id; | |||||
$commandeauto_produit->id_produit = $id_produit; | |||||
$commandeauto_produit->quantite = $quantite; | |||||
$commandeauto_produit->save(); | |||||
} | |||||
} | } | ||||
} | } | ||||
return true ; | |||||
return true; | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\Produit ; | |||||
use common\models\Produit; | |||||
/** | /** | ||||
* This is the model class for table "commande_auto_produit". | * This is the model class for table "commande_auto_produit". | ||||
* @property integer $id_produit | * @property integer $id_produit | ||||
* @property double $quantite | * @property double $quantite | ||||
*/ | */ | ||||
class CommandeAutoProduit extends \yii\db\ActiveRecord | |||||
{ | |||||
class CommandeAutoProduit extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'commande_auto_produit'; | return 'commande_auto_produit'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_commande_auto', 'id_produit'], 'required'], | [['id_commande_auto', 'id_produit'], 'required'], | ||||
[['id_commande_auto', 'id_produit'], 'integer'], | [['id_commande_auto', 'id_produit'], 'integer'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_commande_auto' => 'Id Commande Auto', | 'id_commande_auto' => 'Id Commande Auto', | ||||
'quantite' => 'Quantite', | 'quantite' => 'Quantite', | ||||
]; | ]; | ||||
} | } | ||||
public function getProduit() | |||||
{ | |||||
return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ; | |||||
public function getProduit() { | |||||
return $this->hasOne(Produit::className(), ['id' => 'id_produit']); | |||||
} | } | ||||
} | } |
* @property integer $id_produit | * @property integer $id_produit | ||||
* @property double $quantite | * @property double $quantite | ||||
*/ | */ | ||||
class CommandeProduit extends \yii\db\ActiveRecord | |||||
{ | |||||
class CommandeProduit extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'commande_produit'; | return 'commande_produit'; | ||||
} | } | ||||
/* | /* | ||||
* Relations | * Relations | ||||
*/ | */ | ||||
public function getProduit() { | public function getProduit() { | ||||
return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ; | |||||
return $this->hasOne(Produit::className(), ['id' => 'id_produit']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_commande', 'id_produit', 'quantite'], 'required'], | [['id_commande', 'id_produit', 'quantite'], 'required'], | ||||
[['id_commande', 'id_produit'], 'integer'], | [['id_commande', 'id_produit'], 'integer'], | ||||
[['quantite'], 'number','min' => 0] | |||||
[['quantite'], 'number', 'min' => 0] | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_commande' => 'Id Commande', | 'id_commande' => 'Id Commande', | ||||
'quantite' => 'Quantite', | 'quantite' => 'Quantite', | ||||
]; | ]; | ||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use yii\db\ActiveRecord ; | |||||
use common\models\User ; | |||||
use common\models\Commande ; | |||||
use yii\db\ActiveRecord; | |||||
use common\models\User; | |||||
use common\models\Commande; | |||||
/** | /** | ||||
* This is the model class for table "credit_historique". | * This is the model class for table "credit_historique". | ||||
* @property integer $id_etablissement | * @property integer $id_etablissement | ||||
* @property string $moyen_paiement | * @property string $moyen_paiement | ||||
*/ | */ | ||||
class CreditHistorique extends ActiveRecord | |||||
{ | |||||
const TYPE_CREDIT_INITIAL = 'credit-initial' ; | |||||
const TYPE_CREDIT = 'credit' ; | |||||
const TYPE_PAIEMENT = 'paiement' ; | |||||
const TYPE_REMBOURSEMENT = 'remboursement' ; | |||||
const TYPE_DEBIT = 'debit' ; | |||||
const MOYEN_CB = 'cb' ; | |||||
const MOYEN_ESPECES = 'especes' ; | |||||
const MOYEN_CHEQUE = 'cheque' ; | |||||
const MOYEN_AUTRE = 'autre' ; | |||||
class CreditHistorique extends ActiveRecord { | |||||
const TYPE_CREDIT_INITIAL = 'credit-initial'; | |||||
const TYPE_CREDIT = 'credit'; | |||||
const TYPE_PAIEMENT = 'paiement'; | |||||
const TYPE_REMBOURSEMENT = 'remboursement'; | |||||
const TYPE_DEBIT = 'debit'; | |||||
const MOYEN_CB = 'cb'; | |||||
const MOYEN_ESPECES = 'especes'; | |||||
const MOYEN_CHEQUE = 'cheque'; | |||||
const MOYEN_AUTRE = 'autre'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'credit_historique'; | return 'credit_historique'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['montant'], 'required'], | [['montant'], 'required'], | ||||
[['id_user','id_user_action', 'id_commande', 'id_etablissement'], 'integer'], | |||||
[['id_user', 'id_user_action', 'id_commande', 'id_etablissement'], 'integer'], | |||||
[['date'], 'safe'], | [['date'], 'safe'], | ||||
[['montant'], 'double'], | [['montant'], 'double'], | ||||
[['type', 'moyen_paiement','commentaire'], 'string', 'max' => 255], | |||||
[['type', 'moyen_paiement', 'commentaire'], 'string', 'max' => 255], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_user' => 'Utilisateur', | 'id_user' => 'Utilisateur', | ||||
'commentaire' => 'Commentaire', | 'commentaire' => 'Commentaire', | ||||
]; | ]; | ||||
} | } | ||||
public function getUser() | |||||
{ | |||||
return $this->hasOne(User::className(),['id' => 'id_user']) ; | |||||
public function getUser() { | |||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getUserAction() | |||||
{ | |||||
return $this->hasOne(User::className(),['id' => 'id_user_action']) ; | |||||
public function getUserAction() { | |||||
return $this->hasOne(User::className(), ['id' => 'id_user_action']); | |||||
} | } | ||||
public function getCommande() | |||||
{ | |||||
return $this->hasOne(Commande::className(),['id' => 'id_commande']) ; | |||||
public function getCommande() { | |||||
return $this->hasOne(Commande::className(), ['id' => 'id_commande']); | |||||
} | } | ||||
public function getLibelleType() | |||||
{ | |||||
switch($this->type) | |||||
{ | |||||
case 'paiement': | |||||
return 'Paiement' ; | |||||
break ; | |||||
case 'remboursement': | |||||
return 'Remboursement' ; | |||||
break ; | |||||
case 'debit': | |||||
return 'Débit' ; | |||||
break ; | |||||
public function getLibelleType() { | |||||
switch ($this->type) { | |||||
case 'paiement': | |||||
return 'Paiement'; | |||||
break; | |||||
case 'remboursement': | |||||
return 'Remboursement'; | |||||
break; | |||||
case 'debit': | |||||
return 'Débit'; | |||||
break; | |||||
} | } | ||||
} | } | ||||
public function save($runValidation = true, $attributeNames = NULL) { | public function save($runValidation = true, $attributeNames = NULL) { | ||||
parent::save($runValidation, $attributeNames) ; | |||||
parent::save($runValidation, $attributeNames); | |||||
$user_etablissement = UserEtablissement::findOne([ | $user_etablissement = UserEtablissement::findOne([ | ||||
'id_user' => $this->id_user, | |||||
'id_etablissement' => $this->id_etablissement | |||||
]) ; | |||||
if($user_etablissement) | |||||
{ | |||||
if($this->type == self::TYPE_CREDIT || | |||||
$this->type == self::TYPE_CREDIT_INITIAL || | |||||
$this->type == self::TYPE_REMBOURSEMENT) | |||||
{ | |||||
$user_etablissement->credit += $this->montant ; | |||||
$user_etablissement->save() ; | |||||
} | |||||
elseif($this->type == self::TYPE_PAIEMENT) | |||||
{ | |||||
$user_etablissement->credit -= $this->montant ; | |||||
'id_user' => $this->id_user, | |||||
'id_etablissement' => $this->id_etablissement | |||||
]); | |||||
if ($user_etablissement) { | |||||
if ($this->type == self::TYPE_CREDIT || | |||||
$this->type == self::TYPE_CREDIT_INITIAL || | |||||
$this->type == self::TYPE_REMBOURSEMENT) { | |||||
$user_etablissement->credit += $this->montant; | |||||
$user_etablissement->save(); | |||||
} elseif ($this->type == self::TYPE_PAIEMENT) { | |||||
$user_etablissement->credit -= $this->montant; | |||||
} | } | ||||
$user_etablissement->save() ; | |||||
$user_etablissement->save(); | |||||
} | } | ||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\DeveloppementPriorite ; | |||||
use common\models\DeveloppementPriorite; | |||||
/** | /** | ||||
* This is the model class for table "developpement". | * This is the model class for table "developpement". | ||||
*/ | */ | ||||
class Developpement extends \yii\db\ActiveRecord { | class Developpement extends \yii\db\ActiveRecord { | ||||
const STATUT_OPEN = 'open' ; | |||||
const STATUT_CLOSED = 'closed' ; | |||||
const TYPE_EVOLUTION = 'evolution' ; | |||||
const TYPE_BUG = 'bug' ; | |||||
const STATUT_OPEN = 'open'; | |||||
const STATUT_CLOSED = 'closed'; | |||||
const TYPE_EVOLUTION = 'evolution'; | |||||
const TYPE_BUG = 'bug'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
[['objet', 'date'], 'required'], | [['objet', 'date'], 'required'], | ||||
[['id', 'avancement'], 'integer'], | [['id', 'avancement'], 'integer'], | ||||
[['description'], 'string'], | [['description'], 'string'], | ||||
[['date','date_livraison'], 'safe'], | |||||
[['date', 'date_livraison'], 'safe'], | |||||
[['estimation_temps'], 'number'], | [['estimation_temps'], 'number'], | ||||
[['objet', 'statut','type'], 'string', 'max' => 255], | |||||
[['objet', 'statut', 'type'], 'string', 'max' => 255], | |||||
]; | ]; | ||||
} | } | ||||
public function getDeveloppementPriorite() { | public function getDeveloppementPriorite() { | ||||
return $this->hasMany(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->with('etablissement') ; | |||||
return $this->hasMany(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->with('etablissement'); | |||||
} | } | ||||
public function getDeveloppementPrioriteCurrentEtablissement() { | public function getDeveloppementPrioriteCurrentEtablissement() { | ||||
return $this->hasOne(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->where(['id_etablissement'=>Yii::$app->user->identity->id_etablissement])->with('etablissement') ; | |||||
return $this->hasOne(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])->with('etablissement'); | |||||
} | } | ||||
/** | /** | ||||
'date_livraison' => 'Date de livraison' | 'date_livraison' => 'Date de livraison' | ||||
]; | ]; | ||||
} | } | ||||
public function setDateLivraison($date = '') { | public function setDateLivraison($date = '') { | ||||
if(strlen($date)) | |||||
$this->date_livraison = $date ; | |||||
if(strlen($this->date_livraison)) | |||||
$this->date_livraison = date('Y-m-d',strtotime($this->date_livraison)) ; | |||||
if (strlen($date)) | |||||
$this->date_livraison = $date; | |||||
if (strlen($this->date_livraison)) | |||||
$this->date_livraison = date('Y-m-d', strtotime($this->date_livraison)); | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\Etablissement ; | |||||
use common\models\Etablissement; | |||||
/** | /** | ||||
* This is the model class for table "developpement_priorite". | * This is the model class for table "developpement_priorite". | ||||
*/ | */ | ||||
class DeveloppementPriorite extends \yii\db\ActiveRecord { | class DeveloppementPriorite extends \yii\db\ActiveRecord { | ||||
const PRIORITE_HAUTE = 'haute' ; | |||||
const PRIORITE_NORMALE = 'normale' ; | |||||
const PRIORITE_BASSE = 'basse' ; | |||||
const PRIORITE_HAUTE = 'haute'; | |||||
const PRIORITE_NORMALE = 'normale'; | |||||
const PRIORITE_BASSE = 'basse'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
[['priorite'], 'string'], | [['priorite'], 'string'], | ||||
]; | ]; | ||||
} | } | ||||
public function getEtablissement() { | public function getEtablissement() { | ||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ; | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||||
} | } | ||||
/** | /** | ||||
'priorite' => 'Priorité' | 'priorite' => 'Priorité' | ||||
]; | ]; | ||||
} | } | ||||
public function getStrPriorite() | |||||
{ | |||||
switch($this->priorite) | |||||
{ | |||||
case self::PRIORITE_BASSE : return 'Basse' ; break ; | |||||
case self::PRIORITE_NORMALE : return 'Normale' ; break ; | |||||
case self::PRIORITE_HAUTE : return 'Haute' ; break ; | |||||
default: return 'Non définie' ; break ; | |||||
public function getStrPriorite() { | |||||
switch ($this->priorite) { | |||||
case self::PRIORITE_BASSE : return 'Basse'; | |||||
break; | |||||
case self::PRIORITE_NORMALE : return 'Normale'; | |||||
break; | |||||
case self::PRIORITE_HAUTE : return 'Haute'; | |||||
break; | |||||
default: return 'Non définie'; | |||||
break; | |||||
} | } | ||||
} | } | ||||
public function getClassCssStyleBouton() { | public function getClassCssStyleBouton() { | ||||
$style_bouton = 'default' ; | |||||
if($this->priorite == DeveloppementPriorite::PRIORITE_BASSE) | |||||
$style_bouton = 'info' ; | |||||
elseif($this->priorite == DeveloppementPriorite::PRIORITE_NORMALE) | |||||
$style_bouton = 'warning' ; | |||||
elseif($this->priorite == DeveloppementPriorite::PRIORITE_HAUTE) | |||||
$style_bouton = 'danger' ; | |||||
return $style_bouton ; | |||||
$style_bouton = 'default'; | |||||
if ($this->priorite == DeveloppementPriorite::PRIORITE_BASSE) | |||||
$style_bouton = 'info'; | |||||
elseif ($this->priorite == DeveloppementPriorite::PRIORITE_NORMALE) | |||||
$style_bouton = 'warning'; | |||||
elseif ($this->priorite == DeveloppementPriorite::PRIORITE_HAUTE) | |||||
$style_bouton = 'danger'; | |||||
return $style_bouton; | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\helpers\Departements ; | |||||
use yii\helpers\Html ; | |||||
use common\helpers\Departements; | |||||
use yii\helpers\Html; | |||||
/** | /** | ||||
* This is the model class for table "etablissement". | * This is the model class for table "etablissement". | ||||
* @property string $code_postal | * @property string $code_postal | ||||
* @property string $ville | * @property string $ville | ||||
*/ | */ | ||||
class Etablissement extends \yii\db\ActiveRecord | |||||
{ | |||||
const PAIEMENT_OK = 'ok' ; | |||||
const PAIEMENT_ESSAI = 'essai' ; | |||||
const PAIEMENT_ESSAI_TERMINE = 'essai-terminee' ; | |||||
const PAIEMENT_RETARD = 'retard-paiement' ; | |||||
class Etablissement extends \yii\db\ActiveRecord { | |||||
const PAIEMENT_OK = 'ok'; | |||||
const PAIEMENT_ESSAI = 'essai'; | |||||
const PAIEMENT_ESSAI_TERMINE = 'essai-terminee'; | |||||
const PAIEMENT_RETARD = 'retard-paiement'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'etablissement'; | return 'etablissement'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['nom', 'siret', 'heure_limite_commande','delai_commande'], 'required'], | |||||
[['heure_limite_commande','delai_commande'],'integer'], | |||||
['heure_limite_commande','in', 'range' => [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]], | |||||
['delai_commande','in', 'range' => [1,2,3,4,5,6,7]], | |||||
['code', function($attribute, $params) | |||||
{ | |||||
$code = $this->$attribute ; | |||||
$etablissement = Etablissement::findOne(['code' => $code]) ; | |||||
if($etablissement && $etablissement->id != $this->id) | |||||
{ | |||||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | |||||
} | |||||
}], | |||||
[['description','infos_commande'], 'string'], | |||||
[['solde_negatif', 'credit_pain','actif'], 'boolean'], | |||||
[['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville','code'], 'string', 'max' => 255], | |||||
['prix_libre','double'], | |||||
['prix_libre', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number','message' => 'Prix libre doit être supérieur ou égal à 0'], | |||||
[['nom', 'siret', 'heure_limite_commande', 'delai_commande'], 'required'], | |||||
[['heure_limite_commande', 'delai_commande'], 'integer'], | |||||
['heure_limite_commande', 'in', 'range' => [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]], | |||||
['delai_commande', 'in', 'range' => [1, 2, 3, 4, 5, 6, 7]], | |||||
['code', function($attribute, $params) { | |||||
$code = $this->$attribute; | |||||
$etablissement = Etablissement::findOne(['code' => $code]); | |||||
if ($etablissement && $etablissement->id != $this->id) { | |||||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | |||||
} | |||||
}], | |||||
[['description', 'infos_commande'], 'string'], | |||||
[['solde_negatif', 'credit_pain', 'actif'], 'boolean'], | |||||
[['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville', 'code'], 'string', 'max' => 255], | |||||
['prix_libre', 'double'], | |||||
['prix_libre', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'nom' => 'Nom', | 'nom' => 'Nom', | ||||
'infos_commande' => 'Informations' | 'infos_commande' => 'Informations' | ||||
]; | ]; | ||||
} | } | ||||
public function getUserEtablissement() | |||||
{ | |||||
return $this->hasMany(UserEtablissement::className(), ['id_etablissement' => 'id']) ; | |||||
public function getUserEtablissement() { | |||||
return $this->hasMany(UserEtablissement::className(), ['id_etablissement' => 'id']); | |||||
} | } | ||||
public function getUser() | |||||
{ | |||||
return $this->hasMany(User::className(), ['id_etablissement' => 'id']) ; | |||||
public function getUser() { | |||||
return $this->hasMany(User::className(), ['id_etablissement' => 'id']); | |||||
} | } | ||||
public static function getEtablissementsPopulateDropdown() | |||||
{ | |||||
public static function getEtablissementsPopulateDropdown() { | |||||
$etablissements_dispos = Etablissement::find() | $etablissements_dispos = Etablissement::find() | ||||
->where(['actif' => 1]) | ->where(['actif' => 1]) | ||||
->orderby('code_postal, ville ASC') | ->orderby('code_postal, ville ASC') | ||||
->all() ; | |||||
$departements = Departements::get() ; | |||||
$data_etablissements_dispos = [] ; | |||||
$options_etablissements_dispos = [] ; | |||||
foreach($etablissements_dispos as $e) | |||||
{ | |||||
if($e->etatPaiement() == self::PAIEMENT_OK || $e->etatPaiement() == self::PAIEMENT_ESSAI) | |||||
{ | |||||
if(!key_exists('d'. substr($e->code_postal, 0, 2), $data_etablissements_dispos)) | |||||
{ | |||||
$data_etablissements_dispos['d'. substr($e->code_postal, 0, 2)] = '<strong>'.$departements[substr($e->code_postal, 0, 2)].'</strong>' ; | |||||
$options_etablissements_dispos['d'. substr($e->code_postal, 0, 2)] = ['disabled' => true] ; | |||||
->all(); | |||||
$departements = Departements::get(); | |||||
$data_etablissements_dispos = []; | |||||
$options_etablissements_dispos = []; | |||||
foreach ($etablissements_dispos as $e) { | |||||
if ($e->etatPaiement() == self::PAIEMENT_OK || $e->etatPaiement() == self::PAIEMENT_ESSAI) { | |||||
if (!key_exists('d' . substr($e->code_postal, 0, 2), $data_etablissements_dispos)) { | |||||
$data_etablissements_dispos['d' . substr($e->code_postal, 0, 2)] = '<strong>' . $departements[substr($e->code_postal, 0, 2)] . '</strong>'; | |||||
$options_etablissements_dispos['d' . substr($e->code_postal, 0, 2)] = ['disabled' => true]; | |||||
} | } | ||||
$data_etablissements_dispos[$e->id] = '<span class="glyphicon glyphicon-lock"></span> '.Html::encode($e->nom).' - '.Html::encode($e->code_postal).' '.Html::encode($e->ville).' <span class="glyphicon glyphicon-lock"></span>' ; | |||||
if(strlen($e->code)) | |||||
$options_etablissements_dispos[$e->id] = ['class' => 'lock'] ; | |||||
$data_etablissements_dispos[$e->id] = '<span class="glyphicon glyphicon-lock"></span> ' . Html::encode($e->nom) . ' - ' . Html::encode($e->code_postal) . ' ' . Html::encode($e->ville) . ' <span class="glyphicon glyphicon-lock"></span>'; | |||||
if (strlen($e->code)) | |||||
$options_etablissements_dispos[$e->id] = ['class' => 'lock']; | |||||
} | } | ||||
} | } | ||||
return ['data' => $data_etablissements_dispos, 'options' => $options_etablissements_dispos] ; | |||||
return ['data' => $data_etablissements_dispos, 'options' => $options_etablissements_dispos]; | |||||
} | } | ||||
public function etatPaiement() | |||||
{ | |||||
$date_limite = strtotime($this->date_creation) + 30*24*60*60 ; | |||||
$date = time() ; | |||||
$date_paiement = strtotime($this->date_paiement) ; | |||||
if($date < $date_paiement + 30*24*60*60 || $this->gratuit) | |||||
{ | |||||
return 'ok' ; | |||||
} | |||||
else { | |||||
if($date < $date_limite) | |||||
{ | |||||
return 'essai' ; | |||||
} | |||||
else { | |||||
if(!$this->date_paiement) | |||||
return 'essai-terminee' ; | |||||
public function etatPaiement() { | |||||
$date_limite = strtotime($this->date_creation) + 30 * 24 * 60 * 60; | |||||
$date = time(); | |||||
$date_paiement = strtotime($this->date_paiement); | |||||
if ($date < $date_paiement + 30 * 24 * 60 * 60 || $this->gratuit) { | |||||
return 'ok'; | |||||
} else { | |||||
if ($date < $date_limite) { | |||||
return 'essai'; | |||||
} else { | |||||
if (!$this->date_paiement) | |||||
return 'essai-terminee'; | |||||
else | else | ||||
return 'retard-paiement' ; | |||||
return 'retard-paiement'; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public function getCA($periode = '', $format = false) | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m') ; | |||||
public function getCA($periode = '', $format = false) { | |||||
if (!$periode) | |||||
$periode = date('Y-m'); | |||||
$connection = Yii::$app->getDb(); | $connection = Yii::$app->getDb(); | ||||
$command = $connection->createCommand(' | $command = $connection->createCommand(' | ||||
SELECT SUM(IF(produit.vrac,0,commande_produit.prix * commande_produit.quantite)) AS CA | |||||
FROM commande, commande_produit, production, produit | |||||
WHERE commande.id = commande_produit.id_commande | |||||
AND production.id_etablissement = :id_etablissement | |||||
AND commande.id_production = production.id | |||||
AND commande_produit.id_produit = produit.id | |||||
AND production.date > :date_debut | |||||
AND production.date < :date_fin', | |||||
[ | |||||
':date_debut' => date('Y-m-31', strtotime("-1 month", strtotime($periode))), | |||||
':date_fin' => date('Y-m-01', strtotime("+1 month", strtotime($periode))), | |||||
':id_etablissement' => $this->id | |||||
]); | |||||
SELECT SUM(IF(produit.vrac,0,commande_produit.prix * commande_produit.quantite)) AS CA | |||||
FROM commande, commande_produit, production, produit | |||||
WHERE commande.id = commande_produit.id_commande | |||||
AND production.id_etablissement = :id_etablissement | |||||
AND commande.id_production = production.id | |||||
AND commande_produit.id_produit = produit.id | |||||
AND production.date > :date_debut | |||||
AND production.date < :date_fin', [ | |||||
':date_debut' => date('Y-m-31', strtotime("-1 month", strtotime($periode))), | |||||
':date_fin' => date('Y-m-01', strtotime("+1 month", strtotime($periode))), | |||||
':id_etablissement' => $this->id | |||||
]); | |||||
$result = $command->queryOne(); | $result = $command->queryOne(); | ||||
$ca = $result['CA'] ; | |||||
if($format) | |||||
return number_format($ca, 2).' €' ; | |||||
$ca = $result['CA']; | |||||
if ($format) | |||||
return number_format($ca, 2) . ' €'; | |||||
else | else | ||||
return $ca ; | |||||
return $ca; | |||||
} | } | ||||
public function getMontantFacturer($periode = '', $ca = 0, $format = false) | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m') ; | |||||
if(!$ca) | |||||
$ca = $this->getCA($periode) ; | |||||
if($ca < 500) | |||||
{ | |||||
$montant = 0 ; | |||||
} | |||||
else { | |||||
$montant = $ca * 0.02 ; | |||||
} | |||||
if($format) | |||||
{ | |||||
return number_format($montant, 2).' €' ; | |||||
public function getMontantFacturer($periode = '', $ca = 0, $format = false) { | |||||
if (!$periode) | |||||
$periode = date('Y-m'); | |||||
if (!$ca) | |||||
$ca = $this->getCA($periode); | |||||
if ($ca < 500) { | |||||
$montant = 0; | |||||
} else { | |||||
$montant = $ca * 0.02; | |||||
} | } | ||||
else { | |||||
return $montant ; | |||||
if ($format) { | |||||
return number_format($montant, 2) . ' €'; | |||||
} else { | |||||
return $montant; | |||||
} | } | ||||
} | } | ||||
public function getFacture($periode = '') | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m', strtotime('-1 month')) ; | |||||
public function getFacture($periode = '') { | |||||
if (!$periode) | |||||
$periode = date('Y-m', strtotime('-1 month')); | |||||
$facture = Facture::find() | $facture = Facture::find() | ||||
->where('id_etablissement = :id_etablissement') | ->where('id_etablissement = :id_etablissement') | ||||
->andWhere('periode = :periode') | ->andWhere('periode = :periode') | ||||
':id_etablissement' => $this->id, | ':id_etablissement' => $this->id, | ||||
':periode' => $periode, | ':periode' => $periode, | ||||
]) | ]) | ||||
->one() ; | |||||
return $facture ; | |||||
->one(); | |||||
return $facture; | |||||
} | } | ||||
public function factureMoisDernier() | |||||
{ | |||||
return $this->getFacture(date('Y-m', strtotime('-1 month'))) ; | |||||
public function factureMoisDernier() { | |||||
return $this->getFacture(date('Y-m', strtotime('-1 month'))); | |||||
} | } | ||||
public static function getConfig($config = '', $id_etablissement = 0) | |||||
{ | |||||
if(strlen($config)) | |||||
{ | |||||
if(!$id_etablissement) | |||||
$id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$etablissement = self::findOne($id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
return $etablissement->$config ; | |||||
public static function getConfig($config = '', $id_etablissement = 0) { | |||||
if (strlen($config)) { | |||||
if (!$id_etablissement) | |||||
$id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
$etablissement = self::findOne($id_etablissement); | |||||
if ($etablissement) { | |||||
return $etablissement->$config; | |||||
} | } | ||||
} | } | ||||
return false ; | |||||
return false; | |||||
} | } | ||||
public function getPrixLibre() | |||||
{ | |||||
if(!is_null($this->prix_libre)) | |||||
{ | |||||
return number_format($this->prix_libre, 2, ',', false).' €' ; | |||||
public function getPrixLibre() { | |||||
if (!is_null($this->prix_libre)) { | |||||
return number_format($this->prix_libre, 2, ',', false) . ' €'; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
* @property string $date_paiement | * @property string $date_paiement | ||||
* @property string $methode_paiement | * @property string $methode_paiement | ||||
*/ | */ | ||||
class Facture extends \yii\db\ActiveRecord | |||||
{ | |||||
class Facture extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'facture'; | return 'facture'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_etablissement', 'paye'], 'integer'], | [['id_etablissement', 'paye'], 'integer'], | ||||
[['date', 'date_paiement'], 'safe'], | [['date', 'date_paiement'], 'safe'], | ||||
[['texte'], 'string'], | [['texte'], 'string'], | ||||
[['montant_ht','ca'], 'number'], | |||||
[['montant_ht', 'ca'], 'number'], | |||||
[['reference', 'libelle', 'methode_paiement'], 'string', 'max' => 255], | [['reference', 'libelle', 'methode_paiement'], 'string', 'max' => 255], | ||||
]; | ]; | ||||
} | } | ||||
public function getEtablissement() | |||||
{ | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ; | |||||
public function getEtablissement() { | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_etablissement' => 'Id Etablissement', | 'id_etablissement' => 'Id Etablissement', | ||||
'ca' => 'CA' | 'ca' => 'CA' | ||||
]; | ]; | ||||
} | } | ||||
public static function getLastFacture() | |||||
{ | |||||
public static function getLastFacture() { | |||||
return Facture::find() | return Facture::find() | ||||
->orderBy('reference DESC') | |||||
->one() ; | |||||
->orderBy('reference DESC') | |||||
->one(); | |||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
/** | /** | ||||
* Login form | * Login form | ||||
*/ | */ | ||||
class LoginForm extends Model | |||||
{ | |||||
class LoginForm extends Model { | |||||
public $username; | public $username; | ||||
public $password; | public $password; | ||||
public $rememberMe = true; | public $rememberMe = true; | ||||
public $email; | public $email; | ||||
private $_user = false; | private $_user = false; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['email', 'filter', 'filter' => 'trim'], | |||||
['email', 'required','message'=>'Champs obligatoire'], | |||||
['email', 'email'], | |||||
['email', 'filter', 'filter' => 'trim'], | |||||
['email', 'required', 'message' => 'Champs obligatoire'], | |||||
['email', 'email'], | |||||
// username and password are both required | // username and password are both required | ||||
[ 'password', 'required','message'=>'Champs obligatoire'], | |||||
[ 'password', 'required', 'message' => 'Champs obligatoire'], | |||||
// rememberMe must be a boolean value | // rememberMe must be a boolean value | ||||
['rememberMe', 'boolean'], | ['rememberMe', 'boolean'], | ||||
// password is validated by validatePassword() | // password is validated by validatePassword() | ||||
* @param string $attribute the attribute currently being validated | * @param string $attribute the attribute currently being validated | ||||
* @param array $params the additional name-value pairs given in the rule | * @param array $params the additional name-value pairs given in the rule | ||||
*/ | */ | ||||
public function validatePassword($attribute, $params) | |||||
{ | |||||
public function validatePassword($attribute, $params) { | |||||
if (!$this->hasErrors()) { | if (!$this->hasErrors()) { | ||||
$user = $this->getUser(); | $user = $this->getUser(); | ||||
if (!$user || !$user->validatePassword($this->password)) { | if (!$user || !$user->validatePassword($this->password)) { | ||||
* | * | ||||
* @return boolean whether the user is logged in successfully | * @return boolean whether the user is logged in successfully | ||||
*/ | */ | ||||
public function login() | |||||
{ | |||||
public function login() { | |||||
if ($this->validate()) { | if ($this->validate()) { | ||||
$this->updateDerniereConnexion() ; | |||||
$this->updateDerniereConnexion(); | |||||
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | ||||
} else { | } else { | ||||
return false; | return false; | ||||
* | * | ||||
* @return User|null | * @return User|null | ||||
*/ | */ | ||||
public function getUser() | |||||
{ | |||||
public function getUser() { | |||||
if ($this->_user === false) { | if ($this->_user === false) { | ||||
$this->_user = User::findByEmail($this->email) ; | |||||
$this->_user = User::findByEmail($this->email); | |||||
} | } | ||||
return $this->_user; | return $this->_user; | ||||
} | } | ||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'email' => 'Email', | |||||
]; | |||||
public function attributeLabels() { | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'email' => 'Email', | |||||
]; | |||||
} | } | ||||
public function updateDerniereConnexion() | |||||
{ | |||||
$user = $this->getUser() ; | |||||
$user->date_derniere_connexion = date('Y-m-d H:i:s') ; | |||||
$user->save() ; | |||||
public function updateDerniereConnexion() { | |||||
$user = $this->getUser(); | |||||
$user->date_derniere_connexion = date('Y-m-d H:i:s'); | |||||
$user->save(); | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use yii\helpers\Html ; | |||||
use common\models\PointVenteUser ; | |||||
use common\models\ProductionPointVente ; | |||||
use yii\helpers\Html; | |||||
use common\models\PointVenteUser; | |||||
use common\models\ProductionPointVente; | |||||
/** | /** | ||||
* This is the model class for table "point_vente". | * This is the model class for table "point_vente". | ||||
* @property string $adresse | * @property string $adresse | ||||
* @property integer $id_boulangerie | * @property integer $id_boulangerie | ||||
*/ | */ | ||||
class PointVente extends \yii\db\ActiveRecord | |||||
{ | |||||
var $commandes = [] ; | |||||
var $recettes = 0 ; | |||||
var $recettes_pain = 0 ; | |||||
var $recettes_vrac = 0 ; | |||||
var $data_select_commandes ; | |||||
var $data_options_commandes ; | |||||
var $users = [] ; | |||||
var $users_commentaire = [] ; | |||||
class PointVente extends \yii\db\ActiveRecord { | |||||
var $commandes = []; | |||||
var $recettes = 0; | |||||
var $recettes_pain = 0; | |||||
var $recettes_vrac = 0; | |||||
var $data_select_commandes; | |||||
var $data_options_commandes; | |||||
var $users = []; | |||||
var $users_commentaire = []; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'point_vente'; | return 'point_vente'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['nom'], 'required'], | [['nom'], 'required'], | ||||
[['acces_restreint'], 'boolean'], | [['acces_restreint'], 'boolean'], | ||||
[['nom','code'], 'string', 'max' => 255], | |||||
[['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'], | |||||
[['point_fabrication','vrac','pain', 'credit_pain','livraison_lundi','livraison_mardi','livraison_mercredi','livraison_jeudi','livraison_vendredi','livraison_samedi','livraison_dimanche'], 'boolean'], | |||||
['point_fabrication', 'default','value'=>0], | |||||
['id_etablissement','integer'], | |||||
['id_etablissement','required'], | |||||
[['users','users_commentaire','code'],'safe'] | |||||
[['nom', 'code'], 'string', 'max' => 255], | |||||
[['adresse', 'localite', 'horaires_lundi', 'horaires_mardi', 'horaires_mercredi', 'horaires_jeudi', 'horaires_vendredi', 'horaires_samedi', 'horaires_dimanche'], 'string'], | |||||
[['point_fabrication', 'vrac', 'pain', 'credit_pain', 'livraison_lundi', 'livraison_mardi', 'livraison_mercredi', 'livraison_jeudi', 'livraison_vendredi', 'livraison_samedi', 'livraison_dimanche'], 'boolean'], | |||||
['point_fabrication', 'default', 'value' => 0], | |||||
['id_etablissement', 'integer'], | |||||
['id_etablissement', 'required'], | |||||
[['users', 'users_commentaire', 'code'], 'safe'] | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'nom' => 'Nom', | 'nom' => 'Nom', | ||||
'livraison_samedi' => 'Samedi', | 'livraison_samedi' => 'Samedi', | ||||
'livraison_dimanche' => 'Dimanche', | 'livraison_dimanche' => 'Dimanche', | ||||
'code' => 'Code', | 'code' => 'Code', | ||||
]; | |||||
]; | |||||
} | } | ||||
public function getPointVenteUser() | |||||
{ | |||||
return $this->hasMany(PointVenteUser::className(), ['id_point_vente'=>'id']) ; | |||||
public function getPointVenteUser() { | |||||
return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); | |||||
} | } | ||||
public function getProductionPointVente() | |||||
{ | |||||
return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']) ; | |||||
public function getProductionPointVente() { | |||||
return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']); | |||||
} | } | ||||
public function initCommandes($commandes) { | public function initCommandes($commandes) { | ||||
$this->commandes = [] ; | |||||
$this->recettes = 0 ; | |||||
$this->recettes_pain = 0 ; | |||||
$this->recettes_vrac = 0 ; | |||||
foreach($commandes as $c) { | |||||
if($this->id == $c->id_point_vente) { | |||||
$this->commandes[] = $c ; | |||||
$this->recettes += (float) $c->montant ; | |||||
$this->recettes_pain += (float) $c->montant_pain ; | |||||
$this->recettes_vrac += (float) $c->montant_vrac ; | |||||
} | |||||
} | |||||
$this->commandes = []; | |||||
$this->recettes = 0; | |||||
$this->recettes_pain = 0; | |||||
$this->recettes_vrac = 0; | |||||
foreach ($commandes as $c) { | |||||
if ($this->id == $c->id_point_vente) { | |||||
$this->commandes[] = $c; | |||||
$this->recettes += (float) $c->montant; | |||||
$this->recettes_pain += (float) $c->montant_pain; | |||||
$this->recettes_vrac += (float) $c->montant_vrac; | |||||
} | |||||
} | |||||
} | } | ||||
public function getCommandes() | |||||
{ | |||||
return $this->commandes ; | |||||
public function getCommandes() { | |||||
return $this->commandes; | |||||
} | } | ||||
public function strListeVrac() { | public function strListeVrac() { | ||||
$str = '' ; | |||||
$produits = Produit::find()->orderBy('order ASC')->all() ; | |||||
foreach($produits as $p) { | |||||
if($p->vrac) { | |||||
$quantite = Commande::getQuantiteProduit($p->id, $this->commandes) ; | |||||
if($quantite) { | |||||
$str .= $quantite.' '.Html::encode($p->diminutif).', ' ; | |||||
} | |||||
} | |||||
} | |||||
return substr($str, 0, strlen($str) - 2) ; | |||||
$str = ''; | |||||
$produits = Produit::find()->orderBy('order ASC')->all(); | |||||
foreach ($produits as $p) { | |||||
if ($p->vrac) { | |||||
$quantite = Commande::getQuantiteProduit($p->id, $this->commandes); | |||||
if ($quantite) { | |||||
$str .= $quantite . ' ' . Html::encode($p->diminutif) . ', '; | |||||
} | |||||
} | |||||
} | |||||
return substr($str, 0, strlen($str) - 2); | |||||
} | } | ||||
public function save($runValidation = true, $attributeNames = NULL) | |||||
{ | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$this->pain = 1 ; | |||||
return parent::save($runValidation, $attributeNames) ; | |||||
public function save($runValidation = true, $attributeNames = NULL) { | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
$this->pain = 1; | |||||
return parent::save($runValidation, $attributeNames); | |||||
} | } | ||||
public function gestionPointFabrication() | |||||
{ | |||||
if($this->point_fabrication) | |||||
{ | |||||
public function gestionPointFabrication() { | |||||
if ($this->point_fabrication) { | |||||
PointVente::updateAll( | PointVente::updateAll( | ||||
['point_fabrication' => 0], | |||||
['id_etablissement' => $this->id_etablissement] | |||||
) ; | |||||
$this->point_fabrication = 1 ; | |||||
$this->save() ; | |||||
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] | |||||
); | |||||
$this->point_fabrication = 1; | |||||
$this->save(); | |||||
} | } | ||||
} | } | ||||
public function gestionAccesRestreint() | |||||
{ | |||||
PointVenteUser::deleteAll(['id_point_vente' => $this->id]) ; | |||||
if(is_array($this->users) && count($this->users)) | |||||
{ | |||||
foreach($this->users as $key => $val) | |||||
{ | |||||
$user = User::findOne($val) ; | |||||
if($user) | |||||
{ | |||||
$point_vente_user = new PointVenteUser ; | |||||
$point_vente_user->id_user = $val ; | |||||
$point_vente_user->id_point_vente = $this->id ; | |||||
if(isset($this->users_commentaire[$val]) && strlen($this->users_commentaire[$val])) | |||||
$point_vente_user->commentaire = $this->users_commentaire[$val] ; | |||||
$point_vente_user->save() ; | |||||
public function gestionAccesRestreint() { | |||||
PointVenteUser::deleteAll(['id_point_vente' => $this->id]); | |||||
if (is_array($this->users) && count($this->users)) { | |||||
foreach ($this->users as $key => $val) { | |||||
$user = User::findOne($val); | |||||
if ($user) { | |||||
$point_vente_user = new PointVenteUser; | |||||
$point_vente_user->id_user = $val; | |||||
$point_vente_user->id_point_vente = $this->id; | |||||
if (isset($this->users_commentaire[$val]) && strlen($this->users_commentaire[$val])) | |||||
$point_vente_user->commentaire = $this->users_commentaire[$val]; | |||||
$point_vente_user->save(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function getCommentaire() | |||||
{ | |||||
if(isset($this->pointVenteUser)) | |||||
{ | |||||
foreach($this->pointVenteUser as $pvu) | |||||
{ | |||||
if($pvu->id_user == Yii::$app->user->identity->id) | |||||
{ | |||||
return $pvu->commentaire ; | |||||
public function getCommentaire() { | |||||
if (isset($this->pointVenteUser)) { | |||||
foreach ($this->pointVenteUser as $pvu) { | |||||
if ($pvu->id_user == Yii::$app->user->identity->id) { | |||||
return $pvu->commentaire; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public static function count() | |||||
{ | |||||
public static function count() { | |||||
return PointVente::find() | return PointVente::find() | ||||
->where([ | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->count() ; | |||||
->where([ | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->count(); | |||||
} | } | ||||
public function verifCode($code) | |||||
{ | |||||
if(strlen($this->code)) | |||||
{ | |||||
if(trim(strtolower($code)) == trim(strtolower($this->code))) | |||||
{ | |||||
return true ; | |||||
} | |||||
else { | |||||
return false ; | |||||
public function verifCode($code) { | |||||
if (strlen($this->code)) { | |||||
if (trim(strtolower($code)) == trim(strtolower($this->code))) { | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | } | ||||
} | |||||
else { | |||||
return true ; | |||||
} else { | |||||
return true; | |||||
} | } | ||||
} | } | ||||
} | } |
* @property integer $id_point_vente | * @property integer $id_point_vente | ||||
* @property integer $id_user | * @property integer $id_user | ||||
*/ | */ | ||||
class PointVenteUser extends \yii\db\ActiveRecord | |||||
{ | |||||
class PointVenteUser extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'point_vente_user'; | return 'point_vente_user'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_point_vente', 'id_user'], 'required'], | [['id_point_vente', 'id_user'], 'required'], | ||||
[['id_point_vente', 'id_user'], 'integer'], | [['id_point_vente', 'id_user'], 'integer'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id_point_vente' => 'Id Point Vente', | 'id_point_vente' => 'Id Point Vente', | ||||
'id_user' => 'Id User', | 'id_user' => 'Id User', | ||||
'commentaire' => 'Commentaire' | 'commentaire' => 'Commentaire' | ||||
]; | ]; | ||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\Commande ; | |||||
use common\models\Commande; | |||||
/** | /** | ||||
* This is the model class for table "production". | * This is the model class for table "production". | ||||
* @property string $date | * @property string $date | ||||
* @property integer $actif | * @property integer $actif | ||||
*/ | */ | ||||
class Production extends \yii\db\ActiveRecord | |||||
{ | |||||
class Production extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'production'; | return 'production'; | ||||
} | } | ||||
public function getEtablissement() { | public function getEtablissement() { | ||||
return $this->hasOne(Etablissement::className(), ['id'=>'id_etablissement']) ; | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['date'], 'required'], | [['date'], 'required'], | ||||
[['date'], 'safe'], | [['date'], 'safe'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'date' => 'Date', | 'date' => 'Date', | ||||
'actif' => 'Actif', | 'actif' => 'Actif', | ||||
]; | ]; | ||||
} | } | ||||
public function getCommande() | |||||
{ | |||||
return $this->hasMany(Commande::className(), ['id_production' => 'id']) ; | |||||
public function getCommande() { | |||||
return $this->hasMany(Commande::className(), ['id_production' => 'id']); | |||||
} | } | ||||
public function getProductionProduit() | |||||
{ | |||||
return $this->hasMany(ProductionProduit::className(),['id_production' => 'id']) ; | |||||
public function getProductionProduit() { | |||||
return $this->hasMany(ProductionProduit::className(), ['id_production' => 'id']); | |||||
} | } | ||||
public function produitActif($id_produit) | |||||
{ | |||||
if($id_produit && | |||||
isset($this->productionProduit) && | |||||
count($this->productionProduit) > 0) | |||||
{ | |||||
foreach($this->productionProduit as $production_produit) | |||||
{ | |||||
if($production_produit['id_produit'] == $id_produit && | |||||
$production_produit['actif']) | |||||
{ | |||||
return true ; | |||||
} | |||||
} | |||||
public function produitActif($id_produit) { | |||||
if ($id_produit && | |||||
isset($this->productionProduit) && | |||||
count($this->productionProduit) > 0) { | |||||
foreach ($this->productionProduit as $production_produit) { | |||||
if ($production_produit['id_produit'] == $id_produit && | |||||
$production_produit['actif']) { | |||||
return true; | |||||
} | |||||
} | |||||
} | } | ||||
return false ; | |||||
return false; | |||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\models\PointVente ; | |||||
use common\models\Production ; | |||||
use common\models\PointVente; | |||||
use common\models\Production; | |||||
/** | /** | ||||
* This is the model class for table "production_point_vente". | * This is the model class for table "production_point_vente". | ||||
* @property integer $id_point_vente | * @property integer $id_point_vente | ||||
* @property integer $livraison | * @property integer $livraison | ||||
*/ | */ | ||||
class ProductionPointVente extends \yii\db\ActiveRecord | |||||
{ | |||||
var $productions_point_vente ; | |||||
class ProductionPointVente extends \yii\db\ActiveRecord { | |||||
var $productions_point_vente; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'production_point_vente'; | return 'production_point_vente'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_production', 'id_point_vente'], 'required'], | [['id_production', 'id_point_vente'], 'required'], | ||||
[['id_production', 'id_point_vente', 'livraison'], 'integer'], | [['id_production', 'id_point_vente', 'livraison'], 'integer'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id_production' => 'Id Production', | 'id_production' => 'Id Production', | ||||
'id_point_vente' => 'Id Point Vente', | 'id_point_vente' => 'Id Point Vente', | ||||
'livraison' => 'Livraison', | 'livraison' => 'Livraison', | ||||
]; | ]; | ||||
} | } | ||||
public function getProduction() | |||||
{ | |||||
return $this->hasOne(Production::className(), ['id' => 'id_production']) ; | |||||
public function getProduction() { | |||||
return $this->hasOne(Production::className(), ['id' => 'id_production']); | |||||
} | } | ||||
public function getPointVente() | |||||
{ | |||||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']) ; | |||||
public function getPointVente() { | |||||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); | |||||
} | } | ||||
public static function setAll($id_production, $bool_livraison) | |||||
{ | |||||
public static function setAll($id_production, $bool_livraison) { | |||||
$count_productions_point_vente = self::find()-> | $count_productions_point_vente = self::find()-> | ||||
where([ | where([ | ||||
'id_production' => $id_production | 'id_production' => $id_production | ||||
]) | ]) | ||||
->count() ; | |||||
if(!$count_productions_point_vente) | |||||
{ | |||||
->count(); | |||||
if (!$count_productions_point_vente) { | |||||
$points_vente = PointVente::find() | $points_vente = PointVente::find() | ||||
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | ||||
->all(); | ->all(); | ||||
foreach($points_vente as $pv) | |||||
{ | |||||
$production_pv = new ProductionPointVente() ; | |||||
$production_pv->id_production = $id_production ; | |||||
$production_pv->id_point_vente = $pv->id ; | |||||
$production_pv->save() ; | |||||
foreach ($points_vente as $pv) { | |||||
$production_pv = new ProductionPointVente(); | |||||
$production_pv->id_production = $id_production; | |||||
$production_pv->id_point_vente = $pv->id; | |||||
$production_pv->save(); | |||||
} | } | ||||
} | } | ||||
$production = Production::findOne($id_production) ; | |||||
if($production) | |||||
{ | |||||
$jour = date('N', strtotime($production->date)) ; | |||||
$production = Production::findOne($id_production); | |||||
if ($production) { | |||||
$jour = date('N', strtotime($production->date)); | |||||
$productions_point_vente = self::find() | $productions_point_vente = self::find() | ||||
->with(['production','pointVente']) | |||||
->with(['production', 'pointVente']) | |||||
->where([ | ->where([ | ||||
'id_production' => $id_production | 'id_production' => $id_production | ||||
]) | ]) | ||||
->all() ; | |||||
foreach($productions_point_vente as $production_pv) | |||||
{ | |||||
if($bool_livraison && | |||||
( ($jour == 1 && $production_pv->pointVente->livraison_lundi) || | |||||
($jour == 2 && $production_pv->pointVente->livraison_mardi) || | |||||
($jour == 3 && $production_pv->pointVente->livraison_mercredi) || | |||||
($jour == 4 && $production_pv->pointVente->livraison_jeudi) || | |||||
($jour == 5 && $production_pv->pointVente->livraison_vendredi) || | |||||
($jour == 6 && $production_pv->pointVente->livraison_samedi) || | |||||
($jour == 7 && $production_pv->pointVente->livraison_dimanche) || | |||||
$production_pv->pointVente->point_fabrication | |||||
)) | |||||
{ | |||||
$production_pv->livraison = 1 ; | |||||
} | |||||
else { | |||||
$production_pv->livraison = 0 ; | |||||
->all(); | |||||
foreach ($productions_point_vente as $production_pv) { | |||||
if ($bool_livraison && | |||||
( ($jour == 1 && $production_pv->pointVente->livraison_lundi) || | |||||
($jour == 2 && $production_pv->pointVente->livraison_mardi) || | |||||
($jour == 3 && $production_pv->pointVente->livraison_mercredi) || | |||||
($jour == 4 && $production_pv->pointVente->livraison_jeudi) || | |||||
($jour == 5 && $production_pv->pointVente->livraison_vendredi) || | |||||
($jour == 6 && $production_pv->pointVente->livraison_samedi) || | |||||
($jour == 7 && $production_pv->pointVente->livraison_dimanche) || | |||||
$production_pv->pointVente->point_fabrication | |||||
)) { | |||||
$production_pv->livraison = 1; | |||||
} else { | |||||
$production_pv->livraison = 0; | |||||
} | } | ||||
$production_pv->save() ; | |||||
$production_pv->save(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
namespace common\models; | namespace common\models; | ||||
use yii\base\Object; | use yii\base\Object; | ||||
use Yii; | use Yii; | ||||
/** | /** | ||||
* @property integer $id_produit | * @property integer $id_produit | ||||
* @property integer $actif | * @property integer $actif | ||||
*/ | */ | ||||
class ProductionProduit extends \yii\db\ActiveRecord | |||||
{ | |||||
class ProductionProduit extends \yii\db\ActiveRecord { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'production_produit'; | return 'production_produit'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['id_production', 'id_produit', 'actif','quantite_max'], 'integer'] | |||||
[['id_production', 'id_produit', 'actif', 'quantite_max'], 'integer'] | |||||
]; | ]; | ||||
} | } | ||||
public function getProduit() | |||||
{ | |||||
return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ; | |||||
public function getProduit() { | |||||
return $this->hasOne(Produit::className(), ['id' => 'id_produit']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_production' => 'Id Production', | 'id_production' => 'Id Production', | ||||
'quantite_max' => 'Quantité max', | 'quantite_max' => 'Quantité max', | ||||
]; | ]; | ||||
} | } | ||||
public static function findProduits($id_production) { | public static function findProduits($id_production) { | ||||
$production_produits = ProductionProduit::find() | |||||
$production_produits = ProductionProduit::find() | |||||
->with('produit') | ->with('produit') | ||||
->where(['id_production'=>$id_production]) | |||||
->all() ; | |||||
$arr_production_produits = [] ; | |||||
$commandes = Commande::find() | |||||
->with('commandeProduits','user') | |||||
->joinWith('production') | |||||
->where(['production.id'=> $id_production]) | |||||
->orderBy('date ASC') | |||||
->all() ; | |||||
foreach($production_produits as $pp) | |||||
{ | |||||
if(isset($pp->produit)) | |||||
{ | |||||
->where(['id_production' => $id_production]) | |||||
->all(); | |||||
$arr_production_produits = []; | |||||
$commandes = Commande::find() | |||||
->with('commandeProduits', 'user') | |||||
->joinWith('production') | |||||
->where(['production.id' => $id_production]) | |||||
->orderBy('date ASC') | |||||
->all(); | |||||
foreach ($production_produits as $pp) { | |||||
if (isset($pp->produit)) { | |||||
$arr_production_produits[$pp->id_produit] = [ | $arr_production_produits[$pp->id_produit] = [ | ||||
'actif'=> (int) $pp->actif, | |||||
'actif' => (int) $pp->actif, | |||||
'epuise' => (int) $pp->produit->epuise, | 'epuise' => (int) $pp->produit->epuise, | ||||
'vrac' => (int) $pp->produit->vrac, | 'vrac' => (int) $pp->produit->vrac, | ||||
'quantite_max' => $pp->quantite_max, | 'quantite_max' => $pp->quantite_max, | ||||
'quantite_commandee' => Commande::getQuantiteProduit($pp->id_produit, $commandes), | 'quantite_commandee' => Commande::getQuantiteProduit($pp->id_produit, $commandes), | ||||
'quantite_restante' => $pp->quantite_max - Commande::getQuantiteProduit($pp->id_produit, $commandes) | |||||
] ; | |||||
} | |||||
} | |||||
return $arr_production_produits ; | |||||
'quantite_restante' => $pp->quantite_max - Commande::getQuantiteProduit($pp->id_produit, $commandes) | |||||
]; | |||||
} | |||||
} | |||||
return $arr_production_produits; | |||||
} | } | ||||
} | } |
* @property double $poids | * @property double $poids | ||||
* @property string $recette | * @property string $recette | ||||
*/ | */ | ||||
class Produit extends \yii\db\ActiveRecord | |||||
{ | |||||
var $total = 0 ; | |||||
class Produit extends \yii\db\ActiveRecord { | |||||
var $total = 0; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return 'produit'; | return 'produit'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
[['nom', 'id_etablissement'], 'required'], | [['nom', 'id_etablissement'], 'required'], | ||||
[['actif','order','quantite_max', 'id_etablissement'], 'integer'], | |||||
[['lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche','epuise'], 'boolean'], | |||||
[['actif', 'order', 'quantite_max', 'id_etablissement'], 'integer'], | |||||
[['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'epuise'], 'boolean'], | |||||
[['prix', 'poids'], 'number'], | [['prix', 'poids'], 'number'], | ||||
[['illustration','photo'], 'file'], | |||||
[['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255], | |||||
[['recette'], 'string','max'=>1000], | |||||
[['illustration', 'photo'], 'file'], | |||||
[['nom', 'description', 'illustration', 'photo', 'saison', 'diminutif'], 'string', 'max' => 255], | |||||
[['recette'], 'string', 'max' => 1000], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'nom' => 'Nom', | 'nom' => 'Nom', | ||||
'epuise' => 'Épuisé', | 'epuise' => 'Épuisé', | ||||
]; | ]; | ||||
} | } | ||||
public function getDescription() { | public function getDescription() { | ||||
$description = $this->description ; | |||||
if(isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { | |||||
if($this->poids >= 1000) { | |||||
$description .= ' ('.($this->poids / 1000).'kg)' ; | |||||
} | |||||
else { | |||||
$description .= ' ('.$this->poids.'g)' ; | |||||
} | |||||
} | |||||
return $description ; | |||||
$description = $this->description; | |||||
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { | |||||
if ($this->poids >= 1000) { | |||||
$description .= ' (' . ($this->poids / 1000) . 'kg)'; | |||||
} else { | |||||
$description .= ' (' . $this->poids . 'g)'; | |||||
} | |||||
} | |||||
return $description; | |||||
} | } | ||||
public function getLibelleAdmin() | |||||
{ | |||||
return $this->nom ; | |||||
public function getLibelleAdmin() { | |||||
return $this->nom; | |||||
} | } | ||||
public function save($runValidation = true, $attributeNames = NULL) | |||||
{ | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
return parent::save($runValidation, $attributeNames) ; | |||||
public function save($runValidation = true, $attributeNames = NULL) { | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
return parent::save($runValidation, $attributeNames); | |||||
} | } | ||||
public function getAll() | |||||
{ | |||||
public function getAll() { | |||||
return Produit::find() | return Produit::find() | ||||
->where([ | ->where([ | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | 'id_etablissement' => Yii::$app->user->identity->id_etablissement, | ||||
]) | |||||
]) | |||||
->orderBy('order ASC') | ->orderBy('order ASC') | ||||
->all(); | ->all(); | ||||
} | } | ||||
public function getByProduction($id_production) | |||||
{ | |||||
public function getByProduction($id_production) { | |||||
return Produit::find() | return Produit::find() | ||||
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | ->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | ||||
->where([ | ->where([ | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | 'id_etablissement' => Yii::$app->user->identity->id_etablissement, | ||||
'production_produit.id_production' => $id_production | 'production_produit.id_production' => $id_production | ||||
]) | |||||
]) | |||||
->orderBy('production_produit.actif DESC, produit.order ASC') | ->orderBy('production_produit.actif DESC, produit.order ASC') | ||||
->all(); | ->all(); | ||||
} | } | ||||
public static function count() | |||||
{ | |||||
public static function count() { | |||||
return Produit::find() | return Produit::find() | ||||
->where([ | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->count() ; | |||||
->where([ | |||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
]) | |||||
->count(); | |||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
* @property string $password write-only password | * @property string $password write-only password | ||||
* @property boolean $confiance | * @property boolean $confiance | ||||
*/ | */ | ||||
class User extends ActiveRecord implements IdentityInterface | |||||
{ | |||||
class User extends ActiveRecord implements IdentityInterface { | |||||
const STATUS_DELETED = 0; | const STATUS_DELETED = 0; | ||||
const STATUS_ACTIVE = 10; | const STATUS_ACTIVE = 10; | ||||
const STATUS_BOULANGER = 11; | const STATUS_BOULANGER = 11; | ||||
const STATUS_ADMIN = 13; | const STATUS_ADMIN = 13; | ||||
var $password_old ; | |||||
var $password_new ; | |||||
var $password_new_confirm ; | |||||
var $password_old; | |||||
var $password_new; | |||||
var $password_new_confirm; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
{ | |||||
public static function tableName() { | |||||
return '{{%user}}'; | return '{{%user}}'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
TimestampBehavior::className(), | TimestampBehavior::className(), | ||||
]; | ]; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['confiance','default','value'=>1], | |||||
[['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'], | |||||
[['nom','prenom','telephone','adresse'], 'string'], | |||||
[['nom','prenom'],'required','message'=> 'Ce champs ne peut être vide'], | |||||
['email','email','message'=> 'Cette adresse email n\'est pas valide'], | |||||
['email','verifyEmail'], | |||||
['status', 'default', 'value' => self::STATUS_ACTIVE], | |||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN,self::STATUS_BOULANGER ]], | |||||
['password_old','verifyPasswordOld'], | |||||
['password_new','verifyPasswordNew'], | |||||
['password_new_confirm','verifyPasswordNewConfirm'], | |||||
[['date_derniere_connexion','password_old','password_new','password_new_confirm','password_hash'],'safe'], | |||||
['confiance', 'default', 'value' => 1], | |||||
[['no_mail', 'mail_prod_lundi', 'mail_prod_mardi', 'mail_prod_mercredi', 'mail_prod_jeudi', 'mail_prod_vendredi', 'mail_prod_samedi', 'mail_prod_dimanche'], 'boolean'], | |||||
[['nom', 'prenom', 'telephone', 'adresse'], 'string'], | |||||
[['nom', 'prenom'], 'required', 'message' => 'Ce champs ne peut être vide'], | |||||
['email', 'email', 'message' => 'Cette adresse email n\'est pas valide'], | |||||
['email', 'verifyEmail'], | |||||
['status', 'default', 'value' => self::STATUS_ACTIVE], | |||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN, self::STATUS_BOULANGER]], | |||||
['password_old', 'verifyPasswordOld'], | |||||
['password_new', 'verifyPasswordNew'], | |||||
['password_new_confirm', 'verifyPasswordNewConfirm'], | |||||
[['date_derniere_connexion', 'password_old', 'password_new', 'password_new_confirm', 'password_hash'], 'safe'], | |||||
]; | ]; | ||||
} | } | ||||
public function verifyPasswordOld($attribute,$params) | |||||
{ | |||||
if(strlen($this->password_old)) | |||||
{ | |||||
if(!$this->validatePassword($this->password_old)) | |||||
{ | |||||
$this->addError($attribute, 'Mot de passe invalide.') ; | |||||
public function verifyPasswordOld($attribute, $params) { | |||||
if (strlen($this->password_old)) { | |||||
if (!$this->validatePassword($this->password_old)) { | |||||
$this->addError($attribute, 'Mot de passe invalide.'); | |||||
} | } | ||||
} | } | ||||
if(!strlen($this->password_old) && (strlen($this->password_new) || strlen($this->password_new_confirm))) | |||||
{ | |||||
$this->addError($attribute, 'Ce champs ne peut être vide') ; | |||||
if (!strlen($this->password_old) && (strlen($this->password_new) || strlen($this->password_new_confirm))) { | |||||
$this->addError($attribute, 'Ce champs ne peut être vide'); | |||||
} | } | ||||
if(!strlen($this->password_new) && (strlen($this->password_old) || strlen($this->password_new_confirm))) | |||||
{ | |||||
$this->addError('password_new', 'Ce champs ne peut être vide') ; | |||||
if (!strlen($this->password_new) && (strlen($this->password_old) || strlen($this->password_new_confirm))) { | |||||
$this->addError('password_new', 'Ce champs ne peut être vide'); | |||||
} | } | ||||
if(!strlen($this->password_new_confirm) && (strlen($this->password_old) || strlen($this->password_new))) | |||||
{ | |||||
$this->addError('password_new_confirm', 'Ce champs ne peut être vide') ; | |||||
if (!strlen($this->password_new_confirm) && (strlen($this->password_old) || strlen($this->password_new))) { | |||||
$this->addError('password_new_confirm', 'Ce champs ne peut être vide'); | |||||
} | } | ||||
} | } | ||||
public function verifyPasswordNew($attribute,$params) | |||||
{ | |||||
if(strlen($this->password_new) < 6) | |||||
{ | |||||
$this->addError($attribute, 'Votre mot de passe doit comporter au moins 6 caractères.') ; | |||||
public function verifyPasswordNew($attribute, $params) { | |||||
if (strlen($this->password_new) < 6) { | |||||
$this->addError($attribute, 'Votre mot de passe doit comporter au moins 6 caractères.'); | |||||
} | } | ||||
} | } | ||||
public function verifyPasswordNewConfirm($attribute,$params) | |||||
{ | |||||
if($this->password_new != $this->password_new_confirm) | |||||
{ | |||||
$this->addError($attribute, 'Les deux mots de passe doivent être identiques') ; | |||||
public function verifyPasswordNewConfirm($attribute, $params) { | |||||
if ($this->password_new != $this->password_new_confirm) { | |||||
$this->addError($attribute, 'Les deux mots de passe doivent être identiques'); | |||||
} | } | ||||
} | } | ||||
public function verifyEmail($attribute,$params) { | |||||
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email'=>'%'.$this->email.'%', ':id'=>$this->id))->one() ; | |||||
if($user) | |||||
public function verifyEmail($attribute, $params) { | |||||
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id))->one(); | |||||
if ($user) | |||||
$this->addError($attribute, 'Cette adresse email est déjà utilisée par un autre utilisateur '); | $this->addError($attribute, 'Cette adresse email est déjà utilisée par un autre utilisateur '); | ||||
} | } | ||||
public function getUserEtablissement() { | public function getUserEtablissement() { | ||||
return $this->hasMany(UserEtablissement::className(), ['id_user'=>'id']) ; | |||||
return $this->hasMany(UserEtablissement::className(), ['id_user' => 'id']); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function findIdentity($id) | |||||
{ | |||||
return static::findOne(['id' => $id/*, 'status' => self::STATUS_ACTIVE*/]); | |||||
public static function findIdentity($id) { | |||||
return static::findOne(['id' => $id/* , 'status' => self::STATUS_ACTIVE */]); | |||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function findIdentityByAccessToken($token, $type = null) | |||||
{ | |||||
public static function findIdentityByAccessToken($token, $type = null) { | |||||
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | ||||
} | } | ||||
* @param string $username | * @param string $username | ||||
* @return static|null | * @return static|null | ||||
*/ | */ | ||||
public static function findByUsername($username) | |||||
{ | |||||
return static::findOne(['username' => $username/*, 'status' => self::STATUS_ACTIVE*/]); | |||||
public static function findByUsername($username) { | |||||
return static::findOne(['username' => $username/* , 'status' => self::STATUS_ACTIVE */]); | |||||
} | } | ||||
public static function findByEmail($email) | |||||
{ | |||||
return static::findOne(['email' => $email /*, 'status' => self::STATUS_ACTIVE*/]); | |||||
public static function findByEmail($email) { | |||||
return static::findOne(['email' => $email /* , 'status' => self::STATUS_ACTIVE */]); | |||||
} | } | ||||
/** | /** | ||||
* @param string $token password reset token | * @param string $token password reset token | ||||
* @return static|null | * @return static|null | ||||
*/ | */ | ||||
public static function findByPasswordResetToken($token) | |||||
{ | |||||
public static function findByPasswordResetToken($token) { | |||||
if (!static::isPasswordResetTokenValid($token)) { | if (!static::isPasswordResetTokenValid($token)) { | ||||
return null; | return null; | ||||
} | } | ||||
return static::findOne([ | return static::findOne([ | ||||
'password_reset_token' => $token, | |||||
'password_reset_token' => $token, | |||||
]); | ]); | ||||
} | } | ||||
public static function findBy($params = []) | |||||
{ | |||||
if(!isset($params['id_etablissement'])) | |||||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement ; | |||||
public static function findBy($params = []) { | |||||
if (!isset($params['id_etablissement'])) | |||||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; | |||||
$query = (new \yii\db\Query()) | $query = (new \yii\db\Query()) | ||||
->select(['user.id AS user_id', 'user.prenom','user.nom','user.telephone','user.email','user.created_at','user.date_derniere_connexion','user_etablissement.*']) | |||||
->select(['user.id AS user_id', 'user.prenom', 'user.nom', 'user.telephone', 'user.email', 'user.created_at', 'user.date_derniere_connexion', 'user_etablissement.*']) | |||||
->from('user, user_etablissement') | ->from('user, user_etablissement') | ||||
->where('user.id = user_etablissement.id_user') | ->where('user.id = user_etablissement.id_user') | ||||
->andWhere('user_etablissement.actif = 1') | ->andWhere('user_etablissement.actif = 1') | ||||
->andWhere('user_etablissement.id_etablissement = '.$params['id_etablissement']) ; | |||||
if(isset($params['nom'])) | |||||
->andWhere('user_etablissement.id_etablissement = ' . $params['id_etablissement']); | |||||
if (isset($params['nom'])) | |||||
$query->andFilterWhere(['like', 'nom', $params['nom']]); | $query->andFilterWhere(['like', 'nom', $params['nom']]); | ||||
if(isset($params['prenom'])) | |||||
$query->andFilterWhere(['like', 'prenom', $params['prenom']]) ; | |||||
if(isset($params['email'])) | |||||
$query->andFilterWhere(['like', 'email', $params['email']]) ; | |||||
if(isset($params['telephone'])) | |||||
$query->andFilterWhere(['like', 'telephone', $params['telephone']]) ; | |||||
return $query ; | |||||
if (isset($params['prenom'])) | |||||
$query->andFilterWhere(['like', 'prenom', $params['prenom']]); | |||||
if (isset($params['email'])) | |||||
$query->andFilterWhere(['like', 'email', $params['email']]); | |||||
if (isset($params['telephone'])) | |||||
$query->andFilterWhere(['like', 'telephone', $params['telephone']]); | |||||
return $query; | |||||
} | } | ||||
/** | /** | ||||
* @param string $token password reset token | * @param string $token password reset token | ||||
* @return boolean | * @return boolean | ||||
*/ | */ | ||||
public static function isPasswordResetTokenValid($token) | |||||
{ | |||||
public static function isPasswordResetTokenValid($token) { | |||||
if (empty($token)) { | if (empty($token)) { | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function getId() | |||||
{ | |||||
public function getId() { | |||||
return $this->getPrimaryKey(); | return $this->getPrimaryKey(); | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function getAuthKey() | |||||
{ | |||||
public function getAuthKey() { | |||||
return $this->auth_key; | return $this->auth_key; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function validateAuthKey($authKey) | |||||
{ | |||||
public function validateAuthKey($authKey) { | |||||
return $this->getAuthKey() === $authKey; | return $this->getAuthKey() === $authKey; | ||||
} | } | ||||
* @param string $password password to validate | * @param string $password password to validate | ||||
* @return boolean if password provided is valid for current user | * @return boolean if password provided is valid for current user | ||||
*/ | */ | ||||
public function validatePassword($password) | |||||
{ | |||||
public function validatePassword($password) { | |||||
return Yii::$app->security->validatePassword($password, $this->password_hash); | return Yii::$app->security->validatePassword($password, $this->password_hash); | ||||
} | } | ||||
* | * | ||||
* @param string $password | * @param string $password | ||||
*/ | */ | ||||
public function setPassword($password) | |||||
{ | |||||
public function setPassword($password) { | |||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password); | $this->password_hash = Yii::$app->security->generatePasswordHash($password); | ||||
} | } | ||||
/** | /** | ||||
* Generates "remember me" authentication key | * Generates "remember me" authentication key | ||||
*/ | */ | ||||
public function generateAuthKey() | |||||
{ | |||||
public function generateAuthKey() { | |||||
$this->auth_key = Yii::$app->security->generateRandomString(); | $this->auth_key = Yii::$app->security->generateRandomString(); | ||||
} | } | ||||
/** | /** | ||||
* Generates new password reset token | * Generates new password reset token | ||||
*/ | */ | ||||
public function generatePasswordResetToken() | |||||
{ | |||||
public function generatePasswordResetToken() { | |||||
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | ||||
} | } | ||||
/** | /** | ||||
* Removes password reset token | * Removes password reset token | ||||
*/ | */ | ||||
public function removePasswordResetToken() | |||||
{ | |||||
public function removePasswordResetToken() { | |||||
$this->password_reset_token = null; | $this->password_reset_token = null; | ||||
} | } | ||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'confiance' => 'De confiance', | |||||
'no_mail' => 'Ne pas recevoir d\'email de la part du Chat des Noisettes', | |||||
'mail_prod_lundi' => 'Lundi', | |||||
'mail_prod_mardi' => 'Mardi', | |||||
'mail_prod_mercredi' => 'Mercredi', | |||||
'mail_prod_jeudi' => 'Jeudi', | |||||
'mail_prod_vendredi' => 'Vendredi', | |||||
'mail_prod_samedi' => 'Samedi', | |||||
'mail_prod_dimanche' => 'Dimanche', | |||||
'password_old' => 'Ancien mot de passe', | |||||
'password_new' => 'Nouveau mot de passe', | |||||
'password_new_confirm' => 'Confirmation du nouveau mot de passe', | |||||
'prix_libre' => 'Prix libre', | |||||
]; | |||||
public function attributeLabels() { | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'confiance' => 'De confiance', | |||||
'no_mail' => 'Ne pas recevoir d\'email de la part du Chat des Noisettes', | |||||
'mail_prod_lundi' => 'Lundi', | |||||
'mail_prod_mardi' => 'Mardi', | |||||
'mail_prod_mercredi' => 'Mercredi', | |||||
'mail_prod_jeudi' => 'Jeudi', | |||||
'mail_prod_vendredi' => 'Vendredi', | |||||
'mail_prod_samedi' => 'Samedi', | |||||
'mail_prod_dimanche' => 'Dimanche', | |||||
'password_old' => 'Ancien mot de passe', | |||||
'password_new' => 'Nouveau mot de passe', | |||||
'password_new_confirm' => 'Confirmation du nouveau mot de passe', | |||||
'prix_libre' => 'Prix libre', | |||||
]; | |||||
} | } | ||||
public function isBoulanger() | |||||
{ | |||||
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_BOULANGER) && $this->id_etablissement ; | |||||
} | |||||
public function getNomMagasin() | |||||
{ | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
return $etablissement->nom ; | |||||
public function isBoulanger() { | |||||
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_BOULANGER) && $this->id_etablissement; | |||||
} | } | ||||
public function getEtablissementsFavoris() | |||||
{ | |||||
public function getNomMagasin() { | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
return $etablissement->nom; | |||||
} | |||||
public function getEtablissementsFavoris() { | |||||
$etabs = (new \yii\db\Query()) | $etabs = (new \yii\db\Query()) | ||||
->select('*') | |||||
->from(['user_etablissement', 'etablissement']) | |||||
->where('user_etablissement.id_etablissement = etablissement.id') | |||||
->andWhere(['user_etablissement.id_user' => $this->id]) | |||||
->andWhere(['user_etablissement.actif' => 1]) | |||||
->all(); | |||||
return $etabs ; | |||||
->select('*') | |||||
->from(['user_etablissement', 'etablissement']) | |||||
->where('user_etablissement.id_etablissement = etablissement.id') | |||||
->andWhere(['user_etablissement.id_user' => $this->id]) | |||||
->andWhere(['user_etablissement.actif' => 1]) | |||||
->all(); | |||||
return $etabs; | |||||
} | } | ||||
public function etatPaiementEtablissement() | |||||
{ | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
return $etablissement->etatPaiement() ; | |||||
public function etatPaiementEtablissement() { | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement) { | |||||
return $etablissement->etatPaiement(); | |||||
} | } | ||||
} | } | ||||
public function periodeEssai() | |||||
{ | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
$date_limite = strtotime($etablissement->date_creation) + 30*24*60*60 ; | |||||
$date = time() ; | |||||
if($date < $date_limite) | |||||
{ | |||||
$date = $date_limite - $date ; | |||||
return (int) ($date / (24*60*60)) ; | |||||
} | |||||
else { | |||||
return 0 ; | |||||
public function periodeEssai() { | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement) { | |||||
$date_limite = strtotime($etablissement->date_creation) + 30 * 24 * 60 * 60; | |||||
$date = time(); | |||||
if ($date < $date_limite) { | |||||
$date = $date_limite - $date; | |||||
return (int) ($date / (24 * 60 * 60)); | |||||
} else { | |||||
return 0; | |||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
public function getCredit($id_etablissement) | |||||
{ | |||||
public function getCredit($id_etablissement) { | |||||
$user_etablissement = UserEtablissement::find() | $user_etablissement = UserEtablissement::find() | ||||
->where([ | ->where([ | ||||
'id_user' => $this->id, | 'id_user' => $this->id, | ||||
'id_etablissement' => $id_etablissement | 'id_etablissement' => $id_etablissement | ||||
]) | ]) | ||||
->one() ; | |||||
if($user_etablissement) | |||||
{ | |||||
return $user_etablissement->credit ; | |||||
->one(); | |||||
if ($user_etablissement) { | |||||
return $user_etablissement->credit; | |||||
} | } | ||||
return 0 ; | |||||
return 0; | |||||
} | } | ||||
public function updateDerniereConnexion() { | public function updateDerniereConnexion() { | ||||
$this->date_derniere_connexion = date('Y-m-d H:i:s') ; | |||||
$this->save() ; | |||||
$this->date_derniere_connexion = date('Y-m-d H:i:s'); | |||||
$this->save(); | |||||
} | } | ||||
} | } |
<?php | |||||
namespace common\models; | |||||
use Yii; | |||||
use yii\helpers\Html ; | |||||
/** | |||||
* This is the model class for table "user_boulangerie". | |||||
* | |||||
* @property integer $id | |||||
* @property integer $id_user | |||||
* @property integer $id_boulangerie | |||||
*/ | |||||
class UserBoulangerie extends \yii\db\ActiveRecord | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'user_boulangerie'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['id_user', 'id_etablissement'], 'required'], | |||||
[['id_user', 'id_etablissement'], 'integer'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
]; | |||||
} | |||||
} |
[['id_user', 'id_etablissement'], 'required'], | [['id_user', 'id_etablissement'], 'required'], | ||||
[['id_user', 'id_etablissement'], 'integer'], | [['id_user', 'id_etablissement'], 'integer'], | ||||
[['actif'], 'boolean'], | [['actif'], 'boolean'], | ||||
[['credit'],'double'], | |||||
[['credit'], 'double'], | |||||
]; | ]; | ||||
} | } | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use frontend\models\AddEtablissementForm; | use frontend\models\AddEtablissementForm; | ||||
use common\models\UserEtablissement; | use common\models\UserEtablissement; | ||||
use common\models\CreditHistorique ; | |||||
use yii\web\NotFoundHttpException ; | |||||
use common\models\ProductionPointVente ; | |||||
use yii\base\UserException ; | |||||
use common\models\CreditHistorique; | |||||
use yii\web\NotFoundHttpException; | |||||
use common\models\ProductionPointVente; | |||||
use yii\base\UserException; | |||||
use frontend\controllers\FrontendController; | use frontend\controllers\FrontendController; | ||||
class CommandeController extends FrontendController { | class CommandeController extends FrontendController { | ||||
$production = Production::findOne($id_production); | $production = Production::findOne($id_production); | ||||
if ($production) { | if ($production) { | ||||
$arr = [] ; | |||||
$arr = []; | |||||
$produits_dispos = ProductionProduit::findProduits($production->id); | $produits_dispos = ProductionProduit::findProduits($production->id); | ||||
$arr['produits_dispos'] = $produits_dispos ; | |||||
$arr['produits_dispos'] = $produits_dispos; | |||||
$points_vente = PointVente::find() | $points_vente = PointVente::find() | ||||
->joinWith(['productionPointVente'=> function($q) use ($production) { | |||||
$q->where(['id_production' => $production->id]) ; | |||||
} ]) | |||||
->joinWith(['productionPointVente' => function($q) use ($production) { | |||||
$q->where(['id_production' => $production->id]); | |||||
}]) | |||||
->where([ | ->where([ | ||||
'id_etablissement' => $production->id_etablissement, | 'id_etablissement' => $production->id_etablissement, | ||||
]) | ]) | ||||
->all(); | ->all(); | ||||
$arr['points_vente'] = [] ; | |||||
foreach($points_vente as $pv) | |||||
{ | |||||
if(isset($pv->productionPointVente) && | |||||
isset($pv->productionPointVente[0])) | |||||
{ | |||||
$arr['points_vente'][$pv->id] = $pv->productionPointVente[0]->livraison ; | |||||
} | |||||
else { | |||||
$arr['points_vente'][$pv->id] = false ; | |||||
$arr['points_vente'] = []; | |||||
foreach ($points_vente as $pv) { | |||||
if (isset($pv->productionPointVente) && | |||||
isset($pv->productionPointVente[0])) { | |||||
$arr['points_vente'][$pv->id] = $pv->productionPointVente[0]->livraison; | |||||
} else { | |||||
$arr['points_vente'][$pv->id] = false; | |||||
} | } | ||||
} | } | ||||
public static function initForm($commande = null) { | public static function initForm($commande = null) { | ||||
// etablissements | // etablissements | ||||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris() ; | |||||
$id_etablissement = Yii::$app->request->get('id_etablissement', 0) ; | |||||
$etablissement_paiement_ok = false ; | |||||
if($id_etablissement) | |||||
{ | |||||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | |||||
$id_etablissement = Yii::$app->request->get('id_etablissement', 0); | |||||
$etablissement_paiement_ok = false; | |||||
if ($id_etablissement) { | |||||
$etablissement = Etablissement::findOne($id_etablissement); | $etablissement = Etablissement::findOne($id_etablissement); | ||||
if($etablissement->etatPaiement() == Etablissement::PAIEMENT_OK || $etablissement->etatPaiement() == Etablissement::PAIEMENT_ESSAI) | |||||
{ | |||||
$etablissement_paiement_ok = true ; | |||||
if ($etablissement->etatPaiement() == Etablissement::PAIEMENT_OK || $etablissement->etatPaiement() == Etablissement::PAIEMENT_ESSAI) { | |||||
$etablissement_paiement_ok = true; | |||||
} | } | ||||
} | } | ||||
// etablissement | // etablissement | ||||
$etablissement = Etablissement::findOne($id_etablissement) ; | |||||
$etablissement = Etablissement::findOne($id_etablissement); | |||||
// points de vente | // points de vente | ||||
$points_vente = PointVente::find() | $points_vente = PointVente::find() | ||||
->with('pointVenteUser') | ->with('pointVenteUser') | ||||
->where(['id_etablissement'=>$id_etablissement]) | |||||
->where(['id_etablissement' => $id_etablissement]) | |||||
->andWhere('acces_restreint = 0 OR (acces_restreint = 1 AND (SELECT COUNT(*) FROM point_vente_user WHERE point_vente.id = point_vente_user.id_point_vente AND point_vente_user.id_user = :id_user) > 0)') | ->andWhere('acces_restreint = 0 OR (acces_restreint = 1 AND (SELECT COUNT(*) FROM point_vente_user WHERE point_vente.id = point_vente_user.id_point_vente AND point_vente_user.id_user = :id_user) > 0)') | ||||
->params([':id_user' => Yii::$app->user->identity->id]) | ->params([':id_user' => Yii::$app->user->identity->id]) | ||||
->all(); | ->all(); | ||||
$arr_points_vente = $points_vente; | $arr_points_vente = $points_vente; | ||||
// jours de production | // jours de production | ||||
$heure_limite = 20 ; | |||||
$date = date('Y-m-d') ; | |||||
if(isset($etablissement)) | |||||
{ | |||||
$heure_limite = $etablissement->heure_limite_commande ; | |||||
$heure_limite = 20; | |||||
$date = date('Y-m-d'); | |||||
if (isset($etablissement)) { | |||||
$heure_limite = $etablissement->heure_limite_commande; | |||||
if (date('H') >= $heure_limite) { | if (date('H') >= $heure_limite) { | ||||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande)*(24*60*60) ); | |||||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande) * (24 * 60 * 60)); | |||||
} else { | } else { | ||||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande - 1)*(24*60*60)); | |||||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande - 1) * (24 * 60 * 60)); | |||||
} | } | ||||
} | } | ||||
$jours_production = Production::find() | $jours_production = Production::find() | ||||
->where(['actif' => 1]) | ->where(['actif' => 1]) | ||||
->andWhere('date > :date') | ->andWhere('date > :date') | ||||
->andWhere(['id_etablissement'=>$id_etablissement]) | |||||
->andWhere(['id_etablissement' => $id_etablissement]) | |||||
->addParams([':date' => $date]) | ->addParams([':date' => $date]) | ||||
->all(); | ->all(); | ||||
// produits | // produits | ||||
$produits = Produit::find() | $produits = Produit::find() | ||||
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | |||||
->where(['produit.actif' => 1, 'id_etablissement' => $id_etablissement]) | |||||
->andWhere('produit.vrac IS NULL OR produit.vrac = 0') | |||||
->orderBy('produit.order ASC')->all(); | |||||
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | |||||
->where(['produit.actif' => 1, 'id_etablissement' => $id_etablissement]) | |||||
->andWhere('produit.vrac IS NULL OR produit.vrac = 0') | |||||
->orderBy('produit.order ASC')->all(); | |||||
$arr_produits = array(); | $arr_produits = array(); | ||||
foreach ($produits as $p) | foreach ($produits as $p) | ||||
$arr_produits[] = $p; | $arr_produits[] = $p; | ||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->where(['id_user' => Yii::$app->user->identity->id]) | ->where(['id_user' => Yii::$app->user->identity->id]) | ||||
->all(); | ->all(); | ||||
if($id_etablissement) | |||||
{ | |||||
if ($id_etablissement) { | |||||
$user_etablissement = UserEtablissement::find() | $user_etablissement = UserEtablissement::find() | ||||
->where([ | |||||
'id_etablissement' => $id_etablissement, | |||||
'id_user' => Yii::$app->user->identity->id | |||||
]) | |||||
->one() ; | |||||
$credit = $user_etablissement->credit ; | |||||
} | |||||
else { | |||||
$credit = 0 ; | |||||
->where([ | |||||
'id_etablissement' => $id_etablissement, | |||||
'id_user' => Yii::$app->user->identity->id | |||||
]) | |||||
->one(); | |||||
$credit = $user_etablissement->credit; | |||||
} else { | |||||
$credit = 0; | |||||
} | } | ||||
return [ | return [ | ||||
'points_vente' => $arr_points_vente, | 'points_vente' => $arr_points_vente, | ||||
'jours_production' => $arr_jours_production, | 'jours_production' => $arr_jours_production, | ||||
public function actionIndex() { | public function actionIndex() { | ||||
$model_form_etablissement = new AddEtablissementForm() ; | |||||
if($model_form_etablissement->load(Yii::$app->request->post()) | |||||
&& $model_form_etablissement->validate()) | |||||
{ | |||||
$model_form_etablissement->add() ; | |||||
$model_form_etablissement->code = '' ; | |||||
$model_form_etablissement = new AddEtablissementForm(); | |||||
if ($model_form_etablissement->load(Yii::$app->request->post()) && $model_form_etablissement->validate()) { | |||||
$model_form_etablissement->add(); | |||||
$model_form_etablissement->code = ''; | |||||
} | } | ||||
// liste des etablissements | // liste des etablissements | ||||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | $etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | ||||
// liste des établissement disponibles | // liste des établissement disponibles | ||||
$arr_etablissements = Etablissement::getEtablissementsPopulateDropdown() ; | |||||
$data_etablissements_dispos = $arr_etablissements['data'] ; | |||||
$options_etablissements_dispos = $arr_etablissements['options'] ; | |||||
$arr_etablissements = Etablissement::getEtablissementsPopulateDropdown(); | |||||
$data_etablissements_dispos = $arr_etablissements['data']; | |||||
$options_etablissements_dispos = $arr_etablissements['options']; | |||||
// liste des commandes | // liste des commandes | ||||
$commandes = Commande::find() | $commandes = Commande::find() | ||||
->with('commandeProduits', 'pointVente', 'creditHistorique') | ->with('commandeProduits', 'pointVente', 'creditHistorique') | ||||
->joinWith('production','production.etablissement') | |||||
->joinWith('production', 'production.etablissement') | |||||
->where(['id_user' => Yii::$app->user->id]) | ->where(['id_user' => Yii::$app->user->id]) | ||||
//->andWhere('production.date < '.) | //->andWhere('production.date < '.) | ||||
->orderBy('production.date DESC') | ->orderBy('production.date DESC') | ||||
// initilisation commandes | // initilisation commandes | ||||
foreach ($commandes as $c) | foreach ($commandes as $c) | ||||
$c->init(); | $c->init(); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'commandes' => $commandes, | |||||
'commande_ok' => Yii::$app->getRequest()->get('commande_ok', false), | |||||
'annule_ok' => Yii::$app->getRequest()->get('annule_ok', false), | |||||
'pate_deja_petrie' => Yii::$app->getRequest()->get('pate_deja_petrie', false), | |||||
'etablissements' => $etablissements, | |||||
'model_form_etablissement' => $model_form_etablissement, | |||||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||||
'commandes' => $commandes, | |||||
'commande_ok' => Yii::$app->getRequest()->get('commande_ok', false), | |||||
'annule_ok' => Yii::$app->getRequest()->get('annule_ok', false), | |||||
'pate_deja_petrie' => Yii::$app->getRequest()->get('pate_deja_petrie', false), | |||||
'etablissements' => $etablissements, | |||||
'model_form_etablissement' => $model_form_etablissement, | |||||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||||
]); | ]); | ||||
} | } | ||||
public function actionRemoveEtablissement($id = 0) | |||||
{ | |||||
public function actionRemoveEtablissement($id = 0) { | |||||
$user_etablissement = UserEtablissement::find() | $user_etablissement = UserEtablissement::find() | ||||
->where(['id_etablissement'=>$id, 'id_user' => Yii::$app->user->identity->id]) | |||||
->one() ; | |||||
$user_etablissement->actif = 0 ; | |||||
$user_etablissement->save() ; | |||||
$this->redirect(['commande/index']) ; | |||||
->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id]) | |||||
->one(); | |||||
$user_etablissement->actif = 0; | |||||
$user_etablissement->save(); | |||||
$this->redirect(['commande/index']); | |||||
} | } | ||||
public function actionCreate($id_etablissement = 0) { | public function actionCreate($id_etablissement = 0) { | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
if($id_etablissement) | |||||
$this->_verifEtablissementActif($id_etablissement) ; | |||||
if ($id_etablissement) | |||||
$this->_verifEtablissementActif($id_etablissement); | |||||
if ($commande->load($posts)) { | if ($commande->load($posts)) { | ||||
$commande = Commande::find()->where('id_production = ' . $posts['Commande']['id_production'])->andWhere('id_user = ' . Yii::$app->user->id)->one(); | $commande = Commande::find()->where('id_production = ' . $posts['Commande']['id_production'])->andWhere('id_user = ' . Yii::$app->user->id)->one(); | ||||
$commande->load(Yii::$app->request->post()); | $commande->load(Yii::$app->request->post()); | ||||
$commande->id_user = Yii::$app->user->id; | $commande->id_user = Yii::$app->user->id; | ||||
$commande->date = date('Y-m-d H:i:s'); | $commande->date = date('Y-m-d H:i:s'); | ||||
$commande->type = Commande::TYPE_USER ; | |||||
$commande->type = Commande::TYPE_USER; | |||||
} | } | ||||
$this->gestionForm($commande); | $this->gestionForm($commande); | ||||
} | } | ||||
return $this->render('create', array_merge(self::initForm($commande), [ | return $this->render('create', array_merge(self::initForm($commande), [ | ||||
'model' => $commande | |||||
'model' => $commande | |||||
])); | ])); | ||||
} | } | ||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
->one(); | ->one(); | ||||
if($commande->getEtat() != Commande::ETAT_MODIFIABLE) | |||||
{ | |||||
throw new UserException('Cette commande n\'est pas modifiable.') ; | |||||
if ($commande->getEtat() != Commande::ETAT_MODIFIABLE) { | |||||
throw new UserException('Cette commande n\'est pas modifiable.'); | |||||
} | } | ||||
$this->_verifEtablissementActif($commande->production->id_etablissement) ; | |||||
if ($commande && $commande->load(Yii::$app->request->post())) | |||||
{ | |||||
$this->_verifEtablissementActif($commande->production->id_etablissement); | |||||
if ($commande && $commande->load(Yii::$app->request->post())) { | |||||
$commande->date_update = date('Y-m-d H:i:s'); | $commande->date_update = date('Y-m-d H:i:s'); | ||||
$this->gestionForm($commande); | $this->gestionForm($commande); | ||||
} | } | ||||
'commande_introuvable' => !$commande, | 'commande_introuvable' => !$commande, | ||||
])); | ])); | ||||
} | } | ||||
public function _verifEtablissementActif($id_etablissement) | |||||
{ | |||||
$etablissement = Etablissement::findOne($id_etablissement) ; | |||||
if($etablissement && !$etablissement->actif) | |||||
{ | |||||
public function _verifEtablissementActif($id_etablissement) { | |||||
$etablissement = Etablissement::findOne($id_etablissement); | |||||
if ($etablissement && !$etablissement->actif) { | |||||
throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); | throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); | ||||
} | } | ||||
} | } | ||||
$err_date = true; | $err_date = true; | ||||
} | } | ||||
} | } | ||||
// point de vente | // point de vente | ||||
$err_point_vente = false ; | |||||
if(isset($production) && $production) | |||||
{ | |||||
$err_point_vente = false; | |||||
if (isset($production) && $production) { | |||||
$ppv = ProductionPointVente::find() | $ppv = ProductionPointVente::find() | ||||
->where([ | ->where([ | ||||
'id_production' => $production->id, | 'id_production' => $production->id, | ||||
'id_point_vente' => $posts['Commande']['id_point_vente'] | 'id_point_vente' => $posts['Commande']['id_point_vente'] | ||||
]) | ]) | ||||
->one() ; | |||||
if(!$ppv || !$ppv->livraison) | |||||
{ | |||||
$err_point_vente = true ; | |||||
->one(); | |||||
if (!$ppv || !$ppv->livraison) { | |||||
$err_point_vente = true; | |||||
} | } | ||||
$point_vente = PointVente::findOne($posts['Commande']['id_point_vente']) ; | |||||
if($point_vente) | |||||
{ | |||||
if(strlen($point_vente->code) && !$point_vente->verifCode($posts['code_point_vente_'.$point_vente->id])) | |||||
{ | |||||
$err_point_vente = true ; | |||||
$point_vente = PointVente::findOne($posts['Commande']['id_point_vente']); | |||||
if ($point_vente) { | |||||
if (strlen($point_vente->code) && !$point_vente->verifCode($posts['code_point_vente_' . $point_vente->id])) { | |||||
$err_point_vente = true; | |||||
} | } | ||||
} | |||||
else { | |||||
$err_point_vente = true ; | |||||
} else { | |||||
$err_point_vente = true; | |||||
} | } | ||||
} | } | ||||
if ($commande->validate() && count($produits) && !$err_nb_produits && !$err_date && !$err_point_vente) { | if ($commande->validate() && count($produits) && !$err_nb_produits && !$err_date && !$err_point_vente) { | ||||
// gestion point de vente | // gestion point de vente | ||||
$pv = PointVente::find() | $pv = PointVente::find() | ||||
->with('pointVenteUser') | ->with('pointVenteUser') | ||||
->where(['id' => $commande->id_point_vente]) | ->where(['id' => $commande->id_point_vente]) | ||||
->one() ; | |||||
if($pv && strlen($pv->getCommentaire())) | |||||
$commande->commentaire_point_vente = $pv->getCommentaire() ; | |||||
->one(); | |||||
if ($pv && strlen($pv->getCommentaire())) | |||||
$commande->commentaire_point_vente = $pv->getCommentaire(); | |||||
else | else | ||||
$commande->commentaire_point_vente = '' ; | |||||
$commande->commentaire_point_vente = ''; | |||||
// sauvegarde de la commande | // sauvegarde de la commande | ||||
$commande->save(); | $commande->save(); | ||||
$quantite_voulue = $produits_dispos[$p->id]['quantite_restante']; | $quantite_voulue = $produits_dispos[$p->id]['quantite_restante']; | ||||
$commande_produit->quantite = $quantite_voulue; | $commande_produit->quantite = $quantite_voulue; | ||||
$commande_produit->save(); | $commande_produit->save(); | ||||
} | } | ||||
} | } | ||||
// credit pain | // credit pain | ||||
$credit_pain = isset($posts['credit_pain']) && $posts['credit_pain'] ; | |||||
if($credit_pain && ($pv->credit_pain || $commande->getMontantPaye())) | |||||
{ | |||||
$credit_pain = isset($posts['credit_pain']) && $posts['credit_pain']; | |||||
if ($credit_pain && ($pv->credit_pain || $commande->getMontantPaye())) { | |||||
$commande = Commande::find() | $commande = Commande::find() | ||||
->with('commandeProduits') | |||||
->where(['id' => $commande->id]) | |||||
->one() ; | |||||
$commande->init() ; | |||||
$montant_paye = $commande->getMontantPaye() ; | |||||
->with('commandeProduits') | |||||
->where(['id' => $commande->id]) | |||||
->one(); | |||||
$commande->init(); | |||||
$montant_paye = $commande->getMontantPaye(); | |||||
// à payer | // à payer | ||||
if($commande->getStatutPaiement() == Commande::STATUT_IMPAYEE) | |||||
{ | |||||
$montant_payer = $commande->montant - $montant_paye ; | |||||
$credit = Yii::$app->user->identity->getCredit($production->id_etablissement) ; | |||||
if($montant_payer > $credit) | |||||
{ | |||||
$montant_payer = $credit ; | |||||
if ($commande->getStatutPaiement() == Commande::STATUT_IMPAYEE) { | |||||
$montant_payer = $commande->montant - $montant_paye; | |||||
$credit = Yii::$app->user->identity->getCredit($production->id_etablissement); | |||||
if ($montant_payer > $credit) { | |||||
$montant_payer = $credit; | |||||
} | } | ||||
if($montant_payer > 0) | |||||
{ | |||||
if ($montant_payer > 0) { | |||||
$commande->creditHistorique( | $commande->creditHistorique( | ||||
CreditHistorique::TYPE_PAIEMENT, | |||||
$montant_payer, | |||||
$production->id_etablissement, | |||||
Yii::$app->user->identity->id | |||||
) ; | |||||
CreditHistorique::TYPE_PAIEMENT, $montant_payer, $production->id_etablissement, Yii::$app->user->identity->id | |||||
); | |||||
} | } | ||||
} | } | ||||
// surplus à rembourser | // surplus à rembourser | ||||
elseif($commande->getStatutPaiement() == Commande::STATUT_SURPLUS) | |||||
{ | |||||
$montant_rembourser = $montant_paye - $commande->montant ; | |||||
elseif ($commande->getStatutPaiement() == Commande::STATUT_SURPLUS) { | |||||
$montant_rembourser = $montant_paye - $commande->montant; | |||||
$commande->creditHistorique( | $commande->creditHistorique( | ||||
CreditHistorique::TYPE_REMBOURSEMENT, | |||||
$montant_rembourser, | |||||
$production->id_etablissement, | |||||
Yii::$app->user->identity->id | |||||
) ; | |||||
} | |||||
CreditHistorique::TYPE_REMBOURSEMENT, $montant_rembourser, $production->id_etablissement, Yii::$app->user->identity->id | |||||
); | |||||
} | |||||
} | } | ||||
// redirection | // redirection | ||||
$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie])); | $this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie])); | ||||
} | |||||
else { | |||||
} else { | |||||
if (!count($produits)) | if (!count($produits)) | ||||
Yii::$app->session->setFlash('error', "Vous n'avez choisi aucun produit"); | Yii::$app->session->setFlash('error', "Vous n'avez choisi aucun produit"); | ||||
if ($err_nb_produits) | if ($err_nb_produits) | ||||
Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander plus de 3 produits"); | Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander plus de 3 produits"); | ||||
if ($err_date) | if ($err_date) | ||||
Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander pour cette date."); | Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander pour cette date."); | ||||
if($err_point_vente) | |||||
if ($err_point_vente) | |||||
Yii::$app->session->setFlash('error', "Point de vente invalide."); | Yii::$app->session->setFlash('error', "Point de vente invalide."); | ||||
} | } | ||||
} | } | ||||
public function actionAnnuler($id) { | public function actionAnnuler($id) { | ||||
$commande = Commande::find() | $commande = Commande::find() | ||||
->with('production','creditHistorique','commandeProduits') | |||||
->with('production', 'creditHistorique', 'commandeProduits') | |||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
->one(); | ->one(); | ||||
if($commande->getEtat() != Commande::ETAT_MODIFIABLE) | |||||
{ | |||||
throw new UserException('Vous ne pouvez plus annuler cette commande.') ; | |||||
if ($commande->getEtat() != Commande::ETAT_MODIFIABLE) { | |||||
throw new UserException('Vous ne pouvez plus annuler cette commande.'); | |||||
} | } | ||||
$commande->init() ; | |||||
$commande->init(); | |||||
if ($commande && Yii::$app->user->id == $commande->id_user) { | if ($commande && Yii::$app->user->id == $commande->id_user) { | ||||
// remboursement | // remboursement | ||||
if($commande->getMontantPaye()) | |||||
{ | |||||
if ($commande->getMontantPaye()) { | |||||
$commande->creditHistorique( | $commande->creditHistorique( | ||||
CreditHistorique::TYPE_REMBOURSEMENT, | |||||
$commande->getMontantPaye(), | |||||
$commande->production->id_etablissement, | |||||
Yii::$app->user->identity->id | |||||
) ; | |||||
CreditHistorique::TYPE_REMBOURSEMENT, $commande->getMontantPaye(), $commande->production->id_etablissement, Yii::$app->user->identity->id | |||||
); | |||||
} | } | ||||
// delete | // delete | ||||
$commande->delete(); | $commande->delete(); | ||||
$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'annule_ok' => true])); | $this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'annule_ok' => true])); | ||||
} | } | ||||
public function actionVerifCodePointVente($id_point_vente, $code) | |||||
{ | |||||
$point_vente = PointVente::findOne($id_point_vente) ; | |||||
if($point_vente) | |||||
{ | |||||
if($point_vente->verifCode($code)) | |||||
{ | |||||
return true ; | |||||
public function actionVerifCodePointVente($id_point_vente, $code) { | |||||
$point_vente = PointVente::findOne($id_point_vente); | |||||
if ($point_vente) { | |||||
if ($point_vente->verifCode($code)) { | |||||
return true; | |||||
} | } | ||||
} | } | ||||
return false ; | |||||
return false; | |||||
} | } | ||||
} | } | ||||
namespace frontend\controllers; | namespace frontend\controllers; | ||||
use yii ; | |||||
use common\controllers\CommonController ; | |||||
use yii; | |||||
use common\controllers\CommonController; | |||||
class FrontendController extends CommonController | |||||
{ | |||||
class FrontendController extends CommonController { | |||||
} | } | ||||
<?php | <?php | ||||
namespace frontend\controllers; | namespace frontend\controllers; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use frontend\controllers\FrontendController; | use frontend\controllers\FrontendController; | ||||
use common\models\UserEtablissement ; | |||||
use common\models\UserEtablissement; | |||||
use dosamigos\leaflet\types\LatLng; | use dosamigos\leaflet\types\LatLng; | ||||
use dosamigos\leaflet\layers\Marker; | use dosamigos\leaflet\layers\Marker; | ||||
use dosamigos\leaflet\layers\TileLayer; | use dosamigos\leaflet\layers\TileLayer; | ||||
use dosamigos\leaflet\LeafLet; | use dosamigos\leaflet\LeafLet; | ||||
use dosamigos\leaflet\widgets\Map; | use dosamigos\leaflet\widgets\Map; | ||||
/** | /** | ||||
* Site controller | * Site controller | ||||
*/ | */ | ||||
class SiteController extends FrontendController | |||||
{ | |||||
class SiteController extends FrontendController { | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function behaviors() | |||||
{ | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | 'class' => AccessControl::className(), | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function actions() | |||||
{ | |||||
public function actions() { | |||||
return [ | return [ | ||||
'error' => [ | 'error' => [ | ||||
'class' => 'yii\web\ErrorAction', | 'class' => 'yii\web\ErrorAction', | ||||
]; | ]; | ||||
} | } | ||||
public function actionIndex() | |||||
{ | |||||
// redirection de l'utilisateur vers le tableau de bord s'il est connecté | |||||
if(!Yii::$app->user->isGuest) { | |||||
return $this->redirect(['commande/index']) ; | |||||
public function actionIndex() { | |||||
// redirection de l'utilisateur vers le tableau de bord s'il est connecté | |||||
if (!Yii::$app->user->isGuest) { | |||||
return $this->redirect(['commande/index']); | |||||
} | |||||
// produits | |||||
$produits = Produit::find()->orderBy('order ASC')->all(); | |||||
// contact | |||||
$model = new ContactForm(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||||
if ($model->sendEmail('matthieu@lechatdesnoisettes.com')) { | |||||
Yii::$app->session->setFlash('success', "Votre message a bien été envoyé, j'y répondrai dès que possible."); | |||||
} else { | |||||
Yii::$app->session->setFlash('error', 'There was an error sending email.'); | |||||
} | |||||
return $this->refresh(); | |||||
} | } | ||||
// produits | |||||
$produits = Produit::find()->orderBy('order ASC')->all() ; | |||||
// contact | |||||
$model = new ContactForm(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||||
if ($model->sendEmail('matthieu@lechatdesnoisettes.com')) { | |||||
Yii::$app->session->setFlash('success', "Votre message a bien été envoyé, j'y répondrai dès que possible."); | |||||
} else { | |||||
Yii::$app->session->setFlash('error', 'There was an error sending email.'); | |||||
} | |||||
return $this->refresh(); | |||||
} | |||||
// map | // map | ||||
$center = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']); | $center = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']); | ||||
$tileLayer = new TileLayer([ | $tileLayer = new TileLayer([ | ||||
'map' => 'test1', | |||||
'urlTemplate' => 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', | |||||
'clientOptions' => [ | |||||
'attribution' => 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' . | |||||
'<img src="http://developer.mapquest.com/content/osm/mq_logo.png">, ' . | |||||
'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>', | |||||
] | |||||
]); | |||||
'map' => 'test1', | |||||
'urlTemplate' => 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', | |||||
'clientOptions' => [ | |||||
'attribution' => 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' . | |||||
'<img src="http://developer.mapquest.com/content/osm/mq_logo.png">, ' . | |||||
'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>', | |||||
] | |||||
]); | |||||
$map = new LeafLet([ | $map = new LeafLet([ | ||||
'tileLayer' => $tileLayer, | |||||
'center' => $center | |||||
]); | |||||
'tileLayer' => $tileLayer, | |||||
'center' => $center | |||||
]); | |||||
$point = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']); | $point = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']); | ||||
$marker = new Marker(['latLng' => $point, 'popupContent' => Html::encode('Le Chat des Noisettes')]); | $marker = new Marker(['latLng' => $point, 'popupContent' => Html::encode('Le Chat des Noisettes')]); | ||||
$map->addLayer($marker); | $map->addLayer($marker); | ||||
return $this->render('index',[ | |||||
'page_principale'=>true, | |||||
'produits' => $produits, | |||||
'model' => $model, | |||||
'map' => $map | |||||
return $this->render('index', [ | |||||
'page_principale' => true, | |||||
'produits' => $produits, | |||||
'model' => $model, | |||||
'map' => $map | |||||
]); | ]); | ||||
} | } | ||||
public function actionMentions() | |||||
{ | |||||
return $this->render('mentions'); | |||||
public function actionMentions() { | |||||
return $this->render('mentions'); | |||||
} | } | ||||
public function actionCommander() { | public function actionCommander() { | ||||
if (Yii::$app->user->isGuest) { | |||||
$this->redirect(Yii::$app->urlManager->createUrl('site/login')) ; | |||||
} | |||||
if (Yii::$app->user->isGuest) { | |||||
$this->redirect(Yii::$app->urlManager->createUrl('site/login')); | |||||
} | |||||
} | } | ||||
public function actionLogin() | |||||
{ | |||||
public function actionLogin() { | |||||
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return Yii::$app->getResponse()->redirect(['commande/index']); | return Yii::$app->getResponse()->redirect(['commande/index']); | ||||
} | } | ||||
return $this->goBack(['commande/index']); | return $this->goBack(['commande/index']); | ||||
} else { | } else { | ||||
return $this->render('login', [ | return $this->render('login', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public function actionLogout() | |||||
{ | |||||
public function actionLogout() { | |||||
Yii::$app->user->logout(); | Yii::$app->user->logout(); | ||||
return $this->goHome(); | return $this->goHome(); | ||||
} | } | ||||
public function actionContact() | |||||
{ | |||||
public function actionContact() { | |||||
$model = new ContactForm(); | $model = new ContactForm(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | if ($model->load(Yii::$app->request->post()) && $model->validate()) { | ||||
if ($model->sendEmail(Yii::$app->params['adminEmail'])) { | if ($model->sendEmail(Yii::$app->params['adminEmail'])) { | ||||
return $this->refresh(); | return $this->refresh(); | ||||
} else { | } else { | ||||
return $this->render('contact', [ | return $this->render('contact', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public function actionAbout() | |||||
{ | |||||
public function actionAbout() { | |||||
return $this->render('about'); | return $this->render('about'); | ||||
} | } | ||||
public function actionSignup() | |||||
{ | |||||
public function actionSignup() { | |||||
$model = new SignupForm(); | $model = new SignupForm(); | ||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
if ($user = $model->signup()) { | if ($user = $model->signup()) { | ||||
if (Yii::$app->getUser()->login($user)) { | if (Yii::$app->getUser()->login($user)) { | ||||
$this->redirect(['commande/index']) ; | |||||
$this->redirect(['commande/index']); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// liste des établissements disponibles | // liste des établissements disponibles | ||||
$etablissements = Etablissement::getEtablissementsPopulateDropdown() ; | |||||
$data_etablissements_dispos = $etablissements['data'] ; | |||||
$options_etablissements_dispos = $etablissements['options'] ; | |||||
$etablissements = Etablissement::getEtablissementsPopulateDropdown(); | |||||
$data_etablissements_dispos = $etablissements['data']; | |||||
$options_etablissements_dispos = $etablissements['options']; | |||||
return $this->render('signup', [ | return $this->render('signup', [ | ||||
'model' => $model, | |||||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||||
'model' => $model, | |||||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||||
]); | ]); | ||||
} | } | ||||
public function actionRequestPasswordReset() | |||||
{ | |||||
public function actionRequestPasswordReset() { | |||||
$model = new PasswordResetRequestForm(); | $model = new PasswordResetRequestForm(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | if ($model->load(Yii::$app->request->post()) && $model->validate()) { | ||||
if ($model->sendEmail()) { | if ($model->sendEmail()) { | ||||
} | } | ||||
return $this->render('requestPasswordResetToken', [ | return $this->render('requestPasswordResetToken', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
public function actionResetPassword($token) | |||||
{ | |||||
public function actionResetPassword($token) { | |||||
try { | try { | ||||
$model = new ResetPasswordForm($token); | $model = new ResetPasswordForm($token); | ||||
} catch (InvalidParamException $e) { | } catch (InvalidParamException $e) { | ||||
} | } | ||||
return $this->render('resetPassword', [ | return $this->render('resetPassword', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
public function actionCgv() | |||||
{ | |||||
return $this->render('cgv') ; | |||||
public function actionCgv() { | |||||
return $this->render('cgv'); | |||||
} | } | ||||
public function actionCreditpain() | |||||
{ | |||||
return $this->render('creditpain') ; | |||||
public function actionCreditpain() { | |||||
return $this->render('creditpain'); | |||||
} | } | ||||
public function actionEtablissement($id_etablissement) | |||||
{ | |||||
public function actionEtablissement($id_etablissement) { | |||||
$model_login = new LoginForm(); | $model_login = new LoginForm(); | ||||
$model_signup = new SignupForm(); | $model_signup = new SignupForm(); | ||||
$etablissement = Etablissement::findOne($id_etablissement) ; | |||||
if(Yii::$app->user->isGuest) | |||||
{ | |||||
if ($model_login->load(Yii::$app->request->post()) && $model_login->login()) | |||||
{ | |||||
$etablissement = Etablissement::findOne($id_etablissement); | |||||
if (Yii::$app->user->isGuest) { | |||||
if ($model_login->load(Yii::$app->request->post()) && $model_login->login()) { | |||||
// ajout de l'établissement en favoris si ce n'est pas encore le cas | // ajout de l'établissement en favoris si ce n'est pas encore le cas | ||||
$user_etablissement_exist = UserEtablissement::find() | $user_etablissement_exist = UserEtablissement::find() | ||||
->where([ | |||||
'id_user' => Yii::$app->user->id, | |||||
'id_etablissement' => $id_etablissement | |||||
])->one(); | |||||
if(!$user_etablissement_exist) | |||||
{ | |||||
$etab_user = new UserEtablissement ; | |||||
$etab_user->id_etablissement = $id_etablissement ; | |||||
$etab_user->id_user = Yii::$app->user->id ; | |||||
$etab_user->credit = 0 ; | |||||
$etab_user->actif = 1 ; | |||||
$etab_user->save() ; | |||||
} | |||||
else { | |||||
if(!$user_etablissement_exist->actif) | |||||
{ | |||||
$user_etablissement_exist->actif = 1 ; | |||||
$user_etablissement_exist->save() ; | |||||
->where([ | |||||
'id_user' => Yii::$app->user->id, | |||||
'id_etablissement' => $id_etablissement | |||||
])->one(); | |||||
if (!$user_etablissement_exist) { | |||||
$etab_user = new UserEtablissement; | |||||
$etab_user->id_etablissement = $id_etablissement; | |||||
$etab_user->id_user = Yii::$app->user->id; | |||||
$etab_user->credit = 0; | |||||
$etab_user->actif = 1; | |||||
$etab_user->save(); | |||||
} else { | |||||
if (!$user_etablissement_exist->actif) { | |||||
$user_etablissement_exist->actif = 1; | |||||
$user_etablissement_exist->save(); | |||||
} | } | ||||
} | } | ||||
$this->redirect(['commande/index']) ; | |||||
$this->redirect(['commande/index']); | |||||
} | } | ||||
if ($model_signup->load(Yii::$app->request->post())) { | if ($model_signup->load(Yii::$app->request->post())) { | ||||
$model_signup->id_etablissement = $id_etablissement ; | |||||
$model_signup->option_client_boulanger = 'client' ; | |||||
$model_signup->id_etablissement = $id_etablissement; | |||||
$model_signup->option_client_boulanger = 'client'; | |||||
if ($user = $model_signup->signup()) { | if ($user = $model_signup->signup()) { | ||||
if (Yii::$app->getUser()->login($user)) { | if (Yii::$app->getUser()->login($user)) { | ||||
$this->redirect(['commande/index']) ; | |||||
$this->redirect(['commande/index']); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
else { | |||||
$this->redirect(['commande/create','id_etablissement' => $id_etablissement]) ; | |||||
} else { | |||||
$this->redirect(['commande/create', 'id_etablissement' => $id_etablissement]); | |||||
} | } | ||||
return $this->render('etablissement',[ | |||||
'model_login' => $model_login, | |||||
'model_signup' => $model_signup, | |||||
'etablissement' => $etablissement, | |||||
]) ; | |||||
return $this->render('etablissement', [ | |||||
'model_login' => $model_login, | |||||
'model_signup' => $model_signup, | |||||
'etablissement' => $etablissement, | |||||
]); | |||||
} | } | ||||
} | } |
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class UserController extends FrontendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
class UserController extends FrontendController { | |||||
public function behaviors() { | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
/*'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; | |||||
}*/ | |||||
] | |||||
], | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
/* 'matchCallback' => function ($rule, $action) { | |||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; | |||||
} */ | |||||
] | |||||
], | |||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionUpdate() | |||||
{ | |||||
public function actionUpdate() { | |||||
$model = $this->findModel(Yii::$app->user->identity->id); | $model = $this->findModel(Yii::$app->user->identity->id); | ||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | if ($model->load(Yii::$app->request->post()) && $model->validate()) { | ||||
// l'utilisateur ne peut pas changer d'adresse email | // l'utilisateur ne peut pas changer d'adresse email | ||||
$old_model = $this->findModel(Yii::$app->user->identity->id) ; | |||||
$model->email = $old_model->email ; | |||||
$old_model = $this->findModel(Yii::$app->user->identity->id); | |||||
$model->email = $old_model->email; | |||||
// modification du mot de passe | // modification du mot de passe | ||||
if(strlen($model->password_new)) | |||||
{ | |||||
if (strlen($model->password_new)) { | |||||
//$model->setPassword($model->password_new) ; | //$model->setPassword($model->password_new) ; | ||||
$model->password_hash = Yii::$app->security->generatePasswordHash($model->password_new); | $model->password_hash = Yii::$app->security->generatePasswordHash($model->password_new); | ||||
$model->password_old = '' ; | |||||
$model->password_new = '' ; | |||||
$model->password_new_confirm = '' ; | |||||
$model->password_old = ''; | |||||
$model->password_new = ''; | |||||
$model->password_new_confirm = ''; | |||||
} | } | ||||
$model->save() ; | |||||
Yii::$app->session->setFlash('success','Votre profil a bien été modifié.') ; | |||||
$model->save(); | |||||
Yii::$app->session->setFlash('success', 'Votre profil a bien été modifié.'); | |||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} else { | } else { | ||||
if(!$model->validate()) | |||||
{ | |||||
Yii::$app->session->setFlash('error','Le formulaire comporte des erreurs.') ; | |||||
if (!$model->validate()) { | |||||
Yii::$app->session->setFlash('error', 'Le formulaire comporte des erreurs.'); | |||||
} | } | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
'model' => $model, | |||||
'model' => $model, | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
public function actionCredit() | |||||
{ | |||||
return $this->render('credit', [ | |||||
]); | |||||
public function actionCredit() { | |||||
return $this->render('credit', [ | |||||
]); | |||||
} | } | ||||
/** | /** | ||||
* Finds the User model based on its primary key value. | * Finds the User model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
* @return User the loaded model | * @return User the loaded model | ||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | |||||
{ | |||||
protected function findModel($id) { | |||||
if (($model = User::findOne($id)) !== null) { | if (($model = User::findOne($id)) !== null) { | ||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\UserEtablissement; | use common\models\UserEtablissement; | ||||
use common\models\Etablissement ; | |||||
use yii\helpers\Html ; | |||||
use common\models\Etablissement; | |||||
use yii\helpers\Html; | |||||
/** | /** | ||||
* ContactForm is the model behind the contact form. | * ContactForm is the model behind the contact form. | ||||
*/ | */ | ||||
class AddEtablissementForm extends Model | |||||
{ | |||||
class AddEtablissementForm extends Model { | |||||
public $id_etablissement; | public $id_etablissement; | ||||
public $code ; | |||||
public $code; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['id_etablissement','integer'], | |||||
['id_etablissement', 'integer'], | |||||
['id_etablissement', 'required'], | ['id_etablissement', 'required'], | ||||
['id_etablissement', function($attribute, $params) { | ['id_etablissement', function($attribute, $params) { | ||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if(!$etablissement) | |||||
{ | |||||
$this->addError($attribute, 'Cet établissement n\'existe pas.') ; | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if (!$etablissement) { | |||||
$this->addError($attribute, 'Cet établissement n\'existe pas.'); | |||||
} | } | ||||
$user_etablissement_exist = UserEtablissement::find() | $user_etablissement_exist = UserEtablissement::find() | ||||
->where([ | |||||
'id_user' => Yii::$app->user->identity->id, | |||||
'id_etablissement' => $this->id_etablissement, | |||||
'actif' => 1 | |||||
]) | |||||
->one() ; | |||||
if($user_etablissement_exist) | |||||
{ | |||||
$this->addError($attribute, 'Cet établissement est déjà sur votre tableau de bord.') ; | |||||
->where([ | |||||
'id_user' => Yii::$app->user->identity->id, | |||||
'id_etablissement' => $this->id_etablissement, | |||||
'actif' => 1 | |||||
]) | |||||
->one(); | |||||
if ($user_etablissement_exist) { | |||||
$this->addError($attribute, 'Cet établissement est déjà sur votre tableau de bord.'); | |||||
} | } | ||||
}], | }], | ||||
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
return strlen($etablissement->code) ; | |||||
} | |||||
else { | |||||
return false ; | |||||
} | |||||
}], | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement) { | |||||
return strlen($etablissement->code); | |||||
} else { | |||||
return false; | |||||
} | |||||
}], | |||||
['code', function($attribute, $params) { | ['code', function($attribute, $params) { | ||||
$code = $this->$attribute ; | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) | |||||
{ | |||||
$this->addError($attribute, 'Code incorrect'); | |||||
} | |||||
}], | |||||
$code = $this->$attribute; | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) { | |||||
$this->addError($attribute, 'Code incorrect'); | |||||
} | |||||
}], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'id_etablissement' => 'Établissement', | 'id_etablissement' => 'Établissement', | ||||
'code' => 'Code', | 'code' => 'Code', | ||||
* @param string $email the target email address | * @param string $email the target email address | ||||
* @return boolean whether the email was sent | * @return boolean whether the email was sent | ||||
*/ | */ | ||||
public function add() | |||||
{ | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
public function add() { | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
$user_etablissement_exist = UserEtablissement::find() | $user_etablissement_exist = UserEtablissement::find() | ||||
->where([ | |||||
'id_user' => Yii::$app->user->identity->id, | |||||
'id_etablissement' => $this->id_etablissement, | |||||
'actif' => 0 | |||||
]) | |||||
->one() ; | |||||
if($user_etablissement_exist) | |||||
{ | |||||
$user_etablissement_exist->actif = 1 ; | |||||
$user_etablissement_exist->save() ; | |||||
} | |||||
else { | |||||
$user_etablissement = new UserEtablissement() ; | |||||
$user_etablissement->id_user = Yii::$app->user->identity->id ; | |||||
$user_etablissement->id_etablissement = $this->id_etablissement ; | |||||
$user_etablissement->credit = 0 ; | |||||
$user_etablissement->actif = 1 ; | |||||
$user_etablissement->save() ; | |||||
->where([ | |||||
'id_user' => Yii::$app->user->identity->id, | |||||
'id_etablissement' => $this->id_etablissement, | |||||
'actif' => 0 | |||||
]) | |||||
->one(); | |||||
if ($user_etablissement_exist) { | |||||
$user_etablissement_exist->actif = 1; | |||||
$user_etablissement_exist->save(); | |||||
} else { | |||||
$user_etablissement = new UserEtablissement(); | |||||
$user_etablissement->id_user = Yii::$app->user->identity->id; | |||||
$user_etablissement->id_etablissement = $this->id_etablissement; | |||||
$user_etablissement->credit = 0; | |||||
$user_etablissement->actif = 1; | |||||
$user_etablissement->save(); | |||||
} | } | ||||
Yii::$app->session->setFlash('success', 'Le producteur <strong>'.Html::encode($etablissement->nom).'</strong> a bien été ajoutée à votre tableau de bord.') ; | |||||
Yii::$app->session->setFlash('success', 'Le producteur <strong>' . Html::encode($etablissement->nom) . '</strong> a bien été ajoutée à votre tableau de bord.'); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* ContactForm is the model behind the contact form. | * ContactForm is the model behind the contact form. | ||||
*/ | */ | ||||
class ContactForm extends Model | |||||
{ | |||||
class ContactForm extends Model { | |||||
public $name; | public $name; | ||||
public $email; | public $email; | ||||
public $subject; | public $subject; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
// name, email, subject and body are required | // name, email, subject and body are required | ||||
[['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'], | [['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'], | ||||
// email has to be a valid email address | // email has to be a valid email address | ||||
['email', 'email','message' => 'Email incorrect'], | |||||
['email', 'email', 'message' => 'Email incorrect'], | |||||
// verifyCode needs to be entered correctly | // verifyCode needs to be entered correctly | ||||
['verifyCode', 'captcha','message'=> 'Veuillez recopier le code de vérification'], | |||||
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'], | |||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'name' => 'Nom', | |||||
'email' => 'Email', | |||||
'subject' => 'Sujet', | |||||
'body' => 'Message', | |||||
'name' => 'Nom', | |||||
'email' => 'Email', | |||||
'subject' => 'Sujet', | |||||
'body' => 'Message', | |||||
'verifyCode' => 'Code de vérification', | 'verifyCode' => 'Code de vérification', | ||||
]; | ]; | ||||
} | } | ||||
* @param string $email the target email address | * @param string $email the target email address | ||||
* @return boolean whether the email was sent | * @return boolean whether the email was sent | ||||
*/ | */ | ||||
public function sendEmail($email) | |||||
{ | |||||
public function sendEmail($email) { | |||||
return Yii::$app->mailer->compose([ | return Yii::$app->mailer->compose([ | ||||
'html' => 'contact-html', | 'html' => 'contact-html', | ||||
'text' => 'contact-text'], | |||||
[ 'content' => $this->body, | |||||
'text' => 'contact-text'], [ 'content' => $this->body, | |||||
'nom' => $this->name | 'nom' => $this->name | ||||
]) | ]) | ||||
->setTo($email) | ->setTo($email) | ||||
->setFrom([$this->email => $this->name]) | ->setFrom([$this->email => $this->name]) | ||||
->setSubject('[La boîte à pain] Contact : '.$this->subject) | |||||
->setSubject('[La boîte à pain] Contact : ' . $this->subject) | |||||
->send(); | ->send(); | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace frontend\models; | namespace frontend\models; | ||||
use common\models\User; | use common\models\User; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use yii ; | |||||
use yii; | |||||
/** | /** | ||||
* Password reset request form | * Password reset request form | ||||
*/ | */ | ||||
class PasswordResetRequestForm extends Model | |||||
{ | |||||
class PasswordResetRequestForm extends Model { | |||||
public $email; | public $email; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['email', 'filter', 'filter' => 'trim'], | ['email', 'filter', 'filter' => 'trim'], | ||||
['email', 'required'], | ['email', 'required'], | ||||
* | * | ||||
* @return boolean whether the email was send | * @return boolean whether the email was send | ||||
*/ | */ | ||||
public function sendEmail() | |||||
{ | |||||
public function sendEmail() { | |||||
/* @var $user User */ | /* @var $user User */ | ||||
$user = User::findOne([ | $user = User::findOne([ | ||||
'email' => $this->email, | |||||
'email' => $this->email, | |||||
]); | ]); | ||||
if ($user) { | if ($user) { | ||||
$user->generatePasswordResetToken(); | $user->generatePasswordResetToken(); | ||||
} | } | ||||
if ($user->save()) | |||||
{ | |||||
if ($user->save()) { | |||||
return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]) | return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]) | ||||
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) | ->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) | ||||
->setTo($this->email) | ->setTo($this->email) | ||||
return false; | return false; | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace frontend\models; | namespace frontend\models; | ||||
use common\models\User; | use common\models\User; | ||||
/** | /** | ||||
* Password reset form | * Password reset form | ||||
*/ | */ | ||||
class ResetPasswordForm extends Model | |||||
{ | |||||
class ResetPasswordForm extends Model { | |||||
public $password; | public $password; | ||||
/** | /** | ||||
*/ | */ | ||||
private $_user; | private $_user; | ||||
/** | /** | ||||
* Creates a form model given a token. | * Creates a form model given a token. | ||||
* | * | ||||
* @param array $config name-value pairs that will be used to initialize the object properties | * @param array $config name-value pairs that will be used to initialize the object properties | ||||
* @throws \yii\base\InvalidParamException if token is empty or not valid | * @throws \yii\base\InvalidParamException if token is empty or not valid | ||||
*/ | */ | ||||
public function __construct($token, $config = []) | |||||
{ | |||||
public function __construct($token, $config = []) { | |||||
if (empty($token) || !is_string($token)) { | if (empty($token) || !is_string($token)) { | ||||
throw new InvalidParamException('Password reset token cannot be blank.'); | throw new InvalidParamException('Password reset token cannot be blank.'); | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['password', 'required'], | ['password', 'required'], | ||||
['password', 'string', 'min' => 6], | ['password', 'string', 'min' => 6], | ||||
* | * | ||||
* @return boolean if password was reset. | * @return boolean if password was reset. | ||||
*/ | */ | ||||
public function resetPassword() | |||||
{ | |||||
public function resetPassword() { | |||||
$user = $this->_user; | $user = $this->_user; | ||||
$user->setPassword($this->password); | $user->setPassword($this->password); | ||||
$user->removePasswordResetToken(); | $user->removePasswordResetToken(); | ||||
return $user->save(); | return $user->save(); | ||||
} | } | ||||
public function attributeLabels() | |||||
{ | |||||
public function attributeLabels() { | |||||
return [ | return [ | ||||
'password' => 'Mot de passe', | |||||
'password' => 'Mot de passe', | |||||
]; | ]; | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace frontend\models; | namespace frontend\models; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | use common\models\User; | ||||
use common\models\Etablissement; | use common\models\Etablissement; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\UserEtablissement ; | |||||
use common\helpers\Password ; | |||||
use common\models\UserEtablissement; | |||||
use common\helpers\Password; | |||||
/** | /** | ||||
* Signup form | * Signup form | ||||
*/ | */ | ||||
class SignupForm extends Model | |||||
{ | |||||
class SignupForm extends Model { | |||||
public $username; | public $username; | ||||
public $email; | public $email; | ||||
public $password; | public $password; | ||||
public $prenom; | public $prenom; | ||||
public $telephone; | public $telephone; | ||||
public $is_boulanger; | public $is_boulanger; | ||||
public $siret; | public $siret; | ||||
public $nom_magasin; | public $nom_magasin; | ||||
public $code_postal; | public $code_postal; | ||||
public $ville; | public $ville; | ||||
public $id_etablissement ; | |||||
public $option_client_boulanger ; | |||||
public $cgv ; | |||||
public $code ; | |||||
public $id_etablissement; | |||||
public $option_client_boulanger; | |||||
public $cgv; | |||||
public $code; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
{ | |||||
public function rules() { | |||||
return [ | return [ | ||||
['email', 'filter', 'filter' => 'trim'], | ['email', 'filter', 'filter' => 'trim'], | ||||
['email', 'required','message'=>'Champs obligatoire'], | |||||
['email', 'required', 'message' => 'Champs obligatoire'], | |||||
['email', 'email'], | ['email', 'email'], | ||||
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | ||||
[['nom', 'prenom', 'telephone'],'required','message'=>'Champs obligatoire'], | |||||
[['nom', 'prenom', 'telephone'], 'required', 'message' => 'Champs obligatoire'], | |||||
[['nom', 'prenom', 'telephone', 'option_client_boulanger'], 'string', 'min' => 2, 'max' => 255], | [['nom', 'prenom', 'telephone', 'option_client_boulanger'], 'string', 'min' => 2, 'max' => 255], | ||||
['password', 'required','message'=>'Champs obligatoire'], | |||||
['password', 'required', 'message' => 'Champs obligatoire'], | |||||
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | ['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | ||||
['is_boulanger', 'boolean'], | ['is_boulanger', 'boolean'], | ||||
['cgv', 'boolean'], | ['cgv', 'boolean'], | ||||
['cgv', function($attribute, $params) { | ['cgv', function($attribute, $params) { | ||||
$cgv = $this->$attribute ; | |||||
if($this->option_client_boulanger == 'boulanger' && !$cgv) | |||||
{ | |||||
$this->addError($attribute, 'Vous devez accepter les conditions générales de vente pour vous inscrire.'); | |||||
} | |||||
}], | |||||
['code_postal', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
$cgv = $this->$attribute; | |||||
if ($this->option_client_boulanger == 'boulanger' && !$cgv) { | |||||
$this->addError($attribute, 'Vous devez accepter les conditions générales de vente pour vous inscrire.'); | |||||
} | |||||
}], | |||||
['code_postal', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger'; | |||||
}, 'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | return $('#option-boulanger').prop('checked') ; | ||||
}"], | }"], | ||||
['ville', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
['ville', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger'; | |||||
}, 'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | return $('#option-boulanger').prop('checked') ; | ||||
}"], | }"], | ||||
['nom_magasin', 'string'], | ['nom_magasin', 'string'], | ||||
['nom_magasin', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
['nom_magasin', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger'; | |||||
}, 'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | return $('#option-boulanger').prop('checked') ; | ||||
}"], | }"], | ||||
['siret', 'string'], | ['siret', 'string'], | ||||
['siret', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
['siret', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger'; | |||||
}, 'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | return $('#option-boulanger').prop('checked') ; | ||||
}"], | }"], | ||||
['siret', function($attribute, $params) { | ['siret', function($attribute, $params) { | ||||
$siret = $this->$attribute ; | |||||
$siret = str_replace(' ', '', $siret) ; | |||||
if (strlen($siret) != 14) | |||||
{ | |||||
$this->addError($attribute, 'Le numéro SIRET doit contenir 14 caractères'); | |||||
return; | |||||
} | |||||
if (!is_numeric($siret)) | |||||
{ | |||||
$this->addError($attribute, 'Le numéro SIRET ne doit contenir que des chiffres'); | |||||
return; | |||||
} | |||||
// on prend chaque chiffre un par un | |||||
// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair | |||||
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 | |||||
// on ajoute cette valeur à la somme totale | |||||
$sum = 0 ; | |||||
for ($index = 0; $index < 14; $index ++) | |||||
{ | |||||
$siret = $this->$attribute; | |||||
$siret = str_replace(' ', '', $siret); | |||||
if (strlen($siret) != 14) { | |||||
$this->addError($attribute, 'Le numéro SIRET doit contenir 14 caractères'); | |||||
return; | |||||
} | |||||
if (!is_numeric($siret)) { | |||||
$this->addError($attribute, 'Le numéro SIRET ne doit contenir que des chiffres'); | |||||
return; | |||||
} | |||||
// on prend chaque chiffre un par un | |||||
// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair | |||||
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 | |||||
// on ajoute cette valeur à la somme totale | |||||
$sum = 0; | |||||
for ($index = 0; $index < 14; $index ++) { | |||||
$number = (int) $siret[$index]; | $number = (int) $siret[$index]; | ||||
if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; } | |||||
if (($index % 2) == 0) { | |||||
if (($number *= 2) > 9) | |||||
$number -= 9; | |||||
} | |||||
$sum += $number; | $sum += $number; | ||||
} | |||||
} | |||||
// le numéro est valide si la somme des chiffres est multiple de 10 | |||||
if (($sum % 10) != 0) | |||||
$this->addError($attribute, 'Numéro SIRET invalide'); | |||||
}], | |||||
['id_etablissement','integer'], | |||||
// le numéro est valide si la somme des chiffres est multiple de 10 | |||||
if (($sum % 10) != 0) | |||||
$this->addError($attribute, 'Numéro SIRET invalide'); | |||||
}], | |||||
['id_etablissement', 'integer'], | |||||
['id_etablissement', function($attribute, $params) { | ['id_etablissement', function($attribute, $params) { | ||||
if($this->id_etablissement) | |||||
{ | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if(!$etablissement) | |||||
{ | |||||
$this->addError($attribute, 'Ce producteur n\'existe pas.') ; | |||||
if ($this->id_etablissement) { | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if (!$etablissement) { | |||||
$this->addError($attribute, 'Ce producteur n\'existe pas.'); | |||||
} | |||||
} | } | ||||
} | |||||
}], | |||||
}], | |||||
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement) | |||||
{ | |||||
return strlen($etablissement->code) ; | |||||
} | |||||
else { | |||||
return false ; | |||||
} | |||||
}], | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement) { | |||||
return strlen($etablissement->code); | |||||
} else { | |||||
return false; | |||||
} | |||||
}], | |||||
['code', function($attribute, $params) { | ['code', function($attribute, $params) { | ||||
$code = $this->$attribute ; | |||||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||||
if($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) | |||||
{ | |||||
$this->addError($attribute, 'Code incorrect'); | |||||
} | |||||
}], | |||||
$code = $this->$attribute; | |||||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||||
if ($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) { | |||||
$this->addError($attribute, 'Code incorrect'); | |||||
} | |||||
}], | |||||
]; | ]; | ||||
} | } | ||||
* | * | ||||
* @return User|null the saved model or null if saving fails | * @return User|null the saved model or null if saving fails | ||||
*/ | */ | ||||
public function signup() | |||||
{ | |||||
public function signup() { | |||||
if ($this->validate()) { | if ($this->validate()) { | ||||
$user = new User(); | $user = new User(); | ||||
$user->username = $this->email; | $user->username = $this->email; | ||||
$user->email = $this->email; | $user->email = $this->email; | ||||
$user->nom = $this->nom ; | |||||
$user->prenom = $this->prenom ; | |||||
$user->telephone = $this->telephone ; | |||||
$user->confiance = 1 ; | |||||
if($this->option_client_boulanger == 'boulanger') | |||||
{ | |||||
$user->nom = $this->nom; | |||||
$user->prenom = $this->prenom; | |||||
$user->telephone = $this->telephone; | |||||
$user->confiance = 1; | |||||
if ($this->option_client_boulanger == 'boulanger') { | |||||
// etablissement | // etablissement | ||||
$etablissement = new Etablissement ; | |||||
$etablissement->nom = $this->nom_magasin ; | |||||
$etablissement = new Etablissement; | |||||
$etablissement->nom = $this->nom_magasin; | |||||
$etablissement->siret = $this->siret; | $etablissement->siret = $this->siret; | ||||
$etablissement->code_postal = $this->code_postal; | $etablissement->code_postal = $this->code_postal; | ||||
$etablissement->ville = $this->ville; | $etablissement->ville = $this->ville; | ||||
$etablissement->heure_limite_commande = 20 ; | |||||
$etablissement->delai_commande = 1 ; | |||||
$etablissement->gratuit = 1 ; | |||||
$etablissement->heure_limite_commande = 20; | |||||
$etablissement->delai_commande = 1; | |||||
$etablissement->gratuit = 1; | |||||
// génération d'un code | // génération d'un code | ||||
do { | do { | ||||
$code = Password::generate() ; | |||||
$etablissement->code = $code ; | |||||
} while(Etablissement::findOne(['code' => $code])); | |||||
$etablissement->save() ; | |||||
$code = Password::generate(); | |||||
$etablissement->code = $code; | |||||
} while (Etablissement::findOne(['code' => $code])); | |||||
$etablissement->save(); | |||||
// user | // user | ||||
$user->id_etablissement = $etablissement->id ; | |||||
$user->status = User::STATUS_BOULANGER ; | |||||
$user->id_etablissement = $etablissement->id; | |||||
$user->status = User::STATUS_BOULANGER; | |||||
// envoi d'un email à l'administrateur pour le prévenir | // envoi d'un email à l'administrateur pour le prévenir | ||||
Yii::$app->mailer->compose( | Yii::$app->mailer->compose( | ||||
[ | |||||
'html' => 'new-boulanger-html', | |||||
'text' => 'new-boulanger-text' | |||||
], | |||||
[ | |||||
'etablissement' => $etablissement | |||||
]) | |||||
->setTo(Yii::$app->params['adminEmail']) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Nouveau producteur') | |||||
->send(); | |||||
[ | |||||
'html' => 'new-boulanger-html', | |||||
'text' => 'new-boulanger-text' | |||||
], [ | |||||
'etablissement' => $etablissement | |||||
]) | |||||
->setTo(Yii::$app->params['adminEmail']) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Nouveau producteur') | |||||
->send(); | |||||
} | } | ||||
$user->setPassword($this->password); | $user->setPassword($this->password); | ||||
$user->generateAuthKey(); | $user->generateAuthKey(); | ||||
if ($user->save()) { | if ($user->save()) { | ||||
// on ajoute l'établissement sélectionnée par l'user en favoris | // on ajoute l'établissement sélectionnée par l'user en favoris | ||||
if($this->option_client_boulanger == 'client') | |||||
{ | |||||
if($this->id_etablissement) | |||||
{ | |||||
$etablissement = Etablissement::find()->where(['id'=>$this->id_etablissement])->one() ; | |||||
if($etablissement) | |||||
{ | |||||
$etab_user = new UserEtablissement ; | |||||
$etab_user->id_etablissement = $this->id_etablissement ; | |||||
$etab_user->id_user = $user->id ; | |||||
$etab_user->credit = 0 ; | |||||
$etab_user->actif = 1 ; | |||||
$etab_user->save() ; | |||||
if ($this->option_client_boulanger == 'client') { | |||||
if ($this->id_etablissement) { | |||||
$etablissement = Etablissement::find()->where(['id' => $this->id_etablissement])->one(); | |||||
if ($etablissement) { | |||||
$etab_user = new UserEtablissement; | |||||
$etab_user->id_etablissement = $this->id_etablissement; | |||||
$etab_user->id_user = $user->id; | |||||
$etab_user->credit = 0; | |||||
$etab_user->actif = 1; | |||||
$etab_user->save(); | |||||
// envoi d'un email à l'utilisateur | // envoi d'un email à l'utilisateur | ||||
Yii::$app->mailer->compose( | Yii::$app->mailer->compose( | ||||
[ | |||||
'html' => 'signup-html', | |||||
'text' => 'signup-text' | |||||
], | |||||
[ | |||||
'user' => $user, | |||||
'etablissement' => $etablissement | |||||
]) | |||||
->setTo($user->email) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send(); | |||||
[ | |||||
'html' => 'signup-html', | |||||
'text' => 'signup-text' | |||||
], [ | |||||
'user' => $user, | |||||
'etablissement' => $etablissement | |||||
]) | |||||
->setTo($user->email) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send(); | |||||
} | } | ||||
} | } | ||||
} | |||||
if($this->option_client_boulanger == 'boulanger') | |||||
{ | |||||
$etab_user = new UserEtablissement ; | |||||
$etab_user->id_etablissement = $etablissement->id ; | |||||
$etab_user->id_user = $user->id ; | |||||
$etab_user->credit = 0 ; | |||||
$etab_user->actif = 1 ; | |||||
$etab_user->save() ; | |||||
} | } | ||||
if ($this->option_client_boulanger == 'boulanger') { | |||||
$etab_user = new UserEtablissement; | |||||
$etab_user->id_etablissement = $etablissement->id; | |||||
$etab_user->id_user = $user->id; | |||||
$etab_user->credit = 0; | |||||
$etab_user->actif = 1; | |||||
$etab_user->save(); | |||||
} | |||||
return $user; | return $user; | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'prenom' => 'Prénom', | |||||
'telephone' => 'Téléphone', | |||||
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation dans mon établissement", | |||||
'nom_magasin' => 'Nom de l\'établissement', | |||||
'siret' => 'Numéro SIRET', | |||||
'code_postal' => 'Code postal', | |||||
'ville' => 'Commune', | |||||
'id_etablissement' => 'Producteur', | |||||
]; | |||||
public function attributeLabels() { | |||||
return [ | |||||
'id' => 'ID', | |||||
'username' => 'Identifiant', | |||||
'password' => 'Mot de passe', | |||||
'rememberMe' => 'Se souvenir de moi', | |||||
'prenom' => 'Prénom', | |||||
'telephone' => 'Téléphone', | |||||
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation dans mon établissement", | |||||
'nom_magasin' => 'Nom de l\'établissement', | |||||
'siret' => 'Numéro SIRET', | |||||
'code_postal' => 'Code postal', | |||||
'ville' => 'Commune', | |||||
'id_etablissement' => 'Producteur', | |||||
]; | |||||
} | } | ||||
} | } |