Commit 8edbf83107d74486cac03eab3212298982d50fe5

Authored by Mauricio Cattafi
1 parent 81fcc1d481
Exists in ultimos_despachos

se agrega validación de pago electronico

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