Tarea #658 dialogo de añadir cantidad
This commit is contained in:
parent
702690e949
commit
4fb31f9522
|
@ -97,5 +97,6 @@
|
|||
</vn-horizontal>
|
||||
|
||||
<vn-order-prices-popover
|
||||
vn-id="pricesPopover">
|
||||
vn-id="pricesPopover"
|
||||
order="$ctrl.order">
|
||||
</vn-order-prices-popover>
|
||||
|
|
|
@ -90,32 +90,40 @@ class Controller {
|
|||
|
||||
getFilledLines() {
|
||||
let filledLines = [];
|
||||
let match;
|
||||
this.prices.forEach(price => {
|
||||
if (price.quantity && price.quantity > 0)
|
||||
filledLines.push(price);
|
||||
if (price.quantity && price.quantity > 0) {
|
||||
match = filledLines.find(element => {
|
||||
return element.warehouseFk == price.warehouseFk;
|
||||
});
|
||||
|
||||
if (!match) {
|
||||
filledLines.push(Object.assign({}, price));
|
||||
return;
|
||||
}
|
||||
match.quantity += price.quantity;
|
||||
}
|
||||
});
|
||||
return filledLines;
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.calculateTotal();
|
||||
let filledLines = getFilledLines();
|
||||
let filledLines = this.getFilledLines();
|
||||
|
||||
if (filledLines.length <= 0) return;
|
||||
if (filledLines.length <= 0) {
|
||||
this.vnApp.showError('First you must add some quantity');
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
let params = {
|
||||
orderFk: this.order.id,
|
||||
lines: filledLines,
|
||||
itemFk: this.item.id,
|
||||
landed: this.order.landed,
|
||||
addressFk: this.order.address_id,
|
||||
agencyFk: this.order.agency_id
|
||||
items: filledLines
|
||||
};
|
||||
|
||||
this.$http.post(`/order/api/OrderRows/new`, params).then(res => {
|
||||
console.log(res.data);
|
||||
this.tags = res.data;
|
||||
this.$http.post(`/order/api/OrderRows/addToOrder`, params).then(res => {
|
||||
this.$.popover.hide();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
const UserError = require('vn-loopback/common/helpers').UserError;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('addToOrder', {
|
||||
description: 'Creates rows (lines) for a order',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'order id, [items]',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/addToOrder`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.addToOrder = async params => {
|
||||
console.log(params);
|
||||
let isEditable = await Self.app.models.Order.isEditable(params.orderFk);
|
||||
|
||||
if (!isEditable)
|
||||
throw new UserError('This order is not editable');
|
||||
|
||||
let promises = [];
|
||||
params.items.forEach(item => {
|
||||
promises.push(
|
||||
Self.rawSql(
|
||||
`CALL hedera.orderAddItem(?, ?, ?, ?)`,
|
||||
[item.warehouseFk, item.itemFk, item.quantity, params.orderFk]
|
||||
)
|
||||
);
|
||||
});
|
||||
await Promise.all(promises);
|
||||
return true;
|
||||
};
|
||||
};
|
|
@ -1,28 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('new', {
|
||||
description: 'Creates rows (lines) for a order',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'order id, item id, warehouse, quantity',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/new`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.new = async params => {
|
||||
return await Self.rawSql(
|
||||
`CALL vn.orderAddItem(?, ?, ?, ?)`,
|
||||
[params.warehouseFk, params.itemFk, params.quantity, params.orderFk]
|
||||
);
|
||||
};
|
||||
};
|
|
@ -1,5 +1,3 @@
|
|||
const UserError = require('vn-loopback/common/helpers').UserError;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('isEditable', {
|
||||
description: 'Check if an order is editable',
|
||||
|
@ -25,6 +23,8 @@ module.exports = Self => {
|
|||
let exists = await Self.app.models.Order.findOne({where: {id: orderId}, fields: ['isConfirmed']});
|
||||
|
||||
if (!exists || exists.isConfirmed === 1)
|
||||
throw new UserError('This order is not editable');
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = Self => {
|
||||
//require('../methods/order-row/new')(Self);
|
||||
require('../methods/order-row/addToOrder')(Self);
|
||||
require('../methods/order-row/removes')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue