Commit f4b1e80e350891d3da392a12457c1831493fa1bc
1 parent
e84b5020b9
Exists in
master
elimino facturas al seleccionar cliente
Showing
2 changed files
with
21 additions
and
3 deletions
Show diff stats
spec/controllerSpec.js
1 | describe('controladores módulo crear cobranza', function() { | 1 | describe('controladores módulo crear cobranza', function() { |
2 | 2 | ||
3 | var $controller; | 3 | var $controller; |
4 | 4 | ||
5 | beforeEach(function() { | 5 | beforeEach(function() { |
6 | 6 | ||
7 | module('focaCrearCobranza'); | 7 | module('focaCrearCobranza'); |
8 | 8 | ||
9 | inject(function(_$controller_) { | 9 | inject(function(_$controller_) { |
10 | 10 | ||
11 | $controller = _$controller_; | 11 | $controller = _$controller_; |
12 | }); | 12 | }); |
13 | }); | 13 | }); |
14 | 14 | ||
15 | describe('Controlador cobranzaController', function() { | 15 | describe('Controlador cobranzaController', function() { |
16 | 16 | ||
17 | var $filter = function() { | 17 | var $filter = function() { |
18 | return function() { }; | 18 | return function() { }; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | var $timeout = function() { }; | 21 | var $timeout = function() { }; |
22 | 22 | ||
23 | it('existe el controlador cobranzaController', function() { | 23 | it('existe el controlador cobranzaController', function() { |
24 | 24 | ||
25 | //act | 25 | //act |
26 | var controlador = $controller('cobranzaController', { | 26 | var controlador = $controller('cobranzaController', { |
27 | $scope: { | 27 | $scope: { |
28 | $broadcast: function() { }, | 28 | $broadcast: function() { }, |
29 | $watch: function() { } | 29 | $watch: function() { } |
30 | }, | 30 | }, |
31 | $timeout: $timeout, | 31 | $timeout: $timeout, |
32 | $uibModal: {}, | 32 | $uibModal: {}, |
33 | $location: {}, | 33 | $location: {}, |
34 | focaCrearCobranzaService: { | 34 | focaCrearCobranzaService: { |
35 | getCotizacionByIdMoneda: function() { | 35 | getCotizacionByIdMoneda: function() { |
36 | return { | 36 | return { |
37 | then: function() { } | 37 | then: function() { } |
38 | }; | 38 | }; |
39 | }, | 39 | }, |
40 | getBotonera: function() { }, | 40 | getBotonera: function() { }, |
41 | getNumeroRecibo: function() { | 41 | getNumeroRecibo: function() { |
42 | return { | 42 | return { |
43 | then: function() { } | 43 | then: function() { } |
44 | }; | 44 | }; |
45 | } | 45 | } |
46 | }, | 46 | }, |
47 | focaModalService: {}, | 47 | focaModalService: {}, |
48 | $filter: $filter, | 48 | $filter: $filter, |
49 | focaSeguimientoService: {}, | 49 | focaSeguimientoService: {}, |
50 | focaBotoneraLateralService: {}, | 50 | focaBotoneraLateralService: {}, |
51 | APP: {}, | 51 | APP: {}, |
52 | focaLoginService: {}, | 52 | focaLoginService: {}, |
53 | $localStorage: true | 53 | $localStorage: true |
54 | }); | 54 | }); |
55 | 55 | ||
56 | //assert | 56 | //assert |
57 | expect(typeof controlador).toEqual('object'); | 57 | expect(typeof controlador).toEqual('object'); |
58 | }); | 58 | }); |
59 | 59 | ||
60 | it('function crearCobranza muestra alerta cuando no hay cliente', function() { | 60 | it('function crearCobranza muestra alerta cuando no hay cliente', function() { |
61 | 61 | ||
62 | //arrange | 62 | //arrange |
63 | var scope = { | 63 | var scope = { |
64 | $broadcast: function() { }, | 64 | $broadcast: function() { }, |
65 | $watch: function() { } | 65 | $watch: function() { } |
66 | }; | 66 | }; |
67 | var focaModalService = { | 67 | var focaModalService = { |
68 | alert: function() { } | 68 | alert: function() { } |
69 | }; | 69 | }; |
70 | 70 | ||
71 | $controller('cobranzaController', { | 71 | $controller('cobranzaController', { |
72 | $scope: scope, | 72 | $scope: scope, |
73 | $timeout: $timeout, | 73 | $timeout: $timeout, |
74 | $uibModal: {}, | 74 | $uibModal: {}, |
75 | $location: {}, | 75 | $location: {}, |
76 | focaCrearCobranzaService: { | 76 | focaCrearCobranzaService: { |
77 | getCotizacionByIdMoneda: function() { | 77 | getCotizacionByIdMoneda: function() { |
78 | return { | 78 | return { |
79 | then: function() { } | 79 | then: function() { } |
80 | }; | 80 | }; |
81 | }, | 81 | }, |
82 | getBotonera: function() { }, | 82 | getBotonera: function() { }, |
83 | getNumeroRecibo: function() { | 83 | getNumeroRecibo: function() { |
84 | return { | 84 | return { |
85 | then: function() { } | 85 | then: function() { } |
86 | }; | 86 | }; |
87 | } | 87 | } |
88 | }, | 88 | }, |
89 | focaModalService: focaModalService, | 89 | focaModalService: focaModalService, |
90 | $filter: $filter, | 90 | $filter: $filter, |
91 | focaSeguimientoService: {}, | 91 | focaSeguimientoService: {}, |
92 | focaBotoneraLateralService: {}, | 92 | focaBotoneraLateralService: {}, |
93 | APP: {}, | 93 | APP: {}, |
94 | focaLoginService: {}, | 94 | focaLoginService: {}, |
95 | $localStorage: true | 95 | $localStorage: true |
96 | }); | 96 | }); |
97 | 97 | ||
98 | //act | 98 | //act |
99 | spyOn(focaModalService, 'alert'); | 99 | spyOn(focaModalService, 'alert'); |
100 | scope.crearCobranza(); | 100 | scope.crearCobranza(); |
101 | 101 | ||
102 | //assert | 102 | //assert |
103 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); | 103 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); |
104 | }); | 104 | }); |
105 | 105 | ||
106 | it('function crearCobranza muestra alerta cuando no hay cobrador', function() { | 106 | it('function crearCobranza muestra alerta cuando no hay cobrador', function() { |
107 | 107 | ||
108 | //arrange | 108 | //arrange |
109 | var scope = { | 109 | var scope = { |
110 | $broadcast: function() { }, | 110 | $broadcast: function() { }, |
111 | $watch: function() { } | 111 | $watch: function() { } |
112 | }; | 112 | }; |
113 | var focaModalService = { | 113 | var focaModalService = { |
114 | alert: function() { } | 114 | alert: function() { } |
115 | }; | 115 | }; |
116 | 116 | ||
117 | $controller('cobranzaController', { | 117 | $controller('cobranzaController', { |
118 | $scope: scope, | 118 | $scope: scope, |
119 | $timeout: $timeout, | 119 | $timeout: $timeout, |
120 | $uibModal: {}, | 120 | $uibModal: {}, |
121 | $location: {}, | 121 | $location: {}, |
122 | focaCrearCobranzaService: { | 122 | focaCrearCobranzaService: { |
123 | getCotizacionByIdMoneda: function() { | 123 | getCotizacionByIdMoneda: function() { |
124 | return { | 124 | return { |
125 | then: function() { } | 125 | then: function() { } |
126 | }; | 126 | }; |
127 | }, | 127 | }, |
128 | getBotonera: function() { }, | 128 | getBotonera: function() { }, |
129 | getNumeroRecibo: function() { | 129 | getNumeroRecibo: function() { |
130 | return { | 130 | return { |
131 | then: function() { } | 131 | then: function() { } |
132 | }; | 132 | }; |
133 | } | 133 | } |
134 | }, | 134 | }, |
135 | focaModalService: focaModalService, | 135 | focaModalService: focaModalService, |
136 | $filter: $filter, | 136 | $filter: $filter, |
137 | focaSeguimientoService: {}, | 137 | focaSeguimientoService: {}, |
138 | focaBotoneraLateralService: {}, | 138 | focaBotoneraLateralService: {}, |
139 | APP: {}, | 139 | APP: {}, |
140 | focaLoginService: {}, | 140 | focaLoginService: {}, |
141 | $localStorage: true | 141 | $localStorage: true |
142 | }); | 142 | }); |
143 | scope.cobranza = { | 143 | scope.cobranza = { |
144 | cliente: { | 144 | cliente: { |
145 | COD: true | 145 | COD: true |
146 | }, | 146 | }, |
147 | cobrador: {} | 147 | cobrador: {} |
148 | }; | 148 | }; |
149 | 149 | ||
150 | //act | 150 | //act |
151 | spyOn(focaModalService, 'alert'); | 151 | spyOn(focaModalService, 'alert'); |
152 | scope.crearCobranza(); | 152 | scope.crearCobranza(); |
153 | 153 | ||
154 | //assert | 154 | //assert |
155 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador'); | 155 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador'); |
156 | }); | 156 | }); |
157 | 157 | ||
158 | it('function crearCobranza muestra alerta cuando no hay facturas', function() { | 158 | it('function crearCobranza muestra alerta cuando no hay facturas', function() { |
159 | 159 | ||
160 | //arrange | 160 | //arrange |
161 | var scope = { | 161 | var scope = { |
162 | $broadcast: function() { }, | 162 | $broadcast: function() { }, |
163 | $watch: function() { } | 163 | $watch: function() { } |
164 | }; | 164 | }; |
165 | var focaModalService = { | 165 | var focaModalService = { |
166 | alert: function() { } | 166 | alert: function() { } |
167 | }; | 167 | }; |
168 | 168 | ||
169 | $controller('cobranzaController', { | 169 | $controller('cobranzaController', { |
170 | $scope: scope, | 170 | $scope: scope, |
171 | $timeout: $timeout, | 171 | $timeout: $timeout, |
172 | $uibModal: {}, | 172 | $uibModal: {}, |
173 | $location: {}, | 173 | $location: {}, |
174 | focaCrearCobranzaService: { | 174 | focaCrearCobranzaService: { |
175 | getCotizacionByIdMoneda: function() { | 175 | getCotizacionByIdMoneda: function() { |
176 | return { | 176 | return { |
177 | then: function() { } | 177 | then: function() { } |
178 | }; | 178 | }; |
179 | }, | 179 | }, |
180 | getBotonera: function() { }, | 180 | getBotonera: function() { }, |
181 | getNumeroRecibo: function() { | 181 | getNumeroRecibo: function() { |
182 | return { | 182 | return { |
183 | then: function() { } | 183 | then: function() { } |
184 | }; | 184 | }; |
185 | } | 185 | } |
186 | }, | 186 | }, |
187 | focaModalService: focaModalService, | 187 | focaModalService: focaModalService, |
188 | $filter: $filter, | 188 | $filter: $filter, |
189 | focaSeguimientoService: {}, | 189 | focaSeguimientoService: {}, |
190 | focaBotoneraLateralService: {}, | 190 | focaBotoneraLateralService: {}, |
191 | APP: {}, | 191 | APP: {}, |
192 | focaLoginService: {}, | 192 | focaLoginService: {}, |
193 | $localStorage: true | 193 | $localStorage: true |
194 | }); | 194 | }); |
195 | scope.cobranza = { | 195 | scope.cobranza = { |
196 | cliente: { | 196 | cliente: { |
197 | COD: true | 197 | COD: true |
198 | }, | 198 | }, |
199 | cobrador: { | 199 | cobrador: { |
200 | NUM: true | 200 | NUM: true |
201 | }, | 201 | }, |
202 | facturas: [] | 202 | facturas: [] |
203 | }; | 203 | }; |
204 | 204 | ||
205 | //act | 205 | //act |
206 | spyOn(focaModalService, 'alert'); | 206 | spyOn(focaModalService, 'alert'); |
207 | scope.crearCobranza(); | 207 | scope.crearCobranza(); |
208 | 208 | ||
209 | //assert | 209 | //assert |
210 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura'); | 210 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura'); |
211 | }); | 211 | }); |
212 | 212 | ||
213 | it('crearCobranza muestra alerta cuando la diferencia no es 0', function() { | 213 | it('crearCobranza muestra alerta cuando la diferencia no es 0', function() { |
214 | 214 | ||
215 | //arrange | 215 | //arrange |
216 | var scope = { | 216 | var scope = { |
217 | $broadcast: function() { }, | 217 | $broadcast: function() { }, |
218 | $watch: function() { } | 218 | $watch: function() { } |
219 | }; | 219 | }; |
220 | var focaModalService = { | 220 | var focaModalService = { |
221 | alert: function() { } | 221 | alert: function() { } |
222 | }; | 222 | }; |
223 | 223 | ||
224 | $controller('cobranzaController', { | 224 | $controller('cobranzaController', { |
225 | $scope: scope, | 225 | $scope: scope, |
226 | $timeout: $timeout, | 226 | $timeout: $timeout, |
227 | $uibModal: {}, | 227 | $uibModal: {}, |
228 | $location: {}, | 228 | $location: {}, |
229 | focaCrearCobranzaService: { | 229 | focaCrearCobranzaService: { |
230 | getCotizacionByIdMoneda: function() { | 230 | getCotizacionByIdMoneda: function() { |
231 | return { | 231 | return { |
232 | then: function() { } | 232 | then: function() { } |
233 | }; | 233 | }; |
234 | }, | 234 | }, |
235 | getBotonera: function() { }, | 235 | getBotonera: function() { }, |
236 | getNumeroRecibo: function() { | 236 | getNumeroRecibo: function() { |
237 | return { | 237 | return { |
238 | then: function() { } | 238 | then: function() { } |
239 | }; | 239 | }; |
240 | } | 240 | } |
241 | }, | 241 | }, |
242 | focaModalService: focaModalService, | 242 | focaModalService: focaModalService, |
243 | $filter: $filter, | 243 | $filter: $filter, |
244 | focaSeguimientoService: {}, | 244 | focaSeguimientoService: {}, |
245 | focaBotoneraLateralService: {}, | 245 | focaBotoneraLateralService: {}, |
246 | APP: {}, | 246 | APP: {}, |
247 | focaLoginService: {}, | 247 | focaLoginService: {}, |
248 | $localStorage: true | 248 | $localStorage: true |
249 | }); | 249 | }); |
250 | scope.cobranza = { | 250 | scope.cobranza = { |
251 | cliente: { | 251 | cliente: { |
252 | COD: true | 252 | COD: true |
253 | }, | 253 | }, |
254 | cobrador: { | 254 | cobrador: { |
255 | NUM: true | 255 | NUM: true |
256 | }, | 256 | }, |
257 | cotizacion: { | 257 | cotizacion: { |
258 | moneda: { SIMBOLO: '' }, | 258 | moneda: { SIMBOLO: '' }, |
259 | }, | 259 | }, |
260 | facturas: [1] | 260 | facturas: [1] |
261 | }; | 261 | }; |
262 | scope.facturaTabla = [1]; | 262 | scope.facturaTabla = [1]; |
263 | 263 | ||
264 | //act | 264 | //act |
265 | spyOn(focaModalService, 'alert'); | 265 | spyOn(focaModalService, 'alert'); |
266 | spyOn(scope, 'getTotalCobrado').and.returnValue(1); | 266 | spyOn(scope, 'getTotalCobrado').and.returnValue(1); |
267 | spyOn(scope, 'getTotalDeuda').and.returnValue(1); | 267 | spyOn(scope, 'getTotalDeuda').and.returnValue(1); |
268 | scope.crearCobranza(); | 268 | scope.crearCobranza(); |
269 | 269 | ||
270 | //assert | 270 | //assert |
271 | expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00'); | 271 | expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00'); |
272 | }); | 272 | }); |
273 | 273 | ||
274 | it('crearCobranza llama a startGuardar y guardarCobranza', function() { | 274 | it('crearCobranza llama a startGuardar y guardarCobranza', function() { |
275 | 275 | ||
276 | //arrange | 276 | //arrange |
277 | var scope = { | 277 | var scope = { |
278 | $broadcast: function() { }, | 278 | $broadcast: function() { }, |
279 | $watch: function() { } | 279 | $watch: function() { } |
280 | }; | 280 | }; |
281 | var focaBotoneraLateralService = { | 281 | var focaBotoneraLateralService = { |
282 | startGuardar: function() { } | 282 | startGuardar: function() { } |
283 | }; | 283 | }; |
284 | var focaCrearCobranzaService = { | 284 | var focaCrearCobranzaService = { |
285 | guardarCobranza: function() { }, | 285 | guardarCobranza: function() { }, |
286 | getCotizacionByIdMoneda: function() { | 286 | getCotizacionByIdMoneda: function() { |
287 | return { | 287 | return { |
288 | then: function() { } | 288 | then: function() { } |
289 | }; | 289 | }; |
290 | }, | 290 | }, |
291 | getBotonera: function() { }, | 291 | getBotonera: function() { }, |
292 | getNumeroRecibo: function() { | 292 | getNumeroRecibo: function() { |
293 | return { | 293 | return { |
294 | then: function() { } | 294 | then: function() { } |
295 | }; | 295 | }; |
296 | } | 296 | } |
297 | }; | 297 | }; |
298 | 298 | ||
299 | $controller('cobranzaController', { | 299 | $controller('cobranzaController', { |
300 | $scope: scope, | 300 | $scope: scope, |
301 | $timeout: $timeout, | 301 | $timeout: $timeout, |
302 | $uibModal: {}, | 302 | $uibModal: {}, |
303 | $location: {}, | 303 | $location: {}, |
304 | focaCrearCobranzaService: focaCrearCobranzaService, | 304 | focaCrearCobranzaService: focaCrearCobranzaService, |
305 | focaModalService: { | 305 | focaModalService: { |
306 | alert: function() {} | 306 | alert: function() {} |
307 | }, | 307 | }, |
308 | $filter: $filter, | 308 | $filter: $filter, |
309 | focaSeguimientoService: {}, | 309 | focaSeguimientoService: {}, |
310 | focaBotoneraLateralService: focaBotoneraLateralService, | 310 | focaBotoneraLateralService: focaBotoneraLateralService, |
311 | APP: {}, | 311 | APP: {}, |
312 | focaLoginService: {}, | 312 | focaLoginService: {}, |
313 | $localStorage: true | 313 | $localStorage: true |
314 | }); | 314 | }); |
315 | scope.cobranza = { | 315 | scope.cobranza = { |
316 | cliente: { | 316 | cliente: { |
317 | COD: true | 317 | COD: true |
318 | }, | 318 | }, |
319 | cobrador: { | 319 | cobrador: { |
320 | NUM: true | 320 | NUM: true |
321 | }, | 321 | }, |
322 | cotizacion: { | 322 | cotizacion: { |
323 | moneda: { | 323 | moneda: { |
324 | ID: true, | 324 | ID: true, |
325 | SIMBOLO: '' | 325 | SIMBOLO: '' |
326 | } | 326 | } |
327 | }, | 327 | }, |
328 | facturas: [1], | 328 | facturas: [1], |
329 | cobros: [{ | 329 | cobros: [{ |
330 | fecha: new Date(), | 330 | fecha: new Date(), |
331 | fechaPresentacion: new Date(), | 331 | fechaPresentacion: new Date(), |
332 | fechaEmision: new Date(), | 332 | fechaEmision: new Date(), |
333 | tipo: true, | 333 | tipo: true, |
334 | banco: { | 334 | banco: { |
335 | ID: true | 335 | ID: true |
336 | }, | 336 | }, |
337 | localidad: { | 337 | localidad: { |
338 | ID: true, | 338 | ID: true, |
339 | NOMBRE: true | 339 | NOMBRE: true |
340 | }, | 340 | }, |
341 | provincia: { | 341 | provincia: { |
342 | ID: true | 342 | ID: true |
343 | } | 343 | } |
344 | }], | 344 | }], |
345 | fecha: new Date() | 345 | fecha: new Date() |
346 | }; | 346 | }; |
347 | 347 | ||
348 | //act | 348 | //act |
349 | spyOn(focaBotoneraLateralService, 'startGuardar'); | 349 | spyOn(focaBotoneraLateralService, 'startGuardar'); |
350 | spyOn(focaCrearCobranzaService, 'guardarCobranza') | 350 | spyOn(focaCrearCobranzaService, 'guardarCobranza') |
351 | .and.returnValue({ then: function() { } }); | 351 | .and.returnValue({ then: function() { } }); |
352 | spyOn(scope, 'getTotalCobrado').and.returnValue(0); | 352 | spyOn(scope, 'getTotalCobrado').and.returnValue(0); |
353 | spyOn(scope, 'getTotalDeuda').and.returnValue(0); | 353 | spyOn(scope, 'getTotalDeuda').and.returnValue(0); |
354 | scope.crearCobranza(); | 354 | scope.crearCobranza(); |
355 | 355 | ||
356 | //assert | 356 | //assert |
357 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); | 357 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); |
358 | expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled(); | 358 | expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled(); |
359 | }); | 359 | }); |
360 | 360 | ||
361 | it('seleccionarCobros seatea cobroDeuda en false', function() { | 361 | it('seleccionarCobros seatea cobroDeuda en false', function() { |
362 | 362 | ||
363 | //arrange | 363 | //arrange |
364 | var scope = { | 364 | var scope = { |
365 | $broadcast: function() { }, | 365 | $broadcast: function() { }, |
366 | $watch: function() { } | 366 | $watch: function() { } |
367 | }; | 367 | }; |
368 | 368 | ||
369 | $controller('cobranzaController', { | 369 | $controller('cobranzaController', { |
370 | $scope: scope, | 370 | $scope: scope, |
371 | $timeout: $timeout, | 371 | $timeout: $timeout, |
372 | $uibModal: {}, | 372 | $uibModal: {}, |
373 | $location: {}, | 373 | $location: {}, |
374 | focaCrearCobranzaService: { | 374 | focaCrearCobranzaService: { |
375 | getCotizacionByIdMoneda: function() { | 375 | getCotizacionByIdMoneda: function() { |
376 | return { | 376 | return { |
377 | then: function() { } | 377 | then: function() { } |
378 | }; | 378 | }; |
379 | }, | 379 | }, |
380 | getBotonera: function() { }, | 380 | getBotonera: function() { }, |
381 | getNumeroRecibo: function() { | 381 | getNumeroRecibo: function() { |
382 | return { | 382 | return { |
383 | then: function() { } | 383 | then: function() { } |
384 | }; | 384 | }; |
385 | } | 385 | } |
386 | }, | 386 | }, |
387 | focaModalService: {}, | 387 | focaModalService: {}, |
388 | $filter: $filter, | 388 | $filter: $filter, |
389 | focaSeguimientoService: {}, | 389 | focaSeguimientoService: {}, |
390 | focaBotoneraLateralService: {}, | 390 | focaBotoneraLateralService: {}, |
391 | APP: {}, | 391 | APP: {}, |
392 | focaLoginService: {}, | 392 | focaLoginService: {}, |
393 | $localStorage: true | 393 | $localStorage: true |
394 | }); | 394 | }); |
395 | 395 | ||
396 | //act | 396 | //act |
397 | scope.seleccionarCobros(); | 397 | scope.seleccionarCobros(); |
398 | 398 | ||
399 | //assert | 399 | //assert |
400 | expect(scope.cobroDeuda).toEqual(false); | 400 | expect(scope.cobroDeuda).toEqual(false); |
401 | }); | 401 | }); |
402 | 402 | ||
403 | it('seleccionarComprobantes seatea cobroDeuda en true', function() { | 403 | it('seleccionarComprobantes seatea cobroDeuda en true', function() { |
404 | 404 | ||
405 | //arrange | 405 | //arrange |
406 | var scope = { | 406 | var scope = { |
407 | $broadcast: function() { }, | 407 | $broadcast: function() { }, |
408 | $watch: function() { } | 408 | $watch: function() { } |
409 | }; | 409 | }; |
410 | 410 | ||
411 | $controller('cobranzaController', { | 411 | $controller('cobranzaController', { |
412 | $scope: scope, | 412 | $scope: scope, |
413 | $timeout: $timeout, | 413 | $timeout: $timeout, |
414 | $uibModal: {}, | 414 | $uibModal: {}, |
415 | $location: {}, | 415 | $location: {}, |
416 | focaCrearCobranzaService: { | 416 | focaCrearCobranzaService: { |
417 | getCotizacionByIdMoneda: function() { | 417 | getCotizacionByIdMoneda: function() { |
418 | return { | 418 | return { |
419 | then: function() { } | 419 | then: function() { } |
420 | }; | 420 | }; |
421 | }, | 421 | }, |
422 | getBotonera: function() { }, | 422 | getBotonera: function() { }, |
423 | getNumeroRecibo: function() { | 423 | getNumeroRecibo: function() { |
424 | return { | 424 | return { |
425 | then: function() { } | 425 | then: function() { } |
426 | }; | 426 | }; |
427 | } | 427 | } |
428 | }, | 428 | }, |
429 | focaModalService: {}, | 429 | focaModalService: {}, |
430 | $filter: $filter, | 430 | $filter: $filter, |
431 | focaSeguimientoService: {}, | 431 | focaSeguimientoService: {}, |
432 | focaBotoneraLateralService: {}, | 432 | focaBotoneraLateralService: {}, |
433 | APP: {}, | 433 | APP: {}, |
434 | focaLoginService: {}, | 434 | focaLoginService: {}, |
435 | $localStorage: true | 435 | $localStorage: true |
436 | }); | 436 | }); |
437 | 437 | ||
438 | //act | 438 | //act |
439 | scope.seleccionarComprobantes(); | 439 | scope.seleccionarComprobantes(); |
440 | 440 | ||
441 | //assert | 441 | //assert |
442 | expect(scope.cobroDeuda).toEqual(true); | 442 | expect(scope.cobroDeuda).toEqual(true); |
443 | }); | 443 | }); |
444 | 444 | ||
445 | it('seleccionarCobranza levanta modal y setea datos', function(done) { | 445 | it('seleccionarCobranza levanta modal y setea datos', function(done) { |
446 | 446 | ||
447 | //arrange | 447 | //arrange |
448 | var scope = { | 448 | var scope = { |
449 | $broadcast: function() { }, | 449 | $broadcast: function() { }, |
450 | $watch: function() { } | 450 | $watch: function() { } |
451 | }; | 451 | }; |
452 | var uibModal = { | 452 | var uibModal = { |
453 | open: function() { } | 453 | open: function() { } |
454 | }; | 454 | }; |
455 | 455 | ||
456 | $controller('cobranzaController', { | 456 | $controller('cobranzaController', { |
457 | $scope: scope, | 457 | $scope: scope, |
458 | $timeout: $timeout, | 458 | $timeout: $timeout, |
459 | $uibModal: uibModal, | 459 | $uibModal: uibModal, |
460 | $location: {}, | 460 | $location: {}, |
461 | focaCrearCobranzaService: { | 461 | focaCrearCobranzaService: { |
462 | getCotizacionByIdMoneda: function() { | 462 | getCotizacionByIdMoneda: function() { |
463 | return { | 463 | return { |
464 | then: function() { } | 464 | then: function() { } |
465 | }; | 465 | }; |
466 | }, | 466 | }, |
467 | getBotonera: function() { }, | 467 | getBotonera: function() { }, |
468 | getNumeroRecibo: function() { | 468 | getNumeroRecibo: function() { |
469 | return { | 469 | return { |
470 | then: function() { } | 470 | then: function() { } |
471 | }; | 471 | }; |
472 | } | 472 | } |
473 | }, | 473 | }, |
474 | focaModalService: {}, | 474 | focaModalService: {}, |
475 | $filter: $filter, | 475 | $filter: $filter, |
476 | focaSeguimientoService: {}, | 476 | focaSeguimientoService: {}, |
477 | focaBotoneraLateralService: {}, | 477 | focaBotoneraLateralService: {}, |
478 | APP: {}, | 478 | APP: {}, |
479 | focaLoginService: {}, | 479 | focaLoginService: {}, |
480 | $localStorage: true | 480 | $localStorage: true |
481 | }); | 481 | }); |
482 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; | 482 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; |
483 | var promesa = { result: Promise.resolve(respuesta) }; | 483 | var promesa = { result: Promise.resolve(respuesta) }; |
484 | 484 | ||
485 | //act | 485 | //act |
486 | spyOn(uibModal, 'open').and.returnValue(promesa); | 486 | spyOn(uibModal, 'open').and.returnValue(promesa); |
487 | spyOn(scope, '$broadcast'); | 487 | spyOn(scope, '$broadcast'); |
488 | scope.seleccionarCobranza(); | 488 | scope.seleccionarCobranza(); |
489 | 489 | ||
490 | //assert | 490 | //assert |
491 | promesa.result.then(function() { | 491 | promesa.result.then(function() { |
492 | expect(uibModal.open).toHaveBeenCalled(); | 492 | expect(uibModal.open).toHaveBeenCalled(); |
493 | expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera'); | 493 | expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera'); |
494 | expect(scope.cobranza.facturas).toEqual(respuesta.facturas); | 494 | expect(scope.cobranza.facturas).toEqual(respuesta.facturas); |
495 | expect(scope.cobranza.cobros).toEqual(respuesta.cobros); | 495 | expect(scope.cobranza.cobros).toEqual(respuesta.cobros); |
496 | done(); | 496 | done(); |
497 | }); | 497 | }); |
498 | }); | 498 | }); |
499 | 499 | ||
500 | it('seleccionarCliente levanta modal y setea datos', function(done) { | 500 | it('seleccionarCliente levanta modal y setea datos', function(done) { |
501 | 501 | ||
502 | //arrange | 502 | //arrange |
503 | var scope = { | 503 | var scope = { |
504 | $broadcast: function() { }, | 504 | $broadcast: function() { }, |
505 | $watch: function() { } | 505 | $watch: function() { } |
506 | }; | 506 | }; |
507 | var uibModal = { | 507 | var uibModal = { |
508 | open: function() { } | 508 | open: function() { } |
509 | }; | 509 | }; |
510 | 510 | ||
511 | $controller('cobranzaController', { | 511 | $controller('cobranzaController', { |
512 | $scope: scope, | 512 | $scope: scope, |
513 | $timeout: $timeout, | 513 | $timeout: $timeout, |
514 | $uibModal: uibModal, | 514 | $uibModal: uibModal, |
515 | $location: {}, | 515 | $location: {}, |
516 | focaCrearCobranzaService: { | 516 | focaCrearCobranzaService: { |
517 | getCotizacionByIdMoneda: function() { | 517 | getCotizacionByIdMoneda: function() { |
518 | return { | 518 | return { |
519 | then: function() { } | 519 | then: function() { } |
520 | }; | 520 | }; |
521 | }, | 521 | }, |
522 | getBotonera: function() { }, | 522 | getBotonera: function() { }, |
523 | getNumeroRecibo: function() { | 523 | getNumeroRecibo: function() { |
524 | return { | 524 | return { |
525 | then: function() { } | 525 | then: function() { } |
526 | }; | 526 | }; |
527 | }, | ||
528 | getCobradorById: function() { | ||
529 | return { | ||
530 | then: function() { } | ||
531 | }; | ||
532 | } | ||
533 | }, | ||
534 | focaModalService: { | ||
535 | modal: function() { | ||
536 | return { | ||
537 | then: function() {} | ||
538 | }; | ||
527 | } | 539 | } |
528 | }, | 540 | }, |
529 | focaModalService: {}, | ||
530 | $filter: $filter, | 541 | $filter: $filter, |
531 | focaSeguimientoService: {}, | 542 | focaSeguimientoService: {}, |
532 | focaBotoneraLateralService: {}, | 543 | focaBotoneraLateralService: {}, |
533 | APP: {}, | 544 | APP: 'cobranza', |
534 | focaLoginService: {}, | 545 | focaLoginService: { |
546 | getLoginData: function() { | ||
547 | return { | ||
548 | vendedorCobrador: true | ||
549 | }; | ||
550 | } | ||
551 | }, | ||
535 | $localStorage: true | 552 | $localStorage: true |
536 | }); | 553 | }); |
537 | scope.cobranza = { | 554 | scope.cobranza = { |
538 | cobrador: {} | 555 | cobrador: {} |
539 | }; | 556 | }; |
540 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; | 557 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; |
541 | var promesa = { result: Promise.resolve(respuesta) }; | 558 | var promesa = { result: Promise.resolve(respuesta) }; |
542 | 559 | ||
543 | //act | 560 | //act |
544 | spyOn(uibModal, 'open').and.returnValue(promesa); | 561 | spyOn(uibModal, 'open').and.returnValue(promesa); |
545 | spyOn(scope, '$broadcast'); | 562 | spyOn(scope, '$broadcast'); |
546 | scope.seleccionarCliente(); | 563 | scope.seleccionarCliente(); |
547 | 564 | ||
548 | //assert | 565 | //assert |
549 | promesa.result.then(function() { | 566 | promesa.result.then(function() { |
550 | expect(uibModal.open).toHaveBeenCalled(); | 567 | expect(uibModal.open).toHaveBeenCalled(); |
551 | expect(scope.$broadcast).toHaveBeenCalled(); | 568 | expect(scope.$broadcast).toHaveBeenCalled(); |
552 | done(); | 569 | done(); |
553 | }); | 570 | }); |
554 | }); | 571 | }); |
555 | 572 | ||
556 | it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() { | 573 | it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() { |
557 | 574 | ||
558 | //arrange | 575 | //arrange |
559 | var scope = { | 576 | var scope = { |
560 | $broadcast: function() { }, | 577 | $broadcast: function() { }, |
561 | $watch: function() { } | 578 | $watch: function() { } |
562 | }; | 579 | }; |
563 | var focaModalService = { | 580 | var focaModalService = { |
564 | alert: function() { } | 581 | alert: function() { } |
565 | }; | 582 | }; |
566 | 583 | ||
567 | $controller('cobranzaController', { | 584 | $controller('cobranzaController', { |
568 | $scope: scope, | 585 | $scope: scope, |
569 | $timeout: $timeout, | 586 | $timeout: $timeout, |
570 | $uibModal: { | 587 | $uibModal: { |
571 | open: function() { | 588 | open: function() { |
572 | return { | 589 | return { |
573 | result: { | 590 | result: { |
574 | then: function() { } | 591 | then: function() { } |
575 | } | 592 | } |
576 | }; | 593 | }; |
577 | } | 594 | } |
578 | }, | 595 | }, |
579 | $location: {}, | 596 | $location: {}, |
580 | focaCrearCobranzaService: { | 597 | focaCrearCobranzaService: { |
581 | getCotizacionByIdMoneda: function() { | 598 | getCotizacionByIdMoneda: function() { |
582 | return { | 599 | return { |
583 | then: function() { } | 600 | then: function() { } |
584 | }; | 601 | }; |
585 | }, | 602 | }, |
586 | getBotonera: function() { }, | 603 | getBotonera: function() { }, |
587 | getNumeroRecibo: function() { | 604 | getNumeroRecibo: function() { |
588 | return { | 605 | return { |
589 | then: function() { } | 606 | then: function() { } |
590 | }; | 607 | }; |
591 | } | 608 | } |
592 | }, | 609 | }, |
593 | focaModalService: focaModalService, | 610 | focaModalService: focaModalService, |
594 | $filter: $filter, | 611 | $filter: $filter, |
595 | focaSeguimientoService: {}, | 612 | focaSeguimientoService: {}, |
596 | focaBotoneraLateralService: {}, | 613 | focaBotoneraLateralService: {}, |
597 | APP: {}, | 614 | APP: {}, |
598 | focaLoginService: {}, | 615 | focaLoginService: {}, |
599 | $localStorage: true | 616 | $localStorage: true |
600 | }); | 617 | }); |
601 | 618 | ||
602 | //act | 619 | //act |
603 | spyOn(focaModalService, 'alert'); | 620 | spyOn(focaModalService, 'alert'); |
604 | scope.seleccionarFactura(); | 621 | scope.seleccionarFactura(); |
605 | 622 | ||
606 | //assert | 623 | //assert |
607 | expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente'); | 624 | expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente'); |
608 | }); | 625 | }); |
609 | 626 | ||
610 | it('seleccionarFactura levanta modal', function() { | 627 | it('seleccionarFactura levanta modal', function() { |
611 | 628 | ||
612 | //arrange | 629 | //arrange |
613 | var scope = { | 630 | var scope = { |
614 | $broadcast: function() { }, | 631 | $broadcast: function() { }, |
615 | $watch: function() { } | 632 | $watch: function() { } |
616 | }; | 633 | }; |
617 | var uibModal = { | 634 | var uibModal = { |
618 | open: function() { } | 635 | open: function() { } |
619 | }; | 636 | }; |
620 | 637 | ||
621 | $controller('cobranzaController', { | 638 | $controller('cobranzaController', { |
622 | $scope: scope, | 639 | $scope: scope, |
623 | $timeout: $timeout, | 640 | $timeout: $timeout, |
624 | $uibModal: uibModal, | 641 | $uibModal: uibModal, |
625 | $location: {}, | 642 | $location: {}, |
626 | focaCrearCobranzaService: { | 643 | focaCrearCobranzaService: { |
627 | getCotizacionByIdMoneda: function() { | 644 | getCotizacionByIdMoneda: function() { |
628 | return { | 645 | return { |
629 | then: function() { } | 646 | then: function() { } |
630 | }; | 647 | }; |
631 | }, | 648 | }, |
632 | getBotonera: function() { }, | 649 | getBotonera: function() { }, |
633 | getNumeroRecibo: function() { | 650 | getNumeroRecibo: function() { |
634 | return { | 651 | return { |
635 | then: function() { } | 652 | then: function() { } |
636 | }; | 653 | }; |
637 | } | 654 | } |
638 | }, | 655 | }, |
639 | focaModalService: { | 656 | focaModalService: { |
640 | alert: function() {} | 657 | alert: function() {} |
641 | }, | 658 | }, |
642 | $filter: $filter, | 659 | $filter: $filter, |
643 | focaSeguimientoService: {}, | 660 | focaSeguimientoService: {}, |
644 | focaBotoneraLateralService: {}, | 661 | focaBotoneraLateralService: {}, |
645 | APP: {}, | 662 | APP: {}, |
646 | focaLoginService: {}, | 663 | focaLoginService: {}, |
647 | $localStorage: true | 664 | $localStorage: true |
648 | }); | 665 | }); |
649 | scope.cobranza = { | 666 | scope.cobranza = { |
650 | cliente: { | 667 | cliente: { |
651 | COD: true | 668 | COD: true |
652 | } | 669 | } |
653 | }; | 670 | }; |
654 | 671 | ||
655 | var respuesta = { result: { then: function() { } } }; | 672 | var respuesta = { result: { then: function() { } } }; |
656 | 673 | ||
657 | //act | 674 | //act |
658 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 675 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
659 | scope.seleccionarFactura(); | 676 | scope.seleccionarFactura(); |
660 | 677 | ||
661 | //assert | 678 | //assert |
662 | expect(uibModal.open).toHaveBeenCalled(); | 679 | expect(uibModal.open).toHaveBeenCalled(); |
663 | }); | 680 | }); |
664 | 681 | ||
665 | it('seleccionarCheque levanta modal', function() { | 682 | it('seleccionarCheque levanta modal', function() { |
666 | 683 | ||
667 | //arrange | 684 | //arrange |
668 | var scope = { | 685 | var scope = { |
669 | $broadcast: function() { }, | 686 | $broadcast: function() { }, |
670 | $watch: function() { } | 687 | $watch: function() { } |
671 | }; | 688 | }; |
672 | var uibModal = { | 689 | var uibModal = { |
673 | open: function() { } | 690 | open: function() { } |
674 | }; | 691 | }; |
675 | 692 | ||
676 | $controller('cobranzaController', { | 693 | $controller('cobranzaController', { |
677 | $scope: scope, | 694 | $scope: scope, |
678 | $timeout: $timeout, | 695 | $timeout: $timeout, |
679 | $uibModal: uibModal, | 696 | $uibModal: uibModal, |
680 | $location: {}, | 697 | $location: {}, |
681 | focaCrearCobranzaService: { | 698 | focaCrearCobranzaService: { |
682 | getCotizacionByIdMoneda: function() { | 699 | getCotizacionByIdMoneda: function() { |
683 | return { | 700 | return { |
684 | then: function() { } | 701 | then: function() { } |
685 | }; | 702 | }; |
686 | }, | 703 | }, |
687 | getBotonera: function() { }, | 704 | getBotonera: function() { }, |
688 | getNumeroRecibo: function() { | 705 | getNumeroRecibo: function() { |
689 | return { | 706 | return { |
690 | then: function() { } | 707 | then: function() { } |
691 | }; | 708 | }; |
692 | } | 709 | } |
693 | }, | 710 | }, |
694 | focaModalService: {}, | 711 | focaModalService: {}, |
695 | $filter: $filter, | 712 | $filter: $filter, |
696 | focaSeguimientoService: {}, | 713 | focaSeguimientoService: {}, |
697 | focaBotoneraLateralService: {}, | 714 | focaBotoneraLateralService: {}, |
698 | APP: {}, | 715 | APP: {}, |
699 | focaLoginService: {}, | 716 | focaLoginService: {}, |
700 | $localStorage: true | 717 | $localStorage: true |
701 | }); | 718 | }); |
702 | scope.cobranza = { | 719 | scope.cobranza = { |
703 | cliente: { } | 720 | cliente: { } |
704 | }; | 721 | }; |
705 | 722 | ||
706 | var respuesta = { result: { then: function() { } } }; | 723 | var respuesta = { result: { then: function() { } } }; |
707 | 724 | ||
708 | //act | 725 | //act |
709 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 726 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
710 | scope.seleccionarCheque(); | 727 | scope.seleccionarCheque(); |
711 | 728 | ||
712 | //assert | 729 | //assert |
713 | expect(uibModal.open).toHaveBeenCalled(); | 730 | expect(uibModal.open).toHaveBeenCalled(); |
714 | }); | 731 | }); |
715 | 732 | ||
716 | it('seleccionarEfectivo levanta modal', function() { | 733 | it('seleccionarEfectivo levanta modal', function() { |
717 | 734 | ||
718 | //arrange | 735 | //arrange |
719 | var scope = { | 736 | var scope = { |
720 | $broadcast: function() { }, | 737 | $broadcast: function() { }, |
721 | $watch: function() { } | 738 | $watch: function() { } |
722 | }; | 739 | }; |
723 | var uibModal = { | 740 | var uibModal = { |
724 | open: function() { } | 741 | open: function() { } |
725 | }; | 742 | }; |
726 | 743 | ||
727 | $controller('cobranzaController', { | 744 | $controller('cobranzaController', { |
728 | $scope: scope, | 745 | $scope: scope, |
729 | $timeout: $timeout, | 746 | $timeout: $timeout, |
730 | $uibModal: uibModal, | 747 | $uibModal: uibModal, |
731 | $location: {}, | 748 | $location: {}, |
732 | focaCrearCobranzaService: { | 749 | focaCrearCobranzaService: { |
733 | getCotizacionByIdMoneda: function() { | 750 | getCotizacionByIdMoneda: function() { |
734 | return { | 751 | return { |
735 | then: function() { } | 752 | then: function() { } |
736 | }; | 753 | }; |
737 | }, | 754 | }, |
738 | getBotonera: function() { }, | 755 | getBotonera: function() { }, |
739 | getNumeroRecibo: function() { | 756 | getNumeroRecibo: function() { |
740 | return { | 757 | return { |
741 | then: function() { } | 758 | then: function() { } |
742 | }; | 759 | }; |
743 | } | 760 | } |
744 | }, | 761 | }, |
745 | focaModalService: {}, | 762 | focaModalService: {}, |
746 | $filter: $filter, | 763 | $filter: $filter, |
747 | focaSeguimientoService: {}, | 764 | focaSeguimientoService: {}, |
748 | focaBotoneraLateralService: {}, | 765 | focaBotoneraLateralService: {}, |
749 | APP: {}, | 766 | APP: {}, |
750 | focaLoginService: {}, | 767 | focaLoginService: {}, |
751 | $localStorage: true | 768 | $localStorage: true |
752 | }); | 769 | }); |
753 | scope.cobranza = { | 770 | scope.cobranza = { |
754 | cliente: { } | 771 | cliente: { } |
755 | }; | 772 | }; |
756 | 773 | ||
757 | var respuesta = { result: { then: function() { } } }; | 774 | var respuesta = { result: { then: function() { } } }; |
758 | 775 | ||
759 | //act | 776 | //act |
760 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 777 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
761 | scope.seleccionarEfectivo(); | 778 | scope.seleccionarEfectivo(); |
762 | 779 | ||
763 | //assert | 780 | //assert |
764 | expect(uibModal.open).toHaveBeenCalled(); | 781 | expect(uibModal.open).toHaveBeenCalled(); |
765 | }); | 782 | }); |
766 | 783 | ||
767 | it('seleccionarDetalles levanta modal', function() { | 784 | it('seleccionarDetalles levanta modal', function() { |
768 | 785 | ||
769 | //arrange | 786 | //arrange |
770 | var scope = { | 787 | var scope = { |
771 | $broadcast: function() { }, | 788 | $broadcast: function() { }, |
772 | $watch: function() { } | 789 | $watch: function() { } |
773 | }; | 790 | }; |
774 | var uibModal = { | 791 | var uibModal = { |
775 | open: function() { } | 792 | open: function() { } |
776 | }; | 793 | }; |
777 | 794 | ||
778 | $controller('cobranzaController', { | 795 | $controller('cobranzaController', { |
779 | $scope: scope, | 796 | $scope: scope, |
780 | $timeout: $timeout, | 797 | $timeout: $timeout, |
781 | $uibModal: uibModal, | 798 | $uibModal: uibModal, |
782 | $location: {}, | 799 | $location: {}, |
783 | focaCrearCobranzaService: { | 800 | focaCrearCobranzaService: { |
784 | getCotizacionByIdMoneda: function() { | 801 | getCotizacionByIdMoneda: function() { |
785 | return { | 802 | return { |
786 | then: function() { } | 803 | then: function() { } |
787 | }; | 804 | }; |
788 | }, | 805 | }, |
789 | getBotonera: function() { }, | 806 | getBotonera: function() { }, |
790 | getNumeroRecibo: function() { | 807 | getNumeroRecibo: function() { |
791 | return { | 808 | return { |
792 | then: function() { } | 809 | then: function() { } |
793 | }; | 810 | }; |
794 | } | 811 | } |
795 | }, | 812 | }, |
796 | focaModalService: {}, | 813 | focaModalService: {}, |
797 | $filter: $filter, | 814 | $filter: $filter, |
798 | focaSeguimientoService: {}, | 815 | focaSeguimientoService: {}, |
799 | focaBotoneraLateralService: {}, | 816 | focaBotoneraLateralService: {}, |
800 | APP: {}, | 817 | APP: {}, |
801 | focaLoginService: {}, | 818 | focaLoginService: {}, |
802 | $localStorage: true | 819 | $localStorage: true |
803 | }); | 820 | }); |
804 | scope.cobranza = { | 821 | scope.cobranza = { |
805 | cliente: { } | 822 | cliente: { } |
806 | }; | 823 | }; |
807 | 824 | ||
808 | var respuesta = { result: { then: function() { } } }; | 825 | var respuesta = { result: { then: function() { } } }; |
809 | 826 | ||
810 | //act | 827 | //act |
811 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 828 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
812 | scope.seleccionarDetalles(); | 829 | scope.seleccionarDetalles(); |
813 | 830 | ||
814 | //assert | 831 | //assert |
815 | expect(uibModal.open).toHaveBeenCalled(); | 832 | expect(uibModal.open).toHaveBeenCalled(); |
816 | }); | 833 | }); |
817 | 834 | ||
818 | it('seleccionarMoneda levanta modal', function(done) { | 835 | it('seleccionarMoneda levanta modal', function(done) { |
819 | 836 | ||
820 | //arrange | 837 | //arrange |
821 | var scope = { | 838 | var scope = { |
822 | $broadcast: function() { }, | 839 | $broadcast: function() { }, |
823 | $watch: function() { } | 840 | $watch: function() { } |
824 | }; | 841 | }; |
825 | var focaModalService = { | 842 | var focaModalService = { |
826 | modal: function() { } | 843 | modal: function() { } |
827 | }; | 844 | }; |
828 | 845 | ||
829 | $controller('cobranzaController', { | 846 | $controller('cobranzaController', { |
830 | $scope: scope, | 847 | $scope: scope, |
831 | $timeout: $timeout, | 848 | $timeout: $timeout, |
832 | $uibModal: {}, | 849 | $uibModal: {}, |
833 | $location: {}, | 850 | $location: {}, |
834 | focaCrearCobranzaService: { | 851 | focaCrearCobranzaService: { |
835 | getCotizacionByIdMoneda: function() { | 852 | getCotizacionByIdMoneda: function() { |
836 | return { | 853 | return { |
837 | then: function() { } | 854 | then: function() { } |
838 | }; | 855 | }; |
839 | }, | 856 | }, |
840 | getBotonera: function() { }, | 857 | getBotonera: function() { }, |
841 | getNumeroRecibo: function() { | 858 | getNumeroRecibo: function() { |
842 | return { | 859 | return { |
843 | then: function() { } | 860 | then: function() { } |
844 | }; | 861 | }; |
845 | } | 862 | } |
846 | }, | 863 | }, |
847 | focaModalService: focaModalService, | 864 | focaModalService: focaModalService, |
848 | $filter: $filter, | 865 | $filter: $filter, |
849 | focaSeguimientoService: {}, | 866 | focaSeguimientoService: {}, |
850 | focaBotoneraLateralService: {}, | 867 | focaBotoneraLateralService: {}, |
851 | APP: {}, | 868 | APP: {}, |
852 | focaLoginService: {}, | 869 | focaLoginService: {}, |
853 | $localStorage: true | 870 | $localStorage: true |
854 | }); | 871 | }); |
855 | 872 | ||
856 | var respuesta = 1; | 873 | var respuesta = 1; |
857 | var promesa = Promise.resolve(respuesta); | 874 | var promesa = Promise.resolve(respuesta); |
858 | 875 | ||
859 | //act | 876 | //act |
860 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 877 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
861 | spyOn(scope, 'seleccionarCotizacion'); | 878 | spyOn(scope, 'seleccionarCotizacion'); |
862 | scope.seleccionarMoneda(); | 879 | scope.seleccionarMoneda(); |
863 | 880 | ||
864 | //assert | 881 | //assert |
865 | expect(focaModalService.modal).toHaveBeenCalled(); | 882 | expect(focaModalService.modal).toHaveBeenCalled(); |
866 | promesa.then(function() { | 883 | promesa.then(function() { |
867 | expect(scope.seleccionarCotizacion).toHaveBeenCalled(); | 884 | expect(scope.seleccionarCotizacion).toHaveBeenCalled(); |
868 | done(); | 885 | done(); |
869 | }); | 886 | }); |
870 | }); | 887 | }); |
871 | 888 | ||
872 | it('seleccionarCotizacion levanta modal', function(done) { | 889 | it('seleccionarCotizacion levanta modal', function(done) { |
873 | 890 | ||
874 | //arrange | 891 | //arrange |
875 | var scope = { | 892 | var scope = { |
876 | $broadcast: function() { }, | 893 | $broadcast: function() { }, |
877 | $watch: function() { } | 894 | $watch: function() { } |
878 | }; | 895 | }; |
879 | var uibModal = { | 896 | var uibModal = { |
880 | open: function() { } | 897 | open: function() { } |
881 | }; | 898 | }; |
882 | 899 | ||
883 | $controller('cobranzaController', { | 900 | $controller('cobranzaController', { |
884 | $scope: scope, | 901 | $scope: scope, |
885 | $timeout: $timeout, | 902 | $timeout: $timeout, |
886 | $uibModal: uibModal, | 903 | $uibModal: uibModal, |
887 | $location: {}, | 904 | $location: {}, |
888 | focaCrearCobranzaService: { | 905 | focaCrearCobranzaService: { |
889 | getCotizacionByIdMoneda: function() { | 906 | getCotizacionByIdMoneda: function() { |
890 | return { | 907 | return { |
891 | then: function() { } | 908 | then: function() { } |
892 | }; | 909 | }; |
893 | }, | 910 | }, |
894 | getBotonera: function() { }, | 911 | getBotonera: function() { }, |
895 | getNumeroRecibo: function() { | 912 | getNumeroRecibo: function() { |
896 | return { | 913 | return { |
897 | then: function() { } | 914 | then: function() { } |
898 | }; | 915 | }; |
899 | } | 916 | } |
900 | }, | 917 | }, |
901 | focaModalService: {}, | 918 | focaModalService: {}, |
902 | $filter: $filter, | 919 | $filter: $filter, |
903 | focaSeguimientoService: {}, | 920 | focaSeguimientoService: {}, |
904 | focaBotoneraLateralService: {}, | 921 | focaBotoneraLateralService: {}, |
905 | APP: {}, | 922 | APP: {}, |
906 | focaLoginService: {}, | 923 | focaLoginService: {}, |
907 | $localStorage: true | 924 | $localStorage: true |
908 | }); | 925 | }); |
909 | 926 | ||
910 | var respuesta = 1; | 927 | var respuesta = 1; |
911 | var promesa = { result: Promise.resolve(respuesta) }; | 928 | var promesa = { result: Promise.resolve(respuesta) }; |
912 | 929 | ||
913 | //act | 930 | //act |
914 | spyOn(uibModal, 'open').and.returnValue(promesa); | 931 | spyOn(uibModal, 'open').and.returnValue(promesa); |
915 | spyOn(scope, '$broadcast'); | 932 | spyOn(scope, '$broadcast'); |
916 | scope.seleccionarCotizacion({ }); | 933 | scope.seleccionarCotizacion({ }); |
917 | 934 | ||
918 | //assert | 935 | //assert |
919 | promesa.result.then(function() { | 936 | promesa.result.then(function() { |
920 | expect(uibModal.open).toHaveBeenCalled(); | 937 | expect(uibModal.open).toHaveBeenCalled(); |
921 | expect(scope.$broadcast).toHaveBeenCalled(); | 938 | expect(scope.$broadcast).toHaveBeenCalled(); |
922 | scope.cobranza.cotizacion = respuesta; | 939 | scope.cobranza.cotizacion = respuesta; |
923 | done(); | 940 | done(); |
924 | }); | 941 | }); |
925 | }); | 942 | }); |
926 | 943 | ||
927 | it('seleccionarCobrador levanta modal', function(done) { | 944 | it('seleccionarCobrador levanta modal', function(done) { |
928 | 945 | ||
929 | //arrange | 946 | //arrange |
930 | var scope = { | 947 | var scope = { |
931 | $broadcast: function() { }, | 948 | $broadcast: function() { }, |
932 | $watch: function() { } | 949 | $watch: function() { } |
933 | }; | 950 | }; |
934 | var focaModalService = { | 951 | var focaModalService = { |
935 | modal: function() { } | 952 | modal: function() { } |
936 | }; | 953 | }; |
937 | 954 | ||
938 | $controller('cobranzaController', { | 955 | $controller('cobranzaController', { |
939 | $scope: scope, | 956 | $scope: scope, |
940 | $timeout: $timeout, | 957 | $timeout: $timeout, |
941 | $uibModal: {}, | 958 | $uibModal: {}, |
942 | $location: {}, | 959 | $location: {}, |
943 | focaCrearCobranzaService: { | 960 | focaCrearCobranzaService: { |
944 | getCotizacionByIdMoneda: function() { | 961 | getCotizacionByIdMoneda: function() { |
945 | return { | 962 | return { |
946 | then: function() { } | 963 | then: function() { } |
947 | }; | 964 | }; |
948 | }, | 965 | }, |
949 | getBotonera: function() { }, | 966 | getBotonera: function() { }, |
950 | getNumeroRecibo: function() { | 967 | getNumeroRecibo: function() { |
951 | return { | 968 | return { |
952 | then: function() { } | 969 | then: function() { } |
953 | }; | 970 | }; |
954 | } | 971 | } |
955 | }, | 972 | }, |
956 | focaModalService: focaModalService, | 973 | focaModalService: focaModalService, |
957 | $filter: $filter, | 974 | $filter: $filter, |
958 | focaSeguimientoService: {}, | 975 | focaSeguimientoService: {}, |
959 | focaBotoneraLateralService: {}, | 976 | focaBotoneraLateralService: {}, |
960 | APP: {}, | 977 | APP: {}, |
961 | focaLoginService: {}, | 978 | focaLoginService: {}, |
962 | $localStorage: true | 979 | $localStorage: true |
963 | }); | 980 | }); |
964 | 981 | ||
965 | var respuesta = 1; | 982 | var respuesta = 1; |
966 | var promesa = Promise.resolve(respuesta); | 983 | var promesa = Promise.resolve(respuesta); |
967 | 984 | ||
968 | //act | 985 | //act |
969 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 986 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
970 | spyOn(scope, '$broadcast'); | 987 | spyOn(scope, '$broadcast'); |
971 | scope.seleccionarCobrador({ }); | 988 | scope.seleccionarCobrador({ }); |
972 | 989 | ||
973 | //assert | 990 | //assert |
974 | promesa.then(function() { | 991 | promesa.then(function() { |
975 | expect(focaModalService.modal).toHaveBeenCalled(); | 992 | expect(focaModalService.modal).toHaveBeenCalled(); |
976 | expect(scope.$broadcast).toHaveBeenCalled(); | 993 | expect(scope.$broadcast).toHaveBeenCalled(); |
977 | scope.cobranza.cobrador = respuesta; | 994 | scope.cobranza.cobrador = respuesta; |
978 | done(); | 995 | done(); |
979 | }); | 996 | }); |
980 | }); | 997 | }); |
981 | 998 | ||
982 | it('getTotalDeuda devuelve correcto', function() { | 999 | it('getTotalDeuda devuelve correcto', function() { |
983 | 1000 | ||
984 | //arrange | 1001 | //arrange |
985 | var scope = { | 1002 | var scope = { |
986 | $broadcast: function() { }, | 1003 | $broadcast: function() { }, |
987 | $watch: function() { } | 1004 | $watch: function() { } |
988 | }; | 1005 | }; |
989 | 1006 | ||
990 | $controller('cobranzaController', { | 1007 | $controller('cobranzaController', { |
991 | $scope: scope, | 1008 | $scope: scope, |
992 | $timeout: $timeout, | 1009 | $timeout: $timeout, |
993 | $uibModal: {}, | 1010 | $uibModal: {}, |
994 | $location: {}, | 1011 | $location: {}, |
995 | focaCrearCobranzaService: { | 1012 | focaCrearCobranzaService: { |
996 | getCotizacionByIdMoneda: function() { | 1013 | getCotizacionByIdMoneda: function() { |
997 | return { | 1014 | return { |
998 | then: function() { } | 1015 | then: function() { } |
999 | }; | 1016 | }; |
1000 | }, | 1017 | }, |
1001 | getBotonera: function() { }, | 1018 | getBotonera: function() { }, |
1002 | getNumeroRecibo: function() { | 1019 | getNumeroRecibo: function() { |
1003 | return { | 1020 | return { |
1004 | then: function() { } | 1021 | then: function() { } |
1005 | }; | 1022 | }; |
1006 | } | 1023 | } |
1007 | }, | 1024 | }, |
1008 | focaModalService: {}, | 1025 | focaModalService: {}, |
1009 | $filter: $filter, | 1026 | $filter: $filter, |
1010 | focaSeguimientoService: {}, | 1027 | focaSeguimientoService: {}, |
1011 | focaBotoneraLateralService: {}, | 1028 | focaBotoneraLateralService: {}, |
1012 | APP: {}, | 1029 | APP: {}, |
1013 | focaLoginService: {}, | 1030 | focaLoginService: {}, |
1014 | $localStorage: true | 1031 | $localStorage: true |
1015 | }); | 1032 | }); |
1016 | scope.cobranza = { | 1033 | scope.cobranza = { |
1017 | facturas: [{ IPA: 1 }] | 1034 | facturas: [{ IPA: 1 }] |
1018 | }; | 1035 | }; |
1019 | 1036 | ||
1020 | //act | 1037 | //act |
1021 | var esperado = 1; | 1038 | var esperado = 1; |
1022 | var resultado = scope.getTotalDeuda(); | 1039 | var resultado = scope.getTotalDeuda(); |
1023 | 1040 | ||
1024 | //assert | 1041 | //assert |
1025 | expect(resultado).toEqual(esperado); | 1042 | expect(resultado).toEqual(esperado); |
1026 | }); | 1043 | }); |
1027 | 1044 | ||
1028 | it('getTotalCobrado devuelve correcto', function() { | 1045 | it('getTotalCobrado devuelve correcto', function() { |
1029 | 1046 | ||
1030 | //arrange | 1047 | //arrange |
1031 | var scope = { | 1048 | var scope = { |
1032 | $broadcast: function() { }, | 1049 | $broadcast: function() { }, |
1033 | $watch: function() { } | 1050 | $watch: function() { } |
1034 | }; | 1051 | }; |
1035 | 1052 | ||
1036 | $controller('cobranzaController', { | 1053 | $controller('cobranzaController', { |
1037 | $scope: scope, | 1054 | $scope: scope, |
1038 | $timeout: $timeout, | 1055 | $timeout: $timeout, |
1039 | $uibModal: {}, | 1056 | $uibModal: {}, |
1040 | $location: {}, | 1057 | $location: {}, |
1041 | focaCrearCobranzaService: { | 1058 | focaCrearCobranzaService: { |
1042 | getCotizacionByIdMoneda: function() { | 1059 | getCotizacionByIdMoneda: function() { |
1043 | return { | 1060 | return { |
1044 | then: function() { } | 1061 | then: function() { } |
1045 | }; | 1062 | }; |
1046 | }, | 1063 | }, |
1047 | getBotonera: function() { }, | 1064 | getBotonera: function() { }, |
1048 | getNumeroRecibo: function() { | 1065 | getNumeroRecibo: function() { |
1049 | return { | 1066 | return { |
1050 | then: function() { } | 1067 | then: function() { } |
1051 | }; | 1068 | }; |
1052 | } | 1069 | } |
1053 | }, | 1070 | }, |
1054 | focaModalService: {}, | 1071 | focaModalService: {}, |
1055 | $filter: $filter, | 1072 | $filter: $filter, |
1056 | focaSeguimientoService: {}, | 1073 | focaSeguimientoService: {}, |
1057 | focaBotoneraLateralService: {}, | 1074 | focaBotoneraLateralService: {}, |
1058 | APP: {}, | 1075 | APP: {}, |
1059 | focaLoginService: {}, | 1076 | focaLoginService: {}, |
1060 | $localStorage: true | 1077 | $localStorage: true |
1061 | }); | 1078 | }); |
1062 | scope.cobranza = { | 1079 | scope.cobranza = { |
1063 | cobros: [{ importe: 1 }] | 1080 | cobros: [{ importe: 1 }] |
1064 | }; | 1081 | }; |
1065 | 1082 | ||
1066 | //act | 1083 | //act |
1067 | var esperado = 1; | 1084 | var esperado = 1; |
1068 | var resultado = scope.getTotalCobrado(); | 1085 | var resultado = scope.getTotalCobrado(); |
1069 | 1086 | ||
1070 | //assert | 1087 | //assert |
1071 | expect(resultado).toEqual(esperado); | 1088 | expect(resultado).toEqual(esperado); |
1072 | }); | 1089 | }); |
1073 | 1090 | ||
1074 | it('getSubTotal devuelve correcto', function() { | 1091 | it('getSubTotal devuelve correcto', function() { |
1075 | 1092 | ||
1076 | //arrange | 1093 | //arrange |
1077 | var scope = { | 1094 | var scope = { |
1078 | $broadcast: function() { }, | 1095 | $broadcast: function() { }, |
1079 | $watch: function() { } | 1096 | $watch: function() { } |
1080 | }; | 1097 | }; |
1081 | 1098 | ||
1082 | $controller('cobranzaController', { | 1099 | $controller('cobranzaController', { |
1083 | $scope: scope, | 1100 | $scope: scope, |
1084 | $timeout: $timeout, | 1101 | $timeout: $timeout, |
1085 | $uibModal: {}, | 1102 | $uibModal: {}, |
1086 | $location: {}, | 1103 | $location: {}, |
1087 | focaCrearCobranzaService: { | 1104 | focaCrearCobranzaService: { |
1088 | getCotizacionByIdMoneda: function() { | 1105 | getCotizacionByIdMoneda: function() { |
1089 | return { | 1106 | return { |
1090 | then: function() { } | 1107 | then: function() { } |
1091 | }; | 1108 | }; |
1092 | }, | 1109 | }, |
1093 | getBotonera: function() { }, | 1110 | getBotonera: function() { }, |
1094 | getNumeroRecibo: function() { | 1111 | getNumeroRecibo: function() { |
1095 | return { | 1112 | return { |
1096 | then: function() { } | 1113 | then: function() { } |
1097 | }; | 1114 | }; |
1098 | } | 1115 | } |
1099 | }, | 1116 | }, |
1100 | focaModalService: {}, | 1117 | focaModalService: {}, |
1101 | $filter: $filter, | 1118 | $filter: $filter, |
1102 | focaSeguimientoService: {}, | 1119 | focaSeguimientoService: {}, |
1103 | focaBotoneraLateralService: {}, | 1120 | focaBotoneraLateralService: {}, |
1104 | APP: {}, | 1121 | APP: {}, |
1105 | focaLoginService: {}, | 1122 | focaLoginService: {}, |
1106 | $localStorage: true | 1123 | $localStorage: true |
1107 | }); | 1124 | }); |
1108 | scope.articuloACargar = { | 1125 | scope.articuloACargar = { |
1109 | precio: 2, | 1126 | precio: 2, |
1110 | cantidad: 5 | 1127 | cantidad: 5 |
1111 | }; | 1128 | }; |
1112 | 1129 | ||
1113 | //act | 1130 | //act |
1114 | var esperado = 10; | 1131 | var esperado = 10; |
1115 | var resultado = scope.getSubTotal(); | 1132 | var resultado = scope.getSubTotal(); |
1116 | 1133 | ||
1117 | //assert | 1134 | //assert |
1118 | expect(resultado).toEqual(esperado); | 1135 | expect(resultado).toEqual(esperado); |
1119 | }); | 1136 | }); |
1120 | 1137 | ||
1121 | it('salir lleva a la ruta correcta', function() { | 1138 | it('salir lleva a la ruta correcta', function() { |
1122 | 1139 | ||
1123 | inject(function($location) { | 1140 | inject(function($location) { |
1124 | 1141 | ||
1125 | //arrange | 1142 | //arrange |
1126 | var scope = { | 1143 | var scope = { |
1127 | $broadcast: function() { }, | 1144 | $broadcast: function() { }, |
1128 | $watch: function() { } | 1145 | $watch: function() { } |
1129 | }; | 1146 | }; |
1130 | 1147 | ||
1131 | $controller('cobranzaController', { | 1148 | $controller('cobranzaController', { |
1132 | $scope: scope, | 1149 | $scope: scope, |
1133 | $timeout: $timeout, | 1150 | $timeout: $timeout, |
1134 | $uibModal: {}, | 1151 | $uibModal: {}, |
1135 | $location: $location, | 1152 | $location: $location, |
1136 | focaCrearCobranzaService: { | 1153 | focaCrearCobranzaService: { |
1137 | getCotizacionByIdMoneda: function() { | 1154 | getCotizacionByIdMoneda: function() { |
1138 | return { | 1155 | return { |
1139 | then: function() { } | 1156 | then: function() { } |
1140 | }; | 1157 | }; |
1141 | }, | 1158 | }, |
1142 | getBotonera: function() { }, | 1159 | getBotonera: function() { }, |
1143 | getNumeroRecibo: function() { | 1160 | getNumeroRecibo: function() { |
1144 | return { | 1161 | return { |
1145 | then: function() { } | 1162 | then: function() { } |
1146 | }; | 1163 | }; |
1147 | } | 1164 | } |
1148 | }, | 1165 | }, |
1149 | focaModalService: {}, | 1166 | focaModalService: {}, |
1150 | $filter: $filter, | 1167 | $filter: $filter, |
1151 | focaSeguimientoService: {}, | 1168 | focaSeguimientoService: {}, |
1152 | focaBotoneraLateralService: {}, | 1169 | focaBotoneraLateralService: {}, |
1153 | APP: {}, | 1170 | APP: {}, |
1154 | focaLoginService: {}, | 1171 | focaLoginService: {}, |
1155 | $localStorage: true | 1172 | $localStorage: true |
1156 | }); | 1173 | }); |
1157 | 1174 | ||
1158 | //act | 1175 | //act |
1159 | scope.salir(); | 1176 | scope.salir(); |
1160 | 1177 | ||
1161 | //assert | 1178 | //assert |
1162 | expect($location.url()).toEqual('/'); | 1179 | expect($location.url()).toEqual('/'); |
1163 | }); | 1180 | }); |
1164 | }); | 1181 | }); |
1165 | 1182 | ||
1166 | it('parsearATexto parsea correctamente', function() { | 1183 | it('parsearATexto parsea correctamente', function() { |
1167 | 1184 | ||
1168 | //arrange | 1185 | //arrange |
1169 | var scope = { | 1186 | var scope = { |
1170 | $broadcast: function() { }, | 1187 | $broadcast: function() { }, |
1171 | $watch: function() { } | 1188 | $watch: function() { } |
1172 | }; | 1189 | }; |
1173 | 1190 | ||
1174 | $controller('cobranzaController', { | 1191 | $controller('cobranzaController', { |
1175 | $scope: scope, | 1192 | $scope: scope, |
1176 | $timeout: $timeout, | 1193 | $timeout: $timeout, |
1177 | $uibModal: {}, | 1194 | $uibModal: {}, |
1178 | $location: {}, | 1195 | $location: {}, |
1179 | focaCrearCobranzaService: { | 1196 | focaCrearCobranzaService: { |
1180 | getCotizacionByIdMoneda: function() { | 1197 | getCotizacionByIdMoneda: function() { |
1181 | return { | 1198 | return { |
1182 | then: function() { } | 1199 | then: function() { } |
1183 | }; | 1200 | }; |
1184 | }, | 1201 | }, |
1185 | getBotonera: function() { }, | 1202 | getBotonera: function() { }, |
1186 | getNumeroRecibo: function() { | 1203 | getNumeroRecibo: function() { |
1187 | return { | 1204 | return { |
1188 | then: function() { } | 1205 | then: function() { } |
1189 | }; | 1206 | }; |
1190 | } | 1207 | } |
1191 | }, | 1208 | }, |
1192 | focaModalService: {}, | 1209 | focaModalService: {}, |
1193 | $filter: $filter, | 1210 | $filter: $filter, |
1194 | focaSeguimientoService: {}, | 1211 | focaSeguimientoService: {}, |
1195 | focaBotoneraLateralService: {}, | 1212 | focaBotoneraLateralService: {}, |
1196 | APP: {}, | 1213 | APP: {}, |
1197 | focaLoginService: {}, | 1214 | focaLoginService: {}, |
1198 | $localStorage: true | 1215 | $localStorage: true |
1199 | }); | 1216 | }); |
1200 | 1217 | ||
1201 | var parametro = { | 1218 | var parametro = { |
1202 | cantidad: '1', | 1219 | cantidad: '1', |
1203 | precio: '2' | 1220 | precio: '2' |
1204 | }; | 1221 | }; |
1205 | 1222 | ||
1206 | //act | 1223 | //act |
1207 | scope.parsearATexto(parametro); | 1224 | scope.parsearATexto(parametro); |
1208 | 1225 | ||
1209 | //assert | 1226 | //assert |
1210 | expect(typeof parametro.cantidad).toEqual('number'); | 1227 | expect(typeof parametro.cantidad).toEqual('number'); |
1211 | expect(typeof parametro.precio).toEqual('number'); | 1228 | expect(typeof parametro.precio).toEqual('number'); |
1212 | }); | 1229 | }); |
1213 | 1230 | ||
1214 | }); | 1231 | }); |
1215 | }); | 1232 | }); |
src/js/controller.js
1 | angular.module('focaCrearCobranza') .controller('cobranzaController', | 1 | angular.module('focaCrearCobranza') .controller('cobranzaController', |
2 | [ | 2 | [ |
3 | '$scope', '$timeout', '$uibModal', '$location', | 3 | '$scope', '$timeout', '$uibModal', '$location', |
4 | 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', | 4 | 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', |
5 | 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', | 5 | 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', |
6 | function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, | 6 | function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, |
7 | focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, | 7 | focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, |
8 | APP, loginService, $localStorage) | 8 | APP, loginService, $localStorage) |
9 | { | 9 | { |
10 | config(); | 10 | config(); |
11 | 11 | ||
12 | function config() { | 12 | function config() { |
13 | $scope.datepickerAbierto = false; | 13 | $scope.datepickerAbierto = false; |
14 | $scope.cobroDeuda = true; | 14 | $scope.cobroDeuda = true; |
15 | $scope.show = false; | 15 | $scope.show = false; |
16 | $scope.cargando = true; | 16 | $scope.cargando = true; |
17 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 17 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
18 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 18 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
19 | $scope.botonera = focaCrearCobranzaService.getBotonera(); | 19 | $scope.botonera = focaCrearCobranzaService.getBotonera(); |
20 | $scope.dateOptions = { | 20 | $scope.dateOptions = { |
21 | maxDate: new Date(), | 21 | maxDate: new Date(), |
22 | minDate: new Date(2010, 0, 1) | 22 | minDate: new Date(2010, 0, 1) |
23 | }; | 23 | }; |
24 | 24 | ||
25 | var monedaPorDefecto; | 25 | var monedaPorDefecto; |
26 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 26 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
27 | focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { | 27 | focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { |
28 | monedaPorDefecto = res.data[0]; | 28 | monedaPorDefecto = res.data[0]; |
29 | 29 | ||
30 | $scope.cobranza.cotizacion = Object.assign( | 30 | $scope.cobranza.cotizacion = Object.assign( |
31 | {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] | 31 | {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] |
32 | ); | 32 | ); |
33 | $scope.inicial.cotizacion = $scope.cobranza.cotizacion; | 33 | $scope.inicial.cotizacion = $scope.cobranza.cotizacion; |
34 | 34 | ||
35 | }); | 35 | }); |
36 | 36 | ||
37 | $timeout(function() { | 37 | $timeout(function() { |
38 | focaBotoneraLateralService.showSalir(false); | 38 | focaBotoneraLateralService.showSalir(false); |
39 | focaBotoneraLateralService.showPausar(true); | 39 | focaBotoneraLateralService.showPausar(true); |
40 | focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); | 40 | focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); |
41 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 41 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
42 | }); | 42 | }); |
43 | 43 | ||
44 | if (APP === 'cobranza') { | 44 | if (APP === 'cobranza') { |
45 | $scope.idCobrador = loginService.getLoginData().vendedorCobrador; | 45 | $scope.idCobrador = loginService.getLoginData().vendedorCobrador; |
46 | } | 46 | } |
47 | 47 | ||
48 | init(); | 48 | init(); |
49 | $timeout(function() {getLSCobranza();}); | 49 | $timeout(function() {getLSCobranza();}); |
50 | } | 50 | } |
51 | 51 | ||
52 | function init() { | 52 | function init() { |
53 | $scope.$broadcast('cleanCabecera'); | 53 | $scope.$broadcast('cleanCabecera'); |
54 | $scope.cobranza = { | 54 | $scope.cobranza = { |
55 | fecha: new Date(), | 55 | fecha: new Date(), |
56 | cotizacion: {}, | 56 | cotizacion: {}, |
57 | facturas: [], | 57 | facturas: [], |
58 | cobros: [], | 58 | cobros: [], |
59 | cliente: {}, | 59 | cliente: {}, |
60 | cobrador: {} | 60 | cobrador: {} |
61 | }; | 61 | }; |
62 | if (APP === 'cobranza') { | 62 | if (APP === 'cobranza') { |
63 | focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( | 63 | focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( |
64 | function(res) { | 64 | function(res) { |
65 | var cobrador = res.data; | 65 | var cobrador = res.data; |
66 | 66 | ||
67 | $scope.$broadcast('addCabecera', { | 67 | $scope.$broadcast('addCabecera', { |
68 | label: 'Cobrador:', | 68 | label: 'Cobrador:', |
69 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | 69 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + |
70 | cobrador.NOM | 70 | cobrador.NOM |
71 | }); | 71 | }); |
72 | 72 | ||
73 | $scope.cobranza.cobrador = cobrador; | 73 | $scope.cobranza.cobrador = cobrador; |
74 | $scope.inicial.cobranza.cobrador = $scope.cobranza.cobrador; | 74 | $scope.inicial.cobranza.cobrador = $scope.cobranza.cobrador; |
75 | } | 75 | } |
76 | ); | 76 | ); |
77 | } | 77 | } |
78 | 78 | ||
79 | $scope.inicial = angular.copy($scope.cobranza); | 79 | $scope.inicial = angular.copy($scope.cobranza); |
80 | 80 | ||
81 | focaCrearCobranzaService.getNumeroRecibo().then( | 81 | focaCrearCobranzaService.getNumeroRecibo().then( |
82 | function(res) { | 82 | function(res) { |
83 | $scope.puntoVenta = $filter('rellenarDigitos')( | 83 | $scope.puntoVenta = $filter('rellenarDigitos')( |
84 | res.data.sucursal, 4 | 84 | res.data.sucursal, 4 |
85 | ); | 85 | ); |
86 | 86 | ||
87 | $scope.comprobante = $filter('rellenarDigitos')( | 87 | $scope.comprobante = $filter('rellenarDigitos')( |
88 | res.data.numeroRecibo, 8 | 88 | res.data.numeroRecibo, 8 |
89 | ); | 89 | ); |
90 | }, | 90 | }, |
91 | function(err) { | 91 | function(err) { |
92 | focaModalService.alert( | 92 | focaModalService.alert( |
93 | 'La terminal no esta configurada correctamente' | 93 | 'La terminal no esta configurada correctamente' |
94 | ); | 94 | ); |
95 | console.info(err); | 95 | console.info(err); |
96 | } | 96 | } |
97 | ); | 97 | ); |
98 | } | 98 | } |
99 | 99 | ||
100 | $scope.$watch('cobranza', function(newValue) { | 100 | $scope.$watch('cobranza', function(newValue) { |
101 | focaBotoneraLateralService.setPausarData({ | 101 | focaBotoneraLateralService.setPausarData({ |
102 | label: 'cobranza', | 102 | label: 'cobranza', |
103 | val: newValue | 103 | val: newValue |
104 | }); | 104 | }); |
105 | }, true); | 105 | }, true); |
106 | 106 | ||
107 | $scope.crearCobranza = function() { | 107 | $scope.crearCobranza = function() { |
108 | if (!$scope.cobranza.cliente.COD) { | 108 | if (!$scope.cobranza.cliente.COD) { |
109 | focaModalService.alert('Ingrese Cliente'); | 109 | focaModalService.alert('Ingrese Cliente'); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | if (!$scope.cobranza.cobrador.NUM) { | 112 | if (!$scope.cobranza.cobrador.NUM) { |
113 | focaModalService.alert('Ingrese Cobrador'); | 113 | focaModalService.alert('Ingrese Cobrador'); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | if ($scope.cobranza.facturas.length < 1) { | 116 | if ($scope.cobranza.facturas.length < 1) { |
117 | focaModalService.alert('Ingrese al menos una factura'); | 117 | focaModalService.alert('Ingrese al menos una factura'); |
118 | return; | 118 | return; |
119 | } | 119 | } |
120 | if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { | 120 | if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { |
121 | focaModalService.alert('La diferencia debe ser ' + | 121 | focaModalService.alert('La diferencia debe ser ' + |
122 | $scope.cobranza.cotizacion.moneda.SIMBOLO + '0,00'); | 122 | $scope.cobranza.cotizacion.moneda.SIMBOLO + '0,00'); |
123 | return; | 123 | return; |
124 | } | 124 | } |
125 | 125 | ||
126 | var cobranza = {}; | 126 | var cobranza = {}; |
127 | var cheques = []; | 127 | var cheques = []; |
128 | var cuerpos = []; | 128 | var cuerpos = []; |
129 | var imgs = []; | 129 | var imgs = []; |
130 | var observacion; | 130 | var observacion; |
131 | //TODO: habilitar edición | 131 | //TODO: habilitar edición |
132 | $scope.editando = false; | 132 | $scope.editando = false; |
133 | focaBotoneraLateralService.startGuardar(); | 133 | focaBotoneraLateralService.startGuardar(); |
134 | $scope.saveLoading = true; | 134 | $scope.saveLoading = true; |
135 | for(var i = 0; i < $scope.cobranza.facturas.length; i++) { | 135 | for(var i = 0; i < $scope.cobranza.facturas.length; i++) { |
136 | var cuerpoFactura = { | 136 | var cuerpoFactura = { |
137 | CYV: 'V', | 137 | CYV: 'V', |
138 | TIP: 'C', | 138 | TIP: 'C', |
139 | TCO: 'RC', | 139 | TCO: 'RC', |
140 | PVE: $scope.puntoVenta, | 140 | PVE: $scope.puntoVenta, |
141 | NCO: $scope.comprobante, | 141 | NCO: $scope.comprobante, |
142 | LOP: 'L', | 142 | LOP: 'L', |
143 | TIL: $scope.cobranza.facturas[i].TCO, | 143 | TIL: $scope.cobranza.facturas[i].TCO, |
144 | COM: $scope.cobranza.facturas[i].numeroFactura + '-' + | 144 | COM: $scope.cobranza.facturas[i].numeroFactura + '-' + |
145 | $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU,2), | 145 | $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU,2), |
146 | FEC: new Date($scope.cobranza.fecha) | 146 | FEC: new Date($scope.cobranza.fecha) |
147 | .toISOString().slice(0, 19).replace('T', ' '), | 147 | .toISOString().slice(0, 19).replace('T', ' '), |
148 | IMP: Math.abs($scope.cobranza.facturas[i].IPA), | 148 | IMP: Math.abs($scope.cobranza.facturas[i].IPA), |
149 | RES: 0,//caja de tesorería | 149 | RES: 0,//caja de tesorería |
150 | SUBM: 0, | 150 | SUBM: 0, |
151 | NCU: $scope.cobranza.facturas[i].NCU | 151 | NCU: $scope.cobranza.facturas[i].NCU |
152 | }; | 152 | }; |
153 | cuerpos.push(cuerpoFactura); | 153 | cuerpos.push(cuerpoFactura); |
154 | 154 | ||
155 | } | 155 | } |
156 | 156 | ||
157 | for (var j = 0; j < $scope.cobranza.cobros.length; j++) { | 157 | for (var j = 0; j < $scope.cobranza.cobros.length; j++) { |
158 | 158 | ||
159 | var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo'; | 159 | var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo'; |
160 | var cuerpoCobros = { | 160 | var cuerpoCobros = { |
161 | CYV: 'V', | 161 | CYV: 'V', |
162 | TIP: 'C', | 162 | TIP: 'C', |
163 | TCO: 'RC', | 163 | TCO: 'RC', |
164 | PVE: $scope.puntoVenta, | 164 | PVE: $scope.puntoVenta, |
165 | NCO: $scope.comprobante, | 165 | NCO: $scope.comprobante, |
166 | LOP: 'P', | 166 | LOP: 'P', |
167 | TIL: $scope.cobranza.cobros[j].til, | 167 | TIL: $scope.cobranza.cobros[j].til, |
168 | COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].tipo, | 168 | COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].tipo, |
169 | FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? | 169 | FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? |
170 | new Date($scope.cobranza.cobros[j].fecha) | 170 | new Date($scope.cobranza.cobros[j].fecha) |
171 | .toISOString().slice(0, 19).replace('T', ' ') : | 171 | .toISOString().slice(0, 19).replace('T', ' ') : |
172 | new Date($scope.cobranza.cobros[j].fechaPresentacion) | 172 | new Date($scope.cobranza.cobros[j].fechaPresentacion) |
173 | .toISOString().slice(0, 19).replace('T', ' '), | 173 | .toISOString().slice(0, 19).replace('T', ' '), |
174 | IMP: Math.abs($scope.cobranza.cobros[j].importe), | 174 | IMP: Math.abs($scope.cobranza.cobros[j].importe), |
175 | RES: 0,//caja de tesorería | 175 | RES: 0,//caja de tesorería |
176 | SUBM: 0 | 176 | SUBM: 0 |
177 | }; | 177 | }; |
178 | cuerpos.push(cuerpoCobros); | 178 | cuerpos.push(cuerpoCobros); |
179 | 179 | ||
180 | if ($scope.cobranza.cobros[j].observacion) | 180 | if ($scope.cobranza.cobros[j].observacion) |
181 | observacion = $scope.cobranza.cobros[j].observacion; | 181 | observacion = $scope.cobranza.cobros[j].observacion; |
182 | 182 | ||
183 | if ($scope.cobranza.cobros[j].banco) { | 183 | if ($scope.cobranza.cobros[j].banco) { |
184 | var cheque = { | 184 | var cheque = { |
185 | BCO: $scope.cobranza.cobros[j].banco.ID, | 185 | BCO: $scope.cobranza.cobros[j].banco.ID, |
186 | NUM: $scope.comprobante, | 186 | NUM: $scope.comprobante, |
187 | FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion) | 187 | FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion) |
188 | .toISOString().slice(0, 19).replace('T', ' '), | 188 | .toISOString().slice(0, 19).replace('T', ' '), |
189 | FEE: new Date($scope.cobranza.cobros[j].fechaEmision) | 189 | FEE: new Date($scope.cobranza.cobros[j].fechaEmision) |
190 | .toISOString().slice(0, 19).replace('T', ' '), | 190 | .toISOString().slice(0, 19).replace('T', ' '), |
191 | LUG: $scope.cobranza.cobros[j].localidad.NOMBRE, | 191 | LUG: $scope.cobranza.cobros[j].localidad.NOMBRE, |
192 | IMP: $scope.cobranza.cobros[j].importe, | 192 | IMP: $scope.cobranza.cobros[j].importe, |
193 | LIB: $scope.cobranza.cobros[j].librador, | 193 | LIB: $scope.cobranza.cobros[j].librador, |
194 | EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera | 194 | EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera |
195 | PCI: $scope.cobranza.cobros[j].provincia.ID, | 195 | PCI: $scope.cobranza.cobros[j].provincia.ID, |
196 | LPLA: 0, | 196 | LPLA: 0, |
197 | PLA: 0, | 197 | PLA: 0, |
198 | VEN: $scope.cobranza.cobrador.id,//Id vendedor | 198 | VEN: $scope.cobranza.cobrador.id,//Id vendedor |
199 | CCLIE: $scope.cobranza.cliente.COD,//Id cliente | 199 | CCLIE: $scope.cobranza.cliente.COD,//Id cliente |
200 | REN: 0, | 200 | REN: 0, |
201 | PVEC: $scope.puntoVenta, | 201 | PVEC: $scope.puntoVenta, |
202 | NCOC: $scope.comprobante, | 202 | NCOC: $scope.comprobante, |
203 | OBSE: $scope.cobranza.cobros[j].observaciones, | 203 | OBSE: $scope.cobranza.cobros[j].observaciones, |
204 | LUV: 0, | 204 | LUV: 0, |
205 | ORI: 've', | 205 | ORI: 've', |
206 | FER: '', | 206 | FER: '', |
207 | BIMP: 0, | 207 | BIMP: 0, |
208 | COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, | 208 | COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, |
209 | VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso | 209 | VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso |
210 | VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso | 210 | VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso |
211 | REC_CAJ: 'D', | 211 | REC_CAJ: 'D', |
212 | TIPO_C: 0,//?? | 212 | TIPO_C: 0,//?? |
213 | SALDO_CAJ: 'S', | 213 | SALDO_CAJ: 'S', |
214 | FECHA_INGRESO: new Date($scope.cobranza.fecha) | 214 | FECHA_INGRESO: new Date($scope.cobranza.fecha) |
215 | .toISOString().slice(0, 19).replace('T', ' '), | 215 | .toISOString().slice(0, 19).replace('T', ' '), |
216 | Vendedor_valor: 0, | 216 | Vendedor_valor: 0, |
217 | FAMILIA: 0, | 217 | FAMILIA: 0, |
218 | CUIT_LIB: '', | 218 | CUIT_LIB: '', |
219 | COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar | 219 | COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar |
220 | SEN: '', | 220 | SEN: '', |
221 | NRC: 0, | 221 | NRC: 0, |
222 | COD_LARGO: '', | 222 | COD_LARGO: '', |
223 | VN: 0, | 223 | VN: 0, |
224 | ID_LECTOR: 0, | 224 | ID_LECTOR: 0, |
225 | NATHB: '' | 225 | NATHB: '' |
226 | }; | 226 | }; |
227 | cheques.push(cheque); | 227 | cheques.push(cheque); |
228 | } | 228 | } |
229 | if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; | 229 | if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | cobranza = { | 233 | cobranza = { |
234 | recibo: { | 234 | recibo: { |
235 | CYV: 'V', | 235 | CYV: 'V', |
236 | TIP: 'C', | 236 | TIP: 'C', |
237 | TCO: 'RC', | 237 | TCO: 'RC', |
238 | PVE: $scope.puntoVenta, //Sucursar, punto de venta | 238 | PVE: $scope.puntoVenta, //Sucursar, punto de venta |
239 | NCO: $scope.comprobante, //Numero de comprobante | 239 | NCO: $scope.comprobante, //Numero de comprobante |
240 | FEC: new Date($scope.cobranza.fecha) | 240 | FEC: new Date($scope.cobranza.fecha) |
241 | .toISOString().slice(0, 19).replace('T', ' '), | 241 | .toISOString().slice(0, 19).replace('T', ' '), |
242 | CLI: $scope.cobranza.cliente.COD, | 242 | CLI: $scope.cobranza.cliente.COD, |
243 | ATO: 0, //número de asiento | 243 | ATO: 0, //número de asiento |
244 | CFE: $scope.cobranza.cobrador.NOM, | 244 | CFE: $scope.cobranza.cobrador.NOM, |
245 | PLA: '',//Numero de planilla, sin uso | 245 | PLA: '',//Numero de planilla, sin uso |
246 | ID_MONEDA: $scope.cobranza.cotizacion.moneda.ID, | 246 | ID_MONEDA: $scope.cobranza.cotizacion.moneda.ID, |
247 | COTIZACION: $scope.cobranza.cotizacion.VENDEDOR, | 247 | COTIZACION: $scope.cobranza.cotizacion.VENDEDOR, |
248 | idCobrador: $scope.cobranza.cobrador.id | 248 | idCobrador: $scope.cobranza.cobrador.id |
249 | }, | 249 | }, |
250 | cuerpo: cuerpos, | 250 | cuerpo: cuerpos, |
251 | cheques: cheques, | 251 | cheques: cheques, |
252 | acobypag: { | 252 | acobypag: { |
253 | CYV: 'V', | 253 | CYV: 'V', |
254 | COD: $scope.cobranza.cliente.COD, | 254 | COD: $scope.cobranza.cliente.COD, |
255 | FEP: new Date($scope.cobranza.fecha) | 255 | FEP: new Date($scope.cobranza.fecha) |
256 | .toISOString().slice(0, 19).replace('T', ' '), | 256 | .toISOString().slice(0, 19).replace('T', ' '), |
257 | TIP: 'C', | 257 | TIP: 'C', |
258 | TCO: 'RC', | 258 | TCO: 'RC', |
259 | SUC: $scope.puntoVenta, | 259 | SUC: $scope.puntoVenta, |
260 | NCO: $scope.comprobante, | 260 | NCO: $scope.comprobante, |
261 | IPA: $scope.getTotalCobrado(), | 261 | IPA: $scope.getTotalCobrado(), |
262 | SAL: '',//?? | 262 | SAL: '',//?? |
263 | TCA: 1, | 263 | TCA: 1, |
264 | ZONA: 1, | 264 | ZONA: 1, |
265 | FPA: 2,//Forma de pago | 265 | FPA: 2,//Forma de pago |
266 | REC: 0, | 266 | REC: 0, |
267 | REP: 0, | 267 | REP: 0, |
268 | FER: null, | 268 | FER: null, |
269 | REM: 0, | 269 | REM: 0, |
270 | FRE: null,//?? | 270 | FRE: null,//?? |
271 | PRO: 'N', | 271 | PRO: 'N', |
272 | FEV: new Date($scope.cobranza.fecha) | 272 | FEV: new Date($scope.cobranza.fecha) |
273 | .toISOString().slice(0, 19).replace('T', ' ') | 273 | .toISOString().slice(0, 19).replace('T', ' ') |
274 | }, | 274 | }, |
275 | datosCobrador: { | 275 | datosCobrador: { |
276 | COD: $scope.cobranza.cobrador.NUM, | 276 | COD: $scope.cobranza.cobrador.NUM, |
277 | PVE: $scope.puntoVenta, | 277 | PVE: $scope.puntoVenta, |
278 | NUM: $scope.comprobante, | 278 | NUM: $scope.comprobante, |
279 | EST: 'C', | 279 | EST: 'C', |
280 | OBS: 'RC: ' + $scope.comprobante + '-' + | 280 | OBS: 'RC: ' + $scope.comprobante + '-' + |
281 | new Date($scope.cobranza.fecha).toLocaleDateString(), | 281 | new Date($scope.cobranza.fecha).toLocaleDateString(), |
282 | DAT1: 'C', | 282 | DAT1: 'C', |
283 | CLI: $scope.cobranza.cliente.COD | 283 | CLI: $scope.cobranza.cliente.COD |
284 | }, | 284 | }, |
285 | cliente: $scope.cobranza.cliente, | 285 | cliente: $scope.cobranza.cliente, |
286 | imgs: imgs, | 286 | imgs: imgs, |
287 | observacion: observacion | 287 | observacion: observacion |
288 | }; | 288 | }; |
289 | //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS | 289 | //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS |
290 | var cobranzaMail = angular.copy(cobranza); | 290 | var cobranzaMail = angular.copy(cobranza); |
291 | cobranza.cuerpo = cobranza.cuerpo.map(function(c) { | 291 | cobranza.cuerpo = cobranza.cuerpo.map(function(c) { |
292 | if (c.NCU) delete c.NCU; | 292 | if (c.NCU) delete c.NCU; |
293 | return c; | 293 | return c; |
294 | }); | 294 | }); |
295 | 295 | ||
296 | focaCrearCobranzaService | 296 | focaCrearCobranzaService |
297 | .guardarCobranza(cobranza) | 297 | .guardarCobranza(cobranza) |
298 | .then( | 298 | .then( |
299 | function(result) { | 299 | function(result) { |
300 | var cliente = angular.copy($scope.cobranza.cliente); | 300 | var cliente = angular.copy($scope.cobranza.cliente); |
301 | focaBotoneraLateralService.endGuardar(true); | 301 | focaBotoneraLateralService.endGuardar(true); |
302 | $scope.saveLoading = false; | 302 | $scope.saveLoading = false; |
303 | 303 | ||
304 | focaModalService | 304 | focaModalService |
305 | .prompt({ | 305 | .prompt({ |
306 | titulo: 'Ingrese los emails separados por' + | 306 | titulo: 'Ingrese los emails separados por' + |
307 | ' coma para enviar comprobante', | 307 | ' coma para enviar comprobante', |
308 | value: cliente.MAIL, | 308 | value: cliente.MAIL, |
309 | email: true | 309 | email: true |
310 | }) | 310 | }) |
311 | .then(function(res) { | 311 | .then(function(res) { |
312 | return Promise.all([ | 312 | return Promise.all([ |
313 | focaCrearCobranzaService | 313 | focaCrearCobranzaService |
314 | .enviarComprobantePorMail(res, cobranzaMail), | 314 | .enviarComprobantePorMail(res, cobranzaMail), |
315 | focaCrearCobranzaService | 315 | focaCrearCobranzaService |
316 | .actualizarEmail(res, cliente.COD) | 316 | .actualizarEmail(res, cliente.COD) |
317 | ]); | 317 | ]); |
318 | }) | 318 | }) |
319 | .then(function() { | 319 | .then(function() { |
320 | focaModalService.alert('Mensaje enviado correctamente'); | 320 | focaModalService.alert('Mensaje enviado correctamente'); |
321 | }); | 321 | }); |
322 | 322 | ||
323 | focaSeguimientoService.guardarPosicion( | 323 | focaSeguimientoService.guardarPosicion( |
324 | 'Cobranza', | 324 | 'Cobranza', |
325 | result.data, | 325 | result.data, |
326 | '' | 326 | '' |
327 | ); | 327 | ); |
328 | 328 | ||
329 | init(); | 329 | init(); |
330 | }, function(error) { | 330 | }, function(error) { |
331 | focaModalService.alert('Hubo un problema al cargar la cobranza'); | 331 | focaModalService.alert('Hubo un problema al cargar la cobranza'); |
332 | focaBotoneraLateralService.endGuardar(); | 332 | focaBotoneraLateralService.endGuardar(); |
333 | $scope.saveLoading = false; | 333 | $scope.saveLoading = false; |
334 | console.info(error); | 334 | console.info(error); |
335 | } | 335 | } |
336 | ); | 336 | ); |
337 | }; | 337 | }; |
338 | 338 | ||
339 | $scope.seleccionarCobros = function() { | 339 | $scope.seleccionarCobros = function() { |
340 | $scope.cobroDeuda = false; | 340 | $scope.cobroDeuda = false; |
341 | }; | 341 | }; |
342 | 342 | ||
343 | $scope.seleccionarComprobantes = function() { | 343 | $scope.seleccionarComprobantes = function() { |
344 | $scope.cobroDeuda = true; | 344 | $scope.cobroDeuda = true; |
345 | }; | 345 | }; |
346 | 346 | ||
347 | $scope.seleccionarCobranza = function() { | 347 | $scope.seleccionarCobranza = function() { |
348 | 348 | ||
349 | var modalInstance = $uibModal.open( | 349 | var modalInstance = $uibModal.open( |
350 | { | 350 | { |
351 | ariaLabelledBy: 'Busqueda de Cobranzas', | 351 | ariaLabelledBy: 'Busqueda de Cobranzas', |
352 | templateUrl: 'foca-modal-cobranza.html', | 352 | templateUrl: 'foca-modal-cobranza.html', |
353 | controller: 'focaModalCobranzaController', | 353 | controller: 'focaModalCobranzaController', |
354 | size: 'lg' | 354 | size: 'lg' |
355 | } | 355 | } |
356 | ); | 356 | ); |
357 | modalInstance.result.then(setearCobranza); | 357 | modalInstance.result.then(setearCobranza); |
358 | }; | 358 | }; |
359 | 359 | ||
360 | $scope.seleccionarResumenDeCuenta = function() { | 360 | $scope.seleccionarResumenDeCuenta = function() { |
361 | if (!$scope.cobranza.cliente.COD) { | 361 | if (!$scope.cobranza.cliente.COD) { |
362 | focaModalService.alert('Seleccione primero un cliente'); | 362 | focaModalService.alert('Seleccione primero un cliente'); |
363 | return; | 363 | return; |
364 | } | 364 | } |
365 | var modalInstance = $uibModal.open( | 365 | var modalInstance = $uibModal.open( |
366 | { | 366 | { |
367 | ariaLabelledBy: 'Resumen de cuentas', | 367 | ariaLabelledBy: 'Resumen de cuentas', |
368 | templateUrl: 'modal-resumen-cuenta.html', | 368 | templateUrl: 'modal-resumen-cuenta.html', |
369 | controller: 'focaModalResumenCuentaController', | 369 | controller: 'focaModalResumenCuentaController', |
370 | resolve: { | 370 | resolve: { |
371 | idCliente: function() { return $scope.cobranza.cliente.COD; } | 371 | idCliente: function() { return $scope.cobranza.cliente.COD; } |
372 | }, | 372 | }, |
373 | size: 'lg' | 373 | size: 'lg' |
374 | } | 374 | } |
375 | ); | 375 | ); |
376 | modalInstance.result.then( | 376 | modalInstance.result.then( |
377 | function(cliente) { | 377 | function(cliente) { |
378 | $scope.abrirModalDomicilios(cliente); | 378 | $scope.abrirModalDomicilios(cliente); |
379 | $scope.cliente = cliente; | 379 | $scope.cliente = cliente; |
380 | }, function() {} | 380 | }, function() {} |
381 | ); | 381 | ); |
382 | }; | 382 | }; |
383 | 383 | ||
384 | $scope.seleccionarCliente = function() { | 384 | $scope.seleccionarCliente = function() { |
385 | $scope.seleccionarCobrador(function() { | 385 | $scope.seleccionarCobrador(function() { |
386 | var modalInstance = $uibModal.open( | 386 | var modalInstance = $uibModal.open( |
387 | { | 387 | { |
388 | ariaLabelledBy: 'Busqueda de Cliente', | 388 | ariaLabelledBy: 'Busqueda de Cliente', |
389 | templateUrl: 'foca-busqueda-cliente-modal.html', | 389 | templateUrl: 'foca-busqueda-cliente-modal.html', |
390 | controller: 'focaBusquedaClienteModalController', | 390 | controller: 'focaBusquedaClienteModalController', |
391 | resolve: { | 391 | resolve: { |
392 | vendedor: function() { return null; }, | 392 | vendedor: function() { return null; }, |
393 | cobrador: function() { return $scope.cobranza.cobrador; } | 393 | cobrador: function() { return $scope.cobranza.cobrador; } |
394 | }, | 394 | }, |
395 | size: 'lg' | 395 | size: 'lg' |
396 | } | 396 | } |
397 | ); | 397 | ); |
398 | modalInstance.result.then( | 398 | modalInstance.result.then( |
399 | function(cliente) { | 399 | function(cliente) { |
400 | var clienteMayus = { | 400 | var clienteMayus = { |
401 | COD: cliente.cod, | 401 | COD: cliente.cod, |
402 | NOM: cliente.nom, | 402 | NOM: cliente.nom, |
403 | CUIT: cliente.cuit | 403 | CUIT: cliente.cuit |
404 | }; | 404 | }; |
405 | 405 | ||
406 | $scope.$broadcast('addCabecera', { | 406 | $scope.$broadcast('addCabecera', { |
407 | label: 'Cliente:', | 407 | label: 'Cliente:', |
408 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + | 408 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + |
409 | clienteMayus.NOM | 409 | clienteMayus.NOM |
410 | }); | 410 | }); |
411 | $scope.cobranza.cliente = clienteMayus; | 411 | $scope.cobranza.cliente = clienteMayus; |
412 | $scope.cobranza.facturas = []; | ||
412 | }, function() { | 413 | }, function() { |
413 | if (APP !== 'cobranza') $scope.seleccionarCliente(); | 414 | if (APP !== 'cobranza') $scope.seleccionarCliente(); |
414 | } | 415 | } |
415 | ); | 416 | ); |
416 | }); | 417 | }); |
417 | }; | 418 | }; |
418 | 419 | ||
419 | $scope.seleccionarCobrador = function(callback) { | 420 | $scope.seleccionarCobrador = function(callback) { |
420 | 421 | ||
421 | if (APP === 'cobranza') { | 422 | if (APP === 'cobranza') { |
422 | callback(); | 423 | callback(); |
423 | return; | 424 | return; |
424 | } | 425 | } |
425 | 426 | ||
426 | var parametrosModal = { | 427 | var parametrosModal = { |
427 | query: '/cobrador', | 428 | query: '/cobrador', |
428 | columnas: [ | 429 | columnas: [ |
429 | { | 430 | { |
430 | propiedad: 'NUM', | 431 | propiedad: 'NUM', |
431 | nombre: 'Codigo', | 432 | nombre: 'Codigo', |
432 | filtro: { | 433 | filtro: { |
433 | nombre: 'rellenarDigitos', | 434 | nombre: 'rellenarDigitos', |
434 | parametro: 3 | 435 | parametro: 3 |
435 | } | 436 | } |
436 | }, | 437 | }, |
437 | { | 438 | { |
438 | propiedad: 'NOM', | 439 | propiedad: 'NOM', |
439 | nombre: 'Nombre' | 440 | nombre: 'Nombre' |
440 | } | 441 | } |
441 | ], | 442 | ], |
442 | titulo:'Búsqueda de cobradores' | 443 | titulo:'Búsqueda de cobradores' |
443 | }; | 444 | }; |
444 | focaModalService.modal(parametrosModal).then( | 445 | focaModalService.modal(parametrosModal).then( |
445 | function(cobrador) { | 446 | function(cobrador) { |
446 | $scope.$broadcast('addCabecera', { | 447 | $scope.$broadcast('addCabecera', { |
447 | label: 'Cobrador:', | 448 | label: 'Cobrador:', |
448 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | 449 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + |
449 | cobrador.NOM | 450 | cobrador.NOM |
450 | }); | 451 | }); |
451 | $scope.cobranza.cobrador = cobrador; | 452 | $scope.cobranza.cobrador = cobrador; |
452 | 453 | ||
453 | //ELIMINO CLIENTE | 454 | //ELIMINO CLIENTE |
454 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 455 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
455 | $scope.cobranza.cliente = {}; | 456 | $scope.cobranza.cliente = {}; |
456 | 457 | ||
457 | callback(); | 458 | callback(); |
458 | }, function() {} | 459 | }, function() {} |
459 | ); | 460 | ); |
460 | }; | 461 | }; |
461 | 462 | ||
462 | $scope.seleccionarFactura = function() { | 463 | $scope.seleccionarFactura = function() { |
463 | if (!$scope.cobranza.cliente.COD) { | 464 | if (!$scope.cobranza.cliente.COD) { |
464 | focaModalService.alert('Seleccione primero un cliente'); | 465 | focaModalService.alert('Seleccione primero un cliente'); |
465 | return; | 466 | return; |
466 | } | 467 | } |
467 | var modalInstance = $uibModal.open( | 468 | var modalInstance = $uibModal.open( |
468 | { | 469 | { |
469 | ariaLabelledBy: 'Busqueda de Facturas', | 470 | ariaLabelledBy: 'Busqueda de Facturas', |
470 | templateUrl: 'foca-modal-factura.html', | 471 | templateUrl: 'foca-modal-factura.html', |
471 | controller: 'focaModalFacturaController', | 472 | controller: 'focaModalFacturaController', |
472 | size: 'lg', | 473 | size: 'lg', |
473 | resolve: { | 474 | resolve: { |
474 | parametrosFactura: function() { | 475 | parametrosFactura: function() { |
475 | return { | 476 | return { |
476 | cliente: $scope.cobranza.cliente, | 477 | cliente: $scope.cobranza.cliente, |
477 | simbolo: $scope.cobranza.cotizacion.moneda.SIMBOLO, | 478 | simbolo: $scope.cobranza.cotizacion.moneda.SIMBOLO, |
478 | cotizacion: $scope.cobranza.cotizacion.VENDEDOR, | 479 | cotizacion: $scope.cobranza.cotizacion.VENDEDOR, |
479 | moneda: $scope.cobranza.cotizacion.moneda.ID | 480 | moneda: $scope.cobranza.cotizacion.moneda.ID |
480 | }; | 481 | }; |
481 | } | 482 | } |
482 | } | 483 | } |
483 | } | 484 | } |
484 | ); | 485 | ); |
485 | modalInstance.result.then( | 486 | modalInstance.result.then( |
486 | function(facturas) { | 487 | function(facturas) { |
487 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturas); | 488 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturas); |
488 | }, function() { | 489 | }, function() { |
489 | 490 | ||
490 | } | 491 | } |
491 | ); | 492 | ); |
492 | }; | 493 | }; |
493 | 494 | ||
494 | $scope.seleccionarCheque = function() { | 495 | $scope.seleccionarCheque = function() { |
495 | var modalInstance = $uibModal.open( | 496 | var modalInstance = $uibModal.open( |
496 | { | 497 | { |
497 | ariaLabelledBy: 'Carga de cheques', | 498 | ariaLabelledBy: 'Carga de cheques', |
498 | templateUrl: 'modal-cheque.html', | 499 | templateUrl: 'modal-cheque.html', |
499 | controller: 'focaModalChequeController', | 500 | controller: 'focaModalChequeController', |
500 | size: 'lg', | 501 | size: 'lg', |
501 | resolve: { | 502 | resolve: { |
502 | sugerido: function() { | 503 | sugerido: function() { |
503 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | 504 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); |
504 | return sugerido < 0 ? sugerido : null; | 505 | return sugerido < 0 ? sugerido : null; |
505 | } | 506 | } |
506 | } | 507 | } |
507 | } | 508 | } |
508 | ); | 509 | ); |
509 | modalInstance.result.then( | 510 | modalInstance.result.then( |
510 | function(cheque) { | 511 | function(cheque) { |
511 | var cobro = { | 512 | var cobro = { |
512 | tipo: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | 513 | tipo: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, |
513 | numero: cheque.numero, | 514 | numero: cheque.numero, |
514 | banco: cheque.banco, | 515 | banco: cheque.banco, |
515 | fecha: cheque.fechaEmision.toLocaleDateString() + '-' + | 516 | fecha: cheque.fechaEmision.toLocaleDateString() + '-' + |
516 | cheque.fechaPresentacion.toLocaleDateString(), | 517 | cheque.fechaPresentacion.toLocaleDateString(), |
517 | fechaPresentacion: cheque.fechaPresentacion, | 518 | fechaPresentacion: cheque.fechaPresentacion, |
518 | fechaEmision: cheque.fechaEmision, | 519 | fechaEmision: cheque.fechaEmision, |
519 | importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, | 520 | importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, |
520 | localidad: cheque.localidad, | 521 | localidad: cheque.localidad, |
521 | librador: cheque.librador, | 522 | librador: cheque.librador, |
522 | provincia: cheque.provincia, | 523 | provincia: cheque.provincia, |
523 | observaciones: cheque.observaciones, | 524 | observaciones: cheque.observaciones, |
524 | til: 'EF' | 525 | til: 'EF' |
525 | }; | 526 | }; |
526 | $scope.cobranza.cobros.push(cobro); | 527 | $scope.cobranza.cobros.push(cobro); |
527 | }, function() { | 528 | }, function() { |
528 | 529 | ||
529 | } | 530 | } |
530 | ); | 531 | ); |
531 | }; | 532 | }; |
532 | 533 | ||
533 | $scope.seleccionarEfectivo = function() { | 534 | $scope.seleccionarEfectivo = function() { |
534 | var modalInstance = $uibModal.open( | 535 | var modalInstance = $uibModal.open( |
535 | { | 536 | { |
536 | ariaLabelledBy: 'Carga de cheques', | 537 | ariaLabelledBy: 'Carga de cheques', |
537 | templateUrl: 'modal-efectivo.html', | 538 | templateUrl: 'modal-efectivo.html', |
538 | controller: 'focaModalEfectivoController', | 539 | controller: 'focaModalEfectivoController', |
539 | size: 'sm', | 540 | size: 'sm', |
540 | resolve: { | 541 | resolve: { |
541 | sugerido: function() { | 542 | sugerido: function() { |
542 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | 543 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); |
543 | return sugerido < 0 ? sugerido : null; | 544 | return sugerido < 0 ? sugerido : null; |
544 | } | 545 | } |
545 | } | 546 | } |
546 | } | 547 | } |
547 | ); | 548 | ); |
548 | modalInstance.result.then( | 549 | modalInstance.result.then( |
549 | function(efectivo) { | 550 | function(efectivo) { |
550 | var cobro = { | 551 | var cobro = { |
551 | tipo: 'Efectivo', | 552 | tipo: 'Efectivo', |
552 | fecha: new Date(), | 553 | fecha: new Date(), |
553 | importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR, | 554 | importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR, |
554 | til: 'EF' | 555 | til: 'EF' |
555 | }; | 556 | }; |
556 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | 557 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { |
557 | return a.tipo !== 'Efectivo'; | 558 | return a.tipo !== 'Efectivo'; |
558 | }); | 559 | }); |
559 | $scope.cobranza.cobros.push(cobro); | 560 | $scope.cobranza.cobros.push(cobro); |
560 | }, function() { | 561 | }, function() { |
561 | 562 | ||
562 | } | 563 | } |
563 | ); | 564 | ); |
564 | }; | 565 | }; |
565 | 566 | ||
566 | $scope.seleccionarDetalles = function() { | 567 | $scope.seleccionarDetalles = function() { |
567 | var modalInstance = $uibModal.open( | 568 | var modalInstance = $uibModal.open( |
568 | { | 569 | { |
569 | ariaLabelledBy: 'Carga de detalles', | 570 | ariaLabelledBy: 'Carga de detalles', |
570 | templateUrl: 'modal-detalles.html', | 571 | templateUrl: 'modal-detalles.html', |
571 | controller: 'focaModalDetallesController', | 572 | controller: 'focaModalDetallesController', |
572 | size: 'lg', | 573 | size: 'lg', |
573 | resolve: { | 574 | resolve: { |
574 | sugerido: function() { | 575 | sugerido: function() { |
575 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | 576 | var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); |
576 | return sugerido < 0 ? sugerido : null; | 577 | return sugerido < 0 ? sugerido : null; |
577 | } | 578 | } |
578 | } | 579 | } |
579 | } | 580 | } |
580 | ); | 581 | ); |
581 | modalInstance.result.then( | 582 | modalInstance.result.then( |
582 | function(detalles) { | 583 | function(detalles) { |
583 | var cobro = { | 584 | var cobro = { |
584 | tipo: 'de(COBRO POR DETALLES)', | 585 | tipo: 'de(COBRO POR DETALLES)', |
585 | fecha: new Date(), | 586 | fecha: new Date(), |
586 | importe: detalles.monto * $scope.cobranza.cotizacion.VENDEDOR, | 587 | importe: detalles.monto * $scope.cobranza.cotizacion.VENDEDOR, |
587 | imgs: detalles.imgs, | 588 | imgs: detalles.imgs, |
588 | til: 'DE', | 589 | til: 'DE', |
589 | observacion: detalles.observacion | 590 | observacion: detalles.observacion |
590 | }; | 591 | }; |
591 | var existe = false; | 592 | var existe = false; |
592 | 593 | ||
593 | $scope.cobranza.cobros.forEach(function(c, idx) { | 594 | $scope.cobranza.cobros.forEach(function(c, idx) { |
594 | if (c.til === 'DE') { | 595 | if (c.til === 'DE') { |
595 | $scope.cobranza.cobros[idx] = cobro; | 596 | $scope.cobranza.cobros[idx] = cobro; |
596 | existe = true; | 597 | existe = true; |
597 | } | 598 | } |
598 | }); | 599 | }); |
599 | if (!existe) { | 600 | if (!existe) { |
600 | $scope.cobranza.cobros.push(cobro); | 601 | $scope.cobranza.cobros.push(cobro); |
601 | } | 602 | } |
602 | }, function() {} | 603 | }, function() {} |
603 | ); | 604 | ); |
604 | }; | 605 | }; |
605 | 606 | ||
606 | $scope.seleccionarMoneda = function() { | 607 | $scope.seleccionarMoneda = function() { |
607 | var parametrosModal = { | 608 | var parametrosModal = { |
608 | titulo: 'Búsqueda de monedas', | 609 | titulo: 'Búsqueda de monedas', |
609 | query: '/moneda', | 610 | query: '/moneda', |
610 | columnas: [ | 611 | columnas: [ |
611 | { | 612 | { |
612 | propiedad: 'DETALLE', | 613 | propiedad: 'DETALLE', |
613 | nombre: 'Nombre' | 614 | nombre: 'Nombre' |
614 | }, | 615 | }, |
615 | { | 616 | { |
616 | propiedad: 'SIMBOLO', | 617 | propiedad: 'SIMBOLO', |
617 | nombre: 'Símbolo' | 618 | nombre: 'Símbolo' |
618 | } | 619 | } |
619 | ], | 620 | ], |
620 | size: 'md' | 621 | size: 'md' |
621 | }; | 622 | }; |
622 | focaModalService.modal(parametrosModal).then( | 623 | focaModalService.modal(parametrosModal).then( |
623 | function(moneda) { | 624 | function(moneda) { |
624 | $scope.seleccionarCotizacion(moneda); | 625 | $scope.seleccionarCotizacion(moneda); |
625 | }, function() { | 626 | }, function() { |
626 | 627 | ||
627 | } | 628 | } |
628 | ); | 629 | ); |
629 | }; | 630 | }; |
630 | 631 | ||
631 | $scope.seleccionarCotizacion = function(moneda) { | 632 | $scope.seleccionarCotizacion = function(moneda) { |
632 | var modalInstance = $uibModal.open( | 633 | var modalInstance = $uibModal.open( |
633 | { | 634 | { |
634 | ariaLabelledBy: 'Busqueda de Cotización', | 635 | ariaLabelledBy: 'Busqueda de Cotización', |
635 | templateUrl: 'modal-cotizacion.html', | 636 | templateUrl: 'modal-cotizacion.html', |
636 | controller: 'focaModalCotizacionController', | 637 | controller: 'focaModalCotizacionController', |
637 | size: 'lg', | 638 | size: 'lg', |
638 | resolve: {idMoneda: function() {return moneda.ID;}} | 639 | resolve: {idMoneda: function() {return moneda.ID;}} |
639 | } | 640 | } |
640 | ); | 641 | ); |
641 | modalInstance.result.then( | 642 | modalInstance.result.then( |
642 | function(cotizacion) { | 643 | function(cotizacion) { |
643 | $scope.cobranza.cotizacion.moneda = moneda; | 644 | $scope.cobranza.cotizacion.moneda = moneda; |
644 | $scope.cobranza.cotizacion = cotizacion; | 645 | $scope.cobranza.cotizacion = cotizacion; |
645 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 646 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
646 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 647 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
647 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 648 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
648 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 649 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
649 | } else { | 650 | } else { |
650 | $scope.$broadcast('addCabecera', { | 651 | $scope.$broadcast('addCabecera', { |
651 | label: 'Moneda:', | 652 | label: 'Moneda:', |
652 | valor: moneda.DETALLE | 653 | valor: moneda.DETALLE |
653 | }); | 654 | }); |
654 | $scope.$broadcast('addCabecera', { | 655 | $scope.$broadcast('addCabecera', { |
655 | label: 'Fecha cotizacion:', | 656 | label: 'Fecha cotizacion:', |
656 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 657 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
657 | }); | 658 | }); |
658 | $scope.$broadcast('addCabecera', { | 659 | $scope.$broadcast('addCabecera', { |
659 | label: 'Cotizacion:', | 660 | label: 'Cotizacion:', |
660 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 661 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
661 | }); | 662 | }); |
662 | } | 663 | } |
663 | }, function() { | 664 | }, function() { |
664 | 665 | ||
665 | } | 666 | } |
666 | ); | 667 | ); |
667 | }; | 668 | }; |
668 | 669 | ||
669 | $scope.getTotalDeuda = function() { | 670 | $scope.getTotalDeuda = function() { |
670 | var total = 0; | 671 | var total = 0; |
671 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { | 672 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { |
672 | total += $scope.cobranza.facturas[i].IPA; | 673 | total += $scope.cobranza.facturas[i].IPA; |
673 | } | 674 | } |
674 | return parseFloat(total.toFixed(2)); | 675 | return parseFloat(total.toFixed(2)); |
675 | }; | 676 | }; |
676 | 677 | ||
677 | $scope.getTotalCobrado = function() { | 678 | $scope.getTotalCobrado = function() { |
678 | var total = 0; | 679 | var total = 0; |
679 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { | 680 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { |
680 | total += $scope.cobranza.cobros[i].importe; | 681 | total += $scope.cobranza.cobros[i].importe; |
681 | } | 682 | } |
682 | return parseFloat(total.toFixed(2)); | 683 | return parseFloat(total.toFixed(2)); |
683 | }; | 684 | }; |
684 | 685 | ||
685 | $scope.getSubTotal = function() { | 686 | $scope.getSubTotal = function() { |
686 | if ($scope.articuloACargar) { | 687 | if ($scope.articuloACargar) { |
687 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 688 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
688 | } | 689 | } |
689 | }; | 690 | }; |
690 | //Recibe aviso si el teclado está en uso | 691 | //Recibe aviso si el teclado está en uso |
691 | // $rootScope.$on('usarTeclado', function(event, data) { | 692 | // $rootScope.$on('usarTeclado', function(event, data) { |
692 | // if(data) { | 693 | // if(data) { |
693 | // $scope.mostrarTeclado = true; | 694 | // $scope.mostrarTeclado = true; |
694 | // return; | 695 | // return; |
695 | // } | 696 | // } |
696 | // $scope.mostrarTeclado = false; | 697 | // $scope.mostrarTeclado = false; |
697 | // }) | 698 | // }) |
698 | $scope.selectFocus = function($event) { | 699 | $scope.selectFocus = function($event) { |
699 | //Si el teclado esta en uso no selecciona el valor | 700 | //Si el teclado esta en uso no selecciona el valor |
700 | // if($scope.mostrarTeclado) { | 701 | // if($scope.mostrarTeclado) { |
701 | // return; | 702 | // return; |
702 | // } | 703 | // } |
703 | $event.target.select(); | 704 | $event.target.select(); |
704 | }; | 705 | }; |
705 | 706 | ||
706 | $scope.salir = function() { | 707 | $scope.salir = function() { |
707 | $location.path('/'); | 708 | $location.path('/'); |
708 | }; | 709 | }; |
709 | 710 | ||
710 | $scope.parsearATexto = function(articulo) { | 711 | $scope.parsearATexto = function(articulo) { |
711 | articulo.cantidad = parseFloat(articulo.cantidad); | 712 | articulo.cantidad = parseFloat(articulo.cantidad); |
712 | articulo.precio = parseFloat(articulo.precio); | 713 | articulo.precio = parseFloat(articulo.precio); |
713 | }; | 714 | }; |
714 | 715 | ||
715 | $scope.quitarFactura = function(key) { | 716 | $scope.quitarFactura = function(key) { |
716 | $scope.cobranza.facturas.splice(key, 1); | 717 | $scope.cobranza.facturas.splice(key, 1); |
717 | }; | 718 | }; |
718 | 719 | ||
719 | $scope.quitarCobro = function(key) { | 720 | $scope.quitarCobro = function(key) { |
720 | $scope.cobranza.cobros.splice(key, 1); | 721 | $scope.cobranza.cobros.splice(key, 1); |
721 | }; | 722 | }; |
722 | 723 | ||
723 | function salir() { | 724 | function salir() { |
724 | var confirmacion = false; | 725 | var confirmacion = false; |
725 | 726 | ||
726 | if (!angular.equals($scope.cobranza, $scope.inicial)) { | 727 | if (!angular.equals($scope.cobranza, $scope.inicial)) { |
727 | confirmacion = true; | 728 | confirmacion = true; |
728 | } | 729 | } |
729 | 730 | ||
730 | if (confirmacion) { | 731 | if (confirmacion) { |
731 | focaModalService.confirm( | 732 | focaModalService.confirm( |
732 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 733 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
733 | ).then(function(data) { | 734 | ).then(function(data) { |
734 | if (data) { | 735 | if (data) { |
735 | $location.path('/'); | 736 | $location.path('/'); |
736 | } | 737 | } |
737 | }); | 738 | }); |
738 | } else { | 739 | } else { |
739 | $location.path('/'); | 740 | $location.path('/'); |
740 | } | 741 | } |
741 | } | 742 | } |
742 | 743 | ||
743 | function setearCobranza(cobranza) { | 744 | function setearCobranza(cobranza) { |
744 | $scope.editando = true; | 745 | $scope.editando = true; |
745 | $scope.$broadcast('cleanCabecera'); | 746 | $scope.$broadcast('cleanCabecera'); |
746 | 747 | ||
747 | if (cobranza.cliente) { | 748 | if (cobranza.cliente) { |
748 | $scope.$broadcast('addCabecera', { | 749 | $scope.$broadcast('addCabecera', { |
749 | label: 'Cliente:', | 750 | label: 'Cliente:', |
750 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + | 751 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + |
751 | cobranza.cliente.NOM | 752 | cobranza.cliente.NOM |
752 | }); | 753 | }); |
753 | } | 754 | } |
754 | if (cobranza.cobrador && cobranza.cobrador.NUM) { | 755 | if (cobranza.cobrador && cobranza.cobrador.NUM) { |
755 | $scope.$broadcast('addCabecera', { | 756 | $scope.$broadcast('addCabecera', { |
756 | label: 'Cobrador:', | 757 | label: 'Cobrador:', |
757 | valor: (cobranza.cobrador.NUM) ? | 758 | valor: (cobranza.cobrador.NUM) ? |
758 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + | 759 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + |
759 | cobranza.cobrador.NOM : cobranza.cobrador | 760 | cobranza.cobrador.NOM : cobranza.cobrador |
760 | 761 | ||
761 | }); | 762 | }); |
762 | } | 763 | } |
763 | 764 | ||
764 | $scope.cobranza = cobranza; | 765 | $scope.cobranza = cobranza; |
765 | } | 766 | } |
766 | 767 | ||
767 | function getLSCobranza() { | 768 | function getLSCobranza() { |
768 | var cobranza = JSON.parse($localStorage.cobranza || null); | 769 | var cobranza = JSON.parse($localStorage.cobranza || null); |
769 | if (cobranza) { | 770 | if (cobranza) { |
770 | setearCobranza(cobranza); | 771 | setearCobranza(cobranza); |
771 | delete $localStorage.cobranza; | 772 | delete $localStorage.cobranza; |
772 | } | 773 | } |
773 | } | 774 | } |
774 | } | 775 | } |
775 | ]); | 776 | ]); |
776 | 777 |