hotfix_arcRfid #1441
|
@ -6,5 +6,9 @@
|
|||
"source.fixAll.eslint": true
|
||||
},
|
||||
"search.useIgnoreFiles": false,
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||
"eslint.format.enable": true,
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
||||
}
|
||||
}
|
||||
|
|
24
CHANGELOG.md
24
CHANGELOG.md
|
@ -5,6 +5,27 @@ 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/),
|
||||
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
|
||||
|
||||
### Added
|
||||
- (Clientes -> Morosos) Ahora se puede filtrar por las columnas "Desde" y "Fecha Ú. O.". También se envia un email al comercial cuando se añade una nota.
|
||||
- (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
|
||||
|
||||
### Fixed
|
||||
- (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
|
||||
|
||||
## [2312.01] - 2023-04-06
|
||||
|
||||
### Added
|
||||
|
@ -15,9 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- (Envíos -> Extra comunitarios) Se agrupan las entradas del mismo travel. Añadidos campos Referencia y Importe.
|
||||
- (Envíos -> Índice) Cambiado el buscador superior por uno lateral
|
||||
|
||||
### Fixed
|
||||
-
|
||||
|
||||
## [2310.01] - 2023-03-23
|
||||
|
||||
### Added
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId)
|
||||
VALUES('Mail', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`claimBeginning_afterInsert`;
|
|
@ -0,0 +1,72 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`;
|
||||
USE `vn`;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
|
||||
BEFORE UPDATE ON `client`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vText VARCHAR(255) DEFAULT NULL;
|
||||
DECLARE vPayMethodFk INT;
|
||||
-- Comprueba que el formato de los teléfonos es válido
|
||||
|
||||
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
|
||||
CALL pbx.phone_isValid(NEW.phone);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN
|
||||
CALL pbx.phone_isValid(NEW.mobile);
|
||||
END IF;
|
||||
|
||||
SELECT id INTO vPayMethodFk
|
||||
FROM vn.payMethod
|
||||
WHERE code = 'bankDraft';
|
||||
|
||||
IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN
|
||||
SET NEW.dueDay = 5;
|
||||
END IF;
|
||||
|
||||
-- Avisar al comercial si ha llegado la documentación sepa/core
|
||||
|
||||
IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN
|
||||
SET vText = 'Sepa de VNL';
|
||||
END IF;
|
||||
|
||||
IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN
|
||||
SET vText = 'Core de VNL';
|
||||
END IF;
|
||||
|
||||
IF vText IS NOT NULL
|
||||
THEN
|
||||
INSERT INTO mail(receiver, replyTo, `subject`, body)
|
||||
SELECT
|
||||
CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'),
|
||||
'administracion@verdnatura.es',
|
||||
CONCAT('Cliente ', NEW.id),
|
||||
CONCAT('Recibida la documentación: ', vText)
|
||||
FROM worker w
|
||||
LEFT JOIN account.user u ON w.userFk = u.id AND u.active
|
||||
LEFT JOIN account.account ac ON ac.id = u.id
|
||||
WHERE w.id = NEW.salesPersonFk;
|
||||
END IF;
|
||||
|
||||
IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN
|
||||
IF (SELECT COUNT(clientFk)
|
||||
FROM clientProtected
|
||||
WHERE clientFk = NEW.id
|
||||
) > 0 THEN
|
||||
CALL util.throw("HAS_CLIENT_PROTECTED");
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
|
||||
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||
SET NEW.isTaxDataChecked = 0;
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,13 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
|
||||
USE vn;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert`
|
||||
AFTER INSERT ON `invoiceOut`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('InvoiceIn', 'negativeBases', 'READ', 'ALLOW', 'ROLE', 'administrative'),
|
||||
('InvoiceIn', 'negativeBasesCsv', 'READ', 'ALLOW', 'ROLE', 'administrative');
|
|
@ -0,0 +1,14 @@
|
|||
CREATE TABLE `vn`.`workerObservation` (
|
||||
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`workerFk` int(10) unsigned DEFAULT NULL,
|
||||
`userFk` int(10) unsigned DEFAULT NULL,
|
||||
`text` text COLLATE utf8mb3_unicode_ci NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador';
|
||||
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('WorkerObservation', '*', '*', 'ALLOW', 'ROLE', 'hr');
|
|
@ -1774,12 +1774,12 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
|
|||
( 6, 'mana', 'Mana', 72, 4, 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
|
||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183'),
|
||||
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL),
|
||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL),
|
||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL);
|
||||
(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, 16),
|
||||
(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, 8);
|
||||
|
||||
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
||||
VALUES
|
||||
|
|
|
@ -426,7 +426,8 @@ export default {
|
|||
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
||||
fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]',
|
||||
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
||||
orderColumnId: 'vn-fixed-price th[field="itemFk"]'
|
||||
orderColumnId: 'vn-fixed-price th[field="itemFk"]',
|
||||
removeWarehouseFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(1) > vn-icon > i'
|
||||
},
|
||||
itemCreateView: {
|
||||
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
||||
|
@ -987,6 +988,12 @@ export default {
|
|||
locker: 'vn-worker-basic-data vn-input-number[ng-model="$ctrl.worker.locker"]',
|
||||
saveButton: 'vn-worker-basic-data button[type=submit]'
|
||||
},
|
||||
workerNotes: {
|
||||
addNoteFloatButton: 'vn-float-button',
|
||||
note: 'vn-textarea[ng-model="$ctrl.note.text"]',
|
||||
saveButton: 'button[type=submit]',
|
||||
firstNoteText: 'vn-worker-note .text'
|
||||
},
|
||||
workerPbx: {
|
||||
extension: 'vn-worker-pbx vn-textfield[ng-model="$ctrl.worker.sip.extension"]',
|
||||
saveButton: 'vn-worker-pbx button[type=submit]'
|
||||
|
|
|
@ -90,7 +90,7 @@ describe('SmartTable SearchBar integration', () => {
|
|||
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||
|
||||
expect(result).toEqual('13');
|
||||
expect(result).toEqual('3');
|
||||
});
|
||||
|
||||
it('should reload page and have same order', async() => {
|
||||
|
@ -99,7 +99,7 @@ describe('SmartTable SearchBar integration', () => {
|
|||
});
|
||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||
|
||||
expect(result).toEqual('13');
|
||||
expect(result).toEqual('3');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -28,22 +28,4 @@ describe('Client log path', () => {
|
|||
it('should navigate to the log section', async() => {
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import selectors from '../../helpers/selectors';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('Worker Add notes path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('employee', 'worker');
|
||||
await page.accessToSearchResult('Bruce Banner');
|
||||
await page.accessToSection('worker.card.note.index');
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
it(`should reach the notes index`, async() => {
|
||||
await page.waitForState('worker.card.note.index');
|
||||
});
|
||||
|
||||
it(`should click on the add note button`, async() => {
|
||||
await page.waitToClick(selectors.workerNotes.addNoteFloatButton);
|
||||
await page.waitForState('worker.card.note.create');
|
||||
});
|
||||
|
||||
it(`should create a note`, async() => {
|
||||
await page.waitForSelector(selectors.workerNotes.note);
|
||||
await page.type(`${selectors.workerNotes.note} textarea`, 'Meeting with Black Widow 21st 9am');
|
||||
await page.waitToClick(selectors.workerNotes.saveButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Data saved!');
|
||||
});
|
||||
|
||||
it('should confirm the note was created', async() => {
|
||||
const result = await page.waitToGetProperty(selectors.workerNotes.firstNoteText, 'innerText');
|
||||
|
||||
expect(result).toEqual('Meeting with Black Widow 21st 9am');
|
||||
});
|
||||
});
|
|
@ -42,23 +42,4 @@ describe('Item log path', () => {
|
|||
await page.waitForSelector(selectors.itemsIndex.createItemButton);
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,8 +15,9 @@ describe('Item fixed prices path', () => {
|
|||
await browser.close();
|
||||
});
|
||||
|
||||
it('should click on the add new foxed price button', async() => {
|
||||
await page.doSearch();
|
||||
it('should click on the add new fixed price button', async() => {
|
||||
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||
await page.waitForSpinnerLoad();
|
||||
await page.waitToClick(selectors.itemFixedPrice.add);
|
||||
await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
|
||||
});
|
||||
|
@ -37,7 +38,8 @@ describe('Item fixed prices path', () => {
|
|||
it('should reload the section and check the created price has the expected ID', async() => {
|
||||
await page.accessToSection('item.index');
|
||||
await page.accessToSection('item.fixedPrice');
|
||||
await page.doSearch();
|
||||
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||
await page.waitForSpinnerLoad();
|
||||
|
||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');
|
||||
|
||||
|
|
|
@ -29,20 +29,4 @@ describe('Ticket expeditions and log path', () => {
|
|||
|
||||
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!');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('InvoiceIn negative bases path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
const httpRequests = [];
|
||||
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
page.on('request', req => {
|
||||
if (req.url().includes(`InvoiceIns/negativeBases`))
|
||||
httpRequests.push(req.url());
|
||||
});
|
||||
await page.loginAndModule('administrative', 'invoiceIn');
|
||||
await page.accessToSection('invoiceIn.negative-bases');
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
it('should show negative bases in a date range', async() => {
|
||||
const request = httpRequests.find(req =>
|
||||
req.includes(`from`) && req.includes(`to`));
|
||||
|
||||
expect(request).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -29,14 +29,4 @@ describe('Zone descriptor path', () => {
|
|||
|
||||
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');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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;
|
||||
const barcodeModel = app.models.ItemBarcode;
|
||||
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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', () => {
|
||||
const exampleModel = models.ItemTag;
|
||||
|
||||
|
|
|
@ -268,8 +268,12 @@
|
|||
"Exists an invoice with a previous date": "Existe una factura con fecha anterior",
|
||||
"Invoice date can't be less than max date": "La fecha de factura no puede ser inferior a la fecha límite",
|
||||
"Warehouse inventory not set": "El almacén inventario no está establecido",
|
||||
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
|
||||
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
|
||||
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}",
|
||||
"Not exist this branch": "La rama no existe",
|
||||
"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",
|
||||
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -1,41 +1,9 @@
|
|||
const mysql = require('mysql');
|
||||
const MySQL = require('loopback-connector-mysql').MySQL;
|
||||
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 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 {
|
||||
/**
|
||||
* Promisified version of execute().
|
||||
|
@ -253,49 +221,49 @@ class VnMySQL extends MySQL {
|
|||
}
|
||||
|
||||
create(model, data, opts, cb) {
|
||||
const ctx = { data };
|
||||
const ctx = {data};
|
||||
this.invokeMethod('create',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
createAll(model, data, opts, cb) {
|
||||
const ctx = { data };
|
||||
const ctx = {data};
|
||||
this.invokeMethod('createAll',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
save(model, data, opts, cb) {
|
||||
const ctx = { data };
|
||||
const ctx = {data};
|
||||
this.invokeMethod('save',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
updateOrCreate(model, data, opts, cb) {
|
||||
const ctx = { data };
|
||||
const ctx = {data};
|
||||
this.invokeMethod('updateOrCreate',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
replaceOrCreate(model, data, opts, cb) {
|
||||
const ctx = { data };
|
||||
const ctx = {data};
|
||||
this.invokeMethod('replaceOrCreate',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
destroyAll(model, where, opts, cb) {
|
||||
const ctx = { where };
|
||||
const ctx = {where};
|
||||
this.invokeMethod('destroyAll',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
update(model, where, data, opts, cb) {
|
||||
const ctx = { where, data };
|
||||
const ctx = {where, data};
|
||||
this.invokeMethod('update',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
||||
replaceById(model, id, data, opts, cb) {
|
||||
const ctx = { id, data };
|
||||
const ctx = {id, data};
|
||||
this.invokeMethod('replaceById',
|
||||
arguments, model, ctx, opts, cb);
|
||||
}
|
||||
|
@ -311,91 +279,34 @@ class VnMySQL extends MySQL {
|
|||
return super[method].apply(this, args);
|
||||
|
||||
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) {
|
||||
const Model = this.getModelDefinition(model).model;
|
||||
const settings = Model.definition.settings;
|
||||
let tx;
|
||||
if (!opts.transaction) {
|
||||
tx = await Transaction.begin(this, {});
|
||||
opts = Object.assign({ transaction: tx, httpCtx: opts.httpCtx }, opts);
|
||||
opts = Object.assign({transaction: tx, httpCtx: opts.httpCtx}, opts);
|
||||
}
|
||||
|
||||
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 user = await Model.app.models.Account.findById(userId, { fields: ['name'] }, opts);
|
||||
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
||||
if (userId) {
|
||||
const user = await Model.app.models.Account.findById(userId, {fields: ['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);
|
||||
|
||||
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 res = await new Promise((resolve, reject) => {
|
||||
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);
|
||||
});
|
||||
|
||||
if (hasGrabUser)
|
||||
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 (userId) await this.executeP(`CALL account.myUser_logout()`, null, opts);
|
||||
if (tx) await tx.commit();
|
||||
return res;
|
||||
} catch (err) {
|
||||
|
@ -403,125 +314,6 @@ class VnMySQL extends MySQL {
|
|||
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;
|
||||
|
@ -542,7 +334,7 @@ exports.initialize = function initialize(dataSource, callback) {
|
|||
|
||||
if (callback) {
|
||||
if (dataSource.settings.lazyConnect) {
|
||||
process.nextTick(function () {
|
||||
process.nextTick(function() {
|
||||
callback();
|
||||
});
|
||||
} else
|
||||
|
@ -550,13 +342,13 @@ exports.initialize = function initialize(dataSource, callback) {
|
|||
}
|
||||
};
|
||||
|
||||
MySQL.prototype.connect = function (callback) {
|
||||
MySQL.prototype.connect = function(callback) {
|
||||
const self = this;
|
||||
const options = generateOptions(this.settings);
|
||||
|
||||
if (this.client) {
|
||||
if (callback) {
|
||||
process.nextTick(function () {
|
||||
process.nextTick(function() {
|
||||
callback(null, self.client);
|
||||
});
|
||||
}
|
||||
|
@ -565,7 +357,7 @@ MySQL.prototype.connect = function (callback) {
|
|||
|
||||
function connectionHandler(options, callback) {
|
||||
const client = mysql.createPool(options);
|
||||
client.getConnection(function (err, connection) {
|
||||
client.getConnection(function(err, connection) {
|
||||
const conn = connection;
|
||||
if (!err) {
|
||||
if (self.debug)
|
||||
|
@ -645,30 +437,27 @@ function generateOptions(settings) {
|
|||
return options;
|
||||
}
|
||||
|
||||
|
||||
SQLConnector.prototype.all = function find(model, filter, options, cb) {
|
||||
const self = this;
|
||||
// Order by id if no order is specified
|
||||
filter = filter || {};
|
||||
const stmt = this.buildSelect(model, filter, options);
|
||||
this.execute(stmt.sql, stmt.params, options, function (err, data) {
|
||||
if (err) {
|
||||
this.execute(stmt.sql, stmt.params, options, function(err, data) {
|
||||
if (err)
|
||||
return cb(err, []);
|
||||
}
|
||||
|
||||
try {
|
||||
const objs = data.map(function (obj) {
|
||||
const objs = data.map(function(obj) {
|
||||
return self.fromRow(model, obj);
|
||||
});
|
||||
if (filter && filter.include) {
|
||||
self.getModelDefinition(model).model.include(
|
||||
objs, filter.include, options, cb,
|
||||
);
|
||||
} else {
|
||||
} else
|
||||
cb(null, objs);
|
||||
}
|
||||
} catch (error) {
|
||||
cb(error, [])
|
||||
cb(error, []);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('Claim createFromSales()', () => {
|
||||
const ticketId = 16;
|
||||
const ticketId = 23;
|
||||
const newSale = [{
|
||||
id: 3,
|
||||
id: 31,
|
||||
instance: 0,
|
||||
quantity: 10
|
||||
}];
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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 originalData = {
|
||||
ticketFk: 3,
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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 original = {
|
||||
ticketFk: 3,
|
||||
|
|
|
@ -10,8 +10,16 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.observe('before save', async ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
//await claimIsEditable(ctx);
|
||||
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);
|
||||
});
|
||||
|
||||
Self.observe('before delete', async ctx => {
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ClaimBeginning",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim",
|
||||
"showField": "quantity"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimBeginning"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "ClaimDevelopment",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimDevelopment"
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
{
|
||||
"name": "ClaimDms",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimDms"
|
||||
}
|
||||
},
|
||||
"allowedContentTypes": [
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/jpg"
|
||||
],
|
||||
"properties": {
|
||||
|
@ -34,4 +30,4 @@
|
|||
"foreignKey": "dmsFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "ClaimEnd",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimEnd"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "ClaimObservation",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimObservation"
|
||||
|
@ -40,4 +36,4 @@
|
|||
"foreignKey": "claimFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ClaimState",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"relation": "claim",
|
||||
"showField": "description"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claimState"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Claim",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClaimLog",
|
||||
"showField": "id"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "claim"
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('checkDuplicatedData', {
|
||||
description: 'Checks if a client has same email, mobile or phone than other client and send an email',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The client id'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
verb: 'GET',
|
||||
path: '/:id/checkDuplicatedData'
|
||||
}
|
||||
});
|
||||
|
||||
Self.checkDuplicatedData = async function(id, options) {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const client = await Self.app.models.Client.findById(id, myOptions);
|
||||
|
||||
const findParams = [];
|
||||
if (client.email) {
|
||||
const emails = client.email.split(',');
|
||||
for (let email of emails)
|
||||
findParams.push({email: email});
|
||||
}
|
||||
|
||||
if (client.phone)
|
||||
findParams.push({phone: client.phone});
|
||||
|
||||
if (client.mobile)
|
||||
findParams.push({mobile: client.mobile});
|
||||
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: findParams},
|
||||
{id: {neq: client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const clientSameData = await Self.findOne(filterObj, myOptions);
|
||||
|
||||
if (clientSameData) {
|
||||
await Self.app.models.Mail.create({
|
||||
receiver: 'direccioncomercial@verdnatura.es',
|
||||
subject: `Cliente con email/teléfono/móvil duplicados`,
|
||||
body: 'El cliente ' + client.id + ' comparte alguno de estos datos con el cliente ' + clientSameData.id +
|
||||
'\n- Email: ' + client.email +
|
||||
'\n- Teléfono: ' + client.phone +
|
||||
'\n- Móvil: ' + client.mobile
|
||||
}, myOptions);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('client checkDuplicated()', () => {
|
||||
it('should send an mail if mobile/phone/email is duplicated', async() => {
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const id = 1110;
|
||||
const mailModel = models.Mail;
|
||||
spyOn(mailModel, 'create');
|
||||
|
||||
await models.Client.checkDuplicatedData(id, options);
|
||||
|
||||
expect(mailModel.create).toHaveBeenCalled();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,52 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('observationEmail', {
|
||||
description: 'Send an email with the observation',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'defaulters',
|
||||
type: ['object'],
|
||||
required: true,
|
||||
description: 'The defaulters to send the email'
|
||||
},
|
||||
{
|
||||
arg: 'observation',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The observation'
|
||||
}],
|
||||
returns: {
|
||||
arg: 'observationEmail'
|
||||
},
|
||||
http: {
|
||||
path: `/observationEmail`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.observationEmail = async(ctx, defaulters, observation, options) => {
|
||||
const models = Self.app.models;
|
||||
const $t = ctx.req.__; // $translate
|
||||
const myOptions = {};
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
for (const defaulter of defaulters) {
|
||||
const user = await models.Account.findById(userId, {fields: ['name']}, myOptions);
|
||||
|
||||
const body = $t('Added observation', {
|
||||
user: user.name,
|
||||
text: observation
|
||||
});
|
||||
|
||||
await models.Mail.create({
|
||||
subject: $t('Comment added to client', {clientFk: defaulter.clientFk}),
|
||||
body: body,
|
||||
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
|
||||
replyTo: `${user.name}@verdnatura.es`
|
||||
}, myOptions);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -2,11 +2,6 @@
|
|||
"name": "Address",
|
||||
"description": "Client addresses",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"showField": "nickname"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "address"
|
||||
|
@ -88,4 +83,4 @@
|
|||
"foreignKey": "customsAgentFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
"name": "ClientContact",
|
||||
"description": "Client phone contacts",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"showField": "name"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientContact"
|
||||
|
@ -33,4 +28,4 @@
|
|||
"foreignKey": "clientFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ClientDms",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model":"ClientLog",
|
||||
"relation": "client",
|
||||
"showField": "dmsFk"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientDms"
|
||||
|
|
|
@ -2,7 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/client/addressesPropagateRe')(Self);
|
||||
require('../methods/client/canBeInvoiced')(Self);
|
||||
require('../methods/client/canCreateTicket')(Self);
|
||||
require('../methods/client/checkDuplicated')(Self);
|
||||
require('../methods/client/confirmTransaction')(Self);
|
||||
require('../methods/client/consumption')(Self);
|
||||
require('../methods/client/createAddress')(Self);
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
"name": "ClientObservation",
|
||||
"description": "Client notes",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientObservation"
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ClientSample",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"showField": "type"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientSample"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Client",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model":"ClientLog",
|
||||
"showField": "id"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "client"
|
||||
|
@ -260,4 +256,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/defaulter/filter')(Self);
|
||||
require('../methods/defaulter/observationEmail')(Self);
|
||||
};
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "Greuge",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"showField": "description"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "greuge"
|
||||
|
@ -58,4 +53,4 @@
|
|||
"foreignKey": "userFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Recovery",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "recovery"
|
||||
|
@ -38,4 +34,4 @@
|
|||
"foreignKey": "clientFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
onSubmit() {
|
||||
return this.$.watcher.submit().then(() => {
|
||||
this.$http.get(`Clients/${this.$params.id}/checkDuplicatedData`);
|
||||
});
|
||||
return this.$.watcher.submit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ export default class Controller extends Section {
|
|||
onSubmit() {
|
||||
return this.$.watcher.submit().then(json => {
|
||||
this.$state.go('client.card.basicData', {id: json.data.id});
|
||||
this.$http.get(`Clients/${this.client.id}/checkDuplicatedData`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
limit="20"
|
||||
order="amount DESC"
|
||||
data="defaulters"
|
||||
on-data-change="$ctrl.reCheck()"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-portal slot="topbar">
|
||||
|
@ -17,22 +18,22 @@
|
|||
</vn-searchbar>
|
||||
</vn-portal>
|
||||
<vn-card>
|
||||
<smart-table
|
||||
<smart-table
|
||||
model="model"
|
||||
options="$ctrl.smartTableOptions"
|
||||
options="$ctrl.smartTableOptions"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
<slot-actions>
|
||||
<div>
|
||||
<div class="totalBox" style="text-align: center;">
|
||||
<h6 translate>Total</h6>
|
||||
<vn-label-value
|
||||
label="Balance due"
|
||||
<vn-label-value
|
||||
label="Balance due"
|
||||
value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
|
||||
</vn-label-value>
|
||||
</div>
|
||||
</div>
|
||||
<div class="vn-pa-md">
|
||||
<vn-button
|
||||
<vn-button
|
||||
ng-show="$ctrl.checked.length > 0"
|
||||
ng-click="notesDialog.show()"
|
||||
name="notesDialog"
|
||||
|
@ -46,7 +47,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th shrink>
|
||||
<vn-multi-check
|
||||
<vn-multi-check
|
||||
model="model">
|
||||
</vn-multi-check>
|
||||
</th>
|
||||
|
@ -56,25 +57,25 @@
|
|||
<th field="salesPersonFk">
|
||||
<span translate>Comercial</span>
|
||||
</th>
|
||||
<th
|
||||
field="amount"
|
||||
<th
|
||||
field="amount"
|
||||
vn-tooltip="Balance due">
|
||||
<span translate>Balance D.</span>
|
||||
</th>
|
||||
<th
|
||||
field="workerFk"
|
||||
<th
|
||||
field="workerFk"
|
||||
vn-tooltip="Worker who made the last observation">
|
||||
<span translate>Author</span>
|
||||
</th>
|
||||
<th field="observation" expand>
|
||||
<span translate>Last observation</span>
|
||||
</th>
|
||||
<th
|
||||
<th
|
||||
vn-tooltip="Last observation date"
|
||||
field="created">
|
||||
<span translate>L. O. Date</span>
|
||||
</th>
|
||||
<th
|
||||
<th
|
||||
vn-tooltip="Credit insurance"
|
||||
field="creditInsurance"
|
||||
shrink>
|
||||
|
@ -88,8 +89,9 @@
|
|||
<tbody>
|
||||
<tr ng-repeat="defaulter in defaulters">
|
||||
<td shrink>
|
||||
<vn-check
|
||||
<vn-check
|
||||
ng-model="defaulter.checked"
|
||||
on-change="$ctrl.saveChecked(defaulter.clientFk)"
|
||||
vn-click-stop>
|
||||
</vn-check>
|
||||
</td>
|
||||
|
@ -150,7 +152,7 @@
|
|||
</vn-client-summary>
|
||||
</vn-popup>
|
||||
|
||||
<!-- Dialog of add notes button -->
|
||||
<!-- Dialog of add notes button -->
|
||||
<vn-dialog
|
||||
vn-id="notesDialog"
|
||||
on-accept="$ctrl.onResponse()">
|
||||
|
@ -160,7 +162,7 @@
|
|||
<vn-horizontal>
|
||||
<vn-textarea vn-one
|
||||
vn-id="message"
|
||||
label="Message"
|
||||
label="Message"
|
||||
ng-model="$ctrl.defaulter.observation"
|
||||
rows="3"
|
||||
required="true"
|
||||
|
|
|
@ -6,6 +6,7 @@ export default class Controller extends Section {
|
|||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.defaulter = {};
|
||||
this.checkedDefaulers = [];
|
||||
|
||||
this.smartTableOptions = {
|
||||
activeButtons: {
|
||||
|
@ -45,11 +46,11 @@ export default class Controller extends Section {
|
|||
},
|
||||
{
|
||||
field: 'created',
|
||||
searchable: false
|
||||
datepicker: true
|
||||
},
|
||||
{
|
||||
field: 'defaulterSinced',
|
||||
searchable: false
|
||||
datepicker: true
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -68,6 +69,19 @@ export default class Controller extends Section {
|
|||
return checkedLines;
|
||||
}
|
||||
|
||||
saveChecked(clientId) {
|
||||
this.checkedDefaulers = this.checkedDefaulers.includes(clientId) ?
|
||||
this.checkedDefaulers.filter(id => id !== clientId) : [...this.checkedDefaulers, clientId];
|
||||
}
|
||||
|
||||
reCheck() {
|
||||
if (!this.$.model.data || !this.checkedDefaulers.length) return;
|
||||
|
||||
this.$.model.data.forEach(defaulter => {
|
||||
defaulter.checked = this.checkedDefaulers.includes(defaulter.clientFk);
|
||||
});
|
||||
}
|
||||
|
||||
getBalanceDueTotal() {
|
||||
this.$http.get('Defaulters/filter')
|
||||
.then(res => {
|
||||
|
@ -109,11 +123,20 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
this.$http.post(`ClientObservations`, params) .then(() => {
|
||||
this.vnApp.showMessage(this.$t('Observation saved!'));
|
||||
this.vnApp.showSuccess(this.$t('Observation saved!'));
|
||||
this.sendMail();
|
||||
this.$state.reload();
|
||||
});
|
||||
}
|
||||
|
||||
sendMail() {
|
||||
const params = {
|
||||
defaulters: this.checked,
|
||||
observation: this.defaulter.observation
|
||||
};
|
||||
this.$http.post(`Defaulters/observationEmail`, params);
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
case 'creditInsurance':
|
||||
|
@ -122,8 +145,25 @@ export default class Controller extends Section {
|
|||
case 'workerFk':
|
||||
case 'salesPersonFk':
|
||||
return {[`d.${param}`]: value};
|
||||
case 'created':
|
||||
return {'d.created': {
|
||||
between: this.dateRange(value)}
|
||||
};
|
||||
case 'defaulterSinced':
|
||||
return {'d.defaulterSinced': {
|
||||
between: this.dateRange(value)}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
dateRange(value) {
|
||||
const minHour = new Date(value);
|
||||
minHour.setHours(0, 0, 0, 0);
|
||||
const maxHour = new Date(value);
|
||||
maxHour.setHours(23, 59, 59, 59);
|
||||
|
||||
return [minHour, maxHour];
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnClientDefaulter', {
|
||||
|
|
|
@ -81,14 +81,15 @@ describe('client defaulter', () => {
|
|||
|
||||
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
$httpBackend.expect('GET', `Defaulters/filter`).respond(200);
|
||||
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
|
||||
$httpBackend.expect('POST', `Defaulters/observationEmail`).respond(200);
|
||||
|
||||
controller.onResponse();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!');
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Observation saved!');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -117,5 +118,62 @@ describe('client defaulter', () => {
|
|||
expect(controller.balanceDueTotal).toEqual(875);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dateRange()', () => {
|
||||
it('should return two dates with the hours at the start and end of the given date', () => {
|
||||
const now = Date.vnNew();
|
||||
|
||||
const today = now.getDate();
|
||||
|
||||
const dateRange = controller.dateRange(now);
|
||||
const start = dateRange[0].toString();
|
||||
const end = dateRange[1].toString();
|
||||
|
||||
expect(start).toContain(today);
|
||||
expect(start).toContain('00:00:00');
|
||||
|
||||
expect(end).toContain(today);
|
||||
expect(end).toContain('23:59:59');
|
||||
});
|
||||
});
|
||||
|
||||
describe('reCheck()', () => {
|
||||
it(`should recheck buys`, () => {
|
||||
controller.$.model.data = [
|
||||
{checked: false, clientFk: 1},
|
||||
{checked: false, clientFk: 2},
|
||||
{checked: false, clientFk: 3},
|
||||
{checked: false, clientFk: 4},
|
||||
];
|
||||
controller.checkedDefaulers = [1, 2];
|
||||
|
||||
controller.reCheck();
|
||||
|
||||
expect(controller.$.model.data[0].checked).toEqual(true);
|
||||
expect(controller.$.model.data[1].checked).toEqual(true);
|
||||
expect(controller.$.model.data[2].checked).toEqual(false);
|
||||
expect(controller.$.model.data[3].checked).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveChecked()', () => {
|
||||
it(`should check buy`, () => {
|
||||
const buyCheck = 3;
|
||||
controller.checkedDefaulers = [1, 2];
|
||||
|
||||
controller.saveChecked(buyCheck);
|
||||
|
||||
expect(controller.checkedDefaulers[2]).toEqual(buyCheck);
|
||||
});
|
||||
|
||||
it(`should uncheck buy`, () => {
|
||||
const buyUncheck = 3;
|
||||
controller.checkedDefaulers = [1, 2, 3];
|
||||
|
||||
controller.saveChecked(buyUncheck);
|
||||
|
||||
expect(controller.checkedDefaulers[2]).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,4 +6,6 @@ Last observation: Última observación
|
|||
L. O. Date: Fecha Ú. O.
|
||||
Last observation date: Fecha última observación
|
||||
Search client: Buscar clientes
|
||||
Worker who made the last observation: Trabajador que ha realizado la última observación
|
||||
Worker who made the last observation: Trabajador que ha realizado la última observación
|
||||
Email sended!: Email enviado!
|
||||
Observation saved!: Observación añadida!
|
||||
|
|
|
@ -2,6 +2,10 @@ import ngModule from '../module';
|
|||
import Section from 'salix/components/section';
|
||||
|
||||
export default class Controller extends Section {
|
||||
$onInit() {
|
||||
this.card.reload();
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
const orgData = this.$.watcher.orgData;
|
||||
delete this.client.despiteOfClient;
|
||||
|
|
|
@ -63,4 +63,4 @@ Consumption: Consumo
|
|||
Compensation Account: Cuenta para compensar
|
||||
Amount to return: Cantidad a devolver
|
||||
Delivered amount: Cantidad entregada
|
||||
Unpaid: Impagado
|
||||
Unpaid: Impagado
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "Buy",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "EntryLog",
|
||||
"relation": "entry",
|
||||
"grabUser": true
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "buy"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "EntryObservation",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "EntryLog",
|
||||
"relation": "entry"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "entryObservation"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Entry",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model":"EntryLog",
|
||||
"grabUser": true
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "entry"
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('negativeBases', {
|
||||
description: 'Find all negative bases',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'from',
|
||||
type: 'date',
|
||||
description: 'From date'
|
||||
},
|
||||
{
|
||||
arg: 'to',
|
||||
type: 'date',
|
||||
description: 'To date'
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/negativeBases`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.negativeBases = async(ctx, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
|
||||
if (!args.from || !args.to)
|
||||
throw new UserError(`Insert a date range`);
|
||||
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket`);
|
||||
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.ticket
|
||||
(KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk
|
||||
FROM ticket t
|
||||
WHERE shipped BETWEEN ? AND ?
|
||||
AND refFk IS NULL`, [args.from, args.to]));
|
||||
stmts.push(`CALL vn.ticket_getTax(NULL)`);
|
||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.filter`);
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.filter
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
co.code company,
|
||||
cou.country,
|
||||
c.id clientId,
|
||||
c.socialName clientSocialName,
|
||||
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
|
||||
negativeBase.taxableBase,
|
||||
negativeBase.ticketFk,
|
||||
c.isActive,
|
||||
c.hasToInvoice,
|
||||
c.isTaxDataChecked,
|
||||
w.id comercialId,
|
||||
CONCAT(w.firstName, ' ', w.lastName) comercialName
|
||||
FROM vn.ticket t
|
||||
JOIN vn.company co ON co.id = t.companyFk
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
JOIN vn.country cou ON cou.id = c.countryFk
|
||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||
LEFT JOIN (
|
||||
SELECT ticketFk, taxableBase
|
||||
FROM tmp.ticketAmount
|
||||
GROUP BY ticketFk
|
||||
HAVING taxableBase < 0
|
||||
) negativeBase ON negativeBase.ticketFk = t.id
|
||||
WHERE t.shipped BETWEEN ? AND ?
|
||||
AND t.refFk IS NULL
|
||||
AND c.typeFk IN ('normal','trust')
|
||||
GROUP BY t.clientFk, negativeBase.taxableBase
|
||||
HAVING amount <> 0`, [args.from, args.to]));
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*
|
||||
FROM tmp.filter f`);
|
||||
|
||||
stmt.merge(conn.makeWhere(args.filter.where));
|
||||
stmt.merge(conn.makeOrderBy(args.filter.order));
|
||||
|
||||
const negativeBasesIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(`DROP TEMPORARY TABLE tmp.filter, tmp.ticket, tmp.ticketTax, tmp.ticketAmount`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
return negativeBasesIndex === 0 ? result : result[negativeBasesIndex];
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
const {toCSV} = require('vn-loopback/util/csv');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('negativeBasesCsv', {
|
||||
description: 'Returns the negative bases as .csv',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'negativeBases',
|
||||
type: ['object'],
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'from',
|
||||
type: 'date',
|
||||
description: 'From date'
|
||||
},
|
||||
{
|
||||
arg: 'to',
|
||||
type: 'date',
|
||||
description: 'To date'
|
||||
}],
|
||||
returns: [
|
||||
{
|
||||
arg: 'body',
|
||||
type: 'file',
|
||||
root: true
|
||||
}, {
|
||||
arg: 'Content-Type',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}, {
|
||||
arg: 'Content-Disposition',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: '/negativeBasesCsv',
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.negativeBasesCsv = async ctx => {
|
||||
const args = ctx.args;
|
||||
const content = toCSV(args.negativeBases);
|
||||
|
||||
return [
|
||||
content,
|
||||
'text/csv',
|
||||
`attachment; filename="negative-bases-${new Date(args.from).toLocaleDateString()}-${new Date(args.to).toLocaleDateString()}.csv"`
|
||||
];
|
||||
};
|
||||
};
|
|
@ -1,6 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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() => {
|
||||
const userId = 1;
|
||||
const ctx = {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('invoiceIn negativeBases()', () => {
|
||||
it('should return all negative bases in a date range', async() => {
|
||||
const tx = await models.InvoiceIn.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const ctx = {
|
||||
args: {
|
||||
from: new Date().setMonth(new Date().getMonth() - 12),
|
||||
to: new Date(),
|
||||
filter: {}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await models.InvoiceIn.negativeBases(ctx, options);
|
||||
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error if a date range is not in args', async() => {
|
||||
let error;
|
||||
const tx = await models.InvoiceIn.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const ctx = {
|
||||
args: {
|
||||
filter: {}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await models.InvoiceIn.negativeBases(ctx, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Insert a date range`);
|
||||
});
|
||||
});
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "InvoiceInTax",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "InvoiceInLog",
|
||||
"relation": "invoiceIn"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "invoiceInTax"
|
||||
|
@ -55,4 +51,4 @@
|
|||
"foreignKey": "transactionTypeSageFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,6 @@ module.exports = Self => {
|
|||
require('../methods/invoice-in/invoiceInPdf')(Self);
|
||||
require('../methods/invoice-in/invoiceInEmail')(Self);
|
||||
require('../methods/invoice-in/getSerial')(Self);
|
||||
require('../methods/invoice-in/negativeBases')(Self);
|
||||
require('../methods/invoice-in/negativeBasesCsv')(Self);
|
||||
};
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
{
|
||||
"name": "InvoiceIn",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "InvoiceInLog"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "invoiceIn"
|
||||
|
|
|
@ -15,3 +15,4 @@ import './create';
|
|||
import './log';
|
||||
import './serial';
|
||||
import './serial-search-panel';
|
||||
import './negative-bases';
|
||||
|
|
|
@ -24,3 +24,4 @@ Show agricultural receipt as PDF: Ver recibo agrícola como PDF
|
|||
Send agricultural receipt as PDF: Enviar recibo agrícola como PDF
|
||||
New InvoiceIn: Nueva Factura
|
||||
Days ago: Últimos días
|
||||
Negative bases: Bases negativas
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="InvoiceIns/negativeBases"
|
||||
auto-load="true"
|
||||
params="$ctrl.params">
|
||||
</vn-crud-model>
|
||||
<vn-portal slot="topbar">
|
||||
</vn-portal>
|
||||
<vn-card>
|
||||
<smart-table
|
||||
model="model"
|
||||
options="$ctrl.smartTableOptions"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
<slot-actions>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="From"
|
||||
ng-model="$ctrl.params.from"
|
||||
on-change="model.refresh()">
|
||||
</vn-date-picker>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="To"
|
||||
ng-model="$ctrl.params.to"
|
||||
on-change="model.refresh()">
|
||||
</vn-date-picker>
|
||||
<vn-button
|
||||
disabled="model._orgData.length == 0"
|
||||
icon="download"
|
||||
ng-click="$ctrl.downloadCSV()"
|
||||
vn-tooltip="Download as CSV">
|
||||
</vn-button>
|
||||
</slot-actions>
|
||||
<slot-table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th field="company">
|
||||
<span translate>Company</span>
|
||||
</th>
|
||||
<th field="country">
|
||||
<span translate>Country</span>
|
||||
</th>
|
||||
<th field="clientId">
|
||||
<span translate>Id Client</span>
|
||||
</th>
|
||||
<th field="clientSocialName">
|
||||
<span translate>Client</span>
|
||||
</th>
|
||||
<th field="amount">
|
||||
<span translate>Amount</span>
|
||||
</th>
|
||||
<th field="taxableBase">
|
||||
<span translate>Base</span>
|
||||
</th>
|
||||
<th field="ticketFk">
|
||||
<span translate>Id Ticket</span>
|
||||
</th>
|
||||
<th field="isActive">
|
||||
<span translate>Active</span>
|
||||
</th>
|
||||
<th field="hasToInvoice">
|
||||
<span translate>Has To Invoice</span>
|
||||
</th>
|
||||
<th field="isTaxDataChecked">
|
||||
<span translate>Verified data</span>
|
||||
</th>
|
||||
<th field="comercialName">
|
||||
<span translate>Comercial</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="client in model.data">
|
||||
<td>{{client.company | dashIfEmpty}}</td>
|
||||
<td>{{client.country | dashIfEmpty}}</td>
|
||||
<td>
|
||||
<vn-span
|
||||
class="link"
|
||||
ng-click="clientDescriptor.show($event, client.clientId)">
|
||||
{{::client.clientId | dashIfEmpty}}
|
||||
</vn-span>
|
||||
</td>
|
||||
<td>{{client.clientSocialName | dashIfEmpty}}</td>
|
||||
<td>{{client.amount | currency: 'EUR':2 | dashIfEmpty}}</td>
|
||||
<td>{{client.taxableBase | dashIfEmpty}}</td>
|
||||
<td>
|
||||
<vn-span
|
||||
class="link"
|
||||
ng-click="ticketDescriptor.show($event, client.ticketFk)">
|
||||
{{::client.ticketFk | dashIfEmpty}}
|
||||
</vn-span>
|
||||
</td>
|
||||
<td>
|
||||
<vn-check
|
||||
disabled="true"
|
||||
ng-model="client.isActive">
|
||||
</vn-check>
|
||||
</td>
|
||||
<td>
|
||||
<vn-check
|
||||
disabled="true"
|
||||
ng-model="client.hasToInvoice">
|
||||
</vn-check>
|
||||
</td>
|
||||
<td>
|
||||
<vn-check
|
||||
disabled="true"
|
||||
ng-model="client.isTaxDataChecked">
|
||||
</vn-check>
|
||||
</td>
|
||||
<td>
|
||||
<vn-span
|
||||
class="link"
|
||||
ng-click="workerDescriptor.show($event, client.comercialId)">
|
||||
{{::client.comercialName | dashIfEmpty}}
|
||||
</vn-span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</slot-table>
|
||||
</smart-table>
|
||||
</vn-card>
|
||||
<vn-ticket-descriptor-popover
|
||||
vn-id="ticket-descriptor">
|
||||
</vn-ticket-descriptor-popover>
|
||||
<vn-client-descriptor-popover
|
||||
vn-id="client-descriptor">
|
||||
</vn-client-descriptor-popover>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="worker-descriptor">
|
||||
</vn-worker-descriptor-popover>
|
|
@ -0,0 +1,84 @@
|
|||
import ngModule from '../module';
|
||||
import Section from 'salix/components/section';
|
||||
import './style.scss';
|
||||
|
||||
export default class Controller extends Section {
|
||||
constructor($element, $, vnReport) {
|
||||
super($element, $);
|
||||
|
||||
this.vnReport = vnReport;
|
||||
const now = new Date();
|
||||
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||
this.params = {
|
||||
from: firstDayOfMonth,
|
||||
to: lastDayOfMonth
|
||||
};
|
||||
this.$checkAll = false;
|
||||
|
||||
this.smartTableOptions = {
|
||||
activeButtons: {
|
||||
search: true,
|
||||
}, columns: [
|
||||
{
|
||||
field: 'isActive',
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
field: 'hasToInvoice',
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
field: 'isTaxDataChecked',
|
||||
searchable: false
|
||||
},
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
case 'company':
|
||||
return {'company': value};
|
||||
case 'country':
|
||||
return {'country': value};
|
||||
case 'clientId':
|
||||
return {'clientId': value};
|
||||
case 'clientSocialName':
|
||||
return {'clientSocialName': value};
|
||||
case 'amount':
|
||||
return {'amount': value};
|
||||
case 'taxableBase':
|
||||
return {'taxableBase': value};
|
||||
case 'ticketFk':
|
||||
return {'ticketFk': value};
|
||||
case 'comercialName':
|
||||
return {'comercialName': value};
|
||||
}
|
||||
}
|
||||
|
||||
downloadCSV() {
|
||||
const data = [];
|
||||
this.$.model._orgData.forEach(element => {
|
||||
data.push(Object.keys(element).map(key => {
|
||||
return {newName: this.$t(key), value: element[key]};
|
||||
}).filter(item => item !== null)
|
||||
.reduce((result, item) => {
|
||||
result[item.newName] = item.value;
|
||||
return result;
|
||||
}, {}));
|
||||
});
|
||||
this.vnReport.show('InvoiceIns/negativeBasesCsv', {
|
||||
negativeBases: data,
|
||||
from: this.params.from,
|
||||
to: this.params.to
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', 'vnReport'];
|
||||
|
||||
ngModule.vnComponent('vnNegativeBases', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
Has To Invoice: Facturar
|
||||
Download as CSV: Descargar como CSV
|
||||
company: Compañía
|
||||
country: País
|
||||
clientId: Id Cliente
|
||||
clientSocialName: Cliente
|
||||
amount: Importe
|
||||
taxableBase: Base
|
||||
ticketFk: Id Ticket
|
||||
isActive: Activo
|
||||
hasToInvoice: Facturar
|
||||
isTaxDataChecked: Datos comprobados
|
||||
comercialId: Id Comercial
|
||||
comercialName: Comercial
|
|
@ -0,0 +1,10 @@
|
|||
@import "./variables";
|
||||
|
||||
vn-negative-bases {
|
||||
vn-date-picker{
|
||||
padding-right: 5%;
|
||||
}
|
||||
slot-actions{
|
||||
align-items: center;
|
||||
}
|
||||
}
|
|
@ -9,14 +9,9 @@
|
|||
],
|
||||
"menus": {
|
||||
"main": [
|
||||
{
|
||||
"state": "invoiceIn.index",
|
||||
"icon": "icon-invoice-in"
|
||||
},
|
||||
{
|
||||
"state": "invoiceIn.serial",
|
||||
"icon": "icon-invoice-in"
|
||||
}
|
||||
{ "state": "invoiceIn.index", "icon": "icon-invoice-in"},
|
||||
{ "state": "invoiceIn.serial", "icon": "icon-invoice-in"},
|
||||
{ "state": "invoiceIn.negative-bases", "icon": "icon-ticket"}
|
||||
],
|
||||
"card": [
|
||||
{
|
||||
|
@ -58,6 +53,15 @@
|
|||
"administrative"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "/negative-bases",
|
||||
"state": "invoiceIn.negative-bases",
|
||||
"component": "vn-negative-bases",
|
||||
"description": "Negative bases",
|
||||
"acl": [
|
||||
"administrative"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "/serial",
|
||||
"state": "invoiceIn.serial",
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('editFixedPrice', {
|
||||
description: 'Updates a column for one or more fixed price',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'field',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: `the column to edit`
|
||||
},
|
||||
{
|
||||
arg: 'newValue',
|
||||
type: 'any',
|
||||
required: true,
|
||||
description: `The new value to save`
|
||||
},
|
||||
{
|
||||
arg: 'lines',
|
||||
type: ['object'],
|
||||
required: true,
|
||||
description: `the buys which will be modified`
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/editFixedPrice`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.editFixedPrice = async(ctx, field, newValue, lines, filter, options) => {
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
let modelName;
|
||||
let identifier;
|
||||
|
||||
switch (field) {
|
||||
case 'hasMinPrice':
|
||||
case 'minPrice':
|
||||
modelName = 'Item';
|
||||
identifier = 'itemFk';
|
||||
break;
|
||||
case 'rate2':
|
||||
case 'rate3':
|
||||
case 'started':
|
||||
case 'ended':
|
||||
case 'warehouseFk':
|
||||
modelName = 'FixedPrice';
|
||||
identifier = 'id';
|
||||
}
|
||||
|
||||
const models = Self.app.models;
|
||||
const model = models[modelName];
|
||||
try {
|
||||
const promises = [];
|
||||
const value = {};
|
||||
value[field] = newValue;
|
||||
|
||||
if (filter) {
|
||||
filter = {where: filter};
|
||||
lines = await models.FixedPrice.filter(ctx, filter, myOptions);
|
||||
}
|
||||
|
||||
const targets = lines.map(line => {
|
||||
return line[identifier];
|
||||
});
|
||||
for (let target of targets)
|
||||
promises.push(model.upsertWithWhere({id: target}, value, myOptions));
|
||||
|
||||
const result = await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -184,8 +184,7 @@ module.exports = Self => {
|
|||
}
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
||||
const fixedPriceIndex = stmts.push(stmt) - 1;
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Item editFixedPrice()', () => {
|
||||
it('should change the value of a given column for the selected buys', async() => {
|
||||
const tx = await models.FixedPrice.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const ctx = {
|
||||
args: {
|
||||
search: '1'
|
||||
},
|
||||
req: {accessToken: {userId: 1}}
|
||||
};
|
||||
|
||||
const [original] = await models.FixedPrice.filter(ctx, null, options);
|
||||
|
||||
const field = 'rate2';
|
||||
const newValue = 99;
|
||||
const lines = [{itemFk: original.itemFk, id: original.id}];
|
||||
|
||||
await models.FixedPrice.editFixedPrice(ctx, field, newValue, lines, null, options);
|
||||
|
||||
const [result] = await models.FixedPrice.filter(ctx, null, options);
|
||||
|
||||
expect(result[field]).toEqual(newValue);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should change the value of a given column for filter', async() => {
|
||||
const tx = await models.FixedPrice.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const filter = {'it.categoryFk': 1};
|
||||
const ctx = {
|
||||
args: {
|
||||
filter: filter
|
||||
},
|
||||
req: {accessToken: {userId: 1}}
|
||||
};
|
||||
|
||||
const field = 'rate2';
|
||||
const newValue = 88;
|
||||
|
||||
await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter, options);
|
||||
|
||||
const [result] = await models.FixedPrice.filter(ctx, filter, options);
|
||||
|
||||
expect(result[field]).toEqual(newValue);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -42,7 +42,7 @@ describe('upsertFixedPrice()', () => {
|
|||
|
||||
delete ctx.args.started;
|
||||
delete ctx.args.ended;
|
||||
ctx.args.hasMinPrice = true;
|
||||
ctx.args.hasMinPrice = false;
|
||||
|
||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||
|
||||
|
@ -74,7 +74,7 @@ describe('upsertFixedPrice()', () => {
|
|||
|
||||
delete ctx.args.started;
|
||||
delete ctx.args.ended;
|
||||
ctx.args.hasMinPrice = false;
|
||||
ctx.args.hasMinPrice = true;
|
||||
|
||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||
|
||||
|
@ -105,7 +105,7 @@ describe('upsertFixedPrice()', () => {
|
|||
rate2: rate2,
|
||||
rate3: firstRate3,
|
||||
minPrice: 0,
|
||||
hasMinPrice: false
|
||||
hasMinPrice: true
|
||||
}};
|
||||
|
||||
// create new fixed price
|
||||
|
|
|
@ -87,7 +87,7 @@ module.exports = Self => {
|
|||
|
||||
await targetItem.updateAttributes({
|
||||
minPrice: args.minPrice,
|
||||
hasMinPrice: args.minPrice ? true : false
|
||||
hasMinPrice: args.hasMinPrice
|
||||
}, myOptions);
|
||||
|
||||
const itemFields = [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const axios = require('axios');
|
||||
const uuid = require('uuid');
|
||||
const fs = require('fs/promises');
|
||||
const { createWriteStream } = require('fs');
|
||||
const {createWriteStream} = require('fs');
|
||||
const path = require('path');
|
||||
const gm = require('gm');
|
||||
|
||||
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.download = async () => {
|
||||
Self.download = async() => {
|
||||
const models = Self.app.models;
|
||||
const tempContainer = await models.TempContainer.container(
|
||||
'salix-image'
|
||||
|
@ -32,13 +32,13 @@ module.exports = Self => {
|
|||
let tempFilePath;
|
||||
let queueRow;
|
||||
try {
|
||||
const myOptions = { transaction: tx };
|
||||
const myOptions = {transaction: tx};
|
||||
|
||||
queueRow = await Self.findOne(
|
||||
{
|
||||
fields: ['id', 'itemFk', 'url', 'attempts'],
|
||||
where: {
|
||||
url: { neq: null },
|
||||
url: {neq: null},
|
||||
attempts: {
|
||||
lt: maxAttempts,
|
||||
},
|
||||
|
@ -59,7 +59,7 @@ module.exports = Self => {
|
|||
'model',
|
||||
'property',
|
||||
],
|
||||
where: { name: collectionName },
|
||||
where: {name: collectionName},
|
||||
include: {
|
||||
relation: 'sizes',
|
||||
scope: {
|
||||
|
@ -116,16 +116,16 @@ module.exports = Self => {
|
|||
const collectionDir = path.join(rootPath, collectionName);
|
||||
|
||||
// To max size
|
||||
const { maxWidth, maxHeight } = collection;
|
||||
const {maxWidth, maxHeight} = collection;
|
||||
const fullSizePath = path.join(collectionDir, 'full');
|
||||
const toFullSizePath = `${fullSizePath}/${fileName}`;
|
||||
|
||||
await fs.mkdir(fullSizePath, { recursive: true });
|
||||
await fs.mkdir(fullSizePath, {recursive: true});
|
||||
await new Promise((resolve, reject) => {
|
||||
gm(tempFilePath)
|
||||
.resize(maxWidth, maxHeight, '>')
|
||||
.setFormat('png')
|
||||
.write(toFullSizePath, function (err) {
|
||||
.write(toFullSizePath, function(err) {
|
||||
if (err) reject(err);
|
||||
if (!err) resolve();
|
||||
});
|
||||
|
@ -133,12 +133,12 @@ module.exports = Self => {
|
|||
|
||||
// To collection sizes
|
||||
for (const size of collection.sizes()) {
|
||||
const { width, height } = size;
|
||||
const {width, height} = size;
|
||||
|
||||
const sizePath = path.join(collectionDir, `${width}x${height}`);
|
||||
const toSizePath = `${sizePath}/${fileName}`;
|
||||
|
||||
await fs.mkdir(sizePath, { recursive: true });
|
||||
await fs.mkdir(sizePath, {recursive: true});
|
||||
await new Promise((resolve, reject) => {
|
||||
const gmInstance = gm(tempFilePath);
|
||||
|
||||
|
@ -153,7 +153,7 @@ module.exports = Self => {
|
|||
|
||||
gmInstance
|
||||
.setFormat('png')
|
||||
.write(toSizePath, function (err) {
|
||||
.write(toSizePath, function(err) {
|
||||
if (err) reject(err);
|
||||
if (!err) resolve();
|
||||
});
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
const https = require('https');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const uuid = require('uuid');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('downloadImages', {
|
||||
description: 'Returns last entries',
|
||||
accessType: 'WRITE',
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/downloadImages`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.downloadImages = async() => {
|
||||
const models = Self.app.models;
|
||||
const container = await models.TempContainer.container('salix-image');
|
||||
const tempPath = path.join(container.client.root, container.name);
|
||||
const maxAttempts = 3;
|
||||
|
||||
const images = await Self.find({
|
||||
where: {attempts: {eq: maxAttempts}}
|
||||
});
|
||||
|
||||
for (let image of images) {
|
||||
const currentStamp = Date.vnNew().getTime();
|
||||
const updatedStamp = image.updated.getTime();
|
||||
const graceTime = Math.abs(currentStamp - updatedStamp);
|
||||
const maxTTL = 3600 * 48 * 1000; // 48 hours in ms;
|
||||
|
||||
if (graceTime >= maxTTL)
|
||||
await Self.destroyById(image.itemFk);
|
||||
}
|
||||
|
||||
download();
|
||||
|
||||
async function download() {
|
||||
const image = await Self.findOne({
|
||||
where: {url: {neq: null}, attempts: {lt: maxAttempts}},
|
||||
order: 'priority, attempts, updated'
|
||||
});
|
||||
|
||||
if (!image) return;
|
||||
|
||||
const fileName = `${uuid.v4()}.png`;
|
||||
const filePath = path.join(tempPath, fileName);
|
||||
const imageUrl = image.url.replace('http://', 'https://');
|
||||
|
||||
https.get(imageUrl, async response => {
|
||||
if (response.statusCode != 200) {
|
||||
const error = new Error(`Could not download the image. Status code ${response.statusCode}`);
|
||||
|
||||
return await errorHandler(image.itemFk, error, filePath);
|
||||
}
|
||||
|
||||
const writeStream = fs.createWriteStream(filePath);
|
||||
writeStream.on('open', () => response.pipe(writeStream));
|
||||
writeStream.on('error', async error =>
|
||||
await errorHandler(image.itemFk, error, filePath));
|
||||
writeStream.on('finish', () => writeStream.end());
|
||||
|
||||
writeStream.on('close', async function() {
|
||||
try {
|
||||
await models.Image.registerImage('catalog', filePath, fileName, image.itemFk);
|
||||
await image.destroy();
|
||||
|
||||
download();
|
||||
} catch (error) {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
}
|
||||
});
|
||||
}).on('error', async error => {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
});
|
||||
}
|
||||
|
||||
async function errorHandler(rowId, error, filePath) {
|
||||
try {
|
||||
const row = await Self.findById(rowId);
|
||||
|
||||
if (!row) return;
|
||||
|
||||
if (row.attempts < maxAttempts) {
|
||||
await row.updateAttributes({
|
||||
error: error,
|
||||
attempts: row.attempts + 1,
|
||||
updated: Date.vnNew()
|
||||
});
|
||||
}
|
||||
|
||||
if (filePath && fs.existsSync(filePath))
|
||||
await fs.unlink(filePath);
|
||||
|
||||
download();
|
||||
} catch (err) {
|
||||
throw new Error(`Image download failed: ${err}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,6 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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() => {
|
||||
const tx = await models.Item.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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() => {
|
||||
const tx = await models.Item.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
|
|
@ -2,4 +2,5 @@ module.exports = Self => {
|
|||
require('../methods/fixed-price/filter')(Self);
|
||||
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
||||
require('../methods/fixed-price/getRate2')(Self);
|
||||
require('../methods/fixed-price/editFixedPrice')(Self);
|
||||
};
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ItemBarcode",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ItemLog",
|
||||
"relation": "item",
|
||||
"showField": "code"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "itemBarcode"
|
||||
|
@ -27,6 +22,6 @@
|
|||
"type": "belongsTo",
|
||||
"model": "Item",
|
||||
"foreignKey": "itemFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "ItemBotanical",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ItemLog",
|
||||
"relation": "item"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "itemBotanical"
|
||||
|
@ -34,4 +30,4 @@
|
|||
"foreignKey": "specieFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"isChecked": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ItemTag",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ItemLog",
|
||||
"relation": "item",
|
||||
"showField": "value"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "itemTag"
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "ItemTaxCountry",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ItemLog",
|
||||
"relation": "item",
|
||||
"showField": "countryFk"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "itemTaxCountry"
|
||||
|
@ -47,4 +42,4 @@
|
|||
"foreignKey": "taxClassFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
"name": "Item",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ItemLog",
|
||||
"showField": "id",
|
||||
"grabUser": true
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "item"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="FixedPrices/filter"
|
||||
user-params="::$ctrl.filterParams"
|
||||
limit="20"
|
||||
data="prices"
|
||||
order="itemFk"
|
||||
|
@ -17,6 +18,8 @@
|
|||
auto-state="false"
|
||||
panel="vn-fixed-price-search-panel"
|
||||
info="Search prices by item ID or code"
|
||||
suggested-filter="$ctrl.filterParams"
|
||||
filter="$ctrl.filterParams"
|
||||
placeholder="Search fixed prices"
|
||||
model="model">
|
||||
</vn-searchbar>
|
||||
|
@ -31,15 +34,21 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th shrink>
|
||||
<vn-multi-check
|
||||
model="model"
|
||||
checked="$ctrl.checkAll"
|
||||
check-field="checked"
|
||||
check-dummy-enabled="true"
|
||||
checked-dummy-count="$ctrl.checkedDummyCount">
|
||||
</vn-multi-check>
|
||||
</th>
|
||||
<th field="itemFk">
|
||||
<span translate>Item ID</span>
|
||||
</th>
|
||||
<th field="name">
|
||||
<span translate>Description</span>
|
||||
</th>
|
||||
<th field="warehouseFk">
|
||||
<span translate>Warehouse</span>
|
||||
</th>
|
||||
<th
|
||||
field="rate2">
|
||||
<span translate>Grouping price</span>
|
||||
|
@ -57,13 +66,24 @@
|
|||
<th field="ended">
|
||||
<span translate>Ended</span>
|
||||
</th>
|
||||
<th field="warehouseFk">
|
||||
<span translate>Warehouse</span>
|
||||
</th>
|
||||
<th shrink></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="price in prices">
|
||||
<td>
|
||||
<vn-check
|
||||
ng-model="price.checked"
|
||||
on-change="$ctrl.saveChecked(price.id)"
|
||||
vn-click-stop>
|
||||
</vn-check>
|
||||
</td>
|
||||
<td shrink-field>
|
||||
<vn-autocomplete
|
||||
vn-id="itemFk"
|
||||
class="dense"
|
||||
url="Items/withName"
|
||||
ng-model="price.itemFk"
|
||||
|
@ -88,7 +108,7 @@
|
|||
ng-if="price.itemFk"
|
||||
ng-click="itemDescriptor.show($event, price.itemFk)"
|
||||
class="link">
|
||||
{{price.name}}
|
||||
{{itemFk.selection.name}}
|
||||
</span>
|
||||
<vn-one ng-if="price.subName">
|
||||
<h3 title="{{price.subName}}">{{price.subName}}</h3>
|
||||
|
@ -100,18 +120,11 @@
|
|||
tabindex="-1">
|
||||
</vn-fetched-tags>
|
||||
</td>
|
||||
<td shrink-field-expand>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="price.warehouseFk"
|
||||
data="warehouses"
|
||||
on-change="$ctrl.upsertPrice(price)"
|
||||
tabindex="2">
|
||||
</vn-autocomplete>
|
||||
</td>
|
||||
<td shrink-field>
|
||||
<vn-td-editable number>
|
||||
<text>{{price.rate2 | currency: 'EUR':2}}</text>
|
||||
<text>
|
||||
<strong>{{price.rate2 | currency: 'EUR':2}}</strong>
|
||||
</text>
|
||||
<field>
|
||||
<vn-input-number
|
||||
class="dense"
|
||||
|
@ -125,7 +138,9 @@
|
|||
</td>
|
||||
<td shrink-field>
|
||||
<vn-td-editable number>
|
||||
<text>{{price.rate3 | currency: 'EUR':2}}</text>
|
||||
<text>
|
||||
<strong>{{price.rate3 | currency: 'EUR':2}}</strong>
|
||||
</text>
|
||||
<field>
|
||||
<vn-input-number
|
||||
class="dense"
|
||||
|
@ -140,28 +155,42 @@
|
|||
<td shrink-field-expand class="minPrice">
|
||||
<vn-check
|
||||
vn-one
|
||||
ng-model="price.hasMinPrice">
|
||||
ng-model="price.hasMinPrice"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-check>
|
||||
<vn-input-number
|
||||
disabled="!price.hasMinPrice"
|
||||
ng-class="{inactive: !price.hasMinPrice}"
|
||||
ng-model="price.minPrice"
|
||||
on-change="$ctrl.upsertPrice(price)"
|
||||
step="0.01">
|
||||
</vn-input-number>
|
||||
</td>
|
||||
<td shrink-date>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
ng-model="price.started"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
<vn-chip class="chip {{$ctrl.isBigger(price.started)}} transparent">
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
ng-model="price.started"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
</vn-chip>
|
||||
</td>
|
||||
<td shrink-date>
|
||||
<vn-date-picker
|
||||
<vn-chip class="chip {{$ctrl.isLower(price.ended)}} transparent">
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
ng-model="price.ended"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
</vn-chip>
|
||||
</td>
|
||||
<td expand>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="price.ended"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
ng-model="price.warehouseFk"
|
||||
data="warehouses"
|
||||
on-change="$ctrl.upsertPrice(price)"
|
||||
tabindex="2">
|
||||
</vn-autocomplete>
|
||||
</td>
|
||||
<td shrink>
|
||||
<vn-icon-button
|
||||
|
@ -185,6 +214,69 @@
|
|||
</smart-table>
|
||||
</vn-card>
|
||||
</div>
|
||||
|
||||
<div fixed-bottom-right>
|
||||
<vn-vertical style="align-items: center;">
|
||||
<vn-button class="round sm vn-mb-sm"
|
||||
icon="edit"
|
||||
ng-show="$ctrl.totalChecked > 0"
|
||||
ng-click="edit.show($event)"
|
||||
vn-tooltip="Edit fixed price(s)"
|
||||
tooltip-position="left">
|
||||
</vn-button>
|
||||
</vn-vertical>
|
||||
</div>
|
||||
<vn-dialog class="edit"
|
||||
vn-id="edit"
|
||||
on-accept="$ctrl.onEditAccept()"
|
||||
on-close="$ctrl.editedColumn = null">
|
||||
<tpl-body style="width: 400px;">
|
||||
<span translate>Edit</span>
|
||||
<span class="countLines">
|
||||
{{::$ctrl.totalChecked}}
|
||||
</span>
|
||||
<span translate>buy(s)</span>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="$ctrl.editedColumn.field"
|
||||
data="$ctrl.columns"
|
||||
value-field="field"
|
||||
show-field="displayName"
|
||||
label="Field to edit">
|
||||
</vn-autocomplete>
|
||||
<vn-input-number
|
||||
vn-one
|
||||
ng-if="$ctrl.editedColumn.field == 'rate2' || $ctrl.editedColumn.field == 'rate3' || $ctrl.editedColumn.field == 'minPrice'"
|
||||
label="Value"
|
||||
ng-model="$ctrl.editedColumn.newValue">
|
||||
</vn-input-number>
|
||||
<vn-check
|
||||
vn-one
|
||||
ng-if="$ctrl.editedColumn.field == 'hasMinPrice'"
|
||||
ng-model="$ctrl.editedColumn.newValue">
|
||||
</vn-check>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
ng-if="$ctrl.editedColumn.field == 'started' || $ctrl.editedColumn.field == 'ended'"
|
||||
label="Date"
|
||||
ng-model="$ctrl.editedColumn.newValue">
|
||||
</vn-date-picker>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-if="$ctrl.editedColumn.field == 'warehouseFk'"
|
||||
label="Warehouse"
|
||||
ng-model="$ctrl.editedColumn.newValue"
|
||||
data="warehouses">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
|
||||
<vn-item-descriptor-popover
|
||||
vn-id="item-descriptor"
|
||||
warehouse-fk="$ctrl.vnConfig.warehouseFk">
|
||||
|
|
|
@ -5,6 +5,9 @@ import './style.scss';
|
|||
export default class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.editedColumn;
|
||||
this.checkAll = false;
|
||||
this.checkedFixedPrices = [];
|
||||
|
||||
this.smartTableOptions = {
|
||||
activeButtons: {
|
||||
|
@ -30,13 +33,146 @@ export default class Controller extends Section {
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
this.filterParams = {
|
||||
warehouseFk: this.vnConfig.warehouseFk
|
||||
};
|
||||
}
|
||||
|
||||
getFilterParams() {
|
||||
return {
|
||||
warehouseFk: this.vnConfig.warehouseFk
|
||||
};
|
||||
}
|
||||
|
||||
get columns() {
|
||||
if (this._columns) return this._columns;
|
||||
|
||||
this._columns = [
|
||||
{field: 'rate2', displayName: this.$t('Grouping price')},
|
||||
{field: 'rate3', displayName: this.$t('Packing price')},
|
||||
{field: 'hasMinPrice', displayName: this.$t('Has min price')},
|
||||
{field: 'minPrice', displayName: this.$t('Min price')},
|
||||
{field: 'started', displayName: this.$t('Started')},
|
||||
{field: 'ended', displayName: this.$t('Ended')},
|
||||
{field: 'warehouseFk', displayName: this.$t('Warehouse')}
|
||||
];
|
||||
|
||||
return this._columns;
|
||||
}
|
||||
|
||||
get checked() {
|
||||
const fixedPrices = this.$.model.data || [];
|
||||
const checkedBuys = [];
|
||||
for (let fixedPrice of fixedPrices) {
|
||||
if (fixedPrice.checked)
|
||||
checkedBuys.push(fixedPrice);
|
||||
}
|
||||
|
||||
return checkedBuys;
|
||||
}
|
||||
|
||||
uncheck() {
|
||||
this.checkAll = false;
|
||||
this.checkedFixedPrices = [];
|
||||
}
|
||||
|
||||
get totalChecked() {
|
||||
if (this.checkedDummyCount)
|
||||
return this.checkedDummyCount;
|
||||
|
||||
return this.checked.length;
|
||||
}
|
||||
|
||||
saveChecked(fixedPriceId) {
|
||||
const index = this.checkedFixedPrices.indexOf(fixedPriceId);
|
||||
if (index !== -1)
|
||||
return this.checkedFixedPrices.splice(index, 1);
|
||||
return this.checkedFixedPrices.push(fixedPriceId);
|
||||
}
|
||||
|
||||
reCheck() {
|
||||
if (!this.$.model.data) return;
|
||||
if (!this.checkedFixedPrices.length) return;
|
||||
|
||||
this.$.model.data.forEach(fixedPrice => {
|
||||
if (this.checkedFixedPrices.includes(fixedPrice.id))
|
||||
fixedPrice.checked = true;
|
||||
});
|
||||
}
|
||||
|
||||
onEditAccept() {
|
||||
const rowsToEdit = [];
|
||||
for (let row of this.checked)
|
||||
rowsToEdit.push({id: row.id, itemFk: row.itemFk});
|
||||
|
||||
const data = {
|
||||
field: this.editedColumn.field,
|
||||
newValue: this.editedColumn.newValue,
|
||||
lines: rowsToEdit
|
||||
};
|
||||
|
||||
if (this.checkedDummyCount && this.checkedDummyCount > 0) {
|
||||
const params = {};
|
||||
if (this.$.model.userParams) {
|
||||
const userParams = this.$.model.userParams;
|
||||
for (let param in userParams) {
|
||||
let newParam = this.exprBuilder(param, userParams[param]);
|
||||
if (!newParam)
|
||||
newParam = {[param]: userParams[param]};
|
||||
Object.assign(params, newParam);
|
||||
}
|
||||
}
|
||||
if (this.$.model.userFilter)
|
||||
Object.assign(params, this.$.model.userFilter.where);
|
||||
|
||||
data.filter = params;
|
||||
}
|
||||
|
||||
return this.$http.post('FixedPrices/editFixedPrice', data)
|
||||
.then(() => {
|
||||
this.uncheck();
|
||||
this.$.model.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
isBigger(date) {
|
||||
let today = Date.vnNew();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
date = new Date(date);
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
const timeDifference = today - date;
|
||||
if (timeDifference < 0) return 'warning';
|
||||
}
|
||||
|
||||
isLower(date) {
|
||||
let today = Date.vnNew();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
date = new Date(date);
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
const timeDifference = today - date;
|
||||
if (timeDifference > 0) return 'warning';
|
||||
}
|
||||
|
||||
add() {
|
||||
if (!this.$.model.data || this.$.model.data.length == 0) {
|
||||
this.$.model.data = [];
|
||||
this.$.model.proxiedData = [];
|
||||
this.$.model.insert({});
|
||||
|
||||
const today = Date.vnNew();
|
||||
|
||||
const millisecsInDay = 86400000;
|
||||
const daysInWeek = 7;
|
||||
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||
|
||||
this.$.model.insert({
|
||||
started: today,
|
||||
ended: nextWeek
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -66,10 +202,8 @@ export default class Controller extends Section {
|
|||
if (resetMinPrice)
|
||||
delete price['minPrice'];
|
||||
|
||||
price.hasMinPrice = price.minPrice ? true : false;
|
||||
|
||||
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
||||
for (let field of requiredFields)
|
||||
const requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
||||
for (const field of requiredFields)
|
||||
if (price[field] == undefined) return;
|
||||
|
||||
const query = 'FixedPrices/upsertFixedPrice';
|
||||
|
|
|
@ -12,8 +12,92 @@ describe('fixed price', () => {
|
|||
const $scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
||||
controller = $componentController('vnFixedPrice', {$element, $scope});
|
||||
controller.$ = {
|
||||
model: {refresh: () => {}},
|
||||
edit: {hide: () => {}}
|
||||
};
|
||||
}));
|
||||
|
||||
describe('get columns', () => {
|
||||
it(`should return a set of columns`, () => {
|
||||
let result = controller.columns;
|
||||
|
||||
let length = result.length;
|
||||
let anyColumn = Object.keys(result[Math.floor(Math.random() * Math.floor(length))]);
|
||||
|
||||
expect(anyColumn).toContain('field', 'displayName');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get checked', () => {
|
||||
it(`should return a set of checked lines`, () => {
|
||||
controller.$.model.data = [
|
||||
{checked: true, id: 1},
|
||||
{checked: true, id: 2},
|
||||
{checked: true, id: 3},
|
||||
{checked: false, id: 4},
|
||||
];
|
||||
|
||||
let result = controller.checked;
|
||||
|
||||
expect(result.length).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reCheck()', () => {
|
||||
it(`should recheck buys`, () => {
|
||||
controller.$.model.data = [
|
||||
{checked: false, id: 1},
|
||||
{checked: false, id: 2},
|
||||
{checked: false, id: 3},
|
||||
{checked: false, id: 4},
|
||||
];
|
||||
controller.checkedFixedPrices = [1, 2];
|
||||
|
||||
controller.reCheck();
|
||||
|
||||
expect(controller.$.model.data[0].checked).toEqual(true);
|
||||
expect(controller.$.model.data[1].checked).toEqual(true);
|
||||
expect(controller.$.model.data[2].checked).toEqual(false);
|
||||
expect(controller.$.model.data[3].checked).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveChecked()', () => {
|
||||
it(`should check buy`, () => {
|
||||
const buyCheck = 3;
|
||||
controller.checkedFixedPrices = [1, 2];
|
||||
|
||||
controller.saveChecked(buyCheck);
|
||||
|
||||
expect(controller.checkedFixedPrices[2]).toEqual(buyCheck);
|
||||
});
|
||||
|
||||
it(`should uncheck buy`, () => {
|
||||
const buyUncheck = 3;
|
||||
controller.checkedFixedPrices = [1, 2, 3];
|
||||
|
||||
controller.saveChecked(buyUncheck);
|
||||
|
||||
expect(controller.checkedFixedPrices[2]).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onEditAccept()', () => {
|
||||
it(`should perform a query to update columns`, () => {
|
||||
controller.editedColumn = {field: 'my field', newValue: 'the new value'};
|
||||
const query = 'FixedPrices/editFixedPrice';
|
||||
|
||||
$httpBackend.expectPOST(query).respond();
|
||||
controller.onEditAccept();
|
||||
$httpBackend.flush();
|
||||
|
||||
const result = controller.checked;
|
||||
|
||||
expect(result.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('upsertPrice()', () => {
|
||||
it('should do nothing if one or more required arguments are missing', () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
|
|
@ -3,3 +3,5 @@ Search prices by item ID or code: Buscar por ID de artículo o código
|
|||
Search fixed prices: Buscar precios fijados
|
||||
Add fixed price: Añadir precio fijado
|
||||
This row will be removed: Esta linea se eliminará
|
||||
Edit fixed price(s): Editar precio(s) fijado(s)
|
||||
Has min price: Tiene precio mínimo
|
||||
|
|
|
@ -1,20 +1,46 @@
|
|||
@import "variables";
|
||||
smart-table table{
|
||||
[shrink-field]{
|
||||
width: 80px;
|
||||
max-width: 80px;
|
||||
vn-fixed-price{
|
||||
smart-table table{
|
||||
[shrink-field]{
|
||||
width: 80px;
|
||||
max-width: 80px;
|
||||
}
|
||||
[shrink-field-expand]{
|
||||
width: 150px;
|
||||
max-width: 150px;
|
||||
}
|
||||
}
|
||||
[shrink-field-expand]{
|
||||
width: 150px;
|
||||
max-width: 150px;
|
||||
|
||||
.minPrice {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
vn-input-number {
|
||||
width: 90px;
|
||||
max-width: 90px;
|
||||
}
|
||||
}
|
||||
|
||||
smart-table table tbody > * > td .chip {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
smart-table table tbody > * > td{
|
||||
padding: 0px;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
smart-table table tbody > * > td .chip.warning {
|
||||
color: $color-font-bg
|
||||
}
|
||||
|
||||
.vn-field > .container > .infix > .control > input {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
vn-input-number.inactive{
|
||||
input {
|
||||
color: $color-font-light !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.minPrice {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
vn-input-number {
|
||||
width: 90px;
|
||||
max-width: 90px;
|
||||
}
|
||||
}
|
|
@ -38,6 +38,19 @@
|
|||
url="Warehouses">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-px-lg">
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="filter.requesterFk"
|
||||
url="Workers/activeWithRole"
|
||||
search-function="{firstName: $search}"
|
||||
value-field="id"
|
||||
where="{role: 'salesPerson'}"
|
||||
label="Comercial">
|
||||
<tpl-item>{{firstName}} {{lastName}}</tpl-item>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
|
||||
<section class="vn-px-md">
|
||||
<vn-horizontal class="manifold-panel vn-pa-md">
|
||||
<vn-date-picker
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
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 = [
|
||||
{
|
||||
routeFk: 2,
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Route",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model":"RouteLog",
|
||||
"grabUser": true
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "route"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "Shelving",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ShelvingLog",
|
||||
"showField": "id"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "shelving"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{
|
||||
"name": "SupplierAccount",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model":"SupplierLog",
|
||||
"relation": "supplier"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "supplierAccount"
|
||||
|
@ -35,4 +31,4 @@
|
|||
"foreignKey": "bankEntityFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue