Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3558-setQuantitySale
This commit is contained in:
commit
9296ff83aa
|
@ -133,6 +133,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
const where = buildFilter(ctx.args, (param, value) => {
|
const where = buildFilter(ctx.args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
case 'search':
|
||||||
|
return /^\d+$/.test(value)
|
||||||
|
? {'t.id': {inq: value}}
|
||||||
|
: {'t.nickname': {like: `%${value}%`}};
|
||||||
case 'from':
|
case 'from':
|
||||||
return {'t.shipped': {gte: value}};
|
return {'t.shipped': {gte: value}};
|
||||||
case 'to':
|
case 'to':
|
||||||
|
|
|
@ -138,7 +138,9 @@ module.exports = Self => {
|
||||||
const params = [args.id, args.shipped, args.warehouseFk];
|
const params = [args.id, args.shipped, args.warehouseFk];
|
||||||
const [salesMovable] = await Self.rawSql(query, params, myOptions);
|
const [salesMovable] = await Self.rawSql(query, params, myOptions);
|
||||||
|
|
||||||
const salesNewTicket = salesMovable.filter(sale => (sale.movable ?? 0) >= sale.quantity);
|
const saleMovable = sale.movable ? sale.movable : 0;
|
||||||
|
|
||||||
|
const salesNewTicket = salesMovable.filter(sale => saleMovable >= sale.quantity);
|
||||||
if (salesNewTicket.length) {
|
if (salesNewTicket.length) {
|
||||||
const newTicket = await models.Ticket.transferSales(ctx, args.id, null, salesNewTicket, myOptions);
|
const newTicket = await models.Ticket.transferSales(ctx, args.id, null, salesNewTicket, myOptions);
|
||||||
args.id = newTicket.id;
|
args.id = newTicket.id;
|
||||||
|
@ -250,7 +252,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
res.id = args.id;
|
res.id = args.id;
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
|
@ -114,7 +114,7 @@ module.exports = Self => {
|
||||||
const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions);
|
const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions);
|
||||||
const differenceShipped = ticketOrigin.shipped.getTime() != args.shipped.getTime();
|
const differenceShipped = ticketOrigin.shipped.getTime() != args.shipped.getTime();
|
||||||
const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId;
|
const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId;
|
||||||
|
|
||||||
salesObj.haveDifferences = differenceShipped || differenceWarehouse;
|
salesObj.haveDifferences = differenceShipped || differenceWarehouse;
|
||||||
|
|
||||||
let query = `CALL ticket_getMovable(?,?,?)`;
|
let query = `CALL ticket_getMovable(?,?,?)`;
|
||||||
|
@ -122,8 +122,10 @@ module.exports = Self => {
|
||||||
const [salesMovable] = await Self.rawSql(query, params, myOptions);
|
const [salesMovable] = await Self.rawSql(query, params, myOptions);
|
||||||
|
|
||||||
const itemMovable = new Map();
|
const itemMovable = new Map();
|
||||||
for (sale of salesMovable)
|
for (sale of salesMovable) {
|
||||||
itemMovable.set(sale.id, sale.movable ?? 0);
|
const saleMovable = sale.movable ? sale.movable : 0;
|
||||||
|
itemMovable.set(sale.id, saleMovable);
|
||||||
|
}
|
||||||
|
|
||||||
// Sale price component, one per sale
|
// Sale price component, one per sale
|
||||||
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
||||||
|
@ -152,7 +154,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return salesObj;
|
return salesObj;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
Loading…
Reference in New Issue