Merge branch 'dev' into 8069-Overstocking
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
b53f6d4008
|
@ -59,7 +59,7 @@ BEGIN
|
|||
DELETE b FROM buy b
|
||||
JOIN entryConfig e ON e.defaultEntry = b.entryFk
|
||||
WHERE b.created < v2Months;
|
||||
DELETE FROM stockBuyed WHERE creationDate < v2Months;
|
||||
DELETE FROM stockBought WHERE dated < v2Months;
|
||||
DELETE FROM printQueue WHERE statusCode = 'printed' AND created < v2Months;
|
||||
-- Equipos duplicados
|
||||
DELETE w.*
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyedByWorker`(
|
||||
vDated DATE,
|
||||
vWorker INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Inserta el volumen de compra de un comprador
|
||||
* en stockBuyed de acuerdo con la fecha.
|
||||
*
|
||||
* @param vDated Fecha de compra
|
||||
* @param vWorker Id de trabajador
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tStockBuyed
|
||||
(INDEX (userFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT requested, reserved, userFk
|
||||
FROM stockBuyed
|
||||
WHERE dated = vDated
|
||||
AND userFk = vWorker;
|
||||
|
||||
DELETE FROM stockBuyed
|
||||
WHERE dated = vDated
|
||||
AND userFk = vWorker;
|
||||
|
||||
CALL item_calculateStock(vDated);
|
||||
|
||||
INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description)
|
||||
SELECT it.workerFk,
|
||||
SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000,
|
||||
vDated,
|
||||
sb.reserved,
|
||||
sb.requested,
|
||||
u.name
|
||||
FROM itemType it
|
||||
JOIN item i ON i.typeFk = it.id
|
||||
LEFT JOIN tmp.item ti ON ti.itemFk = i.id
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
JOIN warehouse wh ON wh.code = 'VNH'
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
|
||||
AND bu.warehouseFk = wh.id
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
JOIN volumeConfig vc
|
||||
JOIN account.`user` u ON u.id = it.workerFk
|
||||
LEFT JOIN tStockBuyed sb ON sb.userFk = it.workerFk
|
||||
WHERE ic.display
|
||||
AND it.workerFk = vWorker;
|
||||
|
||||
SELECT b.entryFk Id_Entrada,
|
||||
i.id Id_Article,
|
||||
i.name Article,
|
||||
ti.quantity Cantidad,
|
||||
(ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id))
|
||||
/ (vc.trolleyM3 * 1000000) buyed,
|
||||
b.packagingFk id_cubo,
|
||||
b.packing
|
||||
FROM tmp.item ti
|
||||
JOIN item i ON i.id = ti.itemFk
|
||||
JOIN itemType it ON i.typeFk = it.id
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
JOIN worker w ON w.id = it.workerFk
|
||||
JOIN auctionConfig ac
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
|
||||
AND bu.warehouseFk = ac.warehouseFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
JOIN volumeConfig vc
|
||||
WHERE ic.display
|
||||
AND w.id = vWorker;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate,
|
||||
tmp.item,
|
||||
tStockBuyed;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,70 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyed_add`(
|
||||
vDated DATE
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Inserta el volumen de compra por comprador
|
||||
* en stockBuyed de acuerdo con la fecha.
|
||||
*
|
||||
* @param vDated Fecha de compra
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tStockBuyed
|
||||
(INDEX (userFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT requested, reserved, userFk
|
||||
FROM stockBuyed
|
||||
WHERE dated = vDated;
|
||||
|
||||
DELETE FROM stockBuyed WHERE dated = vDated;
|
||||
|
||||
CALL item_calculateStock(vDated);
|
||||
|
||||
INSERT INTO stockBuyed(userFk, buyed, `dated`, description)
|
||||
SELECT it.workerFk,
|
||||
SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000,
|
||||
vDated,
|
||||
u.name
|
||||
FROM itemType it
|
||||
JOIN item i ON i.typeFk = it.id
|
||||
LEFT JOIN tmp.item ti ON ti.itemFk = i.id
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
JOIN warehouse wh ON wh.code = 'VNH'
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id AND bu.warehouseFk = wh.id
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
JOIN volumeConfig vc
|
||||
JOIN account.`user` u ON u.id = it.workerFk
|
||||
JOIN workerDepartment wd ON wd.workerFk = u.id
|
||||
JOIN department d ON d.id = wd.departmentFk
|
||||
WHERE ic.display
|
||||
AND d.code IN ('shopping', 'logistic', 'franceTeam')
|
||||
GROUP BY it.workerFk;
|
||||
|
||||
INSERT INTO stockBuyed(buyed, dated, description)
|
||||
SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000),
|
||||
vDated,
|
||||
IF(c.code = 'ES', p.name, c.name) destiny
|
||||
FROM itemTicketOut ito
|
||||
JOIN ticket t ON t.id = ito.ticketFk
|
||||
JOIN `address` a ON a.id = t.addressFk
|
||||
JOIN province p ON p.id = a.provinceFk
|
||||
JOIN country c ON c.id = p.countryFk
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk
|
||||
JOIN itemCost ic ON ic.itemFk = ito.itemFk
|
||||
AND ic.warehouseFk = t.warehouseFk
|
||||
JOIN volumeConfig vc
|
||||
WHERE ito.shipped BETWEEN vDated AND util.dayend(vDated)
|
||||
AND wh.code = 'VNH'
|
||||
GROUP BY destiny;
|
||||
|
||||
UPDATE stockBuyed s
|
||||
JOIN tStockBuyed ts ON ts.userFk = s.userFk
|
||||
SET s.requested = ts.requested,
|
||||
s.reserved = ts.reserved
|
||||
WHERE s.dated = vDated;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate,
|
||||
tmp.item,
|
||||
tStockBuyed;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,4 @@
|
|||
-- Place your SQL code here
|
||||
RENAME TABLE vn.stockBuyed TO vn.stockBuyed__;
|
||||
ALTER TABLE vn.stockBuyed__
|
||||
COMMENT='@deprecated 2024-10-01 rename and refactor to stockBought';
|
|
@ -106,10 +106,15 @@ module.exports = Self => {
|
|||
description: `The to shipped date filter`
|
||||
},
|
||||
{
|
||||
arg: 'days',
|
||||
arg: 'daysOnward',
|
||||
type: 'number',
|
||||
description: `N days interval`
|
||||
},
|
||||
{
|
||||
arg: 'daysAgo',
|
||||
type: 'number',
|
||||
description: `N days ago interval`
|
||||
},
|
||||
{
|
||||
arg: 'invoiceAmount',
|
||||
type: 'number',
|
||||
|
@ -216,16 +221,29 @@ module.exports = Self => {
|
|||
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
||||
);
|
||||
|
||||
if (ctx.args.days) {
|
||||
stmt.merge({
|
||||
sql: `
|
||||
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
||||
AND t.shipped >= util.VN_CURDATE()
|
||||
`,
|
||||
params: [ctx.args.days]
|
||||
});
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
|
||||
const {daysAgo, daysOnward} = ctx.args;
|
||||
if (daysOnward || daysAgo) {
|
||||
const params = [];
|
||||
let today = 'util.VN_CURDATE()';
|
||||
let from = today;
|
||||
let to = today;
|
||||
|
||||
if (daysAgo) {
|
||||
from += ' - INTERVAL ? DAY';
|
||||
params.push(daysAgo);
|
||||
}
|
||||
if (daysOnward) {
|
||||
to += ' + INTERVAL ? DAY';
|
||||
params.push(daysOnward);
|
||||
}
|
||||
|
||||
const whereDays = (filter.where ? 'AND' : 'WHERE') + ` t.shipped BETWEEN ${from} AND ${to}`;
|
||||
stmt.merge({sql: whereDays, params});
|
||||
}
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
const itemsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
|
|
@ -49,13 +49,13 @@ describe('Entry filter()', () => {
|
|||
});
|
||||
|
||||
describe('should return the entry matching the supplier', () => {
|
||||
it('when userId is supplier ', async() => {
|
||||
it('when userId is supplier and searching days onward', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const ctx = {
|
||||
args: {days: 6},
|
||||
args: {daysOnward: 6},
|
||||
req: {accessToken: {userId: 1102}}
|
||||
};
|
||||
|
||||
|
@ -70,6 +70,27 @@ describe('Entry filter()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('when userId is supplier and searching days ago', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const ctx = {
|
||||
args: {daysAgo: 31},
|
||||
req: {accessToken: {userId: 1102}}
|
||||
};
|
||||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(6);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('when userId is supplier fetching other supplier', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
|
|
@ -142,12 +142,19 @@ module.exports = Self => {
|
|||
ctx.args.addressId = ticket.addressFk;
|
||||
|
||||
const newTicket = await models.Ticket.new(ctx, myOptions);
|
||||
|
||||
await models.TicketRefund.create({
|
||||
originalTicketFk: ticketId,
|
||||
refundTicketFk: newTicket.id
|
||||
}, myOptions);
|
||||
|
||||
const existingRefund = await models.TicketRefund.findOne({
|
||||
where: {
|
||||
originalTicketFk: ticketId,
|
||||
refundTicketFk: newTicket.id
|
||||
},
|
||||
myOptions
|
||||
});
|
||||
if (!existingRefund) {
|
||||
await models.TicketRefund.create({
|
||||
originalTicketFk: ticketId,
|
||||
refundTicketFk: newTicket.id
|
||||
}, myOptions);
|
||||
}
|
||||
return newTicket;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue