Commit 01da053c8185a12f306eed46fb30b79e1c54bc41

Authored by Eric Fernandez
1 parent 55aef6d2b5
Exists in master and in 1 other branch develop

me quiero ir a mi casa

Showing 1 changed file with 18 additions and 0 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearFactura').controller('facturaController', [ 1 angular.module('focaCrearFactura').controller('facturaController', [
2 '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', 2 '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout',
3 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', 3 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService',
4 '$localStorage', 'APP', 'focaLoginService', 4 '$localStorage', 'APP', 'focaLoginService',
5 function ( 5 function (
6 $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, 6 $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService,
7 crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) { 7 crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) {
8 8
9 config(); 9 config();
10 10
11 function config() { 11 function config() {
12 $scope.tmpCantidad = '0'; 12 $scope.tmpCantidad = '0';
13 $scope.botonera = crearFacturaService.getBotonera(); 13 $scope.botonera = crearFacturaService.getBotonera();
14 $scope.botoneraProductos = []; 14 $scope.botoneraProductos = [];
15 $scope.isNumber = angular.isNumber; 15 $scope.isNumber = angular.isNumber;
16 $scope.datepickerAbierto = false; 16 $scope.datepickerAbierto = false;
17 $scope.show = false; 17 $scope.show = false;
18 $scope.cargando = true; 18 $scope.cargando = true;
19 $scope.now = new Date(); 19 $scope.now = new Date();
20 $scope.puntoVenta = rellenar(0, 4); 20 $scope.puntoVenta = rellenar(0, 4);
21 $scope.comprobante = rellenar(0, 8); 21 $scope.comprobante = rellenar(0, 8);
22 $scope.dateOptions = { 22 $scope.dateOptions = {
23 maxDate: new Date(), 23 maxDate: new Date(),
24 minDate: new Date(2010, 0, 1) 24 minDate: new Date(2010, 0, 1)
25 }; 25 };
26 $scope.cabeceras = []; 26 $scope.cabeceras = [];
27 crearFacturaService.getParametros().then(function (res) { 27 crearFacturaService.getParametros().then(function (res) {
28 28
29 var parametros = JSON.parse(res.data[0].jsonText); 29 var parametros = JSON.parse(res.data[0].jsonText);
30 30
31 if ($localStorage.factura) { 31 if ($localStorage.factura) {
32 32
33 $timeout(function () { getLSFactura(); }); 33 $timeout(function () { getLSFactura(); });
34 } else { 34 } else {
35 35
36 for (var property in parametros) { 36 for (var property in parametros) {
37 $scope.factura[property] = parametros[property]; 37 $scope.factura[property] = parametros[property];
38 $scope.inicial[property] = parametros[property]; 38 $scope.inicial[property] = parametros[property];
39 } 39 }
40 40
41 setearFactura($scope.factura); 41 setearFactura($scope.factura);
42 } 42 }
43 43
44 }); 44 });
45 45
46 //SETEO BOTONERA LATERAL 46 //SETEO BOTONERA LATERAL
47 $timeout(function () { 47 $timeout(function () {
48 focaBotoneraLateralService.showSalir(false); 48 focaBotoneraLateralService.showSalir(false);
49 focaBotoneraLateralService.showPausar(true); 49 focaBotoneraLateralService.showPausar(true);
50 focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); 50 focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago);
51 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); 51 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
52 }); 52 });
53 53
54 init(); 54 init();
55 55
56 } 56 }
57 57
58 function init() { 58 function init() {
59 59
60 $scope.$broadcast('cleanCabecera'); 60 $scope.$broadcast('cleanCabecera');
61 61
62 $scope.factura = { 62 $scope.factura = {
63 id: 0, 63 id: 0,
64 estado: 0, 64 estado: 0,
65 vendedor: {}, 65 vendedor: {},
66 cliente: {}, 66 cliente: {},
67 proveedor: {}, 67 proveedor: {},
68 domicilio: { dom: '' }, 68 domicilio: { dom: '' },
69 moneda: {}, 69 moneda: {},
70 formaPago: 1, // Por defecto paga contado 70 formaPago: 1, // Por defecto paga contado
71 cotizacion: $scope.cotizacionPorDefecto || {}, 71 cotizacion: $scope.cotizacionPorDefecto || {},
72 articulosFactura: [], 72 articulosFactura: [],
73 despachos: [] 73 despachos: []
74 }; 74 };
75 75
76 $scope.factura.articulosFactura = []; 76 $scope.factura.articulosFactura = [];
77 $scope.idLista = undefined; 77 $scope.idLista = undefined;
78 78
79 crearRemitoService.getNumeroRemito().then( 79 crearRemitoService.getNumeroRemito().then(
80 function (res) { 80 function (res) {
81 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 81 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
82 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 82 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
83 }, 83 },
84 function (err) { 84 function (err) {
85 focaModalService.alert('La terminal no esta configurada correctamente'); 85 focaModalService.alert('La terminal no esta configurada correctamente');
86 console.info(err); 86 console.info(err);
87 } 87 }
88 ); 88 );
89 89
90 $scope.inicial = angular.copy($scope.factura); 90 $scope.inicial = angular.copy($scope.factura);
91 91
92 if (APP == 'facturador') { 92 if (APP == 'facturador') {
93 crearFacturaService 93 crearFacturaService
94 .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) 94 .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya)
95 .then(function (res) { 95 .then(function (res) {
96 96
97 validarPlanillaVendedor(res.data) 97 validarPlanillaVendedor(res.data)
98 .then(function () { 98 .then(function () {
99 99
100 $scope.$broadcast('addCabecera', { 100 $scope.$broadcast('addCabecera', {
101 label: 'Vendedor:', 101 label: 'Vendedor:',
102 valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + 102 valor: $filter('rellenarDigitos')(res.data.CodVen, 3) +
103 ' - ' + 103 ' - ' +
104 res.data.NomVen 104 res.data.NomVen
105 }); 105 });
106 106
107 $scope.factura.vendedor = res.data; 107 $scope.factura.vendedor = res.data;
108 $scope.inicial.vendedor = res.data; 108 $scope.inicial.vendedor = res.data;
109 109
110 getProductosByPlanilla(res.data.NplVen); 110 getProductosByPlanilla(res.data.NplVen);
111 }) 111 })
112 .catch(function (err) { 112 .catch(function (err) {
113 console.log(err); 113 console.log(err);
114 focaModalService.alert('Ocurrió un error al intentar recuperar' + 114 focaModalService.alert('Ocurrió un error al intentar recuperar' +
115 'el vendedor logeado'); 115 'el vendedor logeado');
116 }); 116 });
117 }) 117 })
118 } 118 }
119 } 119 }
120 120
121 $scope.$watch('factura', function (newValue) { 121 $scope.$watch('factura', function (newValue) {
122 focaBotoneraLateralService.setPausarData({ 122 focaBotoneraLateralService.setPausarData({
123 label: 'factura', 123 label: 'factura',
124 val: newValue 124 val: newValue
125 }); 125 });
126 }, true); 126 }, true);
127 127
128 $scope.seleccionarFormaDePago = function () { 128 $scope.seleccionarFormaDePago = function () {
129 129
130 if (!validarGuardar()) return; 130 if (!validarGuardar()) return;
131 131
132 if ($scope.factura.formaPago == 2) { 132 if ($scope.factura.formaPago == 2) {
133 $scope.crearFactura(); 133 $scope.crearFactura();
134 return; 134 return;
135 } 135 }
136 136
137 var modalInstance = $uibModal.open( 137 var modalInstance = $uibModal.open(
138 { 138 {
139 templateUrl: 'modal-forma-pago.html', 139 templateUrl: 'modal-forma-pago.html',
140 controller: 'focaModalFormaPagoController', 140 controller: 'focaModalFormaPagoController',
141 resolve: { 141 resolve: {
142 parametros: function () { 142 parametros: function () {
143 return { 143 return {
144 importe: $scope.getTotal() 144 importe: $scope.getTotal()
145 }; 145 };
146 }, 146 },
147 }, 147 },
148 size: 'lg', 148 size: 'lg',
149 } 149 }
150 ); 150 );
151 modalInstance.result 151 modalInstance.result
152 .then(function (data) { 152 .then(function (data) {
153 153
154 if (data.tipo == 'tarjeta') { 154 if (data.tipo == 'tarjeta') {
155 $scope.factura.formaPago = 4; 155 $scope.factura.formaPago = 4;
156 } else { 156 } else {
157 $scope.factura.formaPago = 1; 157 $scope.factura.formaPago = 1;
158 } 158 }
159 159
160 $scope.crearFactura(data); 160 $scope.crearFactura(data);
161 }) 161 })
162 .catch(function (e) { console.error(e); }); 162 .catch(function (e) { console.error(e); });
163 }; 163 };
164 164
165 $scope.crearFactura = function (formaPago) { 165 $scope.crearFactura = function (formaPago) {
166 166
167 var save = { 167 var save = {
168 factura: { 168 factura: {
169 169
170 BONIF: 0, 170 BONIF: 0,
171 CLI: $scope.factura.cliente.cod, 171 CLI: $scope.factura.cliente.cod,
172 CUI: $scope.factura.cliente.cuit, 172 CUI: $scope.factura.cliente.cuit,
173 CTA: $scope.factura.cliente.cod, 173 CTA: $scope.factura.cliente.cod,
174 DC1: '', 174 DC1: '',
175 DC2: '', 175 DC2: '',
176 DE1: '', 176 DE1: '',
177 DOM: $scope.factura.cliente.DOM, 177 DOM: $scope.factura.cliente.DOM,
178 FACAUT: 0, 178 FACAUT: 0,
179 DTO: 0, 179 DTO: 0,
180 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), 180 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'),
181 FEC_ANT: '19000101', 181 FEC_ANT: '19000101',
182 FPA: $scope.factura.formaPago, 182 FPA: $scope.factura.formaPago,
183 IDEXCEPCION: 0, 183 IDEXCEPCION: 0,
184 IDLP: $scope.factura.cliente.mod.trim() || 0, 184 IDLP: $scope.factura.cliente.mod.trim() || 0,
185 IDPERSONERIA: 0, 185 IDPERSONERIA: 0,
186 IMI: getImporte('IMI'), 186 IMI: getImporte('IMI'),
187 IMI2: getImporte('IMI2'), 187 IMI2: getImporte('IMI2'),
188 IMI3: getImporte('IMI3'), 188 IMI3: getImporte('IMI3'),
189 IMP_LEY: 0, 189 IMP_LEY: 0,
190 IRI: getImporte('IVA'), 190 IRI: getImporte('IVA'),
191 IRS: 0, 191 IRS: 0,
192 LEG: '', 192 LEG: '',
193 LUG: $scope.factura.vendedor.LugVen, 193 LUG: $scope.factura.vendedor.LugVen,
194 MK_M: 0, 194 MK_M: 0,
195 NEE: getImporte('NEX'), 195 NEE: getImporte('NEX'),
196 NET: getImporte('NET'), 196 NET: getImporte('NET'),
197 NFI: '', 197 NFI: '',
198 NNP: 0, 198 NNP: 0,
199 NOM: $scope.factura.cliente.nom, 199 NOM: $scope.factura.cliente.nom,
200 OPE: $scope.factura.vendedor.CodVen, 200 OPE: $scope.factura.vendedor.CodVen,
201 PAG: $scope.getTotal(), 201 PAG: $scope.getTotal(),
202 PER: 0, 202 PER: 0,
203 PER_IVA: 0, 203 PER_IVA: 0,
204 PLA: $scope.factura.vendedor.NplVen, 204 PLA: $scope.factura.vendedor.NplVen,
205 PRO: '', 205 PRO: '',
206 REC_ANT: 0, 206 REC_ANT: 0,
207 SUC: parseInt($scope.puntoVenta), 207 SUC: parseInt($scope.puntoVenta),
208 TCA: 1, 208 TCA: 1,
209 TCO: 'FT', 209 TCO: 'FT',
210 TFI: '', 210 TFI: '',
211 TIP: $scope.factura.cliente.tipoFactura, 211 TIP: $scope.factura.cliente.tipoFactura,
212 TIV: $scope.factura.cliente.iva, 212 TIV: $scope.factura.cliente.iva,
213 TOT: $scope.getTotal(), 213 TOT: $scope.getTotal(),
214 TUR: $scope.factura.vendedor.TurVen, 214 TUR: $scope.factura.vendedor.TurVen,
215 VEN: $scope.factura.vendedor.CodVen, 215 VEN: $scope.factura.vendedor.CodVen,
216 VTO_CLI: '', 216 VTO_CLI: '',
217 ZON: 1, // TODO: ZON DE APAREMP 217 ZON: 1, // TODO: ZON DE APAREMP
218 OBSERVACIONES: $scope.factura.observaciones 218 OBSERVACIONES: $scope.factura.observaciones
219 }, 219 },
220 cuerpo: $scope.articulosFiltro(), 220 cuerpo: $scope.articulosFiltro(),
221 despachos: $scope.factura.despachos, 221 despachos: $scope.factura.despachos,
222 formaPago: formaPago 222 formaPago: formaPago
223 }; 223 };
224 224
225 crearFacturaService.guardarFactura(save).then(function (res) { 225 crearFacturaService.guardarFactura(save).then(function (res) {
226 226
227 focaBotoneraLateralService.endGuardar(true); 227 focaBotoneraLateralService.endGuardar(true);
228 228
229 focaModalService.alert('Comprobante guardado con éxito'); 229 focaModalService.alert('Comprobante guardado con éxito');
230 230
231 config(); 231 config();
232 232
233 }).catch(function (err) { 233 }).catch(function (err) {
234 focaModalService.alert('Hubo un error al guardar la factura'); 234 focaModalService.alert('Hubo un error al guardar la factura');
235 console.error(err); 235 console.error(err);
236 }); 236 });
237 237
238 }; 238 };
239 239
240 $scope.seleccionarCliente = function () { 240 $scope.seleccionarCliente = function () {
241 241
242 var modalInstance = $uibModal.open( 242 var modalInstance = $uibModal.open(
243 { 243 {
244 ariaLabelledBy: 'Busqueda de Cliente', 244 ariaLabelledBy: 'Busqueda de Cliente',
245 templateUrl: 'foca-busqueda-cliente-modal.html', 245 templateUrl: 'foca-busqueda-cliente-modal.html',
246 controller: 'focaBusquedaClienteModalController', 246 controller: 'focaBusquedaClienteModalController',
247 resolve: { 247 resolve: {
248 vendedor: function () { return null; }, 248 vendedor: function () { return null; },
249 cobrador: function () { return null; } 249 cobrador: function () { return null; }
250 }, 250 },
251 size: 'lg' 251 size: 'lg'
252 } 252 }
253 ); 253 );
254 modalInstance.result.then( 254 modalInstance.result.then(
255 function (cliente) { 255 function (cliente) {
256 var modalInstance = $uibModal.open( 256 var modalInstance = $uibModal.open(
257 { 257 {
258 templateUrl: 'modal-estado-cuenta.html', 258 templateUrl: 'modal-estado-cuenta.html',
259 controller: 'focaModalEstadoCuentaController', 259 controller: 'focaModalEstadoCuentaController',
260 size: 'lg', 260 size: 'lg',
261 resolve: { 261 resolve: {
262 parametros: function () { return { idCliente: cliente.cod }; }, 262 parametros: function () { return { idCliente: cliente.cod }; },
263 } 263 }
264 } 264 }
265 ); 265 );
266 modalInstance.result 266 modalInstance.result
267 .then(function (data) { 267 .then(function (data) {
268 268
269 $scope.factura.formaPago = data.formaDePago; 269 $scope.factura.formaPago = data.formaDePago;
270 270
271 $scope.factura.cliente = cliente; 271 $scope.factura.cliente = cliente;
272 272
273 $scope.$broadcast('addCabecera', { 273 $scope.$broadcast('addCabecera', {
274 label: 'Cliente:', 274 label: 'Cliente:',
275 valor: $filter('rellenarDigitos')(cliente.cod, 3) + 275 valor: $filter('rellenarDigitos')(cliente.cod, 3) +
276 ' - ' + cliente.nom 276 ' - ' + cliente.nom
277 }); 277 });
278 278
279 $filter('filter')($scope.botonera, 279 $filter('filter')($scope.botonera,
280 { label: 'Cliente' })[0].checked = true; 280 { label: 'Cliente' })[0].checked = true;
281 281
282 $scope.$broadcast('addCabecera', { 282 $scope.$broadcast('addCabecera', {
283 label: 'Tipo de pago: ', 283 label: 'Tipo de pago: ',
284 valor: data.tipo 284 valor: data.tipo
285 }); 285 });
286 }) 286 })
287 .catch(function () { 287 .catch(function () {
288 288
289 $scope.seleccionarCliente(); 289 $scope.seleccionarCliente();
290 }); 290 });
291 291
292 }, function () { 292 }, function () {
293 } 293 }
294 ); 294 );
295 295
296 }; 296 };
297 297
298 $scope.seleccionarVendedor = function () { 298 $scope.seleccionarVendedor = function () {
299 var parametrosModal = { 299 var parametrosModal = {
300 titulo: 'Búsqueda vendedores', 300 titulo: 'Búsqueda vendedores',
301 query: '/vendedor-playa', 301 query: '/vendedor-playa',
302 columnas: [ 302 columnas: [
303 { 303 {
304 propiedad: 'CodVen', 304 propiedad: 'CodVen',
305 nombre: 'Código', 305 nombre: 'Código',
306 filtro: { 306 filtro: {
307 nombre: 'rellenarDigitos', 307 nombre: 'rellenarDigitos',
308 parametro: 3 308 parametro: 3
309 } 309 }
310 }, 310 },
311 { 311 {
312 propiedad: 'NomVen', 312 propiedad: 'NomVen',
313 nombre: 'Nombre' 313 nombre: 'Nombre'
314 } 314 }
315 ], 315 ],
316 size: 'md' 316 size: 'md'
317 }; 317 };
318 focaModalService.modal(parametrosModal).then( 318 focaModalService.modal(parametrosModal).then(
319 function (vendedor) { 319 function (vendedor) {
320 320
321 indicarPassword(vendedor) 321 indicarPassword(vendedor)
322 .then(function () { 322 .then(function () {
323 validarPlanillaVendedor(vendedor) 323 validarPlanillaVendedor(vendedor)
324 .then(function () { 324 .then(function () {
325 325
326 $filter('filter')($scope.botonera, { 326 $filter('filter')($scope.botonera, {
327 label: 'Vendedor' 327 label: 'Vendedor'
328 })[0].checked = true; 328 })[0].checked = true;
329 329
330 $scope.$broadcast('addCabecera', { 330 $scope.$broadcast('addCabecera', {
331 label: 'Vendedor:', 331 label: 'Vendedor:',
332 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + 332 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) +
333 ' - ' + 333 ' - ' +
334 vendedor.NomVen 334 vendedor.NomVen
335 }); 335 });
336 336
337 $scope.factura.vendedor = vendedor; 337 $scope.factura.vendedor = vendedor;
338 338
339 getProductosByPlanilla(vendedor.NplVen); 339 getProductosByPlanilla(vendedor.NplVen);
340 }) 340 })
341 .catch($scope.seleccionarVendedor); 341 .catch($scope.seleccionarVendedor);
342 }) 342 })
343 .catch(function (err) { 343 .catch(function (err) {
344 console.error(err); 344 console.error(err);
345 }); 345 });
346 346
347 }, function () { } 347 }, function () { }
348 ); 348 );
349 }; 349 };
350 350
351 $scope.seleccionarMoneda = function () { 351 $scope.seleccionarMoneda = function () {
352 352
353 var parametrosModal = { 353 var parametrosModal = {
354 titulo: 'Búsqueda de monedas', 354 titulo: 'Búsqueda de monedas',
355 query: '/moneda', 355 query: '/moneda',
356 columnas: [ 356 columnas: [
357 { 357 {
358 propiedad: 'DETALLE', 358 propiedad: 'DETALLE',
359 nombre: 'Nombre' 359 nombre: 'Nombre'
360 }, 360 },
361 { 361 {
362 propiedad: 'SIMBOLO', 362 propiedad: 'SIMBOLO',
363 nombre: 'Símbolo' 363 nombre: 'Símbolo'
364 } 364 }
365 ], 365 ],
366 size: 'md' 366 size: 'md'
367 }; 367 };
368 focaModalService.modal(parametrosModal).then( 368 focaModalService.modal(parametrosModal).then(
369 function (moneda) { 369 function (moneda) {
370 370
371 if (moneda.ID !== 1) { 371 if (moneda.ID !== 1) {
372 $scope.abrirModalCotizacion(moneda); 372 $scope.abrirModalCotizacion(moneda);
373 return; 373 return;
374 } 374 }
375 375
376 crearRemitoService.getCotizacionByIdMoneda(1) 376 crearRemitoService.getCotizacionByIdMoneda(1)
377 .then(function (res) { 377 .then(function (res) {
378 378
379 var cotizacionPArgentino = res.data[0].cotizaciones[0]; 379 var cotizacionPArgentino = res.data[0].cotizaciones[0];
380 cotizacionPArgentino.moneda = moneda; 380 cotizacionPArgentino.moneda = moneda;
381 381
382 actualizarCabeceraMoneda(cotizacionPArgentino); 382 actualizarCabeceraMoneda(cotizacionPArgentino);
383 383
384 $scope.remito.cotizacion = cotizacionPArgentino; 384 $scope.remito.cotizacion = cotizacionPArgentino;
385 }); 385 });
386 }, function () { 386 }, function () {
387 387
388 } 388 }
389 ); 389 );
390 }; 390 };
391 391
392 $scope.abrirModalCotizacion = function (moneda) { 392 $scope.abrirModalCotizacion = function (moneda) {
393 var modalInstance = $uibModal.open( 393 var modalInstance = $uibModal.open(
394 { 394 {
395 ariaLabelledBy: 'Busqueda de Cotización', 395 ariaLabelledBy: 'Busqueda de Cotización',
396 templateUrl: 'modal-cotizacion.html', 396 templateUrl: 'modal-cotizacion.html',
397 controller: 'focaModalCotizacionController', 397 controller: 'focaModalCotizacionController',
398 size: 'lg', 398 size: 'lg',
399 resolve: { idMoneda: function () { return moneda.ID; } } 399 resolve: { idMoneda: function () { return moneda.ID; } }
400 } 400 }
401 ); 401 );
402 modalInstance.result.then( 402 modalInstance.result.then(
403 function (cotizacion) { 403 function (cotizacion) {
404 404
405 cotizacion.moneda = moneda; 405 cotizacion.moneda = moneda;
406 actualizarCabeceraMoneda(cotizacion); 406 actualizarCabeceraMoneda(cotizacion);
407 $scope.factura.cotizacion = cotizacion; 407 $scope.factura.cotizacion = cotizacion;
408 408
409 }, function () { 409 }, function () {
410 410
411 } 411 }
412 ); 412 );
413 }; 413 };
414 414
415 $scope.seleccionarObservaciones = function () { 415 $scope.seleccionarObservaciones = function () {
416 var observacion = { 416 var observacion = {
417 titulo: 'Ingrese Observaciones', 417 titulo: 'Ingrese Observaciones',
418 value: $scope.factura.observaciones, 418 value: $scope.factura.observaciones,
419 maxlength: 155, 419 maxlength: 155,
420 textarea: true 420 textarea: true
421 }; 421 };
422 422
423 focaModalService 423 focaModalService
424 .prompt(observacion) 424 .prompt(observacion)
425 .then(function (observaciones) { 425 .then(function (observaciones) {
426 $scope.factura.observaciones = observaciones; 426 $scope.factura.observaciones = observaciones;
427 }); 427 });
428 }; 428 };
429 429
430 $scope.articulosFiltro = function () { 430 $scope.articulosFiltro = function () {
431 return $scope.factura.articulosFactura.filter(function (articulo) { 431 return $scope.factura.articulosFactura.filter(function (articulo) {
432 return !articulo.desactivado; 432 return !articulo.desactivado;
433 }); 433 });
434 }; 434 };
435 435
436 $scope.getTotal = function () { 436 $scope.getTotal = function () {
437 437
438 var total = 0; 438 var total = 0;
439 439
440 $scope.articulosFiltro().forEach(function (articulo) { 440 $scope.articulosFiltro().forEach(function (articulo) {
441 total += articulo.PUN * articulo.CAN; 441 total += articulo.PUN * articulo.CAN;
442 }); 442 });
443 443
444 return parseFloat(total.toFixed(2)); 444 return parseFloat(total.toFixed(2));
445 }; 445 };
446 446
447 $scope.quitarDespacho = function (articulo, index) { 447 $scope.quitarDespacho = function (articulo, index) {
448 448
449 crearFacturaService 449 crearFacturaService
450 .setearDespachoDesocupado({ 450 .setearDespachoDesocupado({
451 surtidor: $scope.factura.despachos[index].SUR, 451 surtidor: $scope.factura.despachos[index].SUR,
452 producto: $scope.factura.despachos[index].PRO, 452 producto: $scope.factura.despachos[index].PRO,
453 carga: $scope.factura.despachos[index].CAR, 453 carga: $scope.factura.despachos[index].CAR,
454 planilla: $scope.factura.despachos[index].PLA 454 planilla: $scope.factura.despachos[index].PLA
455 }) 455 })
456 .then(function () { 456 .then(function () {
457 articulo.desactivado = true; 457 articulo.desactivado = true;
458 $scope.factura.despachos.splice(index, 1); 458 $scope.factura.despachos.splice(index, 1);
459 }) 459 })
460 .catch(function () { 460 .catch(function () {
461 focaModalService.alert('Hubo un error al desasociar este despacho'); 461 focaModalService.alert('Hubo un error al desasociar este despacho');
462 }); 462 });
463 }; 463 };
464 464
465 //Recibe aviso si el teclado está en uso
466 $rootScope.$on('usarTeclado', function (event, data) {
467 if (data) {
468 $scope.mostrarTeclado = true;
469 return;
470 }
471 $scope.mostrarTeclado = false;
472 });
473
474 $scope.selectFocus = function ($event) {
475 // Si el teclado esta en uso no selecciona el valor
476 if ($scope.mostrarTeclado) {
477 return;
478 }
479 $event.target.select();
480 };
481
482
465 function getProductosByPlanilla(numeroPlanilla) { 483 function getProductosByPlanilla(numeroPlanilla) {
466 484
467 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { 485 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) {
468 486
469 if (!res.data.length) { 487 if (!res.data.length) {
470 488
471 focaModalService.alert('No hay despachos disponibles por el momento'); 489 focaModalService.alert('No hay despachos disponibles por el momento');
472 return; 490 return;
473 } 491 }
474 492
475 $scope.botoneraProductos.length = 0; 493 $scope.botoneraProductos.length = 0;
476 res.data.forEach(function (producto) { 494 res.data.forEach(function (producto) {
477 495
478 $scope.botoneraProductos.push({ 496 $scope.botoneraProductos.push({
479 label: producto.DetArt, 497 label: producto.DetArt,
480 image: producto.nombreImagen, 498 image: producto.nombreImagen,
481 imageDefault: 'productoDefault.png' 499 imageDefault: 'productoDefault.png'
482 }); 500 });
483 501
484 crearFuncionesProductos(producto); 502 crearFuncionesProductos(producto);
485 }); 503 });
486 }); 504 });
487 } 505 }
488 506
489 $scope.seleccionarBusquedaProductos = function () { 507 $scope.seleccionarBusquedaProductos = function () {
490 508
491 if (angular.equals({}, $scope.factura.vendedor)) { 509 if (angular.equals({}, $scope.factura.vendedor)) {
492 510
493 focaModalService.alert('Seleccione Vendedor'); 511 focaModalService.alert('Seleccione Vendedor');
494 return false; 512 return false;
495 } 513 }
496 514
497 var modalInstance = $uibModal.open( 515 var modalInstance = $uibModal.open(
498 { 516 {
499 ariaLabelledBy: 'Busqueda de Productos', 517 ariaLabelledBy: 'Busqueda de Productos',
500 templateUrl: 'modal-busqueda-productos.html', 518 templateUrl: 'modal-busqueda-productos.html',
501 controller: 'modalBusquedaProductosCtrl', 519 controller: 'modalBusquedaProductosCtrl',
502 resolve: { 520 resolve: {
503 parametroProducto: { 521 parametroProducto: {
504 idLista: null, 522 idLista: null,
505 cotizacion: $scope.factura.cotizacion.VENDEDOR, 523 cotizacion: $scope.factura.cotizacion.VENDEDOR,
506 simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, 524 simbolo: $scope.factura.cotizacion.moneda.SIMBOLO,
507 buscarTodos: true 525 buscarTodos: true
508 } 526 }
509 }, 527 },
510 size: 'lg' 528 size: 'lg'
511 } 529 }
512 ); 530 );
513 531
514 modalInstance.result 532 modalInstance.result
515 .then(function (producto) { 533 .then(function (producto) {
516 534
517 var articulo = { 535 var articulo = {
518 TIP: $scope.factura.cliente.tipoFactura, 536 TIP: $scope.factura.cliente.tipoFactura,
519 TCO: 'FT', 537 TCO: 'FT',
520 SUC: parseInt($scope.puntoVenta), 538 SUC: parseInt($scope.puntoVenta),
521 ORD: $scope.articulosFiltro().length + 1, 539 ORD: $scope.articulosFiltro().length + 1,
522 SEC: producto.sector, 540 SEC: producto.sector,
523 ART: producto.codigo, 541 ART: producto.codigo,
524 RUB: producto.CodRub, 542 RUB: producto.CodRub,
525 DES: producto.descripcionLarga, 543 DES: producto.descripcionLarga,
526 PUN: producto.precio, 544 PUN: producto.precio,
527 IVA: producto.IMPIVA, 545 IVA: producto.IMPIVA,
528 NET: producto.IvaCO != 0 ? parseFloat(producto.neto) : 0, 546 NET: producto.IvaCO != 0 ? parseFloat(producto.neto) : 0,
529 NEX: producto.IvaCO == 0 ? parseFloat(producto.neto) : 0, 547 NEX: producto.IvaCO == 0 ? parseFloat(producto.neto) : 0,
530 IMI: producto.ImpInt, 548 IMI: producto.ImpInt,
531 IMI2: producto.ImpInt2, 549 IMI2: producto.ImpInt2,
532 IMI3: producto.ImpInt3, 550 IMI3: producto.ImpInt3,
533 PUT: producto.precio, 551 PUT: producto.precio,
534 SUR: 0, 552 SUR: 0,
535 PLA: $scope.factura.vendedor.NplVen, 553 PLA: $scope.factura.vendedor.NplVen,
536 LUG: $scope.factura.vendedor.LugVen, 554 LUG: $scope.factura.vendedor.LugVen,
537 LEG: $scope.factura.vendedor.CodVen, 555 LEG: $scope.factura.vendedor.CodVen,
538 TUR: $scope.factura.vendedor.TurVen, 556 TUR: $scope.factura.vendedor.TurVen,
539 ORDEN_PRECOMPRA: '', 557 ORDEN_PRECOMPRA: '',
540 ESC: producto.tipoFactura === 'L' ? 1 : 0, 558 ESC: producto.tipoFactura === 'L' ? 1 : 0,
541 CMF: 0, 559 CMF: 0,
542 PTA: 0, 560 PTA: 0,
543 IVS: 0, 561 IVS: 0,
544 TIVA: 0, 562 TIVA: 0,
545 CON: 0, 563 CON: 0,
546 SINO: '', 564 SINO: '',
547 ORD_TRA: 0, 565 ORD_TRA: 0,
548 IMP_DESP: 0, 566 IMP_DESP: 0,
549 PCD: 0, 567 PCD: 0,
550 RTO: '', 568 RTO: '',
551 }; 569 };
552 570
553 $scope.factura.articulosFactura.push(articulo); 571 $scope.factura.articulosFactura.push(articulo);
554 $scope.cambioEdit(articulo, 'cantidad'); 572 $scope.cambioEdit(articulo, 'cantidad');
555 573
556 }) 574 })
557 .catch(function (e) { console.error(e); }); 575 .catch(function (e) { console.error(e); });
558 }; 576 };
559 577
560 function crearFuncionesProductos(producto) { 578 function crearFuncionesProductos(producto) {
561 579
562 $scope[nombreFuncion(producto.DetArt)] = function () { 580 $scope[nombreFuncion(producto.DetArt)] = function () {
563 581
564 if (angular.equals($scope.factura.cliente, {})) { 582 if (angular.equals($scope.factura.cliente, {})) {
565 focaModalService.alert('Seleccione cliente'); 583 focaModalService.alert('Seleccione cliente');
566 return; 584 return;
567 } 585 }
568 586
569 var modalInstance = $uibModal.open( 587 var modalInstance = $uibModal.open(
570 { 588 {
571 templateUrl: 'modal-combustibles.html', 589 templateUrl: 'modal-combustibles.html',
572 controller: 'focaModalCombustiblesController', 590 controller: 'focaModalCombustiblesController',
573 resolve: { 591 resolve: {
574 parametros: function () { 592 parametros: function () {
575 return { 593 return {
576 despachos: producto.despachos, 594 despachos: producto.despachos,
577 nombreProducto: producto.DetArt 595 nombreProducto: producto.DetArt
578 }; 596 };
579 } 597 }
580 }, 598 },
581 size: 'md' 599 size: 'md'
582 } 600 }
583 ); 601 );
584 602
585 modalInstance.result.then(function (despacho) { 603 modalInstance.result.then(function (despacho) {
586 604
587 var articulo = { 605 var articulo = {
588 TIP: $scope.factura.cliente.tipoFactura, 606 TIP: $scope.factura.cliente.tipoFactura,
589 TCO: 'FT', 607 TCO: 'FT',
590 SUC: parseInt($scope.puntoVenta), 608 SUC: parseInt($scope.puntoVenta),
591 ORD: $scope.articulosFiltro().length + 1, 609 ORD: $scope.articulosFiltro().length + 1,
592 SEC: despacho.SEC, 610 SEC: despacho.SEC,
593 ART: despacho.PRO, 611 ART: despacho.PRO,
594 RUB: producto.CodRub, 612 RUB: producto.CodRub,
595 DES: producto.DetArt, 613 DES: producto.DetArt,
596 CAN: despacho.LTS, 614 CAN: despacho.LTS,
597 PUN: producto.PreVen, 615 PUN: producto.PreVen,
598 IVA: producto.IMPIVA, 616 IVA: producto.IMPIVA,
599 NET: producto.IvaCO != 0 ? producto.PreNet : 0, 617 NET: producto.IvaCO != 0 ? producto.PreNet : 0,
600 NEX: producto.IvaCO == 0 ? producto.PreNet : 0, 618 NEX: producto.IvaCO == 0 ? producto.PreNet : 0,
601 IMI: producto.ImpInt, 619 IMI: producto.ImpInt,
602 IMI2: producto.ImpInt2, 620 IMI2: producto.ImpInt2,
603 IMI3: producto.ImpInt3, 621 IMI3: producto.ImpInt3,
604 PUT: producto.PreVen, 622 PUT: producto.PreVen,
605 SUR: despacho.SUR, 623 SUR: despacho.SUR,
606 PLA: despacho.PLA, 624 PLA: despacho.PLA,
607 LUG: despacho.LUG, 625 LUG: despacho.LUG,
608 LEG: $scope.factura.vendedor.CodVen, 626 LEG: $scope.factura.vendedor.CodVen,
609 TUR: $scope.factura.vendedor.TurVen, 627 TUR: $scope.factura.vendedor.TurVen,
610 ORDEN_PRECOMPRA: '', 628 ORDEN_PRECOMPRA: '',
611 ESC: producto.tipoFactura === 'L' ? 1 : 0, 629 ESC: producto.tipoFactura === 'L' ? 1 : 0,
612 CMF: 0, 630 CMF: 0,
613 PTA: 0, 631 PTA: 0,
614 IVS: 0, 632 IVS: 0,
615 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO 633 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO
616 CON: 0, 634 CON: 0,
617 SINO: '', 635 SINO: '',
618 ORD_TRA: 0, 636 ORD_TRA: 0,
619 IMP_DESP: 0, 637 IMP_DESP: 0,
620 PCD: 0, 638 PCD: 0,
621 RTO: '', 639 RTO: '',
622 }; 640 };
623 641
624 crearFacturaService.setearDespachoOcupado({ 642 crearFacturaService.setearDespachoOcupado({
625 surtidor: despacho.SUR, 643 surtidor: despacho.SUR,
626 producto: despacho.PRO, 644 producto: despacho.PRO,
627 carga: despacho.CAR 645 carga: despacho.CAR
628 }) 646 })
629 .then(function () { 647 .then(function () {
630 $scope.factura.articulosFactura.push(articulo); 648 $scope.factura.articulosFactura.push(articulo);
631 $scope.factura.despachos.push(despacho); 649 $scope.factura.despachos.push(despacho);
632 }) 650 })
633 .catch(function (err) { 651 .catch(function (err) {
634 652
635 console.error(err); 653 console.error(err);
636 focaModalService.alert('El despacho esta en uso'); 654 focaModalService.alert('El despacho esta en uso');
637 }); 655 });
638 656
639 }) 657 })
640 .catch(function (err) { 658 .catch(function (err) {
641 console.error(err); 659 console.error(err);
642 }); 660 });
643 661
644 }; 662 };
645 } 663 }
646 664
647 function nombreFuncion(string) { 665 function nombreFuncion(string) {
648 var texto = 'seleccionar'; 666 var texto = 'seleccionar';
649 var arr = string.split(' '); 667 var arr = string.split(' ');
650 arr.forEach(function (palabra) { 668 arr.forEach(function (palabra) {
651 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 669 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
652 texto += palabra; 670 texto += palabra;
653 }); 671 });
654 return texto; 672 return texto;
655 } 673 }
656 674
657 function indicarPassword(vendedor) { 675 function indicarPassword(vendedor) {
658 676
659 return new Promise(function (resolve, reject) { 677 return new Promise(function (resolve, reject) {
660 678
661 function openPrompt() { 679 function openPrompt() {
662 return focaModalService 680 return focaModalService
663 .prompt({ 681 .prompt({
664 titulo: 'Indique Contraseña', 682 titulo: 'Indique Contraseña',
665 value: '', 683 value: '',
666 tipo: 'password' 684 tipo: 'password'
667 }) 685 })
668 .then(function (contraseña) { 686 .then(function (contraseña) {
669 687
670 if (contraseña !== vendedor.ClaVen.trim()) { 688 if (contraseña !== vendedor.ClaVen.trim()) {
671 689
672 focaModalService.alert('Clave incorrecta').then(function () { 690 focaModalService.alert('Clave incorrecta').then(function () {
673 openPrompt(vendedor); 691 openPrompt(vendedor);
674 }); 692 });
675 } else { 693 } else {
676 resolve(); 694 resolve();
677 } 695 }
678 }) 696 })
679 .catch(reject); 697 .catch(reject);
680 } 698 }
681 699
682 openPrompt(); 700 openPrompt();
683 }); 701 });
684 } 702 }
685 703
686 function validarPlanillaVendedor(vendedor) { 704 function validarPlanillaVendedor(vendedor) {
687 705
688 return new Promise(function (resolve, reject) { 706 return new Promise(function (resolve, reject) {
689 707
690 crearFacturaService 708 crearFacturaService
691 .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) 709 .validarPlanillaVendedor(vendedor.CodVen.toString().trim())
692 .then(function (res) { 710 .then(function (res) {
693 711
694 if (!res.data.length) { 712 if (!res.data.length) {
695 713
696 focaModalService 714 focaModalService
697 .alert('No se encontró planilla abierta para el vendedor') 715 .alert('No se encontró planilla abierta para el vendedor')
698 .then(reject); 716 .then(reject);
699 717
700 } else { 718 } else {
701 resolve(); 719 resolve();
702 } 720 }
703 721
704 }) 722 })
705 .catch(function (err) { 723 .catch(function (err) {
706 console.log(err) 724 console.log(err)
707 reject(); 725 reject();
708 }); 726 });
709 }); 727 });
710 } 728 }
711 729
712 function rellenar(relleno, longitud) { 730 function rellenar(relleno, longitud) {
713 relleno = '' + relleno; 731 relleno = '' + relleno;
714 while (relleno.length < longitud) { 732 while (relleno.length < longitud) {
715 relleno = '0' + relleno; 733 relleno = '0' + relleno;
716 } 734 }
717 return relleno; 735 return relleno;
718 } 736 }
719 737
720 $scope.salir = function () { 738 $scope.salir = function () {
721 var confirmacion = false; 739 var confirmacion = false;
722 740
723 if (!angular.equals($scope.factura, $scope.inicial)) { 741 if (!angular.equals($scope.factura, $scope.inicial)) {
724 confirmacion = true; 742 confirmacion = true;
725 } 743 }
726 744
727 if (confirmacion) { 745 if (confirmacion) {
728 focaModalService.confirm( 746 focaModalService.confirm(
729 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 747 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
730 ).then(function (data) { 748 ).then(function (data) {
731 if (data) { 749 if (data) {
732 $location.path('/'); 750 $location.path('/');
733 } 751 }
734 }); 752 });
735 } else { 753 } else {
736 $location.path('/'); 754 $location.path('/');
737 } 755 }
738 } 756 }
739 757
740 function setearFactura(factura) { 758 function setearFactura(factura) {
741 759
742 $scope.$broadcast('cleanCabecera'); 760 $scope.$broadcast('cleanCabecera');
743 761
744 $scope.cabeceras = []; 762 $scope.cabeceras = [];
745 763
746 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 764 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
747 $scope.cabeceras.push({ 765 $scope.cabeceras.push({
748 label: 'Moneda:', 766 label: 'Moneda:',
749 valor: factura.cotizacion.moneda.DETALLE 767 valor: factura.cotizacion.moneda.DETALLE
750 }); 768 });
751 $scope.cabeceras.push({ 769 $scope.cabeceras.push({
752 label: 'Fecha cotizacion:', 770 label: 'Fecha cotizacion:',
753 valor: $filter('date')(factura.cotizacion.FECHA, 771 valor: $filter('date')(factura.cotizacion.FECHA,
754 'dd/MM/yyyy') 772 'dd/MM/yyyy')
755 }); 773 });
756 $scope.cabeceras.push({ 774 $scope.cabeceras.push({
757 label: 'Cotizacion:', 775 label: 'Cotizacion:',
758 valor: $filter('number')(factura.cotizacion.VENDEDOR, 776 valor: $filter('number')(factura.cotizacion.VENDEDOR,
759 '2') 777 '2')
760 }); 778 });
761 } 779 }
762 780
763 if (factura.cotizacion && factura.cotizacion.moneda) { 781 if (factura.cotizacion && factura.cotizacion.moneda) {
764 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 782 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
765 } 783 }
766 784
767 if (factura.cliente && factura.cliente.cod) { 785 if (factura.cliente && factura.cliente.cod) {
768 $scope.cabeceras.push({ 786 $scope.cabeceras.push({
769 label: 'Cliente:', 787 label: 'Cliente:',
770 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + 788 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' +
771 factura.cliente.nom 789 factura.cliente.nom
772 }); 790 });
773 791
774 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 792 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
775 } 793 }
776 794
777 $scope.puntoVenta = rellenar(factura.sucursal, 4); 795 $scope.puntoVenta = rellenar(factura.sucursal, 4);
778 $scope.comprobante = rellenar(factura.numerofactura, 8); 796 $scope.comprobante = rellenar(factura.numerofactura, 8);
779 $scope.factura = factura; 797 $scope.factura = factura;
780 798
781 addArrayCabecera($scope.cabeceras); 799 addArrayCabecera($scope.cabeceras);
782 } 800 }
783 801
784 function getLSFactura() { 802 function getLSFactura() {
785 var factura = JSON.parse($localStorage.factura || null); 803 var factura = JSON.parse($localStorage.factura || null);
786 if (factura) { 804 if (factura) {
787 setearFactura(factura); 805 setearFactura(factura);
788 delete $localStorage.factura; 806 delete $localStorage.factura;
789 } 807 }
790 } 808 }
791 809
792 function addArrayCabecera(array) { 810 function addArrayCabecera(array) {
793 for (var i = 0; i < array.length; i++) { 811 for (var i = 0; i < array.length; i++) {
794 $scope.$broadcast('addCabecera', { 812 $scope.$broadcast('addCabecera', {
795 label: array[i].label, 813 label: array[i].label,
796 valor: array[i].valor 814 valor: array[i].valor
797 }); 815 });
798 } 816 }
799 } 817 }
800 818
801 $scope.cambioEdit = function (articulo, propiedad) { 819 $scope.cambioEdit = function (articulo, propiedad) {
802 if (propiedad === 'cantidad' && articulo.SUR == 0) { 820 if (propiedad === 'cantidad' && articulo.SUR == 0) {
803 articulo.editCantidad = true; 821 articulo.editCantidad = true;
804 } 822 }
805 }; 823 };
806 824
807 $scope.editarArticulo = function (key, articulo, tmpCantidad) { 825 $scope.editarArticulo = function (key, articulo, tmpCantidad) {
808 if (key === 13) { 826 if (key === 13) {
809 if (!articulo.cantidad && tmpCantidad.length === 0) { 827 if (!articulo.cantidad && tmpCantidad.length === 0) {
810 focaModalService.alert('Los valores deben ser al menos 1'); 828 focaModalService.alert('Los valores deben ser al menos 1');
811 return; 829 return;
812 } else if (tmpCantidad === '0') { 830 } else if (tmpCantidad === '0') {
813 focaModalService.alert('Esta ingresando un producto con valor 0'); 831 focaModalService.alert('Esta ingresando un producto con valor 0');
814 return; 832 return;
815 } else if (parseInt(tmpCantidad) < 0) { 833 } else if (parseInt(tmpCantidad) < 0) {
816 focaModalService.alert('Los valores no pueden ser negativos'); 834 focaModalService.alert('Los valores no pueden ser negativos');
817 return; 835 return;
818 } 836 }
819 articulo.CAN = parseInt(tmpCantidad); 837 articulo.CAN = parseInt(tmpCantidad);
820 $scope.getTotal(); 838 $scope.getTotal();
821 articulo.editCantidad = false; 839 articulo.editCantidad = false;
822 } 840 }
823 }; 841 };
824 842
825 $scope.cancelarEditar = function (articulo) { 843 $scope.cancelarEditar = function (articulo) {
826 $scope.tmpCantidad = articulo.CAN; 844 $scope.tmpCantidad = articulo.CAN;
827 articulo.editCantidad = false; 845 articulo.editCantidad = false;
828 }; 846 };
829 847
830 function actualizarCabeceraMoneda(cotizacion) { 848 function actualizarCabeceraMoneda(cotizacion) {
831 849
832 $scope.factura.articulosFactura.forEach(function (art) { 850 $scope.factura.articulosFactura.forEach(function (art) {
833 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); 851 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4);
834 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); 852 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4);
835 }); 853 });
836 854
837 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 855 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
838 $scope.$broadcast('removeCabecera', 'Moneda:'); 856 $scope.$broadcast('removeCabecera', 'Moneda:');
839 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 857 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
840 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 858 $scope.$broadcast('removeCabecera', 'Cotizacion:');
841 } else { 859 } else {
842 $scope.$broadcast('addCabecera', { 860 $scope.$broadcast('addCabecera', {
843 label: 'Moneda:', 861 label: 'Moneda:',
844 valor: cotizacion.moneda.DETALLE 862 valor: cotizacion.moneda.DETALLE
845 }); 863 });
846 $scope.$broadcast('addCabecera', { 864 $scope.$broadcast('addCabecera', {
847 label: 'Fecha cotizacion:', 865 label: 'Fecha cotizacion:',
848 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 866 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
849 }); 867 });
850 $scope.$broadcast('addCabecera', { 868 $scope.$broadcast('addCabecera', {
851 label: 'Cotizacion:', 869 label: 'Cotizacion:',
852 valor: $filter('number')(cotizacion.VENDEDOR, '2') 870 valor: $filter('number')(cotizacion.VENDEDOR, '2')
853 }); 871 });
854 } 872 }
855 } 873 }
856 874
857 function validarGuardar() { 875 function validarGuardar() {
858 876
859 if (angular.equals({}, $scope.factura.vendedor)) { 877 if (angular.equals({}, $scope.factura.vendedor)) {
860 878
861 focaModalService.alert('Seleccione Vendedor'); 879 focaModalService.alert('Seleccione Vendedor');
862 return false; 880 return false;
863 } else if (angular.equals({}, $scope.factura.cliente)) { 881 } else if (angular.equals({}, $scope.factura.cliente)) {
864 882
865 focaModalService.alert('Seleccione Cliente'); 883 focaModalService.alert('Seleccione Cliente');
866 return false; 884 return false;
867 } else if (!$scope.articulosFiltro().length) { 885 } else if (!$scope.articulosFiltro().length) {
868 886
869 focaModalService.alert('Seleccione al menos un Articulo'); 887 focaModalService.alert('Seleccione al menos un Articulo');
870 return false; 888 return false;
871 } 889 }
872 890
873 return true; 891 return true;
874 } 892 }
875 893
876 //recibo la propiedad por la cual quiero obtener el valor 894 //recibo la propiedad por la cual quiero obtener el valor
877 function getImporte(propiedad) { 895 function getImporte(propiedad) {
878 var importe = 0; 896 var importe = 0;
879 897
880 $scope.articulosFiltro().forEach(function (articulo) { 898 $scope.articulosFiltro().forEach(function (articulo) {
881 899
882 if (articulo[propiedad]) { 900 if (articulo[propiedad]) {
883 importe += articulo[propiedad] * articulo.CAN; 901 importe += articulo[propiedad] * articulo.CAN;
884 } 902 }
885 return; 903 return;
886 904
887 }); 905 });
888 906
889 return importe; 907 return importe;
890 } 908 }
891 } 909 }
892 ]); 910 ]);
893 911