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