2344 ticket sale descuento usuario
gitea/salix/pipeline/head This commit has test failures
Details
gitea/salix/pipeline/head This commit has test failures
Details
This commit is contained in:
parent
cd5ec02e42
commit
962436b8bb
|
@ -0,0 +1,71 @@
|
||||||
|
USE `vn`;
|
||||||
|
DROP procedure IF EXISTS `manaSpellersRequery`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
USE `vn`$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER)
|
||||||
|
BEGIN
|
||||||
|
DECLARE vWorkerHasMana BOOLEAN;
|
||||||
|
DECLARE vFromDated DATE;
|
||||||
|
DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE());
|
||||||
|
DECLARE vMana INT;
|
||||||
|
DECLARE vAutoMana INT;
|
||||||
|
DECLARE vManaBank INT;
|
||||||
|
DECLARE vManaGreugeType INT;
|
||||||
|
|
||||||
|
SELECT id INTO vMana
|
||||||
|
FROM `component` WHERE code = 'mana';
|
||||||
|
|
||||||
|
SELECT id INTO vAutoMana
|
||||||
|
FROM `component` WHERE code = 'autoMana';
|
||||||
|
|
||||||
|
SELECT id INTO vManaBank
|
||||||
|
FROM `bank` WHERE code = 'mana';
|
||||||
|
|
||||||
|
SELECT id INTO vManaGreugeType
|
||||||
|
FROM `greugeType` WHERE code = 'mana';
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vWorkerHasMana
|
||||||
|
FROM vn.workerMana wm
|
||||||
|
LEFT JOIN vn.workerManaExcluded wme ON wm.workerFk = wme.workerFk
|
||||||
|
WHERE wm.workerFk = vWorkerFk AND wme.workerFk IS NULL;
|
||||||
|
|
||||||
|
IF vWorkerHasMana THEN
|
||||||
|
|
||||||
|
SELECT max(dated) INTO vFromDated
|
||||||
|
FROM clientManaCache;
|
||||||
|
|
||||||
|
REPLACE workerMana (workerFk, amount)
|
||||||
|
SELECT vWorkerFk, sum(mana) FROM
|
||||||
|
(
|
||||||
|
SELECT s.quantity * sc.value as mana
|
||||||
|
FROM ticket t
|
||||||
|
JOIN address a ON a.id = t.addressFk
|
||||||
|
JOIN client c ON c.id = a.clientFk
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
|
WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana)
|
||||||
|
AND t.shipped > vFromDated AND t.shipped < vToDated
|
||||||
|
UNION ALL
|
||||||
|
SELECT - r.amountPaid
|
||||||
|
FROM receipt r
|
||||||
|
JOIN client c ON c.id = r.clientFk
|
||||||
|
WHERE c.salesPersonFk = vWorkerFk AND bankFk = vManaBank
|
||||||
|
AND payed > vFromDated
|
||||||
|
UNION ALL
|
||||||
|
SELECT g.amount
|
||||||
|
FROM greuge g
|
||||||
|
JOIN client c ON c.id = g.clientFk
|
||||||
|
WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType
|
||||||
|
AND g.shipped > vFromDated and g.shipped < CURDATE()
|
||||||
|
UNION ALL
|
||||||
|
SELECT cc.mana
|
||||||
|
FROM clientManaCache cc
|
||||||
|
JOIN client c ON c.id = cc.clientFk
|
||||||
|
WHERE c.salesPersonFk = vWorkerFk AND cc.dated = vFromDated
|
||||||
|
) sub;
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Hay una versión en salix que machacará toda esta función/procedimiento
|
||||||
|
avisa a ___ de los cambios que quieres hacer
|
||||||
|
*/
|
|
@ -122,6 +122,9 @@
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"columnName": "expenceFk"
|
"columnName": "expenceFk"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"compression": {
|
||||||
|
"type": "Number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -35,7 +35,6 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.updateDiscount = async(ctx, id, salesIds, newDiscount) => {
|
Self.updateDiscount = async(ctx, id, salesIds, newDiscount) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const tx = await Self.beginTransaction({});
|
const tx = await Self.beginTransaction({});
|
||||||
|
|
||||||
|
@ -69,6 +68,7 @@ module.exports = Self => {
|
||||||
if (!allFromSameTicket)
|
if (!allFromSameTicket)
|
||||||
throw new UserError('All sales must belong to the same ticket');
|
throw new UserError('All sales must belong to the same ticket');
|
||||||
|
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const isLocked = await models.Ticket.isLocked(id);
|
const isLocked = await models.Ticket.isLocked(id);
|
||||||
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||||
const state = await Self.app.models.TicketState.findOne({
|
const state = await Self.app.models.TicketState.findOne({
|
||||||
|
@ -79,18 +79,9 @@ module.exports = Self => {
|
||||||
if (isLocked || (!isSalesPerson && alertLevel > 0))
|
if (isLocked || (!isSalesPerson && alertLevel > 0))
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(id, {
|
|
||||||
include: {
|
|
||||||
relation: 'client',
|
|
||||||
scope: {
|
|
||||||
fields: ['salesPersonFk']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}, options);
|
|
||||||
const salesPersonId = ticket.client().salesPersonFk;
|
|
||||||
const usesMana = await models.WorkerMana.findOne({
|
const usesMana = await models.WorkerMana.findOne({
|
||||||
where: {
|
where: {
|
||||||
workerFk: salesPersonId
|
workerFk: userId
|
||||||
},
|
},
|
||||||
fields: 'amount'}, options);
|
fields: 'amount'}, options);
|
||||||
|
|
||||||
|
@ -115,10 +106,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
if (salesPersonId) {
|
|
||||||
const query = `call vn.manaSpellersRequery(?)`;
|
const query = `call vn.manaSpellersRequery(?)`;
|
||||||
await Self.rawSql(query, [salesPersonId], options);
|
await Self.rawSql(query, [userId], options);
|
||||||
}
|
|
||||||
|
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in New Issue