浏览代码

[backend] Boutons "Créer et payer" et "Modifier et payer" lors de l'ajout de commandes

dev
父节点
当前提交
aaa7194d74
共有 4 个文件被更改,包括 58 次插入8 次删除
  1. +15
    -4
      backend/controllers/OrderController.php
  2. +3
    -0
      backend/views/distribution/index.php
  3. +8
    -4
      backend/web/js/vuejs/distribution-index.js
  4. +32
    -0
      common/models/Order.php

+ 15
- 4
backend/controllers/OrderController.php 查看文件

@@ -826,14 +826,15 @@ class OrderController extends BackendController
* Crée une commande via une requête AJAX.
*
* @param string $date
* @param integer $id_pv
* @param integer $id_user
* @param integer $idPointSale
* @param integer $idUser
* @param string $username
* @param array $produits
* @param string $commentaire
* @param string $processCredit
*/
public function actionAjaxCreate(
$date, $idPointSale, $idUser, $username, $products, $comment)
$date, $idPointSale, $idUser, $username, $products, $comment, $processCredit = 0)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
@@ -886,6 +887,11 @@ class OrderController extends BackendController
$productOrder->save();
}
}
$order = Order::searchOne(['id' => $order->id]) ;
if($order && $processCredit) {
$order->processCredit() ;
}
}
return ['success'] ;
@@ -900,7 +906,7 @@ class OrderController extends BackendController
* @param string $comment
*/
public function actionAjaxUpdate(
$date, $idOrder, $idPointSale, $idUser, $username, $products, $comment)
$date, $idOrder, $idPointSale, $idUser, $username, $products, $comment, $processCredit = 0)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
@@ -962,6 +968,11 @@ class OrderController extends BackendController
}
$order->save();
$order = Order::searchOne(['id' => $order->id]) ;
if($order && $processCredit) {
$order->processCredit() ;
}
}
}


+ 3
- 0
backend/views/distribution/index.php 查看文件

@@ -486,6 +486,9 @@ $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" 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" 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-else>Créer</button>


+ 8
- 4
backend/web/js/vuejs/distribution-index.js 查看文件

@@ -396,9 +396,10 @@ Vue.component('order-form',{
}
},
submitFormCreate: function() {
submitFormCreate: function(event) {
var app = this ;
if(this.checkForm()) {
var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-create",{params: {
date: this.date.getFullYear() + '-'
+ ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
@@ -407,7 +408,8 @@ Vue.component('order-form',{
idUser: this.order.id_user,
username: this.order.username,
products: JSON.stringify(this.order.productOrder),
comment: this.order.comment
comment: this.order.comment,
processCredit: processCredit
}})
.then(function(response) {
app.order.id_point_sale = 0 ;
@@ -422,9 +424,10 @@ Vue.component('order-form',{
}) ;
}
},
submitFormUpdate: function() {
submitFormUpdate: function(event) {
var app = this ;
if(this.checkForm()) {
var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-update",{params: {
date: this.date.getFullYear() + '-'
+ ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
@@ -434,7 +437,8 @@ Vue.component('order-form',{
idUser: this.order.id_user,
username: ''+this.order.username,
products: JSON.stringify(this.order.productOrder),
comment: this.comment
comment: this.comment,
processCredit: processCredit
}})
.then(function(response) {
app.$emit('ordercreatedupdated') ;

+ 32
- 0
common/models/Order.php 查看文件

@@ -307,6 +307,38 @@ class Order extends ActiveRecordCommon
$creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one()) ;
$creditHistory->save();
}
/**
* Ajuste le crédit pour que la commande soit payée.
*
* @return boolean
*/
public function processCredit()
{
if($this->id_user) {
$paymentStatus = $this->getPaymentStatus() ;

if($paymentStatus == self::PAYMENT_PAID) {
return true;
}
elseif($paymentStatus == self::PAYMENT_SURPLUS) {
$type = CreditHistory::TYPE_REFUND ;
$amount = $this->getAmount(self::AMOUNT_SURPLUS) ;
}
elseif($paymentStatus == self::PAYMENT_UNPAID) {
$type = CreditHistory::TYPE_PAYMENT ;
$amount = $this->getAmount(self::AMOUNT_REMAINING) ;
}

$this->saveCreditHistory(
$type,
$amount,
Producer::getId(),
$this->id_user,
User::getCurrentId()
);
}
}

/**
* Retourne le statut de paiement de la commande (payée, surplus, ou impayée).

正在加载...
取消
保存