'paymentLabelShort' => $orderManager->getPaymentLabelShort($order), | 'paymentLabelShort' => $orderManager->getPaymentLabelShort($order), | ||||
'isCreditFunctioningMandatory' => $orderManager->isOrderCreditFunctioningMandatory($order), | 'isCreditFunctioningMandatory' => $orderManager->isOrderCreditFunctioningMandatory($order), | ||||
'isCreditFunctioningUser' => $orderManager->isOrderCreditFunctioningUser($order), | 'isCreditFunctioningUser' => $orderManager->isOrderCreditFunctioningUser($order), | ||||
'debitCredit' => false, | |||||
]); | ]); | ||||
} | } | ||||
} | } |
* @param string $commentaire | * @param string $commentaire | ||||
*/ | */ | ||||
public function actionAjaxCreate( | public function actionAjaxCreate( | ||||
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment) | |||||
$date, $idPointSale, $idUser, $username, $meanPayment = '', $products, $comment, $debitCredit = false) | |||||
{ | { | ||||
\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); | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||||
if ($order && $orderManager->isCreditAutoPayment($order, $debitCredit)) { | |||||
$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'); | ||||
$debitCredit = $request->post('debitCredit'); | |||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | |||||
if ($order && $orderManager->isCreditAutoPayment($order, $debitCredit)) { | |||||
$orderManager->processCredit($order); | $orderManager->processCredit($order); | ||||
} | } | ||||
} | } |
<label class="control-label" for="textarea-comment">Commentaire</label> | <label class="control-label" for="textarea-comment">Commentaire</label> | ||||
<textarea class="form-control" id="textarea-comment" v-model="order.comment"></textarea> | <textarea class="form-control" id="textarea-comment" v-model="order.comment"></textarea> | ||||
</div> | </div> | ||||
<div class="form-group" v-if="isPointSaleCreditFunctioningOptional(order.id_point_sale)"> | |||||
<input type="checkbox" id="debit-credit" v-model="order.debitCredit" /> | |||||
<label class="control-label" for="debit-credit">Débiter le crédit</label> | |||||
</div> | |||||
</div> | </div> | ||||
<div class="col-md-8"> | <div class="col-md-8"> | ||||
<label class="control-label">Produits</label> | <label class="control-label">Produits</label> |
} | } | ||||
return JSON.stringify(productOrderArrayRequest); | return JSON.stringify(productOrderArrayRequest); | ||||
}, | }, | ||||
getPointSale: function(idPointSale) { | |||||
for(key in this.pointsSale) { | |||||
if (this.pointsSale[key].id == idPointSale) { | |||||
return this.pointsSale[key]; | |||||
} | |||||
} | |||||
return false; | |||||
}, | |||||
isPointSaleCreditFunctioningOptional: function(idPointSale) { | |||||
var pointSale = this.getPointSale(idPointSale); | |||||
if(pointSale && pointSale.credit_functioning == 'optional') { | |||||
return true; | |||||
} | |||||
return false; | |||||
}, | |||||
submitFormCreate: function (event) { | submitFormCreate: function (event) { | ||||
var app = this; | var app = this; | ||||
if (this.checkForm()) { | if (this.checkForm()) { | ||||
var processCredit = event.currentTarget.getAttribute('data-process-credit'); | |||||
axios.get(UrlManager.getBaseUrlAbsolute() + "order/ajax-create", { | axios.get(UrlManager.getBaseUrlAbsolute() + "order/ajax-create", { | ||||
params: { | params: { | ||||
date: this.date.getFullYear() + '-' | date: this.date.getFullYear() + '-' | ||||
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 | |||||
comment: this.order.comment, | |||||
debitCredit: this.order.debitCredit | |||||
} | } | ||||
}) | }) | ||||
.then(function (response) { | .then(function (response) { | ||||
submitFormUpdate: function (event) { | submitFormUpdate: function (event) { | ||||
var app = this; | var app = this; | ||||
if (this.checkForm()) { | if (this.checkForm()) { | ||||
var processCredit = event.currentTarget.getAttribute('data-process-credit'); | |||||
if (processCredit == null) { | |||||
processCredit = 0; | |||||
} | |||||
var data = new FormData(); | var data = new FormData(); | ||||
data.append('date', this.date.getFullYear() + '-' | data.append('date', this.date.getFullYear() + '-' | ||||
+ ('0' + (this.date.getMonth() + 1)).slice(-2) + '-' | + ('0' + (this.date.getMonth() + 1)).slice(-2) + '-' | ||||
data.append('username', '' + this.order.username); | data.append('username', '' + this.order.username); | ||||
data.append('products', app.getProductOrderArrayRequest()); | data.append('products', app.getProductOrderArrayRequest()); | ||||
data.append('comment', this.order.comment && this.order.comment.length ? this.order.comment : ''); | data.append('comment', this.order.comment && this.order.comment.length ? this.order.comment : ''); | ||||
data.append('processCredit', processCredit); | |||||
data.append('debitCredit', this.order.debitCredit ? this.order.debitCredit : 0); | |||||
axios.post(UrlManager.getBaseUrlAbsolute() + "order/ajax-update", data) | axios.post(UrlManager.getBaseUrlAbsolute() + "order/ajax-update", data) | ||||
.then(function (response) { | .then(function (response) { |
return $productDistributionArray; | return $productDistributionArray; | ||||
} | } | ||||
public function isCreditAutoPayment(Order $order) | |||||
public function isCreditAutoPayment(Order $order, bool $debitCreditOnFunctioningOptional = false) | |||||
{ | { | ||||
//$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||||
$pointSale = $order->pointSale; | $pointSale = $order->pointSale; | ||||
if($pointSale) { | if($pointSale) { | ||||
return true; | return true; | ||||
} | } | ||||
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | ||||
return false; | |||||
return $debitCreditOnFunctioningOptional; | |||||
} | } | ||||
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | ||||
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user); | $userProducer = $this->userProducerRepository->findOneUserProducer($order->user); |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\AbstractService; | use common\logic\AbstractService; | ||||
use common\logic\Order\Order\Model\Order; | |||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Producer\Producer\Model\Producer; | |||||
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||