{
- Self.remoteMethodCtx('getCurrentWorkerMana', {
- description: 'Returns the mana of the logged worker',
- accessType: 'READ',
- accepts: [],
- returns: {
- type: 'number',
- root: true
- },
- http: {
- path: `/getCurrentWorkerMana`,
- verb: 'GET'
- }
- });
-
- Self.getCurrentWorkerMana = async ctx => {
- let userId = ctx.req.accessToken.userId;
-
- let workerMana = await Self.app.models.WorkerMana.findOne({
- where: {workerFk: userId},
- fields: 'amount'
- });
-
- return workerMana ? workerMana.amount : 0;
- };
-};
diff --git a/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js b/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js
deleted file mode 100644
index 8d626e720..000000000
--- a/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const app = require('vn-loopback/server/server');
-
-describe('workerMana getCurrentWorkerMana()', () => {
- it('should get the mana of the logged worker', async() => {
- let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 18}}});
-
- expect(mana).toEqual(124);
- });
-
- it('should return 0 if the user doesnt uses mana', async() => {
- let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 9}}});
-
- expect(mana).toEqual(0);
- });
-});
diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js
index 2c5143612..6f67bbea3 100644
--- a/modules/worker/back/methods/worker-time-control/sendMail.js
+++ b/modules/worker/back/methods/worker-time-control/sendMail.js
@@ -66,46 +66,36 @@ module.exports = Self => {
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate');
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate');
+ const destroyAllWhere = {
+ timed: {between: [started, ended]},
+ isSendMail: true
+ };
+ const updateAllWhere = {
+ year: args.year,
+ week: args.week
+ };
+
+ const tmpUserSQL = `
+ CREATE OR REPLACE TEMPORARY TABLE tmp.user
+ SELECT id as userFk
+ FROM vn.worker`;
+ let tmpUser = new ParameterizedSQL(tmpUserSQL);
+
if (args.workerId) {
- await models.WorkerTimeControl.destroyAll({
- userFk: args.workerId,
- timed: {between: [started, ended]},
- isSendMail: true
- }, myOptions);
-
- const where = {
- workerFk: args.workerId,
- year: args.year,
- week: args.week
- };
- await models.WorkerTimeControlMail.updateAll(where, {
- updated: Date.vnNew(), state: 'SENDED'
- }, myOptions);
-
- stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
- stmts.push(stmt);
- stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = ?', [args.workerId]);
- stmts.push(stmt);
- } else {
- await models.WorkerTimeControl.destroyAll({
- timed: {between: [started, ended]},
- isSendMail: true
- }, myOptions);
-
- const where = {
- year: args.year,
- week: args.week
- };
- await models.WorkerTimeControlMail.updateAll(where, {
- updated: Date.vnNew(), state: 'SENDED'
- }, myOptions);
-
- stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
- stmts.push(stmt);
- stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT id as userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.id WHERE id IS NOT NULL');
- stmts.push(stmt);
+ destroyAllWhere.userFk = args.workerId;
+ updateAllWhere.workerFk = args.workerId;
+ tmpUser = new ParameterizedSQL(tmpUserSQL + ' WHERE id = ?', [args.workerId]);
}
+ await models.WorkerTimeControl.destroyAll(destroyAllWhere, myOptions);
+
+ await models.WorkerTimeControlMail.updateAll(updateAllWhere, {
+ updated: Date.vnNew(),
+ state: 'SENDED'
+ }, myOptions);
+
+ stmts.push(tmpUser);
+
stmt = new ParameterizedSQL(
`CALL vn.timeControl_calculate(?, ?)
`, [started, ended]);
diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js
index cd0a466ea..7fe9e0666 100644
--- a/modules/worker/back/methods/worker/search.js
+++ b/modules/worker/back/methods/worker/search.js
@@ -46,7 +46,7 @@ module.exports = Self => {
SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk
FROM worker w
JOIN account.user u ON u.id = w.id
- JOIN business b ON b.workerFk = w.id
+ LEFT JOIN business b ON b.workerFk = w.id
) w`);
stmt.merge(conn.makeSuffix(filter));
diff --git a/modules/worker/back/models/worker-mana.js b/modules/worker/back/models/worker-mana.js
deleted file mode 100644
index 99a0f7694..000000000
--- a/modules/worker/back/models/worker-mana.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = Self => {
- require('../methods/worker-mana/getCurrentWorkerMana')(Self);
-};
diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html
index 0be5a30f0..92dd1b126 100644
--- a/print/templates/reports/delivery-note/delivery-note.html
+++ b/print/templates/reports/delivery-note/delivery-note.html
@@ -117,7 +117,7 @@
{{service.price | currency('EUR', $i18n.locale)}} |
|
{{service.taxDescription}} |
- {{service.price | currency('EUR', $i18n.locale)}} |
+ {{service.total | currency('EUR', $i18n.locale)}} |
diff --git a/print/templates/reports/delivery-note/sql/services.sql b/print/templates/reports/delivery-note/sql/services.sql
index d64e8dc26..ec8a3e7ac 100644
--- a/print/templates/reports/delivery-note/sql/services.sql
+++ b/print/templates/reports/delivery-note/sql/services.sql
@@ -1,8 +1,9 @@
SELECT
tc.code taxDescription,
ts.description,
- ts.quantity,
- ts.price
+ ts.quantity,
+ ts.price,
+ ts.quantity * ts.price total
FROM ticketService ts
JOIN taxClass tc ON tc.id = ts.taxClassFk
WHERE ts.ticketFk = ?
\ No newline at end of file