Commit dee39a54a91b2a75efaa050c112bd573dadf942b
1 parent
a724e4b4c7
Exists in
master
and in
1 other branch
Limpiar localidad al seleccionar una nueva provincia
Showing
1 changed file
with
2 additions
and
0 deletions
Show diff stats
src/js/controllerCliente.js
| 1 | angular.module('focaAbmCliente') | 1 | angular.module('focaAbmCliente') |
| 2 | .controller('focaModalClienteController', [ | 2 | .controller('focaModalClienteController', [ |
| 3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', | 3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', |
| 4 | 'focaAbmClienteService', 'idCliente', | 4 | 'focaAbmClienteService', 'idCliente', |
| 5 | function ($scope, $timeout, $uibModalInstance, focaModalService, | 5 | function ($scope, $timeout, $uibModalInstance, focaModalService, |
| 6 | focaAbmClienteService, idCliente) { | 6 | focaAbmClienteService, idCliente) { |
| 7 | $scope.cliente = { | 7 | $scope.cliente = { |
| 8 | provincia: {}, | 8 | provincia: {}, |
| 9 | localidad: {}, | 9 | localidad: {}, |
| 10 | zona: {}, | 10 | zona: {}, |
| 11 | actividad: {}, | 11 | actividad: {}, |
| 12 | cobrador: {}, | 12 | cobrador: {}, |
| 13 | vendedor: {}, | 13 | vendedor: {}, |
| 14 | iva: {}, | 14 | iva: {}, |
| 15 | tipoFactura: {}, | 15 | tipoFactura: {}, |
| 16 | tipoComprobante: {}, | 16 | tipoComprobante: {}, |
| 17 | formaPago: {} | 17 | formaPago: {} |
| 18 | }; | 18 | }; |
| 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.vendedor = {}; | 20 | $scope.vendedor = {}; |
| 21 | 21 | ||
| 22 | focaAbmClienteService.obtenerClientePorCodigo(idCliente) | 22 | focaAbmClienteService.obtenerClientePorCodigo(idCliente) |
| 23 | .then(function (res) { | 23 | .then(function (res) { |
| 24 | var data = res.data[0]; | 24 | var data = res.data[0]; |
| 25 | $scope.cliente.codigo = data.COD; | 25 | $scope.cliente.codigo = data.COD; |
| 26 | $scope.cliente.DOM = data.DOM; | 26 | $scope.cliente.DOM = data.DOM; |
| 27 | $scope.cliente.NOM = data.NOM; | 27 | $scope.cliente.NOM = data.NOM; |
| 28 | $scope.cliente.CPO = data.CPO; | 28 | $scope.cliente.CPO = data.CPO; |
| 29 | $scope.cliente.provincia.ID = data.PCX; | 29 | $scope.cliente.provincia.ID = data.PCX; |
| 30 | $scope.cliente.provincia.NOMBRE = data.PCI; | 30 | $scope.cliente.provincia.NOMBRE = data.PCI; |
| 31 | $scope.cliente.localidad.ID = data.LOX; | 31 | $scope.cliente.localidad.ID = data.LOX; |
| 32 | $scope.cliente.localidad.NOMBRE = data.LOC; | 32 | $scope.cliente.localidad.NOMBRE = data.LOC; |
| 33 | $scope.cliente.zona.ID = data.zona.ID; | 33 | $scope.cliente.zona.ID = data.zona.ID; |
| 34 | $scope.cliente.zona.NOM = data.zona.NOM; | 34 | $scope.cliente.zona.NOM = data.zona.NOM; |
| 35 | $scope.cliente.actividad.NOM = data.actividad.NOM; | 35 | $scope.cliente.actividad.NOM = data.actividad.NOM; |
| 36 | $scope.cliente.actividad.ID = data.actividad.ID; | 36 | $scope.cliente.actividad.ID = data.actividad.ID; |
| 37 | $scope.cliente.cobrador.NOM = data.cobrador ? data.cobrador.NOM : ''; | 37 | $scope.cliente.cobrador.NOM = data.cobrador ? data.cobrador.NOM : ''; |
| 38 | $scope.cliente.cobrador.NUM = data.cobrador ? data.cobrador.NUM : undefined; | 38 | $scope.cliente.cobrador.NUM = data.cobrador ? data.cobrador.NUM : undefined; |
| 39 | $scope.cliente.cobrador.ID = data.cobrador ? data.cobrador.id : undefined; | 39 | $scope.cliente.cobrador.ID = data.cobrador ? data.cobrador.id : undefined; |
| 40 | $scope.vendedor.NOM = data.vendedor.NOM; | 40 | $scope.vendedor.NOM = data.vendedor.NOM; |
| 41 | $scope.vendedor.id = data.vendedor.id; | 41 | $scope.vendedor.id = data.vendedor.id; |
| 42 | $scope.cliente.MAIL = data.MAIL; | 42 | $scope.cliente.MAIL = data.MAIL; |
| 43 | $scope.cliente.TEL = data.TEL; | 43 | $scope.cliente.TEL = data.TEL; |
| 44 | $scope.cliente.iva.NOMBRE = data.iva.NOMBRE; | 44 | $scope.cliente.iva.NOMBRE = data.iva.NOMBRE; |
| 45 | $scope.cliente.tipoFactura.NOMBRE = data.tipoFactura.NOMBRE; | 45 | $scope.cliente.tipoFactura.NOMBRE = data.tipoFactura.NOMBRE; |
| 46 | $scope.cliente.tipoFactura.ID = data.tipoFactura.ID; | 46 | $scope.cliente.tipoFactura.ID = data.tipoFactura.ID; |
| 47 | var cuit = data.CUIT.split('-'); | 47 | var cuit = data.CUIT.split('-'); |
| 48 | $scope.cliente.cuit1 = cuit[0]; | 48 | $scope.cliente.cuit1 = cuit[0]; |
| 49 | $scope.cliente.cuit2 = cuit[1]; | 49 | $scope.cliente.cuit2 = cuit[1]; |
| 50 | $scope.cliente.cuit3 = cuit[2]; | 50 | $scope.cliente.cuit3 = cuit[2]; |
| 51 | $scope.cliente.tipoComprobante.NOMBRE = data.tipoComprobante.NOMBRE; | 51 | $scope.cliente.tipoComprobante.NOMBRE = data.tipoComprobante.NOMBRE; |
| 52 | $scope.cliente.tipoComprobante.ID = data.tipoComprobante.ID; | 52 | $scope.cliente.tipoComprobante.ID = data.tipoComprobante.ID; |
| 53 | $scope.cliente.formaPago.NOMBRE = data.formaPago.NOMBRE; | 53 | $scope.cliente.formaPago.NOMBRE = data.formaPago.NOMBRE; |
| 54 | $scope.cliente.formaPago.ID = data.formaPago.ID; | 54 | $scope.cliente.formaPago.ID = data.formaPago.ID; |
| 55 | $scope.cliente.ES_PROS = data.ES_PROS; | 55 | $scope.cliente.ES_PROS = data.ES_PROS; |
| 56 | $scope.cliente.ES_MAY = data.ES_MAY; | 56 | $scope.cliente.ES_MAY = data.ES_MAY; |
| 57 | $scope.editando = true; | 57 | $scope.editando = true; |
| 58 | }) | 58 | }) |
| 59 | .catch(function (e) { console.log(e); }); | 59 | .catch(function (e) { console.log(e); }); |
| 60 | 60 | ||
| 61 | $scope.cancel = function () { | 61 | $scope.cancel = function () { |
| 62 | $uibModalInstance.dismiss('cancel'); | 62 | $uibModalInstance.dismiss('cancel'); |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | $scope.guardar = function () { | 65 | $scope.guardar = function () { |
| 66 | if (!$scope.cliente.NOM) { | 66 | if (!$scope.cliente.NOM) { |
| 67 | focaModalService.alert('Ingrese Nombre'); | 67 | focaModalService.alert('Ingrese Nombre'); |
| 68 | return; | 68 | return; |
| 69 | } else if (!$scope.cliente.CPO) { | 69 | } else if (!$scope.cliente.CPO) { |
| 70 | focaModalService.alert('Ingrese Codigo Postal'); | 70 | focaModalService.alert('Ingrese Codigo Postal'); |
| 71 | return; | 71 | return; |
| 72 | } else if (!$scope.cliente.provincia.NOMBRE) { | 72 | } else if (!$scope.cliente.provincia.NOMBRE) { |
| 73 | focaModalService.alert('Seleccione una provincia'); | 73 | focaModalService.alert('Seleccione una provincia'); |
| 74 | return; | 74 | return; |
| 75 | } else if (!$scope.cliente.DOM) { | 75 | } else if (!$scope.cliente.DOM) { |
| 76 | focaModalService.alert('Ingrese Domicilio'); | 76 | focaModalService.alert('Ingrese Domicilio'); |
| 77 | return; | 77 | return; |
| 78 | } else if (!$scope.cliente.localidad.NOMBRE) { | 78 | } else if (!$scope.cliente.localidad.NOMBRE) { |
| 79 | focaModalService.alert('Seleccione una localidad'); | 79 | focaModalService.alert('Seleccione una localidad'); |
| 80 | return; | 80 | return; |
| 81 | } else if (!$scope.cliente.zona.NOM) { | 81 | } else if (!$scope.cliente.zona.NOM) { |
| 82 | focaModalService.alert('Seleccione una zona'); | 82 | focaModalService.alert('Seleccione una zona'); |
| 83 | return; | 83 | return; |
| 84 | } else if (!$scope.cliente.actividad.NOM) { | 84 | } else if (!$scope.cliente.actividad.NOM) { |
| 85 | focaModalService.alert('Seleccione actividad'); | 85 | focaModalService.alert('Seleccione actividad'); |
| 86 | return; | 86 | return; |
| 87 | } else if (!$scope.cliente.cobrador.NUM) { | 87 | } else if (!$scope.cliente.cobrador.NUM) { |
| 88 | focaModalService.alert('Seleccione un cobrador'); | 88 | focaModalService.alert('Seleccione un cobrador'); |
| 89 | return; | 89 | return; |
| 90 | } else if (!$scope.vendedor.NOM) { | 90 | } else if (!$scope.vendedor.NOM) { |
| 91 | focaModalService.alert('Seleccione un vendedor'); | 91 | focaModalService.alert('Seleccione un vendedor'); |
| 92 | return; | 92 | return; |
| 93 | } else if ($scope.cliente.MAIL && !validateEmails($scope.cliente.MAIL)) { | 93 | } else if ($scope.cliente.MAIL && !validateEmails($scope.cliente.MAIL)) { |
| 94 | focaModalService.alert('Ingrese un formato de email válido'); | 94 | focaModalService.alert('Ingrese un formato de email válido'); |
| 95 | return; | 95 | return; |
| 96 | } else if (!$scope.cliente.TEL) { | 96 | } else if (!$scope.cliente.TEL) { |
| 97 | focaModalService.alert('Ingrese un numero de telefono'); | 97 | focaModalService.alert('Ingrese un numero de telefono'); |
| 98 | return; | 98 | return; |
| 99 | } else if (!$scope.cliente.iva.NOMBRE) { | 99 | } else if (!$scope.cliente.iva.NOMBRE) { |
| 100 | focaModalService.alert('Seleccione responsabilidad ante el IVA'); | 100 | focaModalService.alert('Seleccione responsabilidad ante el IVA'); |
| 101 | return; | 101 | return; |
| 102 | } else if (!$scope.cliente.tipoFactura.NOMBRE) { | 102 | } else if (!$scope.cliente.tipoFactura.NOMBRE) { |
| 103 | focaModalService.alert('Seleccione tipo de Factura'); | 103 | focaModalService.alert('Seleccione tipo de Factura'); |
| 104 | return; | 104 | return; |
| 105 | } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) { | 105 | } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) { |
| 106 | focaModalService.alert('Ingrese CUIT'); | 106 | focaModalService.alert('Ingrese CUIT'); |
| 107 | return; | 107 | return; |
| 108 | } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3) { | 108 | } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3) { |
| 109 | focaModalService.alert('Ingrese CUIT válido'); | 109 | focaModalService.alert('Ingrese CUIT válido'); |
| 110 | return; | 110 | return; |
| 111 | } else if (!$scope.regexCuit.test($scope.cliente.cuit1 + $scope.cliente.cuit2 + $scope.cliente.cuit3)) { | 111 | } else if (!$scope.regexCuit.test($scope.cliente.cuit1 + $scope.cliente.cuit2 + $scope.cliente.cuit3)) { |
| 112 | focaModalService.alert('Ingrese CUIT con formato: XX-XXXXXXXX-X'); | 112 | focaModalService.alert('Ingrese CUIT con formato: XX-XXXXXXXX-X'); |
| 113 | return; | 113 | return; |
| 114 | } else if (!$scope.cliente.tipoComprobante.NOMBRE) { | 114 | } else if (!$scope.cliente.tipoComprobante.NOMBRE) { |
| 115 | focaModalService.alert('Seleccione un Comprobante'); | 115 | focaModalService.alert('Seleccione un Comprobante'); |
| 116 | return; | 116 | return; |
| 117 | } else if (!$scope.cliente.formaPago.NOMBRE) { | 117 | } else if (!$scope.cliente.formaPago.NOMBRE) { |
| 118 | focaModalService.alert('Seleccione una forma de pago'); | 118 | focaModalService.alert('Seleccione una forma de pago'); |
| 119 | return; | 119 | return; |
| 120 | } | 120 | } |
| 121 | $scope.cliente.actividad.ID = parseInt($scope.cliente.actividad.ID); | 121 | $scope.cliente.actividad.ID = parseInt($scope.cliente.actividad.ID); |
| 122 | var cliente = crearCopia(); | 122 | var cliente = crearCopia(); |
| 123 | focaAbmClienteService | 123 | focaAbmClienteService |
| 124 | .guardarCliente(cliente) | 124 | .guardarCliente(cliente) |
| 125 | .then(function () { | 125 | .then(function () { |
| 126 | $uibModalInstance.close(cliente); | 126 | $uibModalInstance.close(cliente); |
| 127 | }) | 127 | }) |
| 128 | .catch(function (e) { | 128 | .catch(function (e) { |
| 129 | console.log(e); | 129 | console.log(e); |
| 130 | }); | 130 | }); |
| 131 | }; | 131 | }; |
| 132 | $scope.seleccionarProvincia = function (key) { | 132 | $scope.seleccionarProvincia = function (key) { |
| 133 | if (key === 13) { | 133 | if (key === 13) { |
| 134 | var parametrosModal = { | 134 | var parametrosModal = { |
| 135 | searchText: $scope.cliente.provincia.NOMBRE, | 135 | searchText: $scope.cliente.provincia.NOMBRE, |
| 136 | query: '/provincia', | 136 | query: '/provincia', |
| 137 | columnas: [ | 137 | columnas: [ |
| 138 | { | 138 | { |
| 139 | propiedad: 'ID', | 139 | propiedad: 'ID', |
| 140 | nombre: 'Codigo', | 140 | nombre: 'Codigo', |
| 141 | filtro: { | 141 | filtro: { |
| 142 | nombre: 'rellenarDigitos', | 142 | nombre: 'rellenarDigitos', |
| 143 | parametro: 3 | 143 | parametro: 3 |
| 144 | } | 144 | } |
| 145 | }, | 145 | }, |
| 146 | { | 146 | { |
| 147 | propiedad: 'NOMBRE', | 147 | propiedad: 'NOMBRE', |
| 148 | nombre: 'Nombre' | 148 | nombre: 'Nombre' |
| 149 | } | 149 | } |
| 150 | ], | 150 | ], |
| 151 | titulo: 'Búsqueda de provincias', | 151 | titulo: 'Búsqueda de provincias', |
| 152 | size: 'md' | 152 | size: 'md' |
| 153 | }; | 153 | }; |
| 154 | focaModalService.modal(parametrosModal).then(function (provincia) { | 154 | focaModalService.modal(parametrosModal).then(function (provincia) { |
| 155 | $scope.cliente.provincia = provincia; | 155 | $scope.cliente.provincia = provincia; |
| 156 | $scope.cliente.localidad.NOMBRE = ''; | ||
| 157 | |||
| 156 | $timeout(function () { | 158 | $timeout(function () { |
| 157 | $scope.focused = 4; | 159 | $scope.focused = 4; |
| 158 | }); | 160 | }); |
| 159 | }, function () { | 161 | }, function () { |
| 160 | //TODO: función llamada cuando cancela el modal | 162 | //TODO: función llamada cuando cancela el modal |
| 161 | }); | 163 | }); |
| 162 | } | 164 | } |
| 163 | }; | 165 | }; |
| 164 | $scope.seleccionarLocalidad = function (key) { | 166 | $scope.seleccionarLocalidad = function (key) { |
| 165 | if ($scope.cliente.provincia.ID === undefined) { | 167 | if ($scope.cliente.provincia.ID === undefined) { |
| 166 | focaModalService.alert('Seleccione una provincia'); | 168 | focaModalService.alert('Seleccione una provincia'); |
| 167 | return; | 169 | return; |
| 168 | } | 170 | } |
| 169 | if (key === 13) { | 171 | if (key === 13) { |
| 170 | var parametrosModal = { | 172 | var parametrosModal = { |
| 171 | searchText: $scope.cliente.localidad.NOMBRE, | 173 | searchText: $scope.cliente.localidad.NOMBRE, |
| 172 | query: '/localidad/' + parseInt($scope.cliente.provincia.ID), | 174 | query: '/localidad/' + parseInt($scope.cliente.provincia.ID), |
| 173 | columnas: [ | 175 | columnas: [ |
| 174 | { | 176 | { |
| 175 | propiedad: 'ID', | 177 | propiedad: 'ID', |
| 176 | nombre: 'Código', | 178 | nombre: 'Código', |
| 177 | }, | 179 | }, |
| 178 | { | 180 | { |
| 179 | propiedad: 'NOMBRE', | 181 | propiedad: 'NOMBRE', |
| 180 | nombre: 'Nombre' | 182 | nombre: 'Nombre' |
| 181 | } | 183 | } |
| 182 | ], | 184 | ], |
| 183 | titulo: 'Búsqueda de localidades', | 185 | titulo: 'Búsqueda de localidades', |
| 184 | size: 'md' | 186 | size: 'md' |
| 185 | }; | 187 | }; |
| 186 | focaModalService.modal(parametrosModal).then(function (localidad) { | 188 | focaModalService.modal(parametrosModal).then(function (localidad) { |
| 187 | $scope.cliente.localidad = localidad; | 189 | $scope.cliente.localidad = localidad; |
| 188 | $timeout(function () { | 190 | $timeout(function () { |
| 189 | $scope.focused = 5; | 191 | $scope.focused = 5; |
| 190 | }); | 192 | }); |
| 191 | }, function () { | 193 | }, function () { |
| 192 | //TODO: función llamada cuando cancela el modal | 194 | //TODO: función llamada cuando cancela el modal |
| 193 | }); | 195 | }); |
| 194 | } | 196 | } |
| 195 | }; | 197 | }; |
| 196 | $scope.seleccionarZona = function (key) { | 198 | $scope.seleccionarZona = function (key) { |
| 197 | if (key === 13) { | 199 | if (key === 13) { |
| 198 | var parametrosModal = { | 200 | var parametrosModal = { |
| 199 | searchText: $scope.cliente.zona.NOM, | 201 | searchText: $scope.cliente.zona.NOM, |
| 200 | query: '/zona', | 202 | query: '/zona', |
| 201 | columnas: [ | 203 | columnas: [ |
| 202 | { | 204 | { |
| 203 | propiedad: 'ID', | 205 | propiedad: 'ID', |
| 204 | nombre: 'Código', | 206 | nombre: 'Código', |
| 205 | filtro: { | 207 | filtro: { |
| 206 | nombre: 'rellenarDigitos', | 208 | nombre: 'rellenarDigitos', |
| 207 | parametro: 3 | 209 | parametro: 3 |
| 208 | } | 210 | } |
| 209 | }, | 211 | }, |
| 210 | { | 212 | { |
| 211 | propiedad: 'NOM', | 213 | propiedad: 'NOM', |
| 212 | nombre: 'Nombre' | 214 | nombre: 'Nombre' |
| 213 | } | 215 | } |
| 214 | ], | 216 | ], |
| 215 | titulo: 'Búsqueda de zonas', | 217 | titulo: 'Búsqueda de zonas', |
| 216 | size: 'md' | 218 | size: 'md' |
| 217 | }; | 219 | }; |
| 218 | focaModalService.modal(parametrosModal).then( | 220 | focaModalService.modal(parametrosModal).then( |
| 219 | function (zona) { | 221 | function (zona) { |
| 220 | $scope.cliente.zona = zona; | 222 | $scope.cliente.zona = zona; |
| 221 | $timeout(function () { | 223 | $timeout(function () { |
| 222 | $scope.focused = 6; | 224 | $scope.focused = 6; |
| 223 | }); | 225 | }); |
| 224 | }, function () { | 226 | }, function () { |
| 225 | // funcion ejecutada cuando se cancela el modal | 227 | // funcion ejecutada cuando se cancela el modal |
| 226 | }); | 228 | }); |
| 227 | } | 229 | } |
| 228 | }; | 230 | }; |
| 229 | $scope.seleccionarActividad = function (key) { | 231 | $scope.seleccionarActividad = function (key) { |
| 230 | if (key === 13) { | 232 | if (key === 13) { |
| 231 | var parametrosModal = { | 233 | var parametrosModal = { |
| 232 | searchText: $scope.cliente.actividad.NOM, | 234 | searchText: $scope.cliente.actividad.NOM, |
| 233 | query: '/actividad', | 235 | query: '/actividad', |
| 234 | columnas: [ | 236 | columnas: [ |
| 235 | { | 237 | { |
| 236 | propiedad: 'ID', | 238 | propiedad: 'ID', |
| 237 | nombre: 'Código', | 239 | nombre: 'Código', |
| 238 | filtro: { | 240 | filtro: { |
| 239 | nombre: 'rellenarDigitos', | 241 | nombre: 'rellenarDigitos', |
| 240 | parametro: 3 | 242 | parametro: 3 |
| 241 | } | 243 | } |
| 242 | }, | 244 | }, |
| 243 | { | 245 | { |
| 244 | propiedad: 'NOM', | 246 | propiedad: 'NOM', |
| 245 | nombre: 'Nombre' | 247 | nombre: 'Nombre' |
| 246 | } | 248 | } |
| 247 | ], | 249 | ], |
| 248 | titulo: 'Búsqueda de actividades', | 250 | titulo: 'Búsqueda de actividades', |
| 249 | size: 'md' | 251 | size: 'md' |
| 250 | }; | 252 | }; |
| 251 | focaModalService.modal(parametrosModal).then( | 253 | focaModalService.modal(parametrosModal).then( |
| 252 | function (actividad) { | 254 | function (actividad) { |
| 253 | $scope.cliente.actividad = actividad; | 255 | $scope.cliente.actividad = actividad; |
| 254 | $timeout(function () { | 256 | $timeout(function () { |
| 255 | $scope.focused = 7; | 257 | $scope.focused = 7; |
| 256 | }); | 258 | }); |
| 257 | }, function () { | 259 | }, function () { |
| 258 | // funcion ejecutada cuando se cancela el modal | 260 | // funcion ejecutada cuando se cancela el modal |
| 259 | }); | 261 | }); |
| 260 | } | 262 | } |
| 261 | }; | 263 | }; |
| 262 | $scope.seleccionarCobrador = function (key) { | 264 | $scope.seleccionarCobrador = function (key) { |
| 263 | if (key === 13) { | 265 | if (key === 13) { |
| 264 | var parametrosModal = { | 266 | var parametrosModal = { |
| 265 | searchText: $scope.cliente.cobrador.NOM, | 267 | searchText: $scope.cliente.cobrador.NOM, |
| 266 | query: '/cobrador', | 268 | query: '/cobrador', |
| 267 | columnas: [ | 269 | columnas: [ |
| 268 | { | 270 | { |
| 269 | propiedad: 'NUM', | 271 | propiedad: 'NUM', |
| 270 | nombre: 'Código' | 272 | nombre: 'Código' |
| 271 | }, | 273 | }, |
| 272 | { | 274 | { |
| 273 | propiedad: 'NOM', | 275 | propiedad: 'NOM', |
| 274 | nombre: 'Nombre' | 276 | nombre: 'Nombre' |
| 275 | } | 277 | } |
| 276 | ], | 278 | ], |
| 277 | titulo: 'Búsqueda de cobradores', | 279 | titulo: 'Búsqueda de cobradores', |
| 278 | size: 'md' | 280 | size: 'md' |
| 279 | }; | 281 | }; |
| 280 | focaModalService.modal(parametrosModal).then( | 282 | focaModalService.modal(parametrosModal).then( |
| 281 | function (cobrador) { | 283 | function (cobrador) { |
| 282 | $scope.cliente.cobrador = cobrador; | 284 | $scope.cliente.cobrador = cobrador; |
| 283 | }, function () { | 285 | }, function () { |
| 284 | // funcion ejecutada cuando se cancela el modal | 286 | // funcion ejecutada cuando se cancela el modal |
| 285 | }); | 287 | }); |
| 286 | } | 288 | } |
| 287 | }; | 289 | }; |
| 288 | $scope.seleccionarVendedor = function (key) { | 290 | $scope.seleccionarVendedor = function (key) { |
| 289 | if (key === 13) { | 291 | if (key === 13) { |
| 290 | var parametrosModal = { | 292 | var parametrosModal = { |
| 291 | titulo: 'Búsqueda vendedores', | 293 | titulo: 'Búsqueda vendedores', |
| 292 | query: '/vendedor', | 294 | query: '/vendedor', |
| 293 | columnas: [ | 295 | columnas: [ |
| 294 | { | 296 | { |
| 295 | propiedad: 'NUM', | 297 | propiedad: 'NUM', |
| 296 | nombre: 'Código', | 298 | nombre: 'Código', |
| 297 | filtro: { | 299 | filtro: { |
| 298 | nombre: 'rellenarDigitos', | 300 | nombre: 'rellenarDigitos', |
| 299 | parametro: 3 | 301 | parametro: 3 |
| 300 | } | 302 | } |
| 301 | }, | 303 | }, |
| 302 | { | 304 | { |
| 303 | propiedad: 'NOM', | 305 | propiedad: 'NOM', |
| 304 | nombre: 'Nombre' | 306 | nombre: 'Nombre' |
| 305 | } | 307 | } |
| 306 | ], | 308 | ], |
| 307 | size: 'md' | 309 | size: 'md' |
| 308 | }; | 310 | }; |
| 309 | focaModalService.modal(parametrosModal).then( | 311 | focaModalService.modal(parametrosModal).then( |
| 310 | function (vendedor) { | 312 | function (vendedor) { |
| 311 | $scope.vendedor = vendedor; | 313 | $scope.vendedor = vendedor; |
| 312 | }, function () { | 314 | }, function () { |
| 313 | // funcion ejecutada cuando se cancela el modal | 315 | // funcion ejecutada cuando se cancela el modal |
| 314 | }); | 316 | }); |
| 315 | } | 317 | } |
| 316 | }; | 318 | }; |
| 317 | $scope.seleccionarIva = function (key) { | 319 | $scope.seleccionarIva = function (key) { |
| 318 | if (key === 13) { | 320 | if (key === 13) { |
| 319 | var parametrosModal = { | 321 | var parametrosModal = { |
| 320 | query: '/iva', | 322 | query: '/iva', |
| 321 | searchText: $scope.cliente.iva.NOMBRE, | 323 | searchText: $scope.cliente.iva.NOMBRE, |
| 322 | columnas: [ | 324 | columnas: [ |
| 323 | { | 325 | { |
| 324 | propiedad: 'ID', | 326 | propiedad: 'ID', |
| 325 | nombre: 'Código', | 327 | nombre: 'Código', |
| 326 | filtro: { | 328 | filtro: { |
| 327 | nombre: 'rellenarDigitos', | 329 | nombre: 'rellenarDigitos', |
| 328 | parametro: 3 | 330 | parametro: 3 |
| 329 | } | 331 | } |
| 330 | }, | 332 | }, |
| 331 | { | 333 | { |
| 332 | propiedad: 'NOMBRE', | 334 | propiedad: 'NOMBRE', |
| 333 | nombre: 'Nombre' | 335 | nombre: 'Nombre' |
| 334 | } | 336 | } |
| 335 | ], | 337 | ], |
| 336 | titulo: 'Búsqueda de responsabilidad ante el IVA', | 338 | titulo: 'Búsqueda de responsabilidad ante el IVA', |
| 337 | size: 'md' | 339 | size: 'md' |
| 338 | }; | 340 | }; |
| 339 | focaModalService.modal(parametrosModal).then( | 341 | focaModalService.modal(parametrosModal).then( |
| 340 | function (iva) { | 342 | function (iva) { |
| 341 | if (iva) { | 343 | if (iva) { |
| 342 | delete $scope.cliente.tipoFactura.NOMBRE; | 344 | delete $scope.cliente.tipoFactura.NOMBRE; |
| 343 | } | 345 | } |
| 344 | $scope.cliente.iva = iva; | 346 | $scope.cliente.iva = iva; |
| 345 | $timeout(function () { | 347 | $timeout(function () { |
| 346 | $scope.focused = 12; | 348 | $scope.focused = 12; |
| 347 | }); | 349 | }); |
| 348 | }, function () { | 350 | }, function () { |
| 349 | // funcion ejecutada cuando se cancela el modal | 351 | // funcion ejecutada cuando se cancela el modal |
| 350 | }); | 352 | }); |
| 351 | } | 353 | } |
| 352 | }; | 354 | }; |
| 353 | $scope.seleccionarTipoFactura = function (key) { | 355 | $scope.seleccionarTipoFactura = function (key) { |
| 354 | 356 | ||
| 355 | if ($scope.cliente.iva.NOMBRE == '') { | 357 | if ($scope.cliente.iva.NOMBRE == '') { |
| 356 | focaModalService.alert('Seleccione una responsabilidad ante el IVA'); | 358 | focaModalService.alert('Seleccione una responsabilidad ante el IVA'); |
| 357 | return; | 359 | return; |
| 358 | } | 360 | } |
| 359 | 361 | ||
| 360 | if (key === 13) { | 362 | if (key === 13) { |
| 361 | var datos; | 363 | var datos; |
| 362 | if ($scope.cliente.iva.ID == 1) { | 364 | if ($scope.cliente.iva.ID == 1) { |
| 363 | datos = [ | 365 | datos = [ |
| 364 | { | 366 | { |
| 365 | ID: 'A', | 367 | ID: 'A', |
| 366 | NOMBRE: 'Factura A' | 368 | NOMBRE: 'Factura A' |
| 367 | }, | 369 | }, |
| 368 | { | 370 | { |
| 369 | ID: 'M', | 371 | ID: 'M', |
| 370 | NOMBRE: 'Factura M' | 372 | NOMBRE: 'Factura M' |
| 371 | }, | 373 | }, |
| 372 | { | 374 | { |
| 373 | ID: 'R', | 375 | ID: 'R', |
| 374 | NOMBRE: 'Remito' | 376 | NOMBRE: 'Remito' |
| 375 | } | 377 | } |
| 376 | ]; | 378 | ]; |
| 377 | } else { | 379 | } else { |
| 378 | datos = [ | 380 | datos = [ |
| 379 | { | 381 | { |
| 380 | ID: 'B', | 382 | ID: 'B', |
| 381 | NOMBRE: 'Factura B' | 383 | NOMBRE: 'Factura B' |
| 382 | }, | 384 | }, |
| 383 | { | 385 | { |
| 384 | ID: 'R', | 386 | ID: 'R', |
| 385 | NOMBRE: 'Remito' | 387 | NOMBRE: 'Remito' |
| 386 | } | 388 | } |
| 387 | ]; | 389 | ]; |
| 388 | } | 390 | } |
| 389 | focaModalService.modal({ | 391 | focaModalService.modal({ |
| 390 | titulo: 'Seleccionar Factura', | 392 | titulo: 'Seleccionar Factura', |
| 391 | data: datos, | 393 | data: datos, |
| 392 | size: 'md', | 394 | size: 'md', |
| 393 | columnas: [ | 395 | columnas: [ |
| 394 | { | 396 | { |
| 395 | propiedad: 'ID', | 397 | propiedad: 'ID', |
| 396 | NOMBRE: 'Codigo' | 398 | NOMBRE: 'Codigo' |
| 397 | }, | 399 | }, |
| 398 | { | 400 | { |
| 399 | propiedad: 'NOMBRE', | 401 | propiedad: 'NOMBRE', |
| 400 | NOMBRE: 'Factura' | 402 | NOMBRE: 'Factura' |
| 401 | } | 403 | } |
| 402 | ], | 404 | ], |
| 403 | }).then(function (res) { | 405 | }).then(function (res) { |
| 404 | $scope.cliente.tipoFactura = res; | 406 | $scope.cliente.tipoFactura = res; |
| 405 | }); | 407 | }); |
| 406 | } | 408 | } |
| 407 | }; | 409 | }; |
| 408 | $scope.pasarCampoCuit = function (numeroCuit) { | 410 | $scope.pasarCampoCuit = function (numeroCuit) { |
| 409 | if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { | 411 | if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { |
| 410 | $scope.cuitActivo = 2; | 412 | $scope.cuitActivo = 2; |
| 411 | } else if (numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { | 413 | } else if (numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { |
| 412 | $scope.cuitActivo = 3; | 414 | $scope.cuitActivo = 3; |
| 413 | } | 415 | } |
| 414 | }; | 416 | }; |
| 415 | $scope.seleccionarTipoComprobante = function (key) { | 417 | $scope.seleccionarTipoComprobante = function (key) { |
| 416 | if (key === 13) { | 418 | if (key === 13) { |
| 417 | var parametrosModal = { | 419 | var parametrosModal = { |
| 418 | searchText: $scope.cliente.tipoComprobante.NOMBRE, | 420 | searchText: $scope.cliente.tipoComprobante.NOMBRE, |
| 419 | query: '/tipo-comprobante', | 421 | query: '/tipo-comprobante', |
| 420 | columnas: [ | 422 | columnas: [ |
| 421 | { | 423 | { |
| 422 | propiedad: 'ID', | 424 | propiedad: 'ID', |
| 423 | nombre: 'Código' | 425 | nombre: 'Código' |
| 424 | }, | 426 | }, |
| 425 | { | 427 | { |
| 426 | propiedad: 'NOMBRE', | 428 | propiedad: 'NOMBRE', |
| 427 | nombre: 'Nombre' | 429 | nombre: 'Nombre' |
| 428 | } | 430 | } |
| 429 | ], | 431 | ], |
| 430 | titulo: 'Búsqueda de tipos de comprobante', | 432 | titulo: 'Búsqueda de tipos de comprobante', |
| 431 | size: 'md' | 433 | size: 'md' |
| 432 | }; | 434 | }; |
| 433 | focaModalService.modal(parametrosModal).then( | 435 | focaModalService.modal(parametrosModal).then( |
| 434 | function (tipoComprobante) { | 436 | function (tipoComprobante) { |
| 435 | $scope.cliente.tipoComprobante = tipoComprobante; | 437 | $scope.cliente.tipoComprobante = tipoComprobante; |
| 436 | $timeout(function () { | 438 | $timeout(function () { |
| 437 | $scope.focused = 17; | 439 | $scope.focused = 17; |
| 438 | }); | 440 | }); |
| 439 | }, function () { | 441 | }, function () { |
| 440 | // funcion ejecutada cuando se cancela el modal | 442 | // funcion ejecutada cuando se cancela el modal |
| 441 | }); | 443 | }); |
| 442 | } | 444 | } |
| 443 | }; | 445 | }; |
| 444 | $scope.seleccionarFormaPago = function (key) { | 446 | $scope.seleccionarFormaPago = function (key) { |
| 445 | if (key === 13) { | 447 | if (key === 13) { |
| 446 | var parametrosModal = { | 448 | var parametrosModal = { |
| 447 | searchText: $scope.cliente.formaPago.NOMBRE, | 449 | searchText: $scope.cliente.formaPago.NOMBRE, |
| 448 | query: '/forma-pago', | 450 | query: '/forma-pago', |
| 449 | columnas: [ | 451 | columnas: [ |
| 450 | { | 452 | { |
| 451 | propiedad: 'ID', | 453 | propiedad: 'ID', |
| 452 | nombre: 'Código', | 454 | nombre: 'Código', |
| 453 | filtro: { | 455 | filtro: { |
| 454 | nombre: 'rellenarDigitos', | 456 | nombre: 'rellenarDigitos', |
| 455 | parametro: 3 | 457 | parametro: 3 |
| 456 | } | 458 | } |
| 457 | }, | 459 | }, |
| 458 | { | 460 | { |
| 459 | propiedad: 'NOMBRE', | 461 | propiedad: 'NOMBRE', |
| 460 | nombre: 'Nombre' | 462 | nombre: 'Nombre' |
| 461 | } | 463 | } |
| 462 | ], | 464 | ], |
| 463 | titulo: 'Búsqueda de formas de pago', | 465 | titulo: 'Búsqueda de formas de pago', |
| 464 | size: 'md' | 466 | size: 'md' |
| 465 | }; | 467 | }; |
| 466 | focaModalService.modal(parametrosModal).then( | 468 | focaModalService.modal(parametrosModal).then( |
| 467 | function (formaPago) { | 469 | function (formaPago) { |
| 468 | $scope.cliente.formaPago = formaPago; | 470 | $scope.cliente.formaPago = formaPago; |
| 469 | }, function () { | 471 | }, function () { |
| 470 | // funcion ejecutada cuando se cancela el modal | 472 | // funcion ejecutada cuando se cancela el modal |
| 471 | }); | 473 | }); |
| 472 | } | 474 | } |
| 473 | }; | 475 | }; |
| 474 | 476 | ||
| 475 | function crearCopia() { | 477 | function crearCopia() { |
| 476 | var cliente = angular.copy($scope.cliente); | 478 | var cliente = angular.copy($scope.cliente); |
| 477 | cliente.COD = cliente.codigo; | 479 | cliente.COD = cliente.codigo; |
| 478 | cliente.CPO = cliente.CPO; | 480 | cliente.CPO = cliente.CPO; |
| 479 | cliente.PCX = parseInt(cliente.provincia.ID); | 481 | cliente.PCX = parseInt(cliente.provincia.ID); |
| 480 | cliente.LOX = parseInt(cliente.localidad.ID); | 482 | cliente.LOX = parseInt(cliente.localidad.ID); |
| 481 | cliente.LOC = cliente.localidad.NOMBRE; | 483 | cliente.LOC = cliente.localidad.NOMBRE; |
| 482 | cliente.PCI = cliente.provincia.NOMBRE; | 484 | cliente.PCI = cliente.provincia.NOMBRE; |
| 483 | cliente.IVA = cliente.iva.ID; | 485 | cliente.IVA = cliente.iva.ID; |
| 484 | cliente.ACT = cliente.actividad.ID; | 486 | cliente.ACT = cliente.actividad.ID; |
| 485 | cliente.ZON = (parseInt(cliente.zona.ID)).toString(); | 487 | cliente.ZON = (parseInt(cliente.zona.ID)).toString(); |
| 486 | cliente.TIP = cliente.tipoFactura.ID; | 488 | cliente.TIP = cliente.tipoFactura.ID; |
| 487 | cliente.TCO = cliente.tipoComprobante.ID; | 489 | cliente.TCO = cliente.tipoComprobante.ID; |
| 488 | cliente.FPA = cliente.formaPago.ID; | 490 | cliente.FPA = cliente.formaPago.ID; |
| 489 | cliente.VEN = $scope.vendedor.id; | 491 | cliente.VEN = $scope.vendedor.id; |
| 490 | cliente.CUIT = `${cliente.cuit1}-${cliente.cuit2}-${cliente.cuit3}`; | 492 | cliente.CUIT = `${cliente.cuit1}-${cliente.cuit2}-${cliente.cuit3}`; |
| 491 | cliente.idCobrador = cliente.cobrador.id; | 493 | cliente.idCobrador = cliente.cobrador.id; |
| 492 | 494 | ||
| 493 | delete cliente.codigo; | 495 | delete cliente.codigo; |
| 494 | delete cliente.provincia; | 496 | delete cliente.provincia; |
| 495 | delete cliente.localidad; | 497 | delete cliente.localidad; |
| 496 | delete cliente.iva; | 498 | delete cliente.iva; |
| 497 | delete cliente.actividad; | 499 | delete cliente.actividad; |
| 498 | delete cliente.zona; | 500 | delete cliente.zona; |
| 499 | delete cliente.tipoFactura; | 501 | delete cliente.tipoFactura; |
| 500 | delete cliente.tipoComprobante; | 502 | delete cliente.tipoComprobante; |
| 501 | delete cliente.formaPago; | 503 | delete cliente.formaPago; |
| 502 | delete cliente.cobrador; | 504 | delete cliente.cobrador; |
| 503 | delete cliente.cuit1; | 505 | delete cliente.cuit1; |
| 504 | delete cliente.cuit2; | 506 | delete cliente.cuit2; |
| 505 | delete cliente.cuit3; | 507 | delete cliente.cuit3; |
| 506 | delete cliente.vendedor; | 508 | delete cliente.vendedor; |
| 507 | 509 | ||
| 508 | return cliente; | 510 | return cliente; |
| 509 | } | 511 | } |
| 510 | function validateEmails(emails) { | 512 | function validateEmails(emails) { |
| 511 | 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,}))$/; | 513 | 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,}))$/; |
| 512 | var arr = emails.split(','); | 514 | var arr = emails.split(','); |
| 513 | var result = true; | 515 | var result = true; |
| 514 | arr.forEach(function (email) { | 516 | arr.forEach(function (email) { |
| 515 | var val = String(email).trim().toLowerCase(); | 517 | var val = String(email).trim().toLowerCase(); |
| 516 | if (!re.test(val)) result = false; | 518 | if (!re.test(val)) result = false; |
| 517 | }); | 519 | }); |
| 518 | return result; | 520 | return result; |
| 519 | } | 521 | } |
| 520 | } | 522 | } |
| 521 | ]); | 523 | ]); |
| 522 | 524 |