Commit 854ba16e9bd26dd25f7b53e2e1847049aade9a6e

Authored by Marcelo Puebla
1 parent 47d08ee7f2
Exists in master

Arreglo de algunos errores de sintaxis.

Showing 1 changed file with 6 additions and 6 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', 4 '$localStorage', 'APP',
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) { 7 crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP) {
8 8
9 config(); 9 config();
10 10
11 function config() { 11 function config() {
12 $scope.tmpCantidad = Number; 12 $scope.tmpCantidad = Number;
13 $scope.tmpPrecio = Number; 13 $scope.tmpPrecio = Number;
14 $scope.botonera = crearFacturaService.getBotonera(); 14 $scope.botonera = crearFacturaService.getBotonera();
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', salir); 51 focaBotoneraLateralService.addCustomButton('Salir', 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 cotizacion: $scope.cotizacionPorDefecto || {}, 70 cotizacion: $scope.cotizacionPorDefecto || {},
71 articulosFactura: [], 71 articulosFactura: [],
72 despachos: [] 72 despachos: []
73 }; 73 };
74 74
75 $scope.factura.articulosFactura = []; 75 $scope.factura.articulosFactura = [];
76 $scope.idLista = undefined; 76 $scope.idLista = undefined;
77 77
78 crearRemitoService.getNumeroRemito().then( 78 crearRemitoService.getNumeroRemito().then(
79 function (res) { 79 function (res) {
80 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 80 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
81 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 81 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
82 }, 82 },
83 function (err) { 83 function (err) {
84 focaModalService.alert('La terminal no esta configurada correctamente'); 84 focaModalService.alert('La terminal no esta configurada correctamente');
85 console.info(err); 85 console.info(err);
86 } 86 }
87 ); 87 );
88 88
89 $scope.inicial = angular.copy($scope.factura); 89 $scope.inicial = angular.copy($scope.factura);
90 } 90 }
91 91
92 $scope.$watch('factura', function (newValue) { 92 $scope.$watch('factura', function (newValue) {
93 focaBotoneraLateralService.setPausarData({ 93 focaBotoneraLateralService.setPausarData({
94 label: 'factura', 94 label: 'factura',
95 val: newValue 95 val: newValue
96 }); 96 });
97 }, true); 97 }, true);
98 98
99 $scope.seleccionarFormaDePago = function () { 99 $scope.seleccionarFormaDePago = function () {
100 if (!validarGuardar()) return; 100 if (!validarGuardar()) return;
101 var modalInstance = $uibModal.open( 101 var modalInstance = $uibModal.open(
102 { 102 {
103 templateUrl: 'modal-forma-pago.html', 103 templateUrl: 'modal-forma-pago.html',
104 controller: 'focaModalFormaPagoController', 104 controller: 'focaModalFormaPagoController',
105 resolve: { 105 resolve: {
106 filters: function () { return null; }, 106 filters: function () { return null; },
107 }, 107 },
108 size: 'lg', 108 size: 'lg',
109 } 109 }
110 ); 110 );
111 modalInstance.result 111 modalInstance.result
112 .then(function (data) { 112 .then(function (data) {
113 console.log(data); 113 console.log(data);
114 $scope.crearFactura(); 114 $scope.crearFactura();
115 }) 115 })
116 .catch(function (e) { console.error(e); }); 116 .catch(function (e) { console.error(e); });
117 }; 117 };
118 118
119 $scope.crearFactura = function () { 119 $scope.crearFactura = function () {
120 120
121 var save = { 121 var save = {
122 factura: { 122 factura: {
123 123
124 BONIF: 0, 124 BONIF: 0,
125 CLI: $scope.factura.cliente.cod, 125 CLI: $scope.factura.cliente.cod,
126 CUI: $scope.factura.cliente.cuit, 126 CUI: $scope.factura.cliente.cuit,
127 CTA: $scope.factura.cliente.cod, 127 CTA: $scope.factura.cliente.cod,
128 DC1: '', 128 DC1: '',
129 DC2: '', 129 DC2: '',
130 DE1: '', 130 DE1: '',
131 DOM: $scope.factura.cliente.DOM, 131 DOM: $scope.factura.cliente.DOM,
132 FACAUT: 0, 132 FACAUT: 0,
133 DTO: 0, 133 DTO: 0,
134 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), 134 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'),
135 FEC_ANT: '19000101', 135 FEC_ANT: '19000101',
136 FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente 136 FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente
137 IDEXCEPCION: 0, 137 IDEXCEPCION: 0,
138 IDLP: $scope.factura.cliente.mod.trim() || 0, 138 IDLP: $scope.factura.cliente.mod.trim() || 0,
139 IDPERSONERIA: 0, 139 IDPERSONERIA: 0,
140 IMI: 0, // TODO 140 IMI: 0, // TODO
141 IMI2: 0, // TODO 141 IMI2: 0, // TODO
142 IMI3: 0, // TODO 142 IMI3: 0, // TODO
143 IMP_LEY: 0, 143 IMP_LEY: 0,
144 IRI: 0, // TODO 144 IRI: 0, // TODO
145 IRS: 0, 145 IRS: 0,
146 LEG: '', 146 LEG: '',
147 LUG: $scope.factura.vendedor.LugVen, 147 LUG: $scope.factura.vendedor.LugVen,
148 MK_M: 0, 148 MK_M: 0,
149 NEE: 0, // TODO 149 NEE: 0, // TODO
150 NET: 0, // TODO 150 NET: 0, // TODO
151 NFI: '', 151 NFI: '',
152 NNP: 0, 152 NNP: 0,
153 NOM: $scope.factura.cliente.nom, 153 NOM: $scope.factura.cliente.nom,
154 OPE: $scope.factura.vendedor.CodVen, 154 OPE: $scope.factura.vendedor.CodVen,
155 PAG: $scope.getTotal(), 155 PAG: $scope.getTotal(),
156 PER: 0, 156 PER: 0,
157 PER_IVA: 0, 157 PER_IVA: 0,
158 PLA: $scope.factura.vendedor.NplVen, 158 PLA: $scope.factura.vendedor.NplVen,
159 PRO: '', 159 PRO: '',
160 REC_ANT: 0, 160 REC_ANT: 0,
161 SUC: parseInt($scope.puntoVenta), 161 SUC: parseInt($scope.puntoVenta),
162 TCA: 1, 162 TCA: 1,
163 TCO: 'FT', 163 TCO: 'FT',
164 TFI: '', 164 TFI: '',
165 TIP: $scope.factura.cliente.tipoFactura, 165 TIP: $scope.factura.cliente.tipoFactura,
166 TIV: 0, // TODO 166 TIV: 0, // TODO
167 TOT: $scope.getTotal(), 167 TOT: $scope.getTotal(),
168 TUR: 0, // TODO 168 TUR: 0, // TODO
169 VEN: $scope.factura.vendedor.CodVen, 169 VEN: $scope.factura.vendedor.CodVen,
170 VTO_CLI: '', 170 VTO_CLI: '',
171 ZON: 1, // TODO 171 ZON: 1, // TODO
172 OBSERVACIONES: $scope.factura.observaciones 172 OBSERVACIONES: $scope.factura.observaciones
173 }, 173 },
174 cuerpo: $scope.articulosFiltro(), 174 cuerpo: $scope.articulosFiltro(),
175 despachos: $scope.factura.despachos 175 despachos: $scope.factura.despachos
176 }; 176 };
177 177
178 crearFacturaService.guardarFactura(save).then(function (res) { 178 crearFacturaService.guardarFactura(save).then(function (res) {
179 179
180 focaBotoneraLateralService.endGuardar(true); 180 focaBotoneraLateralService.endGuardar(true);
181 181
182 focaModalService.alert('Comprobante guardado con éxito'); 182 focaModalService.alert('Comprobante guardado con éxito');
183 183
184 config(); 184 config();
185 185
186 }).catch(function (err) { 186 }).catch(function (err) {
187 focaModalService.alert('Hubo un error al guardar la factura'); 187 focaModalService.alert('Hubo un error al guardar la factura');
188 console.log(err); 188 console.log(err);
189 }); 189 });
190 190
191 }; 191 };
192 192
193 $scope.seleccionarCliente = function () { 193 $scope.seleccionarCliente = function () {
194 194
195 var modalInstance = $uibModal.open( 195 var modalInstance = $uibModal.open(
196 { 196 {
197 ariaLabelledBy: 'Busqueda de Cliente', 197 ariaLabelledBy: 'Busqueda de Cliente',
198 templateUrl: 'foca-busqueda-cliente-modal.html', 198 templateUrl: 'foca-busqueda-cliente-modal.html',
199 controller: 'focaBusquedaClienteModalController', 199 controller: 'focaBusquedaClienteModalController',
200 resolve: { 200 resolve: {
201 vendedor: function () { return null; }, 201 vendedor: function () { return null; },
202 cobrador: function () { return null; } 202 cobrador: function () { return null; }
203 }, 203 },
204 size: 'lg' 204 size: 'lg'
205 } 205 }
206 ); 206 );
207 modalInstance.result.then( 207 modalInstance.result.then(
208 function (cliente) { 208 function (cliente) {
209 var modalInstance = $uibModal.open( 209 var modalInstance = $uibModal.open(
210 { 210 {
211 templateUrl: 'modal-estado-cuenta.html', 211 templateUrl: 'modal-estado-cuenta.html',
212 controller: 'focaModalEstadoCuentaController', 212 controller: 'focaModalEstadoCuentaController',
213 size: 'lg', 213 size: 'lg',
214 resolve: { 214 resolve: {
215 parametros: function () { return { idCliente: cliente.cod }; }, 215 parametros: function () { return { idCliente: cliente.cod }; },
216 } 216 }
217 } 217 }
218 ); 218 );
219 modalInstance.result 219 modalInstance.result
220 .then(function (data) { 220 .then(function (data) {
221 221
222 $scope.factura.cliente = cliente; 222 $scope.factura.cliente = cliente;
223 223
224 $scope.$broadcast('addCabecera', { 224 $scope.$broadcast('addCabecera', {
225 label: 'Cliente:', 225 label: 'Cliente:',
226 valor: $filter('rellenarDigitos')(cliente.cod, 3) + 226 valor: $filter('rellenarDigitos')(cliente.cod, 3) +
227 ' - ' + cliente.nom 227 ' - ' + cliente.nom
228 }); 228 });
229 229
230 $filter('filter')($scope.botonera, 230 $filter('filter')($scope.botonera,
231 { label: 'Cliente' })[0].checked = true; 231 { label: 'Cliente' })[0].checked = true;
232 232
233 $scope.$broadcast('addCabecera', { 233 $scope.$broadcast('addCabecera', {
234 label: 'Tipo de pago: ', 234 label: 'Tipo de pago: ',
235 valor: data 235 valor: data
236 }); 236 });
237 }) 237 })
238 .catch(function () { 238 .catch(function () {
239 239
240 $scope.seleccionarCliente(); 240 $scope.seleccionarCliente();
241 }); 241 });
242 242
243 }, function () { 243 }, function () {
244 } 244 }
245 ); 245 );
246 246
247 }; 247 };
248 248
249 $scope.seleccionarVendedor = function () { 249 $scope.seleccionarVendedor = function () {
250 var parametrosModal = { 250 var parametrosModal = {
251 titulo: 'Búsqueda vendedores', 251 titulo: 'Búsqueda vendedores',
252 query: '/vendedor-playa', 252 query: '/vendedor-playa',
253 columnas: [ 253 columnas: [
254 { 254 {
255 propiedad: 'CodVen', 255 propiedad: 'CodVen',
256 nombre: 'Código', 256 nombre: 'Código',
257 filtro: { 257 filtro: {
258 nombre: 'rellenarDigitos', 258 nombre: 'rellenarDigitos',
259 parametro: 3 259 parametro: 3
260 } 260 }
261 }, 261 },
262 { 262 {
263 propiedad: 'NomVen', 263 propiedad: 'NomVen',
264 nombre: 'Nombre' 264 nombre: 'Nombre'
265 } 265 }
266 ], 266 ],
267 size: 'md' 267 size: 'md'
268 }; 268 };
269 focaModalService.modal(parametrosModal).then( 269 focaModalService.modal(parametrosModal).then(
270 function (vendedor) { 270 function (vendedor) {
271 271
272 indicarPassword(vendedor) 272 indicarPassword(vendedor)
273 .then(function () { 273 .then(function () {
274 validarPlanillaVendedor(vendedor) 274 validarPlanillaVendedor(vendedor)
275 .then(function () { 275 .then(function () {
276 276
277 $filter('filter')($scope.botonera, { 277 $filter('filter')($scope.botonera, {
278 label: 'Vendedor' 278 label: 'Vendedor'
279 })[0].checked = true; 279 })[0].checked = true;
280 280
281 $scope.$broadcast('addCabecera', { 281 $scope.$broadcast('addCabecera', {
282 label: 'Vendedor:', 282 label: 'Vendedor:',
283 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + 283 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) +
284 ' - ' + 284 ' - ' +
285 vendedor.NomVen 285 vendedor.NomVen
286 }); 286 });
287 287
288 $scope.factura.vendedor = vendedor; 288 $scope.factura.vendedor = vendedor;
289 289
290 getProductosByPlanilla(vendedor.NplVen); 290 getProductosByPlanilla(vendedor.NplVen);
291 }) 291 })
292 .catch($scope.seleccionarVendedor); 292 .catch($scope.seleccionarVendedor);
293 }) 293 })
294 .catch(function (err) { 294 .catch(function (err) {
295 console.log(err) 295 console.log(err);
296 }); 296 });
297 297
298 }, function () { } 298 }, function () { }
299 ); 299 );
300 }; 300 };
301 301
302 $scope.seleccionarMoneda = function () { 302 $scope.seleccionarMoneda = function () {
303 303
304 var parametrosModal = { 304 var parametrosModal = {
305 titulo: 'Búsqueda de monedas', 305 titulo: 'Búsqueda de monedas',
306 query: '/moneda', 306 query: '/moneda',
307 columnas: [ 307 columnas: [
308 { 308 {
309 propiedad: 'DETALLE', 309 propiedad: 'DETALLE',
310 nombre: 'Nombre' 310 nombre: 'Nombre'
311 }, 311 },
312 { 312 {
313 propiedad: 'SIMBOLO', 313 propiedad: 'SIMBOLO',
314 nombre: 'Símbolo' 314 nombre: 'Símbolo'
315 } 315 }
316 ], 316 ],
317 size: 'md' 317 size: 'md'
318 }; 318 };
319 focaModalService.modal(parametrosModal).then( 319 focaModalService.modal(parametrosModal).then(
320 function (moneda) { 320 function (moneda) {
321 321
322 if (moneda.ID !== 1) { 322 if (moneda.ID !== 1) {
323 $scope.abrirModalCotizacion(moneda); 323 $scope.abrirModalCotizacion(moneda);
324 return; 324 return;
325 } 325 }
326 326
327 crearRemitoService.getCotizacionByIdMoneda(1) 327 crearRemitoService.getCotizacionByIdMoneda(1)
328 .then(function (res) { 328 .then(function (res) {
329 329
330 cotizacionPArgentino = res.data[0].cotizaciones[0]; 330 var cotizacionPArgentino = res.data[0].cotizaciones[0];
331 cotizacionPArgentino.moneda = moneda; 331 cotizacionPArgentino.moneda = moneda;
332 332
333 actualizarCabeceraMoneda(cotizacionPArgentino); 333 actualizarCabeceraMoneda(cotizacionPArgentino);
334 334
335 $scope.remito.cotizacion = cotizacionPArgentino; 335 $scope.remito.cotizacion = cotizacionPArgentino;
336 }); 336 });
337 }, function () { 337 }, function () {
338 338
339 } 339 }
340 ); 340 );
341 }; 341 };
342 342
343 $scope.abrirModalCotizacion = function (moneda) { 343 $scope.abrirModalCotizacion = function (moneda) {
344 var modalInstance = $uibModal.open( 344 var modalInstance = $uibModal.open(
345 { 345 {
346 ariaLabelledBy: 'Busqueda de Cotización', 346 ariaLabelledBy: 'Busqueda de Cotización',
347 templateUrl: 'modal-cotizacion.html', 347 templateUrl: 'modal-cotizacion.html',
348 controller: 'focaModalCotizacionController', 348 controller: 'focaModalCotizacionController',
349 size: 'lg', 349 size: 'lg',
350 resolve: { idMoneda: function () { return moneda.ID; } } 350 resolve: { idMoneda: function () { return moneda.ID; } }
351 } 351 }
352 ); 352 );
353 modalInstance.result.then( 353 modalInstance.result.then(
354 function (cotizacion) { 354 function (cotizacion) {
355 355
356 cotizacion.moneda = moneda; 356 cotizacion.moneda = moneda;
357 actualizarCabeceraMoneda(cotizacion); 357 actualizarCabeceraMoneda(cotizacion);
358 $scope.factura.cotizacion = cotizacion; 358 $scope.factura.cotizacion = cotizacion;
359 359
360 }, function () { 360 }, function () {
361 361
362 } 362 }
363 ); 363 );
364 }; 364 };
365 365
366 $scope.seleccionarObservaciones = function () { 366 $scope.seleccionarObservaciones = function () {
367 var observacion = { 367 var observacion = {
368 titulo: 'Ingrese Observaciones', 368 titulo: 'Ingrese Observaciones',
369 value: $scope.factura.observaciones, 369 value: $scope.factura.observaciones,
370 maxlength: 155, 370 maxlength: 155,
371 textarea: true 371 textarea: true
372 }; 372 };
373 373
374 focaModalService 374 focaModalService
375 .prompt(observacion) 375 .prompt(observacion)
376 .then(function (observaciones) { 376 .then(function (observaciones) {
377 $scope.factura.observaciones = observaciones; 377 $scope.factura.observaciones = observaciones;
378 }); 378 });
379 }; 379 };
380 380
381 $scope.articulosFiltro = function () { 381 $scope.articulosFiltro = function () {
382 return $scope.factura.articulosFactura.filter(function (articulo) { 382 return $scope.factura.articulosFactura.filter(function (articulo) {
383 return !articulo.desactivado; 383 return !articulo.desactivado;
384 }); 384 });
385 }; 385 };
386 386
387 $scope.getTotal = function () { 387 $scope.getTotal = function () {
388 388
389 var total = 0; 389 var total = 0;
390 390
391 $scope.articulosFiltro().forEach(function (articulo) { 391 $scope.articulosFiltro().forEach(function (articulo) {
392 total += articulo.PUN * articulo.CAN; 392 total += articulo.PUN * articulo.CAN;
393 }); 393 });
394 394
395 return parseFloat(total.toFixed(2)); 395 return parseFloat(total.toFixed(2));
396 }; 396 };
397 397
398 $scope.quitarDespacho = function (articulo, index) { 398 $scope.quitarDespacho = function (articulo, index) {
399 399
400 crearFacturaService 400 crearFacturaService
401 .setearDespachoDesocupado({ 401 .setearDespachoDesocupado({
402 surtidor: $scope.factura.despachos[index].SUR, 402 surtidor: $scope.factura.despachos[index].SUR,
403 producto: $scope.factura.despachos[index].PRO, 403 producto: $scope.factura.despachos[index].PRO,
404 carga: $scope.factura.despachos[index].CAR, 404 carga: $scope.factura.despachos[index].CAR,
405 planilla: $scope.factura.despachos[index].PLA 405 planilla: $scope.factura.despachos[index].PLA
406 }) 406 })
407 .then(function () { 407 .then(function () {
408 articulo.desactivado = true; 408 articulo.desactivado = true;
409 $scope.factura.despachos.splice(index, 1); 409 $scope.factura.despachos.splice(index, 1);
410 }) 410 })
411 .catch(function () { 411 .catch(function () {
412 focaModalService.alert('Hubo un error al desasociar este despacho'); 412 focaModalService.alert('Hubo un error al desasociar este despacho');
413 }); 413 });
414 }; 414 };
415 415
416 function getProductosByPlanilla(numeroPlanilla) { 416 function getProductosByPlanilla(numeroPlanilla) {
417 417
418 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { 418 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) {
419 419
420 res.data.forEach(function (producto) { 420 res.data.forEach(function (producto) {
421 421
422 $scope.botonera.push({ 422 $scope.botonera.push({
423 label: producto.DetArt, 423 label: producto.DetArt,
424 image: 'productos.png' 424 image: 'productos.png'
425 }); 425 });
426 426
427 427
428 crearFuncionesProductos(producto); 428 crearFuncionesProductos(producto);
429 429
430 }); 430 });
431 }); 431 });
432 } 432 }
433 433
434 function crearFuncionesProductos(producto) { 434 function crearFuncionesProductos(producto) {
435 435
436 $scope[nombreFuncion(producto.DetArt)] = function () { 436 $scope[nombreFuncion(producto.DetArt)] = function () {
437 437
438 if (angular.equals($scope.factura.cliente, {})) { 438 if (angular.equals($scope.factura.cliente, {})) {
439 focaModalService.alert('Seleccione cliente'); 439 focaModalService.alert('Seleccione cliente');
440 return; 440 return;
441 } 441 }
442 442
443 var modalInstance = $uibModal.open( 443 var modalInstance = $uibModal.open(
444 { 444 {
445 templateUrl: 'modal-combustibles.html', 445 templateUrl: 'modal-combustibles.html',
446 controller: 'focaModalCombustiblesController', 446 controller: 'focaModalCombustiblesController',
447 resolve: { 447 resolve: {
448 parametros: function () { 448 parametros: function () {
449 return { 449 return {
450 despachos: producto.despachos, 450 despachos: producto.despachos,
451 nombreProducto: producto.DetArt 451 nombreProducto: producto.DetArt
452 } 452 };
453 } 453 }
454 }, 454 },
455 size: 'md' 455 size: 'md'
456 } 456 }
457 ); 457 );
458 458
459 modalInstance.result.then(function (despacho) { 459 modalInstance.result.then(function (despacho) {
460 460
461 var articulo = { 461 var articulo = {
462 TIP: $scope.factura.cliente.tipoFactura, 462 TIP: $scope.factura.cliente.tipoFactura,
463 TCO: 'FT', 463 TCO: 'FT',
464 SUC: parseInt($scope.puntoVenta), 464 SUC: parseInt($scope.puntoVenta),
465 ORD: $scope.articulosFiltro().length + 1, 465 ORD: $scope.articulosFiltro().length + 1,
466 SEC: despacho.SEC, 466 SEC: despacho.SEC,
467 ART: despacho.PRO, 467 ART: despacho.PRO,
468 RUB: producto.CodRub, 468 RUB: producto.CodRub,
469 DES: producto.DetArt, 469 DES: producto.DetArt,
470 CAN: despacho.LTS, 470 CAN: despacho.LTS,
471 PUN: producto.PreVen, // TODO 471 PUN: producto.PreVen, // TODO
472 IVA: producto.IMPIVA, // TODO 472 IVA: producto.IMPIVA, // TODO
473 NET: 0, // TODO 473 NET: 0, // TODO
474 NEX: 0, // TODO 474 NEX: 0, // TODO
475 IMI: producto.ImpInt, // TODO 475 IMI: producto.ImpInt, // TODO
476 IMI2: producto.ImpInt2, // TODO 476 IMI2: producto.ImpInt2, // TODO
477 IMI3: producto.ImpInt3, // TODO 477 IMI3: producto.ImpInt3, // TODO
478 PUT: producto.PreNet, // TODO 478 PUT: producto.PreNet, // TODO
479 SUR: despacho.SUR, 479 SUR: despacho.SUR,
480 PLA: despacho.PLA, 480 PLA: despacho.PLA,
481 LUG: despacho.LUG, 481 LUG: despacho.LUG,
482 LEG: $scope.factura.vendedor.CodVen, 482 LEG: $scope.factura.vendedor.CodVen,
483 TUR: $scope.factura.vendedor.TurVen, 483 TUR: $scope.factura.vendedor.TurVen,
484 ORDEN_PRECOMPRA: '', 484 ORDEN_PRECOMPRA: '',
485 ESC: producto.tipoFactura == 'L' ? 1 : 0, 485 ESC: producto.tipoFactura === 'L' ? 1 : 0,
486 CMF: 0, 486 CMF: 0,
487 PTA: 0, 487 PTA: 0,
488 IVS: 0, 488 IVS: 0,
489 TIVA: 0, 489 TIVA: 0,
490 CON: 0, 490 CON: 0,
491 SINO: '', 491 SINO: '',
492 ORD_TRA: 0, 492 ORD_TRA: 0,
493 IMP_DESP: 0, 493 IMP_DESP: 0,
494 PCD: 0, 494 PCD: 0,
495 RTO: '' 495 RTO: ''
496 }; 496 };
497 497
498 crearFacturaService.setearDespachoOcupado({ 498 crearFacturaService.setearDespachoOcupado({
499 surtidor: despacho.SUR, 499 surtidor: despacho.SUR,
500 producto: despacho.PRO, 500 producto: despacho.PRO,
501 carga: despacho.CAR 501 carga: despacho.CAR
502 }) 502 })
503 .then(function () { 503 .then(function () {
504 $scope.factura.articulosFactura.push(articulo); 504 $scope.factura.articulosFactura.push(articulo);
505 $scope.factura.despachos.push(despacho); 505 $scope.factura.despachos.push(despacho);
506 }) 506 })
507 .catch(function (err) { 507 .catch(function (err) {
508 508
509 focaModalService.alert('El despacho esta en uso'); 509 focaModalService.alert('El despacho esta en uso');
510 }); 510 });
511 511
512 }) 512 })
513 .catch(function (err) { 513 .catch(function (err) {
514 console.log(err); 514 console.log(err);
515 }); 515 });
516 516
517 }; 517 };
518 } 518 }
519 519
520 function nombreFuncion(string) { 520 function nombreFuncion(string) {
521 var texto = 'seleccionar'; 521 var texto = 'seleccionar';
522 var arr = string.split(' '); 522 var arr = string.split(' ');
523 arr.forEach(function (palabra) { 523 arr.forEach(function (palabra) {
524 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 524 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
525 texto += palabra; 525 texto += palabra;
526 }); 526 });
527 return texto; 527 return texto;
528 } 528 }
529 529
530 function indicarPassword(vendedor) { 530 function indicarPassword(vendedor) {
531 531
532 return new Promise(function (resolve, reject) { 532 return new Promise(function (resolve, reject) {
533 533
534 focaModalService 534 focaModalService
535 .prompt({ 535 .prompt({
536 titulo: 'Indique Contraseña', 536 titulo: 'Indique Contraseña',
537 value: '' 537 value: ''
538 }) 538 })
539 .then(function (contraseña) { 539 .then(function (contraseña) {
540 540
541 if (contraseña != vendedor.ClaVen.trim()) { 541 if (contraseña !== vendedor.ClaVen.trim()) {
542 542
543 focaModalService.alert('Clave incorrecta').then(function () { 543 focaModalService.alert('Clave incorrecta').then(function () {
544 indicarPassword(vendedor); 544 indicarPassword(vendedor);
545 }); 545 });
546 } else { 546 } else {
547 resolve(); 547 resolve();
548 } 548 }
549 }) 549 })
550 .catch(reject); 550 .catch(reject);
551 }); 551 });
552 } 552 }
553 553
554 function validarPlanillaVendedor(vendedor) { 554 function validarPlanillaVendedor(vendedor) {
555 555
556 return new Promise(function (resolve, reject) { 556 return new Promise(function (resolve, reject) {
557 557
558 crearFacturaService 558 crearFacturaService
559 .validarPlanillaVendedor(vendedor.CodVen.trim()) 559 .validarPlanillaVendedor(vendedor.CodVen.trim())
560 .then(function (res) { 560 .then(function (res) {
561 561
562 if (!res.data.length) { 562 if (!res.data.length) {
563 563
564 focaModalService 564 focaModalService
565 .alert('No se encontró planilla abierta para el vendedor') 565 .alert('No se encontró planilla abierta para el vendedor')
566 .then(reject); 566 .then(reject);
567 567
568 } else { 568 } else {
569 resolve(); 569 resolve();
570 } 570 }
571 571
572 }) 572 })
573 .catch(reject); 573 .catch(reject);
574 }); 574 });
575 } 575 }
576 576
577 function rellenar(relleno, longitud) { 577 function rellenar(relleno, longitud) {
578 relleno = '' + relleno; 578 relleno = '' + relleno;
579 while (relleno.length < longitud) { 579 while (relleno.length < longitud) {
580 relleno = '0' + relleno; 580 relleno = '0' + relleno;
581 } 581 }
582 return relleno; 582 return relleno;
583 } 583 }
584 584
585 function salir() { 585 function salir() {
586 var confirmacion = false; 586 var confirmacion = false;
587 587
588 if (!angular.equals($scope.factura, $scope.inicial)) { 588 if (!angular.equals($scope.factura, $scope.inicial)) {
589 confirmacion = true; 589 confirmacion = true;
590 } 590 }
591 591
592 if (confirmacion) { 592 if (confirmacion) {
593 focaModalService.confirm( 593 focaModalService.confirm(
594 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 594 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
595 ).then(function (data) { 595 ).then(function (data) {
596 if (data) { 596 if (data) {
597 $location.path('/'); 597 $location.path('/');
598 } 598 }
599 }); 599 });
600 } else { 600 } else {
601 $location.path('/'); 601 $location.path('/');
602 } 602 }
603 } 603 }
604 604
605 function setearFactura(factura) { 605 function setearFactura(factura) {
606 606
607 $scope.$broadcast('cleanCabecera'); 607 $scope.$broadcast('cleanCabecera');
608 608
609 $scope.cabeceras = []; 609 $scope.cabeceras = [];
610 610
611 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 611 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
612 $scope.cabeceras.push({ 612 $scope.cabeceras.push({
613 label: 'Moneda:', 613 label: 'Moneda:',
614 valor: factura.cotizacion.moneda.DETALLE 614 valor: factura.cotizacion.moneda.DETALLE
615 }); 615 });
616 $scope.cabeceras.push({ 616 $scope.cabeceras.push({
617 label: 'Fecha cotizacion:', 617 label: 'Fecha cotizacion:',
618 valor: $filter('date')(factura.cotizacion.FECHA, 618 valor: $filter('date')(factura.cotizacion.FECHA,
619 'dd/MM/yyyy') 619 'dd/MM/yyyy')
620 }); 620 });
621 $scope.cabeceras.push({ 621 $scope.cabeceras.push({
622 label: 'Cotizacion:', 622 label: 'Cotizacion:',
623 valor: $filter('number')(factura.cotizacion.VENDEDOR, 623 valor: $filter('number')(factura.cotizacion.VENDEDOR,
624 '2') 624 '2')
625 }); 625 });
626 } 626 }
627 627
628 if (factura.cotizacion && factura.cotizacion.moneda) { 628 if (factura.cotizacion && factura.cotizacion.moneda) {
629 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 629 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
630 } 630 }
631 631
632 if (factura.cliente && factura.cliente.cod) { 632 if (factura.cliente && factura.cliente.cod) {
633 $scope.cabeceras.push({ 633 $scope.cabeceras.push({
634 label: 'Cliente:', 634 label: 'Cliente:',
635 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + 635 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' +
636 factura.cliente.nom 636 factura.cliente.nom
637 }); 637 });
638 638
639 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 639 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
640 } 640 }
641 641
642 $scope.puntoVenta = rellenar(factura.sucursal, 4); 642 $scope.puntoVenta = rellenar(factura.sucursal, 4);
643 $scope.comprobante = rellenar(factura.numerofactura, 8); 643 $scope.comprobante = rellenar(factura.numerofactura, 8);
644 $scope.factura = factura; 644 $scope.factura = factura;
645 645
646 addArrayCabecera($scope.cabeceras); 646 addArrayCabecera($scope.cabeceras);
647 } 647 }
648 648
649 function getLSFactura() { 649 function getLSFactura() {
650 var factura = JSON.parse($localStorage.factura || null); 650 var factura = JSON.parse($localStorage.factura || null);
651 if (factura) { 651 if (factura) {
652 setearFactura(factura); 652 setearFactura(factura);
653 delete $localStorage.factura; 653 delete $localStorage.factura;
654 } 654 }
655 } 655 }
656 656
657 function addArrayCabecera(array) { 657 function addArrayCabecera(array) {
658 for (var i = 0; i < array.length; i++) { 658 for (var i = 0; i < array.length; i++) {
659 $scope.$broadcast('addCabecera', { 659 $scope.$broadcast('addCabecera', {
660 label: array[i].label, 660 label: array[i].label,
661 valor: array[i].valor 661 valor: array[i].valor
662 }); 662 });
663 } 663 }
664 } 664 }
665 665
666 function actualizarCabeceraMoneda(cotizacion) { 666 function actualizarCabeceraMoneda(cotizacion) {
667 667
668 $scope.factura.articulosFactura.forEach(function (art) { 668 $scope.factura.articulosFactura.forEach(function (art) {
669 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); 669 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4);
670 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); 670 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4);
671 }); 671 });
672 672
673 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 673 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
674 $scope.$broadcast('removeCabecera', 'Moneda:'); 674 $scope.$broadcast('removeCabecera', 'Moneda:');
675 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 675 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
676 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 676 $scope.$broadcast('removeCabecera', 'Cotizacion:');
677 } else { 677 } else {
678 $scope.$broadcast('addCabecera', { 678 $scope.$broadcast('addCabecera', {
679 label: 'Moneda:', 679 label: 'Moneda:',
680 valor: cotizacion.moneda.DETALLE 680 valor: cotizacion.moneda.DETALLE
681 }); 681 });
682 $scope.$broadcast('addCabecera', { 682 $scope.$broadcast('addCabecera', {
683 label: 'Fecha cotizacion:', 683 label: 'Fecha cotizacion:',
684 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 684 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
685 }); 685 });
686 $scope.$broadcast('addCabecera', { 686 $scope.$broadcast('addCabecera', {
687 label: 'Cotizacion:', 687 label: 'Cotizacion:',
688 valor: $filter('number')(cotizacion.VENDEDOR, '2') 688 valor: $filter('number')(cotizacion.VENDEDOR, '2')
689 }); 689 });
690 } 690 }
691 } 691 }
692 692
693 function validarGuardar() { 693 function validarGuardar() {
694 694
695 if (angular.equals({}, $scope.factura.vendedor)) { 695 if (angular.equals({}, $scope.factura.vendedor)) {
696 696
697 focaModalService.alert('Seleccione Vendedor'); 697 focaModalService.alert('Seleccione Vendedor');
698 return false; 698 return false;
699 } else if (angular.equals({}, $scope.factura.cliente)) { 699 } else if (angular.equals({}, $scope.factura.cliente)) {
700 700
701 focaModalService.alert('Seleccione Cliente') 701 focaModalService.alert('Seleccione Cliente');
702 return false; 702 return false;
703 } else if (!$scope.articulosFiltro().length) { 703 } else if (!$scope.articulosFiltro().length) {
704 704
705 focaModalService.alert('Seleccione al menos un Articulo'); 705 focaModalService.alert('Seleccione al menos un Articulo');
706 return false; 706 return false;
707 } 707 }
708 708
709 return true; 709 return true;
710 } 710 }
711 } 711 }
712 ]); 712 ]);
713 713