Commit 04844c0a54c3635ae23abba525a4081dec97d681

Authored by Luigi
1 parent 4d9ec829f4
Exists in master

Espacios

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