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