Browse Source

[Administration] Utilisateurs > historique crédit : ajout date de transaction

feature/souke
Guillaume Bourgeois 10 months ago
parent
commit
9e4c39f1e4
8 changed files with 54 additions and 48 deletions
  1. +7
    -1
      backend/controllers/UserController.php
  2. +3
    -37
      backend/models/CreditForm.php
  3. +17
    -1
      backend/views/user/credit.php
  4. +1
    -0
      common/logic/Order/Order/Service/OrderBuilder.php
  5. +7
    -0
      common/logic/Payment/Model/Payment.php
  6. +4
    -1
      common/logic/Payment/Service/PaymentBuilder.php
  7. +14
    -7
      common/logic/Payment/Service/PaymentManager.php
  8. +1
    -1
      common/logic/Payment/Service/PaymentSolver.php

+ 7
- 1
backend/controllers/UserController.php View File

@@ -386,6 +386,11 @@ class UserController extends BackendController

if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) {

$dateTransaction = null;
if($creditForm->date_transaction) {
$dateTransaction = date('Y-m-d', strtotime(str_replace('/', '-', $creditForm->date_transaction)));
}

$paymentModule->getManager()
->creditOrDebitUser(
$creditForm->type,
@@ -393,7 +398,8 @@ class UserController extends BackendController
$creditForm->amount,
$creditForm->mean_payment,
$this->getUserCurrent(),
$creditForm->comment
$creditForm->comment,
$dateTransaction
);

if ($creditForm->send_mail) {

+ 3
- 37
backend/models/CreditForm.php View File

@@ -50,7 +50,6 @@ use yii\base\Model;
*/
class CreditForm extends Model
{

public $id_user ;
public $id_user_action ;
public $id_producer ;
@@ -59,6 +58,7 @@ class CreditForm extends Model
public $mean_payment ;
public $comment ;
public $send_mail = 1;
public $date_transaction;

/**
* @inheritdoc
@@ -68,7 +68,7 @@ class CreditForm extends Model
return [
[['amount'], 'required'],
[['id_user', 'id_user_action', 'id_producer'], 'integer'],
[['date','send_mail'], 'safe'],
[['date', 'send_mail', 'date_transaction'], 'safe'],
[['amount'], 'double'],
[['type', 'mean_payment'], 'string', 'max' => 255],
[['comment'], 'string', 'max' => 2048],
@@ -90,41 +90,7 @@ class CreditForm extends Model
'mean_payment' => 'Moyen de paiement',
'comment' => 'Commentaire',
'send_mail' => 'Prévenir l\'utilisateur',
'date_transaction' => 'Date de transaction'
];
}
/**
* Enregistre un modèle CreditHistorique.
*/
public function save()
{
$userModule = UserModule::getInstance();
$userProducerModule = UserProducerModule::getInstance();
$paymentManager = PaymentModule::getInstance();

if ($this->validate()) {
$user = $userModule->findOneUserById($this->id_user);
$paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userModule->getCurrent(), $this->comment);
// on prévient l'utilisateur que son compte vient d'être crédité
if($this->send_mail) {
$producer = GlobalParam::getCurrentProducer() ;
$userProducer = $userProducerModule->findOneUserProducer($user);

\Yii::$app->mailerService->sendFromProducer(
'Mouvement de crédit',
'creditUser',
[
'user' => $user,
'producer' => $producer,
'userProducer' => $userProducer,
'creditForm' => $this
],
$user->email,
$producer
);
}
}
}

}

+ 17
- 1
backend/views/user/credit.php View File

@@ -102,6 +102,9 @@ $this->addBreadcrumb('Créditer') ;
MeanPayment::OTHER => MeanPayment::getStrBy(MeanPayment::OTHER),
]) ?>
<?= $form->field($creditForm, 'comment')->textarea() ?>
<?= $form->field($creditForm, 'date_transaction')->textInput([
'class' => 'datepicker form-control'
]) ?>
<?= $form->field($creditForm, 'send_mail')->checkbox() ?>

<div class="form-group">
@@ -167,7 +170,20 @@ $this->addBreadcrumb('Créditer') ;
'label' => 'Commentaire',
'format' => 'raw',
'value' => function ($model) {
return nl2br($model->comment);
if($model->comment) {
return nl2br($model->comment);
}
return '';
}
],
[
'label' => 'Transaction',
'format' => 'raw',
'value' => function ($model) {
if($model->date_transaction) {
return date('d/m/Y', strtotime($model->date_transaction));
}
return '';
}
],
],

+ 1
- 0
common/logic/Order/Order/Service/OrderBuilder.php View File

@@ -367,6 +367,7 @@ class OrderBuilder extends AbstractBuilder
$this->userSolver->getCurrent(),
MeanPayment::CREDIT,
null,
null,
$order
);
}

+ 7
- 0
common/logic/Payment/Model/Payment.php View File

@@ -290,6 +290,13 @@ class Payment extends ActiveRecordCommon
return $this;
}

public function setDateTransaction(?string $dateTransaction): self
{
$this->date_transaction = $dateTransaction;

return $this;
}

public function getSummary(): ?string
{
return $this->summary;

+ 4
- 1
common/logic/Payment/Service/PaymentBuilder.php View File

@@ -29,6 +29,7 @@ class PaymentBuilder extends AbstractBuilder
User $userAction = null,
string $meanPayment = null,
string $comment = null,
string $dateTransaction = null,
Order $order = null,
Invoice $invoice = null
): Payment
@@ -40,6 +41,7 @@ class PaymentBuilder extends AbstractBuilder
$payment->populateProducer($producer);
$payment->setMeanPayment($meanPayment);
$payment->setComment($comment);
$payment->setDateTransaction($dateTransaction);

if($user) {
$payment->populateUser($user);
@@ -68,6 +70,7 @@ class PaymentBuilder extends AbstractBuilder
User $userAction = null,
string $meanPayment = null,
string $comment = null,
string $dateTransaction = null,
Order $order = null,
Invoice $invoice = null
): ?Payment
@@ -76,7 +79,7 @@ class PaymentBuilder extends AbstractBuilder
return null;
}

$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $comment, $order, $invoice);
$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $comment, $dateTransaction, $order, $invoice);
$payment->setSummary($this->orderSolver->getPaymentComment($payment));
$this->create($payment);


+ 14
- 7
common/logic/Payment/Service/PaymentManager.php View File

@@ -28,7 +28,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$this->producerSolver = $this->loadService(ProducerSolver::class);
}

public function creditUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment = null): void
public function creditUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment = null, string $dateTransaction = null): void
{
$this->paymentBuilder->createPayment(
Payment::TYPE_CREDIT,
@@ -37,11 +37,12 @@ class PaymentManager extends AbstractService implements ManagerInterface
$user,
$userAction,
$meanPayment,
$comment
$comment,
$dateTransaction
);
}

public function debitUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment = null): void
public function debitUser(User $user, float $amount, string $meanPayment, User $userAction, string $comment = null, string $dateTransaction = null): void
{
$this->paymentBuilder->createPayment(
Payment::TYPE_DEBIT,
@@ -50,17 +51,18 @@ class PaymentManager extends AbstractService implements ManagerInterface
$user,
$userAction,
$meanPayment,
$comment
$comment,
$dateTransaction
);
}

public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction, string $comment): void
public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction, string $comment, string $dateTransaction = null): void
{
if($type == Payment::TYPE_CREDIT) {
$this->creditUser($user, $amount, $meanPayment, $userAction, $comment);
$this->creditUser($user, $amount, $meanPayment, $userAction, $comment, $dateTransaction);
}
elseif($type == Payment::TYPE_DEBIT) {
$this->debitUser($user, $amount, $meanPayment, $userAction, $comment);
$this->debitUser($user, $amount, $meanPayment, $userAction, $comment, $dateTransaction);
}
else {
throw new ErrorException('$type a une valeur incorrect');
@@ -81,6 +83,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$userAction,
$meanPayment,
null,
null,
$order
);
}
@@ -111,6 +114,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$userAction,
MeanPayment::CREDIT,
null,
null,
$order
);
}
@@ -135,6 +139,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$userAction,
$meanPayment,
null,
null,
$order
);
}
@@ -152,6 +157,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$userAction,
MeanPayment::CREDIT,
null,
null,
$order
);
}
@@ -171,6 +177,7 @@ class PaymentManager extends AbstractService implements ManagerInterface
$userAction,
MeanPayment::CREDIT,
null,
null,
$order
);
}

+ 1
- 1
common/logic/Payment/Service/PaymentSolver.php View File

@@ -78,7 +78,7 @@ class PaymentSolver extends AbstractService implements SolverInterface
}

if ($order && $order->distribution) {
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
$str .= '<br />Commande du <a href="'.\Yii::$app->urlManager->createUrl(['distribution/index', 'date' => $order->distribution->date]).'">' . date('d/m/Y', strtotime($order->distribution->date)).'</a>';
} else {
$str .= '<br />Commande supprimée';
}

Loading…
Cancel
Save