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