Commit 640445d2129d6e6692404593797016b858bd11a0
1 parent
3395c98a22
Exists in
master
se envia parametro de idmoneda al resumen de cuenta.
Showing
1 changed file
with
2 additions
and
1 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 | idMoneda: function() { return $scope.cobranza.moneda.ID; } | ||
354 | }, | 355 | }, |
355 | size: 'lg' | 356 | size: 'lg' |
356 | } | 357 | } |
357 | ); | 358 | ); |
358 | modalInstance.result.then( | 359 | modalInstance.result.then( |
359 | function(cliente) { | 360 | function(cliente) { |
360 | $scope.abrirModalDomicilios(cliente); | 361 | $scope.abrirModalDomicilios(cliente); |
361 | $scope.cliente = cliente; | 362 | $scope.cliente = cliente; |
362 | }, function() {} | 363 | }, function() {} |
363 | ); | 364 | ); |
364 | }; | 365 | }; |
365 | 366 | ||
366 | $scope.seleccionarCliente = function() { | 367 | $scope.seleccionarCliente = function() { |
367 | $scope.seleccionarCobrador(function() { | 368 | $scope.seleccionarCobrador(function() { |
368 | var modalInstance = $uibModal.open( | 369 | var modalInstance = $uibModal.open( |
369 | { | 370 | { |
370 | ariaLabelledBy: 'Busqueda de Cliente', | 371 | ariaLabelledBy: 'Busqueda de Cliente', |
371 | templateUrl: 'foca-busqueda-cliente-modal.html', | 372 | templateUrl: 'foca-busqueda-cliente-modal.html', |
372 | controller: 'focaBusquedaClienteModalController', | 373 | controller: 'focaBusquedaClienteModalController', |
373 | resolve: { | 374 | resolve: { |
374 | vendedor: function() { return null; }, | 375 | vendedor: function() { return null; }, |
375 | cobrador: function() { return $scope.cobranza.cobrador; } | 376 | cobrador: function() { return $scope.cobranza.cobrador; } |
376 | }, | 377 | }, |
377 | size: 'lg' | 378 | size: 'lg' |
378 | } | 379 | } |
379 | ); | 380 | ); |
380 | modalInstance.result.then( | 381 | modalInstance.result.then( |
381 | function(cliente) { | 382 | function(cliente) { |
382 | 383 | ||
383 | var clienteMayus = { | 384 | var clienteMayus = { |
384 | COD: cliente.cod, | 385 | COD: cliente.cod, |
385 | NOM: cliente.nom, | 386 | NOM: cliente.nom, |
386 | CUIT: cliente.cuit, | 387 | CUIT: cliente.cuit, |
387 | MAIL: cliente.mail, | 388 | MAIL: cliente.mail, |
388 | DOM: cliente.DOM, | 389 | DOM: cliente.DOM, |
389 | LOC: cliente.LOC, | 390 | LOC: cliente.LOC, |
390 | PCI: cliente.PCI | 391 | PCI: cliente.PCI |
391 | }; | 392 | }; |
392 | console.log(clienteMayus); | 393 | console.log(clienteMayus); |
393 | $scope.$broadcast('addCabecera', { | 394 | $scope.$broadcast('addCabecera', { |
394 | label: 'Cliente:', | 395 | label: 'Cliente:', |
395 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + | 396 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + |
396 | clienteMayus.NOM | 397 | clienteMayus.NOM |
397 | }); | 398 | }); |
398 | 399 | ||
399 | $filter('filter')($scope.botonera, | 400 | $filter('filter')($scope.botonera, |
400 | { label: 'Cliente'})[0].checked = true; | 401 | { label: 'Cliente'})[0].checked = true; |
401 | 402 | ||
402 | $scope.cobranza.cliente = clienteMayus; | 403 | $scope.cobranza.cliente = clienteMayus; |
403 | $scope.cobranza.facturas = []; | 404 | $scope.cobranza.facturas = []; |
404 | }, function() { | 405 | }, function() { |
405 | if (APP !== 'cobranza') $scope.seleccionarCliente(); | 406 | if (APP !== 'cobranza') $scope.seleccionarCliente(); |
406 | } | 407 | } |
407 | ); | 408 | ); |
408 | }); | 409 | }); |
409 | }; | 410 | }; |
410 | 411 | ||
411 | $scope.seleccionarCobrador = function(callback) { | 412 | $scope.seleccionarCobrador = function(callback) { |
412 | 413 | ||
413 | if (APP === 'cobranza') { | 414 | if (APP === 'cobranza') { |
414 | callback(); | 415 | callback(); |
415 | return; | 416 | return; |
416 | } | 417 | } |
417 | 418 | ||
418 | var parametrosModal = { | 419 | var parametrosModal = { |
419 | query: '/cobrador', | 420 | query: '/cobrador', |
420 | columnas: [ | 421 | columnas: [ |
421 | { | 422 | { |
422 | propiedad: 'NUM', | 423 | propiedad: 'NUM', |
423 | nombre: 'Codigo', | 424 | nombre: 'Codigo', |
424 | filtro: { | 425 | filtro: { |
425 | nombre: 'rellenarDigitos', | 426 | nombre: 'rellenarDigitos', |
426 | parametro: 3 | 427 | parametro: 3 |
427 | } | 428 | } |
428 | }, | 429 | }, |
429 | { | 430 | { |
430 | propiedad: 'NOM', | 431 | propiedad: 'NOM', |
431 | nombre: 'Nombre' | 432 | nombre: 'Nombre' |
432 | } | 433 | } |
433 | ], | 434 | ], |
434 | titulo:'Búsqueda de cobradores' | 435 | titulo:'Búsqueda de cobradores' |
435 | }; | 436 | }; |
436 | focaModalService.modal(parametrosModal).then( | 437 | focaModalService.modal(parametrosModal).then( |
437 | function(cobrador) { | 438 | function(cobrador) { |
438 | $scope.$broadcast('addCabecera', { | 439 | $scope.$broadcast('addCabecera', { |
439 | label: 'Cobrador:', | 440 | label: 'Cobrador:', |
440 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | 441 | valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + |
441 | cobrador.NOM | 442 | cobrador.NOM |
442 | }); | 443 | }); |
443 | $scope.cobranza.cobrador = cobrador; | 444 | $scope.cobranza.cobrador = cobrador; |
444 | 445 | ||
445 | //ELIMINO CLIENTE | 446 | //ELIMINO CLIENTE |
446 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 447 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
447 | $scope.cobranza.cliente = {}; | 448 | $scope.cobranza.cliente = {}; |
448 | 449 | ||
449 | callback(); | 450 | callback(); |
450 | }, function() {} | 451 | }, function() {} |
451 | ); | 452 | ); |
452 | }; | 453 | }; |
453 | 454 | ||
454 | $scope.seleccionarFactura = function() { | 455 | $scope.seleccionarFactura = function() { |
455 | if (!$scope.cobranza.cliente.COD) { | 456 | if (!$scope.cobranza.cliente.COD) { |
456 | focaModalService.alert('Seleccione primero un cliente'); | 457 | focaModalService.alert('Seleccione primero un cliente'); |
457 | return; | 458 | return; |
458 | } | 459 | } |
459 | var modalInstance = $uibModal.open( | 460 | var modalInstance = $uibModal.open( |
460 | { | 461 | { |
461 | ariaLabelledBy: 'Busqueda de Facturas', | 462 | ariaLabelledBy: 'Busqueda de Facturas', |
462 | templateUrl: 'foca-modal-factura.html', | 463 | templateUrl: 'foca-modal-factura.html', |
463 | controller: 'focaModalFacturaController', | 464 | controller: 'focaModalFacturaController', |
464 | size: 'lg', | 465 | size: 'lg', |
465 | resolve: { | 466 | resolve: { |
466 | parametrosFactura: function() { | 467 | parametrosFactura: function() { |
467 | return { | 468 | return { |
468 | cliente: $scope.cobranza.cliente, | 469 | cliente: $scope.cobranza.cliente, |
469 | simbolo: $scope.cobranza.moneda.SIMBOLO, | 470 | simbolo: $scope.cobranza.moneda.SIMBOLO, |
470 | cotizacion: $scope.cobranza.moneda, | 471 | cotizacion: $scope.cobranza.moneda, |
471 | moneda: $scope.cobranza.moneda.ID | 472 | moneda: $scope.cobranza.moneda.ID |
472 | }; | 473 | }; |
473 | } | 474 | } |
474 | } | 475 | } |
475 | } | 476 | } |
476 | ); | 477 | ); |
477 | modalInstance.result.then( | 478 | modalInstance.result.then( |
478 | function(facturas) { | 479 | function(facturas) { |
479 | var facturasResult = []; | 480 | var facturasResult = []; |
480 | //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | 481 | //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS |
481 | facturas.forEach(function(factura) { | 482 | facturas.forEach(function(factura) { |
482 | var existe = $scope.cobranza.facturas.filter(function(e) { | 483 | var existe = $scope.cobranza.facturas.filter(function(e) { |
483 | return angular.equals(factura, e); | 484 | return angular.equals(factura, e); |
484 | }); | 485 | }); |
485 | 486 | ||
486 | if (!existe.length) facturasResult.push(factura); | 487 | if (!existe.length) facturasResult.push(factura); |
487 | }); | 488 | }); |
488 | 489 | ||
489 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); | 490 | $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); |
490 | }, function() { } | 491 | }, function() { } |
491 | ); | 492 | ); |
492 | }; | 493 | }; |
493 | 494 | ||
494 | $scope.seleccionarCheque = function(cheque) { | 495 | $scope.seleccionarCheque = function(cheque) { |
495 | 496 | ||
496 | var parametros; | 497 | var parametros; |
497 | 498 | ||
498 | if(!cheque) { | 499 | if(!cheque) { |
499 | parametros = { | 500 | parametros = { |
500 | importe: getSugerido(), | 501 | importe: getSugerido(), |
501 | esNuevo : true | 502 | esNuevo : true |
502 | }; | 503 | }; |
503 | } else { | 504 | } else { |
504 | parametros = cheque; | 505 | parametros = cheque; |
505 | parametros.importe = cheque.IMP; | 506 | parametros.importe = cheque.IMP; |
506 | } | 507 | } |
507 | 508 | ||
508 | var modalInstance = $uibModal.open( | 509 | var modalInstance = $uibModal.open( |
509 | { | 510 | { |
510 | ariaLabelledBy: 'Carga de cheques', | 511 | ariaLabelledBy: 'Carga de cheques', |
511 | templateUrl: 'modal-cheque.html', | 512 | templateUrl: 'modal-cheque.html', |
512 | controller: 'focaModalChequeController', | 513 | controller: 'focaModalChequeController', |
513 | size: 'lg', | 514 | size: 'lg', |
514 | resolve: { | 515 | resolve: { |
515 | cheque: function() { | 516 | cheque: function() { |
516 | return parametros; | 517 | return parametros; |
517 | } | 518 | } |
518 | } | 519 | } |
519 | } | 520 | } |
520 | ); | 521 | ); |
521 | modalInstance.result.then( | 522 | modalInstance.result.then( |
522 | function(cheque) { | 523 | function(cheque) { |
523 | var cobro = { | 524 | var cobro = { |
524 | COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | 525 | COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, |
525 | numero: cheque.numero, | 526 | numero: cheque.numero, |
526 | banco: cheque.banco, | 527 | banco: cheque.banco, |
527 | FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | 528 | FEC: cheque.fechaEmision.toLocaleDateString() + '-' + |
528 | cheque.fechaPresentacion.toLocaleDateString(), | 529 | cheque.fechaPresentacion.toLocaleDateString(), |
529 | fechaPresentacion: cheque.fechaPresentacion, | 530 | fechaPresentacion: cheque.fechaPresentacion, |
530 | fechaEmision: cheque.fechaEmision, | 531 | fechaEmision: cheque.fechaEmision, |
531 | IMP: cheque.importe, | 532 | IMP: cheque.importe, |
532 | localidad: cheque.localidad, | 533 | localidad: cheque.localidad, |
533 | librador: cheque.librador, | 534 | librador: cheque.librador, |
534 | provincia: cheque.provincia, | 535 | provincia: cheque.provincia, |
535 | observaciones: cheque.observaciones, | 536 | observaciones: cheque.observaciones, |
536 | TIL: 'EF' | 537 | TIL: 'EF' |
537 | }; | 538 | }; |
538 | pushearCobro(cobro, cheque.$$hashKey); | 539 | pushearCobro(cobro, cheque.$$hashKey); |
539 | }, function() { | 540 | }, function() { |
540 | 541 | ||
541 | } | 542 | } |
542 | ); | 543 | ); |
543 | }; | 544 | }; |
544 | 545 | ||
545 | $scope.seleccionarEfectivo = function() { | 546 | $scope.seleccionarEfectivo = function() { |
546 | 547 | ||
547 | var importe = 0; | 548 | var importe = 0; |
548 | $scope.cobranza.cobros.filter(function(a) { | 549 | $scope.cobranza.cobros.filter(function(a) { |
549 | if(a.COM === 'Efectivo') { | 550 | if(a.COM === 'Efectivo') { |
550 | importe = a.IMP; | 551 | importe = a.IMP; |
551 | } | 552 | } |
552 | }); | 553 | }); |
553 | 554 | ||
554 | var modalInstance = $uibModal.open( | 555 | var modalInstance = $uibModal.open( |
555 | { | 556 | { |
556 | ariaLabelledBy: 'Carga de cheques', | 557 | ariaLabelledBy: 'Carga de cheques', |
557 | templateUrl: 'modal-efectivo.html', | 558 | templateUrl: 'modal-efectivo.html', |
558 | controller: 'focaModalEfectivoController', | 559 | controller: 'focaModalEfectivoController', |
559 | size: 'sm', | 560 | size: 'sm', |
560 | resolve: { | 561 | resolve: { |
561 | sugerido: function() { | 562 | sugerido: function() { |
562 | return parseFloat(getSugerido()) + parseFloat(importe); | 563 | return parseFloat(getSugerido()) + parseFloat(importe); |
563 | } | 564 | } |
564 | } | 565 | } |
565 | } | 566 | } |
566 | ); | 567 | ); |
567 | modalInstance.result.then( | 568 | modalInstance.result.then( |
568 | function(efectivo) { | 569 | function(efectivo) { |
569 | 570 | ||
570 | var cobro = { | 571 | var cobro = { |
571 | COM: 'Efectivo', | 572 | COM: 'Efectivo', |
572 | FEC: new Date(), | 573 | FEC: new Date(), |
573 | IMP: efectivo, | 574 | IMP: efectivo, |
574 | TIL: 'EF' | 575 | TIL: 'EF' |
575 | }; | 576 | }; |
576 | 577 | ||
577 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | 578 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { |
578 | return a.COM !== 'Efectivo'; | 579 | return a.COM !== 'Efectivo'; |
579 | }); | 580 | }); |
580 | 581 | ||
581 | $scope.cobranza.cobros.push(cobro); | 582 | $scope.cobranza.cobros.push(cobro); |
582 | }, function() { | 583 | }, function() { |
583 | 584 | ||
584 | } | 585 | } |
585 | ); | 586 | ); |
586 | }; | 587 | }; |
587 | 588 | ||
588 | $scope.seleccionarDetalles = function(detalle) { | 589 | $scope.seleccionarDetalles = function(detalle) { |
589 | 590 | ||
590 | var parametro = {}; | 591 | var parametro = {}; |
591 | 592 | ||
592 | if(!detalle) { | 593 | if(!detalle) { |
593 | parametro = { | 594 | parametro = { |
594 | importe: getSugerido(), | 595 | importe: getSugerido(), |
595 | files: [] | 596 | files: [] |
596 | }; | 597 | }; |
597 | } else { | 598 | } else { |
598 | parametro = detalle; | 599 | parametro = detalle; |
599 | parametro.importe = detalle.IMP; | 600 | parametro.importe = detalle.IMP; |
600 | parametro.files= detalle.imgs; | 601 | parametro.files= detalle.imgs; |
601 | } | 602 | } |
602 | 603 | ||
603 | var modalInstance = $uibModal.open( | 604 | var modalInstance = $uibModal.open( |
604 | { | 605 | { |
605 | ariaLabelledBy: 'Carga de detalles', | 606 | ariaLabelledBy: 'Carga de detalles', |
606 | templateUrl: 'modal-detalles.html', | 607 | templateUrl: 'modal-detalles.html', |
607 | controller: 'focaModalDetallesController', | 608 | controller: 'focaModalDetallesController', |
608 | size: 'lg', | 609 | size: 'lg', |
609 | resolve: { | 610 | resolve: { |
610 | parametros: function() { | 611 | parametros: function() { |
611 | return parametro; | 612 | return parametro; |
612 | } | 613 | } |
613 | } | 614 | } |
614 | } | 615 | } |
615 | ); | 616 | ); |
616 | modalInstance.result.then( | 617 | modalInstance.result.then( |
617 | function(detalles) { | 618 | function(detalles) { |
618 | 619 | ||
619 | var cobro = { | 620 | var cobro = { |
620 | COM: 'de(COBRO POR DETALLES)', | 621 | COM: 'de(COBRO POR DETALLES)', |
621 | FEC: new Date(), | 622 | FEC: new Date(), |
622 | IMP: detalles.importe, | 623 | IMP: detalles.importe, |
623 | imgs: detalles.files, | 624 | imgs: detalles.files, |
624 | TIL: 'DE', | 625 | TIL: 'DE', |
625 | observacion: detalles.observacion | 626 | observacion: detalles.observacion |
626 | }; | 627 | }; |
627 | pushearCobro(cobro, detalles.$$hashKey); | 628 | pushearCobro(cobro, detalles.$$hashKey); |
628 | }, function() {} | 629 | }, function() {} |
629 | ); | 630 | ); |
630 | }; | 631 | }; |
631 | 632 | ||
632 | $scope.seleccionarMoneda = function() { | 633 | $scope.seleccionarMoneda = function() { |
633 | var parametrosModal = { | 634 | var parametrosModal = { |
634 | titulo: 'Búsqueda de monedas', | 635 | titulo: 'Búsqueda de monedas', |
635 | query: '/moneda', | 636 | query: '/moneda', |
636 | columnas: [ | 637 | columnas: [ |
637 | { | 638 | { |
638 | propiedad: 'DETALLE', | 639 | propiedad: 'DETALLE', |
639 | nombre: 'Nombre' | 640 | nombre: 'Nombre' |
640 | }, | 641 | }, |
641 | { | 642 | { |
642 | propiedad: 'SIMBOLO', | 643 | propiedad: 'SIMBOLO', |
643 | nombre: 'Símbolo' | 644 | nombre: 'Símbolo' |
644 | } | 645 | } |
645 | ], | 646 | ], |
646 | size: 'md' | 647 | size: 'md' |
647 | }; | 648 | }; |
648 | focaModalService.modal(parametrosModal).then( | 649 | focaModalService.modal(parametrosModal).then( |
649 | function(moneda) { | 650 | function(moneda) { |
650 | $scope.seleccionarCotizacion(moneda); | 651 | $scope.seleccionarCotizacion(moneda); |
651 | }, function() { | 652 | }, function() { |
652 | 653 | ||
653 | } | 654 | } |
654 | ); | 655 | ); |
655 | }; | 656 | }; |
656 | 657 | ||
657 | $scope.seleccionarCotizacion = function(moneda) { | 658 | $scope.seleccionarCotizacion = function(moneda) { |
658 | var modalInstance = $uibModal.open( | 659 | var modalInstance = $uibModal.open( |
659 | { | 660 | { |
660 | ariaLabelledBy: 'Busqueda de Cotización', | 661 | ariaLabelledBy: 'Busqueda de Cotización', |
661 | templateUrl: 'modal-cotizacion.html', | 662 | templateUrl: 'modal-cotizacion.html', |
662 | controller: 'focaModalCotizacionController', | 663 | controller: 'focaModalCotizacionController', |
663 | size: 'lg', | 664 | size: 'lg', |
664 | resolve: {idMoneda: function() {return moneda.ID;}} | 665 | resolve: {idMoneda: function() {return moneda.ID;}} |
665 | } | 666 | } |
666 | ); | 667 | ); |
667 | modalInstance.result.then( | 668 | modalInstance.result.then( |
668 | function(cotizacion) { | 669 | function(cotizacion) { |
669 | $scope.cobranza.moneda = moneda; | 670 | $scope.cobranza.moneda = moneda; |
670 | $scope.cobranza.moneda.cotizacion = cotizacion; | 671 | $scope.cobranza.moneda.cotizacion = cotizacion; |
671 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 672 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
672 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 673 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
673 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 674 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
674 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 675 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
675 | } else { | 676 | } else { |
676 | $scope.$broadcast('addCabecera', { | 677 | $scope.$broadcast('addCabecera', { |
677 | label: 'Moneda:', | 678 | label: 'Moneda:', |
678 | valor: moneda.DETALLE | 679 | valor: moneda.DETALLE |
679 | }); | 680 | }); |
680 | $scope.$broadcast('addCabecera', { | 681 | $scope.$broadcast('addCabecera', { |
681 | label: 'Fecha cotizacion:', | 682 | label: 'Fecha cotizacion:', |
682 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 683 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
683 | }); | 684 | }); |
684 | $scope.$broadcast('addCabecera', { | 685 | $scope.$broadcast('addCabecera', { |
685 | label: 'Cotizacion:', | 686 | label: 'Cotizacion:', |
686 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 687 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
687 | }); | 688 | }); |
688 | } | 689 | } |
689 | 690 | ||
690 | $filter('filter')( $scope.botonera, { | 691 | $filter('filter')( $scope.botonera, { |
691 | label: 'Moneda' | 692 | label: 'Moneda' |
692 | })[0].checked = true; | 693 | })[0].checked = true; |
693 | 694 | ||
694 | }, function() { | 695 | }, function() { |
695 | 696 | ||
696 | } | 697 | } |
697 | ); | 698 | ); |
698 | }; | 699 | }; |
699 | 700 | ||
700 | $scope.getTotalDeuda = function() { | 701 | $scope.getTotalDeuda = function() { |
701 | var total = 0; | 702 | var total = 0; |
702 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { | 703 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { |
703 | total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; | 704 | total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; |
704 | } | 705 | } |
705 | return parseFloat(total.toFixed(2)); | 706 | return parseFloat(total.toFixed(2)); |
706 | }; | 707 | }; |
707 | 708 | ||
708 | $scope.getTotalCobrado = function() { | 709 | $scope.getTotalCobrado = function() { |
709 | var total = 0; | 710 | var total = 0; |
710 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { | 711 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { |
711 | total += $scope.cobranza.cobros[i].IMP; | 712 | total += $scope.cobranza.cobros[i].IMP; |
712 | } | 713 | } |
713 | return parseFloat(total.toFixed(2)); | 714 | return parseFloat(total.toFixed(2)); |
714 | }; | 715 | }; |
715 | 716 | ||
716 | $scope.getSubTotal = function() { | 717 | $scope.getSubTotal = function() { |
717 | if ($scope.articuloACargar) { | 718 | if ($scope.articuloACargar) { |
718 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 719 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
719 | } | 720 | } |
720 | }; | 721 | }; |
721 | //Recibe aviso si el teclado está en uso | 722 | //Recibe aviso si el teclado está en uso |
722 | // $rootScope.$on('usarTeclado', function(event, data) { | 723 | // $rootScope.$on('usarTeclado', function(event, data) { |
723 | // if(data) { | 724 | // if(data) { |
724 | // $scope.mostrarTeclado = true; | 725 | // $scope.mostrarTeclado = true; |
725 | // return; | 726 | // return; |
726 | // } | 727 | // } |
727 | // $scope.mostrarTeclado = false; | 728 | // $scope.mostrarTeclado = false; |
728 | // }) | 729 | // }) |
729 | $scope.selectFocus = function($event) { | 730 | $scope.selectFocus = function($event) { |
730 | //Si el teclado esta en uso no selecciona el valor | 731 | //Si el teclado esta en uso no selecciona el valor |
731 | // if($scope.mostrarTeclado) { | 732 | // if($scope.mostrarTeclado) { |
732 | // return; | 733 | // return; |
733 | // } | 734 | // } |
734 | $event.target.select(); | 735 | $event.target.select(); |
735 | }; | 736 | }; |
736 | 737 | ||
737 | $scope.salir = function() { | 738 | $scope.salir = function() { |
738 | $location.path('/'); | 739 | $location.path('/'); |
739 | }; | 740 | }; |
740 | 741 | ||
741 | $scope.parsearATexto = function(articulo) { | 742 | $scope.parsearATexto = function(articulo) { |
742 | articulo.cantidad = parseFloat(articulo.cantidad); | 743 | articulo.cantidad = parseFloat(articulo.cantidad); |
743 | articulo.precio = parseFloat(articulo.precio); | 744 | articulo.precio = parseFloat(articulo.precio); |
744 | }; | 745 | }; |
745 | 746 | ||
746 | $scope.quitarFactura = function(key) { | 747 | $scope.quitarFactura = function(key) { |
747 | $scope.cobranza.facturas.splice(key, 1); | 748 | $scope.cobranza.facturas.splice(key, 1); |
748 | }; | 749 | }; |
749 | 750 | ||
750 | $scope.quitarCobro = function(key) { | 751 | $scope.quitarCobro = function(key) { |
751 | $scope.cobranza.cobros.splice(key, 1); | 752 | $scope.cobranza.cobros.splice(key, 1); |
752 | }; | 753 | }; |
753 | 754 | ||
754 | $scope.editarCobro = function(cobro) { | 755 | $scope.editarCobro = function(cobro) { |
755 | if(cobro.COM === 'Efectivo') { | 756 | if(cobro.COM === 'Efectivo') { |
756 | $scope.seleccionarEfectivo(); | 757 | $scope.seleccionarEfectivo(); |
757 | } else if(cobro.COM.substring(0, 2) === 'de') { | 758 | } else if(cobro.COM.substring(0, 2) === 'de') { |
758 | $scope.seleccionarDetalles(cobro); | 759 | $scope.seleccionarDetalles(cobro); |
759 | } else if(cobro.COM.substring(0, 2) === 'ch') { | 760 | } else if(cobro.COM.substring(0, 2) === 'ch') { |
760 | $scope.seleccionarCheque(cobro); | 761 | $scope.seleccionarCheque(cobro); |
761 | } | 762 | } |
762 | }; | 763 | }; |
763 | 764 | ||
764 | $scope.$watch('cobranza.facturas', function() { | 765 | $scope.$watch('cobranza.facturas', function() { |
765 | if ($scope.cobranza.facturas.length) { | 766 | if ($scope.cobranza.facturas.length) { |
766 | $filter('filter')( $scope.botonera, { | 767 | $filter('filter')( $scope.botonera, { |
767 | label: 'Comprobantes' | 768 | label: 'Comprobantes' |
768 | })[0].checked = true; | 769 | })[0].checked = true; |
769 | } else { | 770 | } else { |
770 | $filter('filter')( $scope.botonera, { | 771 | $filter('filter')( $scope.botonera, { |
771 | label: 'Comprobantes' | 772 | label: 'Comprobantes' |
772 | })[0].checked = false; | 773 | })[0].checked = false; |
773 | } | 774 | } |
774 | }, true); | 775 | }, true); |
775 | 776 | ||
776 | $scope.$watch('cobranza.cobros', function() { | 777 | $scope.$watch('cobranza.cobros', function() { |
777 | if ($scope.cobranza.cobros.length) { | 778 | if ($scope.cobranza.cobros.length) { |
778 | $filter('filter')( $scope.botonera, { | 779 | $filter('filter')( $scope.botonera, { |
779 | label: 'Cobros' | 780 | label: 'Cobros' |
780 | })[0].checked = true; | 781 | })[0].checked = true; |
781 | } else { | 782 | } else { |
782 | $filter('filter')( $scope.botonera, { | 783 | $filter('filter')( $scope.botonera, { |
783 | label: 'Cobros' | 784 | label: 'Cobros' |
784 | })[0].checked = false; | 785 | })[0].checked = false; |
785 | } | 786 | } |
786 | }, true); | 787 | }, true); |
787 | 788 | ||
788 | function pushearCobro(cobro, hashKey) { | 789 | function pushearCobro(cobro, hashKey) { |
789 | var existe; | 790 | var existe; |
790 | 791 | ||
791 | $scope.cobranza.cobros.forEach(function(c, idx) { | 792 | $scope.cobranza.cobros.forEach(function(c, idx) { |
792 | if(c.$$hashKey === hashKey) { | 793 | if(c.$$hashKey === hashKey) { |
793 | $scope.cobranza.cobros[idx] = cobro; | 794 | $scope.cobranza.cobros[idx] = cobro; |
794 | existe = true; | 795 | existe = true; |
795 | } | 796 | } |
796 | }); | 797 | }); |
797 | if (!existe) { | 798 | if (!existe) { |
798 | $scope.cobranza.cobros.push(cobro); | 799 | $scope.cobranza.cobros.push(cobro); |
799 | } | 800 | } |
800 | } | 801 | } |
801 | 802 | ||
802 | function salir() { | 803 | function salir() { |
803 | var confirmacion = false; | 804 | var confirmacion = false; |
804 | 805 | ||
805 | if (!angular.equals($scope.cobranza, $scope.inicial)) { | 806 | if (!angular.equals($scope.cobranza, $scope.inicial)) { |
806 | confirmacion = true; | 807 | confirmacion = true; |
807 | } | 808 | } |
808 | 809 | ||
809 | if (confirmacion) { | 810 | if (confirmacion) { |
810 | focaModalService.confirm( | 811 | focaModalService.confirm( |
811 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 812 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
812 | ).then(function(data) { | 813 | ).then(function(data) { |
813 | if (data) { | 814 | if (data) { |
814 | $location.path('/'); | 815 | $location.path('/'); |
815 | } | 816 | } |
816 | }); | 817 | }); |
817 | } else { | 818 | } else { |
818 | $location.path('/'); | 819 | $location.path('/'); |
819 | } | 820 | } |
820 | } | 821 | } |
821 | 822 | ||
822 | function setearCobranza(cobranza) { | 823 | function setearCobranza(cobranza) { |
823 | $scope.editando = true; | 824 | $scope.editando = true; |
824 | $scope.$broadcast('cleanCabecera'); | 825 | $scope.$broadcast('cleanCabecera'); |
825 | 826 | ||
826 | if (cobranza.cliente) { | 827 | if (cobranza.cliente) { |
827 | $scope.$broadcast('addCabecera', { | 828 | $scope.$broadcast('addCabecera', { |
828 | label: 'Cliente:', | 829 | label: 'Cliente:', |
829 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + | 830 | valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + |
830 | cobranza.cliente.NOM | 831 | cobranza.cliente.NOM |
831 | }); | 832 | }); |
832 | 833 | ||
833 | $filter('filter')( $scope.botonera, { | 834 | $filter('filter')( $scope.botonera, { |
834 | label: 'Cliente' | 835 | label: 'Cliente' |
835 | })[0].checked = true; | 836 | })[0].checked = true; |
836 | } | 837 | } |
837 | if (cobranza.cobrador && cobranza.cobrador.NUM) { | 838 | if (cobranza.cobrador && cobranza.cobrador.NUM) { |
838 | $scope.$broadcast('addCabecera', { | 839 | $scope.$broadcast('addCabecera', { |
839 | label: 'Cobrador:', | 840 | label: 'Cobrador:', |
840 | valor: (cobranza.cobrador.NUM) ? | 841 | valor: (cobranza.cobrador.NUM) ? |
841 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + | 842 | $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + |
842 | cobranza.cobrador.NOM : cobranza.cobrador | 843 | cobranza.cobrador.NOM : cobranza.cobrador |
843 | 844 | ||
844 | }); | 845 | }); |
845 | } | 846 | } |
846 | 847 | ||
847 | // TODO: Setear moneda | 848 | // TODO: Setear moneda |
848 | if (cobranza.moneda) { | 849 | if (cobranza.moneda) { |
849 | $filter('filter')( $scope.botonera, { | 850 | $filter('filter')( $scope.botonera, { |
850 | label: 'Moneda' | 851 | label: 'Moneda' |
851 | })[0].checked = true; | 852 | })[0].checked = true; |
852 | } | 853 | } |
853 | 854 | ||
854 | $scope.cobranza = cobranza; | 855 | $scope.cobranza = cobranza; |
855 | } | 856 | } |
856 | 857 | ||
857 | function getLSCobranza() { | 858 | function getLSCobranza() { |
858 | var cobranza = JSON.parse($localStorage.cobranza || null); | 859 | var cobranza = JSON.parse($localStorage.cobranza || null); |
859 | if (cobranza) { | 860 | if (cobranza) { |
860 | setearCobranza(cobranza); | 861 | setearCobranza(cobranza); |
861 | delete $localStorage.cobranza; | 862 | delete $localStorage.cobranza; |
862 | } | 863 | } |
863 | } | 864 | } |
864 | 865 | ||
865 | function enviarMail(recibo) { | 866 | function enviarMail(recibo) { |
866 | focaModalService.mail( | 867 | focaModalService.mail( |
867 | { | 868 | { |
868 | titulo: 'Enviar recibo', | 869 | titulo: 'Enviar recibo', |
869 | descarga: { | 870 | descarga: { |
870 | nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf', | 871 | nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf', |
871 | url: '/mail/recibo/descargar', | 872 | url: '/mail/recibo/descargar', |
872 | }, | 873 | }, |
873 | envio: { | 874 | envio: { |
874 | mailCliente: recibo.cliente.MAIL, | 875 | mailCliente: recibo.cliente.MAIL, |
875 | url: '/mail/recibo', | 876 | url: '/mail/recibo', |
876 | }, | 877 | }, |
877 | options: { | 878 | options: { |
878 | recibo: recibo | 879 | recibo: recibo |
879 | } | 880 | } |
880 | } | 881 | } |
881 | ); | 882 | ); |
882 | } | 883 | } |
883 | 884 | ||
884 | function getSugerido() { | 885 | function getSugerido() { |
885 | var result; | 886 | var result; |
886 | 887 | ||
887 | var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | 888 | var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); |
888 | 889 | ||
889 | if (valor < 0) { | 890 | if (valor < 0) { |
890 | result = Math.abs(valor).toFixed(4); | 891 | result = Math.abs(valor).toFixed(4); |
891 | } | 892 | } |
892 | 893 | ||
893 | return result; | 894 | return result; |
894 | } | 895 | } |
895 | } | 896 | } |
896 | ]); | 897 | ]); |
897 | 898 |