|
|
|
|
|
|
|
|
* @property integer $id_etablissement |
|
|
* @property integer $id_etablissement |
|
|
* @property string $moyen_paiement |
|
|
* @property string $moyen_paiement |
|
|
*/ |
|
|
*/ |
|
|
class CreditHistorique extends ActiveRecord { |
|
|
|
|
|
|
|
|
class CreditHistorique extends ActiveRecord |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
const TYPE_CREDIT_INITIAL = 'credit-initial'; |
|
|
const TYPE_CREDIT_INITIAL = 'credit-initial'; |
|
|
const TYPE_CREDIT = 'credit'; |
|
|
const TYPE_CREDIT = 'credit'; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public static function tableName() { |
|
|
|
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
return 'credit_historique'; |
|
|
return 'credit_historique'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function rules() { |
|
|
|
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['montant'], 'required'], |
|
|
[['montant'], 'required'], |
|
|
[['id_user', 'id_user_action', 'id_commande', 'id_etablissement'], 'integer'], |
|
|
[['id_user', 'id_user_action', 'id_commande', 'id_etablissement'], 'integer'], |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function attributeLabels() { |
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'id' => 'ID', |
|
|
'id' => 'ID', |
|
|
'id_user' => 'Utilisateur', |
|
|
'id_user' => 'Utilisateur', |
|
|
|
|
|
|
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUser() { |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Relations |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public function getUser() |
|
|
|
|
|
{ |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user']); |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserAction() { |
|
|
|
|
|
|
|
|
public function getUserAction() |
|
|
|
|
|
{ |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user_action']); |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user_action']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCommande() { |
|
|
|
|
|
|
|
|
public function getCommande() |
|
|
|
|
|
{ |
|
|
return $this->hasOne(Commande::className(), ['id' => 'id_commande']); |
|
|
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) { |
|
|
switch ($this->type) { |
|
|
case 'paiement': |
|
|
case 'paiement': |
|
|
return 'Paiement'; |
|
|
return 'Paiement'; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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 |
|
|
// initialisation du commentaire avant sauvegarde |
|
|
$this->commentaire .= $this->getStrCommentaire() ; |
|
|
$this->commentaire .= $this->getStrCommentaire() ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function isTypeDebit() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne si le CreditHistorique est un débit ou non. |
|
|
|
|
|
* |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
|
|
|
public function isTypeDebit() |
|
|
|
|
|
{ |
|
|
return in_array($this->type, [ |
|
|
return in_array($this->type, [ |
|
|
self::TYPE_DEBIT, |
|
|
self::TYPE_DEBIT, |
|
|
self::TYPE_PAIEMENT, |
|
|
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, [ |
|
|
return in_array($this->type, [ |
|
|
self::TYPE_CREDIT, |
|
|
self::TYPE_CREDIT, |
|
|
self::TYPE_CREDIT_INITIAL, |
|
|
self::TYPE_CREDIT_INITIAL, |
|
|
|
|
|
|
|
|
]) ; |
|
|
]) ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMontant($format = false) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le montant. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $format |
|
|
|
|
|
* @return float |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getMontant($format = false) |
|
|
|
|
|
{ |
|
|
if($format) |
|
|
if($format) |
|
|
return number_format($this->montant,2) .' €' ; |
|
|
return number_format($this->montant,2) .' €' ; |
|
|
else |
|
|
else |
|
|
return $this->montant ; |
|
|
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 = '' ; |
|
|
$str = '' ; |
|
|
|
|
|
|
|
|
if($this->type == self::TYPE_CREDIT_INITIAL) { |
|
|
if($this->type == self::TYPE_CREDIT_INITIAL) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $str ; |
|
|
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 = '' ; |
|
|
$str = '' ; |
|
|
if(strlen($this->commentaire)) { |
|
|
if(strlen($this->commentaire)) { |
|
|
$str .= '<br />' ; |
|
|
$str .= '<br />' ; |
|
|
|
|
|
|
|
|
return $str ; |
|
|
return $str ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getDate($format = false) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne la date. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $format |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getDate($format = false) |
|
|
|
|
|
{ |
|
|
if($format) |
|
|
if($format) |
|
|
return date('d/m/Y à H:i:s',strtotime($this->date)) ; |
|
|
return date('d/m/Y à H:i:s',strtotime($this->date)) ; |
|
|
else |
|
|
else |
|
|
return $this->date ; |
|
|
return $this->date ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getStrMoyenPaiement() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le moyen de paiement. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getStrMoyenPaiement() |
|
|
|
|
|
{ |
|
|
switch($this->moyen_paiement) { |
|
|
switch($this->moyen_paiement) { |
|
|
case CreditHistorique::MOYEN_ESPECES : return 'Espèces' ; |
|
|
case CreditHistorique::MOYEN_ESPECES : return 'Espèces' ; |
|
|
case CreditHistorique::MOYEN_CHEQUE : return 'Chèque' ; |
|
|
case CreditHistorique::MOYEN_CHEQUE : return 'Chèque' ; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function strUserAction() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le libellé de l'utilisateur ayant initié l'action. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function strUserAction() |
|
|
|
|
|
{ |
|
|
if($this->userAction) { |
|
|
if($this->userAction) { |
|
|
return $this->userAction->nom . ' ' . $this->userAction->prenom ; |
|
|
return $this->userAction->nom . ' ' . $this->userAction->prenom ; |
|
|
} |
|
|
} |