Commit c396f04d4b3dbaa3b7dfc8c2500393e07b78cfb5

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(mpuebla)

See merge request !18
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 }; 535 };
537 536
538 $scope.factura.articulosFactura.push(articulo); 537 $scope.factura.articulosFactura.push(articulo);
539 $scope.cambioEdit(articulo, 'cantidad'); 538 $scope.cambioEdit(articulo, 'cantidad');
540 539
541 }) 540 })
542 .catch(function (e) { console.error(e); }); 541 .catch(function (e) { console.error(e); });
543 }; 542 };
544 543
545 function crearFuncionesProductos(producto) { 544 function crearFuncionesProductos(producto) {
546 545
547 $scope[nombreFuncion(producto.DetArt)] = function () { 546 $scope[nombreFuncion(producto.DetArt)] = function () {
548 547
549 if (angular.equals($scope.factura.cliente, {})) { 548 if (angular.equals($scope.factura.cliente, {})) {
550 focaModalService.alert('Seleccione cliente'); 549 focaModalService.alert('Seleccione cliente');
551 return; 550 return;
552 } 551 }
553 552
554 var modalInstance = $uibModal.open( 553 var modalInstance = $uibModal.open(
555 { 554 {
556 templateUrl: 'modal-combustibles.html', 555 templateUrl: 'modal-combustibles.html',
557 controller: 'focaModalCombustiblesController', 556 controller: 'focaModalCombustiblesController',
558 resolve: { 557 resolve: {
559 parametros: function () { 558 parametros: function () {
560 return { 559 return {
561 despachos: producto.despachos, 560 despachos: producto.despachos,
562 nombreProducto: producto.DetArt 561 nombreProducto: producto.DetArt
563 }; 562 };
564 } 563 }
565 }, 564 },
566 size: 'md' 565 size: 'md'
567 } 566 }
568 ); 567 );
569 568
570 modalInstance.result.then(function (despacho) { 569 modalInstance.result.then(function (despacho) {
571 570
572 var articulo = { 571 var articulo = {
573 TIP: $scope.factura.cliente.tipoFactura, 572 TIP: $scope.factura.cliente.tipoFactura,
574 TCO: 'FT', 573 TCO: 'FT',
575 SUC: parseInt($scope.puntoVenta), 574 SUC: parseInt($scope.puntoVenta),
576 ORD: $scope.articulosFiltro().length + 1, 575 ORD: $scope.articulosFiltro().length + 1,
577 SEC: despacho.SEC, 576 SEC: despacho.SEC,
578 ART: despacho.PRO, 577 ART: despacho.PRO,
579 RUB: producto.CodRub, 578 RUB: producto.CodRub,
580 DES: producto.DetArt, 579 DES: producto.DetArt,
581 CAN: despacho.LTS, 580 CAN: despacho.LTS,
582 PUN: producto.PreVen, // TODO 581 PUN: producto.PreVen, // TODO
583 IVA: producto.IMPIVA, // TODO 582 IVA: producto.IMPIVA, // TODO
584 NET: 0, // TODO 583 NET: 0, // TODO
585 NEX: 0, // TODO 584 NEX: 0, // TODO
586 IMI: producto.ImpInt, // TODO 585 IMI: producto.ImpInt, // TODO
587 IMI2: producto.ImpInt2, // TODO 586 IMI2: producto.ImpInt2, // TODO
588 IMI3: producto.ImpInt3, // TODO 587 IMI3: producto.ImpInt3, // TODO
589 PUT: producto.PreNet, // TODO 588 PUT: producto.PreNet, // TODO
590 SUR: despacho.SUR, 589 SUR: despacho.SUR,
591 PLA: despacho.PLA, 590 PLA: despacho.PLA,
592 LUG: despacho.LUG, 591 LUG: despacho.LUG,
593 LEG: $scope.factura.vendedor.CodVen, 592 LEG: $scope.factura.vendedor.CodVen,
594 TUR: $scope.factura.vendedor.TurVen, 593 TUR: $scope.factura.vendedor.TurVen,
595 ORDEN_PRECOMPRA: '', 594 ORDEN_PRECOMPRA: '',
596 ESC: producto.tipoFactura === 'L' ? 1 : 0, 595 ESC: producto.tipoFactura === 'L' ? 1 : 0,
597 CMF: 0, 596 CMF: 0,
598 PTA: 0, 597 PTA: 0,
599 IVS: 0, 598 IVS: 0,
600 TIVA: 0, 599 TIVA: 0,
601 CON: 0, 600 CON: 0,
602 SINO: '', 601 SINO: '',
603 ORD_TRA: 0, 602 ORD_TRA: 0,
604 IMP_DESP: 0, 603 IMP_DESP: 0,
605 PCD: 0, 604 PCD: 0,
606 RTO: '' 605 RTO: '',
607 }; 606 };
608 607
609 crearFacturaService.setearDespachoOcupado({ 608 crearFacturaService.setearDespachoOcupado({
610 surtidor: despacho.SUR, 609 surtidor: despacho.SUR,
611 producto: despacho.PRO, 610 producto: despacho.PRO,
612 carga: despacho.CAR 611 carga: despacho.CAR
613 }) 612 })
614 .then(function () { 613 .then(function () {
615 $scope.factura.articulosFactura.push(articulo); 614 $scope.factura.articulosFactura.push(articulo);
616 $scope.factura.despachos.push(despacho); 615 $scope.factura.despachos.push(despacho);
617 }) 616 })
618 .catch(function (err) { 617 .catch(function (err) {
619 618
620 console.error(err); 619 console.error(err);
621 focaModalService.alert('El despacho esta en uso'); 620 focaModalService.alert('El despacho esta en uso');
622 }); 621 });
623 622
624 }) 623 })
625 .catch(function (err) { 624 .catch(function (err) {
626 console.error(err); 625 console.error(err);
627 }); 626 });
628 627
629 }; 628 };
630 } 629 }
631 630
632 function nombreFuncion(string) { 631 function nombreFuncion(string) {
633 var texto = 'seleccionar'; 632 var texto = 'seleccionar';
634 var arr = string.split(' '); 633 var arr = string.split(' ');
635 arr.forEach(function (palabra) { 634 arr.forEach(function (palabra) {
636 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 635 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
637 texto += palabra; 636 texto += palabra;
638 }); 637 });
639 return texto; 638 return texto;
640 } 639 }
641 640
642 function indicarPassword(vendedor) { 641 function indicarPassword(vendedor) {
643 642
644 return new Promise(function (resolve, reject) { 643 return new Promise(function (resolve, reject) {
645 644
646 function openPrompt() { 645 function openPrompt() {
647 return focaModalService 646 return focaModalService
648 .prompt({ 647 .prompt({
649 titulo: 'Indique Contraseña', 648 titulo: 'Indique Contraseña',
650 value: '' 649 value: ''
651 }) 650 })
652 .then(function (contraseña) { 651 .then(function (contraseña) {
653 652
654 if (contraseña !== vendedor.ClaVen.trim()) { 653 if (contraseña !== vendedor.ClaVen.trim()) {
655 654
656 focaModalService.alert('Clave incorrecta').then(function () { 655 focaModalService.alert('Clave incorrecta').then(function () {
657 openPrompt(vendedor); 656 openPrompt(vendedor);
658 }); 657 });
659 } else { 658 } else {
660 resolve(); 659 resolve();
661 } 660 }
662 }) 661 })
663 .catch(reject);; 662 .catch(reject);
664 } 663 }
665 664
666 openPrompt() 665 openPrompt();
667 }); 666 });
668 } 667 }
669 668
670 function validarPlanillaVendedor(vendedor) { 669 function validarPlanillaVendedor(vendedor) {
671 670
672 return new Promise(function (resolve, reject) { 671 return new Promise(function (resolve, reject) {
673 672
674 crearFacturaService 673 crearFacturaService
675 .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) 674 .validarPlanillaVendedor(vendedor.CodVen.toString().trim())
676 .then(function (res) { 675 .then(function (res) {
677 676
678 if (!res.data.length) { 677 if (!res.data.length) {
679 678
680 focaModalService 679 focaModalService
681 .alert('No se encontró planilla abierta para el vendedor') 680 .alert('No se encontró planilla abierta para el vendedor')
682 .then(reject); 681 .then(reject);
683 682
684 } else { 683 } else {
685 resolve(); 684 resolve();
686 } 685 }
687 686
688 }) 687 })
689 .catch(function (err) { 688 .catch(function (err) {
690 console.log(err) 689 console.log(err)
691 reject(); 690 reject();
692 }); 691 });
693 }); 692 });
694 } 693 }
695 694
696 function rellenar(relleno, longitud) { 695 function rellenar(relleno, longitud) {
697 relleno = '' + relleno; 696 relleno = '' + relleno;
698 while (relleno.length < longitud) { 697 while (relleno.length < longitud) {
699 relleno = '0' + relleno; 698 relleno = '0' + relleno;
700 } 699 }
701 return relleno; 700 return relleno;
702 } 701 }
703 702
704 $scope.salir = function () { 703 $scope.salir = function () {
705 var confirmacion = false; 704 var confirmacion = false;
706 705
707 if (!angular.equals($scope.factura, $scope.inicial)) { 706 if (!angular.equals($scope.factura, $scope.inicial)) {
708 confirmacion = true; 707 confirmacion = true;
709 } 708 }
710 709
711 if (confirmacion) { 710 if (confirmacion) {
712 focaModalService.confirm( 711 focaModalService.confirm(
713 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 712 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
714 ).then(function (data) { 713 ).then(function (data) {
715 if (data) { 714 if (data) {
716 $location.path('/'); 715 $location.path('/');
717 } 716 }
718 }); 717 });
719 } else { 718 } else {
720 $location.path('/'); 719 $location.path('/');
721 } 720 }
722 } 721 }
723 722
724 function setearFactura(factura) { 723 function setearFactura(factura) {
725 724
726 $scope.$broadcast('cleanCabecera'); 725 $scope.$broadcast('cleanCabecera');
727 726
728 $scope.cabeceras = []; 727 $scope.cabeceras = [];
729 728
730 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 729 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
731 $scope.cabeceras.push({ 730 $scope.cabeceras.push({
732 label: 'Moneda:', 731 label: 'Moneda:',
733 valor: factura.cotizacion.moneda.DETALLE 732 valor: factura.cotizacion.moneda.DETALLE
734 }); 733 });
735 $scope.cabeceras.push({ 734 $scope.cabeceras.push({
736 label: 'Fecha cotizacion:', 735 label: 'Fecha cotizacion:',
737 valor: $filter('date')(factura.cotizacion.FECHA, 736 valor: $filter('date')(factura.cotizacion.FECHA,
738 'dd/MM/yyyy') 737 'dd/MM/yyyy')
739 }); 738 });
740 $scope.cabeceras.push({ 739 $scope.cabeceras.push({
741 label: 'Cotizacion:', 740 label: 'Cotizacion:',
742 valor: $filter('number')(factura.cotizacion.VENDEDOR, 741 valor: $filter('number')(factura.cotizacion.VENDEDOR,
743 '2') 742 '2')
744 }); 743 });
745 } 744 }
746 745
747 if (factura.cotizacion && factura.cotizacion.moneda) { 746 if (factura.cotizacion && factura.cotizacion.moneda) {
748 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 747 // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
749 } 748 }
750 749
751 if (factura.cliente && factura.cliente.cod) { 750 if (factura.cliente && factura.cliente.cod) {
752 $scope.cabeceras.push({ 751 $scope.cabeceras.push({
753 label: 'Cliente:', 752 label: 'Cliente:',
754 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + 753 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' +
755 factura.cliente.nom 754 factura.cliente.nom
756 }); 755 });
757 756
758 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 757 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
759 } 758 }
760 759
761 $scope.puntoVenta = rellenar(factura.sucursal, 4); 760 $scope.puntoVenta = rellenar(factura.sucursal, 4);
762 $scope.comprobante = rellenar(factura.numerofactura, 8); 761 $scope.comprobante = rellenar(factura.numerofactura, 8);
763 $scope.factura = factura; 762 $scope.factura = factura;
764 763
765 addArrayCabecera($scope.cabeceras); 764 addArrayCabecera($scope.cabeceras);
766 } 765 }
767 766
768 function getLSFactura() { 767 function getLSFactura() {
769 var factura = JSON.parse($localStorage.factura || null); 768 var factura = JSON.parse($localStorage.factura || null);
770 if (factura) { 769 if (factura) {
771 setearFactura(factura); 770 setearFactura(factura);
772 delete $localStorage.factura; 771 delete $localStorage.factura;
773 } 772 }
774 } 773 }
775 774
776 function addArrayCabecera(array) { 775 function addArrayCabecera(array) {
777 for (var i = 0; i < array.length; i++) { 776 for (var i = 0; i < array.length; i++) {
778 $scope.$broadcast('addCabecera', { 777 $scope.$broadcast('addCabecera', {
779 label: array[i].label, 778 label: array[i].label,
780 valor: array[i].valor 779 valor: array[i].valor
781 }); 780 });
782 } 781 }
783 } 782 }
784 783
785 $scope.cambioEdit = function (articulo, propiedad) { 784 $scope.cambioEdit = function (articulo, propiedad) {
786 if (propiedad === 'cantidad') { 785 if (propiedad === 'cantidad' && articulo.SUR !== 0) {
787 articulo.editCantidad = true; 786 articulo.editCantidad = true;
788 } 787 }
789 }; 788 };
790 789
791 $scope.editarArticulo = function (key, articulo, tmpCantidad) { 790 $scope.editarArticulo = function (key, articulo, tmpCantidad) {
792 if (key === 13) { 791 if (key === 13) {
793 if (!articulo.cantidad && !tmpCantidad) { 792 if (!articulo.cantidad && tmpCantidad.length === 0) {
794 focaModalService.alert('Los valores deben ser al menos 1'); 793 focaModalService.alert('Los valores deben ser al menos 1');
795 return; 794 return;
796 } else if (tmpCantidad === '0') { 795 } else if (tmpCantidad === '0') {
797 focaModalService.alert('Esta ingresando un producto con valor 0'); 796 focaModalService.alert('Esta ingresando un producto con valor 0');
798 } else if (articulo.cantidad < 0) { 797 return;
798 } else if (parseInt(tmpCantidad) < 0) {
799 focaModalService.alert('Los valores no pueden ser negativos'); 799 focaModalService.alert('Los valores no pueden ser negativos');
800 return; 800 return;
801 } 801 }
802 articulo.CAN = parseInt(tmpCantidad); 802 articulo.CAN = parseInt(tmpCantidad);
803 $scope.getTotal(); 803 $scope.getTotal();
804 articulo.editCantidad = false; 804 articulo.editCantidad = false;
805 } 805 }
806 }; 806 };
807 807
808 $scope.cancelarEditar = function (articulo) { 808 $scope.cancelarEditar = function (articulo) {
809 $scope.tmpCantidad = articulo.CAN; 809 $scope.tmpCantidad = articulo.CAN;
810 articulo.editCantidad = false; 810 articulo.editCantidad = false;
811 }; 811 };
812 812
813 function actualizarCabeceraMoneda(cotizacion) { 813 function actualizarCabeceraMoneda(cotizacion) {
814 814
815 $scope.factura.articulosFactura.forEach(function (art) { 815 $scope.factura.articulosFactura.forEach(function (art) {
816 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); 816 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4);
817 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); 817 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4);
818 }); 818 });
819 819
820 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 820 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
821 $scope.$broadcast('removeCabecera', 'Moneda:'); 821 $scope.$broadcast('removeCabecera', 'Moneda:');
822 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 822 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
823 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 823 $scope.$broadcast('removeCabecera', 'Cotizacion:');
824 } else { 824 } else {
825 $scope.$broadcast('addCabecera', { 825 $scope.$broadcast('addCabecera', {
826 label: 'Moneda:', 826 label: 'Moneda:',
827 valor: cotizacion.moneda.DETALLE 827 valor: cotizacion.moneda.DETALLE
828 }); 828 });
829 $scope.$broadcast('addCabecera', { 829 $scope.$broadcast('addCabecera', {
830 label: 'Fecha cotizacion:', 830 label: 'Fecha cotizacion:',
831 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 831 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
832 }); 832 });
833 $scope.$broadcast('addCabecera', { 833 $scope.$broadcast('addCabecera', {
834 label: 'Cotizacion:', 834 label: 'Cotizacion:',
835 valor: $filter('number')(cotizacion.VENDEDOR, '2') 835 valor: $filter('number')(cotizacion.VENDEDOR, '2')
836 }); 836 });
837 } 837 }
838 } 838 }
839 839
840 function validarGuardar() { 840 function validarGuardar() {
841 841
842 if (angular.equals({}, $scope.factura.vendedor)) { 842 if (angular.equals({}, $scope.factura.vendedor)) {
843 843
844 focaModalService.alert('Seleccione Vendedor'); 844 focaModalService.alert('Seleccione Vendedor');
845 return false; 845 return false;
846 } else if (angular.equals({}, $scope.factura.cliente)) { 846 } else if (angular.equals({}, $scope.factura.cliente)) {
847 847
848 focaModalService.alert('Seleccione Cliente'); 848 focaModalService.alert('Seleccione Cliente');
849 return false; 849 return false;
850 } else if (!$scope.articulosFiltro().length) { 850 } else if (!$scope.articulosFiltro().length) {
851 851
852 focaModalService.alert('Seleccione al menos un Articulo'); 852 focaModalService.alert('Seleccione al menos un Articulo');
853 return false; 853 return false;
854 } 854 }
855 855
856 return true; 856 return true;
857 } 857 }
858 } 858 }
859 ]); 859 ]);
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