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