* @param string $username | * @param string $username | ||||
* @param array $produits | * @param array $produits | ||||
* @param string $commentaire | * @param string $commentaire | ||||
* @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 = $orderManager->findOneOrderById($order->id); | $order = $orderManager->findOneOrderById($order->id); | ||||
if ($order && $processCredit) { | |||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||||
$orderManager->processCredit($order); | $orderManager->processCredit($order); | ||||
} | } | ||||
$meanPayment = $request->post('meanPayment'); | $meanPayment = $request->post('meanPayment'); | ||||
$products = $request->post('products'); | $products = $request->post('products'); | ||||
$comment = $request->post('comment'); | $comment = $request->post('comment'); | ||||
$processCredit = $request->post('processCredit'); | |||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
$user = $userManager->findOneUserById($idUser); | $user = $userManager->findOneUserById($idUser); | ||||
$order->save(); | $order->save(); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
if ($order && $processCredit) { | |||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||||
// 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 ; |
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; | ||||
use common\logic\PointSale\PointSale\Model\PointSale; | |||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | use common\logic\Producer\Producer\Repository\ProducerRepository; | ||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use common\logic\User\UserProducer\Model\UserProducer; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
class OrderRepository extends AbstractRepository | class OrderRepository extends AbstractRepository | ||||
return $productDistributionArray; | return $productDistributionArray; | ||||
} | } | ||||
public function isCreditAutoPayment(Order $order) | |||||
{ | |||||
$pointSale = PointSale::findOne($order->id_point_sale); | |||||
$distribution = Distribution::findOne($order->id_distribution); | |||||
$creditFunctioning = $pointSale->getCreditFunctioning(); | |||||
if ($order->id_user && $order->producerRepository->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' => $order->id_user, | |||||
'id_producer' => $distribution->id_producer | |||||
]); | |||||
if ($userProducer) { | |||||
return $userProducer->credit_active; | |||||
} | |||||
} | |||||
} | |||||
return 0; | |||||
} | |||||
} | } |