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