namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\MeanPayment; | |||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use Yii; | use Yii; | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
if ($order->auto_payment && $configCredit) { | if ($order->auto_payment && $configCredit) { | ||||
if ($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { | if ($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { | ||||
$paymentManager->payOrder($order, $userManager->findOneUserById(User::ID_USER_SYSTEM), false); | |||||
$paymentManager->payOrder($order, MeanPayment::CREDIT, $userManager->findOneUserById(User::ID_USER_SYSTEM), false); | |||||
$countOrders++; | $countOrders++; | ||||
} | } | ||||
} | } |
'oneProductUnactivated' => $oneProductUnactivated, | 'oneProductUnactivated' => $oneProductUnactivated, | ||||
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | 'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | ||||
'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order), | 'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order), | ||||
'isCreditContext' => $orderManager->isCreditContext($order) | |||||
'isCreditContext' => $orderManager->isCreditContext($order), | |||||
'isPaid' => $orderManager->isOrderPaid($order), | |||||
]); | ]); | ||||
} | } | ||||
} | } |
use common\helpers\Ajax; | use common\helpers\Ajax; | ||||
use common\helpers\CSV; | use common\helpers\CSV; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\MeanPayment; | |||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\logic\Document\DeliveryNote\Model\DeliveryNote; | use common\logic\Document\DeliveryNote\Model\DeliveryNote; | ||||
use common\logic\Document\Document\Model\Document; | use common\logic\Document\Document\Model\Document; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\logic\Payment\Model\Payment; | |||||
class DocumentController extends BackendController | class DocumentController extends BackendController | ||||
{ | { | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$model = $this->findModel($id); | |||||
$documentManager = $this->getDocumentManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$document = $this->findModel($id); | |||||
if (!$model) { | |||||
if (!$document) { | |||||
throw new yii\web\NotFoundHttpException('Le document n\'a pas été trouvé.'); | throw new yii\web\NotFoundHttpException('Le document n\'a pas été trouvé.'); | ||||
} | } | ||||
if ($model && $model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
$this->setFlash('success', $this->getFlashMessage('update', $model)); | |||||
if ($document && $document->load(\Yii::$app->request->post()) && $document->save()) { | |||||
$this->setFlash('success', $this->getFlashMessage('update', $document)); | |||||
} | |||||
$payment = null; | |||||
if($documentManager->isDocumentInvoice($document) && $documentManager->isStatusValid($document)) { | |||||
$payment = $paymentManager->instanciatePayment( | |||||
Payment::TYPE_PAYMENT, | |||||
$documentManager->getAmountWithTax($document), | |||||
$this->getProducerCurrent(), | |||||
null, | |||||
null, | |||||
MeanPayment::TRANSFER, | |||||
null, | |||||
$document | |||||
); | |||||
if ($payment->load(\Yii::$app->request->post()) && $payment->save()) { | |||||
$this->setFlash('success', 'Le règlement a bien été ajouté.'); | |||||
return $this->redirect(['invoice/update', 'id' => $document->id]); | |||||
} | |||||
} | } | ||||
return $this->render('/document/update', [ | return $this->render('/document/update', [ | ||||
'title' => $this->getTitle('Modifier'), | 'title' => $this->getTitle('Modifier'), | ||||
'typeDocument' => $this->getDocumentType(), | 'typeDocument' => $this->getDocumentType(), | ||||
'model' => $model, | |||||
'model' => $document, | |||||
'payment' => $payment | |||||
]); | ]); | ||||
} | } | ||||
<template v-if="order.isCreditAutoPayment"> | <template v-if="order.isCreditAutoPayment"> | ||||
({{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}) | ({{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}) | ||||
<span class="glyphicon glyphicon-time" title="Paiement automatique la veille de la distribution" v-if="(order.amount_paid == 0 || order.amount_paid < order.amount)"></span> | |||||
<span class="glyphicon glyphicon-time" title="Paiement automatique la veille de la distribution" v-if="order.auto_payment && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span> | |||||
</template> | </template> | ||||
{{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par virement') }} | {{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par virement') }} | ||||
</a> | </a> | ||||
</li> | </li> | ||||
<li> | |||||
<!--<li> | |||||
<a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="credit-card"> | <a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="credit-card"> | ||||
{{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par carte bancaire') }} | {{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par carte bancaire') }} | ||||
</a> | </a> | ||||
</li> | |||||
</li>--> | |||||
<li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li> | <li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li> | ||||
</ul> | </ul> | ||||
<div class="row"> | <div class="row"> | ||||
<div class="col-md-6"> | <div class="col-md-6"> | ||||
<div class="info-box"> | <div class="info-box"> | ||||
<span :class="'info-box-icon ' +((order.amount_paid == order.amount) ? 'bg-green' : 'bg-red')"><i class="fa fa-check"></i></span> | |||||
<span :class="'info-box-icon ' +((order.isPaid) ? 'bg-green' : 'bg-red')"><i class="fa fa-check"></i></span> | |||||
<div class="info-box-content"> | <div class="info-box-content"> | ||||
<span class="info-box-text">Montant</span> | <span class="info-box-text">Montant</span> | ||||
<span class="info-box-number"> | <span class="info-box-number"> | ||||
</td> | </td> | ||||
<td class="column-delivery-note"> | <td class="column-delivery-note"> | ||||
<a v-if="order.id_delivery_note" class="btn btn-default btn-xs" :href="UrlManager.getBaseUrl()+'delivery-note/update?id='+order.id_delivery_note"> | <a v-if="order.id_delivery_note" class="btn btn-default btn-xs" :href="UrlManager.getBaseUrl()+'delivery-note/update?id='+order.id_delivery_note"> | ||||
<span class="glyphicon glyphicon-file"></span> BL #{{ order.id_delivery_note }} | |||||
<span class="glyphicon glyphicon-file"></span> BL | |||||
</a> | |||||
<a v-if="order.id_invoice" class="btn btn-default btn-xs" :href="UrlManager.getBaseUrl()+'invoice/update?id='+order.id_invoice"> | |||||
<span class="glyphicon glyphicon-file"></span> FA | |||||
</a> | </a> | ||||
</td> | </td> | ||||
</tr> | </tr> | ||||
</div> | </div> | ||||
<script type="text/x-template" id="order-state-payment"> | <script type="text/x-template" id="order-state-payment"> | ||||
<span class="label label-success" v-if="order.amount_paid == order.amount"> </span> | |||||
<span class="label label-default" v-else-if="order.amount_paid == 0"> </span> | |||||
<span class="label label-success" v-if="order.isPaid"> </span> | |||||
<span class="label label-default" v-else> </span> | |||||
<!--<span class="label label-success" v-if="order.amount_paid == order.amount"> </span> | |||||
<span class="label label-default" v-else-if="order.amount_paid == 0"> </span>--> | |||||
<!--<span class="label label-success input-group-addon" v-if="order.amount_paid == order.amount">débité</span> | <!--<span class="label label-success input-group-addon" v-if="order.amount_paid == order.amount">débité</span> | ||||
<span class="label label-default input-group-addon" v-else-if="order.amount_paid == 0">non débité</span> | <span class="label label-default input-group-addon" v-else-if="order.amount_paid == 0">non débité</span> | ||||
<span class="label label-default input-group-addon" v-else-if="order.amount_paid > order.amount">surplus</span> | <span class="label label-default input-group-addon" v-else-if="order.amount_paid > order.amount">surplus</span> |
* termes. | * termes. | ||||
*/ | */ | ||||
use common\logic\Document\Document\Wrapper\DocumentManager; | |||||
use common\logic\Producer\Producer\Wrapper\ProducerManager; | |||||
use common\helpers\MeanPayment;use common\helpers\Price;use common\logic\Document\Document\Wrapper\DocumentManager; | |||||
use common\logic\Document\Invoice\Wrapper\InvoiceManager;use common\logic\Payment\Wrapper\PaymentManager;use common\logic\Producer\Producer\Wrapper\ProducerManager; | |||||
use common\logic\User\User\Wrapper\UserManager; | use common\logic\User\User\Wrapper\UserManager; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
$producerManager = ProducerManager::getInstance(); | $producerManager = ProducerManager::getInstance(); | ||||
$documentManager = DocumentManager::getInstance(); | $documentManager = DocumentManager::getInstance(); | ||||
$invoiceManager = InvoiceManager::getInstance(); | |||||
$userManager = UserManager::getInstance(); | $userManager = UserManager::getInstance(); | ||||
$paymentManager = PaymentManager::getInstance(); | |||||
$documentClass = $documentManager->getClass($model); | $documentClass = $documentManager->getClass($model); | ||||
<div id="" class="info-box"> | <div id="" class="info-box"> | ||||
<span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span> | <span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span> | ||||
<div class="info-box-content"> | <div class="info-box-content"> | ||||
<span class="info-box-text">Total<span v-if="taxRateProducer != 0"> (TTC)</span></span> | |||||
<span class="info-box-text"> | |||||
Total<span v-if="taxRateProducer != 0"> (TTC)</span> | |||||
<?php if($invoiceManager->isInvoicePaid($model)): ?> | |||||
<span class="label label-success">PAYÉE</span> | |||||
<?php endif; ?> | |||||
</span> | |||||
<span class="info-box-number">{{ formatPrice(total_with_tax) }}</span> | <span class="info-box-number">{{ formatPrice(total_with_tax) }}</span> | ||||
<p v-if="invoiceUrl"> | <p v-if="invoiceUrl"> | ||||
<a class="btn btn-sm btn-default" :href="invoiceUrl"> | <a class="btn btn-sm btn-default" :href="invoiceUrl"> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
<?php if ($action == 'update' && $documentClass == 'Invoice'): ?> | <?php if ($action == 'update' && $documentClass == 'Invoice'): ?> | ||||
<div v-if="document.status == 'valid'"> | |||||
<div class="panel panel-default"> | |||||
<div class="panel-heading"> | |||||
Règlement | |||||
</div> | |||||
<div class="panel-body"> | |||||
<?php if($model->payments && count($model->payments) > 0): ?> | |||||
<table class="table table-bordered"> | |||||
<thead> | |||||
<tr> | |||||
<th>Moyen de paiement</th> | |||||
<th>Montant</th> | |||||
</tr> | |||||
</thead> | |||||
<tbody> | |||||
<?php foreach($model->payments as $payment): ?> | |||||
<tr> | |||||
<td><?= $paymentManager->getStrMeanPayment($payment); ?></td> | |||||
<td><?= Price::format($payment->amount); ?></td> | |||||
</tr> | |||||
<?php endforeach; ?> | |||||
</tbody> | |||||
</table> | |||||
<?php endif; ?> | |||||
<?php if(!$invoiceManager->isInvoicePaid($model)): ?> | |||||
<div class="row"> | |||||
<?php $form = ActiveForm::begin(); ?> | |||||
<div class="col-md-4"> | |||||
<?= $form->field($payment, 'mean_payment')->dropDownList(MeanPayment::getAll()); ?> | |||||
</div> | |||||
<div class="col-md-4"> | |||||
<?= $form->field($payment, 'amount')->textInput(); ?> | |||||
</div> | |||||
<div class="col-md-4"> | |||||
<div class="form-group"> | |||||
<br> | |||||
<?= Html::submitButton('Ajouter', ['class' => 'btn btn-primary']) ?> | |||||
</div> | |||||
</div> | |||||
<?php ActiveForm::end(); ?> | |||||
</div> | |||||
<?php endif; ?> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
<div v-if="(deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0) || (deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0)"> | <div v-if="(deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0) || (deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0)"> | ||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> |
'action' => 'update', | 'action' => 'update', | ||||
'model' => $model, | 'model' => $model, | ||||
'typeDocument' => $typeDocument, | 'typeDocument' => $typeDocument, | ||||
'payment' => $payment | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
[ | [ | ||||
'attribute' => 'amount', | 'attribute' => 'amount', | ||||
'header' => 'Montant', | 'header' => 'Montant', | ||||
'format' => 'raw', | |||||
'value' => function ($invoice) use ($invoiceManager) { | 'value' => function ($invoice) use ($invoiceManager) { | ||||
return $invoiceManager->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL, true); | |||||
$amountWithTax = $invoiceManager->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL); | |||||
$html = $invoiceManager->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL, true); | |||||
if($amountWithTax && $invoiceManager->isInvoicePaid($invoice)) { | |||||
$html .= ' <span class="label label-success">Payée</span>'; | |||||
} | |||||
return $html; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
return null; | return null; | ||||
} | } | ||||
public function isDocumentDeliveryNote(DocumentInterface $document): bool | |||||
{ | |||||
return $this->getClass($document) == 'DeliveryNote'; | |||||
} | |||||
public function isDocumentInvoice(DocumentInterface $document): bool | |||||
{ | |||||
return $this->getClass($document) == 'Invoice'; | |||||
} | |||||
public function isDocumentQuotation(DocumentInterface $document): bool | |||||
{ | |||||
return $this->getClass($document) == 'Quotation'; | |||||
} | |||||
public function getClass(DocumentInterface $document, bool $pathComplete = false): string | public function getClass(DocumentInterface $document, bool $pathComplete = false): string | ||||
{ | { | ||||
$classDocument = get_class($document); | $classDocument = get_class($document); |
namespace common\logic\Document\Invoice\Model; | namespace common\logic\Document\Invoice\Model; | ||||
use common\logic\Document\Document\Model\Document; | use common\logic\Document\Document\Model\Document; | ||||
use common\logic\Payment\Model\Payment; | |||||
/** | /** | ||||
* This is the model class for table "invoice". | * This is the model class for table "invoice". | ||||
{ | { | ||||
return $this->relationOrders('id_invoice'); | return $this->relationOrders('id_invoice'); | ||||
} | } | ||||
public function getPayments() | |||||
{ | |||||
return $this->hasMany(Payment::class, ['id_invoice' => 'id']) | |||||
->orderBy(['payment.id' => SORT_DESC]); | |||||
} | |||||
} | } |
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
{ | { | ||||
return [ | return [ | ||||
self::WITH => [], | |||||
self::WITH => ['payments'], | |||||
self::JOIN_WITH => ['user AS user_invoice', 'producer'], | self::JOIN_WITH => ['user AS user_invoice', 'producer'], | ||||
self::ORDER_BY => 'date ASC', | self::ORDER_BY => 'date ASC', | ||||
self::ATTRIBUTE_ID_PRODUCER => 'invoice.id_producer' | self::ATTRIBUTE_ID_PRODUCER => 'invoice.id_producer' |
<?php | |||||
namespace common\logic\Document\Invoice\Service; | |||||
use common\helpers\Price; | |||||
use common\logic\Document\Document\Service\DocumentSolver; | |||||
use common\logic\Document\Invoice\Model\Invoice; | |||||
class InvoiceSolver extends DocumentSolver | |||||
{ | |||||
public function getInvoiceAmountPaid(Invoice $invoice): float | |||||
{ | |||||
$amountPaid = 0; | |||||
foreach($invoice->payments as $payment) { | |||||
$amountPaid += $payment->amount; | |||||
} | |||||
return $amountPaid; | |||||
} | |||||
public function isInvoicePaid(Invoice $invoice): bool | |||||
{ | |||||
return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice)); | |||||
} | |||||
} |
namespace common\logic\Document\Invoice\Wrapper; | namespace common\logic\Document\Invoice\Wrapper; | ||||
use common\logic\AbstractContainer; | use common\logic\AbstractContainer; | ||||
use common\logic\Document\Document\Service\DocumentSolver; | |||||
use common\logic\Document\Invoice\Repository\InvoiceRepository; | use common\logic\Document\Invoice\Repository\InvoiceRepository; | ||||
use common\logic\Document\Invoice\Service\InvoiceBuilder; | use common\logic\Document\Invoice\Service\InvoiceBuilder; | ||||
use common\logic\Document\Invoice\Service\InvoiceDefinition; | use common\logic\Document\Invoice\Service\InvoiceDefinition; | ||||
use common\logic\Document\Invoice\Service\InvoiceSolver; | |||||
class InvoiceContainer extends AbstractContainer | class InvoiceContainer extends AbstractContainer | ||||
{ | { | ||||
{ | { | ||||
return [ | return [ | ||||
InvoiceDefinition::class, | InvoiceDefinition::class, | ||||
DocumentSolver::class, | |||||
InvoiceSolver::class, | |||||
InvoiceRepository::class, | InvoiceRepository::class, | ||||
InvoiceBuilder::class, | InvoiceBuilder::class, | ||||
]; | ]; | ||||
return InvoiceDefinition::getInstance(); | return InvoiceDefinition::getInstance(); | ||||
} | } | ||||
public function getSolver(): DocumentSolver | |||||
public function getSolver(): InvoiceSolver | |||||
{ | { | ||||
return DocumentSolver::getInstance(); | |||||
return InvoiceSolver::getInstance(); | |||||
} | } | ||||
public function getRepository(): InvoiceRepository | public function getRepository(): InvoiceRepository |
use common\logic\Document\Invoice\Repository\InvoiceRepository; | use common\logic\Document\Invoice\Repository\InvoiceRepository; | ||||
use common\logic\Document\Invoice\Service\InvoiceBuilder; | use common\logic\Document\Invoice\Service\InvoiceBuilder; | ||||
use common\logic\Document\Invoice\Service\InvoiceDefinition; | use common\logic\Document\Invoice\Service\InvoiceDefinition; | ||||
use common\logic\Document\Invoice\Service\InvoiceSolver; | |||||
/** | /** | ||||
* @mixin InvoiceDefinition | * @mixin InvoiceDefinition | ||||
* @mixin InvoiceSolver | |||||
* @mixin InvoiceRepository | * @mixin InvoiceRepository | ||||
* @mixin InvoiceBuilder | * @mixin InvoiceBuilder | ||||
*/ | */ |
use common\logic\Distribution\Distribution\Repository\DistributionRepository; | use common\logic\Distribution\Distribution\Repository\DistributionRepository; | ||||
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; | use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; | ||||
use common\logic\Document\Invoice\Model\Invoice; | use common\logic\Document\Invoice\Model\Invoice; | ||||
use common\logic\Document\Invoice\Repository\InvoiceRepository; | |||||
use common\logic\Document\Invoice\Service\InvoiceSolver; | |||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Order\Order\Service\OrderSolver; | use common\logic\Order\Order\Service\OrderSolver; | ||||
use common\logic\Order\ProductOrder\Repository\ProductOrderRepository; | use common\logic\Order\ProductOrder\Repository\ProductOrderRepository; | ||||
protected DistributionRepository $distributionRepository; | protected DistributionRepository $distributionRepository; | ||||
protected PointSaleRepository $pointSaleRepository; | protected PointSaleRepository $pointSaleRepository; | ||||
protected UserPointSaleRepository $userPointSaleRepository; | protected UserPointSaleRepository $userPointSaleRepository; | ||||
protected InvoiceRepository $invoiceRepository; | |||||
protected InvoiceSolver $invoiceSolver; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | $this->distributionRepository = $this->loadService(DistributionRepository::class); | ||||
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class); | $this->pointSaleRepository = $this->loadService(PointSaleRepository::class); | ||||
$this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class); | $this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class); | ||||
$this->invoiceRepository = $this->loadService(InvoiceRepository::class); | |||||
$this->invoiceSolver = $this->loadService(InvoiceSolver::class); | |||||
} | } | ||||
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
return intval($total / 3); | return intval($total / 3); | ||||
} | } | ||||
public function isOrderPaid(Order $order): bool | |||||
{ | |||||
if($this->orderSolver->getOrderAmount($order, Order::AMOUNT_PAID) | |||||
>= $this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL)) { | |||||
return true; | |||||
} | |||||
if($order->invoice) { | |||||
$invoice = $this->invoiceRepository->findOneInvoiceById($order->id_invoice); | |||||
if($invoice && $this->invoiceSolver->isInvoicePaid($invoice)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
namespace common\logic\Payment\Service; | namespace common\logic\Payment\Service; | ||||
use common\logic\AbstractBuilder; | use common\logic\AbstractBuilder; | ||||
use common\logic\Document\Invoice\Model\Invoice; | |||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Order\Order\Service\OrderSolver; | use common\logic\Order\Order\Service\OrderSolver; | ||||
use common\logic\Payment\Model\Payment; | use common\logic\Payment\Model\Payment; | ||||
User $user = null, | User $user = null, | ||||
User $userAction = null, | User $userAction = null, | ||||
string $meanPayment = null, | string $meanPayment = null, | ||||
Order $order = null | |||||
Order $order = null, | |||||
Invoice $invoice = null | |||||
): Payment | ): Payment | ||||
{ | { | ||||
$payment = new Payment; | $payment = new Payment; | ||||
$payment->populateOrder($order); | $payment->populateOrder($order); | ||||
} | } | ||||
if($invoice) { | |||||
$payment->populateInvoice($invoice); | |||||
} | |||||
if($meanPayment) { | if($meanPayment) { | ||||
$payment->mean_payment = $meanPayment; | $payment->mean_payment = $meanPayment; | ||||
} | } | ||||
User $user = null, | User $user = null, | ||||
User $userAction = null, | User $userAction = null, | ||||
string $meanPayment = null, | string $meanPayment = null, | ||||
Order $order = null | |||||
Order $order = null, | |||||
Invoice $invoice = null | |||||
): ?Payment | ): ?Payment | ||||
{ | { | ||||
if ($amount > -0.01 && $amount < 0.01) { | if ($amount > -0.01 && $amount < 0.01) { | ||||
return null; | return null; | ||||
} | } | ||||
$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order); | |||||
$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order, $invoice); | |||||
$payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment)); | $payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment)); | ||||
$this->create($payment); | $this->create($payment); | ||||