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