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