{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
$json = [ | $json = [ | ||||
'distribution' => [], | 'distribution' => [], | ||||
'products' => [] | 'products' => [] | ||||
foreach ($order->creditHistory as $creditHistory) { | foreach ($order->creditHistory as $creditHistory) { | ||||
$creditHistoryArray[] = [ | $creditHistoryArray[] = [ | ||||
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | 'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | ||||
'user' => $creditHistory->user->getUsername(), | |||||
'user_action' => $creditHistory->strUserAction(), | |||||
'wording' => $creditHistory->getStrWording(), | |||||
'debit' => ($creditHistory->isTypeDebit() ? '- ' . $creditHistory->getAmount( | |||||
'user' => $creditHistory->getUserObject()->getUsername(), | |||||
'user_action' => $creditHistoryService->getStrUserAction($creditHistory), | |||||
'wording' => $creditHistoryService->getStrWording($creditHistory), | |||||
'debit' => ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmount( | |||||
$creditHistory, | |||||
Order::AMOUNT_TOTAL, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
) : ''), | ) : ''), | ||||
'credit' => ($creditHistory->isTypeCredit() ? '+ ' . $creditHistory->getAmount( | |||||
'credit' => ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmount( | |||||
$creditHistory, | |||||
Order::AMOUNT_TOTAL, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
) : '') | ) : '') |
*/ | */ | ||||
public function actionPaymentStatus($idOrder) | public function actionPaymentStatus($idOrder) | ||||
{ | { | ||||
$creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
$order = Order::searchOne(['id' => $idOrder]); | $order = Order::searchOne(['id' => $idOrder]); | ||||
if ($order) { | if ($order) { | ||||
. '<tbody>'; | . '<tbody>'; | ||||
if ($history && is_array($history) && count($history)) { | if ($history && is_array($history) && count($history)) { | ||||
foreach ($history as $h) { | |||||
foreach ($history as $creditHistory) { | |||||
$html .= '<tr>' | $html .= '<tr>' | ||||
. '<td>' . date('d/m/Y H:i:s', strtotime($h->date)) . '</td>' | |||||
. '<td>' . Html::encode($h->strUserAction()) . '</td>' | |||||
. '<td>' . $h->getStrWording() . '</td>' | |||||
. '<td>' . ($h->isTypeDebit() ? '- ' . $h->getAmountWithTax(Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . ($h->isTypeCredit() ? '+ ' . $h->getAmountWithTax(Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . date('d/m/Y H:i:s', strtotime($creditHistoryService->getDate($creditHistory))) . '</td>' | |||||
. '<td>' . Html::encode($creditHistoryService->getStrUserAction($creditHistory)) . '</td>' | |||||
. '<td>' . $creditHistoryService->getStrWording($creditHistory) . '</td>' | |||||
. '<td>' . ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '</tr>'; | . '</tr>'; | ||||
} | } | ||||
} else { | } else { |
*/ | */ | ||||
public function save() | public function save() | ||||
{ | { | ||||
$creditHistoryService = Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
if ($this->validate()) { | if ($this->validate()) { | ||||
$creditHistory = new CreditHistory; | $creditHistory = new CreditHistory; | ||||
$creditHistory->id_user = $this->id_user; | $creditHistory->id_user = $this->id_user; | ||||
$creditHistory->comment = $this->comment ; | $creditHistory->comment = $this->comment ; | ||||
$creditHistory->amount = $this->amount ; | $creditHistory->amount = $this->amount ; | ||||
$creditHistory->mean_payment = $this->mean_payment ; | $creditHistory->mean_payment = $this->mean_payment ; | ||||
$creditHistory->save(); | |||||
$creditHistoryService->save($creditHistory); | |||||
// on prévient l'utilisateur que son compte vient d'être crédité | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { |
<tbody> | <tbody> | ||||
<?php if(count($history)): ?> | <?php if(count($history)): ?> | ||||
<?php foreach($history as $creditHistory): ?> | <?php foreach($history as $creditHistory): ?> | ||||
<tr> | <tr> | ||||
<td><?= $creditHistory->getDate(true) ; ?></td> | |||||
<td><?= $creditHistoryService->getDate($creditHistory, true) ; ?></td> | |||||
<td><?= Html::encode($creditHistoryService->getStrUserAction($creditHistory)); ?></td> | <td><?= Html::encode($creditHistoryService->getStrUserAction($creditHistory)); ?></td> | ||||
<td><?= $creditHistoryService->getStrWording($creditHistory); ?></td> | <td><?= $creditHistoryService->getStrWording($creditHistory); ?></td> | ||||
<td> | <td> |
namespace common\models; | namespace common\models; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use yii\db\ActiveQuery; | |||||
/** | |||||
* This is the model class for table "credit_historique". | |||||
* | |||||
* @property integer $id | |||||
* @property integer $id_user | |||||
* @property integer $id_order | |||||
* @property string $date | |||||
* @property double $amount | |||||
* @property string $type | |||||
* @property integer $id_producer | |||||
* @property string $mean_payment | |||||
*/ | |||||
class CreditHistory extends ActiveRecordCommon | class CreditHistory extends ActiveRecordCommon | ||||
{ | { | ||||
const TYPE_INITIAL_CREDIT = 'initial-credit'; | const TYPE_INITIAL_CREDIT = 'initial-credit'; | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public static function tableName() | |||||
public static function tableName(): string | |||||
{ | { | ||||
return 'credit_history'; | return 'credit_history'; | ||||
} | } | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function rules() | |||||
public function rules(): array | |||||
{ | { | ||||
return [ | return [ | ||||
[['amount'], 'required'], | [['amount'], 'required'], | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
public function attributeLabels(): array | |||||
{ | { | ||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
* Relations | * Relations | ||||
*/ | */ | ||||
public function getUser() | |||||
public function getUser(): ActiveQuery | |||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(User::class, ['id' => 'id_user']); | |||||
} | } | ||||
public function getUserObject() | |||||
public function getUserObject(): ?User | |||||
{ | { | ||||
return $this->user; | return $this->user; | ||||
} | } | ||||
public function getUserAction() | |||||
public function getUserAction(): ActiveQuery | |||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user_action']); | |||||
return $this->hasOne(User::class, ['id' => 'id_user_action']); | |||||
} | } | ||||
public function getUserActionObject() | |||||
public function getUserActionObject(): ?User | |||||
{ | { | ||||
return $this->userAction; | return $this->userAction; | ||||
} | } | ||||
public function getOrder() | |||||
public function getOrder(): ActiveQuery | |||||
{ | { | ||||
return $this->hasOne(Order::className(), ['id' => 'id_order']); | |||||
return $this->hasOne(Order::class, ['id' => 'id_order']); | |||||
} | } | ||||
public function getOrderObject() | |||||
public function getOrderObject(): ?Order | |||||
{ | { | ||||
return $this->order; | return $this->order; | ||||
} | } | ||||
/* | /* | ||||
* Getters / setters | * Getters / setters | ||||
*/ | */ | ||||
public function getId() | |||||
public function getId(): int | |||||
{ | { | ||||
return $this->id; | return $this->id; | ||||
} | } | ||||
public function getIdUser() | |||||
public function getIdUser(): ?int | |||||
{ | { | ||||
return $this->id_user; | return $this->id_user; | ||||
} | } | ||||
public function setIdUser($idUser) | |||||
public function setIdUser(?int $idUser): self | |||||
{ | { | ||||
$this->id_user = $idUser; | $this->id_user = $idUser; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getIdUserAction() | |||||
public function getIdUserAction(): ?int | |||||
{ | { | ||||
return $this->id_user_action; | return $this->id_user_action; | ||||
} | } | ||||
public function setIdUserAction($idUserAction) | |||||
public function setIdUserAction(?int $idUserAction): self | |||||
{ | { | ||||
$this->id_user_action = $idUserAction; | $this->id_user_action = $idUserAction; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getIdOrder() | |||||
public function getIdOrder(): ?int | |||||
{ | { | ||||
return $this->id_order; | return $this->id_order; | ||||
} | } | ||||
public function setIdOrder($idOrder) | |||||
public function setIdOrder(?int $idOrder): self | |||||
{ | { | ||||
$this->id_order = $idOrder; | $this->id_order = $idOrder; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDate() | |||||
public function getDate(): ?string | |||||
{ | { | ||||
return $this->date; | return $this->date; | ||||
} | } | ||||
public function setDate($date) | |||||
public function setDate(?string $date): self | |||||
{ | { | ||||
$this->date = $date; | $this->date = $date; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAmount() | |||||
public function getAmount(): ?float | |||||
{ | { | ||||
return $this->amount; | return $this->amount; | ||||
} | } | ||||
public function setAmount($amount) | |||||
public function setAmount(?float $amount): self | |||||
{ | { | ||||
$this->amount = $amount; | $this->amount = $amount; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getType() | |||||
public function getType(): ?string | |||||
{ | { | ||||
return $this->type; | return $this->type; | ||||
} | } | ||||
public function setType($type) | |||||
public function setType(?string $type): self | |||||
{ | { | ||||
$this->type = $type; | $this->type = $type; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getIdProducer() | |||||
public function getIdProducer(): ?int | |||||
{ | { | ||||
return $this->id_producer; | return $this->id_producer; | ||||
} | } | ||||
public function setIdProducer($idProducer) | |||||
public function setIdProducer(?int $idProducer): self | |||||
{ | { | ||||
$this->id_producer = $idProducer; | $this->id_producer = $idProducer; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getMeanPayment() | |||||
public function getMeanPayment(): ?string | |||||
{ | { | ||||
return $this->mean_payment; | return $this->mean_payment; | ||||
} | } | ||||
public function setMeanPayment($meanPayment) | |||||
public function setMeanPayment(?string $meanPayment): self | |||||
{ | { | ||||
$this->mean_payment = $meanPayment; | $this->mean_payment = $meanPayment; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getComment() | |||||
public function getComment(): ?string | |||||
{ | { | ||||
return $this->comment; | return $this->comment; | ||||
} | } | ||||
public function setComment($comment) | |||||
public function setComment(?string $comment): self | |||||
{ | { | ||||
$this->comment = $comment; | $this->comment = $comment; | ||||
]; | ]; | ||||
} | } | ||||
public function getDate(): string | |||||
{ | |||||
return $this->date; | |||||
} | |||||
/** | /** | ||||
* Retourne si un produit est actif ou non. | * Retourne si un produit est actif ou non. | ||||
* | * |
->with('producer'); | ->with('producer'); | ||||
} | } | ||||
public function getDistributionOject(): ?Distribution | |||||
{ | |||||
return $this->distribution; | |||||
} | |||||
public function getPointSale() | public function getPointSale() | ||||
{ | { | ||||
return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']) | return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']) | ||||
*/ | */ | ||||
public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction) | public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction) | ||||
{ | { | ||||
$creditHistoryService = Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
$creditHistory = new CreditHistory; | $creditHistory = new CreditHistory; | ||||
$creditHistory->id_user = $idUser; | $creditHistory->id_user = $idUser; | ||||
$creditHistory->id_order = $this->id; | $creditHistory->id_order = $this->id; | ||||
$creditHistory->id_user_action = $idUserAction; | $creditHistory->id_user_action = $idUserAction; | ||||
$creditHistory->populateRelation('order', $this); | $creditHistory->populateRelation('order', $this); | ||||
$creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one()); | $creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one()); | ||||
$creditHistory->save(); | |||||
$creditHistoryService->save($creditHistory); | |||||
} | } | ||||
/** | /** |
namespace common\repositories; | namespace common\repositories; | ||||
use common\models\CreditHistory; | use common\models\CreditHistory; | ||||
use common\models\User; | |||||
class CreditHistoryRepository | class CreditHistoryRepository | ||||
{ | { |
class CreditHistoryService | class CreditHistoryService | ||||
{ | { | ||||
/** | |||||
* Enregistre le modèle. | |||||
* | |||||
* @param boolean $runValidation | |||||
* @param array $attributeNames | |||||
*/ | |||||
public function save($creditHistory) | |||||
public function save(CreditHistory $creditHistory): bool | |||||
{ | { | ||||
if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) { | if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) { | ||||
return false; | return false; | ||||
} | } | ||||
// initialisation du commentaire avant sauvegarde | |||||
// Initialisation du commentaire avant sauvegarde | |||||
$creditHistory->setComment($creditHistory->getComment() . $this->getStrComment($creditHistory)); | $creditHistory->setComment($creditHistory->getComment() . $this->getStrComment($creditHistory)); | ||||
$creditHistory->save(); | $creditHistory->save(); | ||||
// Mise à jour du crédit au niveau de UserProducer | // Mise à jour du crédit au niveau de UserProducer | ||||
Yii::$app->logic->getUserProducerContainer()->getService()->updateCredit($creditHistory); | |||||
\Yii::$app->logic->getUserProducerContainer()->getService()->updateCredit($creditHistory); | |||||
return true; | |||||
} | } | ||||
/** | |||||
* Retourne si le CreditHistorique est un débit ou non. | |||||
* | |||||
* @return boolean | |||||
*/ | |||||
public function isTypeDebit($creditHistory) | |||||
public function isTypeDebit(CreditHistory $creditHistory): bool | |||||
{ | { | ||||
return in_array($creditHistory->type, [ | return in_array($creditHistory->type, [ | ||||
CreditHistory::TYPE_DEBIT, | CreditHistory::TYPE_DEBIT, | ||||
]); | ]); | ||||
} | } | ||||
/** | |||||
* Retourne si le CreditHistorique est un crédit ou non. | |||||
* | |||||
* @return boolean | |||||
*/ | |||||
public function isTypeCredit($creditHistory) | |||||
public function isTypeCredit(CreditHistory $creditHistory): bool | |||||
{ | { | ||||
return in_array($creditHistory->type, [ | return in_array($creditHistory->type, [ | ||||
CreditHistory::TYPE_CREDIT, | CreditHistory::TYPE_CREDIT, | ||||
]); | ]); | ||||
} | } | ||||
/** | |||||
* Retourne le montant. | |||||
* | |||||
* @param boolean $format | |||||
* @return float | |||||
*/ | |||||
public function getAmount($creditHistory, $format = false) | |||||
public function getAmount(CreditHistory $creditHistory, bool $format = false): string | |||||
{ | { | ||||
if ($format) { | if ($format) { | ||||
return number_format($creditHistory->amount, 2) . ' €'; | return number_format($creditHistory->amount, 2) . ' €'; | ||||
} | |||||
else { | |||||
} else { | |||||
return $creditHistory->amount; | return $creditHistory->amount; | ||||
} | } | ||||
} | } | ||||
* Retourne le libellé du CreditHistory informant de son type et | * Retourne le libellé du CreditHistory informant de son type et | ||||
* éventuellement de la date de sa commande associée. | * éventuellement de la date de sa commande associée. | ||||
* | * | ||||
* @return string | |||||
*/ | */ | ||||
public function getStrWording($creditHistory) | |||||
public function getStrWording(CreditHistory $creditHistory): string | |||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
$type = $creditHistory->getType(); | |||||
if ($creditHistory->type == CreditHistory::TYPE_INITIAL_CREDIT) { | |||||
if (CreditHistory::TYPE_INITIAL_CREDIT == $type) { | |||||
$str = 'Crédit initial'; | $str = 'Crédit initial'; | ||||
} | |||||
elseif ($creditHistory->type == CreditHistory::TYPE_CREDIT) { | |||||
} elseif (CreditHistory::TYPE_CREDIT == $type) { | |||||
$str = 'Crédit'; | $str = 'Crédit'; | ||||
} | |||||
elseif ($creditHistory->type == CreditHistory::TYPE_PAYMENT) { | |||||
} elseif (CreditHistory::TYPE_PAYMENT == $type) { | |||||
$str = 'Paiement'; | $str = 'Paiement'; | ||||
} | |||||
elseif ($creditHistory->type == CreditHistory::TYPE_REFUND) { | |||||
} elseif (CreditHistory::TYPE_REFUND == $type) { | |||||
$str = 'Remboursement'; | $str = 'Remboursement'; | ||||
} | |||||
elseif ($creditHistory->type == CreditHistory::TYPE_DEBIT) { | |||||
} elseif (CreditHistory::TYPE_DEBIT == $type) { | |||||
$str = 'Débit'; | $str = 'Débit'; | ||||
} | } | ||||
if ($creditHistory->type == CreditHistory::TYPE_PAYMENT || $creditHistory->type == CreditHistory::TYPE_REFUND) { | |||||
if (isset($creditHistory->order) && isset($creditHistory->order->distribution)) { | |||||
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($creditHistory->order->distribution->date)); | |||||
} | |||||
else { | |||||
if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) { | |||||
$order = $creditHistory->getOrderObject(); | |||||
if ($order && $order->getDistributionOject()) { | |||||
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->getDistributionOject()->getDate())); | |||||
} else { | |||||
$str .= '<br />Commande supprimée'; | $str .= '<br />Commande supprimée'; | ||||
} | } | ||||
} | } | ||||
* Retourne les informations à ajouter au commentaire du CreditHistorique | * Retourne les informations à ajouter au commentaire du CreditHistorique | ||||
* (libellé, montant, client, action) au format HTML. | * (libellé, montant, client, action) au format HTML. | ||||
* | * | ||||
* @return string | |||||
*/ | */ | ||||
public function getStrComment($creditHistory) | |||||
public function getStrComment(CreditHistory $creditHistory): string | |||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
if (strlen($creditHistory->getComment())) { | if (strlen($creditHistory->getComment())) { | ||||
$str .= '<br />'; | $str .= '<br />'; | ||||
} | } | ||||
$str .= $this->getStrWording(); | |||||
if ($creditHistory->getOrder()) { | |||||
$str .= '<br />Montant de la commande : ' . $creditHistory->getOrder()->getAmountWithTax(Order::AMOUNT_TOTAL, true); | |||||
$str .= $this->getStrWording($creditHistory); | |||||
$order = $creditHistory->getOrderObject(); | |||||
if ($order) { | |||||
$str .= '<br />Montant de la commande : ' . $order->getAmountWithTax(Order::AMOUNT_TOTAL, true); | |||||
} | } | ||||
if ($creditHistory->getUser()) { | |||||
$str .= '<br />Client : ' . Html::encode($creditHistory->getUser()->name . ' ' . $creditHistory->user->lastname); | |||||
$user = $creditHistory->getUserObject(); | |||||
if ($user) { | |||||
$str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname()); | |||||
} | } | ||||
if ($creditHistory->getUserAction()) { | |||||
$str .= '<br />Action : ' . Html::encode($creditHistory->getUserAction()->name . ' ' . $creditHistory->userAction->lastname); | |||||
$userAction = $creditHistory->getUserActionObject(); | |||||
if ($userAction) { | |||||
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname()); | |||||
} | } | ||||
return $str; | return $str; | ||||
} | } | ||||
/** | |||||
* Retourne la date. | |||||
* | |||||
* @param boolean $format | |||||
* @return string | |||||
*/ | |||||
public function getDate($creditHistory, $format = false) | |||||
public function getDate(CreditHistory $creditHistory, bool $format = false): string | |||||
{ | { | ||||
$date = $creditHistory->getDate(); | $date = $creditHistory->getDate(); | ||||
if ($format) { | if ($format) { | ||||
return date('d/m/Y à H:i:s', strtotime($date)); | return date('d/m/Y à H:i:s', strtotime($date)); | ||||
} | |||||
else { | |||||
} else { | |||||
return $date; | return $date; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Retourne le libellé du moyen de paiement du CreditHistory courant. | |||||
* | |||||
* @return string | |||||
*/ | |||||
public function getStrMeanPayment($creditHistory) | |||||
public function getStrMeanPayment(CreditHistory $creditHistory): string | |||||
{ | { | ||||
return MeanPayment::getStrBy($creditHistory->getMeanPayment()); | return MeanPayment::getStrBy($creditHistory->getMeanPayment()); | ||||
} | } | ||||
/** | |||||
* Retourne le libellé de l'utilisateur ayant initié l'action. | |||||
* | |||||
* @return string | |||||
*/ | |||||
// strUserAction | // strUserAction | ||||
public function getStrUserAction($creditHistory) | |||||
public function getStrUserAction(CreditHistory $creditHistory): string | |||||
{ | { | ||||
$userAction = $creditHistory->getUserActionObject(); | $userAction = $creditHistory->getUserActionObject(); | ||||
if ($userAction) { | if ($userAction) { | ||||
return $userAction->name . ' ' . $userAction->lastname; | |||||
} | |||||
else { | |||||
return $userAction->getName() . ' ' . $userAction->getlastname(); | |||||
} else { | |||||
return 'Système'; | return 'Système'; | ||||
} | } | ||||
} | } |
class UserProducerService | class UserProducerService | ||||
{ | { | ||||
protected CreditHistoryService $creditHistoryService; | |||||
public function __construct() | |||||
{ | |||||
$this->creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
} | |||||
public function updateCredit($creditHistory) | public function updateCredit($creditHistory) | ||||
{ | { | ||||
$userProducer = Yii::$app->logic->getUserProducerContainer()->getRepository()->getOne($creditHistory->id_user, $creditHistory->id_producer); | $userProducer = Yii::$app->logic->getUserProducerContainer()->getRepository()->getOne($creditHistory->id_user, $creditHistory->id_producer); | ||||
public function deductCredit($userProducer, $creditHistory) | public function deductCredit($userProducer, $creditHistory) | ||||
{ | { | ||||
if ($creditHistory->isTypeCredit()) { | |||||
if ($this->creditHistoryService->isTypeCredit($creditHistory)) { | |||||
$userProducer->credit += $creditHistory->amount; | $userProducer->credit += $creditHistory->amount; | ||||
} elseif ($creditHistory->isTypeDebit()) { | |||||
} elseif ($this->creditHistoryService->isTypeDebit($creditHistory)) { | |||||
$userProducer->credit -= $creditHistory->amount; | $userProducer->credit -= $creditHistory->amount; | ||||
} | } | ||||
}, | }, | ||||
"minimum-stability": "stable", | "minimum-stability": "stable", | ||||
"require": { | "require": { | ||||
"php": ">=5.4.0", | |||||
"php": ">=7.4", | |||||
"yiisoft/yii2": "*", | "yiisoft/yii2": "*", | ||||
"yiisoft/yii2-bootstrap": "*", | "yiisoft/yii2-bootstrap": "*", | ||||
"yiisoft/yii2-swiftmailer": "*", | "yiisoft/yii2-swiftmailer": "*", |
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||
"This file is @generated automatically" | "This file is @generated automatically" | ||||
], | ], | ||||
"content-hash": "96d4dfea93de951d74c4d1d099ed27ed", | |||||
"content-hash": "78a16f604e3b8e2cb623f7204619682f", | |||||
"packages": [ | "packages": [ | ||||
{ | { | ||||
"name": "2amigos/yii2-chartjs-widget", | "name": "2amigos/yii2-chartjs-widget", | ||||
"prefer-stable": false, | "prefer-stable": false, | ||||
"prefer-lowest": false, | "prefer-lowest": false, | ||||
"platform": { | "platform": { | ||||
"php": ">=5.4.0" | |||||
"php": ">=7.4" | |||||
}, | }, | ||||
"platform-dev": [], | "platform-dev": [], | ||||
"plugin-api-version": "2.3.0" | "plugin-api-version": "2.3.0" |
public function actionStripeVerification() | public function actionStripeVerification() | ||||
{ | { | ||||
$creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
$producer = $this->getProducer(); | $producer = $this->getProducer(); | ||||
$contactProducer = $producer->getMainContact(); | $contactProducer = $producer->getMainContact(); | ||||
$creditHistory->comment = null; | $creditHistory->comment = null; | ||||
$creditHistory->amount = $amount; | $creditHistory->amount = $amount; | ||||
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD; | $creditHistory->mean_payment = MeanPayment::CREDIT_CARD; | ||||
$creditHistory->save(); | |||||
$creditHistoryService->save($creditHistory); | |||||
if (isset($order) && $order) { | if (isset($order) && $order) { | ||||
// paiement de la commande | // paiement de la commande |
* termes. | * termes. | ||||
*/ | */ | ||||
use yii\helpers\Html; | |||||
use yii\grid\GridView; | |||||
use ruskid\stripe\StripeCheckoutCustom; | use ruskid\stripe\StripeCheckoutCustom; | ||||
use yii\web\JsExpression; | |||||
$creditHistoryService = Yii::$app->logic->getCreditHistoryContainer()->getService(); | |||||
$producer = $this->context->getProducer(); | $producer = $this->context->getProducer(); | ||||
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | $this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | ||||
$this->setPageTitle('Crédit'); | $this->setPageTitle('Crédit'); | ||||
if ($this->context->getProducer()->online_payment) { | if ($this->context->getProducer()->online_payment) { | ||||
$this->addButton( | $this->addButton( | ||||
[ | |||||
'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte', | |||||
'url' => 'credit/add', | |||||
'class' => 'btn btn-primary' | |||||
] | |||||
[ | |||||
'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte', | |||||
'url' => 'credit/add', | |||||
'class' => 'btn btn-primary' | |||||
] | |||||
); | ); | ||||
} | } | ||||
?> | ?> | ||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
// 'filterModel' => $searchModel, | |||||
'dataProvider' => $dataProvider, | |||||
'columns' => [ | |||||
[ | |||||
'attribute' => 'date', | |||||
'value' => function ($model) { | |||||
return $model->getDate(true); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'id_user_action', | |||||
'value' => function ($model) { | |||||
return $model->strUserAction(); | |||||
} | |||||
], | |||||
[ | |||||
'label' => 'Type', | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
return $model->getStrWording(); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'mean_payment', | |||||
'value' => function ($model) { | |||||
return $model->getStrMeanPayment(); | |||||
} | |||||
], | |||||
[ | |||||
'label' => '- Débit', | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
if ($model->isTypeDebit()) { | |||||
return '- ' . $model->getAmount(true); | |||||
} | |||||
return ''; | |||||
} | |||||
], | |||||
[ | |||||
'label' => '+ Crédit', | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
if ($model->isTypeCredit()) { | |||||
return '+ ' . $model->getAmount(true); | |||||
} | |||||
return ''; | |||||
} | |||||
], | |||||
], | |||||
]); | |||||
'dataProvider' => $dataProvider, | |||||
'columns' => [ | |||||
[ | |||||
'attribute' => 'date', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
return $creditHistoryService->getDate($model, true); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'id_user_action', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
return $creditHistoryService->getStrUserAction($model); | |||||
} | |||||
], | |||||
[ | |||||
'label' => 'Type', | |||||
'format' => 'raw', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
return $creditHistoryService->getStrWording($model); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'mean_payment', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
return $creditHistoryService->getStrMeanPayment($model); | |||||
} | |||||
], | |||||
[ | |||||
'label' => '- Débit', | |||||
'format' => 'raw', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
if ($creditHistoryService->isTypeDebit($model)) { | |||||
return '- ' . $creditHistoryService->getAmount($model, true); | |||||
} | |||||
return ''; | |||||
} | |||||
], | |||||
[ | |||||
'label' => '+ Crédit', | |||||
'format' => 'raw', | |||||
'value' => function ($model) use ($creditHistoryService) { | |||||
if ($creditHistoryService->isTypeCredit($model)) { | |||||
return '+ ' . $creditHistoryService->getAmount($model, true); | |||||
} | |||||
return ''; | |||||
} | |||||
], | |||||
], | |||||
]); | |||||
?> | ?> |