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