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