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