Commit 80aa3d951e48383dbb5f3acc2e230fbd6cbff416
1 parent
c665689291
Exists in
master
validacion despacho en uso!
Showing
2 changed files
with
22 additions
and
5 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', | 4 | '$localStorage', |
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) { | 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage) { |
8 | 8 | ||
9 | config(); | 9 | config(); |
10 | 10 | ||
11 | function config() { | 11 | function config() { |
12 | $scope.tmpCantidad = Number; | 12 | $scope.tmpCantidad = Number; |
13 | $scope.tmpPrecio = Number; | 13 | $scope.tmpPrecio = Number; |
14 | $scope.botonera = crearFacturaService.getBotonera(); | 14 | $scope.botonera = crearFacturaService.getBotonera(); |
15 | $scope.isNumber = angular.isNumber; | 15 | $scope.isNumber = angular.isNumber; |
16 | $scope.datepickerAbierto = false; | 16 | $scope.datepickerAbierto = false; |
17 | $scope.show = false; | 17 | $scope.show = false; |
18 | $scope.cargando = true; | 18 | $scope.cargando = true; |
19 | $scope.now = new Date(); | 19 | $scope.now = new Date(); |
20 | $scope.puntoVenta = rellenar(0, 4); | 20 | $scope.puntoVenta = rellenar(0, 4); |
21 | $scope.comprobante = rellenar(0, 8); | 21 | $scope.comprobante = rellenar(0, 8); |
22 | $scope.dateOptions = { | 22 | $scope.dateOptions = { |
23 | maxDate: new Date(), | 23 | maxDate: new Date(), |
24 | minDate: new Date(2010, 0, 1) | 24 | minDate: new Date(2010, 0, 1) |
25 | }; | 25 | }; |
26 | $scope.cabeceras = []; | 26 | $scope.cabeceras = []; |
27 | crearFacturaService.getParametros().then(function (res) { | 27 | crearFacturaService.getParametros().then(function (res) { |
28 | 28 | ||
29 | var parametros = JSON.parse(res.data[0].jsonText); | 29 | var parametros = JSON.parse(res.data[0].jsonText); |
30 | 30 | ||
31 | if ($localStorage.factura) { | 31 | if ($localStorage.factura) { |
32 | 32 | ||
33 | $timeout(function () { getLSFactura(); }); | 33 | $timeout(function () { getLSFactura(); }); |
34 | } else { | 34 | } else { |
35 | 35 | ||
36 | for (var property in parametros) { | 36 | for (var property in parametros) { |
37 | $scope.factura[property] = parametros[property]; | 37 | $scope.factura[property] = parametros[property]; |
38 | $scope.inicial[property] = parametros[property]; | 38 | $scope.inicial[property] = parametros[property]; |
39 | } | 39 | } |
40 | 40 | ||
41 | setearFactura($scope.factura); | 41 | setearFactura($scope.factura); |
42 | } | 42 | } |
43 | 43 | ||
44 | }); | 44 | }); |
45 | 45 | ||
46 | //SETEO BOTONERA LATERAL | 46 | //SETEO BOTONERA LATERAL |
47 | $timeout(function () { | 47 | $timeout(function () { |
48 | focaBotoneraLateralService.showSalir(false); | 48 | focaBotoneraLateralService.showSalir(false); |
49 | focaBotoneraLateralService.showPausar(true); | 49 | focaBotoneraLateralService.showPausar(true); |
50 | focaBotoneraLateralService.showGuardar(true, $scope.crearFactura); | 50 | focaBotoneraLateralService.showGuardar(true, $scope.crearFactura); |
51 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 51 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
52 | }); | 52 | }); |
53 | 53 | ||
54 | init(); | 54 | init(); |
55 | 55 | ||
56 | } | 56 | } |
57 | 57 | ||
58 | function init() { | 58 | function init() { |
59 | 59 | ||
60 | $scope.$broadcast('cleanCabecera'); | 60 | $scope.$broadcast('cleanCabecera'); |
61 | 61 | ||
62 | $scope.factura = { | 62 | $scope.factura = { |
63 | id: 0, | 63 | id: 0, |
64 | estado: 0, | 64 | estado: 0, |
65 | vendedor: {}, | 65 | vendedor: {}, |
66 | cliente: {}, | 66 | cliente: {}, |
67 | proveedor: {}, | 67 | proveedor: {}, |
68 | domicilio: { dom: '' }, | 68 | domicilio: { dom: '' }, |
69 | moneda: {}, | 69 | moneda: {}, |
70 | cotizacion: $scope.cotizacionPorDefecto || {}, | 70 | cotizacion: $scope.cotizacionPorDefecto || {}, |
71 | articulosFactura: [] | 71 | articulosFactura: [], |
72 | despachos: [] | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | $scope.factura.articulosFactura = []; | 75 | $scope.factura.articulosFactura = []; |
75 | $scope.idLista = undefined; | 76 | $scope.idLista = undefined; |
76 | 77 | ||
77 | crearRemitoService.getNumeroRemito().then( | 78 | crearRemitoService.getNumeroRemito().then( |
78 | function (res) { | 79 | function (res) { |
79 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 80 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
80 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 81 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
81 | }, | 82 | }, |
82 | function (err) { | 83 | function (err) { |
83 | focaModalService.alert('La terminal no esta configurada correctamente'); | 84 | focaModalService.alert('La terminal no esta configurada correctamente'); |
84 | console.info(err); | 85 | console.info(err); |
85 | } | 86 | } |
86 | ); | 87 | ); |
87 | 88 | ||
88 | $scope.inicial = angular.copy($scope.factura); | 89 | $scope.inicial = angular.copy($scope.factura); |
89 | } | 90 | } |
90 | 91 | ||
91 | $scope.$watch('factura', function (newValue) { | 92 | $scope.$watch('factura', function (newValue) { |
92 | focaBotoneraLateralService.setPausarData({ | 93 | focaBotoneraLateralService.setPausarData({ |
93 | label: 'factura', | 94 | label: 'factura', |
94 | val: newValue | 95 | val: newValue |
95 | }); | 96 | }); |
96 | }, true); | 97 | }, true); |
97 | 98 | ||
98 | $scope.crearFactura = function () { | 99 | $scope.crearFactura = function () { |
99 | 100 | ||
100 | if (!validarGuardar()) return; | 101 | if (!validarGuardar()) return; |
101 | 102 | ||
102 | var save = { | 103 | var save = { |
103 | factura: { | 104 | factura: { |
104 | 105 | ||
105 | BONIF: 0, | 106 | BONIF: 0, |
106 | CLI: $scope.factura.cliente.cod, | 107 | CLI: $scope.factura.cliente.cod, |
107 | CUI: $scope.factura.cliente.cuit, | 108 | CUI: $scope.factura.cliente.cuit, |
108 | CTA: $scope.factura.cliente.cod, | 109 | CTA: $scope.factura.cliente.cod, |
109 | DC1: '', | 110 | DC1: '', |
110 | DC2: '', | 111 | DC2: '', |
111 | DE1: '', | 112 | DE1: '', |
112 | DOM: $scope.factura.cliente.DOM, | 113 | DOM: $scope.factura.cliente.DOM, |
113 | FACAUT: 0, | 114 | FACAUT: 0, |
114 | DTO: 0, | 115 | DTO: 0, |
115 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 116 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), |
116 | FEC_ANT: '19000101', | 117 | FEC_ANT: '19000101', |
117 | FPA: 2, | 118 | FPA: 2, |
118 | IDEXCEPCION: 0, | 119 | IDEXCEPCION: 0, |
119 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 120 | IDLP: $scope.factura.cliente.mod.trim() || 0, |
120 | IDPERSONERIA: 0, | 121 | IDPERSONERIA: 0, |
121 | IMI: 0, // TODO | 122 | IMI: 0, // TODO |
122 | IMI2: 0, // TODO | 123 | IMI2: 0, // TODO |
123 | IMI3: 0, // TODO | 124 | IMI3: 0, // TODO |
124 | IMP_LEY: 0, | 125 | IMP_LEY: 0, |
125 | IRI: 0, // TODO | 126 | IRI: 0, // TODO |
126 | IRS: 0, | 127 | IRS: 0, |
127 | LEG: '', | 128 | LEG: '', |
128 | LUG: $scope.factura.vendedor.LugVen, | 129 | LUG: $scope.factura.vendedor.LugVen, |
129 | MK_M: 0, | 130 | MK_M: 0, |
130 | NEE: 0, // TODO | 131 | NEE: 0, // TODO |
131 | NET: 0, // TODO | 132 | NET: 0, // TODO |
132 | NFI: '', | 133 | NFI: '', |
133 | NNP: 0, | 134 | NNP: 0, |
134 | NOM: $scope.factura.cliente.nom, | 135 | NOM: $scope.factura.cliente.nom, |
135 | OPE: $scope.factura.vendedor.CodVen, | 136 | OPE: $scope.factura.vendedor.CodVen, |
136 | PAG: $scope.getTotal(), | 137 | PAG: $scope.getTotal(), |
137 | PER: 0, | 138 | PER: 0, |
138 | PER_IVA: 0, | 139 | PER_IVA: 0, |
139 | PLA: $scope.factura.vendedor.NplVen, | 140 | PLA: $scope.factura.vendedor.NplVen, |
140 | PRO: '', | 141 | PRO: '', |
141 | REC_ANT: 0, | 142 | REC_ANT: 0, |
142 | SUC: parseInt($scope.puntoVenta), | 143 | SUC: parseInt($scope.puntoVenta), |
143 | TCA: 1, | 144 | TCA: 1, |
144 | TCO: 'FT', | 145 | TCO: 'FT', |
145 | TFI: '', | 146 | TFI: '', |
146 | TIP: $scope.factura.cliente.tipoFactura, | 147 | TIP: $scope.factura.cliente.tipoFactura, |
147 | TIV: 0, // TODO | 148 | TIV: 0, // TODO |
148 | TOT: $scope.getTotal(), | 149 | TOT: $scope.getTotal(), |
149 | TUR: 0, // TODO | 150 | TUR: 0, // TODO |
150 | VEN: $scope.factura.vendedor.CodVen, | 151 | VEN: $scope.factura.vendedor.CodVen, |
151 | VTO_CLI: '', | 152 | VTO_CLI: '', |
152 | ZON: 1, // TODO | 153 | ZON: 1, // TODO |
153 | OBSERVACIONES: $scope.factura.observaciones | 154 | OBSERVACIONES: $scope.factura.observaciones |
154 | }, | 155 | }, |
155 | cuerpo: $scope.articulosFiltro() | 156 | cuerpo: $scope.articulosFiltro(), |
157 | despachos: $scope.factura.despachos | ||
156 | }; | 158 | }; |
157 | 159 | ||
158 | crearFacturaService.guardarFactura(save).then(function(res) { | 160 | crearFacturaService.guardarFactura(save).then(function(res) { |
159 | 161 | ||
160 | focaBotoneraLateralService.endGuardar(true); | 162 | focaBotoneraLateralService.endGuardar(true); |
161 | 163 | ||
162 | focaModalService.alert('Comprobante guardado con éxito'); | 164 | focaModalService.alert('Comprobante guardado con éxito'); |
163 | 165 | ||
164 | config(); | 166 | config(); |
165 | 167 | ||
166 | }).catch(function(err) { | 168 | }).catch(function(err) { |
167 | focaModalService.alert('Hubo un error al guardar la factura'); | 169 | focaModalService.alert('Hubo un error al guardar la factura'); |
168 | console.log(err); | 170 | console.log(err); |
169 | }); | 171 | }); |
170 | 172 | ||
171 | }; | 173 | }; |
172 | 174 | ||
173 | $scope.seleccionarCliente = function () { | 175 | $scope.seleccionarCliente = function () { |
174 | 176 | ||
175 | var modalInstance = $uibModal.open( | 177 | var modalInstance = $uibModal.open( |
176 | { | 178 | { |
177 | ariaLabelledBy: 'Busqueda de Cliente', | 179 | ariaLabelledBy: 'Busqueda de Cliente', |
178 | templateUrl: 'foca-busqueda-cliente-modal.html', | 180 | templateUrl: 'foca-busqueda-cliente-modal.html', |
179 | controller: 'focaBusquedaClienteModalController', | 181 | controller: 'focaBusquedaClienteModalController', |
180 | resolve: { | 182 | resolve: { |
181 | vendedor: function () { return null; }, | 183 | vendedor: function () { return null; }, |
182 | cobrador: function () { return null; } | 184 | cobrador: function () { return null; } |
183 | }, | 185 | }, |
184 | size: 'lg' | 186 | size: 'lg' |
185 | } | 187 | } |
186 | ); | 188 | ); |
187 | modalInstance.result.then( | 189 | modalInstance.result.then( |
188 | function (cliente) { | 190 | function (cliente) { |
189 | $scope.factura.cliente = cliente; | 191 | $scope.factura.cliente = cliente; |
190 | 192 | ||
191 | $scope.$broadcast('addCabecera', { | 193 | $scope.$broadcast('addCabecera', { |
192 | label: 'Cliente:', | 194 | label: 'Cliente:', |
193 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom | 195 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom |
194 | }); | 196 | }); |
195 | 197 | ||
196 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 198 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
197 | 199 | ||
198 | }, function () { | 200 | }, function () { |
199 | } | 201 | } |
200 | ); | 202 | ); |
201 | 203 | ||
202 | }; | 204 | }; |
203 | 205 | ||
204 | $scope.seleccionarVendedor = function() { | 206 | $scope.seleccionarVendedor = function() { |
205 | var parametrosModal = { | 207 | var parametrosModal = { |
206 | titulo: 'Búsqueda vendedores', | 208 | titulo: 'Búsqueda vendedores', |
207 | query: '/vendedor-playa', | 209 | query: '/vendedor-playa', |
208 | columnas: [ | 210 | columnas: [ |
209 | { | 211 | { |
210 | propiedad: 'CodVen', | 212 | propiedad: 'CodVen', |
211 | nombre: 'Código', | 213 | nombre: 'Código', |
212 | filtro: { | 214 | filtro: { |
213 | nombre: 'rellenarDigitos', | 215 | nombre: 'rellenarDigitos', |
214 | parametro: 3 | 216 | parametro: 3 |
215 | } | 217 | } |
216 | }, | 218 | }, |
217 | { | 219 | { |
218 | propiedad: 'NomVen', | 220 | propiedad: 'NomVen', |
219 | nombre: 'Nombre' | 221 | nombre: 'Nombre' |
220 | } | 222 | } |
221 | ], | 223 | ], |
222 | size: 'md' | 224 | size: 'md' |
223 | }; | 225 | }; |
224 | focaModalService.modal(parametrosModal).then( | 226 | focaModalService.modal(parametrosModal).then( |
225 | function (vendedor) { | 227 | function (vendedor) { |
226 | 228 | ||
227 | indicarPassword(vendedor) | 229 | indicarPassword(vendedor) |
228 | .then(function() { | 230 | .then(function() { |
229 | validarPlanillaVendedor(vendedor) | 231 | validarPlanillaVendedor(vendedor) |
230 | .then(function() { | 232 | .then(function() { |
231 | 233 | ||
232 | $filter('filter')($scope.botonera, { | 234 | $filter('filter')($scope.botonera, { |
233 | label: 'Vendedor' | 235 | label: 'Vendedor' |
234 | })[0].checked = true; | 236 | })[0].checked = true; |
235 | 237 | ||
236 | $scope.$broadcast('addCabecera', { | 238 | $scope.$broadcast('addCabecera', { |
237 | label: 'Vendedor:', | 239 | label: 'Vendedor:', |
238 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 240 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + |
239 | ' - ' + | 241 | ' - ' + |
240 | vendedor.NomVen | 242 | vendedor.NomVen |
241 | }); | 243 | }); |
242 | 244 | ||
243 | $scope.factura.vendedor = vendedor; | 245 | $scope.factura.vendedor = vendedor; |
244 | 246 | ||
245 | getProductosByPlanilla(vendedor.NplVen); | 247 | getProductosByPlanilla(vendedor.NplVen); |
246 | }) | 248 | }) |
247 | .catch($scope.seleccionarVendedor); | 249 | .catch($scope.seleccionarVendedor); |
248 | }) | 250 | }) |
249 | .catch(function(err) { | 251 | .catch(function(err) { |
250 | console.log(err) | 252 | console.log(err) |
251 | }); | 253 | }); |
252 | 254 | ||
253 | }, function () { } | 255 | }, function () { } |
254 | ); | 256 | ); |
255 | }; | 257 | }; |
256 | 258 | ||
257 | $scope.seleccionarMoneda = function () { | 259 | $scope.seleccionarMoneda = function () { |
258 | 260 | ||
259 | var parametrosModal = { | 261 | var parametrosModal = { |
260 | titulo: 'Búsqueda de monedas', | 262 | titulo: 'Búsqueda de monedas', |
261 | query: '/moneda', | 263 | query: '/moneda', |
262 | columnas: [ | 264 | columnas: [ |
263 | { | 265 | { |
264 | propiedad: 'DETALLE', | 266 | propiedad: 'DETALLE', |
265 | nombre: 'Nombre' | 267 | nombre: 'Nombre' |
266 | }, | 268 | }, |
267 | { | 269 | { |
268 | propiedad: 'SIMBOLO', | 270 | propiedad: 'SIMBOLO', |
269 | nombre: 'Símbolo' | 271 | nombre: 'Símbolo' |
270 | } | 272 | } |
271 | ], | 273 | ], |
272 | size: 'md' | 274 | size: 'md' |
273 | }; | 275 | }; |
274 | focaModalService.modal(parametrosModal).then( | 276 | focaModalService.modal(parametrosModal).then( |
275 | function (moneda) { | 277 | function (moneda) { |
276 | 278 | ||
277 | if (moneda.ID !== 1) { | 279 | if (moneda.ID !== 1) { |
278 | $scope.abrirModalCotizacion(moneda); | 280 | $scope.abrirModalCotizacion(moneda); |
279 | return; | 281 | return; |
280 | } | 282 | } |
281 | 283 | ||
282 | crearRemitoService.getCotizacionByIdMoneda(1) | 284 | crearRemitoService.getCotizacionByIdMoneda(1) |
283 | .then(function (res) { | 285 | .then(function (res) { |
284 | 286 | ||
285 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 287 | cotizacionPArgentino = res.data[0].cotizaciones[0]; |
286 | cotizacionPArgentino.moneda = moneda; | 288 | cotizacionPArgentino.moneda = moneda; |
287 | 289 | ||
288 | actualizarCabeceraMoneda(cotizacionPArgentino); | 290 | actualizarCabeceraMoneda(cotizacionPArgentino); |
289 | 291 | ||
290 | $scope.remito.cotizacion = cotizacionPArgentino; | 292 | $scope.remito.cotizacion = cotizacionPArgentino; |
291 | }); | 293 | }); |
292 | }, function () { | 294 | }, function () { |
293 | 295 | ||
294 | } | 296 | } |
295 | ); | 297 | ); |
296 | }; | 298 | }; |
297 | 299 | ||
298 | $scope.abrirModalCotizacion = function (moneda) { | 300 | $scope.abrirModalCotizacion = function (moneda) { |
299 | var modalInstance = $uibModal.open( | 301 | var modalInstance = $uibModal.open( |
300 | { | 302 | { |
301 | ariaLabelledBy: 'Busqueda de Cotización', | 303 | ariaLabelledBy: 'Busqueda de Cotización', |
302 | templateUrl: 'modal-cotizacion.html', | 304 | templateUrl: 'modal-cotizacion.html', |
303 | controller: 'focaModalCotizacionController', | 305 | controller: 'focaModalCotizacionController', |
304 | size: 'lg', | 306 | size: 'lg', |
305 | resolve: { idMoneda: function () { return moneda.ID; } } | 307 | resolve: { idMoneda: function () { return moneda.ID; } } |
306 | } | 308 | } |
307 | ); | 309 | ); |
308 | modalInstance.result.then( | 310 | modalInstance.result.then( |
309 | function (cotizacion) { | 311 | function (cotizacion) { |
310 | 312 | ||
311 | cotizacion.moneda = moneda; | 313 | cotizacion.moneda = moneda; |
312 | actualizarCabeceraMoneda(cotizacion); | 314 | actualizarCabeceraMoneda(cotizacion); |
313 | $scope.factura.cotizacion = cotizacion; | 315 | $scope.factura.cotizacion = cotizacion; |
314 | 316 | ||
315 | }, function () { | 317 | }, function () { |
316 | 318 | ||
317 | } | 319 | } |
318 | ); | 320 | ); |
319 | }; | 321 | }; |
320 | 322 | ||
321 | $scope.seleccionarObservaciones = function () { | 323 | $scope.seleccionarObservaciones = function () { |
322 | var observacion = { | 324 | var observacion = { |
323 | titulo: 'Ingrese Observaciones', | 325 | titulo: 'Ingrese Observaciones', |
324 | value: $scope.factura.observaciones, | 326 | value: $scope.factura.observaciones, |
325 | maxlength: 155, | 327 | maxlength: 155, |
326 | textarea: true | 328 | textarea: true |
327 | }; | 329 | }; |
328 | 330 | ||
329 | focaModalService | 331 | focaModalService |
330 | .prompt(observacion) | 332 | .prompt(observacion) |
331 | .then(function (observaciones) { | 333 | .then(function (observaciones) { |
332 | $scope.factura.observaciones = observaciones; | 334 | $scope.factura.observaciones = observaciones; |
333 | }); | 335 | }); |
334 | }; | 336 | }; |
335 | 337 | ||
336 | |||
337 | $scope.articulosFiltro = function () { | 338 | $scope.articulosFiltro = function () { |
338 | return $scope.factura.articulosFactura; | 339 | return $scope.factura.articulosFactura; |
339 | }; | 340 | }; |
340 | 341 | ||
341 | $scope.getTotal = function () { | 342 | $scope.getTotal = function () { |
342 | 343 | ||
343 | var total = 0; | 344 | var total = 0; |
344 | 345 | ||
345 | $scope.articulosFiltro().forEach(function (articulo) { | 346 | $scope.articulosFiltro().forEach(function (articulo) { |
346 | total += articulo.PUN * articulo.CAN; | 347 | total += articulo.PUN * articulo.CAN; |
347 | }); | 348 | }); |
348 | 349 | ||
349 | return parseFloat(total.toFixed(2)); | 350 | return parseFloat(total.toFixed(2)); |
350 | }; | 351 | }; |
351 | 352 | ||
352 | function getProductosByPlanilla(numeroPlanilla) { | 353 | function getProductosByPlanilla(numeroPlanilla) { |
353 | 354 | ||
354 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function(res) { | 355 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function(res) { |
355 | 356 | ||
356 | res.data.forEach(function (producto) { | 357 | res.data.forEach(function (producto) { |
357 | 358 | ||
358 | $scope.botonera.push({ | 359 | $scope.botonera.push({ |
359 | label: producto.DetArt, | 360 | label: producto.DetArt, |
360 | image: 'productos.png' | 361 | image: 'productos.png' |
361 | }); | 362 | }); |
362 | 363 | ||
363 | 364 | ||
364 | crearFuncionesProductos(producto); | 365 | crearFuncionesProductos(producto); |
365 | 366 | ||
366 | }); | 367 | }); |
367 | }); | 368 | }); |
368 | } | 369 | } |
369 | 370 | ||
370 | function crearFuncionesProductos(producto) { | 371 | function crearFuncionesProductos(producto) { |
371 | 372 | ||
372 | $scope[nombreFuncion(producto.DetArt)] = function() { | 373 | $scope[nombreFuncion(producto.DetArt)] = function() { |
373 | 374 | ||
374 | if (angular.equals($scope.factura.cliente, {})) { | 375 | if (angular.equals($scope.factura.cliente, {})) { |
375 | focaModalService.alert('Seleccione cliente'); | 376 | focaModalService.alert('Seleccione cliente'); |
376 | return; | 377 | return; |
377 | } | 378 | } |
378 | 379 | ||
379 | var parametrosModal = { | 380 | var parametrosModal = { |
380 | titulo: 'Despachos ' + producto.DetArt, | 381 | titulo: 'Despachos ' + producto.DetArt, |
381 | data: producto.despachos, | 382 | data: producto.despachos, |
382 | columnas: [ | 383 | columnas: [ |
383 | { | 384 | { |
384 | propiedad: 'FEC', | 385 | propiedad: 'FEC', |
385 | nombre: 'Fecha', | 386 | nombre: 'Fecha', |
386 | filtro: { | 387 | filtro: { |
387 | nombre: 'date', | 388 | nombre: 'date', |
388 | parametro: 'dd/MM/yyyy HH:mm' | 389 | parametro: 'dd/MM/yyyy HH:mm' |
389 | } | 390 | } |
390 | }, | 391 | }, |
391 | { | 392 | { |
392 | propiedad: 'IMP', | 393 | propiedad: 'IMP', |
393 | nombre: 'Importe' | 394 | nombre: 'Importe' |
394 | }, | 395 | }, |
395 | { | 396 | { |
396 | propiedad: 'LTS', | 397 | propiedad: 'LTS', |
397 | nombre: 'Litros' | 398 | nombre: 'Litros' |
398 | } | 399 | } |
399 | ], | 400 | ], |
400 | size: 'md' | 401 | size: 'md' |
401 | }; | 402 | }; |
402 | 403 | ||
403 | focaModalService.modal(parametrosModal).then(function(despacho) { | 404 | focaModalService.modal(parametrosModal).then(function(despacho) { |
404 | 405 | ||
405 | var articulo = { | 406 | var articulo = { |
406 | TIP: $scope.factura.cliente.tipoFactura, | 407 | TIP: $scope.factura.cliente.tipoFactura, |
407 | TCO: 'FT', | 408 | TCO: 'FT', |
408 | SUC: parseInt($scope.puntoVenta), | 409 | SUC: parseInt($scope.puntoVenta), |
409 | ORD: $scope.articulosFiltro().length + 1, | 410 | ORD: $scope.articulosFiltro().length + 1, |
410 | SEC: despacho.SEC, | 411 | SEC: despacho.SEC, |
411 | ART: despacho.PRO, | 412 | ART: despacho.PRO, |
412 | RUB: producto.CodRub, | 413 | RUB: producto.CodRub, |
413 | DES: producto.DetArt, | 414 | DES: producto.DetArt, |
414 | CAN: despacho.LTS, | 415 | CAN: despacho.LTS, |
415 | PUN: producto.PreVen, // TODO | 416 | PUN: producto.PreVen, // TODO |
416 | IVA: producto.IMPIVA, // TODO | 417 | IVA: producto.IMPIVA, // TODO |
417 | NET: 0, // TODO | 418 | NET: 0, // TODO |
418 | NEX: 0, // TODO | 419 | NEX: 0, // TODO |
419 | IMI: producto.ImpInt, // TODO | 420 | IMI: producto.ImpInt, // TODO |
420 | IMI2: producto.ImpInt2, // TODO | 421 | IMI2: producto.ImpInt2, // TODO |
421 | IMI3: producto.ImpInt3, // TODO | 422 | IMI3: producto.ImpInt3, // TODO |
422 | PUT: producto.PreNet, // TODO | 423 | PUT: producto.PreNet, // TODO |
423 | SUR: despacho.SUR, | 424 | SUR: despacho.SUR, |
424 | PLA: despacho.PLA, | 425 | PLA: despacho.PLA, |
425 | LUG: despacho.LUG, | 426 | LUG: despacho.LUG, |
426 | LEG: $scope.factura.vendedor.CodVen, | 427 | LEG: $scope.factura.vendedor.CodVen, |
427 | TUR: $scope.factura.vendedor.TurVen, | 428 | TUR: $scope.factura.vendedor.TurVen, |
428 | ORDEN_PRECOMPRA: '', | 429 | ORDEN_PRECOMPRA: '', |
429 | ESC: producto.tipoFactura == 'L' ? 1 : 0, | 430 | ESC: producto.tipoFactura == 'L' ? 1 : 0, |
430 | CMF: 0, | 431 | CMF: 0, |
431 | PTA: 0, | 432 | PTA: 0, |
432 | IVS: 0, | 433 | IVS: 0, |
433 | TIVA: 0, | 434 | TIVA: 0, |
434 | CON: 0, | 435 | CON: 0, |
435 | SINO: '', | 436 | SINO: '', |
436 | ORD_TRA: 0, | 437 | ORD_TRA: 0, |
437 | IMP_DESP: 0, | 438 | IMP_DESP: 0, |
438 | PCD: 0, | 439 | PCD: 0, |
439 | RTO: '' | 440 | RTO: '' |
440 | }; | 441 | }; |
441 | 442 | ||
442 | $scope.factura.articulosFactura.push(articulo); | 443 | crearFacturaService.setearDespachoOcupado({ |
444 | surtidor: despacho.SUR, | ||
445 | producto: despacho.PRO, | ||
446 | carga: despacho.CAR | ||
447 | }) | ||
448 | .then(function () { | ||
449 | $scope.factura.articulosFactura.push(articulo); | ||
450 | $scope.factura.despachos.push(despacho); | ||
451 | }) | ||
452 | .catch(function (err) { | ||
453 | |||
454 | focaModalService.alert('El despacho esta en uso'); | ||
455 | }); | ||
456 | |||
443 | }) | 457 | }) |
444 | .catch(function (err) { | 458 | .catch(function (err) { |
445 | console.log(err) | 459 | console.log(err); |
446 | }); | 460 | }); |
447 | 461 | ||
448 | }; | 462 | }; |
449 | } | 463 | } |
450 | 464 | ||
451 | function nombreFuncion(string) { | 465 | function nombreFuncion(string) { |
452 | var texto = 'seleccionar'; | 466 | var texto = 'seleccionar'; |
453 | var arr = string.split(' '); | 467 | var arr = string.split(' '); |
454 | arr.forEach(function(palabra) { | 468 | arr.forEach(function(palabra) { |
455 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 469 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); |
456 | texto += palabra; | 470 | texto += palabra; |
457 | }); | 471 | }); |
458 | return texto; | 472 | return texto; |
459 | } | 473 | } |
460 | 474 | ||
461 | function indicarPassword(vendedor) { | 475 | function indicarPassword(vendedor) { |
462 | 476 | ||
463 | return new Promise(function(resolve, reject) { | 477 | return new Promise(function(resolve, reject) { |
464 | 478 | ||
465 | focaModalService | 479 | focaModalService |
466 | .prompt({ | 480 | .prompt({ |
467 | titulo: 'Indique Contraseña', | 481 | titulo: 'Indique Contraseña', |
468 | value: '' | 482 | value: '' |
469 | }) | 483 | }) |
470 | .then(function (contraseña) { | 484 | .then(function (contraseña) { |
471 | 485 | ||
472 | if (contraseña != vendedor.ClaVen.trim()) { | 486 | if (contraseña != vendedor.ClaVen.trim()) { |
473 | 487 | ||
474 | focaModalService.alert('Clave incorrecta').then(function() { | 488 | focaModalService.alert('Clave incorrecta').then(function() { |
475 | indicarPassword(vendedor); | 489 | indicarPassword(vendedor); |
476 | }); | 490 | }); |
477 | } else { | 491 | } else { |
478 | resolve(); | 492 | resolve(); |
479 | } | 493 | } |
480 | }) | 494 | }) |
481 | .catch(reject); | 495 | .catch(reject); |
482 | }); | 496 | }); |
483 | } | 497 | } |
484 | 498 | ||
485 | function validarPlanillaVendedor(vendedor) { | 499 | function validarPlanillaVendedor(vendedor) { |
486 | 500 | ||
487 | return new Promise(function(resolve, reject) { | 501 | return new Promise(function(resolve, reject) { |
488 | 502 | ||
489 | crearFacturaService | 503 | crearFacturaService |
490 | .validarPlanillaVendedor(vendedor.CodVen.trim()) | 504 | .validarPlanillaVendedor(vendedor.CodVen.trim()) |
491 | .then(function (res) { | 505 | .then(function (res) { |
492 | 506 | ||
493 | if (!res.data.length) { | 507 | if (!res.data.length) { |
494 | 508 | ||
495 | focaModalService | 509 | focaModalService |
496 | .alert('No se encontró planilla abierta para el vendedor') | 510 | .alert('No se encontró planilla abierta para el vendedor') |
497 | .then(reject); | 511 | .then(reject); |
498 | 512 | ||
499 | } else { | 513 | } else { |
500 | resolve(); | 514 | resolve(); |
501 | } | 515 | } |
502 | 516 | ||
503 | }) | 517 | }) |
504 | .catch(reject); | 518 | .catch(reject); |
505 | }); | 519 | }); |
506 | } | 520 | } |
507 | 521 | ||
508 | function rellenar(relleno, longitud) { | 522 | function rellenar(relleno, longitud) { |
509 | relleno = '' + relleno; | 523 | relleno = '' + relleno; |
510 | while (relleno.length < longitud) { | 524 | while (relleno.length < longitud) { |
511 | relleno = '0' + relleno; | 525 | relleno = '0' + relleno; |
512 | } | 526 | } |
513 | return relleno; | 527 | return relleno; |
514 | } | 528 | } |
515 | 529 | ||
516 | function salir() { | 530 | function salir() { |
517 | var confirmacion = false; | 531 | var confirmacion = false; |
518 | 532 | ||
519 | if (!angular.equals($scope.factura, $scope.inicial)) { | 533 | if (!angular.equals($scope.factura, $scope.inicial)) { |
520 | confirmacion = true; | 534 | confirmacion = true; |
521 | } | 535 | } |
522 | 536 | ||
523 | if (confirmacion) { | 537 | if (confirmacion) { |
524 | focaModalService.confirm( | 538 | focaModalService.confirm( |
525 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 539 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
526 | ).then(function (data) { | 540 | ).then(function (data) { |
527 | if (data) { | 541 | if (data) { |
528 | $location.path('/'); | 542 | $location.path('/'); |
529 | } | 543 | } |
530 | }); | 544 | }); |
531 | } else { | 545 | } else { |
532 | $location.path('/'); | 546 | $location.path('/'); |
533 | } | 547 | } |
534 | } | 548 | } |
535 | 549 | ||
536 | function setearFactura(factura) { | 550 | function setearFactura(factura) { |
537 | 551 | ||
538 | $scope.$broadcast('cleanCabecera'); | 552 | $scope.$broadcast('cleanCabecera'); |
539 | 553 | ||
540 | $scope.cabeceras = []; | 554 | $scope.cabeceras = []; |
541 | 555 | ||
542 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 556 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
543 | $scope.cabeceras.push({ | 557 | $scope.cabeceras.push({ |
544 | label: 'Moneda:', | 558 | label: 'Moneda:', |
545 | valor: factura.cotizacion.moneda.DETALLE | 559 | valor: factura.cotizacion.moneda.DETALLE |
546 | }); | 560 | }); |
547 | $scope.cabeceras.push({ | 561 | $scope.cabeceras.push({ |
548 | label: 'Fecha cotizacion:', | 562 | label: 'Fecha cotizacion:', |
549 | valor: $filter('date')(factura.cotizacion.FECHA, | 563 | valor: $filter('date')(factura.cotizacion.FECHA, |
550 | 'dd/MM/yyyy') | 564 | 'dd/MM/yyyy') |
551 | }); | 565 | }); |
552 | $scope.cabeceras.push({ | 566 | $scope.cabeceras.push({ |
553 | label: 'Cotizacion:', | 567 | label: 'Cotizacion:', |
554 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 568 | valor: $filter('number')(factura.cotizacion.VENDEDOR, |
555 | '2') | 569 | '2') |
556 | }); | 570 | }); |
557 | } | 571 | } |
558 | 572 | ||
559 | if (factura.cotizacion && factura.cotizacion.moneda) { | 573 | if (factura.cotizacion && factura.cotizacion.moneda) { |
560 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 574 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
561 | } | 575 | } |
562 | 576 | ||
563 | if (factura.cliente && factura.cliente.cod) { | 577 | if (factura.cliente && factura.cliente.cod) { |
564 | $scope.cabeceras.push({ | 578 | $scope.cabeceras.push({ |
565 | label: 'Cliente:', | 579 | label: 'Cliente:', |
566 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 580 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + |
567 | factura.cliente.nom | 581 | factura.cliente.nom |
568 | }); | 582 | }); |
569 | 583 | ||
570 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 584 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
571 | } | 585 | } |
572 | 586 | ||
573 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 587 | $scope.puntoVenta = rellenar(factura.sucursal, 4); |
574 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 588 | $scope.comprobante = rellenar(factura.numerofactura, 8); |
575 | $scope.factura = factura; | 589 | $scope.factura = factura; |
576 | 590 | ||
577 | addArrayCabecera($scope.cabeceras); | 591 | addArrayCabecera($scope.cabeceras); |
578 | } | 592 | } |
579 | 593 | ||
580 | function getLSFactura() { | 594 | function getLSFactura() { |
581 | var factura = JSON.parse($localStorage.factura || null); | 595 | var factura = JSON.parse($localStorage.factura || null); |
582 | if (factura) { | 596 | if (factura) { |
583 | setearFactura(factura); | 597 | setearFactura(factura); |
584 | delete $localStorage.factura; | 598 | delete $localStorage.factura; |
585 | } | 599 | } |
586 | } | 600 | } |
587 | 601 | ||
588 | function addArrayCabecera(array) { | 602 | function addArrayCabecera(array) { |
589 | for (var i = 0; i < array.length; i++) { | 603 | for (var i = 0; i < array.length; i++) { |
590 | $scope.$broadcast('addCabecera', { | 604 | $scope.$broadcast('addCabecera', { |
591 | label: array[i].label, | 605 | label: array[i].label, |
592 | valor: array[i].valor | 606 | valor: array[i].valor |
593 | }); | 607 | }); |
594 | } | 608 | } |
595 | } | 609 | } |
596 | 610 | ||
597 | function actualizarCabeceraMoneda(cotizacion) { | 611 | function actualizarCabeceraMoneda(cotizacion) { |
598 | 612 | ||
599 | $scope.factura.articulosFactura.forEach(function (art) { | 613 | $scope.factura.articulosFactura.forEach(function (art) { |
600 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 614 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); |
601 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 615 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); |
602 | }); | 616 | }); |
603 | 617 | ||
604 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 618 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
605 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 619 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
606 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 620 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
607 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 621 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
608 | } else { | 622 | } else { |
609 | $scope.$broadcast('addCabecera', { | 623 | $scope.$broadcast('addCabecera', { |
610 | label: 'Moneda:', | 624 | label: 'Moneda:', |
611 | valor: cotizacion.moneda.DETALLE | 625 | valor: cotizacion.moneda.DETALLE |
612 | }); | 626 | }); |
613 | $scope.$broadcast('addCabecera', { | 627 | $scope.$broadcast('addCabecera', { |
614 | label: 'Fecha cotizacion:', | 628 | label: 'Fecha cotizacion:', |
615 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 629 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
616 | }); | 630 | }); |
617 | $scope.$broadcast('addCabecera', { | 631 | $scope.$broadcast('addCabecera', { |
618 | label: 'Cotizacion:', | 632 | label: 'Cotizacion:', |
619 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 633 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
620 | }); | 634 | }); |
621 | } | 635 | } |
622 | } | 636 | } |
623 | 637 | ||
624 | function validarGuardar() { | 638 | function validarGuardar() { |
625 | 639 | ||
626 | if (angular.equals({}, $scope.factura.vendedor)) { | 640 | if (angular.equals({}, $scope.factura.vendedor)) { |
627 | 641 | ||
628 | focaModalService.alert('Seleccione Vendedor'); | 642 | focaModalService.alert('Seleccione Vendedor'); |
629 | return false; | 643 | return false; |
630 | } else if (angular.equals({}, $scope.factura.cliente)) { | 644 | } else if (angular.equals({}, $scope.factura.cliente)) { |
631 | 645 | ||
632 | focaModalService.alert('Seleccione Cliente') | 646 | focaModalService.alert('Seleccione Cliente') |
633 | return false; | 647 | return false; |
634 | } else if (!$scope.articulosFiltro().length) { | 648 | } else if (!$scope.articulosFiltro().length) { |
635 | 649 | ||
636 | focaModalService.alert('Seleccione al menos un Articulo'); | 650 | focaModalService.alert('Seleccione al menos un Articulo'); |
637 | return false; | 651 | return false; |
638 | } | 652 | } |
639 | 653 | ||
640 | return true; | 654 | return true; |
641 | } | 655 | } |
642 | } | 656 | } |
643 | ]); | 657 | ]); |
src/js/service.js
1 | angular.module('focaCrearFactura') | 1 | angular.module('focaCrearFactura') |
2 | .service('crearFacturaService', ['$http', 'API_ENDPOINT', | 2 | .service('crearFacturaService', ['$http', 'API_ENDPOINT', |
3 | function($http, API_ENDPOINT) { | 3 | function($http, API_ENDPOINT) { |
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) { | ||
19 | return $http.post(route + '/turnos/despacho-en-uso', parametros); | ||
20 | }, | ||
18 | getBotonera: function() { | 21 | getBotonera: function() { |
19 | return [ | 22 | return [ |
20 | { | 23 | { |
21 | label: 'Vendedor', | 24 | label: 'Vendedor', |
22 | image: 'vendedor.png' | 25 | image: 'vendedor.png' |
23 | }, | 26 | }, |
24 | { | 27 | { |
25 | label: 'Cliente', | 28 | label: 'Cliente', |
26 | image: 'cliente.png' | 29 | image: 'cliente.png' |
27 | }, | 30 | }, |
28 | { | 31 | { |
29 | label: 'Moneda', | 32 | label: 'Moneda', |
30 | image: 'moneda.png' | 33 | image: 'moneda.png' |
31 | }, | 34 | }, |
32 | { | 35 | { |
33 | label: 'Observaciones', | 36 | label: 'Observaciones', |
34 | image: 'botonObservaciones.png' | 37 | image: 'botonObservaciones.png' |
35 | } | 38 | } |
36 | ]; | 39 | ]; |
37 | } | 40 | } |
38 | }; | 41 | }; |
39 | }]); | 42 | }]); |
40 | 43 |