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 620dd3d836 - Show all commits

View File

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

View File

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

View File

@ -28,11 +28,10 @@ BEGIN
JOIN entry e ON e.invoiceInFk = ii.id JOIN entry e ON e.invoiceInFk = ii.id
JOIN duaEntry de ON de.entryFk = e.id JOIN duaEntry de ON de.entryFk = e.id
JOIN dua d ON d.id = de.duaFk JOIN dua d ON d.id = de.duaFk
SET ii.isBooked = TRUE, SET ii.booked = IFNULL(ii.booked, d.booked),
ii.booked = IFNULL(ii.booked,d.booked), ii.operated = IFNULL(ii.operated, d.operated),
ii.operated = IFNULL(ii.operated,d.operated), ii.issued = IFNULL(ii.issued, d.issued),
ii.issued = IFNULL(ii.issued,d.issued), ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried),
ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried),
e.isBooked = TRUE, e.isBooked = TRUE,
e.isConfirmed = TRUE e.isConfirmed = TRUE
WHERE d.id = vDuaFk; WHERE d.id = vDuaFk;
@ -71,5 +70,9 @@ BEGIN
SET ASIEN = vASIEN SET ASIEN = vASIEN
WHERE id = vDuaFk; WHERE id = vDuaFk;
UPDATE invoiceIn ii
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
SET ii.isBooked = TRUE
WHERE dii.duaFk = vDuaFk;
END$$ END$$
DELIMITER ; 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 vLines INT;
DECLARE vHasDistinctTransactions INT; DECLARE vHasDistinctTransactions INT;
CALL invoiceIn_checkBooked(vInvoiceInFk);
SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig;
SELECT COUNT(*) INTO vLines SELECT COUNT(*) INTO vLines

View File

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

View File

@ -21,9 +21,6 @@ BEGIN
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated); 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 ( WITH itemTags AS (
SELECT i.id, SELECT i.id,
typeFk, typeFk,
@ -82,7 +79,7 @@ BEGIN
AND iss.warehouseFk = vWarehouseFk AND iss.warehouseFk = vWarehouseFk
JOIN itemTags its JOIN itemTags its
WHERE a.available > 0 WHERE a.available > 0
AND IF(vShowType, i.typeFk = its.typeFk, TRUE) AND (i.typeFk = its.typeFk OR NOT vShowType)
AND i.id <> vSelf AND i.id <> vSelf
ORDER BY `counter` DESC, ORDER BY `counter` DESC,
(t.name = its.name) DESC, (t.name = its.name) DESC,

View File

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

View File

@ -5,7 +5,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor
BEGIN BEGIN
DECLARE vIsNotified BOOLEAN; DECLARE vIsNotified BOOLEAN;
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SELECT isNotified INTO vIsNotified 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` BEFORE UPDATE ON `invoiceInTax`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
CALL invoiceIn_checkBooked(OLD.invoiceInFk);
IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN
CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); CALL invoiceInTax_afterUpsert(NEW.invoiceInFk);
END IF; END IF;

View File

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

View File

@ -7,6 +7,8 @@ BEGIN
UPDATE expedition UPDATE expedition
SET hasNewRoute = TRUE SET hasNewRoute = TRUE
WHERE ticketFk = NEW.id; WHERE ticketFk = NEW.id;
CALL ticket_doCmr(NEW.id);
END IF; END IF;
END$$ END$$
DELIMITER ; 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'; import getBrowser from '../../helpers/puppeteer';
describe('Worker summary path', () => { describe('Worker summary path', () => {
const workerId = 3;
let browser; let browser;
let page; let page;
beforeAll(async() => { beforeAll(async() => {
@ -9,7 +10,7 @@ describe('Worker summary path', () => {
page = browser.page; page = browser.page;
await page.loginAndModule('employee', 'worker'); await page.loginAndModule('employee', 'worker');
const httpDataResponse = page.waitForResponse(response => { 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 page.accessToSearchResult('agencyNick');
await httpDataResponse; 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", "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", "They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked" "InvoiceIn is already booked": "InvoiceIn is already booked"
} }

View File

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

View File

@ -98,6 +98,22 @@ module.exports = Self => {
if (isHalfHoliday && hasHalfHoliday) if (isHalfHoliday && hasHalfHoliday)
throw new UserError(`Cannot add more than one '1/2 day vacation'`); 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({ const absence = await models.Calendar.create({
businessFk: labour.businessFk, businessFk: labour.businessFk,
dayOffTypeFk: args.absenceTypeId, 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'`); 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() => { 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 = { const ctx = {
req: {accessToken: {userId: 19}}, req: {accessToken: {userId: 19}},

View File

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

View File

@ -59,6 +59,9 @@
}, },
"isF11Allowed": { "isF11Allowed": {
"type" : "boolean" "type" : "boolean"
},
"isFreelance": {
"type" : "boolean"
} }
}, },
"relations": { "relations": {
@ -92,86 +95,5 @@
"model": "WorkerTeamCollegues", "model": "WorkerTeamCollegues",
"foreignKey": "workerFk" "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 { class Controller extends ModuleCard {
reload() { reload() {
const filter = { const filter = {
where: { include: [
id: this.$params.id} {
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([ return Promise.all([
this.$http.get(`Workers/summary`, {filter}) this.$http.get(`Workers/${this.$params.id}`, {filter})
.then(res => this.worker = res.data[0]), .then(res => this.worker = res.data),
this.$http.get(`Workers/${this.$params.id}/activeContract`) this.$http.get(`Workers/${this.$params.id}/activeContract`)
.then(res => this.hasWorkCenter = res.data?.workCenterFk) .then(res => this.hasWorkCenter = res.data?.workCenterFk)
]); ]);

View File

@ -37,11 +37,41 @@ class Controller extends Descriptor {
loadData() { loadData() {
const filter = { 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}) return this.getData(`Workers/${this.id}`, {filter})
.then(res => this.entity = res.data[0]); .then(res => this.entity = res.data);
} }
getPassRequirements() { getPassRequirements() {

View File

@ -14,14 +14,14 @@ describe('vnWorkerDescriptor', () => {
describe('loadData()', () => { describe('loadData()', () => {
it(`should perform a get query to store the worker data into the controller`, () => { it(`should perform a get query to store the worker data into the controller`, () => {
const id = 1; const id = 1;
const response = ['foo']; const response = 'foo';
$httpBackend.whenGET('UserConfigs/getUserConfig').respond({}); $httpBackend.whenGET('UserConfigs/getUserConfig').respond({});
$httpBackend.expectRoute('GET', `Workers/summary`).respond(response); $httpBackend.expectRoute('GET', `Workers/${id}`).respond(response);
controller.id = id; controller.id = id;
$httpBackend.flush(); $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; this.$.worker = null;
if (!value) return; if (!value) return;
const query = `Workers/${value.id}`;
const filter = { const filter = {
where: { include: [
id: value.id {
} 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.$http.get(query, {params: {filter}}).then(res => {
this.$.worker = res.data[0]; this.$.worker = res.data;
}); });
} }