chore: refs #7323 worker changes wip #2930

Merged
jorgep merged 5 commits from 7323-dynamicRole into dev 2024-09-06 12:03:21 +00:00
16 changed files with 233 additions and 56 deletions
Showing only changes of commit b277ae2d92 - Show all commits

View File

@ -3971,4 +3971,4 @@ VALUES
INSERT IGNORE INTO ormConfig INSERT IGNORE INTO ormConfig
SET id =1, SET id =1,
selectLimit = 1000; selectLimit = 1000;

View File

@ -1,5 +1,10 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDated` DATE) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refresh`(
OUT `vCalc` INT,
`vRefresh` INT,
`vWarehouse` INT,
`vDated` DATE
)
proc: BEGIN proc: BEGIN
DECLARE vStartDate DATE; DECLARE vStartDate DATE;
DECLARE vReserveDate DATETIME; DECLARE vReserveDate DATETIME;

View File

@ -0,0 +1,31 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_updateItem`(
`vItem` INT,
`vWarehouse` INT,
`vDated` DATE,
`vQuantity` INT
)
BEGIN
/**
* Immediately deduct/add an amount from the available cache (if exists).
*
* @param vItem The item id
* @param vWarehouse The warehouse id
* @param vDated Available cache date
* @param vQuantity The amount to be deducted from the cache
*/
DECLARE vCalc INT;
SELECT id INTO vCalc
FROM cache_calc
WHERE cacheName = 'available'
AND params = CONCAT_WS('/', vWarehouse, vDated);
IF vCalc IS NOT NULL THEN
UPDATE available
SET available = available - vQuantity
WHERE calc_id = vCalc
AND item_id = vItem;
END IF;
END$$
DELIMITER ;

View File

@ -4,7 +4,7 @@ proc: BEGIN
/** /**
* Crea o actualiza la cache con la última compra y fecha de cada * Crea o actualiza la cache con la última compra y fecha de cada
* artículo hasta ayer. Para obtener la última compra hasta una fecha * artículo hasta ayer. Para obtener la última compra hasta una fecha
* determinada utilizar el procedimiento vn.buyUltimate(). * determinada utilizar el procedimiento vn.buy_getUltimate().
* *
* @param vRefresh %TRUE para forzar el recálculo de la cache * @param vRefresh %TRUE para forzar el recálculo de la cache
*/ */

View File

@ -1,8 +1,8 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_addItem`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_addItem`(
vSelf INT, vSelf INT,
vWarehouse INT, vWarehouse INT,
vItem INT, vItem INT,
vAmount INT) vAmount INT)
BEGIN BEGIN
/** /**
@ -37,7 +37,7 @@ BEGIN
ROLLBACK; ROLLBACK;
RESIGNAL; RESIGNAL;
END; END;
CALL order_calcCatalogFromItem(vSelf, vItem); CALL order_calcCatalogFromItem(vSelf, vItem);
START TRANSACTION; START TRANSACTION;
@ -102,6 +102,8 @@ BEGIN
amount = vAdd, amount = vAdd,
price = vPrice; price = vPrice;
CALL cache.available_updateItem(vItem, vWarehouse, vShipment, vAdd);
SET vRow = LAST_INSERT_ID(); SET vRow = LAST_INSERT_ID();
INSERT INTO orderRowComponent (rowFk, componentFk, price) INSERT INTO orderRowComponent (rowFk, componentFk, price)
@ -121,6 +123,6 @@ BEGIN
END IF; END IF;
COMMIT; COMMIT;
CALL vn.ticketCalculatePurge; CALL vn.ticketCalculatePurge;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,18 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buyUltimate`(
vWarehouseFk SMALLINT,
vDated DATE
)
BEGIN
/**
* @deprecated Usar buy_getUltimate
* Calcula las últimas compras realizadas hasta una fecha.
*
* @param vItemFk Id del artículo
* @param vWarehouseFk Id del almacén
* @param vDated Compras hasta fecha
* @return tmp.buyUltimate
*/
CALL buy_getUltimate(NULL, vWarehouseFk, vDated);
END$$
DELIMITER ;

View File

@ -1,20 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(
vWarehouseFk SMALLINT,
vStarted DATE,
vEnded DATE
)
BEGIN
/**
* @deprecated Usar buy_getUltimateFromInterval
* Calcula las últimas compras realizadas
* desde un rango de fechas.
*
* @param vWarehouseFk Id del almacén si es NULL se actualizan todos
* @param vStarted Fecha inicial
* @param vEnded Fecha fin
* @return tmp.buyUltimateFromInterval
*/
CALL vn.buy_getUltimateFromInterval(NULL, vWarehouseFk, vStarted, vEnded);
END$$
DELIMITER ;

View File

@ -17,6 +17,7 @@ BEGIN
DECLARE vHasDailyInvoice BOOL; DECLARE vHasDailyInvoice BOOL;
DECLARE vWithPackage BOOL; DECLARE vWithPackage BOOL;
DECLARE vHasToInvoice BOOL; DECLARE vHasToInvoice BOOL;
DECLARE vSerial VARCHAR(2);
DECLARE cur CURSOR FOR DECLARE cur CURSOR FOR
SELECT ticketFk FROM tmp.ticket_close; SELECT ticketFk FROM tmp.ticket_close;
@ -83,14 +84,17 @@ BEGIN
GROUP BY e.freightItemFk); GROUP BY e.freightItemFk);
IF(vHasDailyInvoice) AND vHasToInvoice THEN IF(vHasDailyInvoice) AND vHasToInvoice THEN
SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial;
IF NOT vSerial THEN
CALL util.throw('Cannot booking without a serial');
END IF;
-- Facturacion rapida
CALL ticket_setState(vCurTicketFk, 'DELIVERED'); CALL ticket_setState(vCurTicketFk, 'DELIVERED');
-- Facturar si está contabilizado
IF vIsTaxDataChecked THEN IF vIsTaxDataChecked THEN
CALL invoiceOut_newFromClient( CALL invoiceOut_newFromClient(
vClientFk, vClientFk,
(SELECT invoiceSerial(vClientFk, vCompanyFk, 'multiple')), vSerial,
vShipped, vShipped,
vCompanyFk, vCompanyFk,
NULL, NULL,

View File

@ -0,0 +1 @@
ALTER TABLE vn.parking ADD COLUMN floor VARCHAR(5) DEFAULT NULL AFTER row;

View File

@ -0,0 +1,129 @@
use vn;
CREATE TABLE IF NOT EXISTS `material` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
INSERT IGNORE INTO `material` (`name`) VALUES ('Abedul');
INSERT IGNORE INTO `material` (`name`) VALUES ('Acacia');
INSERT IGNORE INTO `material` (`name`) VALUES ('Acero');
INSERT IGNORE INTO `material` (`name`) VALUES ('Acero Galvanizado');
INSERT IGNORE INTO `material` (`name`) VALUES ('Acetato');
INSERT IGNORE INTO `material` (`name`) VALUES ('Acrílico');
INSERT IGNORE INTO `material` (`name`) VALUES ('Alambre');
INSERT IGNORE INTO `material` (`name`) VALUES ('Algodón');
INSERT IGNORE INTO `material` (`name`) VALUES ('Aluminio');
INSERT IGNORE INTO `material` (`name`) VALUES ('Antracita');
INSERT IGNORE INTO `material` (`name`) VALUES ('Arcilla');
INSERT IGNORE INTO `material` (`name`) VALUES ('Bambú');
INSERT IGNORE INTO `material` (`name`) VALUES ('Banano');
INSERT IGNORE INTO `material` (`name`) VALUES ('Canneté');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cartón');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cartulina');
INSERT IGNORE INTO `material` (`name`) VALUES ('Celofán');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cemento');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cera');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cerámica');
INSERT IGNORE INTO `material` (`name`) VALUES ('Chapa');
INSERT IGNORE INTO `material` (`name`) VALUES ('Chenilla');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cloruro de polivinilo');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cobre');
INSERT IGNORE INTO `material` (`name`) VALUES ('Corcho');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cordel');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cotton');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cotton Chess');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cristal');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cubo Asa');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cuerda');
INSERT IGNORE INTO `material` (`name`) VALUES ('Cuero');
INSERT IGNORE INTO `material` (`name`) VALUES ('Doble Raso');
INSERT IGNORE INTO `material` (`name`) VALUES ('Doble Velvet');
INSERT IGNORE INTO `material` (`name`) VALUES ('Eco Glass');
INSERT IGNORE INTO `material` (`name`) VALUES ('Encaje');
INSERT IGNORE INTO `material` (`name`) VALUES ('Esparto');
INSERT IGNORE INTO `material` (`name`) VALUES ('Espuma');
INSERT IGNORE INTO `material` (`name`) VALUES ('Felpa');
INSERT IGNORE INTO `material` (`name`) VALUES ('Fibra');
INSERT IGNORE INTO `material` (`name`) VALUES ('Fibra de Coco');
INSERT IGNORE INTO `material` (`name`) VALUES ('Fibra de Vidrio y Resina');
INSERT IGNORE INTO `material` (`name`) VALUES ('Fieltro');
INSERT IGNORE INTO `material` (`name`) VALUES ('Foam');
INSERT IGNORE INTO `material` (`name`) VALUES ('Gamuza');
INSERT IGNORE INTO `material` (`name`) VALUES ('Gasa');
INSERT IGNORE INTO `material` (`name`) VALUES ('Glass');
INSERT IGNORE INTO `material` (`name`) VALUES ('Goma');
INSERT IGNORE INTO `material` (`name`) VALUES ('Grafito');
INSERT IGNORE INTO `material` (`name`) VALUES ('Hierro');
INSERT IGNORE INTO `material` (`name`) VALUES ('Hoja Carbono');
INSERT IGNORE INTO `material` (`name`) VALUES ('Hoja de Mirto');
INSERT IGNORE INTO `material` (`name`) VALUES ('Hormigón');
INSERT IGNORE INTO `material` (`name`) VALUES ('Jute');
INSERT IGNORE INTO `material` (`name`) VALUES ('Kraft');
INSERT IGNORE INTO `material` (`name`) VALUES ('Lana');
INSERT IGNORE INTO `material` (`name`) VALUES ('Látex');
INSERT IGNORE INTO `material` (`name`) VALUES ('Latrix');
INSERT IGNORE INTO `material` (`name`) VALUES ('Lienzo');
INSERT IGNORE INTO `material` (`name`) VALUES ('Lino');
INSERT IGNORE INTO `material` (`name`) VALUES ('Lurex');
INSERT IGNORE INTO `material` (`name`) VALUES ('Madera');
INSERT IGNORE INTO `material` (`name`) VALUES ('Metacrilato');
INSERT IGNORE INTO `material` (`name`) VALUES ('Metal');
INSERT IGNORE INTO `material` (`name`) VALUES ('Mimbre');
INSERT IGNORE INTO `material` (`name`) VALUES ('Musgo');
INSERT IGNORE INTO `material` (`name`) VALUES ('Nonwoven');
INSERT IGNORE INTO `material` (`name`) VALUES ('Nylon');
INSERT IGNORE INTO `material` (`name`) VALUES ('Organza');
INSERT IGNORE INTO `material` (`name`) VALUES ('Paja');
INSERT IGNORE INTO `material` (`name`) VALUES ('Pana');
INSERT IGNORE INTO `material` (`name`) VALUES ('Papel');
INSERT IGNORE INTO `material` (`name`) VALUES ('Paperweb');
INSERT IGNORE INTO `material` (`name`) VALUES ('Paulownia');
INSERT IGNORE INTO `material` (`name`) VALUES ('Peluche');
INSERT IGNORE INTO `material` (`name`) VALUES ('Piedra');
INSERT IGNORE INTO `material` (`name`) VALUES ('Pizarra');
INSERT IGNORE INTO `material` (`name`) VALUES ('Plástico');
INSERT IGNORE INTO `material` (`name`) VALUES ('Poliestireno');
INSERT IGNORE INTO `material` (`name`) VALUES ('Polipropileno');
INSERT IGNORE INTO `material` (`name`) VALUES ('Poliresina');
INSERT IGNORE INTO `material` (`name`) VALUES ('Polyester');
INSERT IGNORE INTO `material` (`name`) VALUES ('Porcelana');
INSERT IGNORE INTO `material` (`name`) VALUES ('Puntilla');
INSERT IGNORE INTO `material` (`name`) VALUES ('PVC');
INSERT IGNORE INTO `material` (`name`) VALUES ('Rafia');
INSERT IGNORE INTO `material` (`name`) VALUES ('Rama');
INSERT IGNORE INTO `material` (`name`) VALUES ('Raso');
INSERT IGNORE INTO `material` (`name`) VALUES ('Rattan');
INSERT IGNORE INTO `material` (`name`) VALUES ('Rayon');
INSERT IGNORE INTO `material` (`name`) VALUES ('Reciclable');
INSERT IGNORE INTO `material` (`name`) VALUES ('Red');
INSERT IGNORE INTO `material` (`name`) VALUES ('Resina');
INSERT IGNORE INTO `material` (`name`) VALUES ('Roca');
INSERT IGNORE INTO `material` (`name`) VALUES ('Rope');
INSERT IGNORE INTO `material` (`name`) VALUES ('Saco');
INSERT IGNORE INTO `material` (`name`) VALUES ('Salim');
INSERT IGNORE INTO `material` (`name`) VALUES ('Seagrass');
INSERT IGNORE INTO `material` (`name`) VALUES ('Silicona');
INSERT IGNORE INTO `material` (`name`) VALUES ('Sisal');
INSERT IGNORE INTO `material` (`name`) VALUES ('Tejido');
INSERT IGNORE INTO `material` (`name`) VALUES ('Tela');
INSERT IGNORE INTO `material` (`name`) VALUES ('Terciopelo');
INSERT IGNORE INTO `material` (`name`) VALUES ('Terracota');
INSERT IGNORE INTO `material` (`name`) VALUES ('Textil');
INSERT IGNORE INTO `material` (`name`) VALUES ('Titanio');
INSERT IGNORE INTO `material` (`name`) VALUES ('Tul');
INSERT IGNORE INTO `material` (`name`) VALUES ('Velvet');
INSERT IGNORE INTO `material` (`name`) VALUES ('Vidrio');
INSERT IGNORE INTO `material` (`name`) VALUES ('Yute');
INSERT IGNORE INTO `material` (`name`) VALUES ('Zinc');
INSERT IGNORE INTO `material` (`name`) VALUES ('Base de goma');
INSERT IGNORE INTO `material` (`name`) VALUES ('Base de madera');
INSERT IGNORE INTO `material` (`name`) VALUES ('Plumas');
INSERT IGNORE INTO `material` (`name`) VALUES ('Protección Uva');
INSERT IGNORE INTO `material` (`name`) VALUES ('Purpurina');
UPDATE vn.tag SET isFree=0,sourceTable='material' WHERE name= 'Material';
UPDATE vn.tag SET isFree=0,sourceTable='material' WHERE name='Material secundario';

View File

@ -1,4 +1,3 @@
/** /**
* Flattens an array of objects by converting each object into a flat structure. * Flattens an array of objects by converting each object into a flat structure.
* *

View File

@ -23,6 +23,7 @@ class Controller extends Dialog {
} }
set clientFk(value) { set clientFk(value) {
if (!value) return;
this.receipt.clientFk = value; this.receipt.clientFk = value;
const filter = { const filter = {
@ -32,6 +33,7 @@ class Controller extends Dialog {
} }
}; };
this.getAmountPaid();
this.$http.get(`Clients/findOne`, {filter}) this.$http.get(`Clients/findOne`, {filter})
.then(res => { .then(res => {
this.receipt.email = res.data.email; this.receipt.email = res.data.email;
@ -50,7 +52,6 @@ class Controller extends Dialog {
set companyFk(value) { set companyFk(value) {
this.receipt.companyFk = value; this.receipt.companyFk = value;
this.getAmountPaid();
} }
set description(value) { set description(value) {
@ -152,7 +153,7 @@ class Controller extends Dialog {
getAmountPaid() { getAmountPaid() {
const filter = { const filter = {
where: { where: {
clientFk: this.$params.id, clientFk: this.$params.id ?? this.clientFk,
companyFk: this.receipt.companyFk companyFk: this.receipt.companyFk
} }
}; };
@ -210,8 +211,8 @@ ngModule.vnComponent('vnClientBalanceCreate', {
payed: '<?', payed: '<?',
bankFk: '<?', bankFk: '<?',
amountPaid: '<?', amountPaid: '<?',
clientFk: '<?',
companyFk: '<?', companyFk: '<?',
description: '<?', description: '<?',
clientFk: '<?'
} }
}); });

View File

@ -9,6 +9,11 @@ module.exports = Self => {
required: true, required: true,
description: 'Issued invoice id' description: 'Issued invoice id'
}, },
{
arg: 'withWarehouse',
type: 'boolean',
required: true
},
{ {
arg: 'cplusRectificationTypeFk', arg: 'cplusRectificationTypeFk',
type: 'number', type: 'number',
@ -38,6 +43,7 @@ module.exports = Self => {
Self.refundAndInvoice = async( Self.refundAndInvoice = async(
ctx, ctx,
id, id,
withWarehouse,
cplusRectificationTypeFk, cplusRectificationTypeFk,
siiTypeInvoiceOutFk, siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk, invoiceCorrectionTypeFk,
@ -59,7 +65,7 @@ module.exports = Self => {
try { try {
const originalInvoice = await models.InvoiceOut.findById(id, myOptions); const originalInvoice = await models.InvoiceOut.findById(id, myOptions);
const refundedTickets = await Self.refund(ctx, originalInvoice.ref, false, myOptions); const refundedTickets = await Self.refund(ctx, originalInvoice.ref, withWarehouse, myOptions);
const invoiceCorrection = { const invoiceCorrection = {
correctedFk: id, correctedFk: id,

View File

@ -14,14 +14,16 @@ describe('InvoiceOut refundAndInvoice()', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx});
}); });
it('should refund an invoice and create a new invoice', async() => { it('should refund an invoice and create a new invoice with warehouse', async() => {
const tx = await models.InvoiceOut.beginTransaction({}); const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
const withWarehouse = true;
try { try {
const result = await models.InvoiceOut.refundAndInvoice( const result = await models.InvoiceOut.refundAndInvoice(
ctx, ctx,
id, id,
withWarehouse,
cplusRectificationTypeFk, cplusRectificationTypeFk,
siiTypeInvoiceOutFk, siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk, invoiceCorrectionTypeFk,
@ -32,7 +34,40 @@ describe('InvoiceOut refundAndInvoice()', () => {
expect(result.refundId).toBeDefined(); expect(result.refundId).toBeDefined();
const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options); const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options);
const ticketsAfter = await models.Ticket.find({where: {refFk: 'R10100001'}}, options); const ticketsAfter = await models.Ticket.find(
{where: {refFk: 'R10100001', warehouse: {neq: null}}}, options);
expect(invoicesAfter.length).toBeGreaterThan(0);
expect(ticketsAfter.length).toBeGreaterThan(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should refund an invoice and create a new invoice with warehouse null', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
const withWarehouse = false;
try {
const result = await models.InvoiceOut.refundAndInvoice(
ctx,
id,
withWarehouse,
cplusRectificationTypeFk,
siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk,
options
);
expect(result).toBeDefined();
expect(result.refundId).toBeDefined();
const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options);
const ticketsAfter = await models.Ticket.find({where: {refFk: 'R10100001', warehouse: null}}, options);
expect(invoicesAfter.length).toBeGreaterThan(0); expect(invoicesAfter.length).toBeGreaterThan(0);
expect(ticketsAfter.length).toBeGreaterThan(0); expect(ticketsAfter.length).toBeGreaterThan(0);

View File

@ -75,6 +75,7 @@ module.exports = Self => {
await Self.refundAndInvoice( await Self.refundAndInvoice(
ctx, ctx,
id, id,
false,
cplusRectificationTypeFk, cplusRectificationTypeFk,
siiTypeInvoiceOutFk, siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk, invoiceCorrectionTypeFk,

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('item getVisibleAvailable()', () => { describe('item getVisibleAvailable()', () => {
it('should check available visible for today', async() => { it('should check available visible for tomorrow', async() => {
const tx = await models.Item.beginTransaction({}); const tx = await models.Item.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
@ -9,6 +9,7 @@ describe('item getVisibleAvailable()', () => {
const itemFk = 1; const itemFk = 1;
const warehouseFk = 1; const warehouseFk = 1;
const dated = Date.vnNew(); const dated = Date.vnNew();
dated.setDate(dated.getDate() + 1);
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options); const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);