null, | null, | ||||
MeanPayment::TRANSFER, | MeanPayment::TRANSFER, | ||||
null, | null, | ||||
null, | |||||
$document | $document | ||||
); | ); | ||||
$payment->amount = number_format($payment->amount, 2); | $payment->amount = number_format($payment->amount, 2); |
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | ||||
$paymentContainer->getUtils() | $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) { | if($creditForm->send_mail) { | ||||
$paymentContainer->getNotifier() | $paymentContainer->getNotifier() |
if ($this->validate()) { | if ($this->validate()) { | ||||
$user = $userManager->findOneUserById($this->id_user); | $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é | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { |
return ''; | return ''; | ||||
} | } | ||||
], | ], | ||||
[ | |||||
'label' => 'Commentaire', | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
return nl2br($model->comment); | |||||
} | |||||
], | |||||
], | ], | ||||
]); ?> | ]); ?> | ||||
</div> | </div> |
$order->user, | $order->user, | ||||
$this->userSolver->getCurrent(), | $this->userSolver->getCurrent(), | ||||
MeanPayment::CREDIT, | MeanPayment::CREDIT, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } |
[['amount'], 'double'], | [['amount'], 'double'], | ||||
[['date_transaction'], 'date', 'format' => 'php:Y-m-d'], | [['date_transaction'], 'date', 'format' => 'php:Y-m-d'], | ||||
[['type', 'mean_payment'], 'string', 'max' => 255], | [['type', 'mean_payment'], 'string', 'max' => 255], | ||||
[['comment'], 'string', 'max' => 2048], | |||||
[['comment', 'summary'], 'string', 'max' => 2048], | |||||
]; | ]; | ||||
} | } | ||||
'id_producer' => 'Producteur', | 'id_producer' => 'Producteur', | ||||
'mean_payment' => 'Moyen de paiement', | 'mean_payment' => 'Moyen de paiement', | ||||
'comment' => 'Commentaire', | 'comment' => 'Commentaire', | ||||
'summary' => 'Résumé', | |||||
'date_transaction' => 'Date transaction' | 'date_transaction' => 'Date transaction' | ||||
]; | ]; | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getSummary(): ?string | |||||
{ | |||||
return $this->summary; | |||||
} | |||||
public function setSummary(?string $summary): self | |||||
{ | |||||
$this->summary = $summary; | |||||
return $this; | |||||
} | |||||
} | } |
User $user = null, | User $user = null, | ||||
User $userAction = null, | User $userAction = null, | ||||
string $meanPayment = null, | string $meanPayment = null, | ||||
string $comment = null, | |||||
Order $order = null, | Order $order = null, | ||||
Invoice $invoice = null | Invoice $invoice = null | ||||
): Payment | ): Payment | ||||
$payment->type = $type; | $payment->type = $type; | ||||
$payment->amount = round($amount, 2); | $payment->amount = round($amount, 2); | ||||
$payment->populateProducer($producer); | $payment->populateProducer($producer); | ||||
$payment->setMeanPayment($meanPayment); | |||||
$payment->setComment($comment); | |||||
if($user) { | if($user) { | ||||
$payment->populateUser($user); | $payment->populateUser($user); | ||||
$payment->populateInvoice($invoice); | $payment->populateInvoice($invoice); | ||||
} | } | ||||
if($meanPayment) { | |||||
$payment->mean_payment = $meanPayment; | |||||
} | |||||
return $payment; | return $payment; | ||||
} | } | ||||
User $user = null, | User $user = null, | ||||
User $userAction = null, | User $userAction = null, | ||||
string $meanPayment = null, | string $meanPayment = null, | ||||
string $comment = null, | |||||
Order $order = null, | Order $order = null, | ||||
Invoice $invoice = null | Invoice $invoice = null | ||||
): ?Payment | ): ?Payment | ||||
return null; | 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); | $this->create($payment); | ||||
return $payment; | return $payment; |
$this->producerSolver = $this->loadService(ProducerSolver::class); | $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( | $this->paymentBuilder->createPayment( | ||||
Payment::TYPE_CREDIT, | Payment::TYPE_CREDIT, | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$user, | $user, | ||||
$userAction, | $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( | $this->paymentBuilder->createPayment( | ||||
Payment::TYPE_DEBIT, | Payment::TYPE_DEBIT, | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$user, | $user, | ||||
$userAction, | $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) { | if($type == Payment::TYPE_CREDIT) { | ||||
$this->creditUser($user, $amount, $meanPayment, $userAction); | |||||
$this->creditUser($user, $amount, $meanPayment, $userAction, $comment); | |||||
} | } | ||||
elseif($type == Payment::TYPE_DEBIT) { | elseif($type == Payment::TYPE_DEBIT) { | ||||
$this->debitUser($user, $amount, $meanPayment, $userAction); | |||||
$this->debitUser($user, $amount, $meanPayment, $userAction, $comment); | |||||
} | } | ||||
else { | else { | ||||
throw new ErrorException('$type a une valeur incorrect'); | throw new ErrorException('$type a une valeur incorrect'); | ||||
$order->user, | $order->user, | ||||
$userAction, | $userAction, | ||||
$meanPayment, | $meanPayment, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } | ||||
$order->user, | $order->user, | ||||
$userAction, | $userAction, | ||||
MeanPayment::CREDIT, | MeanPayment::CREDIT, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } | ||||
$order->user, | $order->user, | ||||
$userAction, | $userAction, | ||||
$meanPayment, | $meanPayment, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } | ||||
$order->user, | $order->user, | ||||
$userAction, | $userAction, | ||||
MeanPayment::CREDIT, | MeanPayment::CREDIT, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } | ||||
$order->user, | $order->user, | ||||
$userAction, | $userAction, | ||||
MeanPayment::CREDIT, | MeanPayment::CREDIT, | ||||
null, | |||||
$order | $order | ||||
); | ); | ||||
} | } |
<?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'); | |||||
} | |||||
} |