@@ -1261,7 +1261,7 @@ class CommandeController extends BackendController { | |||
if (abs($commande->montant - $montant_paye) < 0.0001) { | |||
$html .= '<span class="label label-success">Payé</span>'; | |||
$buttons_credit = Html::a('Rembourser ' . $commande->getMontantFormat(), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $commande->montant, 'data-type' => 'remboursement']); | |||
$buttons_credit = Html::a('Rembourser ' . $commande->getMontant(true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $commande->montant, 'data-type' => 'remboursement']); | |||
} elseif ($commande->montant > $montant_paye) { | |||
$montant_payer = $commande->montant - $montant_paye; | |||
$html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($montant_payer, 2) . ' €</strong> à payer'; |
@@ -49,7 +49,8 @@ use common\helpers\Mail ; | |||
/** | |||
* ContactForm is the model behind the contact form. | |||
*/ | |||
class CreditForm extends Model { | |||
class CreditForm extends Model | |||
{ | |||
public $id_user ; | |||
public $id_user_action ; | |||
@@ -63,7 +64,8 @@ class CreditForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
[['montant'], 'required'], | |||
[['id_user', 'id_user_action', 'id_etablissement'], 'integer'], | |||
@@ -76,7 +78,8 @@ class CreditForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_user' => 'Utilisateur', | |||
'id_user_action' => 'Utilisateur', | |||
@@ -90,7 +93,11 @@ class CreditForm extends Model { | |||
]; | |||
} | |||
public function save() { | |||
/** | |||
* Enregistre un modèle CreditHistorique. | |||
*/ | |||
public function save() | |||
{ | |||
if ($this->validate()) { | |||
$credit_historique = new CreditHistorique ; | |||
$credit_historique->id_user = $this->id_user; | |||
@@ -115,7 +122,6 @@ class CreditForm extends Model { | |||
'credit_form' => $this | |||
]) ; | |||
} | |||
} | |||
} | |||
@@ -44,7 +44,8 @@ use yii\base\Model; | |||
/** | |||
* ContactForm is the model behind the contact form. | |||
*/ | |||
class MailForm extends Model { | |||
class MailForm extends Model | |||
{ | |||
public $subject; | |||
public $body; | |||
@@ -52,7 +53,8 @@ class MailForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
// name, email, subject and body are required | |||
[['subject', 'body'], 'required', 'message' => 'Champs obligatoire'], | |||
@@ -62,7 +64,8 @@ class MailForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'subject' => 'Sujet', | |||
'body' => 'Message', | |||
@@ -75,7 +78,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) |
@@ -230,21 +230,6 @@ if(!Yii::$app->user->isGuest) | |||
<?php endif; ?> | |||
<div class="clr"></div> | |||
<?php $etat_paiement_etablissement = Yii::$app->user->identity->etatPaiementEtablissement(); ?> | |||
<?php if ($etat_paiement_etablissement == 'essai'): ?> | |||
<span id="etat-paiement-etablissement">Période d'essai gratuite | |||
<span class="strong"><?php echo Yii::$app->user->identity->periodeEssai(); ?> jours</span> <a class="btn btn-success" href="<?php echo Yii::$app->urlManager->createUrl(['paiement/index']) ?>">S'abonner</a> | |||
</span> | |||
<?php elseif ($etat_paiement_etablissement == Etablissement::PAIEMENT_ESSAI_TERMINE || $etat_paiement_etablissement == Etablissement::PAIEMENT_RETARD): ?> | |||
<span id="etat-paiement-etablissement"> | |||
<span class="strong"> | |||
<?php if ($etat_paiement_etablissement == Etablissement::PAIEMENT_ESSAI_TERMINE): ?>Période d'essai gratuite terminée | |||
<?php elseif ($etat_paiement_etablissement == Etablissement::PAIEMENT_RETARD): ?>Retard de paiement | |||
<?php endif; ?> | |||
</span> | |||
</span> | |||
<?php endif; ?> | |||
</div> | |||
<?php endif; ?> | |||
@@ -46,45 +46,6 @@ use common\models\Etablissement ; | |||
$this->title = 'Paiement'; | |||
$etat_paiement = Yii::$app->user->identity->etatPaiementEtablissement() ; | |||
?> | |||
<h1>Paiement</h1> | |||
<div class="alert alert-warning"> | |||
<?php if($etat_paiement == Etablissement::PAIEMENT_ESSAI_TERMINE): ?> | |||
Votre période d'essai gratuite est terminée.<br /> | |||
Vous pouvez continuer à bénéficier de ce service en vous abonnant à <strong>La boîte à pain</strong> | |||
pour <strong>30 € / mois</strong> | |||
<?php elseif($etat_paiement == Etablissement::PAIEMENT_RETARD): ?> | |||
Nous constatons un retard de paiement sur votre compte.<br /> | |||
Nous vous invitons à vérifier que tout est en ordre au niveau de votre compte Paypal ou à vous | |||
abonner à nouveau en utilisant le bouton ci-dessous (<strong>30 € / mois</strong>). | |||
<?php elseif($etat_paiement == Etablissement::PAIEMENT_ESSAI): ?> | |||
Si vous souhaitez profiter de ce service au-delà de la période d'essai gratuite, | |||
abonnez-vous à <strong>La boîte à pain</strong> pour <strong>30 € / mois</strong>. | |||
<?php endif; ?> | |||
</div> | |||
<div class="alert alert-info">Si vous rencontrez des difficultés, n'hésitez pas à nous contacter.</div> | |||
<!--<h2>Prod</h2> | |||
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> | |||
<input type="hidden" name="cmd" value="_s-xclick"> | |||
<input type="hidden" name="hosted_button_id" value="K96K2WLBSBDSA"> | |||
<input name="custom" value="<?php echo Yii::$app->user->identity->id; ?>" type="hidden" /> | |||
<input type="image" src="https://www.paypalobjects.com/fr_FR/FR/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal, le réflexe sécurité pour payer en ligne"> | |||
<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"> | |||
</form>--> | |||
<!--<h2>Test</h2>--> | |||
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> | |||
<input type="hidden" name="cmd" value="_s-xclick"> | |||
<input type="hidden" name="hosted_button_id" value="USASPWAC39S4N"> | |||
<input name="custom" value="<?php echo Yii::$app->user->identity->id; ?>" type="hidden" /> | |||
<input type="image" src="https://www.sandbox.paypal.com/fr_FR/FR/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal, le réflexe sécurité pour payer en ligne"> | |||
<img alt="" border="0" src="https://www.sandbox.paypal.com/fr_FR/i/scr/pixel.gif" width="1" height="1"> | |||
</form> | |||
@@ -301,7 +301,7 @@ $this->title = 'Tableau de bord'; | |||
<td class="historique"><?= $c->getStrHistorique() ; ?></td> | |||
<td><?= $c->getResumePanier() ; ?></td> | |||
<td><?= $c->getResumePointVente() ; ?></td> | |||
<td><?= $c->getStrMontant() ; ?></td> | |||
<td><?= $c->getMontant(true) ; ?></td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> |
@@ -53,21 +53,21 @@ use common\models\Etablissement; | |||
* @property integer $id_production | |||
* @property boolean $paiement_automatique | |||
*/ | |||
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; | |||
class Commande extends \yii\db\ActiveRecord | |||
{ | |||
var $montant = 0 ; | |||
var $montant_paye = 0 ; | |||
var $poids = 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'; | |||
@@ -75,80 +75,48 @@ class Commande extends \yii\db\ActiveRecord { | |||
/** | |||
* @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; | |||
if(isset($p->produit)) | |||
$this->poids_pain += ($p->quantite * $p->produit->poids) / 1000 ; | |||
} 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) { | |||
if(is_null($c->date_delete)) { | |||
foreach ($c->commandeProduits as $cp) { | |||
if ($cp->id_produit == $id_produit) | |||
$quantite += $cp->quantite; | |||
} | |||
} | |||
} | |||
} | |||
return $quantite; | |||
} | |||
/* | |||
* relations | |||
*/ | |||
public function getUser() { | |||
public function getUser() | |||
{ | |||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||
} | |||
public function getCommandeProduits() { | |||
return $this->hasMany(CommandeProduit::className(), ['id_commande' => 'id'])->with('produit'); | |||
public function getCommandeProduits() | |||
{ | |||
return $this->hasMany(CommandeProduit::className(),['id_commande' => 'id']) | |||
->with('produit'); | |||
} | |||
public function getProduction() { | |||
return $this->hasOne(Production::className(), ['id' => 'id_production'])->with('etablissement'); | |||
public function getProduction() | |||
{ | |||
return $this->hasOne(Production::className(), ['id' => 'id_production']) | |||
->with('etablissement'); | |||
} | |||
public function getPointVente() { | |||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente'])->with('pointVenteUser'); | |||
public function getPointVente() | |||
{ | |||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']) | |||
->with('pointVenteUser'); | |||
} | |||
public function getCreditHistorique() { | |||
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', 'id_point_vente', 'id_production'], 'integer'], | |||
@@ -160,7 +128,8 @@ class Commande extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_user' => 'Id User', | |||
@@ -170,23 +139,78 @@ 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 . ' ' . Html::encode($cp->produit->diminutif) . ', '; | |||
/** | |||
* Initialise le montant total, le montant déjà payé et le poids de la | |||
* commande | |||
*/ | |||
public function init() | |||
{ | |||
// Montant | |||
if (isset($this->commandeProduits)) { | |||
foreach ($this->commandeProduits as $p) { | |||
if ($p->mode_vente == 'unite') { | |||
$this->montant += $p->prix * $p->quantite; | |||
if(isset($p->produit)) { | |||
$this->poids += ($p->quantite * $p->produit->poids) / 1000 ; | |||
} | |||
} | |||
elseif ($p->mode_vente == 'poids') { | |||
$this->montant += $p->prix * $p->quantite / 1000; | |||
} | |||
} | |||
} | |||
// Montant payé | |||
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; | |||
} | |||
} | |||
} | |||
return substr($str, 0, strlen($str) - 2); | |||
} | |||
/** | |||
* Retourne la quantité d'un produit donné de plusieurs commandes. | |||
* | |||
* @param integer $id_produit | |||
* @param array $commandes | |||
* | |||
* @return integer | |||
*/ | |||
public static function getQuantiteProduit($id_produit, $commandes) | |||
{ | |||
$quantite = 0; | |||
if (isset($commandes) && is_array($commandes) && count($commandes)) { | |||
foreach ($commandes as $c) { | |||
if(is_null($c->date_delete)) { | |||
foreach ($c->commandeProduits as $cp) { | |||
if ($cp->id_produit == $id_produit) { | |||
$quantite += $cp->quantite; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
public function getMontantPaye() { | |||
return $quantite; | |||
} | |||
/** | |||
* Retourne le montant payé de la commande. | |||
* | |||
* @return float | |||
*/ | |||
public function getMontantPaye() | |||
{ | |||
if ($this->montant_paye) { | |||
return $this->montant_paye; | |||
} else { | |||
} | |||
else { | |||
$historique = CreditHistorique::find() | |||
->where(['id_commande' => $this->id]) | |||
->all(); | |||
@@ -194,46 +218,77 @@ class Commande extends \yii\db\ActiveRecord { | |||
$montant = 0; | |||
foreach ($historique as $ch) { | |||
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) | |||
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) { | |||
$montant += $ch->montant; | |||
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) | |||
} | |||
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) { | |||
$montant -= $ch->montant; | |||
} | |||
} | |||
return $montant; | |||
} | |||
} | |||
public function getMontant($format = false) { | |||
if ($format) | |||
/** | |||
* Retourne le montant de la commande. | |||
* | |||
* @param boolean $format | |||
* @return float | |||
*/ | |||
public function getMontant($format = false) | |||
{ | |||
if ($format) { | |||
return number_format($this->getMontant(), 2) . ' €'; | |||
else | |||
} | |||
else { | |||
return $this->montant; | |||
} | |||
} | |||
public function getMontantFormat() { | |||
return number_format($this->getMontant(), 2) . ' €'; | |||
} | |||
public function getMontantRestant($format = false) { | |||
/** | |||
* Retourne le montant restant à payer. | |||
* | |||
* @param boolean $format | |||
* @return float | |||
*/ | |||
public function getMontantRestant($format = false) | |||
{ | |||
$montant_restant = $this->getMontant() - $this->getMontantPaye(); | |||
if ($format) | |||
if ($format) { | |||
return number_format($montant_restant, 2) . ' €'; | |||
else | |||
} | |||
else { | |||
return $montant_restant; | |||
} | |||
} | |||
public function getMontantSurplus($format = false) { | |||
/** | |||
* Retourne le montant payé en surplus. | |||
* | |||
* @param boolean $format | |||
* @return float | |||
*/ | |||
public function getMontantSurplus($format = false) | |||
{ | |||
$montant_surplus = $this->getMontantPaye() - $this->getMontant(); | |||
if ($format) | |||
if ($format) { | |||
return number_format($montant_surplus, 2) . ' €'; | |||
else | |||
} | |||
else { | |||
return $montant_surplus; | |||
} | |||
} | |||
public function getDataJson() { | |||
/** | |||
* Retourne les informations relatives à la commande au format JSON. | |||
* | |||
* @return string | |||
*/ | |||
public function getDataJson() | |||
{ | |||
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one(); | |||
$commande->init(); | |||
$json_commande = [ | |||
@@ -242,7 +297,7 @@ class Commande extends \yii\db\ActiveRecord { | |||
'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; | |||
@@ -251,7 +306,17 @@ class Commande extends \yii\db\ActiveRecord { | |||
return json_encode($json_commande); | |||
} | |||
public function creditHistorique($type, $montant, $id_etablissement, $id_user, $id_user_action) { | |||
/** | |||
* Enregistre un modèle de type CreditHistorique. | |||
* | |||
* @param string $type | |||
* @param float $montant | |||
* @param integer $id_etablissement | |||
* @param integer $id_user | |||
* @param integer $id_user_action | |||
*/ | |||
public function creditHistorique($type, $montant, $id_etablissement, $id_user, $id_user_action) | |||
{ | |||
$credit_historique = new CreditHistorique; | |||
$credit_historique->id_user = $this->id_user; | |||
$credit_historique->id_commande = $this->id; | |||
@@ -264,10 +329,17 @@ class Commande extends \yii\db\ActiveRecord { | |||
$credit_historique->save(); | |||
} | |||
public function getStatutPaiement() { | |||
/** | |||
* Retourne le statut de paiement de la commande (payée, surplus, ou impayée). | |||
* | |||
* @return string | |||
*/ | |||
public function getStatutPaiement() | |||
{ | |||
// payé | |||
if ($this->getMontant() - $this->getMontantPaye() < 0.01 && | |||
$this->getMontant() - $this->getMontantPaye() >= 0) { | |||
$this->getMontant() - $this->getMontantPaye() >= 0) | |||
{ | |||
return self::STATUT_PAYEE; | |||
} | |||
// à rembourser | |||
@@ -279,25 +351,40 @@ class Commande extends \yii\db\ActiveRecord { | |||
return self::STATUT_IMPAYEE; | |||
} | |||
} | |||
public function getResumePanier() { | |||
if (!isset($this->commandeProduits)) | |||
/** | |||
* Retourne le résumé du panier au format HTML. | |||
* | |||
* @return string | |||
*/ | |||
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) | |||
if (++$i != $count) { | |||
$html .= '<br />'; | |||
} | |||
} | |||
} | |||
return $html; | |||
} | |||
public function getResumePointVente() { | |||
/** | |||
* Retourne le résumé du point de vente lié à la commande au format HTML. | |||
* | |||
* @return string | |||
*/ | |||
public function getResumePointVente() | |||
{ | |||
$html = ''; | |||
if (isset($this->pointVente)) { | |||
@@ -313,14 +400,16 @@ class Commande extends \yii\db\ActiveRecord { | |||
return $html; | |||
} | |||
public function getStrMontant() { | |||
return number_format($this->montant, 2) . ' €'; | |||
} | |||
public function getResumeMontant() { | |||
/** | |||
* Retourne le résumé du paiement (montant, statut). | |||
* | |||
* @return string | |||
*/ | |||
public function getResumeMontant() | |||
{ | |||
$html = ''; | |||
$html .= $this->getStrMontant() . '<br />'; | |||
$html .= $this->getMontant(true) . '<br />'; | |||
if ($this->montant_paye) { | |||
if ($this->getStatutPaiement() == Commande::STATUT_PAYEE) { | |||
@@ -331,14 +420,21 @@ class Commande extends \yii\db\ActiveRecord { | |||
} elseif ($this->getStatutPaiement() == Commande::STATUT_SURPLUS) { | |||
$html .= '<span class="label label-success">Payée</span>'; | |||
} | |||
} else { | |||
} | |||
else { | |||
$html .= '<span class="label label-default">À régler sur place</span>'; | |||
} | |||
return $html; | |||
} | |||
public function getStrUser() { | |||
/** | |||
* Retourne une chaine de caractère décrivant l'utilisateur lié à la commande. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrUser() | |||
{ | |||
if (isset($this->user)) { | |||
return Html::encode($this->user->prenom . ' ' . $this->user->nom); | |||
} elseif (strlen($this->username)) { | |||
@@ -348,7 +444,20 @@ class Commande extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public static function findBy($params = []) { | |||
/** | |||
* Recherche dans les commandes suivant les paramètres suivants : | |||
* - id_etablissement | |||
* - condition | |||
* - date | |||
* - type | |||
* - orderby | |||
* - limit | |||
* | |||
* @param array $params | |||
* @return array | |||
*/ | |||
public static function findBy($params = []) | |||
{ | |||
if (!isset($params['id_etablissement'])) | |||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; | |||
@@ -380,7 +489,13 @@ class Commande extends \yii\db\ActiveRecord { | |||
return $commandes; | |||
} | |||
public function getEtat() { | |||
/** | |||
* Retourne l'état de la commande (livrée, modifiable ou en préparation) | |||
* | |||
* @return string | |||
*/ | |||
public function getEtat() | |||
{ | |||
$delai_commande = Etablissement::getConfig('delai_commande', $this->production->id_etablissement); | |||
$heure_limite = Etablissement::getConfig('heure_limite_commande', $this->production->id_etablissement); | |||
@@ -392,15 +507,24 @@ class Commande extends \yii\db\ActiveRecord { | |||
if ($nb_jours <= 0) { | |||
return self::ETAT_LIVREE; | |||
} elseif ($nb_jours >= $delai_commande && | |||
} | |||
elseif ($nb_jours >= $delai_commande && | |||
($nb_jours != $delai_commande || | |||
($nb_jours == $delai_commande && $heure_today < $heure_limite))) { | |||
($nb_jours == $delai_commande && $heure_today < $heure_limite))) | |||
{ | |||
return self::ETAT_MODIFIABLE; | |||
} | |||
return self::ETAT_PREPARATION; | |||
} | |||
/** | |||
* Retourne le type de la commande (client, automatique ou admin) sous forme | |||
* texte ou HTML. | |||
* | |||
* @param boolean $with_label | |||
* @return string | |||
*/ | |||
public function getStrType($with_label = false) { | |||
$class_label = ''; | |||
$str = ''; | |||
@@ -422,7 +546,14 @@ class Commande extends \yii\db\ActiveRecord { | |||
return $str; | |||
} | |||
public function getStrHistorique() { | |||
/** | |||
* Retourne l'historique de la commande (ajoutée, modifiée, supprimée) au format | |||
* HTML. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrHistorique() | |||
{ | |||
$arr = [ | |||
'class' => 'create', | |||
'glyphicon' => 'plus', | |||
@@ -451,7 +582,15 @@ class Commande extends \yii\db\ActiveRecord { | |||
return $html ; | |||
} | |||
public function getClassHistorique() { | |||
/** | |||
* Retourne une classe identifiant l'historique de la commande (ajoutée, | |||
* modifiée, supprimée). | |||
* | |||
* @return string | |||
*/ | |||
public function getClassHistorique() | |||
{ | |||
if(!is_null($this->date_delete)) { | |||
return 'commande-delete' ; | |||
} | |||
@@ -461,4 +600,4 @@ class Commande extends \yii\db\ActiveRecord { | |||
return 'commande-create' ; | |||
} | |||
} | |||
} |
@@ -65,19 +65,22 @@ 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'], | |||
@@ -89,7 +92,8 @@ class CommandeAuto extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_user' => 'Utilisateur', | |||
@@ -109,23 +113,38 @@ class CommandeAuto extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getUser() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getUser() | |||
{ | |||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||
} | |||
public function getEtablissement() { | |||
public function getEtablissement() | |||
{ | |||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||
} | |||
public function getPointVente() { | |||
public function getPointVente() | |||
{ | |||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); | |||
} | |||
public function getCommandeAutoProduit() { | |||
public function getCommandeAutoProduit() | |||
{ | |||
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto' => 'id'])->with('produit'); | |||
} | |||
public static function getAll($date) { | |||
/** | |||
* Retourne les commandes récurrentes pour une date donnée. | |||
* | |||
* @param string $date | |||
* @return array | |||
*/ | |||
public static function getAll($date) | |||
{ | |||
$date = date('Y-m-d', strtotime($date)); | |||
// commandes auto | |||
@@ -139,7 +158,8 @@ class CommandeAuto extends \yii\db\ActiveRecord { | |||
foreach ($commandes_auto as $c) { | |||
// vérif dates | |||
if ($date >= $c->date_debut && | |||
(!$c->date_fin || $date <= $c->date_fin)) { | |||
(!$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) { | |||
@@ -172,17 +192,25 @@ class CommandeAuto extends \yii\db\ActiveRecord { | |||
return $arr_commandes_auto; | |||
} | |||
public static function addAll($date, $force = false) { | |||
/** | |||
* Ajoute les commandes pour une date donnée à partir des commnandes | |||
* récurrentes. | |||
* | |||
* @param string $date | |||
* @param boolean $force | |||
*/ | |||
public static function addAll($date, $force = false) | |||
{ | |||
// production | |||
$production = Production::findOne([ | |||
'date' => date('Y-m-d', strtotime($date)), | |||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||
]); | |||
'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(); | |||
->where(['id_production' => $production->id]) | |||
->count(); | |||
if (!$count_commandes_prod || $force) { | |||
$commandes_auto = self::getAll($date); | |||
@@ -193,7 +221,13 @@ class CommandeAuto extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public function add($date) { | |||
/** | |||
* Ajoute la commande récurrente pour une date donnée. | |||
* | |||
* @param string $date | |||
*/ | |||
public function add($date) | |||
{ | |||
// production | |||
$production = Production::find() | |||
->where([ |
@@ -46,7 +46,8 @@ use common\models\CommandeAutoProduit; | |||
/** | |||
* Login form | |||
*/ | |||
class CommandeAutoForm extends Model { | |||
class CommandeAutoForm extends Model | |||
{ | |||
public $id; | |||
public $id_user; | |||
@@ -69,7 +70,8 @@ class CommandeAutoForm extends Model { | |||
/** | |||
* @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'], | |||
@@ -84,7 +86,8 @@ class CommandeAutoForm extends Model { | |||
]; | |||
} | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_user' => 'Utilisateur', | |||
@@ -105,10 +108,17 @@ class CommandeAutoForm extends Model { | |||
]; | |||
} | |||
public function save() { | |||
/** | |||
* Enregistre la CommandeAuto. | |||
* | |||
* @return boolean | |||
*/ | |||
public function save() | |||
{ | |||
if ($this->id) { | |||
$commandeauto = CommandeAuto::findOne($this->id); | |||
} else { | |||
} | |||
else { | |||
$commandeauto = new CommandeAuto; | |||
} | |||
@@ -117,9 +127,15 @@ class CommandeAutoForm extends Model { | |||
$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))); | |||
$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->date_fin = date( | |||
'Y-m-d', | |||
strtotime(str_replace('/', '-', $this->date_fin) | |||
)); | |||
} | |||
$commandeauto->lundi = $this->lundi; | |||
$commandeauto->mardi = $this->mardi; | |||
@@ -149,7 +165,6 @@ class CommandeAutoForm extends Model { | |||
} | |||
} | |||
} | |||
return true; | |||
} | |||
@@ -49,19 +49,22 @@ 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'], | |||
@@ -72,7 +75,8 @@ class CommandeAutoProduit extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_commande_auto' => 'Id Commande Auto', | |||
@@ -81,7 +85,12 @@ class CommandeAutoProduit extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getProduit() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getProduit() | |||
{ | |||
return $this->hasOne(Produit::className(), ['id' => 'id_produit']); | |||
} | |||
@@ -48,12 +48,14 @@ 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'; | |||
} | |||
@@ -61,14 +63,16 @@ class CommandeProduit extends \yii\db\ActiveRecord { | |||
* Relations | |||
*/ | |||
public function getProduit() { | |||
public function getProduit() | |||
{ | |||
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'], | |||
@@ -79,7 +83,8 @@ class CommandeProduit extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_commande' => 'Id Commande', | |||
@@ -88,4 +93,4 @@ class CommandeProduit extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
} | |||
} |
@@ -44,7 +44,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; | |||
@@ -55,7 +56,8 @@ 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'], | |||
@@ -69,7 +71,8 @@ class ContactForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'name' => 'Nom', | |||
'email' => 'Email', | |||
@@ -85,7 +88,8 @@ 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', |
@@ -56,7 +56,8 @@ use yii\helpers\Html; | |||
* @property integer $id_etablissement | |||
* @property string $moyen_paiement | |||
*/ | |||
class CreditHistorique extends ActiveRecord { | |||
class CreditHistorique extends ActiveRecord | |||
{ | |||
const TYPE_CREDIT_INITIAL = 'credit-initial'; | |||
const TYPE_CREDIT = 'credit'; | |||
@@ -72,14 +73,16 @@ class CreditHistorique extends ActiveRecord { | |||
/** | |||
* @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'], | |||
@@ -92,7 +95,8 @@ class CreditHistorique extends ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_user' => 'Utilisateur', | |||
@@ -107,19 +111,32 @@ class CreditHistorique extends ActiveRecord { | |||
]; | |||
} | |||
public function getUser() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getUser() | |||
{ | |||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||
} | |||
public function getUserAction() { | |||
public function getUserAction() | |||
{ | |||
return $this->hasOne(User::className(), ['id' => 'id_user_action']); | |||
} | |||
public function getCommande() { | |||
public function getCommande() | |||
{ | |||
return $this->hasOne(Commande::className(), ['id' => 'id_commande']); | |||
} | |||
public function getLibelleType() { | |||
/** | |||
* Retourne le type de CreditHistorique (paiement, remboursement ou débit). | |||
* | |||
* @return string | |||
*/ | |||
public function getLibelleType() | |||
{ | |||
switch ($this->type) { | |||
case 'paiement': | |||
return 'Paiement'; | |||
@@ -133,7 +150,14 @@ class CreditHistorique extends ActiveRecord { | |||
} | |||
} | |||
public function save($runValidation = true, $attributeNames = NULL) { | |||
/** | |||
* Enregistre le modèle. | |||
* | |||
* @param boolean $runValidation | |||
* @param array $attributeNames | |||
*/ | |||
public function save($runValidation = true, $attributeNames = NULL) | |||
{ | |||
// initialisation du commentaire avant sauvegarde | |||
$this->commentaire .= $this->getStrCommentaire() ; | |||
@@ -154,14 +178,26 @@ class CreditHistorique extends ActiveRecord { | |||
} | |||
} | |||
public function isTypeDebit() { | |||
/** | |||
* Retourne si le CreditHistorique est un débit ou non. | |||
* | |||
* @return boolean | |||
*/ | |||
public function isTypeDebit() | |||
{ | |||
return in_array($this->type, [ | |||
self::TYPE_DEBIT, | |||
self::TYPE_PAIEMENT, | |||
]) ; | |||
} | |||
public function isTypeCredit() { | |||
/** | |||
* Retourne si le CreditHistorique est un crédit ou non. | |||
* | |||
* @return boolean | |||
*/ | |||
public function isTypeCredit() | |||
{ | |||
return in_array($this->type, [ | |||
self::TYPE_CREDIT, | |||
self::TYPE_CREDIT_INITIAL, | |||
@@ -169,14 +205,28 @@ class CreditHistorique extends ActiveRecord { | |||
]) ; | |||
} | |||
public function getMontant($format = false) { | |||
/** | |||
* Retourne le montant. | |||
* | |||
* @param boolean $format | |||
* @return float | |||
*/ | |||
public function getMontant($format = false) | |||
{ | |||
if($format) | |||
return number_format($this->montant,2) .' €' ; | |||
else | |||
return $this->montant ; | |||
} | |||
public function getStrLibelle() { | |||
/** | |||
* Retourne le libellé du CreditHistorique informant de son type et | |||
* éventuellement de la date de sa commande associée. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrLibelle() | |||
{ | |||
$str = '' ; | |||
if($this->type == self::TYPE_CREDIT_INITIAL) { | |||
@@ -204,11 +254,18 @@ class CreditHistorique extends ActiveRecord { | |||
} | |||
} | |||
return $str ; | |||
} | |||
public function getStrCommentaire() { | |||
/** | |||
* Retourne les informations à ajouter au commentaire du CreditHistorique | |||
* (libellé, montant, client, action) au format HTML. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrCommentaire() | |||
{ | |||
$str = '' ; | |||
if(strlen($this->commentaire)) { | |||
$str .= '<br />' ; | |||
@@ -227,14 +284,27 @@ class CreditHistorique extends ActiveRecord { | |||
return $str ; | |||
} | |||
public function getDate($format = false) { | |||
/** | |||
* Retourne la date. | |||
* | |||
* @param boolean $format | |||
* @return string | |||
*/ | |||
public function getDate($format = false) | |||
{ | |||
if($format) | |||
return date('d/m/Y à H:i:s',strtotime($this->date)) ; | |||
else | |||
return $this->date ; | |||
} | |||
public function getStrMoyenPaiement() { | |||
/** | |||
* Retourne le moyen de paiement. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrMoyenPaiement() | |||
{ | |||
switch($this->moyen_paiement) { | |||
case CreditHistorique::MOYEN_ESPECES : return 'Espèces' ; | |||
case CreditHistorique::MOYEN_CHEQUE : return 'Chèque' ; | |||
@@ -244,7 +314,13 @@ class CreditHistorique extends ActiveRecord { | |||
} | |||
} | |||
public function strUserAction() { | |||
/** | |||
* Retourne le libellé de l'utilisateur ayant initié l'action. | |||
* | |||
* @return string | |||
*/ | |||
public function strUserAction() | |||
{ | |||
if($this->userAction) { | |||
return $this->userAction->nom . ' ' . $this->userAction->prenom ; | |||
} |
@@ -52,7 +52,8 @@ use common\models\DeveloppementPriorite; | |||
* @property string $statut | |||
* @property double $estimation_temps | |||
*/ | |||
class Developpement extends \yii\db\ActiveRecord { | |||
class Developpement extends \yii\db\ActiveRecord | |||
{ | |||
const STATUT_OPEN = 'open'; | |||
const STATUT_CLOSED = 'closed'; | |||
@@ -62,14 +63,16 @@ class Developpement extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public static function tableName() { | |||
public static function tableName() | |||
{ | |||
return 'developpement'; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
[['objet', 'date'], 'required'], | |||
[['id', 'avancement'], 'integer'], | |||
@@ -80,18 +83,25 @@ class Developpement extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getDeveloppementPriorite() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getDeveloppementPriorite() | |||
{ | |||
return $this->hasMany(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->with('etablissement'); | |||
} | |||
public function getDeveloppementPrioriteCurrentEtablissement() { | |||
public function getDeveloppementPrioriteCurrentEtablissement() | |||
{ | |||
return $this->hasOne(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])->with('etablissement'); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'objet' => 'Sujet', | |||
@@ -104,7 +114,12 @@ class Developpement extends \yii\db\ActiveRecord { | |||
'date_livraison' => 'Date de livraison' | |||
]; | |||
} | |||
/** | |||
* Définit une date de livraison. | |||
* | |||
* @param string $date | |||
*/ | |||
public function setDateLivraison($date = '') { | |||
if (strlen($date)) |
@@ -47,7 +47,8 @@ use common\models\Etablissement; | |||
* @property integer $id_user | |||
* @property integer $id_developpement | |||
*/ | |||
class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
class DeveloppementPriorite extends \yii\db\ActiveRecord | |||
{ | |||
const PRIORITE_HAUTE = 'haute'; | |||
const PRIORITE_NORMALE = 'normale'; | |||
@@ -56,29 +57,37 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public static function tableName() { | |||
public static function tableName() | |||
{ | |||
return 'developpement_priorite'; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_etablissement', 'id_developpement'], 'required'], | |||
[['id_etablissement', 'id_developpement'], 'integer'], | |||
[['priorite'], 'string'], | |||
]; | |||
} | |||
/* | |||
* Relations | |||
*/ | |||
public function getEtablissement() { | |||
public function getEtablissement() | |||
{ | |||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_etablissement' => 'Établissement', | |||
'id_developpement' => 'Développement', | |||
@@ -86,7 +95,13 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getStrPriorite() { | |||
/** | |||
* Retourne la priorité. | |||
* | |||
* @return string | |||
*/ | |||
public function getStrPriorite() | |||
{ | |||
switch ($this->priorite) { | |||
case self::PRIORITE_BASSE : return 'Basse'; | |||
break; | |||
@@ -99,7 +114,13 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public function getClassCssStyleBouton() { | |||
/** | |||
* Retourne la classe CSS du bouton servant à définir la priorité. | |||
* | |||
* @return string | |||
*/ | |||
public function getClassCssStyleBouton() | |||
{ | |||
$style_bouton = 'default'; | |||
if ($this->priorite == DeveloppementPriorite::PRIORITE_BASSE) | |||
$style_bouton = 'info'; |
@@ -54,7 +54,8 @@ use yii\helpers\Html; | |||
* @property string $code_postal | |||
* @property string $ville | |||
*/ | |||
class Etablissement extends \yii\db\ActiveRecord { | |||
class Etablissement extends \yii\db\ActiveRecord | |||
{ | |||
const PAIEMENT_OK = 'ok'; | |||
const PAIEMENT_ESSAI = 'essai'; | |||
@@ -64,14 +65,16 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
/** | |||
* @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','type'], 'required'], | |||
[['heure_limite_commande', 'delai_commande'], 'integer'], | |||
@@ -97,7 +100,8 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'nom' => 'Nom', | |||
@@ -120,20 +124,37 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getUserEtablissement() { | |||
return $this->hasMany(UserEtablissement::className(), ['id_etablissement' => 'id']); | |||
/* | |||
* Relations | |||
*/ | |||
public function getUserEtablissement() | |||
{ | |||
return $this->hasMany( | |||
UserEtablissement::className(), | |||
['id_etablissement' => 'id'] | |||
); | |||
} | |||
public function getUser() { | |||
public function getUser() | |||
{ | |||
return $this->hasMany(User::className(), ['id_etablissement' => 'id']); | |||
} | |||
public function getContact() { | |||
return $this->hasMany(User::className(), ['id_etablissement' => 'id'])->where(['status' => User::STATUS_BOULANGER]); | |||
public function getContact() | |||
{ | |||
return $this->hasMany(User::className(),['id_etablissement' => 'id']) | |||
->where(['status' => User::STATUS_BOULANGER]); | |||
} | |||
public static function getEtablissementsPopulateDropdown() { | |||
/** | |||
* Retourne la liste des établissements pour l'initialisation d'une liste | |||
* sélective. | |||
* | |||
* @return array | |||
*/ | |||
public static function getEtablissementsPopulateDropdown() | |||
{ | |||
$etablissements_dispos = Etablissement::find() | |||
->where(['actif' => 1]) | |||
->orderby('code_postal, ville ASC') | |||
@@ -159,42 +180,31 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
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'; | |||
else | |||
return 'retard-paiement'; | |||
} | |||
} | |||
} | |||
public function getCA($periode = '', $format = false) { | |||
/** | |||
* Retourne le CA de l'établissement pour un mois donné. | |||
* | |||
* @param string $periode | |||
* @param boolean $format | |||
* @return string | |||
*/ | |||
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(); | |||
@@ -206,7 +216,16 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
return $ca; | |||
} | |||
public function getMontantFacturer($periode = '', $ca = 0, $format = false) { | |||
/** | |||
* Retourne le montant à facturer pour une période donnée. | |||
* | |||
* @param string $periode | |||
* @param float $ca | |||
* @param boolean $format | |||
* @return string | |||
*/ | |||
public function getMontantFacturer($periode = '', $ca = 0, $format = false) | |||
{ | |||
if (!$periode) | |||
$periode = date('Y-m'); | |||
@@ -226,7 +245,14 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public function getFacture($periode = '') { | |||
/** | |||
* Retourne la facture d'une période donnée. | |||
* | |||
* @param string $periode | |||
* @return Facture | |||
*/ | |||
public function getFacture($periode = '') | |||
{ | |||
if (!$periode) | |||
$periode = date('Y-m', strtotime('-1 month')); | |||
@@ -242,15 +268,30 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
return $facture; | |||
} | |||
public function factureMoisDernier() { | |||
/** | |||
* Retourne la facture du mois dernier. | |||
* | |||
* @return Facture | |||
*/ | |||
public function factureMoisDernier() | |||
{ | |||
return $this->getFacture(date('Y-m', strtotime('-1 month'))); | |||
} | |||
public static function getConfig($config = '', $id_etablissement = 0) { | |||
/** | |||
* Retourne une configuration d'un établissement donné. | |||
* | |||
* @param string $config | |||
* @param integer $id_etablissement | |||
* @return mixed | |||
*/ | |||
public static function getConfig($config = '', $id_etablissement = 0) | |||
{ | |||
if (strlen($config)) { | |||
if (!$id_etablissement) | |||
if (!$id_etablissement) { | |||
$id_etablissement = Yii::$app->user->identity->id_etablissement; | |||
} | |||
$etablissement = self::findOne($id_etablissement); | |||
if ($etablissement) { | |||
return $etablissement->$config; | |||
@@ -260,13 +301,34 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
return false; | |||
} | |||
public function getPrixLibre() { | |||
/** | |||
* Retourne le montant de l'abonnement à prix libre définit par | |||
* l'établissement | |||
* | |||
* @param boolean $format | |||
* @return mixed | |||
*/ | |||
public function getPrixLibre($format = true) | |||
{ | |||
if (!is_null($this->prix_libre)) { | |||
return number_format($this->prix_libre, 2, ',', false) . ' € HT'; | |||
if($format) { | |||
return number_format($this->prix_libre, 2, ',', false) . ' € HT'; | |||
} | |||
else { | |||
return $this->prix_libre; | |||
} | |||
} | |||
} | |||
public static function addUser($id_user, $id_producer) { | |||
/** | |||
* Lie un utilisateur à un producteur. | |||
* | |||
* @param integer $id_user | |||
* @param integer $id_producer | |||
* @return UserProducer | |||
*/ | |||
public static function addUser($id_user, $id_producer) | |||
{ | |||
$user_producer = UserEtablissement::find() | |||
->where([ | |||
'id_user' => $id_user, |
@@ -54,19 +54,22 @@ 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'], | |||
@@ -76,14 +79,20 @@ class Facture extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getEtablissement() { | |||
/* | |||
* Relations | |||
*/ | |||
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', | |||
@@ -99,7 +108,13 @@ class Facture extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public static function getLastFacture() { | |||
/** | |||
* Retourne la dernière facture émise. | |||
* | |||
* @return Facture | |||
*/ | |||
public static function getLastFacture() | |||
{ | |||
return Facture::find() | |||
->orderBy('reference DESC') | |||
->one(); |
@@ -44,7 +44,8 @@ use yii\base\Model; | |||
/** | |||
* Login form | |||
*/ | |||
class LoginForm extends Model { | |||
class LoginForm extends Model | |||
{ | |||
public $username; | |||
public $password; | |||
@@ -57,7 +58,8 @@ class LoginForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
['email', 'filter', 'filter' => 'trim'], | |||
@@ -104,7 +106,8 @@ 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)) { | |||
@@ -118,7 +121,8 @@ class LoginForm extends Model { | |||
* | |||
* @return boolean whether the user is logged in successfully | |||
*/ | |||
public function login() { | |||
public function login() | |||
{ | |||
if ($this->validate()) { | |||
$this->updateDerniereConnexion(); | |||
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | |||
@@ -132,7 +136,8 @@ class LoginForm extends Model { | |||
* | |||
* @return User|null | |||
*/ | |||
public function getUser() { | |||
public function getUser() | |||
{ | |||
if ($this->_user === false) { | |||
$this->_user = User::findByEmail($this->email); | |||
} | |||
@@ -140,7 +145,8 @@ class LoginForm extends Model { | |||
return $this->_user; | |||
} | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'username' => 'Identifiant', | |||
@@ -150,7 +156,11 @@ class LoginForm extends Model { | |||
]; | |||
} | |||
public function updateDerniereConnexion() { | |||
/** | |||
* Met à jour la date de dernière connexion de l'utilisateur. | |||
*/ | |||
public function updateDerniereConnexion() | |||
{ | |||
$user = $this->getUser(); | |||
$user->date_derniere_connexion = date('Y-m-d H:i:s'); | |||
$user->save(); |
@@ -51,8 +51,8 @@ use common\models\ProductionPointVente; | |||
* @property string $adresse | |||
* @property integer $id_boulangerie | |||
*/ | |||
class PointVente extends \yii\db\ActiveRecord { | |||
class PointVente extends \yii\db\ActiveRecord | |||
{ | |||
var $commandes = []; | |||
var $recettes = 0; | |||
var $recettes_pain = 0; | |||
@@ -65,14 +65,16 @@ class PointVente extends \yii\db\ActiveRecord { | |||
/** | |||
* @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'], | |||
@@ -89,7 +91,8 @@ class PointVente extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'nom' => 'Nom', | |||
@@ -118,16 +121,27 @@ class PointVente extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getPointVenteUser() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getPointVenteUser() | |||
{ | |||
return $this->hasMany(PointVenteUser::className(), ['id_point_vente' => 'id']); | |||
} | |||
public function getProductionPointVente() { | |||
public function getProductionPointVente() | |||
{ | |||
return $this->hasMany(ProductionPointVente::className(), ['id_point_vente' => 'id']); | |||
} | |||
public function initCommandes($commandes) { | |||
/** | |||
* Initialise les commandes liées au point de vente. | |||
* | |||
* @param array $commandes | |||
*/ | |||
public function initCommandes($commandes) | |||
{ | |||
$this->commandes = []; | |||
$this->recettes = 0; | |||
$this->recettes_pain = 0; | |||
@@ -146,34 +160,35 @@ class PointVente extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public function getCommandes() { | |||
/** | |||
* Retourne les commandes liées à ce point de vente. | |||
* | |||
* @return array | |||
*/ | |||
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); | |||
} | |||
public function save($runValidation = true, $attributeNames = NULL) { | |||
/** | |||
* Enregistre le point de vente. | |||
* | |||
* @param boolean $runValidation | |||
* @param array $attributeNames | |||
* @return type | |||
*/ | |||
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() { | |||
/** | |||
* Traite la mise à jour de l'attribut 'point_fabrication'. | |||
*/ | |||
public function gestionPointFabrication() | |||
{ | |||
if ($this->point_fabrication) { | |||
PointVente::updateAll( | |||
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement] | |||
@@ -183,7 +198,11 @@ class PointVente extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
public function gestionAccesRestreint() { | |||
/** | |||
* Traite les accès restreints d'un point de vente. | |||
*/ | |||
public function gestionAccesRestreint() | |||
{ | |||
PointVenteUser::deleteAll(['id_point_vente' => $this->id]); | |||
if (is_array($this->users) && count($this->users)) { | |||
@@ -193,15 +212,22 @@ class PointVente extends \yii\db\ActiveRecord { | |||
$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])) | |||
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() { | |||
/** | |||
* Retourne le commentaire de l'utilisateur courant lié au point de vente. | |||
* | |||
* @return string|null | |||
*/ | |||
public function getCommentaire() | |||
{ | |||
if (isset($this->pointVenteUser)) { | |||
foreach ($this->pointVenteUser as $pvu) { | |||
if ($pvu->id_user == Yii::$app->user->identity->id) { | |||
@@ -209,9 +235,16 @@ class PointVente extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
} | |||
return null ; | |||
} | |||
public static function count() { | |||
/** | |||
* Retourne le nombre de points de vente pour l'établissement courant. | |||
* | |||
* @return integer | |||
*/ | |||
public static function count() | |||
{ | |||
return PointVente::find() | |||
->where([ | |||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||
@@ -219,7 +252,14 @@ class PointVente extends \yii\db\ActiveRecord { | |||
->count(); | |||
} | |||
public function verifCode($code) { | |||
/** | |||
* Vérifie le code d'accès à un point de vente. | |||
* | |||
* @param string $code | |||
* @return boolean | |||
*/ | |||
public function verifCode($code) | |||
{ | |||
if (strlen($this->code)) { | |||
if (trim(strtolower($code)) == trim(strtolower($this->code))) { | |||
return true; | |||
@@ -231,6 +271,12 @@ class PointVente extends \yii\db\ActiveRecord { | |||
} | |||
} | |||
/** | |||
* Retourne les jours de livraison du point de vente sous forme d'une chaine | |||
* de caractères. | |||
* | |||
* @return string | |||
*/ | |||
public function strJoursLivraison() { | |||
$str = '' ; | |||
if($this->livraison_lundi) $str .= 'lundi, ' ; | |||
@@ -247,6 +293,13 @@ class PointVente extends \yii\db\ActiveRecord { | |||
return '' ; | |||
} | |||
/** | |||
* Retourne un commentaire informant l'utilisateur sur les détails de | |||
* livraison d'un point de vente et pour un jour donné. | |||
* | |||
* @param string $jour | |||
* @return string | |||
*/ | |||
public function strInfos($jour) { | |||
$str = '' ; | |||
$champs = 'horaires_'.$jour ; |
@@ -46,19 +46,22 @@ 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'], | |||
@@ -69,7 +72,8 @@ class PointVenteUser extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_point_vente' => 'Id Point Vente', | |||
'id_user' => 'Id User', |
@@ -40,6 +40,7 @@ namespace common\models; | |||
use Yii; | |||
use common\models\Commande; | |||
use common\models\Production; | |||
/** | |||
* This is the model class for table "production". | |||
@@ -48,23 +49,27 @@ 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() { | |||
public function getEtablissement() | |||
{ | |||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
[['date'], 'required'], | |||
[['date'], 'safe'], | |||
@@ -75,7 +80,8 @@ class Production extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'date' => 'Date', | |||
@@ -83,22 +89,37 @@ class Production extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getCommande() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getCommande() | |||
{ | |||
return $this->hasMany(Commande::className(), ['id_production' => 'id']); | |||
} | |||
public function getProductionProduit() { | |||
public function getProductionProduit() | |||
{ | |||
return $this->hasMany(ProductionProduit::className(), ['id_production' => 'id']); | |||
} | |||
public function produitActif($id_produit) { | |||
/** | |||
* Retourne si un produit est actif ou non. | |||
* | |||
* @param integer $id_produit | |||
* @return boolean | |||
*/ | |||
public function produitActif($id_produit) | |||
{ | |||
if ($id_produit && | |||
isset($this->productionProduit) && | |||
count($this->productionProduit) > 0) { | |||
isset($this->productionProduit) && | |||
count($this->productionProduit) > 0) | |||
{ | |||
foreach ($this->productionProduit as $production_produit) { | |||
if ($production_produit['id_produit'] == $id_produit && | |||
$production_produit['actif']) { | |||
$production_produit['actif']) | |||
{ | |||
return true; | |||
} | |||
} | |||
@@ -107,7 +128,14 @@ class Production extends \yii\db\ActiveRecord { | |||
return false; | |||
} | |||
public static function initProduction($date) { | |||
/** | |||
* Initialise un jour de production. | |||
* | |||
* @param string $date | |||
* @return Production | |||
*/ | |||
public static function initProduction($date) | |||
{ | |||
$production = null ; | |||
if ($date != '') { | |||
$production = Production::find() | |||
@@ -126,10 +154,10 @@ class Production extends \yii\db\ActiveRecord { | |||
// production_point_vente à définir s'ils ne sont pas initialisés | |||
if ($production) { | |||
$count_productions_point_vente = ProductionPointVente::find()-> | |||
where([ | |||
'id_production' => $production->id | |||
]) | |||
->count(); | |||
where([ | |||
'id_production' => $production->id | |||
]) | |||
->count(); | |||
if (!$count_productions_point_vente) { | |||
ProductionPointVente::setAll($production->id, true); |
@@ -49,21 +49,24 @@ use common\models\Production; | |||
* @property integer $id_point_vente | |||
* @property integer $livraison | |||
*/ | |||
class ProductionPointVente extends \yii\db\ActiveRecord { | |||
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'], | |||
@@ -73,7 +76,8 @@ class ProductionPointVente extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_production' => 'Id Production', | |||
'id_point_vente' => 'Id Point Vente', | |||
@@ -81,15 +85,29 @@ class ProductionPointVente extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getProduction() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getProduction() | |||
{ | |||
return $this->hasOne(Production::className(), ['id' => 'id_production']); | |||
} | |||
public function getPointVente() { | |||
public function getPointVente() | |||
{ | |||
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); | |||
} | |||
public static function setAll($id_production, $bool_livraison) { | |||
/** | |||
* Définit les jours de livraisons des points de vente pour un jour de | |||
* production donné. | |||
* | |||
* @param integer $id_production | |||
* @param boolean $bool_livraison | |||
*/ | |||
public static function setAll($id_production, $bool_livraison) | |||
{ | |||
$count_productions_point_vente = self::find()-> | |||
where([ | |||
'id_production' => $id_production |
@@ -49,32 +49,41 @@ 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'] | |||
]; | |||
} | |||
public function getProduit() { | |||
/* | |||
* Relations | |||
*/ | |||
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', | |||
@@ -84,6 +93,12 @@ class ProductionProduit extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
/** | |||
* Recherche les enregistrement ProductionProduit liés à une production. | |||
* | |||
* @param integer $id_production | |||
* @return array | |||
*/ | |||
public static function findProduits($id_production) { | |||
$production_produits = ProductionProduit::find() |
@@ -54,21 +54,24 @@ use Yii; | |||
* @property double $poids | |||
* @property string $recette | |||
*/ | |||
class Produit extends \yii\db\ActiveRecord { | |||
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'], | |||
@@ -83,7 +86,8 @@ class Produit extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'nom' => 'Nom', | |||
@@ -108,7 +112,13 @@ class Produit extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function getDescription() { | |||
/** | |||
* Retourne la description du produit. | |||
* | |||
* @return string | |||
*/ | |||
public function getDescription() | |||
{ | |||
$description = $this->description; | |||
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { | |||
if ($this->poids >= 1000) { | |||
@@ -120,16 +130,35 @@ class Produit extends \yii\db\ActiveRecord { | |||
return $description; | |||
} | |||
public function getLibelleAdmin() { | |||
/** | |||
* Retourne le libellé (admin) du produit. | |||
* @return type | |||
*/ | |||
public function getLibelleAdmin() | |||
{ | |||
return $this->nom; | |||
} | |||
public function save($runValidation = true, $attributeNames = NULL) { | |||
/** | |||
* Enregistre le produit. | |||
* | |||
* @param boolean $runValidation | |||
* @param array $attributeNames | |||
* @return boolean | |||
*/ | |||
public function save($runValidation = true, $attributeNames = NULL) | |||
{ | |||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||
return parent::save($runValidation, $attributeNames); | |||
} | |||
public function getAll() { | |||
/** | |||
* Retourne les produits de l'établissement courant. | |||
* | |||
* @return array | |||
*/ | |||
public function getAll() | |||
{ | |||
return Produit::find() | |||
->where([ | |||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | |||
@@ -138,7 +167,14 @@ class Produit extends \yii\db\ActiveRecord { | |||
->all(); | |||
} | |||
public function getByProduction($id_production) { | |||
/** | |||
* Retourne les produits d'une production donnée. | |||
* | |||
* @param integer $id_production | |||
* @return array | |||
*/ | |||
public function getByProduction($id_production) | |||
{ | |||
return Produit::find() | |||
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | |||
->where([ | |||
@@ -149,7 +185,13 @@ class Produit extends \yii\db\ActiveRecord { | |||
->all(); | |||
} | |||
public static function count() { | |||
/** | |||
* Retourne le nombre de produits du producteur courant. | |||
* | |||
* @return integer | |||
*/ | |||
public static function count() | |||
{ | |||
return Produit::find() | |||
->where([ | |||
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
@@ -39,6 +39,7 @@ termes. | |||
namespace common\models; | |||
use yii\web\IdentityInterface; | |||
use yii\db\Query ; | |||
/** | |||
* User model | |||
@@ -55,7 +56,8 @@ 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; | |||
@@ -71,14 +73,16 @@ class User extends ActiveRecord implements IdentityInterface { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public static function tableName() { | |||
public static function tableName() | |||
{ | |||
return '{{%user}}'; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function behaviors() { | |||
public function behaviors() | |||
{ | |||
return [ | |||
TimestampBehavior::className(), | |||
]; | |||
@@ -87,7 +91,8 @@ 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'], | |||
@@ -104,7 +109,14 @@ class User extends ActiveRecord implements IdentityInterface { | |||
]; | |||
} | |||
public function verifyPasswordOld($attribute, $params) { | |||
/** | |||
* Vérifie le mot de passe envoyé par l'utilisateur. | |||
* | |||
* @param string $attribute | |||
* @param array $params | |||
*/ | |||
public function verifyPasswordOld($attribute, $params) | |||
{ | |||
if (strlen($this->password_old)) { | |||
if (!$this->validatePassword($this->password_old)) { | |||
$this->addError($attribute, 'Mot de passe invalide.'); | |||
@@ -124,40 +136,68 @@ class User extends ActiveRecord implements IdentityInterface { | |||
} | |||
} | |||
public function verifyPasswordNew($attribute, $params) { | |||
/** | |||
* Vérifie le mot de passe de l'utilisateur. | |||
* | |||
* @param string $attribute | |||
* @param array $params | |||
*/ | |||
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) { | |||
/** | |||
* Vérifie la confirmation de mot de passe de l'utilisateur. | |||
* | |||
* @param string $attribute | |||
* @param array $params | |||
*/ | |||
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) { | |||
/** | |||
* Vérifie l'email de l'utilisateur. | |||
* | |||
* @param string $attribute | |||
* @param array $params | |||
*/ | |||
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() { | |||
/* | |||
* Relations | |||
*/ | |||
public function getUserEtablissement() | |||
{ | |||
return $this->hasMany(UserEtablissement::className(), ['id_user' => 'id']); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public static function findIdentity($id) { | |||
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.'); | |||
} | |||
@@ -167,12 +207,20 @@ 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]); | |||
} | |||
public static function findByEmail($email) { | |||
return static::findOne(['email' => $email /* , 'status' => self::STATUS_ACTIVE */]); | |||
/** | |||
* Recherche un utilisateur via son adresse email. | |||
* | |||
* @param string $email | |||
* @return User | |||
*/ | |||
public static function findByEmail($email) | |||
{ | |||
return static::findOne(['email' => $email]); | |||
} | |||
/** | |||
@@ -181,7 +229,8 @@ 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; | |||
} | |||
@@ -191,11 +240,19 @@ class User extends ActiveRecord implements IdentityInterface { | |||
]); | |||
} | |||
public static function findBy($params = []) { | |||
/** | |||
* Recherche des utilisateurs suivant les paramètres : id_etablissement, | |||
* inactifs, id_point_vente, nom, prenom, email, telephone. | |||
* | |||
* @param array $params | |||
* @return Query | |||
*/ | |||
public static function findBy($params = []) | |||
{ | |||
if (!isset($params['id_etablissement'])) | |||
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; | |||
$query = (new \yii\db\Query()) | |||
$query = (new Query()) | |||
->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'); | |||
@@ -224,15 +281,22 @@ class User extends ActiveRecord implements IdentityInterface { | |||
->groupBy('user.id'); | |||
} | |||
if (isset($params['nom'])) | |||
if (isset($params['nom'])) { | |||
$query->andFilterWhere(['like', 'nom', $params['nom']]); | |||
if (isset($params['prenom'])) | |||
} | |||
if (isset($params['prenom'])) { | |||
$query->andFilterWhere(['like', 'prenom', $params['prenom']]); | |||
if (isset($params['email'])) | |||
} | |||
if (isset($params['email'])) { | |||
$query->andFilterWhere(['like', 'email', $params['email']]); | |||
if (isset($params['telephone'])) | |||
} | |||
if (isset($params['telephone'])) { | |||
$query->andFilterWhere(['like', 'telephone', $params['telephone']]); | |||
} | |||
return $query; | |||
} | |||
@@ -242,7 +306,8 @@ 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; | |||
} | |||
@@ -255,21 +320,24 @@ 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; | |||
} | |||
@@ -279,7 +347,8 @@ 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); | |||
} | |||
@@ -288,32 +357,37 @@ 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() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'username' => 'Identifiant', | |||
@@ -335,16 +409,34 @@ class User extends ActiveRecord implements IdentityInterface { | |||
]; | |||
} | |||
public function isBoulanger() { | |||
/** | |||
* Retourne si l'utilisateur est un boulanger ou non. | |||
* | |||
* @return boolean | |||
*/ | |||
public function isBoulanger() | |||
{ | |||
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_BOULANGER) && $this->id_etablissement; | |||
} | |||
public function getNomMagasin() { | |||
/** | |||
* Retourne le nom du producteur. | |||
* | |||
* @return string | |||
*/ | |||
public function getNomMagasin() | |||
{ | |||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||
return $etablissement->nom; | |||
} | |||
public function getEtablissementsFavoris() { | |||
/** | |||
* Retourne les établissements liés à l'utilisateur. | |||
* | |||
* @return array | |||
*/ | |||
public function getEtablissementsFavoris() | |||
{ | |||
$etabs = (new \yii\db\Query()) | |||
->select('*') | |||
->from(['user_etablissement', 'etablissement']) | |||
@@ -356,37 +448,20 @@ class User extends ActiveRecord implements IdentityInterface { | |||
return $etabs; | |||
} | |||
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 getCredit($id_etablissement) { | |||
/** | |||
* Retourne le crédit de l'utilisateur pour un producteur donné. | |||
* | |||
* @param integer $id_etablissement | |||
* @return float | |||
*/ | |||
public function getCredit($id_etablissement) | |||
{ | |||
$user_etablissement = UserEtablissement::find() | |||
->where([ | |||
'id_user' => $this->id, | |||
'id_etablissement' => $id_etablissement | |||
]) | |||
->one(); | |||
->where([ | |||
'id_user' => $this->id, | |||
'id_etablissement' => $id_etablissement | |||
]) | |||
->one(); | |||
if ($user_etablissement) { | |||
return $user_etablissement->credit; | |||
@@ -395,12 +470,23 @@ class User extends ActiveRecord implements IdentityInterface { | |||
return 0; | |||
} | |||
public function updateDerniereConnexion() { | |||
/** | |||
* Met à jour la date de dernière connexion de l'utilisateur. | |||
*/ | |||
public function updateDerniereConnexion() | |||
{ | |||
$this->date_derniere_connexion = date('Y-m-d H:i:s'); | |||
$this->save(); | |||
} | |||
public function sendMailWelcome($password) { | |||
/** | |||
* Envoie un email de bienvenue à l'utilisateur lors de son inscription | |||
* via le backend du site. | |||
* | |||
* @param string $password | |||
*/ | |||
public function sendMailWelcome($password) | |||
{ | |||
if (strlen($this->email)) { | |||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); | |||
Yii::$app->mailer->compose(); |
@@ -48,19 +48,22 @@ use Yii; | |||
* @property boolean $actif | |||
* @property boolean $favoris | |||
*/ | |||
class UserEtablissement extends \yii\db\ActiveRecord { | |||
class UserEtablissement extends \yii\db\ActiveRecord | |||
{ | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public static function tableName() { | |||
public static function tableName() | |||
{ | |||
return 'user_etablissement'; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_user', 'id_etablissement'], 'required'], | |||
[['id_user', 'id_etablissement'], 'integer'], | |||
@@ -72,7 +75,8 @@ class UserEtablissement extends \yii\db\ActiveRecord { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_user' => 'Id User', | |||
'id_etablissement' => 'Id Etablissement', |
@@ -47,7 +47,8 @@ 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; | |||
@@ -55,7 +56,8 @@ class AddEtablissementForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
['id_etablissement', 'integer'], | |||
['id_etablissement', 'required'], | |||
@@ -100,7 +102,8 @@ class AddEtablissementForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_etablissement' => 'Établissement', | |||
'code' => 'Code', | |||
@@ -113,7 +116,8 @@ class AddEtablissementForm extends Model { | |||
* @param string $email the target email address | |||
* @return boolean whether the email was sent | |||
*/ | |||
public function add() { | |||
public function add() | |||
{ | |||
$etablissement = Etablissement::findOne($this->id_etablissement); | |||
$user_etablissement_exist = UserEtablissement::find() |
@@ -45,14 +45,16 @@ 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'], | |||
@@ -69,7 +71,8 @@ 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, |
@@ -44,7 +44,8 @@ use yii\base\Model; | |||
/** | |||
* Producer Code form | |||
*/ | |||
class ProducerCodeForm extends Model { | |||
class ProducerCodeForm extends Model | |||
{ | |||
public $id_producer ; | |||
public $code; | |||
@@ -52,7 +53,8 @@ class ProducerCodeForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
['id_producer','required','message' => 'Champs obligatoire'], | |||
['id_producer', 'integer'], | |||
@@ -83,7 +85,8 @@ class ProducerCodeForm extends Model { | |||
]; | |||
} | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_producer' => 'Producteur', | |||
'code' => 'Code de l\'établissement', |
@@ -46,7 +46,8 @@ use Yii; | |||
/** | |||
* Password reset form | |||
*/ | |||
class ResetPasswordForm extends Model { | |||
class ResetPasswordForm extends Model | |||
{ | |||
public $password; | |||
@@ -62,7 +63,8 @@ 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.'); | |||
} | |||
@@ -76,7 +78,8 @@ class ResetPasswordForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
['password', 'required'], | |||
['password', 'string', 'min' => 6], | |||
@@ -88,7 +91,8 @@ 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(); | |||
@@ -96,7 +100,8 @@ class ResetPasswordForm extends Model { | |||
return $user->save(); | |||
} | |||
public function attributeLabels() { | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'password' => 'Mot de passe', | |||
]; |
@@ -48,7 +48,8 @@ use common\helpers\Password; | |||
/** | |||
* Signup form | |||
*/ | |||
class SignupForm extends Model { | |||
class SignupForm extends Model | |||
{ | |||
public $username; | |||
public $email; | |||
@@ -71,7 +72,8 @@ class SignupForm extends Model { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function rules() { | |||
public function rules() | |||
{ | |||
return [ | |||
['email', 'filter', 'filter' => 'trim'], | |||
['email', 'required', 'message' => 'Champs obligatoire'], | |||
@@ -180,13 +182,34 @@ class SignupForm extends Model { | |||
['prix_libre', 'number'], | |||
]; | |||
} | |||
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', | |||
'type' => 'Type d\'établissement', | |||
'prix_libre' => 'Prix libre' | |||
]; | |||
} | |||
/** | |||
* Signs user up. | |||
* | |||
* @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; | |||
@@ -280,24 +303,5 @@ class SignupForm extends Model { | |||
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', | |||
'type' => 'Type d\'établissement', | |||
'prix_libre' => 'Prix libre' | |||
]; | |||
} | |||
} |