feat: refs #6739 transferInvoice new functionality #2412

Merged
jon merged 10 commits from 6739-transferInvoiceOut into dev 2024-05-10 04:51:42 +00:00
35 changed files with 273 additions and 376 deletions
Showing only changes of commit 0f973baa65 - Show all commits

View File

@ -5,97 +5,90 @@ BEGIN
DECLARE vFromDated DATE;
DECLARE vForDeleteDated DATE;
DECLARE vManaId INT;
DECLARE vManaAutoId INT;
DECLARE vClaimManaId INT;
DECLARE vManaBankId INT;
DECLARE vManaGreugeTypeId INT;
DECLARE vManaFromDays INT;
DECLARE vManaToDays INT;
DECLARE vManaAutoId INT;
DECLARE vClaimManaId INT;
DECLARE vManaBankId INT;
DECLARE vManaGreugeTypeId INT;
DECLARE vManaFromDays INT;
DECLARE vManaToDays INT;
SELECT id INTO vManaId
FROM vn.component WHERE code = 'mana';
SELECT id INTO vManaId
FROM vn.component WHERE code = 'mana';
SELECT id INTO vManaAutoId
SELECT id INTO vManaAutoId
FROM vn.component WHERE code = 'autoMana';
SELECT id INTO vClaimManaId
FROM vn.component WHERE code = 'manaClaim';
SELECT id INTO vManaBankId
SELECT id INTO vManaBankId
FROM vn.accounting WHERE code = 'mana';
SELECT id INTO vManaGreugeTypeId
SELECT id INTO vManaGreugeTypeId
FROM vn.greugeType WHERE code = 'mana';
SELECT manaFromDays, manaToDays
INTO vManaFromDays, vManaToDays
FROM vn.salespersonConfig;
SELECT manaFromDays, manaToDays
INTO vManaFromDays, vManaToDays
FROM vn.salespersonConfig;
SELECT MAX(dated)
INTO vFromDated
FROM vn.clientManaCache;
SELECT MAX(dated) INTO vFromDated
FROM vn.clientManaCache;
DELETE
FROM vn.clientManaCache
WHERE dated = vFromDated;
SELECT MAX(dated)
INTO vFromDated
FROM vn.clientManaCache;
IF ISNULL(vFromDated) THEN
SELECT manaDateFrom
INTO vFromDated
FROM vn.salespersonConfig;
END IF;
DELETE FROM vn.clientManaCache
WHERE dated = vFromDated;
SELECT MAX(dated) INTO vFromDated
FROM vn.clientManaCache;
IF vFromDated IS NULL THEN
SELECT manaDateFrom
INTO vFromDated
FROM vn.salespersonConfig;
END IF;
WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO
SELECT
vFromDated + INTERVAL vManaToDays DAY,
vFromDated - INTERVAL vManaFromDays DAY
INTO
vToDated,
vForDeleteDated;
DELETE FROM vn.clientManaCache
WHERE dated <= vForDeleteDated;
WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO
SELECT vFromDated + INTERVAL vManaToDays DAY,
vFromDated - INTERVAL vManaFromDays DAY
INTO vToDated,
vForDeleteDated;
DELETE FROM vn.clientManaCache
WHERE dated <= vForDeleteDated;
INSERT INTO vn.clientManaCache(clientFk, mana, dated)
SELECT
Id_Cliente,
SUM(mana),
vToDated
FROM
(
SELECT a.clientFk Id_Cliente, s.quantity * sc.value as mana
FROM vn.ticket t
JOIN vn.address a ON a.id = t.addressFk
JOIN vn.sale s on s.ticketFk = t.id
JOIN vn.saleComponent sc on sc.saleFk = s.id
WHERE sc.componentFk IN (vManaAutoId, vManaId, vClaimManaId)
AND t.shipped > vFromDated
AND date(t.shipped) <= vToDated
UNION ALL
SELECT clientFk, - amountPaid
FROM vn.receipt
WHERE bankFk = vManaBankId
AND payed > vFromDated
AND payed <= vToDated
UNION ALL
SELECT clientFk, amount
FROM vn.greuge
WHERE greugeTypeFk = vManaGreugeTypeId
AND shipped > vFromDated
AND shipped <= vToDated
UNION ALL
SELECT clientFk, mana
FROM vn.clientManaCache
WHERE dated = vFromDated
) sub
GROUP BY Id_Cliente
HAVING Id_Cliente;
INSERT INTO vn.clientManaCache(clientFk, mana, dated)
SELECT Id_Cliente,
SUM(mana),
vToDated
FROM (
SELECT a.clientFk Id_Cliente, s.quantity * sc.value mana
FROM vn.ticket t
JOIN vn.address a ON a.id = t.addressFk
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk IN (vManaAutoId, vManaId, vClaimManaId)
AND t.shipped > vFromDated
AND DATE(t.shipped) <= vToDated
UNION ALL
SELECT clientFk, - amountPaid
FROM vn.receipt
WHERE bankFk = vManaBankId
AND payed > vFromDated
AND payed <= vToDated
UNION ALL
SELECT clientFk, amount
FROM vn.greuge
WHERE greugeTypeFk = vManaGreugeTypeId
AND shipped > vFromDated
AND shipped <= vToDated
UNION ALL
SELECT clientFk, mana
FROM vn.clientManaCache
WHERE dated = vFromDated
) sub
GROUP BY Id_Cliente
HAVING Id_Cliente;
SET vFromDated = vToDated;
END WHILE;
SET vFromDated = vToDated;
END WHILE;
END$$
DELIMITER ;

View File

@ -259,7 +259,7 @@ BEGIN
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 1) = 1
AND NOT tcc.groupingMode = 'packing'
AND (tcc.groupingMode = 'grouping' OR tcc.groupingMode IS NULL)
AND (tcc.packing > tcc.`grouping` OR tcc.groupingMode IS NULL)
GROUP BY tcs.warehouseFk, tcs.itemFk;

View File

@ -28,11 +28,10 @@ BEGIN
JOIN entry e ON e.invoiceInFk = ii.id
JOIN duaEntry de ON de.entryFk = e.id
JOIN dua d ON d.id = de.duaFk
SET ii.isBooked = TRUE,
ii.booked = IFNULL(ii.booked,d.booked),
ii.operated = IFNULL(ii.operated,d.operated),
ii.issued = IFNULL(ii.issued,d.issued),
ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried),
SET ii.booked = IFNULL(ii.booked, d.booked),
ii.operated = IFNULL(ii.operated, d.operated),
ii.issued = IFNULL(ii.issued, d.issued),
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried),
e.isBooked = TRUE,
e.isConfirmed = TRUE
WHERE d.id = vDuaFk;
@ -71,5 +70,9 @@ BEGIN
SET ASIEN = vASIEN
WHERE id = vDuaFk;
UPDATE invoiceIn ii
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
SET ii.isBooked = TRUE
WHERE dii.duaFk = vDuaFk;
END$$
DELIMITER ;

View File

@ -1,101 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fv_pca`()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE vTicketFk INT;
DECLARE vSaleFk INT;
DECLARE vClonTicket INT DEFAULT 0;
DECLARE cur1 CURSOR FOR
SELECT s.ticketFk, s.id
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.itemType it ON it.id = i.typeFk
WHERE t.shipped BETWEEN '2020-10-18' AND '2020-10-31'
AND it.code IN ('ANT','ANS','ORQ','TRO')
and t.warehouseFk = 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
FETCH cur1 INTO vTicketFk, vSaleFk;
WHILE done = 0 DO
SELECT t.id INTO vClonTicket
FROM vn.ticket t
JOIN (SELECT addressFk, shipped FROM vn.ticket WHERE id = vTicketFk) sub USING(addressFk, shipped)
WHERE t.warehouseFk = 44
LIMIT 1;
SELECT vTicketFk, vClonTicket;
IF vClonTicket = 0 THEN
INSERT INTO ticket (
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk
)
SELECT
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
44,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk
FROM ticket
WHERE id = vTicketFk;
SET vClonTicket = LAST_INSERT_ID();
SELECT 'lstID', vClonTicket;
/*
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
SELECT vTicketFk, ao.observationTypeFk, ao.description
FROM addressObservation ao
JOIN ticket t ON t.addressFk = ao.addressFk
WHERE t.id = vClonTicket;
*/
INSERT INTO ticketLog
SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert',
description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk);
END IF;
UPDATE vn.sale
SET ticketFk = vClonTicket
WHERE id = vSaleFk;
SET vClonTicket = 0;
SET done = 0;
FETCH cur1 INTO vTicketFk, vSaleFk;
END WHILE;
CLOSE cur1;
END$$
DELIMITER ;

View File

@ -10,8 +10,6 @@ BEGIN
DECLARE vLines INT;
DECLARE vHasDistinctTransactions INT;
CALL invoiceIn_checkBooked(vInvoiceInFk);
SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig;
SELECT COUNT(*) INTO vLines

View File

@ -5,8 +5,6 @@ BEGIN
DECLARE vDated DATE;
DECLARE vExpenseFk VARCHAR(10);
CALL invoiceIn_checkBooked(vInvoiceInFk);
SELECT MAX(rr.dated) INTO vDated
FROM referenceRate rr
JOIN invoiceIn ii ON ii.id = vInvoiceInFk

View File

@ -21,9 +21,6 @@ BEGIN
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated);
-- Añadido temporalmente para ver si ya no sucede el cuelgue de db
SET vShowType = TRUE;
WITH itemTags AS (
SELECT i.id,
typeFk,
@ -82,7 +79,7 @@ BEGIN
AND iss.warehouseFk = vWarehouseFk
JOIN itemTags its
WHERE a.available > 0
AND IF(vShowType, i.typeFk = its.typeFk, TRUE)
AND (i.typeFk = its.typeFk OR NOT vShowType)
AND i.id <> vSelf
ORDER BY `counter` DESC,
(t.name = its.name) DESC,

View File

@ -7,7 +7,7 @@ BEGIN
*
* @param vSelf El id del ticket
*/
DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT;
DECLARE vCmrFk INT;
SELECT cmrFk INTO vCmrFk
FROM ticket
WHERE id = vSelf;
@ -44,8 +44,6 @@ BEGIN
AND t.id = vSelf
GROUP BY t.id;
START TRANSACTION;
IF vCmrFk THEN
UPDATE cmr c
JOIN tTicket t
@ -57,9 +55,7 @@ BEGIN
c.supplierFk = t.supplierFk,
c.ead = t.landed
WHERE id = vCmrFk;
ELSE
SELECT MAX(id) INTO vPreviousCmrFk FROM cmr;
ELSE
INSERT INTO cmr (
senderInstruccions,
truckPlate,
@ -70,17 +66,14 @@ BEGIN
ead
)
SELECT * FROM tTicket;
SELECT MAX(id) INTO vCurrentCmrFk FROM cmr;
IF vPreviousCmrFk <> vCurrentCmrFk THEN
IF (SELECT EXISTS(SELECT * FROM tTicket)) THEN
UPDATE ticket
SET cmrFk = vCurrentCmrFk
SET cmrFk = LAST_INSERT_ID()
WHERE id = vSelf;
END IF;
END IF;
COMMIT;
DROP TEMPORARY TABLE tTicket;
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_beforeDelete`
BEFORE DELETE ON `invoiceInCorrection`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.correctingFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_beforeInsert`
BEFORE INSERT ON `invoiceInCorrection`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(NEW.correctingFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_beforeUpdate`
BEFORE UPDATE ON `invoiceInCorrection`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.correctingFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_beforeDelete`
BEFORE DELETE ON `invoiceInDueDay`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
END$$
DELIMITER ;

View File

@ -5,8 +5,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor
BEGIN
DECLARE vIsNotified BOOLEAN;
CALL invoiceIn_checkBooked(NEW.invoiceInFk);
SET NEW.editorFk = account.myUser_getId();
SELECT isNotified INTO vIsNotified

View File

@ -5,7 +5,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor
BEGIN
DECLARE vIsNotified BOOLEAN;
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
SET NEW.editorFk = account.myUser_getId();
SELECT isNotified INTO vIsNotified

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeDelete`
BEFORE DELETE ON `invoiceInIntrastat`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeInsert`
BEFORE INSERT ON `invoiceInIntrastat`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(NEW.invoiceInFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeUpdate`
BEFORE UPDATE ON `invoiceInIntrastat`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
END$$
DELIMITER ;

View File

@ -1,8 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeDelete`
BEFORE DELETE ON `invoiceInTax`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
END$$
DELIMITER ;

View File

@ -3,8 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeUp
BEFORE UPDATE ON `invoiceInTax`
FOR EACH ROW
BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN
CALL invoiceInTax_afterUpsert(NEW.invoiceInFk);
END IF;

View File

@ -5,10 +5,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdat
BEGIN
DECLARE vWithholdingSageFk INT;
IF NEW.isBooked = OLD.isBooked THEN
CALL invoiceIn_checkBooked(OLD.id);
END IF;
IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN
CALL util.throw('The invoiceIn reference contains invalid characters');
END IF;

View File

@ -7,6 +7,8 @@ BEGIN
UPDATE expedition
SET hasNewRoute = TRUE
WHERE ticketFk = NEW.id;
CALL ticket_doCmr(NEW.id);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,10 @@
-- Place your SQL code here
ALTER TABLE vn.absenceType ADD isFestiveEligible BOOL DEFAULT 1 NOT NULL COMMENT 'Para marcar un tipo de absence';
UPDATE vn.absenceType
SET isFestiveEligible = 0
WHERE code = 'holiday';
UPDATE vn.absenceType
SET isFestiveEligible=0
WHERE code = 'halfHoliday';

View File

@ -0,0 +1,9 @@
DELETE FROM salix.ACL
WHERE model = 'Worker'
AND property = '__get__summary'
AND principalId = 'employee';
UPDATE salix.ACL SET principalId = 'employee'
WHERE model = 'Worker'
AND property IN ('find','findById','findOne')
AND principalId = 'hr';

View File

@ -0,0 +1 @@
REVOKE UPDATE (`size`, longName, name) ON vn.item FROM buyer;

View File

@ -2,6 +2,7 @@ import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Worker summary path', () => {
const workerId = 3;
let browser;
let page;
beforeAll(async() => {
@ -9,7 +10,7 @@ describe('Worker summary path', () => {
page = browser.page;
await page.loginAndModule('employee', 'worker');
const httpDataResponse = page.waitForResponse(response => {
return response.status() === 200 && response.url().includes(`Workers/summary`);
return response.status() === 200 && response.url().includes(`Workers/${workerId}`);
});
await page.accessToSearchResult('agencyNick');
await httpDataResponse;

View File

@ -226,4 +226,4 @@
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
"They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked"
}
}

View File

@ -10,6 +10,9 @@
"id": {
"type": "number",
"id": true
},
"workcenterFk" : {
"type": "number"
}
},
"relations": {
@ -24,4 +27,4 @@
"foreignKey": "departmentFk"
}
}
}
}

View File

@ -98,6 +98,22 @@ module.exports = Self => {
if (isHalfHoliday && hasHalfHoliday)
throw new UserError(`Cannot add more than one '1/2 day vacation'`);
const isFestive = absenceType.isFestiveEligible;
const workCenter = await models.Business.findOne({
where: {id: args.businessFk}
},);
const [holiday] = await models.CalendarHoliday.find({
where: {
dated: args.dated,
workCenterFk: workCenter.workCenterFk
}
});
if (holiday && isFestive)
throw new UserError(`Cannot add holidays on this day`);
const absence = await models.Calendar.create({
businessFk: labour.businessFk,
dayOffTypeFk: args.absenceTypeId,

View File

@ -104,6 +104,35 @@ describe('Worker createAbsence()', () => {
expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`);
});
it(`should throw an error when adding a "Holiday" absence if there's a festivity`, async() => {
const ctx = {
req: {accessToken: {userId: 9}},
args: {
id: 3,
businessFk: 3,
absenceTypeId: 1,
dated: '2001-12-08T23:00:00.000Z'
}
};
const workerId = 1;
const tx = await app.models.Calendar.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await app.models.Worker.createAbsence(ctx, workerId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual(`Cannot add holidays on this day`);
});
it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => {
const ctx = {
req: {accessToken: {userId: 19}},

View File

@ -22,7 +22,10 @@
},
"holidayEntitlementRate": {
"type": "number"
}
},
"isFestiveEligible": {
"type": "boolean"
}
},
"acls": [
{
@ -32,4 +35,4 @@
"permission": "ALLOW"
}
]
}
}

View File

@ -59,6 +59,9 @@
},
"isF11Allowed": {
"type" : "boolean"
},
"isFreelance": {
"type" : "boolean"
}
},
"relations": {
@ -92,86 +95,5 @@
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
}
},
"scopes":{
"summary": {
"include": [
{
"relation": "user",
"scope": {
"fields": ["email", "name", "nickname", "roleFk", "emailVerified"],
"include": [
{
"relation": "role",
"scope": {
"fields": ["name"]
}
},
{
"relation": "emailUser",
"scope": {
"fields": ["email"]
}
}
]
}
}, {
"relation": "department",
"scope": {
"include": {
"relation": "department"
}
}
}, {
"relation": "boss"
}, {
"relation": "client",
"scope": {
"fields": [
"id",
"name",
"fi",
"socialName",
"contact",
"street",
"city",
"postcode",
"email",
"mobile",
"isActive",
"credit",
"creditInsurance",
"iban",
"dueDay",
"isEqualizated",
"isFreezed",
"hasToInvoiceByAddress",
"hasToInvoice",
"isToBeMailed",
"hasSepaVnl",
"hasLcr",
"hasCoreVnl",
"hasCoreVnh",
"hasIncoterms",
"isTaxDataChecked",
"quality",
"isVies",
"isRelevant",
"accountingAccount",
"created",
"sageTaxTypeFk",
"sageTransactionTypeFk",
"businessTypeFk",
"salesPersonFk",
"hasElectronicInvoice",
"rating",
"recommendedCredit"
]
}
}, {
"relation": "sip"
}
]
}
}
}

View File

@ -4,13 +4,37 @@ import ModuleCard from 'salix/components/module-card';
class Controller extends ModuleCard {
reload() {
const filter = {
where: {
id: this.$params.id}
include: [
{
relation: 'user',
scope: {
fields: ['name', 'emailVerified'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}, {
relation: 'sip',
scope: {
fields: ['extension', 'secret']
}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
};
return Promise.all([
this.$http.get(`Workers/summary`, {filter})
.then(res => this.worker = res.data[0]),
this.$http.get(`Workers/${this.$params.id}`, {filter})
.then(res => this.worker = res.data),
this.$http.get(`Workers/${this.$params.id}/activeContract`)
.then(res => this.hasWorkCenter = res.data?.workCenterFk)
]);

View File

@ -37,11 +37,41 @@ class Controller extends Descriptor {
loadData() {
const filter = {
where: {id: this.id},
include: [
{
relation: 'user',
scope: {
fields: ['name', 'emailVerified'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}, {
relation: 'client',
scope: {
fields: ['fi']
}
}, {
relation: 'sip',
scope: {
fields: ['extension']
}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
};
return this.getData(`Workers/summary`, {filter})
.then(res => this.entity = res.data[0]);
return this.getData(`Workers/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
getPassRequirements() {

View File

@ -14,14 +14,14 @@ describe('vnWorkerDescriptor', () => {
describe('loadData()', () => {
it(`should perform a get query to store the worker data into the controller`, () => {
const id = 1;
const response = ['foo'];
const response = 'foo';
$httpBackend.whenGET('UserConfigs/getUserConfig').respond({});
$httpBackend.expectRoute('GET', `Workers/summary`).respond(response);
$httpBackend.expectRoute('GET', `Workers/${id}`).respond(response);
controller.id = id;
$httpBackend.flush();
expect([controller.worker]).toEqual(response);
expect(controller.worker).toEqual(response);
});
});

View File

@ -10,14 +10,53 @@ class Controller extends Summary {
this.$.worker = null;
if (!value) return;
const query = `Workers/${value.id}`;
const filter = {
where: {
id: value.id
}
include: [
{
relation: 'user',
scope: {
fields: ['name', 'roleFk'],
include: [{
relation: 'role',
scope: {
fields: ['name']
}
},
{
relation: 'emailUser',
scope: {
fields: ['email']
}
}]
}
},
{
relation: 'client',
scope: {fields: ['fi', 'phone']}
},
{
relation: 'boss',
scope: {fields: ['id', 'name']}
},
{
relation: 'sip',
scope: {fields: ['extension']}
},
{
relation: 'department',
scope: {
include: {
relation: 'department',
scope: {fields: ['id', 'code', 'name']}
}
}
}
]
};
this.$http.get(`Workers/summary`, {filter}).then(res => {
this.$.worker = res.data[0];
this.$http.get(query, {params: {filter}}).then(res => {
this.$.worker = res.data;
});
}