231801_test_to_master #1519
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2316.01] - 2023-05-04
|
||||||
|
|
||||||
|
### Added
|
||||||
|
-
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
-
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
-
|
||||||
|
|
||||||
## [2314.01] - 2023-04-20
|
## [2314.01] - 2023-04-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -12,9 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia
|
- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia
|
||||||
- (Facturas recibidas -> Bases negativas) Nueva sección
|
- (Facturas recibidas -> Bases negativas) Nueva sección
|
||||||
|
|
||||||
### Changed
|
|
||||||
-
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
|
- (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs/promises');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const uuid = require('uuid');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('upload', {
|
Self.remoteMethodCtx('upload', {
|
||||||
|
@ -36,7 +35,7 @@ module.exports = Self => {
|
||||||
const fileOptions = {};
|
const fileOptions = {};
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
||||||
let srcFile;
|
let tempFilePath;
|
||||||
try {
|
try {
|
||||||
const hasWriteRole = await models.ImageCollection.hasWriteRole(ctx, args.collection);
|
const hasWriteRole = await models.ImageCollection.hasWriteRole(ctx, args.collection);
|
||||||
if (!hasWriteRole)
|
if (!hasWriteRole)
|
||||||
|
@ -53,15 +52,20 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
||||||
srcFile = path.join(file.client.root, file.container, file.name);
|
tempFilePath = path.join(file.client.root, file.container, file.name);
|
||||||
|
|
||||||
const fileName = `${uuid.v4()}.png`;
|
const fileName = `${args.id}.png`;
|
||||||
await models.Image.registerImage(args.collection, srcFile, fileName, args.id);
|
|
||||||
} catch (e) {
|
|
||||||
if (fs.existsSync(srcFile))
|
|
||||||
await fs.unlink(srcFile);
|
|
||||||
|
|
||||||
throw e;
|
await models.Image.resize({
|
||||||
|
collectionName: args.collection,
|
||||||
|
srcFile: tempFilePath,
|
||||||
|
fileName: fileName,
|
||||||
|
entityId: args.id
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await fs.unlink(tempFilePath);
|
||||||
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,161 +1,110 @@
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const sharp = require('sharp');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const readChunk = require('read-chunk');
|
const gm = require('gm');
|
||||||
const imageType = require('image-type');
|
|
||||||
const bmp = require('bmp-js');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/image/download')(Self);
|
require('../methods/image/download')(Self);
|
||||||
require('../methods/image/upload')(Self);
|
require('../methods/image/upload')(Self);
|
||||||
|
|
||||||
// Function extracted from jimp package (utils)
|
Self.resize = async function({collectionName, srcFile, fileName, entityId}) {
|
||||||
function scan(image, x, y, w, h, f) {
|
|
||||||
// round input
|
|
||||||
x = Math.round(x);
|
|
||||||
y = Math.round(y);
|
|
||||||
w = Math.round(w);
|
|
||||||
h = Math.round(h);
|
|
||||||
|
|
||||||
for (let _y = y; _y < y + h; _y++) {
|
|
||||||
for (let _x = x; _x < x + w; _x++) {
|
|
||||||
const idx = (image.bitmap.width * _y + _x) << 2;
|
|
||||||
f.call(image, _x, _y, idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function extracted from jimp package (type-bmp)
|
|
||||||
function fromAGBR(bitmap) {
|
|
||||||
return scan({bitmap}, 0, 0, bitmap.width, bitmap.height, function(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
index
|
|
||||||
) {
|
|
||||||
const alpha = this.bitmap.data[index + 0];
|
|
||||||
const blue = this.bitmap.data[index + 1];
|
|
||||||
const green = this.bitmap.data[index + 2];
|
|
||||||
const red = this.bitmap.data[index + 3];
|
|
||||||
|
|
||||||
this.bitmap.data[index + 0] = red;
|
|
||||||
this.bitmap.data[index + 1] = green;
|
|
||||||
this.bitmap.data[index + 2] = blue;
|
|
||||||
this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;
|
|
||||||
}).bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
Self.registerImage = async(collectionName, srcFilePath, fileName, entityId) => {
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
const myOptions = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
const collection = await models.ImageCollection.findOne(
|
||||||
const collection = await models.ImageCollection.findOne({
|
{
|
||||||
fields: [
|
fields: [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
|
||||||
'maxWidth',
|
'maxWidth',
|
||||||
'maxHeight',
|
'maxHeight',
|
||||||
'model',
|
'model',
|
||||||
'property'
|
'property',
|
||||||
],
|
],
|
||||||
where: {name: collectionName},
|
where: {name: collectionName},
|
||||||
include: {
|
include: {
|
||||||
relation: 'sizes',
|
relation: 'sizes',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['width', 'height', 'crop']
|
fields: ['width', 'height', 'crop'],
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const data = {
|
// Insert image row
|
||||||
|
await models.Image.upsertWithWhere(
|
||||||
|
{
|
||||||
name: fileName,
|
name: fileName,
|
||||||
collectionFk: collectionName
|
collectionFk: collectionName
|
||||||
};
|
},
|
||||||
const newImage = await Self.upsertWithWhere(data, {
|
{
|
||||||
name: fileName,
|
name: fileName,
|
||||||
collectionFk: collectionName,
|
collectionFk: collectionName,
|
||||||
updated: Date.vnNow()
|
updated: Date.vnNow() / 1000,
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
// Resizes and saves the image
|
|
||||||
const container = await models.ImageContainer.container(collectionName);
|
|
||||||
const rootPath = container.client.root;
|
|
||||||
const collectionDir = path.join(rootPath, collectionName);
|
|
||||||
const dstDir = path.join(collectionDir, 'full');
|
|
||||||
const dstFile = path.join(dstDir, fileName);
|
|
||||||
|
|
||||||
const buffer = readChunk.sync(srcFilePath, 0, 12);
|
|
||||||
const type = imageType(buffer);
|
|
||||||
|
|
||||||
let sharpOptions;
|
|
||||||
let imgSrc = srcFilePath;
|
|
||||||
if (type.mime == 'image/bmp') {
|
|
||||||
const bmpBuffer = fs.readFileSync(srcFilePath);
|
|
||||||
const bmpData = fromAGBR(bmp.decode(bmpBuffer));
|
|
||||||
imgSrc = bmpData.data;
|
|
||||||
sharpOptions = {
|
|
||||||
raw: {
|
|
||||||
width: bmpData.width,
|
|
||||||
height: bmpData.height,
|
|
||||||
channels: 4
|
|
||||||
},
|
|
||||||
failOn: 'none'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const resizeOpts = {
|
|
||||||
withoutEnlargement: true,
|
|
||||||
fit: 'inside'
|
|
||||||
};
|
|
||||||
|
|
||||||
await fs.mkdir(dstDir, {recursive: true});
|
|
||||||
await sharp(imgSrc, sharpOptions)
|
|
||||||
.resize(collection.maxWidth, collection.maxHeight, resizeOpts)
|
|
||||||
.png()
|
|
||||||
.toFile(dstFile);
|
|
||||||
|
|
||||||
const sizes = collection.sizes();
|
|
||||||
for (let size of sizes) {
|
|
||||||
const dstDir = path.join(collectionDir, `${size.width}x${size.height}`);
|
|
||||||
const dstFile = path.join(dstDir, fileName);
|
|
||||||
const resizeOpts = {
|
|
||||||
withoutEnlargement: true,
|
|
||||||
fit: size.crop ? 'cover' : 'inside'
|
|
||||||
};
|
|
||||||
|
|
||||||
await fs.mkdir(dstDir, {recursive: true});
|
|
||||||
await sharp(imgSrc, sharpOptions)
|
|
||||||
.resize(size.width, size.height, resizeOpts)
|
|
||||||
.png()
|
|
||||||
.toFile(dstFile);
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update entity image file name
|
||||||
const model = models[collection.model];
|
const model = models[collection.model];
|
||||||
|
if (!model) throw new Error('No matching model found');
|
||||||
|
|
||||||
if (!model)
|
const entity = await model.findById(entityId);
|
||||||
throw new Error('Matching model not found');
|
if (entity) {
|
||||||
|
await entity.updateAttribute(
|
||||||
const item = await model.findById(entityId, null, myOptions);
|
|
||||||
if (item) {
|
|
||||||
await item.updateAttribute(
|
|
||||||
collection.property,
|
collection.property,
|
||||||
fileName,
|
fileName
|
||||||
myOptions
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.existsSync(srcFilePath))
|
// Resize
|
||||||
await fs.unlink(srcFilePath);
|
const container = await models.ImageContainer.container(
|
||||||
|
collectionName
|
||||||
|
);
|
||||||
|
const rootPath = container.client.root;
|
||||||
|
const collectionDir = path.join(rootPath, collectionName);
|
||||||
|
|
||||||
await tx.commit();
|
// To max size
|
||||||
|
const {maxWidth, maxHeight} = collection;
|
||||||
|
const fullSizePath = path.join(collectionDir, 'full');
|
||||||
|
const toFullSizePath = `${fullSizePath}/${fileName}`;
|
||||||
|
|
||||||
return newImage;
|
await fs.mkdir(fullSizePath, {recursive: true});
|
||||||
} catch (e) {
|
await new Promise((resolve, reject) => {
|
||||||
await tx.rollback();
|
gm(srcFile)
|
||||||
throw e;
|
.resize(maxWidth, maxHeight, '>')
|
||||||
|
.setFormat('png')
|
||||||
|
.quality(100)
|
||||||
|
.write(toFullSizePath, function(err) {
|
||||||
|
if (err) reject(err);
|
||||||
|
if (!err) resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// To collection sizes
|
||||||
|
for (const size of collection.sizes()) {
|
||||||
|
const {width, height} = size;
|
||||||
|
|
||||||
|
const sizePath = path.join(collectionDir, `${width}x${height}`);
|
||||||
|
const toSizePath = `${sizePath}/${fileName}`;
|
||||||
|
|
||||||
|
await fs.mkdir(sizePath, {recursive: true});
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const gmInstance = gm(srcFile);
|
||||||
|
|
||||||
|
if (size.crop) {
|
||||||
|
gmInstance
|
||||||
|
.resize(width, height, '^')
|
||||||
|
.gravity('Center')
|
||||||
|
.crop(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!size.crop) gmInstance.resize(width, height, '>');
|
||||||
|
|
||||||
|
gmInstance
|
||||||
|
.setFormat('png')
|
||||||
|
.quality(100)
|
||||||
|
.write(toSizePath, function(err) {
|
||||||
|
if (err) reject(err);
|
||||||
|
if (!err) resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE `vn`.`ticketConfig` ADD daysForWarningClaim INT DEFAULT 2 NOT NULL COMMENT 'dias restantes hasta que salte el aviso de reclamación fuerade plazo';
|
|
@ -0,0 +1,74 @@
|
||||||
|
DROP TABLE `vn`.`dmsRecover`;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK;
|
||||||
|
ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk;
|
||||||
|
ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL;
|
||||||
|
ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`);
|
||||||
|
|
||||||
|
DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign';
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`)
|
||||||
|
VALUES
|
||||||
|
('Ticket','saveSign','WRITE','ALLOW','employee');
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS vn.route_getTickets;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Pasado un RouteFk devuelve la información
|
||||||
|
* de sus tickets.
|
||||||
|
*
|
||||||
|
* @param vRouteFk
|
||||||
|
*
|
||||||
|
* @select Información de los tickets
|
||||||
|
*/
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
t.id Id,
|
||||||
|
t.clientFk Client,
|
||||||
|
a.id Address,
|
||||||
|
t.packages Packages,
|
||||||
|
a.street AddressName,
|
||||||
|
a.postalCode PostalCode,
|
||||||
|
a.city City,
|
||||||
|
sub2.itemPackingTypeFk PackingType,
|
||||||
|
c.phone ClientPhone,
|
||||||
|
c.mobile ClientMobile,
|
||||||
|
a.phone AddressPhone,
|
||||||
|
a.mobile AddressMobile,
|
||||||
|
d.longitude Longitude,
|
||||||
|
d.latitude Latitude,
|
||||||
|
wm.mediaValue SalePersonPhone,
|
||||||
|
tob.Note Note,
|
||||||
|
t.isSigned Signed
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON t.clientFk = c.id
|
||||||
|
JOIN address a ON t.addressFk = a.id
|
||||||
|
LEFT JOIN delivery d ON t.id = d.ticketFk
|
||||||
|
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT tob.description Note, t.id
|
||||||
|
FROM ticketObservation tob
|
||||||
|
JOIN ticket t ON tob.ticketFk = t.id
|
||||||
|
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
AND ot.code = 'delivery'
|
||||||
|
)tob ON tob.id = t.id
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT sub.ticketFk,
|
||||||
|
CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
|
||||||
|
FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
|
||||||
|
FROM ticket t
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id,i.itemPackingTypeFk)sub
|
||||||
|
GROUP BY sub.ticketFk
|
||||||
|
) sub2 ON sub2.ticketFk = t.id
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id
|
||||||
|
ORDER BY t.priority;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,67 @@
|
||||||
|
DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign';
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`)
|
||||||
|
VALUES
|
||||||
|
('Ticket','saveSign','WRITE','ALLOW','employee');
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS vn.route_getTickets;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Pasado un RouteFk devuelve la información
|
||||||
|
* de sus tickets.
|
||||||
|
*
|
||||||
|
* @param vRouteFk
|
||||||
|
*
|
||||||
|
* @select Información de los tickets
|
||||||
|
*/
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
t.id Id,
|
||||||
|
t.clientFk Client,
|
||||||
|
a.id Address,
|
||||||
|
t.packages Packages,
|
||||||
|
a.street AddressName,
|
||||||
|
a.postalCode PostalCode,
|
||||||
|
a.city City,
|
||||||
|
sub2.itemPackingTypeFk PackingType,
|
||||||
|
c.phone ClientPhone,
|
||||||
|
c.mobile ClientMobile,
|
||||||
|
a.phone AddressPhone,
|
||||||
|
a.mobile AddressMobile,
|
||||||
|
d.longitude Longitude,
|
||||||
|
d.latitude Latitude,
|
||||||
|
wm.mediaValue SalePersonPhone,
|
||||||
|
tob.Note Note,
|
||||||
|
t.isSigned Signed
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON t.clientFk = c.id
|
||||||
|
JOIN address a ON t.addressFk = a.id
|
||||||
|
LEFT JOIN delivery d ON t.id = d.ticketFk
|
||||||
|
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT tob.description Note, t.id
|
||||||
|
FROM ticketObservation tob
|
||||||
|
JOIN ticket t ON tob.ticketFk = t.id
|
||||||
|
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
AND ot.code = 'delivery'
|
||||||
|
)tob ON tob.id = t.id
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT sub.ticketFk,
|
||||||
|
CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
|
||||||
|
FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
|
||||||
|
FROM ticket t
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id,i.itemPackingTypeFk)sub
|
||||||
|
GROUP BY sub.ticketFk
|
||||||
|
) sub2 ON sub2.ticketFk = t.id
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id
|
||||||
|
ORDER BY t.priority;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,83 @@
|
||||||
|
CREATE TABLE `vn`.`dmsRecover` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`ticketFk` int(11) DEFAULT NULL,
|
||||||
|
`sign` text DEFAULT NULL,
|
||||||
|
`created` timestamp NULL DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `ticketFk_idx` (`ticketFk`),
|
||||||
|
CONSTRAINT `ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=31917 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`delivery` ADD addressFk INT;
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`route_getTickets`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Pasado un RouteFk devuelve la información
|
||||||
|
* de sus tickets.
|
||||||
|
*
|
||||||
|
* @param vRouteFk
|
||||||
|
* @select Información de los tickets
|
||||||
|
*/
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT t.id Id,
|
||||||
|
t.clientFk Client,
|
||||||
|
a.id Address,
|
||||||
|
a.nickname ClientName,
|
||||||
|
t.packages Packages,
|
||||||
|
a.street AddressName,
|
||||||
|
a.postalCode PostalCode,
|
||||||
|
a.city City,
|
||||||
|
sub2.itemPackingTypeFk PackingType,
|
||||||
|
c.phone ClientPhone,
|
||||||
|
c.mobile ClientMobile,
|
||||||
|
a.phone AddressPhone,
|
||||||
|
a.mobile AddressMobile,
|
||||||
|
d.longitude Longitude,
|
||||||
|
d.latitude Latitude,
|
||||||
|
wm.mediaValue SalePersonPhone,
|
||||||
|
tob.description Note,
|
||||||
|
t.isSigned Signed,
|
||||||
|
t.priority
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON t.clientFk = c.id
|
||||||
|
JOIN address a ON t.addressFk = a.id
|
||||||
|
LEFT JOIN delivery d ON d.addressFk = a.id
|
||||||
|
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
||||||
|
LEFT JOIN(
|
||||||
|
SELECT tob.description, t.id
|
||||||
|
FROM ticketObservation tob
|
||||||
|
JOIN ticket t ON tob.ticketFk = t.id
|
||||||
|
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
AND ot.code = 'delivery'
|
||||||
|
)tob ON tob.id = t.id
|
||||||
|
LEFT JOIN(
|
||||||
|
SELECT sub.ticketFk,
|
||||||
|
CONCAT('(',
|
||||||
|
GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk
|
||||||
|
ORDER BY sub.items DESC SEPARATOR ','),
|
||||||
|
') ') itemPackingTypeFk
|
||||||
|
FROM (
|
||||||
|
SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items
|
||||||
|
FROM ticket t
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id, i.itemPackingTypeFk
|
||||||
|
)sub
|
||||||
|
GROUP BY sub.ticketFk
|
||||||
|
)sub2 ON sub2.ticketFk = t.id
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
ORDER BY d.id DESC
|
||||||
|
LIMIT 10000000000000000000
|
||||||
|
)sub3
|
||||||
|
GROUP BY sub3.id
|
||||||
|
ORDER BY sub3.priority;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1 @@
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`claimBeginning_afterInsert`;
|
|
@ -0,0 +1,70 @@
|
||||||
|
DROP TABLE IF EXISTS `vn`.`dmsRecover`;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk;
|
||||||
|
ALTER TABLE `vn`.`delivery` DROP CONSTRAINT delivery_ticketFk_FK;
|
||||||
|
ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk;
|
||||||
|
ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL;
|
||||||
|
ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`);
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS vn.route_getTickets;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Pasado un RouteFk devuelve la información
|
||||||
|
* de sus tickets.
|
||||||
|
*
|
||||||
|
* @param vRouteFk
|
||||||
|
*
|
||||||
|
* @select Información de los tickets
|
||||||
|
*/
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
t.id Id,
|
||||||
|
t.clientFk Client,
|
||||||
|
a.id Address,
|
||||||
|
t.packages Packages,
|
||||||
|
a.street AddressName,
|
||||||
|
a.postalCode PostalCode,
|
||||||
|
a.city City,
|
||||||
|
sub2.itemPackingTypeFk PackingType,
|
||||||
|
c.phone ClientPhone,
|
||||||
|
c.mobile ClientMobile,
|
||||||
|
a.phone AddressPhone,
|
||||||
|
a.mobile AddressMobile,
|
||||||
|
d.longitude Longitude,
|
||||||
|
d.latitude Latitude,
|
||||||
|
wm.mediaValue SalePersonPhone,
|
||||||
|
tob.Note Note,
|
||||||
|
t.isSigned Signed
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON t.clientFk = c.id
|
||||||
|
JOIN address a ON t.addressFk = a.id
|
||||||
|
LEFT JOIN delivery d ON t.id = d.ticketFk
|
||||||
|
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT tob.description Note, t.id
|
||||||
|
FROM ticketObservation tob
|
||||||
|
JOIN ticket t ON tob.ticketFk = t.id
|
||||||
|
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
AND ot.code = 'delivery'
|
||||||
|
)tob ON tob.id = t.id
|
||||||
|
LEFT JOIN
|
||||||
|
(SELECT sub.ticketFk,
|
||||||
|
CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
|
||||||
|
FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
|
||||||
|
FROM ticket t
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id,i.itemPackingTypeFk)sub
|
||||||
|
GROUP BY sub.ticketFk
|
||||||
|
) sub2 ON sub2.ticketFk = t.id
|
||||||
|
WHERE t.routeFk = vRouteFk
|
||||||
|
GROUP BY t.id
|
||||||
|
ORDER BY t.priority;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('Defaulter', 'observationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
@ -1774,12 +1774,12 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
|
||||||
( 6, 'mana', 'Mana', 72, 4, 0),
|
( 6, 'mana', 'Mana', 72, 4, 0),
|
||||||
( 7, 'lack', 'Faltas', 72, 2, 0);
|
( 7, 'lack', 'Faltas', 72, 2, 0);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`)
|
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183'),
|
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11),
|
||||||
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL),
|
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16),
|
||||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL),
|
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7),
|
||||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL);
|
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -989,7 +989,7 @@ export default {
|
||||||
saveButton: 'vn-worker-basic-data button[type=submit]'
|
saveButton: 'vn-worker-basic-data button[type=submit]'
|
||||||
},
|
},
|
||||||
workerNotes: {
|
workerNotes: {
|
||||||
addNoteFloatButton: 'vn-float-button',
|
addNoteFloatButton: 'vn-worker-note vn-float-button',
|
||||||
note: 'vn-textarea[ng-model="$ctrl.note.text"]',
|
note: 'vn-textarea[ng-model="$ctrl.note.text"]',
|
||||||
saveButton: 'button[type=submit]',
|
saveButton: 'button[type=submit]',
|
||||||
firstNoteText: 'vn-worker-note .text'
|
firstNoteText: 'vn-worker-note .text'
|
||||||
|
|
|
@ -28,22 +28,4 @@ describe('Client log path', () => {
|
||||||
it('should navigate to the log section', async() => {
|
it('should navigate to the log section', async() => {
|
||||||
await page.accessToSection('client.card.log');
|
await page.accessToSection('client.card.log');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the previous value of the last logged change', async() => {
|
|
||||||
let lastModificationPreviousValue = await page
|
|
||||||
.waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText');
|
|
||||||
|
|
||||||
expect(lastModificationPreviousValue).toContain('DavidCharlesHaller');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should check the current value of the last logged change', async() => {
|
|
||||||
let lastModificationPreviousValue = await page
|
|
||||||
.waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText');
|
|
||||||
|
|
||||||
let lastModificationCurrentValue = await page.
|
|
||||||
waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText');
|
|
||||||
|
|
||||||
expect(lastModificationPreviousValue).toEqual('DavidCharlesHaller');
|
|
||||||
expect(lastModificationCurrentValue).toEqual('this is a test');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe('Client defaulter path', () => {
|
||||||
expect(message.text).toContain(`The message can't be empty`);
|
expect(message.text).toContain(`The message can't be empty`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shoul checked all defaulters', async() => {
|
it('should checked all defaulters', async() => {
|
||||||
await page.loginAndModule('insurance', 'client');
|
await page.loginAndModule('insurance', 'client');
|
||||||
await page.accessToSection('client.defaulter');
|
await page.accessToSection('client.defaulter');
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe('Worker Add notes path', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
browser = await getBrowser();
|
browser = await getBrowser();
|
||||||
page = browser.page;
|
page = browser.page;
|
||||||
await page.loginAndModule('employee', 'worker');
|
await page.loginAndModule('hr', 'worker');
|
||||||
await page.accessToSearchResult('Bruce Banner');
|
await page.accessToSearchResult('Bruce Banner');
|
||||||
await page.accessToSection('worker.card.note.index');
|
await page.accessToSection('worker.card.note.index');
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,23 +42,4 @@ describe('Item log path', () => {
|
||||||
await page.waitForSelector(selectors.itemsIndex.createItemButton);
|
await page.waitForSelector(selectors.itemsIndex.createItemButton);
|
||||||
await page.waitForState('item.index');
|
await page.waitForState('item.index');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should search for the created item and navigate to it's log section`, async() => {
|
|
||||||
await page.accessToSearchResult('Knowledge artifact');
|
|
||||||
await page.accessToSection('item.card.log');
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should confirm the log is showing 4 entries`, async() => {
|
|
||||||
await page.waitForSelector(selectors.itemLog.anyLineCreated);
|
|
||||||
const anyLineCreatedCount = await page.countElement(selectors.itemLog.anyLineCreated);
|
|
||||||
|
|
||||||
expect(anyLineCreatedCount).toEqual(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
xit(`should confirm the log is showing the intrastat for the created item`, async() => {
|
|
||||||
const fifthLineCreatedProperty = await page
|
|
||||||
.waitToGetProperty(selectors.itemLog.fifthLineCreatedProperty, 'innerText');
|
|
||||||
|
|
||||||
expect(fifthLineCreatedProperty).toEqual('05080000');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -249,6 +249,7 @@ describe('Ticket Edit sale path', () => {
|
||||||
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
||||||
await page.waitToClick(selectors.ticketSales.moreMenu);
|
await page.waitToClick(selectors.ticketSales.moreMenu);
|
||||||
await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim);
|
await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim);
|
||||||
|
await page.waitToClick(selectors.globalItems.acceptButton);
|
||||||
await page.waitForState('claim.card.basicData');
|
await page.waitForState('claim.card.basicData');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -29,20 +29,4 @@ describe('Ticket expeditions and log path', () => {
|
||||||
|
|
||||||
expect(result).toEqual(3);
|
expect(result).toEqual(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should confirm the expedition deleted is shown now in the ticket log`, async() => {
|
|
||||||
await page.accessToSection('ticket.card.log');
|
|
||||||
const user = await page
|
|
||||||
.waitToGetProperty(selectors.ticketLog.user, 'innerText');
|
|
||||||
|
|
||||||
const action = await page
|
|
||||||
.waitToGetProperty(selectors.ticketLog.action, 'innerText');
|
|
||||||
|
|
||||||
const id = await page
|
|
||||||
.waitToGetProperty(selectors.ticketLog.id, 'innerText');
|
|
||||||
|
|
||||||
expect(user).toContain('production');
|
|
||||||
expect(action).toContain('Deletes');
|
|
||||||
expect(id).toEqual('2');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,30 +31,4 @@ describe('Ticket log path', () => {
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
expect(message.text).toContain('Data saved!');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate to the log section', async() => {
|
|
||||||
await page.accessToSection('ticket.card.log');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the viewport width to 1920 to see the table full width', async() => {
|
|
||||||
await page.setViewport({
|
|
||||||
width: 1920,
|
|
||||||
height: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await page.waitToGetProperty(selectors.ticketLog.firstTD, 'innerText');
|
|
||||||
|
|
||||||
expect(result.length).not.toBeGreaterThan('20');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the viewport width to 800 to see the table shrink and move data to the 1st column', async() => {
|
|
||||||
await page.setViewport({
|
|
||||||
width: 800,
|
|
||||||
height: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await page.waitToGetProperty(selectors.ticketLog.firstTD, 'innerText');
|
|
||||||
|
|
||||||
expect(result.length).toBeGreaterThan('15');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,14 +29,4 @@ describe('Zone descriptor path', () => {
|
||||||
|
|
||||||
expect(count).toEqual(0);
|
expect(count).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the ticket whom lost the zone and see evidence on the logs', async() => {
|
|
||||||
await page.waitToClick(selectors.globalItems.homeButton);
|
|
||||||
await page.selectModule('ticket');
|
|
||||||
await page.accessToSearchResult('20');
|
|
||||||
await page.accessToSection('ticket.card.log');
|
|
||||||
const lastChanges = await page.waitToGetProperty(selectors.ticketLog.changes, 'innerText');
|
|
||||||
|
|
||||||
expect(lastChanges).toContain('1');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,14 +64,4 @@ describe('Supplier basic data path', () => {
|
||||||
|
|
||||||
expect(result).toEqual('Some notes');
|
expect(result).toEqual('Some notes');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate to the log section', async() => {
|
|
||||||
await page.accessToSection('supplier.card.log');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should check the changes have been recorded', async() => {
|
|
||||||
const result = await page.waitToGetProperty('vn-tr table tr:nth-child(3) td.after', 'innerText');
|
|
||||||
|
|
||||||
expect(result).toEqual('Some notes');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -162,14 +162,8 @@ export default class UploadPhoto extends Component {
|
||||||
if (!this.newPhoto.files)
|
if (!this.newPhoto.files)
|
||||||
throw new Error(`Select an image`);
|
throw new Error(`Select an image`);
|
||||||
|
|
||||||
const viewportType = this.viewportSelection;
|
|
||||||
const output = viewportType.output;
|
|
||||||
const options = {
|
const options = {
|
||||||
type: 'blob',
|
type: 'blob',
|
||||||
size: {
|
|
||||||
width: output.width,
|
|
||||||
height: output.height
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return this.editor.result(options)
|
return this.editor.result(options)
|
||||||
.then(blob => this.newPhoto.blob = blob)
|
.then(blob => this.newPhoto.blob = blob)
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Model crud()', () => {
|
describe('Model crud()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
let insertId;
|
let insertId;
|
||||||
const barcodeModel = app.models.ItemBarcode;
|
const barcodeModel = app.models.ItemBarcode;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Model rewriteDbError()', () => {
|
describe('Model rewriteDbError()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should extend rewriteDbError properties to any model passed', () => {
|
it('should extend rewriteDbError properties to any model passed', () => {
|
||||||
const exampleModel = models.ItemTag;
|
const exampleModel = models.ItemTag;
|
||||||
|
|
||||||
|
|
|
@ -274,5 +274,6 @@
|
||||||
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
|
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
|
||||||
"Insert a date range": "Inserte un rango de fechas",
|
"Insert a date range": "Inserte un rango de fechas",
|
||||||
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
||||||
"Comment added to client": "Observación añadida al cliente {{clientFk}}"
|
"Comment added to client": "Observación añadida al cliente {{clientFk}}",
|
||||||
|
"Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,38 +4,6 @@ const EnumFactory = require('loopback-connector-mysql').EnumFactory;
|
||||||
const {Transaction, SQLConnector, ParameterizedSQL} = require('loopback-connector');
|
const {Transaction, SQLConnector, ParameterizedSQL} = require('loopback-connector');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const limitSet = new Set([
|
|
||||||
'save',
|
|
||||||
'updateOrCreate',
|
|
||||||
'replaceOrCreate',
|
|
||||||
'replaceById',
|
|
||||||
'update'
|
|
||||||
]);
|
|
||||||
|
|
||||||
const opOpts = {
|
|
||||||
update: [
|
|
||||||
'update',
|
|
||||||
'replaceById',
|
|
||||||
// |insert
|
|
||||||
'save',
|
|
||||||
'updateOrCreate',
|
|
||||||
'replaceOrCreate'
|
|
||||||
],
|
|
||||||
delete: [
|
|
||||||
'destroy',
|
|
||||||
'destroyAll'
|
|
||||||
],
|
|
||||||
insert: [
|
|
||||||
'create'
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
const opMap = new Map();
|
|
||||||
for (const op in opOpts) {
|
|
||||||
for (const met of opOpts[op])
|
|
||||||
opMap.set(met, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
class VnMySQL extends MySQL {
|
class VnMySQL extends MySQL {
|
||||||
/**
|
/**
|
||||||
* Promisified version of execute().
|
* Promisified version of execute().
|
||||||
|
@ -311,12 +279,11 @@ class VnMySQL extends MySQL {
|
||||||
return super[method].apply(this, args);
|
return super[method].apply(this, args);
|
||||||
|
|
||||||
this.invokeMethodP(method, [...args], model, ctx, opts)
|
this.invokeMethodP(method, [...args], model, ctx, opts)
|
||||||
.then(res => cb(...res), cb);
|
.then(res => cb(...[null].concat(res)), cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
async invokeMethodP(method, args, model, ctx, opts) {
|
async invokeMethodP(method, args, model, ctx, opts) {
|
||||||
const Model = this.getModelDefinition(model).model;
|
const Model = this.getModelDefinition(model).model;
|
||||||
const settings = Model.definition.settings;
|
|
||||||
let tx;
|
let tx;
|
||||||
if (!opts.transaction) {
|
if (!opts.transaction) {
|
||||||
tx = await Transaction.begin(this, {});
|
tx = await Transaction.begin(this, {});
|
||||||
|
@ -324,78 +291,22 @@ class VnMySQL extends MySQL {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch old values (update|delete) or login
|
|
||||||
let where, id, data, idName, limit, op, oldInstances, newInstances;
|
|
||||||
const hasGrabUser = settings.log && settings.log.grabUser;
|
|
||||||
if (hasGrabUser) {
|
|
||||||
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
||||||
|
if (userId) {
|
||||||
const user = await Model.app.models.Account.findById(userId, {fields: ['name']}, opts);
|
const user = await Model.app.models.Account.findById(userId, {fields: ['name']}, opts);
|
||||||
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
where = ctx.where;
|
|
||||||
id = ctx.id;
|
|
||||||
data = ctx.data;
|
|
||||||
idName = this.idName(model);
|
|
||||||
|
|
||||||
limit = limitSet.has(method);
|
const res = await new Promise((resolve, reject) => {
|
||||||
|
|
||||||
op = opMap.get(method);
|
|
||||||
|
|
||||||
if (!where) {
|
|
||||||
if (id) where = { [idName]: id };
|
|
||||||
else where = { [idName]: data[idName] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch old values
|
|
||||||
switch (op) {
|
|
||||||
case 'update':
|
|
||||||
case 'delete':
|
|
||||||
// Single entity operation
|
|
||||||
const stmt = this.buildSelectStmt(op, data, idName, model, where, limit);
|
|
||||||
stmt.merge(`FOR UPDATE`);
|
|
||||||
oldInstances = await this.executeStmt(stmt, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await new Promise(resolve => {
|
|
||||||
const fnArgs = args.slice(0, -2);
|
const fnArgs = args.slice(0, -2);
|
||||||
fnArgs.push(opts, (...args) => resolve(args));
|
fnArgs.push(opts, (err, ...args) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
resolve(args);
|
||||||
|
});
|
||||||
super[method].apply(this, fnArgs);
|
super[method].apply(this, fnArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasGrabUser)
|
if (userId) await this.executeP(`CALL account.myUser_logout()`, null, opts);
|
||||||
await this.executeP(`CALL account.myUser_logout()`, null, opts);
|
|
||||||
else {
|
|
||||||
// Fetch new values
|
|
||||||
const ids = [];
|
|
||||||
|
|
||||||
switch (op) {
|
|
||||||
case 'insert':
|
|
||||||
case 'update': {
|
|
||||||
switch (method) {
|
|
||||||
case 'createAll':
|
|
||||||
for (const row of res[1])
|
|
||||||
ids.push(row[idName]);
|
|
||||||
break;
|
|
||||||
case 'create':
|
|
||||||
ids.push(res[1]);
|
|
||||||
break;
|
|
||||||
case 'update':
|
|
||||||
if (data[idName] != null)
|
|
||||||
ids.push(data[idName]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newWhere = ids.length ? { [idName]: ids } : where;
|
|
||||||
|
|
||||||
const stmt = this.buildSelectStmt(op, data, idName, model, newWhere, limit);
|
|
||||||
newInstances = await this.executeStmt(stmt, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.createLogRecord(oldInstances, newInstances, model, opts);
|
|
||||||
}
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
return res;
|
return res;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -403,125 +314,6 @@ class VnMySQL extends MySQL {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildSelectStmt(op, data, idName, model, where, limit) {
|
|
||||||
const Model = this.getModelDefinition(model).model;
|
|
||||||
const properties = Object.keys(Model.definition.properties);
|
|
||||||
|
|
||||||
const fields = data ? Object.keys(data) : [];
|
|
||||||
if (op == 'delete')
|
|
||||||
properties.forEach(property => fields.push(property));
|
|
||||||
else {
|
|
||||||
const log = Model.definition.settings.log;
|
|
||||||
fields.push(idName);
|
|
||||||
if (log.relation) fields.push(Model.relations[log.relation].keyFrom);
|
|
||||||
if (log.showField) fields.push(log.showField);
|
|
||||||
else {
|
|
||||||
const showFieldNames = ['name', 'description', 'code', 'nickname'];
|
|
||||||
for (const field of showFieldNames) {
|
|
||||||
if (properties.includes(field)) {
|
|
||||||
log.showField = field;
|
|
||||||
fields.push(field);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const stmt = new ParameterizedSQL(
|
|
||||||
'SELECT ' +
|
|
||||||
this.buildColumnNames(model, { fields }) +
|
|
||||||
' FROM ' +
|
|
||||||
this.tableEscaped(model)
|
|
||||||
);
|
|
||||||
stmt.merge(this.buildWhere(model, where));
|
|
||||||
if (limit) stmt.merge(`LIMIT 1`);
|
|
||||||
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createLogRecord(oldInstances, newInstances, model, opts) {
|
|
||||||
function setActionType() {
|
|
||||||
if (oldInstances && newInstances)
|
|
||||||
return 'update';
|
|
||||||
else if (!oldInstances && newInstances)
|
|
||||||
return 'insert';
|
|
||||||
return 'delete';
|
|
||||||
}
|
|
||||||
|
|
||||||
const action = setActionType();
|
|
||||||
if (!newInstances && action != 'delete') return;
|
|
||||||
|
|
||||||
const Model = this.getModelDefinition(model).model;
|
|
||||||
const models = Model.app.models;
|
|
||||||
const definition = Model.definition;
|
|
||||||
const log = definition.settings.log;
|
|
||||||
|
|
||||||
const primaryKey = this.idName(model);
|
|
||||||
const originRelation = log.relation;
|
|
||||||
const originFkField = originRelation
|
|
||||||
? Model.relations[originRelation].keyFrom
|
|
||||||
: primaryKey;
|
|
||||||
|
|
||||||
// Prevent adding logs when deleting a principal entity (Client, Zone...)
|
|
||||||
if (action == 'delete' && !originRelation) return;
|
|
||||||
|
|
||||||
function map(instances) {
|
|
||||||
const map = new Map();
|
|
||||||
if (!instances) return;
|
|
||||||
for (const instance of instances)
|
|
||||||
map.set(instance[primaryKey], instance);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
const changedModel = definition.name;
|
|
||||||
const userFk = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
|
||||||
const oldMap = map(oldInstances);
|
|
||||||
const newMap = map(newInstances);
|
|
||||||
const ids = (oldMap || newMap).keys();
|
|
||||||
|
|
||||||
const logEntries = [];
|
|
||||||
|
|
||||||
function insertValuesLogEntry(logEntry, instance) {
|
|
||||||
logEntry.originFk = instance[originFkField];
|
|
||||||
logEntry.changedModelId = instance[primaryKey];
|
|
||||||
if (log.showField) logEntry.changedModelValue = instance[log.showField];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const id of ids) {
|
|
||||||
const oldI = oldMap && oldMap.get(id);
|
|
||||||
const newI = newMap && newMap.get(id);
|
|
||||||
|
|
||||||
const logEntry = {
|
|
||||||
action,
|
|
||||||
userFk,
|
|
||||||
changedModel,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (newI) {
|
|
||||||
insertValuesLogEntry(logEntry, newI);
|
|
||||||
// Delete unchanged properties
|
|
||||||
if (oldI) {
|
|
||||||
Object.keys(oldI).forEach(prop => {
|
|
||||||
const hasChanges = oldI[prop] instanceof Date ?
|
|
||||||
oldI[prop]?.getTime() != newI[prop]?.getTime() :
|
|
||||||
oldI[prop] != newI[prop];
|
|
||||||
|
|
||||||
if (!hasChanges) {
|
|
||||||
delete oldI[prop];
|
|
||||||
delete newI[prop];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
insertValuesLogEntry(logEntry, oldI);
|
|
||||||
|
|
||||||
logEntry.oldInstance = oldI;
|
|
||||||
logEntry.newInstance = newI;
|
|
||||||
logEntries.push(logEntry);
|
|
||||||
}
|
|
||||||
await models[log.model].create(logEntries, opts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.VnMySQL = VnMySQL;
|
exports.VnMySQL = VnMySQL;
|
||||||
|
@ -645,16 +437,14 @@ function generateOptions(settings) {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SQLConnector.prototype.all = function find(model, filter, options, cb) {
|
SQLConnector.prototype.all = function find(model, filter, options, cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
// Order by id if no order is specified
|
// Order by id if no order is specified
|
||||||
filter = filter || {};
|
filter = filter || {};
|
||||||
const stmt = this.buildSelect(model, filter, options);
|
const stmt = this.buildSelect(model, filter, options);
|
||||||
this.execute(stmt.sql, stmt.params, options, function(err, data) {
|
this.execute(stmt.sql, stmt.params, options, function(err, data) {
|
||||||
if (err) {
|
if (err)
|
||||||
return cb(err, []);
|
return cb(err, []);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const objs = data.map(function(obj) {
|
const objs = data.map(function(obj) {
|
||||||
|
@ -664,11 +454,10 @@ SQLConnector.prototype.all = function find(model, filter, options, cb) {
|
||||||
self.getModelDefinition(model).model.include(
|
self.getModelDefinition(model).model.include(
|
||||||
objs, filter.include, options, cb,
|
objs, filter.include, options, cb,
|
||||||
);
|
);
|
||||||
} else {
|
} else
|
||||||
cb(null, objs);
|
cb(null, objs);
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
cb(error, [])
|
cb(error, []);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Claim createFromSales()', () => {
|
describe('Claim createFromSales()', () => {
|
||||||
const ticketId = 16;
|
const ticketId = 23;
|
||||||
const newSale = [{
|
const newSale = [{
|
||||||
id: 3,
|
id: 31,
|
||||||
instance: 0,
|
instance: 0,
|
||||||
quantity: 10
|
quantity: 10
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Update Claim', () => {
|
describe('Update Claim', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
const newDate = Date.vnNew();
|
const newDate = Date.vnNew();
|
||||||
const originalData = {
|
const originalData = {
|
||||||
ticketFk: 3,
|
ticketFk: 3,
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Update Claim', () => {
|
describe('Update Claim', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
const newDate = Date.vnNew();
|
const newDate = Date.vnNew();
|
||||||
const original = {
|
const original = {
|
||||||
ticketFk: 3,
|
ticketFk: 3,
|
||||||
|
|
|
@ -10,7 +10,15 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before save', async ctx => {
|
Self.observe('before save', async ctx => {
|
||||||
if (ctx.isNewInstance) return;
|
if (ctx.isNewInstance) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const options = ctx.options;
|
||||||
|
const instance = ctx.instance;
|
||||||
|
const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options);
|
||||||
|
const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options);
|
||||||
|
if (ticket.ticketFk != claim.ticketFk)
|
||||||
|
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
||||||
|
}
|
||||||
// await claimIsEditable(ctx);
|
// await claimIsEditable(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimBeginning",
|
"name": "ClaimBeginning",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim",
|
|
||||||
"showField": "quantity"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimBeginning"
|
"table": "claimBeginning"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimDevelopment",
|
"name": "ClaimDevelopment",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimDevelopment"
|
"table": "claimDevelopment"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimDms",
|
"name": "ClaimDms",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimDms"
|
"table": "claimDms"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimEnd",
|
"name": "ClaimEnd",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimEnd"
|
"table": "claimEnd"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimObservation",
|
"name": "ClaimObservation",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimObservation"
|
"table": "claimObservation"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClaimState",
|
"name": "ClaimState",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"relation": "claim",
|
|
||||||
"showField": "description"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claimState"
|
"table": "claimState"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Claim",
|
"name": "Claim",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClaimLog",
|
|
||||||
"showField": "id"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "claim"
|
"table": "claim"
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
"name": "Address",
|
"name": "Address",
|
||||||
"description": "Client addresses",
|
"description": "Client addresses",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client",
|
|
||||||
"showField": "nickname"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "address"
|
"table": "address"
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
"name": "ClientContact",
|
"name": "ClientContact",
|
||||||
"description": "Client phone contacts",
|
"description": "Client phone contacts",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client",
|
|
||||||
"showField": "name"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "clientContact"
|
"table": "clientContact"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClientDms",
|
"name": "ClientDms",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"ClientLog",
|
|
||||||
"relation": "client",
|
|
||||||
"showField": "dmsFk"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "clientDms"
|
"table": "clientDms"
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
"name": "ClientObservation",
|
"name": "ClientObservation",
|
||||||
"description": "Client notes",
|
"description": "Client notes",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "clientObservation"
|
"table": "clientObservation"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ClientSample",
|
"name": "ClientSample",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client",
|
|
||||||
"showField": "type"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "clientSample"
|
"table": "clientSample"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Client",
|
"name": "Client",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"ClientLog",
|
|
||||||
"showField": "id"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "client"
|
"table": "client"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Greuge",
|
"name": "Greuge",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client",
|
|
||||||
"showField": "description"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "greuge"
|
"table": "greuge"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Recovery",
|
"name": "Recovery",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ClientLog",
|
|
||||||
"relation": "client"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "recovery"
|
"table": "recovery"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Buy",
|
"name": "Buy",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "EntryLog",
|
|
||||||
"relation": "entry",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "buy"
|
"table": "buy"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "EntryObservation",
|
"name": "EntryObservation",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "EntryLog",
|
|
||||||
"relation": "entry"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "entryObservation"
|
"table": "entryObservation"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Entry",
|
"name": "Entry",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"EntryLog",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "entry"
|
"table": "entry"
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('invoiceIn clone()', () => {
|
describe('invoiceIn clone()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => {
|
it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => {
|
||||||
const userId = 1;
|
const userId = 1;
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "InvoiceInTax",
|
"name": "InvoiceInTax",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "InvoiceInLog",
|
|
||||||
"relation": "invoiceIn"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "invoiceInTax"
|
"table": "invoiceInTax"
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "InvoiceIn",
|
"name": "InvoiceIn",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "InvoiceInLog"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "invoiceIn"
|
"table": "invoiceIn"
|
||||||
|
|
|
@ -56,7 +56,7 @@ module.exports = Self => {
|
||||||
reference: invoiceOut.ref,
|
reference: invoiceOut.ref,
|
||||||
recipientId: invoiceOut.clientFk
|
recipientId: invoiceOut.clientFk
|
||||||
});
|
});
|
||||||
const stream = await invoiceReport.toPdfStream();
|
const buffer = await invoiceReport.toPdfStream();
|
||||||
|
|
||||||
const issued = invoiceOut.issued;
|
const issued = invoiceOut.issued;
|
||||||
const year = issued.getFullYear().toString();
|
const year = issued.getFullYear().toString();
|
||||||
|
@ -66,7 +66,7 @@ module.exports = Self => {
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
// Store invoice
|
// Store invoice
|
||||||
print.storage.write(stream, {
|
await print.storage.write(buffer, {
|
||||||
type: 'invoice',
|
type: 'invoice',
|
||||||
path: `${year}/${month}/${day}`,
|
path: `${year}/${month}/${day}`,
|
||||||
fileName: fileName
|
fileName: fileName
|
||||||
|
|
|
@ -100,16 +100,23 @@ class Controller extends Section {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
||||||
|
.then(() => this.invoiceNext())
|
||||||
.catch(res => {
|
.catch(res => {
|
||||||
this.errors.unshift({
|
const message = res.data?.error?.message || res.message;
|
||||||
address,
|
if (res.status >= 400 && res.status < 500) {
|
||||||
message: res.data.error.message
|
this.errors.unshift({address, message});
|
||||||
});
|
this.invoiceNext();
|
||||||
|
} else {
|
||||||
|
this.invoicing = false;
|
||||||
|
this.status = 'done';
|
||||||
|
throw new UserError(`Critical invoicing error, proccess stopped`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
}
|
||||||
|
|
||||||
|
invoiceNext() {
|
||||||
this.addressIndex++;
|
this.addressIndex++;
|
||||||
this.invoiceOut();
|
this.invoiceOut();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get nAddresses() {
|
get nAddresses() {
|
||||||
|
|
|
@ -18,3 +18,4 @@ Invoice out: Facturar
|
||||||
One client: Un solo cliente
|
One client: Un solo cliente
|
||||||
Choose a valid client: Selecciona un cliente válido
|
Choose a valid client: Selecciona un cliente válido
|
||||||
Stop: Parar
|
Stop: Parar
|
||||||
|
Critical invoicing error, proccess stopped: Error crítico al facturar, proceso detenido
|
|
@ -1,9 +1,7 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const uuid = require('uuid');
|
|
||||||
const fs = require('fs/promises');
|
const fs = require('fs/promises');
|
||||||
const {createWriteStream} = require('fs');
|
const {createWriteStream} = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const gm = require('gm');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('download', {
|
Self.remoteMethod('download', {
|
||||||
|
@ -27,13 +25,9 @@ module.exports = Self => {
|
||||||
const maxAttempts = 3;
|
const maxAttempts = 3;
|
||||||
const collectionName = 'catalog';
|
const collectionName = 'catalog';
|
||||||
|
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
|
|
||||||
let tempFilePath;
|
let tempFilePath;
|
||||||
let queueRow;
|
let queueRow;
|
||||||
try {
|
try {
|
||||||
const myOptions = {transaction: tx};
|
|
||||||
|
|
||||||
queueRow = await Self.findOne(
|
queueRow = await Self.findOne(
|
||||||
{
|
{
|
||||||
fields: ['id', 'itemFk', 'url', 'attempts'],
|
fields: ['id', 'itemFk', 'url', 'attempts'],
|
||||||
|
@ -44,58 +38,14 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
order: 'priority, attempts, updated',
|
order: 'priority, attempts, updated',
|
||||||
},
|
}
|
||||||
myOptions
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!queueRow) return;
|
if (!queueRow) return;
|
||||||
|
|
||||||
const collection = await models.ImageCollection.findOne(
|
const fileName = `${queueRow.itemFk}.png`;
|
||||||
{
|
|
||||||
fields: [
|
|
||||||
'id',
|
|
||||||
'maxWidth',
|
|
||||||
'maxHeight',
|
|
||||||
'model',
|
|
||||||
'property',
|
|
||||||
],
|
|
||||||
where: {name: collectionName},
|
|
||||||
include: {
|
|
||||||
relation: 'sizes',
|
|
||||||
scope: {
|
|
||||||
fields: ['width', 'height', 'crop'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
|
|
||||||
const fileName = `${uuid.v4()}.png`;
|
|
||||||
tempFilePath = path.join(tempPath, fileName);
|
tempFilePath = path.join(tempPath, fileName);
|
||||||
|
|
||||||
// Insert image row
|
|
||||||
await models.Image.create(
|
|
||||||
{
|
|
||||||
name: fileName,
|
|
||||||
collectionFk: collectionName,
|
|
||||||
updated: Date.vnNow(),
|
|
||||||
},
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update item
|
|
||||||
const model = models[collection.model];
|
|
||||||
if (!model) throw new Error('No matching model found');
|
|
||||||
|
|
||||||
const item = await model.findById(queueRow.itemFk, null, myOptions);
|
|
||||||
if (item) {
|
|
||||||
await item.updateAttribute(
|
|
||||||
collection.property,
|
|
||||||
fileName,
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download remote image
|
// Download remote image
|
||||||
const response = await axios.get(queueRow.url, {
|
const response = await axios.get(queueRow.url, {
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
|
@ -108,71 +58,22 @@ module.exports = Self => {
|
||||||
writeStream.on('error', error => reject(error));
|
writeStream.on('error', error => reject(error));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resize
|
await models.Image.resize({
|
||||||
const container = await models.ImageContainer.container(
|
collectionName: collectionName,
|
||||||
collectionName
|
srcFile: tempFilePath,
|
||||||
);
|
fileName: fileName,
|
||||||
const rootPath = container.client.root;
|
entityId: queueRow.itemFk
|
||||||
const collectionDir = path.join(rootPath, collectionName);
|
|
||||||
|
|
||||||
// To max size
|
|
||||||
const {maxWidth, maxHeight} = collection;
|
|
||||||
const fullSizePath = path.join(collectionDir, 'full');
|
|
||||||
const toFullSizePath = `${fullSizePath}/${fileName}`;
|
|
||||||
|
|
||||||
await fs.mkdir(fullSizePath, {recursive: true});
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
gm(tempFilePath)
|
|
||||||
.resize(maxWidth, maxHeight, '>')
|
|
||||||
.setFormat('png')
|
|
||||||
.write(toFullSizePath, function(err) {
|
|
||||||
if (err) reject(err);
|
|
||||||
if (!err) resolve();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// To collection sizes
|
|
||||||
for (const size of collection.sizes()) {
|
|
||||||
const {width, height} = size;
|
|
||||||
|
|
||||||
const sizePath = path.join(collectionDir, `${width}x${height}`);
|
|
||||||
const toSizePath = `${sizePath}/${fileName}`;
|
|
||||||
|
|
||||||
await fs.mkdir(sizePath, {recursive: true});
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const gmInstance = gm(tempFilePath);
|
|
||||||
|
|
||||||
if (size.crop) {
|
|
||||||
gmInstance
|
|
||||||
.resize(width, height, '^')
|
|
||||||
.gravity('Center')
|
|
||||||
.crop(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!size.crop) gmInstance.resize(width, height, '>');
|
|
||||||
|
|
||||||
gmInstance
|
|
||||||
.setFormat('png')
|
|
||||||
.write(toSizePath, function(err) {
|
|
||||||
if (err) reject(err);
|
|
||||||
if (!err) resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.unlink(tempFilePath);
|
await fs.unlink(tempFilePath);
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
|
|
||||||
await queueRow.destroy(myOptions);
|
await queueRow.destroy();
|
||||||
|
|
||||||
// Restart queue
|
// Restart queue
|
||||||
Self.download();
|
Self.download();
|
||||||
|
|
||||||
await tx.commit();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await tx.rollback();
|
|
||||||
|
|
||||||
if (queueRow.attempts < maxAttempts) {
|
if (queueRow.attempts < maxAttempts) {
|
||||||
await queueRow.updateAttributes({
|
await queueRow.updateAttributes({
|
||||||
error: error,
|
error: error,
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('item updateTaxes()', () => {
|
describe('item updateTaxes()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw an error if the taxClassFk is blank', async() => {
|
it('should throw an error if the taxClassFk is blank', async() => {
|
||||||
const tx = await models.Item.beginTransaction({});
|
const tx = await models.Item.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('tag onSubmit()', () => {
|
describe('tag onSubmit()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should delete a tag', async() => {
|
it('should delete a tag', async() => {
|
||||||
const tx = await models.Item.beginTransaction({});
|
const tx = await models.Item.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ItemBarcode",
|
"name": "ItemBarcode",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ItemLog",
|
|
||||||
"relation": "item",
|
|
||||||
"showField": "code"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "itemBarcode"
|
"table": "itemBarcode"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ItemBotanical",
|
"name": "ItemBotanical",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ItemLog",
|
|
||||||
"relation": "item"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "itemBotanical"
|
"table": "itemBotanical"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ItemTag",
|
"name": "ItemTag",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ItemLog",
|
|
||||||
"relation": "item",
|
|
||||||
"showField": "value"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "itemTag"
|
"table": "itemTag"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ItemTaxCountry",
|
"name": "ItemTaxCountry",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ItemLog",
|
|
||||||
"relation": "item",
|
|
||||||
"showField": "countryFk"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "itemTaxCountry"
|
"table": "itemTaxCountry"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Item",
|
"name": "Item",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ItemLog",
|
|
||||||
"showField": "id",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "item"
|
"table": "item"
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('AgencyTerm createInvoiceIn()', () => {
|
describe('AgencyTerm createInvoiceIn()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
const rows = [
|
const rows = [
|
||||||
{
|
{
|
||||||
routeFk: 2,
|
routeFk: 2,
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Route",
|
"name": "Route",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"RouteLog",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "route"
|
"table": "route"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Shelving",
|
"name": "Shelving",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "ShelvingLog",
|
|
||||||
"showField": "id"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "shelving"
|
"table": "shelving"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "SupplierAccount",
|
"name": "SupplierAccount",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"SupplierLog",
|
|
||||||
"relation": "supplier"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "supplierAccount"
|
"table": "supplierAccount"
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
"name": "SupplierAddress",
|
"name": "SupplierAddress",
|
||||||
"description": "Supplier addresses",
|
"description": "Supplier addresses",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "SupplierLog",
|
|
||||||
"relation": "supplier",
|
|
||||||
"showField": "name"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "supplierAddress"
|
"table": "supplierAddress"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "SupplierContact",
|
"name": "SupplierContact",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"SupplierLog",
|
|
||||||
"relation": "supplier"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "supplierContact"
|
"table": "supplierContact"
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Supplier",
|
"name": "Supplier",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"SupplierLog"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "supplier"
|
"table": "supplier"
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
type="number"
|
type="number"
|
||||||
label="Km Price"
|
label="Km Price"
|
||||||
ng-model="$ctrl.supplierAgencyTerm.kmPrice"
|
ng-model="$ctrl.supplierAgencyTerm.kmPrice"
|
||||||
|
step="0.01"
|
||||||
rule>
|
rule>
|
||||||
</vn-input-number>
|
</vn-input-number>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket deleteExpeditions()', () => {
|
describe('ticket deleteExpeditions()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should delete the selected expeditions', async() => {
|
it('should delete the selected expeditions', async() => {
|
||||||
const tx = await models.Expedition.beginTransaction({});
|
const tx = await models.Expedition.beginTransaction({});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket moveExpeditions()', () => {
|
describe('ticket moveExpeditions()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should move the selected expeditions to new ticket', async() => {
|
it('should move the selected expeditions to new ticket', async() => {
|
||||||
const tx = await models.Expedition.beginTransaction({});
|
const tx = await models.Expedition.beginTransaction({});
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket-request confirm()', () => {
|
describe('ticket-request confirm()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
let ctx = {
|
let ctx = {
|
||||||
req: {
|
req: {
|
||||||
accessToken: {userId: 9},
|
accessToken: {userId: 9},
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket-request deny()', () => {
|
describe('ticket-request deny()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the denied ticket request', async() => {
|
it('should return the denied ticket request', async() => {
|
||||||
const tx = await models.TicketRequest.beginTransaction({});
|
const tx = await models.TicketRequest.beginTransaction({});
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
// Store invoice
|
// Store invoice
|
||||||
storage.write(stream, {
|
await storage.write(stream, {
|
||||||
type: 'invoice',
|
type: 'invoice',
|
||||||
path: `${year}/${month}/${day}`,
|
path: `${year}/${month}/${day}`,
|
||||||
fileName: fileName
|
fileName: fileName
|
||||||
|
|
|
@ -34,6 +34,8 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
let dms;
|
||||||
|
let gestDocCreated = false;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -96,11 +98,12 @@ module.exports = Self => {
|
||||||
warehouseId: ticket.warehouseFk,
|
warehouseId: ticket.warehouseFk,
|
||||||
companyId: ticket.companyFk,
|
companyId: ticket.companyFk,
|
||||||
dmsTypeId: dmsType.id,
|
dmsTypeId: dmsType.id,
|
||||||
reference: id,
|
reference: '',
|
||||||
description: `Ticket ${id} Cliente ${ticket.client().name} Ruta ${ticket.route().id}`,
|
description: `Firma del cliente - Ruta ${ticket.route().id}`,
|
||||||
hasFile: true
|
hasFile: true
|
||||||
};
|
};
|
||||||
await models.Ticket.uploadFile(ctxUploadFile, id, myOptions);
|
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||||
|
gestDocCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -118,12 +121,16 @@ module.exports = Self => {
|
||||||
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
||||||
else if (!await gestDocExists(args.tickets[i])) {
|
else if (!await gestDocExists(args.tickets[i])) {
|
||||||
if (args.location) setLocation(args.tickets[i]);
|
if (args.location) setLocation(args.tickets[i]);
|
||||||
await createGestDoc(args.tickets[i]);
|
if (!gestDocCreated) await createGestDoc(args.tickets[i]);
|
||||||
|
await models.TicketDms.create({ticketFk: args.tickets[i], dmsFk: dms[0].id}, myOptions);
|
||||||
|
const ticket = await models.Ticket.findById(args.tickets[i], null, myOptions);
|
||||||
|
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -17,6 +17,17 @@ describe('ticket componentUpdate()', () => {
|
||||||
let componentValue;
|
let componentValue;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}});
|
const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}});
|
||||||
deliveryComponentId = deliveryComponenet.id;
|
deliveryComponentId = deliveryComponenet.id;
|
||||||
componentOfSaleSeven = `SELECT value
|
componentOfSaleSeven = `SELECT value
|
||||||
|
@ -180,9 +191,6 @@ describe('ticket componentUpdate()', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
||||||
active: ctx.req
|
|
||||||
});
|
|
||||||
const oldTicket = await models.Ticket.findById(ticketID, null, options);
|
const oldTicket = await models.Ticket.findById(ticketID, null, options);
|
||||||
|
|
||||||
await models.Ticket.componentUpdate(ctx, options);
|
await models.Ticket.componentUpdate(ctx, options);
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Expedition",
|
"name": "Expedition",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "expedition"
|
"table": "expedition"
|
||||||
|
@ -59,4 +55,3 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Sale",
|
"name": "Sale",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket",
|
|
||||||
"showField": "concept",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "sale"
|
"table": "sale"
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket model TicketTracking', () => {
|
describe('ticket model TicketTracking', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
let ticketTrackingId;
|
let ticketTrackingId;
|
||||||
|
|
||||||
afterAll(async() => {
|
afterAll(async() => {
|
||||||
|
|
|
@ -14,6 +14,15 @@
|
||||||
},
|
},
|
||||||
"scopeDays": {
|
"scopeDays": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"pickingDelay": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"packagingInvoicingDated": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"daysForWarningClaim": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketDms",
|
"name": "TicketDms",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketDms"
|
"table": "ticketDms"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketObservation",
|
"name": "TicketObservation",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketObservation"
|
"table": "ticketObservation"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketPackaging",
|
"name": "TicketPackaging",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketPackaging"
|
"table": "ticketPackaging"
|
||||||
|
|
|
@ -6,10 +6,6 @@
|
||||||
"table": "ticketRefund"
|
"table": "ticketRefund"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "originalTicket"
|
|
||||||
},
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketRequest",
|
"name": "TicketRequest",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketRequest"
|
"table": "ticketRequest"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketService",
|
"name": "TicketService",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket",
|
|
||||||
"showField": "description"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketService"
|
"table": "ticketService"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketTracking",
|
"name": "TicketTracking",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket",
|
|
||||||
"showField": "stateFk"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketTracking"
|
"table": "ticketTracking"
|
||||||
|
@ -48,4 +43,3 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TicketWeekly",
|
"name": "TicketWeekly",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model": "TicketLog",
|
|
||||||
"relation": "ticket",
|
|
||||||
"showField": "ticketFk"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketWeekly"
|
"table": "ticketWeekly"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Ticket",
|
"name": "Ticket",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"TicketLog",
|
|
||||||
"showField": "id",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticket"
|
"table": "ticket"
|
||||||
|
|
|
@ -481,6 +481,13 @@
|
||||||
on-accept="$ctrl.transferSales($ctrl.transfer.ticketId)">
|
on-accept="$ctrl.transferSales($ctrl.transfer.ticketId)">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="claimConfirm"
|
||||||
|
question="Do you want to continue?"
|
||||||
|
message="Claim out of time"
|
||||||
|
on-accept="$ctrl.onCreateClaimAccepted()">
|
||||||
|
</vn-confirm>
|
||||||
|
|
||||||
<vn-menu vn-id="moreOptions">
|
<vn-menu vn-id="moreOptions">
|
||||||
<vn-item translate
|
<vn-item translate
|
||||||
name="sms"
|
name="sms"
|
||||||
|
@ -503,6 +510,7 @@
|
||||||
ng-click="$ctrl.createClaim()"
|
ng-click="$ctrl.createClaim()"
|
||||||
ng-if="$ctrl.isClaimable">
|
ng-if="$ctrl.isClaimable">
|
||||||
Add claim
|
Add claim
|
||||||
|
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item translate
|
<vn-item translate
|
||||||
name="reserve"
|
name="reserve"
|
||||||
|
|
|
@ -7,6 +7,7 @@ class Controller extends Section {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this._sales = [];
|
this._sales = [];
|
||||||
this.manaCode = 'mana';
|
this.manaCode = 'mana';
|
||||||
|
this.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
get manaCode() {
|
get manaCode() {
|
||||||
|
@ -43,6 +44,15 @@ class Controller extends Section {
|
||||||
|
|
||||||
return ticketState && ticketState.state.code;
|
return ticketState && ticketState.state.code;
|
||||||
}
|
}
|
||||||
|
getConfig() {
|
||||||
|
let filter = {
|
||||||
|
fields: ['daysForWarningClaim'],
|
||||||
|
};
|
||||||
|
this.$http.get(`TicketConfigs`, {filter})
|
||||||
|
.then(res => {
|
||||||
|
this.ticketConfig = res.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get isClaimable() {
|
get isClaimable() {
|
||||||
if (this.ticket) {
|
if (this.ticket) {
|
||||||
|
@ -184,6 +194,16 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
createClaim() {
|
createClaim() {
|
||||||
|
const timeDifference = new Date().getTime() - new Date(this.ticket.shipped).getTime();
|
||||||
|
const pastDays = Math.floor(timeDifference / 86400000);
|
||||||
|
|
||||||
|
if (pastDays >= this.ticketConfig[0].daysForWarningClaim)
|
||||||
|
this.$.claimConfirm.show();
|
||||||
|
else
|
||||||
|
this.onCreateClaimAccepted();
|
||||||
|
}
|
||||||
|
|
||||||
|
onCreateClaimAccepted() {
|
||||||
const sales = this.selectedValidSales();
|
const sales = this.selectedValidSales();
|
||||||
const params = {ticketId: this.ticket.id, sales: sales};
|
const params = {ticketId: this.ticket.id, sales: sales};
|
||||||
this.resetChanges();
|
this.resetChanges();
|
||||||
|
|
|
@ -45,6 +45,7 @@ describe('Ticket', () => {
|
||||||
$scope.model = crudModel;
|
$scope.model = crudModel;
|
||||||
$scope.editDiscount = {relocate: () => {}, hide: () => {}};
|
$scope.editDiscount = {relocate: () => {}, hide: () => {}};
|
||||||
$scope.editPricePopover = {relocate: () => {}};
|
$scope.editPricePopover = {relocate: () => {}};
|
||||||
|
$scope.claimConfirm = {show: () => {}};
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
Object.defineProperties($state.params, {
|
Object.defineProperties($state.params, {
|
||||||
id: {
|
id: {
|
||||||
|
@ -61,6 +62,10 @@ describe('Ticket', () => {
|
||||||
controller.card = {reload: () => {}};
|
controller.card = {reload: () => {}};
|
||||||
controller._ticket = ticket;
|
controller._ticket = ticket;
|
||||||
controller._sales = sales;
|
controller._sales = sales;
|
||||||
|
controller.ticketConfig = [
|
||||||
|
{daysForWarningClaim: 1}
|
||||||
|
];
|
||||||
|
$httpBackend.expect('GET', 'TicketConfigs').respond(200);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('ticket() setter', () => {
|
describe('ticket() setter', () => {
|
||||||
|
@ -113,7 +118,6 @@ describe('Ticket', () => {
|
||||||
it('should make an HTTP GET query and return the worker mana', () => {
|
it('should make an HTTP GET query and return the worker mana', () => {
|
||||||
controller.edit = {};
|
controller.edit = {};
|
||||||
const expectedAmount = 250;
|
const expectedAmount = 250;
|
||||||
|
|
||||||
$httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount);
|
$httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount);
|
||||||
$httpBackend.expect('GET', 'Sales/usesMana').respond(200);
|
$httpBackend.expect('GET', 'Sales/usesMana').respond(200);
|
||||||
$httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount);
|
$httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount);
|
||||||
|
@ -279,7 +283,17 @@ describe('Ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createClaim()', () => {
|
describe('createClaim()', () => {
|
||||||
it('should perform a query and call windows open', () => {
|
it('should call to the claimConfirm show() method', () => {
|
||||||
|
jest.spyOn(controller.$.claimConfirm, 'show').mockReturnThis();
|
||||||
|
|
||||||
|
controller.createClaim();
|
||||||
|
|
||||||
|
expect(controller.$.claimConfirm.show).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onCreateClaimAccepted()', () => {
|
||||||
|
it('should perform a query and call window open', () => {
|
||||||
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
||||||
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
||||||
|
|
||||||
|
@ -290,7 +304,7 @@ describe('Ticket', () => {
|
||||||
|
|
||||||
const expectedParams = {ticketId: 1, sales: [firstSale]};
|
const expectedParams = {ticketId: 1, sales: [firstSale]};
|
||||||
$httpBackend.expect('POST', `Claims/createFromSales`, expectedParams).respond(200, {id: 1});
|
$httpBackend.expect('POST', `Claims/createFromSales`, expectedParams).respond(200, {id: 1});
|
||||||
controller.createClaim();
|
controller.onCreateClaimAccepted();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.resetChanges).toHaveBeenCalledWith();
|
expect(controller.resetChanges).toHaveBeenCalledWith();
|
||||||
|
|
|
@ -40,4 +40,5 @@ Refund: Abono
|
||||||
Promotion mana: Maná promoción
|
Promotion mana: Maná promoción
|
||||||
Claim mana: Maná reclamación
|
Claim mana: Maná reclamación
|
||||||
History: Historial
|
History: Historial
|
||||||
Select lines to see the options: Seleccione lineas para ver las opciones
|
Do you want to continue?: ¿Desea continuar?
|
||||||
|
Claim out of time: Reclamación fuera de plazo
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Travel createThermograph()', () => {
|
describe('Travel createThermograph()', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
const travelId = 3;
|
const travelId = 3;
|
||||||
const currentUserId = 1102;
|
const currentUserId = 1102;
|
||||||
const thermographId = '138350-0';
|
const thermographId = '138350-0';
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "TravelThermograph",
|
"name": "TravelThermograph",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"TravelLog",
|
|
||||||
"relation": "travel",
|
|
||||||
"showField": "ref"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "travelThermograph"
|
"table": "travelThermograph"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Travel",
|
"name": "Travel",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"TravelLog",
|
|
||||||
"showField": "ref",
|
|
||||||
"grabUser": true
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "travel"
|
"table": "travel"
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "WorkerDms",
|
"name": "WorkerDms",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"ClientLog",
|
|
||||||
"relation": "worker",
|
|
||||||
"showField": "dmsFk"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "workerDocument"
|
"table": "workerDocument"
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
"name": "Worker",
|
"name": "Worker",
|
||||||
"description": "Company employees",
|
"description": "Company employees",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
|
||||||
"model":"WorkerLog",
|
|
||||||
"showField": "firstName"
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "worker"
|
"table": "worker"
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue