feat: refs #6321 fix methods

This commit is contained in:
Javier Segarra 2025-01-31 01:07:28 +01:00
parent 9791f3b935
commit 7fdd3d1eb8
6 changed files with 60 additions and 110 deletions

View File

@ -26,10 +26,7 @@ module.exports = Self => {
Object.assign(myOptions, options); Object.assign(myOptions, options);
const {where} = filter; const {where} = filter;
const today =
new Date().toLocaleDateString('en-US', {year: 'numeric',
month: '2-digit',
day: '2-digit'});
const query = [ const query = [
filter.itemFk, filter.itemFk,
where.warehouseFk, where.warehouseFk,
@ -38,78 +35,7 @@ module.exports = Self => {
where.scopeDays ?? 2 where.scopeDays ?? 2
]; ];
const [results] = await Self.rawSql('CALL vn.item_getSimilar(?, ?, ?, ?, ?)', query, myOptions); const [results] = await Self.rawSql('CALL vn.item_getSimilar(?, ?, ?, ?, ?)', query, myOptions);
// return results
return [
{
'id': 1,
'longName': 'Ranged weapon longbow 50cm',
'subName': 'Stark Industries',
'tag5': 'Color',
'value5': 'Brown',
'match5': 0,
'match6': 0,
'match7': 0,
'match8': 1,
'tag6': 'Categoria',
'value6': '+1 precission',
'tag7': 'Tallos',
'value7': '1',
'tag8': null,
'value8': null,
'available': 20,
'calc_id': 6,
'counter': 0,
'minQuantity': 1,
'visible': null,
'price2': 1
},
{
'id': 2,
'longName': 'Ranged weapon longbow 100cm',
'subName': 'Stark Industries',
'tag5': 'Color',
'value5': 'Brown',
'match5': 0,
'match6': 1,
'match7': 0,
'match8': 1,
'tag6': 'Categoria',
'value6': '+1 precission',
'tag7': 'Tallos',
'value7': '1',
'tag8': null,
'value8': null,
'available': 50,
'calc_id': 6,
'counter': 1,
'minQuantity': 5,
'visible': null,
'price2': 10
},
{
'id': 3,
'longName': 'Ranged weapon longbow 200cm',
'subName': 'Stark Industries',
'tag5': 'Color',
'value5': 'Brown',
'match5': 1,
'match6': 1,
'match7': 1,
'match8': 1,
'tag6': 'Categoria',
'value6': '+1 precission',
'tag7': 'Tallos',
'value7': '1',
'tag8': null,
'value8': null,
'available': 185,
'calc_id': 6,
'counter': 10,
'minQuantity': 10,
'visible': null,
'price2': 100
}
]; return results;
}; };
}; };

View File

@ -3,7 +3,8 @@ module.exports = Self => {
Self.remoteMethodCtx('replaceItem', { Self.remoteMethodCtx('replaceItem', {
description: 'Replace item from sale', description: 'Replace item from sale',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [
{
arg: 'saleFk', arg: 'saleFk',
type: 'number', type: 'number',
required: true, required: true,
@ -36,8 +37,6 @@ module.exports = Self => {
const models = Self.app.models; const models = Self.app.models;
// const {_saleFk, _substitutionFk, _quantity} = ctx.args;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -47,25 +46,46 @@ module.exports = Self => {
} }
try { try {
const _replaceItem = { const replaceItemQuery = {
sql: 'CALL sale_replaceItem(?,?,?)', sql: 'CALL sale_replaceItem(?,?,?)',
query: [saleFk, substitutionFk, quantity] query: [saleFk, substitutionFk, quantity]
}; };
const resultReplaceItem = await Self.rawSql(_replaceItem.sql, _replaceItem.query, myOptions); const resultReplaceItem = await Self.rawSql(replaceItemQuery.sql, replaceItemQuery.query, myOptions);
const sale = await models.Sale.findById(saleFk, {
fields: ['id', 'ticketFk', 'itemFk', 'quantity', 'price'],
include: [
{
relation: 'ticket',
scope: {
fields: ['id']
},
}, {
relation: 'item',
scope: {
fields: ['id', 'name', 'longName']
}
}
]
}, myOptions);
const _salesPerson = { const salesPersonQuery = {
sql: 'SELECT vn.client_getSalesPersonByTicket(?)', sql: 'SELECT vn.client_getSalesPersonByTicket(?)',
query: [saleFk.ticket.id] query: [sale.ticketFk]
}; };
const salesPerson = await Self.rawSql(_salesPerson.query, _salesPerson.sql, myOptions); const salesPerson = await Self.rawSql(salesPersonQuery.sql, salesPersonQuery.query, myOptions);
const url = await Self.app.models.Url.getUrl();
const substitution = await models.Item.findById(substitutionFk, {
fields: ['id', 'name', 'longName']
}, myOptions);
const message = $t('negativeReplaced', { const message = $t('negativeReplaced', {
oldItemId: itemFk, oldItemId: sale.itemFk,
oldItemUrl: `${url}item/${itemFk}/summary`, oldItem: sale.item().longName,
newItemId: substitutionFk, oldItemUrl: `${url}item/${sale.itemFk}/summary`,
newItemUrl: `${url}item/${substitutionFk}/summary`, newItemId: substitution.id,
ticketId: ticketFk, newItem: substitution.longName,
ticketUrl: `${url}ticket/${ticketFk}/sale`, newItemUrl: `${url}item/${substitution.id}/summary`,
ticketId: sale.ticketFk,
ticketUrl: `${url}ticket/${sale.ticketFk}/sale`
}); });
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);

View File

@ -2,7 +2,7 @@ const {ParameterizedSQL} = require('loopback-connector');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('itemLackDetail', { Self.remoteMethod('itemLackDetail', {
description: 'Retrieve detail from ticket', description: 'Retrieve detail from ticket as negative',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
{ {

View File

@ -90,7 +90,7 @@ describe('Item Lack', () => {
try { try {
const result = await models.Ticket.itemLack(ctx, filter, options); const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(0); expect(result.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();

View File

@ -1,6 +1,6 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('split', { Self.remoteMethodCtx('split', {
description: 'Split ticket', description: 'Split ticket with custom date',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [ accepts: [
{ {
@ -8,6 +8,11 @@ module.exports = Self => {
type: 'Object', type: 'Object',
required: true, required: true,
http: {source: 'body'} http: {source: 'body'}
},
{
arg: 'date',
type: 'date',
required: true,
} }
], ],
returns: { returns: {

View File

@ -33,8 +33,7 @@ module.exports = Self => {
} }
}); });
Self.transferSales = async(ctx, id, ticketId, sales, Self.transferSales = async(ctx, id, ticketId, sales, options) => {
options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const models = Self.app.models; const models = Self.app.models;
const myOptions = {userId}; const myOptions = {userId};