Commit f77071c959127f146d6adb732d1821f03280f48c

Authored by Marcelo Puebla
1 parent 802b978f77
Exists in master

Agregada boton a botonera de arriba.

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