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