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