#128 - Client invoices form

This commit is contained in:
Juan 2018-03-01 14:01:45 +01:00
parent 3d4ff56888
commit de145bd814
9 changed files with 103 additions and 29 deletions

View File

@ -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"
}
}
]
}

View File

@ -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';

View File

@ -1,30 +1,40 @@
<mg-ajax path="/client/api/Clients/{{index.params.id}}/listAddresses" options="mgIndex"></mg-ajax>
<vn-card margin-medium pad-large>
<vn-title>Invoices</vn-title>
<vn-grid data="invoices">
<table>
<vn-grid-header>
<vn-column-header field="ref" text="Reference" default-order="ASC"></vn-column-header>
<vn-column-header field="issued" text="Issue date"></vn-column-header>
<vn-column-header field="amount" text="Amount"></vn-column-header>
<mg-ajax path="/client/api/InvoiceOuts/filter" options="vnIndexNonAuto"></mg-ajax>
<mg-ajax path="/client/api/InvoiceOuts/{{edit.params.id}}/sumAmount" options="mgEdit"></mg-ajax>
<vn-card margin-medium>
<vn-vertical pad-large>
<vn-title margin-large-bottom>Invoices</vn-title>
<vn-vertical style="text-align: center;">
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one field="ref" text="Reference" default-order="ASC"></vn-column-header>
<vn-column-header vn-one field="issued" text="Issue date"></vn-column-header>
<vn-column-header vn-one field="dued" text="Due date"></vn-column-header>
<vn-column-header vn-one field="amount" text="Amount"></vn-column-header>
</vn-grid-header>
<tbody>
<tr ng-if="invoices.length > 0" ng-repeat="invoice in invoices track by id">
<td>{{::invoice.ref}}</td>
<td>{{::invoice.issued | date:'dd/MM/yyyy'}}</td>
<td>{{::invoice.amount | currency:'€':2}} €</td>
</tr>
<tr ng-if="!invoices || invoices.length == 0">
<td colspan="3" translate>No results</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td ng-if="$ctrl.sum > 0">{{total | currency:'€':2}}</td>
</tr>
</tfoot>
</table>
<vn-paging margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-grid>
<vn-vertical>
<vn-one
ng-if="index.model.count > 0"
class="list list-content">
<vn-horizontal
class="list list-element"
pad-small-bottom
ng-repeat="invoice in index.model.instances track by greuge.id">
<vn-one>{{::invoice.ref}}</vn-one>
<vn-one>{{::invoice.issued | date:'dd/MM/yyyy' }}</vn-one>
<vn-one>{{::invoice.dued | date:'dd/MM/yyyy' }}</vn-one>
<vn-one>{{::invoice.amount | currency:'€':2}}</vn-one>
</vn-horizontal>
</vn-one>
<vn-one
ng-if="index.model.count === 0"
pad-small-v translate>
No results
</vn-one>
</vn-vertical>
<vn-horizontal vn-one class="list list-footer">
<vn-three></vn-three>
<vn-one>{{edit.model.sumAmount | currency:'€':2}}</vn-one>
</vn-horizontal>
</vn-vertical>
<vn-paging margin-large-top vn-one index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-card>

View File

@ -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
});

View File

@ -1,4 +1,5 @@
Invoices: Facturas
Reference: Referencia
Issue date: Fecha de emisión
Due date: Vencimiento
Amount: Total

View File

@ -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,
};
}
};

View File

@ -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;
};
};

View File

@ -0,0 +1,4 @@
module.exports = function(Self) {
require('../methods/invoiceOut/filter.js')(Self);
require('../methods/invoiceOut/sumAmount.js')(Self);
};