Commit 4dd279e94e477ee590fdd95939a6c7c8e6d1c672

Authored by Marcelo Puebla
1 parent 839f054680
Exists in master

Arreglo para poder ver el nombe y codigo del cliente en el modal de estado cuenta.

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