Commit 50d4da8057a068bfff3b830c4e0c7f759514dd6c

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

Elimino log

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