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