Merge branch '1915-claim_regularize_fk' of verdnatura/salix into dev
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
commit
472352e24c
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE `vn`.`greugeConfig` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`freightPickUpPrice` DECIMAL(10,2) NOT NULL,
|
||||
PRIMARY KEY (`id`));
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
|
@ -586,7 +586,8 @@ INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
|||
(3, 'Mana', 'mana'),
|
||||
(4, 'Reclaim', 'reclaim'),
|
||||
(5, 'Heritage', 'heritage'),
|
||||
(6, 'Miscellaneous', 'miscellaneous');
|
||||
(6, 'Miscellaneous', 'miscellaneous'),
|
||||
(7, 'Freight Pickup', 'freightPickUp');
|
||||
|
||||
INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`)
|
||||
VALUES
|
||||
|
@ -1979,3 +1980,4 @@ INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `week
|
|||
VALUES
|
||||
(1, 43200, 129600, 734400, 43200, 50400);
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
||||
|
|
|
@ -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,61 @@ 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;
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
getGreugeConfig() {
|
||||
const query = `GreugeConfigs/findOne`;
|
||||
return this.$http.get(query).then(res => {
|
||||
this.freightPickUpPrice = res.data.freightPickUpPrice;
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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!'));
|
||||
});
|
||||
return 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
|
||||
};
|
||||
return 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 +195,7 @@ class Controller {
|
|||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
saveMana(value) {
|
||||
let query = `Claims/${this.$stateParams.id}/updateClaimAction`;
|
||||
|
||||
|
@ -173,7 +205,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 = {
|
||||
|
@ -149,6 +153,8 @@ describe('claim', () => {
|
|||
});
|
||||
|
||||
describe('onUpdateGreugeResponse()', () => {
|
||||
const greugeTypeId = 7;
|
||||
const freightPickUpPrice = 11;
|
||||
it('should do nothing', () => {
|
||||
spyOn(controller.$http, 'post');
|
||||
spyOn(controller.card, 'reload');
|
||||
|
@ -161,24 +167,51 @@ describe('claim', () => {
|
|||
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!');
|
||||
});
|
||||
|
||||
it('should perform a insert into greuges', () => {
|
||||
it('should make a query and get the greugeTypeId and greuge config', () => {
|
||||
spyOn(controller.card, 'reload');
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}});
|
||||
$httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId});
|
||||
$httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice});
|
||||
controller.onUpdateGreugeResponse('accept');
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.greugeTypeFreightId).toEqual(greugeTypeId);
|
||||
expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice);
|
||||
});
|
||||
|
||||
// #1957 - Investigate how to test nested httpBackend requests
|
||||
xit('should perform a insert into greuges', () => {
|
||||
spyOn(controller.card, 'reload');
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => {
|
||||
return resolve({id: greugeTypeId});
|
||||
}));
|
||||
spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => {
|
||||
return resolve({freightPickUpPrice});
|
||||
}));
|
||||
|
||||
controller.claim.clientFk = 101;
|
||||
controller.claim.id = 11;
|
||||
let data = {
|
||||
clientFk: 101,
|
||||
description: `claim: ${controller.claim.id}`,
|
||||
amount: 11,
|
||||
greugeTypeFk: 7,
|
||||
amount: freightPickUpPrice,
|
||||
greugeTypeFk: greugeTypeId,
|
||||
ticketFk: controller.claim.ticketFk
|
||||
};
|
||||
$httpBackend.expect('POST', `Greuges/`, data).respond();
|
||||
controller.onUpdateGreugeResponse('accept');
|
||||
$httpBackend.flush();
|
||||
$httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => {
|
||||
return resolve({id: freightPickUpPrice});
|
||||
}));
|
||||
controller.onUpdateGreugeResponse('accept').then(res => {
|
||||
console.log('asdas');
|
||||
}).catch(error => {
|
||||
console.log('errorrrr!!');
|
||||
});
|
||||
|
||||
expect(controller.card.reload).toHaveBeenCalledWith();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!');
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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