Commit 3c88aaf632ba2dfc2491333e8bb41cc9e51b11b6

Authored by Jose Pinto
1 parent 5e73c4e810
Exists in master

agrego boton "resumen cuenta"

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