Credit classification fixes #189
This commit is contained in:
parent
1dc9345bec
commit
ffde937022
|
@ -1,20 +1,28 @@
|
|||
<mg-ajax path="/client/api/clients/{{post.params.id}}/creditClassifications" options="vnPost"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.creditClassification"
|
||||
form="form"
|
||||
save="post">
|
||||
</vn-watcher>
|
||||
<form name="form" ng-submit="watcher.submitGo('clientCard.creditClassification.list')">
|
||||
<form name="form" ng-submit="$ctrl.submit()">
|
||||
<vn-card pad-large>
|
||||
<vn-title>New contract</vn-title>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
margin-medium-right
|
||||
label="Credit"
|
||||
model="$ctrl.creditClassification.credit",
|
||||
rule="CreditInsurance.credit"
|
||||
step="1"
|
||||
vn-focus>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
argin-medium-right
|
||||
label="Grade"
|
||||
model="$ctrl.creditClassification.grade"
|
||||
rule="CreditInsurance.grade">
|
||||
</vn-textfield>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="Since"
|
||||
model="$ctrl.creditClassification.started"
|
||||
ini-options="{dateFormat: 'd-m-Y'}"
|
||||
vn-focus>
|
||||
ini-options="{dateFormat: 'd-m-Y'}">
|
||||
</vn-date-picker>
|
||||
</vn-horizontal>
|
||||
</vn-card>
|
||||
|
|
|
@ -1,15 +1,33 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class Controller {
|
||||
constructor($filter, $state) {
|
||||
constructor($http, $filter, $state, $scope, $translate, vnApp) {
|
||||
this.$http = $http;
|
||||
this.$state = $state;
|
||||
this.$scope = $scope;
|
||||
this.$translate = $translate;
|
||||
this.vnApp = vnApp;
|
||||
this.creditClassification = {
|
||||
started: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
|
||||
};
|
||||
this.$state = $state;
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (this.$scope.form.$invalid)
|
||||
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid'));
|
||||
|
||||
let query = `/client/api/creditClassifications/createWithInsurance`;
|
||||
let data = this.creditClassification;
|
||||
data.clientFk = this.client.id;
|
||||
|
||||
this.$http.post(query, data).then((res, err) => {
|
||||
if (res.data)
|
||||
this.$state.go('clientCard.creditClassification.list');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$filter', '$state'];
|
||||
Controller.$inject = ['$http', '$filter', '$state', '$scope', '$translate', 'vnApp'];
|
||||
|
||||
ngModule.component('vnClientCreditClassificationCreate', {
|
||||
template: require('./credit-classification-create.html'),
|
||||
|
|
|
@ -16,16 +16,24 @@
|
|||
<div><vn-label translate>To</vn-label> {{classification.finished | date:'dd/MM/yyyy'}}</div>
|
||||
</vn-one>
|
||||
<vn-vertical vn-one pad-medium-h>
|
||||
<vn-one ng-repeat="insurance in classification.creditInsurances track by insurance.id">
|
||||
<vn-label translate>Credit</vn-label> <span>{{insurance.credit}}</span>
|
||||
<vn-horizontal ng-repeat="insurance in classification.creditInsurances track by insurance.id">
|
||||
<vn-one>
|
||||
<vn-label translate>Credit</vn-label>
|
||||
<span>{{::insurance.credit}}</span>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-label translate>Grade</vn-label>
|
||||
<span ng-if="!insurance.grade">-</span>
|
||||
<span ng-if="insurance.grade">{{insurance.grade}}</span>
|
||||
<vn-label translate>Date</vn-label> <span>{{insurance.created | date:'dd/MM/yyyy' }}</span>
|
||||
<span ng-if="insurance.grade">{{::insurance.grade}}</span>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-label translate>Date</vn-label>
|
||||
<span>{{::insurance.created | date:'dd/MM/yyyy' }}</span>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
</vn-vertical>
|
||||
<a vn-auto ui-sref="clientCard.creditInsurance.list({classificationId: {{classification.id}}})">
|
||||
<vn-icon-button icon="edit" vn-tooltip="Edit contract" tooltip-position="left"></vn-icon-button>
|
||||
<vn-icon-button icon="desktop_windows" vn-tooltip="List classifications" tooltip-position="left"></vn-icon-button>
|
||||
</a>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
|
@ -41,3 +49,9 @@
|
|||
label="Add">
|
||||
</vn-float-button>
|
||||
</vn-vertical>
|
||||
<vn-confirm
|
||||
vn-id="close-contract"
|
||||
on-response="$ctrl.returnDialog(response)"
|
||||
question="Close contract"
|
||||
message="Are you sure you want to close this contract?">
|
||||
</vn-confirm>
|
|
@ -14,6 +14,7 @@ class Controller {
|
|||
|
||||
_getClassifications(clientId) {
|
||||
let filter = {
|
||||
order: 'finished ASC, started DESC',
|
||||
include: [
|
||||
{
|
||||
relation: 'creditInsurances',
|
||||
|
@ -50,8 +51,16 @@ class Controller {
|
|||
}
|
||||
|
||||
closeContract(classification) {
|
||||
this.classificationId = classification.id;
|
||||
this.$scope.closeContract.show();
|
||||
}
|
||||
|
||||
returnDialog(response) {
|
||||
if (response === 'CANCEL')
|
||||
return;
|
||||
|
||||
let params = {finished: Date.now()};
|
||||
this.$http.patch(`/client/api/CreditClassifications/${classification.id}`, params).then(() => {
|
||||
this.$http.patch(`/client/api/CreditClassifications/${this.classificationId}`, params).then(() => {
|
||||
this._getClassifications(this.client.id);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,3 +2,5 @@ Contract credit insurance: Contratos de seguro de crédito
|
|||
New contract: Nuevo contrato
|
||||
Close contract: Cerrar contrato
|
||||
Edit contract: Modificar contrato
|
||||
List classifications: Ver clasificaciones
|
||||
Are you sure you want to close this contract?: ¿Seguro que quieres cerrar este contrato?
|
|
@ -8,7 +8,7 @@
|
|||
<form name="form"
|
||||
ng-submit="watcher.submitGo('clientCard.creditInsurance.list', {classificationId: post.params.classificationId})">
|
||||
<vn-card pad-large>
|
||||
<vn-title>New credit</vn-title>
|
||||
<vn-title>New classification</vn-title>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
|
|
|
@ -1 +1 @@
|
|||
New credit: Añadir crédito
|
||||
New classification: Nueva clasificación
|
|
@ -1,28 +1,29 @@
|
|||
<mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/creditInsurances" options="vnIndex"></mg-ajax>
|
||||
<mg-ajax path="/client/api/CreditInsurances/filter" options="vnIndexNonAuto"></mg-ajax>
|
||||
<vn-vertical>
|
||||
<vn-card pad-large>
|
||||
<vn-vertical>
|
||||
<vn-title>Requested credits</vn-title>
|
||||
<vn-grid-header>
|
||||
<vn-column-header vn-one pad-medium-h text="Amount"></vn-column-header>
|
||||
<vn-column-header vn-one pad-medium-h text="Grade"></vn-column-header>
|
||||
<vn-column-header vn-two pad-medium-h text="Date"></vn-column-header>
|
||||
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
|
||||
<vn-column-header vn-one pad-medium-h field="credit" text="Credit"></vn-column-header>
|
||||
<vn-column-header vn-one pad-medium-h field="grade" text="Grade"></vn-column-header>
|
||||
<vn-column-header vn-two pad-medium-h field="created" text="Created" default-order="DESC"></vn-column-header>
|
||||
</vn-grid-header>
|
||||
<vn-one class="list list-content">
|
||||
<vn-horizontal
|
||||
vn-one class="list list-element text-center"
|
||||
pad-small-bottom
|
||||
ng-repeat="insurance in index.model track by insurance.id">
|
||||
<vn-one pad-medium-h>{{insurance.credit}}</vn-one>
|
||||
<vn-one pad-medium-h>{{insurance.grade}}</vn-one>
|
||||
<vn-two pad-medium-h>{{insurance.created | date: 'dd/MM/yyyy'}}</vn-two>
|
||||
ng-repeat="insurance in index.model.instances track by insurance.id">
|
||||
<vn-one pad-medium-h>{{::insurance.credit}}</vn-one>
|
||||
<vn-one pad-medium-h>{{::insurance.grade}}</vn-one>
|
||||
<vn-two pad-medium-h>{{::insurance.created | date: 'dd/MM/yyyy'}}</vn-two>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
|
||||
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
|
||||
</vn-vertical>
|
||||
</vn-card>
|
||||
</vn-vertical>
|
||||
<a ui-sref="clientCard.creditInsurance.create({classificationId: {{index.params.classificationId}}})"
|
||||
fixed-bottom-right vn-tooltip="New credit" tooltip-position="left">
|
||||
fixed-bottom-right vn-tooltip="New classification" tooltip-position="left" ng-if="!$ctrl.isClosed">
|
||||
<vn-float-button icon="add"></vn-float-button>
|
||||
</a>
|
|
@ -1,12 +1,31 @@
|
|||
import ngModule from '../module';
|
||||
import FilterList from 'core/src/lib/filter-list';
|
||||
|
||||
class Controller {
|
||||
constructor($state) {
|
||||
this.classificationId = $state.params.classificationId;
|
||||
class Controller extends FilterList {
|
||||
constructor($scope, $timeout, $state, $http) {
|
||||
super($scope, $timeout, $state);
|
||||
this.modelName = 'creditClassificationFk';
|
||||
this.modelId = $state.params.classificationId;
|
||||
this.isClosed = true;
|
||||
this.$http = $http;
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
let filter = {
|
||||
fields: ['finished'],
|
||||
where: {id: this.modelId}
|
||||
};
|
||||
filter = encodeURIComponent(JSON.stringify(filter));
|
||||
|
||||
let query = `/client/api/CreditClassifications?filter=${filter}`;
|
||||
this.$http.get(query).then(res => {
|
||||
if (res.data)
|
||||
this.isClosed = res.data[0].finished != null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$state'];
|
||||
Controller.$inject = ['$scope', '$timeout', '$state', '$http'];
|
||||
|
||||
ngModule.component('vnClientCreditInsuranceList', {
|
||||
template: require('./credit-insurance-list.html'),
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
Requested credits: Créditos solicitados
|
||||
Created: Creado
|
|
@ -0,0 +1,40 @@
|
|||
module.exports = function(Self) {
|
||||
Self.remoteMethod('createWithInsurance', {
|
||||
description: 'Creates both classification and one insurance',
|
||||
accepts: {
|
||||
arg: 'data',
|
||||
type: 'object',
|
||||
http: {source: 'body'}
|
||||
},
|
||||
returns: {
|
||||
root: true,
|
||||
type: 'boolean'
|
||||
},
|
||||
http: {
|
||||
verb: 'post',
|
||||
path: '/createWithInsurance'
|
||||
}
|
||||
});
|
||||
|
||||
Self.createWithInsurance = async data => {
|
||||
let transaction = await Self.beginTransaction({});
|
||||
|
||||
try {
|
||||
let classificationSchema = {client: data.clientFk, started: data.started};
|
||||
let newClassification = await Self.create(classificationSchema, {transaction});
|
||||
let insuranceSchema = {
|
||||
creditClassification: newClassification.id,
|
||||
credit: data.credit,
|
||||
grade: data.grade
|
||||
};
|
||||
|
||||
Self.app.models.CreditInsurance.create(insuranceSchema, {transaction});
|
||||
|
||||
await transaction.commit();
|
||||
return newClassification;
|
||||
} catch (e) {
|
||||
transaction.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -4,7 +4,7 @@ module.exports = Self => {
|
|||
function filterParams(params) {
|
||||
return {
|
||||
where: {
|
||||
creditClassification: params.creditClassification
|
||||
creditClassification: params.creditClassificationFk
|
||||
},
|
||||
skip: (params.page - 1) * params.size,
|
||||
limit: params.size,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/creditClassification/createWithInsurance')(Self);
|
||||
};
|
Loading…
Reference in New Issue