Commit e8eab560445d74d884262c799a2b0660901ed7f5

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(efernandez)

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