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