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