Commit a40d8827163b0bc6eec54006d0c7618e53a18e7f

Authored by Luigi
1 parent eaa5cb3ba3
Exists in master and in 1 other branch develop

Al seleccionar otro IVA, el tipo de factura se reinicia a 0

Showing 1 changed file with 9 additions and 1 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaBusquedaCliente') 1 angular.module('focaBusquedaCliente')
2 .controller('focaBusquedaClienteModalController', [ 2 .controller('focaBusquedaClienteModalController', [
3 '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter', 3 '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter',
4 '$uibModal', 'focaModalService', '$timeout', 'vendedor', 'cobrador', 4 '$uibModal', 'focaModalService', '$timeout', 'vendedor', 'cobrador',
5 function($uibModalInstance, focaBusquedaClienteService, $scope, $filter, 5 function($uibModalInstance, focaBusquedaClienteService, $scope, $filter,
6 $uibModal, focaModalService, $timeout, vendedor, cobrador) { 6 $uibModal, focaModalService, $timeout, vendedor, cobrador) {
7 7
8 $scope.cobrador = cobrador ? cobrador : {}; 8 $scope.cobrador = cobrador ? cobrador : {};
9 $scope.vendedor = vendedor ? vendedor : {}; 9 $scope.vendedor = vendedor ? vendedor : {};
10 $scope.filters = ''; 10 $scope.filters = '';
11 $scope.primerBusqueda = false; 11 $scope.primerBusqueda = false;
12 // pagination 12 // pagination
13 $scope.numPerPage = 10; 13 $scope.numPerPage = 10;
14 $scope.currentPage = 1; 14 $scope.currentPage = 1;
15 $scope.filteredClientes = []; 15 $scope.filteredClientes = [];
16 $scope.currentPageClientes = []; 16 $scope.currentPageClientes = [];
17 $scope.selectedClientes = -1; 17 $scope.selectedClientes = -1;
18 $scope.ingreso = false; 18 $scope.ingreso = false;
19 $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/); 19 $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/);
20 $scope.focused = 1; 20 $scope.focused = 1;
21 21
22 $scope.cliente = { 22 $scope.cliente = {
23 COD: 0, 23 COD: 0,
24 ES_MAY: true, 24 ES_MAY: true,
25 cuit1: '', 25 cuit1: '',
26 cuit2: '', 26 cuit2: '',
27 cuit3: '', 27 cuit3: '',
28 provincia: { 28 provincia: {
29 NOMBRE: '' 29 NOMBRE: ''
30 }, 30 },
31 localidad: { 31 localidad: {
32 NOMBRE: '' 32 NOMBRE: ''
33 }, 33 },
34 iva: { 34 iva: {
35 NOMBRE: '' 35 NOMBRE: ''
36 }, 36 },
37 actividad: { 37 actividad: {
38 NOM: '' 38 NOM: ''
39 }, 39 },
40 zona: { 40 zona: {
41 NOM: '' 41 NOM: ''
42 }, 42 },
43 tipoFactura: { 43 tipoFactura: {
44 NOMBRE: '' 44 NOMBRE: ''
45 }, 45 },
46 tipoComprobante: { 46 tipoComprobante: {
47 NOMBRE: '' 47 NOMBRE: ''
48 }, 48 },
49 formaPago: { 49 formaPago: {
50 NOMBRE: '' 50 NOMBRE: ''
51 }, 51 },
52 cobrador: { 52 cobrador: {
53 NomVen: '' 53 NomVen: ''
54 } 54 }
55 }; 55 };
56 56
57 $scope.busquedaPress = function(key) { 57 $scope.busquedaPress = function(key) {
58 if (key === 13) { 58 if (key === 13) {
59 var funcion; 59 var funcion;
60 if ($scope.vendedor.id) { 60 if ($scope.vendedor.id) {
61 funcion = 'obtenerClientesPorNombreOCuitByVendedor'; 61 funcion = 'obtenerClientesPorNombreOCuitByVendedor';
62 } else if ($scope.cobrador.id) { 62 } else if ($scope.cobrador.id) {
63 funcion = 'obtenerClientesPorNombreOCuitByCobrador'; 63 funcion = 'obtenerClientesPorNombreOCuitByCobrador';
64 } else { 64 } else {
65 funcion = 'obtenerClientesPorNombreOCuit'; 65 funcion = 'obtenerClientesPorNombreOCuit';
66 } 66 }
67 67
68
69 $scope.searchLoading = true; 68 $scope.searchLoading = true;
70 focaBusquedaClienteService 69 focaBusquedaClienteService
71 [funcion]($scope.filters, $scope.vendedor.id || $scope.cobrador.id) 70 [funcion]($scope.filters, $scope.vendedor.id || $scope.cobrador.id)
72 .then( 71 .then(
73 function(res) { 72 function(res) {
74 $scope.primerBusqueda = true; 73 $scope.primerBusqueda = true;
75 $scope.clientes = res.data; 74 $scope.clientes = res.data;
76 $scope.search(true); 75 $scope.search(true);
77 primera(); 76 primera();
78 $scope.searchLoading = false; 77 $scope.searchLoading = false;
79 }); 78 });
80 } 79 }
81 }; 80 };
82 81
83 $scope.search = function (pressed) { 82 $scope.search = function (pressed) {
84 if ($scope.primerBusqueda) { 83 if ($scope.primerBusqueda) {
85 $scope.filteredClientes = $filter('filter')( 84 $scope.filteredClientes = $filter('filter')(
86 $scope.clientes, {$: $scope.filters} 85 $scope.clientes, {$: $scope.filters}
87 ); 86 );
88 87
89 if (pressed && $scope.filteredClientes.length === 0) { 88 if (pressed && $scope.filteredClientes.length === 0) {
90 $timeout(function() { 89 $timeout(function() {
91 angular.element('#search')[0].focus(); 90 angular.element('#search')[0].focus();
92 $scope.filters = ''; 91 $scope.filters = '';
93 }); 92 });
94 } 93 }
95 94
96 $scope.lastPage = Math.ceil( 95 $scope.lastPage = Math.ceil(
97 $scope.filteredClientes.length / $scope.numPerPage 96 $scope.filteredClientes.length / $scope.numPerPage
98 ); 97 );
99 98
100 $scope.resetPage(); 99 $scope.resetPage();
101 } 100 }
102 }; 101 };
103 102
104 $scope.resetPage = function () { 103 $scope.resetPage = function () {
105 $scope.currentPage = 1; 104 $scope.currentPage = 1;
106 $scope.selectPage(1); 105 $scope.selectPage(1);
107 }; 106 };
108 107
109 $scope.selectPage = function (page) { 108 $scope.selectPage = function (page) {
110 var start = (page - 1) * $scope.numPerPage; 109 var start = (page - 1) * $scope.numPerPage;
111 var end = start + $scope.numPerPage; 110 var end = start + $scope.numPerPage;
112 $scope.paginas = []; 111 $scope.paginas = [];
113 $scope.paginas = calcularPages(page); 112 $scope.paginas = calcularPages(page);
114 $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); 113 $scope.currentPageClientes = $scope.filteredClientes.slice(start, end);
115 $scope.currentPage = page; 114 $scope.currentPage = page;
116 }; 115 };
117 116
118 $scope.select = function(cliente, esNuevo = false) { 117 $scope.select = function(cliente, esNuevo = false) {
119 cliente.esNuevo = esNuevo; 118 cliente.esNuevo = esNuevo;
120 $uibModalInstance.close(cliente); 119 $uibModalInstance.close(cliente);
121 }; 120 };
122 121
123 $scope.cancel = function() { 122 $scope.cancel = function() {
124 if ($scope.ingreso) { 123 if ($scope.ingreso) {
125 $scope.ingreso = false; 124 $scope.ingreso = false;
126 } else { 125 } else {
127 $uibModalInstance.dismiss('cancel'); 126 $uibModalInstance.dismiss('cancel');
128 } 127 }
129 }; 128 };
130 129
131 $scope.busquedaDown = function(key) { 130 $scope.busquedaDown = function(key) {
132 if (key === 40) { 131 if (key === 40) {
133 primera(key); 132 primera(key);
134 } 133 }
135 }; 134 };
136 135
137 $scope.itemCliente = function(key) { 136 $scope.itemCliente = function(key) {
138 if (key === 38) { 137 if (key === 38) {
139 anterior(key); 138 anterior(key);
140 } 139 }
141 140
142 if (key === 40) { 141 if (key === 40) {
143 siguiente(key); 142 siguiente(key);
144 } 143 }
145 144
146 if (key === 37) { 145 if (key === 37) {
147 retrocederPagina(); 146 retrocederPagina();
148 } 147 }
149 148
150 if (key === 39) { 149 if (key === 39) {
151 avanzarPagina(); 150 avanzarPagina();
152 } 151 }
153 }; 152 };
154 153
155 $scope.focus = function(val) { 154 $scope.focus = function(val) {
156 $scope.focused = val; 155 $scope.focused = val;
157 }; 156 };
158 157
159 $scope.next = function(key) { 158 $scope.next = function(key) {
160 if (key === 13) $scope.focused++; 159 if (key === 13) $scope.focused++;
161 }; 160 };
162 161
163 $scope.seleccionarProvincia = function(key) { 162 $scope.seleccionarProvincia = function(key) {
164 if (key === 13) { 163 if (key === 13) {
165 var parametrosModal = { 164 var parametrosModal = {
166 searchText: $scope.cliente.provincia.NOMBRE, 165 searchText: $scope.cliente.provincia.NOMBRE,
167 query: '/provincia', 166 query: '/provincia',
168 columnas: [ 167 columnas: [
169 { 168 {
170 propiedad: 'ID', 169 propiedad: 'ID',
171 nombre: 'Codigo', 170 nombre: 'Codigo',
172 filtro: { 171 filtro: {
173 nombre: 'rellenarDigitos', 172 nombre: 'rellenarDigitos',
174 parametro: 3 173 parametro: 3
175 } 174 }
176 }, 175 },
177 { 176 {
178 propiedad: 'NOMBRE', 177 propiedad: 'NOMBRE',
179 nombre: 'Nombre' 178 nombre: 'Nombre'
180 } 179 }
181 ], 180 ],
182 titulo:'Búsqueda de provincias', 181 titulo:'Búsqueda de provincias',
183 size: 'md' 182 size: 'md'
184 }; 183 };
185 focaModalService.modal(parametrosModal).then(function(provincia) { 184 focaModalService.modal(parametrosModal).then(function(provincia) {
186 $scope.cliente.provincia = provincia; 185 $scope.cliente.provincia = provincia;
187 $timeout(function() { 186 $timeout(function() {
188 $scope.focused = 4; 187 $scope.focused = 4;
189 }); 188 });
190 }, function() { 189 }, function() {
191 //TODO: función llamada cuando cancela el modal 190 //TODO: función llamada cuando cancela el modal
192 }); 191 });
193 } 192 }
194 }; 193 };
195 $scope.seleccionarLocalidad = function(key) { 194 $scope.seleccionarLocalidad = function(key) {
196 if ($scope.cliente.provincia.ID === undefined) { 195 if ($scope.cliente.provincia.ID === undefined) {
197 focaModalService.alert('Seleccione una provincia'); 196 focaModalService.alert('Seleccione una provincia');
198 return; 197 return;
199 } 198 }
200 if (key === 13) { 199 if (key === 13) {
201 var parametrosModal = { 200 var parametrosModal = {
202 searchText: $scope.cliente.localidad.NOMBRE, 201 searchText: $scope.cliente.localidad.NOMBRE,
203 query: '/localidad/' + $scope.cliente.provincia.ID, 202 query: '/localidad/' + $scope.cliente.provincia.ID,
204 columnas: [ 203 columnas: [
205 { 204 {
206 propiedad: 'ID', 205 propiedad: 'ID',
207 nombre: 'Código', 206 nombre: 'Código',
208 filtro: { 207 filtro: {
209 nombre: 'rellenarDigitos', 208 nombre: 'rellenarDigitos',
210 parametro: 3 209 parametro: 3
211 } 210 }
212 }, 211 },
213 { 212 {
214 propiedad: 'NOMBRE', 213 propiedad: 'NOMBRE',
215 nombre: 'Nombre' 214 nombre: 'Nombre'
216 } 215 }
217 ], 216 ],
218 titulo:'Búsqueda de localidades', 217 titulo:'Búsqueda de localidades',
219 size: 'md' 218 size: 'md'
220 }; 219 };
221 focaModalService.modal(parametrosModal).then(function(localidad) { 220 focaModalService.modal(parametrosModal).then(function(localidad) {
222 $scope.cliente.localidad = localidad; 221 $scope.cliente.localidad = localidad;
223 $timeout(function() { 222 $timeout(function() {
224 $scope.focused = 5; 223 $scope.focused = 5;
225 }); 224 });
226 }, function() { 225 }, function() {
227 //TODO: función llamada cuando cancela el modal 226 //TODO: función llamada cuando cancela el modal
228 }); 227 });
229 } 228 }
230 }; 229 };
231 $scope.seleccionarIva = function(key) { 230 $scope.seleccionarIva = function(key) {
232 if (key === 13) { 231 if (key === 13) {
233 var parametrosModal = { 232 var parametrosModal = {
234 query: '/iva', 233 query: '/iva',
235 searchText: $scope.cliente.iva.NOMBRE, 234 searchText: $scope.cliente.iva.NOMBRE,
236 columnas: [ 235 columnas: [
237 { 236 {
238 propiedad: 'ID', 237 propiedad: 'ID',
239 nombre: 'Código', 238 nombre: 'Código',
240 filtro: { 239 filtro: {
241 nombre: 'rellenarDigitos', 240 nombre: 'rellenarDigitos',
242 parametro: 3 241 parametro: 3
243 } 242 }
244 }, 243 },
245 { 244 {
246 propiedad: 'NOMBRE', 245 propiedad: 'NOMBRE',
247 nombre: 'Nombre' 246 nombre: 'Nombre'
248 } 247 }
249 ], 248 ],
250 titulo:'Búsqueda de responsabilidad ante el IVA', 249 titulo:'Búsqueda de responsabilidad ante el IVA',
251 size: 'md' 250 size: 'md'
252 }; 251 };
253 focaModalService.modal(parametrosModal).then( 252 focaModalService.modal(parametrosModal).then(
254 function(iva) { 253 function(iva) {
254 if (iva) {
255 delete $scope.cliente.tipoFactura.NOMBRE;
256 }
255 $scope.cliente.iva = iva; 257 $scope.cliente.iva = iva;
256 $timeout(function() { 258 $timeout(function() {
257 $scope.focused = 12; 259 $scope.focused = 12;
258 }); 260 });
259 }, function() { 261 }, function() {
260 // funcion ejecutada cuando se cancela el modal 262 // funcion ejecutada cuando se cancela el modal
261 }); 263 });
262 } 264 }
263 }; 265 };
264 $scope.seleccionarActividad = function(key) { 266 $scope.seleccionarActividad = function(key) {
265 if (key === 13) { 267 if (key === 13) {
266 var parametrosModal = { 268 var parametrosModal = {
267 searchText: $scope.cliente.actividad.NOM, 269 searchText: $scope.cliente.actividad.NOM,
268 query: '/actividad', 270 query: '/actividad',
269 columnas: [ 271 columnas: [
270 { 272 {
271 propiedad: 'ID', 273 propiedad: 'ID',
272 nombre: 'Código', 274 nombre: 'Código',
273 filtro: { 275 filtro: {
274 nombre: 'rellenarDigitos', 276 nombre: 'rellenarDigitos',
275 parametro: 3 277 parametro: 3
276 } 278 }
277 }, 279 },
278 { 280 {
279 propiedad: 'NOM', 281 propiedad: 'NOM',
280 nombre: 'Nombre' 282 nombre: 'Nombre'
281 } 283 }
282 ], 284 ],
283 titulo: 'Búsqueda de actividades', 285 titulo: 'Búsqueda de actividades',
284 size: 'md' 286 size: 'md'
285 }; 287 };
286 focaModalService.modal(parametrosModal).then( 288 focaModalService.modal(parametrosModal).then(
287 function(actividad) { 289 function(actividad) {
288 $scope.cliente.actividad = actividad; 290 $scope.cliente.actividad = actividad;
289 $timeout(function() { 291 $timeout(function() {
290 $scope.focused = 7; 292 $scope.focused = 7;
291 }); 293 });
292 }, function() { 294 }, function() {
293 // funcion ejecutada cuando se cancela el modal 295 // funcion ejecutada cuando se cancela el modal
294 }); 296 });
295 } 297 }
296 }; 298 };
297 $scope.seleccionarZona = function(key) { 299 $scope.seleccionarZona = function(key) {
298 if (key === 13) { 300 if (key === 13) {
299 var parametrosModal = { 301 var parametrosModal = {
300 searchText: $scope.cliente.zona.NOM, 302 searchText: $scope.cliente.zona.NOM,
301 query: '/zona', 303 query: '/zona',
302 columnas: [ 304 columnas: [
303 { 305 {
304 propiedad: 'ID', 306 propiedad: 'ID',
305 nombre: 'Código', 307 nombre: 'Código',
306 filtro: { 308 filtro: {
307 nombre: 'rellenarDigitos', 309 nombre: 'rellenarDigitos',
308 parametro: 3 310 parametro: 3
309 } 311 }
310 }, 312 },
311 { 313 {
312 propiedad: 'NOM', 314 propiedad: 'NOM',
313 nombre: 'Nombre' 315 nombre: 'Nombre'
314 } 316 }
315 ], 317 ],
316 titulo: 'Búsqueda de zonas', 318 titulo: 'Búsqueda de zonas',
317 size: 'md' 319 size: 'md'
318 }; 320 };
319 focaModalService.modal(parametrosModal).then( 321 focaModalService.modal(parametrosModal).then(
320 function(zona) { 322 function(zona) {
321 $scope.cliente.zona = zona; 323 $scope.cliente.zona = zona;
322 $timeout(function() { 324 $timeout(function() {
323 $scope.focused = 6; 325 $scope.focused = 6;
324 }); 326 });
325 }, function() { 327 }, function() {
326 // funcion ejecutada cuando se cancela el modal 328 // funcion ejecutada cuando se cancela el modal
327 }); 329 });
328 } 330 }
329 }; 331 };
330 $scope.seleccionarTipoFactura = function(key) { 332 $scope.seleccionarTipoFactura = function(key) {
333
334 if ($scope.cliente.iva.NOMBRE == '') {
335 focaModalService.alert('Seleccione una responsabilidad ante el IVA');
336 return;
337 }
338
331 if (key === 13) { 339 if (key === 13) {
332 var datos; 340 var datos;
333 if ($scope.cliente.iva.ID == 1) { 341 if ($scope.cliente.iva.ID == 1) {
334 datos = [ 342 datos = [
335 { 343 {
336 ID: 'A', 344 ID: 'A',
337 NOMBRE: 'Factura A' 345 NOMBRE: 'Factura A'
338 }, 346 },
339 { 347 {
340 ID: 'M', 348 ID: 'M',
341 NOMBRE: 'Factura M' 349 NOMBRE: 'Factura M'
342 }, 350 },
343 { 351 {
344 ID: 'R', 352 ID: 'R',
345 NOMBRE: 'Remito' 353 NOMBRE: 'Remito'
346 } 354 }
347 ]; 355 ];
348 } else { 356 } else {
349 datos = [ 357 datos = [
350 { 358 {
351 ID: 'B', 359 ID: 'B',
352 NOMBRE: 'Factura B' 360 NOMBRE: 'Factura B'
353 }, 361 },
354 { 362 {
355 ID: 'R', 363 ID: 'R',
356 NOMBRE: 'Remito' 364 NOMBRE: 'Remito'
357 } 365 }
358 ]; 366 ];
359 } 367 }
360 focaModalService.modal({ 368 focaModalService.modal({
361 titulo: 'Seleccionar Factura', 369 titulo: 'Seleccionar Factura',
362 data: datos, 370 data: datos,
363 size: 'md', 371 size: 'md',
364 columnas: [ 372 columnas: [
365 { 373 {
366 propiedad: 'ID', 374 propiedad: 'ID',
367 NOMBRE: 'Codigo' 375 NOMBRE: 'Codigo'
368 }, 376 },
369 { 377 {
370 propiedad: 'NOMBRE', 378 propiedad: 'NOMBRE',
371 NOMBRE: 'Factura' 379 NOMBRE: 'Factura'
372 } 380 }
373 ], 381 ],
374 }).then(function(res) { 382 }).then(function(res) {
375 $scope.cliente.tipoFactura = res; 383 $scope.cliente.tipoFactura = res;
376 }); 384 });
377 } 385 }
378 }; 386 };
379 $scope.seleccionarTipoComprobante = function(key) { 387 $scope.seleccionarTipoComprobante = function(key) {
380 if (key === 13) { 388 if (key === 13) {
381 var parametrosModal = { 389 var parametrosModal = {
382 searchText: $scope.cliente.tipoComprobante.NOMBRE, 390 searchText: $scope.cliente.tipoComprobante.NOMBRE,
383 query: '/tipo-comprobante', 391 query: '/tipo-comprobante',
384 columnas: [ 392 columnas: [
385 { 393 {
386 propiedad: 'ID', 394 propiedad: 'ID',
387 nombre: 'Código' 395 nombre: 'Código'
388 }, 396 },
389 { 397 {
390 propiedad: 'NOMBRE', 398 propiedad: 'NOMBRE',
391 nombre: 'Nombre' 399 nombre: 'Nombre'
392 } 400 }
393 ], 401 ],
394 titulo: 'Búsqueda de tipos de comprobante', 402 titulo: 'Búsqueda de tipos de comprobante',
395 size: 'md' 403 size: 'md'
396 }; 404 };
397 focaModalService.modal(parametrosModal).then( 405 focaModalService.modal(parametrosModal).then(
398 function(tipoComprobante) { 406 function(tipoComprobante) {
399 $scope.cliente.tipoComprobante = tipoComprobante; 407 $scope.cliente.tipoComprobante = tipoComprobante;
400 $timeout(function() { 408 $timeout(function() {
401 $scope.focused = 17; 409 $scope.focused = 17;
402 }); 410 });
403 }, function() { 411 }, function() {
404 // funcion ejecutada cuando se cancela el modal 412 // funcion ejecutada cuando se cancela el modal
405 }); 413 });
406 } 414 }
407 }; 415 };
408 $scope.seleccionarFormaPago = function(key) { 416 $scope.seleccionarFormaPago = function(key) {
409 if (key === 13) { 417 if (key === 13) {
410 var parametrosModal = { 418 var parametrosModal = {
411 searchText: $scope.cliente.formaPago.NOMBRE, 419 searchText: $scope.cliente.formaPago.NOMBRE,
412 query: '/forma-pago', 420 query: '/forma-pago',
413 columnas: [ 421 columnas: [
414 { 422 {
415 propiedad: 'ID', 423 propiedad: 'ID',
416 nombre: 'Código', 424 nombre: 'Código',
417 filtro: { 425 filtro: {
418 nombre: 'rellenarDigitos', 426 nombre: 'rellenarDigitos',
419 parametro: 3 427 parametro: 3
420 } 428 }
421 }, 429 },
422 { 430 {
423 propiedad: 'NOMBRE', 431 propiedad: 'NOMBRE',
424 nombre: 'Nombre' 432 nombre: 'Nombre'
425 } 433 }
426 ], 434 ],
427 titulo: 'Búsqueda de formas de pago', 435 titulo: 'Búsqueda de formas de pago',
428 size: 'md' 436 size: 'md'
429 }; 437 };
430 focaModalService.modal(parametrosModal).then( 438 focaModalService.modal(parametrosModal).then(
431 function(formaPago) { 439 function(formaPago) {
432 $scope.cliente.formaPago = formaPago; 440 $scope.cliente.formaPago = formaPago;
433 }, function() { 441 }, function() {
434 // funcion ejecutada cuando se cancela el modal 442 // funcion ejecutada cuando se cancela el modal
435 }); 443 });
436 } 444 }
437 }; 445 };
438 $scope.seleccionarCobrador = function(key) { 446 $scope.seleccionarCobrador = function(key) {
439 if (key === 13) { 447 if (key === 13) {
440 var parametrosModal = { 448 var parametrosModal = {
441 searchText: $scope.cliente.cobrador.NOM, 449 searchText: $scope.cliente.cobrador.NOM,
442 query: '/cobrador', 450 query: '/cobrador',
443 columnas: [ 451 columnas: [
444 { 452 {
445 propiedad: 'NUM', 453 propiedad: 'NUM',
446 nombre: 'Código' 454 nombre: 'Código'
447 }, 455 },
448 { 456 {
449 propiedad: 'NOM', 457 propiedad: 'NOM',
450 nombre: 'Nombre' 458 nombre: 'Nombre'
451 } 459 }
452 ], 460 ],
453 titulo: 'Búsqueda de cobradores', 461 titulo: 'Búsqueda de cobradores',
454 size: 'md' 462 size: 'md'
455 }; 463 };
456 focaModalService.modal(parametrosModal).then( 464 focaModalService.modal(parametrosModal).then(
457 function(cobrador) { 465 function(cobrador) {
458 $scope.cliente.cobrador = cobrador; 466 $scope.cliente.cobrador = cobrador;
459 }, function() { 467 }, function() {
460 // funcion ejecutada cuando se cancela el modal 468 // funcion ejecutada cuando se cancela el modal
461 }); 469 });
462 } 470 }
463 }; 471 };
464 472
465 $scope.pasarCampoCuit = function(numeroCuit) { 473 $scope.pasarCampoCuit = function(numeroCuit) {
466 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { 474 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) {
467 $scope.cuitActivo = 2; 475 $scope.cuitActivo = 2;
468 } else if ( numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { 476 } else if ( numeroCuit === 2 && $scope.cliente.cuit2.length === 8) {
469 $scope.cuitActivo = 3; 477 $scope.cuitActivo = 3;
470 } 478 }
471 }; 479 };
472 480
473 $scope.guardar = function() { 481 $scope.guardar = function() {
474 if (!$scope.cliente.NOM) { 482 if (!$scope.cliente.NOM) {
475 focaModalService.alert('Ingrese Nombre'); 483 focaModalService.alert('Ingrese Nombre');
476 return; 484 return;
477 } else if (!$scope.cliente.CPO) { 485 } else if (!$scope.cliente.CPO) {
478 focaModalService.alert('Ingrese Codigo Postal'); 486 focaModalService.alert('Ingrese Codigo Postal');
479 return; 487 return;
480 } else if (!$scope.cliente.provincia.NOMBRE) { 488 } else if (!$scope.cliente.provincia.NOMBRE) {
481 focaModalService.alert('Seleccione una provincia'); 489 focaModalService.alert('Seleccione una provincia');
482 return; 490 return;
483 } else if (!$scope.cliente.DOM) { 491 } else if (!$scope.cliente.DOM) {
484 focaModalService.alert('Ingrese Domicilio'); 492 focaModalService.alert('Ingrese Domicilio');
485 return; 493 return;
486 } else if (!$scope.cliente.localidad.NOMBRE) { 494 } else if (!$scope.cliente.localidad.NOMBRE) {
487 focaModalService.alert('Seleccione una localidad'); 495 focaModalService.alert('Seleccione una localidad');
488 return; 496 return;
489 } else if (!$scope.cliente.zona.NOM) { 497 } else if (!$scope.cliente.zona.NOM) {
490 focaModalService.alert('Seleccione una zona'); 498 focaModalService.alert('Seleccione una zona');
491 return; 499 return;
492 } else if (!$scope.cliente.actividad.NOM) { 500 } else if (!$scope.cliente.actividad.NOM) {
493 focaModalService.alert('Seleccione actividad'); 501 focaModalService.alert('Seleccione actividad');
494 return; 502 return;
495 } else if (!$scope.cliente.cobrador.NUM) { 503 } else if (!$scope.cliente.cobrador.NUM) {
496 focaModalService.alert('Seleccione un cobrador'); 504 focaModalService.alert('Seleccione un cobrador');
497 return; 505 return;
498 } else if ($scope.cliente.MAIL && !validateEmails($scope.cliente.MAIL)) { 506 } else if ($scope.cliente.MAIL && !validateEmails($scope.cliente.MAIL)) {
499 focaModalService.alert('Ingrese un formato de email válido'); 507 focaModalService.alert('Ingrese un formato de email válido');
500 return; 508 return;
501 } else if (!$scope.cliente.TEL) { 509 } else if (!$scope.cliente.TEL) {
502 focaModalService.alert('Ingrese un numero de telefono'); 510 focaModalService.alert('Ingrese un numero de telefono');
503 return; 511 return;
504 } else if (!$scope.cliente.iva.NOMBRE) { 512 } else if (!$scope.cliente.iva.NOMBRE) {
505 focaModalService.alert('Seleccione responsabilidad ante el IVA'); 513 focaModalService.alert('Seleccione responsabilidad ante el IVA');
506 return; 514 return;
507 } else if (!$scope.cliente.tipoFactura.NOMBRE) { 515 } else if (!$scope.cliente.tipoFactura.NOMBRE) {
508 focaModalService.alert('Seleccione tipo de Factura'); 516 focaModalService.alert('Seleccione tipo de Factura');
509 return; 517 return;
510 } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) { 518 } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) {
511 focaModalService.alert('Ingrese CUIT'); 519 focaModalService.alert('Ingrese CUIT');
512 return; 520 return;
513 } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3){ 521 } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3){
514 focaModalService.alert('Ingrese CUIT válido'); 522 focaModalService.alert('Ingrese CUIT válido');
515 return; 523 return;
516 } else if (!$scope.regexCuit.test($scope.cliente.cuit1 + $scope.cliente.cuit2 + $scope.cliente.cuit3) ) { 524 } else if (!$scope.regexCuit.test($scope.cliente.cuit1 + $scope.cliente.cuit2 + $scope.cliente.cuit3) ) {
517 focaModalService.alert('Ingrese CUIT con formato: XX-XXXXXXXX-X'); 525 focaModalService.alert('Ingrese CUIT con formato: XX-XXXXXXXX-X');
518 return; 526 return;
519 } else if (!$scope.cliente.tipoComprobante.NOMBRE) { 527 } else if (!$scope.cliente.tipoComprobante.NOMBRE) {
520 focaModalService.alert('Seleccione un Comprobante'); 528 focaModalService.alert('Seleccione un Comprobante');
521 return; 529 return;
522 } else if (!$scope.cliente.formaPago.NOMBRE) { 530 } else if (!$scope.cliente.formaPago.NOMBRE) {
523 focaModalService.alert('Seleccione una forma de pago'); 531 focaModalService.alert('Seleccione una forma de pago');
524 return; 532 return;
525 } 533 }
526 534
527 var cliente = crearCopia(); 535 var cliente = crearCopia();
528 536
529 focaBusquedaClienteService 537 focaBusquedaClienteService
530 .guardarCliente(cliente) 538 .guardarCliente(cliente)
531 .then(function(res) { 539 .then(function(res) {
532 var cliente = { 540 var cliente = {
533 cod: res.data.COD, 541 cod: res.data.COD,
534 cuit: res.data.CUIT, 542 cuit: res.data.CUIT,
535 esNuevo: res.data.esNuevo, 543 esNuevo: res.data.esNuevo,
536 nom: res.data.NOM 544 nom: res.data.NOM
537 }; 545 };
538 $scope.select(cliente, true); 546 $scope.select(cliente, true);
539 }); 547 });
540 }; 548 };
541 549
542 function crearCopia(){ 550 function crearCopia(){
543 var cliente = angular.copy($scope.cliente); 551 var cliente = angular.copy($scope.cliente);
544 552
545 cliente.PCX = cliente.provincia.ID; 553 cliente.PCX = cliente.provincia.ID;
546 cliente.LOX = cliente.localidad.ID; 554 cliente.LOX = cliente.localidad.ID;
547 cliente.IVA = cliente.iva.ID; 555 cliente.IVA = cliente.iva.ID;
548 cliente.ACT = cliente.actividad.ID; 556 cliente.ACT = cliente.actividad.ID;
549 cliente.ZON = cliente.zona.ID; 557 cliente.ZON = cliente.zona.ID;
550 cliente.TIP = cliente.tipoFactura.ID; 558 cliente.TIP = cliente.tipoFactura.ID;
551 cliente.TCO = cliente.tipoComprobante.ID; 559 cliente.TCO = cliente.tipoComprobante.ID;
552 cliente.FPA = cliente.formaPago.ID; 560 cliente.FPA = cliente.formaPago.ID;
553 cliente.VEN = vendedor.ID; 561 cliente.VEN = vendedor.ID;
554 cliente.CUIT = cliente.cuit1 + cliente.cuit2 + cliente.cuit3; 562 cliente.CUIT = cliente.cuit1 + cliente.cuit2 + cliente.cuit3;
555 cliente.idCobrador = cliente.cobrador.ID; 563 cliente.idCobrador = cliente.cobrador.ID;
556 564
557 delete cliente.provincia; 565 delete cliente.provincia;
558 delete cliente.localidad; 566 delete cliente.localidad;
559 delete cliente.iva; 567 delete cliente.iva;
560 delete cliente.actividad; 568 delete cliente.actividad;
561 delete cliente.zona; 569 delete cliente.zona;
562 delete cliente.tipoFactura; 570 delete cliente.tipoFactura;
563 delete cliente.tipoComprobante; 571 delete cliente.tipoComprobante;
564 delete cliente.formaPago; 572 delete cliente.formaPago;
565 delete cliente.cobrador; 573 delete cliente.cobrador;
566 delete cliente.cuit1; 574 delete cliente.cuit1;
567 delete cliente.cuit2; 575 delete cliente.cuit2;
568 delete cliente.cuit3; 576 delete cliente.cuit3;
569 577
570 return cliente; 578 return cliente;
571 } 579 }
572 580
573 function calcularPages(paginaActual) { 581 function calcularPages(paginaActual) {
574 var paginas = []; 582 var paginas = [];
575 paginas.push(paginaActual); 583 paginas.push(paginaActual);
576 584
577 if (paginaActual - 1 > 1) { 585 if (paginaActual - 1 > 1) {
578 586
579 paginas.unshift(paginaActual - 1); 587 paginas.unshift(paginaActual - 1);
580 if (paginaActual - 2 > 1) { 588 if (paginaActual - 2 > 1) {
581 paginas.unshift(paginaActual - 2); 589 paginas.unshift(paginaActual - 2);
582 } 590 }
583 } 591 }
584 592
585 if (paginaActual + 1 < $scope.lastPage) { 593 if (paginaActual + 1 < $scope.lastPage) {
586 paginas.push(paginaActual + 1); 594 paginas.push(paginaActual + 1);
587 if (paginaActual + 2 < $scope.lastPage) { 595 if (paginaActual + 2 < $scope.lastPage) {
588 paginas.push(paginaActual + 2); 596 paginas.push(paginaActual + 2);
589 } 597 }
590 } 598 }
591 599
592 if (paginaActual !== 1) { 600 if (paginaActual !== 1) {
593 paginas.unshift(1); 601 paginas.unshift(1);
594 } 602 }
595 603
596 if (paginaActual !== $scope.lastPage) { 604 if (paginaActual !== $scope.lastPage) {
597 paginas.push($scope.lastPage); 605 paginas.push($scope.lastPage);
598 } 606 }
599 607
600 return paginas; 608 return paginas;
601 } 609 }
602 610
603 function primera() { 611 function primera() {
604 $scope.selectedClientes = 0; 612 $scope.selectedClientes = 0;
605 } 613 }
606 614
607 function anterior() { 615 function anterior() {
608 if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { 616 if ($scope.selectedClientes === 0 && $scope.currentPage > 1) {
609 retrocederPagina(); 617 retrocederPagina();
610 } else { 618 } else {
611 $scope.selectedClientes--; 619 $scope.selectedClientes--;
612 } 620 }
613 } 621 }
614 622
615 function siguiente() { 623 function siguiente() {
616 if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { 624 if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) {
617 $scope.selectedClientes++; 625 $scope.selectedClientes++;
618 } else { 626 } else {
619 avanzarPagina(); 627 avanzarPagina();
620 } 628 }
621 } 629 }
622 630
623 function retrocederPagina() { 631 function retrocederPagina() {
624 if ($scope.currentPage > 1) { 632 if ($scope.currentPage > 1) {
625 $scope.selectPage($scope.currentPage - 1); 633 $scope.selectPage($scope.currentPage - 1);
626 $scope.selectedClientes = $scope.numPerPage - 1; 634 $scope.selectedClientes = $scope.numPerPage - 1;
627 } 635 }
628 } 636 }
629 637
630 function avanzarPagina() { 638 function avanzarPagina() {
631 if ($scope.currentPage < $scope.lastPage) { 639 if ($scope.currentPage < $scope.lastPage) {
632 $scope.selectPage($scope.currentPage + 1); 640 $scope.selectPage($scope.currentPage + 1);
633 $scope.selectedClientes = 0; 641 $scope.selectedClientes = 0;
634 } 642 }
635 } 643 }
636 function validateEmails(emails) { 644 function validateEmails(emails) {
637 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 645 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
638 var arr = emails.split(','); 646 var arr = emails.split(',');
639 var result = true; 647 var result = true;
640 arr.forEach(function(email) { 648 arr.forEach(function(email) {
641 var val = String(email).trim().toLowerCase(); 649 var val = String(email).trim().toLowerCase();
642 if (!re.test(val)) result = false; 650 if (!re.test(val)) result = false;
643 }); 651 });
644 return result; 652 return result;
645 } 653 }
646 } 654 }
647 ]); 655 ]);