Commit 3e325c506745f7da26798d7728412e4724e17159
1 parent
d12bccc382
Exists in
master
espacios y corrijo errores test
Showing
3 changed files
with
20 additions
and
23 deletions
Show diff stats
spec/controllerSpec.js
1 | describe('Controladores módulo crear nota de pedido', function() { | 1 | describe('Controladores módulo crear nota de pedido', function() { |
2 | 2 | ||
3 | var $controler; | 3 | var $controler; |
4 | 4 | ||
5 | beforeEach(function() { | 5 | beforeEach(function() { |
6 | module('focaCrearNotaPedido'); | 6 | module('focaCrearNotaPedido'); |
7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
8 | $controler = _$controller_; | 8 | $controler = _$controller_; |
9 | }); | 9 | }); |
10 | }); | 10 | }); |
11 | 11 | ||
12 | describe('Controlador notaPedidoCtrl', function() { | 12 | describe('Controlador notaPedidoCtrl', function() { |
13 | 13 | ||
14 | var filter = function() { | 14 | var filter = function() { |
15 | return function() { }; | 15 | return function() { }; |
16 | }; | 16 | }; |
17 | var timeout; | 17 | var timeout; |
18 | 18 | ||
19 | beforeEach(function() { | 19 | beforeEach(function() { |
20 | 20 | ||
21 | inject(function($timeout) { | 21 | inject(function($timeout) { |
22 | timeout = $timeout; | 22 | timeout = $timeout; |
23 | }); | 23 | }); |
24 | }); | 24 | }); |
25 | 25 | ||
26 | it('La función seleccionarNotaPedido levanta modal', function() { | 26 | it('La función seleccionarNotaPedido levanta modal', function() { |
27 | //arrange | 27 | //arrange |
28 | var scope = { | 28 | var scope = { |
29 | $watch: function() { }, | 29 | $watch: function() { }, |
30 | $broadcast: function() { } | 30 | $broadcast: function() { } |
31 | }; | 31 | }; |
32 | var uibModal = { | 32 | var uibModal = { |
33 | open: function() { } | 33 | open: function() { } |
34 | }; | 34 | }; |
35 | 35 | ||
36 | $controler('notaPedidoCtrl', { | 36 | $controler('notaPedidoCtrl', { |
37 | $scope: scope, | 37 | $scope: scope, |
38 | $uibModal: uibModal, | 38 | $uibModal: uibModal, |
39 | $location: {}, | 39 | $location: {}, |
40 | $filter: filter, | 40 | $filter: filter, |
41 | $timeout: timeout, | 41 | $timeout: timeout, |
42 | crearNotaPedidoService: { | 42 | crearNotaPedidoService: { |
43 | getNumeroNotaPedido: function() { | 43 | getNumeroNotaPedido: function() { |
44 | return { | 44 | return { |
45 | then: function() { } | 45 | then: function() { } |
46 | }; | 46 | }; |
47 | }, | 47 | }, |
48 | getBotonera: function() { }, | 48 | getBotonera: function() { }, |
49 | getCotizacionByIdMoneda: function() { | 49 | getCotizacionByIdMoneda: function() { |
50 | return { | 50 | return { |
51 | then: function() { } | 51 | then: function() { } |
52 | }; | 52 | }; |
53 | } | 53 | } |
54 | }, | 54 | }, |
55 | focaBotoneraLateralService: {}, | 55 | focaBotoneraLateralService: {}, |
56 | focaModalService: {}, | 56 | focaModalService: {}, |
57 | notaPedidoBusinessService: {}, | 57 | notaPedidoBusinessService: {}, |
58 | $rootScope: { | 58 | $rootScope: { |
59 | $on: function() { } | 59 | $on: function() { } |
60 | }, | 60 | }, |
61 | focaSeguimientoService: {}, | 61 | focaSeguimientoService: {}, |
62 | APP: {}, | 62 | APP: {}, |
63 | focaLoginService: {}, | 63 | focaLoginService: {}, |
64 | $localStorage: {} | 64 | $localStorage: {} |
65 | }); | 65 | }); |
66 | var respuesta = { result: { then: function() { } } }; | 66 | var respuesta = { result: { then: function() { } } }; |
67 | 67 | ||
68 | //act | 68 | //act |
69 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 69 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
70 | scope.seleccionarNotaPedido(); | 70 | scope.seleccionarNotaPedido(); |
71 | 71 | ||
72 | //assert | 72 | //assert |
73 | expect(uibModal.open).toHaveBeenCalled(); | 73 | expect(uibModal.open).toHaveBeenCalled(); |
74 | }); | 74 | }); |
75 | 75 | ||
76 | it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { | 76 | it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { |
77 | //arrange | 77 | //arrange |
78 | var scope = { | 78 | var scope = { |
79 | $watch: function() { }, | 79 | $watch: function() { }, |
80 | $broadcast: function() { } | 80 | $broadcast: function() { } |
81 | }; | 81 | }; |
82 | var uibModal = { | 82 | var uibModal = { |
83 | open: function() { } | 83 | open: function() { } |
84 | }; | 84 | }; |
85 | 85 | ||
86 | $controler('notaPedidoCtrl', { | 86 | $controler('notaPedidoCtrl', { |
87 | $scope: scope, | 87 | $scope: scope, |
88 | $uibModal: uibModal, | 88 | $uibModal: uibModal, |
89 | $location: {}, | 89 | $location: {}, |
90 | $filter: filter, | 90 | $filter: filter, |
91 | $timeout: timeout, | 91 | $timeout: timeout, |
92 | crearNotaPedidoService: { | 92 | crearNotaPedidoService: { |
93 | getNumeroNotaPedido: function() { | 93 | getNumeroNotaPedido: function() { |
94 | return { | 94 | return { |
95 | then: function() { } | 95 | then: function() { } |
96 | }; | 96 | }; |
97 | }, | 97 | }, |
98 | getBotonera: function() { }, | 98 | getBotonera: function() { }, |
99 | getCotizacionByIdMoneda: function() { | 99 | getCotizacionByIdMoneda: function() { |
100 | return { | 100 | return { |
101 | then: function() { } | 101 | then: function() { } |
102 | }; | 102 | }; |
103 | } | 103 | } |
104 | }, | 104 | }, |
105 | focaBotoneraLateralService: {}, | 105 | focaBotoneraLateralService: {}, |
106 | focaModalService: {}, | 106 | focaModalService: {}, |
107 | notaPedidoBusinessService: { | 107 | notaPedidoBusinessService: { |
108 | plazoToString: function() { }, | 108 | plazoToString: function() { }, |
109 | calcularArticulos: function() { } | 109 | calcularArticulos: function() { } |
110 | }, | 110 | }, |
111 | $rootScope: { | 111 | $rootScope: { |
112 | $on: function() { } | 112 | $on: function() { } |
113 | }, | 113 | }, |
114 | focaSeguimientoService: {}, | 114 | focaSeguimientoService: {}, |
115 | APP: {}, | 115 | APP: {}, |
116 | focaLoginService: {}, | 116 | focaLoginService: {}, |
117 | $localStorage: {} | 117 | $localStorage: {} |
118 | }); | 118 | }); |
119 | var notaPedido = { | 119 | var notaPedido = { |
120 | cotizacion: { | 120 | cotizacion: { |
121 | moneda: {} | 121 | moneda: {} |
122 | }, | 122 | }, |
123 | cliente: {}, | 123 | cliente: {}, |
124 | vendedor: {}, | 124 | vendedor: {}, |
125 | proveedor: {}, | 125 | proveedor: {}, |
126 | notaPedidoPlazo: [], | 126 | notaPedidoPlazo: [], |
127 | notaPedidoPuntoDescarga: [] | 127 | notaPedidoPuntoDescarga: [] |
128 | }; | 128 | }; |
129 | var respuesta = { result: Promise.resolve(notaPedido) }; | 129 | var respuesta = { result: Promise.resolve(notaPedido) }; |
130 | 130 | ||
131 | //act | 131 | //act |
132 | scope.notaPedido = {}; | 132 | scope.notaPedido = {}; |
133 | scope.$broadcast = function() { }; | 133 | scope.$broadcast = function() { }; |
134 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 134 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
135 | spyOn(scope, '$broadcast'); | 135 | spyOn(scope, '$broadcast'); |
136 | scope.seleccionarNotaPedido(); | 136 | scope.seleccionarNotaPedido(); |
137 | 137 | ||
138 | //assert | 138 | //assert |
139 | respuesta.result.then(function() { | 139 | respuesta.result.then(function() { |
140 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); | 140 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); |
141 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); | 141 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); |
142 | done(); | 142 | done(); |
143 | }); | 143 | }); |
144 | }); | 144 | }); |
145 | 145 | ||
146 | it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { | 146 | it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { |
147 | //arrange | 147 | //arrange |
148 | var scope = { | 148 | var scope = { |
149 | $watch: function() { }, | 149 | $watch: function() { }, |
150 | $broadcast: function() { } | 150 | $broadcast: function() { } |
151 | }; | 151 | }; |
152 | var focaModalService = { | 152 | var focaModalService = { |
153 | alert: function() { } | 153 | alert: function() { } |
154 | }; | 154 | }; |
155 | 155 | ||
156 | $controler('notaPedidoCtrl', { | 156 | $controler('notaPedidoCtrl', { |
157 | $scope: scope, | 157 | $scope: scope, |
158 | $uibModal: {}, | 158 | $uibModal: {}, |
159 | $location: {}, | 159 | $location: {}, |
160 | $filter: filter, | 160 | $filter: filter, |
161 | $timeout: timeout, | 161 | $timeout: timeout, |
162 | crearNotaPedidoService: { | 162 | crearNotaPedidoService: { |
163 | getNumeroNotaPedido: function() { | 163 | getNumeroNotaPedido: function() { |
164 | return { | 164 | return { |
165 | then: function() { } | 165 | then: function() { } |
166 | }; | 166 | }; |
167 | }, | 167 | }, |
168 | getBotonera: function() { }, | 168 | getBotonera: function() { }, |
169 | getCotizacionByIdMoneda: function() { | 169 | getCotizacionByIdMoneda: function() { |
170 | return { | 170 | return { |
171 | then: function() { } | 171 | then: function() { } |
172 | }; | 172 | }; |
173 | } | 173 | } |
174 | }, | 174 | }, |
175 | focaBotoneraLateralService: {}, | 175 | focaBotoneraLateralService: {}, |
176 | focaModalService: focaModalService, | 176 | focaModalService: focaModalService, |
177 | notaPedidoBusinessService: {}, | 177 | notaPedidoBusinessService: {}, |
178 | $rootScope: { | 178 | $rootScope: { |
179 | $on: function() { } | 179 | $on: function() { } |
180 | }, | 180 | }, |
181 | focaSeguimientoService: {}, | 181 | focaSeguimientoService: {}, |
182 | APP: {}, | 182 | APP: {}, |
183 | focaLoginService: {}, | 183 | focaLoginService: {}, |
184 | $localStorage: {} | 184 | $localStorage: {} |
185 | }); | 185 | }); |
186 | 186 | ||
187 | //act | 187 | //act |
188 | spyOn(focaModalService, 'alert'); | 188 | spyOn(focaModalService, 'alert'); |
189 | scope.idLista = undefined; | 189 | scope.idLista = undefined; |
190 | scope.seleccionarProductos(); | 190 | scope.seleccionarProductos(); |
191 | 191 | ||
192 | //assert | 192 | //assert |
193 | expect(focaModalService.alert) | 193 | expect(focaModalService.alert) |
194 | .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); | 194 | .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); |
195 | }); | 195 | }); |
196 | 196 | ||
197 | it('función seleccionarProductos abre modal', function() { | 197 | it('función seleccionarProductos abre modal', function() { |
198 | //arrange | 198 | //arrange |
199 | var scope = { | 199 | var scope = { |
200 | $watch: function() { }, | 200 | $watch: function() { }, |
201 | $broadcast: function() { } | 201 | $broadcast: function() { } |
202 | }; | 202 | }; |
203 | var uibModal = { | 203 | var uibModal = { |
204 | open: function() { } | 204 | open: function() { } |
205 | }; | 205 | }; |
206 | 206 | ||
207 | $controler('notaPedidoCtrl', { | 207 | $controler('notaPedidoCtrl', { |
208 | $scope: scope, | 208 | $scope: scope, |
209 | $uibModal: uibModal, | 209 | $uibModal: uibModal, |
210 | $location: {}, | 210 | $location: {}, |
211 | $filter: filter, | 211 | $filter: filter, |
212 | $timeout: timeout, | 212 | $timeout: timeout, |
213 | crearNotaPedidoService: { | 213 | crearNotaPedidoService: { |
214 | getNumeroNotaPedido: function() { | 214 | getNumeroNotaPedido: function() { |
215 | return { | 215 | return { |
216 | then: function() { } | 216 | then: function() { } |
217 | }; | 217 | }; |
218 | }, | 218 | }, |
219 | getBotonera: function() { }, | 219 | getBotonera: function() { }, |
220 | getCotizacionByIdMoneda: function() { | 220 | getCotizacionByIdMoneda: function() { |
221 | return { | 221 | return { |
222 | then: function() { } | 222 | then: function() { } |
223 | }; | 223 | }; |
224 | } | 224 | } |
225 | }, | 225 | }, |
226 | focaBotoneraLateralService: {}, | 226 | focaBotoneraLateralService: {}, |
227 | focaModalService: {}, | 227 | focaModalService: {}, |
228 | notaPedidoBusinessService: {}, | 228 | notaPedidoBusinessService: {}, |
229 | $rootScope: { | 229 | $rootScope: { |
230 | $on: function() { } | 230 | $on: function() { } |
231 | }, | 231 | }, |
232 | focaSeguimientoService: {}, | 232 | focaSeguimientoService: {}, |
233 | APP: {}, | 233 | APP: {}, |
234 | focaLoginService: {}, | 234 | focaLoginService: {}, |
235 | $localStorage: {} | 235 | $localStorage: {} |
236 | }); | 236 | }); |
237 | scope.idLista = true; | 237 | scope.idLista = true; |
238 | scope.notaPedido = { | 238 | scope.notaPedido = { |
239 | cotizacion: { | 239 | cotizacion: { |
240 | moneda: {} | 240 | moneda: {} |
241 | }, | 241 | }, |
242 | 242 | ||
243 | }; | 243 | }; |
244 | var respuesta = { result: {then: function() { } } }; | 244 | var respuesta = { result: {then: function() { } } }; |
245 | 245 | ||
246 | //act | 246 | //act |
247 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 247 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
248 | scope.seleccionarProductos(); | 248 | scope.seleccionarProductos(); |
249 | 249 | ||
250 | //assert | 250 | //assert |
251 | expect(uibModal.open).toHaveBeenCalled(); | 251 | expect(uibModal.open).toHaveBeenCalled(); |
252 | }); | 252 | }); |
253 | 253 | ||
254 | it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + | 254 | it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + |
255 | 'undefined', function() | 255 | 'undefined', function() |
256 | { | 256 | { |
257 | //arrange | 257 | //arrange |
258 | var scope = { | 258 | var scope = { |
259 | $watch: function() { }, | 259 | $watch: function() { }, |
260 | $broadcast: function() { } | 260 | $broadcast: function() { } |
261 | }; | 261 | }; |
262 | var focaModalService = { | 262 | var focaModalService = { |
263 | alert: function() { } | 263 | alert: function() { } |
264 | }; | 264 | }; |
265 | 265 | ||
266 | $controler('notaPedidoCtrl', { | 266 | $controler('notaPedidoCtrl', { |
267 | $scope: scope, | 267 | $scope: scope, |
268 | $uibModal: {}, | 268 | $uibModal: {}, |
269 | $location: {}, | 269 | $location: {}, |
270 | $filter: filter, | 270 | $filter: filter, |
271 | $timeout: timeout, | 271 | $timeout: timeout, |
272 | crearNotaPedidoService: { | 272 | crearNotaPedidoService: { |
273 | getNumeroNotaPedido: function() { | 273 | getNumeroNotaPedido: function() { |
274 | return { | 274 | return { |
275 | then: function() { } | 275 | then: function() { } |
276 | }; | 276 | }; |
277 | }, | 277 | }, |
278 | getBotonera: function() { }, | 278 | getBotonera: function() { }, |
279 | getCotizacionByIdMoneda: function() { | 279 | getCotizacionByIdMoneda: function() { |
280 | return { | 280 | return { |
281 | then: function() { } | 281 | then: function() { } |
282 | }; | 282 | }; |
283 | } | 283 | } |
284 | }, | 284 | }, |
285 | focaBotoneraLateralService: {}, | 285 | focaBotoneraLateralService: {}, |
286 | focaModalService: focaModalService, | 286 | focaModalService: focaModalService, |
287 | notaPedidoBusinessService: {}, | 287 | notaPedidoBusinessService: {}, |
288 | $rootScope: { | 288 | $rootScope: { |
289 | $on: function() { } | 289 | $on: function() { } |
290 | }, | 290 | }, |
291 | focaSeguimientoService: {}, | 291 | focaSeguimientoService: {}, |
292 | APP: {}, | 292 | APP: {}, |
293 | focaLoginService: {}, | 293 | focaLoginService: {}, |
294 | $localStorage: {} | 294 | $localStorage: {} |
295 | }); | 295 | }); |
296 | scope.idLista = true; | 296 | scope.idLista = true; |
297 | scope.notaPedido = { | 297 | scope.notaPedido = { |
298 | cliente: { COD: false }, | 298 | cliente: { COD: false }, |
299 | domicilio: { id: false} | 299 | domicilio: { id: false} |
300 | }; | 300 | }; |
301 | 301 | ||
302 | //act | 302 | //act |
303 | spyOn(focaModalService, 'alert'); | 303 | spyOn(focaModalService, 'alert'); |
304 | scope.seleccionarPuntosDeDescarga(); | 304 | scope.seleccionarPuntosDeDescarga(); |
305 | 305 | ||
306 | //assert | 306 | //assert |
307 | expect(focaModalService.alert).toHaveBeenCalled(); | 307 | expect(focaModalService.alert).toHaveBeenCalled(); |
308 | }); | 308 | }); |
309 | 309 | ||
310 | it('función seleccionarPuntosDeDescarga abre modal', function() { | 310 | it('función seleccionarPuntosDeDescarga abre modal', function() { |
311 | //arrange | 311 | //arrange |
312 | var scope = { | 312 | var scope = { |
313 | $watch: function() { }, | 313 | $watch: function() { }, |
314 | $broadcast: function() { } | 314 | $broadcast: function() { } |
315 | }; | 315 | }; |
316 | var uibModal = { | 316 | var uibModal = { |
317 | open: function() { } | 317 | open: function() { } |
318 | }; | 318 | }; |
319 | 319 | ||
320 | $controler('notaPedidoCtrl', { | 320 | $controler('notaPedidoCtrl', { |
321 | $scope: scope, | 321 | $scope: scope, |
322 | $uibModal: uibModal, | 322 | $uibModal: uibModal, |
323 | $location: {}, | 323 | $location: {}, |
324 | $filter: filter, | 324 | $filter: filter, |
325 | $timeout: timeout, | 325 | $timeout: timeout, |
326 | crearNotaPedidoService: { | 326 | crearNotaPedidoService: { |
327 | getNumeroNotaPedido: function() { | 327 | getNumeroNotaPedido: function() { |
328 | return { | 328 | return { |
329 | then: function() { } | 329 | then: function() { } |
330 | }; | 330 | }; |
331 | }, | 331 | }, |
332 | getBotonera: function() { }, | 332 | getBotonera: function() { }, |
333 | getCotizacionByIdMoneda: function() { | 333 | getCotizacionByIdMoneda: function() { |
334 | return { | 334 | return { |
335 | then: function() { } | 335 | then: function() { } |
336 | }; | 336 | }; |
337 | } | 337 | } |
338 | }, | 338 | }, |
339 | focaBotoneraLateralService: {}, | 339 | focaBotoneraLateralService: {}, |
340 | focaModalService: {}, | 340 | focaModalService: {}, |
341 | notaPedidoBusinessService: {}, | 341 | notaPedidoBusinessService: {}, |
342 | $rootScope: { | 342 | $rootScope: { |
343 | $on: function() { } | 343 | $on: function() { } |
344 | }, | 344 | }, |
345 | focaSeguimientoService: {}, | 345 | focaSeguimientoService: {}, |
346 | APP: {}, | 346 | APP: {}, |
347 | focaLoginService: {}, | 347 | focaLoginService: {}, |
348 | $localStorage: {} | 348 | $localStorage: {} |
349 | }); | 349 | }); |
350 | scope.idLista = true; | 350 | scope.idLista = true; |
351 | scope.notaPedido = { | 351 | scope.notaPedido = { |
352 | cliente: { COD: true }, | 352 | cliente: { COD: true }, |
353 | domicilio: { id: true } | 353 | domicilio: { id: true } |
354 | }; | 354 | }; |
355 | var respuesta = { result: { then: function() { } } }; | 355 | var respuesta = { result: { then: function() { } } }; |
356 | 356 | ||
357 | //act | 357 | //act |
358 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 358 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
359 | scope.seleccionarPuntosDeDescarga(); | 359 | scope.seleccionarPuntosDeDescarga(); |
360 | 360 | ||
361 | //assert | 361 | //assert |
362 | expect(uibModal.open).toHaveBeenCalled(); | 362 | expect(uibModal.open).toHaveBeenCalled(); |
363 | }); | 363 | }); |
364 | 364 | ||
365 | it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { | 365 | it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { |
366 | //arrange | 366 | //arrange |
367 | var scope = { | 367 | var scope = { |
368 | $watch: function() { }, | 368 | $watch: function() { }, |
369 | $broadcast: function() { } | 369 | $broadcast: function() { } |
370 | }; | 370 | }; |
371 | var uibModal = { | 371 | var uibModal = { |
372 | open: function() { } | 372 | open: function() { } |
373 | }; | 373 | }; |
374 | 374 | ||
375 | $controler('notaPedidoCtrl', { | 375 | $controler('notaPedidoCtrl', { |
376 | $scope: scope, | 376 | $scope: scope, |
377 | $uibModal: uibModal, | 377 | $uibModal: uibModal, |
378 | $location: {}, | 378 | $location: {}, |
379 | $filter: filter, | 379 | $filter: filter, |
380 | $timeout: timeout, | 380 | $timeout: timeout, |
381 | crearNotaPedidoService: { | 381 | crearNotaPedidoService: { |
382 | getNumeroNotaPedido: function() { | 382 | getNumeroNotaPedido: function() { |
383 | return { | 383 | return { |
384 | then: function() { } | 384 | then: function() { } |
385 | }; | 385 | }; |
386 | }, | 386 | }, |
387 | getBotonera: function() { }, | 387 | getBotonera: function() { }, |
388 | getCotizacionByIdMoneda: function() { | 388 | getCotizacionByIdMoneda: function() { |
389 | return { | 389 | return { |
390 | then: function() { } | 390 | then: function() { } |
391 | }; | 391 | }; |
392 | } | 392 | } |
393 | }, | 393 | }, |
394 | focaBotoneraLateralService: {}, | 394 | focaBotoneraLateralService: {}, |
395 | focaModalService: {}, | 395 | focaModalService: {}, |
396 | notaPedidoBusinessService: {}, | 396 | notaPedidoBusinessService: {}, |
397 | $rootScope: { | 397 | $rootScope: { |
398 | $on: function() { } | 398 | $on: function() { } |
399 | }, | 399 | }, |
400 | focaSeguimientoService: {}, | 400 | focaSeguimientoService: {}, |
401 | APP: {}, | 401 | APP: {}, |
402 | focaLoginService: {}, | 402 | focaLoginService: {}, |
403 | $localStorage: {} | 403 | $localStorage: {} |
404 | }); | 404 | }); |
405 | scope.idLista = true; | 405 | scope.idLista = true; |
406 | scope.notaPedido = { | 406 | scope.notaPedido = { |
407 | cliente: { COD: true }, | 407 | cliente: { COD: true }, |
408 | domicilio: { id: true }, | 408 | domicilio: { id: true }, |
409 | puntosDescarga: [] | 409 | puntosDescarga: [] |
410 | }; | 410 | }; |
411 | var respuesta = []; | 411 | var respuesta = []; |
412 | var promiseRespuesta = { result: Promise.resolve(respuesta) }; | 412 | var promiseRespuesta = { result: Promise.resolve(respuesta) }; |
413 | scope.$broadcast = function() { }; | 413 | scope.$broadcast = function() { }; |
414 | 414 | ||
415 | //act | 415 | //act |
416 | spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); | 416 | spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); |
417 | scope.seleccionarPuntosDeDescarga(); | 417 | scope.seleccionarPuntosDeDescarga(); |
418 | 418 | ||
419 | //assert | 419 | //assert |
420 | promiseRespuesta.result.then(function() { | 420 | promiseRespuesta.result.then(function() { |
421 | expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); | 421 | expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); |
422 | done(); | 422 | done(); |
423 | }); | 423 | }); |
424 | }); | 424 | }); |
425 | 425 | ||
426 | it('función seleccionarVendedor abre modal', function() { | 426 | it('función seleccionarVendedor abre modal', function() { |
427 | //arrange | 427 | //arrange |
428 | var scope = { | 428 | var scope = { |
429 | $watch: function() { }, | 429 | $watch: function() { }, |
430 | $broadcast: function() { } | 430 | $broadcast: function() { } |
431 | }; | 431 | }; |
432 | var focaModalService = { | 432 | var focaModalService = { |
433 | modal: function() { } | 433 | modal: function() { } |
434 | }; | 434 | }; |
435 | 435 | ||
436 | $controler('notaPedidoCtrl', { | 436 | $controler('notaPedidoCtrl', { |
437 | $scope: scope, | 437 | $scope: scope, |
438 | $uibModal: {}, | 438 | $uibModal: {}, |
439 | $location: {}, | 439 | $location: {}, |
440 | $filter: filter, | 440 | $filter: filter, |
441 | $timeout: timeout, | 441 | $timeout: timeout, |
442 | crearNotaPedidoService: { | 442 | crearNotaPedidoService: { |
443 | getNumeroNotaPedido: function() { | 443 | getNumeroNotaPedido: function() { |
444 | return { | 444 | return { |
445 | then: function() { } | 445 | then: function() { } |
446 | }; | 446 | }; |
447 | }, | 447 | }, |
448 | getBotonera: function() { }, | 448 | getBotonera: function() { }, |
449 | getCotizacionByIdMoneda: function() { | 449 | getCotizacionByIdMoneda: function() { |
450 | return { | 450 | return { |
451 | then: function() { } | 451 | then: function() { } |
452 | }; | 452 | }; |
453 | } | 453 | } |
454 | }, | 454 | }, |
455 | focaBotoneraLateralService: {}, | 455 | focaBotoneraLateralService: {}, |
456 | focaModalService: focaModalService, | 456 | focaModalService: focaModalService, |
457 | notaPedidoBusinessService: {}, | 457 | notaPedidoBusinessService: {}, |
458 | $rootScope: { | 458 | $rootScope: { |
459 | $on: function() { } | 459 | $on: function() { } |
460 | }, | 460 | }, |
461 | focaSeguimientoService: {}, | 461 | focaSeguimientoService: {}, |
462 | APP: {}, | 462 | APP: {}, |
463 | focaLoginService: {}, | 463 | focaLoginService: {}, |
464 | $localStorage: {} | 464 | $localStorage: {} |
465 | }); | 465 | }); |
466 | scope.idLista = true; | 466 | scope.idLista = true; |
467 | scope.notaPedido = { | 467 | scope.notaPedido = { |
468 | cliente: { COD: true }, | 468 | cliente: { COD: true }, |
469 | domicilio: { id: true } | 469 | domicilio: { id: true } |
470 | }; | 470 | }; |
471 | 471 | ||
472 | var respuesta = { then: function() { } }; | 472 | var respuesta = { then: function() { } }; |
473 | 473 | ||
474 | //act | 474 | //act |
475 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 475 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
476 | scope.seleccionarVendedor(); | 476 | scope.seleccionarVendedor(); |
477 | 477 | ||
478 | //assert | 478 | //assert |
479 | expect(focaModalService.modal).toHaveBeenCalled(); | 479 | expect(focaModalService.modal).toHaveBeenCalled(); |
480 | }); | 480 | }); |
481 | 481 | ||
482 | it('función seleccionarVendedor setea vendedor y cabecera', function(done) { | 482 | it('función seleccionarVendedor setea vendedor y cabecera', function(done) { |
483 | //arrange | 483 | //arrange |
484 | var scope = { | 484 | var scope = { |
485 | $watch: function() { }, | 485 | $watch: function() { }, |
486 | $broadcast: function() { } | 486 | $broadcast: function() { } |
487 | }; | 487 | }; |
488 | var focaModalService = { | 488 | var focaModalService = { |
489 | modal: function() { } | 489 | modal: function() { } |
490 | }; | 490 | }; |
491 | 491 | ||
492 | $controler('notaPedidoCtrl', { | 492 | $controler('notaPedidoCtrl', { |
493 | $scope: scope, | 493 | $scope: scope, |
494 | $uibModal: {}, | 494 | $uibModal: {}, |
495 | $location: {}, | 495 | $location: {}, |
496 | $filter: filter, | 496 | $filter: filter, |
497 | $timeout: timeout, | 497 | $timeout: timeout, |
498 | crearNotaPedidoService: { | 498 | crearNotaPedidoService: { |
499 | getNumeroNotaPedido: function() { | 499 | getNumeroNotaPedido: function() { |
500 | return { | 500 | return { |
501 | then: function() { } | 501 | then: function() { } |
502 | }; | 502 | }; |
503 | }, | 503 | }, |
504 | getBotonera: function() { }, | 504 | getBotonera: function() { }, |
505 | getCotizacionByIdMoneda: function() { | 505 | getCotizacionByIdMoneda: function() { |
506 | return { | 506 | return { |
507 | then: function() { } | 507 | then: function() { } |
508 | }; | 508 | }; |
509 | } | 509 | } |
510 | }, | 510 | }, |
511 | focaBotoneraLateralService: {}, | 511 | focaBotoneraLateralService: {}, |
512 | focaModalService: focaModalService, | 512 | focaModalService: focaModalService, |
513 | notaPedidoBusinessService: {}, | 513 | notaPedidoBusinessService: {}, |
514 | $rootScope: { | 514 | $rootScope: { |
515 | $on: function() { } | 515 | $on: function() { } |
516 | }, | 516 | }, |
517 | focaSeguimientoService: {}, | 517 | focaSeguimientoService: {}, |
518 | APP: {}, | 518 | APP: {}, |
519 | focaLoginService: {}, | 519 | focaLoginService: {}, |
520 | $localStorage: {} | 520 | $localStorage: {} |
521 | }); | 521 | }); |
522 | scope.idLista = true; | 522 | scope.idLista = true; |
523 | scope.notaPedido = { | 523 | scope.notaPedido = { |
524 | cliente: { COD: true }, | 524 | cliente: { COD: true }, |
525 | domicilio: { id: true } | 525 | domicilio: { id: true } |
526 | }; | 526 | }; |
527 | var respuesta = {}; | 527 | var respuesta = {}; |
528 | var promesaRespuesta = Promise.resolve(respuesta); | 528 | var promesaRespuesta = Promise.resolve(respuesta); |
529 | scope.$broadcast = function() { }; | 529 | scope.$broadcast = function() { }; |
530 | 530 | ||
531 | //act | 531 | //act |
532 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 532 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
533 | spyOn(scope, '$broadcast'); | 533 | spyOn(scope, '$broadcast'); |
534 | scope.seleccionarVendedor(); | 534 | scope.seleccionarVendedor(); |
535 | 535 | ||
536 | //assert | 536 | //assert |
537 | promesaRespuesta.then(function() { | 537 | promesaRespuesta.then(function() { |
538 | expect(scope.notaPedido.vendedor).toEqual(respuesta); | 538 | expect(scope.notaPedido.vendedor).toEqual(respuesta); |
539 | expect(scope.$broadcast).toHaveBeenCalled(); | 539 | expect(scope.$broadcast).toHaveBeenCalled(); |
540 | done(); | 540 | done(); |
541 | }); | 541 | }); |
542 | }); | 542 | }); |
543 | 543 | ||
544 | it('función seleccionarProveedor abre modal', function() { | 544 | it('función seleccionarProveedor abre modal', function() { |
545 | //arrange | 545 | //arrange |
546 | var scope = { | 546 | var scope = { |
547 | $watch: function() { }, | 547 | $watch: function() { }, |
548 | $broadcast: function() { } | 548 | $broadcast: function() { } |
549 | }; | 549 | }; |
550 | var focaModalService = { | 550 | var focaModalService = { |
551 | modal: function() { } | 551 | modal: function() { } |
552 | }; | 552 | }; |
553 | 553 | ||
554 | $controler('notaPedidoCtrl', { | 554 | $controler('notaPedidoCtrl', { |
555 | $scope: scope, | 555 | $scope: scope, |
556 | $uibModal: {}, | 556 | $uibModal: {}, |
557 | $location: {}, | 557 | $location: {}, |
558 | $filter: filter, | 558 | $filter: filter, |
559 | $timeout: timeout, | 559 | $timeout: timeout, |
560 | crearNotaPedidoService: { | 560 | crearNotaPedidoService: { |
561 | getNumeroNotaPedido: function() { | 561 | getNumeroNotaPedido: function() { |
562 | return { | 562 | return { |
563 | then: function() { } | 563 | then: function() { } |
564 | }; | 564 | }; |
565 | }, | 565 | }, |
566 | getBotonera: function() { }, | 566 | getBotonera: function() { }, |
567 | getCotizacionByIdMoneda: function() { | 567 | getCotizacionByIdMoneda: function() { |
568 | return { | 568 | return { |
569 | then: function() { } | 569 | then: function() { } |
570 | }; | 570 | }; |
571 | } | 571 | } |
572 | }, | 572 | }, |
573 | focaBotoneraLateralService: {}, | 573 | focaBotoneraLateralService: {}, |
574 | focaModalService: focaModalService, | 574 | focaModalService: focaModalService, |
575 | notaPedidoBusinessService: {}, | 575 | notaPedidoBusinessService: {}, |
576 | $rootScope: { | 576 | $rootScope: { |
577 | $on: function() { } | 577 | $on: function() { } |
578 | }, | 578 | }, |
579 | focaSeguimientoService: {}, | 579 | focaSeguimientoService: {}, |
580 | APP: {}, | 580 | APP: {}, |
581 | focaLoginService: {}, | 581 | focaLoginService: {}, |
582 | $localStorage: {} | 582 | $localStorage: {} |
583 | }); | 583 | }); |
584 | scope.notaPedido = {}; | 584 | scope.notaPedido = {}; |
585 | 585 | ||
586 | var respuesta = { then: function() { } }; | 586 | var respuesta = { then: function() { } }; |
587 | 587 | ||
588 | //act | 588 | //act |
589 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 589 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
590 | scope.seleccionarProveedor(); | 590 | scope.seleccionarProveedor(); |
591 | 591 | ||
592 | //assert | 592 | //assert |
593 | expect(focaModalService.modal).toHaveBeenCalled(); | 593 | expect(focaModalService.modal).toHaveBeenCalled(); |
594 | }); | 594 | }); |
595 | 595 | ||
596 | it('función seleccionarProveedor setea vendedor y cabecera', function(done) { | 596 | it('función seleccionarProveedor setea vendedor y cabecera', function(done) { |
597 | //arrange | 597 | //arrange |
598 | var scope = { | 598 | var scope = { |
599 | $watch: function() { }, | 599 | $watch: function() { }, |
600 | $broadcast: function() { } | 600 | $broadcast: function() { } |
601 | }; | 601 | }; |
602 | var focaModalService = { | 602 | var focaModalService = { |
603 | modal: function() { } | 603 | modal: function() { } |
604 | }; | 604 | }; |
605 | 605 | ||
606 | $controler('notaPedidoCtrl', { | 606 | $controler('notaPedidoCtrl', { |
607 | $scope: scope, | 607 | $scope: scope, |
608 | $uibModal: {}, | 608 | $uibModal: {}, |
609 | $location: {}, | 609 | $location: {}, |
610 | $filter: filter, | 610 | $filter: filter, |
611 | $timeout: timeout, | 611 | $timeout: timeout, |
612 | crearNotaPedidoService: { | 612 | crearNotaPedidoService: { |
613 | getNumeroNotaPedido: function() { | 613 | getNumeroNotaPedido: function() { |
614 | return { | 614 | return { |
615 | then: function() { } | 615 | then: function() { } |
616 | }; | 616 | }; |
617 | }, | 617 | }, |
618 | getBotonera: function() { }, | 618 | getBotonera: function() { }, |
619 | getCotizacionByIdMoneda: function() { | 619 | getCotizacionByIdMoneda: function() { |
620 | return { | 620 | return { |
621 | then: function() { } | 621 | then: function() { } |
622 | }; | 622 | }; |
623 | } | 623 | } |
624 | }, | 624 | }, |
625 | focaBotoneraLateralService: {}, | 625 | focaBotoneraLateralService: {}, |
626 | focaModalService: focaModalService, | 626 | focaModalService: focaModalService, |
627 | notaPedidoBusinessService: {}, | 627 | notaPedidoBusinessService: {}, |
628 | $rootScope: { | 628 | $rootScope: { |
629 | $on: function() { } | 629 | $on: function() { } |
630 | }, | 630 | }, |
631 | focaSeguimientoService: {}, | 631 | focaSeguimientoService: {}, |
632 | APP: {}, | 632 | APP: {}, |
633 | focaLoginService: {}, | 633 | focaLoginService: {}, |
634 | $localStorage: {} | 634 | $localStorage: {} |
635 | }); | 635 | }); |
636 | 636 | ||
637 | scope.notaPedido = {}; | 637 | scope.notaPedido = {}; |
638 | var respuesta = {}; | 638 | var respuesta = {}; |
639 | var promesaRespuesta = Promise.resolve(respuesta); | 639 | var promesaRespuesta = Promise.resolve(respuesta); |
640 | scope.$broadcast = function() { }; | 640 | scope.$broadcast = function() { }; |
641 | 641 | ||
642 | //act | 642 | //act |
643 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 643 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
644 | spyOn(scope, '$broadcast'); | 644 | spyOn(scope, '$broadcast'); |
645 | scope.seleccionarProveedor(); | 645 | scope.seleccionarProveedor(); |
646 | 646 | ||
647 | //assert | 647 | //assert |
648 | promesaRespuesta.then(function() { | 648 | promesaRespuesta.then(function() { |
649 | expect(scope.notaPedido.proveedor).toEqual(respuesta); | 649 | expect(scope.notaPedido.proveedor).toEqual(respuesta); |
650 | expect(scope.$broadcast).toHaveBeenCalled(); | 650 | expect(scope.$broadcast).toHaveBeenCalled(); |
651 | done(); | 651 | done(); |
652 | }); | 652 | }); |
653 | }); | 653 | }); |
654 | 654 | ||
655 | it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() { | 655 | it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() { |
656 | //arrange | 656 | //arrange |
657 | var scope = { | 657 | var scope = { |
658 | $watch: function() { }, | 658 | $watch: function() { }, |
659 | $broadcast: function() { } | 659 | $broadcast: function() { } |
660 | }; | 660 | }; |
661 | var focaModalService = { | 661 | var focaModalService = { |
662 | alert: function() { } | 662 | alert: function() { } |
663 | }; | 663 | }; |
664 | 664 | ||
665 | $controler('notaPedidoCtrl', { | 665 | $controler('notaPedidoCtrl', { |
666 | $scope: scope, | 666 | $scope: scope, |
667 | $uibModal: {}, | 667 | $uibModal: {}, |
668 | $location: {}, | 668 | $location: {}, |
669 | $filter: filter, | 669 | $filter: filter, |
670 | $timeout: timeout, | 670 | $timeout: timeout, |
671 | crearNotaPedidoService: { | 671 | crearNotaPedidoService: { |
672 | getNumeroNotaPedido: function() { | 672 | getNumeroNotaPedido: function() { |
673 | return { | 673 | return { |
674 | then: function() { } | 674 | then: function() { } |
675 | }; | 675 | }; |
676 | }, | 676 | }, |
677 | getBotonera: function() { }, | 677 | getBotonera: function() { }, |
678 | getCotizacionByIdMoneda: function() { | 678 | getCotizacionByIdMoneda: function() { |
679 | return { | 679 | return { |
680 | then: function() { } | 680 | then: function() { } |
681 | }; | 681 | }; |
682 | } | 682 | } |
683 | }, | 683 | }, |
684 | focaBotoneraLateralService: {}, | 684 | focaBotoneraLateralService: {}, |
685 | focaModalService: focaModalService, | 685 | focaModalService: focaModalService, |
686 | notaPedidoBusinessService: {}, | 686 | notaPedidoBusinessService: {}, |
687 | $rootScope: { | 687 | $rootScope: { |
688 | $on: function() { } | 688 | $on: function() { } |
689 | }, | 689 | }, |
690 | focaSeguimientoService: {}, | 690 | focaSeguimientoService: {}, |
691 | APP: {}, | 691 | APP: {}, |
692 | focaLoginService: {}, | 692 | focaLoginService: {}, |
693 | $localStorage: {} | 693 | $localStorage: {} |
694 | }); | 694 | }); |
695 | scope.notaPedido = { | 695 | scope.notaPedido = { |
696 | vendedor: { NUM: false } | 696 | vendedor: { NUM: false } |
697 | }; | 697 | }; |
698 | 698 | ||
699 | //act | 699 | //act |
700 | spyOn(focaModalService, 'alert'); | 700 | spyOn(focaModalService, 'alert'); |
701 | scope.seleccionarCliente(); | 701 | scope.seleccionarCliente(); |
702 | 702 | ||
703 | //assert | 703 | //assert |
704 | expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor'); | 704 | expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor'); |
705 | }); | 705 | }); |
706 | 706 | ||
707 | it('función seleccionarCliente abre modal', function() { | 707 | it('función seleccionarCliente abre modal', function() { |
708 | //arrange | 708 | //arrange |
709 | var scope = { | 709 | var scope = { |
710 | $watch: function() { }, | 710 | $watch: function() { }, |
711 | $broadcast: function() { } | 711 | $broadcast: function() { } |
712 | }; | 712 | }; |
713 | var uibModal = { | 713 | var uibModal = { |
714 | open: function() { } | 714 | open: function() { } |
715 | }; | 715 | }; |
716 | 716 | ||
717 | $controler('notaPedidoCtrl', { | 717 | $controler('notaPedidoCtrl', { |
718 | $scope: scope, | 718 | $scope: scope, |
719 | $uibModal: uibModal, | 719 | $uibModal: uibModal, |
720 | $location: {}, | 720 | $location: {}, |
721 | $filter: filter, | 721 | $filter: filter, |
722 | $timeout: timeout, | 722 | $timeout: timeout, |
723 | crearNotaPedidoService: { | 723 | crearNotaPedidoService: { |
724 | getNumeroNotaPedido: function() { | 724 | getNumeroNotaPedido: function() { |
725 | return { | 725 | return { |
726 | then: function() { } | 726 | then: function() { } |
727 | }; | 727 | }; |
728 | }, | 728 | }, |
729 | getBotonera: function() { }, | 729 | getBotonera: function() { }, |
730 | getCotizacionByIdMoneda: function() { | 730 | getCotizacionByIdMoneda: function() { |
731 | return { | 731 | return { |
732 | then: function() { } | 732 | then: function() { } |
733 | }; | 733 | }; |
734 | } | 734 | } |
735 | }, | 735 | }, |
736 | focaBotoneraLateralService: {}, | 736 | focaBotoneraLateralService: {}, |
737 | focaModalService: {}, | 737 | focaModalService: {}, |
738 | notaPedidoBusinessService: {}, | 738 | notaPedidoBusinessService: {}, |
739 | $rootScope: { | 739 | $rootScope: { |
740 | $on: function() { } | 740 | $on: function() { } |
741 | }, | 741 | }, |
742 | focaSeguimientoService: {}, | 742 | focaSeguimientoService: {}, |
743 | APP: {}, | 743 | APP: {}, |
744 | focaLoginService: {}, | 744 | focaLoginService: {}, |
745 | $localStorage: {} | 745 | $localStorage: {} |
746 | }); | 746 | }); |
747 | scope.notaPedido = { | 747 | scope.notaPedido = { |
748 | vendedor: { NUM: true } | 748 | vendedor: { NUM: true } |
749 | }; | 749 | }; |
750 | 750 | ||
751 | var respuesta = { result: {then: function() { } } }; | 751 | var respuesta = { result: {then: function() { } } }; |
752 | 752 | ||
753 | //act | 753 | //act |
754 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 754 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
755 | scope.seleccionarCliente(); | 755 | scope.seleccionarCliente(); |
756 | 756 | ||
757 | //assert | 757 | //assert |
758 | expect(uibModal.open).toHaveBeenCalled(); | 758 | expect(uibModal.open).toHaveBeenCalled(); |
759 | }); | 759 | }); |
760 | 760 | ||
761 | it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { | 761 | it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { |
762 | 762 | ||
763 | //arrange | 763 | //arrange |
764 | var scope = { | 764 | var scope = { |
765 | $watch: function() { }, | 765 | $watch: function() { }, |
766 | $broadcast: function() { } | 766 | $broadcast: function() { } |
767 | }; | 767 | }; |
768 | var uibModal = { | 768 | var uibModal = { |
769 | open: function() { } | 769 | open: function() { } |
770 | }; | 770 | }; |
771 | 771 | ||
772 | $controler('notaPedidoCtrl', { | 772 | $controler('notaPedidoCtrl', { |
773 | $scope: scope, | 773 | $scope: scope, |
774 | $uibModal: uibModal, | 774 | $uibModal: uibModal, |
775 | $location: {}, | 775 | $location: {}, |
776 | $filter: filter, | 776 | $filter: filter, |
777 | $timeout: timeout, | 777 | $timeout: timeout, |
778 | crearNotaPedidoService: { | 778 | crearNotaPedidoService: { |
779 | getNumeroNotaPedido: function() { | 779 | getNumeroNotaPedido: function() { |
780 | return { | 780 | return { |
781 | then: function() { } | 781 | then: function() { } |
782 | }; | 782 | }; |
783 | }, | 783 | }, |
784 | getBotonera: function() { }, | 784 | getBotonera: function() { }, |
785 | getCotizacionByIdMoneda: function() { | 785 | getCotizacionByIdMoneda: function() { |
786 | return { | 786 | return { |
787 | then: function() { } | 787 | then: function() { } |
788 | }; | 788 | }; |
789 | } | 789 | } |
790 | }, | 790 | }, |
791 | focaBotoneraLateralService: {}, | 791 | focaBotoneraLateralService: {}, |
792 | focaModalService: {}, | 792 | focaModalService: {}, |
793 | notaPedidoBusinessService: {}, | 793 | notaPedidoBusinessService: {}, |
794 | $rootScope: { | 794 | $rootScope: { |
795 | $on: function() { } | 795 | $on: function() { } |
796 | }, | 796 | }, |
797 | focaSeguimientoService: {}, | 797 | focaSeguimientoService: {}, |
798 | APP: {}, | 798 | APP: {}, |
799 | focaLoginService: {}, | 799 | focaLoginService: {}, |
800 | $localStorage: {} | 800 | $localStorage: {} |
801 | }); | 801 | }); |
802 | scope.idLista = true; | 802 | scope.idLista = true; |
803 | scope.notaPedido = { | 803 | scope.notaPedido = { |
804 | vendedor: { NUM: true } | 804 | vendedor: { NUM: true } |
805 | }; | 805 | }; |
806 | var respuesta = {}; | 806 | var respuesta = {}; |
807 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 807 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
808 | 808 | ||
809 | //act | 809 | //act |
810 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 810 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
811 | spyOn(scope, 'abrirModalDomicilios'); | 811 | spyOn(scope, 'abrirModalDomicilios'); |
812 | scope.seleccionarCliente(); | 812 | scope.seleccionarCliente(); |
813 | 813 | ||
814 | //assert | 814 | //assert |
815 | promesaRespuesta.result.then(function() { | 815 | promesaRespuesta.result.then(function() { |
816 | expect(scope.cliente).toEqual(respuesta); | 816 | expect(scope.cliente).toEqual(respuesta); |
817 | expect(scope.abrirModalDomicilios).toHaveBeenCalled(); | 817 | expect(scope.abrirModalDomicilios).toHaveBeenCalled(); |
818 | done(); | 818 | done(); |
819 | }); | 819 | }); |
820 | }); | 820 | }); |
821 | 821 | ||
822 | it('función abrirModalDomicilios abre modal', function() { | 822 | it('función abrirModalDomicilios abre modal', function() { |
823 | //arrange | 823 | //arrange |
824 | var scope = { | 824 | var scope = { |
825 | $watch: function() { }, | 825 | $watch: function() { }, |
826 | $broadcast: function() { } | 826 | $broadcast: function() { } |
827 | }; | 827 | }; |
828 | var uibModal = { | 828 | var uibModal = { |
829 | open: function() { } | 829 | open: function() { } |
830 | }; | 830 | }; |
831 | 831 | ||
832 | $controler('notaPedidoCtrl', { | 832 | $controler('notaPedidoCtrl', { |
833 | $scope: scope, | 833 | $scope: scope, |
834 | $uibModal: uibModal, | 834 | $uibModal: uibModal, |
835 | $location: {}, | 835 | $location: {}, |
836 | $filter: filter, | 836 | $filter: filter, |
837 | $timeout: timeout, | 837 | $timeout: timeout, |
838 | crearNotaPedidoService: { | 838 | crearNotaPedidoService: { |
839 | getNumeroNotaPedido: function() { | 839 | getNumeroNotaPedido: function() { |
840 | return { | 840 | return { |
841 | then: function() { } | 841 | then: function() { } |
842 | }; | 842 | }; |
843 | }, | 843 | }, |
844 | getBotonera: function() { }, | 844 | getBotonera: function() { }, |
845 | getCotizacionByIdMoneda: function() { | 845 | getCotizacionByIdMoneda: function() { |
846 | return { | 846 | return { |
847 | then: function() { } | 847 | then: function() { } |
848 | }; | 848 | }; |
849 | } | 849 | } |
850 | }, | 850 | }, |
851 | focaBotoneraLateralService: {}, | 851 | focaBotoneraLateralService: {}, |
852 | focaModalService: {}, | 852 | focaModalService: {}, |
853 | notaPedidoBusinessService: {}, | 853 | notaPedidoBusinessService: {}, |
854 | $rootScope: { | 854 | $rootScope: { |
855 | $on: function() { } | 855 | $on: function() { } |
856 | }, | 856 | }, |
857 | focaSeguimientoService: {}, | 857 | focaSeguimientoService: {}, |
858 | APP: {}, | 858 | APP: {}, |
859 | focaLoginService: {}, | 859 | focaLoginService: {}, |
860 | $localStorage: {} | 860 | $localStorage: {} |
861 | }); | 861 | }); |
862 | 862 | ||
863 | var respuesta = { result: {then: function() { } } }; | 863 | var respuesta = { result: {then: function() { } } }; |
864 | 864 | ||
865 | //act | 865 | //act |
866 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 866 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
867 | scope.abrirModalDomicilios(); | 867 | scope.abrirModalDomicilios(); |
868 | 868 | ||
869 | //assert | 869 | //assert |
870 | expect(uibModal.open).toHaveBeenCalled(); | 870 | expect(uibModal.open).toHaveBeenCalled(); |
871 | }); | 871 | }); |
872 | 872 | ||
873 | it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { | 873 | it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { |
874 | 874 | ||
875 | //arrange | 875 | //arrange |
876 | var scope = { | 876 | var scope = { |
877 | $watch: function() { }, | 877 | $watch: function() { }, |
878 | $broadcast: function() { } | 878 | $broadcast: function() { } |
879 | }; | 879 | }; |
880 | var uibModal = { | 880 | var uibModal = { |
881 | open: function() { } | 881 | open: function() { } |
882 | }; | 882 | }; |
883 | 883 | ||
884 | $controler('notaPedidoCtrl', { | 884 | $controler('notaPedidoCtrl', { |
885 | $scope: scope, | 885 | $scope: scope, |
886 | $uibModal: uibModal, | 886 | $uibModal: uibModal, |
887 | $location: {}, | 887 | $location: {}, |
888 | $filter: filter, | 888 | $filter: filter, |
889 | $timeout: timeout, | 889 | $timeout: timeout, |
890 | crearNotaPedidoService: { | 890 | crearNotaPedidoService: { |
891 | getNumeroNotaPedido: function() { | 891 | getNumeroNotaPedido: function() { |
892 | return { | 892 | return { |
893 | then: function() { } | 893 | then: function() { } |
894 | }; | 894 | }; |
895 | }, | 895 | }, |
896 | getBotonera: function() { }, | 896 | getBotonera: function() { }, |
897 | getCotizacionByIdMoneda: function() { | 897 | getCotizacionByIdMoneda: function() { |
898 | return { | 898 | return { |
899 | then: function() { } | 899 | then: function() { } |
900 | }; | 900 | }; |
901 | }, | 901 | }, |
902 | getPuntosDescargaByClienDom: function() { | 902 | getPuntosDescargaByClienDom: function() { |
903 | return { | 903 | return { |
904 | then: function() { } | 904 | then: function() { } |
905 | }; | 905 | }; |
906 | } | 906 | } |
907 | }, | 907 | }, |
908 | focaBotoneraLateralService: {}, | 908 | focaBotoneraLateralService: {}, |
909 | focaModalService: {}, | 909 | focaModalService: {}, |
910 | notaPedidoBusinessService: {}, | 910 | notaPedidoBusinessService: {}, |
911 | $rootScope: { | 911 | $rootScope: { |
912 | $on: function() { } | 912 | $on: function() { } |
913 | }, | 913 | }, |
914 | focaSeguimientoService: {}, | 914 | focaSeguimientoService: {}, |
915 | APP: {}, | 915 | APP: {}, |
916 | focaLoginService: {}, | 916 | focaLoginService: {}, |
917 | $localStorage: {} | 917 | $localStorage: {} |
918 | }); | 918 | }); |
919 | scope.idLista = true; | 919 | scope.idLista = true; |
920 | scope.notaPedido = { | 920 | scope.notaPedido = { |
921 | vendedor: { NUM: true } | 921 | vendedor: { NUM: true } |
922 | }; | 922 | }; |
923 | var respuesta = {}; | 923 | var respuesta = {}; |
924 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 924 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
925 | scope.$broadcast = function() { }; | 925 | scope.$broadcast = function() { }; |
926 | var cliente = { | 926 | var cliente = { |
927 | COD: undefined, | 927 | COD: undefined, |
928 | CUIT: undefined, | 928 | CUIT: undefined, |
929 | NOM: undefined | 929 | NOM: undefined |
930 | }; | 930 | }; |
931 | 931 | ||
932 | //act | 932 | //act |
933 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 933 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
934 | spyOn(scope, '$broadcast'); | 934 | spyOn(scope, '$broadcast'); |
935 | scope.abrirModalDomicilios({ }); | 935 | scope.abrirModalDomicilios({ }); |
936 | 936 | ||
937 | //assert | 937 | //assert |
938 | promesaRespuesta.result.then(function() { | 938 | promesaRespuesta.result.then(function() { |
939 | expect(scope.notaPedido.domicilio).toEqual(respuesta); | 939 | expect(scope.notaPedido.domicilio).toEqual(respuesta); |
940 | expect(scope.notaPedido.cliente).toEqual(cliente); | 940 | expect(scope.notaPedido.cliente).toEqual(cliente); |
941 | expect(scope.$broadcast).toHaveBeenCalled(); | 941 | expect(scope.$broadcast).toHaveBeenCalled(); |
942 | done(); | 942 | done(); |
943 | }); | 943 | }); |
944 | }); | 944 | }); |
945 | 945 | ||
946 | it('función getTotal devulve correctamente', function() { | 946 | it('función getTotal devulve correctamente', function() { |
947 | 947 | ||
948 | //arrange | 948 | //arrange |
949 | var scope = { | 949 | var scope = { |
950 | $watch: function() { }, | 950 | $watch: function() { }, |
951 | $broadcast: function() { } | 951 | $broadcast: function() { } |
952 | }; | 952 | }; |
953 | 953 | ||
954 | $controler('notaPedidoCtrl', { | 954 | $controler('notaPedidoCtrl', { |
955 | $scope: scope, | 955 | $scope: scope, |
956 | $uibModal: {}, | 956 | $uibModal: {}, |
957 | $location: {}, | 957 | $location: {}, |
958 | $filter: filter, | 958 | $filter: filter, |
959 | $timeout: timeout, | 959 | $timeout: timeout, |
960 | crearNotaPedidoService: { | 960 | crearNotaPedidoService: { |
961 | getNumeroNotaPedido: function() { | 961 | getNumeroNotaPedido: function() { |
962 | return { | 962 | return { |
963 | then: function() { } | 963 | then: function() { } |
964 | }; | 964 | }; |
965 | }, | 965 | }, |
966 | getBotonera: function() { }, | 966 | getBotonera: function() { }, |
967 | getCotizacionByIdMoneda: function() { | 967 | getCotizacionByIdMoneda: function() { |
968 | return { | 968 | return { |
969 | then: function() { } | 969 | then: function() { } |
970 | }; | 970 | }; |
971 | } | 971 | } |
972 | }, | 972 | }, |
973 | focaBotoneraLateralService: {}, | 973 | focaBotoneraLateralService: {}, |
974 | focaModalService: {}, | 974 | focaModalService: {}, |
975 | notaPedidoBusinessService: {}, | 975 | notaPedidoBusinessService: {}, |
976 | $rootScope: { | 976 | $rootScope: { |
977 | $on: function() { } | 977 | $on: function() { } |
978 | }, | 978 | }, |
979 | focaSeguimientoService: {}, | 979 | focaSeguimientoService: {}, |
980 | APP: {}, | 980 | APP: {}, |
981 | focaLoginService: {}, | 981 | focaLoginService: {}, |
982 | $localStorage: {} | 982 | $localStorage: {} |
983 | }); | 983 | }); |
984 | scope.idLista = true; | 984 | scope.idLista = true; |
985 | scope.notaPedido = { | 985 | scope.notaPedido = { |
986 | vendedor: { NUM: true } | 986 | vendedor: { NUM: true } |
987 | }; | 987 | }; |
988 | 988 | ||
989 | //act | 989 | //act |
990 | scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; | 990 | scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; |
991 | var esperado = 2; | 991 | var esperado = 2; |
992 | var resultado = scope.getTotal(); | 992 | var resultado = scope.getTotal(); |
993 | console.log('resultado', resultado); | ||
994 | 993 | ||
995 | //assert | 994 | //assert |
996 | expect(resultado).toEqual(esperado); | 995 | expect(resultado).toEqual(esperado); |
997 | }); | 996 | }); |
998 | 997 | ||
999 | it('función getSubTotal devulve correctamente', function() { | 998 | it('función getSubTotal devulve correctamente', function() { |
1000 | 999 | ||
1001 | //arrange | 1000 | //arrange |
1002 | var scope = { | 1001 | var scope = { |
1003 | $watch: function() { }, | 1002 | $watch: function() { }, |
1004 | $broadcast: function() { } | 1003 | $broadcast: function() { } |
1005 | }; | 1004 | }; |
1006 | 1005 | ||
1007 | $controler('notaPedidoCtrl', { | 1006 | $controler('notaPedidoCtrl', { |
1008 | $scope: scope, | 1007 | $scope: scope, |
1009 | $uibModal: {}, | 1008 | $uibModal: {}, |
1010 | $location: {}, | 1009 | $location: {}, |
1011 | $filter: filter, | 1010 | $filter: filter, |
1012 | $timeout: timeout, | 1011 | $timeout: timeout, |
1013 | crearNotaPedidoService: { | 1012 | crearNotaPedidoService: { |
1014 | getNumeroNotaPedido: function() { | 1013 | getNumeroNotaPedido: function() { |
1015 | return { | 1014 | return { |
1016 | then: function() { } | 1015 | then: function() { } |
1017 | }; | 1016 | }; |
1018 | }, | 1017 | }, |
1019 | getBotonera: function() { }, | 1018 | getBotonera: function() { }, |
1020 | getCotizacionByIdMoneda: function() { | 1019 | getCotizacionByIdMoneda: function() { |
1021 | return { | 1020 | return { |
1022 | then: function() { } | 1021 | then: function() { } |
1023 | }; | 1022 | }; |
1024 | } | 1023 | } |
1025 | }, | 1024 | }, |
1026 | focaBotoneraLateralService: {}, | 1025 | focaBotoneraLateralService: {}, |
1027 | focaModalService: {}, | 1026 | focaModalService: {}, |
1028 | notaPedidoBusinessService: {}, | 1027 | notaPedidoBusinessService: {}, |
1029 | $rootScope: { | 1028 | $rootScope: { |
1030 | $on: function() { } | 1029 | $on: function() { } |
1031 | }, | 1030 | }, |
1032 | focaSeguimientoService: {}, | 1031 | focaSeguimientoService: {}, |
1033 | APP: {}, | 1032 | APP: {}, |
1034 | focaLoginService: {}, | 1033 | focaLoginService: {}, |
1035 | $localStorage: {} | 1034 | $localStorage: {} |
1036 | }); | 1035 | }); |
1037 | scope.idLista = true; | 1036 | scope.idLista = true; |
1038 | scope.notaPedido = { | 1037 | scope.notaPedido = { |
1039 | vendedor: { NUM: true } | 1038 | vendedor: { NUM: true } |
1040 | }; | 1039 | }; |
1041 | 1040 | ||
1042 | //act | 1041 | //act |
1043 | scope.articuloACargar = { precio: 2, cantidad: 1}; | 1042 | scope.articuloACargar = { precio: 2, cantidad: 1}; |
1044 | var esperado = 2; | 1043 | var esperado = 2; |
1045 | var resultado = scope.getSubTotal(); | 1044 | var resultado = scope.getSubTotal(); |
1046 | 1045 | ||
1047 | //assert | 1046 | //assert |
1048 | expect(resultado).toEqual(esperado); | 1047 | expect(resultado).toEqual(esperado); |
1049 | }); | 1048 | }); |
1050 | 1049 | ||
1051 | it('función seleccionarPreciosYCondiciones abre modal', function() { | 1050 | it('función seleccionarPreciosYCondiciones abre modal', function() { |
1052 | 1051 | ||
1053 | //arrange | 1052 | //arrange |
1054 | var scope = { | 1053 | var scope = { |
1055 | $watch: function() { }, | 1054 | $watch: function() { }, |
1056 | $broadcast: function() { } | 1055 | $broadcast: function() { } |
1057 | }; | 1056 | }; |
1058 | var uibModal = { | 1057 | var uibModal = { |
1059 | open: function() { } | 1058 | open: function() { } |
1060 | }; | 1059 | }; |
1061 | 1060 | ||
1062 | $controler('notaPedidoCtrl', { | 1061 | $controler('notaPedidoCtrl', { |
1063 | $scope: scope, | 1062 | $scope: scope, |
1064 | $uibModal: uibModal, | 1063 | $uibModal: uibModal, |
1065 | $location: {}, | 1064 | $location: {}, |
1066 | $filter: filter, | 1065 | $filter: filter, |
1067 | $timeout: timeout, | 1066 | $timeout: timeout, |
1068 | crearNotaPedidoService: { | 1067 | crearNotaPedidoService: { |
1069 | getNumeroNotaPedido: function() { | 1068 | getNumeroNotaPedido: function() { |
1070 | return { | 1069 | return { |
1071 | then: function() { } | 1070 | then: function() { } |
1072 | }; | 1071 | }; |
1073 | }, | 1072 | }, |
1074 | getBotonera: function() { }, | 1073 | getBotonera: function() { }, |
1075 | getCotizacionByIdMoneda: function() { | 1074 | getCotizacionByIdMoneda: function() { |
1076 | return { | 1075 | return { |
1077 | then: function() { } | 1076 | then: function() { } |
1078 | }; | 1077 | }; |
1079 | } | 1078 | } |
1080 | }, | 1079 | }, |
1081 | focaBotoneraLateralService: {}, | 1080 | focaBotoneraLateralService: {}, |
1082 | focaModalService: {}, | 1081 | focaModalService: {}, |
1083 | notaPedidoBusinessService: {}, | 1082 | notaPedidoBusinessService: {}, |
1084 | $rootScope: { | 1083 | $rootScope: { |
1085 | $on: function() { } | 1084 | $on: function() { } |
1086 | }, | 1085 | }, |
1087 | focaSeguimientoService: {}, | 1086 | focaSeguimientoService: {}, |
1088 | APP: {}, | 1087 | APP: {}, |
1089 | focaLoginService: {}, | 1088 | focaLoginService: {}, |
1090 | $localStorage: {} | 1089 | $localStorage: {} |
1091 | }); | 1090 | }); |
1092 | 1091 | ||
1093 | scope.notaPedido = {}; | 1092 | scope.notaPedido = {}; |
1094 | 1093 | ||
1095 | var respuesta = { result: {then: function() { } } }; | 1094 | var respuesta = { result: {then: function() { } } }; |
1096 | 1095 | ||
1097 | //act | 1096 | //act |
1098 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 1097 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
1099 | scope.seleccionarPreciosYCondiciones(); | 1098 | scope.seleccionarPreciosYCondiciones(); |
1100 | 1099 | ||
1101 | //assert | 1100 | //assert |
1102 | expect(uibModal.open).toHaveBeenCalled(); | 1101 | expect(uibModal.open).toHaveBeenCalled(); |
1103 | }); | 1102 | }); |
1104 | 1103 | ||
1105 | it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { | 1104 | it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { |
1106 | 1105 | ||
1107 | //arrange | 1106 | //arrange |
1108 | var scope = { | 1107 | var scope = { |
1109 | $watch: function() { }, | 1108 | $watch: function() { }, |
1110 | $broadcast: function() { } | 1109 | $broadcast: function() { } |
1111 | }; | 1110 | }; |
1112 | var uibModal = { | 1111 | var uibModal = { |
1113 | open: function() { } | 1112 | open: function() { } |
1114 | }; | 1113 | }; |
1115 | 1114 | ||
1116 | $controler('notaPedidoCtrl', { | 1115 | $controler('notaPedidoCtrl', { |
1117 | $scope: scope, | 1116 | $scope: scope, |
1118 | $uibModal: uibModal, | 1117 | $uibModal: uibModal, |
1119 | $location: {}, | 1118 | $location: {}, |
1120 | $filter: filter, | 1119 | $filter: filter, |
1121 | $timeout: timeout, | 1120 | $timeout: timeout, |
1122 | crearNotaPedidoService: { | 1121 | crearNotaPedidoService: { |
1123 | getNumeroNotaPedido: function() { | 1122 | getNumeroNotaPedido: function() { |
1124 | return { | 1123 | return { |
1125 | then: function() { } | 1124 | then: function() { } |
1126 | }; | 1125 | }; |
1127 | }, | 1126 | }, |
1128 | getBotonera: function() { }, | 1127 | getBotonera: function() { }, |
1129 | getCotizacionByIdMoneda: function() { | 1128 | getCotizacionByIdMoneda: function() { |
1130 | return { | 1129 | return { |
1131 | then: function() { } | 1130 | then: function() { } |
1132 | }; | 1131 | }; |
1133 | } | 1132 | } |
1134 | }, | 1133 | }, |
1135 | focaBotoneraLateralService: {}, | 1134 | focaBotoneraLateralService: {}, |
1136 | focaModalService: {}, | 1135 | focaModalService: {}, |
1137 | notaPedidoBusinessService: {}, | 1136 | notaPedidoBusinessService: {}, |
1138 | $rootScope: { | 1137 | $rootScope: { |
1139 | $on: function() { } | 1138 | $on: function() { } |
1140 | }, | 1139 | }, |
1141 | focaSeguimientoService: {}, | 1140 | focaSeguimientoService: {}, |
1142 | APP: {}, | 1141 | APP: {}, |
1143 | focaLoginService: {}, | 1142 | focaLoginService: {}, |
1144 | $localStorage: {} | 1143 | $localStorage: {} |
1145 | }); | 1144 | }); |
1146 | scope.idLista = true; | 1145 | scope.idLista = true; |
1147 | scope.notaPedido = { | 1146 | scope.notaPedido = { |
1148 | vendedor: { NUM: true } | 1147 | vendedor: { NUM: true } |
1149 | }; | 1148 | }; |
1150 | var respuesta = { plazoPago: { } }; | 1149 | var respuesta = { plazoPago: { } }; |
1151 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 1150 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
1152 | scope.$broadcast = function() { }; | 1151 | scope.$broadcast = function() { }; |
1153 | 1152 | ||
1154 | //act | 1153 | //act |
1155 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 1154 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
1156 | spyOn(scope, '$broadcast'); | 1155 | spyOn(scope, '$broadcast'); |
1157 | scope.seleccionarPreciosYCondiciones(); | 1156 | scope.seleccionarPreciosYCondiciones(); |
1158 | 1157 | ||
1159 | //assert | 1158 | //assert |
1160 | promesaRespuesta.result.then(function() { | 1159 | promesaRespuesta.result.then(function() { |
1161 | expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); | 1160 | expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); |
1162 | expect(scope.$broadcast).toHaveBeenCalled(); | 1161 | expect(scope.$broadcast).toHaveBeenCalled(); |
1163 | done(); | 1162 | done(); |
1164 | }); | 1163 | }); |
1165 | }); | 1164 | }); |
1166 | 1165 | ||
1167 | it('función seleccionarFlete abre modal', function() { | 1166 | it('función seleccionarFlete abre modal', function() { |
1168 | 1167 | ||
1169 | //arrange | 1168 | //arrange |
1170 | var scope = { | 1169 | var scope = { |
1171 | $watch: function() { }, | 1170 | $watch: function() { }, |
1172 | $broadcast: function() { } | 1171 | $broadcast: function() { } |
1173 | }; | 1172 | }; |
1174 | var uibModal = { | 1173 | var uibModal = { |
1175 | open: function() { } | 1174 | open: function() { } |
1176 | }; | 1175 | }; |
1177 | 1176 | ||
1178 | $controler('notaPedidoCtrl', { | 1177 | $controler('notaPedidoCtrl', { |
1179 | $scope: scope, | 1178 | $scope: scope, |
1180 | $uibModal: uibModal, | 1179 | $uibModal: uibModal, |
1181 | $location: {}, | 1180 | $location: {}, |
1182 | $filter: filter, | 1181 | $filter: filter, |
1183 | $timeout: timeout, | 1182 | $timeout: timeout, |
1184 | crearNotaPedidoService: { | 1183 | crearNotaPedidoService: { |
1185 | getNumeroNotaPedido: function() { | 1184 | getNumeroNotaPedido: function() { |
1186 | return { | 1185 | return { |
1187 | then: function() { } | 1186 | then: function() { } |
1188 | }; | 1187 | }; |
1189 | }, | 1188 | }, |
1190 | getBotonera: function() { }, | 1189 | getBotonera: function() { }, |
1191 | getCotizacionByIdMoneda: function() { | 1190 | getCotizacionByIdMoneda: function() { |
1192 | return { | 1191 | return { |
1193 | then: function() { } | 1192 | then: function() { } |
1194 | }; | 1193 | }; |
1195 | } | 1194 | } |
1196 | }, | 1195 | }, |
1197 | focaBotoneraLateralService: {}, | 1196 | focaBotoneraLateralService: {}, |
1198 | focaModalService: {}, | 1197 | focaModalService: {}, |
1199 | notaPedidoBusinessService: {}, | 1198 | notaPedidoBusinessService: {}, |
1200 | $rootScope: { | 1199 | $rootScope: { |
1201 | $on: function() { } | 1200 | $on: function() { } |
1202 | }, | 1201 | }, |
1203 | focaSeguimientoService: {}, | 1202 | focaSeguimientoService: {}, |
1204 | APP: {}, | 1203 | APP: {}, |
1205 | focaLoginService: {}, | 1204 | focaLoginService: {}, |
1206 | $localStorage: {} | 1205 | $localStorage: {} |
1207 | }); | 1206 | }); |
1208 | 1207 | ||
1209 | scope.notaPedido = {}; | 1208 | scope.notaPedido = {}; |
1210 | 1209 | ||
1211 | var respuesta = { result: {then: function() { } } }; | 1210 | var respuesta = { result: {then: function() { } } }; |
1212 | 1211 | ||
1213 | //act | 1212 | //act |
1214 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 1213 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
1215 | scope.seleccionarFlete(); | 1214 | scope.seleccionarFlete(); |
1216 | 1215 | ||
1217 | //assert | 1216 | //assert |
1218 | expect(uibModal.open).toHaveBeenCalled(); | 1217 | expect(uibModal.open).toHaveBeenCalled(); |
1219 | }); | 1218 | }); |
1220 | 1219 | ||
1221 | it('función seleccionarFlete setea flete y cabecera', function(done) { | 1220 | it('función seleccionarFlete setea flete y cabecera', function(done) { |
1222 | 1221 | ||
1223 | //arrange | 1222 | //arrange |
1224 | var scope = { | 1223 | var scope = { |
1225 | $watch: function() { }, | 1224 | $watch: function() { }, |
1226 | $broadcast: function() { } | 1225 | $broadcast: function() { } |
1227 | }; | 1226 | }; |
1228 | var uibModal = { | 1227 | var uibModal = { |
1229 | open: function() { } | 1228 | open: function() { } |
1230 | }; | 1229 | }; |
1231 | 1230 | ||
1232 | $controler('notaPedidoCtrl', { | 1231 | $controler('notaPedidoCtrl', { |
1233 | $scope: scope, | 1232 | $scope: scope, |
1234 | $uibModal: uibModal, | 1233 | $uibModal: uibModal, |
1235 | $location: {}, | 1234 | $location: {}, |
1236 | $filter: filter, | 1235 | $filter: filter, |
1237 | $timeout: timeout, | 1236 | $timeout: timeout, |
1238 | crearNotaPedidoService: { | 1237 | crearNotaPedidoService: { |
1239 | getNumeroNotaPedido: function() { | 1238 | getNumeroNotaPedido: function() { |
1240 | return { | 1239 | return { |
1241 | then: function() { } | 1240 | then: function() { } |
1242 | }; | 1241 | }; |
1243 | }, | 1242 | }, |
1244 | getBotonera: function() { }, | 1243 | getBotonera: function() { }, |
1245 | getCotizacionByIdMoneda: function() { | 1244 | getCotizacionByIdMoneda: function() { |
1246 | return { | 1245 | return { |
1247 | then: function() { } | 1246 | then: function() { } |
1248 | }; | 1247 | }; |
1249 | } | 1248 | } |
1250 | }, | 1249 | }, |
1251 | focaBotoneraLateralService: {}, | 1250 | focaBotoneraLateralService: {}, |
1252 | focaModalService: {}, | 1251 | focaModalService: {}, |
1253 | notaPedidoBusinessService: {}, | 1252 | notaPedidoBusinessService: {}, |
1254 | $rootScope: { | 1253 | $rootScope: { |
1255 | $on: function() { } | 1254 | $on: function() { } |
1256 | }, | 1255 | }, |
1257 | focaSeguimientoService: {}, | 1256 | focaSeguimientoService: {}, |
1258 | APP: {}, | 1257 | APP: {}, |
1259 | focaLoginService: {}, | 1258 | focaLoginService: {}, |
1260 | $localStorage: {} | 1259 | $localStorage: {} |
1261 | }); | 1260 | }); |
1262 | scope.idLista = true; | 1261 | scope.idLista = true; |
1263 | scope.notaPedido = { | 1262 | scope.notaPedido = { |
1264 | vendedor: { NUM: true } | 1263 | vendedor: { NUM: true } |
1265 | }; | 1264 | }; |
1266 | var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 }; | 1265 | var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 }; |
1267 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 1266 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
1268 | scope.$broadcast = function() { }; | 1267 | scope.$broadcast = function() { }; |
1269 | 1268 | ||
1270 | //act | 1269 | //act |
1271 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 1270 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
1272 | spyOn(scope, '$broadcast'); | 1271 | spyOn(scope, '$broadcast'); |
1273 | scope.seleccionarFlete(); | 1272 | scope.seleccionarFlete(); |
1274 | 1273 | ||
1275 | //assert | 1274 | //assert |
1276 | 1275 | ||
1277 | promesaRespuesta.result.then(function() { | 1276 | promesaRespuesta.result.then(function() { |
1278 | expect(scope.notaPedido.flete).toEqual(respuesta.flete); | 1277 | expect(scope.notaPedido.flete).toEqual(respuesta.flete); |
1279 | expect(scope.notaPedido.fob).toEqual(respuesta.FOB); | 1278 | expect(scope.notaPedido.fob).toEqual(respuesta.FOB); |
1280 | expect(scope.notaPedido.bomba).toEqual(respuesta.bomba); | 1279 | expect(scope.notaPedido.bomba).toEqual(respuesta.bomba); |
1281 | expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros); | 1280 | expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros); |
1282 | expect(scope.$broadcast).toHaveBeenCalled(); | 1281 | expect(scope.$broadcast).toHaveBeenCalled(); |
1283 | done(); | 1282 | done(); |
1284 | }); | 1283 | }); |
1285 | }); | 1284 | }); |
1286 | 1285 | ||
1287 | it('función seleccionarMoneda abre modal', function() { | 1286 | it('función seleccionarMoneda abre modal', function() { |
1288 | //arrange | 1287 | //arrange |
1289 | var scope = { | 1288 | var scope = { |
1290 | $watch: function() { }, | 1289 | $watch: function() { }, |
1291 | $broadcast: function() { } | 1290 | $broadcast: function() { } |
1292 | }; | 1291 | }; |
1293 | var focaModalService = { | 1292 | var focaModalService = { |
1294 | modal: function() { } | 1293 | modal: function() { } |
1295 | }; | 1294 | }; |
1296 | 1295 | ||
1297 | $controler('notaPedidoCtrl', { | 1296 | $controler('notaPedidoCtrl', { |
1298 | $scope: scope, | 1297 | $scope: scope, |
1299 | $uibModal: {}, | 1298 | $uibModal: {}, |
1300 | $location: {}, | 1299 | $location: {}, |
1301 | $filter: filter, | 1300 | $filter: filter, |
1302 | $timeout: timeout, | 1301 | $timeout: timeout, |
1303 | crearNotaPedidoService: { | 1302 | crearNotaPedidoService: { |
1304 | getNumeroNotaPedido: function() { | 1303 | getNumeroNotaPedido: function() { |
1305 | return { | 1304 | return { |
1306 | then: function() { } | 1305 | then: function() { } |
1307 | }; | 1306 | }; |
1308 | }, | 1307 | }, |
1309 | getBotonera: function() { }, | 1308 | getBotonera: function() { }, |
1310 | getCotizacionByIdMoneda: function() { | 1309 | getCotizacionByIdMoneda: function() { |
1311 | return { | 1310 | return { |
1312 | then: function() { } | 1311 | then: function() { } |
1313 | }; | 1312 | }; |
1314 | } | 1313 | } |
1315 | }, | 1314 | }, |
1316 | focaBotoneraLateralService: {}, | 1315 | focaBotoneraLateralService: {}, |
1317 | focaModalService: focaModalService, | 1316 | focaModalService: focaModalService, |
1318 | notaPedidoBusinessService: {}, | 1317 | notaPedidoBusinessService: {}, |
1319 | $rootScope: { | 1318 | $rootScope: { |
1320 | $on: function() { } | 1319 | $on: function() { } |
1321 | }, | 1320 | }, |
1322 | focaSeguimientoService: {}, | 1321 | focaSeguimientoService: {}, |
1323 | APP: {}, | 1322 | APP: {}, |
1324 | focaLoginService: {}, | 1323 | focaLoginService: {}, |
1325 | $localStorage: {} | 1324 | $localStorage: {} |
1326 | }); | 1325 | }); |
1327 | scope.notaPedido = {}; | 1326 | scope.notaPedido = {}; |
1328 | 1327 | ||
1329 | var respuesta = { then: function() { } }; | 1328 | var respuesta = { then: function() { } }; |
1330 | 1329 | ||
1331 | //act | 1330 | //act |
1332 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 1331 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
1333 | scope.seleccionarMoneda(); | 1332 | scope.seleccionarMoneda(); |
1334 | 1333 | ||
1335 | //assert | 1334 | //assert |
1336 | expect(focaModalService.modal).toHaveBeenCalled(); | 1335 | expect(focaModalService.modal).toHaveBeenCalled(); |
1337 | }); | 1336 | }); |
1338 | 1337 | ||
1339 | it('función seleccionarMoneda llama Modal Cotizacion', function(done) { | 1338 | it('función seleccionarMoneda llama Modal Cotizacion', function(done) { |
1340 | //arrange | 1339 | //arrange |
1341 | var scope = { | 1340 | var scope = { |
1342 | $watch: function() { }, | 1341 | $watch: function() { }, |
1343 | $broadcast: function() { } | 1342 | $broadcast: function() { } |
1344 | }; | 1343 | }; |
1345 | var focaModalService = { | 1344 | var focaModalService = { |
1346 | modal: function() { } | 1345 | modal: function() { } |
1347 | }; | 1346 | }; |
1348 | 1347 | ||
1349 | $controler('notaPedidoCtrl', { | 1348 | $controler('notaPedidoCtrl', { |
1350 | $scope: scope, | 1349 | $scope: scope, |
1351 | $uibModal: {}, | 1350 | $uibModal: {}, |
1352 | $location: {}, | 1351 | $location: {}, |
1353 | $filter: filter, | 1352 | $filter: filter, |
1354 | $timeout: timeout, | 1353 | $timeout: timeout, |
1355 | crearNotaPedidoService: { | 1354 | crearNotaPedidoService: { |
1356 | getNumeroNotaPedido: function() { | 1355 | getNumeroNotaPedido: function() { |
1357 | return { | 1356 | return { |
1358 | then: function() { } | 1357 | then: function() { } |
1359 | }; | 1358 | }; |
1360 | }, | 1359 | }, |
1361 | getBotonera: function() { }, | 1360 | getBotonera: function() { }, |
1362 | getCotizacionByIdMoneda: function() { | 1361 | getCotizacionByIdMoneda: function() { |
1363 | return { | 1362 | return { |
1364 | then: function() { } | 1363 | then: function() { } |
1365 | }; | 1364 | }; |
1366 | } | 1365 | } |
1367 | }, | 1366 | }, |
1368 | focaBotoneraLateralService: {}, | 1367 | focaBotoneraLateralService: {}, |
1369 | focaModalService: focaModalService, | 1368 | focaModalService: focaModalService, |
1370 | notaPedidoBusinessService: {}, | 1369 | notaPedidoBusinessService: {}, |
1371 | $rootScope: { | 1370 | $rootScope: { |
1372 | $on: function() { } | 1371 | $on: function() { } |
1373 | }, | 1372 | }, |
1374 | focaSeguimientoService: {}, | 1373 | focaSeguimientoService: {}, |
1375 | APP: {}, | 1374 | APP: {}, |
1376 | focaLoginService: {}, | 1375 | focaLoginService: {}, |
1377 | $localStorage: {} | 1376 | $localStorage: {} |
1378 | }); | 1377 | }); |
1379 | 1378 | ||
1380 | scope.notaPedido = {}; | 1379 | scope.notaPedido = {}; |
1381 | var respuesta = 'test'; | 1380 | var respuesta = 'test'; |
1382 | var promesaRespuesta = Promise.resolve(respuesta); | 1381 | var promesaRespuesta = Promise.resolve(respuesta); |
1383 | 1382 | ||
1384 | //act | 1383 | //act |
1385 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 1384 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
1386 | spyOn(scope, 'abrirModalCotizacion'); | 1385 | spyOn(scope, 'abrirModalCotizacion'); |
1387 | scope.seleccionarMoneda(); | 1386 | scope.seleccionarMoneda(); |
1388 | 1387 | ||
1389 | //assert | 1388 | //assert |
1390 | promesaRespuesta.then(function() { | 1389 | promesaRespuesta.then(function() { |
1391 | expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); | 1390 | expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); |
1392 | done(); | 1391 | done(); |
1393 | }); | 1392 | }); |
1394 | }); | 1393 | }); |
1395 | 1394 | ||
1396 | it('función seleccionarObservaciones llama a prompt', function() { | 1395 | it('función seleccionarObservaciones llama a prompt', function() { |
1397 | 1396 | ||
1398 | //arrange | 1397 | //arrange |
1399 | var scope = { | 1398 | var scope = { |
1400 | $watch: function() { }, | 1399 | $watch: function() { }, |
1401 | $broadcast: function() { } | 1400 | $broadcast: function() { } |
1402 | }; | 1401 | }; |
1403 | var focaModalService = { | 1402 | var focaModalService = { |
1404 | prompt: function() { } | 1403 | prompt: function() { } |
1405 | }; | 1404 | }; |
1406 | 1405 | ||
1407 | $controler('notaPedidoCtrl', { | 1406 | $controler('notaPedidoCtrl', { |
1408 | $scope: scope, | 1407 | $scope: scope, |
1409 | $uibModal: {}, | 1408 | $uibModal: {}, |
1410 | $location: {}, | 1409 | $location: {}, |
1411 | $filter: filter, | 1410 | $filter: filter, |
1412 | $timeout: timeout, | 1411 | $timeout: timeout, |
1413 | crearNotaPedidoService: { | 1412 | crearNotaPedidoService: { |
1414 | getNumeroNotaPedido: function() { | 1413 | getNumeroNotaPedido: function() { |
1415 | return { | 1414 | return { |
1416 | then: function() { } | 1415 | then: function() { } |
1417 | }; | 1416 | }; |
1418 | }, | 1417 | }, |
1419 | getBotonera: function() { }, | 1418 | getBotonera: function() { }, |
1420 | getCotizacionByIdMoneda: function() { | 1419 | getCotizacionByIdMoneda: function() { |
1421 | return { | 1420 | return { |
1422 | then: function() { } | 1421 | then: function() { } |
1423 | }; | 1422 | }; |
1424 | } | 1423 | } |
1425 | }, | 1424 | }, |
1426 | focaBotoneraLateralService: {}, | 1425 | focaBotoneraLateralService: {}, |
1427 | focaModalService: focaModalService, | 1426 | focaModalService: focaModalService, |
1428 | notaPedidoBusinessService: {}, | 1427 | notaPedidoBusinessService: {}, |
1429 | $rootScope: { | 1428 | $rootScope: { |
1430 | $on: function() { } | 1429 | $on: function() { } |
1431 | }, | 1430 | }, |
1432 | focaSeguimientoService: {}, | 1431 | focaSeguimientoService: {}, |
1433 | APP: {}, | 1432 | APP: {}, |
1434 | focaLoginService: {}, | 1433 | focaLoginService: {}, |
1435 | $localStorage: {} | 1434 | $localStorage: {} |
1436 | }); | 1435 | }); |
1437 | var respuesta = { then: function() { } }; | 1436 | var respuesta = { then: function() { } }; |
1438 | scope.notaPedido = {}; | 1437 | scope.notaPedido = {}; |
1439 | 1438 | ||
1440 | //act | 1439 | //act |
1441 | spyOn(focaModalService, 'prompt').and.returnValue(respuesta); | 1440 | spyOn(focaModalService, 'prompt').and.returnValue(respuesta); |
1442 | scope.seleccionarObservaciones(); | 1441 | scope.seleccionarObservaciones(); |
1443 | 1442 | ||
1444 | //assert | 1443 | //assert |
1445 | expect(focaModalService.prompt).toHaveBeenCalled(); | 1444 | expect(focaModalService.prompt).toHaveBeenCalled(); |
1446 | }); | 1445 | }); |
1447 | 1446 | ||
1448 | it('función seleccionarObservaciones setea observaciones', function(done) { | 1447 | it('función seleccionarObservaciones setea observaciones', function(done) { |
1449 | 1448 | ||
1450 | //arrange | 1449 | //arrange |
1451 | var scope = { | 1450 | var scope = { |
1452 | $watch: function() { }, | 1451 | $watch: function() { }, |
1453 | $broadcast: function() { } | 1452 | $broadcast: function() { } |
1454 | }; | 1453 | }; |
1455 | var focaModalService = { | 1454 | var focaModalService = { |
1456 | prompt: function() { } | 1455 | prompt: function() { } |
1457 | }; | 1456 | }; |
1458 | 1457 | ||
1459 | $controler('notaPedidoCtrl', { | 1458 | $controler('notaPedidoCtrl', { |
1460 | $scope: scope, | 1459 | $scope: scope, |
1461 | $uibModal: {}, | 1460 | $uibModal: {}, |
1462 | $location: {}, | 1461 | $location: {}, |
1463 | $filter: filter, | 1462 | $filter: filter, |
1464 | $timeout: timeout, | 1463 | $timeout: timeout, |
1465 | crearNotaPedidoService: { | 1464 | crearNotaPedidoService: { |
1466 | getNumeroNotaPedido: function() { | 1465 | getNumeroNotaPedido: function() { |
1467 | return { | 1466 | return { |
1468 | then: function() { } | 1467 | then: function() { } |
1469 | }; | 1468 | }; |
1470 | }, | 1469 | }, |
1471 | getBotonera: function() { }, | 1470 | getBotonera: function() { }, |
1472 | getCotizacionByIdMoneda: function() { | 1471 | getCotizacionByIdMoneda: function() { |
1473 | return { | 1472 | return { |
1474 | then: function() { } | 1473 | then: function() { } |
1475 | }; | 1474 | }; |
1476 | } | 1475 | } |
1477 | }, | 1476 | }, |
1478 | focaBotoneraLateralService: {}, | 1477 | focaBotoneraLateralService: {}, |
1479 | focaModalService: focaModalService, | 1478 | focaModalService: focaModalService, |
1480 | notaPedidoBusinessService: {}, | 1479 | notaPedidoBusinessService: {}, |
1481 | $rootScope: { | 1480 | $rootScope: { |
1482 | $on: function() { } | 1481 | $on: function() { } |
1483 | }, | 1482 | }, |
1484 | focaSeguimientoService: {}, | 1483 | focaSeguimientoService: {}, |
1485 | APP: {}, | 1484 | APP: {}, |
1486 | focaLoginService: {}, | 1485 | focaLoginService: {}, |
1487 | $localStorage: {} | 1486 | $localStorage: {} |
1488 | }); | 1487 | }); |
1489 | var respuesta = 'unit test'; | 1488 | var respuesta = 'unit test'; |
1490 | var promesa = Promise.resolve(respuesta); | 1489 | var promesa = Promise.resolve(respuesta); |
1491 | scope.notaPedido = {}; | 1490 | scope.notaPedido = {}; |
1492 | 1491 | ||
1493 | //act | 1492 | //act |
1494 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); | 1493 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); |
1495 | scope.seleccionarObservaciones(); | 1494 | scope.seleccionarObservaciones(); |
1496 | 1495 | ||
1497 | //assert | 1496 | //assert |
1498 | promesa.then(function() { | 1497 | promesa.then(function() { |
1499 | expect(scope.notaPedido.observaciones).toEqual(respuesta); | 1498 | expect(scope.notaPedido.observaciones).toEqual(respuesta); |
1500 | done(); | 1499 | done(); |
1501 | }); | 1500 | }); |
1502 | }); | 1501 | }); |
1503 | 1502 | ||
1504 | it('función abrirModalCotizacion abre modal', function() { | 1503 | it('función abrirModalCotizacion abre modal', function() { |
1505 | 1504 | ||
1506 | //arrange | 1505 | //arrange |
1507 | var scope = { | 1506 | var scope = { |
1508 | $watch: function() { }, | 1507 | $watch: function() { }, |
1509 | $broadcast: function() { } | 1508 | $broadcast: function() { } |
1510 | }; | 1509 | }; |
1511 | var uibModal = { | 1510 | var uibModal = { |
1512 | open: function() { } | 1511 | open: function() { } |
1513 | }; | 1512 | }; |
1514 | 1513 | ||
1515 | $controler('notaPedidoCtrl', { | 1514 | $controler('notaPedidoCtrl', { |
1516 | $scope: scope, | 1515 | $scope: scope, |
1517 | $uibModal: uibModal, | 1516 | $uibModal: uibModal, |
1518 | $location: {}, | 1517 | $location: {}, |
1519 | $filter: filter, | 1518 | $filter: filter, |
1520 | $timeout: timeout, | 1519 | $timeout: timeout, |
1521 | crearNotaPedidoService: { | 1520 | crearNotaPedidoService: { |
1522 | getNumeroNotaPedido: function() { | 1521 | getNumeroNotaPedido: function() { |
1523 | return { | 1522 | return { |
1524 | then: function() { } | 1523 | then: function() { } |
1525 | }; | 1524 | }; |
1526 | }, | 1525 | }, |
1527 | getBotonera: function() { }, | 1526 | getBotonera: function() { }, |
1528 | getCotizacionByIdMoneda: function() { | 1527 | getCotizacionByIdMoneda: function() { |
1529 | return { | 1528 | return { |
1530 | then: function() { } | 1529 | then: function() { } |
1531 | }; | 1530 | }; |
1532 | } | 1531 | } |
1533 | }, | 1532 | }, |
1534 | focaBotoneraLateralService: {}, | 1533 | focaBotoneraLateralService: {}, |
1535 | focaModalService: {}, | 1534 | focaModalService: {}, |
1536 | notaPedidoBusinessService: {}, | 1535 | notaPedidoBusinessService: {}, |
1537 | $rootScope: { | 1536 | $rootScope: { |
1538 | $on: function() { } | 1537 | $on: function() { } |
1539 | }, | 1538 | }, |
1540 | focaSeguimientoService: {}, | 1539 | focaSeguimientoService: {}, |
1541 | APP: {}, | 1540 | APP: {}, |
1542 | focaLoginService: {}, | 1541 | focaLoginService: {}, |
1543 | $localStorage: {} | 1542 | $localStorage: {} |
1544 | }); | 1543 | }); |
1545 | 1544 | ||
1546 | scope.notaPedido = {}; | 1545 | scope.notaPedido = {}; |
1547 | 1546 | ||
1548 | var respuesta = { result: {then: function() { } } }; | 1547 | var respuesta = { result: {then: function() { } } }; |
1549 | 1548 | ||
1550 | //act | 1549 | //act |
1551 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 1550 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
1552 | scope.abrirModalCotizacion(); | 1551 | scope.abrirModalCotizacion(); |
1553 | 1552 | ||
1554 | //assert | 1553 | //assert |
1555 | expect(uibModal.open).toHaveBeenCalled(); | 1554 | expect(uibModal.open).toHaveBeenCalled(); |
1556 | }); | 1555 | }); |
1557 | 1556 | ||
1558 | it('función abrirModalCotizacion setea datos y cabecera', function(done) { | 1557 | it('función abrirModalCotizacion setea datos y cabecera', function(done) { |
1559 | //arrange | 1558 | //arrange |
1560 | var scope = { | 1559 | var scope = { |
1561 | $watch: function() { }, | 1560 | $watch: function() { }, |
1562 | $broadcast: function() { } | 1561 | $broadcast: function() { } |
1563 | }; | 1562 | }; |
1564 | var uibModal = { | 1563 | var uibModal = { |
1565 | open: function() { } | 1564 | open: function() { } |
1566 | }; | 1565 | }; |
1567 | 1566 | ||
1568 | $controler('notaPedidoCtrl', { | 1567 | $controler('notaPedidoCtrl', { |
1569 | $scope: scope, | 1568 | $scope: scope, |
1570 | $uibModal: uibModal, | 1569 | $uibModal: uibModal, |
1571 | $location: {}, | 1570 | $location: {}, |
1572 | $filter: filter, | 1571 | $filter: filter, |
1573 | $timeout: timeout, | 1572 | $timeout: timeout, |
1574 | crearNotaPedidoService: { | 1573 | crearNotaPedidoService: { |
1575 | getNumeroNotaPedido: function() { | 1574 | getNumeroNotaPedido: function() { |
1576 | return { | 1575 | return { |
1577 | then: function() { } | 1576 | then: function() { } |
1578 | }; | 1577 | }; |
1579 | }, | 1578 | }, |
1580 | getBotonera: function() { }, | 1579 | getBotonera: function() { }, |
1581 | getCotizacionByIdMoneda: function() { | 1580 | getCotizacionByIdMoneda: function() { |
1582 | return { | 1581 | return { |
1583 | then: function() { } | 1582 | then: function() { } |
1584 | }; | 1583 | }; |
1585 | } | 1584 | } |
1586 | }, | 1585 | }, |
1587 | focaBotoneraLateralService: {}, | 1586 | focaBotoneraLateralService: {}, |
1588 | focaModalService: {}, | 1587 | focaModalService: {}, |
1589 | notaPedidoBusinessService: {}, | 1588 | notaPedidoBusinessService: {}, |
1590 | $rootScope: { | 1589 | $rootScope: { |
1591 | $on: function() { } | 1590 | $on: function() { } |
1592 | }, | 1591 | }, |
1593 | focaSeguimientoService: {}, | 1592 | focaSeguimientoService: {}, |
1594 | APP: {}, | 1593 | APP: {}, |
1595 | focaLoginService: {}, | 1594 | focaLoginService: {}, |
1596 | $localStorage: {}, | 1595 | $localStorage: {}, |
1597 | articulosNotaPedido: [] | 1596 | articulosNotaPedido: [] |
1598 | }); | 1597 | }); |
1599 | 1598 | ||
1600 | scope.notaPedido = {}; | 1599 | scope.notaPedido = {}; |
1601 | scope.articulosTabla = []; | 1600 | scope.articulosTabla = []; |
1602 | scope.$broadcast = function() { }; | 1601 | scope.$broadcast = function() { }; |
1603 | var moneda = 'moneda'; | 1602 | var moneda = 'moneda'; |
1604 | var cotizacion = 'test'; | 1603 | var cotizacion = 'test'; |
1605 | var promesaRespuesta = { result: Promise.resolve(cotizacion) }; | 1604 | var promesaRespuesta = { result: Promise.resolve(cotizacion) }; |
1606 | 1605 | ||
1607 | //act | 1606 | //act |
1608 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 1607 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
1609 | spyOn(scope, '$broadcast'); | 1608 | spyOn(scope, '$broadcast'); |
1610 | scope.abrirModalCotizacion(moneda); | 1609 | scope.abrirModalCotizacion(moneda); |
1611 | 1610 | ||
1612 | //assert | 1611 | //assert |
1613 | promesaRespuesta.result.then(function() { | 1612 | promesaRespuesta.result.then(function() { |
1614 | 1613 | ||
1615 | expect(scope.$broadcast).toHaveBeenCalled(); | 1614 | expect(scope.$broadcast).toHaveBeenCalled(); |
1616 | expect(scope.notaPedido.cotizacion).toEqual(cotizacion); | 1615 | expect(scope.notaPedido.cotizacion).toEqual(cotizacion); |
1617 | done(); | 1616 | done(); |
1618 | }); | 1617 | }); |
1619 | }); | 1618 | }); |
1620 | 1619 | ||
1621 | it('función agregarATabla muestra alerta cuando a cargar undefined', function() { | 1620 | it('función agregarATabla muestra alerta cuando a cargar undefined', function() { |
1622 | 1621 | ||
1623 | //arrange | 1622 | //arrange |
1624 | var scope = { | 1623 | var scope = { |
1625 | $watch: function() { }, | 1624 | $watch: function() { }, |
1626 | $broadcast: function() { } | 1625 | $broadcast: function() { } |
1627 | }; | 1626 | }; |
1628 | var focaModalService = { | 1627 | var focaModalService = { |
1629 | alert: function() { } | 1628 | alert: function() { } |
1630 | }; | 1629 | }; |
1631 | 1630 | ||
1632 | $controler('notaPedidoCtrl', { | 1631 | $controler('notaPedidoCtrl', { |
1633 | $scope: scope, | 1632 | $scope: scope, |
1634 | $uibModal: {}, | 1633 | $uibModal: {}, |
1635 | $location: {}, | 1634 | $location: {}, |
1636 | $filter: filter, | 1635 | $filter: filter, |
1637 | $timeout: timeout, | 1636 | $timeout: timeout, |
1638 | crearNotaPedidoService: { | 1637 | crearNotaPedidoService: { |
1639 | getNumeroNotaPedido: function() { | 1638 | getNumeroNotaPedido: function() { |
1640 | return { | 1639 | return { |
1641 | then: function() { } | 1640 | then: function() { } |
1642 | }; | 1641 | }; |
1643 | }, | 1642 | }, |
1644 | getBotonera: function() { }, | 1643 | getBotonera: function() { }, |
1645 | getCotizacionByIdMoneda: function() { | 1644 | getCotizacionByIdMoneda: function() { |
1646 | return { | 1645 | return { |
1647 | then: function() { } | 1646 | then: function() { } |
1648 | }; | 1647 | }; |
1649 | } | 1648 | } |
1650 | }, | 1649 | }, |
1651 | focaBotoneraLateralService: {}, | 1650 | focaBotoneraLateralService: {}, |
1652 | focaModalService: focaModalService, | 1651 | focaModalService: focaModalService, |
1653 | notaPedidoBusinessService: {}, | 1652 | notaPedidoBusinessService: {}, |
1654 | $rootScope: { | 1653 | $rootScope: { |
1655 | $on: function() { } | 1654 | $on: function() { } |
1656 | }, | 1655 | }, |
1657 | focaSeguimientoService: {}, | 1656 | focaSeguimientoService: {}, |
1658 | APP: {}, | 1657 | APP: {}, |
1659 | focaLoginService: {}, | 1658 | focaLoginService: {}, |
1660 | $localStorage: {} | 1659 | $localStorage: {} |
1661 | }); | 1660 | }); |
1662 | scope.articuloACargar = {}; | 1661 | scope.articuloACargar = {}; |
1663 | 1662 | ||
1664 | //act | 1663 | //act |
1665 | spyOn(focaModalService, 'alert'); | 1664 | spyOn(focaModalService, 'alert'); |
1666 | scope.agregarATabla(13); | 1665 | scope.agregarATabla(13); |
1667 | 1666 | ||
1668 | //assert | 1667 | //assert |
1669 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); | 1668 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); |
1670 | }); | 1669 | }); |
1671 | 1670 | ||
1672 | it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { | 1671 | it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { |
1673 | 1672 | ||
1674 | //arrange | 1673 | //arrange |
1675 | var scope = { | 1674 | var scope = { |
1676 | $watch: function() { }, | 1675 | $watch: function() { }, |
1677 | $broadcast: function() { } | 1676 | $broadcast: function() { } |
1678 | }; | 1677 | }; |
1679 | var focaModalService = { | 1678 | var focaModalService = { |
1680 | alert: function() { } | 1679 | alert: function() { } |
1681 | }; | 1680 | }; |
1682 | 1681 | ||
1683 | $controler('notaPedidoCtrl', { | 1682 | $controler('notaPedidoCtrl', { |
1684 | $scope: scope, | 1683 | $scope: scope, |
1685 | $uibModal: {}, | 1684 | $uibModal: {}, |
1686 | $location: {}, | 1685 | $location: {}, |
1687 | $filter: filter, | 1686 | $filter: filter, |
1688 | $timeout: timeout, | 1687 | $timeout: timeout, |
1689 | crearNotaPedidoService: { | 1688 | crearNotaPedidoService: { |
1690 | getNumeroNotaPedido: function() { | 1689 | getNumeroNotaPedido: function() { |
1691 | return { | 1690 | return { |
1692 | then: function() { } | 1691 | then: function() { } |
1693 | }; | 1692 | }; |
1694 | }, | 1693 | }, |
1695 | getBotonera: function() { }, | 1694 | getBotonera: function() { }, |
1696 | getCotizacionByIdMoneda: function() { | 1695 | getCotizacionByIdMoneda: function() { |
1697 | return { | 1696 | return { |
1698 | then: function() { } | 1697 | then: function() { } |
1699 | }; | 1698 | }; |
1700 | } | 1699 | } |
1701 | }, | 1700 | }, |
1702 | focaBotoneraLateralService: {}, | 1701 | focaBotoneraLateralService: {}, |
1703 | focaModalService: focaModalService, | 1702 | focaModalService: focaModalService, |
1704 | notaPedidoBusinessService: {}, | 1703 | notaPedidoBusinessService: {}, |
1705 | $rootScope: { | 1704 | $rootScope: { |
1706 | $on: function() { } | 1705 | $on: function() { } |
1707 | }, | 1706 | }, |
1708 | focaSeguimientoService: {}, | 1707 | focaSeguimientoService: {}, |
1709 | APP: {}, | 1708 | APP: {}, |
1710 | focaLoginService: {}, | 1709 | focaLoginService: {}, |
1711 | $localStorage: {} | 1710 | $localStorage: {} |
1712 | }); | 1711 | }); |
1713 | scope.articuloACargar = {}; | 1712 | scope.articuloACargar = {}; |
1714 | 1713 | ||
1715 | //act | 1714 | //act |
1716 | spyOn(focaModalService, 'alert'); | 1715 | spyOn(focaModalService, 'alert'); |
1717 | scope.agregarATabla(13); | 1716 | scope.agregarATabla(13); |
1718 | 1717 | ||
1719 | //assert | 1718 | //assert |
1720 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); | 1719 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); |
1721 | }); | 1720 | }); |
1722 | 1721 | ||
1723 | it('función salir lleva a ruta correcta', function() { | 1722 | it('función salir lleva a ruta correcta', function() { |
1724 | 1723 | ||
1725 | inject(function($location) { | 1724 | inject(function($location) { |
1726 | 1725 | ||
1727 | //arrange | 1726 | //arrange |
1728 | var scope = { | 1727 | var scope = { |
1729 | $watch: function() { }, | 1728 | $watch: function() { }, |
1730 | $broadcast: function() { } | 1729 | $broadcast: function() { } |
1731 | }; | 1730 | }; |
1732 | 1731 | ||
1733 | $controler('notaPedidoCtrl', { | 1732 | $controler('notaPedidoCtrl', { |
1734 | $scope: scope, | 1733 | $scope: scope, |
1735 | $uibModal: {}, | 1734 | $uibModal: {}, |
1736 | $location: $location, | 1735 | $location: $location, |
1737 | $filter: filter, | 1736 | $filter: filter, |
1738 | $timeout: timeout, | 1737 | $timeout: timeout, |
1739 | crearNotaPedidoService: { | 1738 | crearNotaPedidoService: { |
1740 | getNumeroNotaPedido: function() { | 1739 | getNumeroNotaPedido: function() { |
1741 | return { | 1740 | return { |
1742 | then: function() { } | 1741 | then: function() { } |
1743 | }; | 1742 | }; |
1744 | }, | 1743 | }, |
1745 | getBotonera: function() { }, | 1744 | getBotonera: function() { }, |
1746 | getCotizacionByIdMoneda: function() { | 1745 | getCotizacionByIdMoneda: function() { |
1747 | return { | 1746 | return { |
1748 | then: function() { } | 1747 | then: function() { } |
1749 | }; | 1748 | }; |
1750 | } | 1749 | } |
1751 | }, | 1750 | }, |
1752 | focaBotoneraLateralService: {}, | 1751 | focaBotoneraLateralService: {}, |
1753 | focaModalService: {}, | 1752 | focaModalService: {}, |
1754 | notaPedidoBusinessService: {}, | 1753 | notaPedidoBusinessService: {}, |
1755 | $rootScope: { | 1754 | $rootScope: { |
1756 | $on: function() { } | 1755 | $on: function() { } |
1757 | }, | 1756 | }, |
1758 | focaSeguimientoService: {}, | 1757 | focaSeguimientoService: {}, |
1759 | APP: {}, | 1758 | APP: {}, |
1760 | focaLoginService: {}, | 1759 | focaLoginService: {}, |
1761 | $localStorage: {}, | 1760 | $localStorage: {}, |
1762 | }); | 1761 | }); |
1763 | 1762 | ||
1764 | //act | 1763 | //act |
1765 | scope.salir(); | 1764 | scope.salir(); |
1766 | 1765 | ||
1767 | //assert | 1766 | //assert |
1768 | expect($location.url()).toEqual('/'); | 1767 | expect($location.url()).toEqual('/'); |
1769 | }); | 1768 | }); |
1770 | }); | 1769 | }); |
1771 | }); | 1770 | }); |
1772 | }); | 1771 | }); |
1773 | 1772 |
spec/controllerSpecCrearPedido.js
1 | describe('Controladores módulo crear nota de pedido', function() { | 1 | describe('Controladores módulo crear nota de pedido', function() { |
2 | 2 | ||
3 | var $controler; | 3 | var $controler; |
4 | 4 | ||
5 | beforeEach(function() { | 5 | beforeEach(function() { |
6 | module('focaCrearNotaPedido'); | 6 | module('focaCrearNotaPedido'); |
7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
8 | $controler = _$controller_; | 8 | $controler = _$controller_; |
9 | }); | 9 | }); |
10 | }); | 10 | }); |
11 | 11 | ||
12 | describe('Controlador notaPedidoCtrl crear nota de pedido', function() { | 12 | describe('Controlador notaPedidoCtrl crear nota de pedido', function() { |
13 | 13 | ||
14 | var filter = function() { | 14 | var filter = function() { |
15 | return function() { }; | 15 | return function() { }; |
16 | }; | 16 | }; |
17 | var timeout; | 17 | var timeout; |
18 | 18 | ||
19 | beforeEach(function() { | 19 | beforeEach(function() { |
20 | 20 | ||
21 | inject(function($timeout) { | 21 | inject(function($timeout) { |
22 | timeout = $timeout; | 22 | timeout = $timeout; |
23 | }); | 23 | }); |
24 | }); | 24 | }); |
25 | 25 | ||
26 | it('Existe el controlador notaPedidoCtrl', function() { | 26 | it('Existe el controlador notaPedidoCtrl', function() { |
27 | 27 | ||
28 | //act | 28 | //act |
29 | var controlador = $controler('notaPedidoCtrl', { | 29 | var controlador = $controler('notaPedidoCtrl', { |
30 | $scope: { | 30 | $scope: { |
31 | $watch: function() { }, | 31 | $watch: function() { }, |
32 | $broadcast: function() {} | 32 | $broadcast: function() {} |
33 | }, | 33 | }, |
34 | $uibModal: {}, | 34 | $uibModal: {}, |
35 | $location: {}, | 35 | $location: {}, |
36 | $filter: filter, | 36 | $filter: filter, |
37 | $timeout: timeout, | 37 | $timeout: timeout, |
38 | crearNotaPedidoService: { | 38 | crearNotaPedidoService: { |
39 | getNumeroNotaPedido: function() { | 39 | getNumeroNotaPedido: function() { |
40 | return { | 40 | return { |
41 | then: function() { } | 41 | then: function() { } |
42 | }; | 42 | }; |
43 | }, | 43 | }, |
44 | getBotonera: function() { }, | 44 | getBotonera: function() { }, |
45 | getCotizacionByIdMoneda: function() { | 45 | getCotizacionByIdMoneda: function() { |
46 | return { | 46 | return { |
47 | then: function() {} | 47 | then: function() {} |
48 | }; | 48 | }; |
49 | } | 49 | } |
50 | }, | 50 | }, |
51 | focaBotoneraLateralService: {}, | 51 | focaBotoneraLateralService: {}, |
52 | focaModalService: {}, | 52 | focaModalService: {}, |
53 | notaPedidoBusinessService: {}, | 53 | notaPedidoBusinessService: {}, |
54 | $rootScope: { | 54 | $rootScope: { |
55 | $on: function() { } | 55 | $on: function() { } |
56 | }, | 56 | }, |
57 | focaSeguimientoService: {}, | 57 | focaSeguimientoService: {}, |
58 | APP: {}, | 58 | APP: {}, |
59 | focaLoginService: {}, | 59 | focaLoginService: {}, |
60 | $localStorage: {} | 60 | $localStorage: {} |
61 | }); | 61 | }); |
62 | 62 | ||
63 | //expect | 63 | //expect |
64 | expect(typeof controlador).toEqual('object'); | 64 | expect(typeof controlador).toEqual('object'); |
65 | }); | 65 | }); |
66 | 66 | ||
67 | it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() { | 67 | it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() { |
68 | 68 | ||
69 | //arrange | 69 | //arrange |
70 | var scope = { | 70 | var scope = { |
71 | $watch: function() { }, | 71 | $watch: function() { }, |
72 | $broadcast: function() {} | 72 | $broadcast: function() {} |
73 | }; | 73 | }; |
74 | var focaModalService = { | 74 | var focaModalService = { |
75 | alert: function() { } | 75 | alert: function() { } |
76 | }; | 76 | }; |
77 | 77 | ||
78 | $controler('notaPedidoCtrl', { | 78 | $controler('notaPedidoCtrl', { |
79 | $scope: scope, | 79 | $scope: scope, |
80 | $uibModal: {}, | 80 | $uibModal: {}, |
81 | $location: {}, | 81 | $location: {}, |
82 | $filter: filter, | 82 | $filter: filter, |
83 | $timeout: timeout, | 83 | $timeout: timeout, |
84 | crearNotaPedidoService: { | 84 | crearNotaPedidoService: { |
85 | getNumeroNotaPedido: function() { | 85 | getNumeroNotaPedido: function() { |
86 | return { | 86 | return { |
87 | then: function() { } | 87 | then: function() { } |
88 | }; | 88 | }; |
89 | }, | 89 | }, |
90 | getBotonera: function() { }, | 90 | getBotonera: function() { }, |
91 | getCotizacionByIdMoneda: function() { | 91 | getCotizacionByIdMoneda: function() { |
92 | return { | 92 | return { |
93 | then: function() {} | 93 | then: function() {} |
94 | }; | 94 | }; |
95 | } | 95 | } |
96 | }, | 96 | }, |
97 | focaBotoneraLateralService: {}, | 97 | focaBotoneraLateralService: {}, |
98 | focaModalService: focaModalService, | 98 | focaModalService: focaModalService, |
99 | notaPedidoBusinessService: {}, | 99 | notaPedidoBusinessService: {}, |
100 | $rootScope: { | 100 | $rootScope: { |
101 | $on: function() { } | 101 | $on: function() { } |
102 | }, | 102 | }, |
103 | focaSeguimientoService: {}, | 103 | focaSeguimientoService: {}, |
104 | APP: {}, | 104 | APP: {}, |
105 | focaLoginService: {}, | 105 | focaLoginService: {}, |
106 | $localStorage: {}, | 106 | $localStorage: {}, |
107 | $watch: function() { }, | 107 | $watch: function() { }, |
108 | $broadcast: function() {} | 108 | $broadcast: function() {} |
109 | }); | 109 | }); |
110 | 110 | ||
111 | //act | 111 | //act |
112 | scope.notaPedido = { | 112 | scope.notaPedido = { |
113 | vendedor: { | 113 | vendedor: { |
114 | id: null | 114 | id: null |
115 | } | 115 | } |
116 | }; | 116 | }; |
117 | spyOn(focaModalService, 'alert'); | 117 | spyOn(focaModalService, 'alert'); |
118 | scope.crearNotaPedido(); | 118 | scope.crearNotaPedido(); |
119 | 119 | ||
120 | //expect | 120 | //expect |
121 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor'); | 121 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor'); |
122 | }); | 122 | }); |
123 | 123 | ||
124 | it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { | 124 | it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { |
125 | 125 | ||
126 | //arrange | 126 | //arrange |
127 | var scope = { | 127 | var scope = { |
128 | $watch: function() { }, | 128 | $watch: function() { }, |
129 | $broadcast: function() {} | 129 | $broadcast: function() {} |
130 | }; | 130 | }; |
131 | var focaModalService = { | 131 | var focaModalService = { |
132 | alert: function() { } | 132 | alert: function() { } |
133 | }; | 133 | }; |
134 | 134 | ||
135 | $controler('notaPedidoCtrl', { | 135 | $controler('notaPedidoCtrl', { |
136 | $scope: scope, | 136 | $scope: scope, |
137 | $uibModal: {}, | 137 | $uibModal: {}, |
138 | $location: {}, | 138 | $location: {}, |
139 | $filter: filter, | 139 | $filter: filter, |
140 | $timeout: timeout, | 140 | $timeout: timeout, |
141 | crearNotaPedidoService: { | 141 | crearNotaPedidoService: { |
142 | getNumeroNotaPedido: function() { | 142 | getNumeroNotaPedido: function() { |
143 | return { | 143 | return { |
144 | then: function() { } | 144 | then: function() { } |
145 | }; | 145 | }; |
146 | }, | 146 | }, |
147 | getBotonera: function() { }, | 147 | getBotonera: function() { }, |
148 | getCotizacionByIdMoneda: function() { | 148 | getCotizacionByIdMoneda: function() { |
149 | return { | 149 | return { |
150 | then: function() {} | 150 | then: function() {} |
151 | }; | 151 | }; |
152 | } | 152 | } |
153 | }, | 153 | }, |
154 | focaBotoneraLateralService: {}, | 154 | focaBotoneraLateralService: {}, |
155 | focaModalService: focaModalService, | 155 | focaModalService: focaModalService, |
156 | notaPedidoBusinessService: {}, | 156 | notaPedidoBusinessService: {}, |
157 | $rootScope: { | 157 | $rootScope: { |
158 | $on: function() { } | 158 | $on: function() { } |
159 | }, | 159 | }, |
160 | focaSeguimientoService: {}, | 160 | focaSeguimientoService: {}, |
161 | APP: {}, | 161 | APP: {}, |
162 | focaLoginService: {}, | 162 | focaLoginService: {}, |
163 | $localStorage: {}, | 163 | $localStorage: {}, |
164 | $watch: function() { }, | 164 | $watch: function() { }, |
165 | $broadcast: function() {} | 165 | $broadcast: function() {} |
166 | }); | 166 | }); |
167 | 167 | ||
168 | scope.notaPedido = { | 168 | scope.notaPedido = { |
169 | vendedor: { | 169 | vendedor: { |
170 | id: true | 170 | id: true |
171 | }, | 171 | }, |
172 | cliente:{ | 172 | cliente:{ |
173 | COD: false | 173 | COD: false |
174 | } | 174 | } |
175 | }; | 175 | }; |
176 | 176 | ||
177 | //act | 177 | //act |
178 | spyOn(focaModalService, 'alert'); | 178 | spyOn(focaModalService, 'alert'); |
179 | scope.crearNotaPedido(); | 179 | scope.crearNotaPedido(); |
180 | 180 | ||
181 | //expect | 181 | //expect |
182 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); | 182 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); |
183 | }); | 183 | }); |
184 | 184 | ||
185 | it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { | 185 | it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { |
186 | 186 | ||
187 | //arrange | 187 | //arrange |
188 | var scope = { | 188 | var scope = { |
189 | $watch: function() { }, | 189 | $watch: function() { }, |
190 | $broadcast: function() {} | 190 | $broadcast: function() {} |
191 | }; | 191 | }; |
192 | var focaModalService = { | 192 | var focaModalService = { |
193 | alert: function() { } | 193 | alert: function() { } |
194 | }; | 194 | }; |
195 | 195 | ||
196 | $controler('notaPedidoCtrl', { | 196 | $controler('notaPedidoCtrl', { |
197 | $scope: scope, | 197 | $scope: scope, |
198 | $uibModal: {}, | 198 | $uibModal: {}, |
199 | $location: {}, | 199 | $location: {}, |
200 | $filter: filter, | 200 | $filter: filter, |
201 | $timeout: timeout, | 201 | $timeout: timeout, |
202 | crearNotaPedidoService: { | 202 | crearNotaPedidoService: { |
203 | getNumeroNotaPedido: function() { | 203 | getNumeroNotaPedido: function() { |
204 | return { | 204 | return { |
205 | then: function() { } | 205 | then: function() { } |
206 | }; | 206 | }; |
207 | }, | 207 | }, |
208 | getBotonera: function() { }, | 208 | getBotonera: function() { }, |
209 | getCotizacionByIdMoneda: function() { | 209 | getCotizacionByIdMoneda: function() { |
210 | return { | 210 | return { |
211 | then: function() {} | 211 | then: function() {} |
212 | }; | 212 | }; |
213 | } | 213 | } |
214 | }, | 214 | }, |
215 | focaBotoneraLateralService: {}, | 215 | focaBotoneraLateralService: {}, |
216 | focaModalService: focaModalService, | 216 | focaModalService: focaModalService, |
217 | notaPedidoBusinessService: {}, | 217 | notaPedidoBusinessService: {}, |
218 | $rootScope: { | 218 | $rootScope: { |
219 | $on: function() { } | 219 | $on: function() { } |
220 | }, | 220 | }, |
221 | focaSeguimientoService: {}, | 221 | focaSeguimientoService: {}, |
222 | APP: {}, | 222 | APP: {}, |
223 | focaLoginService: {}, | 223 | focaLoginService: {}, |
224 | $localStorage: {}, | 224 | $localStorage: {}, |
225 | $watch: function() { }, | 225 | $watch: function() { }, |
226 | $broadcast: function() {} | 226 | $broadcast: function() {} |
227 | }); | 227 | }); |
228 | 228 | ||
229 | scope.notaPedido = { | 229 | scope.notaPedido = { |
230 | vendedor: { | 230 | vendedor: { |
231 | id: true | 231 | id: true |
232 | }, | 232 | }, |
233 | cliente:{ | 233 | cliente:{ |
234 | COD: true | 234 | COD: true |
235 | }, | 235 | }, |
236 | proveedor:{ | 236 | proveedor:{ |
237 | COD: null | 237 | COD: null |
238 | } | 238 | } |
239 | }; | 239 | }; |
240 | 240 | ||
241 | //act | 241 | //act |
242 | spyOn(focaModalService, 'alert'); | 242 | spyOn(focaModalService, 'alert'); |
243 | scope.crearNotaPedido(); | 243 | scope.crearNotaPedido(); |
244 | 244 | ||
245 | //expect | 245 | //expect |
246 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); | 246 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); |
247 | }); | 247 | }); |
248 | 248 | ||
249 | it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { | 249 | it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { |
250 | 250 | ||
251 | //arrange | 251 | //arrange |
252 | var scope = { | 252 | var scope = { |
253 | $watch: function() { }, | 253 | $watch: function() { }, |
254 | $broadcast: function() {} | 254 | $broadcast: function() {} |
255 | }; | 255 | }; |
256 | var focaModalService = { | 256 | var focaModalService = { |
257 | alert: function() { } | 257 | alert: function() { } |
258 | }; | 258 | }; |
259 | 259 | ||
260 | $controler('notaPedidoCtrl', { | 260 | $controler('notaPedidoCtrl', { |
261 | $scope: scope, | 261 | $scope: scope, |
262 | $uibModal: {}, | 262 | $uibModal: {}, |
263 | $location: {}, | 263 | $location: {}, |
264 | $filter: filter, | 264 | $filter: filter, |
265 | $timeout: timeout, | 265 | $timeout: timeout, |
266 | crearNotaPedidoService: { | 266 | crearNotaPedidoService: { |
267 | getNumeroNotaPedido: function() { | 267 | getNumeroNotaPedido: function() { |
268 | return { | 268 | return { |
269 | then: function() { } | 269 | then: function() { } |
270 | }; | 270 | }; |
271 | }, | 271 | }, |
272 | getBotonera: function() { }, | 272 | getBotonera: function() { }, |
273 | getCotizacionByIdMoneda: function() { | 273 | getCotizacionByIdMoneda: function() { |
274 | return { | 274 | return { |
275 | then: function() {} | 275 | then: function() {} |
276 | }; | 276 | }; |
277 | } | 277 | } |
278 | }, | 278 | }, |
279 | focaBotoneraLateralService: {}, | 279 | focaBotoneraLateralService: {}, |
280 | focaModalService: focaModalService, | 280 | focaModalService: focaModalService, |
281 | notaPedidoBusinessService: {}, | 281 | notaPedidoBusinessService: {}, |
282 | $rootScope: { | 282 | $rootScope: { |
283 | $on: function() { } | 283 | $on: function() { } |
284 | }, | 284 | }, |
285 | focaSeguimientoService: {}, | 285 | focaSeguimientoService: {}, |
286 | APP: {}, | 286 | APP: {}, |
287 | focaLoginService: {}, | 287 | focaLoginService: {}, |
288 | $localStorage: {}, | 288 | $localStorage: {}, |
289 | $watch: function() { }, | 289 | $watch: function() { }, |
290 | $broadcast: function() {} | 290 | $broadcast: function() {} |
291 | }); | 291 | }); |
292 | 292 | ||
293 | scope.notaPedido = { | 293 | scope.notaPedido = { |
294 | vendedor: { | 294 | vendedor: { |
295 | id: true | 295 | id: true |
296 | }, | 296 | }, |
297 | cliente:{ | 297 | cliente:{ |
298 | COD: true | 298 | COD: true |
299 | }, | 299 | }, |
300 | proveedor:{ | 300 | proveedor:{ |
301 | COD: true | 301 | COD: true |
302 | }, | 302 | }, |
303 | cotizacion: { | 303 | cotizacion: { |
304 | ID: true, | 304 | ID: true, |
305 | moneda:{ | 305 | moneda:{ |
306 | ID: null | 306 | ID: null |
307 | } | 307 | } |
308 | } | 308 | } |
309 | }; | 309 | }; |
310 | 310 | ||
311 | //act | 311 | //act |
312 | spyOn(focaModalService, 'alert'); | 312 | spyOn(focaModalService, 'alert'); |
313 | scope.crearNotaPedido(); | 313 | scope.crearNotaPedido(); |
314 | 314 | ||
315 | //expect | 315 | //expect |
316 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); | 316 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); |
317 | }); | 317 | }); |
318 | 318 | ||
319 | it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { | 319 | it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { |
320 | 320 | ||
321 | //arrange | 321 | //arrange |
322 | var scope = { | 322 | var scope = { |
323 | $watch: function() { }, | 323 | $watch: function() { }, |
324 | $broadcast: function() {} | 324 | $broadcast: function() {} |
325 | }; | 325 | }; |
326 | var focaModalService = { | 326 | var focaModalService = { |
327 | alert: function() { } | 327 | alert: function() { } |
328 | }; | 328 | }; |
329 | 329 | ||
330 | $controler('notaPedidoCtrl', { | 330 | $controler('notaPedidoCtrl', { |
331 | $scope: scope, | 331 | $scope: scope, |
332 | $uibModal: {}, | 332 | $uibModal: {}, |
333 | $location: {}, | 333 | $location: {}, |
334 | $filter: filter, | 334 | $filter: filter, |
335 | $timeout: timeout, | 335 | $timeout: timeout, |
336 | crearNotaPedidoService: { | 336 | crearNotaPedidoService: { |
337 | getNumeroNotaPedido: function() { | 337 | getNumeroNotaPedido: function() { |
338 | return { | 338 | return { |
339 | then: function() { } | 339 | then: function() { } |
340 | }; | 340 | }; |
341 | }, | 341 | }, |
342 | getBotonera: function() { }, | 342 | getBotonera: function() { }, |
343 | getCotizacionByIdMoneda: function() { | 343 | getCotizacionByIdMoneda: function() { |
344 | return { | 344 | return { |
345 | then: function() {} | 345 | then: function() {} |
346 | }; | 346 | }; |
347 | } | 347 | } |
348 | }, | 348 | }, |
349 | focaBotoneraLateralService: {}, | 349 | focaBotoneraLateralService: {}, |
350 | focaModalService: focaModalService, | 350 | focaModalService: focaModalService, |
351 | notaPedidoBusinessService: {}, | 351 | notaPedidoBusinessService: {}, |
352 | $rootScope: { | 352 | $rootScope: { |
353 | $on: function() { } | 353 | $on: function() { } |
354 | }, | 354 | }, |
355 | focaSeguimientoService: {}, | 355 | focaSeguimientoService: {}, |
356 | APP: {}, | 356 | APP: {}, |
357 | focaLoginService: {}, | 357 | focaLoginService: {}, |
358 | $localStorage: {}, | 358 | $localStorage: {}, |
359 | $watch: function() { }, | 359 | $watch: function() { }, |
360 | $broadcast: function() {} | 360 | $broadcast: function() {} |
361 | }); | 361 | }); |
362 | 362 | ||
363 | scope.notaPedido = { | 363 | scope.notaPedido = { |
364 | vendedor: { | 364 | vendedor: { |
365 | id: true | 365 | id: true |
366 | }, | 366 | }, |
367 | cliente:{ | 367 | cliente:{ |
368 | COD: true | 368 | COD: true |
369 | }, | 369 | }, |
370 | proveedor:{ | 370 | proveedor:{ |
371 | COD: true | 371 | COD: true |
372 | }, | 372 | }, |
373 | cotizacion:{ | 373 | cotizacion:{ |
374 | ID: null, | 374 | ID: null, |
375 | moneda: { | 375 | moneda: { |
376 | ID: true | 376 | ID: true |
377 | } | 377 | } |
378 | } | 378 | } |
379 | }; | 379 | }; |
380 | 380 | ||
381 | //act | 381 | //act |
382 | spyOn(focaModalService, 'alert'); | 382 | spyOn(focaModalService, 'alert'); |
383 | scope.crearNotaPedido(); | 383 | scope.crearNotaPedido(); |
384 | 384 | ||
385 | //expect | 385 | //expect |
386 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); | 386 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); |
387 | }); | 387 | }); |
388 | 388 | ||
389 | it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { | 389 | it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { |
390 | 390 | ||
391 | //arrange | 391 | //arrange |
392 | var scope = { | 392 | var scope = { |
393 | $watch: function() { }, | 393 | $watch: function() { }, |
394 | $broadcast: function() {} | 394 | $broadcast: function() {} |
395 | }; | 395 | }; |
396 | var focaModalService = { | 396 | var focaModalService = { |
397 | alert: function() { } | 397 | alert: function() { } |
398 | }; | 398 | }; |
399 | 399 | ||
400 | $controler('notaPedidoCtrl', { | 400 | $controler('notaPedidoCtrl', { |
401 | $scope: scope, | 401 | $scope: scope, |
402 | $uibModal: {}, | 402 | $uibModal: {}, |
403 | $location: {}, | 403 | $location: {}, |
404 | $filter: filter, | 404 | $filter: filter, |
405 | $timeout: timeout, | 405 | $timeout: timeout, |
406 | crearNotaPedidoService: { | 406 | crearNotaPedidoService: { |
407 | getNumeroNotaPedido: function() { | 407 | getNumeroNotaPedido: function() { |
408 | return { | 408 | return { |
409 | then: function() { } | 409 | then: function() { } |
410 | }; | 410 | }; |
411 | }, | 411 | }, |
412 | getBotonera: function() { }, | 412 | getBotonera: function() { }, |
413 | getCotizacionByIdMoneda: function() { | 413 | getCotizacionByIdMoneda: function() { |
414 | return { | 414 | return { |
415 | then: function() {} | 415 | then: function() {} |
416 | }; | 416 | }; |
417 | } | 417 | } |
418 | }, | 418 | }, |
419 | focaBotoneraLateralService: {}, | 419 | focaBotoneraLateralService: {}, |
420 | focaModalService: focaModalService, | 420 | focaModalService: focaModalService, |
421 | notaPedidoBusinessService: {}, | 421 | notaPedidoBusinessService: {}, |
422 | $rootScope: { | 422 | $rootScope: { |
423 | $on: function() { } | 423 | $on: function() { } |
424 | }, | 424 | }, |
425 | focaSeguimientoService: {}, | 425 | focaSeguimientoService: {}, |
426 | APP: {}, | 426 | APP: {}, |
427 | focaLoginService: {}, | 427 | focaLoginService: {}, |
428 | $localStorage: {}, | 428 | $localStorage: {}, |
429 | $watch: function() { }, | 429 | $watch: function() { }, |
430 | $broadcast: function() {} | 430 | $broadcast: function() {} |
431 | }); | 431 | }); |
432 | 432 | ||
433 | scope.notaPedido = { | 433 | scope.notaPedido = { |
434 | vendedor: { | 434 | vendedor: { |
435 | id: true | 435 | id: true |
436 | }, | 436 | }, |
437 | cliente:{ | 437 | cliente:{ |
438 | COD: true | 438 | COD: true |
439 | }, | 439 | }, |
440 | proveedor:{ | 440 | proveedor:{ |
441 | COD: true | 441 | COD: true |
442 | }, | 442 | }, |
443 | cotizacion:{ | 443 | cotizacion:{ |
444 | ID: true, | 444 | ID: true, |
445 | moneda:{ | 445 | moneda:{ |
446 | ID: true | 446 | ID: true |
447 | } | 447 | } |
448 | } | 448 | } |
449 | }; | 449 | }; |
450 | 450 | ||
451 | scope.plazosPagos = null; | 451 | scope.plazosPagos = null; |
452 | 452 | ||
453 | //act | 453 | //act |
454 | spyOn(focaModalService, 'alert'); | 454 | spyOn(focaModalService, 'alert'); |
455 | scope.crearNotaPedido(); | 455 | scope.crearNotaPedido(); |
456 | 456 | ||
457 | //expect | 457 | //expect |
458 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); | 458 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); |
459 | }); | 459 | }); |
460 | 460 | ||
461 | it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { | 461 | it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { |
462 | 462 | ||
463 | //arrange | 463 | //arrange |
464 | var scope = { | 464 | var scope = { |
465 | $watch: function() { }, | 465 | $watch: function() { }, |
466 | $broadcast: function() {} | 466 | $broadcast: function() {} |
467 | }; | 467 | }; |
468 | var focaModalService = { | 468 | var focaModalService = { |
469 | alert: function() { } | 469 | alert: function() { } |
470 | }; | 470 | }; |
471 | 471 | ||
472 | $controler('notaPedidoCtrl', { | 472 | $controler('notaPedidoCtrl', { |
473 | $scope: scope, | 473 | $scope: scope, |
474 | $uibModal: {}, | 474 | $uibModal: {}, |
475 | $location: {}, | 475 | $location: {}, |
476 | $filter: filter, | 476 | $filter: filter, |
477 | $timeout: timeout, | 477 | $timeout: timeout, |
478 | crearNotaPedidoService: { | 478 | crearNotaPedidoService: { |
479 | getNumeroNotaPedido: function() { | 479 | getNumeroNotaPedido: function() { |
480 | return { | 480 | return { |
481 | then: function() { } | 481 | then: function() { } |
482 | }; | 482 | }; |
483 | }, | 483 | }, |
484 | getBotonera: function() { }, | 484 | getBotonera: function() { }, |
485 | getCotizacionByIdMoneda: function() { | 485 | getCotizacionByIdMoneda: function() { |
486 | return { | 486 | return { |
487 | then: function() {} | 487 | then: function() {} |
488 | }; | 488 | }; |
489 | } | 489 | } |
490 | }, | 490 | }, |
491 | focaBotoneraLateralService: {}, | 491 | focaBotoneraLateralService: {}, |
492 | focaModalService: focaModalService, | 492 | focaModalService: focaModalService, |
493 | notaPedidoBusinessService: {}, | 493 | notaPedidoBusinessService: {}, |
494 | $rootScope: { | 494 | $rootScope: { |
495 | $on: function() { } | 495 | $on: function() { } |
496 | }, | 496 | }, |
497 | focaSeguimientoService: {}, | 497 | focaSeguimientoService: {}, |
498 | APP: {}, | 498 | APP: {}, |
499 | focaLoginService: {}, | 499 | focaLoginService: {}, |
500 | $localStorage: {}, | 500 | $localStorage: {}, |
501 | $watch: function() { }, | 501 | $watch: function() { }, |
502 | $broadcast: function() {} | 502 | $broadcast: function() {} |
503 | }); | 503 | }); |
504 | 504 | ||
505 | scope.notaPedido = { | 505 | scope.notaPedido = { |
506 | vendedor: { | 506 | vendedor: { |
507 | id: true | 507 | id: true |
508 | }, | 508 | }, |
509 | cliente:{ | 509 | cliente:{ |
510 | COD: true | 510 | COD: true |
511 | }, | 511 | }, |
512 | proveedor:{ | 512 | proveedor:{ |
513 | COD: true | 513 | COD: true |
514 | }, | 514 | }, |
515 | cotizacion:{ | 515 | cotizacion:{ |
516 | ID: true, | 516 | ID: true, |
517 | moneda:{ | 517 | moneda:{ |
518 | ID: true | 518 | ID: true |
519 | } | 519 | } |
520 | }, | 520 | }, |
521 | flete: null, | 521 | flete: null, |
522 | notaPedidoPlazo: [] | 522 | notaPedidoPlazo: [] |
523 | }; | 523 | }; |
524 | 524 | ||
525 | scope.plazosPagos = true; | 525 | scope.plazosPagos = true; |
526 | 526 | ||
527 | //act | 527 | //act |
528 | spyOn(focaModalService, 'alert'); | 528 | spyOn(focaModalService, 'alert'); |
529 | scope.crearNotaPedido(); | 529 | scope.crearNotaPedido(); |
530 | 530 | ||
531 | //expect | 531 | //expect |
532 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); | 532 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); |
533 | }); | 533 | }); |
534 | 534 | ||
535 | it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { | 535 | it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { |
536 | 536 | ||
537 | //arrange | 537 | //arrange |
538 | var scope = { | 538 | var scope = { |
539 | $watch: function() { }, | 539 | $watch: function() { }, |
540 | $broadcast: function() {} | 540 | $broadcast: function() {} |
541 | }; | 541 | }; |
542 | var focaModalService = { | 542 | var focaModalService = { |
543 | alert: function() { } | 543 | alert: function() { } |
544 | }; | 544 | }; |
545 | 545 | ||
546 | $controler('notaPedidoCtrl', { | 546 | $controler('notaPedidoCtrl', { |
547 | $scope: scope, | 547 | $scope: scope, |
548 | $uibModal: {}, | 548 | $uibModal: {}, |
549 | $location: {}, | 549 | $location: {}, |
550 | $filter: filter, | 550 | $filter: filter, |
551 | $timeout: timeout, | 551 | $timeout: timeout, |
552 | crearNotaPedidoService: { | 552 | crearNotaPedidoService: { |
553 | getNumeroNotaPedido: function() { | 553 | getNumeroNotaPedido: function() { |
554 | return { | 554 | return { |
555 | then: function() { } | 555 | then: function() { } |
556 | }; | 556 | }; |
557 | }, | 557 | }, |
558 | getBotonera: function() { }, | 558 | getBotonera: function() { }, |
559 | getCotizacionByIdMoneda: function() { | 559 | getCotizacionByIdMoneda: function() { |
560 | return { | 560 | return { |
561 | then: function() {} | 561 | then: function() {} |
562 | }; | 562 | }; |
563 | } | 563 | } |
564 | }, | 564 | }, |
565 | focaBotoneraLateralService: {}, | 565 | focaBotoneraLateralService: {}, |
566 | focaModalService: focaModalService, | 566 | focaModalService: focaModalService, |
567 | notaPedidoBusinessService: {}, | 567 | notaPedidoBusinessService: {}, |
568 | $rootScope: { | 568 | $rootScope: { |
569 | $on: function() { } | 569 | $on: function() { } |
570 | }, | 570 | }, |
571 | focaSeguimientoService: {}, | 571 | focaSeguimientoService: {}, |
572 | APP: {}, | 572 | APP: {}, |
573 | focaLoginService: {}, | 573 | focaLoginService: {}, |
574 | $localStorage: {}, | 574 | $localStorage: {}, |
575 | $watch: function() { }, | 575 | $watch: function() { }, |
576 | $broadcast: function() {} | 576 | $broadcast: function() {} |
577 | }); | 577 | }); |
578 | 578 | ||
579 | scope.notaPedido = { | 579 | scope.notaPedido = { |
580 | vendedor: { | 580 | vendedor: { |
581 | id: true | 581 | id: true |
582 | }, | 582 | }, |
583 | cliente:{ | 583 | cliente:{ |
584 | COD: true | 584 | COD: true |
585 | }, | 585 | }, |
586 | proveedor:{ | 586 | proveedor:{ |
587 | COD: true | 587 | COD: true |
588 | }, | 588 | }, |
589 | cotizacion:{ | 589 | cotizacion:{ |
590 | ID: true, | 590 | ID: true, |
591 | moneda:{ | 591 | moneda:{ |
592 | ID: true | 592 | ID: true |
593 | } | 593 | } |
594 | }, | 594 | }, |
595 | flete: true, | 595 | flete: true, |
596 | domicilioStamp: null, | 596 | domicilioStamp: null, |
597 | notaPedidoPlazo: [] | 597 | notaPedidoPlazo: [] |
598 | }; | 598 | }; |
599 | 599 | ||
600 | scope.plazosPagos = true; | 600 | scope.plazosPagos = true; |
601 | 601 | ||
602 | //act | 602 | //act |
603 | spyOn(focaModalService, 'alert'); | 603 | spyOn(focaModalService, 'alert'); |
604 | scope.crearNotaPedido(); | 604 | scope.crearNotaPedido(); |
605 | 605 | ||
606 | //expect | 606 | //expect |
607 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); | 607 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); |
608 | }); | 608 | }); |
609 | 609 | ||
610 | it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', | 610 | it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', |
611 | function() | 611 | function() |
612 | { | 612 | { |
613 | 613 | ||
614 | //arrange | 614 | //arrange |
615 | var scope = { | 615 | var scope = { |
616 | $watch: function() { }, | 616 | $watch: function() { }, |
617 | $broadcast: function() {} | 617 | $broadcast: function() {} |
618 | }; | 618 | }; |
619 | var focaModalService = { | 619 | var focaModalService = { |
620 | alert: function() { } | 620 | alert: function() { } |
621 | }; | 621 | }; |
622 | 622 | ||
623 | $controler('notaPedidoCtrl', { | 623 | $controler('notaPedidoCtrl', { |
624 | $scope: scope, | 624 | $scope: scope, |
625 | $uibModal: {}, | 625 | $uibModal: {}, |
626 | $location: {}, | 626 | $location: {}, |
627 | $filter: filter, | 627 | $filter: filter, |
628 | $timeout: timeout, | 628 | $timeout: timeout, |
629 | crearNotaPedidoService: { | 629 | crearNotaPedidoService: { |
630 | getNumeroNotaPedido: function() { | 630 | getNumeroNotaPedido: function() { |
631 | return { | 631 | return { |
632 | then: function() {} | 632 | then: function() {} |
633 | }; | 633 | }; |
634 | }, | 634 | }, |
635 | getBotonera: function() { }, | 635 | getBotonera: function() { }, |
636 | getCotizacionByIdMoneda: function() { | 636 | getCotizacionByIdMoneda: function() { |
637 | return { | 637 | return { |
638 | then: function() {} | 638 | then: function() {} |
639 | }; | 639 | }; |
640 | }, | 640 | }, |
641 | crearNotaPedido: function() { | 641 | crearNotaPedido: function() { |
642 | return { | 642 | return { |
643 | then: function() { } | 643 | then: function() { } |
644 | }; | 644 | }; |
645 | } | 645 | } |
646 | }, | 646 | }, |
647 | focaBotoneraLateralService: { | 647 | focaBotoneraLateralService: { |
648 | startGuardar: function() {} | 648 | startGuardar: function() {} |
649 | }, | 649 | }, |
650 | focaModalService: focaModalService, | 650 | focaModalService: focaModalService, |
651 | notaPedidoBusinessService: {}, | 651 | notaPedidoBusinessService: {}, |
652 | $rootScope: { | 652 | $rootScope: { |
653 | $on: function() { } | 653 | $on: function() { } |
654 | }, | 654 | }, |
655 | focaSeguimientoService: {}, | 655 | focaSeguimientoService: {}, |
656 | APP: {}, | 656 | APP: {}, |
657 | focaLoginService: {}, | 657 | focaLoginService: {}, |
658 | $localStorage: {}, | 658 | $localStorage: {}, |
659 | $watch: function() { }, | 659 | $watch: function() { }, |
660 | $broadcast: function() {} | 660 | $broadcast: function() {} |
661 | }); | 661 | }); |
662 | 662 | ||
663 | scope.notaPedido = { | 663 | scope.notaPedido = { |
664 | vendedor: { | 664 | vendedor: { |
665 | id: true | 665 | id: true |
666 | }, | 666 | }, |
667 | cliente:{ | 667 | cliente:{ |
668 | COD: true | 668 | COD: true |
669 | }, | 669 | }, |
670 | proveedor:{ | 670 | proveedor:{ |
671 | COD: true | 671 | COD: true |
672 | }, | 672 | }, |
673 | cotizacion:{ | 673 | cotizacion:{ |
674 | ID: true, | 674 | ID: true, |
675 | moneda:{ | 675 | moneda:{ |
676 | ID: true | 676 | ID: true |
677 | } | 677 | } |
678 | }, | 678 | }, |
679 | precioCondicion: { | 679 | precioCondicion: { |
680 | id: true | 680 | id: true |
681 | }, | 681 | }, |
682 | domicilio: { | 682 | domicilio: { |
683 | id: true | 683 | id: true |
684 | }, | 684 | }, |
685 | flete: true, | 685 | flete: true, |
686 | domicilioStamp: true, | 686 | domicilioStamp: true, |
687 | notaPedidoPlazo: [], | 687 | notaPedidoPlazo: [], |
688 | articulosNotaPedido: [], | 688 | articulosNotaPedido: [], |
689 | fechaCarga: true | 689 | fechaCarga: true |
690 | }; | 690 | }; |
691 | 691 | ||
692 | scope.articulosTabla = []; | 692 | scope.articulosTabla = []; |
693 | 693 | ||
694 | //act | 694 | //act |
695 | spyOn(focaModalService, 'alert'); | 695 | spyOn(focaModalService, 'alert'); |
696 | scope.crearNotaPedido(); | 696 | scope.crearNotaPedido(); |
697 | 697 | ||
698 | //expect | 698 | //expect |
699 | expect(focaModalService.alert) | 699 | expect(focaModalService.alert) |
700 | .toHaveBeenCalledWith('Debe cargar al menos un articulo'); | 700 | .toHaveBeenCalledWith('Debe cargar al menos un articulo'); |
701 | }); | 701 | }); |
702 | 702 | ||
703 | it('funcion $scope.crearNotaPedido llama startGuardar', function() { | 703 | it('funcion $scope.crearNotaPedido llama startGuardar', function() { |
704 | 704 | ||
705 | //arrange | 705 | //arrange |
706 | var scope = { | 706 | var scope = { |
707 | $watch: function() { }, | 707 | $watch: function() { }, |
708 | $broadcast: function() {} | 708 | $broadcast: function() {} |
709 | }; | 709 | }; |
710 | var focaBotoneraLateralService = { | 710 | var focaBotoneraLateralService = { |
711 | startGuardar: function() { } | 711 | startGuardar: function() { } |
712 | }; | 712 | }; |
713 | 713 | ||
714 | $controler('notaPedidoCtrl', { | 714 | $controler('notaPedidoCtrl', { |
715 | $scope: scope, | 715 | $scope: scope, |
716 | $uibModal: {}, | 716 | $uibModal: {}, |
717 | $location: {}, | 717 | $location: {}, |
718 | $filter: filter, | 718 | $filter: filter, |
719 | $timeout: timeout, | 719 | $timeout: timeout, |
720 | crearNotaPedidoService: { | 720 | crearNotaPedidoService: { |
721 | getNumeroNotaPedido: function() { | 721 | getNumeroNotaPedido: function() { |
722 | return { | 722 | return { |
723 | then: function() { } | 723 | then: function() { } |
724 | }; | 724 | }; |
725 | }, | 725 | }, |
726 | getBotonera: function() { }, | 726 | getBotonera: function() { }, |
727 | getCotizacionByIdMoneda: function() { | 727 | getCotizacionByIdMoneda: function() { |
728 | return { | 728 | return { |
729 | then: function() {} | 729 | then: function() {} |
730 | }; | 730 | }; |
731 | }, | 731 | }, |
732 | crearNotaPedido: function() { | 732 | crearNotaPedido: function() { |
733 | return { | 733 | return { |
734 | then: function() { } | 734 | then: function() { } |
735 | }; | 735 | }; |
736 | } | 736 | } |
737 | }, | 737 | }, |
738 | focaBotoneraLateralService: focaBotoneraLateralService, | 738 | focaBotoneraLateralService: focaBotoneraLateralService, |
739 | focaModalService: { | 739 | focaModalService: { |
740 | alert: function() {} | 740 | alert: function() {} |
741 | }, | 741 | }, |
742 | notaPedidoBusinessService: {}, | 742 | notaPedidoBusinessService: {}, |
743 | $rootScope: { | 743 | $rootScope: { |
744 | $on: function() { } | 744 | $on: function() { } |
745 | }, | 745 | }, |
746 | focaSeguimientoService: {}, | 746 | focaSeguimientoService: {}, |
747 | APP: {}, | 747 | APP: {}, |
748 | focaLoginService: {}, | 748 | focaLoginService: {}, |
749 | $localStorage: {}, | 749 | $localStorage: {}, |
750 | $watch: function() { }, | 750 | $watch: function() { }, |
751 | $broadcast: function() {} | 751 | $broadcast: function() {} |
752 | }); | 752 | }); |
753 | 753 | ||
754 | scope.notaPedido = { | 754 | scope.notaPedido = { |
755 | vendedor: { | 755 | vendedor: { |
756 | id: true | 756 | id: true |
757 | }, | 757 | }, |
758 | cliente:{ | 758 | cliente:{ |
759 | COD: true | 759 | COD: true |
760 | }, | 760 | }, |
761 | proveedor:{ | 761 | proveedor:{ |
762 | COD: true | 762 | COD: true |
763 | }, | 763 | }, |
764 | cotizacion:{ | 764 | cotizacion:{ |
765 | ID: true, | 765 | ID: true, |
766 | moneda:{ | 766 | moneda:{ |
767 | ID: true | 767 | ID: true |
768 | } | 768 | } |
769 | }, | 769 | }, |
770 | flete: true, | 770 | flete: true, |
771 | domicilioStamp: true, | 771 | domicilioStamp: true, |
772 | domicilio: { | 772 | domicilio: { |
773 | id: true | 773 | id: true |
774 | }, | 774 | }, |
775 | notaPedidoPlazo: [], | 775 | notaPedidoPlazo: [], |
776 | articulosNotaPedido: true, | 776 | articulosNotaPedido: true, |
777 | fechaCarga: true | 777 | fechaCarga: true |
778 | }; | 778 | }; |
779 | 779 | ||
780 | scope.plazosPagos = true; | 780 | scope.plazosPagos = true; |
781 | scope.articulosTabla = [1]; | 781 | scope.articulosTabla = [1]; |
782 | 782 | ||
783 | //act | 783 | //act |
784 | spyOn(focaBotoneraLateralService, 'startGuardar'); | 784 | spyOn(focaBotoneraLateralService, 'startGuardar'); |
785 | scope.crearNotaPedido(scope.notaPedido); | 785 | scope.crearNotaPedido(scope.notaPedido); |
786 | 786 | ||
787 | //expect | 787 | //expect |
788 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); | 788 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); |
789 | }); | 789 | }); |
790 | 790 | ||
791 | it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { | 791 | it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { |
792 | 792 | ||
793 | //arrange | 793 | //arrange |
794 | var scope = { | 794 | var scope = { |
795 | $watch: function() { }, | 795 | $watch: function() { }, |
796 | $broadcast: function() {} | 796 | $broadcast: function() {} |
797 | }; | 797 | }; |
798 | var focaBotoneraLateralService = { | 798 | var focaBotoneraLateralService = { |
799 | startGuardar: function() { }, | 799 | startGuardar: function() { }, |
800 | endGuardar: function() { } | 800 | endGuardar: function() { } |
801 | }; | 801 | }; |
802 | var focaSeguimientoService = { | 802 | var focaSeguimientoService = { |
803 | guardarPosicion: function() { } | 803 | guardarPosicion: function() { } |
804 | }; | 804 | }; |
805 | var notaPedidoBusinessService = { | 805 | var notaPedidoBusinessService = { |
806 | addArticulos: function() { }, | 806 | addArticulos: function() { }, |
807 | addEstado: function() { } | 807 | addEstado: function() { } |
808 | }; | 808 | }; |
809 | var crearNotaPedidoService = { | 809 | var crearNotaPedidoService = { |
810 | getBotonera: function() { }, | 810 | getBotonera: function() { }, |
811 | getCotizacionByIdMoneda: function() { | 811 | getCotizacionByIdMoneda: function() { |
812 | return { | 812 | return { |
813 | then: function() {} | 813 | then: function() {} |
814 | }; | 814 | }; |
815 | }, | 815 | }, |
816 | crearNotaPedido: function() { | 816 | crearNotaPedido: function() { |
817 | return { | 817 | return { |
818 | then: function() { } | 818 | then: function() { } |
819 | }; | 819 | }; |
820 | }, | 820 | }, |
821 | getNumeroNotaPedido: function() { | 821 | getNumeroNotaPedido: function() { |
822 | return { | 822 | return { |
823 | then: function() { } | 823 | then: function() { } |
824 | }; | 824 | }; |
825 | } | 825 | } |
826 | }; | 826 | }; |
827 | 827 | ||
828 | $controler('notaPedidoCtrl', { | 828 | $controler('notaPedidoCtrl', { |
829 | $scope: scope, | 829 | $scope: scope, |
830 | $uibModal: {}, | 830 | $uibModal: {}, |
831 | $location: {}, | 831 | $location: {}, |
832 | $filter: filter, | 832 | $filter: filter, |
833 | $timeout: timeout, | 833 | $timeout: timeout, |
834 | crearNotaPedidoService: crearNotaPedidoService, | 834 | crearNotaPedidoService: crearNotaPedidoService, |
835 | focaBotoneraLateralService: focaBotoneraLateralService, | 835 | focaBotoneraLateralService: focaBotoneraLateralService, |
836 | focaModalService: { | 836 | focaModalService: { |
837 | alert: function() {} | 837 | alert: function() {} |
838 | }, | 838 | }, |
839 | notaPedidoBusinessService: notaPedidoBusinessService, | 839 | notaPedidoBusinessService: notaPedidoBusinessService, |
840 | $rootScope: { | 840 | $rootScope: { |
841 | $on: function() { } | 841 | $on: function() { } |
842 | }, | 842 | }, |
843 | focaSeguimientoService: focaSeguimientoService, | 843 | focaSeguimientoService: focaSeguimientoService, |
844 | APP: {}, | 844 | APP: {}, |
845 | focaLoginService: {}, | 845 | focaLoginService: {}, |
846 | $localStorage: {}, | 846 | $localStorage: {}, |
847 | $watch: function() { }, | 847 | $watch: function() { }, |
848 | $broadcast: function() {} | 848 | $broadcast: function() {} |
849 | }); | 849 | }); |
850 | 850 | ||
851 | scope.notaPedido = { | 851 | scope.notaPedido = { |
852 | vendedor: { | 852 | vendedor: { |
853 | id: true | 853 | id: true |
854 | }, | 854 | }, |
855 | cliente:{ | 855 | cliente:{ |
856 | COD: true | 856 | COD: true |
857 | }, | 857 | }, |
858 | proveedor:{ | 858 | proveedor:{ |
859 | COD: true | 859 | COD: true |
860 | }, | 860 | }, |
861 | cotizacion:{ | 861 | cotizacion:{ |
862 | ID: true, | 862 | ID: true, |
863 | moneda:{ | 863 | moneda:{ |
864 | ID: true | 864 | ID: true |
865 | } | 865 | } |
866 | }, | 866 | }, |
867 | flete: true, | 867 | flete: true, |
868 | domicilioStamp: true, | 868 | domicilioStamp: true, |
869 | domicilio: { | 869 | domicilio: { |
870 | id: true | 870 | id: true |
871 | }, | 871 | }, |
872 | notaPedidoPlazo: [], | 872 | notaPedidoPlazo: [], |
873 | articulosNotaPedido: [1], | 873 | articulosNotaPedido: [1], |
874 | fechaCarga: true | 874 | fechaCarga: true |
875 | }; | 875 | }; |
876 | 876 | ||
877 | scope.plazosPagos = []; | 877 | scope.plazosPagos = []; |
878 | scope.articulosTabla = [1]; | 878 | scope.articulosTabla = [1]; |
879 | 879 | ||
880 | var promesa = Promise.resolve({ data: 1 }); | 880 | var promesa = Promise.resolve({ data: 1 }); |
881 | scope.$broadcast = function() { }; | 881 | scope.$broadcast = function() { }; |
882 | 882 | ||
883 | //act | 883 | //act |
884 | spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); | 884 | spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); |
885 | spyOn(focaSeguimientoService, 'guardarPosicion'); | 885 | spyOn(focaSeguimientoService, 'guardarPosicion'); |
886 | spyOn(notaPedidoBusinessService, 'addArticulos'); | 886 | spyOn(notaPedidoBusinessService, 'addArticulos'); |
887 | scope.crearNotaPedido(); | 887 | scope.crearNotaPedido(); |
888 | //expect | 888 | //expect |
889 | crearNotaPedidoService.crearNotaPedido().then(function() { | 889 | |
890 | promesa.then(function() { | ||
890 | expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); | 891 | expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); |
891 | expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); | 892 | expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); |
892 | done(); | 893 | done(); |
893 | }).catch(done); | 894 | }); |
894 | 895 | ||
895 | }); | 896 | }); |
896 | }); | 897 | }); |
897 | }); | 898 | }); |
898 | 899 |
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
12 | '$rootScope', | 12 | '$rootScope', |
13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
14 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | '$localStorage', | 16 | '$localStorage', |
17 | function( | 17 | function( |
18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
21 | { | 21 | { |
22 | config(); | 22 | config(); |
23 | 23 | ||
24 | function config() { | 24 | function config() { |
25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
26 | $scope.notaPedido = {}; | 26 | $scope.notaPedido = {}; |
27 | $scope.isNumber = angular.isNumber; | 27 | $scope.isNumber = angular.isNumber; |
28 | $scope.datepickerAbierto = false; | 28 | $scope.datepickerAbierto = false; |
29 | $scope.show = false; | 29 | $scope.show = false; |
30 | $scope.cargando = true; | 30 | $scope.cargando = true; |
31 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 31 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
32 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 32 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
33 | $scope.dateOptions = { | 33 | $scope.dateOptions = { |
34 | maxDate: new Date(), | 34 | maxDate: new Date(), |
35 | minDate: new Date(2010, 0, 1) | 35 | minDate: new Date(2010, 0, 1) |
36 | }; | 36 | }; |
37 | 37 | ||
38 | //SETEO BOTONERA LATERAL | 38 | //SETEO BOTONERA LATERAL |
39 | $timeout(function() { | 39 | $timeout(function() { |
40 | focaBotoneraLateralService.showSalir(false); | 40 | focaBotoneraLateralService.showSalir(false); |
41 | focaBotoneraLateralService.showPausar(true); | 41 | focaBotoneraLateralService.showPausar(true); |
42 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 42 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
43 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 43 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
44 | }); | 44 | }); |
45 | 45 | ||
46 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 46 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
47 | if (APP === 'distribuidor') { | 47 | if (APP === 'distribuidor') { |
48 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 48 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
49 | $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); | 49 | $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); |
50 | } else { | 50 | } else { |
51 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 51 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
52 | } | 52 | } |
53 | 53 | ||
54 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 54 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
55 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 55 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
56 | var monedaPorDefecto = res.data[0]; | 56 | var monedaPorDefecto = res.data[0]; |
57 | 57 | ||
58 | $scope.notaPedido.cotizacion = Object.assign( | 58 | $scope.notaPedido.cotizacion = Object.assign( |
59 | {moneda: monedaPorDefecto}, | 59 | {moneda: monedaPorDefecto}, |
60 | monedaPorDefecto.cotizaciones[0] | 60 | monedaPorDefecto.cotizaciones[0] |
61 | ); | 61 | ); |
62 | 62 | ||
63 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | 63 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; |
64 | |||
65 | }); | 64 | }); |
66 | 65 | ||
67 | init(); | 66 | init(); |
68 | $timeout(function() {getLSNotaPedido();}); | 67 | $timeout(function() {getLSNotaPedido();}); |
69 | |||
70 | } | 68 | } |
71 | 69 | ||
72 | function init() { | 70 | function init() { |
73 | $scope.$broadcast('cleanCabecera'); | 71 | $scope.$broadcast('cleanCabecera'); |
74 | 72 | ||
75 | $scope.notaPedido = { | 73 | $scope.notaPedido = { |
76 | id: 0, | 74 | id: 0, |
77 | cliente: {}, | 75 | cliente: {}, |
78 | proveedor: {}, | 76 | proveedor: {}, |
79 | domicilio: {dom: ''}, | 77 | domicilio: {dom: ''}, |
80 | vendedor: {}, | 78 | vendedor: {}, |
81 | fechaCarga: new Date(), | 79 | fechaCarga: new Date(), |
82 | cotizacion: {}, | 80 | cotizacion: {}, |
83 | articulosNotaPedido: [], | 81 | articulosNotaPedido: [], |
84 | notaPedidoPlazo: [] | 82 | notaPedidoPlazo: [] |
85 | }; | 83 | }; |
86 | |||
87 | $scope.idLista = undefined; | 84 | $scope.idLista = undefined; |
88 | 85 | ||
89 | crearNotaPedidoService.getNumeroNotaPedido().then( | 86 | crearNotaPedidoService.getNumeroNotaPedido().then( |
90 | function(res) { | 87 | function(res) { |
91 | $scope.puntoVenta = $filter('rellenarDigitos')( | 88 | $scope.puntoVenta = $filter('rellenarDigitos')( |
92 | res.data.sucursal, 4 | 89 | res.data.sucursal, 4 |
93 | ); | 90 | ); |
94 | 91 | ||
95 | $scope.comprobante = $filter('rellenarDigitos')( | 92 | $scope.comprobante = $filter('rellenarDigitos')( |
96 | res.data.numeroNotaPedido, 8 | 93 | res.data.numeroNotaPedido, 8 |
97 | ); | 94 | ); |
98 | }, | 95 | }, |
99 | function(err) { | 96 | function(err) { |
100 | focaModalService.alert('La terminal no esta configurada correctamente'); | 97 | focaModalService.alert('La terminal no esta configurada correctamente'); |
101 | console.info(err); | 98 | console.info(err); |
102 | } | 99 | } |
103 | ); | 100 | ); |
104 | 101 | ||
105 | if (APP === 'distribuidor') { | 102 | if (APP === 'distribuidor') { |
106 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 103 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
107 | function(res) { | 104 | function(res) { |
108 | var vendedor = res.data; | 105 | var vendedor = res.data; |
109 | $scope.$broadcast('addCabecera', { | 106 | $scope.$broadcast('addCabecera', { |
110 | label: 'Vendedor:', | 107 | label: 'Vendedor:', |
111 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 108 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
112 | vendedor.NOM | 109 | vendedor.NOM |
113 | }); | 110 | }); |
114 | 111 | ||
115 | $scope.notaPedido.vendedor = vendedor; | 112 | $scope.notaPedido.vendedor = vendedor; |
116 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; | 113 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; |
117 | } | 114 | } |
118 | ); | 115 | ); |
119 | } | 116 | } |
120 | 117 | ||
121 | $scope.inicial = angular.copy($scope.notaPedido); | 118 | $scope.inicial = angular.copy($scope.notaPedido); |
122 | } | 119 | } |
123 | 120 | ||
124 | $scope.$watch('notaPedido', function(newValue, oldValue) { | 121 | $scope.$watch('notaPedido', function(newValue, oldValue) { |
125 | focaBotoneraLateralService.setPausarData({ | 122 | focaBotoneraLateralService.setPausarData({ |
126 | label: 'notaPedido', | 123 | label: 'notaPedido', |
127 | val: newValue | 124 | val: newValue |
128 | }); | 125 | }); |
129 | }, true); | 126 | }, true); |
130 | 127 | ||
131 | $scope.crearNotaPedido = function() { | 128 | $scope.crearNotaPedido = function() { |
132 | if(!$scope.notaPedido.vendedor.id) { | 129 | if (!$scope.notaPedido.vendedor.id) { |
133 | focaModalService.alert('Ingrese Vendedor'); | 130 | focaModalService.alert('Ingrese Vendedor'); |
134 | return; | 131 | return; |
135 | } else if(!$scope.notaPedido.cliente.COD) { | 132 | } else if (!$scope.notaPedido.cliente.COD) { |
136 | focaModalService.alert('Ingrese Cliente'); | 133 | focaModalService.alert('Ingrese Cliente'); |
137 | return; | 134 | return; |
138 | } else if(!$scope.notaPedido.proveedor.COD) { | 135 | } else if (!$scope.notaPedido.proveedor.COD) { |
139 | focaModalService.alert('Ingrese Proveedor'); | 136 | focaModalService.alert('Ingrese Proveedor'); |
140 | return; | 137 | return; |
141 | } else if(!$scope.notaPedido.cotizacion.ID) { | 138 | } else if (!$scope.notaPedido.cotizacion.ID) { |
142 | focaModalService.alert('Ingrese Cotización'); | 139 | focaModalService.alert('Ingrese Cotización'); |
143 | return; | 140 | return; |
144 | } else if(!$scope.notaPedido.cotizacion.moneda.ID) { | 141 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
145 | focaModalService.alert('Ingrese Moneda'); | 142 | focaModalService.alert('Ingrese Moneda'); |
146 | return; | 143 | return; |
147 | } else if(!$scope.notaPedido.notaPedidoPlazo) { | 144 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
148 | focaModalService.alert('Ingrese Precios y Condiciones'); | 145 | focaModalService.alert('Ingrese Precios y Condiciones'); |
149 | return; | 146 | return; |
150 | } else if( | 147 | } else if ( |
151 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 148 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
152 | { | 149 | { |
153 | focaModalService.alert('Ingrese Flete'); | 150 | focaModalService.alert('Ingrese Flete'); |
154 | return; | 151 | return; |
155 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 152 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
156 | focaModalService.alert('Ingrese Domicilio'); | 153 | focaModalService.alert('Ingrese Domicilio'); |
157 | return; | 154 | return; |
158 | } else if($scope.notaPedido.articulosNotaPedido.length === 0) { | 155 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
159 | focaModalService.alert('Debe cargar al menos un articulo'); | 156 | focaModalService.alert('Debe cargar al menos un articulo'); |
160 | return; | 157 | return; |
161 | } | 158 | } |
162 | focaBotoneraLateralService.startGuardar(); | 159 | focaBotoneraLateralService.startGuardar(); |
163 | $scope.saveLoading = true; | 160 | $scope.saveLoading = true; |
164 | var notaPedido = { | 161 | var notaPedido = { |
165 | id: $scope.notaPedido.id, | 162 | id: $scope.notaPedido.id, |
166 | fechaCarga: new Date($scope.notaPedido.fechaCarga).toISOString().slice(0, 19).replace('T', ' '), | 163 | fechaCarga: new Date($scope.notaPedido.fechaCarga).toISOString().slice(0, 19).replace('T', ' '), |
167 | idVendedor: $scope.notaPedido.vendedor.id, | 164 | idVendedor: $scope.notaPedido.vendedor.id, |
168 | idCliente: $scope.notaPedido.cliente.COD, | 165 | idCliente: $scope.notaPedido.cliente.COD, |
169 | nombreCliente: $scope.notaPedido.cliente.NOM, | 166 | nombreCliente: $scope.notaPedido.cliente.NOM, |
170 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 167 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
171 | idProveedor: $scope.notaPedido.proveedor.COD, | 168 | idProveedor: $scope.notaPedido.proveedor.COD, |
172 | idDomicilio: $scope.notaPedido.idDomicilio || $scope.notaPedido.domicilio.id, | 169 | idDomicilio: $scope.notaPedido.domicilio.id, |
173 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 170 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
174 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 171 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
175 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 172 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
176 | flete: $scope.notaPedido.flete, | 173 | flete: $scope.notaPedido.flete, |
177 | fob: $scope.notaPedido.fob, | 174 | fob: $scope.notaPedido.fob, |
178 | bomba: $scope.notaPedido.bomba, | 175 | bomba: $scope.notaPedido.bomba, |
179 | kilometros: $scope.notaPedido.kilometros, | 176 | kilometros: $scope.notaPedido.kilometros, |
180 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 177 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
181 | observaciones: $scope.notaPedido.observaciones, | 178 | observaciones: $scope.notaPedido.observaciones, |
182 | estado: 0, | 179 | estado: 0, |
183 | total: $scope.getTotal() | 180 | total: $scope.getTotal() |
184 | }; | 181 | }; |
185 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 182 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
186 | function(data) { | 183 | function(data) { |
187 | // Al guardar los datos de la nota de pedido logueamos la | 184 | // Al guardar los datos de la nota de pedido logueamos la |
188 | // actividad para su seguimiento. | 185 | // actividad para su seguimiento. |
189 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 186 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
190 | focaSeguimientoService.guardarPosicion( | 187 | focaSeguimientoService.guardarPosicion( |
191 | 'Nota de pedido', | 188 | 'Nota de pedido', |
192 | data.data.id, | 189 | data.data.id, |
193 | '' | 190 | '' |
194 | ); | 191 | ); |
195 | notaPedidoBusinessService.addArticulos( | 192 | notaPedidoBusinessService.addArticulos( |
196 | $scope.notaPedido.articulosNotaPedido, | 193 | $scope.notaPedido.articulosNotaPedido, |
197 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 194 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
198 | 195 | ||
199 | if($scope.notaPedido.notaPedidoPuntoDescarga) { | 196 | if($scope.notaPedido.notaPedidoPuntoDescarga) { |
200 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 197 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
201 | $scope.notaPedido.notaPedidoPuntoDescarga); | 198 | $scope.notaPedido.notaPedidoPuntoDescarga); |
202 | } | 199 | } |
203 | 200 | ||
204 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 201 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
205 | var plazosACrear = []; | 202 | var plazosACrear = []; |
206 | plazos.forEach(function(plazo) { | 203 | plazos.forEach(function(plazo) { |
207 | plazosACrear.push({ | 204 | plazosACrear.push({ |
208 | idNotaPedido: data.data.id, | 205 | idNotaPedido: data.data.id, |
209 | dias: plazo.dias | 206 | dias: plazo.dias |
210 | }); | 207 | }); |
211 | }); | 208 | }); |
212 | 209 | ||
213 | if (plazosACrear.length) { | 210 | if (plazosACrear.length) { |
214 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 211 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
215 | } | 212 | } |
216 | 213 | ||
217 | notaPedidoBusinessService.addEstado(data.data.id, | 214 | notaPedidoBusinessService.addEstado(data.data.id, |
218 | $scope.notaPedido.vendedor.id); | 215 | $scope.notaPedido.vendedor.id); |
219 | 216 | ||
220 | focaBotoneraLateralService.endGuardar(true); | 217 | focaBotoneraLateralService.endGuardar(true); |
221 | $scope.saveLoading = false; | 218 | $scope.saveLoading = false; |
222 | 219 | ||
223 | init(); | 220 | init(); |
224 | }, function(error) { | 221 | }, function(error) { |
225 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 222 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
226 | focaBotoneraLateralService.endGuardar(); | 223 | focaBotoneraLateralService.endGuardar(); |
227 | $scope.saveLoading = false; | 224 | $scope.saveLoading = false; |
228 | console.info(error); | 225 | console.info(error); |
229 | } | 226 | } |
230 | ); | 227 | ); |
231 | }; | 228 | }; |
232 | 229 | ||
233 | $scope.seleccionarNotaPedido = function() { | 230 | $scope.seleccionarNotaPedido = function() { |
234 | var modalInstance = $uibModal.open( | 231 | var modalInstance = $uibModal.open( |
235 | { | 232 | { |
236 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 233 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
237 | templateUrl: 'foca-modal-nota-pedido.html', | 234 | templateUrl: 'foca-modal-nota-pedido.html', |
238 | controller: 'focaModalNotaPedidoController', | 235 | controller: 'focaModalNotaPedidoController', |
239 | size: 'lg', | 236 | size: 'lg', |
240 | resolve: { | 237 | resolve: { |
241 | usadoPor: function() {return 'notaPedido';}, | 238 | usadoPor: function() {return 'notaPedido';}, |
242 | idVendedor: function() { | 239 | idVendedor: function() { |
243 | if(APP === 'distribuidor') | 240 | if(APP === 'distribuidor') |
244 | return $scope.notaPedido.vendedor.id; | 241 | return $scope.notaPedido.vendedor.id; |
245 | else | 242 | else |
246 | return null; | 243 | return null; |
247 | } | 244 | } |
248 | } | 245 | } |
249 | } | 246 | } |
250 | ); | 247 | ); |
251 | modalInstance.result.then(setearNotaPedido); | 248 | modalInstance.result.then(setearNotaPedido); |
252 | }; | 249 | }; |
253 | 250 | ||
254 | $scope.seleccionarProductos = function() { | 251 | $scope.seleccionarProductos = function() { |
255 | if ($scope.idLista === undefined) { | 252 | if ($scope.idLista === undefined) { |
256 | focaModalService.alert( | 253 | focaModalService.alert( |
257 | 'Primero seleccione una lista de precio y condicion'); | 254 | 'Primero seleccione una lista de precio y condicion'); |
258 | return; | 255 | return; |
259 | } | 256 | } |
260 | var modalInstance = $uibModal.open( | 257 | var modalInstance = $uibModal.open( |
261 | { | 258 | { |
262 | ariaLabelledBy: 'Busqueda de Productos', | 259 | ariaLabelledBy: 'Busqueda de Productos', |
263 | templateUrl: 'modal-busqueda-productos.html', | 260 | templateUrl: 'modal-busqueda-productos.html', |
264 | controller: 'modalBusquedaProductosCtrl', | 261 | controller: 'modalBusquedaProductosCtrl', |
265 | resolve: { | 262 | resolve: { |
266 | parametroProducto: { | 263 | parametroProducto: { |
267 | idLista: $scope.idLista, | 264 | idLista: $scope.idLista, |
268 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 265 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
269 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 266 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
270 | } | 267 | } |
271 | }, | 268 | }, |
272 | size: 'lg' | 269 | size: 'lg' |
273 | } | 270 | } |
274 | ); | 271 | ); |
275 | modalInstance.result.then( | 272 | modalInstance.result.then( |
276 | function(producto) { | 273 | function(producto) { |
277 | var newArt = | 274 | var newArt = |
278 | { | 275 | { |
279 | id: 0, | 276 | id: 0, |
280 | codigo: producto.codigo, | 277 | codigo: producto.codigo, |
281 | sector: producto.sector, | 278 | sector: producto.sector, |
282 | sectorCodigo: producto.sector + '-' + producto.codigo, | 279 | sectorCodigo: producto.sector + '-' + producto.codigo, |
283 | descripcion: producto.descripcion, | 280 | descripcion: producto.descripcion, |
284 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 281 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
285 | nombre: producto.descripcion, | 282 | nombre: producto.descripcion, |
286 | precio: parseFloat(producto.precio.toFixed(4)), | 283 | precio: parseFloat(producto.precio.toFixed(4)), |
287 | costoUnitario: producto.costo, | 284 | costoUnitario: producto.costo, |
288 | editCantidad: false, | 285 | editCantidad: false, |
289 | editPrecio: false, | 286 | editPrecio: false, |
290 | rubro: producto.CodRub, | 287 | rubro: producto.CodRub, |
291 | exentoUnitario: producto.precio, | 288 | exentoUnitario: producto.precio, |
292 | ivaUnitario: producto.IMPIVA, | 289 | ivaUnitario: producto.IMPIVA, |
293 | impuestoInternoUnitario: producto.ImpInt, | 290 | impuestoInternoUnitario: producto.ImpInt, |
294 | impuestoInterno1Unitario: producto.ImpInt2, | 291 | impuestoInterno1Unitario: producto.ImpInt2, |
295 | impuestoInterno2Unitario: producto.ImpInt3, | 292 | impuestoInterno2Unitario: producto.ImpInt3, |
296 | precioLista: producto.precio, | 293 | precioLista: producto.precio, |
297 | combustible: 1, | 294 | combustible: 1, |
298 | facturado: 0, | 295 | facturado: 0, |
299 | idArticulo: producto.id | 296 | idArticulo: producto.id |
300 | }; | 297 | }; |
301 | $scope.articuloACargar = newArt; | 298 | $scope.articuloACargar = newArt; |
302 | $scope.cargando = false; | 299 | $scope.cargando = false; |
303 | }, function() { | 300 | }, function() { |
304 | // funcion ejecutada cuando se cancela el modal | 301 | // funcion ejecutada cuando se cancela el modal |
305 | } | 302 | } |
306 | ); | 303 | ); |
307 | }; | 304 | }; |
308 | 305 | ||
309 | $scope.seleccionarPuntosDeDescarga = function() { | 306 | $scope.seleccionarPuntosDeDescarga = function() { |
310 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 307 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
311 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 308 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
312 | return; | 309 | return; |
313 | }else { | 310 | }else { |
314 | var modalInstance = $uibModal.open( | 311 | var modalInstance = $uibModal.open( |
315 | { | 312 | { |
316 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 313 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
317 | templateUrl: 'modal-punto-descarga.html', | 314 | templateUrl: 'modal-punto-descarga.html', |
318 | controller: 'focaModalPuntoDescargaController', | 315 | controller: 'focaModalPuntoDescargaController', |
319 | size: 'lg', | 316 | size: 'lg', |
320 | resolve: { | 317 | resolve: { |
321 | filters: { | 318 | filters: { |
322 | idDomicilio: $scope.notaPedido.domicilio.id, | 319 | idDomicilio: $scope.notaPedido.domicilio.id, |
323 | idCliente: $scope.notaPedido.cliente.COD, | 320 | idCliente: $scope.notaPedido.cliente.COD, |
324 | articulos: $scope.notaPedido.articulosNotaPedido, | 321 | articulos: $scope.notaPedido.articulosNotaPedido, |
325 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga | 322 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga |
326 | } | 323 | } |
327 | } | 324 | } |
328 | } | 325 | } |
329 | ); | 326 | ); |
330 | modalInstance.result.then( | 327 | modalInstance.result.then( |
331 | function(puntosDescarga) { | 328 | function(puntosDescarga) { |
332 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; | 329 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; |
333 | 330 | ||
334 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 331 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
335 | var puntosStamp = ''; | 332 | var puntosStamp = ''; |
336 | puntosDescarga.forEach(function(punto, idx, arr) { | 333 | puntosDescarga.forEach(function(punto, idx, arr) { |
337 | puntosStamp += punto.descripcion; | 334 | puntosStamp += punto.descripcion; |
338 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 335 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
339 | }); | 336 | }); |
340 | 337 | ||
341 | $scope.$broadcast('addCabecera', { | 338 | $scope.$broadcast('addCabecera', { |
342 | label: 'Puntos de descarga:', | 339 | label: 'Puntos de descarga:', |
343 | valor: puntosStamp | 340 | valor: puntosStamp |
344 | }); | 341 | }); |
345 | }, function() { | 342 | }, function() { |
346 | $scope.abrirModalDomicilios($scope.cliente); | 343 | $scope.abrirModalDomicilios($scope.cliente); |
347 | } | 344 | } |
348 | ); | 345 | ); |
349 | } | 346 | } |
350 | }; | 347 | }; |
351 | 348 | ||
352 | $scope.seleccionarVendedor = function() { | 349 | $scope.seleccionarVendedor = function() { |
353 | if(validarNotaRemitada()) { | 350 | if(validarNotaRemitada()) { |
354 | var parametrosModal = { | 351 | var parametrosModal = { |
355 | titulo: 'Búsqueda vendedores', | 352 | titulo: 'Búsqueda vendedores', |
356 | query: '/vendedor', | 353 | query: '/vendedor', |
357 | columnas: [ | 354 | columnas: [ |
358 | { | 355 | { |
359 | propiedad: 'NUM', | 356 | propiedad: 'NUM', |
360 | nombre: 'Código', | 357 | nombre: 'Código', |
361 | filtro: { | 358 | filtro: { |
362 | nombre: 'rellenarDigitos', | 359 | nombre: 'rellenarDigitos', |
363 | parametro: 3 | 360 | parametro: 3 |
364 | } | 361 | } |
365 | }, | 362 | }, |
366 | { | 363 | { |
367 | propiedad: 'NOM', | 364 | propiedad: 'NOM', |
368 | nombre: 'Nombre' | 365 | nombre: 'Nombre' |
369 | } | 366 | } |
370 | ], | 367 | ], |
371 | size: 'md' | 368 | size: 'md' |
372 | }; | 369 | }; |
373 | focaModalService.modal(parametrosModal).then( | 370 | focaModalService.modal(parametrosModal).then( |
374 | function(vendedor) { | 371 | function(vendedor) { |
375 | $scope.$broadcast('addCabecera', { | 372 | $scope.$broadcast('addCabecera', { |
376 | label: 'Vendedor:', | 373 | label: 'Vendedor:', |
377 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 374 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
378 | vendedor.NOM | 375 | vendedor.NOM |
379 | }); | 376 | }); |
380 | $scope.notaPedido.vendedor = vendedor; | 377 | $scope.notaPedido.vendedor = vendedor; |
381 | }, function() { | 378 | }, function() { |
382 | 379 | ||
383 | } | 380 | } |
384 | ); | 381 | ); |
385 | } | 382 | } |
386 | }; | 383 | }; |
387 | 384 | ||
388 | $scope.seleccionarProveedor = function() { | 385 | $scope.seleccionarProveedor = function() { |
389 | if(validarNotaRemitada()) { | 386 | if(validarNotaRemitada()) { |
390 | var parametrosModal = { | 387 | var parametrosModal = { |
391 | titulo: 'Búsqueda de Proveedor', | 388 | titulo: 'Búsqueda de Proveedor', |
392 | query: '/proveedor', | 389 | query: '/proveedor', |
393 | columnas: [ | 390 | columnas: [ |
394 | { | 391 | { |
395 | nombre: 'Código', | 392 | nombre: 'Código', |
396 | propiedad: 'COD', | 393 | propiedad: 'COD', |
397 | filtro: { | 394 | filtro: { |
398 | nombre: 'rellenarDigitos', | 395 | nombre: 'rellenarDigitos', |
399 | parametro: 5 | 396 | parametro: 5 |
400 | } | 397 | } |
401 | }, | 398 | }, |
402 | { | 399 | { |
403 | nombre: 'Nombre', | 400 | nombre: 'Nombre', |
404 | propiedad: 'NOM' | 401 | propiedad: 'NOM' |
405 | }, | 402 | }, |
406 | { | 403 | { |
407 | nombre: 'CUIT', | 404 | nombre: 'CUIT', |
408 | propiedad: 'CUIT' | 405 | propiedad: 'CUIT' |
409 | } | 406 | } |
410 | ], | 407 | ], |
411 | tipo: 'POST', | 408 | tipo: 'POST', |
412 | json: {razonCuitCod: ''} | 409 | json: {razonCuitCod: ''} |
413 | }; | 410 | }; |
414 | focaModalService.modal(parametrosModal).then( | 411 | focaModalService.modal(parametrosModal).then( |
415 | function(proveedor) { | 412 | function(proveedor) { |
416 | $scope.notaPedido.proveedor = proveedor; | 413 | $scope.notaPedido.proveedor = proveedor; |
417 | $scope.$broadcast('addCabecera', { | 414 | $scope.$broadcast('addCabecera', { |
418 | label: 'Proveedor:', | 415 | label: 'Proveedor:', |
419 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 416 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
420 | proveedor.NOM | 417 | proveedor.NOM |
421 | }); | 418 | }); |
422 | }, function() { | 419 | }, function() { |
423 | 420 | ||
424 | } | 421 | } |
425 | ); | 422 | ); |
426 | } | 423 | } |
427 | }; | 424 | }; |
428 | 425 | ||
429 | $scope.seleccionarCliente = function() { | 426 | $scope.seleccionarCliente = function() { |
430 | if(!$scope.notaPedido.vendedor.NUM) { | 427 | if(!$scope.notaPedido.vendedor.NUM) { |
431 | focaModalService.alert('Primero seleccione un vendedor'); | 428 | focaModalService.alert('Primero seleccione un vendedor'); |
432 | return; | 429 | return; |
433 | } | 430 | } |
434 | if(validarNotaRemitada()) { | 431 | if(validarNotaRemitada()) { |
435 | var modalInstance = $uibModal.open( | 432 | var modalInstance = $uibModal.open( |
436 | { | 433 | { |
437 | ariaLabelledBy: 'Busqueda de Cliente', | 434 | ariaLabelledBy: 'Busqueda de Cliente', |
438 | templateUrl: 'foca-busqueda-cliente-modal.html', | 435 | templateUrl: 'foca-busqueda-cliente-modal.html', |
439 | controller: 'focaBusquedaClienteModalController', | 436 | controller: 'focaBusquedaClienteModalController', |
440 | resolve: { | 437 | resolve: { |
441 | vendedor: function() { return $scope.notaPedido.vendedor; } | 438 | vendedor: function() { return $scope.notaPedido.vendedor; } |
442 | }, | 439 | }, |
443 | size: 'lg' | 440 | size: 'lg' |
444 | } | 441 | } |
445 | ); | 442 | ); |
446 | modalInstance.result.then( | 443 | modalInstance.result.then( |
447 | function(cliente) { | 444 | function(cliente) { |
448 | $scope.abrirModalDomicilios(cliente); | 445 | $scope.abrirModalDomicilios(cliente); |
449 | $scope.cliente = cliente; | 446 | $scope.cliente = cliente; |
450 | }, function() {} | 447 | }, function() {} |
451 | ); | 448 | ); |
452 | } | 449 | } |
453 | }; | 450 | }; |
454 | 451 | ||
455 | $scope.abrirModalDomicilios = function(cliente) { | 452 | $scope.abrirModalDomicilios = function(cliente) { |
456 | var modalInstanceDomicilio = $uibModal.open( | 453 | var modalInstanceDomicilio = $uibModal.open( |
457 | { | 454 | { |
458 | ariaLabelledBy: 'Busqueda de Domicilios', | 455 | ariaLabelledBy: 'Busqueda de Domicilios', |
459 | templateUrl: 'modal-domicilio.html', | 456 | templateUrl: 'modal-domicilio.html', |
460 | controller: 'focaModalDomicilioController', | 457 | controller: 'focaModalDomicilioController', |
461 | resolve: { | 458 | resolve: { |
462 | idCliente: function() { return cliente.cod; }, | 459 | idCliente: function() { return cliente.cod; }, |
463 | esNuevo: function() { return cliente.esNuevo; } | 460 | esNuevo: function() { return cliente.esNuevo; } |
464 | }, | 461 | }, |
465 | size: 'lg', | 462 | size: 'lg', |
466 | } | 463 | } |
467 | ); | 464 | ); |
468 | modalInstanceDomicilio.result.then( | 465 | modalInstanceDomicilio.result.then( |
469 | function(domicilio) { | 466 | function(domicilio) { |
470 | $scope.notaPedido.domicilio = domicilio; | 467 | $scope.notaPedido.domicilio = domicilio; |
471 | $scope.notaPedido.cliente = { | 468 | $scope.notaPedido.cliente = { |
472 | COD: cliente.cod, | 469 | COD: cliente.cod, |
473 | CUIT: cliente.cuit, | 470 | CUIT: cliente.cuit, |
474 | NOM: cliente.nom | 471 | NOM: cliente.nom |
475 | }; | 472 | }; |
476 | var domicilioStamp = | 473 | var domicilioStamp = |
477 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 474 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
478 | domicilio.Localidad + ', ' + domicilio.Provincia; | 475 | domicilio.Localidad + ', ' + domicilio.Provincia; |
479 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 476 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
480 | 477 | ||
481 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; | 478 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; |
482 | 479 | ||
483 | $scope.$broadcast('addCabecera', { | 480 | $scope.$broadcast('addCabecera', { |
484 | label: 'Cliente:', | 481 | label: 'Cliente:', |
485 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 482 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
486 | }); | 483 | }); |
487 | $scope.$broadcast('addCabecera', { | 484 | $scope.$broadcast('addCabecera', { |
488 | label: 'Domicilio:', | 485 | label: 'Domicilio:', |
489 | valor: domicilioStamp | 486 | valor: domicilioStamp |
490 | }); | 487 | }); |
491 | if(domicilio.verPuntos) { | 488 | if(domicilio.verPuntos) { |
492 | delete $scope.notaPedido.domicilio.verPuntos; | 489 | delete $scope.notaPedido.domicilio.verPuntos; |
493 | $scope.seleccionarPuntosDeDescarga(); | 490 | $scope.seleccionarPuntosDeDescarga(); |
494 | }else { | 491 | }else { |
495 | crearNotaPedidoService | 492 | crearNotaPedidoService |
496 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 493 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
497 | .then(function(res) { | 494 | .then(function(res) { |
498 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 495 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
499 | }); | 496 | }); |
500 | } | 497 | } |
501 | }, function() { | 498 | }, function() { |
502 | $scope.seleccionarCliente(); | 499 | $scope.seleccionarCliente(); |
503 | return; | 500 | return; |
504 | } | 501 | } |
505 | ); | 502 | ); |
506 | }; | 503 | }; |
507 | 504 | ||
508 | $scope.getTotal = function() { | 505 | $scope.getTotal = function() { |
509 | var total = 0; | 506 | var total = 0; |
510 | if ($scope.notaPedido.articulosNotaPedido) { | 507 | if ($scope.notaPedido.articulosNotaPedido) { |
511 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 508 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
512 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 509 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
513 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 510 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
514 | } | 511 | } |
515 | } | 512 | } |
516 | 513 | ||
517 | return parseFloat(total.toFixed(2)); | 514 | return parseFloat(total.toFixed(2)); |
518 | }; | 515 | }; |
519 | 516 | ||
520 | $scope.getSubTotal = function() { | 517 | $scope.getSubTotal = function() { |
521 | if($scope.articuloACargar) { | 518 | if($scope.articuloACargar) { |
522 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 519 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
523 | } | 520 | } |
524 | }; | 521 | }; |
525 | 522 | ||
526 | $scope.seleccionarPreciosYCondiciones = function() { | 523 | $scope.seleccionarPreciosYCondiciones = function() { |
527 | if(validarNotaRemitada()) { | 524 | if(validarNotaRemitada()) { |
528 | var modalInstance = $uibModal.open( | 525 | var modalInstance = $uibModal.open( |
529 | { | 526 | { |
530 | ariaLabelledBy: 'Busqueda de Precio Condición', | 527 | ariaLabelledBy: 'Busqueda de Precio Condición', |
531 | templateUrl: 'modal-precio-condicion.html', | 528 | templateUrl: 'modal-precio-condicion.html', |
532 | controller: 'focaModalPrecioCondicionController', | 529 | controller: 'focaModalPrecioCondicionController', |
533 | size: 'lg' | 530 | size: 'lg' |
534 | } | 531 | } |
535 | ); | 532 | ); |
536 | modalInstance.result.then( | 533 | modalInstance.result.then( |
537 | function(precioCondicion) { | 534 | function(precioCondicion) { |
538 | var cabecera = ''; | 535 | var cabecera = ''; |
539 | var plazosConcat = ''; | 536 | var plazosConcat = ''; |
540 | if(!Array.isArray(precioCondicion)) { | 537 | if(!Array.isArray(precioCondicion)) { |
541 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 538 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
542 | $scope.notaPedido.precioCondicion = precioCondicion; | 539 | $scope.notaPedido.precioCondicion = precioCondicion; |
543 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 540 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
544 | $scope.idLista = precioCondicion.idListaPrecio; | 541 | $scope.idLista = precioCondicion.idListaPrecio; |
545 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 542 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
546 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 543 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
547 | } | 544 | } |
548 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 545 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
549 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 546 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
550 | } else { //Cuando se ingresan los plazos manualmente | 547 | } else { //Cuando se ingresan los plazos manualmente |
551 | $scope.notaPedido.idPrecioCondicion = 0; | 548 | $scope.notaPedido.idPrecioCondicion = 0; |
552 | //-1, el modal productos busca todos los productos | 549 | //-1, el modal productos busca todos los productos |
553 | $scope.idLista = -1; | 550 | $scope.idLista = -1; |
554 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 551 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
555 | for(var j = 0; j < precioCondicion.length; j++) { | 552 | for(var j = 0; j < precioCondicion.length; j++) { |
556 | plazosConcat += precioCondicion[j].dias + ' '; | 553 | plazosConcat += precioCondicion[j].dias + ' '; |
557 | } | 554 | } |
558 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 555 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
559 | } | 556 | } |
560 | $scope.notaPedido.articulosNotaPedido = []; | 557 | $scope.notaPedido.articulosNotaPedido = []; |
561 | $scope.$broadcast('addCabecera', { | 558 | $scope.$broadcast('addCabecera', { |
562 | label: 'Precios y condiciones:', | 559 | label: 'Precios y condiciones:', |
563 | valor: cabecera | 560 | valor: cabecera |
564 | }); | 561 | }); |
565 | }, function() { | 562 | }, function() { |
566 | 563 | ||
567 | } | 564 | } |
568 | ); | 565 | ); |
569 | } | 566 | } |
570 | }; | 567 | }; |
571 | 568 | ||
572 | $scope.seleccionarFlete = function() { | 569 | $scope.seleccionarFlete = function() { |
573 | if(validarNotaRemitada()) { | 570 | if(validarNotaRemitada()) { |
574 | var modalInstance = $uibModal.open( | 571 | var modalInstance = $uibModal.open( |
575 | { | 572 | { |
576 | ariaLabelledBy: 'Busqueda de Flete', | 573 | ariaLabelledBy: 'Busqueda de Flete', |
577 | templateUrl: 'modal-flete.html', | 574 | templateUrl: 'modal-flete.html', |
578 | controller: 'focaModalFleteController', | 575 | controller: 'focaModalFleteController', |
579 | size: 'lg', | 576 | size: 'lg', |
580 | resolve: { | 577 | resolve: { |
581 | parametrosFlete: | 578 | parametrosFlete: |
582 | function() { | 579 | function() { |
583 | return { | 580 | return { |
584 | flete: $scope.notaPedido.fob ? 'FOB' : | 581 | flete: $scope.notaPedido.fob ? 'FOB' : |
585 | ( $scope.notaPedido.flete ? '1' : | 582 | ( $scope.notaPedido.flete ? '1' : |
586 | ($scope.notaPedido.flete === undefined ? | 583 | ($scope.notaPedido.flete === undefined ? |
587 | null : '0')), | 584 | null : '0')), |
588 | bomba: $scope.notaPedido.bomba ? '1' : | 585 | bomba: $scope.notaPedido.bomba ? '1' : |
589 | ($scope.notaPedido.bomba === undefined ? | 586 | ($scope.notaPedido.bomba === undefined ? |
590 | null : '0'), | 587 | null : '0'), |
591 | kilometros: $scope.notaPedido.kilometros | 588 | kilometros: $scope.notaPedido.kilometros |
592 | }; | 589 | }; |
593 | } | 590 | } |
594 | } | 591 | } |
595 | } | 592 | } |
596 | ); | 593 | ); |
597 | modalInstance.result.then( | 594 | modalInstance.result.then( |
598 | function(datos) { | 595 | function(datos) { |
599 | $scope.notaPedido.flete = datos.flete; | 596 | $scope.notaPedido.flete = datos.flete; |
600 | $scope.notaPedido.fob = datos.FOB; | 597 | $scope.notaPedido.fob = datos.FOB; |
601 | $scope.notaPedido.bomba = datos.bomba; | 598 | $scope.notaPedido.bomba = datos.bomba; |
602 | $scope.notaPedido.kilometros = datos.kilometros; | 599 | $scope.notaPedido.kilometros = datos.kilometros; |
603 | $scope.$broadcast('addCabecera', { | 600 | $scope.$broadcast('addCabecera', { |
604 | label: 'Flete:', | 601 | label: 'Flete:', |
605 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 602 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
606 | }); | 603 | }); |
607 | if(datos.flete) { | 604 | if(datos.flete) { |
608 | $scope.$broadcast('addCabecera', { | 605 | $scope.$broadcast('addCabecera', { |
609 | label: 'Bomba:', | 606 | label: 'Bomba:', |
610 | valor: datos.bomba ? 'Si' : 'No' | 607 | valor: datos.bomba ? 'Si' : 'No' |
611 | }); | 608 | }); |
612 | $scope.$broadcast('addCabecera', { | 609 | $scope.$broadcast('addCabecera', { |
613 | label: 'Kilometros:', | 610 | label: 'Kilometros:', |
614 | valor: datos.kilometros | 611 | valor: datos.kilometros |
615 | }); | 612 | }); |
616 | } else { | 613 | } else { |
617 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 614 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
618 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 615 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
619 | $scope.notaPedido.bomba = false; | 616 | $scope.notaPedido.bomba = false; |
620 | $scope.notaPedido.kilometros = null; | 617 | $scope.notaPedido.kilometros = null; |
621 | } | 618 | } |
622 | }, function() { | 619 | }, function() { |
623 | 620 | ||
624 | } | 621 | } |
625 | ); | 622 | ); |
626 | } | 623 | } |
627 | }; | 624 | }; |
628 | 625 | ||
629 | $scope.seleccionarMoneda = function() { | 626 | $scope.seleccionarMoneda = function() { |
630 | if(validarNotaRemitada()) { | 627 | if(validarNotaRemitada()) { |
631 | var parametrosModal = { | 628 | var parametrosModal = { |
632 | titulo: 'Búsqueda de monedas', | 629 | titulo: 'Búsqueda de monedas', |
633 | query: '/moneda', | 630 | query: '/moneda', |
634 | columnas: [ | 631 | columnas: [ |
635 | { | 632 | { |
636 | propiedad: 'DETALLE', | 633 | propiedad: 'DETALLE', |
637 | nombre: 'Nombre' | 634 | nombre: 'Nombre' |
638 | }, | 635 | }, |
639 | { | 636 | { |
640 | propiedad: 'SIMBOLO', | 637 | propiedad: 'SIMBOLO', |
641 | nombre: 'Símbolo' | 638 | nombre: 'Símbolo' |
642 | } | 639 | } |
643 | ], | 640 | ], |
644 | size: 'md' | 641 | size: 'md' |
645 | }; | 642 | }; |
646 | focaModalService.modal(parametrosModal).then( | 643 | focaModalService.modal(parametrosModal).then( |
647 | function(moneda) { | 644 | function(moneda) { |
648 | $scope.abrirModalCotizacion(moneda); | 645 | $scope.abrirModalCotizacion(moneda); |
649 | }, function() { | 646 | }, function() { |
650 | 647 | ||
651 | } | 648 | } |
652 | ); | 649 | ); |
653 | } | 650 | } |
654 | }; | 651 | }; |
655 | 652 | ||
656 | $scope.seleccionarObservaciones = function() { | 653 | $scope.seleccionarObservaciones = function() { |
657 | focaModalService | 654 | focaModalService |
658 | .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) | 655 | .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) |
659 | .then(function(observaciones) { | 656 | .then(function(observaciones) { |
660 | $scope.notaPedido.observaciones = observaciones; | 657 | $scope.notaPedido.observaciones = observaciones; |
661 | }); | 658 | }); |
662 | }; | 659 | }; |
663 | 660 | ||
664 | $scope.abrirModalCotizacion = function(moneda) { | 661 | $scope.abrirModalCotizacion = function(moneda) { |
665 | var modalInstance = $uibModal.open( | 662 | var modalInstance = $uibModal.open( |
666 | { | 663 | { |
667 | ariaLabelledBy: 'Busqueda de Cotización', | 664 | ariaLabelledBy: 'Busqueda de Cotización', |
668 | templateUrl: 'modal-cotizacion.html', | 665 | templateUrl: 'modal-cotizacion.html', |
669 | controller: 'focaModalCotizacionController', | 666 | controller: 'focaModalCotizacionController', |
670 | size: 'lg', | 667 | size: 'lg', |
671 | resolve: { | 668 | resolve: { |
672 | idMoneda: function() { | 669 | idMoneda: function() { |
673 | return moneda.ID; | 670 | return moneda.ID; |
674 | } | 671 | } |
675 | } | 672 | } |
676 | } | 673 | } |
677 | ); | 674 | ); |
678 | modalInstance.result.then( | 675 | modalInstance.result.then( |
679 | function(cotizacion) { | 676 | function(cotizacion) { |
680 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | 677 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; |
681 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 678 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
682 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 679 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
683 | $scope.notaPedido.cotizacion.VENDEDOR; | 680 | $scope.notaPedido.cotizacion.VENDEDOR; |
684 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 681 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
685 | cotizacion.VENDEDOR; | 682 | cotizacion.VENDEDOR; |
686 | } | 683 | } |
687 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | 684 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; |
688 | $scope.notaPedido.cotizacion = cotizacion; | 685 | $scope.notaPedido.cotizacion = cotizacion; |
689 | $scope.notaPedido.cotizacion.moneda = moneda; | 686 | $scope.notaPedido.cotizacion.moneda = moneda; |
690 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 687 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
691 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 688 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
692 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 689 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
693 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 690 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
694 | } else { | 691 | } else { |
695 | $scope.$broadcast('addCabecera', { | 692 | $scope.$broadcast('addCabecera', { |
696 | label: 'Moneda:', | 693 | label: 'Moneda:', |
697 | valor: moneda.DETALLE | 694 | valor: moneda.DETALLE |
698 | }); | 695 | }); |
699 | $scope.$broadcast('addCabecera', { | 696 | $scope.$broadcast('addCabecera', { |
700 | label: 'Fecha cotizacion:', | 697 | label: 'Fecha cotizacion:', |
701 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 698 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
702 | }); | 699 | }); |
703 | $scope.$broadcast('addCabecera', { | 700 | $scope.$broadcast('addCabecera', { |
704 | label: 'Cotizacion:', | 701 | label: 'Cotizacion:', |
705 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 702 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
706 | }); | 703 | }); |
707 | } | 704 | } |
708 | }, function() { | 705 | }, function() { |
709 | 706 | ||
710 | } | 707 | } |
711 | ); | 708 | ); |
712 | }; | 709 | }; |
713 | 710 | ||
714 | $scope.agregarATabla = function(key) { | 711 | $scope.agregarATabla = function(key) { |
715 | if(key === 13) { | 712 | if(key === 13) { |
716 | if($scope.articuloACargar.cantidad === undefined || | 713 | if($scope.articuloACargar.cantidad === undefined || |
717 | $scope.articuloACargar.cantidad === 0 || | 714 | $scope.articuloACargar.cantidad === 0 || |
718 | $scope.articuloACargar.cantidad === null ) { | 715 | $scope.articuloACargar.cantidad === null ) { |
719 | focaModalService.alert('El valor debe ser al menos 1'); | 716 | focaModalService.alert('El valor debe ser al menos 1'); |
720 | return; | 717 | return; |
721 | } | 718 | } |
722 | delete $scope.articuloACargar.sectorCodigo; | 719 | delete $scope.articuloACargar.sectorCodigo; |
723 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 720 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
724 | $scope.cargando = true; | 721 | $scope.cargando = true; |
725 | } | 722 | } |
726 | }; | 723 | }; |
727 | 724 | ||
728 | $scope.quitarArticulo = function(key) { | 725 | $scope.quitarArticulo = function(key) { |
729 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 726 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
730 | }; | 727 | }; |
731 | 728 | ||
732 | $scope.editarArticulo = function(key, articulo) { | 729 | $scope.editarArticulo = function(key, articulo) { |
733 | if(key === 13) { | 730 | if(key === 13) { |
734 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 731 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
735 | articulo.cantidad === undefined) { | 732 | articulo.cantidad === undefined) { |
736 | focaModalService.alert('El valor debe ser al menos 1'); | 733 | focaModalService.alert('El valor debe ser al menos 1'); |
737 | return; | 734 | return; |
738 | } | 735 | } |
739 | articulo.editCantidad = false; | 736 | articulo.editCantidad = false; |
740 | articulo.editPrecio = false; | 737 | articulo.editPrecio = false; |
741 | } | 738 | } |
742 | }; | 739 | }; |
743 | 740 | ||
744 | $scope.cambioEdit = function(articulo, propiedad) { | 741 | $scope.cambioEdit = function(articulo, propiedad) { |
745 | if(propiedad === 'cantidad') { | 742 | if(propiedad === 'cantidad') { |
746 | articulo.editCantidad = true; | 743 | articulo.editCantidad = true; |
747 | } else if(propiedad === 'precio') { | 744 | } else if(propiedad === 'precio') { |
748 | articulo.editPrecio = true; | 745 | articulo.editPrecio = true; |
749 | } | 746 | } |
750 | }; | 747 | }; |
751 | 748 | ||
752 | $scope.resetFilter = function() { | 749 | $scope.resetFilter = function() { |
753 | $scope.articuloACargar = {}; | 750 | $scope.articuloACargar = {}; |
754 | $scope.cargando = true; | 751 | $scope.cargando = true; |
755 | }; | 752 | }; |
756 | //Recibe aviso si el teclado está en uso | 753 | //Recibe aviso si el teclado está en uso |
757 | $rootScope.$on('usarTeclado', function(event, data) { | 754 | $rootScope.$on('usarTeclado', function(event, data) { |
758 | if(data) { | 755 | if(data) { |
759 | $scope.mostrarTeclado = true; | 756 | $scope.mostrarTeclado = true; |
760 | return; | 757 | return; |
761 | } | 758 | } |
762 | $scope.mostrarTeclado = false; | 759 | $scope.mostrarTeclado = false; |
763 | }); | 760 | }); |
764 | 761 | ||
765 | $scope.selectFocus = function($event) { | 762 | $scope.selectFocus = function($event) { |
766 | // Si el teclado esta en uso no selecciona el valor | 763 | // Si el teclado esta en uso no selecciona el valor |
767 | if($scope.mostrarTeclado) { | 764 | if($scope.mostrarTeclado) { |
768 | return; | 765 | return; |
769 | } | 766 | } |
770 | $event.target.select(); | 767 | $event.target.select(); |
771 | }; | 768 | }; |
772 | 769 | ||
773 | $scope.salir = function() { | 770 | $scope.salir = function() { |
774 | $location.path('/'); | 771 | $location.path('/'); |
775 | }; | 772 | }; |
776 | 773 | ||
777 | $scope.parsearATexto = function(articulo) { | 774 | $scope.parsearATexto = function(articulo) { |
778 | articulo.cantidad = parseFloat(articulo.cantidad); | 775 | articulo.cantidad = parseFloat(articulo.cantidad); |
779 | articulo.precio = parseFloat(articulo.precio); | 776 | articulo.precio = parseFloat(articulo.precio); |
780 | }; | 777 | }; |
781 | 778 | ||
782 | function setearNotaPedido(notaPedido) { | 779 | function setearNotaPedido(notaPedido) { |
783 | //añado cabeceras | 780 | //añado cabeceras |
784 | $scope.notaPedido = notaPedido; | 781 | $scope.notaPedido = notaPedido; |
785 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 782 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
786 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 783 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
787 | 784 | ||
788 | var cabeceras = []; | 785 | var cabeceras = []; |
789 | 786 | ||
790 | if (notaPedido.cotizacion) { | 787 | if (notaPedido.cotizacion) { |
791 | cabeceras.push({ | 788 | cabeceras.push({ |
792 | label: 'Moneda:', | 789 | label: 'Moneda:', |
793 | valor: notaPedido.cotizacion.moneda.DETALLE | 790 | valor: notaPedido.cotizacion.moneda.DETALLE |
794 | }); | 791 | }); |
795 | cabeceras.push({ | 792 | cabeceras.push({ |
796 | label: 'Fecha cotizacion:', | 793 | label: 'Fecha cotizacion:', |
797 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 794 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
798 | 'dd/MM/yyyy') | 795 | 'dd/MM/yyyy') |
799 | }); | 796 | }); |
800 | cabeceras.push({ | 797 | cabeceras.push({ |
801 | label: 'Cotizacion:', | 798 | label: 'Cotizacion:', |
802 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 799 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
803 | '2') | 800 | '2') |
804 | }); | 801 | }); |
805 | } | 802 | } |
806 | if (notaPedido.cliente.COD) { | 803 | if (notaPedido.cliente.COD) { |
807 | cabeceras.push({ | 804 | cabeceras.push({ |
808 | label: 'Cliente:', | 805 | label: 'Cliente:', |
809 | valor: notaPedido.cliente.NOM | 806 | valor: notaPedido.cliente.NOM |
810 | }); | 807 | }); |
811 | cabeceras.push({ | 808 | cabeceras.push({ |
812 | label: 'Domicilio:', | 809 | label: 'Domicilio:', |
813 | valor: notaPedido.domicilioStamp | 810 | valor: notaPedido.domicilioStamp |
814 | }); | 811 | }); |
815 | } | 812 | } |
816 | if (notaPedido.vendedor.NUM) { | 813 | if (notaPedido.vendedor.NUM) { |
817 | cabeceras.push({ | 814 | cabeceras.push({ |
818 | label: 'Vendedor:', | 815 | label: 'Vendedor:', |
819 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 816 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
820 | ' - ' + notaPedido.vendedor.NOM | 817 | ' - ' + notaPedido.vendedor.NOM |
821 | }); | 818 | }); |
822 | } | 819 | } |
823 | if (notaPedido.proveedor.COD) { | 820 | if (notaPedido.proveedor.COD) { |
824 | cabeceras.push({ | 821 | cabeceras.push({ |
825 | label: 'Proveedor:', | 822 | label: 'Proveedor:', |
826 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 823 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
827 | ' - ' + notaPedido.proveedor.NOM | 824 | ' - ' + notaPedido.proveedor.NOM |
828 | }); | 825 | }); |
829 | } | 826 | } |
830 | if (notaPedido.notaPedidoPlazo.length) { | 827 | if (notaPedido.notaPedidoPlazo.length) { |
831 | cabeceras.push({ | 828 | cabeceras.push({ |
832 | label: 'Precios y condiciones:', | 829 | label: 'Precios y condiciones:', |
833 | valor: valorPrecioCondicion() + ' ' + | 830 | valor: valorPrecioCondicion() + ' ' + |
834 | notaPedidoBusinessService | 831 | notaPedidoBusinessService |
835 | .plazoToString(notaPedido.notaPedidoPlazo) | 832 | .plazoToString(notaPedido.notaPedidoPlazo) |
836 | }); | 833 | }); |
837 | } | 834 | } |
838 | if (notaPedido.flete !== undefined) { | 835 | if (notaPedido.flete !== undefined) { |
839 | cabeceras.push({ | 836 | cabeceras.push({ |
840 | label: 'Flete:', | 837 | label: 'Flete:', |
841 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 838 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
842 | notaPedido.flete === 1 ? 'Si' : 'No') | 839 | notaPedido.flete === 1 ? 'Si' : 'No') |
843 | }); | 840 | }); |
844 | } | 841 | } |
845 | 842 | ||
846 | 843 | ||
847 | function valorPrecioCondicion() { | 844 | function valorPrecioCondicion() { |
848 | if(notaPedido.idPrecioCondicion > 0) { | 845 | if (notaPedido.idPrecioCondicion > 0) { |
849 | return notaPedido.precioCondicion.nombre; | 846 | return notaPedido.precioCondicion.nombre; |
850 | } else { | 847 | } else { |
851 | return 'Ingreso Manual'; | 848 | return 'Ingreso Manual'; |
852 | } | 849 | } |
853 | } | 850 | } |
854 | 851 | ||
855 | if(notaPedido.flete === 1) { | 852 | if (notaPedido.flete === 1) { |
856 | var cabeceraBomba = { | 853 | var cabeceraBomba = { |
857 | label: 'Bomba:', | 854 | label: 'Bomba:', |
858 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 855 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
859 | }; | 856 | }; |
860 | if(notaPedido.kilometros) { | 857 | if (notaPedido.kilometros) { |
861 | var cabeceraKilometros = { | 858 | var cabeceraKilometros = { |
862 | label: 'Kilometros:', | 859 | label: 'Kilometros:', |
863 | valor: notaPedido.kilometros | 860 | valor: notaPedido.kilometros |
864 | }; | 861 | }; |
865 | cabeceras.push(cabeceraKilometros); | 862 | cabeceras.push(cabeceraKilometros); |
866 | } | 863 | } |
867 | cabeceras.push(cabeceraBomba); | 864 | cabeceras.push(cabeceraBomba); |
868 | } | 865 | } |
869 | 866 | ||
870 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, | 867 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, |
871 | notaPedido.cotizacion.VENDEDOR); | 868 | notaPedido.cotizacion.VENDEDOR); |
872 | 869 | ||
873 | if(notaPedido.idPrecioCondicion > 0) { | 870 | if (notaPedido.idPrecioCondicion > 0) { |
874 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 871 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
875 | } else { | 872 | } else { |
876 | $scope.idLista = -1; | 873 | $scope.idLista = -1; |
877 | } | 874 | } |
878 | 875 | ||
879 | $scope.puntoVenta = $filter('rellenarDigitos')( | 876 | $scope.puntoVenta = $filter('rellenarDigitos')( |
880 | notaPedido.sucursal, 4 | 877 | notaPedido.sucursal, 4 |
881 | ); | 878 | ); |
882 | 879 | ||
883 | $scope.comprobante = $filter('rellenarDigitos')( | 880 | $scope.comprobante = $filter('rellenarDigitos')( |
884 | notaPedido.numeroNotaPedido, 8 | 881 | notaPedido.numeroNotaPedido, 8 |
885 | ); | 882 | ); |
886 | 883 | ||
887 | $scope.notaPedido.notaPedidoPuntoDescarga = | 884 | $scope.notaPedido.notaPedidoPuntoDescarga = |
888 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); | 885 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); |
889 | addArrayCabecera(cabeceras); | 886 | addArrayCabecera(cabeceras); |
890 | } | 887 | } |
891 | 888 | ||
892 | function addArrayCabecera(array) { | 889 | function addArrayCabecera(array) { |
893 | for(var i = 0; i < array.length; i++) { | 890 | for(var i = 0; i < array.length; i++) { |
894 | $scope.$broadcast('addCabecera', { | 891 | $scope.$broadcast('addCabecera', { |
895 | label: array[i].label, | 892 | label: array[i].label, |
896 | valor: array[i].valor | 893 | valor: array[i].valor |
897 | }); | 894 | }); |
898 | } | 895 | } |
899 | } | 896 | } |
900 | 897 | ||
901 | function validarNotaRemitada() { | 898 | function validarNotaRemitada() { |
902 | if(!$scope.notaPedido.idRemito) { | 899 | if(!$scope.notaPedido.idRemito) { |
903 | return true; | 900 | return true; |
904 | }else{ | 901 | }else{ |
905 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 902 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
906 | return false; | 903 | return false; |
907 | } | 904 | } |
908 | } | 905 | } |
909 | 906 | ||
910 | function formatearPuntosDescarga(puntosDescarga) { | 907 | function formatearPuntosDescarga(puntosDescarga) { |
911 | var result = []; | 908 | var result = []; |
912 | 909 | ||
913 | puntosDescarga.forEach(function(el) { | 910 | puntosDescarga.forEach(function(el) { |
914 | var puntoDescarga = result.filter(function(resultPunto) { | 911 | var puntoDescarga = result.filter(function(resultPunto) { |
915 | return resultPunto.id === el.idPuntoDescarga; | 912 | return resultPunto.id === el.idPuntoDescarga; |
916 | }); | 913 | }); |
917 | 914 | ||
918 | if (puntoDescarga.length) { | 915 | if (puntoDescarga.length) { |
919 | puntoDescarga[0].articulosAgregados.push({ | 916 | puntoDescarga[0].articulosAgregados.push({ |
920 | cantidad: el.cantidad, | 917 | cantidad: el.cantidad, |
921 | descripcion: el.producto.descripcion, | 918 | descripcion: el.producto.descripcion, |
922 | id: el.producto.id | 919 | id: el.producto.id |
923 | }); | 920 | }); |
924 | } else { | 921 | } else { |
925 | result.push({ | 922 | result.push({ |
926 | id: el.puntoDescarga.id, | 923 | id: el.puntoDescarga.id, |
927 | id_cliente: el.puntoDescarga.id_cliente, | 924 | id_cliente: el.puntoDescarga.id_cliente, |
928 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 925 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
929 | latitud: el.puntoDescarga.latitud, | 926 | latitud: el.puntoDescarga.latitud, |
930 | longitud: el.puntoDescarga.longitud, | 927 | longitud: el.puntoDescarga.longitud, |
931 | descripcion: el.puntoDescarga.descripcion, | 928 | descripcion: el.puntoDescarga.descripcion, |
932 | articulosAgregados: [ | 929 | articulosAgregados: [ |
933 | { | 930 | { |
934 | cantidad: el.cantidad, | 931 | cantidad: el.cantidad, |
935 | descripcion: el.producto.descripcion, | 932 | descripcion: el.producto.descripcion, |
936 | id: el.producto.id | 933 | id: el.producto.id |
937 | } | 934 | } |
938 | ] | 935 | ] |
939 | }); | 936 | }); |
940 | } | 937 | } |
941 | }); | 938 | }); |
942 | return result; | 939 | return result; |
943 | } | 940 | } |
944 | 941 | ||
945 | function salir() { | 942 | function salir() { |
946 | var confirmacion = false; | 943 | var confirmacion = false; |
947 | 944 | ||
948 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 945 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
949 | confirmacion = true; | 946 | confirmacion = true; |
950 | } | 947 | } |
951 | 948 | ||
952 | if (confirmacion) { | 949 | if (confirmacion) { |
953 | focaModalService.confirm( | 950 | focaModalService.confirm( |
954 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 951 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
955 | ).then(function(data) { | 952 | ).then(function(data) { |
956 | if (data) { | 953 | if (data) { |
957 | $location.path('/'); | 954 | $location.path('/'); |
958 | } | 955 | } |
959 | }); | 956 | }); |
960 | } else { | 957 | } else { |
961 | $location.path('/'); | 958 | $location.path('/'); |
962 | } | 959 | } |
963 | } | 960 | } |
964 | 961 | ||
965 | function getLSNotaPedido() { | 962 | function getLSNotaPedido() { |
966 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 963 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
967 | if (notaPedido) { | 964 | if (notaPedido) { |
968 | setearNotaPedido(notaPedido); | 965 | setearNotaPedido(notaPedido); |
969 | delete $localStorage.notaPedido; | 966 | delete $localStorage.notaPedido; |
970 | } | 967 | } |
971 | } | 968 | } |
972 | } | 969 | } |
973 | ]); | 970 | ]); |
974 | 971 |