@@ -765,10 +765,9 @@ class OrderController extends BackendController | |||
* @param string $username | |||
* @param array $produits | |||
* @param string $commentaire | |||
* @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; | |||
@@ -854,7 +853,7 @@ class OrderController extends BackendController | |||
} | |||
$order = $orderManager->findOneOrderById($order->id); | |||
if ($order && $processCredit) { | |||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||
$orderManager->processCredit($order); | |||
} | |||
@@ -898,7 +897,6 @@ class OrderController extends BackendController | |||
$meanPayment = $request->post('meanPayment'); | |||
$products = $request->post('products'); | |||
$comment = $request->post('comment'); | |||
$processCredit = $request->post('processCredit'); | |||
$order = $orderManager->findOneOrderById($idOrder); | |||
$user = $userManager->findOneUserById($idUser); | |||
@@ -986,7 +984,7 @@ class OrderController extends BackendController | |||
$order->save(); | |||
$order = Order::searchOne(['id' => $order->id]); | |||
if ($order && $processCredit) { | |||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||
// 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 ; |
@@ -8,10 +8,12 @@ use common\logic\Distribution\ProductDistribution\Repository\ProductDistribution | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Order\Order\Service\OrderSolver; | |||
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\Repository\ProducerRepository; | |||
use common\logic\Product\Product\Model\Product; | |||
use common\logic\User\User\Model\User; | |||
use common\logic\User\UserProducer\Model\UserProducer; | |||
use yii\helpers\Html; | |||
class OrderRepository extends AbstractRepository | |||
@@ -278,4 +280,29 @@ class OrderRepository extends AbstractRepository | |||
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; | |||
} | |||
} |