Commit ee34395a29d4fe3a04141e9bd9dd2bd968aa92ea

Authored by Marcelo Puebla
1 parent 25a16b22f1
Exists in master

Agregado boton de busqueda de productos.

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