浏览代码

[Administration] Abonnements : ajustement paiement automatique #487

refactoring
Guillaume Bourgeois 2 年前
父节点
当前提交
5190e6f197
共有 2 个文件被更改,包括 33 次插入17 次删除
  1. +6
    -4
      backend/views/subscription/_form.php
  2. +27
    -13
      common/models/Subscription.php

+ 6
- 4
backend/views/subscription/_form.php 查看文件

@@ -83,10 +83,12 @@ use common\helpers\GlobalParam ;
<?= $form->field($model, 'week_frequency')->dropDownList([1=>1, 2=>2, 3=>3, 4=>4]) ?>

<?= $form->field($model, 'auto_payment')
->checkbox()
->hint('Cochez cette case si vous souhaitez que le crédit pain du client soit automatiquement débité lors de la création de la commande.<br />'
. 'Attention, un compte client existant doit être spécifié en haut de ce formulaire.'
. '<br /><strong>Pris en compte uniquement dans le cas d\'un Crédit défini comme optionnel au niveau du point de vente. Dans les autres cas, il sera automatiquement déduit.</strong>') ?>
->dropDownList([
Subscription::AUTO_PAYMENT_DEDUCTED => 'Déduit',
Subscription::AUTO_PAYMENT_YES => 'Oui',
Subscription::AUTO_PAYMENT_NO => 'Non'
])
->hint('Attention, un compte client existant doit être spécifié en haut de ce formulaire.') ?>
<div class="products">
<h2>Produits</h2>

+ 27
- 13
common/models/Subscription.php 查看文件

@@ -71,6 +71,11 @@ use common\models\ProductOrder;
*/
class Subscription extends ActiveRecordCommon
{
const AUTO_PAYMENT_DEDUCTED = 1;
const AUTO_PAYMENT_YES = 2;
const AUTO_PAYMENT_NO = 0;


/**
* @inheritdoc
*/
@@ -216,22 +221,31 @@ class Subscription extends ActiveRecordCommon
$creditFunctioning = $pointSale->getCreditFunctioning();

$order->auto_payment = 0;
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
$order->auto_payment = $this->auto_payment;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$order->auto_payment = 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$user = User::findOne($order->id_user);
$userProducer = UserProducer::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]);
if ($userProducer) {
$order->auto_payment = $userProducer->credit_active;
if($this->auto_payment == self::AUTO_PAYMENT_DEDUCTED) {
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
$order->auto_payment = 0;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$order->auto_payment = 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$user = User::findOne($order->id_user);
$userProducer = UserProducer::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]);
if ($userProducer) {
$order->auto_payment = $userProducer->credit_active;
}
}
}
}
elseif($this->auto_payment == self::AUTO_PAYMENT_YES) {
$order->auto_payment = 1;
}
elseif($this->auto_payment == self::AUTO_PAYMENT_NO) {
$order->auto_payment = 0;
}


$order->tiller_synchronization = $order->auto_payment;


正在加载...
取消
保存