* @param string $processCredit | * @param string $processCredit | ||||
*/ | */ | ||||
public function actionAjaxCreate( | 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; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
} | } | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
if ($order && $processCredit) { | |||||
if ($order && $order->isCreditAutoPayment()) { | |||||
$order->processCredit(); | $order->processCredit(); | ||||
} | } | ||||
$order->save(); | $order->save(); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
if ($order && $processCredit) { | |||||
if($order && $order->isCreditAutoPayment()) { | |||||
// Si changement d'user : on rembourse l'ancien user | // Si changement d'user : on rembourse l'ancien user | ||||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | $amountPaid = $order->getAmount(Order::AMOUNT_PAID); | ||||
if($oldIdUser != $idUser && $amountPaid > 0) { | if($oldIdUser != $idUser && $amountPaid > 0) { |
</div> | </div> | ||||
<div slot="footer"> | <div slot="footer"> | ||||
<div class="actions-form"> | <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="submitFormUpdate" v-if="order.id">Modifier</button> | ||||
<button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id">Créer</button> | <button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id">Créer</button> |
username: this.order.username, | username: this.order.username, | ||||
meanPayment: this.order.mean_payment, | meanPayment: this.order.mean_payment, | ||||
products: app.getProductOrderArrayRequest(), | products: app.getProductOrderArrayRequest(), | ||||
comment: this.order.comment, | |||||
processCredit: processCredit | |||||
comment: this.order.comment | |||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
app.order.id_point_sale = 0 ; | app.order.id_point_sale = 0 ; |
|| ($this->quotation && $this->quotation->isStatusValid()) | || ($this->quotation && $this->quotation->isStatusValid()) | ||||
|| ($this->invoice && $this->invoice->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; | |||||
} | |||||
} | } |
$pointSale = PointSale::findOne($this->id_point_sale); | $pointSale = PointSale::findOne($this->id_point_sale); | ||||
if ($pointSale) { | if ($pointSale) { | ||||
$creditFunctioning = $pointSale->getCreditFunctioning(); | |||||
$order->auto_payment = 0; | $order->auto_payment = 0; | ||||
if($this->auto_payment == self::AUTO_PAYMENT_DEDUCTED) { | 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) { | elseif($this->auto_payment == self::AUTO_PAYMENT_YES) { | ||||
$order->auto_payment = 1; | $order->auto_payment = 1; | ||||
$order->auto_payment = 0; | $order->auto_payment = 0; | ||||
} | } | ||||
$order->tiller_synchronization = $order->auto_payment; | $order->tiller_synchronization = $order->auto_payment; | ||||
$userPointSale = UserPointSale::searchOne([ | $userPointSale = UserPointSale::searchOne([ |