Commit 22c46eab7c16c30b98f6f1960f484d86bbe04972

Authored by Marcelo Puebla
1 parent a2cc4b8c29
Exists in master

Arreglo al intentar editar la cantidad de un producto.

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