diff --git a/modules/ticket/front/services/index.html b/modules/ticket/front/services/index.html
index 9f943b7a4..94ff67868 100644
--- a/modules/ticket/front/services/index.html
+++ b/modules/ticket/front/services/index.html
@@ -2,18 +2,18 @@
vn-id="model"
url="/ticket/api/TicketServices"
link="{ticketFk: $ctrl.$stateParams.id}"
- data="services"
+ data="$ctrl.services"
auto-load="true">
\ No newline at end of file
+
+
+
+
+
+ New service type
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/ticket/front/services/index.js b/modules/ticket/front/services/index.js
index b9bccd446..c576ccbda 100644
--- a/modules/ticket/front/services/index.js
+++ b/modules/ticket/front/services/index.js
@@ -1,19 +1,72 @@
import ngModule from '../module';
class Controller {
- constructor($scope, $stateParams) {
+ constructor($http, $scope, $stateParams, vnApp, $translate, $element) {
+ this.$http = $http;
this.$scope = $scope;
this.$stateParams = $stateParams;
+ this.vnApp = vnApp;
+ this.$translate = $translate;
+ this.$element = $element;
+ this.services = [];
+ }
+
+ $onInit() {
+ this.getDefaultTaxClass();
+ }
+
+ getDefaultTaxClass() {
+ let config = {params: {
+ filter: {
+ where: {
+ code: 'G'
+ }
+ }
+ }};
+
+ let query = '/api/TaxClasses/findOne';
+ this.$http.get(query, config).then(res => {
+ if (res.data)
+ this.defaultTaxClass = res.data;
+ });
}
add() {
this.$scope.model.insert({
- taxClassFk: 2,
+ taxClassFk: this.defaultTaxClass.id,
quantity: 1,
ticketFk: this.$stateParams.id
});
}
+ onNewServiceTypeOpen() {
+ this.newServiceType.name = '';
+
+ this.nameInput = this.$element[0].querySelector('.edit input');
+ this.nameInput.focus();
+ }
+
+ newServiceTypeDialog(elementIndex) {
+ this.$scope.createServiceTypeDialog.show();
+ this.currentServiceIndex = elementIndex;
+ }
+
+ onNewServiceTypeResponse(response) {
+ if (response == 'ACCEPT') {
+ try {
+ if (!this.newServiceType.name)
+ throw new Error(`Name can't be empty`);
+
+ this.$http.post(`/api/TicketServiceTypes`, this.newServiceType).then(response => {
+ this.services[this.currentServiceIndex].description = response.data.name;
+ });
+ } catch (err) {
+ this.vnApp.showError(this.$translate.instant(err.message));
+ return err;
+ }
+ }
+ }
+
onSubmit() {
this.$scope.watcher.check();
this.$scope.model.save().then(() => {
@@ -23,7 +76,7 @@ class Controller {
}
}
-Controller.$inject = ['$scope', '$stateParams'];
+Controller.$inject = ['$http', '$scope', '$stateParams', 'vnApp', '$translate', '$element'];
ngModule.component('vnTicketService', {
template: require('./index.html'),
diff --git a/modules/ticket/front/services/index.spec.js b/modules/ticket/front/services/index.spec.js
new file mode 100644
index 000000000..209459789
--- /dev/null
+++ b/modules/ticket/front/services/index.spec.js
@@ -0,0 +1,64 @@
+import './index.js';
+
+describe('Ticket component vnTicketService', () => {
+ let controller;
+ let $httpBackend;
+ let $httpParamSerializer;
+ let $scope;
+ let $element;
+
+ beforeEach(ngModule('ticket'));
+
+ beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_, $rootScope) => {
+ $element = angular.element(``);
+ $httpBackend = _$httpBackend_;
+ $httpParamSerializer = _$httpParamSerializer_;
+ $scope = $rootScope.$new();
+ controller = $componentController('vnTicketService', {$scope, $element});
+ }));
+
+ describe('getDefaultTaxClass', () => {
+ it('should set the default tax class in the controller', () => {
+ const config = {
+ filter: {
+ where: {
+ code: 'G'
+ }
+ }
+ };
+ let serializedParams = $httpParamSerializer(config);
+
+ $httpBackend.when('GET', `/api/TaxClasses/findOne?${serializedParams}`).respond({id: 4000, name: 'Whatever', code: 'GG'});
+ $httpBackend.expect('GET', `/api/TaxClasses/findOne?${serializedParams}`);
+ controller.getDefaultTaxClass();
+ $httpBackend.flush();
+
+ expect(controller.defaultTaxClass.code).toEqual('GG');
+ });
+ });
+
+ describe('onNewServiceTypeResponse', () => {
+ it(`should throw an error`, () => {
+ controller.newServiceType = {name: undefined};
+ let error = controller.onNewServiceTypeResponse('ACCEPT');
+
+ expect(error.message).toEqual(`Name can't be empty`);
+ });
+
+ it('should set the description of the selected service upon service type creation', () => {
+ controller.services = [
+ {id: 1, description: 'not too great service'}
+ ];
+
+ controller.newServiceType = {name: 'totally new stuff'};
+ controller.currentServiceIndex = 0;
+
+ $httpBackend.when('POST', '/api/TicketServiceTypes').respond({id: 4001, name: 'great service!'});
+ $httpBackend.expect('POST', '/api/TicketServiceTypes');
+ controller.onNewServiceTypeResponse('ACCEPT');
+ $httpBackend.flush();
+
+ expect(controller.services[0].description).toEqual('great service!');
+ });
+ });
+});
diff --git a/modules/ticket/front/services/locale/es.yml b/modules/ticket/front/services/locale/es.yml
index 9059c9250..08788fc09 100644
--- a/modules/ticket/front/services/locale/es.yml
+++ b/modules/ticket/front/services/locale/es.yml
@@ -1,4 +1,5 @@
Service: Servicios
Tax class: Tipo IVA
Add service: AƱadir servicio
-Remove service: Quitar servicio
\ No newline at end of file
+Remove service: Quitar servicio
+New service type: Nuevo tipo de servicio
\ No newline at end of file