8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
15 changed files with 286 additions and 19 deletions
Showing only changes of commit c43c61991d - Show all commits

View File

@ -108,6 +108,7 @@ INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`)
UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20;
UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9;
UPDATE `vn`.`worker` SET bossFk = 19 WHERE id = 18;
UPDATE `vn`.`worker` SET bossFk = 50 WHERE id = 49;
DELETE FROM `vn`.`worker` WHERE firstName ='customer';
@ -3970,4 +3971,4 @@ VALUES
INSERT IGNORE INTO ormConfig
SET id =1,
selectLimit = 1000;
selectLimit = 1000;

View File

@ -1,5 +1,10 @@
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
DECLARE vStartDate DATE;
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

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

View File

@ -17,6 +17,7 @@ BEGIN
DECLARE vHasDailyInvoice BOOL;
DECLARE vWithPackage BOOL;
DECLARE vHasToInvoice BOOL;
DECLARE vSerial VARCHAR(2);
DECLARE cur CURSOR FOR
SELECT ticketFk FROM tmp.ticket_close;
@ -83,14 +84,17 @@ BEGIN
GROUP BY e.freightItemFk);
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');
-- Facturar si está contabilizado
IF vIsTaxDataChecked THEN
CALL invoiceOut_newFromClient(
vClientFk,
(SELECT invoiceSerial(vClientFk, vCompanyFk, 'multiple')),
vSerial,
vShipped,
vCompanyFk,
NULL,

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

@ -0,0 +1,4 @@
-- Place your SQL code here
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('Worker', '__get__descriptor', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Worker', 'findById', 'READ', 'ALLOW', 'ROLE', '$subordinate');

View File

@ -0,0 +1,12 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = async function(app) {
const models = app.models;
models.VnRole.registerResolver('$subordinate', async(role, ctx) => {
Object.assign(ctx, {req: {accessToken: {userId: ctx.accessToken.userId}}});
const isSubordinate = await models.Worker.isSubordinate(ctx, +ctx.modelId);
if (!isSubordinate) throw new UserError(`You don't have enough privileges`);
});
};

View File

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

View File

@ -9,6 +9,11 @@ module.exports = Self => {
required: true,
description: 'Issued invoice id'
},
{
arg: 'withWarehouse',
type: 'boolean',
required: true
},
{
arg: 'cplusRectificationTypeFk',
type: 'number',
@ -38,6 +43,7 @@ module.exports = Self => {
Self.refundAndInvoice = async(
ctx,
id,
withWarehouse,
cplusRectificationTypeFk,
siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk,
@ -59,7 +65,7 @@ module.exports = Self => {
try {
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 = {
correctedFk: id,

View File

@ -14,14 +14,16 @@ describe('InvoiceOut refundAndInvoice()', () => {
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 options = {transaction: tx};
const withWarehouse = true;
try {
const result = await models.InvoiceOut.refundAndInvoice(
ctx,
id,
withWarehouse,
cplusRectificationTypeFk,
siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk,
@ -32,7 +34,40 @@ describe('InvoiceOut refundAndInvoice()', () => {
expect(result.refundId).toBeDefined();
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(ticketsAfter.length).toBeGreaterThan(0);

View File

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

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
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 options = {transaction: tx};
@ -9,6 +9,7 @@ describe('item getVisibleAvailable()', () => {
const itemFk = 1;
const warehouseFk = 1;
const dated = Date.vnNew();
dated.setDate(dated.getDate() + 1);
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);

View File

@ -140,5 +140,41 @@
"principalType": "ROLE",
"principalId": "$owner"
}
]
}
],
"scopes": {
"descriptor": {
"include": [
{
"relation": "user",
"scope": {
"fields": [
"name",
"nickname"
],
"include": {
"relation": "emailUser",
"scope": {
"fields": [
"email"
]
}
}
}
},
{
"relation": "department",
"scope": {
"include": [
{
"relation": "department"
}
]
}
},
{
"relation": "sip"
}
]
}
}
}