Bläddra i källkod

Refactoring/traduction modèle CreditHistorique > CreditHistory

dev
Guillaume Bourgeois 6 år sedan
förälder
incheckning
ca80851ee4
1 ändrade filer med 74 tillägg och 56 borttagningar
  1. +74
    -56
      common/models/CreditHistory.php

+ 74
- 56
common/models/CreditHistory.php Visa fil

@@ -41,7 +41,7 @@ namespace common\models;
use Yii;
use yii\db\ActiveRecord;
use common\models\User;
use common\models\Commande;
use common\models\Order;
use yii\helpers\Html;

/**
@@ -49,26 +49,26 @@ use yii\helpers\Html;
*
* @property integer $id
* @property integer $id_user
* @property integer $id_commande
* @property integer $id_order
* @property string $date
* @property double $montant
* @property double $amount
* @property string $type
* @property integer $id_etablissement
* @property string $moyen_paiement
* @property integer $id_producer
* @property string $means_payement
*/
class CreditHistory extends ActiveRecord
{

const TYPE_INITIAL_CREDIT = 'initial-credit';
const TYPE_CREDIT = 'credit';
const TYPE_PAYMENT = 'payment';
const TYPE_REFUND= 'refund';
const TYPE_DEBIT = 'debit';
const TYPE_INITIAL_CREDIT = 'initial-credit';
const TYPE_CREDIT = 'credit';
const TYPE_PAYMENT = 'payment';
const TYPE_REFUND = 'refund';
const TYPE_DEBIT = 'debit';
const PAYMENT_CREDIT_CARD = 'credit-card';
const PAYMENT_MONEY = 'money';
const PAYMENT_CHEQUE = 'cheque';
const PAYMENT_OTHER = 'other';
const MEANS_PAYMENT_CREDIT_CARD = 'credit-card';
const MEANS_PAYMENT_MONEY = 'money';
const MEANS_PAYMENT_CHEQUE = 'cheque';
const MEANS_PAYMENT_OTHER = 'other';
/**
* @inheritdoc
@@ -85,10 +85,10 @@ class CreditHistory extends ActiveRecord
{
return [
[['montant'], 'required'],
[['id_user', 'id_user_action', 'id_commande', 'id_etablissement'], 'integer'],
[['id_user', 'id_user_action', 'id_order', 'id_producer'], 'integer'],
[['date'], 'safe'],
[['montant'], 'double'],
[['type', 'moyen_paiement', 'commentaire'], 'string', 'max' => 255],
[['amount'], 'double'],
[['type', 'means_payment', 'comment'], 'string', 'max' => 255],
];
}

@@ -101,15 +101,17 @@ class CreditHistory extends ActiveRecord
'id' => 'ID',
'id_user' => 'Utilisateur',
'id_user_action' => 'Utilisateur',
'id_commande' => 'Commande',
'id_order' => 'Commande',
'date' => 'Date',
'montant' => 'Montant',
'amount' => 'Montant',
'type' => 'Type',
'id_etablissement' => 'Établissement',
'moyen_paiement' => 'Moyen de paiement',
'commentaire' => 'Commentaire',
'id_producer' => 'Producteur',
'means_payment' => 'Moyen de paiement',
'comment' => 'Commentaire',
];
}

/*
* Relations
@@ -125,9 +127,24 @@ class CreditHistory extends ActiveRecord
return $this->hasOne(User::className(), ['id' => 'id_user_action']);
}

public function getCommande()
public function getOrder()
{
return $this->hasOne(Commande::className(), ['id' => 'id_commande']);
return $this->hasOne(Order::className(), ['id' => 'id_order']);
}
/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch() {
return [
'class' => 'CreditHistory',
'with' => [],
'join_with' => [],
'orderby' => self::tableName().'.date ASc',
'attribute_id_producer' => self::tableName().'.id_producer'
] ;
}

/**
@@ -135,16 +152,16 @@ class CreditHistory extends ActiveRecord
*
* @return string
*/
public function getLibelleType()
public function getStrType()
{
switch ($this->type) {
case 'paiement':
case self::TYPE_PAYMENT:
return 'Paiement';
break;
case 'remboursement':
case self::TYPE_REFUND:
return 'Remboursement';
break;
case 'debit':
case self::TYPE_DEBIT:
return 'Débit';
break;
}
@@ -159,22 +176,23 @@ class CreditHistory extends ActiveRecord
public function save($runValidation = true, $attributeNames = NULL)
{
// initialisation du commentaire avant sauvegarde
$this->commentaire .= $this->getStrCommentaire() ;
$this->comment .= $this->getStrComment() ;
parent::save($runValidation, $attributeNames);

// mise à jour du crédit au niveau de UserEtablissement
$user_etablissement = UserEtablissement::findOne([
'id_user' => $this->id_user,
'id_etablissement' => $this->id_etablissement
]);
if ($user_etablissement) {
$userProducer = UserProducer::searchOne([
'id_user' => $this->id_user,
'id_producer' => $this->id_producer
]) ;
if ($userProducer) {
if ($this->isTypeCredit()) {
$user_etablissement->credit += $this->montant;
$userProducer->credit += $this->amount;
} elseif ($this->isTypeDebit()) {
$user_etablissement->credit -= $this->montant;
$userProducer->credit -= $this->amount;
}
$user_etablissement->save();
$userProducer->save();
}
}
@@ -211,21 +229,21 @@ class CreditHistory extends ActiveRecord
* @param boolean $format
* @return float
*/
public function getMontant($format = false)
public function getAmount($format = false)
{
if($format)
return number_format($this->montant,2) .' €' ;
return number_format($this->amount,2) .' €' ;
else
return $this->montant ;
return $this->amount ;
}
/**
* Retourne le libellé du CreditHistorique informant de son type et
* Retourne le libellé du CreditHistory informant de son type et
* éventuellement de la date de sa commande associée.
*
* @return string
*/
public function getStrLibelle()
public function getStrWording()
{
$str = '' ;
@@ -264,21 +282,21 @@ class CreditHistory extends ActiveRecord
*
* @return string
*/
public function getStrCommentaire()
public function getStrComment()
{
$str = '' ;
if(strlen($this->commentaire)) {
if(strlen($this->comment)) {
$str .= '<br />' ;
}
$str .= $this->getStrLibelle() ;
if(isset($this->commande)) {
$str .= '<br />Montant de la commande : '.$this->commande->getMontant(true) ;
$str .= $this->getStrWording() ;
if(isset($this->order)) {
$str .= '<br />Montant de la commande : '.$this->order->getAmount(Order::AMOUNT_TOTAL, true) ;
}
if(isset($this->user)) {
$str .= '<br />Client : '.Html::encode($this->user->nom. ' '.$this->user->prenom) ;
$str .= '<br />Client : '.Html::encode($this->user->name. ' '.$this->user->lastname) ;
}
if(isset($this->userAction)) {
$str .= '<br />Action : '.Html::encode($this->userAction->nom. ' '.$this->userAction->prenom) ;
$str .= '<br />Action : '.Html::encode($this->userAction->name. ' '.$this->userAction->lastname) ;
}
return $str ;
@@ -303,13 +321,13 @@ class CreditHistory extends ActiveRecord
*
* @return string
*/
public function getStrMoyenPaiement()
public function getStrMeansPayment()
{
switch($this->moyen_paiement) {
case CreditHistorique::MOYEN_ESPECES : return 'Espèces' ;
case CreditHistorique::MOYEN_CHEQUE : return 'Chèque' ;
case CreditHistorique::MOYEN_CB : return 'Carte bancaire' ;
case CreditHistorique::MOYEN_AUTRE : return 'Autre' ;
switch($this->means_payment) {
case CreditHistory::MEANS_PAYMENT_MONEY : return 'Espèces' ;
case CreditHistory::MEANS_PAYMENT_CHEQUE : return 'Chèque' ;
case CreditHistory::MEANS_PAYMENT_CREDIT_CARD : return 'Carte bancaire' ;
case CreditHistory::MEANS_PAYMENT_OTHER : return 'Autre' ;
default: return 'Crédit pain' ;
}
}
@@ -322,7 +340,7 @@ class CreditHistory extends ActiveRecord
public function strUserAction()
{
if($this->userAction) {
return $this->userAction->nom . ' ' . $this->userAction->prenom ;
return $this->userAction->name . ' ' . $this->userAction->lastname ;
}
else {
return 'Système' ;

Laddar…
Avbryt
Spara