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