Просмотр исходного кода

Indentation Controllers / Models

prodstable
keun 6 лет назад
Родитель
Сommit
44ccbd66bc
46 измененных файлов: 3121 добавлений и 3759 удалений
  1. +3
    -5
      backend/controllers/BackendController.php
  2. +402
    -476
      backend/controllers/CommandeController.php
  3. +86
    -97
      backend/controllers/CommandeautoController.php
  4. +43
    -48
      backend/controllers/CommuniquerController.php
  5. +141
    -165
      backend/controllers/CronController.php
  6. +42
    -47
      backend/controllers/DeveloppementController.php
  7. +60
    -68
      backend/controllers/EtablissementAdminController.php
  8. +50
    -56
      backend/controllers/EtablissementController.php
  9. +45
    -60
      backend/controllers/PaiementController.php
  10. +48
    -57
      backend/controllers/PointVenteController.php
  11. +83
    -96
      backend/controllers/ProduitController.php
  12. +42
    -49
      backend/controllers/SiteController.php
  13. +48
    -53
      backend/controllers/StatsController.php
  14. +124
    -142
      backend/controllers/UserController.php
  15. +84
    -94
      backend/controllers/VracController.php
  16. +9
    -11
      backend/models/MailForm.php
  17. +8
    -11
      common/controllers/CommonController.php
  18. +263
    -320
      common/models/Commande.php
  19. +128
    -157
      common/models/CommandeAuto.php
  20. +93
    -102
      common/models/CommandeAutoForm.php
  21. +10
    -13
      common/models/CommandeAutoProduit.php
  22. +10
    -12
      common/models/CommandeProduit.php
  23. +58
    -71
      common/models/CreditHistorique.php
  24. +20
    -21
      common/models/Developpement.php
  25. +28
    -26
      common/models/DeveloppementPriorite.php
  26. +137
    -166
      common/models/Etablissement.php
  27. +14
    -18
      common/models/Facture.php
  28. +29
    -37
      common/models/LoginForm.php
  29. +113
    -137
      common/models/PointVente.php
  30. +6
    -8
      common/models/PointVenteUser.php
  31. +28
    -39
      common/models/Production.php
  32. +51
    -65
      common/models/ProductionPointVente.php
  33. +34
    -40
      common/models/ProductionProduit.php
  34. +42
    -54
      common/models/Produit.php
  35. +158
    -198
      common/models/User.php
  36. +0
    -46
      common/models/UserBoulangerie.php
  37. +1
    -1
      common/models/UserEtablissement.php
  38. +166
    -205
      frontend/controllers/CommandeController.php
  39. +3
    -5
      frontend/controllers/FrontendController.php
  40. +110
    -130
      frontend/controllers/SiteController.php
  41. +41
    -48
      frontend/controllers/UserController.php
  42. +60
    -68
      frontend/models/AddEtablissementForm.php
  43. +15
    -18
      frontend/models/ContactForm.php
  44. +10
    -11
      frontend/models/PasswordResetRequestForm.php
  45. +10
    -13
      frontend/models/ResetPasswordForm.php
  46. +165
    -195
      frontend/models/SignupForm.php

+ 3
- 5
backend/controllers/BackendController.php Просмотреть файл

@@ -2,12 +2,10 @@

namespace backend\controllers;

use yii ;
use common\controllers\CommonController ;
use yii;
use common\controllers\CommonController;

class BackendController extends CommonController
{
class BackendController extends CommonController {
}


+ 402
- 476
backend/controllers/CommandeController.php
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 86
- 97
backend/controllers/CommandeautoController.php Просмотреть файл

@@ -13,19 +13,18 @@ use common\models\CommandeProduit;
use common\models\PointVente;
use common\models\Produit;
use common\models\User;
use common\models\CommandeAutoForm ;
use common\models\CommandeAutoForm;
use common\models\ProductionProduit;
use yii\data\ActiveDataProvider;
use common\models\CommandeAuto ;
use common\models\CommandeAutoProduit ;
use common\models\CommandeAuto;
use common\models\CommandeAutoProduit;
use yii\web\NotFoundHttpException;

class CommandeautoController extends BackendController {

var $enableCsrfValidation = false;

public function behaviors()
{
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
@@ -34,124 +33,114 @@ class CommandeautoController extends BackendController {
'allow' => true,
'roles' => ['@'],
'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([
'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' => [
'pageSize' => 1000,
],
]);
return $this->render('index',[
'dataProvider' => $dataProvider
]) ;
return $this->render('index', [
'dataProvider' => $dataProvider
]);
}
public function actionCreate()
{

public function actionCreate() {
// 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 = 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
$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
$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);
}
// produits
$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']);
}
}

}

+ 43
- 48
backend/controllers/CommuniquerController.php Просмотреть файл

@@ -15,10 +15,9 @@ use common\models\Etablissement;
/**
* UserController implements the CRUD actions for User model.
*/
class CommuniquerController extends BackendController
{
public function behaviors()
{
class CommuniquerController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
@@ -27,52 +26,49 @@ class CommuniquerController extends BackendController
],
],
'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', [
'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
$content = $this->renderPartial('mode_emploi_multi',[
$content = $this->renderPartial('mode_emploi_multi', [
'pdf' => true,
'etablissement' => $etablissement
]);
]);

$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
'mode' => Pdf::MODE_UTF8,
// A4 paper format
'format' => Pdf::FORMAT_A4,
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
'content' => $content,
'marginRight' => 0,
'marginLeft' => 0,
'marginTop' => 0,
@@ -81,21 +77,20 @@ class CommuniquerController extends BackendController
// enhanced bootstrap css built by Krajee for mPDF formatting
//'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.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 $pdf->render();
return $pdf->render();
}
}

+ 141
- 165
backend/controllers/CronController.php Просмотреть файл

@@ -11,17 +11,16 @@ use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use kartik\mpdf\Pdf;
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.
*/
class CronController extends BackendController
{
public function behaviors()
{
class CronController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
@@ -30,223 +29,200 @@ class CronController extends BackendController
],
],
'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 = [
'Martin', 'Bernard', 'Thomas','Petit','Robert', 'Richard','Durand','Dubois',
'Martin', 'Bernard', 'Thomas', 'Petit', 'Robert', 'Richard', 'Durand', 'Dubois',
'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 = [
'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()
->joinWith('userEtablissement')
->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 {
$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 = 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('#&[^;]+;#', '', $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
* pour empêcher la connexion des utilisateurs via ce compte en prod.
* Lors de l'initialisation des utilisateurs sur l'espace de démo,
* 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();
}
$commandes = Commande::find()
->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()
->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([
'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()
->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([
'id_etablissement' => $e['id'],
'status' => User::STATUS_BOULANGER
]) ;
'id_etablissement' => $e['id'],
'status' => User::STATUS_BOULANGER
]);

$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)
->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
Yii::$app->runAction('commande/report-cron', [
'date' => $date,
'date' => $date,
'save' => true,
'id_etablissement' => $e['id'] ,
'id_etablissement' => $e['id'],
'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)
->send();

->send();
}
}
}
}
}
}

+ 42
- 47
backend/controllers/DeveloppementController.php Просмотреть файл

@@ -20,8 +20,7 @@ class DeveloppementController extends Controller {
/**
* @inheritdoc
*/
public function behaviors()
{
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
@@ -30,9 +29,8 @@ class DeveloppementController extends Controller {
'allow' => true,
'roles' => ['@'],
'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;
}
]
],
],
@@ -45,11 +43,11 @@ class DeveloppementController extends Controller {
*/
public function actionIndex() {
$dataProvider = new ActiveDataProvider([
'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']),
'query' => Developpement::find()->with(['developpementPriorite', 'developpementPrioriteCurrentEtablissement']),
]);

return $this->render('index', [
'dataProvider' => $dataProvider,
'dataProvider' => $dataProvider,
]);
}

@@ -60,17 +58,17 @@ class DeveloppementController extends Controller {
*/
public function actionCreate() {
$model = new Developpement();
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']);
}
} else {
return $this->render('create', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -85,14 +83,14 @@ class DeveloppementController extends Controller {
$model = $this->findModel($id);

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']);
}
} else {
return $this->render('update', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -105,44 +103,41 @@ class DeveloppementController extends Controller {
*/
public function actionDelete($id) {
$this->findModel($id)->delete();
Yii::$app->getSession()->setFlash('success','Développement supprimé') ;
Yii::$app->getSession()->setFlash('success', 'Développement supprimé');
return $this->redirect(['index']);
}

public function actionPriorite($id_developpement, $priorite = null) {
$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.
* If the model is not found, a 404 HTTP exception will be thrown.
@@ -157,5 +152,5 @@ class DeveloppementController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

+ 60
- 68
backend/controllers/EtablissementAdminController.php Просмотреть файл

@@ -7,18 +7,17 @@ use common\models\User;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\helpers\Upload ;
use common\models\Etablissement ;
use yii\data\ActiveDataProvider ;
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.
*/
class EtablissementAdminController extends BackendController
{
public function behaviors()
{
class EtablissementAdminController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
@@ -27,96 +26,89 @@ class EtablissementAdminController extends BackendController
],
],
'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([
'query' => Etablissement::find()
->with('userEtablissement','user')
->orderBy('date_creation DESC'),
->with('userEtablissement', 'user')
->orderBy('date_creation DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

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([
'query' => Facture::find()
->with('etablissement')
->orderBy('reference DESC'),
->with('etablissement')
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

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) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

+ 50
- 56
backend/controllers/EtablissementController.php Просмотреть файл

@@ -10,17 +10,16 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
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.
*/
class EtablissementController extends BackendController
{
public function behaviors()
{
class EtablissementController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
@@ -29,88 +28,83 @@ class EtablissementController extends BackendController
],
],
'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);
$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()) {
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]);
} else {
return $this->render('update', [
'model' => $model,
'model' => $model,
]);
}
}
public function actionFacturation()
{

public function actionFacturation() {
$datas_factures = new ActiveDataProvider([
'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' => [
'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', [
'datas_factures' => $datas_factures,
'etablissement' => $etablissement,
'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false
]);
}
protected function findModel($id)
{

protected function findModel($id) {
if (($model = Etablissement::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

+ 45
- 60
backend/controllers/PaiementController.php Просмотреть файл

@@ -15,37 +15,34 @@ use c006\paypal_ipn\PayPal_Ipn;
/**
* 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 [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
'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;
}
]
],
],
];
}
@@ -54,62 +51,50 @@ class PaiementController extends BackendController
* Lists all Produit models.
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {

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;
return parent::beforeAction($action);
}
public function actionIpn()
{

public function actionIpn() {
if (isset($_POST)) {
$ipn = new PayPal_Ipn(false);
if ($ipn->init())
{
if ($ipn->init()) {
$custom = $ipn->getKeyValue('custom');
$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 */
Yii::$app->request->enableCsrfValidation = true;
}

}

+ 48
- 57
backend/controllers/PointVenteController.php Просмотреть файл

@@ -10,34 +10,32 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\User;
use common\models\PointVenteUser ;
use common\models\PointVenteUser;

/**
* PointVenteController implements the CRUD actions for PointVente model.
*/
class PointVenteController extends BackendController
{
public function behaviors()
{
class PointVenteController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
'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;
}
],
],
],
];
}
@@ -46,15 +44,14 @@ class PointVenteController extends BackendController
* Lists all PointVente models.
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {

$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', [
'dataProvider' => $dataProvider,
'dataProvider' => $dataProvider,
]);
}

@@ -63,10 +60,9 @@ class PointVenteController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
'model' => $this->findModel($id),
]);
}

@@ -75,17 +71,16 @@ class PointVenteController extends BackendController
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
public function actionCreate() {
$model = new PointVente();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->gestionPointFabrication() ;
$model->gestionAccesRestreint() ;
$model->gestionPointFabrication();
$model->gestionAccesRestreint();
return $this->redirect(['index']);
} else {
return $this->render('update', array_merge($this->initForm(),[
'model' => $model,
return $this->render('update', array_merge($this->initForm(), [
'model' => $model,
]));
}
}
@@ -96,39 +91,36 @@ class PointVenteController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
public function actionUpdate($id) {
$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()) {
$model->gestionPointFabrication() ;
$model->gestionAccesRestreint() ;
$model->gestionPointFabrication();
$model->gestionAccesRestreint();
return $this->redirect(['index']);
} 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()
->orderBy('nom ASC')
->all() ;
->all();
return [
'users' => $users
] ;
];
}

/**
@@ -137,10 +129,9 @@ class PointVenteController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
public function actionDelete($id) {
$this->findModel($id)->delete();
PointVenteUser::deleteAll(['id_point_vente' => $id]) ;
PointVenteUser::deleteAll(['id_point_vente' => $id]);

return $this->redirect(['index']);
}
@@ -152,12 +143,12 @@ class PointVenteController extends BackendController
* @return PointVente the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
protected function findModel($id) {
if (($model = PointVente::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 83
- 96
backend/controllers/ProduitController.php Просмотреть файл

@@ -3,7 +3,6 @@
namespace backend\controllers;

use common\models\ProductionProduit;

use Yii;
use yii\filters\AccessControl;
use common\models\Produit;
@@ -17,36 +16,32 @@ use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use common\helpers\Upload;


/**
* 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 [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
'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;
}
]
],
],
];
}
@@ -55,20 +50,19 @@ class ProduitController extends BackendController
* Lists all Produit models.
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {
$dataProvider = new ActiveDataProvider([
'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' => [
'pageSize' => 1000,
],
]);

return $this->render('index', [
'dataProvider' => $dataProvider,
'dataProvider' => $dataProvider,
]);
}

@@ -77,10 +71,9 @@ class ProduitController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
'model' => $this->findModel($id),
]);
}

@@ -89,35 +82,34 @@ class ProduitController extends BackendController
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
public function actionCreate() {
$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()) {
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']);
} else {
return $this->render('create', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -128,34 +120,33 @@ class ProduitController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$request = Yii::$app->request ;
public function actionUpdate($id) {
$request = Yii::$app->request;

$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']);
} else {
return $this->render('update', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -166,28 +157,24 @@ class ProduitController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
public function actionDelete($id) {
$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']);
}
public function actionOrdre($tab)
{

public function actionOrdre($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();
}
}

@@ -198,12 +185,12 @@ class ProduitController extends BackendController
* @return Produit the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
protected function findModel($id) {
if (($model = Produit::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 42
- 49
backend/controllers/SiteController.php Просмотреть файл

@@ -1,4 +1,5 @@
<?php

namespace backend\controllers;

use Yii;
@@ -13,17 +14,15 @@ use common\models\Etablissement;
use common\models\Production;
use common\models\Commande;


/**
* Site controller
*/
class SiteController extends BackendController
{
class SiteController extends BackendController {
/**
* @inheritdoc
*/
public function behaviors()
{
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
@@ -37,7 +36,7 @@ class SiteController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN
return Yii::$app->user->identity->status == USER::STATUS_ADMIN
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
}
],
@@ -46,7 +45,7 @@ class SiteController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
return Yii::$app->user->identity->status == USER::STATUS_ADMIN;
}
],
],
@@ -63,8 +62,7 @@ class SiteController extends BackendController
/**
* @inheritdoc
*/
public function actions()
{
public function actions() {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
@@ -72,33 +70,32 @@ class SiteController extends BackendController
];
}

public function actionIndex()
{
public function actionIndex() {
// commandes
$productions = Production::find()
->with('commande')
->where(['>=','production.date',date('Y-m-d')])
->where(['>=', 'production.date', date('Y-m-d')])
->andWhere([
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement,
'production.actif' => 1
])
->orderBy('date ASC')
->limit(5)
->all() ;
->limit(5)
->all();
// dernières commandes
$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
$nb_clients = User::findBy()->count();
$clients = User::findBy()
->orderBy('created_at DESC')
->limit(5)
@@ -107,49 +104,45 @@ class SiteController extends BackendController
$clients_credit_pain_negatif = User::findBy(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->andWhere('user_etablissement.credit < 0')
->all();
// 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) {
return $this->goHome();
}

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login())
{
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
else {
} else {
return $this->render('login', [
'model' => $model,
'model' => $model,
]);
}
}

public function actionLogout()
{
public function actionLogout() {
Yii::$app->user->logout();

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']);
}

}

+ 48
- 53
backend/controllers/StatsController.php Просмотреть файл

@@ -7,89 +7,84 @@ use yii\filters\AccessControl;
use Yii;
use common\models\User;
use common\models\Commande;
use DateTime;
use DateInterval;
use DatePeriod;
use DateTime;
use DateInterval;
use DatePeriod;

class StatsController extends BackendController {
public function behaviors()
{

public function behaviors() {
return [
'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() {
/*
* 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
$data_labels = [] ;
$data_labels = [];

$start = new DateTime($date_start);
$interval = new DateInterval('P1M');
$end = new DateTime($date_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 = Commande::find()
->with('commandeProduits')
->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
$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', [
'data_labels' => $data_labels,
'data_pain' => $data_pain_noindex,
]);
]);
}
}

}

?>

+ 124
- 142
backend/controllers/UserController.php Просмотреть файл

@@ -10,21 +10,20 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
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.
*/
class UserController extends BackendController
{
public function behaviors()
{
class UserController extends BackendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
@@ -33,28 +32,26 @@ class UserController extends BackendController
],
],
'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;
}
}
]
],
],
];
}
@@ -63,20 +60,19 @@ class UserController extends BackendController
* Lists all User models.
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {
$params = Yii::$app->request->queryParams;
$query = User::findBy($params) ;
$query = User::findBy($params);
$dataProvider = new ActiveDataProvider([
'query' => $query
]);
$etablissement = Etablissement::find()
->where(['id' => Yii::$app->user->identity->id_etablissement])
->one() ;
->one();
return $this->render('index', [
'dataProvider' => $dataProvider,
'etablissement' => $etablissement
@@ -88,10 +84,9 @@ class UserController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
'model' => $this->findModel($id),
]);
}

@@ -100,49 +95,46 @@ class UserController extends BackendController
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
public function actionCreate() {
$model = new User();

if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') {
// save use
$password = Password::generate() ;
$password = Password::generate();
$model->setPassword($password);
$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
$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
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(
['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']);
} else {
return $this->render('create', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -153,114 +145,106 @@ class UserController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
public function actionUpdate($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()) {
return $this->redirect(['index']);
return $this->redirect(['index']);
} else {
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.");
}
}

public function actionMail() {
$users = (new \yii\db\Query())
->select('*')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user')
->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', [
//'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()
->with(['commande','userAction'])
->with(['commande', 'userAction'])
->where([
'id_user' => $user->id,
'id_etablissement' => Yii::$app->user->identity->id_etablissement,
])
->orderBy('date DESC')
->all() ;
->all();
return $this->render('credit', [
'user' => $user,
'credit_historique' => $credit_historique,
'historique' => $historique
]) ;
]);
}
else {
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()
->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)
$c->init();
return $this->render('commandes', [
'commandes' => $commandes,
'user' => $user
]) ;
]);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
@@ -268,14 +252,12 @@ class UserController extends BackendController
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
protected function findModel($id) {
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 84
- 94
backend/controllers/VracController.php Просмотреть файл

@@ -3,7 +3,6 @@
namespace backend\controllers;

use common\models\ProductionProduit;

use Yii;
use yii\filters\AccessControl;
use common\models\Produit;
@@ -15,17 +14,14 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;


/**
* 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 [
'verbs' => [
'class' => VerbFilter::className(),
@@ -34,17 +30,17 @@ class VracController extends BackendController
],
],
'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;
}
]
],
],
];
}
@@ -53,8 +49,7 @@ class VracController extends BackendController
* Lists all Produit models.
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {
$dataProvider = new ActiveDataProvider([
'query' => Produit::find()->where('vrac = 1')->orderBy('order ASC'),
]);
@@ -69,8 +64,7 @@ class VracController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
@@ -81,38 +75,37 @@ class VracController extends BackendController
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
public function actionCreate() {
$model = new Produit();
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']);
} else {
return $this->render('create', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -123,30 +116,29 @@ class VracController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$request = Yii::$app->request ;
public function actionUpdate($id) {
$request = Yii::$app->request;

$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']);
} else {
return $this->render('update', [
@@ -154,19 +146,18 @@ class VracController extends BackendController
]);
}
}
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();
}

/**
@@ -175,15 +166,14 @@ class VracController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
public function actionDelete($id) {
$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']);
}

@@ -194,12 +184,12 @@ class VracController extends BackendController
* @return Produit the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
protected function findModel($id) {
if (($model = Produit::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 9
- 11
backend/models/MailForm.php Просмотреть файл

@@ -8,16 +8,15 @@ use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class MailForm extends Model
{
class MailForm extends Model {
public $subject;
public $body;

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
// name, email, subject and body are required
[['subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
@@ -27,11 +26,10 @@ class MailForm extends Model
/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'subject' => 'Sujet',
'body' => 'Message',
'subject' => 'Sujet',
'body' => 'Message',
];
}

@@ -41,9 +39,8 @@ class MailForm extends Model
* @param string $email the target email address
* @return boolean whether the email was sent
*/
public function sendEmail($email)
{
public function sendEmail($email) {

return Yii::$app->mailer->compose()
->setTo($email)
->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes'])
@@ -51,4 +48,5 @@ class MailForm extends Model
->setTextBody($this->body)
->send();
}

}

+ 8
- 11
common/controllers/CommonController.php Просмотреть файл

@@ -2,21 +2,18 @@

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);
}
}

?>

+ 263
- 320
common/models/Commande.php Просмотреть файл

@@ -3,8 +3,8 @@
namespace common\models;

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".
@@ -16,122 +16,109 @@ use common\models\Etablissement ;
* @property integer $id_point_vente
* @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
*/
public static function tableName()
{
public static function tableName() {
return 'commande';
}
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) {
$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
*/
public function getUser() {
return $this->hasOne(User::className(), ['id'=>'id_user']) ;
return $this->hasOne(User::className(), ['id' => 'id_user']);
}
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() {
return $this->hasOne(Production::className(), ['id'=>'id_production'])->with('etablissement') ;
return $this->hasOne(Production::className(), ['id' => 'id_production'])->with('etablissement');
}
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
*/
public function rules()
{
public function rules() {
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'],
[['date', 'date_update','commentaire', 'commentaire_point_vente'], 'safe']
[['date', 'date_update', 'commentaire', 'commentaire_point_vente'], 'safe']
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_user' => 'Id User',
@@ -141,297 +128,253 @@ class Commande extends \yii\db\ActiveRecord
'id_production' => 'Date de production',
];
}
public function strListeVrac()
{
$str = '' ;
foreach($this->commandeProduits as $cp) {
if($cp->produit->vrac) {
$str .= $cp->quantite.'&nbsp;'.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 . '&nbsp;' . 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()
->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
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
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
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 = [
'produits'=> [],
'produits' => [],
'montant' => $commande->montant,
'str_montant' => $commande->getMontantFormat(),
'str_montant' => $commande->getMontantFormat(),
'montant_paye' => $commande->getMontantPaye(),
'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
if($this->getMontant() - $this->getMontantPaye() < 0)
{
return self::STATUT_SURPLUS ;
if ($this->getMontant() - $this->getMontantPaye() < 0) {
return self::STATUT_SURPLUS;
}
// 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
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);
$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 />
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()
->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']);
if(isset($params['date']))
if (isset($params['date']))
$commandes = $commandes->andWhere(['production.date' => $params['date']]);
if(isset($params['type']))
if (isset($params['type']))
$commandes = $commandes->andWhere(['commande.type' => $params['type']]);
if(isset($params['orderby']))
if (isset($params['orderby']))
$commandes = $commandes->orderBy($params['orderby']);
else
else
$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'));
$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) {
$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
return $str ;
return $str;
}
}

+ 128
- 157
common/models/CommandeAuto.php Просмотреть файл

@@ -3,12 +3,11 @@
namespace common\models;

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".
@@ -30,35 +29,31 @@ use common\models\CommandeProduit ;
* @property string $username
* @property string $paiement_automatique
*/
class CommandeAuto extends \yii\db\ActiveRecord
{
class CommandeAuto extends \yii\db\ActiveRecord {

/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'commande_auto';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_etablissement', 'id_point_vente'], 'required'],
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'],
[['paiement_automatique'], 'boolean'],
[['date_debut', 'date_fin','username'], 'safe'],
[['date_debut', 'date_fin', 'username'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_user' => 'Utilisateur',
@@ -77,196 +72,172 @@ class CommandeAuto extends \yii\db\ActiveRecord
'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 = self::find()
->with('commandeAutoProduit')
->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
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
$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 = 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::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()
->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::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 = 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()
->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
$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
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()
->with('commandeProduits')
->where(['id' => $commande->id])
->one() ;
->one();

$commande->init() ;
$commande->init();

$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;
else
$id_user_action = NULL ;
$id_user_action = NULL;

if($commande->getMontant() > 0)
{
if ($commande->getMontant() > 0) {
$commande->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$commande->getMontant(),
$production->id_etablissement,
$id_user_action
) ;
CreditHistorique::TYPE_PAIEMENT, $commande->getMontant(), $production->id_etablissement, $id_user_action
);
}
}
}
}
}

}

+ 93
- 102
common/models/CommandeAutoForm.php Просмотреть файл

@@ -1,129 +1,120 @@
<?php

namespace common\models;

use Yii;
use yii\base\Model;
use common\models\CommandeAuto ;
use common\models\CommandeAutoProduit ;
use common\models\CommandeAuto;
use common\models\CommandeAutoProduit;

/**
* 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_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
*/
public function rules()
{
public function rules() {
return [
[['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'],
[['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) {
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
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;
}

}

+ 10
- 13
common/models/CommandeAutoProduit.php Просмотреть файл

@@ -3,7 +3,7 @@
namespace common\models;

use Yii;
use common\models\Produit ;
use common\models\Produit;

/**
* This is the model class for table "commande_auto_produit".
@@ -13,21 +13,19 @@ use common\models\Produit ;
* @property integer $id_produit
* @property double $quantite
*/
class CommandeAutoProduit extends \yii\db\ActiveRecord
{
class CommandeAutoProduit extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'commande_auto_produit';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_commande_auto', 'id_produit'], 'required'],
[['id_commande_auto', 'id_produit'], 'integer'],
@@ -38,8 +36,7 @@ class CommandeAutoProduit extends \yii\db\ActiveRecord
/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_commande_auto' => 'Id Commande Auto',
@@ -47,9 +44,9 @@ class CommandeAutoProduit extends \yii\db\ActiveRecord
'quantite' => 'Quantite',
];
}
public function getProduit()
{
return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ;

public function getProduit() {
return $this->hasOne(Produit::className(), ['id' => 'id_produit']);
}

}

+ 10
- 12
common/models/CommandeProduit.php Просмотреть файл

@@ -12,41 +12,38 @@ use Yii;
* @property integer $id_produit
* @property double $quantite
*/
class CommandeProduit extends \yii\db\ActiveRecord
{
class CommandeProduit extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'commande_produit';
}
/*
* Relations
*/
public function getProduit() {
return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ;
return $this->hasOne(Produit::className(), ['id' => 'id_produit']);
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_commande', 'id_produit', 'quantite'], 'required'],
[['id_commande', 'id_produit'], 'integer'],
[['quantite'], 'number','min' => 0]
[['quantite'], 'number', 'min' => 0]
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_commande' => 'Id Commande',
@@ -54,4 +51,5 @@ class CommandeProduit extends \yii\db\ActiveRecord
'quantite' => 'Quantite',
];
}

}

+ 58
- 71
common/models/CreditHistorique.php Просмотреть файл

@@ -3,9 +3,9 @@
namespace common\models;

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".
@@ -19,46 +19,42 @@ use common\models\Commande ;
* @property integer $id_etablissement
* @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
*/
public static function tableName()
{
public static function tableName() {
return 'credit_historique';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['montant'], 'required'],
[['id_user','id_user_action', 'id_commande', 'id_etablissement'], 'integer'],
[['id_user', 'id_user_action', 'id_commande', 'id_etablissement'], 'integer'],
[['date'], 'safe'],
[['montant'], 'double'],
[['type', 'moyen_paiement','commentaire'], 'string', 'max' => 255],
[['type', 'moyen_paiement', 'commentaire'], 'string', 'max' => 255],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_user' => 'Utilisateur',
@@ -72,61 +68,52 @@ class CreditHistorique extends ActiveRecord
'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) {
parent::save($runValidation, $attributeNames) ;
parent::save($runValidation, $attributeNames);
$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();
}
}

}

+ 20
- 21
common/models/Developpement.php Просмотреть файл

@@ -3,7 +3,7 @@
namespace common\models;

use Yii;
use common\models\DeveloppementPriorite ;
use common\models\DeveloppementPriorite;

/**
* This is the model class for table "developpement".
@@ -18,12 +18,11 @@ use common\models\DeveloppementPriorite ;
*/
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
*/
@@ -39,18 +38,18 @@ class Developpement extends \yii\db\ActiveRecord {
[['objet', 'date'], 'required'],
[['id', 'avancement'], 'integer'],
[['description'], 'string'],
[['date','date_livraison'], 'safe'],
[['date', 'date_livraison'], 'safe'],
[['estimation_temps'], 'number'],
[['objet', 'statut','type'], 'string', 'max' => 255],
[['objet', 'statut', 'type'], 'string', 'max' => 255],
];
}
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() {
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');
}

/**
@@ -69,14 +68,14 @@ class Developpement extends \yii\db\ActiveRecord {
'date_livraison' => 'Date de livraison'
];
}
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));
}
}

+ 28
- 26
common/models/DeveloppementPriorite.php Просмотреть файл

@@ -3,7 +3,7 @@
namespace common\models;

use Yii;
use common\models\Etablissement ;
use common\models\Etablissement;

/**
* This is the model class for table "developpement_priorite".
@@ -13,10 +13,10 @@ use common\models\Etablissement ;
*/
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
*/
@@ -34,9 +34,9 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord {
[['priorite'], 'string'],
];
}
public function getEtablissement() {
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ;
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']);
}

/**
@@ -49,28 +49,30 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord {
'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() {
$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;
}

}

+ 137
- 166
common/models/Etablissement.php Просмотреть файл

@@ -3,8 +3,8 @@
namespace common\models;

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".
@@ -18,56 +18,50 @@ use yii\helpers\Html ;
* @property string $code_postal
* @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
*/
public static function tableName()
{
public static function tableName() {
return 'etablissement';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'nom' => 'Nom',
@@ -87,132 +81,113 @@ class Etablissement extends \yii\db\ActiveRecord
'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()
->where(['actif' => 1])
->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
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();
$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();
$ca = $result['CA'] ;
if($format)
return number_format($ca, 2).' €' ;
$ca = $result['CA'];
if ($format)
return number_format($ca, 2) . ' €';
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()
->where('id_etablissement = :id_etablissement')
->andWhere('periode = :periode')
@@ -220,38 +195,34 @@ class Etablissement extends \yii\db\ActiveRecord
':id_etablissement' => $this->id,
':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) . ' €';
}
}

}

+ 14
- 18
common/models/Facture.php Просмотреть файл

@@ -18,40 +18,36 @@ use Yii;
* @property string $date_paiement
* @property string $methode_paiement
*/
class Facture extends \yii\db\ActiveRecord
{
class Facture extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'facture';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_etablissement', 'paye'], 'integer'],
[['date', 'date_paiement'], 'safe'],
[['texte'], 'string'],
[['montant_ht','ca'], 'number'],
[['montant_ht', 'ca'], 'number'],
[['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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_etablissement' => 'Id Etablissement',
@@ -66,11 +62,11 @@ class Facture extends \yii\db\ActiveRecord
'ca' => 'CA'
];
}
public static function getLastFacture()
{

public static function getLastFacture() {
return Facture::find()
->orderBy('reference DESC')
->one() ;
->orderBy('reference DESC')
->one();
}

}

+ 29
- 37
common/models/LoginForm.php Просмотреть файл

@@ -1,4 +1,5 @@
<?php

namespace common\models;

use Yii;
@@ -7,30 +8,25 @@ use yii\base\Model;
/**
* Login form
*/
class LoginForm extends Model
{
class LoginForm extends Model {
public $username;
public $password;
public $rememberMe = true;
public $email;

private $_user = false;


/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
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
[ 'password', 'required','message'=>'Champs obligatoire'],
[ 'password', 'required', 'message' => 'Champs obligatoire'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
@@ -45,8 +41,7 @@ class LoginForm extends Model
* @param string $attribute the attribute currently being validated
* @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()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
@@ -60,10 +55,9 @@ class LoginForm extends Model
*
* @return boolean whether the user is logged in successfully
*/
public function login()
{
public function login() {
if ($this->validate()) {
$this->updateDerniereConnexion() ;
$this->updateDerniereConnexion();
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
@@ -75,30 +69,28 @@ class LoginForm extends Model
*
* @return User|null
*/
public function getUser()
{
public function getUser() {
if ($this->_user === false) {
$this->_user = User::findByEmail($this->email) ;
$this->_user = User::findByEmail($this->email);
}

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();
}

}

+ 113
- 137
common/models/PointVente.php Просмотреть файл

@@ -3,9 +3,9 @@
namespace common\models;

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".
@@ -15,49 +15,45 @@ use common\models\ProductionPointVente ;
* @property string $adresse
* @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
*/
public static function tableName()
{
public static function tableName() {
return 'point_vente';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['nom'], 'required'],
[['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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'nom' => 'Nom',
@@ -83,138 +79,118 @@ class PointVente extends \yii\db\ActiveRecord
'livraison_samedi' => 'Samedi',
'livraison_dimanche' => 'Dimanche',
'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) {
$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() {
$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(
['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()
->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;
}
}

}

+ 6
- 8
common/models/PointVenteUser.php Просмотреть файл

@@ -10,21 +10,19 @@ use Yii;
* @property integer $id_point_vente
* @property integer $id_user
*/
class PointVenteUser extends \yii\db\ActiveRecord
{
class PointVenteUser extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'point_vente_user';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_point_vente', 'id_user'], 'required'],
[['id_point_vente', 'id_user'], 'integer'],
@@ -35,12 +33,12 @@ class PointVenteUser extends \yii\db\ActiveRecord
/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id_point_vente' => 'Id Point Vente',
'id_user' => 'Id User',
'commentaire' => 'Commentaire'
];
}

}

+ 28
- 39
common/models/Production.php Просмотреть файл

@@ -3,7 +3,7 @@
namespace common\models;

use Yii;
use common\models\Commande ;
use common\models\Commande;

/**
* This is the model class for table "production".
@@ -12,25 +12,23 @@ use common\models\Commande ;
* @property string $date
* @property integer $actif
*/
class Production extends \yii\db\ActiveRecord
{
class Production extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'production';
}
public function getEtablissement() {
return $this->hasOne(Etablissement::className(), ['id'=>'id_etablissement']) ;
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']);
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['date'], 'required'],
[['date'], 'safe'],
@@ -41,45 +39,36 @@ class Production extends \yii\db\ActiveRecord
/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'date' => 'Date',
'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;
}

}

+ 51
- 65
common/models/ProductionPointVente.php Просмотреть файл

@@ -3,8 +3,8 @@
namespace common\models;

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".
@@ -13,24 +13,21 @@ use common\models\Production ;
* @property integer $id_point_vente
* @property integer $livraison
*/
class ProductionPointVente extends \yii\db\ActiveRecord
{
var $productions_point_vente ;
class ProductionPointVente extends \yii\db\ActiveRecord {

var $productions_point_vente;

/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'production_point_vente';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['id_production', 'id_point_vente'], 'required'],
[['id_production', 'id_point_vente', 'livraison'], 'integer'],
@@ -40,84 +37,73 @@ class ProductionPointVente extends \yii\db\ActiveRecord
/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id_production' => 'Id Production',
'id_point_vente' => 'Id Point Vente',
'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()->
where([
'id_production' => $id_production
])
->count() ;
if(!$count_productions_point_vente)
{
->count();

if (!$count_productions_point_vente) {
$points_vente = PointVente::find()
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->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()
->with(['production','pointVente'])
->with(['production', 'pointVente'])
->where([
'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();
}
}
}

}

+ 34
- 40
common/models/ProductionProduit.php Просмотреть файл

@@ -3,7 +3,6 @@
namespace common\models;

use yii\base\Object;

use Yii;

/**
@@ -14,36 +13,32 @@ use Yii;
* @property integer $id_produit
* @property integer $actif
*/
class ProductionProduit extends \yii\db\ActiveRecord
{
class ProductionProduit extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'production_produit';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'id_production' => 'Id Production',
@@ -52,38 +47,37 @@ class ProductionProduit extends \yii\db\ActiveRecord
'quantite_max' => 'Quantité max',
];
}
public static function findProduits($id_production) {
$production_produits = ProductionProduit::find()
$production_produits = ProductionProduit::find()
->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] = [
'actif'=> (int) $pp->actif,
'actif' => (int) $pp->actif,
'epuise' => (int) $pp->produit->epuise,
'vrac' => (int) $pp->produit->vrac,
'quantite_max' => $pp->quantite_max,
'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;
}

}

+ 42
- 54
common/models/Produit.php Просмотреть файл

@@ -18,40 +18,36 @@ use Yii;
* @property double $poids
* @property string $recette
*/
class Produit extends \yii\db\ActiveRecord
{
var $total = 0 ;
class Produit extends \yii\db\ActiveRecord {

var $total = 0;

/**
* @inheritdoc
*/
public static function tableName()
{
public static function tableName() {
return 'produit';
}

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
[['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'],
[['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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id' => 'ID',
'nom' => 'Nom',
@@ -75,62 +71,54 @@ class Produit extends \yii\db\ActiveRecord
'epuise' => 'Épuisé',
];
}

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()
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement,
])
])
->orderBy('order ASC')
->all();
}
public function getByProduction($id_production)
{

public function getByProduction($id_production) {
return Produit::find()
->leftJoin('production_produit', 'produit.id = production_produit.id_produit')
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement,
'production_produit.id_production' => $id_production
])
])
->orderBy('production_produit.actif DESC, produit.order ASC')
->all();
}
public static function count()
{

public static function count() {
return Produit::find()
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement
])
->count() ;
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement
])
->count();
}

}

+ 158
- 198
common/models/User.php Просмотреть файл

@@ -1,4 +1,5 @@
<?php

namespace common\models;

use Yii;
@@ -23,30 +24,28 @@ use yii\web\IdentityInterface;
* @property string $password write-only password
* @property boolean $confiance
*/
class User extends ActiveRecord implements IdentityInterface
{
class User extends ActiveRecord implements IdentityInterface {
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
const STATUS_BOULANGER = 11;
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
*/
public static function tableName()
{
public static function tableName() {
return '{{%user}}';
}

/**
* @inheritdoc
*/
public function behaviors()
{
public function behaviors() {
return [
TimestampBehavior::className(),
];
@@ -55,90 +54,77 @@ class User extends ActiveRecord implements IdentityInterface
/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
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 ');
}
public function getUserEtablissement() {
return $this->hasMany(UserEtablissement::className(), ['id_user'=>'id']) ;
return $this->hasMany(UserEtablissement::className(), ['id_user' => 'id']);
}
/**
* @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
*/
public static function findIdentityByAccessToken($token, $type = null)
{
public static function findIdentityByAccessToken($token, $type = null) {
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}

@@ -148,14 +134,12 @@ class User extends ActiveRecord implements IdentityInterface
* @param string $username
* @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 */]);
}

/**
@@ -164,40 +148,37 @@ class User extends ActiveRecord implements IdentityInterface
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
public static function findByPasswordResetToken($token) {
if (!static::isPasswordResetTokenValid($token)) {
return null;
}

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())
->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')
->where('user.id = user_etablissement.id_user')
->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']]);
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;
}

/**
@@ -206,8 +187,7 @@ class User extends ActiveRecord implements IdentityInterface
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
public static function isPasswordResetTokenValid($token) {
if (empty($token)) {
return false;
}
@@ -220,24 +200,21 @@ class User extends ActiveRecord implements IdentityInterface
/**
* @inheritdoc
*/
public function getId()
{
public function getId() {
return $this->getPrimaryKey();
}

/**
* @inheritdoc
*/
public function getAuthKey()
{
public function getAuthKey() {
return $this->auth_key;
}

/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
public function validateAuthKey($authKey) {
return $this->getAuthKey() === $authKey;
}

@@ -247,8 +224,7 @@ class User extends ActiveRecord implements IdentityInterface
* @param string $password password to validate
* @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);
}

@@ -257,132 +233,116 @@ class User extends ActiveRecord implements IdentityInterface
*
* @param string $password
*/
public function setPassword($password)
{
public function setPassword($password) {
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}

/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
public function generateAuthKey() {
$this->auth_key = Yii::$app->security->generateRandomString();
}

/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
public function generatePasswordResetToken() {
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}

/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
public function removePasswordResetToken() {
$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())
->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()
->where([
'id_user' => $this->id,
'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() {
$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();
}
}

+ 0
- 46
common/models/UserBoulangerie.php Просмотреть файл

@@ -1,46 +0,0 @@
<?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',
];
}
}

+ 1
- 1
common/models/UserEtablissement.php Просмотреть файл

@@ -27,7 +27,7 @@ class UserEtablissement extends \yii\db\ActiveRecord {
[['id_user', 'id_etablissement'], 'required'],
[['id_user', 'id_etablissement'], 'integer'],
[['actif'], 'boolean'],
[['credit'],'double'],
[['credit'], 'double'],
];
}


+ 166
- 205
frontend/controllers/CommandeController.php Просмотреть файл

@@ -15,10 +15,10 @@ use common\helpers\Departements;
use yii\helpers\Html;
use frontend\models\AddEtablissementForm;
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;

class CommandeController extends FrontendController {
@@ -42,31 +42,28 @@ class CommandeController extends FrontendController {
$production = Production::findOne($id_production);

if ($production) {
$arr = [] ;
$arr = [];
$produits_dispos = ProductionProduit::findProduits($production->id);

$arr['produits_dispos'] = $produits_dispos ;
$arr['produits_dispos'] = $produits_dispos;
$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([
'id_etablissement' => $production->id_etablissement,
])
->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;
}
}

@@ -79,48 +76,45 @@ class CommandeController extends FrontendController {
public static function initForm($commande = null) {

// 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);
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::findOne($id_etablissement) ;
$etablissement = Etablissement::findOne($id_etablissement);
// points de vente
$points_vente = PointVente::find()
->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)')
->params([':id_user' => Yii::$app->user->identity->id])
->all();
$arr_points_vente = $points_vente;

// 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) {
$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 {
$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()
->where(['actif' => 1])
->andWhere('date > :date')
->andWhere(['id_etablissement'=>$id_etablissement])
->andWhere(['id_etablissement' => $id_etablissement])
->addParams([':date' => $date])
->all();

@@ -130,10 +124,10 @@ class CommandeController extends FrontendController {

// produits
$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();
foreach ($produits as $p)
$arr_produits[] = $p;
@@ -169,22 +163,20 @@ class CommandeController extends FrontendController {
$commandes = Commande::find()
->where(['id_user' => Yii::$app->user->identity->id])
->all();
if($id_etablissement)
{

if ($id_etablissement) {
$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 [
'points_vente' => $arr_points_vente,
'jours_production' => $arr_jours_production,
@@ -204,26 +196,24 @@ class CommandeController extends FrontendController {

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
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris();
// 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
$commandes = Commande::find()
->with('commandeProduits', 'pointVente', 'creditHistorique')
->joinWith('production','production.etablissement')
->joinWith('production', 'production.etablissement')
->where(['id_user' => Yii::$app->user->id])
//->andWhere('production.date < '.)
->orderBy('production.date DESC')
@@ -233,29 +223,28 @@ class CommandeController extends FrontendController {
// initilisation commandes
foreach ($commandes as $c)
$c->init();
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()
->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) {
@@ -264,9 +253,9 @@ class CommandeController extends FrontendController {

$posts = Yii::$app->request->post();

if($id_etablissement)
$this->_verifEtablissementActif($id_etablissement) ;
if ($id_etablissement)
$this->_verifEtablissementActif($id_etablissement);
if ($commande->load($posts)) {

$commande = Commande::find()->where('id_production = ' . $posts['Commande']['id_production'])->andWhere('id_user = ' . Yii::$app->user->id)->one();
@@ -275,14 +264,14 @@ class CommandeController extends FrontendController {
$commande->load(Yii::$app->request->post());
$commande->id_user = Yii::$app->user->id;
$commande->date = date('Y-m-d H:i:s');
$commande->type = Commande::TYPE_USER ;
$commande->type = Commande::TYPE_USER;
}
$this->gestionForm($commande);
}

return $this->render('create', array_merge(self::initForm($commande), [
'model' => $commande
'model' => $commande
]));
}

@@ -293,15 +282,13 @@ class CommandeController extends FrontendController {
->where(['id' => $id])
->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');
$this->gestionForm($commande);
}
@@ -312,12 +299,10 @@ class CommandeController extends FrontendController {
'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.');
}
}
@@ -358,50 +343,45 @@ class CommandeController extends FrontendController {
$err_date = true;
}
}
// point de vente
$err_point_vente = false ;
if(isset($production) && $production)
{
$err_point_vente = false;
if (isset($production) && $production) {

$ppv = ProductionPointVente::find()
->where([
'id_production' => $production->id,
'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) {
// gestion point de vente
$pv = PointVente::find()
->with('pointVenteUser')
->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
$commande->commentaire_point_vente = '' ;
$commande->commentaire_point_vente = '';
// sauvegarde de la commande
$commande->save();

@@ -429,67 +409,55 @@ class CommandeController extends FrontendController {
$quantite_voulue = $produits_dispos[$p->id]['quantite_restante'];

$commande_produit->quantite = $quantite_voulue;
$commande_produit->save();
}
}
// 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()
->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
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(
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
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(
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
$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie]));
}
else {
} else {
if (!count($produits))
Yii::$app->session->setFlash('error', "Vous n'avez choisi aucun produit");
if ($err_nb_produits)
Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander plus de 3 produits");
if ($err_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.");
}
}
@@ -497,26 +465,21 @@ class CommandeController extends FrontendController {
public function actionAnnuler($id) {

$commande = Commande::find()
->with('production','creditHistorique','commandeProduits')
->with('production', 'creditHistorique', 'commandeProduits')
->where(['id' => $id])
->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) {
// remboursement
if($commande->getMontantPaye())
{
if ($commande->getMontantPaye()) {
$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
$commande->delete();
@@ -525,18 +488,16 @@ class CommandeController extends FrontendController {

$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;
}

}

+ 3
- 5
frontend/controllers/FrontendController.php Просмотреть файл

@@ -2,12 +2,10 @@

namespace frontend\controllers;

use yii ;
use common\controllers\CommonController ;
use yii;
use common\controllers\CommonController;

class FrontendController extends CommonController
{
class FrontendController extends CommonController {
}


+ 110
- 130
frontend/controllers/SiteController.php Просмотреть файл

@@ -1,4 +1,5 @@
<?php

namespace frontend\controllers;

use Yii;
@@ -16,25 +17,22 @@ use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\helpers\Html;
use frontend\controllers\FrontendController;
use common\models\UserEtablissement ;

use common\models\UserEtablissement;
use dosamigos\leaflet\types\LatLng;
use dosamigos\leaflet\layers\Marker;
use dosamigos\leaflet\layers\TileLayer;
use dosamigos\leaflet\LeafLet;
use dosamigos\leaflet\widgets\Map;


/**
* Site controller
*/
class SiteController extends FrontendController
{
class SiteController extends FrontendController {
/**
* @inheritdoc
*/
public function behaviors()
{
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
@@ -64,8 +62,7 @@ class SiteController extends FrontendController
/**
* @inheritdoc
*/
public function actions()
{
public function actions() {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
@@ -77,68 +74,65 @@ class SiteController extends FrontendController
];
}

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
$center = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']);
$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 &copy; <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 &copy; <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([
'tileLayer' => $tileLayer,
'center' => $center
]);
'tileLayer' => $tileLayer,
'center' => $center
]);
$point = new LatLng(['lat' => '46,9991224', 'lng' => '6,0582595']);
$marker = new Marker(['latLng' => $point, 'popupContent' => Html::encode('Le Chat des Noisettes')]);
$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() {
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) {
return Yii::$app->getResponse()->redirect(['commande/index']);
}
@@ -148,20 +142,18 @@ class SiteController extends FrontendController
return $this->goBack(['commande/index']);
} else {
return $this->render('login', [
'model' => $model,
'model' => $model,
]);
}
}

public function actionLogout()
{
public function actionLogout() {
Yii::$app->user->logout();

return $this->goHome();
}

public function actionContact()
{
public function actionContact() {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
@@ -173,42 +165,39 @@ class SiteController extends FrontendController
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
'model' => $model,
]);
}
}

public function actionAbout()
{
public function actionAbout() {
return $this->render('about');
}

public function actionSignup()
{
public function actionSignup() {
$model = new SignupForm();
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->signup()) {
if (Yii::$app->getUser()->login($user)) {
$this->redirect(['commande/index']) ;
$this->redirect(['commande/index']);
}
}
}

// 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', [
'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();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
@@ -221,12 +210,11 @@ class SiteController extends FrontendController
}

return $this->render('requestPasswordResetToken', [
'model' => $model,
'model' => $model,
]);
}

public function actionResetPassword($token)
{
public function actionResetPassword($token) {
try {
$model = new ResetPasswordForm($token);
} catch (InvalidParamException $e) {
@@ -240,78 +228,70 @@ class SiteController extends FrontendController
}

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_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
$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())) {

$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 (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,
]);
}

}

+ 41
- 48
frontend/controllers/UserController.php Просмотреть файл

@@ -14,28 +14,26 @@ use frontend\controllers\FrontendController;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends FrontendController
{
public function behaviors()
{
class UserController extends FrontendController {

public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
'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 ;
} */
]
],
],
];
}
@@ -46,55 +44,50 @@ class UserController extends FrontendController
* @param integer $id
* @return mixed
*/
public function actionUpdate()
{
public function actionUpdate() {
$model = $this->findModel(Yii::$app->user->identity->id);

if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// 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
if(strlen($model->password_new))
{
if (strlen($model->password_new)) {
//$model->setPassword($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', [
'model' => $model,
'model' => $model,
]);
} 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', [
'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.
* If the model is not found, a 404 HTTP exception will be thrown.
@@ -102,12 +95,12 @@ class UserController extends FrontendController
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
protected function findModel($id) {
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 60
- 68
frontend/models/AddEtablissementForm.php Просмотреть файл

@@ -5,73 +5,66 @@ namespace frontend\models;
use Yii;
use yii\base\Model;
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.
*/
class AddEtablissementForm extends Model
{
class AddEtablissementForm extends Model {
public $id_etablissement;
public $code ;
public $code;

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
['id_etablissement','integer'],
['id_etablissement', 'integer'],
['id_etablissement', 'required'],
['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()
->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) {
$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 = $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
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'id_etablissement' => 'Établissement',
'code' => 'Code',
@@ -84,32 +77,31 @@ class AddEtablissementForm extends Model
* @param string $email the target email address
* @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()
->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.');
}

}

+ 15
- 18
frontend/models/ContactForm.php Просмотреть файл

@@ -8,8 +8,8 @@ use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
class ContactForm extends Model {
public $name;
public $email;
public $subject;
@@ -19,28 +19,26 @@ class ContactForm extends Model
/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
// 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', 'captcha','message'=> 'Veuillez recopier le code de vérification'],
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
public function attributeLabels() {
return [
'name' => 'Nom',
'email' => 'Email',
'subject' => 'Sujet',
'body' => 'Message',
'name' => 'Nom',
'email' => 'Email',
'subject' => 'Sujet',
'body' => 'Message',
'verifyCode' => 'Code de vérification',
];
}
@@ -51,18 +49,17 @@ class ContactForm extends Model
* @param string $email the target email address
* @return boolean whether the email was sent
*/
public function sendEmail($email)
{
public function sendEmail($email) {

return Yii::$app->mailer->compose([
'html' => 'contact-html',
'text' => 'contact-text'],
[ 'content' => $this->body,
'text' => 'contact-text'], [ 'content' => $this->body,
'nom' => $this->name
])
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('[La boîte à pain] Contact : '.$this->subject)
->setSubject('[La boîte à pain] Contact : ' . $this->subject)
->send();
}

}

+ 10
- 11
frontend/models/PasswordResetRequestForm.php Просмотреть файл

@@ -1,22 +1,22 @@
<?php

namespace frontend\models;

use common\models\User;
use yii\base\Model;
use yii ;
use yii;

/**
* Password reset request form
*/
class PasswordResetRequestForm extends Model
{
class PasswordResetRequestForm extends Model {
public $email;

/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
@@ -33,11 +33,10 @@ class PasswordResetRequestForm extends Model
*
* @return boolean whether the email was send
*/
public function sendEmail()
{
public function sendEmail() {
/* @var $user User */
$user = User::findOne([
'email' => $this->email,
'email' => $this->email,
]);

if ($user) {
@@ -45,9 +44,8 @@ class PasswordResetRequestForm extends Model
$user->generatePasswordResetToken();
}

if ($user->save())
{
if ($user->save()) {

return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain'])
->setTo($this->email)
@@ -58,4 +56,5 @@ class PasswordResetRequestForm extends Model

return false;
}

}

+ 10
- 13
frontend/models/ResetPasswordForm.php Просмотреть файл

@@ -1,4 +1,5 @@
<?php

namespace frontend\models;

use common\models\User;
@@ -9,8 +10,8 @@ use Yii;
/**
* Password reset form
*/
class ResetPasswordForm extends Model
{
class ResetPasswordForm extends Model {
public $password;

/**
@@ -18,7 +19,6 @@ class ResetPasswordForm extends Model
*/
private $_user;


/**
* Creates a form model given a token.
*
@@ -26,8 +26,7 @@ class ResetPasswordForm extends Model
* @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
*/
public function __construct($token, $config = [])
{
public function __construct($token, $config = []) {
if (empty($token) || !is_string($token)) {
throw new InvalidParamException('Password reset token cannot be blank.');
}
@@ -41,8 +40,7 @@ class ResetPasswordForm extends Model
/**
* @inheritdoc
*/
public function rules()
{
public function rules() {
return [
['password', 'required'],
['password', 'string', 'min' => 6],
@@ -54,19 +52,18 @@ class ResetPasswordForm extends Model
*
* @return boolean if password was reset.
*/
public function resetPassword()
{
public function resetPassword() {
$user = $this->_user;
$user->setPassword($this->password);
$user->removePasswordResetToken();

return $user->save();
}
public function attributeLabels()
{

public function attributeLabels() {
return [
'password' => 'Mot de passe',
'password' => 'Mot de passe',
];
}

}

+ 165
- 195
frontend/models/SignupForm.php Просмотреть файл

@@ -1,18 +1,19 @@
<?php

namespace frontend\models;

use Yii;
use common\models\User;
use common\models\Etablissement;
use yii\base\Model;
use common\models\UserEtablissement ;
use common\helpers\Password ;
use common\models\UserEtablissement;
use common\helpers\Password;

/**
* Signup form
*/
class SignupForm extends Model
{
class SignupForm extends Model {
public $username;
public $email;
public $password;
@@ -20,140 +21,118 @@ class SignupForm extends Model
public $prenom;
public $telephone;
public $is_boulanger;
public $siret;
public $nom_magasin;
public $code_postal;
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
*/
public function rules()
{
public function rules() {
return [
['email', 'filter', 'filter' => 'trim'],
['email', 'required','message'=>'Champs obligatoire'],
['email', 'required', 'message' => 'Champs obligatoire'],
['email', 'email'],
['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],
['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'],
['is_boulanger', 'boolean'],
['cgv', 'boolean'],
['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') ;
}"],
['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') ;
}"],
['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') ;
}"],
['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') ;
}"],
['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];
if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
if (($index % 2) == 0) {
if (($number *= 2) > 9)
$number -= 9;
}
$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) {
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) {
$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 = $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');
}
}],
];
}

@@ -162,126 +141,117 @@ class SignupForm extends Model
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
public function signup() {
if ($this->validate()) {
$user = new User();
$user->username = $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 = new Etablissement ;
$etablissement->nom = $this->nom_magasin ;
$etablissement = new Etablissement;
$etablissement->nom = $this->nom_magasin;
$etablissement->siret = $this->siret;
$etablissement->code_postal = $this->code_postal;
$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
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->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
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->generateAuthKey();
if ($user->save()) {
// 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
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 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',
];
}

}

Загрузка…
Отмена
Сохранить