@@ -814,7 +814,7 @@ class OrderController extends BackendController | |||
* @param string $processCredit | |||
*/ | |||
public function actionAjaxCreate( | |||
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment, $processCredit = 0) | |||
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
@@ -894,7 +894,7 @@ class OrderController extends BackendController | |||
} | |||
$order = Order::searchOne(['id' => $order->id]); | |||
if ($order && $processCredit) { | |||
if ($order && $order->isCreditAutoPayment()) { | |||
$order->processCredit(); | |||
} | |||
@@ -1024,7 +1024,7 @@ class OrderController extends BackendController | |||
$order->save(); | |||
$order = Order::searchOne(['id' => $order->id]); | |||
if ($order && $processCredit) { | |||
if($order && $order->isCreditAutoPayment()) { | |||
// Si changement d'user : on rembourse l'ancien user | |||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | |||
if($oldIdUser != $idUser && $amountPaid > 0) { |
@@ -684,8 +684,8 @@ $this->setPageTitle('Distributions') ; | |||
</div> | |||
<div slot="footer"> | |||
<div class="actions-form"> | |||
<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id && order.id_user > 0" data-process-credit="1">Créer et payer</button> | |||
<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id && order.id_user > 0" data-process-credit="1">Modifier et payer</button> | |||
<!--<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id && order.id_user > 0" data-process-credit="1">Créer et payer</button> | |||
<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id && order.id_user > 0" data-process-credit="1">Modifier et payer</button>--> | |||
<button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id">Modifier</button> | |||
<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id">Créer</button> |
@@ -830,8 +830,7 @@ Vue.component('order-form',{ | |||
username: this.order.username, | |||
meanPayment: this.order.mean_payment, | |||
products: app.getProductOrderArrayRequest(), | |||
comment: this.order.comment, | |||
processCredit: processCredit | |||
comment: this.order.comment | |||
}}) | |||
.then(function(response) { | |||
app.order.id_point_sale = 0 ; |
@@ -1099,4 +1099,29 @@ class Order extends ActiveRecordCommon | |||
|| ($this->quotation && $this->quotation->isStatusValid()) | |||
|| ($this->invoice && $this->invoice->isStatusValid()); | |||
} | |||
public function isCreditAutoPayment() | |||
{ | |||
$pointSale = PointSale::findOne($this->id_point_sale); | |||
$distribution = Distribution::findOne($this->id_distribution); | |||
$creditFunctioning = $pointSale->getCreditFunctioning(); | |||
if ($this->id_user && Producer::getConfig('credit') && $pointSale->credit) { | |||
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | |||
return 0; | |||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { | |||
return 1; | |||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $this->id_user, | |||
'id_producer' => $distribution->id_producer | |||
]); | |||
if ($userProducer) { | |||
return $userProducer->credit_active; | |||
} | |||
} | |||
} | |||
return 0; | |||
} | |||
} |
@@ -217,26 +217,9 @@ class Subscription extends ActiveRecordCommon | |||
$pointSale = PointSale::findOne($this->id_point_sale); | |||
if ($pointSale) { | |||
$creditFunctioning = $pointSale->getCreditFunctioning(); | |||
$order->auto_payment = 0; | |||
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; | |||
} | |||
} | |||
} | |||
$order->auto_payment = $order->isCreditAutoPayment(); | |||
} | |||
elseif($this->auto_payment == self::AUTO_PAYMENT_YES) { | |||
$order->auto_payment = 1; | |||
@@ -245,7 +228,6 @@ class Subscription extends ActiveRecordCommon | |||
$order->auto_payment = 0; | |||
} | |||
$order->tiller_synchronization = $order->auto_payment; | |||
$userPointSale = UserPointSale::searchOne([ |