From 812d79f2d56f69280f08b68b02a13e01520e3311 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Feb 2022 15:11:39 +0100 Subject: [PATCH 01/13] feat(client_defaulter): implemented smart-table --- front/core/components/smart-table/table.scss | 5 + .../client/back/methods/defaulter/filter.js | 6 +- modules/client/front/defaulter/index.html | 216 ++++++++---------- modules/client/front/defaulter/index.js | 84 ++++++- modules/client/front/defaulter/index.spec.js | 31 ++- 5 files changed, 209 insertions(+), 133 deletions(-) diff --git a/front/core/components/smart-table/table.scss b/front/core/components/smart-table/table.scss index c38c149ca..b40b988a7 100644 --- a/front/core/components/smart-table/table.scss +++ b/front/core/components/smart-table/table.scss @@ -99,6 +99,11 @@ smart-table table { } } } + & > td > textarea { + background-color: $color-font-light; + color: $color-font-bg; + width: 90%; + } } .vn-check { margin: 0; diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index c06d1c51b..0a1d5093b 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -58,16 +58,16 @@ module.exports = Self => { DISTINCT c.id clientFk, c.name clientName, c.salesPersonFk, - u.name salesPersonName, + u.nickname salesPersonName, d.amount, co.created, CONCAT(DATE(co.created), ' ', co.text) observation, uw.id workerFk, - uw.name workerName, + uw.nickname workerName, c.creditInsurance, d.defaulterSinced FROM vn.defaulter d - JOIN vn.client c ON c.id = d.clientFk + JOIN vn.client c ON c.id = d.clientFk LEFT JOIN vn.clientObservation co ON co.clientFk = c.id LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN account.user uw ON uw.id = co.workerFk diff --git a/modules/client/front/defaulter/index.html b/modules/client/front/defaulter/index.html index 121556df2..6d723c975 100644 --- a/modules/client/front/defaulter/index.html +++ b/modules/client/front/defaulter/index.html @@ -15,17 +15,18 @@ model="model"> - - - -
+ + + +
Total
+ value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
@@ -38,90 +39,98 @@ icon="icon-notes">
-
- - - - - - - - Client - Comercial - - Balance D. - - - Author - - Last observation - - Credit I. - - From - - - - - - - - - - - {{::defaulter.clientName}} - - - - - {{::defaulter.salesPersonName | dashIfEmpty}} - - - {{::defaulter.amount}} - - - {{::defaulter.workerName | dashIfEmpty}} - - - - - - - {{::defaulter.creditInsurance}} - {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} - - - -
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Client + + Comercial + + Balance D. + + Author + + Last observation + + Credit I. + + From +
+ + + + + {{::defaulter.clientName}} + + + + {{::defaulter.salesPersonName | dashIfEmpty}} + + {{::defaulter.amount | currency: 'EUR': 2}} + + {{::defaulter.workerName | dashIfEmpty}} + + + + {{::defaulter.creditInsurance | currency: 'EUR': 2}}{{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}}
+
+ + + vn-id="client-descriptor"> + vn-id="worker-descriptor"> - - - - - Filter by selection - - - Exclude selection - - - Remove filter - - - Remove all filters - - - Copy value - - - - 0) { - for (let defaulter of this.checked) - balanceDueTotal += defaulter.amount; - - return balanceDueTotal; - } + for (let defaulter of defaulters) + balanceDueTotal += defaulter.amount; return balanceDueTotal; } @@ -32,6 +85,22 @@ export default class Controller extends Section { return checkedLines; } + chipColor(date) { + const day = 24 * 60 * 60 * 1000; + const today = new Date(); + today.setHours(0, 0, 0, 0); + + const observationShipped = new Date(date); + observationShipped.setHours(0, 0, 0, 0); + + const difference = today - observationShipped; + + if (difference > (day * 20)) + return 'alert'; + if (difference > (day * 10)) + return 'warning'; + } + onResponse() { if (!this.defaulter.observation) throw new UserError(`The message can't be empty`); @@ -52,7 +121,10 @@ export default class Controller extends Section { exprBuilder(param, value) { switch (param) { + case 'observation': + return {[`observation`]: value}; case 'clientName': + case 'workerFk': case 'salesPersonFk': return {[`d.${param}`]: value}; } diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js index 6428952ec..8d6c8c307 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -39,11 +39,7 @@ describe('client defaulter', () => { describe('balanceDueTotal() getter', () => { it('should return balance due total', () => { const data = controller.$.model.data; - data[1].checked = true; - data[2].checked = true; - - const checkedRows = controller.checked; - const expectedAmount = checkedRows[0].amount + checkedRows[1].amount; + const expectedAmount = data[0].amount + data[1].amount + data[2].amount; const result = controller.balanceDueTotal; @@ -51,6 +47,31 @@ describe('client defaulter', () => { }); }); + describe('chipColor()', () => { + it('should return undefined when the date is the present', () => { + let today = new Date(); + let result = controller.chipColor(today); + + expect(result).toEqual(undefined); + }); + + it('should return warning when the date is 10 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 11); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('warning'); + }); + + it('should return alert when the date is 20 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 21); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('alert'); + }); + }); + describe('onResponse()', () => { it('should return error for empty message', () => { let error; From 4e89c66e2ca550c80deaa46183a6ffeef523ffc0 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Feb 2022 08:58:22 +0100 Subject: [PATCH 02/13] refactor(client_defaulter): add column date --- e2e/helpers/selectors.js | 10 +++++----- e2e/paths/02-client/21_defaulter.spec.js | 3 ++- front/core/components/smart-table/table.scss | 5 ----- modules/client/front/defaulter/index.html | 21 +++++++++++++++----- modules/client/front/defaulter/locale/es.yml | 8 +++++--- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f0a5c37b5..bb141de8e 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -305,11 +305,11 @@ export default { anyCreditInsuranceLine: 'vn-client-credit-insurance-insurance-index vn-tbody > vn-tr', }, clientDefaulter: { - anyClient: 'vn-client-defaulter-index vn-tbody > vn-tr', - firstClientName: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(2) > span', - firstSalesPersonName: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(3) > span', - firstObservation: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', - allDefaulterCheckbox: 'vn-client-defaulter-index vn-thead vn-multi-check', + anyClient: 'vn-client-defaulter-index tbody > tr', + firstClientName: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(2) > span', + firstSalesPersonName: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(3) > span', + firstObservation: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', + allDefaulterCheckbox: 'vn-client-defaulter-index thead vn-multi-check', addObservationButton: 'vn-client-defaulter-index vn-button[icon="icon-notes"]', observation: '.vn-dialog.shown vn-textarea[ng-model="$ctrl.defaulter.observation"]', saveButton: 'button[response="accept"]' diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index 89b5c5761..1066776d6 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -29,7 +29,7 @@ describe('Client defaulter path', () => { await page.waitToGetProperty(selectors.clientDefaulter.firstSalesPersonName, 'innerText'); expect(clientName).toEqual('Ororo Munroe'); - expect(salesPersonName).toEqual('salesPerson'); + expect(salesPersonName).toEqual('salesPersonNick'); }); it('should first observation not changed', async() => { @@ -65,6 +65,7 @@ describe('Client defaulter path', () => { it('should first observation changed', async() => { const message = await page.waitForSnackbar(); + await page.waitForSelector(selectors.clientDefaulter.firstObservation); const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value'); expect(message.text).toContain('Observation saved!'); diff --git a/front/core/components/smart-table/table.scss b/front/core/components/smart-table/table.scss index b40b988a7..c38c149ca 100644 --- a/front/core/components/smart-table/table.scss +++ b/front/core/components/smart-table/table.scss @@ -99,11 +99,6 @@ smart-table table { } } } - & > td > textarea { - background-color: $color-font-light; - color: $color-font-bg; - width: 90%; - } } .vn-check { margin: 0; diff --git a/modules/client/front/defaulter/index.html b/modules/client/front/defaulter/index.html index 6d723c975..59f7b7d67 100644 --- a/modules/client/front/defaulter/index.html +++ b/modules/client/front/defaulter/index.html @@ -65,9 +65,15 @@ vn-tooltip="Worker who made the last observation"> Author - + Last observation + + Last observation D. + @@ -111,12 +117,17 @@ {{::defaulter.workerName | dashIfEmpty}} - - + + + + + {{::defaulter.created | date: 'dd/MM/yyyy'}} + {{::defaulter.creditInsurance | currency: 'EUR': 2}} {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} diff --git a/modules/client/front/defaulter/locale/es.yml b/modules/client/front/defaulter/locale/es.yml index 172a3125d..3f046e8d6 100644 --- a/modules/client/front/defaulter/locale/es.yml +++ b/modules/client/front/defaulter/locale/es.yml @@ -1,7 +1,9 @@ -Last observation: Última observación Add observation: Añadir observación -Search client: Buscar clientes Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) -Credit I.: Crédito A. Balance D.: Saldo V. +Credit I.: Crédito A. +Last observation: Última observación +Last observation D.: Fecha última O. +Last observation date: Fecha última observación +Search client: Buscar clientes Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file From 8a8951b8b0a0dcb46bd2688cf5f665c9b4e3d375 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Feb 2022 08:53:25 +0100 Subject: [PATCH 03/13] feat(client_defaulter): add columns to search --- modules/client/front/defaulter/index.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 434ae9cb6..f4071108c 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -30,10 +30,6 @@ export default class Controller extends Section { valueField: 'id', } }, - { - field: 'amount', - searchable: false - }, { field: 'workerFk', autocomplete: { @@ -52,10 +48,6 @@ export default class Controller extends Section { valueField: 'observation', } }, - { - field: 'creditInsurance', - searchable: false - }, { field: 'defaulterSinced', searchable: false @@ -122,7 +114,9 @@ export default class Controller extends Section { exprBuilder(param, value) { switch (param) { case 'observation': - return {[`observation`]: value}; + return {[`observation`]: {like: `%${value}%`}}; + case 'creditInsurance': + case 'amount': case 'clientName': case 'workerFk': case 'salesPersonFk': From a5614e5d5dbd0f363d9e7a6368a313ea687a1720 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Feb 2022 09:52:45 +0100 Subject: [PATCH 04/13] change client.name for client.socialName --- e2e/paths/02-client/21_defaulter.spec.js | 2 +- modules/client/back/methods/defaulter/filter.js | 2 +- .../client/back/methods/defaulter/specs/filter.spec.js | 4 ++-- modules/client/front/defaulter/index.js | 9 ++++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index 1066776d6..3630a958a 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -28,7 +28,7 @@ describe('Client defaulter path', () => { const salesPersonName = await page.waitToGetProperty(selectors.clientDefaulter.firstSalesPersonName, 'innerText'); - expect(clientName).toEqual('Ororo Munroe'); + expect(clientName).toEqual('Batman'); expect(salesPersonName).toEqual('salesPersonNick'); }); diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 0a1d5093b..c65991273 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -56,7 +56,7 @@ module.exports = Self => { FROM ( SELECT DISTINCT c.id clientFk, - c.name clientName, + c.socialName clientName, c.salesPersonFk, u.nickname salesPersonName, d.amount, diff --git a/modules/client/back/methods/defaulter/specs/filter.spec.js b/modules/client/back/methods/defaulter/specs/filter.spec.js index 145bb5132..ca14d1e43 100644 --- a/modules/client/back/methods/defaulter/specs/filter.spec.js +++ b/modules/client/back/methods/defaulter/specs/filter.spec.js @@ -47,12 +47,12 @@ describe('defaulter filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 'bruce'}}; + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 'spider'}}; const result = await models.Defaulter.filter(ctx, null, options); const firstRow = result[0]; - expect(firstRow.clientName).toEqual('Bruce Wayne'); + expect(firstRow.clientName).toEqual('Spider man'); await tx.rollback(); } catch (e) { diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index f4071108c..5fcc955cc 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -16,8 +16,8 @@ export default class Controller extends Section { field: 'clientName', autocomplete: { url: 'Clients', - showField: 'name', - valueField: 'name' + showField: 'socialName', + valueField: 'socialName' } }, { @@ -34,7 +34,6 @@ export default class Controller extends Section { field: 'workerFk', autocomplete: { url: 'Workers/activeWithInheritedRole', - where: `{role: 'salesPerson'}`, searchFunction: '{firstName: $search}', showField: 'nickname', valueField: 'id', @@ -48,6 +47,10 @@ export default class Controller extends Section { valueField: 'observation', } }, + { + field: 'created', + searchable: false + }, { field: 'defaulterSinced', searchable: false From 52cf79516a16263e5d343fa451cefbd37361cffc Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Feb 2022 12:23:47 +0100 Subject: [PATCH 05/13] refactor(claim_summary): move responsability and improve fixtures --- db/dump/fixtures.sql | 8 +++--- modules/claim/front/summary/index.html | 36 ++++++++++++++------------ modules/claim/front/summary/style.scss | 3 +++ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fd..172aad8ec 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1703,10 +1703,10 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`) INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` ) VALUES - (1, CURDATE(), 1, 'observation one', 1101, 18, 3, 0, CURDATE()), - (2, CURDATE(), 2, 'observation two', 1101, 18, 3, 0, CURDATE()), - (3, CURDATE(), 3, 'observation three', 1101, 18, 1, 1, CURDATE()), - (4, CURDATE(), 3, 'observation four', 1104, 18, 5, 0, CURDATE()); + (1, CURDATE(), 1, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', 1101, 18, 3, 0, CURDATE()), + (2, CURDATE(), 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', 1101, 18, 3, 0, CURDATE()), + (3, CURDATE(), 3, 'An vim commodo dolorem volutpat, cu expetendis voluptatum usu, et mutat consul adversarium his. His natum numquam legimus an, diam fabulas mei ut. Melius fabellas sadipscing vel id. Partem diceret mandamus mea ne, has te tempor nostrud. Aeque nostro eum no.', 1101, 18, 1, 1, CURDATE()), + (4, CURDATE(), 3, 'Wisi forensibus mnesarchum in cum. Per id impetus abhorreant, his no magna definiebas, inani rationibus in quo. Ut vidisse dolores est, ut quis nominavi mel. Ad pri quod apeirian concludaturque,', 1104, 18, 5, 0, CURDATE()); INSERT INTO `vn`.`claimBeginning`(`id`, `claimFk`, `saleFk`, `quantity`) VALUES diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 8eea89a2b..723d2a5e7 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -32,28 +32,14 @@ value="{{$ctrl.summary.claim.worker.user.nickname}}"> - + - - - - - +

Action

+ + + + + + diff --git a/modules/claim/front/summary/style.scss b/modules/claim/front/summary/style.scss index e0542dea0..e81213658 100644 --- a/modules/claim/front/summary/style.scss +++ b/modules/claim/front/summary/style.scss @@ -7,4 +7,7 @@ vn-claim-summary { .photo .image { border-radius: 3px; } + vn-textarea *{ + height: 80px; + } } \ No newline at end of file From c33b8fbb83804aedd7789d69f35ccaf95631cf86 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Feb 2022 14:50:59 +0100 Subject: [PATCH 06/13] refactor(worker): absences return one or all abscences --- modules/worker/back/methods/calendar/absences.js | 15 +++++++++++++-- modules/worker/front/time-control/index.js | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/calendar/absences.js b/modules/worker/back/methods/calendar/absences.js index 32d311cdb..5861890ed 100644 --- a/modules/worker/back/methods/calendar/absences.js +++ b/modules/worker/back/methods/calendar/absences.js @@ -12,6 +12,11 @@ module.exports = Self => { arg: 'year', type: 'date', required: true, + }, + { + arg: 'all', + type: 'boolean', + required: false, }], returns: [{ arg: 'absences', @@ -27,7 +32,7 @@ module.exports = Self => { } }); - Self.absences = async(ctx, businessFk, year, options) => { + Self.absences = async(ctx, businessFk, year, all, options) => { const models = Self.app.models; const started = new Date(); @@ -45,6 +50,12 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + let where = {businessFk}; + if (all) { + let worker = await models.WorkerLabour.findOne({where: where}); + where = {workerFk: worker.workerFk}; + } + const contract = await models.WorkerLabour.findOne({ include: [{ relation: 'holidays', @@ -82,7 +93,7 @@ module.exports = Self => { } } }], - where: {businessFk} + where: where }, myOptions); if (!contract) return; diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 1f6251391..6af977506 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -128,7 +128,8 @@ class Controller extends Section { const fullYear = this.started.getFullYear(); let params = { businessFk: this.businessId, - year: fullYear + year: fullYear, + all: true }; return this.$http.get(`Calendars/absences`, {params}) From fc3a46eb2646261bba6c4b98c3492b6a20fb7d87 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 24 Feb 2022 13:52:26 +0100 Subject: [PATCH 07/13] refactor(claim): removed importTicketSales and fix tests --- .../10420-valentines/00-ImportTicketAcl.sql | 2 + db/dump/fixtures.sql | 2 +- e2e/helpers/selectors.js | 11 ++-- e2e/paths/06-claim/04_claim_action.spec.js | 29 +-------- e2e/paths/06-claim/05_summary.spec.js | 3 +- .../methods/claim-end/importTicketSales.js | 61 ------------------- .../claim-end/specs/importTicketSales.spec.js | 26 -------- .../back/methods/claim/regularizeClaim.js | 3 +- .../claim/specs/regularizeClaim.spec.js | 59 ++++++++++-------- modules/claim/back/models/claim-end.js | 3 - modules/claim/front/action/index.html | 40 +----------- modules/claim/front/action/index.js | 30 --------- modules/claim/front/action/index.spec.js | 29 --------- modules/claim/front/action/locale/es.yml | 2 - 14 files changed, 49 insertions(+), 251 deletions(-) create mode 100644 db/changes/10420-valentines/00-ImportTicketAcl.sql delete mode 100644 modules/claim/back/methods/claim-end/importTicketSales.js delete mode 100644 modules/claim/back/methods/claim-end/specs/importTicketSales.spec.js delete mode 100644 modules/claim/back/models/claim-end.js diff --git a/db/changes/10420-valentines/00-ImportTicketAcl.sql b/db/changes/10420-valentines/00-ImportTicketAcl.sql new file mode 100644 index 000000000..98192a39c --- /dev/null +++ b/db/changes/10420-valentines/00-ImportTicketAcl.sql @@ -0,0 +1,2 @@ +DELETE FROM salix.ACL +WHERE model = 'ClaimEnd' AND property = 'importTicketSales'; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 172aad8ec..39377fad8 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1706,7 +1706,7 @@ INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, ` (1, CURDATE(), 1, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', 1101, 18, 3, 0, CURDATE()), (2, CURDATE(), 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', 1101, 18, 3, 0, CURDATE()), (3, CURDATE(), 3, 'An vim commodo dolorem volutpat, cu expetendis voluptatum usu, et mutat consul adversarium his. His natum numquam legimus an, diam fabulas mei ut. Melius fabellas sadipscing vel id. Partem diceret mandamus mea ne, has te tempor nostrud. Aeque nostro eum no.', 1101, 18, 1, 1, CURDATE()), - (4, CURDATE(), 3, 'Wisi forensibus mnesarchum in cum. Per id impetus abhorreant, his no magna definiebas, inani rationibus in quo. Ut vidisse dolores est, ut quis nominavi mel. Ad pri quod apeirian concludaturque,', 1104, 18, 5, 0, CURDATE()); + (4, CURDATE(), 3, 'Wisi forensibus mnesarchum in cum. Per id impetus abhorreant, his no magna definiebas, inani rationibus in quo. Ut vidisse dolores est, ut quis nominavi mel. Ad pri quod apeirian concludaturque.', 1104, 18, 5, 0, CURDATE()); INSERT INTO `vn`.`claimBeginning`(`id`, `claimFk`, `saleFk`, `quantity`) VALUES diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f0a5c37b5..0ca23f49a 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -680,13 +680,13 @@ export default { header: 'vn-claim-summary > vn-card > h5', state: 'vn-claim-summary vn-label-value[label="State"] > section > span', observation: 'vn-claim-summary vn-textarea[ng-model="$ctrl.summary.claim.observation"]', - firstSaleItemId: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(4) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(1) > span', + firstSaleItemId: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(1) > span', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor', itemDescriptorPopoverItemDiaryButton: '.vn-popover vn-item-descriptor vn-quick-link[icon="icon-transaction"] > a', - firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', + firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(4) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', firstDevelopmentWorkerGoToClientButton: '.vn-popover vn-worker-descriptor vn-quick-link[icon="person"] > a', - firstActionTicketId: 'vn-claim-summary > vn-card > vn-horizontal > vn-auto:nth-child(6) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', + firstActionTicketId: 'vn-claim-summary > vn-card > vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', firstActionTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor' }, claimBasicData: { @@ -722,10 +722,7 @@ export default { }, claimAction: { importClaimButton: 'vn-claim-action vn-button[label="Import claim"]', - importTicketButton: 'vn-claim-action vn-button[label="Import ticket"]', - secondImportableTicket: '.vn-popover.shown .content > div > vn-table > div > vn-tbody > vn-tr:nth-child(2)', - firstLineDestination: 'vn-claim-action vn-tr:nth-child(1) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]', - secondLineDestination: 'vn-claim-action vn-tr:nth-child(2) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]', + anyLine: 'vn-claim-action vn-tbody > vn-tr', firstDeleteLine: 'vn-claim-action vn-tr:nth-child(1) vn-icon-button[icon="delete"]', isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]' }, diff --git a/e2e/paths/06-claim/04_claim_action.spec.js b/e2e/paths/06-claim/04_claim_action.spec.js index 1170e0c9c..62a0ac232 100644 --- a/e2e/paths/06-claim/04_claim_action.spec.js +++ b/e2e/paths/06-claim/04_claim_action.spec.js @@ -24,22 +24,6 @@ describe('Claim action path', () => { expect(message.text).toContain('Data saved!'); }); - it('should import the second importable ticket', async() => { - await page.waitToClick(selectors.claimAction.importTicketButton); - await page.waitToClick(selectors.claimAction.secondImportableTicket); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should edit the second line destination field', async() => { - await page.waitForContentLoaded(); - await page.autocompleteSearch(selectors.claimAction.secondLineDestination, 'Bueno'); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - it('should delete the first line', async() => { await page.waitToClick(selectors.claimAction.firstDeleteLine); const message = await page.waitForSnackbar(); @@ -47,18 +31,11 @@ describe('Claim action path', () => { expect(message.text).toContain('Data saved!'); }); - it('should refresh the view to check the remaining line is the expected one', async() => { + it('should refresh the view to check not have lines', async() => { await page.reloadSection('claim.card.action'); - const result = await page.waitToGetProperty(selectors.claimAction.firstLineDestination, 'value'); + const result = await page.countElement(selectors.claimAction.anyLine); - expect(result).toEqual('Bueno'); - }); - - it('should delete the current first line', async() => { - await page.waitToClick(selectors.claimAction.firstDeleteLine); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); + expect(result).toEqual(0); }); it('should check the "is paid with mana" checkbox', async() => { diff --git a/e2e/paths/06-claim/05_summary.spec.js b/e2e/paths/06-claim/05_summary.spec.js index cea5edb55..589b3b6cb 100644 --- a/e2e/paths/06-claim/05_summary.spec.js +++ b/e2e/paths/06-claim/05_summary.spec.js @@ -1,3 +1,4 @@ + import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; @@ -38,7 +39,7 @@ describe('Claim summary path', () => { it('should display the observation', async() => { const result = await page.waitToGetProperty(selectors.claimSummary.observation, 'value'); - expect(result).toContain('observation four'); + expect(result).toContain('Wisi forensibus mnesarchum in cum. Per id impetus abhorreant'); }); it('should display the claimed line(s)', async() => { diff --git a/modules/claim/back/methods/claim-end/importTicketSales.js b/modules/claim/back/methods/claim-end/importTicketSales.js deleted file mode 100644 index 6dd64be36..000000000 --- a/modules/claim/back/methods/claim-end/importTicketSales.js +++ /dev/null @@ -1,61 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('importTicketSales', { - description: 'Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company', - accessType: 'WRITE', - accepts: [{ - arg: 'params', - type: 'object', - http: {source: 'body'} - }], - returns: { - type: ['Object'], - root: true - }, - http: { - path: `/importTicketSales`, - verb: 'POST' - } - }); - - Self.importTicketSales = async(ctx, params, options) => { - let models = Self.app.models; - let userId = ctx.req.accessToken.userId; - - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const worker = await models.Worker.findOne({where: {userFk: userId}}, myOptions); - - let ticketSales = await models.Sale.find({ - where: {ticketFk: params.ticketFk} - }, myOptions); - - let claimEnds = []; - ticketSales.forEach(sale => { - claimEnds.push({ - saleFk: sale.id, - claimFk: params.claimFk, - workerFk: worker.id - }); - }); - - const createdClaimEnds = await Self.create(claimEnds, myOptions); - - if (tx) await tx.commit(); - - return createdClaimEnds; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/claim/back/methods/claim-end/specs/importTicketSales.spec.js b/modules/claim/back/methods/claim-end/specs/importTicketSales.spec.js deleted file mode 100644 index 93f11e21f..000000000 --- a/modules/claim/back/methods/claim-end/specs/importTicketSales.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -const app = require('vn-loopback/server/server'); - -describe('Claim importTicketSales()', () => { - it('should import sales to a claim actions from an specific ticket', async() => { - const ctx = {req: {accessToken: {userId: 5}}}; - - const tx = await app.models.Entry.beginTransaction({}); - try { - const options = {transaction: tx}; - - const claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, { - claimFk: 1, - ticketFk: 1 - }, options); - - expect(claimEnds.length).toEqual(4); - expect(claimEnds[0].saleFk).toEqual(1); - expect(claimEnds[2].saleFk).toEqual(3); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/claim/back/methods/claim/regularizeClaim.js b/modules/claim/back/methods/claim/regularizeClaim.js index d1fe7c13e..29c7320f5 100644 --- a/modules/claim/back/methods/claim/regularizeClaim.js +++ b/modules/claim/back/methods/claim/regularizeClaim.js @@ -1,6 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('regularizeClaim', { - description: 'Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company', + description: `Imports lines from claimBeginning to a new ticket + with specific shipped, landed dates, agency and company`, accessType: 'WRITE', accepts: [{ arg: 'id', diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 8ea310772..bf26d2255 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,9 +1,10 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('claim regularizeClaim()', () => { + const userId = 18; const ctx = { req: { - accessToken: {userId: 18}, + accessToken: {userId: userId}, headers: {origin: 'http://localhost'} } }; @@ -11,8 +12,9 @@ describe('claim regularizeClaim()', () => { return params.nickname; }; - const chatModel = app.models.Chat; - const claimFk = 1; + const chatModel = models.Chat; + const claimId = 1; + const ticketId = 1; const pendentState = 1; const resolvedState = 3; const trashDestination = 2; @@ -21,27 +23,40 @@ describe('claim regularizeClaim()', () => { let claimEnds = []; let trashTicket; + async function importTicket(ticketId, claimId, userId, options) { + const ticketSales = await models.Sale.find({ + where: {ticketFk: ticketId} + }, options); + const claimEnds = []; + for (let sale of ticketSales) { + claimEnds.push({ + saleFk: sale.id, + claimFk: claimId, + workerFk: userId + }); + } + + return await models.ClaimEnd.create(claimEnds, options); + } + it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { - const tx = await app.models.Claim.beginTransaction({}); + const tx = await models.Claim.beginTransaction({}); try { const options = {transaction: tx}; spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); - claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, { - claimFk: claimFk, - ticketFk: 1 - }, options); + claimEnds = await importTicket(ticketId, claimId, userId, options); for (claimEnd of claimEnds) await claimEnd.updateAttributes({claimDestinationFk: trashDestination}, options); - let claimBefore = await app.models.Claim.findById(claimFk, null, options); - await app.models.Claim.regularizeClaim(ctx, claimFk, options); - let claimAfter = await app.models.Claim.findById(claimFk, null, options); + let claimBefore = await models.Claim.findById(claimId, null, options); + await models.Claim.regularizeClaim(ctx, claimId, options); + let claimAfter = await models.Claim.findById(claimId, null, options); - trashTicket = await app.models.Ticket.findOne({where: {addressFk: 12}}, options); + trashTicket = await models.Ticket.findOne({where: {addressFk: 12}}, options); expect(trashTicket.addressFk).toEqual(trashAddress); expect(claimBefore.claimStateFk).toEqual(pendentState); @@ -57,22 +72,19 @@ describe('claim regularizeClaim()', () => { }); it('should send a chat message with value "Bueno" and then change claim state to resolved', async() => { - const tx = await app.models.Claim.beginTransaction({}); + const tx = await models.Claim.beginTransaction({}); try { const options = {transaction: tx}; spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); - claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, { - claimFk: claimFk, - ticketFk: 1 - }, options); + claimEnds = await importTicket(ticketId, claimId, userId, options); for (claimEnd of claimEnds) await claimEnd.updateAttributes({claimDestinationFk: okDestination}, options); - await app.models.Claim.regularizeClaim(ctx, claimFk, options); + await models.Claim.regularizeClaim(ctx, claimId, options); expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4); @@ -85,22 +97,19 @@ describe('claim regularizeClaim()', () => { }); it('should send a chat message to the salesPerson when claim isPickUp is enabled', async() => { - const tx = await app.models.Claim.beginTransaction({}); + const tx = await models.Claim.beginTransaction({}); try { const options = {transaction: tx}; spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); - claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, { - claimFk: claimFk, - ticketFk: 1 - }, options); + claimEnds = await importTicket(ticketId, claimId, userId, options); for (claimEnd of claimEnds) await claimEnd.updateAttributes({claimDestinationFk: okDestination}, options); - await app.models.Claim.regularizeClaim(ctx, claimFk, options); + await models.Claim.regularizeClaim(ctx, claimId, options); expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4); diff --git a/modules/claim/back/models/claim-end.js b/modules/claim/back/models/claim-end.js deleted file mode 100644 index 73531cdfc..000000000 --- a/modules/claim/back/models/claim-end.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - require('../methods/claim-end/importTicketSales')(Self); -}; diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index eeac01d78..6c0e2402d 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -24,15 +24,9 @@ - - - - - - -
- - - - ID - F. envio - Agencia - Almacen - - - - - {{::ticket.id}} - {{::ticket.shipped | date: 'dd/MM/yyyy'}} - {{::ticket.agencyMode.name}} - {{::ticket.warehouse.name}} - - - -
-
diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index cddc6873f..4b3214211 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -60,36 +60,6 @@ export default class Controller extends Section { }); } - showLastTickets(event) { - let pastWeek = new Date(); - pastWeek.setDate(-7); - - let filter = { - include: [ - {relation: 'agencyMode', fields: ['name']}, - {relation: 'warehouse', fields: ['name']} - ], - where: { - created: {gt: pastWeek}, - clientFk: this.claim.clientFk - } - }; - this.$.lastTicketsModel.filter = filter; - this.$.lastTicketsModel.refresh(); - this.$.lastTicketsPopover.show(event); - } - - importTicketLines(ticketFk) { - let data = {claimFk: this.$params.id, ticketFk: ticketFk}; - - let query = `ClaimEnds/importTicketSales`; - this.$http.post(query, data).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - this.$.lastTicketsPopover.hide(); - this.$.model.refresh(); - }); - } - regularize() { const query = `Claims/${this.$params.id}/regularizeClaim`; return this.$http.post(query).then(() => { diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 9fb9b75eb..f25f2eb3c 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -67,35 +67,6 @@ describe('claim', () => { }); }); - describe('showLastTickets()', () => { - it('should get a list of tickets and call lastTicketsPopover show() method', () => { - jest.spyOn(controller.$.lastTicketsModel, 'refresh'); - jest.spyOn(controller.$.lastTicketsPopover, 'show'); - - controller.showLastTickets({}); - - expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalled(); - expect(controller.$.lastTicketsPopover.show).toHaveBeenCalled(); - }); - }); - - describe('importTicketLines()', () => { - it('should perform a post query and add lines from an existent ticket', () => { - jest.spyOn(controller.$.model, 'refresh'); - jest.spyOn(controller.vnApp, 'showSuccess'); - jest.spyOn(controller.$.lastTicketsPopover, 'hide'); - - let data = {claimFk: 1, ticketFk: 1}; - $httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({}); - controller.importTicketLines(1); - $httpBackend.flush(); - - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalled(); - expect(controller.$.lastTicketsPopover.hide).toHaveBeenCalledWith(); - }); - }); - describe('regularize()', () => { it('should perform a post query and reload the claim card', () => { jest.spyOn(controller.card, 'reload'); diff --git a/modules/claim/front/action/locale/es.yml b/modules/claim/front/action/locale/es.yml index 3ff25dca5..22b2740b3 100644 --- a/modules/claim/front/action/locale/es.yml +++ b/modules/claim/front/action/locale/es.yml @@ -3,8 +3,6 @@ Action: Actuaciones Total claimed: Total Reclamado Import claim: Importar reclamacion Imports claim details: Importa detalles de la reclamacion -Import ticket: Importar ticket -Imports ticket lines: Importa las lineas de un ticket Regularize: Regularizar Do you want to insert greuges?: Desea insertar greuges? Insert greuges on client card: Insertar greuges en la ficha del cliente From bf712ba5af999de3b74f05796275e9cf73b5e052 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 25 Feb 2022 10:33:47 +0100 Subject: [PATCH 08/13] feat(worker): absences can return all absences of worker --- db/dump/fixtures.sql | 9 ++++ .../worker/back/methods/calendar/absences.js | 54 ++++++++++++------- .../methods/calendar/specs/absences.spec.js | 9 ++-- modules/worker/front/calendar/index.js | 1 + modules/worker/front/calendar/index.spec.js | 2 +- modules/worker/front/time-control/index.js | 18 +------ 6 files changed, 54 insertions(+), 39 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fd..7133e60cc 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1851,6 +1851,15 @@ INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_i SELECT b.business_id, NULL, 23, 1, 0, 1, 1, 1, 1 FROM `postgresql`.`business` `b`; +INSERT INTO `postgresql`.`business` (`client_id`, `provider_id`, `date_start`, `date_end`, `workerBusiness`, `reasonEndFk`) + SELECT p.profile_id, 1000, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -2 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-24'), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL + FROM `postgresql`.`profile` `p` + WHERE `p`.`profile_id` = 1109; + +INSERT INTO `postgresql`.`business_labour` (`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`) + VALUES + (1111, NULL, 23, 1, 0.0, 1, 1, 1, 1); + UPDATE `postgresql`.`business_labour` bl JOIN `postgresql`.`business` b ON b.business_id = bl.business_id JOIN `postgresql`.`profile` pr ON pr.profile_id = b.client_id diff --git a/modules/worker/back/methods/calendar/absences.js b/modules/worker/back/methods/calendar/absences.js index 32d311cdb..ddf38a604 100644 --- a/modules/worker/back/methods/calendar/absences.js +++ b/modules/worker/back/methods/calendar/absences.js @@ -4,10 +4,15 @@ module.exports = Self => { Self.remoteMethodCtx('absences', { description: 'Returns an array of absences from an specified contract', accepts: [{ - arg: 'businessFk', + arg: 'workerFk', type: 'number', required: true, }, + { + arg: 'businessFk', + type: 'number', + required: false, + }, { arg: 'year', type: 'date', @@ -27,7 +32,7 @@ module.exports = Self => { } }); - Self.absences = async(ctx, businessFk, year, options) => { + Self.absences = async(ctx, workerFk, businessFk, year, options) => { const models = Self.app.models; const started = new Date(); @@ -45,7 +50,17 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const contract = await models.WorkerLabour.findOne({ + let condition = { + and: [ + {workerFk: workerFk}, + {businessFk: businessFk} + ] + }; + + if (businessFk) + condition.and.push({workerFk: workerFk}); + + const contracts = await models.WorkerLabour.find({ include: [{ relation: 'holidays', scope: { @@ -82,31 +97,32 @@ module.exports = Self => { } } }], - where: {businessFk} + where: condition }, myOptions); - if (!contract) return; + if (!contracts) return; - const isSubordinate = await models.Worker.isSubordinate(ctx, contract.workerFk, myOptions); + const isSubordinate = await models.Worker.isSubordinate(ctx, workerFk, myOptions); if (!isSubordinate) throw new UserError(`You don't have enough privileges`); const absences = []; - for (let absence of contract.absences()) { - absence.dated = new Date(absence.dated); - absence.dated.setHours(0, 0, 0, 0); - - absences.push(absence); - } - - // Workcenter holidays const holidays = []; - const holidayList = contract.workCenter().holidays(); - for (let day of holidayList) { - day.dated = new Date(day.dated); - day.dated.setHours(0, 0, 0, 0); - holidays.push(day); + for (let contract of contracts) { + for (let absence of contract.absences()) { + absence.dated = new Date(absence.dated); + absence.dated.setHours(0, 0, 0, 0); + + absences.push(absence); + } + + for (let day of contract.workCenter().holidays()) { + day.dated = new Date(day.dated); + day.dated.setHours(0, 0, 0, 0); + + holidays.push(day); + } } return [absences, holidays]; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index cfe7379c3..812b9c23c 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -3,12 +3,13 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; + const workerId = 1106; const businessId = 1106; const now = new Date(); const year = now.getFullYear(); - const [absences] = await app.models.Calendar.absences(ctx, businessId, year); + const [absences] = await app.models.Calendar.absences(ctx, workerId, businessId, year); const firstType = absences[0].absenceType().name; const sixthType = absences[5].absenceType().name; @@ -35,7 +36,7 @@ describe('Worker absences()', () => { `UPDATE postgresql.business SET date_end = ? WHERE business_id = ?`, [null, worker.businessFk], options); - const [absences] = await app.models.Calendar.absences(ctx, businessId, year, options); + const [absences] = await app.models.Calendar.absences(ctx, worker.id, businessId, year, options); let firstType = absences[0].absenceType().name; let sixthType = absences[5].absenceType().name; @@ -51,6 +52,8 @@ describe('Worker absences()', () => { it('should give the same holidays as worked days since the holidays amount matches the amount of days in a year', async() => { const businessId = 1106; + const workerId = 1106; + const userId = 1106; const today = new Date(); @@ -101,7 +104,7 @@ describe('Worker absences()', () => { const ctx = {req: {accessToken: {userId: userId}}}; - const [absences] = await app.models.Calendar.absences(ctx, businessId, currentYear); + const [absences] = await app.models.Calendar.absences(ctx, workerId, businessId, currentYear); const firstType = absences[0].absenceType().name; const sixthType = absences[5].absenceType().name; diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 6e0cf0d9a..92bad1f0f 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -282,6 +282,7 @@ class Controller extends Section { refresh() { const params = { + workerFk: this.$params.id, businessFk: this.businessId, year: this.year }; diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index e8f9b3130..3d5775663 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -328,7 +328,7 @@ describe('Worker', () => { jest.spyOn(controller, 'onData').mockReturnThis(); const expecteResponse = [{id: 1}]; - const expectedParams = {year: year}; + const expectedParams = {workerFk: controller.worker.id, year: year}; const serializedParams = $httpParamSerializer(expectedParams); $httpBackend.expect('GET', `Calendars/absences?${serializedParams}`).respond(200, expecteResponse); controller.refresh(); diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 1f6251391..ebf70e886 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -32,11 +32,6 @@ class Controller extends Section { set worker(value) { this._worker = value; - - if (value) { - this.getActiveContract() - .then(() => this.getAbsences()); - } } /** @@ -96,14 +91,6 @@ class Controller extends Section { } } - getActiveContract() { - return this.$http.get(`Workers/${this.worker.id}/activeContract`) - .then(res => { - if (res.data) - this.businessId = res.data.businessFk; - }); - } - fetchHours() { const params = {workerFk: this.$params.id}; const filter = { @@ -123,11 +110,10 @@ class Controller extends Section { } getAbsences() { - if (!this.businessId) return; - const fullYear = this.started.getFullYear(); let params = { - businessFk: this.businessId, + workerFk: this.$params.id, + businessFk: null, year: fullYear }; From 62286c2f9a48e34caa3a3668fa02c8cd786a2df1 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 25 Feb 2022 10:34:17 +0100 Subject: [PATCH 09/13] refactor(defaulter): simple route --- e2e/helpers/selectors.js | 12 ++++++------ e2e/paths/02-client/21_defaulter.spec.js | 4 ++-- modules/client/front/defaulter/index.js | 2 +- modules/client/front/defaulter/index.spec.js | 4 ++-- modules/client/front/routes.json | 10 ++-------- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f0a5c37b5..f29e38961 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -305,12 +305,12 @@ export default { anyCreditInsuranceLine: 'vn-client-credit-insurance-insurance-index vn-tbody > vn-tr', }, clientDefaulter: { - anyClient: 'vn-client-defaulter-index vn-tbody > vn-tr', - firstClientName: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(2) > span', - firstSalesPersonName: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(3) > span', - firstObservation: 'vn-client-defaulter-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', - allDefaulterCheckbox: 'vn-client-defaulter-index vn-thead vn-multi-check', - addObservationButton: 'vn-client-defaulter-index vn-button[icon="icon-notes"]', + anyClient: 'vn-client-defaulter vn-tbody > vn-tr', + firstClientName: 'vn-client-defaulter vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(2) > span', + firstSalesPersonName: 'vn-client-defaulter vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(3) > span', + firstObservation: 'vn-client-defaulter vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', + allDefaulterCheckbox: 'vn-client-defaulter vn-thead vn-multi-check', + addObservationButton: 'vn-client-defaulter vn-button[icon="icon-notes"]', observation: '.vn-dialog.shown vn-textarea[ng-model="$ctrl.defaulter.observation"]', saveButton: 'button[response="accept"]' }, diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index 89b5c5761..eb26d375e 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -9,7 +9,7 @@ describe('Client defaulter path', () => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter.index'); + await page.accessToSection('client.defaulter'); }); afterAll(async() => { @@ -52,7 +52,7 @@ describe('Client defaulter path', () => { it('shoul checked all defaulters', async() => { await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter.index'); + await page.accessToSection('client.defaulter'); await page.waitToClick(selectors.clientDefaulter.allDefaulterCheckbox); }); diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 76afeb160..9259ad917 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -59,7 +59,7 @@ export default class Controller extends Section { } } -ngModule.vnComponent('vnClientDefaulterIndex', { +ngModule.vnComponent('vnClientDefaulter', { template: require('./index.html'), controller: Controller }); diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js index 6428952ec..0a7d7fcc6 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -2,7 +2,7 @@ import './index'; import crudModel from 'core/mocks/crud-model'; describe('client defaulter', () => { - describe('Component vnClientDefaulterIndex', () => { + describe('Component vnClientDefaulter', () => { let controller; let $httpBackend; @@ -11,7 +11,7 @@ describe('client defaulter', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; const $element = angular.element(''); - controller = $componentController('vnClientDefaulterIndex', {$element}); + controller = $componentController('vnClientDefaulter', {$element}); controller.$.model = crudModel; controller.$.model.data = [ {clientFk: 1101, amount: 125}, diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index d6f8a70bd..8398a8745 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -8,7 +8,7 @@ "main": [ {"state": "client.index", "icon": "person"}, {"state": "client.notification", "icon": "campaign"}, - {"state": "client.defaulter.index", "icon": "icon-defaulter"} + {"state": "client.defaulter", "icon": "icon-defaulter"} ], "card": [ {"state": "client.card.basicData", "icon": "settings"}, @@ -366,13 +366,7 @@ { "url": "/defaulter", "state": "client.defaulter", - "component": "ui-view", - "description": "Defaulter" - }, - { - "url": "/index?q", - "state": "client.defaulter.index", - "component": "vn-client-defaulter-index", + "component": "vn-client-defaulter", "description": "Defaulter" }, { From 5434dd3bafba686dbf1333d4deb537931b6b8d87 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 28 Feb 2022 07:57:46 +0100 Subject: [PATCH 10/13] feat(claim_index): implemented smart-table and change state in summary --- modules/claim/back/methods/claim/filter.js | 37 +++--- modules/claim/front/index/index.html | 124 ++++++++++++--------- modules/claim/front/index/index.js | 64 ++++++++++- modules/claim/front/summary/index.html | 9 ++ modules/claim/front/summary/index.js | 41 ++++++- modules/claim/front/summary/index.spec.js | 1 + 6 files changed, 204 insertions(+), 72 deletions(-) diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js index f4b0c26a2..cf2748e4f 100644 --- a/modules/claim/back/methods/claim/filter.js +++ b/modules/claim/back/methods/claim/filter.js @@ -94,19 +94,15 @@ module.exports = Self => { ? {'cl.id': value} : { or: [ - {'c.name': {like: `%${value}%`}} + {'cl.socialName': {like: `%${value}%`}} ] }; - case 'client': - return {'c.name': {like: `%${value}%`}}; + case 'workerFk': + return {['cl.workerFk']: value}; case 'id': - return {'cl.id': value}; - case 'clientFk': - return {'c.id': value}; case 'claimStateFk': - return {'cl.claimStateFk': value}; - case 'salesPersonFk': - return {'c.salesPersonFk': value}; + case 'priority': + return {[`cl.${param}`]: value}; case 'attenderFk': return {'cl.workerFk': value}; case 'created': @@ -123,12 +119,23 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( - `SELECT cl.id, c.name, cl.clientFk, cl.workerFk, u.name AS userName, cs.description, cl.created - FROM claim cl - LEFT JOIN client c ON c.id = cl.clientFk - LEFT JOIN worker w ON w.id = cl.workerFk - LEFT JOIN account.user u ON u.id = w.userFk - LEFT JOIN claimState cs ON cs.id = cl.claimStateFk` + `SELECT * + FROM ( + SELECT + cl.id, + cl.clientFk, + c.socialName, + cl.workerFk, + u.name AS workerName, + cs.description, + cl.created, + cs.priority, + cl.claimStateFk + FROM claim cl + LEFT JOIN client c ON c.id = cl.clientFk + LEFT JOIN worker w ON w.id = cl.workerFk + LEFT JOIN account.user u ON u.id = w.userFk + LEFT JOIN claimState cs ON cs.id = cl.claimStateFk ) cl` ); stmt.merge(conn.makeSuffix(filter)); diff --git a/modules/claim/front/index/index.html b/modules/claim/front/index/index.html index c8f7e994c..bb2e2f711 100644 --- a/modules/claim/front/index/index.html +++ b/modules/claim/front/index/index.html @@ -1,59 +1,74 @@ - - - - - - Id - Client - Created - Worker - State - - - - -
- {{::claim.id}} - - - {{::claim.name}} - - - {{::claim.created | date:'dd/MM/yyyy'}} - - - {{::claim.userName}} - - - - - {{::claim.description}} - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +
+ Id + + Client + + Created + + Worker + + State +
{{::claim.id}} + + {{::claim.socialName}} + + {{::claim.created | date:'dd/MM/yyyy'}} + + {{::claim.workerName}} + + + + {{::claim.description}} + + + + +
+
+
+
@@ -62,6 +77,7 @@ + claim="$ctrl.claimSelected" + parent-reload="$ctrl.reload()"> diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index fe4b6def7..a2cc8b5e1 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -1,7 +1,69 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -export default class Controller extends Section { +class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'clientFk', + autocomplete: { + url: 'Clients', + showField: 'socialName', + valueField: 'socialName' + } + }, + { + field: 'workerFk', + autocomplete: { + url: 'Workers/activeWithInheritedRole', + where: `{role: 'salesPerson'}`, + searchFunction: '{firstName: $search}', + showField: 'name', + valueField: 'id', + } + }, + { + field: 'claimStateFk', + autocomplete: { + url: 'ClaimStates', + showField: 'description', + valueField: 'id', + } + }, + { + field: 'created', + searchable: false + } + ] + }; + } + + exprBuilder(param, value) { + switch (param) { + case 'clientFk': + return {['cl.socialName']: value}; + case 'id': + case 'workerFk': + case 'claimStateFk': + case 'priority': + return {[`cl.${param}`]: value}; + case 'attenderFk': + return {'cl.workerFk': value}; + case 'created': + value.setHours(0, 0, 0, 0); + to = new Date(value); + to.setHours(23, 59, 59, 999); + + return {'cl.created': {between: [value, to]}}; + } + } + stateColor(claim) { switch (claim.description) { case 'Pendiente': diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 8eea89a2b..f46b3622a 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -12,6 +12,15 @@ {{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}} + + diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index bda830d6a..89a920962 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -13,6 +13,18 @@ class Controller extends Summary { this.getSummary(); } + loadData() { + this.getSummary(); + } + + reload() { + if (this.card) { + console.log('CARD'); + this.card.reload(); + } + if (this.parentReload) + this.parentReload(); + } get isSalesPerson() { return this.aclService.hasAny(['salesPerson']); } @@ -29,8 +41,10 @@ class Controller extends Summary { this._claim = value; // Get DMS on summary load - if (value) + if (value) { this.$.$applyAsync(() => this.loadDms()); + this.loadData(); + } } loadDms() { @@ -44,11 +58,29 @@ class Controller extends Summary { this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => { this.summary = response.data; }); + this.$http.get(`Claims/${this.claim.id}/isEditable`).then(response => { + this.isEditable = response.data; + }); } getImagePath(dmsId) { return this.vnFile.getPath(`/api/dms/${dmsId}/downloadFile`); } + + changeState(value) { + const params = { + id: this.claim.id, + claimStateFk: value + }; + + this.$http.patch(`Claims/updateClaim/${this.claim.id}`, params) + .then(() => { + this.reload(); + }) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } } Controller.$inject = ['$element', '$scope', 'vnFile']; @@ -57,6 +89,11 @@ ngModule.vnComponent('vnClaimSummary', { template: require('./index.html'), controller: Controller, bindings: { - claim: '<' + claim: '<', + model: ' { it('should perform a query to set summary', () => { $httpBackend.expect('GET', `Claims/1/getSummary`).respond(200, 24); controller.getSummary(); + $httpBackend.expect('GET', `Claims/1/isEditable`).respond(200, true); $httpBackend.flush(); expect(controller.summary).toEqual(24); From 60e908d82ac160d63cd9d9d3975c0304eda69b31 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 28 Feb 2022 12:40:44 +0100 Subject: [PATCH 11/13] feat(claim_summary): parentReload(), and test --- modules/claim/back/methods/claim/filter.js | 3 +- .../claim/back/methods/claim/getSummary.js | 5 +-- .../back/methods/claim/specs/filter.spec.js | 2 +- .../methods/claim/specs/getSummary.spec.js | 11 +++++-- modules/claim/front/index/index.html | 2 +- modules/claim/front/index/index.js | 6 +++- modules/claim/front/main/index.js | 8 +++-- modules/claim/front/summary/index.html | 2 +- modules/claim/front/summary/index.js | 31 +++++++++---------- modules/claim/front/summary/index.spec.js | 27 +++++++++++----- 10 files changed, 61 insertions(+), 36 deletions(-) diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js index cf2748e4f..f4eecae6d 100644 --- a/modules/claim/back/methods/claim/filter.js +++ b/modules/claim/back/methods/claim/filter.js @@ -97,12 +97,11 @@ module.exports = Self => { {'cl.socialName': {like: `%${value}%`}} ] }; - case 'workerFk': - return {['cl.workerFk']: value}; case 'id': case 'claimStateFk': case 'priority': return {[`cl.${param}`]: value}; + case 'salesPersonFk': case 'attenderFk': return {'cl.workerFk': value}; case 'created': diff --git a/modules/claim/back/methods/claim/getSummary.js b/modules/claim/back/methods/claim/getSummary.js index 512e4a77f..0accbf920 100644 --- a/modules/claim/back/methods/claim/getSummary.js +++ b/modules/claim/back/methods/claim/getSummary.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('getSummary', { + Self.remoteMethodCtx('getSummary', { description: 'Return the claim summary', accessType: 'READ', accepts: [{ @@ -19,7 +19,7 @@ module.exports = Self => { } }); - Self.getSummary = async(id, options) => { + Self.getSummary = async(ctx, id, options) => { const myOptions = {}; if (typeof options == 'object') @@ -135,6 +135,7 @@ module.exports = Self => { const res = await Promise.all(promises); + summary.isEditable = await Self.isEditable(ctx, id, myOptions); [summary.claim] = res[0]; summary.salesClaimed = res[1]; summary.developments = res[2]; diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index b26afe8c4..c54318e45 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -25,7 +25,7 @@ describe('claim filter()', () => { try { const options = {transaction: tx}; - const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options); + const result = await app.models.Claim.filter({args: {filter: {}, search: 'Iron man'}}, null, options); expect(result.length).toEqual(1); expect(result[0].id).toEqual(4); diff --git a/modules/claim/back/methods/claim/specs/getSummary.spec.js b/modules/claim/back/methods/claim/specs/getSummary.spec.js index 541f42cfb..6eb920b29 100644 --- a/modules/claim/back/methods/claim/specs/getSummary.spec.js +++ b/modules/claim/back/methods/claim/specs/getSummary.spec.js @@ -3,17 +3,24 @@ const app = require('vn-loopback/server/server'); describe('claim getSummary()', () => { it('should return summary with claim, salesClaimed, developments and actions defined ', async() => { const tx = await app.models.Claim.beginTransaction({}); - + const ctx = { + req: { + accessToken: { + userId: 9 + } + } + }; try { const options = {transaction: tx}; - const result = await app.models.Claim.getSummary(1, options); + const result = await app.models.Claim.getSummary(ctx, 1, options); const keys = Object.keys(result); expect(keys).toContain('claim'); expect(keys).toContain('salesClaimed'); expect(keys).toContain('developments'); expect(keys).toContain('actions'); + expect(keys).toContain('isEditable'); await tx.rollback(); } catch (e) { diff --git a/modules/claim/front/index/index.html b/modules/claim/front/index/index.html index bb2e2f711..341d6eb2f 100644 --- a/modules/claim/front/index/index.html +++ b/modules/claim/front/index/index.html @@ -19,7 +19,7 @@ Created - + Worker diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index a2cc8b5e1..bf0cb25c0 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -49,10 +49,10 @@ class Controller extends Section { case 'clientFk': return {['cl.socialName']: value}; case 'id': - case 'workerFk': case 'claimStateFk': case 'priority': return {[`cl.${param}`]: value}; + case 'salesPersonFk': case 'attenderFk': return {'cl.workerFk': value}; case 'created': @@ -79,6 +79,10 @@ class Controller extends Section { this.claimSelected = claim; this.$.summary.show(); } + + reload() { + this.$.model.refresh(); + } } ngModule.vnComponent('vnClaimIndex', { diff --git a/modules/claim/front/main/index.js b/modules/claim/front/main/index.js index 77b051897..a9fad2eeb 100644 --- a/modules/claim/front/main/index.js +++ b/modules/claim/front/main/index.js @@ -1,9 +1,13 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Claim extends ModuleMain {} +export default class Claims extends ModuleMain { + constructor($element, $) { + super($element, $); + } +} ngModule.vnComponent('vnClaim', { - controller: Claim, + controller: Claims, template: require('./index.html') }); diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index f46b3622a..c1d056eed 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -13,7 +13,7 @@ {{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}} { + if (res && res.data) + this.summary = res.data; + }); } reload() { - if (this.card) { - console.log('CARD'); - this.card.reload(); - } - if (this.parentReload) - this.parentReload(); + this.loadData() + .then(() => { + if (this.card) + this.card.reload(); + // Refresh index model + if (this.parentReload) + this.parentReload(); + }); } + get isSalesPerson() { return this.aclService.hasAny(['salesPerson']); } @@ -54,15 +60,6 @@ class Controller extends Summary { this.$.model.refresh(); } - getSummary() { - this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => { - this.summary = response.data; - }); - this.$http.get(`Claims/${this.claim.id}/isEditable`).then(response => { - this.isEditable = response.data; - }); - } - getImagePath(dmsId) { return this.vnFile.getPath(`/api/dms/${dmsId}/downloadFile`); } diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index 31e10eccb..02bdf21d2 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -18,24 +18,37 @@ describe('Claim', () => { controller.$.model = crudModel; })); - describe('getSummary()', () => { + describe('loadData()', () => { it('should perform a query to set summary', () => { - $httpBackend.expect('GET', `Claims/1/getSummary`).respond(200, 24); - controller.getSummary(); - $httpBackend.expect('GET', `Claims/1/isEditable`).respond(200, true); + $httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24); + controller.loadData(); $httpBackend.flush(); expect(controller.summary).toEqual(24); }); }); + describe('changeState()', () => { + it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => { + jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); + + const expectedParams = {id: 1, claimStateFk: 1}; + $httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24); + $httpBackend.expect('PATCH', `Claims/updateClaim/1`, expectedParams).respond(200); + controller.changeState(1); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + }); + }); + describe('$onChanges()', () => { - it('should call getSummary when item.id is defined', () => { - jest.spyOn(controller, 'getSummary'); + it('should call loadData when item.id is defined', () => { + jest.spyOn(controller, 'loadData'); controller.$onChanges(); - expect(controller.getSummary).toHaveBeenCalledWith(); + expect(controller.loadData).toHaveBeenCalledWith(); }); }); }); From 2026e909e93e0ff76e2d70b278c65f0855360fab Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 1 Mar 2022 11:43:35 +0100 Subject: [PATCH 12/13] disable search observation --- modules/client/back/methods/defaulter/filter.js | 2 +- modules/client/front/defaulter/index.js | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index c65991273..095b9b1c1 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -61,7 +61,7 @@ module.exports = Self => { u.nickname salesPersonName, d.amount, co.created, - CONCAT(DATE(co.created), ' ', co.text) observation, + co.text observation, uw.id workerFk, uw.nickname workerName, c.creditInsurance, diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 5fcc955cc..9595be61c 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -41,11 +41,7 @@ export default class Controller extends Section { }, { field: 'observation', - autocomplete: { - url: 'Defaulters/filter', - showField: 'observation', - valueField: 'observation', - } + searchable: false }, { field: 'created', @@ -116,8 +112,6 @@ export default class Controller extends Section { exprBuilder(param, value) { switch (param) { - case 'observation': - return {[`observation`]: {like: `%${value}%`}}; case 'creditInsurance': case 'amount': case 'clientName': From 619baf289677a7f2b91e82249a77bfb45213466b Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 2 Mar 2022 11:07:35 +0100 Subject: [PATCH 13/13] refactor claim_main controller --- modules/claim/front/main/index.js | 8 +------- modules/claim/front/summary/index.js | 2 +- modules/claim/front/summary/index.spec.js | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/modules/claim/front/main/index.js b/modules/claim/front/main/index.js index a9fad2eeb..0c5c7d728 100644 --- a/modules/claim/front/main/index.js +++ b/modules/claim/front/main/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Claims extends ModuleMain { - constructor($element, $) { - super($element, $); - } -} - ngModule.vnComponent('vnClaim', { - controller: Claims, + controller: ModuleMain, template: require('./index.html') }); diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index cc9799f05..721f51846 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -25,7 +25,7 @@ class Controller extends Summary { .then(() => { if (this.card) this.card.reload(); - // Refresh index model + if (this.parentReload) this.parentReload(); }); diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index 02bdf21d2..8540a3a97 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -29,7 +29,7 @@ describe('Claim', () => { }); describe('changeState()', () => { - it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => { + it('should make an HTTP post query, then call the showSuccess()', () => { jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); const expectedParams = {id: 1, claimStateFk: 1}; @@ -43,7 +43,7 @@ describe('Claim', () => { }); describe('$onChanges()', () => { - it('should call loadData when item.id is defined', () => { + it('should call loadData when $onChanges is called', () => { jest.spyOn(controller, 'loadData'); controller.$onChanges();