@@ -185,6 +185,7 @@ class DocumentController extends BackendController | |||
null, | |||
MeanPayment::TRANSFER, | |||
null, | |||
null, | |||
$document | |||
); | |||
$payment->amount = number_format($payment->amount, 2); |
@@ -402,7 +402,7 @@ class UserController extends BackendController | |||
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | |||
$paymentContainer->getUtils() | |||
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $this->getUserCurrent()); | |||
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $this->getUserCurrent(), $creditForm->comment); | |||
if($creditForm->send_mail) { | |||
$paymentContainer->getNotifier() |
@@ -103,7 +103,7 @@ class CreditForm extends Model | |||
if ($this->validate()) { | |||
$user = $userManager->findOneUserById($this->id_user); | |||
$paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userManager->getCurrent()); | |||
$paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userManager->getCurrent(), $this->comment); | |||
// on prévient l'utilisateur que son compte vient d'être crédité | |||
if($this->send_mail) { |
@@ -163,6 +163,13 @@ $this->addBreadcrumb('Créditer') ; | |||
return ''; | |||
} | |||
], | |||
[ | |||
'label' => 'Commentaire', | |||
'format' => 'raw', | |||
'value' => function ($model) { | |||
return nl2br($model->comment); | |||
} | |||
], | |||
], | |||
]); ?> | |||
</div> |
@@ -451,6 +451,7 @@ class OrderBuilder extends AbstractBuilder | |||
$order->user, | |||
$this->userSolver->getCurrent(), | |||
MeanPayment::CREDIT, | |||
null, | |||
$order | |||
); | |||
} |
@@ -73,7 +73,7 @@ class Payment extends ActiveRecordCommon | |||
[['amount'], 'double'], | |||
[['date_transaction'], 'date', 'format' => 'php:Y-m-d'], | |||
[['type', 'mean_payment'], 'string', 'max' => 255], | |||
[['comment'], 'string', 'max' => 2048], | |||
[['comment', 'summary'], 'string', 'max' => 2048], | |||
]; | |||
} | |||
@@ -94,6 +94,7 @@ class Payment extends ActiveRecordCommon | |||
'id_producer' => 'Producteur', | |||
'mean_payment' => 'Moyen de paiement', | |||
'comment' => 'Commentaire', | |||
'summary' => 'Résumé', | |||
'date_transaction' => 'Date transaction' | |||
]; | |||
} | |||
@@ -288,4 +289,16 @@ class Payment extends ActiveRecordCommon | |||
return $this; | |||
} | |||
public function getSummary(): ?string | |||
{ | |||
return $this->summary; | |||
} | |||
public function setSummary(?string $summary): self | |||
{ | |||
$this->summary = $summary; | |||
return $this; | |||
} | |||
} |
@@ -28,6 +28,7 @@ class PaymentBuilder extends AbstractBuilder | |||
User $user = null, | |||
User $userAction = null, | |||
string $meanPayment = null, | |||
string $comment = null, | |||
Order $order = null, | |||
Invoice $invoice = null | |||
): Payment | |||
@@ -37,6 +38,8 @@ class PaymentBuilder extends AbstractBuilder | |||
$payment->type = $type; | |||
$payment->amount = round($amount, 2); | |||
$payment->populateProducer($producer); | |||
$payment->setMeanPayment($meanPayment); | |||
$payment->setComment($comment); | |||
if($user) { | |||
$payment->populateUser($user); | |||
@@ -54,10 +57,6 @@ class PaymentBuilder extends AbstractBuilder | |||
$payment->populateInvoice($invoice); | |||
} | |||
if($meanPayment) { | |||
$payment->mean_payment = $meanPayment; | |||
} | |||
return $payment; | |||
} | |||
@@ -68,6 +67,7 @@ class PaymentBuilder extends AbstractBuilder | |||
User $user = null, | |||
User $userAction = null, | |||
string $meanPayment = null, | |||
string $comment = null, | |||
Order $order = null, | |||
Invoice $invoice = null | |||
): ?Payment | |||
@@ -76,8 +76,8 @@ class PaymentBuilder extends AbstractBuilder | |||
return null; | |||
} | |||
$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order, $invoice); | |||
$payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment)); | |||
$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $comment, $order, $invoice); | |||
$payment->setSummary($this->orderSolver->getPaymentComment($payment)); | |||
$this->create($payment); | |||
return $payment; |
@@ -28,7 +28,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
} | |||
public function creditUser(User $user, float $amount, string $meanPayment, User $userAction): void | |||
public function creditUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment): void | |||
{ | |||
$this->paymentBuilder->createPayment( | |||
Payment::TYPE_CREDIT, | |||
@@ -36,11 +36,12 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$this->getProducerContext(), | |||
$user, | |||
$userAction, | |||
$meanPayment | |||
$meanPayment, | |||
$comment | |||
); | |||
} | |||
public function debitUser(User $user, float $amount, string $meanPayment, User $userAction): void | |||
public function debitUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment): void | |||
{ | |||
$this->paymentBuilder->createPayment( | |||
Payment::TYPE_DEBIT, | |||
@@ -48,17 +49,18 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$this->getProducerContext(), | |||
$user, | |||
$userAction, | |||
$meanPayment | |||
$meanPayment, | |||
$comment | |||
); | |||
} | |||
public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction): void | |||
public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction, string $comment): void | |||
{ | |||
if($type == Payment::TYPE_CREDIT) { | |||
$this->creditUser($user, $amount, $meanPayment, $userAction); | |||
$this->creditUser($user, $amount, $meanPayment, $userAction, $comment); | |||
} | |||
elseif($type == Payment::TYPE_DEBIT) { | |||
$this->debitUser($user, $amount, $meanPayment, $userAction); | |||
$this->debitUser($user, $amount, $meanPayment, $userAction, $comment); | |||
} | |||
else { | |||
throw new ErrorException('$type a une valeur incorrect'); | |||
@@ -78,6 +80,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$order->user, | |||
$userAction, | |||
$meanPayment, | |||
null, | |||
$order | |||
); | |||
} | |||
@@ -107,6 +110,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$order->user, | |||
$userAction, | |||
MeanPayment::CREDIT, | |||
null, | |||
$order | |||
); | |||
} | |||
@@ -124,6 +128,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$order->user, | |||
$userAction, | |||
$meanPayment, | |||
null, | |||
$order | |||
); | |||
} | |||
@@ -140,6 +145,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$order->user, | |||
$userAction, | |||
MeanPayment::CREDIT, | |||
null, | |||
$order | |||
); | |||
} | |||
@@ -158,6 +164,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$order->user, | |||
$userAction, | |||
MeanPayment::CREDIT, | |||
null, | |||
$order | |||
); | |||
} |
@@ -0,0 +1,26 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\Schema; | |||
/** | |||
* Class m231002_142915_add_column_payment_summary | |||
*/ | |||
class m231002_142915_add_column_payment_summary extends Migration | |||
{ | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeUp() | |||
{ | |||
$this->addColumn('payment', 'summary', Schema::TYPE_TEXT); | |||
} | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeDown() | |||
{ | |||
$this->dropColumn('payment', 'summary'); | |||
} | |||
} |