Browse Source

[Administration] Distributions : correctif affichage des quantités restantes (décimales et arrondis) #1258

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
2362602784
3 changed files with 44 additions and 22 deletions
  1. +1
    -4
      backend/controllers/DistributionController.php
  2. +4
    -2
      backend/views/distribution/index.php
  3. +39
    -16
      backend/web/js/vuejs/distribution-index.js

+ 1
- 4
backend/controllers/DistributionController.php View File

@@ -127,6 +127,7 @@ class DistributionController extends BackendController
$json['means_payment'] = MeanPayment::getAll();
$json['producer'] = $this->buildAjaxInfosResponseProducer($producer);
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject);
$json['units'] = Product::$unitsArray;

if ($dateObject && $dateObject->format($format) === $date) {
$distribution = $distributionManager->createDistributionIfNotExist($date);
@@ -310,7 +311,6 @@ class DistributionController extends BackendController
$productOrderArray[$productOrder->id_product] = [
'quantity' => $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'],
'unit' => $productOrder->unit,
'unit_coefficient' => Product::$unitsArray[$productOrder->unit]['coefficient'],
'price' => number_format($productOrder->price, 5),
'invoice_price' => number_format($productOrder->invoice_price, 5),
'price_with_tax' => Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value),
@@ -322,7 +322,6 @@ class DistributionController extends BackendController
$productOrderArray[$product['id']] = [
'quantity' => 0,
'unit' => $product['unit'],
'unit_coefficient' => Product::$unitsArray[$product['unit']]['coefficient'],
'price' => number_format($product['price'], 5),
'price_with_tax' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']),
];
@@ -417,7 +416,6 @@ class DistributionController extends BackendController
$productOrderArray[$product['id']] = [
'quantity' => 0,
'unit' => $product['unit'],
'unit_coefficient' => Product::$unitsArray[$product['unit']]['coefficient'],
'price' => number_format($product['price'], 5),
'price_with_tax' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']),
];
@@ -536,7 +534,6 @@ class DistributionController extends BackendController
$productOrderArray[$product['id']] = [
'quantity' => $quantity,
'unit' => $product->unit,
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $priceArray,
'active' => $product->productDistribution[0]->active
&& (!$pointSale || $productManager->isAvailableOnPointSale($product, $pointSale)),

+ 4
- 2
backend/views/distribution/index.php View File

@@ -251,7 +251,8 @@ $this->setPageTitle('Distributions') ;
:producer="producer"
:orders="ordersUpdate"
:loading-update-product-order="loadingUpdateProductOrder"
@close="showModalFormOrderCreate = false"
:units="units"
@close="closeModalOrderForm(true)"
@ordercreatedupdated="orderCreatedUpdated"
@updateproductorderprices="updateProductOrderPrices"
></order-form>
@@ -528,7 +529,8 @@ $this->setPageTitle('Distributions') ;
:orders="ordersUpdate"
:producer="producer"
:loading-update-product-order="loadingUpdateProductOrder"
@close="showModalFormOrderUpdate = false"
:units="units"
@close="closeModalOrderForm(false)"
@ordercreatedupdated="orderCreatedUpdated"
@updateproductorderprices="updateProductOrderPrices"
@updateinvoiceprices="updateInvoicePrices"

+ 39
- 16
backend/web/js/vuejs/distribution-index.js View File

@@ -80,6 +80,7 @@ var app = new Vue({
messageGenerateDeliveryNoteDisplayed: false,
missingSubscriptions: false,
loadingUpdateProductOrder: false,
units: [],
calendar: {
mode: 'single',
attrs: [],
@@ -156,6 +157,7 @@ var app = new Vue({
axios.get("ajax-infos", {params: {date: this.getDate()}})
.then(function (response) {
app.calendar.attrs = [];
app.units = response.data.units;
app.distribution = response.data.distribution;
app.producer = response.data.producer;
app.products = response.data.products;
@@ -565,6 +567,16 @@ var app = new Vue({
this.showModalProducts = false;
this.init(this.idActivePointSale);
},
closeModalOrderForm: function(create) {
if(create) {
this.showModalFormOrderCreate = false
}
else {
this.showModalFormOrderUpdate = false
}

this.init(this.idActivePointSale);
},
cloneOrder: function (order) {
var clone = Object.assign({}, order);

@@ -788,7 +800,6 @@ var app = new Vue({
if (app.showModalFormOrderCreate) {
Vue.set(app.orderCreate.productOrder[idProduct], 'prices', response.data[idProduct].prices);
Vue.set(app.orderCreate.productOrder[idProduct], 'active', response.data[idProduct].active);
Vue.set(app.orderCreate.productOrder[idProduct], 'unit_coefficient', response.data[idProduct].unit_coefficient);
Vue.set(app.orderCreate.productOrder[idProduct], 'price', app.getBestProductPrice(app.orderCreate, idProduct, app.orderCreate.productOrder[idProduct].quantity, false));
Vue.set(app.orderCreate.productOrder[idProduct], 'price_with_tax', app.getBestProductPrice(app.orderCreate, idProduct, app.orderCreate.productOrder[idProduct].quantity, true));
}
@@ -798,7 +809,6 @@ var app = new Vue({
if (order.id == app.idOrderUpdate) {
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'prices', response.data[idProduct].prices);
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'active', response.data[idProduct].active);
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'unit_coefficient', response.data[idProduct].unit_coefficient);
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'invoice_price', response.data[idProduct].invoice_price);

if (updatePricesOnUpdateOrder) {
@@ -849,9 +859,11 @@ var app = new Vue({
}
},
getBestProductPrice: function (order, idProduct, theQuantity, withTax) {
var product = this.getProduct(idProduct);
var thePrice = 9999;
var pricesArray = order.productOrder[idProduct].prices;
var unitCoefficient = order.productOrder[idProduct].unit_coefficient;

var unitCoefficient = this.getUnitCoefficient(product.unit);
if (theQuantity) {
theQuantity = theQuantity / unitCoefficient;
}
@@ -870,7 +882,6 @@ var app = new Vue({
}
}
} else {
var product = this.getProduct(idProduct);
if (withTax) {
thePrice = getPriceWithTax(product.price, product.taxRate.value);
} else {
@@ -909,6 +920,9 @@ var app = new Vue({
}

return count;
},
getUnitCoefficient: function(unit) {
return this.units[unit].coefficient;
}
},
});
@@ -923,7 +937,7 @@ Vue.component('modal', {
});

Vue.component('order-form', {
props: ['date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'orders', 'producer', 'loadingUpdateProductOrder', 'create'],
props: ['date', 'dateFormat', 'pointsSale', 'idActivePointSale', 'meansPayment', 'users', 'products', 'order', 'orders', 'producer', 'loadingUpdateProductOrder', 'create', 'units'],
emits: ['updateProductPrice', 'updateInvoicePrices'],
data: function () {
return {
@@ -1132,23 +1146,32 @@ Vue.component('order-form', {
}
},
getProductQuantityRemaining: function(product) {
var order = null;
var app = this;
var quantityRemaining = 0;
var productQuantityOrder = 0;
var unitCoefficient = 1;
var unit = product.unit;

for(key in app.orders) {
order = app.orders[key];
unitCoefficient = order.productOrder[product.id].unit_coefficient;
productQuantityOrder += order.productOrder[product.id].quantity / unitCoefficient;
for(key in this.orders) {
productQuantityOrder += this.getProductQuantityProductOrder(this.orders[key], product);
}
if(this.create == 1) {
productQuantityOrder += this.getProductQuantityProductOrder(this.order, product);
}

if(app.create == 1) {
unitCoefficient = app.order.productOrder[product.id].unit_coefficient;
productQuantityOrder += app.order.productOrder[product.id].quantity / unitCoefficient;
quantityRemaining = product.productDistribution[0].quantity_max - productQuantityOrder;
if(unit != 'piece') {
quantityRemaining = quantityRemaining.toFixed(2);
}

return product.productDistribution[0].quantity_max - productQuantityOrder;
return quantityRemaining;
},
getProductQuantityProductOrder: function(order, product) {
var productOrder = order.productOrder[product.id];
var unit = productOrder.unit;
var unitCoefficient = this.getUnitCoefficient(unit);
return parseFloat(productOrder.quantity / unitCoefficient);
},
getUnitCoefficient: function(unit) {
return this.units[unit].coefficient;
}
}
});

Loading…
Cancel
Save