diff --git a/client/client/routes.json b/client/client/routes.json index 353d87d2e8..5d3311a0fa 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -205,14 +205,32 @@ } }, { - "url": "/invoice", - "state": "client.card.invoice", - "component": "vn-client-invoice", - "description": "Invoices", + "url": "/risk", + "abstract": true, + "state": "client.card.risk", + "component": "ui-view" + }, + { + "url": "/index", + "state": "client.card.risk.index", + "component": "vn-client-risk-index", + "description": "Risk", + "params": { + "client": "$ctrl.client" + }, "menu": { "icon": "icon-invoices" } }, + { + "url": "/create", + "state": "client.card.risk.create", + "component": "vn-client-risk-create", + "description": "New payment", + "params": { + "client": "$ctrl.client" + } + }, { "url": "/recovery", "abstract": true, diff --git a/client/client/src/client.js b/client/client/src/client.js index a6cc977166..007a1c970d 100644 --- a/client/client/src/client.js +++ b/client/client/src/client.js @@ -19,8 +19,9 @@ import './credit/index'; import './credit/create'; import './greuge/index'; import './greuge/create'; +import './risk/index'; +import './risk/create'; import './mandate'; -import './invoice'; import './summary'; import './recovery/index'; import './recovery/create'; diff --git a/client/client/src/invoice/index.html b/client/client/src/invoice/index.html deleted file mode 100644 index 64e6f2d846..0000000000 --- a/client/client/src/invoice/index.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - Invoices - - - - Reference - Issue date - Due date - Amount - - - - - - {{::invoice.ref}} - {{::invoice.issued | date:'dd/MM/yyyy' }} - {{::invoice.dued | date:'dd/MM/yyyy' }} - {{::invoice.amount | currency:' €': 2}} - - - - No results - - - - - - - \ No newline at end of file diff --git a/client/client/src/invoice/index.js b/client/client/src/invoice/index.js deleted file mode 100644 index fd973ceb9a..0000000000 --- a/client/client/src/invoice/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import ngModule from '../module'; - -class Controller { - constructor($stateParams) { - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$stateParams']; - -ngModule.component('vnClientInvoice', { - template: require('./index.html'), - controller: Controller -}); diff --git a/client/client/src/invoice/locale/es.yml b/client/client/src/invoice/locale/es.yml deleted file mode 100644 index 8198272849..0000000000 --- a/client/client/src/invoice/locale/es.yml +++ /dev/null @@ -1,4 +0,0 @@ -Reference: Referencia -Issue date: Fecha de emisión -Due date: Vencimiento -Amount: Total \ No newline at end of file diff --git a/client/client/src/risk/index/index.html b/client/client/src/risk/index/index.html new file mode 100644 index 0000000000..95c7fd4317 --- /dev/null +++ b/client/client/src/risk/index/index.html @@ -0,0 +1,79 @@ + + + + + + + + Risk +
+
Total por empresa
+ + + + +
+
+ + + + + Date + Creation date + Employee + Reference + Bank + Debit + Credit + Conciliated + Company + + + + + {{::risk.payed | dateTime:'dd/MM/yyyy'}} + {{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}} + {{::risk.firstName}} {{::risk.name}} + {{::risk.reference}} + {{::risk.bankFk}} + {{::risk.debit | currency: ' €': 2}} + {{::risk.credit | currency: ' €': 2}} + + + + + {{::risk.company}} + + + + No results + + + + + +
+
+ + + + \ No newline at end of file diff --git a/client/client/src/risk/index/index.js b/client/client/src/risk/index/index.js new file mode 100644 index 0000000000..348e9b1077 --- /dev/null +++ b/client/client/src/risk/index/index.js @@ -0,0 +1,25 @@ +import ngModule from '../../module'; + +class Controller { + constructor($stateParams) { + this.$stateParams = $stateParams; + + this.filter = { + include: { + relation: "company", + scope: { + fields: ["code"] + } + }, + where: { + clientFk: $stateParams.id + }}; + } +} + +Controller.$inject = ['$stateParams']; + +ngModule.component('vnClientRiskIndex', { + template: require('./index.html'), + controller: Controller +}); diff --git a/client/client/src/risk/index/locale/es.yml b/client/client/src/risk/index/locale/es.yml new file mode 100644 index 0000000000..78af91b1a1 --- /dev/null +++ b/client/client/src/risk/index/locale/es.yml @@ -0,0 +1,6 @@ +Creation date: Fecha de creación +Reference: Referencia +Bank: Caja +Debit: Debe +Conciliated: Conciliado +New payment: Añadir pago \ No newline at end of file diff --git a/client/client/src/summary/index.html b/client/client/src/summary/index.html index 7972475c5b..4d41ad0367 100644 --- a/client/client/src/summary/index.html +++ b/client/client/src/summary/index.html @@ -190,7 +190,7 @@ value="{{$ctrl.summary.creditInsurance | currency:'€ ':2}}"> + value="{{$ctrl.summary.sumRisk | currency:'€ ':2}}"> { + total += risk.amount; + }); + return total; + } } Controller.$inject = ['$http']; diff --git a/client/client/src/summary/index.spec.js b/client/client/src/summary/index.spec.js index 99c20e37d0..33f0b579b7 100644 --- a/client/client/src/summary/index.spec.js +++ b/client/client/src/summary/index.spec.js @@ -21,32 +21,34 @@ describe('Client', () => { describe('$onChanges()', () => { it('should perform a GET query and define summary property', () => { let res = {name: 'Superman', classifications: []}; + + spyOn(controller, "sumRisk"); $httpBackend.when('GET', `/client/api/Clients/101/summary`).respond(200, res); $httpBackend.expect('GET', `/client/api/Clients/101/summary`); + controller.$onChanges(); $httpBackend.flush(); expect(controller.summary).toBeDefined(); expect(controller.summary.name).toEqual('Superman'); - expect(controller.grade).toBeUndefined(); }); + }); - it('should perform a GET query and define summary and grade property', () => { - let res = { - name: 'Superman', - classifications: [{insurances: [ - {id: 1, grade: 1} - ]}] - }; - $httpBackend.when('GET', `/client/api/Clients/101/summary`).respond(200, res); - $httpBackend.expect('GET', `/client/api/Clients/101/summary`); - controller.$onChanges(); - $httpBackend.flush(); + describe('sumRisk()', () => { + it('should sum property amount of an array', () => { + controller.summary = { + clientRisks: [{ + companyFk: 442, + amount: 100 + }, + { + companyFk: 567, + amount: 200 + }]}; - expect(controller.summary).toBeDefined(); - expect(controller.summary.name).toEqual('Superman'); - expect(controller.grade).toBeDefined(); - expect(controller.grade).toEqual(1); + let result = controller.sumRisk(); + + expect(result).toEqual(300); }); }); }); diff --git a/services/agency/package.json b/services/agency/package.json index 02585bae3d..1de5babf57 100644 --- a/services/agency/package.json +++ b/services/agency/package.json @@ -16,4 +16,4 @@ "dependencies": { "vn-loopback": "file:../loopback" } -} \ No newline at end of file +} diff --git a/services/client/common/methods/receipt/filter.js b/services/client/common/methods/receipt/filter.js new file mode 100644 index 0000000000..d644131971 --- /dev/null +++ b/services/client/common/methods/receipt/filter.js @@ -0,0 +1,74 @@ +const ParameterizedSQL = require('vn-loopback/node_modules/loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethod('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'Object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { + arg: 'params', + type: 'Object', + description: 'clientFk', + http: {source: 'query'} + } + ], + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async (filter, params) => { + let stmt = new ParameterizedSQL( + `SELECT + r.id, + r.isConciliate, + r.payed, + c.code AS company, + r.created, + '' description, + 0 AS debit, + r.amountPaid AS credit, + r.bankFk, + firstName, + name, + r.clientFk + FROM vn.receipt r + JOIN vn.worker w ON w.id = r.workerFk + JOIN vn.company c ON c.id = r.companyFk + WHERE clientFk = ? + UNION ALL + SELECT + i.id, + TRUE, + i.dued, + c.code AS company, + i.created, + CONCAT(' N/FRA ', i.ref) description, + i.amount AS debit, + 0 credit, + NULL bank, + NULL firstName, + NULL name, + i.clientFk + FROM vn.invoiceOut i + JOIN vn.company c ON c.id = i.companyFk + WHERE clientFk = ? + ORDER BY payed DESC, created DESC`, [ + params.clientFk, + params.clientFk + ]); + + stmt.merge(Self.buildPagination(filter)); + return await Self.rawStmt(stmt); + }; +}; diff --git a/services/client/common/methods/receipt/specs/filter.spec.js b/services/client/common/methods/receipt/specs/filter.spec.js new file mode 100644 index 0000000000..381f98eec3 --- /dev/null +++ b/services/client/common/methods/receipt/specs/filter.spec.js @@ -0,0 +1,13 @@ +const app = require(`${servicesDir}/client/server/server`); + +describe('receipt filter()', () => { + it('should call the filter method', async() => { + let filter = {limit: 20}; + let params = { + clientFk: 101 + }; + let result = await app.models.Receipt.filter(filter, params); + + expect(result.length).toBeGreaterThan(0); + }); +}); diff --git a/services/client/common/models/receipt.js b/services/client/common/models/receipt.js new file mode 100644 index 0000000000..97907c457b --- /dev/null +++ b/services/client/common/models/receipt.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/receipt/filter')(Self); +}; diff --git a/services/client/common/models/receipt.json b/services/client/common/models/receipt.json index ad18ff44d7..1e99a3d0cc 100644 --- a/services/client/common/models/receipt.json +++ b/services/client/common/models/receipt.json @@ -5,59 +5,54 @@ "mysql": { "table": "receipt" } -}, -"properties": { - "id": { - "id": true, - "type": "Number", - "description": "Identifier" - }, - "ref": { - "id": true, - "type": "String", - "required": true - }, - "amountPaid": { - "type": "Number" - }, - "amountUnpaid": { - "type": "Number" - }, - "payed": { - "type": "date" - }, - "worcreated": { - "type": "date" - }, - "isConciliate": { - "type": "date" - } -}, -"relations": { - "client": { - "type": "belongsTo", - "model": "Client", - "foreignKey": "clientFk" - }, - "company": { - "type": "belongsTo", - "model": "Company", - "foreignKey": "companyFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "bank": { - "type": "belongsTo", - "model": "Bank", - "foreignKey": "bankFk" - }, - "invoice": { - "type": "belongsTo", - "model": "InvoiceOut", - "foreignKey": "invoiceFk" - } - } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "amountPaid": { + "type": "Number" + }, + "amountUnpaid": { + "type": "Number" + }, + "payed": { + "type": "date" + }, + "created": { + "type": "date" + }, + "isConciliate": { + "type": "date" + } + }, + "relations": { + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + }, + "company": { + "type": "belongsTo", + "model": "Company", + "foreignKey": "companyFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "bank": { + "type": "belongsTo", + "model": "Bank", + "foreignKey": "bankFk" + }, + "invoice": { + "type": "belongsTo", + "model": "InvoiceOut", + "foreignKey": "invoiceFk" + } + } } \ No newline at end of file diff --git a/services/db/install/changes/1.2-CHECK/06.ACL.sql b/services/db/install/changes/1.2-CHECK/06.ACL.sql index ffb794099a..947f7c4a93 100644 --- a/services/db/install/changes/1.2-CHECK/06.ACL.sql +++ b/services/db/install/changes/1.2-CHECK/06.ACL.sql @@ -8,7 +8,8 @@ VALUES (109, 'UserConfig', '*', '*', 'ALLOW', 'ROLE', 'employee'), (110, 'Bank', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), (111, 'ClientLog', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), -(112, 'Defaulter', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); +(112, 'Defaulter', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), +(113, 'ClientRisk', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); UPDATE salix.ACL SET model='ItemTag', property='*', accessType='WRITE', permission='ALLOW', principalType='ROLE', principalId='marketingBoss' WHERE id=52; \ No newline at end of file diff --git a/services/loopback/common/methods/client/summary.js b/services/loopback/common/methods/client/summary.js index 04b4d85794..57d742a131 100644 --- a/services/loopback/common/methods/client/summary.js +++ b/services/loopback/common/methods/client/summary.js @@ -70,11 +70,9 @@ module.exports = Self => { } }, { - relation: 'clientsRisk', + relation: 'clientRisks', scope: { - where: {companyFk: 442}, - fields: ['amount'], - limit: 1 + fields: ['amount', 'companyFk'] } }, { diff --git a/services/loopback/common/models/client.json b/services/loopback/common/models/client.json index 007f027d58..c53b616991 100644 --- a/services/loopback/common/models/client.json +++ b/services/loopback/common/models/client.json @@ -183,7 +183,7 @@ "model": "Defaulter", "foreignKey": "clientFk" }, - "clientsRisk": { + "clientRisks": { "type": "hasMany", "model": "ClientRisk", "foreignKey": "clientFk"