client crud-model refactor #372

This commit is contained in:
Joan Sanchez 2018-07-16 08:00:04 +02:00
parent 84e61c6cdf
commit bd37f91c46
26 changed files with 398 additions and 315 deletions

View File

@ -1,8 +1,15 @@
<mg-ajax path="/client/api/Clients/{{index.params.id}}/listAddresses" options="mgIndex"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/Addresses"
filter="::$ctrl.filter"
link="{clientFk: $ctrl.$stateParams.id}"
data="addresses">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-title vn-one>Addresses</vn-title> <vn-title vn-one>Addresses</vn-title>
<vn-horizontal ng-repeat="address in index.model.items track by address.id" class="pad-medium-top" style="align-items: center;"> <vn-horizontal ng-repeat="address in addresses" class="pad-medium-top" style="align-items: center;">
<vn-one border-radius class="pad-small border-solid" <vn-one border-radius class="pad-small border-solid"
ng-class="{'bg-main': address.isDefaultAddress,'bg-opacity-item': !address.isActive && !address.isDefaultAddress}"> ng-class="{'bg-main': address.isDefaultAddress,'bg-opacity-item': !address.isActive && !address.isDefaultAddress}">
<vn-horizontal style="align-items: center;"> <vn-horizontal style="align-items: center;">
@ -56,7 +63,6 @@
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
</vn-card> </vn-card>
<vn-paging index="index" total="index.model.total"></vn-paging>
<vn-float-button <vn-float-button
vn-bind="+" vn-bind="+"
fixed-bottom-right fixed-bottom-right

View File

@ -1,20 +1,28 @@
import ngModule from '../../module'; import ngModule from '../../module';
class Controller { class Controller {
constructor($http, $scope) { constructor($http, $scope, $stateParams) {
this.$http = $http; this.$http = $http;
this.$scope = $scope; this.$scope = $scope;
this.$stateParams = $stateParams;
this.filter = {
include: {
observations: 'observationType'
},
order: ['isDefaultAddress DESC', 'isActive DESC', 'nickname ASC']
};
} }
setDefault(address) { setDefault(address) {
if (address.isActive) { if (address.isActive) {
let params = {isDefaultAddress: true}; let params = {isDefaultAddress: true};
this.$http.patch(`/client/api/Addresses/${address.id}`, params).then( this.$http.patch(`/client/api/Addresses/${address.id}`, params).then(
() => this.$scope.index.accept() () => this.$scope.model.refresh()
); );
} }
} }
} }
Controller.$inject = ['$http', '$scope']; Controller.$inject = ['$http', '$scope', '$stateParams'];
ngModule.component('vnClientAddressIndex', { ngModule.component('vnClientAddressIndex', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -19,7 +19,7 @@ describe('Client', () => {
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$scope.form = {$invalid: false}; $scope.form = {$invalid: false};
$scope.index = {accept: () => {}}; $scope.model = {refresh: () => {}};
controller = $componentController('vnClientContactIndex', {$scope: $scope}, {$state: $state}); controller = $componentController('vnClientContactIndex', {$scope: $scope}, {$state: $state});
controller.client = { controller.client = {
id: 101 id: 101
@ -70,11 +70,11 @@ describe('Client', () => {
describe('submit()', () => { describe('submit()', () => {
it("should perfom a query to delete contacts", () => { it("should perfom a query to delete contacts", () => {
controller._oldContacts = []; controller.oldContacts = [];
controller._oldContacts[1] = {id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'}; controller.oldContacts[1] = {id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'};
controller._oldContacts[2] = {id: 2, clientFk: 101, name: 'My contact 2', phone: '123456789'}; controller.oldContacts[2] = {id: 2, clientFk: 101, name: 'My contact 2', phone: '123456789'};
controller._contacts = [ controller.contacts = [
{id: 2, name: 'My contact 2', phone: '123456789'} {id: 2, name: 'My contact 2', phone: '123456789'}
]; ];
controller.removedContacts = [1]; controller.removedContacts = [1];
@ -93,11 +93,11 @@ describe('Client', () => {
}); });
it("should perfom a query to update contacts", () => { it("should perfom a query to update contacts", () => {
controller._oldContacts = []; controller.oldContacts = [];
controller._oldContacts[1] = {id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'}; controller.oldContacts[1] = {id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'};
controller._oldContacts[2] = {id: 2, clientFk: 101, name: 'My contact 2', phone: '123456789'}; controller.oldContacts[2] = {id: 2, clientFk: 101, name: 'My contact 2', phone: '123456789'};
controller._contacts = [ controller.contacts = [
{id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'}, {id: 1, clientFk: 101, name: 'My contact 1', phone: '123456789'},
{id: 2, clientFk: 101, name: 'My contact 2', phone: '111111111'} {id: 2, clientFk: 101, name: 'My contact 2', phone: '111111111'}
]; ];
@ -119,11 +119,11 @@ describe('Client', () => {
}); });
it("should perfom a query to create new contact", () => { it("should perfom a query to create new contact", () => {
controller._oldContacts = []; controller.oldContacts = [];
controller._oldContacts[1] = {id: 1, name: 'My contact 1', phone: '123456789'}; controller.oldContacts[1] = {id: 1, name: 'My contact 1', phone: '123456789'};
controller._oldContacts[2] = {id: 2, name: 'My contact 2', phone: '123456789'}; controller.oldContacts[2] = {id: 2, name: 'My contact 2', phone: '123456789'};
controller._contacts = [ controller.contacts = [
{id: 1, name: 'My contact 1', phone: '123456789'}, {id: 1, name: 'My contact 1', phone: '123456789'},
{id: 2, name: 'My contact 2', phone: '123456789'}, {id: 2, name: 'My contact 2', phone: '123456789'},
{name: 'My contact 3', phone: '123456789'} {name: 'My contact 3', phone: '123456789'}

View File

@ -1,12 +1,14 @@
<mg-ajax <vn-crud-model
path="/client/api/Clients/{{index.params.id}}/contacts" vn-id="model"
options="mgIndex" url="/client/api/ClientContacts"
actions="$ctrl.contacts = index.model"> link="{clientFk: $ctrl.$stateParams.id}"
</mg-ajax> data="contacts" on-data-change="$ctrl.onDataChange()">
</vn-crud-model>
<form name="form" ng-submit="$ctrl.submit()"> <form name="form" ng-submit="$ctrl.submit()">
<vn-card pad-large> <vn-card pad-large>
<vn-title>Contacts</vn-title> <vn-title>Contacts</vn-title>
<vn-horizontal ng-repeat="contact in index.model track by $index"> <vn-horizontal ng-repeat="contact in contacts">
<vn-textfield <vn-textfield
vn-one vn-one
label="Name" label="Name"

View File

@ -1,25 +1,18 @@
import ngModule from '../module'; import ngModule from '../module';
class Controller { class Controller {
constructor($http, $scope, $translate, vnApp) { constructor($http, $scope, $stateParams, $translate, vnApp) {
this.$http = $http; this.$http = $http;
this.$scope = $scope; this.$scope = $scope;
this.$stateParams = $stateParams;
this.$translate = $translate; this.$translate = $translate;
this.vnApp = vnApp; this.vnApp = vnApp;
this.removedContacts = []; this.removedContacts = [];
} }
/** onDataChange() {
* Setter for contacts and original contacts this.contacts = this.$scope.model.data;
* @param {Object} value - Contacts object this.oldContacts = this.$scope.model.data;
*/
set contacts(value) {
this._contacts = value;
this.oldContacts = value;
}
get contacts() {
return this._contacts;
} }
/** /**
@ -64,7 +57,7 @@ class Controller {
this.$http.post(query, data).then(() => { this.$http.post(query, data).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$scope.index.accept(); this.$scope.model.refresh();
}); });
} }
@ -85,7 +78,7 @@ class Controller {
add() { add() {
let data = { let data = {
clientFk: this.client.id, clientFk: this.client.id,
name: 'Teléfono', name: this.$translate.instant('Phone'),
phone: null phone: null
}; };
this.contacts.push(data); this.contacts.push(data);
@ -115,7 +108,7 @@ class Controller {
} }
} }
Controller.$inject = ['$http', '$scope', '$translate', 'vnApp']; Controller.$inject = ['$http', '$scope', '$stateParams', '$translate', 'vnApp'];
ngModule.component('vnClientContactIndex', { ngModule.component('vnClientContactIndex', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -12,10 +12,10 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_; $componentController = _$componentController_;
let $state = {params: {classificationId: 1}}; let $stateParams = {classificationId: 1};
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClientCreditInsuranceInsuranceIndex', {$state: $state}); controller = $componentController('vnClientCreditInsuranceInsuranceIndex', {$stateParams: $stateParams});
})); }));
it('should perform a query to GET credit the credit classification', () => { it('should perform a query to GET credit the credit classification', () => {

View File

@ -1,28 +1,39 @@
<mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/insurances" options="vnIndex"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/CreditInsurances"
link="{creditClassification: $ctrl.$stateParams.classificationId}"
limit="20"
data="insurances">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Requested credits</vn-title> <vn-title>Requested credits</vn-title>
<table class="vn-grid"> <vn-table model="model">
<thead> <vn-thead>
<tr> <vn-tr>
<th number translate>Credit</th> <vn-th number>Credit</vn-th>
<th number translate>Grade</th> <vn-th number>Grade</vn-th>
<th translate>Created</th> <vn-th>Created</vn-th>
</tr> </vn-tr>
</thead> </vn-thead>
<tbody> <vn-tbody>
<tr ng-repeat="insurance in index.model track by insurance.id" class="list list-element"> <vn-tr ng-repeat="insurance in insurances">
<td number>{{::insurance.credit | currency: '€': 2}}</td> <vn-td number>{{::insurance.credit | currency: ' €': 2}}</vn-td>
<td number>{{::insurance.grade}}</td> <vn-td number>{{::insurance.grade}}</vn-td>
<td>{{::insurance.created | date: 'dd/MM/yyyy'}}</td> <vn-td>{{::insurance.created | date: 'dd/MM/yyyy'}}</vn-td>
</tr> </vn-tr>
<tr ng-if="index.model.count === 0" class="list list-element"> </vn-tbody>
<td colspan="6" style="text-align: center" translate>No results</td> <vn-empty-rows ng-if="model.data.length === 0" translate>
</tr> No results
</tbody> </vn-empty-rows>
</table> </vn-table>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<button <button
@ -30,9 +41,8 @@
translate translate
ui-sref="client.card.creditInsurance.index">Back</button> ui-sref="client.card.creditInsurance.index">Back</button>
</vn-button-bar> </vn-button-bar>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>
<a ui-sref="client.card.creditInsurance.insurance.create({classificationId: {{index.params.classificationId}}})" <a ui-sref="client.card.creditInsurance.insurance.create({classificationId: {{$ctrl.$stateParams.classificationId}}})"
fixed-bottom-right vn-tooltip="New credit" vn-bind="+" ng-if="!$ctrl.isClosed"> fixed-bottom-right vn-tooltip="New credit" vn-bind="+" ng-if="!$ctrl.isClosed">
<vn-float-button icon="add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>
</a> </a>

View File

@ -1,19 +1,21 @@
import ngModule from '../../../module'; import ngModule from '../../../module';
import FilterList from 'core/src/lib/filter-list';
class Controller extends FilterList { class Controller {
constructor($scope, $timeout, $state, $http) { constructor($stateParams, $http) {
super($scope, $timeout, $state); this.$stateParams = $stateParams;
this.modelName = 'creditClassificationFk';
this.modelId = $state.params.classificationId;
this.isClosed = true;
this.$http = $http; this.$http = $http;
this.isClosed = true;
this.filter = {
include: [
{relation: 'classification'}
]
};
} }
$onInit() { $onInit() {
let filter = { let filter = {
fields: ['finished'], fields: ['finished'],
where: {id: this.modelId} where: {id: this.$stateParams.classificationId}
}; };
filter = encodeURIComponent(JSON.stringify(filter)); filter = encodeURIComponent(JSON.stringify(filter));
@ -25,7 +27,7 @@ class Controller extends FilterList {
} }
} }
Controller.$inject = ['$scope', '$timeout', '$state', '$http']; Controller.$inject = ['$stateParams', '$http'];
ngModule.component('vnClientCreditInsuranceInsuranceIndex', { ngModule.component('vnClientCreditInsuranceInsuranceIndex', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,28 +1,41 @@
<mg-ajax path="/client/api/ClientCredits/filter" options="vnIndexNonAuto"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/ClientCredits"
filter="::$ctrl.filter"
link="{clientFk: $ctrl.$stateParams.id}"
limit="20"
data="credits">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Credit</vn-title> <vn-title>Credit</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)"> <vn-table model="model">
<vn-column-header vn-one pad-medium-h field="amount" text="Credit"></vn-column-header> <vn-thead>
<vn-column-header vn-two pad-medium-h field="created" text="Since" default-order="ASC"></vn-column-header> <vn-tr>
<vn-column-header vn-two pad-medium-h field="worker.firstName" text="Employee" order-locked></vn-column-header> <vn-th field="amount">Credit</vn-th>
</vn-grid-header> <vn-th field="created" default-order="DESC">Since</vn-th>
<vn-one class="list list-content"> <vn-th>Employee</vn-th>
<vn-horizontal </vn-tr>
vn-one class="list list-element text-center" </vn-thead>
pad-small-bottom <vn-tbody>
ng-repeat="credit in index.model.instances track by credit.id"> <vn-tr ng-repeat="credit in credits track by credit.id">
<vn-one pad-medium-h>{{::credit.amount | number:2}} €</vn-one> <vn-td>{{::credit.amount | number:2}} €</vn-td>
<vn-two pad-medium-h>{{::credit.created | date:'dd/MM/yyyy HH:mm'}}</vn-two> <vn-td>{{::credit.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-two pad-medium-h>{{::credit.worker.firstName}} {{::credit.worker.name}}</vn-two> <vn-td>{{::credit.worker.firstName}} {{::credit.worker.name}}</vn-td>
</vn-horizontal> </vn-tr>
</vn-one> </vn-tbody>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one> <vn-empty-rows ng-if="model.data.length === 0" translate>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal> No results
</vn-empty-rows>
</vn-table>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>
<a ui-sref="client.card.credit.create" vn-bind="+" fixed-bottom-right> <a ui-sref="client.card.credit.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>

View File

@ -1,7 +1,24 @@
import ngModule from '../../module'; import ngModule from '../../module';
import FilterClientList from '../../filter-client-list';
class Controller {
constructor($stateParams) {
this.$stateParams = $stateParams;
this.filter = {
include: [
{
relation: 'worker',
scope: {
fields: ['firstName', 'name']
}
}
]
};
}
}
Controller.$inject = ['$stateParams'];
ngModule.component('vnClientCreditIndex', { ngModule.component('vnClientCreditIndex', {
template: require('./index.html'), template: require('./index.html'),
controller: FilterClientList controller: Controller
}); });

View File

@ -1,36 +1,58 @@
<mg-ajax path="/client/api/greuges/filter" options="vnIndexNonAuto"></mg-ajax> <vn-crud-model
<mg-ajax path="/client/api/greuges/{{edit.params.id}}/sumAmount" options="mgEdit"></mg-ajax> vn-id="model"
url="/client/api/greuges"
filter="::$ctrl.filter"
link="{clientFk: $ctrl.$stateParams.id}"
limit="20"
data="greuges">
</vn-crud-model>
<mg-ajax
path="/client/api/greuges/{{$ctrl.$stateParams.id}}/sumAmount"
options="mgEdit">
</mg-ajax>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Greuge</vn-title> <vn-title>Greuge</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)"> <vn-table model="model">
<vn-column-header vn-one pad-medium-h field="shipped" text="Date" default-order="ASC"></vn-column-header> <vn-thead>
<vn-column-header vn-two pad-medium-h field="description" text="Comment"></vn-column-header> <vn-tr>
<vn-column-header vn-one pad-medium-h field="amount" text="Amount"></vn-column-header> <vn-th field="shipped" default-order="DESC">Date</vn-th>
<vn-column-header vn-one pad-medium-h field="greugeTypeFk" text="Type"></vn-column-header> <vn-th field="description">Comment</vn-th>
</vn-grid-header> <vn-th field="amount">Amount</vn-th>
<vn-one class="list list-content"> <vn-th field="greugeTypeFk">Type</vn-th>
<vn-horizontal </vn-tr>
class="list list-element text-center" </vn-thead>
pad-small-bottom <vn-tbody>
ng-repeat="greuge in index.model.instances track by greuge.id"> <vn-tr ng-repeat="greuge in greuges">
<vn-one pad-medium-h>{{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }}</vn-one> <vn-td>{{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }}</vn-td>
<vn-two pad-medium-h>{{::greuge.description}}</vn-two> <vn-td>{{::greuge.description}}</vn-td>
<vn-one pad-medium-h>{{::greuge.amount | number:2}} €</vn-one> <vn-td>{{::greuge.amount | currency: ' €': 2}}</vn-td>
<vn-one pad-medium-h>{{::greuge.greugeType.name}}</vn-one> <vn-td>{{::greuge.greugeType.name}}</vn-td>
</vn-horizontal> </vn-tr>
</vn-one> </vn-tbody>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one> <vn-empty-rows ng-if="model.data.length === 0" translate>
<vn-horizontal vn-one class="list list-footer text-center"> No results
<vn-one pad-medium-h></vn-one> </vn-empty-rows>
<vn-two pad-medium-h></vn-two> <vn-tfoot ng-if="model.data.length > 0">
<vn-one pad-medium-h ng-if="index.model.count > 0">{{edit.model.sumAmount | number:2}} €</vn-one> <vn-tr>
<vn-one pad-medium-h></vn-one> <vn-td></vn-td>
</vn-horizontal> <vn-td></vn-td>
<vn-td>
<strong>{{edit.model.sumAmount | currency: ' €': 2}}</strong>
</vn-td>
<vn-td></vn-td>
</vn-tr>
</vn-tfoot>
</vn-table>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-paging margin-large-top vn-one index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>
<a ui-sref="client.card.greuge.create" vn-bind="+" fixed-bottom-right> <a ui-sref="client.card.greuge.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>

View File

@ -1,7 +1,24 @@
import ngModule from '../../module'; import ngModule from '../../module';
import FilterClientList from '../../filter-client-list';
class Controller {
constructor($stateParams) {
this.$stateParams = $stateParams;
this.filter = {
include: [
{
relation: "greugeType",
scope: {
fields: ["id", "name"]
}
}
]
};
}
}
Controller.$inject = ['$stateParams'];
ngModule.component('vnClientGreugeIndex', { ngModule.component('vnClientGreugeIndex', {
template: require('./index.html'), template: require('./index.html'),
controller: FilterClientList controller: Controller
}); });

View File

@ -1,34 +1,42 @@
<mg-ajax path="/client/api/InvoiceOuts/filter" options="vnIndexNonAuto"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/InvoiceOuts"
filter="{}"
link="{clientFk: $ctrl.$stateParams.id}"
limit="20"
data="invoices">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Invoices</vn-title> <vn-title>Invoices</vn-title>
<vn-vertical style="text-align: center;"> <vn-table model="model">
<vn-grid-header on-order="$ctrl.onOrder(field, order)"> <vn-thead>
<vn-column-header vn-one field="ref" text="Reference" default-order="ASC"></vn-column-header> <vn-tr>
<vn-column-header vn-one field="issued" text="Issue date"></vn-column-header> <vn-th field="ref" default-order="DESC">Reference</vn-th>
<vn-column-header vn-one field="dued" text="Due date"></vn-column-header> <vn-th field="issued">Issue date</vn-th>
<vn-column-header vn-one field="amount" text="Amount"></vn-column-header> <vn-th field="dued">Due date</vn-th>
</vn-grid-header> <vn-th field="amount">Amount</vn-th>
<vn-vertical>
<vn-one </vn-tr>
ng-if="index.model.count > 0" </vn-thead>
class="list list-content"> <vn-tbody>
<vn-horizontal <vn-tr ng-repeat="invoice in invoices">
class="list list-element" <vn-td>{{::invoice.ref}}</vn-td>
pad-small-bottom <vn-td>{{::invoice.issued | date:'dd/MM/yyyy' }}</vn-td>
ng-repeat="invoice in index.model.instances track by invoice.id"> <vn-td>{{::invoice.dued | date:'dd/MM/yyyy' }}</vn-td>
<vn-one>{{::invoice.ref}}</vn-one> <vn-td>{{::invoice.amount | currency:' €': 2}}</vn-td>
<vn-one>{{::invoice.issued | date:'dd/MM/yyyy' }}</vn-one> </vn-tr>
<vn-one>{{::invoice.dued | date:'dd/MM/yyyy' }}</vn-one> </vn-tbody>
<vn-one>{{::invoice.amount | currency:'€':2}}</vn-one> <vn-empty-rows ng-if="model.data.length === 0" translate>
</vn-horizontal> No results
</vn-one> </vn-empty-rows>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one> </vn-table>
</vn-vertical>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
</vn-vertical>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-paging margin-large-top vn-one index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>

View File

@ -1,13 +1,12 @@
import ngModule from '../module'; import ngModule from '../module';
import FilterClientList from '../filter-client-list';
class Controller extends FilterClientList { class Controller {
constructor($scope, $timeout, $state, $stateParams) { constructor($stateParams) {
super($scope, $timeout, $state); this.$stateParams = $stateParams;
$scope.$stateParams = $stateParams;
} }
} }
Controller.$inject = ['$scope', '$timeout', '$state', '$stateParams'];
Controller.$inject = ['$stateParams'];
ngModule.component('vnClientInvoice', { ngModule.component('vnClientInvoice', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,30 +1,43 @@
<mg-ajax path="/client/api/Mandates/filter" options="vnIndexNonAuto"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/Mandates"
filter="::$ctrl.filter"
link="{clientFk: $ctrl.$stateParams.id}"
limit="20"
data="mandates">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Mandate</vn-title> <vn-title>Mandate</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)"> <vn-table model="model">
<vn-column-header vn-one pad-medium-h field="id" text="Id"></vn-column-header> <vn-thead>
<vn-column-header vn-one pad-medium-h field="companyFk" text="Company"></vn-column-header> <vn-tr>
<vn-column-header vn-one pad-medium-h field="mandateTypeFk" text="Type"></vn-column-header> <vn-th field="id">Id</vn-th>
<vn-column-header vn-one pad-medium-h field="created" text="Register date" default-order="ASC"></vn-column-header> <vn-th field="companyFk">Company</vn-th>
<vn-column-header vn-one pad-medium-h field="finished" text="End date"></vn-column-header> <vn-th field="mandateTypeFk">Type</vn-th>
</vn-grid-header> <vn-th field="created" default-order="DESC">Register date</vn-th>
<vn-one class="list list-content"> <vn-th field="finished">End date</vn-th>
<vn-horizontal </vn-tr>
vn-one class="list list-element text-center" </vn-thead>
pad-small-bottom <vn-tbody>
ng-repeat="mandate in index.model.instances track by mandate.id"> <vn-tr ng-repeat="mandate in mandates">
<vn-one pad-medium-h>{{::mandate.id}}</vn-one> <vn-td>{{::mandate.id}}</vn-td>
<vn-one pad-medium-h>{{::mandate.company.code}}</vn-one> <vn-td>{{::mandate.company.code}}</vn-td>
<vn-one pad-medium-h>{{::mandate.mandateType.name}}</vn-one> <vn-td>{{::mandate.mandateType.name}}</vn-td>
<vn-one pad-medium-h>{{::mandate.created | date:'dd/MM/yyyy HH:mm' }}</vn-one> <vn-td>{{::mandate.created | date:'dd/MM/yyyy HH:mm' }}</vn-td>
<vn-one pad-medium-h>{{::mandate.finished | date:'dd/MM/yyyy HH:mm' || '-'}}</vn-one> <vn-td>{{::mandate.finished | date:'dd/MM/yyyy HH:mm' || '-'}}</vn-td>
</vn-horizontal> </vn-tr>
</vn-one> </vn-tbody>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one> <vn-empty-rows ng-if="model.data.length === 0" translate>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal> No results
</vn-empty-rows>
</vn-table>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>

View File

@ -1,7 +1,30 @@
import ngModule from '../module'; import ngModule from '../module';
import FilterClientList from '../filter-client-list';
class Controller {
constructor($stateParams) {
this.$stateParams = $stateParams;
this.filter = {
include: [
{
relation: "mandateType",
scope: {
fields: ["id", "name"]
}
},
{
relation: "company",
scope: {
fields: ["id", "code"]
}
}
]
};
}
}
Controller.$inject = ['$stateParams'];
ngModule.component('vnClientMandate', { ngModule.component('vnClientMandate', {
template: require('./index.html'), template: require('./index.html'),
controller: FilterClientList controller: Controller
}); });

View File

@ -1,25 +1,31 @@
<vn-crud-model
vn-id="model"
url="/client/api/clientObservations"
filter="{order: 'created DESC'}"
link="{clientFk: $ctrl.$stateParams.id}"
data="notes">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card ng-show="$ctrl.observations.length" pad-large> <vn-card pad-large>
<vn-title>Notes</vn-title> <vn-title>Notes</vn-title>
<vn-vertical <vn-vertical
ng-repeat="n in $ctrl.observations" ng-repeat="note in notes"
pad-small pad-small
border-solid border-solid
border-radius border-radius
margin-small-bottom> margin-small-bottom>
<vn-horizontal margin-small-bottom style="color: #666"> <vn-horizontal margin-small-bottom style="color: #666">
<vn-one>{{::n.worker.firstName}} {{::n.worker.name}}</vn-one> <vn-one>{{::note.worker.firstName}} {{::note.worker.name}}</vn-one>
<vn-auto>{{::n.created | date:'dd/MM/yyyy HH:mm'}}</vn-auto> <vn-auto>{{::note.created | date:'dd/MM/yyyy HH:mm'}}</vn-auto>
</vn-horizontal> </vn-horizontal>
<vn-horizontal class="text"> <vn-horizontal class="text">
{{::n.text}} {{::note.text}}
</vn-horizontal> </vn-horizontal>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>
</vn-vertical> </vn-vertical>
<vn-float-button
fixed-bottom-right <a ui-sref="client.card.note.create({id: $ctrl.$stateParams.id})" vn-bind="+" fixed-bottom-right>
ng-click="$ctrl.newObservation()" <vn-float-button icon="add"></vn-float-button>
vn-bind="+" </a>
icon="add">
</vn-float-button>

View File

@ -1,31 +1,12 @@
import ngModule from '../../module'; import ngModule from '../../module';
export default class Controller { export default class Controller {
constructor($http, $state) { constructor($stateParams) {
this.$http = $http; this.$stateParams = $stateParams;
this.$state = $state;
}
$onChanges() {
if (this.client) {
this.getObservation(this.client.id);
}
}
getObservation(clientId) {
let json = JSON.stringify({where: {clientFk: this.client.id}, order: 'created DESC'});
this.$http.get(`/client/api/clientObservations?filter=${json}`).then(
json => {
this.observations = json.data;
}
);
}
newObservation() {
this.$state.go("client.card.note.create", {id: this.client.id});
} }
} }
Controller.$inject = ['$http', '$state'];
Controller.$inject = ['$stateParams'];
ngModule.component('vnClientNote', { ngModule.component('vnClientNote', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,58 +0,0 @@
import './index';
describe('Client', () => {
describe('Component vnClientNote', () => {
let $componentController;
let $state;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClientNote', {$state: $state});
}));
describe('$onChanges()', () => {
it(`should call getObservation() with the client id`, () => {
controller.client = {
id: 1234
};
spyOn(controller, 'getObservation').and.returnValue();
controller.$onChanges();
expect(controller.getObservation).toHaveBeenCalledWith(1234);
});
});
describe('$getObservation()', () => {
it(`should request to GET the client notes`, () => {
controller.client = {id: '1234'};
let jsonString = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
let json = {data: 'some data'};
$httpBackend.when('GET', `/client/api/clientObservations?filter=${jsonString}`).respond(json);
$httpBackend.expectGET(`/client/api/clientObservations?filter=${jsonString}`, {Accept: 'application/json, text/plain, */*'});
controller.getObservation();
$httpBackend.flush();
expect(controller.observations).toEqual(json);
});
});
describe('$newObservation()', () => {
it(`should redirect the user to the newObservation view`, () => {
controller.client = {id: '1234'};
spyOn(controller.$state, 'go');
controller.newObservation();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.note.create', Object({id: '1234'}));
});
});
});
});

View File

@ -1,36 +1,53 @@
<mg-ajax path="/client/api/Recoveries/filter" options="vnIndexNonAuto"></mg-ajax> <vn-crud-model
vn-id="model"
url="/client/api/Recoveries"
filter="{}"
link="{clientFk: $ctrl.$stateParams.id}"
limit="20"
data="recoveries">
</vn-crud-model>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>
<vn-title>Recovery</vn-title> <vn-title>Recovery</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)"> <vn-table model="model">
<vn-column-header vn-one pad-medium-h field="started" text="Since" default-order="ASC"></vn-column-header> <vn-thead>
<vn-column-header vn-one pad-medium-h field="finished" text="To"></vn-column-header> <vn-tr>
<vn-column-header vn-one pad-medium-h field="amount" text="Amount"></vn-column-header> <vn-th></vn-th>
<vn-column-header vn-one pad-medium-h field="period" text="Period"></vn-column-header> <vn-th field="started" default-order="DESC">Since</vn-th>
</vn-grid-header> <vn-th field="finished">To</vn-th>
<vn-one class="list list-content"> <vn-th field="amount">Amount</vn-th>
<vn-horizontal <vn-th field="period">Period</vn-th>
vn-one class="list list-element text-center" </vn-tr>
pad-small-bottom </vn-thead>
ng-repeat="recovery in index.model.instances track by $index"> <vn-tbody>
<vn-none pad-medium-h orange> <vn-tr ng-repeat="recovery in recoveries">
<i class="material-icons pointer" <vn-td>
<vn-icon
class="bright pointer"
icon="lock"
vn-tooltip="Finish that recovery period" vn-tooltip="Finish that recovery period"
ng-if="!recovery.finished" ng-if="!recovery.finished"
ng-click="$ctrl.setFinished(recovery)">lock</i> ng-click="$ctrl.setFinished(recovery)">
</vn-none> </vn-icon>
<vn-one pad-medium-h>{{::recovery.started | date:'dd/MM/yyyy' }}</vn-one> </vn-td>
<vn-one pad-medium-h>{{recovery.finished | date:'dd/MM/yyyy' }}</vn-one> <vn-td>{{::recovery.started | date:'dd/MM/yyyy' }}</vn-td>
<vn-one pad-medium-h>{{::recovery.amount | currency:'€':0}}</vn-one> <vn-td>{{recovery.finished | date:'dd/MM/yyyy' }}</vn-td>
<vn-one pad-medium-h>{{::recovery.period}}</vn-one> <vn-td>{{::recovery.amount | currency:' €': 0}}</vn-td>
</vn-horizontal> <vn-td>{{::recovery.period}}</vn-td>
</vn-one> </vn-tr>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one> </vn-tbody>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal> <vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-vertical> </vn-vertical>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</vn-card> </vn-card>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical> </vn-vertical>
<a ui-sref="client.card.recovery.create" vn-bind="+" fixed-bottom-right> <a ui-sref="client.card.recovery.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>

View File

@ -1,22 +1,23 @@
import ngModule from '../../module'; import ngModule from '../../module';
import FilterClientList from '../../filter-client-list';
class Controller extends FilterClientList { class Controller {
constructor($scope, $timeout, $state, $http) { constructor($stateParams, $scope, $http) {
super($scope, $timeout, $state); this.$stateParams = $stateParams;
this.$scope = $scope;
this.$http = $http; this.$http = $http;
} }
setFinished(recovery) { setFinished(recovery) {
if (!recovery.finished) { if (!recovery.finished) {
let params = {finished: Date.now()}; let params = {finished: Date.now()};
this.$http.patch(`/client/api/Recoveries/${recovery.id}`, params).then( this.$http.patch(`/client/api/Recoveries/${recovery.id}`, params).then(
() => this.$.index.accept() () => this.$scope.model.refresh()
); );
} }
} }
} }
Controller.$inject = ['$scope', '$timeout', '$state', '$http']; Controller.$inject = ['$stateParams', '$scope', '$http'];
ngModule.component('vnClientRecoveryIndex', { ngModule.component('vnClientRecoveryIndex', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -18,15 +18,17 @@ export default class Table {
this.order = order; this.order = order;
} }
applyFilter(field = this.field, order = this.order) { applyOrder(field = this.field, order = this.order) {
this.model.filter.order = `${field} ${order}`; if (!field) return;
this.model.order = `${field} ${order}`;
this.model.refresh(); this.model.refresh();
this.setActiveArrow(); this.setActiveArrow();
} }
$onChanges() { $onChanges() {
if (this.model && this.model.filter) if (this.model && this.model.filter)
this.applyFilter(); this.applyOrder();
} }
setActiveArrow() { setActiveArrow() {

View File

@ -78,6 +78,7 @@ vn-table {
} }
vn-td, vn-th { vn-td, vn-th {
vertical-align: middle;
display: table-cell; display: table-cell;
text-align: left; text-align: left;
padding: 10px; padding: 10px;

View File

@ -57,7 +57,7 @@ export default class Th {
this.updateArrow(); this.updateArrow();
this.table.applyFilter(this.field, this.order); this.table.applyOrder(this.field, this.order);
} }
/** /**

View File

@ -132,7 +132,7 @@ export default {
addCreditFloatButton: `${components.vnFloatButton}`, addCreditFloatButton: `${components.vnFloatButton}`,
creditInput: `${components.vnTextfield}[name="credit"]`, creditInput: `${components.vnTextfield}[name="credit"]`,
saveButton: `${components.vnSubmit}`, saveButton: `${components.vnSubmit}`,
firstCreditText: 'vn-client-credit-index .list-element' firstCreditText: 'vn-client-credit-index vn-card > div vn-table vn-tbody > vn-tr'
}, },
clientGreuge: { clientGreuge: {
greugeButton: `vn-menu-item a[ui-sref="client.card.greuge.index"]`, greugeButton: `vn-menu-item a[ui-sref="client.card.greuge.index"]`,
@ -142,15 +142,15 @@ export default {
typeInput: `vn-autocomplete[field="$ctrl.greuge.greugeTypeFk"] input`, typeInput: `vn-autocomplete[field="$ctrl.greuge.greugeTypeFk"] input`,
typeSecondOption: `vn-autocomplete[field="$ctrl.greuge.greugeTypeFk"] vn-drop-down ul > li`, typeSecondOption: `vn-autocomplete[field="$ctrl.greuge.greugeTypeFk"] vn-drop-down ul > li`,
saveButton: `${components.vnSubmit}`, saveButton: `${components.vnSubmit}`,
firstGreugeText: 'vn-client-greuge-index .list-element' firstGreugeText: 'vn-client-greuge-index vn-card > div vn-table vn-tbody > vn-tr'
}, },
clientMandate: { clientMandate: {
mandateButton: `vn-menu-item a[ui-sref="client.card.mandate"]`, mandateButton: `vn-menu-item a[ui-sref="client.card.mandate"]`,
firstMandateText: 'vn-client-mandate .list-element' firstMandateText: 'vn-client-mandate vn-card > div vn-table vn-tbody > vn-tr'
}, },
clientInvoices: { clientInvoices: {
invoicesButton: `vn-menu-item a[ui-sref="client.card.invoice"]`, invoicesButton: `vn-menu-item a[ui-sref="client.card.invoice"]`,
firstInvoiceText: 'vn-client-invoice .list-element' firstInvoiceText: 'vn-client-invoice vn-card > div vn-table vn-tbody > vn-tr'
}, },
itemsIndex: { itemsIndex: {
createItemButton: `${components.vnFloatButton}`, createItemButton: `${components.vnFloatButton}`,

View File

@ -3,7 +3,7 @@
"title": "Changement des C.G.V", "title": "Changement des C.G.V",
"dear": "Chèr client,", "dear": "Chèr client,",
"bodyDescription": "Nous vous informons que les conditions de paiement ont changé. Voici les nouvelles conditions:", "bodyDescription": "Nous vous informons que les conditions de paiement ont changé. Voici les nouvelles conditions:",
"paymentMethod": "Méthod de paiement:", "paymentMethod": "Méthode de paiement:",
"paymentDay": "Date paiement:", "paymentDay": "Date paiement:",
"everyMonth": "de chaque mois", "everyMonth": "de chaque mois",
"cardPaymentAdvice": "Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.", "cardPaymentAdvice": "Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.",