Commit afb7c9e6e6d4d5d682d0bd54922ce5a33eaf1d68

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

Arreglo de Alertas

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