Commit 570d9fce9b555939a331e6de6755408db322c373

Authored by Jose Pinto
Exists in master

Merge remote-tracking branch 'upstream/develop'

spec/controllerSpec.js
... ... @@ -25,6 +25,7 @@ describe('Controladores abm precios condiciones', function() {
25 25 focaAbmPreciosCondicionesService: {},
26 26 $location: {},
27 27 focaModalService: {},
  28 + $localStorage: {},
28 29 focaBotoneraLateralService: {},
29 30 $timeout: timeout
30 31 });
... ... @@ -42,6 +43,7 @@ describe('Controladores abm precios condiciones', function() {
42 43 $scope: scope,
43 44 focaAbmPreciosCondicionesService: {},
44 45 $location: $location,
  46 + $localStorage: {},
45 47 focaModalService: {},
46 48 focaBotoneraLateralService: {},
47 49 $timeout: timeout
... ... @@ -67,6 +69,7 @@ describe('Controladores abm precios condiciones', function() {
67 69 $scope: scope,
68 70 focaAbmPreciosCondicionesService: {},
69 71 $location: {},
  72 + $localStorage: {},
70 73 focaModalService: focaModalService,
71 74 focaBotoneraLateralService: {},
72 75 $timeout: timeout
... ... @@ -94,6 +97,7 @@ describe('Controladores abm precios condiciones', function() {
94 97 $scope: scope,
95 98 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
96 99 $location: {},
  100 + $localStorage: {},
97 101 focaModalService: focaModalService,
98 102 focaBotoneraLateralService: {},
99 103 $timeout: timeout
... ... @@ -123,6 +127,7 @@ describe('Controladores abm precios condiciones', function() {
123 127 $scope: scope,
124 128 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
125 129 $location: {},
  130 + $localStorage: {},
126 131 focaModalService: {},
127 132 focaBotoneraLateralService: {},
128 133 $timeout: timeout
... ... @@ -143,7 +148,9 @@ describe('Controladores abm precios condiciones', function() {
143 148 it('Existe el controlador focaAbmPrecioCondicionController', function() {
144 149 //act
145 150 var controlador = $controller('focaAbmPrecioCondicionController', {
146   - $scope: {},
  151 + $scope: {
  152 + $watch: function(){}
  153 + },
147 154 focaAbmPreciosCondicionesService: {
148 155 obtenerPrecioCondicion: function() {
149 156 return {
... ... @@ -157,6 +164,7 @@ describe('Controladores abm precios condiciones', function() {
157 164 focaModalService: {},
158 165 $timeout: timeout,
159 166 $uibModal: {},
  167 + $localStorage: {},
160 168 $window: {}
161 169 });
162 170  
... ... @@ -167,7 +175,11 @@ describe('Controladores abm precios condiciones', function() {
167 175 it('La funcion $scope.cancelar lleva a la ruta correcta', function() {
168 176 inject(function($location) {
169 177 //arrange
170   - var scope = {};
  178 + var scope = {
  179 + $watch: function() {},
  180 + salir: function() {},
  181 + formPrecioCondicion: ''
  182 + };
171 183 $controller('focaAbmPrecioCondicionController', {
172 184 $scope: scope,
173 185 focaAbmPreciosCondicionesService: {
... ... @@ -180,6 +192,7 @@ describe('Controladores abm precios condiciones', function() {
180 192 focaBotoneraLateralService: {},
181 193 $routeParams: {},
182 194 $location: $location,
  195 + $localStorage: {},
183 196 focaModalService: {},
184 197 $timeout: timeout,
185 198 $uibModal: {},
... ... @@ -187,7 +200,7 @@ describe('Controladores abm precios condiciones', function() {
187 200 });
188 201  
189 202 //act
190   - scope.cancelar();
  203 + scope.salir();
191 204  
192 205 //assert
193 206 expect($location.url()).toEqual('/precio-condicion');
... ... @@ -197,7 +210,9 @@ describe('Controladores abm precios condiciones', function() {
197 210 it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() {
198 211 inject(function($location) {
199 212 //arrange
200   - var scope = {};
  213 + var scope = {
  214 + $watch: function() { }
  215 + };
201 216 var focaAbmPreciosCondicionesService = {
202 217 obtenerPrecioCondicion: function() {
203 218 return {
... ... @@ -217,13 +232,21 @@ describe('Controladores abm precios condiciones', function() {
217 232 focaBotoneraLateralService: {},
218 233 $routeParams: {},
219 234 $location: $location,
220   - focaModalService: {},
  235 + focaModalService: {
  236 + alert: function() {}
  237 + },
221 238 $timeout: timeout,
222 239 $uibModal: {},
  240 + $localStorage: {},
223 241 $window: window
224 242 });
225 243 var promesaGuardarPrecioCondicion = Promise.resolve(true);
226   - scope.precioCondicion = { listaPrecio: {} };
  244 + scope.precioCondicion = {
  245 + listaPrecio: {},
  246 + nombre: true,
  247 + descripcion: true,
  248 + idListaPrecio: true
  249 + };
227 250  
228 251 //act
229 252 //spyOn(window, 'location').and.returnValue({ assign: function() {} });
... ... @@ -238,7 +261,9 @@ describe('Controladores abm precios condiciones', function() {
238 261  
239 262 it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() {
240 263 //act
241   - var scope = {};
  264 + var scope = {
  265 + $watch: function() {}
  266 + };
242 267 var focaModalService = {
243 268 confirm: function() { }
244 269 };
... ... @@ -257,6 +282,7 @@ describe('Controladores abm precios condiciones', function() {
257 282 focaModalService: focaModalService,
258 283 $timeout: timeout,
259 284 $uibModal: {},
  285 + $localStorage: {},
260 286 $window: {}
261 287 });
262 288  
... ... @@ -271,7 +297,9 @@ describe('Controladores abm precios condiciones', function() {
271 297  
272 298 it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) {
273 299 //act
274   - var scope = {};
  300 + var scope = {
  301 + $watch: function() { }
  302 + };
275 303 var focaModalService = {
276 304 confirm: function() { }
277 305 };
... ... @@ -291,6 +319,7 @@ describe('Controladores abm precios condiciones', function() {
291 319 $location: {},
292 320 focaModalService: focaModalService,
293 321 $timeout: timeout,
  322 + $localStorage: {},
294 323 $uibModal: {},
295 324 $window: {}
296 325 });
... ... @@ -313,7 +342,9 @@ describe('Controladores abm precios condiciones', function() {
313 342  
314 343 it('La funcion $scope.seleccionarListaPrecio levanta modal', function() {
315 344 //arrange
316   - var scope = {};
  345 + var scope = {
  346 + $watch: function() {}
  347 + };
317 348 var uibModal = {
318 349 open: function() { }
319 350 };
... ... @@ -333,6 +364,7 @@ describe('Controladores abm precios condiciones', function() {
333 364 focaModalService: {},
334 365 $timeout: timeout,
335 366 $uibModal: uibModal,
  367 + $localStorage: {},
336 368 $window: {}
337 369 });
338 370  
... ... @@ -346,7 +378,9 @@ describe('Controladores abm precios condiciones', function() {
346 378  
347 379 it('La funcion $scope.verProductosListaPrecio levanta modal', function() {
348 380 //arrange
349   - var scope = {};
  381 + var scope = {
  382 + $watch: function() {}
  383 + };
350 384 var uibModal = {
351 385 open: function() { }
352 386 };
... ... @@ -366,6 +400,7 @@ describe('Controladores abm precios condiciones', function() {
366 400 focaModalService: {},
367 401 $timeout: timeout,
368 402 $uibModal: uibModal,
  403 + $localStorage: {},
369 404 $window: {}
370 405 });
371 406 scope.precioCondicion = {
... ... @@ -381,7 +416,9 @@ describe('Controladores abm precios condiciones', function() {
381 416  
382 417 it('la función next suma uno a $scope.focused', function() {
383 418 //arrange
384   - var scope = {};
  419 + var scope = {
  420 + $watch: function() {}
  421 + };
385 422 var focaAbmPreciosCondicionesService = {
386 423 obtenerPrecioCondicion: function() {
387 424 return {
... ... @@ -398,6 +435,7 @@ describe('Controladores abm precios condiciones', function() {
398 435 focaModalService: {},
399 436 $timeout: timeout,
400 437 $uibModal: {},
  438 + $localStorage: {},
401 439 $window: {}
402 440 });
403 441  
src/js/controller.js
1 1 angular.module('focaAbmPreciosCondiciones')
2 2 .controller('focaAbmPreciosCondicionesController', [
3 3 '$scope', 'focaAbmPreciosCondicionesService', '$location',
4   - 'focaModalService', 'focaBotoneraLateralService', '$timeout',
  4 + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 5 function($scope, focaAbmPreciosCondicionesService, $location,
6   - focaModalService, focaBotoneraLateralService, $timeout) {
  6 + focaModalService, focaBotoneraLateralService, $timeout, $localStorage) {
7 7  
8 8 $timeout(function() {
9 9 focaBotoneraLateralService.showSalir(true);
... ... @@ -11,6 +11,7 @@ angular.module('focaAbmPreciosCondiciones')
11 11 focaBotoneraLateralService.showCancelar(false);
12 12 focaBotoneraLateralService.showGuardar(false);
13 13 });
  14 +
14 15 $scope.filters = '';
15 16 $scope.now = new Date();
16 17 $scope.editar = function(id) {
... ... @@ -45,15 +46,20 @@ angular.module('focaAbmPreciosCondiciones')
45 46 });
46 47 }
47 48 };
  49 +
  50 + if ($localStorage.precioCondicion) {
  51 + var precioCondicion = JSON.parse($localStorage.precioCondicion);
  52 + if (!precioCondicion.id) { precioCondicion.id = 0; }
  53 + $location.path('/precio-condicion/' + precioCondicion.id);
  54 + }
48 55 }
49 56 ])
50 57 .controller('focaAbmPrecioCondicionController', [
51 58 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService',
52   - '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window',
  59 + '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter',
53 60 function(
54 61 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService,
55   - $routeParams, $location, focaModalService, $timeout, $uibModal, $window
56   - ) {
  62 + $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) {
57 63 $scope.focused = 1;
58 64 $scope.plazosAEliminar = [];
59 65 $scope.mostrarPlazos = $routeParams.id > 0;
... ... @@ -69,7 +75,7 @@ angular.module('focaAbmPreciosCondiciones')
69 75 idListaPrecio: 0,
70 76 vigencia: new Date()
71 77 };
72   - if(datos.data.id) {
  78 + if (datos.data.id) {
73 79 $scope.precioCondicion = datos.data;
74 80 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() +
75 81 ' - ' + datos.data.listaPrecio.DES;
... ... @@ -91,22 +97,48 @@ angular.module('focaAbmPreciosCondiciones')
91 97 }
92 98 });
93 99  
  100 + $timeout(function() {getLSPrecioC();});
  101 +
94 102 $timeout(function() {
95 103 focaBotoneraLateralService.showSalir(false);
96 104 focaBotoneraLateralService.showPausar(true);
97   - focaBotoneraLateralService.showCancelar(true);
  105 + focaBotoneraLateralService.showCancelar(false);
98 106 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
  107 + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
99 108 });
100 109  
101   - $scope.cancelar = function() {
102   - $location.path('/precio-condicion');
  110 + $scope.salir = function() {
  111 +
  112 + if ($scope.formPrecioCondicion.$pristine == false) {
  113 + focaModalService.confirm(
  114 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  115 + ).then(function(data) {
  116 + if (data) {
  117 + $location.path('/precio-condicion');
  118 + }
  119 + });
  120 + } else {
  121 + $location.path('/precio-condicion');
  122 + }
103 123 };
104 124 $scope.guardar = function() {
  125 +
  126 + if (!$scope.precioCondicion.nombre) {
  127 + focaModalService.alert('Ingrese nombre');
  128 + return;
  129 + } else if (!$scope.precioCondicion.descripcion) {
  130 + focaModalService.alert('Ingrese descripcion');
  131 + return;
  132 + } else if (!$scope.precioCondicion.idListaPrecio) {
  133 + focaModalService.alert('Seleccione precio');
  134 + return;
  135 + }
  136 +
105 137 var promises = [];
106 138 var precioCondicion = $scope.precioCondicion;
107 139 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID;
108 140 delete precioCondicion.listaPrecio;
109   - if($scope.mostrarPlazos) {
  141 + if ($scope.mostrarPlazos) {
110 142 promises.push(
111 143 focaAbmPreciosCondicionesService
112 144 .guardarPlazosPago($scope.precioCondicion.plazos)
... ... @@ -133,15 +165,15 @@ angular.module('focaAbmPreciosCondiciones')
133 165 };
134 166  
135 167 $scope.agregarPlazo = function(key) {
136   - if(key === 13) {
137   - if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
  168 + if (key === 13) {
  169 + if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
138 170 focaModalService.alert('Ingrese cantidad de días');
139 171 return;
140 172 }
141 173 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) {
142 174 return a.dias === $scope.plazoACargar.dias;
143 175 });
144   - if(tieneEseDia.length > 0) {
  176 + if (tieneEseDia.length > 0) {
145 177 focaModalService.alert('Ya ha ingresado un plazo con esos días');
146 178 return;
147 179 }
... ... @@ -155,7 +187,7 @@ angular.module('focaAbmPreciosCondiciones')
155 187 }
156 188 };
157 189 $scope.quitarPlazo = function(key) {
158   - if($scope.precioCondicion.plazos[key].id)
  190 + if ($scope.precioCondicion.plazos[key].id)
159 191 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id);
160 192  
161 193 $scope.precioCondicion.plazos.splice(key, 1);
... ... @@ -179,7 +211,7 @@ angular.module('focaAbmPreciosCondiciones')
179 211 };
180 212  
181 213 $scope.seleccionarListaPrecio = function(key) {
182   - if(key === 13){
  214 + if (key === 13){
183 215 var modalInstance = $uibModal.open(
184 216 {
185 217 ariaLabelledBy: 'Busqueda de Listas de precio',
... ... @@ -188,7 +220,8 @@ angular.module('focaAbmPreciosCondiciones')
188 220 size: 'lg'
189 221 }
190 222 );
191   - modalInstance.result.then(function(listaPrecio) {
  223 + modalInstance.result.then(function(listaPrecio) {
  224 + $scope.precioCondicion.idListaPrecio = listaPrecio.ID;
192 225 $scope.precioCondicion.listaPrecio = listaPrecio;
193 226 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES;
194 227 $scope.focused = 4;
... ... @@ -216,7 +249,32 @@ angular.module('focaAbmPreciosCondiciones')
216 249 };
217 250  
218 251 $scope.next = function(key) {
219   - if(key === 13) $scope.focused++;
  252 + if (key === 13) $scope.focused++;
220 253 };
  254 +
  255 + //watch
  256 + $scope.$watch('precioCondicion', function(newValue) {
  257 + focaBotoneraLateralService.setPausarData({
  258 + label: 'precioCondicion',
  259 + val: newValue
  260 + });
  261 + }, true);
  262 +
  263 + function setearPrecioCondicion(precioCondicion) {
  264 + $scope.precioCondicion = precioCondicion;
  265 + $scope.$broadcast('addCabecera', {
  266 + label: 'Precio y Condicion:',
  267 + valor: $filter('rellenarDigitos')(precioCondicion.id)
  268 + });
  269 + }
  270 +
  271 + function getLSPrecioC() {
  272 + var precioCondicion = JSON.parse($localStorage.precioCondicion || null);
  273 +
  274 + if (precioCondicion) {
  275 + setearPrecioCondicion(precioCondicion);
  276 + delete $localStorage.precioCondicion;
  277 + }
  278 + }
221 279 }
222 280 ]);
src/views/foca-abm-precios-condiciones-item.html
... ... @@ -6,7 +6,7 @@
6 6 ></foca-cabecera-facturador>
7 7 </div>
8 8 <div class="row">
9   - <form class="col-md-10">
  9 + <form class= "col-md-10" name="formPrecioCondicion">
10 10 <input type="hidden" name="id" ng-model="precioCondicion.id" />
11 11 <div class="row mb-3">
12 12 <label class="col-sm-2 col-form-label">Código</label>