@@ -315,31 +315,25 @@ class DistributionController extends BackendController | |||
} | |||
} | |||
$creditHistoryArray = []; | |||
$paymentArray = []; | |||
foreach ($order->payment as $payment) { | |||
$creditHistoryArray[] = [ | |||
$paymentArray[] = [ | |||
'type' => $payment->type, | |||
'wording_type' => $paymentManager->getStrType($payment), | |||
'mean_payment' => $payment->mean_payment, | |||
'wording_mean_payment' => $paymentManager->getStrMeanPayment($payment), | |||
'date' => date('d/m/Y H:i:s', strtotime($payment->date)), | |||
'user' => $userManager->getUsername($payment->getUserObject()), | |||
'user' => $payment->getUserObject() ? $userManager->getUsername($payment->getUserObject()) : '', | |||
'user_action' => $paymentManager->getStrUserAction($payment), | |||
'wording' => $paymentManager->getStrWording($payment), | |||
'debit' => ($paymentManager->isTypeDebit($payment) ? '- ' . $paymentManager->getAmount( | |||
$payment, | |||
Order::AMOUNT_TOTAL, | |||
true | |||
) : ''), | |||
'credit' => ($paymentManager->isTypeCredit($payment) ? '+ ' . $paymentManager->getAmount( | |||
$payment, | |||
Order::AMOUNT_TOTAL, | |||
true | |||
) : '') | |||
'amount' => $paymentManager->getAmount($payment, Order::AMOUNT_TOTAL, true), | |||
]; | |||
} | |||
$arrayCreditUser = []; | |||
if (isset($order->user) && isset($order->user->userProducer) && isset($order->user->userProducer[0])) { | |||
$arrayCreditUser['credit'] = $order->user->userProducer[0]->credit; | |||
if(isset($order->user)) { | |||
$arrayCreditUser['credit'] = $userManager->getCredit($order->user); | |||
} | |||
$oneProductUnactivated = false; | |||
@@ -364,10 +358,11 @@ class DistributionController extends BackendController | |||
) : null, | |||
'pointSale' => $order->pointSale ? ['id' => $order->pointSale->id, 'name' => $order->pointSale->name] : null, | |||
'productOrder' => $productOrderArray, | |||
'paymentArray' => $creditHistoryArray, | |||
'paymentsArray' => $paymentArray, | |||
'oneProductUnactivated' => $oneProductUnactivated, | |||
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | |||
'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order) | |||
'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order), | |||
'isCreditContext' => $orderManager->isCreditContext($order) | |||
]); | |||
} | |||
} |
@@ -41,6 +41,7 @@ namespace backend\controllers; | |||
use backend\models\CreditForm; | |||
use common\helpers\GlobalParam; | |||
use backend\models\MailForm; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Password; | |||
use common\logic\Order\Order\Model\OrderSearch; | |||
use common\logic\PointSale\PointSale\Model\PointSale; | |||
@@ -407,6 +408,7 @@ class UserController extends BackendController | |||
->where([ | |||
'id_user' => $user->id, | |||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||
'mean_payment' => MeanPayment::CREDIT | |||
]) | |||
->orderBy('date DESC') | |||
->all(); |
@@ -391,10 +391,31 @@ $this->setPageTitle('Distributions') ; | |||
Paiement <span class="caret"></span> | |||
</button> | |||
<ul class="dropdown-menu"> | |||
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="money">Payer en espèce</a></li> | |||
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="cheque">Payer par chèque</a></li> | |||
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="transfer">Payer par virement</a></li> | |||
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="credit-card">Payer par carte bancaire</a></li> | |||
<li v-if="order.isCreditContext"> | |||
<a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="credit"> | |||
{{ getLabelPaymentRefund(order, 'Débiter', 'Recréditer', 'le crédit') }} | |||
</a> | |||
</li> | |||
<li> | |||
<a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="money"> | |||
{{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'en espèce') }} | |||
</a> | |||
</li> | |||
<li> | |||
<a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="cheque"> | |||
{{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par chèque') }} | |||
</a> | |||
</li> | |||
<li> | |||
<a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" :data-type="getTypePayment(order)" data-mean-payment="transfer"> | |||
{{ getLabelPaymentRefund(order, 'Payer', 'Rembourser', 'par virement') }} | |||
</a> | |||
</li> | |||
<li> | |||
<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') }} | |||
</a> | |||
</li> | |||
<li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li> | |||
</ul> | |||
@@ -467,91 +488,62 @@ $this->setPageTitle('Distributions') ; | |||
<span v-else>{{ order.username }}</span></strong> | |||
</h3> | |||
<div slot="body"> | |||
<div class="col-md-4"> | |||
<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> | |||
<div class="info-box-content"> | |||
<span class="info-box-text">Montant</span> | |||
<span class="info-box-number">{{ order.amount.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}</span> | |||
<span class="info-box-text"> | |||
Statut<br /> | |||
<span class="label label-success" v-if="order.amount_paid == order.amount">débité</span> | |||
<span class="label label-default" v-else-if="order.amount_paid == 0">non débité</span> | |||
<span class="label label-default" v-else-if="order.amount_paid > order.amount">surplus</span> | |||
<span class="label label-warning" v-else-if="order.amount_paid < order.amount">reste à débiter</span> | |||
<div class="row"> | |||
<div class="col-md-6"> | |||
<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> | |||
<div class="info-box-content"> | |||
<span class="info-box-text">Montant</span> | |||
<span class="info-box-number"> | |||
{{ order.amount.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</span> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="info-box"> | |||
<span :class="'info-box-icon ' +((order.user.credit > 0) ? 'bg-green' : 'bg-red')"><i class="fa fa-user"></i></span> | |||
<div class="info-box-content"> | |||
<span class="info-box-text">Crédit utilisateur</span> | |||
<span class="info-box-number">{{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}</span> | |||
<div class="col-md-6" v-if="order.isCreditContext"> | |||
<div class="info-box"> | |||
<span :class="'info-box-icon ' +((order.user.credit > 0) ? 'bg-green' : 'bg-red')"><i class="fa fa-user"></i></span> | |||
<div class="info-box-content"> | |||
<span class="info-box-text">Crédit utilisateur</span> | |||
<span class="info-box-number"> | |||
{{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</span> | |||
</div> | |||
</div> | |||
</div> | |||
<button v-if="order.amount_paid == order.amount" | |||
class="btn btn-default" | |||
:data-amount="order.amount" | |||
data-type="refund" | |||
@click="orderPaymentClick" > | |||
<span class="glyphicon glyphicon-chevron-right"></span> | |||
Recréditer {{ order.amount.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</button> | |||
<button v-else-if="order.amount_paid == 0" | |||
class="btn btn-default" | |||
:data-amount="order.amount" | |||
data-type="payment" | |||
@click="orderPaymentClick"> | |||
<span class="glyphicon glyphicon-chevron-right"></span> | |||
Débiter {{ order.amount.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</button> | |||
<button v-else-if="order.amount_paid > order.amount" | |||
class="btn btn-default" | |||
:data-amount="order.amount_surplus" | |||
data-type="refund" | |||
@click="orderPaymentClick"> | |||
<span class="glyphicon glyphicon-chevron-right"></span> | |||
Recréditer {{ order.amount_surplus.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</button> | |||
<button v-else-if="order.amount_paid < order.amount" | |||
class="btn btn-default" | |||
:data-amount="order.amount_remaining" | |||
data-type="payment" | |||
@click="orderPaymentClick"> | |||
<span class="glyphicon glyphicon-chevron-right"></span> | |||
Débiter le restant {{ order.amount_remaining.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }} | |||
</button> | |||
</div> | |||
<div class="col-md-8"> | |||
<h4>Historique paiement</h4> | |||
<table class="table table-condensed table-bordered table-hover"> | |||
<thead> | |||
<tr> | |||
<td>Date</td> | |||
<td>Utilisateur</td> | |||
<td>Action</td> | |||
<td>Origine action</td> | |||
<td>- Débit</td> | |||
<td>+ Crédit</td> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<tr v-for="creditHistory in order.creditHistory"> | |||
<td>{{ creditHistory.date }}</td> | |||
<td>{{ creditHistory.user }}</td> | |||
<td v-html="creditHistory.wording"></td> | |||
<td>{{ creditHistory.user_action }}</td> | |||
<td v-html="creditHistory.debit"></td> | |||
<td v-html="creditHistory.credit"></td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
<div class="row"> | |||
<div class="col-md-12"> | |||
<h4>Historique</h4> | |||
<table class="table table-condensed table-bordered table-hover" v-if="order.paymentsArray && order.paymentsArray.length > 0"> | |||
<thead> | |||
<tr> | |||
<!--<td>Utilisateur</td> | |||
<td>Action</td> | |||
<td>Origine action</td>--> | |||
<td>Date</td> | |||
<td>Type</td> | |||
<td>Moyen</td> | |||
<td>Montant</td> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<tr v-for="payment in order.paymentsArray"> | |||
<!--<td>{{ payment.user }}</td> | |||
<td v-html="payment.wording"></td> | |||
<td>{{ payment.user_action }}</td>--> | |||
<td>{{ payment.date }}</td> | |||
<td>{{ payment.wording_type }}</td> | |||
<td>{{ payment.wording_mean_payment }}</td> | |||
<td v-html="payment.amount"></td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
<div class="alert alert-info" v-else> | |||
Aucun paiement enregistré sur cette commande. | |||
</div> | |||
</div> | |||
</div> | |||
</div> |
@@ -423,6 +423,7 @@ var app = new Vue({ | |||
} else { | |||
this.orderCreate.id_point_sale = id; | |||
} | |||
setTimeout("opendistrib_popover(); opendistrib_dropdown_tooltip();", 500); | |||
}, | |||
orderCreatedUpdated: function () { | |||
this.showModalFormOrderCreate = false; | |||
@@ -499,6 +500,31 @@ var app = new Vue({ | |||
this.idOrderPayment = idOrder; | |||
this.showModalPayment = true; | |||
}, | |||
getTypePayment: function(order) { | |||
if(order.amount_paid < order.amount) { | |||
return 'payment'; | |||
} | |||
else { | |||
return 'refund'; | |||
} | |||
}, | |||
isTypePayment: function(order) { | |||
return this.getTypePayment(order) == 'payment'; | |||
}, | |||
getLabelPaymentRefund: function(order, labelPay, labelRefund, labelMeanPayment) { | |||
var str = ''; | |||
if(this.isTypePayment(order)) { | |||
str += labelPay; | |||
} | |||
else { | |||
str += labelRefund; | |||
} | |||
str += ' '+labelMeanPayment; | |||
return str; | |||
}, | |||
orderPaymentClick: function (event) { | |||
var app = this; | |||
var idOrder = event.currentTarget.getAttribute('data-id-order'); |
@@ -56,7 +56,7 @@ class MeanPayment { | |||
public static function getStrBy($meanPayment) | |||
{ | |||
switch($meanPayment) { | |||
case self::CREDIT_CARD : return 'Paiement en ligne' ; | |||
case self::CREDIT_CARD : return 'Carte bancaire' ; | |||
case self::MONEY : return 'Espèces' ; | |||
case self::CHEQUE : return 'Chèque' ; | |||
case self::TRANSFER : return 'Virement' ; |
@@ -185,7 +185,8 @@ class Order extends ActiveRecordCommon | |||
public function getPayment() | |||
{ | |||
return $this->hasMany(Payment::class, ['id_order' => 'id']); | |||
return $this->hasMany(Payment::class, ['id_order' => 'id']) | |||
->orderBy(['payment.id' => SORT_DESC]); | |||
} | |||
public function getSubscription() |
@@ -315,17 +315,16 @@ class OrderRepository extends AbstractRepository | |||
public function isCreditAutoPayment(Order $order) | |||
{ | |||
$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||
$distribution = $this->distributionRepository->findOneDistributionById($order->id_distribution); | |||
if($pointSale) { | |||
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); | |||
if ($order->id_user && $this->producerRepository->getConfig('credit') && $pointSale->credit) { | |||
if($order->mean_payment == MeanPayment::CREDIT || $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { | |||
return 1; | |||
return true; | |||
} | |||
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | |||
return 0; | |||
return false; | |||
} | |||
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user); | |||
@@ -336,7 +335,32 @@ class OrderRepository extends AbstractRepository | |||
} | |||
} | |||
return 0; | |||
return false; | |||
} | |||
public function isCreditContext(Order $order) | |||
{ | |||
$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||
if($pointSale) { | |||
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); | |||
if ($order->id_user && $this->producerRepository->getConfig('credit') && $pointSale->credit) { | |||
if($order->mean_payment == MeanPayment::CREDIT | |||
|| $creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY | |||
|| $creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | |||
return true; | |||
} | |||
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user); | |||
if ($userProducer) { | |||
return $userProducer->credit_active; | |||
} | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
public function findOneOrderLastByUser(User $user) |
@@ -24,8 +24,8 @@ class PaymentBuilder extends AbstractBuilder | |||
string $type, | |||
float $amount, | |||
Producer $producer, | |||
User $user, | |||
User $userAction, | |||
User $user = null, | |||
User $userAction = null, | |||
string $meanPayment = null, | |||
Order $order = null | |||
): Payment | |||
@@ -35,8 +35,14 @@ class PaymentBuilder extends AbstractBuilder | |||
$payment->type = $type; | |||
$payment->amount = round($amount, 2); | |||
$payment->populateProducer($producer); | |||
$payment->populateUser($user); | |||
$payment->populateUserAction($userAction); | |||
if($user) { | |||
$payment->populateUser($user); | |||
} | |||
if($userAction) { | |||
$payment->populateUserAction($userAction); | |||
} | |||
if($order) { | |||
$payment->populateOrder($order); | |||
@@ -53,8 +59,8 @@ class PaymentBuilder extends AbstractBuilder | |||
string $type, | |||
float $amount, | |||
Producer $producer, | |||
User $user, | |||
User $userAction, | |||
User $user = null, | |||
User $userAction = null, | |||
string $meanPayment = null, | |||
Order $order = null | |||
): ?Payment |
@@ -80,11 +80,34 @@ class PaymentSolver extends AbstractService implements SolverInterface | |||
} | |||
} | |||
public function isMeanPaymentCredit(Payment $payment): bool | |||
{ | |||
return $payment->mean_payment == MeanPayment::CREDIT; | |||
} | |||
public function getStrMeanPayment(Payment $payment): string | |||
{ | |||
return MeanPayment::getStrBy($payment->getMeanPayment()); | |||
} | |||
public function getStrType(Payment $payment): string | |||
{ | |||
switch($payment->type) { | |||
case Payment::TYPE_PAYMENT: | |||
return 'Paiement'; | |||
case Payment::TYPE_DEBIT: | |||
return 'Débit'; | |||
case Payment::TYPE_CREDIT: | |||
return 'Crédit'; | |||
case Payment::TYPE_REFUND: | |||
return 'Remboursement'; | |||
case Payment::TYPE_INITIAL_CREDIT: | |||
return 'Crédit initial'; | |||
} | |||
return 'Type de paiement inconnu'; | |||
} | |||
public function getStrUserAction(Payment $payment): string | |||
{ | |||
$userAction = $payment->getUserActionObject(); |
@@ -112,7 +112,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
} | |||
} | |||
public function refundOrder(Order $order, User $userAction): void | |||
public function refundOrder(Order $order, string $meanPayment, User $userAction): void | |||
{ | |||
$this->paymentBuilder->createPayment( | |||
Payment::TYPE_REFUND, | |||
@@ -120,7 +120,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$this->getProducerContext(), | |||
$order->user, | |||
$userAction, | |||
MeanPayment::CREDIT, | |||
$meanPayment, | |||
$order | |||
); | |||
} | |||
@@ -144,7 +144,7 @@ class PaymentUtils extends AbstractService implements UtilsInterface | |||
$this->payOrder($order, $meanPayment, $userAction, $checkCreditLimit); | |||
} | |||
elseif($type == Payment::TYPE_REFUND) { | |||
$this->refundOrder($order, $userAction); | |||
$this->refundOrder($order, $meanPayment, $userAction); | |||
} | |||
else { | |||
throw new ErrorException('$type a une valeur incorrect'); |
@@ -64,14 +64,16 @@ class UserProducerBuilder extends AbstractBuilder | |||
public function updateCredit(Payment $payment): void | |||
{ | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($payment->user); | |||
if($this->paymentSolver->isMeanPaymentCredit($payment) && $payment->user) { | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($payment->user); | |||
if ($userProducer) { | |||
$oldCredit = $userProducer->getCredit(); | |||
if ($userProducer) { | |||
$oldCredit = $userProducer->getCredit(); | |||
$this->deductCredit($userProducer, $payment); | |||
$this->initMeanPaymentOrder($payment); | |||
$this->sendCreditLimitReminder($userProducer, $payment, $oldCredit); | |||
$this->deductCredit($userProducer, $payment); | |||
$this->initMeanPaymentOrder($payment); | |||
$this->sendCreditLimitReminder($userProducer, $payment, $oldCredit); | |||
} | |||
} | |||
} | |||
@@ -15,6 +15,7 @@ class m230913_071815_alter_table_credit_history_rename_payment extends Migration | |||
{ | |||
$this->renameTable('credit_history', 'payment'); | |||
$this->addColumn('payment', 'id_invoice', Schema::TYPE_INTEGER); | |||
$this->alterColumn('payment', 'id_user', Schema::TYPE_INTEGER.' DEFAULT NULL'); | |||
} | |||
/** |