Commit 66254e618dc2661ca3e813f7c25bfdac09ac50d2

Authored by Eric Fernandez
1 parent 241cae264b
Exists in master

top despachos

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: 'Forma de pago: ', 292 label: 'Forma 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 $scope.topDespachos = res.data[0][0].CID;
513
514 res.data.slice(1, res.data.length).forEach(function (producto) {
513 515
514 $scope.botoneraProductos.push({ 516 $scope.botoneraProductos.push({
515 label: producto.DetArt, 517 label: producto.DetArt,
516 image: producto.nombreImagen, 518 image: producto.nombreImagen,
517 imageDefault: 'productoDefault.png' 519 imageDefault: 'productoDefault.png'
518 }); 520 });
519 521
520 crearFuncionesProductos(producto); 522 crearFuncionesProductos(producto);
521 }); 523 });
522 524
523 $scope.botoneraProductos.push({ 525 $scope.botoneraProductos.push({
524 label: 'Ultimos despachos', 526 label: 'Ultimos despachos',
525 image: 'ultimos-despachos.png', 527 image: 'ultimos-despachos.png',
526 imageDefault: 'productoDefault.png' 528 imageDefault: 'productoDefault.png'
527 }); 529 });
528 }); 530 });
529 } 531 }
530 532
531 $scope.seleccionarBusquedaProductos = function () { 533 $scope.seleccionarBusquedaProductos = function () {
532 534
533 if (angular.equals({}, $scope.factura.vendedor)) { 535 if (angular.equals({}, $scope.factura.vendedor)) {
534 536
535 focaModalService.alert('Seleccione Vendedor'); 537 focaModalService.alert('Seleccione Vendedor');
536 return false; 538 return false;
537 } 539 }
538 540
539 var modalInstance = $uibModal.open( 541 var modalInstance = $uibModal.open(
540 { 542 {
541 ariaLabelledBy: 'Busqueda de Productos', 543 ariaLabelledBy: 'Busqueda de Productos',
542 templateUrl: 'modal-busqueda-productos.html', 544 templateUrl: 'modal-busqueda-productos.html',
543 controller: 'modalBusquedaProductosCtrl', 545 controller: 'modalBusquedaProductosCtrl',
544 resolve: { 546 resolve: {
545 parametroProducto: { 547 parametroProducto: {
546 idLista: null, 548 idLista: null,
547 cotizacion: $scope.factura.cotizacion.VENDEDOR, 549 cotizacion: $scope.factura.cotizacion.VENDEDOR,
548 simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, 550 simbolo: $scope.factura.cotizacion.moneda.SIMBOLO,
549 buscarTodos: true 551 buscarTodos: true
550 } 552 }
551 }, 553 },
552 size: 'lg' 554 size: 'lg'
553 } 555 }
554 ); 556 );
555 557
556 modalInstance.result 558 modalInstance.result
557 .then(function (producto) { 559 .then(function (producto) {
558 560
559 var articulo = { 561 var articulo = {
560 TIP: $scope.factura.cliente.tipoFactura, 562 TIP: $scope.factura.cliente.tipoFactura,
561 TCO: 'FT', 563 TCO: 'FT',
562 SUC: parseInt($scope.puntoVenta), 564 SUC: parseInt($scope.puntoVenta),
563 ORD: $scope.articulosFiltro().length + 1, 565 ORD: $scope.articulosFiltro().length + 1,
564 SEC: producto.sector, 566 SEC: producto.sector,
565 ART: producto.codigo, 567 ART: producto.codigo,
566 RUB: producto.CodRub, 568 RUB: producto.CodRub,
567 DES: producto.descripcionLarga, 569 DES: producto.descripcionLarga,
568 PUN: producto.precio, 570 PUN: producto.precio,
569 IVA: producto.IMPIVA, 571 IVA: producto.IMPIVA,
570 NET: producto.IvaCO != 0 ? parseFloat(producto.neto) : 0, 572 NET: producto.IvaCO != 0 ? parseFloat(producto.neto) : 0,
571 NEX: producto.IvaCO == 0 ? parseFloat(producto.neto) : 0, 573 NEX: producto.IvaCO == 0 ? parseFloat(producto.neto) : 0,
572 IMI: producto.ImpInt, 574 IMI: producto.ImpInt,
573 IMI2: producto.ImpInt2, 575 IMI2: producto.ImpInt2,
574 IMI3: producto.ImpInt3, 576 IMI3: producto.ImpInt3,
575 PUT: producto.precio, 577 PUT: producto.precio,
576 SUR: 0, 578 SUR: 0,
577 PLA: $scope.factura.vendedor.NplVen, 579 PLA: $scope.factura.vendedor.NplVen,
578 LUG: $scope.factura.vendedor.LugVen, 580 LUG: $scope.factura.vendedor.LugVen,
579 LEG: $scope.factura.vendedor.CodVen, 581 LEG: $scope.factura.vendedor.CodVen,
580 TUR: $scope.factura.vendedor.TurVen, 582 TUR: $scope.factura.vendedor.TurVen,
581 ORDEN_PRECOMPRA: '', 583 ORDEN_PRECOMPRA: '',
582 ESC: producto.tipoFactura === 'L' ? 1 : 0, 584 ESC: producto.tipoFactura === 'L' ? 1 : 0,
583 CMF: 0, 585 CMF: 0,
584 PTA: 0, 586 PTA: 0,
585 IVS: 0, 587 IVS: 0,
586 TIVA: 0, 588 TIVA: 0,
587 CON: 0, 589 CON: 0,
588 SINO: '', 590 SINO: '',
589 ORD_TRA: 0, 591 ORD_TRA: 0,
590 IMP_DESP: 0, 592 IMP_DESP: 0,
591 PCD: 0, 593 PCD: 0,
592 RTO: '', 594 RTO: '',
593 }; 595 };
594 596
595 $scope.factura.articulosFactura.push(articulo); 597 $scope.factura.articulosFactura.push(articulo);
596 $scope.cambioEdit(articulo, 'cantidad'); 598 $scope.cambioEdit(articulo, 'cantidad');
597 599
598 }) 600 })
599 .catch(function (e) { console.error(e); }); 601 .catch(function (e) { console.error(e); });
600 }; 602 };
601 603
602 $scope.seleccionarUltimosDespachos = function () { 604 $scope.seleccionarUltimosDespachos = function () {
603 605
604 if (angular.equals($scope.factura.cliente, {})) { 606 if (angular.equals($scope.factura.cliente, {})) {
605 focaModalService.alert('Seleccione cliente'); 607 focaModalService.alert('Seleccione cliente');
606 return; 608 return;
607 } 609 }
608 610
609 var modalInstance = $uibModal.open( 611 var modalInstance = $uibModal.open(
610 { 612 {
611 templateUrl: 'modal-ultimos-despachos.html', 613 templateUrl: 'modal-ultimos-despachos.html',
612 controller: 'ultimosDespachosController', 614 controller: 'ultimosDespachosController',
613 resolve: { 615 resolve: {
614 parametros: function () { 616 parametros: function () {
615 return { 617 return {
616 planilla: $scope.factura.vendedor.NplVen, 618 planilla: $scope.factura.vendedor.NplVen,
617 }; 619 };
618 } 620 }
619 }, 621 },
620 size: 'md' 622 size: 'md'
621 } 623 }
622 ); 624 );
623 625
624 modalInstance.result.then(function (despacho) { 626 modalInstance.result.then(function (despacho) {
625 627
626 var articulo = { 628 var articulo = {
627 TIP: $scope.factura.cliente.tipoFactura, 629 TIP: $scope.factura.cliente.tipoFactura,
628 TCO: 'FT', 630 TCO: 'FT',
629 SUC: parseInt($scope.puntoVenta), 631 SUC: parseInt($scope.puntoVenta),
630 ORD: $scope.articulosFiltro().length + 1, 632 ORD: $scope.articulosFiltro().length + 1,
631 SEC: despacho.SEC, 633 SEC: despacho.SEC,
632 ART: despacho.PRO, 634 ART: despacho.PRO,
633 RUB: producto.CodRub, 635 RUB: producto.CodRub,
634 DES: producto.DetArt, 636 DES: producto.DetArt,
635 CAN: despacho.LTS, 637 CAN: despacho.LTS,
636 PUN: producto.PreVen, 638 PUN: producto.PreVen,
637 IVA: producto.IMPIVA, 639 IVA: producto.IMPIVA,
638 NET: producto.IvaCO != 0 ? producto.PreNet : 0, 640 NET: producto.IvaCO != 0 ? producto.PreNet : 0,
639 NEX: producto.IvaCO == 0 ? producto.PreNet : 0, 641 NEX: producto.IvaCO == 0 ? producto.PreNet : 0,
640 IMI: producto.ImpInt, 642 IMI: producto.ImpInt,
641 IMI2: producto.ImpInt2, 643 IMI2: producto.ImpInt2,
642 IMI3: producto.ImpInt3, 644 IMI3: producto.ImpInt3,
643 PUT: producto.PreVen, 645 PUT: producto.PreVen,
644 SUR: despacho.SUR, 646 SUR: despacho.SUR,
645 PLA: despacho.PLA, 647 PLA: despacho.PLA,
646 LUG: despacho.LUG, 648 LUG: despacho.LUG,
647 LEG: $scope.factura.vendedor.CodVen, 649 LEG: $scope.factura.vendedor.CodVen,
648 TUR: $scope.factura.vendedor.TurVen, 650 TUR: $scope.factura.vendedor.TurVen,
649 ORDEN_PRECOMPRA: '', 651 ORDEN_PRECOMPRA: '',
650 ESC: producto.tipoFactura === 'L' ? 1 : 0, 652 ESC: producto.tipoFactura === 'L' ? 1 : 0,
651 CMF: 0, 653 CMF: 0,
652 PTA: 0, 654 PTA: 0,
653 IVS: 0, 655 IVS: 0,
654 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO 656 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO
655 CON: 0, 657 CON: 0,
656 SINO: '', 658 SINO: '',
657 ORD_TRA: 0, 659 ORD_TRA: 0,
658 IMP_DESP: 0, 660 IMP_DESP: 0,
659 PCD: 0, 661 PCD: 0,
660 RTO: '', 662 RTO: '',
661 }; 663 };
662 664
663 crearFacturaService.setearDespachoOcupado({ 665 crearFacturaService.setearDespachoOcupado({
664 surtidor: despacho.SUR, 666 surtidor: despacho.SUR,
665 producto: despacho.PRO, 667 producto: despacho.PRO,
666 carga: despacho.CAR 668 carga: despacho.CAR
667 }) 669 })
668 .then(function () { 670 .then(function () {
669 $scope.factura.articulosFactura.push(articulo); 671 $scope.factura.articulosFactura.push(articulo);
670 $scope.factura.despachos.push(despacho); 672 $scope.factura.despachos.push(despacho);
671 }) 673 })
672 .catch(function (err) { 674 .catch(function (err) {
673 675
674 console.error(err); 676 console.error(err);
675 focaModalService.alert('El despacho esta en uso'); 677 focaModalService.alert('El despacho esta en uso');
676 }); 678 });
677 679
678 }) 680 })
679 .catch(function (err) { 681 .catch(function (err) {
680 console.error(err); 682 console.error(err);
681 }); 683 });
682 684
683 }; 685 };
684 686
685 function crearFuncionesProductos(producto) { 687 function crearFuncionesProductos(producto) {
686 688
687 $scope[nombreFuncion(producto.DetArt)] = function () { 689 $scope[nombreFuncion(producto.DetArt)] = function () {
688 690
689 if (angular.equals($scope.factura.cliente, {})) { 691 if (angular.equals($scope.factura.cliente, {})) {
690 focaModalService.alert('Seleccione cliente'); 692 focaModalService.alert('Seleccione cliente');
691 return; 693 return;
692 } 694 }
693 695
694 var modalInstance = $uibModal.open( 696 var modalInstance = $uibModal.open(
695 { 697 {
696 templateUrl: 'modal-combustibles.html', 698 templateUrl: 'modal-combustibles.html',
697 controller: 'focaModalCombustiblesController', 699 controller: 'focaModalCombustiblesController',
698 resolve: { 700 resolve: {
699 parametros: function () { 701 parametros: function () {
700 return { 702 return {
701 despachos: producto.despachos, 703 despachos: producto.despachos,
702 nombreProducto: producto.DetArt 704 nombreProducto: producto.DetArt,
705 topDespachos: $scope.topDespachos
703 }; 706 };
704 } 707 }
705 }, 708 },
706 size: 'md' 709 size: 'md'
707 } 710 }
708 ); 711 );
709 712
710 modalInstance.result.then(function (despacho) { 713 modalInstance.result.then(function (despacho) {
711 714
712 var articulo = { 715 var articulo = {
713 TIP: $scope.factura.cliente.tipoFactura, 716 TIP: $scope.factura.cliente.tipoFactura,
714 TCO: 'FT', 717 TCO: 'FT',
715 SUC: parseInt($scope.puntoVenta), 718 SUC: parseInt($scope.puntoVenta),
716 ORD: $scope.articulosFiltro().length + 1, 719 ORD: $scope.articulosFiltro().length + 1,
717 SEC: despacho.SEC, 720 SEC: despacho.SEC,
718 ART: despacho.PRO, 721 ART: despacho.PRO,
719 RUB: producto.CodRub, 722 RUB: producto.CodRub,
720 DES: producto.DetArt, 723 DES: producto.DetArt,
721 CAN: despacho.LTS, 724 CAN: despacho.LTS,
722 PUN: producto.PreVen, 725 PUN: producto.PreVen,
723 IVA: producto.IMPIVA, 726 IVA: producto.IMPIVA,
724 NET: producto.IvaCO != 0 ? producto.PreNet : 0, 727 NET: producto.IvaCO != 0 ? producto.PreNet : 0,
725 NEX: producto.IvaCO == 0 ? producto.PreNet : 0, 728 NEX: producto.IvaCO == 0 ? producto.PreNet : 0,
726 IMI: producto.ImpInt, 729 IMI: producto.ImpInt,
727 IMI2: producto.ImpInt2, 730 IMI2: producto.ImpInt2,
728 IMI3: producto.ImpInt3, 731 IMI3: producto.ImpInt3,
729 PUT: producto.PreVen, 732 PUT: producto.PreVen,
730 SUR: despacho.SUR, 733 SUR: despacho.SUR,
731 PLA: despacho.PLA, 734 PLA: despacho.PLA,
732 LUG: despacho.LUG, 735 LUG: despacho.LUG,
733 LEG: $scope.factura.vendedor.CodVen, 736 LEG: $scope.factura.vendedor.CodVen,
734 TUR: $scope.factura.vendedor.TurVen, 737 TUR: $scope.factura.vendedor.TurVen,
735 ORDEN_PRECOMPRA: '', 738 ORDEN_PRECOMPRA: '',
736 ESC: producto.tipoFactura === 'L' ? 1 : 0, 739 ESC: producto.tipoFactura === 'L' ? 1 : 0,
737 CMF: 0, 740 CMF: 0,
738 PTA: 0, 741 PTA: 0,
739 IVS: 0, 742 IVS: 0,
740 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO 743 TIVA: 21, // TODO traer POR de la tabla ACODIVA where ID = IvaCO
741 CON: 0, 744 CON: 0,
742 SINO: '', 745 SINO: '',
743 ORD_TRA: 0, 746 ORD_TRA: 0,
744 IMP_DESP: 0, 747 IMP_DESP: 0,
745 PCD: 0, 748 PCD: 0,
746 RTO: '', 749 RTO: '',
747 }; 750 };
748 751
749 crearFacturaService.setearDespachoOcupado({ 752 crearFacturaService.setearDespachoOcupado({
750 surtidor: despacho.SUR, 753 surtidor: despacho.SUR,
751 producto: despacho.PRO, 754 producto: despacho.PRO,
752 carga: despacho.CAR 755 carga: despacho.CAR
753 }) 756 })
754 .then(function () { 757 .then(function () {
755 $scope.factura.articulosFactura.push(articulo); 758 $scope.factura.articulosFactura.push(articulo);
756 $scope.factura.despachos.push(despacho); 759 $scope.factura.despachos.push(despacho);
757 }) 760 })
758 .catch(function (err) { 761 .catch(function (err) {
759 762
760 console.error(err); 763 console.error(err);
761 focaModalService.alert('El despacho esta en uso'); 764 focaModalService.alert('El despacho esta en uso');
762 }); 765 });
763 766
764 }) 767 })
765 .catch(function (err) { 768 .catch(function (err) {
766 console.error(err); 769 console.error(err);
767 }); 770 });
768 771
769 }; 772 };
770 } 773 }
771 774
772 function nombreFuncion(string) { 775 function nombreFuncion(string) {
773 var texto = 'seleccionar'; 776 var texto = 'seleccionar';
774 var arr = string.split(' '); 777 var arr = string.split(' ');
775 arr.forEach(function (palabra) { 778 arr.forEach(function (palabra) {
776 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 779 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
777 texto += palabra; 780 texto += palabra;
778 }); 781 });
779 return texto; 782 return texto;
780 } 783 }
781 784
782 function indicarPassword(vendedor) { 785 function indicarPassword(vendedor) {
783 786
784 return new Promise(function (resolve, reject) { 787 return new Promise(function (resolve, reject) {
785 788
786 function openPrompt() { 789 function openPrompt() {
787 return focaModalService 790 return focaModalService
788 .prompt({ 791 .prompt({
789 titulo: 'Indique Contraseña', 792 titulo: 'Indique Contraseña',
790 value: '', 793 value: '',
791 tipo: 'password' 794 tipo: 'password'
792 }) 795 })
793 .then(function (contraseña) { 796 .then(function (contraseña) {
794 797
795 if (contraseña !== vendedor.ClaVen.trim()) { 798 if (contraseña !== vendedor.ClaVen.trim()) {
796 799
797 focaModalService.alert('Clave incorrecta').then(function () { 800 focaModalService.alert('Clave incorrecta').then(function () {
798 openPrompt(vendedor); 801 openPrompt(vendedor);
799 }); 802 });
800 } else { 803 } else {
801 resolve(); 804 resolve();
802 } 805 }
803 }) 806 })
804 .catch(reject); 807 .catch(reject);
805 } 808 }
806 809
807 openPrompt(); 810 openPrompt();
808 }); 811 });
809 } 812 }
810 813
811 function validarPlanillaVendedor(vendedor) { 814 function validarPlanillaVendedor(vendedor) {
812 815
813 return new Promise(function (resolve, reject) { 816 return new Promise(function (resolve, reject) {
814 817
815 crearFacturaService 818 crearFacturaService
816 .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) 819 .validarPlanillaVendedor(vendedor.CodVen.toString().trim())
817 .then(function (res) { 820 .then(function (res) {
818 821
819 if (!res.data.length) { 822 if (!res.data.length) {
820 823
821 focaModalService 824 focaModalService
822 .alert('No se encontró planilla abierta para el vendedor') 825 .alert('No se encontró planilla abierta para el vendedor')
823 .then(reject); 826 .then(reject);
824 827
825 } else { 828 } else {
826 resolve(); 829 resolve();
827 } 830 }
828 831
829 }) 832 })
830 .catch(function (err) { 833 .catch(function (err) {
831 console.log(err) 834 console.log(err)
832 reject(); 835 reject();
833 }); 836 });
834 }); 837 });
835 } 838 }
836 839
837 function rellenar(relleno, longitud) { 840 function rellenar(relleno, longitud) {
838 relleno = '' + relleno; 841 relleno = '' + relleno;
839 while (relleno.length < longitud) { 842 while (relleno.length < longitud) {
840 relleno = '0' + relleno; 843 relleno = '0' + relleno;
841 } 844 }
842 return relleno; 845 return relleno;
843 } 846 }
844 847
845 $scope.salir = function () { 848 $scope.salir = function () {
846 var confirmacion = false; 849 var confirmacion = false;
847 850
848 if (!angular.equals($scope.factura, $scope.inicial)) { 851 if (!angular.equals($scope.factura, $scope.inicial)) {
849 confirmacion = true; 852 confirmacion = true;
850 } 853 }
851 854
852 if (confirmacion) { 855 if (confirmacion) {
853 focaModalService.confirm( 856 focaModalService.confirm(
854 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 857 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
855 ).then(function (data) { 858 ).then(function (data) {
856 if (data) { 859 if (data) {
857 $location.path('/'); 860 $location.path('/');
858 } 861 }
859 }); 862 });
860 } else { 863 } else {
861 $location.path('/'); 864 $location.path('/');
862 } 865 }
863 } 866 }
864 867
865 function setearFactura(factura) { 868 function setearFactura(factura) {
866 869
867 $scope.$broadcast('cleanCabecera'); 870 $scope.$broadcast('cleanCabecera');
868 871
869 $scope.cabeceras = []; 872 $scope.cabeceras = [];
870 873
871 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 874 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
872 $scope.cabeceras.push({ 875 $scope.cabeceras.push({
873 label: 'Moneda:', 876 label: 'Moneda:',
874 valor: factura.cotizacion.moneda.DETALLE 877 valor: factura.cotizacion.moneda.DETALLE
875 }); 878 });
876 $scope.cabeceras.push({ 879 $scope.cabeceras.push({
877 label: 'Fecha cotizacion:', 880 label: 'Fecha cotizacion:',
878 valor: $filter('date')(factura.cotizacion.FECHA, 881 valor: $filter('date')(factura.cotizacion.FECHA,
879 'dd/MM/yyyy') 882 'dd/MM/yyyy')
880 }); 883 });
881 $scope.cabeceras.push({ 884 $scope.cabeceras.push({
882 label: 'Cotizacion:', 885 label: 'Cotizacion:',
883 valor: $filter('number')(factura.cotizacion.VENDEDOR, 886 valor: $filter('number')(factura.cotizacion.VENDEDOR,
884 '2') 887 '2')
885 }); 888 });
886 } 889 }
887 890
888 if (factura.cotizacion && factura.cotizacion.moneda) { 891 if (factura.cotizacion && factura.cotizacion.moneda) {
889 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 892 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
890 } 893 }
891 894
892 if (factura.cliente && factura.cliente.cod) { 895 if (factura.cliente && factura.cliente.cod) {
893 $scope.cabeceras.push({ 896 $scope.cabeceras.push({
894 label: 'Cliente:', 897 label: 'Cliente:',
895 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + 898 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' +
896 factura.cliente.nom 899 factura.cliente.nom
897 }); 900 });
898 901
899 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 902 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
900 } 903 }
901 904
902 $scope.puntoVenta = rellenar(factura.sucursal, 4); 905 $scope.puntoVenta = rellenar(factura.sucursal, 4);
903 $scope.comprobante = rellenar(factura.numerofactura, 8); 906 $scope.comprobante = rellenar(factura.numerofactura, 8);
904 $scope.factura = factura; 907 $scope.factura = factura;
905 908
906 addArrayCabecera($scope.cabeceras); 909 addArrayCabecera($scope.cabeceras);
907 } 910 }
908 911
909 function getLSFactura() { 912 function getLSFactura() {
910 var factura = JSON.parse($localStorage.factura || null); 913 var factura = JSON.parse($localStorage.factura || null);
911 if (factura) { 914 if (factura) {
912 setearFactura(factura); 915 setearFactura(factura);
913 delete $localStorage.factura; 916 delete $localStorage.factura;
914 } 917 }
915 } 918 }
916 919
917 function addArrayCabecera(array) { 920 function addArrayCabecera(array) {
918 for (var i = 0; i < array.length; i++) { 921 for (var i = 0; i < array.length; i++) {
919 $scope.$broadcast('addCabecera', { 922 $scope.$broadcast('addCabecera', {
920 label: array[i].label, 923 label: array[i].label,
921 valor: array[i].valor 924 valor: array[i].valor
922 }); 925 });
923 } 926 }
924 } 927 }
925 928
926 $scope.cambioEdit = function (articulo, propiedad) { 929 $scope.cambioEdit = function (articulo, propiedad) {
927 if (propiedad === 'cantidad' && articulo.SUR == 0) { 930 if (propiedad === 'cantidad' && articulo.SUR == 0) {
928 articulo.editCantidad = true; 931 articulo.editCantidad = true;
929 } 932 }
930 }; 933 };
931 934
932 $scope.editarArticulo = function (key, articulo, tmpCantidad) { 935 $scope.editarArticulo = function (key, articulo, tmpCantidad) {
933 if (key === 13) { 936 if (key === 13) {
934 if (!articulo.cantidad && tmpCantidad.length === 0) { 937 if (!articulo.cantidad && tmpCantidad.length === 0) {
935 focaModalService.alert('Los valores deben ser al menos 1'); 938 focaModalService.alert('Los valores deben ser al menos 1');
936 return; 939 return;
937 } else if (tmpCantidad === '0') { 940 } else if (tmpCantidad === '0') {
938 focaModalService.alert('Esta ingresando un producto con valor 0'); 941 focaModalService.alert('Esta ingresando un producto con valor 0');
939 return; 942 return;
940 } else if (parseInt(tmpCantidad) < 0) { 943 } else if (parseInt(tmpCantidad) < 0) {
941 focaModalService.alert('Los valores no pueden ser negativos'); 944 focaModalService.alert('Los valores no pueden ser negativos');
942 return; 945 return;
943 } 946 }
944 articulo.CAN = parseInt(tmpCantidad); 947 articulo.CAN = parseInt(tmpCantidad);
945 $scope.getTotal(); 948 $scope.getTotal();
946 articulo.editCantidad = false; 949 articulo.editCantidad = false;
947 } 950 }
948 }; 951 };
949 952
950 $scope.cancelarEditar = function (articulo) { 953 $scope.cancelarEditar = function (articulo) {
951 $scope.tmpCantidad = articulo.CAN; 954 $scope.tmpCantidad = articulo.CAN;
952 articulo.editCantidad = false; 955 articulo.editCantidad = false;
953 }; 956 };
954 957
955 function actualizarCabeceraMoneda(cotizacion) { 958 function actualizarCabeceraMoneda(cotizacion) {
956 959
957 $scope.factura.articulosFactura.forEach(function (art) { 960 $scope.factura.articulosFactura.forEach(function (art) {
958 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); 961 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4);
959 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); 962 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4);
960 }); 963 });
961 964
962 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 965 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
963 $scope.$broadcast('removeCabecera', 'Moneda:'); 966 $scope.$broadcast('removeCabecera', 'Moneda:');
964 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 967 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
965 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 968 $scope.$broadcast('removeCabecera', 'Cotizacion:');
966 } else { 969 } else {
967 $scope.$broadcast('addCabecera', { 970 $scope.$broadcast('addCabecera', {
968 label: 'Moneda:', 971 label: 'Moneda:',
969 valor: cotizacion.moneda.DETALLE 972 valor: cotizacion.moneda.DETALLE
970 }); 973 });
971 $scope.$broadcast('addCabecera', { 974 $scope.$broadcast('addCabecera', {
972 label: 'Fecha cotizacion:', 975 label: 'Fecha cotizacion:',
973 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 976 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
974 }); 977 });
975 $scope.$broadcast('addCabecera', { 978 $scope.$broadcast('addCabecera', {
976 label: 'Cotizacion:', 979 label: 'Cotizacion:',
977 valor: $filter('number')(cotizacion.VENDEDOR, '2') 980 valor: $filter('number')(cotizacion.VENDEDOR, '2')
978 }); 981 });
979 } 982 }
980 } 983 }
981 984
982 function validarGuardar() { 985 function validarGuardar() {
983 986
984 if (angular.equals({}, $scope.factura.vendedor)) { 987 if (angular.equals({}, $scope.factura.vendedor)) {
985 988
986 focaModalService.alert('Seleccione Vendedor'); 989 focaModalService.alert('Seleccione Vendedor');
987 return false; 990 return false;
988 } else if (angular.equals({}, $scope.factura.cliente)) { 991 } else if (angular.equals({}, $scope.factura.cliente)) {
989 992
990 focaModalService.alert('Seleccione Cliente'); 993 focaModalService.alert('Seleccione Cliente');
991 return false; 994 return false;
992 } else if (!$scope.articulosFiltro().length) { 995 } else if (!$scope.articulosFiltro().length) {
993 996
994 focaModalService.alert('Seleccione al menos un Articulo'); 997 focaModalService.alert('Seleccione al menos un Articulo');
995 return false; 998 return false;
996 } 999 }
997 1000
998 return true; 1001 return true;
999 } 1002 }
1000 1003
1001 //recibo la propiedad por la cual quiero obtener el valor 1004 //recibo la propiedad por la cual quiero obtener el valor
1002 function getImporte(propiedad) { 1005 function getImporte(propiedad) {
1003 var importe = 0; 1006 var importe = 0;
1004 1007
1005 $scope.articulosFiltro().forEach(function (articulo) { 1008 $scope.articulosFiltro().forEach(function (articulo) {
1006 1009
1007 if (articulo[propiedad]) { 1010 if (articulo[propiedad]) {
1008 importe += articulo[propiedad] * articulo.CAN; 1011 importe += articulo[propiedad] * articulo.CAN;
1009 } 1012 }
1010 return; 1013 return;
1011 1014
1012 }); 1015 });
1013 1016
1014 return importe; 1017 return importe;
1015 } 1018 }
1016 } 1019 }
1017 ]); 1020 ]);
1018 1021
src/js/controllerCombustibles.js
1 angular.module('focaCrearFactura') 1 angular.module('focaCrearFactura')
2 .controller('focaModalCombustiblesController', [ 2 .controller('focaModalCombustiblesController', [
3 '$filter', 3 '$filter',
4 '$scope', 4 '$scope',
5 '$uibModalInstance', 5 '$uibModalInstance',
6 'parametros', 6 'parametros',
7 function ($filter, $scope, $uibModalInstance, parametros) { 7 function ($filter, $scope, $uibModalInstance, parametros) {
8 8
9 $scope.mangueras = []; 9 $scope.mangueras = [];
10 $scope.colorTexto = { color: 'black' }; 10 $scope.colorTexto = { color: 'black' };
11 var productosByMangera = []; 11 var productosByMangera = [];
12 12
13 config(); 13 config();
14 14
15 function config() { 15 function config() {
16 16
17 $scope.nombreProducto = parametros.nombreProducto; 17 $scope.nombreProducto = parametros.nombreProducto;
18 setColorNombreProducto(); 18 setColorNombreProducto();
19 parametros.despachos.forEach(function (despacho) { 19 parametros.despachos.forEach(function (despacho) {
20 20
21 var findCsu = productosByMangera.filter(function (csu) { 21 var findCsu = productosByMangera.filter(function (csu) {
22 return csu.csu === despacho.CSU.trim(); 22 return csu.csu === despacho.CSU.trim();
23 })[0]; 23 })[0];
24 24
25 if (!findCsu) { 25 if (!findCsu) {
26 26
27 var mangera = { 27 var mangera = {
28 csu: despacho.CSU.trim(), 28 csu: despacho.CSU.trim(),
29 despachos: [despacho], 29 despachos: [despacho],
30 show: true 30 show: true
31 }; 31 };
32 32
33 productosByMangera.unshift(mangera); 33 productosByMangera.unshift(mangera);
34 } else { 34 } else {
35 findCsu.despachos.push(despacho); 35 findCsu.despachos.push(despacho);
36 } 36 }
37 }); 37 });
38 } 38 }
39 39
40 $scope.mangueras = productosByMangera; 40 $scope.mangueras = productosByMangera;
41 41
42 $scope.mangueras.forEach(function (producto) { 42 $scope.mangueras.forEach(function (producto) {
43 43
44 producto.despachos.splice(parametros.topDespachos, producto.despachos.length);
45
44 producto.despachos.sort(function (a, b) { 46 producto.despachos.sort(function (a, b) {
45 return a.FEC - b.FEC; 47 return a.FEC - b.FEC;
46 }); 48 });
47 }); 49 });
48 50
49 51
50 $scope.aceptar = function (despacho) { 52 $scope.aceptar = function (despacho) {
51 $uibModalInstance.close(despacho); 53 $uibModalInstance.close(despacho);
52 }; 54 };
53 55
54 $scope.cancel = function () { 56 $scope.cancel = function () {
55 $uibModalInstance.dismiss('cancel'); 57 $uibModalInstance.dismiss('cancel');
56 }; 58 };
57 59
58 //TODO: Cambiar switch case con los casos de nombres de productos axion 60 //TODO: Cambiar switch case con los casos de nombres de productos axion
59 function setColorNombreProducto() { 61 function setColorNombreProducto() {
60 62
61 // Diesel #FF852E | Euro+Diesel #6C389A | Premium #00A857 | Super #175AA5 63 // Diesel #FF852E | Euro+Diesel #6C389A | Premium #00A857 | Super #175AA5
62 switch ($scope.nombreProducto) { 64 switch ($scope.nombreProducto) {
63 case 'NAFTA SUPER XXI': 65 case 'NAFTA SUPER XXI':
64 $scope.colorTexto = { color: '#FF852E' }; 66 $scope.colorTexto = { color: '#FF852E' };
65 break; 67 break;
66 case 'GO-INFINIA DIESEL': 68 case 'GO-INFINIA DIESEL':
67 $scope.colorTexto = { color: '#6C389A' }; 69 $scope.colorTexto = { color: '#6C389A' };
68 break; 70 break;
69 case 'ULTRADIESEL XXI - RED': 71 case 'ULTRADIESEL XXI - RED':
70 $scope.colorTexto = { color: '#00A857' }; 72 $scope.colorTexto = { color: '#00A857' };
71 break; 73 break;
72 case 'NAFTA INFINIA': 74 case 'NAFTA INFINIA':
73 $scope.colorTexto = { color: '#175AA5' }; 75 $scope.colorTexto = { color: '#175AA5' };
74 break; 76 break;
75 default: 77 default:
76 $scope.colorTexto = { color: 'black' }; 78 $scope.colorTexto = { color: 'black' };
77 break; 79 break;
78 } 80 }
79 } 81 }
80 } 82 }
81 ]); 83 ]);
82 84