This commit is contained in:
Carlos Jimenez Ruiz 2020-01-26 21:59:46 +01:00
commit 7fef6dc2b0
20 changed files with 1288 additions and 3612 deletions

View File

@ -109,10 +109,10 @@ proc: BEGIN
GROUP BY tc.itemFk, warehouseFk; GROUP BY tc.itemFk, warehouseFk;
INSERT INTO tmp.ticketComponent INSERT INTO tmp.ticketComponent
SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3) SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.priceIncreasing, 0.25), 3)
FROM tmp.ticketComponentBase tcb FROM tmp.ticketComponentBase tcb
JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk JOIN claimRatio cr ON cr.clientFk = vClientFk
WHERE cr.recobro > 0.009; WHERE cr.priceIncreasing > 0.009;
INSERT INTO tmp.ticketComponent INSERT INTO tmp.ticketComponent
SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto
@ -147,7 +147,7 @@ proc: BEGIN
vGeneralInflationCoefficient vGeneralInflationCoefficient
* ROUND(( * ROUND((
i.compression i.compression
* r.cm3 * ic.cm3
* IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1)
* IFNULL((z.price - z.bonus) * IFNULL((z.price - z.bonus)
* 1/*amz.inflation*/ , 50)) / vBoxVolume, 4 * 1/*amz.inflation*/ , 50)) / vBoxVolume, 4
@ -156,8 +156,8 @@ proc: BEGIN
JOIN item i ON i.id = tcc.itemFk JOIN item i ON i.id = tcc.itemFk
JOIN zone z ON z.id = vZoneFk JOIN zone z ON z.id = vZoneFk
JOIN agencyMode am ON am.id = z.agencyModeFk JOIN agencyMode am ON am.id = z.agencyModeFk
LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
AND r.Id_Article = tcc.itemFk AND ic.itemFk = tcc.itemFk
HAVING cost <> 0; HAVING cost <> 0;
IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN

View File

@ -0,0 +1,81 @@
DROP procedure IF EXISTS `vn`.`buy_afterUpsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`buy_afterUpsert`(vSelf INT)
BEGIN
/**
* Triggered actions when a buy is updated or inserted.
*
* @param vSelf The buy reference
*/
DECLARE vEntryFk INT;
DECLARE vItemFk INT;
DECLARE vStickers INT;
DECLARE vPacking INT;
DECLARE vWarehouse INT;
DECLARE vWarehouseOut INT;
DECLARE vIsMerchandise BOOL;
DECLARE vIsFeedStock BOOL;
DECLARE vLanded DATE;
DECLARE vBuyerFk INT;
DECLARE vItemName VARCHAR(50);
SELECT entryFk, itemFk, stickers, packing
INTO vEntryFk, vItemFk, vStickers, vPacking
FROM buy
WHERE id = vSelf;
SELECT t.warehouseInFk, t.warehouseOutFk, t.landed
INTO vWarehouse, vWarehouseOut, vLanded
FROM entry e
JOIN travel t ON t.id = e.travelFk
WHERE e.id = vEntryFk;
SELECT k.merchandise, it.workerFk, i.longName
INTO vIsMerchandise, vBuyerFk, vItemName
FROM itemCategory k
JOIN itemType it ON it.categoryFk = k.id
JOIN item i ON i.typeFk = it.id
WHERE i.id = vItemFk;
IF vIsMerchandise THEN
REPLACE itemCost SET
itemFk = vItemFk,
warehouseFk = vWarehouse,
cm3 = buy_getUnitVolume(vSelf);
END IF;
SELECT isFeedStock INTO vIsFeedStock
FROM warehouse WHERE id = vWarehouseOut AND id <> 13;
IF vIsFeedStock THEN
INSERT IGNORE INTO producer(`name`)
SELECT es.company_name
FROM buy b
JOIN edi.ekt be ON be.id = b.ektFk
JOIN edi.supplier es ON es.supplier_id = be.pro
WHERE b.id = vSelf;
IF buy_hasNotifyPassport(vSelf, vItemFk) THEN
CALL vn.buy_notifyPassport(vSelf, vItemFk, vStickers, vPacking);
END IF;
END IF;
-- Aviso al comprador de modificacion de entrada en Barajas
IF (SELECT isBuyerToBeEmailed FROM warehouse WHERE id = vWarehouse)
AND vLanded = CURDATE()
AND vBuyerFk != account.myUserGetId()
THEN
CALL vn.mail_insert(CONCAT(account.userGetNameFromId(vBuyerFk),'@verdnatura.es'),
CONCAT(account.myUserGetName(),'@verdnatura.es'),
CONCAT('E ',vEntryFk,' Se ha modificado item ', vItemFk, ' ',vItemName),
'Este email se ha generado automáticamente');
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,18 @@
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clientRisk_update`(vClientId INT, vCompanyId INT, vAmount DECIMAL(10,2))
BEGIN
IF vAmount IS NOT NULL
THEN
INSERT INTO clientRisk
SET
clientFk = vClientId,
companyFk = vCompanyId,
amount = vAmount
ON DUPLICATE KEY UPDATE
amount = amount + VALUES(amount);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,3 @@
ALTER TABLE `vn`.`componentType`
CHANGE COLUMN `base` `isBase` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos' ;

View File

@ -0,0 +1,12 @@
DROP procedure IF EXISTS `bi`.`customer_risk_update`;
DELIMITER $$
USE `bi`$$
CREATE DEFINER=`root`@`%` PROCEDURE `bi`.`customer_risk_update`(v_customer INT, v_company INT, v_amount DECIMAL(10,2))
BEGIN
CALL vn.clientRisk_update(v_customer, v_company, v_amount);
END$$
DELIMITER ;

View File

@ -0,0 +1,155 @@
DROP procedure IF EXISTS `vn`.`ticketComponentUpdateSale`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketComponentUpdateSale`(vOption INT)
BEGIN
/**
* A partir de la tabla tmp.sale, crea los Movimientos_componentes
* y modifica el campo Preu de la tabla Movimientos
*
* @param i_option integer tipo de actualizacion
* @param table tmp.sale tabla memory con el campo saleFk, warehouseFk
**/
DECLARE vComponentFk INT;
DECLARE vRenewComponents BOOLEAN;
DECLARE vKeepPrices BOOLEAN;
CASE vOption
WHEN 1 THEN
SET vRenewComponents = TRUE;
SET vKeepPrices = FALSE;
WHEN 2 THEN
SET vComponentFk = 17;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 3 THEN
SET vComponentFk = 37;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 4 THEN
SET vComponentFk = 34;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 5 THEN
SET vComponentFk = 35;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 6 THEN
SET vComponentFk = 36;
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
WHEN 7 THEN
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk NOT IN (28, 29)
GROUP BY s.id;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk NOT IN (28, 29)
GROUP BY s.id;
SET vRenewComponents = FALSE;
SET vKeepPrices = FALSE;
WHEN 8 THEN
DELETE sc.*
FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3)
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id;
SET vRenewComponents = FALSE;
SET vKeepPrices = FALSE;
WHEN 9 THEN
SET vRenewComponents = TRUE;
SET vKeepPrices = TRUE;
END CASE;
IF vRenewComponents THEN
DELETE sc.*
FROM tmp.sale tmps
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
JOIN `component` c ON c.id = sc.componentFk
WHERE c.isRenewable;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, tc.componentFk, tc.cost
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk
LEFT JOIN `component` c ON c.id = tc.componentFk
WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE);
END IF;
IF vKeepPrices THEN
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.saleFk <> vComponentFk
GROUP BY s.id
HAVING dif <> 0;
ELSE
UPDATE sale s
JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = sumValue
WHERE it.code != 'PRT' ;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk != 21
GROUP BY s.id
HAVING ROUND(saleValue, 4) <> 0;
END IF;
UPDATE sale s
JOIN (
SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN `component` c ON c.id = sc.componentFk
JOIN componentType ct on ct.id = c.typeFk AND ct.isBase
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.priceFixed = sumValue, s.isPriceFixed = 1;
DELETE sc.*
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN sale s on s.id = sc.saleFk
JOIN item i ON i.id = s.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE it.code = 'PRT';
INSERT INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 15, s.price
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
JOIN item i ON i.id = s.itemFK
JOIN itemType it ON it.id = i.typeFk
WHERE it.code = 'PRT' AND s.price > 0;
END$$
DELIMITER ;

View File

@ -0,0 +1,27 @@
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_afterInsert` AFTER INSERT ON `vn`.`invoiceOut` FOR EACH ROW BEGIN
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeUpdate`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeUpdate` BEFORE UPDATE ON `vn`.`invoiceOut` FOR EACH ROW
BEGIN
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeDelete`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeDelete` BEFORE DELETE ON `invoiceOut` FOR EACH ROW BEGIN
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
END$$
DELIMITER ;

View File

@ -0,0 +1,20 @@
DROP TRIGGER IF EXISTS `vn`.`receipt_afterInsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_afterInsert` AFTER INSERT ON `receipt` FOR EACH ROW
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid)$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`receipt_beforeUpdate`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_beforeUpdate` BEFORE UPDATE ON `receipt` FOR EACH ROW BEGIN
CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid);
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`receipt_beforeDelete`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_beforeDelete` BEFORE DELETE ON `receipt` FOR EACH ROW
CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid)$$
DELIMITER ;

View File

@ -0,0 +1,12 @@
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `bi`.`tarifa_componentes_series` AS
SELECT
`ct`.`id` AS `tarifa_componentes_series_id`,
`ct`.`type` AS `Serie`,
`ct`.`isBase` AS `base`,
`ct`.`isMargin` AS `margen`
FROM
`vn`.`componentType` `ct`;

File diff suppressed because one or more lines are too long

View File

@ -124,6 +124,13 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`,
(1, 'Pay on receipt', '0000000000', 4, 0, 1, 1), (1, 'Pay on receipt', '0000000000', 4, 0, 1, 1),
(2, 'Cash', '1111111111', 1, 0, 1, 1); (2, 'Cash', '1111111111', 1, 0, 1, 1);
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES
(1, 'AGENCY', 'Agencia'),
(2, 'DELIVERY', 'Reparto'),
(3, 'PICKUP', 'Recogida'),
(4, 'OTHER', 'Otros');
INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`)
VALUES VALUES
(1, 'inhouse pickup' , 1, 0, 1, 1), (1, 'inhouse pickup' , 1, 0, 1, 1),
@ -1165,13 +1172,6 @@ INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`package
(14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 7.30, 7.00, 0.00, NULL, 0, 1, 0, CURDATE()), (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 7.30, 7.00, 0.00, NULL, 0, 1, 0, CURDATE()),
(15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0.00, NULL, 0, 1, 0, CURDATE()); (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0.00, NULL, 0, 1, 0, CURDATE());
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES
(1, 'AGENCY', 'Agencia'),
(2, 'DELIVERY', 'Reparto'),
(3, 'PICKUP', 'Recogida'),
(4, 'OTHER', 'Otros');
INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`, `date_make`, `first_row_stamp`, `confirm_date`) INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`, `date_make`, `first_row_stamp`, `confirm_date`)
VALUES VALUES
(1, DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 3, 1, 121, 442, NULL, 'TPV', 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (1, DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 3, 1, 121, 442, NULL, 'TPV', 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
@ -1879,12 +1879,12 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`)
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), (8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); (8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY));
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `order`, `manual`, `direction`) INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`)
VALUES VALUES
(106, CONCAT(CURDATE(), ' 07:00'), 1, TRUE, 'in'), (106, CONCAT(CURDATE(), ' 07:00'), TRUE, 'in'),
(106, CONCAT(CURDATE(), ' 10:00'), 2, TRUE, 'middle'), (106, CONCAT(CURDATE(), ' 10:00'), TRUE, 'middle'),
(106, CONCAT(CURDATE(), ' 10:10'), 3, TRUE, 'middle'), (106, CONCAT(CURDATE(), ' 10:10'), TRUE, 'middle'),
(106, CONCAT(CURDATE(), ' 15:00'), 4, TRUE, 'out'); (106, CONCAT(CURDATE(), ' 15:00'), TRUE, 'out');
INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`) INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`)
VALUES VALUES

File diff suppressed because it is too large Load Diff

View File

@ -49,13 +49,8 @@ TABLES=(
state state
sample sample
department department
) component
dump_tables ${TABLES[@]} componentType
TABLES=(
bi
tarifa_componentes
tarifa_componentes_series
) )
dump_tables ${TABLES[@]} dump_tables ${TABLES[@]}

View File

@ -2,7 +2,6 @@
SCHEMAS=( SCHEMAS=(
account account
bi
bs bs
cache cache
edi edi

View File

@ -48,7 +48,7 @@ describe('buyUltimate()', () => {
expect(buyUltimateTable[1].buyFk).toEqual(4); expect(buyUltimateTable[1].buyFk).toEqual(4);
expect(buyUltimateTable[0].buyFk).toEqual(3); expect(buyUltimateTable[0].buyFk).toEqual(3);
expect(buyUltimateTable[2].buyFk).toEqual(5); expect(buyUltimateTable[2].buyFk).toEqual(5);
expect(buyUltimateTable[3].buyFk).toEqual(8); expect(buyUltimateTable[3].buyFk).toEqual(9);
expect(buyUltimateTable[4].buyFk).toEqual(6); expect(buyUltimateTable[4].buyFk).toEqual(6);
expect(buyUltimateTable[5].buyFk).toEqual(7); expect(buyUltimateTable[5].buyFk).toEqual(7);
}); });

View File

@ -23,13 +23,10 @@ describe('Directive vnId', () => {
}).toThrow(new Error(`vnId: Attribute can't be null`)); }).toThrow(new Error(`vnId: Attribute can't be null`));
}); });
// FIXME: Sometimes fails with '$scope is undefined' it(`should set the controller into the $scope as there are no errors being thrown`, () => {
xit(`should set the controller into the $scope as there are no errors being thrown`, () => { let html = `<form vn-id="myId"></form>`;
let html = `<form vn-id="1"></form>`;
expect($scope['1']).not.toBeDefined();
compile(html); compile(html);
expect($scope['1']).toBeDefined(); expect($scope.myId).toBeDefined();
}); });
}); });

View File

@ -7,7 +7,7 @@ describe('Client activeWorkersWithRole', () => {
let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson'); let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson');
expect(result.length).toEqual(15); expect(result.length).toEqual(14);
expect(isSalesPerson).toBeTruthy(); expect(isSalesPerson).toBeTruthy();
}); });

View File

@ -6,7 +6,7 @@ describe('Client listWorkers', () => {
.then(result => { .then(result => {
let amountOfEmployees = Object.keys(result).length; let amountOfEmployees = Object.keys(result).length;
expect(amountOfEmployees).toEqual(50); expect(amountOfEmployees).toEqual(49);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);

View File

@ -16,10 +16,7 @@
"type": "String" "type": "String"
}, },
"isBase":{ "isBase":{
"type":"String", "type":"Boolean"
"mysql": {
"columnName": "base"
}
} }
} }
} }

View File

@ -33,10 +33,11 @@ module.exports = Self => {
} }
}); });
Self.getWorkedHours = async(id, from, to) => { Self.getWorkedHours = async(id, started, ended) => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const stmts = []; const stmts = [];
const startedMinusOne = new Date();
const endedPlusOne = new Date();
let worker = await Self.app.models.Worker.findById(id); let worker = await Self.app.models.Worker.findById(id);
let userId = worker.userFk; let userId = worker.userFk;
@ -45,14 +46,16 @@ module.exports = Self => {
tmp.timeControlCalculate, tmp.timeControlCalculate,
tmp.timeBusinessCalculate tmp.timeBusinessCalculate
`); `);
startedMinusOne.setDate(started.getDate() - 1);
stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, from, to])); endedPlusOne.setDate(ended.getDate() + 1);
stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, from, to])); stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne]));
let resultIndex = stmts.push(` stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne]));
let resultIndex = stmts.push(new ParameterizedSQL(`
SELECT tbc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours SELECT tbc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours
FROM tmp.timeBusinessCalculate tbc FROM tmp.timeBusinessCalculate tbc
LEFT JOIN tmp.timeControlCalculate tcc ON tcc.dated = tbc.dated LEFT JOIN tmp.timeControlCalculate tcc ON tcc.dated = tbc.dated
`) - 1; WHERE tbc.dated BETWEEN ? AND ?
`, [started, ended])) - 1;
stmts.push(` stmts.push(`
DROP TEMPORARY TABLE IF EXISTS DROP TEMPORARY TABLE IF EXISTS
tmp.timeControlCalculate, tmp.timeControlCalculate,