Commit 080e4e5264a631a43030d547cb5f071310495c1b

Authored by Luigi
1 parent 962aba7b9c
Exists in master

Llave al final

Showing 1 changed file with 3 additions and 4 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 $timeout(function () { 156 $timeout(function () {
157 $scope.focused = 4; 157 $scope.focused = 4;
158 }); 158 });
159 }, function () { 159 }, function () {
160 //TODO: función llamada cuando cancela el modal 160 //TODO: función llamada cuando cancela el modal
161 }); 161 });
162 } 162 }
163 }; 163 };
164 $scope.seleccionarLocalidad = function (key) { 164 $scope.seleccionarLocalidad = function (key) {
165 if ($scope.cliente.provincia.ID === undefined) { 165 if ($scope.cliente.provincia.ID === undefined) {
166 focaModalService.alert('Seleccione una provincia'); 166 focaModalService.alert('Seleccione una provincia');
167 return; 167 return;
168 } 168 }
169 if (key === 13) { 169 if (key === 13) {
170 var parametrosModal = { 170 var parametrosModal = {
171 searchText: $scope.cliente.localidad.NOMBRE, 171 searchText: $scope.cliente.localidad.NOMBRE,
172 query: '/localidad/' + parseInt($scope.cliente.provincia.ID), 172 query: '/localidad/' + parseInt($scope.cliente.provincia.ID),
173 columnas: [ 173 columnas: [
174 { 174 {
175 propiedad: 'ID', 175 propiedad: 'ID',
176 nombre: 'Código', 176 nombre: 'Código',
177 }, 177 },
178 { 178 {
179 propiedad: 'NOMBRE', 179 propiedad: 'NOMBRE',
180 nombre: 'Nombre' 180 nombre: 'Nombre'
181 } 181 }
182 ], 182 ],
183 titulo: 'Búsqueda de localidades', 183 titulo: 'Búsqueda de localidades',
184 size: 'md' 184 size: 'md'
185 }; 185 };
186 focaModalService.modal(parametrosModal).then(function (localidad) { 186 focaModalService.modal(parametrosModal).then(function (localidad) {
187 $scope.cliente.localidad = localidad; 187 $scope.cliente.localidad = localidad;
188 $timeout(function () { 188 $timeout(function () {
189 $scope.focused = 5; 189 $scope.focused = 5;
190 }); 190 });
191 }, function () { 191 }, function () {
192 //TODO: función llamada cuando cancela el modal 192 //TODO: función llamada cuando cancela el modal
193 }); 193 });
194 } 194 }
195 }; 195 };
196 $scope.seleccionarZona = function (key) { 196 $scope.seleccionarZona = function (key) {
197 if (key === 13) { 197 if (key === 13) {
198 var parametrosModal = { 198 var parametrosModal = {
199 searchText: $scope.cliente.zona.NOM, 199 searchText: $scope.cliente.zona.NOM,
200 query: '/zona', 200 query: '/zona',
201 columnas: [ 201 columnas: [
202 { 202 {
203 propiedad: 'ID', 203 propiedad: 'ID',
204 nombre: 'Código', 204 nombre: 'Código',
205 filtro: { 205 filtro: {
206 nombre: 'rellenarDigitos', 206 nombre: 'rellenarDigitos',
207 parametro: 3 207 parametro: 3
208 } 208 }
209 }, 209 },
210 { 210 {
211 propiedad: 'NOM', 211 propiedad: 'NOM',
212 nombre: 'Nombre' 212 nombre: 'Nombre'
213 } 213 }
214 ], 214 ],
215 titulo: 'Búsqueda de zonas', 215 titulo: 'Búsqueda de zonas',
216 size: 'md' 216 size: 'md'
217 }; 217 };
218 focaModalService.modal(parametrosModal).then( 218 focaModalService.modal(parametrosModal).then(
219 function (zona) { 219 function (zona) {
220 $scope.cliente.zona = zona; 220 $scope.cliente.zona = zona;
221 $timeout(function () { 221 $timeout(function () {
222 $scope.focused = 6; 222 $scope.focused = 6;
223 }); 223 });
224 }, function () { 224 }, function () {
225 // funcion ejecutada cuando se cancela el modal 225 // funcion ejecutada cuando se cancela el modal
226 }); 226 });
227 } 227 }
228 }; 228 };
229 $scope.seleccionarActividad = function (key) { 229 $scope.seleccionarActividad = function (key) {
230 if (key === 13) { 230 if (key === 13) {
231 var parametrosModal = { 231 var parametrosModal = {
232 searchText: $scope.cliente.actividad.NOM, 232 searchText: $scope.cliente.actividad.NOM,
233 query: '/actividad', 233 query: '/actividad',
234 columnas: [ 234 columnas: [
235 { 235 {
236 propiedad: 'ID', 236 propiedad: 'ID',
237 nombre: 'Código', 237 nombre: 'Código',
238 filtro: { 238 filtro: {
239 nombre: 'rellenarDigitos', 239 nombre: 'rellenarDigitos',
240 parametro: 3 240 parametro: 3
241 } 241 }
242 }, 242 },
243 { 243 {
244 propiedad: 'NOM', 244 propiedad: 'NOM',
245 nombre: 'Nombre' 245 nombre: 'Nombre'
246 } 246 }
247 ], 247 ],
248 titulo: 'Búsqueda de actividades', 248 titulo: 'Búsqueda de actividades',
249 size: 'md' 249 size: 'md'
250 }; 250 };
251 focaModalService.modal(parametrosModal).then( 251 focaModalService.modal(parametrosModal).then(
252 function (actividad) { 252 function (actividad) {
253 $scope.cliente.actividad = actividad; 253 $scope.cliente.actividad = actividad;
254 $timeout(function () { 254 $timeout(function () {
255 $scope.focused = 7; 255 $scope.focused = 7;
256 }); 256 });
257 }, function () { 257 }, function () {
258 // funcion ejecutada cuando se cancela el modal 258 // funcion ejecutada cuando se cancela el modal
259 }); 259 });
260 } 260 }
261 }; 261 };
262 $scope.seleccionarCobrador = function (key) { 262 $scope.seleccionarCobrador = function (key) {
263 if (key === 13) { 263 if (key === 13) {
264 var parametrosModal = { 264 var parametrosModal = {
265 searchText: $scope.cliente.cobrador.NOM, 265 searchText: $scope.cliente.cobrador.NOM,
266 query: '/cobrador', 266 query: '/cobrador',
267 columnas: [ 267 columnas: [
268 { 268 {
269 propiedad: 'NUM', 269 propiedad: 'NUM',
270 nombre: 'Código' 270 nombre: 'Código'
271 }, 271 },
272 { 272 {
273 propiedad: 'NOM', 273 propiedad: 'NOM',
274 nombre: 'Nombre' 274 nombre: 'Nombre'
275 } 275 }
276 ], 276 ],
277 titulo: 'Búsqueda de cobradores', 277 titulo: 'Búsqueda de cobradores',
278 size: 'md' 278 size: 'md'
279 }; 279 };
280 focaModalService.modal(parametrosModal).then( 280 focaModalService.modal(parametrosModal).then(
281 function (cobrador) { 281 function (cobrador) {
282 $scope.cliente.cobrador = cobrador; 282 $scope.cliente.cobrador = cobrador;
283 }, function () { 283 }, function () {
284 // funcion ejecutada cuando se cancela el modal 284 // funcion ejecutada cuando se cancela el modal
285 }); 285 });
286 } 286 }
287 }; 287 };
288 $scope.seleccionarVendedor = function (key) { 288 $scope.seleccionarVendedor = function (key) {
289 if (key === 13) { 289 if (key === 13) {
290 var parametrosModal = { 290 var parametrosModal = {
291 titulo: 'Búsqueda vendedores', 291 titulo: 'Búsqueda vendedores',
292 query: '/vendedor', 292 query: '/vendedor',
293 columnas: [ 293 columnas: [
294 { 294 {
295 propiedad: 'NUM', 295 propiedad: 'NUM',
296 nombre: 'Código', 296 nombre: 'Código',
297 filtro: { 297 filtro: {
298 nombre: 'rellenarDigitos', 298 nombre: 'rellenarDigitos',
299 parametro: 3 299 parametro: 3
300 } 300 }
301 }, 301 },
302 { 302 {
303 propiedad: 'NOM', 303 propiedad: 'NOM',
304 nombre: 'Nombre' 304 nombre: 'Nombre'
305 } 305 }
306 ], 306 ],
307 size: 'md' 307 size: 'md'
308 }; 308 };
309 focaModalService.modal(parametrosModal).then( 309 focaModalService.modal(parametrosModal).then(
310 function (vendedor) { 310 function (vendedor) {
311 $scope.vendedor = vendedor; 311 $scope.vendedor = vendedor;
312 }, function () { 312 }, function () {
313 // funcion ejecutada cuando se cancela el modal 313 // funcion ejecutada cuando se cancela el modal
314 }); 314 });
315 } 315 }
316 }; 316 };
317 $scope.seleccionarIva = function (key) { 317 $scope.seleccionarIva = function (key) {
318 if (key === 13) { 318 if (key === 13) {
319 var parametrosModal = { 319 var parametrosModal = {
320 query: '/iva', 320 query: '/iva',
321 searchText: $scope.cliente.iva.NOMBRE, 321 searchText: $scope.cliente.iva.NOMBRE,
322 columnas: [ 322 columnas: [
323 { 323 {
324 propiedad: 'ID', 324 propiedad: 'ID',
325 nombre: 'Código', 325 nombre: 'Código',
326 filtro: { 326 filtro: {
327 nombre: 'rellenarDigitos', 327 nombre: 'rellenarDigitos',
328 parametro: 3 328 parametro: 3
329 } 329 }
330 }, 330 },
331 { 331 {
332 propiedad: 'NOMBRE', 332 propiedad: 'NOMBRE',
333 nombre: 'Nombre' 333 nombre: 'Nombre'
334 } 334 }
335 ], 335 ],
336 titulo: 'Búsqueda de responsabilidad ante el IVA', 336 titulo: 'Búsqueda de responsabilidad ante el IVA',
337 size: 'md' 337 size: 'md'
338 }; 338 };
339 focaModalService.modal(parametrosModal).then( 339 focaModalService.modal(parametrosModal).then(
340 function (iva) { 340 function (iva) {
341 if (iva) { 341 if (iva) {
342 delete $scope.cliente.tipoFactura.NOMBRE; 342 delete $scope.cliente.tipoFactura.NOMBRE;
343 } 343 }
344 $scope.cliente.iva = iva; 344 $scope.cliente.iva = iva;
345 $timeout(function () { 345 $timeout(function () {
346 $scope.focused = 12; 346 $scope.focused = 12;
347 }); 347 });
348 }, function () { 348 }, function () {
349 // funcion ejecutada cuando se cancela el modal 349 // funcion ejecutada cuando se cancela el modal
350 }); 350 });
351 } 351 }
352 }; 352 };
353 $scope.seleccionarTipoFactura = function (key) { 353 $scope.seleccionarTipoFactura = function (key) {
354 354
355 if ($scope.cliente.iva.NOMBRE == '') { 355 if ($scope.cliente.iva.NOMBRE == '') {
356 focaModalService.alert('Seleccione una responsabilidad ante el IVA'); 356 focaModalService.alert('Seleccione una responsabilidad ante el IVA');
357 return; 357 return;
358 } 358 }
359 359
360 if (key === 13) { 360 if (key === 13) {
361 var datos; 361 var datos;
362 if ($scope.cliente.iva.ID == 1) { 362 if ($scope.cliente.iva.ID == 1) {
363 datos = [ 363 datos = [
364 { 364 {
365 ID: 'A', 365 ID: 'A',
366 NOMBRE: 'Factura A' 366 NOMBRE: 'Factura A'
367 }, 367 },
368 { 368 {
369 ID: 'M', 369 ID: 'M',
370 NOMBRE: 'Factura M' 370 NOMBRE: 'Factura M'
371 }, 371 },
372 { 372 {
373 ID: 'R', 373 ID: 'R',
374 NOMBRE: 'Remito' 374 NOMBRE: 'Remito'
375 } 375 }
376 ]; 376 ];
377 } else { 377 } else {
378 datos = [ 378 datos = [
379 { 379 {
380 ID: 'B', 380 ID: 'B',
381 NOMBRE: 'Factura B' 381 NOMBRE: 'Factura B'
382 }, 382 },
383 { 383 {
384 ID: 'R', 384 ID: 'R',
385 NOMBRE: 'Remito' 385 NOMBRE: 'Remito'
386 } 386 }
387 ]; 387 ];
388 } 388 }
389 focaModalService.modal({ 389 focaModalService.modal({
390 titulo: 'Seleccionar Factura', 390 titulo: 'Seleccionar Factura',
391 data: datos, 391 data: datos,
392 size: 'md', 392 size: 'md',
393 columnas: [ 393 columnas: [
394 { 394 {
395 propiedad: 'ID', 395 propiedad: 'ID',
396 NOMBRE: 'Codigo' 396 NOMBRE: 'Codigo'
397 }, 397 },
398 { 398 {
399 propiedad: 'NOMBRE', 399 propiedad: 'NOMBRE',
400 NOMBRE: 'Factura' 400 NOMBRE: 'Factura'
401 } 401 }
402 ], 402 ],
403 }).then(function (res) { 403 }).then(function (res) {
404 $scope.cliente.tipoFactura = res; 404 $scope.cliente.tipoFactura = res;
405 }); 405 });
406 } 406 }
407 }; 407 };
408 $scope.pasarCampoCuit = function (numeroCuit) { 408 $scope.pasarCampoCuit = function (numeroCuit) {
409 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { 409 if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) {
410 $scope.cuitActivo = 2; 410 $scope.cuitActivo = 2;
411 } else if (numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { 411 } else if (numeroCuit === 2 && $scope.cliente.cuit2.length === 8) {
412 $scope.cuitActivo = 3; 412 $scope.cuitActivo = 3;
413 } 413 }
414 }; 414 };
415 $scope.seleccionarTipoComprobante = function (key) { 415 $scope.seleccionarTipoComprobante = function (key) {
416 if (key === 13) { 416 if (key === 13) {
417 var parametrosModal = { 417 var parametrosModal = {
418 searchText: $scope.cliente.tipoComprobante.NOMBRE, 418 searchText: $scope.cliente.tipoComprobante.NOMBRE,
419 query: '/tipo-comprobante', 419 query: '/tipo-comprobante',
420 columnas: [ 420 columnas: [
421 { 421 {
422 propiedad: 'ID', 422 propiedad: 'ID',
423 nombre: 'Código' 423 nombre: 'Código'
424 }, 424 },
425 { 425 {
426 propiedad: 'NOMBRE', 426 propiedad: 'NOMBRE',
427 nombre: 'Nombre' 427 nombre: 'Nombre'
428 } 428 }
429 ], 429 ],
430 titulo: 'Búsqueda de tipos de comprobante', 430 titulo: 'Búsqueda de tipos de comprobante',
431 size: 'md' 431 size: 'md'
432 }; 432 };
433 focaModalService.modal(parametrosModal).then( 433 focaModalService.modal(parametrosModal).then(
434 function (tipoComprobante) { 434 function (tipoComprobante) {
435 $scope.cliente.tipoComprobante = tipoComprobante; 435 $scope.cliente.tipoComprobante = tipoComprobante;
436 $timeout(function () { 436 $timeout(function () {
437 $scope.focused = 17; 437 $scope.focused = 17;
438 }); 438 });
439 }, function () { 439 }, function () {
440 // funcion ejecutada cuando se cancela el modal 440 // funcion ejecutada cuando se cancela el modal
441 }); 441 });
442 } 442 }
443 }; 443 };
444 $scope.seleccionarFormaPago = function (key) { 444 $scope.seleccionarFormaPago = function (key) {
445 if (key === 13) { 445 if (key === 13) {
446 var parametrosModal = { 446 var parametrosModal = {
447 searchText: $scope.cliente.formaPago.NOMBRE, 447 searchText: $scope.cliente.formaPago.NOMBRE,
448 query: '/forma-pago', 448 query: '/forma-pago',
449 columnas: [ 449 columnas: [
450 { 450 {
451 propiedad: 'ID', 451 propiedad: 'ID',
452 nombre: 'Código', 452 nombre: 'Código',
453 filtro: { 453 filtro: {
454 nombre: 'rellenarDigitos', 454 nombre: 'rellenarDigitos',
455 parametro: 3 455 parametro: 3
456 } 456 }
457 }, 457 },
458 { 458 {
459 propiedad: 'NOMBRE', 459 propiedad: 'NOMBRE',
460 nombre: 'Nombre' 460 nombre: 'Nombre'
461 } 461 }
462 ], 462 ],
463 titulo: 'Búsqueda de formas de pago', 463 titulo: 'Búsqueda de formas de pago',
464 size: 'md' 464 size: 'md'
465 }; 465 };
466 focaModalService.modal(parametrosModal).then( 466 focaModalService.modal(parametrosModal).then(
467 function (formaPago) { 467 function (formaPago) {
468 $scope.cliente.formaPago = formaPago; 468 $scope.cliente.formaPago = formaPago;
469 }, function () { 469 }, function () {
470 // funcion ejecutada cuando se cancela el modal 470 // funcion ejecutada cuando se cancela el modal
471 }); 471 });
472 } 472 }
473 }; 473 };
474 474
475 function crearCopia() { 475 function crearCopia() {
476 var cliente = angular.copy($scope.cliente); 476 var cliente = angular.copy($scope.cliente);
477 cliente.COD = cliente.codigo; 477 cliente.COD = cliente.codigo;
478 cliente.CPO = cliente.CPO; 478 cliente.CPO = cliente.CPO;
479 cliente.PCX = parseInt(cliente.provincia.ID); 479 cliente.PCX = parseInt(cliente.provincia.ID);
480 cliente.LOX = parseInt(cliente.localidad.ID); 480 cliente.LOX = parseInt(cliente.localidad.ID);
481 cliente.LOC = cliente.localidad.NOMBRE; 481 cliente.LOC = cliente.localidad.NOMBRE;
482 cliente.PCI = cliente.provincia.NOMBRE; 482 cliente.PCI = cliente.provincia.NOMBRE;
483 cliente.IVA = cliente.iva.ID; 483 cliente.IVA = cliente.iva.ID;
484 cliente.ACT = cliente.actividad.ID; 484 cliente.ACT = cliente.actividad.ID;
485 cliente.ZON = (parseInt(cliente.zona.ID)).toString(); 485 cliente.ZON = (parseInt(cliente.zona.ID)).toString();
486 cliente.TIP = cliente.tipoFactura.ID; 486 cliente.TIP = cliente.tipoFactura.ID;
487 cliente.TCO = cliente.tipoComprobante.ID; 487 cliente.TCO = cliente.tipoComprobante.ID;
488 cliente.FPA = cliente.formaPago.ID; 488 cliente.FPA = cliente.formaPago.ID;
489 cliente.VEN = $scope.vendedor.id; 489 cliente.VEN = $scope.vendedor.id;
490 cliente.CUIT = `${cliente.cuit1}-${cliente.cuit2}-${cliente.cuit3}`; 490 cliente.CUIT = `${cliente.cuit1}-${cliente.cuit2}-${cliente.cuit3}`;
491 cliente.idCobrador = cliente.cobrador.ID; 491 cliente.idCobrador = cliente.cobrador.ID;
492 492
493 delete cliente.codigo; 493 delete cliente.codigo;
494 delete cliente.provincia; 494 delete cliente.provincia;
495 delete cliente.localidad; 495 delete cliente.localidad;
496 delete cliente.iva; 496 delete cliente.iva;
497 delete cliente.actividad; 497 delete cliente.actividad;
498 delete cliente.zona; 498 delete cliente.zona;
499 delete cliente.tipoFactura; 499 delete cliente.tipoFactura;
500 delete cliente.tipoComprobante; 500 delete cliente.tipoComprobante;
501 delete cliente.formaPago; 501 delete cliente.formaPago;
502 delete cliente.cobrador; 502 delete cliente.cobrador;
503 delete cliente.cuit1; 503 delete cliente.cuit1;
504 delete cliente.cuit2; 504 delete cliente.cuit2;
505 delete cliente.cuit3; 505 delete cliente.cuit3;
506 delete cliente.vendedor; 506 delete cliente.vendedor;
507 507
508 return cliente; 508 return cliente;
509 } 509 }
510 function validateEmails(emails) { 510 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,}))$/; 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,}))$/;
512 var arr = emails.split(','); 512 var arr = emails.split(',');
513 var result = true; 513 var result = true;
514 arr.forEach(function (email) { 514 arr.forEach(function (email) {
515 var val = String(email).trim().toLowerCase(); 515 var val = String(email).trim().toLowerCase();
516 if (!re.test(val)) result = false; 516 if (!re.test(val)) result = false;
517 }); 517 });
518 return result; 518 return result;
519 } 519 }
520
521 }]);
522
523