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