Commit eeb26b5e5be567ae9679e2c6f951d69ecd6f3d83

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

Merge remote-tracking branch 'upstream/develop'

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