refs #6553 changes models #2522

Merged
carlossa merged 41 commits from 6553-workerBusiness into dev 2025-01-31 09:19:15 +00:00
4 changed files with 74 additions and 46 deletions
Showing only changes of commit c1b9032534 - Show all commits

View File

@ -11,6 +11,7 @@ BEGIN
DECLARE vCurrentCommission INT; DECLARE vCurrentCommission INT;
DECLARE vIsNotEUR INT; DECLARE vIsNotEUR INT;
DECLARE vLastEntryFk INT; DECLARE vLastEntryFk INT;
DECLARE vLanded INT;
SELECT count(*) INTO vIsNotEUR SELECT count(*) INTO vIsNotEUR
FROM currency c FROM currency c
@ -26,23 +27,25 @@ BEGIN
RETURN IFNULL(vCommission, 0); RETURN IFNULL(vCommission, 0);
ELSE ELSE
SELECT landed INTO vLanded
FROM travel
WHERE id = vTravelFk;
SELECT e.id INTO vLastEntryFk SELECT e.id INTO vLastEntryFk
FROM `entry` e FROM `entry` e
JOIN travel tr ON tr.id = e.travelFk JOIN travel tr ON tr.id = e.travelFk
WHERE e.supplierFk = vSupplierFk WHERE e.supplierFk = vSupplierFk
ORDER BY tr.landed DESC ORDER BY (vLanded <= tr.landed), tr.landed DESC
LIMIT 1; LIMIT 1;
IF vLastEntryFk THEN IF vLastEntryFk THEN
SELECT commission INTO vCurrentCommission SELECT commission INTO vCurrentCommission
FROM `entry` FROM `entry`
WHERE id = vLastEntryFk; WHERE id = vLastEntryFk;
ELSE ELSE
SELECT commission INTO vCurrentCommission SELECT commission INTO vCurrentCommission
FROM supplier s FROM supplier s
WHERE s.id = vSupplierFk; WHERE s.id = vSupplierFk;
END IF; END IF;
RETURN vCurrentCommission; RETURN vCurrentCommission;

View File

@ -54,9 +54,17 @@ module.exports = Self => {
throw new UserError(`That item doesn't exists`); throw new UserError(`That item doesn't exists`);
const request = await models.TicketRequest.findById(ctx.args.id, { const request = await models.TicketRequest.findById(ctx.args.id, {
include: {relation: 'ticket'} include: {
relation: 'ticket',
scope: {
include: {
relation: 'client',
scope: {
fields: ['id', 'name', 'salesPersonFk']
}
}
}}
}, myOptions); }, myOptions);
const itemStock = await models.Item.getVisibleAvailable( const itemStock = await models.Item.getVisibleAvailable(
ctx.args.itemFk, ctx.args.itemFk,
request.ticket().warehouseFk, request.ticket().warehouseFk,
@ -89,9 +97,9 @@ module.exports = Self => {
const query = `CALL vn.sale_calculateComponent(?, NULL)`; const query = `CALL vn.sale_calculateComponent(?, NULL)`;
await Self.rawSql(query, [sale.id], myOptions); await Self.rawSql(query, [sale.id], myOptions);
const salesPerson = request.ticket().client().salesPersonFk;
if (salesPerson) {
const url = await Self.app.models.Url.getUrl(); const url = await Self.app.models.Url.getUrl();
const requesterId = request.requesterFk;
const message = $t('Bought units from buy request', { const message = $t('Bought units from buy request', {
quantity: sale.quantity, quantity: sale.quantity,
concept: sale.concept, concept: sale.concept,
@ -100,8 +108,8 @@ module.exports = Self => {
url: `${url}ticket/${sale.ticketFk}/summary`, url: `${url}ticket/${sale.ticketFk}/summary`,
urlItem: `${url}item/${sale.itemFk}/summary` urlItem: `${url}item/${sale.itemFk}/summary`
}); });
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions); await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
}
if (tx) await tx.commit(); if (tx) await tx.commit();
return sale; return sale;

View File

@ -1,18 +1,22 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('deny', { Self.remoteMethodCtx('deny', {
description: 'sets a ticket request to denied and returns the changes', description: 'Sets a ticket request to denied and returns the changes',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [
{
arg: 'id', arg: 'id',
type: 'number', type: 'number',
required: true, required: true,
description: 'The request ID', description: 'The request ID',
}, { },
{
arg: 'observation', arg: 'observation',
type: 'String', type: 'string',
required: true, required: true,
description: 'The request observation', description: 'The request observation',
}], }
],
returns: { returns: {
type: 'number', type: 'number',
root: true root: true
@ -29,7 +33,7 @@ module.exports = Self => {
const myOptions = {}; const myOptions = {};
let tx; let tx;
if (typeof options == 'object') if (typeof options === 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (!myOptions.transaction) { if (!myOptions.transaction) {
@ -39,7 +43,7 @@ module.exports = Self => {
try { try {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions); const worker = await models.Worker.findById(userId, {fields: ['id']}, myOptions);
const params = { const params = {
isOk: false, isOk: false,
@ -47,19 +51,32 @@ module.exports = Self => {
response: ctx.args.observation, response: ctx.args.observation,
}; };
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); const request = await models.TicketRequest.findById(ctx.args.id, {
await request.updateAttributes(params, myOptions); include: {
relation: 'ticket',
const url = await Self.app.models.Url.getUrl(); scope: {
const requesterId = request.requesterFk; include: {
relation: 'client',
scope: {
fields: ['id', 'name', 'salesPersonFk']
}
}
}
}
}, myOptions);
const salesPerson = request.ticket().client().salesPersonFk;
if (salesPerson) {
const url = await models.Url.getUrl();
const message = $t('Deny buy request', { const message = $t('Deny buy request', {
ticketId: request.ticketFk, ticketId: request.ticketFk,
url: `${url}ticket/${request.ticketFk}/request/index`, url: `${url}ticket/${request.ticketFk}/request/index`,
observation: params.response observation: params.response
}); });
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions); await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
await request.updateAttributes(params, myOptions);
}
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -25,7 +25,7 @@
"userFk": { "userFk": {
"type": "number" "type": "number"
}, },
"simSerialNumber": { "simFk": {
"type": "string" "type": "string"
}, },
"created": { "created": {