Commit 20d877e7a2d304896db2ee120a28b27ff42d05d9
1 parent
78db92a556
Exists in
master
fix domicilio, localidad, provincia
Showing
1 changed file
with
6 additions
and
2 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearCobranza') .controller('cobranzaController', | 1 | angular.module('focaCrearCobranza') .controller('cobranzaController', |
2 | [ | 2 | [ |
3 | '$scope', '$timeout', '$uibModal', '$location', | 3 | '$scope', '$timeout', '$uibModal', '$location', |
4 | 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', | 4 | 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', |
5 | 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', | 5 | 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', |
6 | function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, | 6 | function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, |
7 | focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, | 7 | focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, |
8 | APP, loginService, $localStorage) | 8 | APP, loginService, $localStorage) |
9 | { | 9 | { |
10 | config(); | 10 | config(); |
11 | 11 | ||
12 | function config() { | 12 | function config() { |
13 | $scope.datepickerAbierto = false; | 13 | $scope.datepickerAbierto = false; |
14 | $scope.cobroDeuda = true; | 14 | $scope.cobroDeuda = true; |
15 | $scope.show = false; | 15 | $scope.show = false; |
16 | $scope.cargando = true; | 16 | $scope.cargando = true; |
17 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 17 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
18 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 18 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
19 | $scope.botonera = focaCrearCobranzaService.getBotonera(); | 19 | $scope.botonera = focaCrearCobranzaService.getBotonera(); |
20 | $scope.dateOptions = { | 20 | $scope.dateOptions = { |
21 | maxDate: new Date(), | 21 | maxDate: new Date(), |
22 | minDate: new Date(2010, 0, 1) | 22 | minDate: new Date(2010, 0, 1) |
23 | }; | 23 | }; |
24 | 24 | ||
25 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 25 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
26 | focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { | 26 | focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { |
27 | var moneda = res.data[0]; | 27 | var moneda = res.data[0]; |
28 | moneda.cotizacion = moneda.cotizaciones[0]; | 28 | moneda.cotizacion = moneda.cotizaciones[0]; |
29 | $scope.cobranza.moneda = $scope.inicial.moneda = moneda; | 29 | $scope.cobranza.moneda = $scope.inicial.moneda = moneda; |
30 | $filter('filter')( $scope.botonera, { | 30 | $filter('filter')( $scope.botonera, { |
31 | label: 'Moneda' | 31 | label: 'Moneda' |
32 | })[0].checked = true; | 32 | })[0].checked = true; |
33 | $timeout(function() { getLSCobranza();} ); | 33 | $timeout(function() { getLSCobranza();} ); |
34 | }); | 34 | }); |
35 | 35 | ||
36 | $timeout(function() { | 36 | $timeout(function() { |
37 | focaBotoneraLateralService.showSalir(false); | 37 | focaBotoneraLateralService.showSalir(false); |
38 | focaBotoneraLateralService.showPausar(true); | 38 | focaBotoneraLateralService.showPausar(true); |
39 | focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); | 39 | focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); |
40 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 40 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
41 | }); | 41 | }); |
42 | 42 | ||
43 | if (APP === 'cobranza') { | 43 | if (APP === 'cobranza') { |
44 | $scope.idCobrador = loginService.getLoginData().vendedorCobrador; | 44 | $scope.idCobrador = loginService.getLoginData().vendedorCobrador; |
45 | } | 45 | } |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | } | 48 | } |
49 | 49 | ||
50 | function init() { | 50 | function init() { |
51 | $scope.$broadcast('cleanCabecera'); | 51 | $scope.$broadcast('cleanCabecera'); |
52 | $scope.cobranza = { | 52 | $scope.cobranza = { |
53 | FEC: new Date(), | 53 | FEC: new Date(), |
54 | moneda: {}, | 54 | moneda: {}, |
55 | facturas: [], | 55 | facturas: [], |
56 | cobros: [], | 56 | cobros: [], |
57 | cliente: {}, | 57 | cliente: {}, |
58 | cobrador: {} | 58 | cobrador: {} |
59 | }; | 59 | }; |
60 | 60 | ||
61 | if (APP === 'cobranza') { | 61 | if (APP === 'cobranza') { |
62 | focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( | 62 | focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( |
63 | function(res) { | 63 | function(res) { |
64 | var cobrador = res.data; | 64 | var cobrador = res.data; |
65 | 65 | ||
66 | $scope.$broadcast('addCabecera', { | 66 | $scope.$broadcast('addCabecera', { |
67 | label: 'Cobrador:', | 67 | label: 'Cobrador:', |
68 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | 68 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + |
69 | cobrador.NOM | 69 | cobrador.NOM |
70 | }); | 70 | }); |
71 | 71 | ||
72 | $scope.cobranza.cobrador = cobrador; | 72 | $scope.cobranza.cobrador = cobrador; |
73 | $scope.inicial.cobrador = $scope.cobranza.cobrador; | 73 | $scope.inicial.cobrador = $scope.cobranza.cobrador; |
74 | } | 74 | } |
75 | ); | 75 | ); |
76 | } | 76 | } |
77 | 77 | ||
78 | $scope.inicial = angular.copy($scope.cobranza); | 78 | $scope.inicial = angular.copy($scope.cobranza); |
79 | 79 | ||
80 | focaCrearCobranzaService.getNumeroRecibo().then( | 80 | focaCrearCobranzaService.getNumeroRecibo().then( |
81 | function(res) { | 81 | function(res) { |
82 | $scope.puntoVenta = $filter('rellenarDigitos')( | 82 | $scope.puntoVenta = $filter('rellenarDigitos')( |
83 | res.data.sucursal, 4 | 83 | res.data.sucursal, 4 |
84 | ); | 84 | ); |
85 | 85 | ||
86 | $scope.comprobante = $filter('rellenarDigitos')( | 86 | $scope.comprobante = $filter('rellenarDigitos')( |
87 | res.data.numeroRecibo, 8 | 87 | res.data.numeroRecibo, 8 |
88 | ); | 88 | ); |
89 | }, | 89 | }, |
90 | function(err) { | 90 | function(err) { |
91 | focaModalService.alert( | 91 | focaModalService.alert( |
92 | 'La terminal no esta configurada correctamente' | 92 | 'La terminal no esta configurada correctamente' |
93 | ); | 93 | ); |
94 | console.info(err); | 94 | console.info(err); |
95 | } | 95 | } |
96 | ); | 96 | ); |
97 | } | 97 | } |
98 | 98 | ||
99 | $scope.$watch('cobranza', function(newValue) { | 99 | $scope.$watch('cobranza', function(newValue) { |
100 | focaBotoneraLateralService.setPausarData({ | 100 | focaBotoneraLateralService.setPausarData({ |
101 | label: 'cobranza', | 101 | label: 'cobranza', |
102 | val: newValue | 102 | val: newValue |
103 | }); | 103 | }); |
104 | }, true); | 104 | }, true); |
105 | 105 | ||
106 | $scope.crearCobranza = function() { | 106 | $scope.crearCobranza = function() { |
107 | if (!$scope.cobranza.cliente.COD) { | 107 | if (!$scope.cobranza.cliente.COD) { |
108 | focaModalService.alert('Ingrese Cliente'); | 108 | focaModalService.alert('Ingrese Cliente'); |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | if (!$scope.cobranza.cobrador.NUM) { | 111 | if (!$scope.cobranza.cobrador.NUM) { |
112 | focaModalService.alert('Ingrese Cobrador'); | 112 | focaModalService.alert('Ingrese Cobrador'); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | if ($scope.cobranza.facturas.length < 1) { | 115 | if ($scope.cobranza.facturas.length < 1) { |
116 | focaModalService.alert('Ingrese al menos una factura'); | 116 | focaModalService.alert('Ingrese al menos una factura'); |
117 | return; | 117 | return; |
118 | } | 118 | } |
119 | if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { | 119 | if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { |
120 | focaModalService.alert('La diferencia debe ser ' + | 120 | focaModalService.alert('La diferencia debe ser ' + |
121 | $scope.cobranza.moneda.SIMBOLO + '0,00'); | 121 | $scope.cobranza.moneda.SIMBOLO + '0,00'); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | var cobranza = {}; | 124 | var cobranza = {}; |
125 | var cheques = []; | 125 | var cheques = []; |
126 | var cuerpos = []; | 126 | var cuerpos = []; |
127 | var imgs = []; | 127 | var imgs = []; |
128 | var observacion; | 128 | var observacion; |
129 | //TODO: habilitar edición | 129 | //TODO: habilitar edición |
130 | $scope.editando = false; | 130 | $scope.editando = false; |
131 | focaBotoneraLateralService.startGuardar(); | 131 | focaBotoneraLateralService.startGuardar(); |
132 | $scope.saveLoading = true; | 132 | $scope.saveLoading = true; |
133 | for(var i = 0; i < $scope.cobranza.facturas.length; i++) { | 133 | for(var i = 0; i < $scope.cobranza.facturas.length; i++) { |
134 | var cuerpoFactura = { | 134 | var cuerpoFactura = { |
135 | CYV: 'V', | 135 | CYV: 'V', |
136 | TIP: 'C', | 136 | TIP: 'C', |
137 | TCO: 'RC', | 137 | TCO: 'RC', |
138 | PVE: $scope.puntoVenta, | 138 | PVE: $scope.puntoVenta, |
139 | NCO: $scope.comprobante, | 139 | NCO: $scope.comprobante, |
140 | LOP: 'L', | 140 | LOP: 'L', |
141 | TIL: $scope.cobranza.facturas[i].TCO, | 141 | TIL: $scope.cobranza.facturas[i].TCO, |
142 | COM: $scope.cobranza.facturas[i].numeroFactura + '-' + | 142 | COM: $scope.cobranza.facturas[i].numeroFactura + '-' + |
143 | $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU), | 143 | $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU), |
144 | FEC: new Date($scope.cobranza.FEC) | 144 | FEC: new Date($scope.cobranza.FEC) |
145 | .toISOString().slice(0, 19).replace('T', ' '), | 145 | .toISOString().slice(0, 19).replace('T', ' '), |
146 | IMP: Math.abs($scope.cobranza.facturas[i].IMP || | 146 | IMP: Math.abs($scope.cobranza.facturas[i].IMP || |
147 | $scope.cobranza.facturas[i].IPA), | 147 | $scope.cobranza.facturas[i].IPA), |
148 | RES: 0,//caja de tesorería | 148 | RES: 0,//caja de tesorería |
149 | SUBM: 0, | 149 | SUBM: 0, |
150 | NCU: $scope.cobranza.facturas[i].NCU | 150 | NCU: $scope.cobranza.facturas[i].NCU |
151 | }; | 151 | }; |
152 | cuerpos.push(cuerpoFactura); | 152 | cuerpos.push(cuerpoFactura); |
153 | } | 153 | } |
154 | for (var j = 0; j < $scope.cobranza.cobros.length; j++) { | 154 | for (var j = 0; j < $scope.cobranza.cobros.length; j++) { |
155 | var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo'; | 155 | var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo'; |
156 | var cuerpoCobros = { | 156 | var cuerpoCobros = { |
157 | CYV: 'V', | 157 | CYV: 'V', |
158 | TIP: 'C', | 158 | TIP: 'C', |
159 | TCO: 'RC', | 159 | TCO: 'RC', |
160 | PVE: $scope.puntoVenta, | 160 | PVE: $scope.puntoVenta, |
161 | NCO: $scope.comprobante, | 161 | NCO: $scope.comprobante, |
162 | LOP: 'P', | 162 | LOP: 'P', |
163 | TIL: $scope.cobranza.cobros[j].TIL, | 163 | TIL: $scope.cobranza.cobros[j].TIL, |
164 | COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM, | 164 | COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM, |
165 | FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? | 165 | FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? |
166 | new Date($scope.cobranza.cobros[j].FEC) | 166 | new Date($scope.cobranza.cobros[j].FEC) |
167 | .toISOString().slice(0, 19).replace('T', ' ') : | 167 | .toISOString().slice(0, 19).replace('T', ' ') : |
168 | new Date($scope.cobranza.cobros[j].fechaPresentacion) | 168 | new Date($scope.cobranza.cobros[j].fechaPresentacion) |
169 | .toISOString().slice(0, 19).replace('T', ' '), | 169 | .toISOString().slice(0, 19).replace('T', ' '), |
170 | IMP: Math.abs($scope.cobranza.cobros[j].IMP), | 170 | IMP: Math.abs($scope.cobranza.cobros[j].IMP), |
171 | RES: 0,//caja de tesorería | 171 | RES: 0,//caja de tesorería |
172 | SUBM: 0 | 172 | SUBM: 0 |
173 | }; | 173 | }; |
174 | cuerpos.push(cuerpoCobros); | 174 | cuerpos.push(cuerpoCobros); |
175 | 175 | ||
176 | if ($scope.cobranza.cobros[j].observacion) | 176 | if ($scope.cobranza.cobros[j].observacion) |
177 | observacion = $scope.cobranza.cobros[j].observacion; | 177 | observacion = $scope.cobranza.cobros[j].observacion; |
178 | 178 | ||
179 | if ($scope.cobranza.cobros[j].banco) { | 179 | if ($scope.cobranza.cobros[j].banco) { |
180 | var cheque = { | 180 | var cheque = { |
181 | BCO: $scope.cobranza.cobros[j].banco.ID, | 181 | BCO: $scope.cobranza.cobros[j].banco.ID, |
182 | NUM: $scope.comprobante, | 182 | NUM: $scope.comprobante, |
183 | FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion) | 183 | FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion) |
184 | .toISOString().slice(0, 19).replace('T', ' '), | 184 | .toISOString().slice(0, 19).replace('T', ' '), |
185 | FEE: new Date($scope.cobranza.cobros[j].fechaEmision) | 185 | FEE: new Date($scope.cobranza.cobros[j].fechaEmision) |
186 | .toISOString().slice(0, 19).replace('T', ' '), | 186 | .toISOString().slice(0, 19).replace('T', ' '), |
187 | LUG: $scope.cobranza.cobros[j].localidad.NOMBRE, | 187 | LUG: $scope.cobranza.cobros[j].localidad.NOMBRE, |
188 | IMP: $scope.cobranza.cobros[j].importe, | 188 | IMP: $scope.cobranza.cobros[j].importe, |
189 | LIB: $scope.cobranza.cobros[j].librador, | 189 | LIB: $scope.cobranza.cobros[j].librador, |
190 | EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera | 190 | EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera |
191 | PCI: $scope.cobranza.cobros[j].provincia.ID, | 191 | PCI: $scope.cobranza.cobros[j].provincia.ID, |
192 | LPLA: 0, | 192 | LPLA: 0, |
193 | PLA: 0, | 193 | PLA: 0, |
194 | VEN: $scope.cobranza.cobrador.id,//Id vendedor | 194 | VEN: $scope.cobranza.cobrador.id,//Id vendedor |
195 | CCLIE: $scope.cobranza.cliente.COD,//Id cliente | 195 | CCLIE: $scope.cobranza.cliente.COD,//Id cliente |
196 | REN: 0, | 196 | REN: 0, |
197 | PVEC: $scope.puntoVenta, | 197 | PVEC: $scope.puntoVenta, |
198 | NCOC: $scope.comprobante, | 198 | NCOC: $scope.comprobante, |
199 | OBSE: $scope.cobranza.cobros[j].observaciones, | 199 | OBSE: $scope.cobranza.cobros[j].observaciones, |
200 | LUV: 0, | 200 | LUV: 0, |
201 | ORI: 've', | 201 | ORI: 've', |
202 | FER: '', | 202 | FER: '', |
203 | BIMP: 0, | 203 | BIMP: 0, |
204 | COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, | 204 | COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, |
205 | VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso | 205 | VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso |
206 | VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso | 206 | VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso |
207 | REC_CAJ: 'D', | 207 | REC_CAJ: 'D', |
208 | TIPO_C: 0,//?? | 208 | TIPO_C: 0,//?? |
209 | SALDO_CAJ: 'S', | 209 | SALDO_CAJ: 'S', |
210 | FECHA_INGRESO: new Date($scope.cobranza.FEC) | 210 | FECHA_INGRESO: new Date($scope.cobranza.FEC) |
211 | .toISOString().slice(0, 19).replace('T', ' '), | 211 | .toISOString().slice(0, 19).replace('T', ' '), |
212 | Vendedor_valor: 0, | 212 | Vendedor_valor: 0, |
213 | FAMILIA: 0, | 213 | FAMILIA: 0, |
214 | CUIT_LIB: '', | 214 | CUIT_LIB: '', |
215 | COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar | 215 | COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar |
216 | SEN: '', | 216 | SEN: '', |
217 | NRC: 0, | 217 | NRC: 0, |
218 | COD_LARGO: '', | 218 | COD_LARGO: '', |
219 | VN: 0, | 219 | VN: 0, |
220 | ID_LECTOR: 0, | 220 | ID_LECTOR: 0, |
221 | NATHB: '' | 221 | NATHB: '' |
222 | }; | 222 | }; |
223 | cheques.push(cheque); | 223 | cheques.push(cheque); |
224 | } | 224 | } |
225 | if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; | 225 | if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; |
226 | 226 | ||
227 | } | 227 | } |
228 | 228 | ||
229 | cobranza = { | 229 | cobranza = { |
230 | recibo: { | 230 | recibo: { |
231 | CYV: 'V', | 231 | CYV: 'V', |
232 | TIP: 'C', | 232 | TIP: 'C', |
233 | TCO: 'RC', | 233 | TCO: 'RC', |
234 | PVE: $scope.puntoVenta, //Sucursar, punto de venta | 234 | PVE: $scope.puntoVenta, //Sucursar, punto de venta |
235 | NCO: $scope.comprobante, //Numero de comprobante | 235 | NCO: $scope.comprobante, //Numero de comprobante |
236 | FEC: new Date($scope.cobranza.FEC) | 236 | FEC: new Date($scope.cobranza.FEC) |
237 | .toISOString().slice(0, 19).replace('T', ' '), | 237 | .toISOString().slice(0, 19).replace('T', ' '), |
238 | CLI: $scope.cobranza.cliente.COD, | 238 | CLI: $scope.cobranza.cliente.COD, |
239 | ATO: 0, //número de asiento | 239 | ATO: 0, //número de asiento |
240 | CFE: $scope.cobranza.cobrador.NOM, | 240 | CFE: $scope.cobranza.cobrador.NOM, |
241 | PLA: '',//Numero de planilla, sin uso | 241 | PLA: '',//Numero de planilla, sin uso |
242 | ID_MONEDA: $scope.cobranza.moneda.ID, | 242 | ID_MONEDA: $scope.cobranza.moneda.ID, |
243 | COTIZACION: $scope.cobranza.moneda.cotizacion.VENDEDOR, | 243 | COTIZACION: $scope.cobranza.moneda.cotizacion.VENDEDOR, |
244 | idCobrador: $scope.cobranza.cobrador.id | 244 | idCobrador: $scope.cobranza.cobrador.id |
245 | }, | 245 | }, |
246 | cuerpo: cuerpos, | 246 | cuerpo: cuerpos, |
247 | cheques: cheques, | 247 | cheques: cheques, |
248 | acobypag: { | 248 | acobypag: { |
249 | CYV: 'V', | 249 | CYV: 'V', |
250 | COD: $scope.cobranza.cliente.COD, | 250 | COD: $scope.cobranza.cliente.COD, |
251 | FEP: new Date($scope.cobranza.FEC) | 251 | FEP: new Date($scope.cobranza.FEC) |
252 | .toISOString().slice(0, 19).replace('T', ' '), | 252 | .toISOString().slice(0, 19).replace('T', ' '), |
253 | TIP: 'C', | 253 | TIP: 'C', |
254 | TCO: 'RC', | 254 | TCO: 'RC', |
255 | SUC: $scope.puntoVenta, | 255 | SUC: $scope.puntoVenta, |
256 | NCO: $scope.comprobante, | 256 | NCO: $scope.comprobante, |
257 | IPA: $scope.getTotalCobrado(), | 257 | IPA: $scope.getTotalCobrado(), |
258 | SAL: '',//?? | 258 | SAL: '',//?? |
259 | TCA: 1, | 259 | TCA: 1, |
260 | ZONA: 1, | 260 | ZONA: 1, |
261 | FPA: 2,//Forma de pago | 261 | FPA: 2,//Forma de pago |
262 | REC: 0, | 262 | REC: 0, |
263 | REP: 0, | 263 | REP: 0, |
264 | FER: null, | 264 | FER: null, |
265 | REM: 0, | 265 | REM: 0, |
266 | FRE: null,//?? | 266 | FRE: null,//?? |
267 | PRO: 'N', | 267 | PRO: 'N', |
268 | FEV: new Date($scope.cobranza.FEC) | 268 | FEV: new Date($scope.cobranza.FEC) |
269 | .toISOString().slice(0, 19).replace('T', ' ') | 269 | .toISOString().slice(0, 19).replace('T', ' ') |
270 | }, | 270 | }, |
271 | datosCobrador: { | 271 | datosCobrador: { |
272 | COD: $scope.cobranza.cobrador.NUM, | 272 | COD: $scope.cobranza.cobrador.NUM, |
273 | PVE: $scope.puntoVenta, | 273 | PVE: $scope.puntoVenta, |
274 | NUM: $scope.comprobante, | 274 | NUM: $scope.comprobante, |
275 | EST: 'C', | 275 | EST: 'C', |
276 | OBS: 'RC: ' + $scope.comprobante + '-' + | 276 | OBS: 'RC: ' + $scope.comprobante + '-' + |
277 | new Date($scope.cobranza.FEC).toLocaleDateString(), | 277 | new Date($scope.cobranza.FEC).toLocaleDateString(), |
278 | DAT1: 'C', | 278 | DAT1: 'C', |
279 | CLI: $scope.cobranza.cliente.COD | 279 | CLI: $scope.cobranza.cliente.COD |
280 | }, | 280 | }, |
281 | cliente: $scope.cobranza.cliente, | 281 | cliente: $scope.cobranza.cliente, |
282 | imgs: imgs, | 282 | imgs: imgs, |
283 | observacion: observacion, | 283 | observacion: observacion, |
284 | facturasACobrar: $scope.cobranza.facturas | 284 | facturasACobrar: $scope.cobranza.facturas |
285 | }; | 285 | }; |
286 | //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS | 286 | //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS |
287 | var cobranzaMail = angular.copy(cobranza); | 287 | var cobranzaMail = angular.copy(cobranza); |
288 | 288 | ||
289 | cobranza.cuerpo = cobranza.cuerpo.map(function(c) { | 289 | cobranza.cuerpo = cobranza.cuerpo.map(function(c) { |
290 | if (c.NCU) delete c.NCU; | 290 | if (c.NCU) delete c.NCU; |
291 | return c; | 291 | return c; |
292 | }); | 292 | }); |
293 | focaCrearCobranzaService | 293 | focaCrearCobranzaService |
294 | .guardarCobranza(cobranza) | 294 | .guardarCobranza(cobranza) |
295 | .then( | 295 | .then( |
296 | function(result) { | 296 | function(result) { |
297 | focaBotoneraLateralService.endGuardar(true); | 297 | focaBotoneraLateralService.endGuardar(true); |
298 | $scope.saveLoading = false; | 298 | $scope.saveLoading = false; |
299 | 299 | ||
300 | enviarMail(cobranzaMail); | 300 | enviarMail(cobranzaMail); |
301 | 301 | ||
302 | focaSeguimientoService.guardarPosicion( | 302 | focaSeguimientoService.guardarPosicion( |
303 | 'Cobranza', | 303 | 'Cobranza', |
304 | result.data, | 304 | result.data, |
305 | '' | 305 | '' |
306 | ); | 306 | ); |
307 | 307 | ||
308 | config(); | 308 | config(); |
309 | }, function(error) { | 309 | }, function(error) { |
310 | focaModalService.alert('Hubo un problema al cargar la cobranza'); | 310 | focaModalService.alert('Hubo un problema al cargar la cobranza'); |
311 | focaBotoneraLateralService.endGuardar(); | 311 | focaBotoneraLateralService.endGuardar(); |
312 | $scope.saveLoading = false; | 312 | $scope.saveLoading = false; |
313 | console.info(error); | 313 | console.info(error); |
314 | } | 314 | } |
315 | ); | 315 | ); |
316 | }; | 316 | }; |
317 | 317 | ||
318 | $scope.seleccionarCobros = function() { | 318 | $scope.seleccionarCobros = function() { |
319 | $scope.cobroDeuda = false; | 319 | $scope.cobroDeuda = false; |
320 | }; | 320 | }; |
321 | 321 | ||
322 | $scope.seleccionarComprobantes = function() { | 322 | $scope.seleccionarComprobantes = function() { |
323 | $scope.cobroDeuda = true; | 323 | $scope.cobroDeuda = true; |
324 | }; | 324 | }; |
325 | 325 | ||
326 | $scope.seleccionarCobranza = function() { | 326 | $scope.seleccionarCobranza = function() { |
327 | 327 | ||
328 | var modalInstance = $uibModal.open( | 328 | var modalInstance = $uibModal.open( |
329 | { | 329 | { |
330 | ariaLabelledBy: 'Busqueda de Cobranzas', | 330 | ariaLabelledBy: 'Busqueda de Cobranzas', |
331 | templateUrl: 'foca-modal-cobranza.html', | 331 | templateUrl: 'foca-modal-cobranza.html', |
332 | controller: 'focaModalCobranzaController', | 332 | controller: 'focaModalCobranzaController', |
333 | size: 'lg' | 333 | size: 'lg' |
334 | } | 334 | } |
335 | ); | 335 | ); |
336 | modalInstance.result.then(function(cobranza) { | 336 | modalInstance.result.then(function(cobranza) { |
337 | cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0]; | 337 | cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0]; |
338 | setearCobranza(cobranza); | 338 | setearCobranza(cobranza); |
339 | }); | 339 | }); |
340 | }; | 340 | }; |
341 | 341 | ||
342 | $scope.seleccionarResumenDeCuenta = function() { | 342 | $scope.seleccionarResumenDeCuenta = function() { |
343 | if (!$scope.cobranza.cliente.COD) { | 343 | if (!$scope.cobranza.cliente.COD) { |
344 | focaModalService.alert('Seleccione primero un cliente'); | 344 | focaModalService.alert('Seleccione primero un cliente'); |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | var modalInstance = $uibModal.open( | 347 | var modalInstance = $uibModal.open( |
348 | { | 348 | { |
349 | ariaLabelledBy: 'Resumen de cuentas', | 349 | ariaLabelledBy: 'Resumen de cuentas', |
350 | templateUrl: 'modal-resumen-cuenta.html', | 350 | templateUrl: 'modal-resumen-cuenta.html', |
351 | controller: 'focaModalResumenCuentaController', | 351 | controller: 'focaModalResumenCuentaController', |
352 | resolve: { | 352 | resolve: { |
353 | cliente: function() { return $scope.cobranza.cliente; } | 353 | cliente: function() { return $scope.cobranza.cliente; } |
354 | }, | 354 | }, |
355 | size: 'lg' | 355 | size: 'lg' |
356 | } | 356 | } |
357 | ); | 357 | ); |
358 | modalInstance.result.then( | 358 | modalInstance.result.then( |
359 | function(cliente) { | 359 | function(cliente) { |
360 | $scope.abrirModalDomicilios(cliente); | 360 | $scope.abrirModalDomicilios(cliente); |
361 | $scope.cliente = cliente; | 361 | $scope.cliente = cliente; |
362 | }, function() {} | 362 | }, function() {} |
363 | ); | 363 | ); |
364 | }; | 364 | }; |
365 | 365 | ||
366 | $scope.seleccionarCliente = function() { | 366 | $scope.seleccionarCliente = function() { |
367 | $scope.seleccionarCobrador(function() { | 367 | $scope.seleccionarCobrador(function() { |
368 | var modalInstance = $uibModal.open( | 368 | var modalInstance = $uibModal.open( |
369 | { | 369 | { |
370 | ariaLabelledBy: 'Busqueda de Cliente', | 370 | ariaLabelledBy: 'Busqueda de Cliente', |
371 | templateUrl: 'foca-busqueda-cliente-modal.html', | 371 | templateUrl: 'foca-busqueda-cliente-modal.html', |
372 | controller: 'focaBusquedaClienteModalController', | 372 | controller: 'focaBusquedaClienteModalController', |
373 | resolve: { | 373 | resolve: { |
374 | vendedor: function() { return null; }, | 374 | vendedor: function() { return null; }, |
375 | cobrador: function() { return $scope.cobranza.cobrador; } | 375 | cobrador: function() { return $scope.cobranza.cobrador; } |
376 | }, | 376 | }, |
377 | size: 'lg' | 377 | size: 'lg' |
378 | } | 378 | } |
379 | ); | 379 | ); |
380 | modalInstance.result.then( | 380 | modalInstance.result.then( |
381 | function(cliente) { | 381 | function(cliente) { |
382 | |||
382 | var clienteMayus = { | 383 | var clienteMayus = { |
383 | COD: cliente.cod, | 384 | COD: cliente.cod, |
384 | NOM: cliente.nom, | 385 | NOM: cliente.nom, |
385 | CUIT: cliente.cuit, | 386 | CUIT: cliente.cuit, |
386 | MAIL: cliente.mail | 387 | MAIL: cliente.mail, |
388 | DOM: cliente.DOM, | ||
389 | LOC: cliente.LOC, | ||
390 | PCI: cliente.PCI | ||
387 | }; | 391 | }; |
388 | 392 | console.log(clienteMayus); | |
389 | $scope.$broadcast('addCabecera', { | 393 | $scope.$broadcast('addCabecera', { |
390 | label: 'Cliente:', | 394 | label: 'Cliente:', |
391 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + | 395 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + |
392 | clienteMayus.NOM | 396 | clienteMayus.NOM |
393 | }); | 397 | }); |
394 | 398 | ||
395 | $filter('filter')($scope.botonera, | 399 | $filter('filter')($scope.botonera, |
396 | { label: 'Cliente'})[0].checked = true; | 400 | { label: 'Cliente'})[0].checked = true; |
397 | 401 | ||
398 | $scope.cobranza.cliente = clienteMayus; | 402 | $scope.cobranza.cliente = clienteMayus; |
399 | $scope.cobranza.facturas = []; | 403 | $scope.cobranza.facturas = []; |
400 | }, function() { | 404 | }, function() { |
401 | if (APP !== 'cobranza') $scope.seleccionarCliente(); | 405 | if (APP !== 'cobranza') $scope.seleccionarCliente(); |
402 | } | 406 | } |
403 | ); | 407 | ); |
404 | }); | 408 | }); |
405 | }; | 409 | }; |
406 | 410 | ||
407 | $scope.seleccionarCobrador = function(callback) { | 411 | $scope.seleccionarCobrador = function(callback) { |
408 | 412 | ||
409 | if (APP === 'cobranza') { | 413 | if (APP === 'cobranza') { |
410 | callback(); | 414 | callback(); |
411 | return; | 415 | return; |
412 | } | 416 | } |
413 | 417 | ||
414 | var parametrosModal = { | 418 | var parametrosModal = { |
415 | query: '/cobrador', | 419 | query: '/cobrador', |
416 | columnas: [ | 420 | columnas: [ |
417 | { | 421 | { |
418 | propiedad: 'NUM', | 422 | propiedad: 'NUM', |
419 | nombre: 'Codigo', | 423 | nombre: 'Codigo', |
420 | filtro: { | 424 | filtro: { |
421 | nombre: 'rellenarDigitos', | 425 | nombre: 'rellenarDigitos', |
422 | parametro: 3 | 426 | parametro: 3 |
423 | } | 427 | } |
424 | }, | 428 | }, |
425 | { | 429 | { |
426 | propiedad: 'NOM', | 430 | propiedad: 'NOM', |
427 | nombre: 'Nombre' | 431 | nombre: 'Nombre' |
428 | } | 432 | } |
429 | ], | 433 | ], |
430 | titulo:'Búsqueda de cobradores' | 434 | titulo:'Búsqueda de cobradores' |
431 | }; | 435 | }; |
432 | focaModalService.modal(parametrosModal).then( | 436 | focaModalService.modal(parametrosModal).then( |
433 | function(cobrador) { | 437 | function(cobrador) { |
434 | $scope.$broadcast('addCabecera', { | 438 | $scope.$broadcast('addCabecera', { |
435 | label: 'Cobrador:', | 439 | label: 'Cobrador:', |
436 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | 440 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + |
437 | cobrador.NOM | 441 | cobrador.NOM |
438 | }); | 442 | }); |
439 | $scope.cobranza.cobrador = cobrador; | 443 | $scope.cobranza.cobrador = cobrador; |
440 | 444 | ||
441 | //ELIMINO CLIENTE | 445 | //ELIMINO CLIENTE |
442 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 446 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
443 | $scope.cobranza.cliente = {}; | 447 | $scope.cobranza.cliente = {}; |
444 | 448 | ||
445 | callback(); | 449 | callback(); |
446 | }, function() {} | 450 | }, function() {} |
447 | ); | 451 | ); |
448 | }; | 452 | }; |
449 | 453 | ||
450 | $scope.seleccionarFactura = function() { | 454 | $scope.seleccionarFactura = function() { |
451 | if (!$scope.cobranza.cliente.COD) { | 455 | if (!$scope.cobranza.cliente.COD) { |
452 | focaModalService.alert('Seleccione primero un cliente'); | 456 | focaModalService.alert('Seleccione primero un cliente'); |
453 | return; | 457 | return; |
454 | } | 458 | } |
455 | var modalInstance = $uibModal.open( | 459 | var modalInstance = $uibModal.open( |
456 | { | 460 | { |
457 | ariaLabelledBy: 'Busqueda de Facturas', | 461 | ariaLabelledBy: 'Busqueda de Facturas', |
458 | templateUrl: 'foca-modal-factura.html', | 462 | templateUrl: 'foca-modal-factura.html', |
459 | controller: 'focaModalFacturaController', | 463 | controller: 'focaModalFacturaController', |
460 | size: 'lg', | 464 | size: 'lg', |
461 | resolve: { | 465 | resolve: { |
462 | parametrosFactura: function() { | 466 | parametrosFactura: function() { |
463 | return { | 467 | return { |
464 | cliente: $scope.cobranza.cliente, | 468 | cliente: $scope.cobranza.cliente, |
465 | simbolo: $scope.cobranza.moneda.SIMBOLO, | 469 | simbolo: $scope.cobranza.moneda.SIMBOLO, |
466 | cotizacion: $scope.cobranza.moneda, | 470 | cotizacion: $scope.cobranza.moneda, |
467 | moneda: $scope.cobranza.moneda.ID | 471 | moneda: $scope.cobranza.moneda.ID |
468 | }; | 472 | }; |
469 | } | 473 | } |
470 | } | 474 | } |
471 | } | 475 | } |
472 | ); | 476 | ); |
473 | modalInstance.result.then( | 477 | modalInstance.result.then( |
474 | function(facturas) { | 478 | function(facturas) { |
475 | var facturasResult = []; | 479 | var facturasResult = []; |
476 | //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | 480 | //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS |
477 | facturas.forEach(function(factura) { | 481 | facturas.forEach(function(factura) { |
478 | var existe = $scope.cobranza.facturas.filter(function(e) { | 482 | var existe = $scope.cobranza.facturas.filter(function(e) { |
479 | return angular.equals(factura, e); | 483 | return angular.equals(factura, e); |
480 | }); | 484 | }); |
481 | 485 | ||
482 | if (!existe.length) facturasResult.push(factura); | 486 | if (!existe.length) facturasResult.push(factura); |
483 | }); | 487 | }); |
484 | 488 | ||
485 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); | 489 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); |
486 | }, function() { } | 490 | }, function() { } |
487 | ); | 491 | ); |
488 | }; | 492 | }; |
489 | 493 | ||
490 | $scope.seleccionarCheque = function(cheque) { | 494 | $scope.seleccionarCheque = function(cheque) { |
491 | 495 | ||
492 | var parametros; | 496 | var parametros; |
493 | 497 | ||
494 | if(!cheque) { | 498 | if(!cheque) { |
495 | parametros = { | 499 | parametros = { |
496 | importe: getSugerido(), | 500 | importe: getSugerido(), |
497 | esNuevo : true | 501 | esNuevo : true |
498 | }; | 502 | }; |
499 | } else { | 503 | } else { |
500 | parametros = cheque; | 504 | parametros = cheque; |
501 | parametros.importe = cheque.IMP; | 505 | parametros.importe = cheque.IMP; |
502 | } | 506 | } |
503 | 507 | ||
504 | var modalInstance = $uibModal.open( | 508 | var modalInstance = $uibModal.open( |
505 | { | 509 | { |
506 | ariaLabelledBy: 'Carga de cheques', | 510 | ariaLabelledBy: 'Carga de cheques', |
507 | templateUrl: 'modal-cheque.html', | 511 | templateUrl: 'modal-cheque.html', |
508 | controller: 'focaModalChequeController', | 512 | controller: 'focaModalChequeController', |
509 | size: 'lg', | 513 | size: 'lg', |
510 | resolve: { | 514 | resolve: { |
511 | cheque: function() { | 515 | cheque: function() { |
512 | return parametros; | 516 | return parametros; |
513 | } | 517 | } |
514 | } | 518 | } |
515 | } | 519 | } |
516 | ); | 520 | ); |
517 | modalInstance.result.then( | 521 | modalInstance.result.then( |
518 | function(cheque) { | 522 | function(cheque) { |
519 | var cobro = { | 523 | var cobro = { |
520 | COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | 524 | COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, |
521 | numero: cheque.numero, | 525 | numero: cheque.numero, |
522 | banco: cheque.banco, | 526 | banco: cheque.banco, |
523 | FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | 527 | FEC: cheque.fechaEmision.toLocaleDateString() + '-' + |
524 | cheque.fechaPresentacion.toLocaleDateString(), | 528 | cheque.fechaPresentacion.toLocaleDateString(), |
525 | fechaPresentacion: cheque.fechaPresentacion, | 529 | fechaPresentacion: cheque.fechaPresentacion, |
526 | fechaEmision: cheque.fechaEmision, | 530 | fechaEmision: cheque.fechaEmision, |
527 | IMP: cheque.importe, | 531 | IMP: cheque.importe, |
528 | localidad: cheque.localidad, | 532 | localidad: cheque.localidad, |
529 | librador: cheque.librador, | 533 | librador: cheque.librador, |
530 | provincia: cheque.provincia, | 534 | provincia: cheque.provincia, |
531 | observaciones: cheque.observaciones, | 535 | observaciones: cheque.observaciones, |
532 | TIL: 'EF' | 536 | TIL: 'EF' |
533 | }; | 537 | }; |
534 | pushearCobro(cobro, cheque.$$hashKey); | 538 | pushearCobro(cobro, cheque.$$hashKey); |
535 | }, function() { | 539 | }, function() { |
536 | 540 | ||
537 | } | 541 | } |
538 | ); | 542 | ); |
539 | }; | 543 | }; |
540 | 544 | ||
541 | $scope.seleccionarEfectivo = function() { | 545 | $scope.seleccionarEfectivo = function() { |
542 | 546 | ||
543 | var importe = 0; | 547 | var importe = 0; |
544 | $scope.cobranza.cobros.filter(function(a) { | 548 | $scope.cobranza.cobros.filter(function(a) { |
545 | if(a.COM === 'Efectivo') { | 549 | if(a.COM === 'Efectivo') { |
546 | importe = a.IMP; | 550 | importe = a.IMP; |
547 | } | 551 | } |
548 | }); | 552 | }); |
549 | 553 | ||
550 | var modalInstance = $uibModal.open( | 554 | var modalInstance = $uibModal.open( |
551 | { | 555 | { |
552 | ariaLabelledBy: 'Carga de cheques', | 556 | ariaLabelledBy: 'Carga de cheques', |
553 | templateUrl: 'modal-efectivo.html', | 557 | templateUrl: 'modal-efectivo.html', |
554 | controller: 'focaModalEfectivoController', | 558 | controller: 'focaModalEfectivoController', |
555 | size: 'sm', | 559 | size: 'sm', |
556 | resolve: { | 560 | resolve: { |
557 | sugerido: function() { | 561 | sugerido: function() { |
558 | return parseFloat(getSugerido()) + parseFloat(importe); | 562 | return parseFloat(getSugerido()) + parseFloat(importe); |
559 | } | 563 | } |
560 | } | 564 | } |
561 | } | 565 | } |
562 | ); | 566 | ); |
563 | modalInstance.result.then( | 567 | modalInstance.result.then( |
564 | function(efectivo) { | 568 | function(efectivo) { |
565 | 569 | ||
566 | var cobro = { | 570 | var cobro = { |
567 | COM: 'Efectivo', | 571 | COM: 'Efectivo', |
568 | FEC: new Date(), | 572 | FEC: new Date(), |
569 | IMP: efectivo, | 573 | IMP: efectivo, |
570 | TIL: 'EF' | 574 | TIL: 'EF' |
571 | }; | 575 | }; |
572 | 576 | ||
573 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | 577 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { |
574 | return a.COM !== 'Efectivo'; | 578 | return a.COM !== 'Efectivo'; |
575 | }); | 579 | }); |
576 | 580 | ||
577 | $scope.cobranza.cobros.push(cobro); | 581 | $scope.cobranza.cobros.push(cobro); |
578 | }, function() { | 582 | }, function() { |
579 | 583 | ||
580 | } | 584 | } |
581 | ); | 585 | ); |
582 | }; | 586 | }; |
583 | 587 | ||
584 | $scope.seleccionarDetalles = function(detalle) { | 588 | $scope.seleccionarDetalles = function(detalle) { |
585 | 589 | ||
586 | var parametro = {}; | 590 | var parametro = {}; |
587 | 591 | ||
588 | if(!detalle) { | 592 | if(!detalle) { |
589 | parametro = { | 593 | parametro = { |
590 | importe: getSugerido(), | 594 | importe: getSugerido(), |
591 | files: [] | 595 | files: [] |
592 | }; | 596 | }; |
593 | } else { | 597 | } else { |
594 | parametro = detalle; | 598 | parametro = detalle; |
595 | parametro.importe = detalle.IMP; | 599 | parametro.importe = detalle.IMP; |
596 | parametro.files= detalle.imgs; | 600 | parametro.files= detalle.imgs; |
597 | } | 601 | } |
598 | 602 | ||
599 | var modalInstance = $uibModal.open( | 603 | var modalInstance = $uibModal.open( |
600 | { | 604 | { |
601 | ariaLabelledBy: 'Carga de detalles', | 605 | ariaLabelledBy: 'Carga de detalles', |
602 | templateUrl: 'modal-detalles.html', | 606 | templateUrl: 'modal-detalles.html', |
603 | controller: 'focaModalDetallesController', | 607 | controller: 'focaModalDetallesController', |
604 | size: 'lg', | 608 | size: 'lg', |
605 | resolve: { | 609 | resolve: { |
606 | parametros: function() { | 610 | parametros: function() { |
607 | return parametro; | 611 | return parametro; |
608 | } | 612 | } |
609 | } | 613 | } |
610 | } | 614 | } |
611 | ); | 615 | ); |
612 | modalInstance.result.then( | 616 | modalInstance.result.then( |
613 | function(detalles) { | 617 | function(detalles) { |
614 | 618 | ||
615 | var cobro = { | 619 | var cobro = { |
616 | COM: 'de(COBRO POR DETALLES)', | 620 | COM: 'de(COBRO POR DETALLES)', |
617 | FEC: new Date(), | 621 | FEC: new Date(), |
618 | IMP: detalles.importe, | 622 | IMP: detalles.importe, |
619 | imgs: detalles.files, | 623 | imgs: detalles.files, |
620 | TIL: 'DE', | 624 | TIL: 'DE', |
621 | observacion: detalles.observacion | 625 | observacion: detalles.observacion |
622 | }; | 626 | }; |
623 | pushearCobro(cobro, detalles.$$hashKey); | 627 | pushearCobro(cobro, detalles.$$hashKey); |
624 | }, function() {} | 628 | }, function() {} |
625 | ); | 629 | ); |
626 | }; | 630 | }; |
627 | 631 | ||
628 | $scope.seleccionarMoneda = function() { | 632 | $scope.seleccionarMoneda = function() { |
629 | var parametrosModal = { | 633 | var parametrosModal = { |
630 | titulo: 'Búsqueda de monedas', | 634 | titulo: 'Búsqueda de monedas', |
631 | query: '/moneda', | 635 | query: '/moneda', |
632 | columnas: [ | 636 | columnas: [ |
633 | { | 637 | { |
634 | propiedad: 'DETALLE', | 638 | propiedad: 'DETALLE', |
635 | nombre: 'Nombre' | 639 | nombre: 'Nombre' |
636 | }, | 640 | }, |
637 | { | 641 | { |
638 | propiedad: 'SIMBOLO', | 642 | propiedad: 'SIMBOLO', |
639 | nombre: 'Símbolo' | 643 | nombre: 'Símbolo' |
640 | } | 644 | } |
641 | ], | 645 | ], |
642 | size: 'md' | 646 | size: 'md' |
643 | }; | 647 | }; |
644 | focaModalService.modal(parametrosModal).then( | 648 | focaModalService.modal(parametrosModal).then( |
645 | function(moneda) { | 649 | function(moneda) { |
646 | $scope.seleccionarCotizacion(moneda); | 650 | $scope.seleccionarCotizacion(moneda); |
647 | }, function() { | 651 | }, function() { |
648 | 652 | ||
649 | } | 653 | } |
650 | ); | 654 | ); |
651 | }; | 655 | }; |
652 | 656 | ||
653 | $scope.seleccionarCotizacion = function(moneda) { | 657 | $scope.seleccionarCotizacion = function(moneda) { |
654 | var modalInstance = $uibModal.open( | 658 | var modalInstance = $uibModal.open( |
655 | { | 659 | { |
656 | ariaLabelledBy: 'Busqueda de Cotización', | 660 | ariaLabelledBy: 'Busqueda de Cotización', |
657 | templateUrl: 'modal-cotizacion.html', | 661 | templateUrl: 'modal-cotizacion.html', |
658 | controller: 'focaModalCotizacionController', | 662 | controller: 'focaModalCotizacionController', |
659 | size: 'lg', | 663 | size: 'lg', |
660 | resolve: {idMoneda: function() {return moneda.ID;}} | 664 | resolve: {idMoneda: function() {return moneda.ID;}} |
661 | } | 665 | } |
662 | ); | 666 | ); |
663 | modalInstance.result.then( | 667 | modalInstance.result.then( |
664 | function(cotizacion) { | 668 | function(cotizacion) { |
665 | $scope.cobranza.moneda = moneda; | 669 | $scope.cobranza.moneda = moneda; |
666 | $scope.cobranza.moneda.cotizacion = cotizacion; | 670 | $scope.cobranza.moneda.cotizacion = cotizacion; |
667 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 671 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
668 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 672 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
669 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 673 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
670 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 674 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
671 | } else { | 675 | } else { |
672 | $scope.$broadcast('addCabecera', { | 676 | $scope.$broadcast('addCabecera', { |
673 | label: 'Moneda:', | 677 | label: 'Moneda:', |
674 | valor: moneda.DETALLE | 678 | valor: moneda.DETALLE |
675 | }); | 679 | }); |
676 | $scope.$broadcast('addCabecera', { | 680 | $scope.$broadcast('addCabecera', { |
677 | label: 'Fecha cotizacion:', | 681 | label: 'Fecha cotizacion:', |
678 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 682 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
679 | }); | 683 | }); |
680 | $scope.$broadcast('addCabecera', { | 684 | $scope.$broadcast('addCabecera', { |
681 | label: 'Cotizacion:', | 685 | label: 'Cotizacion:', |
682 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 686 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
683 | }); | 687 | }); |
684 | } | 688 | } |
685 | 689 | ||
686 | $filter('filter')( $scope.botonera, { | 690 | $filter('filter')( $scope.botonera, { |
687 | label: 'Moneda' | 691 | label: 'Moneda' |
688 | })[0].checked = true; | 692 | })[0].checked = true; |
689 | 693 | ||
690 | }, function() { | 694 | }, function() { |
691 | 695 | ||
692 | } | 696 | } |
693 | ); | 697 | ); |
694 | }; | 698 | }; |
695 | 699 | ||
696 | $scope.getTotalDeuda = function() { | 700 | $scope.getTotalDeuda = function() { |
697 | var total = 0; | 701 | var total = 0; |
698 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { | 702 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { |
699 | total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; | 703 | total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; |
700 | } | 704 | } |
701 | return parseFloat(total.toFixed(2)); | 705 | return parseFloat(total.toFixed(2)); |
702 | }; | 706 | }; |
703 | 707 | ||
704 | $scope.getTotalCobrado = function() { | 708 | $scope.getTotalCobrado = function() { |
705 | var total = 0; | 709 | var total = 0; |
706 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { | 710 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { |
707 | total += $scope.cobranza.cobros[i].IMP; | 711 | total += $scope.cobranza.cobros[i].IMP; |
708 | } | 712 | } |
709 | return parseFloat(total.toFixed(2)); | 713 | return parseFloat(total.toFixed(2)); |
710 | }; | 714 | }; |
711 | 715 | ||
712 | $scope.getSubTotal = function() { | 716 | $scope.getSubTotal = function() { |
713 | if ($scope.articuloACargar) { | 717 | if ($scope.articuloACargar) { |
714 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 718 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
715 | } | 719 | } |
716 | }; | 720 | }; |
717 | //Recibe aviso si el teclado está en uso | 721 | //Recibe aviso si el teclado está en uso |
718 | // $rootScope.$on('usarTeclado', function(event, data) { | 722 | // $rootScope.$on('usarTeclado', function(event, data) { |
719 | // if(data) { | 723 | // if(data) { |
720 | // $scope.mostrarTeclado = true; | 724 | // $scope.mostrarTeclado = true; |
721 | // return; | 725 | // return; |
722 | // } | 726 | // } |
723 | // $scope.mostrarTeclado = false; | 727 | // $scope.mostrarTeclado = false; |
724 | // }) | 728 | // }) |
725 | $scope.selectFocus = function($event) { | 729 | $scope.selectFocus = function($event) { |
726 | //Si el teclado esta en uso no selecciona el valor | 730 | //Si el teclado esta en uso no selecciona el valor |
727 | // if($scope.mostrarTeclado) { | 731 | // if($scope.mostrarTeclado) { |
728 | // return; | 732 | // return; |
729 | // } | 733 | // } |
730 | $event.target.select(); | 734 | $event.target.select(); |
731 | }; | 735 | }; |
732 | 736 | ||
733 | $scope.salir = function() { | 737 | $scope.salir = function() { |
734 | $location.path('/'); | 738 | $location.path('/'); |
735 | }; | 739 | }; |
736 | 740 | ||
737 | $scope.parsearATexto = function(articulo) { | 741 | $scope.parsearATexto = function(articulo) { |
738 | articulo.cantidad = parseFloat(articulo.cantidad); | 742 | articulo.cantidad = parseFloat(articulo.cantidad); |
739 | articulo.precio = parseFloat(articulo.precio); | 743 | articulo.precio = parseFloat(articulo.precio); |
740 | }; | 744 | }; |
741 | 745 | ||
742 | $scope.quitarFactura = function(key) { | 746 | $scope.quitarFactura = function(key) { |
743 | $scope.cobranza.facturas.splice(key, 1); | 747 | $scope.cobranza.facturas.splice(key, 1); |
744 | }; | 748 | }; |
745 | 749 | ||
746 | $scope.quitarCobro = function(key) { | 750 | $scope.quitarCobro = function(key) { |
747 | $scope.cobranza.cobros.splice(key, 1); | 751 | $scope.cobranza.cobros.splice(key, 1); |
748 | }; | 752 | }; |
749 | 753 | ||
750 | $scope.editarCobro = function(cobro) { | 754 | $scope.editarCobro = function(cobro) { |
751 | if(cobro.COM === 'Efectivo') { | 755 | if(cobro.COM === 'Efectivo') { |
752 | $scope.seleccionarEfectivo(); | 756 | $scope.seleccionarEfectivo(); |
753 | } else if(cobro.COM.substring(0, 2) === 'de') { | 757 | } else if(cobro.COM.substring(0, 2) === 'de') { |
754 | $scope.seleccionarDetalles(cobro); | 758 | $scope.seleccionarDetalles(cobro); |
755 | } else if(cobro.COM.substring(0, 2) === 'ch') { | 759 | } else if(cobro.COM.substring(0, 2) === 'ch') { |
756 | $scope.seleccionarCheque(cobro); | 760 | $scope.seleccionarCheque(cobro); |
757 | } | 761 | } |
758 | }; | 762 | }; |
759 | 763 | ||
760 | $scope.$watch('cobranza.facturas', function() { | 764 | $scope.$watch('cobranza.facturas', function() { |
761 | if ($scope.cobranza.facturas.length) { | 765 | if ($scope.cobranza.facturas.length) { |
762 | $filter('filter')( $scope.botonera, { | 766 | $filter('filter')( $scope.botonera, { |
763 | label: 'Comprobantes' | 767 | label: 'Comprobantes' |
764 | })[0].checked = true; | 768 | })[0].checked = true; |
765 | } else { | 769 | } else { |
766 | $filter('filter')( $scope.botonera, { | 770 | $filter('filter')( $scope.botonera, { |
767 | label: 'Comprobantes' | 771 | label: 'Comprobantes' |
768 | })[0].checked = false; | 772 | })[0].checked = false; |
769 | } | 773 | } |
770 | }, true); | 774 | }, true); |
771 | 775 | ||
772 | $scope.$watch('cobranza.cobros', function() { | 776 | $scope.$watch('cobranza.cobros', function() { |
773 | if ($scope.cobranza.cobros.length) { | 777 | if ($scope.cobranza.cobros.length) { |
774 | $filter('filter')( $scope.botonera, { | 778 | $filter('filter')( $scope.botonera, { |
775 | label: 'Cobros' | 779 | label: 'Cobros' |
776 | })[0].checked = true; | 780 | })[0].checked = true; |
777 | } else { | 781 | } else { |
778 | $filter('filter')( $scope.botonera, { | 782 | $filter('filter')( $scope.botonera, { |
779 | label: 'Cobros' | 783 | label: 'Cobros' |
780 | })[0].checked = false; | 784 | })[0].checked = false; |
781 | } | 785 | } |
782 | }, true); | 786 | }, true); |
783 | 787 | ||
784 | function pushearCobro(cobro, hashKey) { | 788 | function pushearCobro(cobro, hashKey) { |
785 | var existe; | 789 | var existe; |
786 | 790 | ||
787 | $scope.cobranza.cobros.forEach(function(c, idx) { | 791 | $scope.cobranza.cobros.forEach(function(c, idx) { |
788 | if(c.$$hashKey === hashKey) { | 792 | if(c.$$hashKey === hashKey) { |
789 | $scope.cobranza.cobros[idx] = cobro; | 793 | $scope.cobranza.cobros[idx] = cobro; |
790 | existe = true; | 794 | existe = true; |
791 | } | 795 | } |
792 | }); | 796 | }); |
793 | if (!existe) { | 797 | if (!existe) { |
794 | $scope.cobranza.cobros.push(cobro); | 798 | $scope.cobranza.cobros.push(cobro); |
795 | } | 799 | } |
796 | } | 800 | } |
797 | 801 | ||
798 | function salir() { | 802 | function salir() { |
799 | var confirmacion = false; | 803 | var confirmacion = false; |
800 | 804 | ||
801 | if (!angular.equals($scope.cobranza, $scope.inicial)) { | 805 | if (!angular.equals($scope.cobranza, $scope.inicial)) { |
802 | confirmacion = true; | 806 | confirmacion = true; |
803 | } | 807 | } |
804 | 808 | ||
805 | if (confirmacion) { | 809 | if (confirmacion) { |
806 | focaModalService.confirm( | 810 | focaModalService.confirm( |
807 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 811 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
808 | ).then(function(data) { | 812 | ).then(function(data) { |
809 | if (data) { | 813 | if (data) { |
810 | $location.path('/'); | 814 | $location.path('/'); |
811 | } | 815 | } |
812 | }); | 816 | }); |
813 | } else { | 817 | } else { |
814 | $location.path('/'); | 818 | $location.path('/'); |
815 | } | 819 | } |
816 | } | 820 | } |
817 | 821 | ||
818 | function setearCobranza(cobranza) { | 822 | function setearCobranza(cobranza) { |
819 | $scope.editando = true; | 823 | $scope.editando = true; |
820 | $scope.$broadcast('cleanCabecera'); | 824 | $scope.$broadcast('cleanCabecera'); |
821 | 825 | ||
822 | if (cobranza.cliente) { | 826 | if (cobranza.cliente) { |
823 | $scope.$broadcast('addCabecera', { | 827 | $scope.$broadcast('addCabecera', { |
824 | label: 'Cliente:', | 828 | label: 'Cliente:', |
825 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + | 829 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + |
826 | cobranza.cliente.NOM | 830 | cobranza.cliente.NOM |
827 | }); | 831 | }); |
828 | 832 | ||
829 | $filter('filter')( $scope.botonera, { | 833 | $filter('filter')( $scope.botonera, { |
830 | label: 'Cliente' | 834 | label: 'Cliente' |
831 | })[0].checked = true; | 835 | })[0].checked = true; |
832 | } | 836 | } |
833 | if (cobranza.cobrador && cobranza.cobrador.NUM) { | 837 | if (cobranza.cobrador && cobranza.cobrador.NUM) { |
834 | $scope.$broadcast('addCabecera', { | 838 | $scope.$broadcast('addCabecera', { |
835 | label: 'Cobrador:', | 839 | label: 'Cobrador:', |
836 | valor: (cobranza.cobrador.NUM) ? | 840 | valor: (cobranza.cobrador.NUM) ? |
837 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + | 841 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + |
838 | cobranza.cobrador.NOM : cobranza.cobrador | 842 | cobranza.cobrador.NOM : cobranza.cobrador |
839 | 843 | ||
840 | }); | 844 | }); |
841 | } | 845 | } |
842 | 846 | ||
843 | // TODO: Setear moneda | 847 | // TODO: Setear moneda |
844 | if (cobranza.moneda) { | 848 | if (cobranza.moneda) { |
845 | $filter('filter')( $scope.botonera, { | 849 | $filter('filter')( $scope.botonera, { |
846 | label: 'Moneda' | 850 | label: 'Moneda' |
847 | })[0].checked = true; | 851 | })[0].checked = true; |
848 | } | 852 | } |
849 | 853 | ||
850 | $scope.cobranza = cobranza; | 854 | $scope.cobranza = cobranza; |
851 | } | 855 | } |
852 | 856 | ||
853 | function getLSCobranza() { | 857 | function getLSCobranza() { |
854 | var cobranza = JSON.parse($localStorage.cobranza || null); | 858 | var cobranza = JSON.parse($localStorage.cobranza || null); |
855 | if (cobranza) { | 859 | if (cobranza) { |
856 | setearCobranza(cobranza); | 860 | setearCobranza(cobranza); |
857 | delete $localStorage.cobranza; | 861 | delete $localStorage.cobranza; |
858 | } | 862 | } |
859 | } | 863 | } |
860 | 864 | ||
861 | function enviarMail(recibo) { | 865 | function enviarMail(recibo) { |
862 | focaModalService.mail( | 866 | focaModalService.mail( |
863 | { | 867 | { |
864 | titulo: 'Enviar recibo', | 868 | titulo: 'Enviar recibo', |
865 | descarga: { | 869 | descarga: { |
866 | nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf', | 870 | nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf', |
867 | url: '/mail/recibo/descargar', | 871 | url: '/mail/recibo/descargar', |
868 | }, | 872 | }, |
869 | envio: { | 873 | envio: { |
870 | mailCliente: recibo.cliente.MAIL, | 874 | mailCliente: recibo.cliente.MAIL, |
871 | url: '/mail/recibo', | 875 | url: '/mail/recibo', |
872 | }, | 876 | }, |
873 | options: { | 877 | options: { |
874 | recibo: recibo | 878 | recibo: recibo |
875 | } | 879 | } |
876 | } | 880 | } |
877 | ); | 881 | ); |
878 | } | 882 | } |
879 | 883 | ||
880 | function getSugerido() { | 884 | function getSugerido() { |
881 | var result; | 885 | var result; |
882 | 886 | ||
883 | var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | 887 | var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); |
884 | 888 | ||
885 | if (valor < 0) { | 889 | if (valor < 0) { |
886 | result = Math.abs(valor).toFixed(4); | 890 | result = Math.abs(valor).toFixed(4); |
887 | } | 891 | } |
888 | 892 | ||
889 | return result; | 893 | return result; |
890 | } | 894 | } |
891 | } | 895 | } |
892 | ]); | 896 | ]); |
893 | 897 |