show grade on client summary + fix insurance datetime #375

This commit is contained in:
Joan Sanchez 2018-07-09 13:01:46 +02:00
parent e863388346
commit 10953841ec
22 changed files with 67 additions and 43 deletions

View File

@ -6,7 +6,7 @@
vn-one vn-one
label="Credit" label="Credit"
model="$ctrl.creditClassification.credit", model="$ctrl.creditClassification.credit",
rule="CreditInsurance.credit" rule="creditInsurance.credit"
step="1" step="1"
vn-focus> vn-focus>
</vn-textfield> </vn-textfield>
@ -20,7 +20,7 @@
vn-one vn-one
label="Since" label="Since"
model="$ctrl.creditClassification.started" model="$ctrl.creditClassification.started"
ini-options="{dateFormat: 'd-m-Y'}"> ini-options="{enableTime: true, dateFormat: 'd-m-Y', time_24hr: true}">
</vn-date-picker> </vn-date-picker>
</vn-horizontal> </vn-horizontal>
</vn-card> </vn-card>

View File

@ -14,7 +14,7 @@ class Controller {
submit() { submit() {
if (this.$scope.form.$invalid) if (this.$scope.form.$invalid)
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
let query = `/client/api/creditClassifications/createWithInsurance`; let query = `/client/api/creditClassifications/createWithInsurance`;
let data = this.creditClassification; let data = this.creditClassification;

View File

@ -20,7 +20,7 @@ describe('Client', () => {
describe('_getClassifications()', () => { describe('_getClassifications()', () => {
it('should perform a GET query to define the classifications property in the controller', () => { it('should perform a GET query to define the classifications property in the controller', () => {
let res = ['some classifications']; let res = ['some classifications'];
let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D'; let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22insurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D';
$httpBackend.whenGET(query).respond(res); $httpBackend.whenGET(query).respond(res);
$httpBackend.expectGET(query); $httpBackend.expectGET(query);

View File

@ -15,7 +15,7 @@
<div><vn-label translate>To</vn-label> {{classification.finished | date:'dd/MM/yyyy'}}</div> <div><vn-label translate>To</vn-label> {{classification.finished | date:'dd/MM/yyyy'}}</div>
</vn-one> </vn-one>
<vn-vertical vn-one pad-medium-h> <vn-vertical vn-one pad-medium-h>
<vn-horizontal ng-repeat="insurance in classification.creditInsurances track by insurance.id"> <vn-horizontal ng-repeat="insurance in classification.insurances track by insurance.id">
<vn-one> <vn-one>
<vn-label-value label="Credit" <vn-label-value label="Credit"
value="{{::insurance.credit}}"> value="{{::insurance.credit}}">

View File

@ -17,7 +17,7 @@ class Controller {
order: 'finished ASC, started DESC', order: 'finished ASC, started DESC',
include: [ include: [
{ {
relation: 'creditInsurances', relation: 'insurances',
scope: { scope: {
fields: ['id', 'credit', 'created', 'grade'], fields: ['id', 'credit', 'created', 'grade'],
order: 'created DESC', order: 'created DESC',

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/CreditClassifications/{{post.params.classificationId}}/creditInsurances" options="vnPost"></mg-ajax> <mg-ajax path="/client/api/CreditClassifications/{{post.params.classificationId}}/insurances" options="vnPost"></mg-ajax>
<vn-watcher <vn-watcher
vn-id="watcher" vn-id="watcher"
data="$ctrl.insurance" data="$ctrl.insurance"
@ -22,7 +22,7 @@
<vn-date-picker vn-one <vn-date-picker vn-one
label="Date" label="Date"
model="$ctrl.insurance.created" model="$ctrl.insurance.created"
ini-options="{enableTime: true, dateFormat: 'd-m-Y h:i', time_24hr: true}"> ini-options="{enableTime: true, dateFormat: 'd-m-Y', time_24hr: true}">
</vn-date-picker> </vn-date-picker>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>

View File

@ -3,7 +3,7 @@ import ngModule from '../../../module';
class Controller { class Controller {
constructor($filter) { constructor($filter) {
this.insurance = { this.insurance = {
created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm') created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss')
}; };
} }
} }

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/creditInsurances" options="vnIndex"></mg-ajax> <mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/insurances" options="vnIndex"></mg-ajax>
<vn-vertical> <vn-vertical>
<vn-card pad-large> <vn-card pad-large>
<vn-vertical> <vn-vertical>

View File

@ -199,10 +199,17 @@
<vn-label-value label="Credit" <vn-label-value label="Credit"
value="{{$ctrl.summary.credit | currency:'€ ':2}}"> value="{{$ctrl.summary.credit | currency:'€ ':2}}">
</vn-label-value> </vn-label-value>
<vn-horizontal>
<vn-one>
<vn-label-value label="Secured credit" <vn-label-value label="Secured credit"
value="{{$ctrl.summary.creditInsurance | currency:'€ ':2}}"> value="{{$ctrl.summary.creditInsurance | currency:'€ ':2}}">
</vn-label-value> </vn-label-value>
</vn-one> </vn-one>
<vn-one title="Grade">
{{$ctrl.grade ? '&nbsp;/ ' + $ctrl.grade : '&nbsp;/ - '}}
</vn-one>
</vn-horizontal>
</vn-one>
</vn-horizontal> </vn-horizontal>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>

View File

@ -11,8 +11,12 @@ class Controller {
return; return;
this.$http.get(`/client/api/Clients/${this.client.id}/summary`).then(res => { this.$http.get(`/client/api/Clients/${this.client.id}/summary`).then(res => {
if (res && res.data) if (res && res.data) {
this.summary = res.data; this.summary = res.data;
if (res.data.classifications.length)
this.grade = res.data.classifications[0].insurances[0].grade;
}
}); });
} }
} }

View File

@ -88,7 +88,7 @@ describe('Item', () => {
describe('submit()', () => { describe('submit()', () => {
it("should return an error message 'The barcode must be unique' when the code isnt unique", () => { it("should return an error message 'The barcode must be unique' when the code isnt unique", () => {
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.barcodes = [ controller.barcodes = [
{code: 123454, itemFk: 1, id: 1}, {code: 123454, itemFk: 1, id: 1},
{code: 123454, itemFk: 1} {code: 123454, itemFk: 1}
@ -96,7 +96,7 @@ describe('Item', () => {
controller.oldBarcodes = {1: {id: 1, code: 123454, itemFk: 1}}; controller.oldBarcodes = {1: {id: 1, code: 123454, itemFk: 1}};
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The barcode must be unique'); expect(controller.vnApp.showError).toHaveBeenCalledWith('The barcode must be unique');
}); });
it("should perfom a query to delete barcodes", () => { it("should perfom a query to delete barcodes", () => {
@ -131,7 +131,7 @@ describe('Item', () => {
}); });
it("should return a message 'No changes to save' when there are no changes to apply", () => { it("should return a message 'No changes to save' when there are no changes to apply", () => {
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.oldBarcodes = [ controller.oldBarcodes = [
{code: 1, itemFk: 1, id: 1}, {code: 1, itemFk: 1, id: 1},
{code: 2, itemFk: 1, id: 2} {code: 2, itemFk: 1, id: 2}
@ -139,7 +139,7 @@ describe('Item', () => {
controller.barcodes = []; controller.barcodes = [];
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
}); });
}); });
}); });

View File

@ -86,7 +86,7 @@ export default class Controller {
} }
if (repeatedBarcodes) { if (repeatedBarcodes) {
return this.vnApp.showMessage(this.$translate.instant('The barcode must be unique')); return this.vnApp.showError(this.$translate.instant('The barcode must be unique'));
} }
canSubmit = barcodesObj.update.length > 0 || barcodesObj.create.length > 0 || barcodesObj.delete.length > 0; canSubmit = barcodesObj.update.length > 0 || barcodesObj.create.length > 0 || barcodesObj.delete.length > 0;
@ -98,7 +98,7 @@ export default class Controller {
this.$scope.watcher.notifySaved(); this.$scope.watcher.notifySaved();
}); });
} }
this.vnApp.showMessage(this.$translate.instant('No changes to save')); this.vnApp.showError(this.$translate.instant('No changes to save'));
} }
setOldBarcodes(response) { setOldBarcodes(response) {

View File

@ -122,11 +122,11 @@ export default class Controller {
}); });
if (this.$scope.form.$invalid) { if (this.$scope.form.$invalid) {
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
} }
if (repeatedWarehouse) { if (repeatedWarehouse) {
return this.vnApp.showMessage(this.$translate.instant('The niche must be unique')); return this.vnApp.showError(this.$translate.instant('The niche must be unique'));
} }
canSubmit = nichesObj.update.length > 0 || nichesObj.create.length > 0 || nichesObj.delete.length > 0; canSubmit = nichesObj.update.length > 0 || nichesObj.create.length > 0 || nichesObj.delete.length > 0;
@ -138,7 +138,7 @@ export default class Controller {
this.$scope.watcher.notifySaved(); this.$scope.watcher.notifySaved();
}); });
} }
this.vnApp.showMessage(this.$translate.instant('No changes to save')); this.vnApp.showError(this.$translate.instant('No changes to save'));
} }
} }

View File

@ -98,7 +98,7 @@ describe('Item', () => {
describe('submit()', () => { describe('submit()', () => {
it("should return an error message 'The niche must be unique' when the niche warehouse isnt unique", () => { it("should return an error message 'The niche must be unique' when the niche warehouse isnt unique", () => {
controller.$scope.form = {}; controller.$scope.form = {};
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.niches = [ controller.niches = [
{warehouseFk: 1, code: 123454, itemFk: 1, id: 1}, {warehouseFk: 1, code: 123454, itemFk: 1, id: 1},
{warehouseFk: 1, code: 123454, itemFk: 1} {warehouseFk: 1, code: 123454, itemFk: 1}
@ -106,7 +106,7 @@ describe('Item', () => {
controller.oldNiches = {1: {warehouseFk: 1, id: 1, code: 123454, itemFk: 1}}; controller.oldNiches = {1: {warehouseFk: 1, id: 1, code: 123454, itemFk: 1}};
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The niche must be unique'); expect(controller.vnApp.showError).toHaveBeenCalledWith('The niche must be unique');
}); });
it("should perfom a query to delete niches", () => { it("should perfom a query to delete niches", () => {
@ -144,7 +144,7 @@ describe('Item', () => {
it("should return a message 'No changes to save' when there are no changes to apply", () => { it("should return a message 'No changes to save' when there are no changes to apply", () => {
controller.$scope.form = {$setPristine: () => {}}; controller.$scope.form = {$setPristine: () => {}};
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.oldNiches = [ controller.oldNiches = [
{warehouseFk: 1, code: 1, itemFk: 1, id: 1}, {warehouseFk: 1, code: 1, itemFk: 1, id: 1},
{warehouseFk: 2, code: 2, itemFk: 1, id: 2} {warehouseFk: 2, code: 2, itemFk: 1, id: 2}
@ -152,7 +152,7 @@ describe('Item', () => {
controller.niches = []; controller.niches = [];
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
}); });
}); });
}); });

View File

@ -132,7 +132,7 @@ describe('Item', () => {
// TODO: Server validation should be implemented // TODO: Server validation should be implemented
xit("should return an error message 'The tag must be unique' when the tag value isnt unique", () => { xit("should return an error message 'The tag must be unique' when the tag value isnt unique", () => {
controller.$.form = []; controller.$.form = [];
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.tags = [ controller.tags = [
{typeFk: 1, value: 123454, itemFk: 1, id: 1}, {typeFk: 1, value: 123454, itemFk: 1, id: 1},
{typeFk: 1, value: 123454, itemFk: 1} {typeFk: 1, value: 123454, itemFk: 1}
@ -140,7 +140,7 @@ describe('Item', () => {
controller.orgTags = {1: {typeFk: 1, id: 1, value: 123454, itemFk: 1}}; controller.orgTags = {1: {typeFk: 1, id: 1, value: 123454, itemFk: 1}};
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The tag must be unique'); expect(controller.vnApp.showError).toHaveBeenCalledWith('The tag must be unique');
}); });
it("should perfom a query to delete tags", () => { it("should perfom a query to delete tags", () => {

View File

@ -29,7 +29,7 @@ export default class Controller {
let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`; let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`;
this.$http.post(url, data).then( this.$http.post(url, data).then(
() => this.vnApp.showMessage(this._.instant('Data saved!')) () => this.vnApp.showSuccess(this._.instant('Data saved!'))
); );
} }
} }

View File

@ -106,11 +106,11 @@ class Controller {
}); });
if (this.$scope.form.$invalid) { if (this.$scope.form.$invalid) {
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
} }
if (repeatedType) { if (repeatedType) {
return this.vnApp.showMessage(this.$translate.instant('The observation type must be unique')); return this.vnApp.showError(this.$translate.instant('The observation type must be unique'));
} }
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0; canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
@ -122,7 +122,7 @@ class Controller {
this.$scope.watcher.notifySaved(); this.$scope.watcher.notifySaved();
}); });
} }
this.vnApp.showMessage(this.$translate.instant('No changes to save')); this.vnApp.showError(this.$translate.instant('No changes to save'));
} }
$onInit() { $onInit() {

View File

@ -90,7 +90,7 @@ describe('ticket', () => {
it("should return an error message 'Some fields are invalid'", () => { it("should return an error message 'Some fields are invalid'", () => {
controller.$scope.form = {}; controller.$scope.form = {};
controller.$scope.form.$invalid = true; controller.$scope.form.$invalid = true;
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.ticketObservations = [ controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}, {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
{observationTypeFk: 1, description: 'one', itemFk: 1} {observationTypeFk: 1, description: 'one', itemFk: 1}
@ -98,12 +98,12 @@ describe('ticket', () => {
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}}; controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Some fields are invalid'); expect(controller.vnApp.showError).toHaveBeenCalledWith('Some fields are invalid');
}); });
it("should return an error message 'The observation type must be unique'", () => { it("should return an error message 'The observation type must be unique'", () => {
controller.$scope.form = {}; controller.$scope.form = {};
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.ticketObservations = [ controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}, {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
{observationTypeFk: 1, description: 'one', itemFk: 1} {observationTypeFk: 1, description: 'one', itemFk: 1}
@ -111,7 +111,7 @@ describe('ticket', () => {
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}}; controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique'); expect(controller.vnApp.showError).toHaveBeenCalledWith('The observation type must be unique');
}); });
it("should perfom a query to delete observations", () => { it("should perfom a query to delete observations", () => {
@ -149,7 +149,7 @@ describe('ticket', () => {
it("should return a message 'No changes to save' when there are no changes to apply", () => { it("should return a message 'No changes to save' when there are no changes to apply", () => {
controller.$scope.form = {$setPristine: () => {}}; controller.$scope.form = {$setPristine: () => {}};
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showError').and.callThrough();
controller.oldObservations = [ controller.oldObservations = [
{id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false}, {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
{id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true} {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true}
@ -157,7 +157,7 @@ describe('ticket', () => {
controller.ticketObservations = []; controller.ticketObservations = [];
controller.submit(); controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
}); });
}); });
}); });

View File

@ -26,10 +26,10 @@ class Controller {
}); });
if (this.$.form.$invalid) if (this.$.form.$invalid)
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
if (!this.hasChanges(packagesObj)) if (!this.hasChanges(packagesObj))
return this.vnApp.showMessage(this.$translate.instant('No changes to save')); return this.vnApp.showError(this.$translate.instant('No changes to save'));
this.$http.post(query, packagesObj).then(res => { this.$http.post(query, packagesObj).then(res => {
this.$.index.accept(); this.$.index.accept();

View File

@ -33,7 +33,7 @@
"model": "Client", "model": "Client",
"foreignKey": "client" "foreignKey": "client"
}, },
"creditInsurances": { "insurances": {
"type": "hasMany", "type": "hasMany",
"model": "CreditInsurance", "model": "CreditInsurance",
"foreignKey": "creditClassification" "foreignKey": "creditClassification"

View File

@ -47,6 +47,19 @@ module.exports = Self => {
where: {isDefaultAddress: true}, where: {isDefaultAddress: true},
fields: ['nickname', 'street', 'city', 'postalCode'] fields: ['nickname', 'street', 'city', 'postalCode']
} }
},
{
relation: 'classifications',
scope: {
include: {
relation: 'insurances',
scope: {
fields: ['id', 'grade', 'created'],
order: 'created DESC'
}
},
where: {finished: null}
}
} }
], ],
where: {id: clientId} where: {id: clientId}

View File

@ -160,7 +160,7 @@
"model": "Greuge", "model": "Greuge",
"foreignKey": "clientFk" "foreignKey": "clientFk"
}, },
"creditClassifications": { "classifications": {
"type": "hasMany", "type": "hasMany",
"model": "CreditClassification", "model": "CreditClassification",
"foreignKey": "client" "foreignKey": "client"