From de145bd8148201f5dafd0a016e852090f7c03103 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Mar 2018 14:01:45 +0100 Subject: [PATCH] #128 - Client invoices form --- client/client/routes.json | 9 +++ client/client/src/client.js | 1 + client/client/src/invoices/invoices.html | 66 +++++++++++-------- client/client/src/invoices/invoices.js | 10 ++- client/client/src/invoices/locale/es.yml | 1 + .../common/methods/invoiceOut/filter.js | 14 ++++ .../common/methods/invoiceOut/sumAmount.js | 27 ++++++++ services/client/common/models/invoice-out.js | 4 ++ .../{mandateType.json => mandate-type.json} | 0 9 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 services/client/common/methods/invoiceOut/filter.js create mode 100644 services/client/common/methods/invoiceOut/sumAmount.js create mode 100644 services/client/common/models/invoice-out.js rename services/client/common/models/{mandateType.json => mandate-type.json} (100%) diff --git a/client/client/routes.json b/client/client/routes.json index a6fcb5036..7fb15d8db 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -179,6 +179,15 @@ "description": "Mandate", "icon": "pan_tool" } + }, + { + "url": "/invoices", + "state": "clientCard.invoices", + "component": "vn-client-invoices", + "menu": { + "description": "Invoices", + "icon": "insert_drive_file" + } } ] } diff --git a/client/client/src/client.js b/client/client/src/client.js index d61f4e4aa..9b4372f3b 100644 --- a/client/client/src/client.js +++ b/client/client/src/client.js @@ -19,3 +19,4 @@ import './credit-create/credit-create'; import './greuge-list/greuge-list'; import './greuge-create/greuge-create'; import './mandate/mandate'; +import './invoices/invoices'; diff --git a/client/client/src/invoices/invoices.html b/client/client/src/invoices/invoices.html index 2721605ee..95fc6ee61 100644 --- a/client/client/src/invoices/invoices.html +++ b/client/client/src/invoices/invoices.html @@ -1,30 +1,40 @@ - - - Invoices - - - - - - + + + + + Invoices + + + + + + - - - - - - - - - - - - - - - - -
{{::invoice.ref}}{{::invoice.issued | date:'dd/MM/yyyy'}}{{::invoice.amount | currency:'€':2}} €
No results
{{total | currency:'€':2}}
- -
+ + + + {{::invoice.ref}} + {{::invoice.issued | date:'dd/MM/yyyy' }} + {{::invoice.dued | date:'dd/MM/yyyy' }} + {{::invoice.amount | currency:'€':2}} + + + + No results + + + + + {{edit.model.sumAmount | currency:'€':2}} + + + +
\ No newline at end of file diff --git a/client/client/src/invoices/invoices.js b/client/client/src/invoices/invoices.js index 52764c1d3..6f1ea5df1 100644 --- a/client/client/src/invoices/invoices.js +++ b/client/client/src/invoices/invoices.js @@ -1,7 +1,15 @@ import ngModule from '../module'; import FilterClientList from '../filter-client-list'; +class Controller extends FilterClientList { + constructor($scope, $timeout, $state, $stateParams) { + super($scope, $timeout, $state); + $scope.$stateParams = $stateParams; + } +} +Controller.$inject = ['$scope', '$timeout', '$state', '$stateParams']; + ngModule.component('vnClientInvoices', { template: require('./invoices.html'), - controller: FilterClientList + controller: Controller }); diff --git a/client/client/src/invoices/locale/es.yml b/client/client/src/invoices/locale/es.yml index 316986d41..1f03f6318 100644 --- a/client/client/src/invoices/locale/es.yml +++ b/client/client/src/invoices/locale/es.yml @@ -1,4 +1,5 @@ Invoices: Facturas Reference: Referencia Issue date: Fecha de emisión +Due date: Vencimiento Amount: Total \ No newline at end of file diff --git a/services/client/common/methods/invoiceOut/filter.js b/services/client/common/methods/invoiceOut/filter.js new file mode 100644 index 000000000..0927f9b02 --- /dev/null +++ b/services/client/common/methods/invoiceOut/filter.js @@ -0,0 +1,14 @@ +module.exports = Self => { + Self.installMethod('filter', filterParams); + + function filterParams(params) { + return { + where: { + clientFk: params.clientFk + }, + skip: (params.page - 1) * params.size, + limit: params.size, + order: params.order, + }; + } +}; diff --git a/services/client/common/methods/invoiceOut/sumAmount.js b/services/client/common/methods/invoiceOut/sumAmount.js new file mode 100644 index 000000000..9f03687ff --- /dev/null +++ b/services/client/common/methods/invoiceOut/sumAmount.js @@ -0,0 +1,27 @@ +module.exports = Self => { + Self.remoteMethod('sumAmount', { + description: 'Returns the sum of invoices amount for a client', + accessType: 'READ', + accepts: [{ + arg: 'id', + description: 'The client Id', + type: 'number', + required: true, + http: {source: 'path'} + }], + returns: { + arg: 'sumAmount', + type: 'number' + }, + http: { + path: `/:id/sumAmount`, + verb: 'GET' + } + }); + + Self.sumAmount = async id => { + let query = `SELECT SUM(amount) AS sumAmount FROM vn.invoiceOut WHERE clientFk = ?`; + let result = await Self.rawSql(query, [id]); + return result[0].sumAmount; + }; +}; diff --git a/services/client/common/models/invoice-out.js b/services/client/common/models/invoice-out.js new file mode 100644 index 000000000..c4c5e0dbd --- /dev/null +++ b/services/client/common/models/invoice-out.js @@ -0,0 +1,4 @@ +module.exports = function(Self) { + require('../methods/invoiceOut/filter.js')(Self); + require('../methods/invoiceOut/sumAmount.js')(Self); +}; diff --git a/services/client/common/models/mandateType.json b/services/client/common/models/mandate-type.json similarity index 100% rename from services/client/common/models/mandateType.json rename to services/client/common/models/mandate-type.json