claim regularize refactor
gitea/salix/1915-claim_regularize_fk This commit looks good
Details
gitea/salix/1915-claim_regularize_fk This commit looks good
Details
This commit is contained in:
parent
82a548edbc
commit
a1c6c0ab39
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE `vn`.`greugeConfig` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`freightPickUpPrice` DECIMAL(10,2) NOT NULL,
|
||||
PRIMARY KEY (`id`));
|
||||
|
||||
INSERT INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
|
@ -0,0 +1 @@
|
|||
INSERT INTO `vn`.`greugeType` (`id`, `name`, `code`) VALUES ('7', 'Freight Pickup ', 'freightPickUp');
|
|
@ -2,12 +2,13 @@ import ngModule from '../module';
|
|||
import './style.scss';
|
||||
|
||||
class Controller {
|
||||
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
||||
constructor($stateParams, $scope, $http, $translate, vnApp, $httpParamSerializer) {
|
||||
this.$stateParams = $stateParams;
|
||||
this.$ = $scope;
|
||||
this.$http = $http;
|
||||
this.$translate = $translate;
|
||||
this.vnApp = vnApp;
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
this.filter = {
|
||||
where: {claimFk: $stateParams.id},
|
||||
include: [
|
||||
|
@ -125,31 +126,57 @@ class Controller {
|
|||
let data = {claimFk: this.$stateParams.id};
|
||||
let query = `Claims/regularizeClaim`;
|
||||
return this.$http.post(query, data).then(() => {
|
||||
this.card.reload();
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2)
|
||||
this.$.updateGreuge.show();
|
||||
else
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
|
||||
this.card.reload();
|
||||
});
|
||||
}
|
||||
|
||||
getGreugeTypeId() {
|
||||
const params = {filter: {where: {code: 'freightPickUp'}}};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
const query = `GreugeTypes/findOne?${serializedParams}`;
|
||||
return this.$http.get(query).then(res => {
|
||||
this.greugeTypeFreightId = res.data.id;
|
||||
});
|
||||
}
|
||||
|
||||
getGreugeConfig() {
|
||||
const query = `GreugeConfigs/findOne`;
|
||||
return this.$http.get(query).then(res => {
|
||||
this.freightPickUpPrice = res.data.freightPickUpPrice;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
onUpdateGreugeResponse(response) {
|
||||
if (response !== 'accept')
|
||||
return;
|
||||
let greugeTypeFreight = 7;
|
||||
let query = `Greuges/`;
|
||||
let data = {
|
||||
clientFk: this.claim.clientFk,
|
||||
description: `claim: ${this.claim.id}`,
|
||||
amount: 11,
|
||||
greugeTypeFk: greugeTypeFreight,
|
||||
ticketFk: this.claim.ticketFk
|
||||
};
|
||||
if (response == 'accept') {
|
||||
const promises = [];
|
||||
promises.push(this.getGreugeTypeId());
|
||||
promises.push(this.getGreugeConfig());
|
||||
|
||||
this.$http.post(query, data).then(() => {
|
||||
this.card.reload();
|
||||
this.vnApp.showSuccess(this.$translate.instant('Greuge inserted!'));
|
||||
});
|
||||
Promise.all(promises).then(() => {
|
||||
const data = {
|
||||
clientFk: this.claim.clientFk,
|
||||
description: this.$translate.instant('ClaimGreugeDescription', {
|
||||
claimId: this.claim.id
|
||||
}).toUpperCase(),
|
||||
amount: this.freightPickUpPrice,
|
||||
greugeTypeFk: this.greugeTypeFreightId,
|
||||
ticketFk: this.claim.ticketFk
|
||||
};
|
||||
this.$http.post(`Greuges/`, data).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
this.vnApp.showMessage(this.$translate.instant('Greuge inserted'));
|
||||
});
|
||||
});
|
||||
} else
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
}
|
||||
|
||||
// Item Descriptor
|
||||
showDescriptor(event, itemFk) {
|
||||
this.$.descriptor.itemFk = itemFk;
|
||||
|
@ -164,6 +191,7 @@ class Controller {
|
|||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
saveMana(value) {
|
||||
let query = `Claims/${this.$stateParams.id}/updateClaimAction`;
|
||||
|
||||
|
@ -173,7 +201,7 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnClaimAction', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -6,15 +6,19 @@ describe('claim', () => {
|
|||
let controller;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
let $httpParamSerializer;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('claim'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($rootScope, $componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$scope = $rootScope.$new();
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$state = _$state_;
|
||||
$state.params.id = 1;
|
||||
|
||||
controller = $componentController('vnClaimAction', {$state});
|
||||
controller = $componentController('vnClaimAction', {$state, $scope});
|
||||
controller.claim = {ticketFk: 1};
|
||||
controller.$.model = {refresh: () => {}};
|
||||
controller.$.addSales = {
|
||||
|
@ -164,21 +168,16 @@ describe('claim', () => {
|
|||
it('should perform a insert into greuges', () => {
|
||||
spyOn(controller.card, 'reload');
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
controller.claim.clientFk = 101;
|
||||
controller.claim.id = 11;
|
||||
let data = {
|
||||
clientFk: 101,
|
||||
description: `claim: ${controller.claim.id}`,
|
||||
amount: 11,
|
||||
greugeTypeFk: 7,
|
||||
ticketFk: controller.claim.ticketFk
|
||||
};
|
||||
$httpBackend.expect('POST', `Greuges/`, data).respond();
|
||||
|
||||
const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}});
|
||||
$httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: 7});
|
||||
$httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice: 11});
|
||||
controller.onUpdateGreugeResponse('accept');
|
||||
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.card.reload).toHaveBeenCalledWith();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!');
|
||||
expect(controller.greugeTypeFreightId).toEqual(7);
|
||||
expect(controller.freightPickUpPrice).toEqual(11);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ClaimGreugeDescription: Claim id {{claimId}}
|
|
@ -8,4 +8,5 @@ Imports ticket lines: Importa las lineas de un ticket
|
|||
Regularize: Regularizar
|
||||
Do you want to insert greuges?: Desea insertar greuges?
|
||||
Insert greuges on client card: Insertar greuges en la ficha del cliente
|
||||
Greuge inserted: Greuge insertado
|
||||
Greuge inserted: Greuge insertado
|
||||
ClaimGreugeDescription: Reclamación id {{claimId}}
|
|
@ -50,6 +50,9 @@
|
|||
"GreugeType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"GreugeConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Mandate": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "GreugeConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "greugeConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"freightPickUpPrice": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"acls": [{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
}
|
|
@ -2,19 +2,22 @@
|
|||
"name": "GreugeType",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "greugeType"
|
||||
}
|
||||
"mysql": {
|
||||
"table": "greugeType"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "Number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"name": {
|
||||
"type": "String"
|
||||
}
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "Number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"name": {
|
||||
"type": "String"
|
||||
},
|
||||
"code": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
|
|
|
@ -37,7 +37,9 @@
|
|||
<vn-tbody>
|
||||
<vn-tr ng-repeat="greuge in greuges">
|
||||
<vn-td>{{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }}</vn-td>
|
||||
<vn-td>{{::greuge.description}}</vn-td>
|
||||
<vn-td>
|
||||
<span title="{{::greuge.description}}">{{::greuge.description}}</span>
|
||||
</vn-td>
|
||||
<vn-td>{{::greuge.greugeType.name}}</vn-td>
|
||||
<vn-td number>{{::greuge.amount | currency: 'EUR': 2}}</vn-td>
|
||||
</vn-tr>
|
||||
|
|
Loading…
Reference in New Issue