Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3928-worker.time-control_sendMail
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
51b047eacc
|
@ -1,5 +0,0 @@
|
||||||
ALTER TABLE `vn`.`itemType` CHANGE `transaction` transaction__ tinyint(4) DEFAULT 0 NOT NULL;
|
|
||||||
ALTER TABLE `vn`.`itemType` CHANGE location location__ varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
|
|
||||||
ALTER TABLE `vn`.`itemType` CHANGE hasComponents hasComponents__ tinyint(1) DEFAULT 1 NOT NULL;
|
|
||||||
ALTER TABLE `vn`.`itemType` CHANGE warehouseFk warehouseFk__ smallint(6) unsigned DEFAULT 60 NOT NULL;
|
|
||||||
ALTER TABLE `vn`.`itemType` CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NULL;
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('Business', '*', '*', 'ALLOW', 'ROLE', 'hr');
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('Sale', 'usesMana', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('InvoiceIn', 'invoiceInPdf', 'READ', 'ALLOW', 'ROLE', 'administrative'),
|
||||||
|
('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
|
|
@ -0,0 +1,9 @@
|
||||||
|
CREATE TABLE `vn`.`zipConfig` (
|
||||||
|
`id` double(10,2) NOT NULL,
|
||||||
|
`maxSize` int(11) DEFAULT NULL COMMENT 'in MegaBytes',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('ZipConfig', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('ItemShelving', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('ItemShelving', '*', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('ItemShelvingPlacementSupplyStock', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`zone_getPostalCode`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Devuelve los códigos postales incluidos en una zona
|
||||||
|
*/
|
||||||
|
DECLARE vGeoFk INT DEFAULT NULL;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes;
|
||||||
|
CREATE TEMPORARY TABLE tmp.zoneNodes (
|
||||||
|
geoFk INT,
|
||||||
|
name VARCHAR(100),
|
||||||
|
parentFk INT,
|
||||||
|
sons INT,
|
||||||
|
isChecked BOOL DEFAULT 0,
|
||||||
|
zoneFk INT,
|
||||||
|
PRIMARY KEY zoneNodesPk (zoneFk, geoFk),
|
||||||
|
INDEX(geoFk))
|
||||||
|
ENGINE = MEMORY;
|
||||||
|
|
||||||
|
CALL zone_getLeaves2(vSelf, NULL , NULL);
|
||||||
|
|
||||||
|
UPDATE tmp.zoneNodes zn
|
||||||
|
SET isChecked = 0
|
||||||
|
WHERE parentFk IS NULL;
|
||||||
|
|
||||||
|
myLoop: LOOP
|
||||||
|
SET vGeoFk = NULL;
|
||||||
|
SELECT geoFk INTO vGeoFk
|
||||||
|
FROM tmp.zoneNodes zn
|
||||||
|
WHERE NOT isChecked
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
CALL zone_getLeaves2(vSelf, vGeoFk, NULL);
|
||||||
|
UPDATE tmp.zoneNodes
|
||||||
|
SET isChecked = TRUE
|
||||||
|
WHERE geoFk = vGeoFk;
|
||||||
|
|
||||||
|
IF vGeoFk IS NULL THEN
|
||||||
|
LEAVE myLoop;
|
||||||
|
END IF;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
DELETE FROM tmp.zoneNodes
|
||||||
|
WHERE sons > 0;
|
||||||
|
|
||||||
|
SELECT zn.geoFk, zn.name
|
||||||
|
FROM tmp.zoneNodes zn
|
||||||
|
JOIN zone z ON z.id = zn.zoneFk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -356,7 +356,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr
|
||||||
(1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1),
|
(1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1),
|
||||||
(2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1),
|
(2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1),
|
||||||
(3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1),
|
(3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1),
|
||||||
(4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 1),
|
(4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1),
|
||||||
(5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1),
|
(5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1),
|
||||||
(6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1),
|
(6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1),
|
||||||
(7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1),
|
(7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1),
|
||||||
|
@ -393,7 +393,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr
|
||||||
(126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0),
|
(126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0),
|
||||||
(127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0),
|
(127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0),
|
||||||
(128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0),
|
(128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0),
|
||||||
(129, 'Luke Cages Bar', 'address 29', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0),
|
(129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0),
|
||||||
(130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0);
|
(130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0);
|
||||||
|
|
||||||
INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`)
|
INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`)
|
||||||
|
@ -2047,6 +2047,7 @@ INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`)
|
||||||
(8, 4, 0),
|
(8, 4, 0),
|
||||||
(8, 5, 0),
|
(8, 5, 0),
|
||||||
(8, 1, 1),
|
(8, 1, 1),
|
||||||
|
(9, 7, 1),
|
||||||
(10, 14, 1);
|
(10, 14, 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`)
|
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`)
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
const app = require('vn-loopback/server/server');
|
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
||||||
|
|
||||||
// #1885
|
|
||||||
xdescribe('order_confirmWithUser()', () => {
|
|
||||||
it('should confirm an order', async() => {
|
|
||||||
let stmts = [];
|
|
||||||
let stmt;
|
|
||||||
|
|
||||||
stmts.push('START TRANSACTION');
|
|
||||||
|
|
||||||
let params = {
|
|
||||||
orderFk: 10,
|
|
||||||
userId: 9
|
|
||||||
};
|
|
||||||
// problema: la funcion order_confirmWithUser tiene una transacción, por tanto esta nunca hace rollback
|
|
||||||
stmt = new ParameterizedSQL('CALL hedera.order_confirmWithUser(?, ?)', [
|
|
||||||
params.orderFk,
|
|
||||||
params.userId
|
|
||||||
]);
|
|
||||||
stmts.push(stmt);
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL('SELECT confirmed FROM hedera.order WHERE id = ?', [
|
|
||||||
params.orderFk
|
|
||||||
]);
|
|
||||||
let orderIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
stmts.push('ROLLBACK');
|
|
||||||
|
|
||||||
let sql = ParameterizedSQL.join(stmts, ';');
|
|
||||||
let result = await app.models.Ticket.rawStmt(sql);
|
|
||||||
|
|
||||||
savedDescription = result[orderIndex][0].confirmed;
|
|
||||||
|
|
||||||
expect(savedDescription).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -394,11 +394,18 @@ export default {
|
||||||
intrastadCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Intrastat"]',
|
intrastadCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Intrastat"]',
|
||||||
originCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Origin"]',
|
originCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Origin"]',
|
||||||
buyerCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Buyer"]',
|
buyerCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Buyer"]',
|
||||||
|
densityCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Density"]',
|
||||||
|
openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
|
||||||
|
advancedSearchItemType: 'vn-item-search-panel vn-autocomplete[ng-model="filter.typeFk"]',
|
||||||
|
advancedSearchButton: 'vn-item-search-panel button[type=submit]',
|
||||||
|
advancedSmartTableButton: 'vn-item-index vn-button[icon="search"]',
|
||||||
|
advancedSmartTableGrouping: 'vn-item-index vn-textfield[name=grouping]',
|
||||||
weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]',
|
weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]',
|
||||||
saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button'
|
saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button'
|
||||||
},
|
},
|
||||||
itemFixedPrice: {
|
itemFixedPrice: {
|
||||||
add: 'vn-fixed-price vn-icon-button[icon="add_circle"]',
|
add: 'vn-fixed-price vn-icon-button[icon="add_circle"]',
|
||||||
|
firstItemID: 'vn-fixed-price tr:nth-child(2) vn-autocomplete[ng-model="price.itemFk"]',
|
||||||
fourthFixedPrice: 'vn-fixed-price tr:nth-child(5)',
|
fourthFixedPrice: 'vn-fixed-price tr:nth-child(5)',
|
||||||
fourthItemID: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.itemFk"]',
|
fourthItemID: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.itemFk"]',
|
||||||
fourthWarehouse: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.warehouseFk"]',
|
fourthWarehouse: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.warehouseFk"]',
|
||||||
|
@ -408,7 +415,8 @@ export default {
|
||||||
fourthMinPrice: 'vn-fixed-price tr:nth-child(5) > td:nth-child(6) > vn-input-number[ng-model="price.minPrice"]',
|
fourthMinPrice: 'vn-fixed-price tr:nth-child(5) > td:nth-child(6) > vn-input-number[ng-model="price.minPrice"]',
|
||||||
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
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"]',
|
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"]'
|
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
||||||
|
orderColumnId: 'vn-fixed-price th[field="itemFk"]'
|
||||||
},
|
},
|
||||||
itemCreateView: {
|
itemCreateView: {
|
||||||
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
||||||
|
@ -596,7 +604,14 @@ export default {
|
||||||
submitNotesButton: 'button[type=submit]'
|
submitNotesButton: 'button[type=submit]'
|
||||||
},
|
},
|
||||||
ticketExpedition: {
|
ticketExpedition: {
|
||||||
thirdExpeditionRemoveButton: 'vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(3) > vn-td:nth-child(1) > vn-icon-button[icon="delete"]',
|
firstSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(1) vn-check[ng-model="expedition.checked"]',
|
||||||
|
thirdSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(3) vn-check[ng-model="expedition.checked"]',
|
||||||
|
deleteExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="delete"]',
|
||||||
|
moveExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="keyboard_arrow_down"]',
|
||||||
|
moreMenuWithoutRoute: 'vn-item[name="withoutRoute"]',
|
||||||
|
moreMenuWithRoute: 'vn-item[name="withRoute"]',
|
||||||
|
newRouteId: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newRoute"]',
|
||||||
|
saveButton: '.vn-dialog.shown [response="accept"]',
|
||||||
expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr'
|
expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr'
|
||||||
},
|
},
|
||||||
ticketPackages: {
|
ticketPackages: {
|
||||||
|
@ -1100,7 +1115,8 @@ export default {
|
||||||
anyBuyLine: 'vn-entry-summary tr.dark-row'
|
anyBuyLine: 'vn-entry-summary tr.dark-row'
|
||||||
},
|
},
|
||||||
entryBasicData: {
|
entryBasicData: {
|
||||||
reference: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.ref"]',
|
reference: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.reference"]',
|
||||||
|
invoiceNumber: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.invoiceNumber"]',
|
||||||
notes: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.notes"]',
|
notes: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.notes"]',
|
||||||
observations: 'vn-entry-basic-data vn-textarea[ng-model="$ctrl.entry.observation"]',
|
observations: 'vn-entry-basic-data vn-textarea[ng-model="$ctrl.entry.observation"]',
|
||||||
supplier: 'vn-entry-basic-data vn-autocomplete[ng-model="$ctrl.entry.supplierFk"]',
|
supplier: 'vn-entry-basic-data vn-autocomplete[ng-model="$ctrl.entry.supplierFk"]',
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
import selectors from '../../helpers/selectors.js';
|
||||||
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
|
describe('SmartTable SearchBar integration', () => {
|
||||||
|
let browser;
|
||||||
|
let page;
|
||||||
|
beforeAll(async() => {
|
||||||
|
browser = await getBrowser();
|
||||||
|
page = browser.page;
|
||||||
|
await page.loginAndModule('salesPerson', 'item');
|
||||||
|
await page.waitToClick(selectors.globalItems.searchButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('as filters', () => {
|
||||||
|
it('should search by type in searchBar', async() => {
|
||||||
|
await page.waitToClick(selectors.itemsIndex.openAdvancedSearchButton);
|
||||||
|
await page.autocompleteSearch(selectors.itemsIndex.advancedSearchItemType, 'Anthurium');
|
||||||
|
await page.waitToClick(selectors.itemsIndex.advancedSearchButton);
|
||||||
|
await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload page and have same results', async() => {
|
||||||
|
await page.reload({
|
||||||
|
waitUntil: 'networkidle2'
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should search by grouping in smartTable', async() => {
|
||||||
|
await page.waitToClick(selectors.itemsIndex.advancedSmartTableButton);
|
||||||
|
await page.write(selectors.itemsIndex.advancedSmartTableGrouping, '1');
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should now reload page and have same results', async() => {
|
||||||
|
await page.reload({
|
||||||
|
waitUntil: 'networkidle2'
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('as orders', () => {
|
||||||
|
it('should order by first id', async() => {
|
||||||
|
await page.loginAndModule('developer', 'item');
|
||||||
|
await page.accessToSection('item.fixedPrice');
|
||||||
|
await page.doSearch();
|
||||||
|
|
||||||
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
|
expect(result).toEqual('1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should order by last id', async() => {
|
||||||
|
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
||||||
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
|
expect(result).toEqual('13');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload page and have same order', async() => {
|
||||||
|
await page.reload({
|
||||||
|
waitUntil: 'networkidle2'
|
||||||
|
});
|
||||||
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
|
expect(result).toEqual('13');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -18,7 +18,8 @@ describe('Ticket expeditions and log path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => {
|
it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => {
|
||||||
await page.waitToClick(selectors.ticketExpedition.thirdExpeditionRemoveButton);
|
await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.deleteExpeditionButton);
|
||||||
await page.waitToClick(selectors.globalItems.acceptButton);
|
await page.waitToClick(selectors.globalItems.acceptButton);
|
||||||
await page.reloadSection('ticket.card.expedition');
|
await page.reloadSection('ticket.card.expedition');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import selectors from '../../helpers/selectors.js';
|
||||||
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
|
describe('Ticket expeditions', () => {
|
||||||
|
let browser;
|
||||||
|
let page;
|
||||||
|
|
||||||
|
beforeAll(async() => {
|
||||||
|
browser = await getBrowser();
|
||||||
|
page = browser.page;
|
||||||
|
await page.loginAndModule('production', 'ticket');
|
||||||
|
await page.accessToSearchResult('1');
|
||||||
|
await page.accessToSection('ticket.card.expedition');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should move one expedition to new ticket withoute route`, async() => {
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.moreMenuWithoutRoute);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.saveButton);
|
||||||
|
await page.waitForState('ticket.card.summary');
|
||||||
|
await page.accessToSection('ticket.card.expedition');
|
||||||
|
|
||||||
|
await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {});
|
||||||
|
const result = await page
|
||||||
|
.countElement(selectors.ticketExpedition.expeditionRow);
|
||||||
|
|
||||||
|
expect(result).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should move one expedition to new ticket with route`, async() => {
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.firstSaleCheckbox);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton);
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.moreMenuWithRoute);
|
||||||
|
await page.write(selectors.ticketExpedition.newRouteId, '1');
|
||||||
|
await page.waitToClick(selectors.ticketExpedition.saveButton);
|
||||||
|
await page.waitForState('ticket.card.summary');
|
||||||
|
await page.accessToSection('ticket.card.expedition');
|
||||||
|
|
||||||
|
await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {});
|
||||||
|
const result = await page
|
||||||
|
.countElement(selectors.ticketExpedition.expeditionRow);
|
||||||
|
|
||||||
|
expect(result).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
|
@ -19,6 +19,7 @@ describe('Entry basic data path', () => {
|
||||||
|
|
||||||
it('should edit the basic data', async() => {
|
it('should edit the basic data', async() => {
|
||||||
await page.write(selectors.entryBasicData.reference, 'new movement 8');
|
await page.write(selectors.entryBasicData.reference, 'new movement 8');
|
||||||
|
await page.write(selectors.entryBasicData.invoiceNumber, 'new movement 8');
|
||||||
await page.write(selectors.entryBasicData.notes, 'new notes');
|
await page.write(selectors.entryBasicData.notes, 'new notes');
|
||||||
await page.write(selectors.entryBasicData.observations, ' edited');
|
await page.write(selectors.entryBasicData.observations, ' edited');
|
||||||
await page.autocompleteSearch(selectors.entryBasicData.supplier, 'Plants nick');
|
await page.autocompleteSearch(selectors.entryBasicData.supplier, 'Plants nick');
|
||||||
|
@ -45,6 +46,13 @@ describe('Entry basic data path', () => {
|
||||||
expect(result).toEqual('new movement 8');
|
expect(result).toEqual('new movement 8');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should confirm the invoiceNumber was edited', async() => {
|
||||||
|
await page.reloadSection('entry.card.basicData');
|
||||||
|
const result = await page.waitToGetProperty(selectors.entryBasicData.invoiceNumber, 'value');
|
||||||
|
|
||||||
|
expect(result).toEqual('new movement 8');
|
||||||
|
});
|
||||||
|
|
||||||
it('should confirm the note was edited', async() => {
|
it('should confirm the note was edited', async() => {
|
||||||
const result = await page.waitToGetProperty(selectors.entryBasicData.notes, 'value');
|
const result = await page.waitToGetProperty(selectors.entryBasicData.notes, 'value');
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,18 @@ export default class CrudModel extends ModelProxy {
|
||||||
return this.refresh();
|
return this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a new filter to the model.
|
||||||
|
*
|
||||||
|
* @param {Object} params Custom parameters
|
||||||
|
* @return {Promise} The request promise
|
||||||
|
*/
|
||||||
|
|
||||||
|
applyParams(params) {
|
||||||
|
this.userParams = params;
|
||||||
|
return this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
removeFilter() {
|
removeFilter() {
|
||||||
return this.applyFilter(null, null);
|
return this.applyFilter(null, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,8 +139,12 @@ export default class Searchbar extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeParam(index) {
|
removeParam(index) {
|
||||||
|
const field = this.params[index].key;
|
||||||
|
this.filterSanitizer(field);
|
||||||
|
|
||||||
this.params.splice(index, 1);
|
this.params.splice(index, 1);
|
||||||
this.doSearch(this.fromBar(), 'bar');
|
this.toRemove = field;
|
||||||
|
this.doSearch(this.fromBar(), 'removeBar');
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBar() {
|
fromBar() {
|
||||||
|
@ -163,7 +167,7 @@ export default class Searchbar extends Component {
|
||||||
|
|
||||||
let keys = Object.keys(filter);
|
let keys = Object.keys(filter);
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
if (key == 'search') return;
|
if (key == 'search' || key == 'tableQ' || key == 'tableOrder') return;
|
||||||
let value = filter[key];
|
let value = filter[key];
|
||||||
let chip;
|
let chip;
|
||||||
|
|
||||||
|
@ -198,6 +202,7 @@ export default class Searchbar extends Component {
|
||||||
let promise = this.onSearch({$params: filter});
|
let promise = this.onSearch({$params: filter});
|
||||||
promise = promise || this.$q.resolve();
|
promise = promise || this.$q.resolve();
|
||||||
promise.then(data => this.onFilter(filter, source, data));
|
promise.then(data => this.onFilter(filter, source, data));
|
||||||
|
this.toBar(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFilter(filter, source, data) {
|
onFilter(filter, source, data) {
|
||||||
|
@ -238,8 +243,11 @@ export default class Searchbar extends Component {
|
||||||
} else {
|
} else {
|
||||||
state = this.searchState;
|
state = this.searchState;
|
||||||
|
|
||||||
if (filter)
|
if (filter) {
|
||||||
|
if (this.tableQ)
|
||||||
|
filter.tableQ = this.tableQ;
|
||||||
params = {q: JSON.stringify(filter)};
|
params = {q: JSON.stringify(filter)};
|
||||||
|
}
|
||||||
if (this.$state.is(state))
|
if (this.$state.is(state))
|
||||||
opts = {location: 'replace'};
|
opts = {location: 'replace'};
|
||||||
}
|
}
|
||||||
|
@ -247,6 +255,12 @@ export default class Searchbar extends Component {
|
||||||
|
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
|
||||||
|
if (source == 'removeBar') {
|
||||||
|
delete params[this.toRemove];
|
||||||
|
delete this.model.userParams[this.toRemove];
|
||||||
|
this.model.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
if (!filter && this.model)
|
if (!filter && this.model)
|
||||||
this.model.clear();
|
this.model.clear();
|
||||||
if (source != 'state')
|
if (source != 'state')
|
||||||
|
@ -269,9 +283,14 @@ export default class Searchbar extends Component {
|
||||||
this.model.clear();
|
this.model.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (Object.keys(filter).length === 0) {
|
||||||
|
this.filterSanitizer('search');
|
||||||
|
if (this.model.userParams)
|
||||||
|
delete this.model.userParams['search'];
|
||||||
|
}
|
||||||
|
|
||||||
let where = null;
|
let where = null;
|
||||||
let params = null;
|
let params = {};
|
||||||
|
|
||||||
if (this.exprBuilder) {
|
if (this.exprBuilder) {
|
||||||
where = buildFilter(filter,
|
where = buildFilter(filter,
|
||||||
|
@ -283,9 +302,89 @@ export default class Searchbar extends Component {
|
||||||
params = this.fetchParams({$params: params});
|
params = this.fetchParams({$params: params});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.tableQ = null;
|
||||||
|
|
||||||
|
const hasParams = this.$params.q && Object.keys(JSON.parse(this.$params.q)).length;
|
||||||
|
if (hasParams) {
|
||||||
|
const stateFilter = JSON.parse(this.$params.q);
|
||||||
|
for (let param in stateFilter) {
|
||||||
|
if (param != 'tableQ' && param != 'orderQ')
|
||||||
|
this.filterSanitizer(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let param in this.suggestedFilter) {
|
||||||
|
this.filterSanitizer(param);
|
||||||
|
delete stateFilter[param];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tableQ = stateFilter.tableQ;
|
||||||
|
for (let param in stateFilter.tableQ)
|
||||||
|
params[param] = stateFilter.tableQ[param];
|
||||||
|
|
||||||
|
Object.assign(stateFilter, params);
|
||||||
|
return this.model.applyParams(params)
|
||||||
|
.then(() => this.model.data);
|
||||||
|
}
|
||||||
|
|
||||||
return this.model.applyFilter(where ? {where} : null, params)
|
return this.model.applyFilter(where ? {where} : null, params)
|
||||||
.then(() => this.model.data);
|
.then(() => this.model.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filterSanitizer(field) {
|
||||||
|
if (!field) return;
|
||||||
|
const userFilter = this.model.userFilter;
|
||||||
|
const userParams = this.model.userParams;
|
||||||
|
const where = userFilter && userFilter.where;
|
||||||
|
|
||||||
|
if (this.model.userParams)
|
||||||
|
delete this.model.userParams[field];
|
||||||
|
|
||||||
|
if (this.exprBuilder) {
|
||||||
|
const param = this.exprBuilder({
|
||||||
|
param: field,
|
||||||
|
value: null
|
||||||
|
});
|
||||||
|
if (param) [field] = Object.keys(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!where) return;
|
||||||
|
|
||||||
|
const whereKeys = Object.keys(where);
|
||||||
|
for (let key of whereKeys) {
|
||||||
|
removeProp(where, field, key);
|
||||||
|
|
||||||
|
if (Object.keys(where).length == 0)
|
||||||
|
delete userFilter.where;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeProp(obj, targetProp, prop) {
|
||||||
|
if (prop == targetProp)
|
||||||
|
delete obj[prop];
|
||||||
|
|
||||||
|
if (prop === 'and' || prop === 'or' && obj[prop]) {
|
||||||
|
const arrayCopy = obj[prop].slice();
|
||||||
|
for (let param of arrayCopy) {
|
||||||
|
const [key] = Object.keys(param);
|
||||||
|
const index = obj[prop].findIndex(param => {
|
||||||
|
return Object.keys(param)[0] == key;
|
||||||
|
});
|
||||||
|
if (key == targetProp)
|
||||||
|
obj[prop].splice(index, 1);
|
||||||
|
|
||||||
|
if (param[key] instanceof Array)
|
||||||
|
removeProp(param, field, key);
|
||||||
|
|
||||||
|
if (Object.keys(param).length == 0)
|
||||||
|
obj[prop].splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj[prop].length == 0)
|
||||||
|
delete obj[prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {userFilter, userParams};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnSearchbar', {
|
ngModule.vnComponent('vnSearchbar', {
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe('Component vnSearchbar', () => {
|
||||||
let $state;
|
let $state;
|
||||||
let $params;
|
let $params;
|
||||||
let $scope;
|
let $scope;
|
||||||
let filter = {id: 1, search: 'needle'};
|
const filter = {id: 1, search: 'needle'};
|
||||||
|
|
||||||
beforeEach(ngModule('vnCore', $stateProvider => {
|
beforeEach(ngModule('vnCore', $stateProvider => {
|
||||||
$stateProvider
|
$stateProvider
|
||||||
|
@ -70,8 +70,8 @@ describe('Component vnSearchbar', () => {
|
||||||
|
|
||||||
describe('filter() setter', () => {
|
describe('filter() setter', () => {
|
||||||
it(`should update the bar params and search`, () => {
|
it(`should update the bar params and search`, () => {
|
||||||
let withoutHours = new Date(2000, 1, 1);
|
const withoutHours = new Date(2000, 1, 1);
|
||||||
let withHours = new Date(withoutHours.getTime());
|
const withHours = new Date(withoutHours.getTime());
|
||||||
withHours.setHours(12, 30, 15, 10);
|
withHours.setHours(12, 30, 15, 10);
|
||||||
|
|
||||||
controller.filter = {
|
controller.filter = {
|
||||||
|
@ -83,8 +83,8 @@ describe('Component vnSearchbar', () => {
|
||||||
myObjectProp: {myProp: 1}
|
myObjectProp: {myProp: 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
let chips = {};
|
const chips = {};
|
||||||
for (let param of controller.params || [])
|
for (const param of controller.params || [])
|
||||||
chips[param.key] = param.chip;
|
chips[param.key] = param.chip;
|
||||||
|
|
||||||
expect(controller.searchString).toBe('needle');
|
expect(controller.searchString).toBe('needle');
|
||||||
|
@ -172,13 +172,22 @@ describe('Component vnSearchbar', () => {
|
||||||
describe('removeParam()', () => {
|
describe('removeParam()', () => {
|
||||||
it(`should remove the parameter from the filter`, () => {
|
it(`should remove the parameter from the filter`, () => {
|
||||||
jest.spyOn(controller, 'doSearch');
|
jest.spyOn(controller, 'doSearch');
|
||||||
|
controller.model = {
|
||||||
|
refresh: jest.fn(),
|
||||||
|
userParams: {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
controller.model.applyParams = jest.fn().mockReturnValue(Promise.resolve());
|
||||||
|
jest.spyOn(controller.model, 'applyParams');
|
||||||
|
|
||||||
controller.filter = filter;
|
controller.filter = filter;
|
||||||
controller.removeParam(0);
|
controller.removeParam(0);
|
||||||
|
|
||||||
expect(controller.doSearch).toHaveBeenCalledWith({
|
expect(controller.doSearch).toHaveBeenCalledWith({
|
||||||
search: 'needle'
|
search: 'needle'
|
||||||
}, 'bar');
|
}, 'removeBar');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -199,7 +208,7 @@ describe('Component vnSearchbar', () => {
|
||||||
it(`should go to the summary state when one result`, () => {
|
it(`should go to the summary state when one result`, () => {
|
||||||
jest.spyOn($state, 'go');
|
jest.spyOn($state, 'go');
|
||||||
|
|
||||||
let data = [{id: 1}];
|
const data = [{id: 1}];
|
||||||
|
|
||||||
controller.baseState = 'foo';
|
controller.baseState = 'foo';
|
||||||
controller.onFilter(filter, 'any', data);
|
controller.onFilter(filter, 'any', data);
|
||||||
|
@ -214,7 +223,7 @@ describe('Component vnSearchbar', () => {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
jest.spyOn($state, 'go');
|
jest.spyOn($state, 'go');
|
||||||
let data = [{id: 1}];
|
const data = [{id: 1}];
|
||||||
|
|
||||||
controller.baseState = 'foo';
|
controller.baseState = 'foo';
|
||||||
controller.onFilter(filter, 'any', data);
|
controller.onFilter(filter, 'any', data);
|
||||||
|
@ -229,7 +238,7 @@ describe('Component vnSearchbar', () => {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
jest.spyOn($state, 'go');
|
jest.spyOn($state, 'go');
|
||||||
let data = [{id: 1}];
|
const data = [{id: 1}];
|
||||||
|
|
||||||
controller.baseState = 'foo';
|
controller.baseState = 'foo';
|
||||||
controller.onFilter(filter, 'any', data);
|
controller.onFilter(filter, 'any', data);
|
||||||
|
@ -247,7 +256,7 @@ describe('Component vnSearchbar', () => {
|
||||||
controller.onFilter(filter, 'any');
|
controller.onFilter(filter, 'any');
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
let queryParams = {q: JSON.stringify(filter)};
|
const queryParams = {q: JSON.stringify(filter)};
|
||||||
|
|
||||||
expect($state.go).toHaveBeenCalledWith('search.state', queryParams, undefined);
|
expect($state.go).toHaveBeenCalledWith('search.state', queryParams, undefined);
|
||||||
expect(controller.filter).toEqual(filter);
|
expect(controller.filter).toEqual(filter);
|
||||||
|
|
|
@ -103,3 +103,4 @@
|
||||||
</div>
|
</div>
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
</vn-popover>
|
</vn-popover>
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,17 @@ export default class SmartTable extends Component {
|
||||||
this.$inputsScope;
|
this.$inputsScope;
|
||||||
this.columns = [];
|
this.columns = [];
|
||||||
this.autoSave = false;
|
this.autoSave = false;
|
||||||
|
this.autoState = true;
|
||||||
this.transclude();
|
this.transclude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$onChanges() {
|
||||||
|
if (this.model) {
|
||||||
|
this.defaultFilter();
|
||||||
|
this.defaultOrder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
$onDestroy() {
|
||||||
const styleElement = document.querySelector('style[id="smart-table"]');
|
const styleElement = document.querySelector('style[id="smart-table"]');
|
||||||
if (this.$.css && styleElement)
|
if (this.$.css && styleElement)
|
||||||
|
@ -47,10 +55,8 @@ export default class SmartTable extends Component {
|
||||||
|
|
||||||
set model(value) {
|
set model(value) {
|
||||||
this._model = value;
|
this._model = value;
|
||||||
if (value) {
|
if (value)
|
||||||
this.$.model = value;
|
this.$.model = value;
|
||||||
this.defaultOrder();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultViewConfig() {
|
getDefaultViewConfig() {
|
||||||
|
@ -160,8 +166,36 @@ export default class SmartTable extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultFilter() {
|
||||||
|
if (this.disabledTableFilter || !this.$params.q) return;
|
||||||
|
|
||||||
|
const stateFilter = JSON.parse(this.$params.q).tableQ;
|
||||||
|
if (!stateFilter || !this.exprBuilder) return;
|
||||||
|
|
||||||
|
const columns = this.columns.map(column => column.field);
|
||||||
|
|
||||||
|
this.displaySearch();
|
||||||
|
if (!this.$inputsScope.searchProps)
|
||||||
|
this.$inputsScope.searchProps = {};
|
||||||
|
|
||||||
|
for (let param in stateFilter) {
|
||||||
|
if (columns.includes(param)) {
|
||||||
|
const whereParams = {[param]: stateFilter[param]};
|
||||||
|
Object.assign(this.$inputsScope.searchProps, whereParams);
|
||||||
|
this.addFilter(param, stateFilter[param]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defaultOrder() {
|
defaultOrder() {
|
||||||
const order = this.model.order;
|
if (this.disabledTableOrder) return;
|
||||||
|
|
||||||
|
let stateOrder;
|
||||||
|
if (this.$params.q)
|
||||||
|
stateOrder = JSON.parse(this.$params.q).tableOrder;
|
||||||
|
|
||||||
|
const order = stateOrder ? stateOrder : this.model.order;
|
||||||
|
|
||||||
if (!order) return;
|
if (!order) return;
|
||||||
|
|
||||||
const orderFields = order.split(', ');
|
const orderFields = order.split(', ');
|
||||||
|
@ -195,6 +229,9 @@ export default class SmartTable extends Component {
|
||||||
this.setPriority(column.element, priority);
|
this.setPriority(column.element, priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.model.order = order;
|
||||||
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerColumns() {
|
registerColumns() {
|
||||||
|
@ -395,30 +432,56 @@ export default class SmartTable extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
searchByColumn(field) {
|
searchByColumn(field) {
|
||||||
const searchCriteria = this.$inputsScope.searchProps[field];
|
|
||||||
const emptySearch = searchCriteria === '' || searchCriteria == null;
|
|
||||||
|
|
||||||
const filters = this.filterSanitizer(field);
|
const filters = this.filterSanitizer(field);
|
||||||
|
|
||||||
if (filters && filters.userFilter)
|
if (filters && filters.userFilter)
|
||||||
this.model.userFilter = filters.userFilter;
|
this.model.userFilter = filters.userFilter;
|
||||||
if (!emptySearch)
|
|
||||||
this.addFilter(field, this.$inputsScope.searchProps[field]);
|
this.addFilter(field, this.$inputsScope.searchProps[field]);
|
||||||
else this.model.refresh();
|
}
|
||||||
|
|
||||||
|
searchPropsSanitizer() {
|
||||||
|
if (!this.$inputsScope || !this.$inputsScope.searchProps) return null;
|
||||||
|
let searchProps = this.$inputsScope.searchProps;
|
||||||
|
const searchPropsArray = Object.entries(searchProps);
|
||||||
|
searchProps = searchPropsArray.filter(
|
||||||
|
([key, value]) => value && value != ''
|
||||||
|
);
|
||||||
|
|
||||||
|
return Object.fromEntries(searchProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
addFilter(field, value) {
|
addFilter(field, value) {
|
||||||
let where = {[field]: value};
|
if (value == '') value = null;
|
||||||
|
|
||||||
|
let stateFilter = {tableQ: {}};
|
||||||
|
if (this.$params.q) {
|
||||||
|
stateFilter = JSON.parse(this.$params.q);
|
||||||
|
if (!stateFilter.tableQ)
|
||||||
|
stateFilter.tableQ = {};
|
||||||
|
delete stateFilter.tableQ[field];
|
||||||
|
}
|
||||||
|
|
||||||
|
const whereParams = {[field]: value};
|
||||||
|
if (value) {
|
||||||
|
let where = {[field]: value};
|
||||||
if (this.exprBuilder) {
|
if (this.exprBuilder) {
|
||||||
where = buildFilter(where, (param, value) =>
|
where = buildFilter(whereParams, (param, value) =>
|
||||||
this.exprBuilder({param, value})
|
this.exprBuilder({param, value})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.model.addFilter({where});
|
this.model.addFilter({where});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchProps = this.searchPropsSanitizer();
|
||||||
|
|
||||||
|
Object.assign(stateFilter.tableQ, searchProps);
|
||||||
|
|
||||||
|
const params = {q: JSON.stringify(stateFilter)};
|
||||||
|
|
||||||
|
this.$state.go(this.$state.current.name, params, {location: 'replace'});
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
applySort() {
|
applySort() {
|
||||||
let order = this.sortCriteria.map(criteria => `${criteria.field} ${criteria.sortType}`);
|
let order = this.sortCriteria.map(criteria => `${criteria.field} ${criteria.sortType}`);
|
||||||
order = order.join(', ');
|
order = order.join(', ');
|
||||||
|
@ -426,7 +489,18 @@ export default class SmartTable extends Component {
|
||||||
if (order)
|
if (order)
|
||||||
this.model.order = order;
|
this.model.order = order;
|
||||||
|
|
||||||
this.model.refresh();
|
let stateFilter = {tableOrder: {}};
|
||||||
|
if (this.$params.q) {
|
||||||
|
stateFilter = JSON.parse(this.$params.q);
|
||||||
|
if (!stateFilter.tableOrder)
|
||||||
|
stateFilter.tableOrder = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
stateFilter.tableOrder = order;
|
||||||
|
|
||||||
|
const params = {q: JSON.stringify(stateFilter)};
|
||||||
|
this.$state.go(this.$state.current.name, params, {location: 'replace'});
|
||||||
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
filterSanitizer(field) {
|
filterSanitizer(field) {
|
||||||
|
@ -535,6 +609,8 @@ ngModule.vnComponent('smartTable', {
|
||||||
autoSave: '<?',
|
autoSave: '<?',
|
||||||
exprBuilder: '&?',
|
exprBuilder: '&?',
|
||||||
defaultNewData: '&?',
|
defaultNewData: '&?',
|
||||||
options: '<?'
|
options: '<?',
|
||||||
|
disabledTableFilter: '<?',
|
||||||
|
disabledTableOrder: '<?',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,11 @@ describe('Component smartTable', () => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$element = $compile(`<smart-table></smart-table>`)($rootScope);
|
$element = $compile(`<smart-table></smart-table>`)($rootScope);
|
||||||
controller = $element.controller('smartTable');
|
controller = $element.controller('smartTable');
|
||||||
|
controller.model = {
|
||||||
|
refresh: jest.fn().mockReturnValue(new Promise(resolve => resolve())),
|
||||||
|
addFilter: jest.fn(),
|
||||||
|
userParams: {}
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -83,7 +88,7 @@ describe('Component smartTable', () => {
|
||||||
describe('defaultOrder', () => {
|
describe('defaultOrder', () => {
|
||||||
it('should insert a new object to the controller sortCriteria with a sortType value of "ASC"', () => {
|
it('should insert a new object to the controller sortCriteria with a sortType value of "ASC"', () => {
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
controller.model = {order: 'id'};
|
controller.model.order = 'id';
|
||||||
controller.columns = [
|
controller.columns = [
|
||||||
{field: 'id', element: element},
|
{field: 'id', element: element},
|
||||||
{field: 'test1', element: element},
|
{field: 'test1', element: element},
|
||||||
|
@ -101,7 +106,8 @@ describe('Component smartTable', () => {
|
||||||
|
|
||||||
it('should add new entries to the controller sortCriteria with a sortType values of "ASC" and "DESC"', () => {
|
it('should add new entries to the controller sortCriteria with a sortType values of "ASC" and "DESC"', () => {
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
controller.model = {order: 'test1, id DESC'};
|
controller.model.order = 'test1, id DESC';
|
||||||
|
|
||||||
controller.columns = [
|
controller.columns = [
|
||||||
{field: 'id', element: element},
|
{field: 'id', element: element},
|
||||||
{field: 'test1', element: element},
|
{field: 'test1', element: element},
|
||||||
|
@ -125,8 +131,6 @@ describe('Component smartTable', () => {
|
||||||
|
|
||||||
describe('addFilter()', () => {
|
describe('addFilter()', () => {
|
||||||
it('should call the model addFilter() with a basic where filter if exprBuilder() was not received', () => {
|
it('should call the model addFilter() with a basic where filter if exprBuilder() was not received', () => {
|
||||||
controller.model = {addFilter: jest.fn()};
|
|
||||||
|
|
||||||
controller.addFilter('myField', 'myValue');
|
controller.addFilter('myField', 'myValue');
|
||||||
|
|
||||||
const expectedFilter = {
|
const expectedFilter = {
|
||||||
|
@ -140,7 +144,6 @@ describe('Component smartTable', () => {
|
||||||
|
|
||||||
it('should call the model addFilter() with a built where filter resultant of exprBuilder()', () => {
|
it('should call the model addFilter() with a built where filter resultant of exprBuilder()', () => {
|
||||||
controller.exprBuilder = jest.fn().mockReturnValue({builtField: 'builtValue'});
|
controller.exprBuilder = jest.fn().mockReturnValue({builtField: 'builtValue'});
|
||||||
controller.model = {addFilter: jest.fn()};
|
|
||||||
|
|
||||||
controller.addFilter('myField', 'myValue');
|
controller.addFilter('myField', 'myValue');
|
||||||
|
|
||||||
|
@ -155,35 +158,48 @@ describe('Component smartTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('applySort()', () => {
|
describe('applySort()', () => {
|
||||||
it('should call the model refresh() without making changes on the model order', () => {
|
it('should call the $state go and model refresh without making changes on the model order', () => {
|
||||||
controller.model = {refresh: jest.fn()};
|
controller.$state = {
|
||||||
|
go: jest.fn(),
|
||||||
|
current: {
|
||||||
|
name: 'section'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
jest.spyOn(controller, 'refresh');
|
||||||
|
|
||||||
controller.applySort();
|
controller.applySort();
|
||||||
|
|
||||||
expect(controller.model.order).toBeUndefined();
|
expect(controller.model.order).toBeUndefined();
|
||||||
expect(controller.model.refresh).toHaveBeenCalled();
|
expect(controller.$state.go).toHaveBeenCalled();
|
||||||
|
expect(controller.refresh).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the model.refresh() after setting model order according to the controller sortCriteria', () => {
|
it('should call the $state go and model refresh after setting model order according to the controller sortCriteria', () => {
|
||||||
controller.model = {refresh: jest.fn()};
|
|
||||||
const orderBy = {field: 'myField', sortType: 'ASC'};
|
const orderBy = {field: 'myField', sortType: 'ASC'};
|
||||||
|
controller.$state = {
|
||||||
|
go: jest.fn(),
|
||||||
|
current: {
|
||||||
|
name: 'section'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
jest.spyOn(controller, 'refresh');
|
||||||
|
|
||||||
controller.sortCriteria = [orderBy];
|
controller.sortCriteria = [orderBy];
|
||||||
|
|
||||||
controller.applySort();
|
controller.applySort();
|
||||||
|
|
||||||
expect(controller.model.order).toEqual(`${orderBy.field} ${orderBy.sortType}`);
|
expect(controller.model.order).toEqual(`${orderBy.field} ${orderBy.sortType}`);
|
||||||
expect(controller.model.refresh).toHaveBeenCalled();
|
expect(controller.$state.go).toHaveBeenCalled();
|
||||||
|
expect(controller.refresh).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('filterSanitizer()', () => {
|
describe('filterSanitizer()', () => {
|
||||||
it('should remove the where filter after leaving no fields in it', () => {
|
it('should remove the where filter after leaving no fields in it', () => {
|
||||||
controller.model = {
|
controller.model.userFilter = {
|
||||||
userFilter: {
|
|
||||||
where: {fieldToRemove: 'valueToRemove'}
|
where: {fieldToRemove: 'valueToRemove'}
|
||||||
},
|
|
||||||
userParams: {}
|
|
||||||
};
|
};
|
||||||
|
controller.model.userParams = {};
|
||||||
|
|
||||||
const result = controller.filterSanitizer('fieldToRemove');
|
const result = controller.filterSanitizer('fieldToRemove');
|
||||||
|
|
||||||
|
@ -193,8 +209,7 @@ describe('Component smartTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove the where filter after leaving no fields and "empty ands/ors" in it', () => {
|
it('should remove the where filter after leaving no fields and "empty ands/ors" in it', () => {
|
||||||
controller.model = {
|
controller.model.userFilter = {
|
||||||
userFilter: {
|
|
||||||
where: {
|
where: {
|
||||||
and: [
|
and: [
|
||||||
{aFieldToRemove: 'aValueToRemove'},
|
{aFieldToRemove: 'aValueToRemove'},
|
||||||
|
@ -208,8 +223,7 @@ describe('Component smartTable', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
userParams: {}
|
controller.model.userParams = {};
|
||||||
};
|
|
||||||
|
|
||||||
const result = controller.filterSanitizer('aFieldToRemove');
|
const result = controller.filterSanitizer('aFieldToRemove');
|
||||||
|
|
||||||
|
@ -219,8 +233,7 @@ describe('Component smartTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not remove the where filter after leaving no empty "ands/ors" in it', () => {
|
it('should not remove the where filter after leaving no empty "ands/ors" in it', () => {
|
||||||
controller.model = {
|
controller.model.userFilter = {
|
||||||
userFilter: {
|
|
||||||
where: {
|
where: {
|
||||||
and: [
|
and: [
|
||||||
{aFieldToRemove: 'aValueToRemove'},
|
{aFieldToRemove: 'aValueToRemove'},
|
||||||
|
@ -234,9 +247,8 @@ describe('Component smartTable', () => {
|
||||||
],
|
],
|
||||||
or: [{dontKillMe: 'thanks'}]
|
or: [{dontKillMe: 'thanks'}]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
userParams: {}
|
|
||||||
};
|
};
|
||||||
|
controller.model.userParams = {};
|
||||||
|
|
||||||
const result = controller.filterSanitizer('aFieldToRemove');
|
const result = controller.filterSanitizer('aFieldToRemove');
|
||||||
|
|
||||||
|
@ -249,7 +261,7 @@ describe('Component smartTable', () => {
|
||||||
describe('saveAll()', () => {
|
describe('saveAll()', () => {
|
||||||
it('should throw an error if there are no changes to save in the model', () => {
|
it('should throw an error if there are no changes to save in the model', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showError');
|
jest.spyOn(controller.vnApp, 'showError');
|
||||||
controller.model = {isChanged: false};
|
controller.model.isChanged = false;
|
||||||
controller.saveAll();
|
controller.saveAll();
|
||||||
|
|
||||||
expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
|
expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
|
||||||
|
@ -258,10 +270,8 @@ describe('Component smartTable', () => {
|
||||||
it('should call the showSuccess() if there are changes to save in the model', done => {
|
it('should call the showSuccess() if there are changes to save in the model', done => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
controller.model = {
|
controller.model.save = jest.fn().mockReturnValue(Promise.resolve());
|
||||||
save: jest.fn().mockReturnValue(Promise.resolve()),
|
controller.model.isChanged = true;
|
||||||
isChanged: true
|
|
||||||
};
|
|
||||||
|
|
||||||
controller.saveAll().then(() => {
|
controller.saveAll().then(() => {
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
||||||
|
@ -269,4 +279,43 @@ describe('Component smartTable', () => {
|
||||||
}).catch(done.fail);
|
}).catch(done.fail);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('defaultFilter()', () => {
|
||||||
|
it('should call model refresh and model addFilter with filter', () => {
|
||||||
|
controller.exprBuilder = jest.fn().mockReturnValue({builtField: 'builtValue'});
|
||||||
|
|
||||||
|
controller.$params = {
|
||||||
|
q: '{"tableQ": {"fieldName":"value"}}'
|
||||||
|
};
|
||||||
|
controller.columns = [
|
||||||
|
{field: 'fieldName'}
|
||||||
|
];
|
||||||
|
controller.$inputsScope = {
|
||||||
|
searchProps: {}
|
||||||
|
};
|
||||||
|
jest.spyOn(controller, 'refresh');
|
||||||
|
|
||||||
|
controller.defaultFilter();
|
||||||
|
|
||||||
|
expect(controller.model.addFilter).toHaveBeenCalled();
|
||||||
|
expect(controller.refresh).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('searchPropsSanitizer()', () => {
|
||||||
|
it('should searchProps sanitize', () => {
|
||||||
|
controller.$inputsScope = {
|
||||||
|
searchProps: {
|
||||||
|
filterOne: '1',
|
||||||
|
filterTwo: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const searchPropsExpected = {
|
||||||
|
filterOne: '1'
|
||||||
|
};
|
||||||
|
const newSearchProps = controller.searchPropsSanitizer();
|
||||||
|
|
||||||
|
expect(newSearchProps).toEqual(searchPropsExpected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,6 +51,7 @@ Entries: Entradas
|
||||||
Users: Usuarios
|
Users: Usuarios
|
||||||
Suppliers: Proveedores
|
Suppliers: Proveedores
|
||||||
Monitors: Monitores
|
Monitors: Monitores
|
||||||
|
Shelvings: Carros
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
|
|
||||||
|
|
|
@ -1,245 +1,25 @@
|
||||||
{
|
{
|
||||||
"Phone format is invalid": "El formato del teléfono no es correcto",
|
"Record of hours week": "Record of hours week",
|
||||||
"You are not allowed to change the credit": "No tienes privilegios para modificar el crédito",
|
"Invalid email": "Invalid email",
|
||||||
"Unable to mark the equivalence surcharge": "No se puede marcar el recargo de equivalencia",
|
"Name cannot be blank": "Name cannot be blank",
|
||||||
"The default consignee can not be unchecked": "No se puede desmarcar el consignatario predeterminado",
|
"Swift / BIC cannot be empty": "Swift / BIC cannot be empty",
|
||||||
"Unable to default a disabled consignee": "No se puede poner predeterminado un consignatario desactivado",
|
"Street cannot be empty": "Street cannot be empty",
|
||||||
"Can't be blank": "No puede estar en blanco",
|
"City cannot be empty": "City cannot be empty",
|
||||||
"Invalid TIN": "NIF/CIF invalido",
|
"Phone cannot be blank": "Phone cannot be blank",
|
||||||
"TIN must be unique": "El NIF/CIF debe ser único",
|
|
||||||
"A client with that Web User name already exists": "Ya existe un cliente con ese Usuario Web",
|
|
||||||
"Is invalid": "Is invalid",
|
|
||||||
"Quantity cannot be zero": "La cantidad no puede ser cero",
|
|
||||||
"Enter an integer different to zero": "Introduce un entero distinto de cero",
|
|
||||||
"Package cannot be blank": "El embalaje no puede estar en blanco",
|
|
||||||
"The company name must be unique": "La razón social debe ser única",
|
|
||||||
"Invalid email": "Correo electrónico inválido",
|
|
||||||
"The IBAN does not have the correct format": "El IBAN no tiene el formato correcto",
|
|
||||||
"That payment method requires an IBAN": "El método de pago seleccionado requiere un IBAN",
|
|
||||||
"That payment method requires a BIC": "El método de pago seleccionado requiere un BIC",
|
|
||||||
"State cannot be blank": "El estado no puede estar en blanco",
|
|
||||||
"Worker cannot be blank": "El trabajador no puede estar en blanco",
|
|
||||||
"Cannot change the payment method if no salesperson": "No se puede cambiar la forma de pago si no hay comercial asignado",
|
|
||||||
"can't be blank": "El campo no puede estar vacío",
|
|
||||||
"Observation type must be unique": "El tipo de observación no puede repetirse",
|
|
||||||
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
|
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
|
||||||
"The grade must be similar to the last one": "El grade debe ser similar al último",
|
"The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero",
|
||||||
"Only manager can change the credit": "Solo el gerente puede cambiar el credito de este cliente",
|
"Description should have maximum of 45 characters": "Description should have maximum of 45 characters",
|
||||||
"Name cannot be blank": "El nombre no puede estar en blanco",
|
"Amount cannot be zero": "Amount cannot be zero",
|
||||||
"Phone cannot be blank": "El teléfono no puede estar en blanco",
|
"Period cannot be blank": "Period cannot be blank",
|
||||||
"Period cannot be blank": "El periodo no puede estar en blanco",
|
"Sample type cannot be blank": "Sample type cannot be blank",
|
||||||
"Choose a company": "Selecciona una empresa",
|
"Cannot be blank": "Cannot be blank",
|
||||||
"Se debe rellenar el campo de texto": "Se debe rellenar el campo de texto",
|
"The social name cannot be empty": "The social name cannot be empty",
|
||||||
"Description should have maximum of 45 characters": "La descripción debe tener maximo 45 caracteres",
|
"Concept cannot be blank": "Concept cannot be blank",
|
||||||
"Cannot be blank": "El campo no puede estar en blanco",
|
"Enter an integer different to zero": "Enter an integer different to zero",
|
||||||
"The grade must be an integer greater than or equal to zero": "El grade debe ser un entero mayor o igual a cero",
|
"Package cannot be blank": "Package cannot be blank",
|
||||||
"Sample type cannot be blank": "El tipo de plantilla no puede quedar en blanco",
|
"State cannot be blank": "State cannot be blank",
|
||||||
"Description cannot be blank": "Se debe rellenar el campo de texto",
|
"Worker cannot be blank": "Worker cannot be blank",
|
||||||
"The new quantity should be smaller than the old one": "La nueva cantidad debe de ser menor que la anterior",
|
"Agency cannot be blank": "Agency cannot be blank",
|
||||||
"The value should not be greater than 100%": "El valor no debe de ser mayor de 100%",
|
|
||||||
"The value should be a number": "El valor debe ser un numero",
|
|
||||||
"This order is not editable": "Esta orden no se puede modificar",
|
|
||||||
"You can't create an order for a frozen client": "No puedes crear una orden para un cliente congelado",
|
|
||||||
"You can't create an order for a client that has a debt": "No puedes crear una orden para un cliente con deuda",
|
|
||||||
"is not a valid date": "No es una fecha valida",
|
|
||||||
"Barcode must be unique": "El código de barras debe ser único",
|
|
||||||
"The warehouse can't be repeated": "El almacén no puede repetirse",
|
|
||||||
"The tag or priority can't be repeated for an item": "El tag o prioridad no puede repetirse para un item",
|
|
||||||
"The observation type can't be repeated": "El tipo de observación no puede repetirse",
|
|
||||||
"A claim with that sale already exists": "Ya existe una reclamación para esta línea",
|
|
||||||
"You don't have enough privileges to change that field": "No tienes permisos para cambiar ese campo",
|
|
||||||
"Warehouse cannot be blank": "El almacén no puede quedar en blanco",
|
|
||||||
"Agency cannot be blank": "La agencia no puede quedar en blanco",
|
|
||||||
"Not enough privileges to edit a client with verified data": "No tienes permisos para hacer cambios en un cliente con datos comprobados",
|
|
||||||
"This address doesn't exist": "Este consignatario no existe",
|
|
||||||
"You must delete the claim id %d first": "Antes debes borrar la reclamación %d",
|
|
||||||
"You don't have enough privileges": "No tienes suficientes permisos",
|
|
||||||
"Cannot check Equalization Tax in this NIF/CIF": "No se puede marcar RE en este NIF/CIF",
|
|
||||||
"You can't make changes on the basic data of an confirmed order or with rows": "No puedes cambiar los datos basicos de una orden con artículos",
|
|
||||||
"INVALID_USER_NAME": "El nombre de usuario solo debe contener letras minúsculas o, a partir del segundo carácter, números o subguiones, no esta permitido el uso de la letra ñ",
|
|
||||||
"You can't create a ticket for a frozen client": "No puedes crear un ticket para un cliente congelado",
|
|
||||||
"You can't create a ticket for a inactive client": "No puedes crear un ticket para un cliente inactivo",
|
|
||||||
"Tag value cannot be blank": "El valor del tag no puede quedar en blanco",
|
|
||||||
"ORDER_EMPTY": "Cesta vacía",
|
|
||||||
"You don't have enough privileges to do that": "No tienes permisos para cambiar esto",
|
|
||||||
"NO SE PUEDE DESACTIVAR EL CONSIGNAT": "NO SE PUEDE DESACTIVAR EL CONSIGNAT",
|
|
||||||
"Error. El NIF/CIF está repetido": "Error. El NIF/CIF está repetido",
|
|
||||||
"Street cannot be empty": "Dirección no puede estar en blanco",
|
|
||||||
"City cannot be empty": "Cuidad no puede estar en blanco",
|
|
||||||
"Code cannot be blank": "Código no puede estar en blanco",
|
|
||||||
"You cannot remove this department": "No puedes eliminar este departamento",
|
|
||||||
"The extension must be unique": "La extensión debe ser unica",
|
|
||||||
"The secret can't be blank": "La contraseña no puede estar en blanco",
|
|
||||||
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
|
|
||||||
"This client can't be invoiced": "Este cliente no puede ser facturado",
|
|
||||||
"This ticket can't be invoiced": "Este ticket no puede ser facturado",
|
|
||||||
"You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado",
|
|
||||||
"This ticket can not be modified": "Este ticket no puede ser modificado",
|
|
||||||
"The introduced hour already exists": "Esta hora ya ha sido introducida",
|
|
||||||
"INFINITE_LOOP": "Existe una dependencia entre dos Jefes",
|
|
||||||
"The sales of the current ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
|
|
||||||
"The sales of the receiver ticket can't be modified": "Las lineas del ticket al que envias no pueden ser modificadas",
|
|
||||||
"NO_AGENCY_AVAILABLE": "No hay una zona de reparto disponible con estos parámetros",
|
|
||||||
"ERROR_PAST_SHIPMENT": "No puedes seleccionar una fecha de envío en pasado",
|
|
||||||
"The current ticket can't be modified": "El ticket actual no puede ser modificado",
|
|
||||||
"The current claim can't be modified": "La reclamación actual no puede ser modificada",
|
|
||||||
"The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
|
|
||||||
"Sale(s) blocked, contact production": "Linea(s) bloqueada(s), contacte con produccion",
|
|
||||||
"Please select at least one sale": "Por favor selecciona al menos una linea",
|
|
||||||
"All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket",
|
|
||||||
"NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",
|
|
||||||
"This item doesn't exists": "El artículo no existe",
|
|
||||||
"NOT_ZONE_WITH_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",
|
|
||||||
"Extension format is invalid": "El formato de la extensión es inválido",
|
|
||||||
"Invalid parameters to create a new ticket": "Parámetros inválidos para crear un nuevo ticket",
|
|
||||||
"This item is not available": "Este artículo no está disponible",
|
|
||||||
"This postcode already exists": "Este código postal ya existe",
|
|
||||||
"Concept cannot be blank": "El concepto no puede quedar en blanco",
|
|
||||||
"File doesn't exists": "El archivo no existe",
|
|
||||||
"You don't have privileges to change the zone": "No tienes permisos para cambiar la zona o para esos parámetros hay más de una opción de envío, hable con las agencias",
|
|
||||||
"This ticket is already on weekly tickets": "Este ticket ya está en tickets programados",
|
|
||||||
"Ticket id cannot be blank": "El id de ticket no puede quedar en blanco",
|
|
||||||
"Weekday cannot be blank": "El día de la semana no puede quedar en blanco",
|
|
||||||
"You can't delete a confirmed order": "No puedes borrar un pedido confirmado",
|
|
||||||
"The social name has an invalid format": "El nombre fiscal tiene un formato incorrecto",
|
|
||||||
"Invalid quantity": "Cantidad invalida",
|
|
||||||
"This postal code is not valid": "This postal code is not valid",
|
|
||||||
"is invalid": "is invalid",
|
|
||||||
"The postcode doesn't exist. Please enter a correct one": "El código postal no existe. Por favor, introduce uno correcto",
|
|
||||||
"The department name can't be repeated": "El nombre del departamento no puede repetirse",
|
|
||||||
"This phone already exists": "Este teléfono ya existe",
|
|
||||||
"You cannot move a parent to its own sons": "No puedes mover un elemento padre a uno de sus hijos",
|
|
||||||
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
|
|
||||||
"You cannot delete a ticket that part of it is being prepared": "No puedes eliminar un ticket en el que una parte que está siendo preparada",
|
|
||||||
"You must delete all the buy requests first": "Debes eliminar todas las peticiones de compra primero",
|
|
||||||
"You should specify a date": "Debes especificar una fecha",
|
|
||||||
"You should specify at least a start or end date": "Debes especificar al menos una fecha de inicio o de fín",
|
|
||||||
"Start date should be lower than end date": "La fecha de inicio debe ser menor que la fecha de fín",
|
|
||||||
"You should mark at least one week day": "Debes marcar al menos un día de la semana",
|
|
||||||
"Swift / BIC can't be empty": "Swift / BIC no puede estar vacío",
|
|
||||||
"Customs agent is required for a non UEE member": "El agente de aduanas es requerido para los clientes extracomunitarios",
|
|
||||||
"Incoterms is required for a non UEE member": "El incoterms es requerido para los clientes extracomunitarios",
|
|
||||||
"Deleted sales from ticket": "He eliminado las siguientes lineas del ticket [{{ticketId}}]({{{ticketUrl}}}): {{{deletions}}}",
|
|
||||||
"Added sale to ticket": "He añadido la siguiente linea al ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}",
|
|
||||||
"Changed sale discount": "He cambiado el descuento de las siguientes lineas al ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
|
|
||||||
"Created claim": "He creado la reclamación [{{claimId}}]({{{claimUrl}}}) de las siguientes lineas del ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
|
|
||||||
"Changed sale price": "He cambiado el precio de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* del ticket [{{ticketId}}]({{{ticketUrl}}})",
|
|
||||||
"Changed sale quantity": "He cambiado la cantidad de [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* del ticket [{{ticketId}}]({{{ticketUrl}}})",
|
|
||||||
"State": "Estado",
|
|
||||||
"regular": "normal",
|
|
||||||
"reserved": "reservado",
|
|
||||||
"Changed sale reserved state": "He cambiado el estado reservado de las siguientes lineas al ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
|
|
||||||
"Bought units from buy request": "Se ha comprado {{quantity}} unidades de [{{itemId}} {{concept}}]({{{urlItem}}}) para el ticket id [{{ticketId}}]({{{url}}})",
|
|
||||||
"Deny buy request": "Se ha rechazado la petición de compra para el ticket id [{{ticketId}}]({{{url}}}). Motivo: {{observation}}",
|
|
||||||
"MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*",
|
|
||||||
"Changed client paymethod": "He cambiado la forma de pago del cliente [{{clientName}} ({{clientId}})]({{{url}}})",
|
|
||||||
"Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})",
|
|
||||||
"Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*",
|
|
||||||
"Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*",
|
|
||||||
"Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*",
|
|
||||||
"Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}",
|
|
||||||
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
|
|
||||||
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",
|
|
||||||
"This ticket is deleted": "Este ticket está eliminado",
|
|
||||||
"Unable to clone this travel": "No ha sido posible clonar este travel",
|
|
||||||
"This thermograph id already exists": "La id del termógrafo ya existe",
|
|
||||||
"Choose a date range or days forward": "Selecciona un rango de fechas o días en adelante",
|
|
||||||
"ORDER_ALREADY_CONFIRMED": "ORDER_ALREADY_CONFIRMED",
|
|
||||||
"Invalid password": "Invalid password",
|
|
||||||
"Password does not meet requirements": "La contraseña no cumple los requisitos",
|
|
||||||
"Role already assigned": "Role already assigned",
|
|
||||||
"Invalid role name": "Invalid role name",
|
|
||||||
"Role name must be written in camelCase": "Role name must be written in camelCase",
|
|
||||||
"Email already exists": "Email already exists",
|
|
||||||
"User already exists": "User already exists",
|
|
||||||
"Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral",
|
|
||||||
"Record of hours week": "Registro de horas semana {{week}} año {{year}} ",
|
|
||||||
"Created absence": "El empleado <strong>{{author}}</strong> ha añadido una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> para el día {{dated}}.",
|
|
||||||
"Deleted absence": "El empleado <strong>{{author}}</strong> ha eliminado una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> del día {{dated}}.",
|
|
||||||
"I have deleted the ticket id": "He eliminado el ticket id [{{id}}]({{{url}}})",
|
|
||||||
"I have restored the ticket id": "He restaurado el ticket id [{{id}}]({{{url}}})",
|
|
||||||
"You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación",
|
|
||||||
"Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
|
|
||||||
"agencyModeFk": "Agencia",
|
|
||||||
"clientFk": "Cliente",
|
|
||||||
"zoneFk": "Zona",
|
|
||||||
"warehouseFk": "Almacén",
|
|
||||||
"shipped": "F. envío",
|
|
||||||
"landed": "F. entrega",
|
|
||||||
"addressFk": "Consignatario",
|
|
||||||
"companyFk": "Empresa",
|
|
||||||
"The social name cannot be empty": "La razón social no puede quedar en blanco",
|
|
||||||
"The nif cannot be empty": "El NIF no puede quedar en blanco",
|
|
||||||
"You need to fill sage information before you check verified data": "Debes rellenar la información de sage antes de marcar datos comprobados",
|
|
||||||
"ASSIGN_ZONE_FIRST": "Asigna una zona primero",
|
|
||||||
"Amount cannot be zero": "El importe no puede ser cero",
|
|
||||||
"Company has to be official": "Empresa inválida",
|
|
||||||
"You can not select this payment method without a registered bankery account": "No se puede utilizar este método de pago si no has registrado una cuenta bancaria",
|
|
||||||
"Action not allowed on the test environment": "Esta acción no está permitida en el entorno de pruebas",
|
|
||||||
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
|
||||||
"Sorts whole route": "Reordena ruta entera",
|
|
||||||
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*",
|
|
||||||
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}*",
|
|
||||||
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
|
|
||||||
"This BIC already exist.": "Este BIC ya existe.",
|
|
||||||
"That item doesn't exists": "Ese artículo no existe",
|
|
||||||
"There's a new urgent ticket:": "Hay un nuevo ticket urgente:",
|
|
||||||
"Invalid account": "Cuenta inválida",
|
|
||||||
"Compensation account is empty": "La cuenta para compensar está vacia",
|
|
||||||
"This genus already exist": "Este genus ya existe",
|
|
||||||
"This specie already exist": "Esta especie ya existe",
|
|
||||||
"Client assignment has changed": "He cambiado el comercial ~*\"<{{previousWorkerName}}>\"*~ por *\"<{{currentWorkerName}}>\"* del cliente [{{clientName}} ({{clientId}})]({{{url}}})",
|
|
||||||
"None": "Ninguno",
|
|
||||||
"The contract was not active during the selected date": "El contrato no estaba activo durante la fecha seleccionada",
|
|
||||||
"Cannot add more than one '1/2 day vacation'": "No puedes añadir más de un 'Vacaciones 1/2 dia'",
|
|
||||||
"This document already exists on this ticket": "Este documento ya existe en el ticket",
|
|
||||||
"Some of the selected tickets are not billable": "Algunos de los tickets seleccionados no son facturables",
|
|
||||||
"You can't invoice tickets from multiple clients": "No puedes facturar tickets de multiples clientes",
|
|
||||||
"nickname": "nickname",
|
|
||||||
"INACTIVE_PROVIDER": "Proveedor inactivo",
|
|
||||||
"This client is not invoiceable": "Este cliente no es facturable",
|
|
||||||
"serial non editable": "Esta serie no permite asignar la referencia",
|
|
||||||
"Max shipped required": "La fecha límite es requerida",
|
|
||||||
"Can't invoice to future": "No se puede facturar a futuro",
|
|
||||||
"Can't invoice to past": "No se puede facturar a pasado",
|
|
||||||
"This ticket is already invoiced": "Este ticket ya está facturado",
|
|
||||||
"A ticket with an amount of zero can't be invoiced": "No se puede facturar un ticket con importe cero",
|
|
||||||
"A ticket with a negative base can't be invoiced": "No se puede facturar un ticket con una base negativa",
|
|
||||||
"Global invoicing failed": "[Facturación global] No se han podido facturar algunos clientes",
|
|
||||||
"Wasn't able to invoice the following clients": "No se han podido facturar los siguientes clientes",
|
|
||||||
"Can't verify data unless the client has a business type": "No se puede verificar datos de un cliente que no tiene tipo de negocio",
|
|
||||||
"You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito",
|
|
||||||
"You can't change the credit set to zero from a financialBoss": "No puedes cambiar el cŕedito establecido a cero por un jefe de finanzas",
|
|
||||||
"Amounts do not match": "Las cantidades no coinciden",
|
|
||||||
"The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'",
|
|
||||||
"The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos",
|
|
||||||
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días",
|
|
||||||
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
|
|
||||||
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
|
|
||||||
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado",
|
|
||||||
"Can't transfer claimed sales": "No puedes transferir lineas reclamadas",
|
|
||||||
"You don't have privileges to create refund": "No tienes permisos para crear un abono",
|
|
||||||
"The item is required": "El artículo es requerido",
|
|
||||||
"The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo",
|
|
||||||
"date in the future": "Fecha en el futuro",
|
|
||||||
"reference duplicated": "Referencia duplicada",
|
|
||||||
"This ticket is already a refund": "Este ticket ya es un abono",
|
|
||||||
"isWithoutNegatives": "isWithoutNegatives",
|
|
||||||
"routeFk": "routeFk",
|
|
||||||
"Can't change the password of another worker": "No se puede cambiar la contraseña de otro trabajador",
|
|
||||||
"No hay un contrato en vigor": "No hay un contrato en vigor",
|
|
||||||
"No se permite fichar a futuro": "No se permite fichar a futuro",
|
|
||||||
"No está permitido trabajar": "No está permitido trabajar",
|
|
||||||
"Fichadas impares": "Fichadas impares",
|
|
||||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
|
||||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
|
||||||
"Dirección incorrecta": "Dirección incorrecta",
|
|
||||||
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
|
|
||||||
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
|
|
||||||
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente",
|
|
||||||
"Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*",
|
|
||||||
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
|
|
||||||
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario",
|
|
||||||
"Already has this status": "Ya tiene este estado",
|
"Already has this status": "Ya tiene este estado",
|
||||||
"There aren't records for this week": "No existen registros para esta semana"
|
"There aren't records for this week": "No existen registros para esta semana"
|
||||||
}
|
}
|
|
@ -5,6 +5,8 @@ const crypto = require('crypto');
|
||||||
const nthash = require('smbhash').nthash;
|
const nthash = require('smbhash').nthash;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
const shouldSync = process.env.NODE_ENV !== 'test';
|
||||||
|
|
||||||
Self.getSynchronizer = async function() {
|
Self.getSynchronizer = async function() {
|
||||||
return await Self.findOne({
|
return await Self.findOne({
|
||||||
fields: [
|
fields: [
|
||||||
|
@ -30,6 +32,7 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
|
|
||||||
async syncUser(userName, info, password) {
|
async syncUser(userName, info, password) {
|
||||||
|
|
||||||
let {
|
let {
|
||||||
client,
|
client,
|
||||||
accountConfig
|
accountConfig
|
||||||
|
@ -130,12 +133,13 @@ module.exports = Self => {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes.length)
|
if (shouldSync && changes.length)
|
||||||
await client.modify(dn, changes);
|
await client.modify(dn, changes);
|
||||||
} else
|
} else if (shouldSync)
|
||||||
await client.add(dn, newEntry);
|
await client.add(dn, newEntry);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
if (shouldSync)
|
||||||
await client.del(dn);
|
await client.del(dn);
|
||||||
console.log(` -> User '${userName}' removed from LDAP`);
|
console.log(` -> User '${userName}' removed from LDAP`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -196,10 +200,12 @@ module.exports = Self => {
|
||||||
for (let group of groups) {
|
for (let group of groups) {
|
||||||
try {
|
try {
|
||||||
let dn = `cn=${group},${groupDn}`;
|
let dn = `cn=${group},${groupDn}`;
|
||||||
|
if (shouldSync) {
|
||||||
await client.modify(dn, new ldap.Change({
|
await client.modify(dn, new ldap.Change({
|
||||||
operation,
|
operation,
|
||||||
modification: {memberUid: userName}
|
modification: {memberUid: userName}
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name !== 'NoSuchObjectError')
|
if (err.name !== 'NoSuchObjectError')
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -266,8 +272,10 @@ module.exports = Self => {
|
||||||
filter: 'objectClass=posixGroup'
|
filter: 'objectClass=posixGroup'
|
||||||
};
|
};
|
||||||
let reqs = [];
|
let reqs = [];
|
||||||
await client.searchForeach(this.groupDn, opts,
|
await client.searchForeach(this.groupDn, opts, object => {
|
||||||
o => reqs.push(client.del(o.dn)));
|
if (shouldSync)
|
||||||
|
reqs.push(client.del(object.dn));
|
||||||
|
});
|
||||||
await Promise.all(reqs);
|
await Promise.all(reqs);
|
||||||
|
|
||||||
// Recreate roles
|
// Recreate roles
|
||||||
|
@ -291,6 +299,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let dn = `cn=${role.name},${this.groupDn}`;
|
let dn = `cn=${role.name},${this.groupDn}`;
|
||||||
|
if (shouldSync)
|
||||||
reqs.push(client.add(dn, newEntry));
|
reqs.push(client.add(dn, newEntry));
|
||||||
}
|
}
|
||||||
await Promise.all(reqs);
|
await Promise.all(reqs);
|
||||||
|
|
|
@ -71,6 +71,9 @@ module.exports = Self => {
|
||||||
let isEnabled = sambaUser
|
let isEnabled = sambaUser
|
||||||
&& !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE);
|
&& !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE);
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'test')
|
||||||
|
return;
|
||||||
|
|
||||||
if (info.hasAccount) {
|
if (info.hasAccount) {
|
||||||
if (!sambaUser) {
|
if (!sambaUser) {
|
||||||
await sshClient.exec('samba-tool user create', [
|
await sshClient.exec('samba-tool user create', [
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
"acl": ["claimManager"]
|
"acl": ["claimManager"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/action",
|
"url": "/action?q",
|
||||||
"state": "claim.card.action",
|
"state": "claim.card.action",
|
||||||
"component": "vn-claim-action",
|
"component": "vn-claim-action",
|
||||||
"description": "Action",
|
"description": "Action",
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
|
||||||
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('filter', {
|
||||||
|
description: 'Find all clients matched by the filter',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'search',
|
||||||
|
type: 'string',
|
||||||
|
description: `If it's and integer searchs by id, otherwise it searchs by name`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'name',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The client name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'salesPersonFk',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'fi',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The client fiscal id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'socialName',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'city',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'postcode',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'provinceFk',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'email',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'phone',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'zoneFk',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/filter`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.filter = async(ctx, filter, options) => {
|
||||||
|
const conn = Self.dataSource.connector;
|
||||||
|
const myOptions = {};
|
||||||
|
const postalCode = [];
|
||||||
|
const args = ctx.args;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (args.zoneFk) {
|
||||||
|
query = `CALL vn.zone_getPostalCode(?)`;
|
||||||
|
const [geos] = await Self.rawSql(query, [args.zoneFk]);
|
||||||
|
for (let geo of geos)
|
||||||
|
postalCode.push(geo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const where = buildFilter(ctx.args, (param, value) => {
|
||||||
|
switch (param) {
|
||||||
|
case 'search':
|
||||||
|
return /^\d+$/.test(value)
|
||||||
|
? {'c.id': {inq: value}}
|
||||||
|
: {'c.name': {like: `%${value}%`}};
|
||||||
|
case 'name':
|
||||||
|
case 'salesPersonFk':
|
||||||
|
case 'fi':
|
||||||
|
case 'socialName':
|
||||||
|
case 'city':
|
||||||
|
case 'postcode':
|
||||||
|
case 'provinceFk':
|
||||||
|
case 'email':
|
||||||
|
case 'phone':
|
||||||
|
param = `c.${param}`;
|
||||||
|
return {[param]: value};
|
||||||
|
case 'zoneFk':
|
||||||
|
param = 'a.postalCode';
|
||||||
|
return {[param]: {inq: postalCode}};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filter = mergeFilters(filter, {where});
|
||||||
|
|
||||||
|
const stmts = [];
|
||||||
|
const stmt = new ParameterizedSQL(
|
||||||
|
`SELECT
|
||||||
|
DISTINCT c.id,
|
||||||
|
c.name,
|
||||||
|
c.fi,
|
||||||
|
c.socialName,
|
||||||
|
c.phone,
|
||||||
|
c.city,
|
||||||
|
c.postcode,
|
||||||
|
c.email,
|
||||||
|
c.isActive,
|
||||||
|
c.isFreezed,
|
||||||
|
p.id AS provinceFk,
|
||||||
|
p.name AS province,
|
||||||
|
u.id AS salesPersonFk,
|
||||||
|
u.name AS salesPerson
|
||||||
|
FROM client c
|
||||||
|
LEFT JOIN account.user u ON u.id = c.salesPersonFk
|
||||||
|
LEFT JOIN province p ON p.id = c.provinceFk
|
||||||
|
JOIN vn.address a ON a.clientFk = c.id
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
|
stmt.merge(conn.makePagination(filter));
|
||||||
|
|
||||||
|
const clientsIndex = stmts.push(stmt) - 1;
|
||||||
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
const result = await conn.executeStmt(sql, myOptions);
|
||||||
|
|
||||||
|
return clientsIndex === 0 ? result : result[clientsIndex];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,199 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('client filter()', () => {
|
||||||
|
it('should return the clients matching the filter with a limit of 20 rows', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {}};
|
||||||
|
const filter = {limit: '8'};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the client "Bruce Wayne" matching the search argument with his name', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {search: 'Bruce Wayne'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const firstResult = result[0];
|
||||||
|
|
||||||
|
expect(result.length).toEqual(1);
|
||||||
|
expect(firstResult.name).toEqual('Bruce Wayne');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the client "Bruce Wayne" matching the search argument with his id', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {search: '1101'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const firstResult = result[0];
|
||||||
|
|
||||||
|
expect(result.length).toEqual(1);
|
||||||
|
expect(firstResult.name).toEqual('Bruce Wayne');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the client "Bruce Wayne" matching the name argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {name: 'Bruce Wayne'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const firstResult = result[0];
|
||||||
|
|
||||||
|
expect(result.length).toEqual(1);
|
||||||
|
expect(firstResult.name).toEqual('Bruce Wayne');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the clients matching the "salesPersonFk" argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
const salesPersonId = 18;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {salesPersonFk: salesPersonId}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const randomIndex = Math.floor(Math.random() * result.length);
|
||||||
|
const randomResultClient = result[randomIndex];
|
||||||
|
|
||||||
|
expect(result.length).toBeGreaterThanOrEqual(5);
|
||||||
|
expect(randomResultClient.salesPersonFk).toEqual(salesPersonId);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the clients matching the "fi" argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {fi: '251628698'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const firstClient = result[0];
|
||||||
|
|
||||||
|
expect(result.length).toEqual(1);
|
||||||
|
expect(firstClient.name).toEqual('Max Eisenhardt');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the clients matching the "city" argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {city: 'Gotham'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const randomIndex = Math.floor(Math.random() * result.length);
|
||||||
|
const randomResultClient = result[randomIndex];
|
||||||
|
|
||||||
|
expect(result.length).toBeGreaterThanOrEqual(20);
|
||||||
|
expect(randomResultClient.city.toLowerCase()).toEqual('gotham');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the clients matching the "postcode" argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {postcode: '46460'}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
const randomIndex = Math.floor(Math.random() * result.length);
|
||||||
|
const randomResultClient = result[randomIndex];
|
||||||
|
|
||||||
|
expect(result.length).toBeGreaterThanOrEqual(20);
|
||||||
|
expect(randomResultClient.postcode).toEqual('46460');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the clients matching the "zoneFk" argument', async() => {
|
||||||
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}, args: {zoneFk: 9}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await models.Client.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
expect(result.length).toBe(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -8,6 +8,9 @@
|
||||||
"BankEntity": {
|
"BankEntity": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Business": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"BusinessType": {
|
"BusinessType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"name": "Business",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "business"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"worker": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Worker",
|
||||||
|
"foreignKey": "workerFk"
|
||||||
|
},
|
||||||
|
"department": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Department",
|
||||||
|
"foreignKey": "departmentFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,4 +47,5 @@ module.exports = Self => {
|
||||||
require('../methods/client/incotermsAuthorizationHtml')(Self);
|
require('../methods/client/incotermsAuthorizationHtml')(Self);
|
||||||
require('../methods/client/incotermsAuthorizationEmail')(Self);
|
require('../methods/client/incotermsAuthorizationEmail')(Self);
|
||||||
require('../methods/client/consumptionSendQueued')(Self);
|
require('../methods/client/consumptionSendQueued')(Self);
|
||||||
|
require('../methods/client/filter')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="Clients"
|
url="Clients/filter"
|
||||||
order="id DESC"
|
order="id DESC"
|
||||||
limit="8"
|
limit="8"
|
||||||
data="clients">
|
data="clients">
|
||||||
|
@ -10,8 +10,7 @@
|
||||||
vn-focus
|
vn-focus
|
||||||
panel="vn-client-search-panel"
|
panel="vn-client-search-panel"
|
||||||
info="Search client by id or name"
|
info="Search client by id or name"
|
||||||
model="model"
|
model="model">
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
</vn-portal>
|
</vn-portal>
|
||||||
<vn-portal slot="menu">
|
<vn-portal slot="menu">
|
||||||
|
|
|
@ -2,32 +2,6 @@ import ngModule from '../module';
|
||||||
import ModuleMain from 'salix/components/module-main';
|
import ModuleMain from 'salix/components/module-main';
|
||||||
|
|
||||||
export default class Client extends ModuleMain {
|
export default class Client extends ModuleMain {
|
||||||
exprBuilder(param, value) {
|
|
||||||
switch (param) {
|
|
||||||
case 'search':
|
|
||||||
return /^\d+$/.test(value)
|
|
||||||
? {id: value}
|
|
||||||
: {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]};
|
|
||||||
case 'phone':
|
|
||||||
return {
|
|
||||||
or: [
|
|
||||||
{phone: value},
|
|
||||||
{mobile: value}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
case 'name':
|
|
||||||
case 'socialName':
|
|
||||||
case 'city':
|
|
||||||
case 'email':
|
|
||||||
return {[param]: {like: `%${value}%`}};
|
|
||||||
case 'id':
|
|
||||||
case 'fi':
|
|
||||||
case 'postcode':
|
|
||||||
case 'provinceFk':
|
|
||||||
case 'salesPersonFk':
|
|
||||||
return {[param]: value};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnClient', {
|
ngModule.vnComponent('vnClient', {
|
||||||
|
|
|
@ -406,13 +406,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/defaulter",
|
"url": "/defaulter?q",
|
||||||
"state": "client.defaulter",
|
"state": "client.defaulter",
|
||||||
"component": "vn-client-defaulter",
|
"component": "vn-client-defaulter",
|
||||||
"description": "Defaulter"
|
"description": "Defaulter"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url" : "/notification",
|
"url" : "/notification?q",
|
||||||
"state": "client.notification",
|
"state": "client.notification",
|
||||||
"component": "vn-client-notification",
|
"component": "vn-client-notification",
|
||||||
"description": "Notifications"
|
"description": "Notifications"
|
||||||
|
@ -424,7 +424,7 @@
|
||||||
"description": "Unpaid"
|
"description": "Unpaid"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/extended-list",
|
"url": "/extended-list?q",
|
||||||
"state": "client.extendedList",
|
"state": "client.extendedList",
|
||||||
"component": "vn-client-extended-list",
|
"component": "vn-client-extended-list",
|
||||||
"description": "Extended list"
|
"description": "Extended list"
|
||||||
|
|
|
@ -58,6 +58,13 @@
|
||||||
value-field="id"
|
value-field="id"
|
||||||
label="Province">
|
label="Province">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
<vn-autocomplete
|
||||||
|
ng-model="filter.zoneFk"
|
||||||
|
url="Zones"
|
||||||
|
show-field="name"
|
||||||
|
value-field="id"
|
||||||
|
label="Zone">
|
||||||
|
</vn-autocomplete>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
|
|
|
@ -154,7 +154,8 @@ module.exports = Self => {
|
||||||
e.id,
|
e.id,
|
||||||
e.supplierFk,
|
e.supplierFk,
|
||||||
e.dated,
|
e.dated,
|
||||||
e.ref,
|
e.ref reference,
|
||||||
|
e.ref invoiceNumber,
|
||||||
e.isBooked,
|
e.isBooked,
|
||||||
e.isExcludedFromAvailable,
|
e.isExcludedFromAvailable,
|
||||||
e.notes,
|
e.notes,
|
||||||
|
|
|
@ -12,10 +12,15 @@ module.exports = Self => {
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'ref',
|
arg: 'reference',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The buyed boxes ids',
|
description: 'The buyed boxes ids',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'invoiceNumber',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The registered invoice number',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'observation',
|
arg: 'observation',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -63,7 +68,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
await entry.updateAttributes({
|
await entry.updateAttributes({
|
||||||
observation: args.observation,
|
observation: args.observation,
|
||||||
ref: args.ref
|
reference: args.reference,
|
||||||
|
invoiceNumber: args.invoiceNumber
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const travel = entry.travel();
|
const travel = entry.travel();
|
||||||
|
|
|
@ -15,13 +15,15 @@ describe('entry import()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should import the buy rows', async() => {
|
it('should import the buy rows', async() => {
|
||||||
const expectedRef = '1, 2';
|
const expectedReference = '1, 2';
|
||||||
|
const expectedInvoiceNumber = '1, 2';
|
||||||
const expectedObservation = '123456';
|
const expectedObservation = '123456';
|
||||||
const ctx = {
|
const ctx = {
|
||||||
req: activeCtx,
|
req: activeCtx,
|
||||||
args: {
|
args: {
|
||||||
observation: expectedObservation,
|
observation: expectedObservation,
|
||||||
ref: expectedRef,
|
reference: expectedReference,
|
||||||
|
invoiceNumber: expectedInvoiceNumber,
|
||||||
buys: [
|
buys: [
|
||||||
{
|
{
|
||||||
itemFk: 1,
|
itemFk: 1,
|
||||||
|
@ -58,7 +60,8 @@ describe('entry import()', () => {
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
expect(updatedEntry.observation).toEqual(expectedObservation);
|
expect(updatedEntry.observation).toEqual(expectedObservation);
|
||||||
expect(updatedEntry.ref).toEqual(expectedRef);
|
expect(updatedEntry.reference).toEqual(expectedReference);
|
||||||
|
expect(updatedEntry.invoiceNumber).toEqual(expectedInvoiceNumber);
|
||||||
expect(entryBuys.length).toEqual(4);
|
expect(entryBuys.length).toEqual(4);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -18,8 +18,17 @@
|
||||||
"dated": {
|
"dated": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
},
|
},
|
||||||
"ref": {
|
"reference": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"mysql": {
|
||||||
|
"columnName": "ref"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"invoiceNumber": {
|
||||||
|
"type": "string",
|
||||||
|
"mysql": {
|
||||||
|
"columnName": "ref"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"isBooked": {
|
"isBooked": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Reference"
|
label="Reference"
|
||||||
ng-model="$ctrl.entry.ref"
|
ng-model="$ctrl.entry.reference"
|
||||||
rule
|
rule
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
|
@ -61,12 +61,20 @@
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textarea
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Observation"
|
label="Invoice number"
|
||||||
ng-model="$ctrl.entry.observation"
|
ng-model="$ctrl.entry.invoiceNumber"
|
||||||
rule>
|
rule
|
||||||
</vn-textarea>
|
vn-focus>
|
||||||
|
</vn-textfield>
|
||||||
|
<vn-autocomplete
|
||||||
|
url="Companies"
|
||||||
|
label="Company"
|
||||||
|
show-field="code"
|
||||||
|
value-field="id"
|
||||||
|
ng-model="$ctrl.entry.companyFk">
|
||||||
|
</vn-autocomplete>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
|
@ -84,13 +92,14 @@
|
||||||
ng-model="$ctrl.entry.commission"
|
ng-model="$ctrl.entry.commission"
|
||||||
rule>
|
rule>
|
||||||
</vn-input-number>
|
</vn-input-number>
|
||||||
<vn-autocomplete
|
</vn-horizontal>
|
||||||
url="Companies"
|
<vn-horizontal>
|
||||||
label="Company"
|
<vn-textarea
|
||||||
show-field="code"
|
vn-one
|
||||||
value-field="id"
|
label="Observation"
|
||||||
ng-model="$ctrl.entry.companyFk">
|
ng-model="$ctrl.entry.observation"
|
||||||
</vn-autocomplete>
|
rule>
|
||||||
|
</vn-textarea>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-check
|
<vn-check
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<vn-th field="id" number>Id</vn-th>
|
<vn-th field="id" number>Id</vn-th>
|
||||||
<vn-th field="landed" center expand>Landed</vn-th>
|
<vn-th field="landed" center expand>Landed</vn-th>
|
||||||
<vn-th>Reference</vn-th>
|
<vn-th>Reference</vn-th>
|
||||||
|
<vn-th>Invoice number</vn-th>
|
||||||
<vn-th field="supplierFk">Supplier</vn-th>
|
<vn-th field="supplierFk">Supplier</vn-th>
|
||||||
<vn-th field="isBooked" center>Booked</vn-th>
|
<vn-th field="isBooked" center>Booked</vn-th>
|
||||||
<vn-th field="isConfirmed" center>Confirmed</vn-th>
|
<vn-th field="isConfirmed" center>Confirmed</vn-th>
|
||||||
|
@ -45,7 +46,8 @@
|
||||||
{{::entry.landed | date:'dd/MM/yyyy'}}
|
{{::entry.landed | date:'dd/MM/yyyy'}}
|
||||||
</span>
|
</span>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td expand>{{::entry.ref}}</vn-td>
|
<vn-td expand>{{::entry.reference}}</vn-td>
|
||||||
|
<vn-td expand>{{::entry.invoiceNumber}}</vn-td>
|
||||||
<vn-td expand>{{::entry.supplierName}}</vn-td>
|
<vn-td expand>{{::entry.supplierName}}</vn-td>
|
||||||
<vn-td center><vn-check ng-model="entry.isBooked" disabled="true"></vn-check></vn-td>
|
<vn-td center><vn-check ng-model="entry.isBooked" disabled="true"></vn-check></vn-td>
|
||||||
<vn-td center><vn-check ng-model="entry.isConfirmed" disabled="true"></vn-check></vn-td>
|
<vn-td center><vn-check ng-model="entry.isConfirmed" disabled="true"></vn-check></vn-td>
|
||||||
|
|
|
@ -15,3 +15,4 @@ Is inventory: Inventario
|
||||||
Notes: Notas
|
Notes: Notas
|
||||||
Status: Estado
|
Status: Estado
|
||||||
Selection: Selección
|
Selection: Selección
|
||||||
|
Invoice number: Núm. factura
|
|
@ -13,8 +13,15 @@
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Reference"
|
label="Reference"
|
||||||
ng-model="filter.ref">
|
ng-model="filter.reference">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Invoice number"
|
||||||
|
ng-model="filter.invoiceNumber">
|
||||||
|
</vn-textfield>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Travel"
|
label="Travel"
|
||||||
|
|
|
@ -6,3 +6,4 @@ To: Hasta
|
||||||
Agency: Agencia
|
Agency: Agencia
|
||||||
Warehouse: Almacén
|
Warehouse: Almacén
|
||||||
Search entry by id or a suppliers by name or alias: Buscar entrada por id o proveedores por nombre y alias
|
Search entry by id or a suppliers by name or alias: Buscar entrada por id o proveedores por nombre y alias
|
||||||
|
Invoice number: Núm. factura
|
|
@ -27,7 +27,10 @@
|
||||||
value="{{$ctrl.entryData.company.code}}">
|
value="{{$ctrl.entryData.company.code}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Reference"
|
<vn-label-value label="Reference"
|
||||||
value="{{$ctrl.entryData.ref}}">
|
value="{{$ctrl.entryData.reference}}">
|
||||||
|
</vn-label-value>
|
||||||
|
<vn-label-value label="Invoice number"
|
||||||
|
value="{{$ctrl.entryData.invoiceNumber}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Notes"
|
<vn-label-value label="Notes"
|
||||||
value="{{$ctrl.entryData.notes}}">
|
value="{{$ctrl.entryData.notes}}">
|
||||||
|
|
|
@ -8,4 +8,4 @@ Minimum price: Precio mínimo
|
||||||
Buys: Compras
|
Buys: Compras
|
||||||
Travel: Envio
|
Travel: Envio
|
||||||
Go to the entry: Ir a la entrada
|
Go to the entry: Ir a la entrada
|
||||||
|
Invoice number: Núm. factura
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('invoiceInEmail', {
|
||||||
|
description: 'Sends the invoice in email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The invoice id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/invoice-in-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.invoiceInEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('invoiceIn', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,50 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('invoiceInPdf', {
|
||||||
|
description: 'Returns the invoiceIn pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The invoiceIn id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
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: '/:id/invoice-in-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.invoiceInPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
delete args.ctx;
|
||||||
|
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('invoiceIn', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -4,4 +4,6 @@ module.exports = Self => {
|
||||||
require('../methods/invoice-in/clone')(Self);
|
require('../methods/invoice-in/clone')(Self);
|
||||||
require('../methods/invoice-in/toBook')(Self);
|
require('../methods/invoice-in/toBook')(Self);
|
||||||
require('../methods/invoice-in/getTotals')(Self);
|
require('../methods/invoice-in/getTotals')(Self);
|
||||||
|
require('../methods/invoice-in/invoiceInPdf')(Self);
|
||||||
|
require('../methods/invoice-in/invoiceInEmail')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -94,6 +94,11 @@
|
||||||
"model": "Supplier",
|
"model": "Supplier",
|
||||||
"foreignKey": "supplierFk"
|
"foreignKey": "supplierFk"
|
||||||
},
|
},
|
||||||
|
"supplierContact": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "SupplierContact",
|
||||||
|
"foreignKey": "supplierFk"
|
||||||
|
},
|
||||||
"currency": {
|
"currency": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Currency",
|
"model": "Currency",
|
||||||
|
|
|
@ -8,6 +8,14 @@ class Controller extends ModuleCard {
|
||||||
{
|
{
|
||||||
relation: 'supplier'
|
relation: 'supplier'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
relation: 'supplierContact',
|
||||||
|
scope: {
|
||||||
|
where: {
|
||||||
|
email: {neq: null}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
relation: 'invoiceInDueDay'
|
relation: 'invoiceInDueDay'
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
translate>
|
translate>
|
||||||
To book
|
To book
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="deleteConfirmation.show()"
|
ng-click="deleteConfirmation.show()"
|
||||||
vn-acl="administrative"
|
vn-acl="administrative"
|
||||||
|
@ -26,6 +25,16 @@
|
||||||
translate>
|
translate>
|
||||||
Clone Invoice
|
Clone Invoice
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
<vn-item
|
||||||
|
ng-click="$ctrl.showPdfInvoice()"
|
||||||
|
translate>
|
||||||
|
Show agricultural invoice as PDF
|
||||||
|
</vn-item>
|
||||||
|
<vn-item
|
||||||
|
ng-click="sendPdfConfirmation.show({email: $ctrl.entity.supplierContact[0].email})"
|
||||||
|
translate>
|
||||||
|
Send agricultural invoice as PDF
|
||||||
|
</vn-item>
|
||||||
</slot-menu>
|
</slot-menu>
|
||||||
<slot-body>
|
<slot-body>
|
||||||
<div class="attributes">
|
<div class="attributes">
|
||||||
|
@ -83,3 +92,21 @@
|
||||||
<vn-popup vn-id="summary">
|
<vn-popup vn-id="summary">
|
||||||
<vn-invoice-in-summary invoice-in="$ctrl.invoiceIn"></vn-invoice-in-summary>
|
<vn-invoice-in-summary invoice-in="$ctrl.invoiceIn"></vn-invoice-in-summary>
|
||||||
</vn-popup>
|
</vn-popup>
|
||||||
|
|
||||||
|
<!-- Send PDF invoice confirmation popup -->
|
||||||
|
<vn-dialog
|
||||||
|
vn-id="sendPdfConfirmation"
|
||||||
|
on-accept="$ctrl.sendPdfInvoice($data)"
|
||||||
|
message="Send PDF invoice">
|
||||||
|
<tpl-body>
|
||||||
|
<span translate>Are you sure you want to send it?</span>
|
||||||
|
<vn-textfield vn-one
|
||||||
|
label="Email"
|
||||||
|
ng-model="sendPdfConfirmation.data.email">
|
||||||
|
</vn-textfield>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
|
<button response="accept" translate>Confirm</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
||||||
|
|
|
@ -96,6 +96,20 @@ class Controller extends Descriptor {
|
||||||
.then(() => this.$state.reload())
|
.then(() => this.$state.reload())
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked')));
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showPdfInvoice() {
|
||||||
|
this.vnReport.show(`InvoiceIns/${this.id}/invoice-in-pdf`);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendPdfInvoice($data) {
|
||||||
|
if (!$data.email)
|
||||||
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
||||||
|
|
||||||
|
return this.vnEmail.send(`InvoiceIns/${this.entity.id}/invoice-in-email`, {
|
||||||
|
recipient: $data.email,
|
||||||
|
recipientId: this.entity.supplier.id
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnInvoiceInDescriptor', {
|
ngModule.vnComponent('vnInvoiceInDescriptor', {
|
||||||
|
|
|
@ -19,3 +19,5 @@ To book: Contabilizar
|
||||||
Total amount: Total importe
|
Total amount: Total importe
|
||||||
Total net: Total neto
|
Total net: Total neto
|
||||||
Total stems: Total tallos
|
Total stems: Total tallos
|
||||||
|
Show agricultural invoice as PDF: Ver factura agrícola como PDF
|
||||||
|
Send agricultural invoice as PDF: Enviar factura agrícola como PDF
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
const JSZip = require('jszip');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('downloadZip', {
|
||||||
|
description: 'Download a zip file with multiple invoices pdfs',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'ids',
|
||||||
|
type: ['number'],
|
||||||
|
description: 'The invoice ids'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
arg: 'base64',
|
||||||
|
type: 'string',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/downloadZip',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.downloadZip = async function(ctx, ids, options) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const zip = new JSZip();
|
||||||
|
let totalSize = 0;
|
||||||
|
const zipConfig = await models.ZipConfig.findOne(null, myOptions);
|
||||||
|
for (let id of ids) {
|
||||||
|
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
|
||||||
|
const invoiceOutPdf = await models.InvoiceOut.download(ctx, id, myOptions);
|
||||||
|
const fileName = extractFileName(invoiceOutPdf[2]);
|
||||||
|
const body = invoiceOutPdf[0];
|
||||||
|
const sizeInBytes = (await fs.promises.stat(body.path)).size;
|
||||||
|
const sizeInMegabytes = sizeInBytes / (1024 * 1024);
|
||||||
|
totalSize += sizeInMegabytes;
|
||||||
|
zip.file(fileName, body);
|
||||||
|
}
|
||||||
|
const base64 = await zip.generateAsync({type: 'base64'});
|
||||||
|
return base64;
|
||||||
|
};
|
||||||
|
|
||||||
|
function extractFileName(str) {
|
||||||
|
const matches = str.match(/"(.*?)"/);
|
||||||
|
return matches ? matches[1] : str;
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,53 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
describe('InvoiceOut downloadZip()', () => {
|
||||||
|
const userId = 9;
|
||||||
|
const invoiceIds = [1, 2];
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
|
||||||
|
accessToken: {userId: userId},
|
||||||
|
headers: {origin: 'http://localhost:5000'},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should return part of link to dowloand the zip', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.InvoiceOut.downloadZip(ctx, invoiceIds, options);
|
||||||
|
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an error if the size of the files is too large', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const zipConfig = {
|
||||||
|
maxSize: 0
|
||||||
|
};
|
||||||
|
await models.ZipConfig.create(zipConfig, options);
|
||||||
|
|
||||||
|
await models.InvoiceOut.downloadZip(ctx, invoiceIds, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toEqual(new UserError(`Files are too large`));
|
||||||
|
});
|
||||||
|
});
|
|
@ -22,5 +22,8 @@
|
||||||
},
|
},
|
||||||
"TaxType": {
|
"TaxType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"ZipConfig": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ module.exports = Self => {
|
||||||
require('../methods/invoiceOut/summary')(Self);
|
require('../methods/invoiceOut/summary')(Self);
|
||||||
require('../methods/invoiceOut/getTickets')(Self);
|
require('../methods/invoiceOut/getTickets')(Self);
|
||||||
require('../methods/invoiceOut/download')(Self);
|
require('../methods/invoiceOut/download')(Self);
|
||||||
|
require('../methods/invoiceOut/downloadZip')(Self);
|
||||||
require('../methods/invoiceOut/delete')(Self);
|
require('../methods/invoiceOut/delete')(Self);
|
||||||
require('../methods/invoiceOut/book')(Self);
|
require('../methods/invoiceOut/book')(Self);
|
||||||
require('../methods/invoiceOut/createPdf')(Self);
|
require('../methods/invoiceOut/createPdf')(Self);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"name": "ZipConfig",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "zipConfig"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"maxSize": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [{
|
||||||
|
"accessType": "READ",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}]
|
||||||
|
}
|
|
@ -4,10 +4,24 @@
|
||||||
<vn-data-viewer
|
<vn-data-viewer
|
||||||
model="model"
|
model="model"
|
||||||
class="vn-w-lg">
|
class="vn-w-lg">
|
||||||
|
<vn-card class="vn-pa-lg">
|
||||||
|
<vn-button
|
||||||
|
disabled="$ctrl.totalChecked == 0"
|
||||||
|
vn-click-stop="$ctrl.openPdf()"
|
||||||
|
icon="cloud_download"
|
||||||
|
title="Download PDF"
|
||||||
|
vn-tooltip="Download PDF">
|
||||||
|
</vn-button>
|
||||||
|
</vn-card>
|
||||||
<vn-card>
|
<vn-card>
|
||||||
<vn-table model="model">
|
<vn-table model="model">
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
|
<vn-th shrink>
|
||||||
|
<vn-multi-check
|
||||||
|
model="model">
|
||||||
|
</vn-multi-check>
|
||||||
|
</vn-th>
|
||||||
<vn-th field="ref">Reference</vn-th>
|
<vn-th field="ref">Reference</vn-th>
|
||||||
<vn-th field="issued" expand>Issued</vn-th>
|
<vn-th field="issued" expand>Issued</vn-th>
|
||||||
<vn-th field="amount" number>Amount</vn-th>
|
<vn-th field="amount" number>Amount</vn-th>
|
||||||
|
@ -23,6 +37,12 @@
|
||||||
<a ng-repeat="invoiceOut in model.data"
|
<a ng-repeat="invoiceOut in model.data"
|
||||||
class="clickable vn-tr search-result"
|
class="clickable vn-tr search-result"
|
||||||
ui-sref="invoiceOut.card.summary({id: {{::invoiceOut.id}}})">
|
ui-sref="invoiceOut.card.summary({id: {{::invoiceOut.id}}})">
|
||||||
|
<vn-td>
|
||||||
|
<vn-check
|
||||||
|
ng-model="invoiceOut.checked"
|
||||||
|
vn-click-stop>
|
||||||
|
</vn-check>
|
||||||
|
</vn-td>
|
||||||
<vn-td>{{::invoiceOut.ref | dashIfEmpty}}</vn-td>
|
<vn-td>{{::invoiceOut.ref | dashIfEmpty}}</vn-td>
|
||||||
<vn-td shrink>{{::invoiceOut.issued | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
<vn-td shrink>{{::invoiceOut.issued | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
||||||
<vn-td number>{{::invoiceOut.amount | currency: 'EUR': 2 | dashIfEmpty}}</vn-td>
|
<vn-td number>{{::invoiceOut.amount | currency: 'EUR': 2 | dashIfEmpty}}</vn-td>
|
||||||
|
@ -36,15 +56,6 @@
|
||||||
<vn-td expand>{{::invoiceOut.created | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
<vn-td expand>{{::invoiceOut.created | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
||||||
<vn-td>{{::invoiceOut.companyCode | dashIfEmpty}}</vn-td>
|
<vn-td>{{::invoiceOut.companyCode | dashIfEmpty}}</vn-td>
|
||||||
<vn-td shrink>{{::invoiceOut.dued | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
<vn-td shrink>{{::invoiceOut.dued | date:'dd/MM/yyyy' | dashIfEmpty}}</vn-td>
|
||||||
<vn-td shrink>
|
|
||||||
<vn-icon-button
|
|
||||||
ng-show="invoiceOut.hasPdf"
|
|
||||||
vn-click-stop="$ctrl.openPdf(invoiceOut.id)"
|
|
||||||
icon="cloud_download"
|
|
||||||
title="Download PDF"
|
|
||||||
vn-tooltip="Download PDF">
|
|
||||||
</vn-icon-button>
|
|
||||||
</vn-td>
|
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
vn-click-stop="$ctrl.preview(invoiceOut)"
|
vn-click-stop="$ctrl.preview(invoiceOut)"
|
||||||
|
|
|
@ -2,14 +2,41 @@ import ngModule from '../module';
|
||||||
import Section from 'salix/components/section';
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
|
get checked() {
|
||||||
|
const rows = this.$.model.data || [];
|
||||||
|
const checkedRows = [];
|
||||||
|
for (let row of rows) {
|
||||||
|
if (row.checked)
|
||||||
|
checkedRows.push(row.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkedRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
get totalChecked() {
|
||||||
|
return this.checked.length;
|
||||||
|
}
|
||||||
|
|
||||||
preview(invoiceOut) {
|
preview(invoiceOut) {
|
||||||
this.selectedInvoiceOut = invoiceOut;
|
this.selectedInvoiceOut = invoiceOut;
|
||||||
this.$.summary.show();
|
this.$.summary.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
openPdf(id) {
|
openPdf() {
|
||||||
let url = `api/InvoiceOuts/${id}/download?access_token=${this.vnToken.token}`;
|
if (this.checked.length <= 1) {
|
||||||
|
const [invoiceOutId] = this.checked;
|
||||||
|
const url = `api/InvoiceOuts/${invoiceOutId}/download?access_token=${this.vnToken.token}`;
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
|
} else {
|
||||||
|
const invoiceOutIds = this.checked;
|
||||||
|
const params = {
|
||||||
|
ids: invoiceOutIds
|
||||||
|
};
|
||||||
|
this.$http.post(`InvoiceOuts/downloadZip`, params)
|
||||||
|
.then(res => {
|
||||||
|
location.href = 'data:application/zip;base64,' + res.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,4 @@ Minimum: Minimo
|
||||||
Maximum: Máximo
|
Maximum: Máximo
|
||||||
Global invoicing: Facturación global
|
Global invoicing: Facturación global
|
||||||
Manual invoicing: Facturación manual
|
Manual invoicing: Facturación manual
|
||||||
|
Files are too large: Los archivos son demasiado grandes
|
|
@ -0,0 +1,51 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('deleteItemShelvings', {
|
||||||
|
description: 'Deletes the selected item shelvings',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'itemShelvingIds',
|
||||||
|
type: ['number'],
|
||||||
|
required: true,
|
||||||
|
description: 'The itemShelving ids to delete'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/deleteItemShelvings`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.deleteItemShelvings = async(itemShelvingIds, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const promises = [];
|
||||||
|
for (let itemShelvingId of itemShelvingIds) {
|
||||||
|
const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions);
|
||||||
|
promises.push(itemShelvingToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deletedItemShelvings = await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return deletedItemShelvings;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,21 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('ItemShelving deleteItemShelvings()', () => {
|
||||||
|
it('should return the deleted itemShelvings', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const itemShelvingIds = [1, 2];
|
||||||
|
const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -53,6 +53,9 @@
|
||||||
"ItemShelvingSale": {
|
"ItemShelvingSale": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"ItemShelvingPlacementSupplyStock": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"ItemImageQueue": {
|
"ItemImageQueue": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"name": "ItemShelvingPlacementSupplyStock",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "itemShelvingPlacementSupplyStock"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"itemShelvingFk": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"itemFk": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"longName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"parking": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"shelving": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"packing": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"stock": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||||
|
};
|
|
@ -34,7 +34,7 @@
|
||||||
<th field="itemFk">
|
<th field="itemFk">
|
||||||
<span translate>Item ID</span>
|
<span translate>Item ID</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="itemName">
|
<th field="name">
|
||||||
<span translate>Description</span>
|
<span translate>Description</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="warehouseFk">
|
<th field="warehouseFk">
|
||||||
|
|
|
@ -12,14 +12,6 @@ export default class Controller extends Section {
|
||||||
},
|
},
|
||||||
defaultSearch: true,
|
defaultSearch: true,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
|
||||||
field: 'itemName',
|
|
||||||
autocomplete: {
|
|
||||||
url: 'Items',
|
|
||||||
showField: 'name',
|
|
||||||
valueField: 'id'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
field: 'warehouseFk',
|
field: 'warehouseFk',
|
||||||
autocomplete: {
|
autocomplete: {
|
||||||
|
@ -105,8 +97,8 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
exprBuilder(param, value) {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'itemName':
|
case 'name':
|
||||||
return {'i.id': value};
|
return {'i.name': {like: `%${value}%`}};
|
||||||
case 'itemFk':
|
case 'itemFk':
|
||||||
case 'warehouseFk':
|
case 'warehouseFk':
|
||||||
case 'rate2':
|
case 'rate2':
|
||||||
|
|
|
@ -24,3 +24,5 @@ import './waste/detail';
|
||||||
import './fixed-price';
|
import './fixed-price';
|
||||||
import './fixed-price-search-panel';
|
import './fixed-price-search-panel';
|
||||||
import './item-type';
|
import './item-type';
|
||||||
|
import './item-shelving';
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
<vn-crud-model
|
||||||
|
vn-id="model"
|
||||||
|
url="ItemShelvingPlacementSupplyStocks"
|
||||||
|
link="{itemFk: $ctrl.$params.id}"
|
||||||
|
data="$ctrl.itemShelvingPlacementSupplyStocks"
|
||||||
|
auto-load="true">
|
||||||
|
</vn-crud-model>
|
||||||
|
<vn-card>
|
||||||
|
<smart-table
|
||||||
|
model="model"
|
||||||
|
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="Total labels"
|
||||||
|
value="{{$ctrl.labelTotal.toFixed(2)}}">
|
||||||
|
</vn-label-value>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="vn-pa-md">
|
||||||
|
<vn-button
|
||||||
|
disabled="!$ctrl.checked.length"
|
||||||
|
ng-click="removeConfirm.show()"
|
||||||
|
icon="delete"
|
||||||
|
vn-tooltip="Remove selected lines"
|
||||||
|
vn-acl="replenisherBos">
|
||||||
|
</vn-button>
|
||||||
|
</div>
|
||||||
|
</slot-actions>
|
||||||
|
<slot-table>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th shrink>
|
||||||
|
<vn-multi-check
|
||||||
|
model="model">
|
||||||
|
</vn-multi-check>
|
||||||
|
</th>
|
||||||
|
<th field="created">
|
||||||
|
<span translate>Created</span>
|
||||||
|
</th>
|
||||||
|
<th shrink field="itemFk">
|
||||||
|
<span translate>Item</span>
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
field="longName">
|
||||||
|
<span translate>Concept</span>
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
field="parking">
|
||||||
|
<span translate>Parking</span>
|
||||||
|
</th>
|
||||||
|
<th field="shelving">
|
||||||
|
<span translate>Shelving</span>
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
field="label">
|
||||||
|
<span translate>Etiqueta</span>
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
field="packing"
|
||||||
|
shrink>
|
||||||
|
<span translate>Packing</span>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
ng-repeat="itemShelvingPlacementSupplyStock in $ctrl.itemShelvingPlacementSupplyStocks"
|
||||||
|
vn-repeat-last on-last="$ctrl.calculateTotals()">
|
||||||
|
<td shrink>
|
||||||
|
<vn-check
|
||||||
|
ng-model="itemShelvingPlacementSupplyStock.checked"
|
||||||
|
vn-click-stop>
|
||||||
|
</vn-check>
|
||||||
|
</td>
|
||||||
|
<td shrink-date>{{::itemShelvingPlacementSupplyStock.created | date: 'dd/MM/yyyy'}}</td>
|
||||||
|
<td>
|
||||||
|
{{::itemShelvingPlacementSupplyStock.itemFk}}
|
||||||
|
</td>
|
||||||
|
<td expand title="{{::itemShelvingPlacementSupplyStock.longName}}">
|
||||||
|
<span
|
||||||
|
vn-click-stop="itemDescriptor.show($event, itemShelvingPlacementSupplyStock.itemFk)"
|
||||||
|
class="link">
|
||||||
|
{{itemShelvingPlacementSupplyStock.longName}}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{::itemShelvingPlacementSupplyStock.parking}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{::itemShelvingPlacementSupplyStock.shelving}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{::itemShelvingPlacementSupplyStock.packing}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</slot-table>
|
||||||
|
</smart-table>
|
||||||
|
</vn-card>
|
||||||
|
<vn-item-descriptor-popover
|
||||||
|
vn-id="item-descriptor">
|
||||||
|
</vn-item-descriptor-popover>
|
||||||
|
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="removeConfirm"
|
||||||
|
message="Selected lines will be deleted"
|
||||||
|
question="Are you sure you want to continue?"
|
||||||
|
on-accept="$ctrl.onRemove()">
|
||||||
|
</vn-confirm>
|
|
@ -0,0 +1,89 @@
|
||||||
|
import ngModule from '../module';
|
||||||
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
|
export default class Controller extends Section {
|
||||||
|
constructor($element, $) {
|
||||||
|
super($element, $);
|
||||||
|
|
||||||
|
this.smartTableOptions = {
|
||||||
|
activeButtons: {
|
||||||
|
search: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'parking',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Parkings',
|
||||||
|
showField: 'code',
|
||||||
|
valueField: 'code'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'shelving',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Shelvings',
|
||||||
|
showField: 'code',
|
||||||
|
valueField: 'code'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'created',
|
||||||
|
searchable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'itemFk',
|
||||||
|
searchable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'longName',
|
||||||
|
searchable: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get checked() {
|
||||||
|
const itemShelvings = this.$.model.data || [];
|
||||||
|
const checkedLines = [];
|
||||||
|
for (let itemShelving of itemShelvings) {
|
||||||
|
if (itemShelving.checked)
|
||||||
|
checkedLines.push(itemShelving.itemShelvingFk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkedLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateTotals() {
|
||||||
|
this.labelTotal = 0;
|
||||||
|
const itemShelvings = this.$.model.data || [];
|
||||||
|
itemShelvings.forEach(itemShelving => {
|
||||||
|
const label = itemShelving.stock / itemShelving.packing;
|
||||||
|
this.labelTotal += label;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onRemove() {
|
||||||
|
const params = {itemShelvingIds: this.checked};
|
||||||
|
const query = `ItemShelvings/deleteItemShelvings`;
|
||||||
|
this.$http.post(query, params)
|
||||||
|
.then(() => {
|
||||||
|
this.vnApp.showSuccess(this.$t('ItemShelvings removed'));
|
||||||
|
this.$.model.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exprBuilder(param, value) {
|
||||||
|
switch (param) {
|
||||||
|
case 'parking':
|
||||||
|
case 'shelving':
|
||||||
|
case 'label':
|
||||||
|
case 'packing':
|
||||||
|
return {[param]: value};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnItemShelving', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller
|
||||||
|
});
|
|
@ -0,0 +1,81 @@
|
||||||
|
import './index';
|
||||||
|
import crudModel from 'core/mocks/crud-model';
|
||||||
|
|
||||||
|
describe('item shelving', () => {
|
||||||
|
describe('Component vnItemShelving', () => {
|
||||||
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
|
beforeEach(ngModule('item'));
|
||||||
|
|
||||||
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
const $element = angular.element('<vn-item-shelving></vn-item-shelving>');
|
||||||
|
controller = $componentController('vnItemShelving', {$element});
|
||||||
|
controller.$.model = crudModel;
|
||||||
|
controller.$.model.data = [
|
||||||
|
{itemShelvingFk: 1, packing: 10, stock: 1},
|
||||||
|
{itemShelvingFk: 2, packing: 12, stock: 5},
|
||||||
|
{itemShelvingFk: 4, packing: 20, stock: 10}
|
||||||
|
];
|
||||||
|
const modelData = controller.$.model.data;
|
||||||
|
modelData[0].checked = true;
|
||||||
|
modelData[1].checked = true;
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('checked() getter', () => {
|
||||||
|
it('should return a the selected rows', () => {
|
||||||
|
const result = controller.checked;
|
||||||
|
|
||||||
|
expect(result).toEqual(expect.arrayContaining([1, 2]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('calculateTotals()', () => {
|
||||||
|
it('should calculate the total of labels', () => {
|
||||||
|
controller.calculateTotals();
|
||||||
|
|
||||||
|
expect(controller.labelTotal).toEqual(1.0166666666666666);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onRemove()', () => {
|
||||||
|
it('shoud remove the selected lines', () => {
|
||||||
|
jest.spyOn(controller.$.model, 'refresh');
|
||||||
|
const expectedParams = {itemShelvingIds: [1, 2]};
|
||||||
|
|
||||||
|
$httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200);
|
||||||
|
controller.onRemove();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$.model.refresh).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('exprBuilder()', () => {
|
||||||
|
it('should search by parking', () => {
|
||||||
|
const expr = controller.exprBuilder('parking', '700-01');
|
||||||
|
|
||||||
|
expect(expr).toEqual({'parking': '700-01'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should search by shelving', () => {
|
||||||
|
const expr = controller.exprBuilder('shelving', 'AAA');
|
||||||
|
|
||||||
|
expect(expr).toEqual({'shelving': 'AAA'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should search by label', () => {
|
||||||
|
const expr = controller.exprBuilder('label', 0.17);
|
||||||
|
|
||||||
|
expect(expr).toEqual({'label': 0.17});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should search by packing', () => {
|
||||||
|
const expr = controller.exprBuilder('packing', 10);
|
||||||
|
|
||||||
|
expect(expr).toEqual({'packing': 10});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
Shelving: Matrícula
|
||||||
|
Remove selected lines: Eliminar líneas seleccionadas
|
||||||
|
Selected lines will be deleted: Las líneas seleccionadas serán eliminadas
|
||||||
|
ItemShelvings removed: Carros eliminados
|
||||||
|
Total labels: Total etiquetas
|
|
@ -54,6 +54,7 @@ Basic data: Datos básicos
|
||||||
Tax: IVA
|
Tax: IVA
|
||||||
History: Historial
|
History: Historial
|
||||||
Botanical: Botánico
|
Botanical: Botánico
|
||||||
|
Shelvings: Carros
|
||||||
Barcodes: Códigos de barras
|
Barcodes: Códigos de barras
|
||||||
Diary: Histórico
|
Diary: Histórico
|
||||||
Item diary: Registro de compra-venta
|
Item diary: Registro de compra-venta
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
"card": [
|
"card": [
|
||||||
{"state": "item.card.basicData", "icon": "settings"},
|
{"state": "item.card.basicData", "icon": "settings"},
|
||||||
{"state": "item.card.tags", "icon": "icon-tags"},
|
{"state": "item.card.tags", "icon": "icon-tags"},
|
||||||
|
{"state": "item.card.last-entries", "icon": "icon-regentry"},
|
||||||
{"state": "item.card.tax", "icon": "icon-tax"},
|
{"state": "item.card.tax", "icon": "icon-tax"},
|
||||||
{"state": "item.card.botanical", "icon": "local_florist"},
|
{"state": "item.card.botanical", "icon": "local_florist"},
|
||||||
|
{"state": "item.card.shelving", "icon": "icon-inventory"},
|
||||||
{"state": "item.card.itemBarcode", "icon": "icon-barcode"},
|
{"state": "item.card.itemBarcode", "icon": "icon-barcode"},
|
||||||
{"state": "item.card.diary", "icon": "icon-transaction"},
|
{"state": "item.card.diary", "icon": "icon-transaction"},
|
||||||
{"state": "item.card.last-entries", "icon": "icon-regentry"},
|
|
||||||
{"state": "item.card.log", "icon": "history"}
|
{"state": "item.card.log", "icon": "history"}
|
||||||
],
|
],
|
||||||
"itemType": [
|
"itemType": [
|
||||||
|
@ -92,6 +93,16 @@
|
||||||
},
|
},
|
||||||
"acl": ["buyer"]
|
"acl": ["buyer"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"url" : "/shelving",
|
||||||
|
"state": "item.card.shelving",
|
||||||
|
"component": "vn-item-shelving",
|
||||||
|
"description": "Shelvings",
|
||||||
|
"params": {
|
||||||
|
"item": "$ctrl.item"
|
||||||
|
},
|
||||||
|
"acl": ["employee"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"url" : "/barcode",
|
"url" : "/barcode",
|
||||||
"state": "item.card.itemBarcode",
|
"state": "item.card.itemBarcode",
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
model="model"
|
model="model"
|
||||||
options="$ctrl.smartTableOptions"
|
options="$ctrl.smartTableOptions"
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
expr-builder="$ctrl.exprBuilder(param, value)"
|
||||||
|
disabled-table-filter="true"
|
||||||
|
disabled-table-order="true"
|
||||||
class="scrollable sm">
|
class="scrollable sm">
|
||||||
<slot-actions>
|
<slot-actions>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
"abstract": true,
|
"abstract": true,
|
||||||
"component": "vn-route-card"
|
"component": "vn-route-card"
|
||||||
}, {
|
}, {
|
||||||
"url": "/agency-term",
|
"url": "/agency-term?q",
|
||||||
"abstract": true,
|
"abstract": true,
|
||||||
"state": "route.agencyTerm",
|
"state": "route.agencyTerm",
|
||||||
"component": "ui-view"
|
"component": "ui-view"
|
||||||
|
|
|
@ -13,9 +13,6 @@
|
||||||
{"state": "shelving.card.log", "icon": "history"}
|
{"state": "shelving.card.log", "icon": "history"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"keybindings": [
|
|
||||||
{"key": "s", "state": "shelving.index"}
|
|
||||||
],
|
|
||||||
"routes": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"url": "/shelving",
|
"url": "/shelving",
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
"isSerious": {
|
"isSerious": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"isTrucker": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"note": {
|
"note": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Controller extends Descriptor {
|
||||||
'payDay',
|
'payDay',
|
||||||
'isActive',
|
'isActive',
|
||||||
'isSerious',
|
'isSerious',
|
||||||
|
'isTrucker',
|
||||||
'account'
|
'account'
|
||||||
],
|
],
|
||||||
include: [
|
include: [
|
||||||
|
|
|
@ -27,6 +27,7 @@ describe('Supplier Component vnSupplierDescriptor', () => {
|
||||||
'payDay',
|
'payDay',
|
||||||
'isActive',
|
'isActive',
|
||||||
'isSerious',
|
'isSerious',
|
||||||
|
'isTrucker',
|
||||||
'account'
|
'account'
|
||||||
],
|
],
|
||||||
include: [
|
include: [
|
||||||
|
|
|
@ -118,8 +118,6 @@
|
||||||
rule
|
rule
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
|
||||||
<vn-horizontal>
|
|
||||||
<vn-datalist vn-one
|
<vn-datalist vn-one
|
||||||
label="Postcode"
|
label="Postcode"
|
||||||
ng-model="$ctrl.supplier.postCode"
|
ng-model="$ctrl.supplier.postCode"
|
||||||
|
@ -144,6 +142,8 @@
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</append>
|
</append>
|
||||||
</vn-datalist>
|
</vn-datalist>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
<vn-datalist vn-id="town" vn-one
|
<vn-datalist vn-id="town" vn-one
|
||||||
label="City"
|
label="City"
|
||||||
ng-model="$ctrl.supplier.city"
|
ng-model="$ctrl.supplier.city"
|
||||||
|
@ -159,8 +159,6 @@
|
||||||
({{province.country.country}})
|
({{province.country.country}})
|
||||||
</tpl-item>
|
</tpl-item>
|
||||||
</vn-datalist>
|
</vn-datalist>
|
||||||
</vn-horizontal>
|
|
||||||
<vn-horizontal>
|
|
||||||
<vn-autocomplete vn-id="province" vn-one
|
<vn-autocomplete vn-id="province" vn-one
|
||||||
label="Province"
|
label="Province"
|
||||||
ng-model="$ctrl.supplier.provinceFk"
|
ng-model="$ctrl.supplier.provinceFk"
|
||||||
|
@ -172,6 +170,8 @@
|
||||||
rule>
|
rule>
|
||||||
<tpl-item>{{name}} ({{country.country}})</tpl-item>
|
<tpl-item>{{name}} ({{country.country}})</tpl-item>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
<vn-autocomplete vn-id="country" vn-one
|
<vn-autocomplete vn-id="country" vn-one
|
||||||
ng-model="$ctrl.supplier.countryFk"
|
ng-model="$ctrl.supplier.countryFk"
|
||||||
data="countries"
|
data="countries"
|
||||||
|
@ -180,6 +180,10 @@
|
||||||
label="Country"
|
label="Country"
|
||||||
rule>
|
rule>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
<vn-check
|
||||||
|
label="Trucker"
|
||||||
|
ng-model="$ctrl.supplier.isTrucker">
|
||||||
|
</vn-check>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
|
|
|
@ -3,3 +3,4 @@ Sage transaction type: Tipo de transacción Sage
|
||||||
Sage withholding: Retención Sage
|
Sage withholding: Retención Sage
|
||||||
Supplier activity: Actividad proveedor
|
Supplier activity: Actividad proveedor
|
||||||
Healt register: Pasaporte sanitario
|
Healt register: Pasaporte sanitario
|
||||||
|
Trucker: Transportista
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('deleteExpeditions', {
|
||||||
|
description: 'Delete the selected expeditions',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'expeditionIds',
|
||||||
|
type: ['number'],
|
||||||
|
required: true,
|
||||||
|
description: 'The expeditions ids to delete'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/deleteExpeditions`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.deleteExpeditions = async(expeditionIds, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const promises = [];
|
||||||
|
for (let expeditionId of expeditionIds) {
|
||||||
|
const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions);
|
||||||
|
promises.push(deletedExpedition);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deletedExpeditions = await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return deletedExpeditions;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,93 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('moveExpeditions', {
|
||||||
|
description: 'Move the selected expeditions to another ticket',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'clientId',
|
||||||
|
type: 'number',
|
||||||
|
description: `The client id`,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'landed',
|
||||||
|
type: 'date',
|
||||||
|
description: `The landing date`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'warehouseId',
|
||||||
|
type: 'number',
|
||||||
|
description: `The warehouse id`,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'addressId',
|
||||||
|
type: 'number',
|
||||||
|
description: `The address id`,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'agencyModeId',
|
||||||
|
type: 'any',
|
||||||
|
description: `The agencyMode id`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'routeId',
|
||||||
|
type: 'any',
|
||||||
|
description: `The route id`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'expeditionIds',
|
||||||
|
type: ['number'],
|
||||||
|
required: true,
|
||||||
|
description: 'The expeditions ids to move'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/moveExpeditions`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.moveExpeditions = async(ctx, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const args = ctx.args;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (args.routeId) {
|
||||||
|
const route = await models.Route.findById(args.routeId, null, myOptions);
|
||||||
|
if (!route) throw new UserError('This route does not exists');
|
||||||
|
}
|
||||||
|
const ticket = await models.Ticket.new(ctx, myOptions);
|
||||||
|
const promises = [];
|
||||||
|
for (let expeditionsId of args.expeditionIds) {
|
||||||
|
const expeditionToUpdate = await models.Expedition.findById(expeditionsId, null, myOptions);
|
||||||
|
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions);
|
||||||
|
promises.push(expeditionUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,22 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('ticket deleteExpeditions()', () => {
|
||||||
|
it('should delete the selected expeditions', async() => {
|
||||||
|
const tx = await models.Expedition.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const expeditionIds = [12, 13];
|
||||||
|
const result = await models.Expedition.deleteExpeditions(expeditionIds, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('ticket moveExpeditions()', () => {
|
||||||
|
it('should move the selected expeditions to new ticket', async() => {
|
||||||
|
const tx = await models.Expedition.beginTransaction({});
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: 9}},
|
||||||
|
args: {},
|
||||||
|
params: {}
|
||||||
|
};
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
myCtx.args = {
|
||||||
|
clientId: 1101,
|
||||||
|
landed: new Date(),
|
||||||
|
warehouseId: 1,
|
||||||
|
addressId: 121,
|
||||||
|
agencyModeId: 1,
|
||||||
|
routeId: null,
|
||||||
|
expeditionIds: [1, 2]
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const ticket = await models.Expedition.moveExpeditions(myCtx, options);
|
||||||
|
|
||||||
|
const newestTicketIdInFixtures = 27;
|
||||||
|
|
||||||
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -79,10 +79,18 @@ describe('sale updatePrice()', () => {
|
||||||
const price = 5.4;
|
const price = 5.4;
|
||||||
const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options);
|
const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options);
|
||||||
const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options);
|
const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options);
|
||||||
|
const teamOne = 96;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||||
|
await business.updateAttribute('departmentFk', teamOne, options);
|
||||||
|
|
||||||
await models.Sale.updatePrice(ctx, saleId, price, options);
|
await models.Sale.updatePrice(ctx, saleId, price, options);
|
||||||
const updatedSale = await models.Sale.findById(saleId, null, options);
|
const updatedSale = await models.Sale.findById(saleId, null, options);
|
||||||
createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options);
|
const createdSaleComponent = await models.SaleComponent.findOne({
|
||||||
|
where: {
|
||||||
|
saleFk: saleId, componentFk: manaComponent.id
|
||||||
|
}}, options);
|
||||||
|
|
||||||
expect(updatedSale.price).toBe(price);
|
expect(updatedSale.price).toBe(price);
|
||||||
expect(createdSaleComponent.value).toEqual(-2.04);
|
expect(createdSaleComponent.value).toEqual(-2.04);
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('sale usesMana()', () => {
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 18}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should return that the worker uses mana', async() => {
|
||||||
|
const tx = await models.Sale.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const teamOne = 96;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||||
|
await business.updateAttribute('departmentFk', teamOne, options);
|
||||||
|
|
||||||
|
const usesMana = await models.Sale.usesMana(ctx, options);
|
||||||
|
|
||||||
|
expect(usesMana).toBe(true);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return that the worker not uses mana', async() => {
|
||||||
|
const tx = await models.Sale.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const usesMana = await models.Sale.usesMana(ctx, options);
|
||||||
|
|
||||||
|
expect(usesMana).toBe(false);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -77,7 +77,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
const oldPrice = sale.price;
|
const oldPrice = sale.price;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions);
|
|
||||||
|
const usesMana = await models.Sale.usesMana(ctx, myOptions);
|
||||||
const componentCode = usesMana ? 'mana' : 'buyerDiscount';
|
const componentCode = usesMana ? 'mana' : 'buyerDiscount';
|
||||||
const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions);
|
const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions);
|
||||||
const componentId = discount.id;
|
const componentId = discount.id;
|
||||||
|
@ -88,7 +89,6 @@ module.exports = Self => {
|
||||||
saleFk: id
|
saleFk: id
|
||||||
};
|
};
|
||||||
const saleComponent = await models.SaleComponent.findOne({where}, myOptions);
|
const saleComponent = await models.SaleComponent.findOne({where}, myOptions);
|
||||||
|
|
||||||
if (saleComponent) {
|
if (saleComponent) {
|
||||||
await models.SaleComponent.updateAll(where, {
|
await models.SaleComponent.updateAll(where, {
|
||||||
value: saleComponent.value + componentValue
|
value: saleComponent.value + componentValue
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('usesMana', {
|
||||||
|
description: 'Returns if the worker uses mana',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [],
|
||||||
|
returns: {
|
||||||
|
type: 'boolean',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/usesMana`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.usesMana = async(ctx, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
|
||||||
|
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
|
||||||
|
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
|
||||||
|
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
|
||||||
|
|
||||||
|
return usesMana ? true : false;
|
||||||
|
};
|
||||||
|
};
|
|
@ -18,9 +18,12 @@ describe('ticket componentUpdate()', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}});
|
const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}});
|
||||||
deliveryComponentId = deliveryComponenet.id;
|
deliveryComponentId = deliveryComponenet.id;
|
||||||
componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
|
componentOfSaleSeven = `SELECT value
|
||||||
componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`;
|
FROM vn.saleComponent
|
||||||
|
WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
|
||||||
|
componentOfSaleEight = `SELECT value
|
||||||
|
FROM vn.saleComponent
|
||||||
|
WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`;
|
||||||
[componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven);
|
[componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven);
|
||||||
firstvalueBeforeChange = componentValue.value;
|
firstvalueBeforeChange = componentValue.value;
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,11 @@ describe('sale updateDiscount()', () => {
|
||||||
const componentId = manaDiscount.id;
|
const componentId = manaDiscount.id;
|
||||||
const manaCode = 'mana';
|
const manaCode = 'mana';
|
||||||
|
|
||||||
|
const teamOne = 96;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||||
|
await business.updateAttribute('departmentFk', teamOne, options);
|
||||||
|
|
||||||
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
||||||
|
|
||||||
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
||||||
|
@ -150,6 +155,11 @@ describe('sale updateDiscount()', () => {
|
||||||
const componentId = manaDiscount.id;
|
const componentId = manaDiscount.id;
|
||||||
const manaCode = 'manaClaim';
|
const manaCode = 'manaClaim';
|
||||||
|
|
||||||
|
const teamOne = 96;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||||
|
await business.updateAttribute('departmentFk', teamOne, options);
|
||||||
|
|
||||||
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
||||||
|
|
||||||
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
||||||
|
|
|
@ -98,12 +98,7 @@ module.exports = Self => {
|
||||||
if (isLocked || (!hasAllowedRoles && alertLevel > 0))
|
if (isLocked || (!hasAllowedRoles && alertLevel > 0))
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
const usesMana = await models.WorkerMana.findOne({
|
const usesMana = await models.Sale.usesMana(ctx, myOptions);
|
||||||
where: {
|
|
||||||
workerFk: userId
|
|
||||||
},
|
|
||||||
fields: 'amount'}, myOptions);
|
|
||||||
|
|
||||||
const componentCode = usesMana ? manaCode : 'buyerDiscount';
|
const componentCode = usesMana ? manaCode : 'buyerDiscount';
|
||||||
const discountComponent = await models.Component.findOne({
|
const discountComponent = await models.Component.findOne({
|
||||||
where: {code: componentCode}}, myOptions);
|
where: {code: componentCode}}, myOptions);
|
||||||
|
@ -115,14 +110,38 @@ module.exports = Self => {
|
||||||
for (let sale of sales) {
|
for (let sale of sales) {
|
||||||
const oldDiscount = sale.discount;
|
const oldDiscount = sale.discount;
|
||||||
const value = ((-sale.price * newDiscount) / 100);
|
const value = ((-sale.price * newDiscount) / 100);
|
||||||
const newComponent = models.SaleComponent.upsert({
|
|
||||||
|
const manaComponent = await models.Component.findOne({
|
||||||
|
where: {code: 'mana'}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const manaClaimComponent = await models.Component.findOne({
|
||||||
|
where: {code: 'manaClaim'}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const [oldComponent] = await models.SaleComponent.find({
|
||||||
|
where: {
|
||||||
|
and: [
|
||||||
|
{saleFk: sale.id},
|
||||||
|
{componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
let deletedComponent;
|
||||||
|
if (oldComponent) {
|
||||||
|
const filter = {
|
||||||
saleFk: sale.id,
|
saleFk: sale.id,
|
||||||
value: value,
|
componentFk: oldComponent.componentFk
|
||||||
componentFk: componentId}, myOptions);
|
};
|
||||||
|
deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions);
|
||||||
|
|
||||||
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
|
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
|
||||||
|
|
||||||
promises.push(newComponent, updatedSale);
|
promises.push(newComponent, updatedSale, deletedComponent);
|
||||||
|
|
||||||
const change = `${oldDiscount}% ➔ *${newDiscount}%*`;
|
const change = `${oldDiscount}% ➔ *${newDiscount}%*`;
|
||||||
changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`;
|
changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`;
|
||||||
|
@ -165,4 +184,14 @@ module.exports = Self => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function createSaleComponent(saleId, value, componentId, myOptions) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
return models.SaleComponent.create({
|
||||||
|
saleFk: saleId,
|
||||||
|
value: value,
|
||||||
|
componentFk: componentId
|
||||||
|
}, myOptions);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue