Commit c524383b8ba5ee55892db3e4a36e530f28f2bc59

Authored by Luigi
1 parent 2aeb5fc11d
Exists in master

Alerta en el campo CUIT - Cambio en Seleccionar TipoFactura

Showing 1 changed file with 25 additions and 38 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 if ($scope.cliente.iva.ID == 1) { 328 if ($scope.cliente.iva.ID == 1) {
328 var datos = [ 329 datos = [
329 { 330 {
330 id: 'A', 331 id: 'A',
331 nombre: 'Factura A' 332 nombre: 'Factura A'
332 }, 333 },
333 { 334 {
334 id: 'M', 335 id: 'M',
335 nombre: 'Factura M' 336 nombre: 'Factura M'
336 }, 337 },
337 { 338 {
338 id: 'R', 339 id: 'R',
339 nombre: 'Remito' 340 nombre: 'Remito'
340 } 341 }
341 ]; 342 ];
342 focaModalService.modal({ 343
343 titulo: 'Seleccionar Factura', 344 } else {
344 data: datos, 345 datos = [
345 size: 'md',
346 columnas: [
347 {
348 propiedad: 'id',
349 nombre: 'Codigo'
350 },
351 {
352 propiedad: 'nombre',
353 nombre: 'Factura'
354 }
355 ],
356 }).then(function(res) {
357 $scope.cliente.tipoFactura.NOMBRE = res.nombre;
358 });
359 } else if ($scope.cliente.iva.ID == 3 || $scope.cliente.iva.ID == 4 || $scope.cliente.iva.ID == 5) {
360 var datos2 = [
361 { 346 {
362 id: 'B', 347 id: 'B',
363 nombre: 'Factura B' 348 nombre: 'Factura B'
364 }, 349 },
365 { 350 {
366 id: 'R', 351 id: 'R',
367 nombre: 'Remito' 352 nombre: 'Remito'
368 } 353 }
369 ]; 354 ];
370 focaModalService.modal({
371 titulo: 'Seleccionar Factura',
372 data: datos2,
373 size: 'md',
374 columnas: [
375 {
376 propiedad: 'id',
377 nombre: 'Codigo'
378 },
379 {
380 propiedad: 'nombre',
381 nombre: 'Factura'
382 }
383 ],
384 }).then(function(res) {
385 $scope.cliente.tipoFactura.NOMBRE = res.nombre;
386 });
387 } 355 }
356 focaModalService.modal({
357 titulo: 'Seleccionar Factura',
358 data: datos,
359 size: 'md',
360 columnas: [
361 {
362 propiedad: 'id',
363 nombre: 'Codigo'
364 },
365 {
366 propiedad: 'nombre',
367 nombre: 'Factura'
368 }
369 ],
370 }).then(function(res) {
371 $scope.cliente.tipoFactura.NOMBRE = res.nombre;
372 });
388 } 373 }
389 }; 374 };
390 $scope.seleccionarTipoComprobante = function(key) { 375 $scope.seleccionarTipoComprobante = function(key) {
391 if (key === 13) { 376 if (key === 13) {
392 var parametrosModal = { 377 var parametrosModal = {
393 query: '/tipo-comprobante', 378 query: '/tipo-comprobante',
394 columnas: [ 379 columnas: [
395 { 380 {
396 propiedad: 'ID', 381 propiedad: 'ID',
397 nombre: 'Código' 382 nombre: 'Código'
398 }, 383 },
399 { 384 {
400 propiedad: 'NOMBRE', 385 propiedad: 'NOMBRE',
401 nombre: 'Nombre' 386 nombre: 'Nombre'
402 } 387 }
403 ], 388 ],
404 titulo: 'Búsqueda de tipos de comprobante', 389 titulo: 'Búsqueda de tipos de comprobante',
405 size: 'md' 390 size: 'md'
406 }; 391 };
407 focaModalService.modal(parametrosModal).then( 392 focaModalService.modal(parametrosModal).then(
408 function(tipoComprobante) { 393 function(tipoComprobante) {
409 $scope.cliente.tipoComprobante = tipoComprobante; 394 $scope.cliente.tipoComprobante = tipoComprobante;
410 $timeout(function() { 395 $timeout(function() {
411 $scope.focused = 17; 396 $scope.focused = 17;
412 }); 397 });
413 }, function() { 398 }, function() {
414 // funcion ejecutada cuando se cancela el modal 399 // funcion ejecutada cuando se cancela el modal
415 }); 400 });
416 } 401 }
417 }; 402 };
418 $scope.seleccionarFormaPago = function(key) { 403 $scope.seleccionarFormaPago = function(key) {
419 if (key === 13) { 404 if (key === 13) {
420 var parametrosModal = { 405 var parametrosModal = {
421 query: '/forma-pago', 406 query: '/forma-pago',
422 columnas: [ 407 columnas: [
423 { 408 {
424 propiedad: 'ID', 409 propiedad: 'ID',
425 nombre: 'Código', 410 nombre: 'Código',
426 filtro: { 411 filtro: {
427 nombre: 'rellenarDigitos', 412 nombre: 'rellenarDigitos',
428 parametro: 3 413 parametro: 3
429 } 414 }
430 }, 415 },
431 { 416 {
432 propiedad: 'NOMBRE', 417 propiedad: 'NOMBRE',
433 nombre: 'Nombre' 418 nombre: 'Nombre'
434 } 419 }
435 ], 420 ],
436 titulo: 'Búsqueda de formas de pago', 421 titulo: 'Búsqueda de formas de pago',
437 size: 'md' 422 size: 'md'
438 }; 423 };
439 focaModalService.modal(parametrosModal).then( 424 focaModalService.modal(parametrosModal).then(
440 function(formaPago) { 425 function(formaPago) {
441 $scope.cliente.formaPago = formaPago; 426 $scope.cliente.formaPago = formaPago;
442 }, function() { 427 }, function() {
443 // funcion ejecutada cuando se cancela el modal 428 // funcion ejecutada cuando se cancela el modal
444 }); 429 });
445 } 430 }
446 }; 431 };
447 $scope.seleccionarCobrador = function(key) { 432 $scope.seleccionarCobrador = function(key) {
448 if (key === 13) { 433 if (key === 13) {
449 var parametrosModal = { 434 var parametrosModal = {
450 query: '/cobrador', 435 query: '/cobrador',
451 columnas: [ 436 columnas: [
452 { 437 {
453 propiedad: 'NUM', 438 propiedad: 'NUM',
454 nombre: 'Código' 439 nombre: 'Código'
455 }, 440 },
456 { 441 {
457 propiedad: 'NOM', 442 propiedad: 'NOM',
458 nombre: 'Nombre' 443 nombre: 'Nombre'
459 } 444 }
460 ], 445 ],
461 titulo: 'Búsqueda de cobradores', 446 titulo: 'Búsqueda de cobradores',
462 size: 'md' 447 size: 'md'
463 }; 448 };
464 focaModalService.modal(parametrosModal).then( 449 focaModalService.modal(parametrosModal).then(
465 function(cobrador) { 450 function(cobrador) {
466 $scope.cliente.cobrador = cobrador; 451 $scope.cliente.cobrador = cobrador;
467 }, function() { 452 }, function() {
468 // funcion ejecutada cuando se cancela el modal 453 // funcion ejecutada cuando se cancela el modal
469 }); 454 });
470 } 455 }
471 }; 456 };
472 457
473 $scope.pasarCampoCuit = function(numeroCuit) { 458 $scope.pasarCampoCuit = function(numeroCuit) {
474 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { 459 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) {
475 $scope.cuitActivo = 2; 460 $scope.cuitActivo = 2;
476 } else if ( numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { 461 } else if ( numeroCuit === 2 && $scope.cliente.cuit2.length === 8) {
477 $scope.cuitActivo = 3; 462 $scope.cuitActivo = 3;
478 } 463 }
479 }; 464 };
480 465
481 $scope.guardar = function() { 466 $scope.guardar = function() {
482 if (!$scope.cliente.NOM) { 467 if (!$scope.cliente.NOM) {
483 focaModalService.alert('Ingrese Nombre'); 468 focaModalService.alert('Ingrese Nombre');
484 return; 469 return;
485 } else if (!$scope.cliente.CPO) { 470 } else if (!$scope.cliente.CPO) {
486 focaModalService.alert('Ingrese Codigo Postal'); 471 focaModalService.alert('Ingrese Codigo Postal');
487 return; 472 return;
488 } else if (!$scope.cliente.provincia.NOMBRE) { 473 } else if (!$scope.cliente.provincia.NOMBRE) {
489 focaModalService.alert('Seleccione una provincia'); 474 focaModalService.alert('Seleccione una provincia');
490 return; 475 return;
491 } else if (!$scope.cliente.DOM) { 476 } else if (!$scope.cliente.DOM) {
492 focaModalService.alert('Ingrese Domicilio'); 477 focaModalService.alert('Ingrese Domicilio');
493 return; 478 return;
494 } else if (!$scope.cliente.localidad.NOMBRE) { 479 } else if (!$scope.cliente.localidad.NOMBRE) {
495 focaModalService.alert('Seleccione una localidad'); 480 focaModalService.alert('Seleccione una localidad');
496 return; 481 return;
497 } else if (!$scope.cliente.zona.NOM) { 482 } else if (!$scope.cliente.zona.NOM) {
498 focaModalService.alert('Seleccione una zona'); 483 focaModalService.alert('Seleccione una zona');
499 return; 484 return;
500 } else if (!$scope.cliente.actividad.NOM) { 485 } else if (!$scope.cliente.actividad.NOM) {
501 focaModalService.alert('Seleccione actividad'); 486 focaModalService.alert('Seleccione actividad');
502 return; 487 return;
503 } else if (!$scope.cliente.cobrador.NUM) { 488 } else if (!$scope.cliente.cobrador.NUM) {
504 focaModalService.alert('Seleccione un cobrador'); 489 focaModalService.alert('Seleccione un cobrador');
505 return; 490 return;
506 } else if (!$scope.cliente.TEL) { 491 } else if (!$scope.cliente.TEL) {
507 focaModalService.alert('Ingrese un numero de telefono'); 492 focaModalService.alert('Ingrese un numero de telefono');
508 return; 493 return;
509 } else if (!$scope.cliente.iva.NOMBRE) { 494 } else if (!$scope.cliente.iva.NOMBRE) {
510 focaModalService.alert('Seleccione responsabilidad ante el IVA'); 495 focaModalService.alert('Seleccione responsabilidad ante el IVA');
511 return; 496 return;
512 } else if (!$scope.cliente.tipoFactura.NOMBRE) { 497 } else if (!$scope.cliente.tipoFactura.NOMBRE) {
513 focaModalService.alert('Seleccione tipo de Factura'); 498 focaModalService.alert('Seleccione tipo de Factura');
514 return; 499 return;
515 } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) { 500 } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) {
516 focaModalService.alert('Ingresar CUIT'); 501 focaModalService.alert('Ingresar CUIT');
517 return; 502 return;
503 } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3){
504 focaModalService.alert('Cuit Incompleto');
505 return;
518 } 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) ) {
519 focaModalService.alert('Debe ingresar CUIT con formato: XX-XXXXXXXX-X'); 507 focaModalService.alert('Debe ingresar CUIT con formato: XX-XXXXXXXX-X');
520 return; 508 return;
521 } else if (!$scope.cliente.tipoComprobante.NOMBRE) { 509 } else if (!$scope.cliente.tipoComprobante.NOMBRE) {
522 focaModalService.alert('Seleccione un Comprobante'); 510 focaModalService.alert('Seleccione un Comprobante');
523 return; 511 return;
524 } else if (!$scope.cliente.formaPago.NOMBRE) { 512 } else if (!$scope.cliente.formaPago.NOMBRE) {
525 focaModalService.alert('Seleccione una forma de pago'); 513 focaModalService.alert('Seleccione una forma de pago');
526 return; 514 return;
527 } 515 }
528 516
529
530 var cliente = crearCopia(); 517 var cliente = crearCopia();
531 518
532 focaBusquedaClienteService 519 focaBusquedaClienteService
533 .guardarCliente(cliente) 520 .guardarCliente(cliente)
534 .then(function(res) { 521 .then(function(res) {
535 var cliente = { 522 var cliente = {
536 cod: res.data.COD, 523 cod: res.data.COD,
537 cuit: res.data.CUIT, 524 cuit: res.data.CUIT,
538 esNuevo: res.data.esNuevo, 525 esNuevo: res.data.esNuevo,
539 nom: res.data.NOM 526 nom: res.data.NOM
540 }; 527 };
541 $scope.select(cliente, true); 528 $scope.select(cliente, true);
542 }); 529 });
543 }; 530 };
544 531
545 function crearCopia(){ 532 function crearCopia(){
546 var cliente = angular.copy($scope.cliente); 533 var cliente = angular.copy($scope.cliente);
547 534
548 cliente.PCX = cliente.provincia.ID; 535 cliente.PCX = cliente.provincia.ID;
549 cliente.LOX = cliente.localidad.ID; 536 cliente.LOX = cliente.localidad.ID;
550 cliente.IVA = cliente.iva.ID; 537 cliente.IVA = cliente.iva.ID;
551 cliente.ACT = cliente.actividad.ID; 538 cliente.ACT = cliente.actividad.ID;
552 cliente.ZON = cliente.zona.ID; 539 cliente.ZON = cliente.zona.ID;
553 cliente.TIP = cliente.tipoFactura.ID; 540 cliente.TIP = cliente.tipoFactura.ID;
554 cliente.TCO = cliente.tipoComprobante.ID; 541 cliente.TCO = cliente.tipoComprobante.ID;
555 cliente.FPA = cliente.formaPago.ID; 542 cliente.FPA = cliente.formaPago.ID;
556 cliente.VEN = vendedor.ID; 543 cliente.VEN = vendedor.ID;
557 cliente.CUIT = cliente.cuit1 + cliente.cuit2 + cliente.cuit3; 544 cliente.CUIT = cliente.cuit1 + cliente.cuit2 + cliente.cuit3;
558 cliente.idCobrador = cliente.cobrador.ID; 545 cliente.idCobrador = cliente.cobrador.ID;
559 546
560 delete cliente.provincia; 547 delete cliente.provincia;
561 delete cliente.localidad; 548 delete cliente.localidad;
562 delete cliente.iva; 549 delete cliente.iva;
563 delete cliente.actividad; 550 delete cliente.actividad;
564 delete cliente.zona; 551 delete cliente.zona;
565 delete cliente.tipoFactura; 552 delete cliente.tipoFactura;
566 delete cliente.tipoComprobante; 553 delete cliente.tipoComprobante;
567 delete cliente.formaPago; 554 delete cliente.formaPago;
568 delete cliente.cobrador; 555 delete cliente.cobrador;
569 delete cliente.cuit1; 556 delete cliente.cuit1;
570 delete cliente.cuit2; 557 delete cliente.cuit2;
571 delete cliente.cuit3; 558 delete cliente.cuit3;
572 559
573 return cliente; 560 return cliente;
574 } 561 }
575 562
576 function calcularPages(paginaActual) { 563 function calcularPages(paginaActual) {
577 var paginas = []; 564 var paginas = [];
578 paginas.push(paginaActual); 565 paginas.push(paginaActual);
579 566
580 if (paginaActual - 1 > 1) { 567 if (paginaActual - 1 > 1) {
581 568
582 paginas.unshift(paginaActual - 1); 569 paginas.unshift(paginaActual - 1);
583 if (paginaActual - 2 > 1) { 570 if (paginaActual - 2 > 1) {
584 paginas.unshift(paginaActual - 2); 571 paginas.unshift(paginaActual - 2);
585 } 572 }
586 } 573 }
587 574
588 if (paginaActual + 1 < $scope.lastPage) { 575 if (paginaActual + 1 < $scope.lastPage) {
589 paginas.push(paginaActual + 1); 576 paginas.push(paginaActual + 1);
590 if (paginaActual + 2 < $scope.lastPage) { 577 if (paginaActual + 2 < $scope.lastPage) {
591 paginas.push(paginaActual + 2); 578 paginas.push(paginaActual + 2);
592 } 579 }
593 } 580 }
594 581
595 if (paginaActual !== 1) { 582 if (paginaActual !== 1) {
596 paginas.unshift(1); 583 paginas.unshift(1);
597 } 584 }
598 585
599 if (paginaActual !== $scope.lastPage) { 586 if (paginaActual !== $scope.lastPage) {
600 paginas.push($scope.lastPage); 587 paginas.push($scope.lastPage);
601 } 588 }
602 589
603 return paginas; 590 return paginas;
604 } 591 }
605 592
606 function primera() { 593 function primera() {
607 $scope.selectedClientes = 0; 594 $scope.selectedClientes = 0;
608 } 595 }
609 596
610 function anterior() { 597 function anterior() {
611 if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { 598 if ($scope.selectedClientes === 0 && $scope.currentPage > 1) {
612 retrocederPagina(); 599 retrocederPagina();
613 } else { 600 } else {
614 $scope.selectedClientes--; 601 $scope.selectedClientes--;
615 } 602 }
616 } 603 }
617 604
618 function siguiente() { 605 function siguiente() {
619 if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { 606 if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) {
620 $scope.selectedClientes++; 607 $scope.selectedClientes++;
621 } else { 608 } else {