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