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