Commit d3306bd9836f572797cc669a614967f61d0d2a90

Authored by Marcelo Puebla
Exists in master

Merge branch 'master' into 'develop'

Master(benjamin)

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