Commit 5df24d63ace7333d395b1eeec5b75baffaa0edd8

Authored by Jose Pinto
1 parent 3c88aaf632
Exists in master

ok modal-prompt

Showing 1 changed file with 5 additions and 2 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearCobranza') .controller('cobranzaController', 1 angular.module('focaCrearCobranza') .controller('cobranzaController',
2 [ 2 [
3 '$scope', '$timeout', '$uibModal', '$location', 3 '$scope', '$timeout', '$uibModal', '$location',
4 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', 4 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService',
5 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', 5 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage',
6 function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, 6 function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService,
7 focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, 7 focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService,
8 APP, loginService, $localStorage) 8 APP, loginService, $localStorage)
9 { 9 {
10 config(); 10 config();
11 11
12 function config() { 12 function config() {
13 $scope.datepickerAbierto = false; 13 $scope.datepickerAbierto = false;
14 $scope.cobroDeuda = true; 14 $scope.cobroDeuda = true;
15 $scope.show = false; 15 $scope.show = false;
16 $scope.cargando = true; 16 $scope.cargando = true;
17 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 17 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
18 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 18 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
19 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({
309 cliente.MAIL) 309 titulo: 'Ingrese los emails separados por' +
310 ' coma para enviar comprobante',
311 value: cliente.MAIL
312 })
310 .then(function(res) { 313 .then(function(res) {
311 return Promise.all([ 314 return Promise.all([
312 focaCrearCobranzaService 315 focaCrearCobranzaService
313 .enviarComprobantePorMail(res, cobranzaMail), 316 .enviarComprobantePorMail(res, cobranzaMail),
314 focaCrearCobranzaService 317 focaCrearCobranzaService
315 .actualizarEmail(res, cliente.COD) 318 .actualizarEmail(res, cliente.COD)
316 ]); 319 ]);
317 }) 320 })
318 .then(function() { 321 .then(function() {
319 focaModalService.alert('Mensaje enviado correctamente'); 322 focaModalService.alert('Mensaje enviado correctamente');
320 }); 323 });
321 324
322 focaSeguimientoService.guardarPosicion( 325 focaSeguimientoService.guardarPosicion(
323 'Cobranza', 326 'Cobranza',
324 result.data, 327 result.data,
325 '' 328 ''
326 ); 329 );
327 330
328 init(); 331 init();
329 }, function(error) { 332 }, function(error) {
330 focaModalService.alert('Hubo un problema al cargar la cobranza'); 333 focaModalService.alert('Hubo un problema al cargar la cobranza');
331 focaBotoneraLateralService.endGuardar(); 334 focaBotoneraLateralService.endGuardar();
332 $scope.saveLoading = false; 335 $scope.saveLoading = false;
333 console.info(error); 336 console.info(error);
334 } 337 }
335 ); 338 );
336 }; 339 };
337 340
338 $scope.seleccionarCobros = function() { 341 $scope.seleccionarCobros = function() {
339 $scope.cobroDeuda = false; 342 $scope.cobroDeuda = false;
340 }; 343 };
341 344
342 $scope.seleccionarComprobantes = function() { 345 $scope.seleccionarComprobantes = function() {
343 $scope.cobroDeuda = true; 346 $scope.cobroDeuda = true;
344 }; 347 };
345 348
346 $scope.seleccionarCobranza = function() { 349 $scope.seleccionarCobranza = function() {
347 350
348 var modalInstance = $uibModal.open( 351 var modalInstance = $uibModal.open(
349 { 352 {
350 ariaLabelledBy: 'Busqueda de Cobranzas', 353 ariaLabelledBy: 'Busqueda de Cobranzas',
351 templateUrl: 'foca-modal-cobranza.html', 354 templateUrl: 'foca-modal-cobranza.html',
352 controller: 'focaModalCobranzaController', 355 controller: 'focaModalCobranzaController',
353 size: 'lg' 356 size: 'lg'
354 } 357 }
355 ); 358 );
356 modalInstance.result.then(setearCobranza); 359 modalInstance.result.then(setearCobranza);
357 }; 360 };
358 361
359 $scope.seleccionarResumenDeCuenta = function() { 362 $scope.seleccionarResumenDeCuenta = function() {
360 if (!$scope.cobranza.cliente.COD) { 363 if (!$scope.cobranza.cliente.COD) {
361 focaModalService.alert('Seleccione primero un cliente'); 364 focaModalService.alert('Seleccione primero un cliente');
362 return; 365 return;
363 } 366 }
364 var modalInstance = $uibModal.open( 367 var modalInstance = $uibModal.open(
365 { 368 {
366 ariaLabelledBy: 'Resumen de cuentas', 369 ariaLabelledBy: 'Resumen de cuentas',
367 templateUrl: 'modal-resumen-cuenta.html', 370 templateUrl: 'modal-resumen-cuenta.html',
368 controller: 'focaModalResumenCuentaController', 371 controller: 'focaModalResumenCuentaController',
369 resolve: { 372 resolve: {
370 idCliente: function() { return $scope.cobranza.cliente.COD; } 373 idCliente: function() { return $scope.cobranza.cliente.COD; }
371 }, 374 },
372 size: 'lg' 375 size: 'lg'
373 } 376 }
374 ); 377 );
375 modalInstance.result.then( 378 modalInstance.result.then(
376 function(cliente) { 379 function(cliente) {
377 $scope.abrirModalDomicilios(cliente); 380 $scope.abrirModalDomicilios(cliente);
378 $scope.cliente = cliente; 381 $scope.cliente = cliente;
379 }, function() {} 382 }, function() {}
380 ); 383 );
381 }; 384 };
382 385
383 $scope.seleccionarCliente = function() { 386 $scope.seleccionarCliente = function() {
384 if(!$scope.cobranza.cobrador) { 387 if(!$scope.cobranza.cobrador) {
385 focaModalService.alert('Ingrese primero cobrador'); 388 focaModalService.alert('Ingrese primero cobrador');
386 return; 389 return;
387 } 390 }
388 var modalInstance = $uibModal.open( 391 var modalInstance = $uibModal.open(
389 { 392 {
390 ariaLabelledBy: 'Busqueda de Cliente', 393 ariaLabelledBy: 'Busqueda de Cliente',
391 templateUrl: 'foca-busqueda-cliente-modal.html', 394 templateUrl: 'foca-busqueda-cliente-modal.html',
392 controller: 'focaBusquedaClienteModalController', 395 controller: 'focaBusquedaClienteModalController',
393 resolve: { 396 resolve: {
394 vendedor: function() { return null; } 397 vendedor: function() { return null; }
395 }, 398 },
396 size: 'lg' 399 size: 'lg'
397 } 400 }
398 ); 401 );
399 modalInstance.result.then( 402 modalInstance.result.then(
400 function(cliente) { 403 function(cliente) {
401 var clienteMayus = { 404 var clienteMayus = {
402 COD: cliente.cod, 405 COD: cliente.cod,
403 NOM: cliente.nom, 406 NOM: cliente.nom,
404 CUIT: cliente.cuit 407 CUIT: cliente.cuit
405 }; 408 };
406 409
407 $scope.$broadcast('addCabecera', { 410 $scope.$broadcast('addCabecera', {
408 label: 'Cliente:', 411 label: 'Cliente:',
409 valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + 412 valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' +
410 clienteMayus.NOM 413 clienteMayus.NOM
411 }); 414 });
412 $scope.cobranza.cliente = clienteMayus; 415 $scope.cobranza.cliente = clienteMayus;
413 } 416 }
414 ); 417 );
415 }; 418 };
416 419
417 $scope.seleccionarFactura = function() { 420 $scope.seleccionarFactura = function() {
418 if (!$scope.cobranza.cliente.COD) { 421 if (!$scope.cobranza.cliente.COD) {
419 focaModalService.alert('Seleccione primero un cliente'); 422 focaModalService.alert('Seleccione primero un cliente');
420 return; 423 return;
421 } 424 }
422 var modalInstance = $uibModal.open( 425 var modalInstance = $uibModal.open(
423 { 426 {
424 ariaLabelledBy: 'Busqueda de Facturas', 427 ariaLabelledBy: 'Busqueda de Facturas',
425 templateUrl: 'foca-modal-factura.html', 428 templateUrl: 'foca-modal-factura.html',
426 controller: 'focaModalFacturaController', 429 controller: 'focaModalFacturaController',
427 size: 'lg', 430 size: 'lg',
428 resolve: { 431 resolve: {
429 parametrosFactura: function() { 432 parametrosFactura: function() {
430 return { 433 return {
431 cliente: $scope.cobranza.cliente, 434 cliente: $scope.cobranza.cliente,
432 simbolo: $scope.cobranza.cotizacion.moneda.SIMBOLO, 435 simbolo: $scope.cobranza.cotizacion.moneda.SIMBOLO,
433 cotizacion: $scope.cobranza.cotizacion.VENDEDOR, 436 cotizacion: $scope.cobranza.cotizacion.VENDEDOR,
434 moneda: $scope.cobranza.cotizacion.moneda.ID 437 moneda: $scope.cobranza.cotizacion.moneda.ID
435 }; 438 };
436 } 439 }
437 } 440 }
438 } 441 }
439 ); 442 );
440 modalInstance.result.then( 443 modalInstance.result.then(
441 function(facturas) { 444 function(facturas) {
442 $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturas); 445 $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturas);
443 }, function() { 446 }, function() {
444 447
445 } 448 }
446 ); 449 );
447 }; 450 };
448 451
449 $scope.seleccionarCheque = function() { 452 $scope.seleccionarCheque = function() {
450 var modalInstance = $uibModal.open( 453 var modalInstance = $uibModal.open(
451 { 454 {
452 ariaLabelledBy: 'Carga de cheques', 455 ariaLabelledBy: 'Carga de cheques',
453 templateUrl: 'modal-cheque.html', 456 templateUrl: 'modal-cheque.html',
454 controller: 'focaModalChequeController', 457 controller: 'focaModalChequeController',
455 size: 'lg', 458 size: 'lg',
456 resolve: { 459 resolve: {
457 sugerido: function() { 460 sugerido: function() {
458 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 461 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
459 return sugerido < 0 ? sugerido : null; 462 return sugerido < 0 ? sugerido : null;
460 } 463 }
461 } 464 }
462 } 465 }
463 ); 466 );
464 modalInstance.result.then( 467 modalInstance.result.then(
465 function(cheque) { 468 function(cheque) {
466 var cobro = { 469 var cobro = {
467 tipo: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, 470 tipo: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
468 numero: cheque.numero, 471 numero: cheque.numero,
469 banco: cheque.banco, 472 banco: cheque.banco,
470 fecha: cheque.fechaEmision.toLocaleDateString() + '-' + 473 fecha: cheque.fechaEmision.toLocaleDateString() + '-' +
471 cheque.fechaPresentacion.toLocaleDateString(), 474 cheque.fechaPresentacion.toLocaleDateString(),
472 fechaPresentacion: cheque.fechaPresentacion, 475 fechaPresentacion: cheque.fechaPresentacion,
473 fechaEmision: cheque.fechaEmision, 476 fechaEmision: cheque.fechaEmision,
474 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, 477 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR,
475 localidad: cheque.localidad, 478 localidad: cheque.localidad,
476 librador: cheque.librador, 479 librador: cheque.librador,
477 provincia: cheque.provincia, 480 provincia: cheque.provincia,
478 observaciones: cheque.observaciones, 481 observaciones: cheque.observaciones,
479 til: 'EF' 482 til: 'EF'
480 }; 483 };
481 $scope.cobranza.cobros.push(cobro); 484 $scope.cobranza.cobros.push(cobro);
482 }, function() { 485 }, function() {
483 486
484 } 487 }
485 ); 488 );
486 }; 489 };
487 490
488 $scope.seleccionarEfectivo = function() { 491 $scope.seleccionarEfectivo = function() {
489 var modalInstance = $uibModal.open( 492 var modalInstance = $uibModal.open(
490 { 493 {
491 ariaLabelledBy: 'Carga de cheques', 494 ariaLabelledBy: 'Carga de cheques',
492 templateUrl: 'modal-efectivo.html', 495 templateUrl: 'modal-efectivo.html',
493 controller: 'focaModalEfectivoController', 496 controller: 'focaModalEfectivoController',
494 size: 'sm', 497 size: 'sm',
495 resolve: { 498 resolve: {
496 sugerido: function() { 499 sugerido: function() {
497 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 500 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
498 return sugerido < 0 ? sugerido : null; 501 return sugerido < 0 ? sugerido : null;
499 } 502 }
500 } 503 }
501 } 504 }
502 ); 505 );
503 modalInstance.result.then( 506 modalInstance.result.then(
504 function(efectivo) { 507 function(efectivo) {
505 var cobro = { 508 var cobro = {
506 tipo: 'Efectivo', 509 tipo: 'Efectivo',
507 fecha: new Date(), 510 fecha: new Date(),
508 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR, 511 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR,
509 til: 'EF' 512 til: 'EF'
510 }; 513 };
511 $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { 514 $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) {
512 return a.tipo !== 'Efectivo'; 515 return a.tipo !== 'Efectivo';
513 }); 516 });
514 $scope.cobranza.cobros.push(cobro); 517 $scope.cobranza.cobros.push(cobro);
515 }, function() { 518 }, function() {
516 519
517 } 520 }
518 ); 521 );
519 }; 522 };
520 523
521 $scope.seleccionarDetalles = function() { 524 $scope.seleccionarDetalles = function() {
522 var modalInstance = $uibModal.open( 525 var modalInstance = $uibModal.open(
523 { 526 {
524 ariaLabelledBy: 'Carga de detalles', 527 ariaLabelledBy: 'Carga de detalles',
525 templateUrl: 'modal-detalles.html', 528 templateUrl: 'modal-detalles.html',
526 controller: 'focaModalDetallesController', 529 controller: 'focaModalDetallesController',
527 size: 'lg', 530 size: 'lg',
528 resolve: { 531 resolve: {
529 sugerido: function() { 532 sugerido: function() {
530 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 533 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
531 return sugerido < 0 ? sugerido : null; 534 return sugerido < 0 ? sugerido : null;
532 } 535 }
533 } 536 }
534 } 537 }
535 ); 538 );
536 modalInstance.result.then( 539 modalInstance.result.then(
537 function(detalles) { 540 function(detalles) {
538 var cobro = { 541 var cobro = {
539 tipo: 'de(COBRO POR DETALLES)', 542 tipo: 'de(COBRO POR DETALLES)',
540 fecha: new Date(), 543 fecha: new Date(),
541 importe: detalles.monto * $scope.cobranza.cotizacion.VENDEDOR, 544 importe: detalles.monto * $scope.cobranza.cotizacion.VENDEDOR,
542 imgs: detalles.imgs, 545 imgs: detalles.imgs,
543 til: 'DE', 546 til: 'DE',
544 observacion: detalles.observacion 547 observacion: detalles.observacion
545 }; 548 };
546 var existe = false; 549 var existe = false;
547 550
548 $scope.cobranza.cobros.forEach(function(c, idx) { 551 $scope.cobranza.cobros.forEach(function(c, idx) {
549 if (c.til === 'DE') { 552 if (c.til === 'DE') {
550 $scope.cobranza.cobros[idx] = cobro; 553 $scope.cobranza.cobros[idx] = cobro;
551 existe = true; 554 existe = true;
552 } 555 }
553 }); 556 });
554 if (!existe) { 557 if (!existe) {
555 $scope.cobranza.cobros.push(cobro); 558 $scope.cobranza.cobros.push(cobro);
556 } 559 }
557 }, function() {} 560 }, function() {}
558 ); 561 );
559 }; 562 };
560 563
561 $scope.seleccionarMoneda = function() { 564 $scope.seleccionarMoneda = function() {
562 var parametrosModal = { 565 var parametrosModal = {
563 titulo: 'Búsqueda de monedas', 566 titulo: 'Búsqueda de monedas',
564 query: '/moneda', 567 query: '/moneda',
565 columnas: [ 568 columnas: [
566 { 569 {
567 propiedad: 'DETALLE', 570 propiedad: 'DETALLE',
568 nombre: 'Nombre' 571 nombre: 'Nombre'
569 }, 572 },
570 { 573 {
571 propiedad: 'SIMBOLO', 574 propiedad: 'SIMBOLO',
572 nombre: 'Símbolo' 575 nombre: 'Símbolo'
573 } 576 }
574 ], 577 ],
575 size: 'md' 578 size: 'md'
576 }; 579 };
577 focaModalService.modal(parametrosModal).then( 580 focaModalService.modal(parametrosModal).then(
578 function(moneda) { 581 function(moneda) {
579 $scope.seleccionarCotizacion(moneda); 582 $scope.seleccionarCotizacion(moneda);
580 }, function() { 583 }, function() {
581 584
582 } 585 }
583 ); 586 );
584 }; 587 };
585 588
586 $scope.seleccionarCotizacion = function(moneda) { 589 $scope.seleccionarCotizacion = function(moneda) {
587 var modalInstance = $uibModal.open( 590 var modalInstance = $uibModal.open(
588 { 591 {
589 ariaLabelledBy: 'Busqueda de Cotización', 592 ariaLabelledBy: 'Busqueda de Cotización',
590 templateUrl: 'modal-cotizacion.html', 593 templateUrl: 'modal-cotizacion.html',
591 controller: 'focaModalCotizacionController', 594 controller: 'focaModalCotizacionController',
592 size: 'lg', 595 size: 'lg',
593 resolve: {idMoneda: function() {return moneda.ID;}} 596 resolve: {idMoneda: function() {return moneda.ID;}}
594 } 597 }
595 ); 598 );
596 modalInstance.result.then( 599 modalInstance.result.then(
597 function(cotizacion) { 600 function(cotizacion) {
598 $scope.cobranza.cotizacion.moneda = moneda; 601 $scope.cobranza.cotizacion.moneda = moneda;
599 $scope.cobranza.cotizacion = cotizacion; 602 $scope.cobranza.cotizacion = cotizacion;
600 if (moneda.DETALLE === 'PESOS ARGENTINOS') { 603 if (moneda.DETALLE === 'PESOS ARGENTINOS') {
601 $scope.$broadcast('removeCabecera', 'Moneda:'); 604 $scope.$broadcast('removeCabecera', 'Moneda:');
602 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 605 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
603 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 606 $scope.$broadcast('removeCabecera', 'Cotizacion:');
604 } else { 607 } else {
605 $scope.$broadcast('addCabecera', { 608 $scope.$broadcast('addCabecera', {
606 label: 'Moneda:', 609 label: 'Moneda:',
607 valor: moneda.DETALLE 610 valor: moneda.DETALLE
608 }); 611 });
609 $scope.$broadcast('addCabecera', { 612 $scope.$broadcast('addCabecera', {
610 label: 'Fecha cotizacion:', 613 label: 'Fecha cotizacion:',
611 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 614 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
612 }); 615 });
613 $scope.$broadcast('addCabecera', { 616 $scope.$broadcast('addCabecera', {
614 label: 'Cotizacion:', 617 label: 'Cotizacion:',
615 valor: $filter('number')(cotizacion.VENDEDOR, '2') 618 valor: $filter('number')(cotizacion.VENDEDOR, '2')
616 }); 619 });
617 } 620 }
618 }, function() { 621 }, function() {
619 622
620 } 623 }
621 ); 624 );
622 }; 625 };
623 626
624 $scope.seleccionarCobrador = function() { 627 $scope.seleccionarCobrador = function() {
625 var parametrosModal = { 628 var parametrosModal = {
626 query: '/cobrador', 629 query: '/cobrador',
627 columnas: [ 630 columnas: [
628 { 631 {
629 propiedad: 'NUM', 632 propiedad: 'NUM',
630 nombre: 'Codigo', 633 nombre: 'Codigo',
631 filtro: { 634 filtro: {
632 nombre: 'rellenarDigitos', 635 nombre: 'rellenarDigitos',
633 parametro: 3 636 parametro: 3
634 } 637 }
635 }, 638 },
636 { 639 {
637 propiedad: 'NOM', 640 propiedad: 'NOM',
638 nombre: 'Nombre' 641 nombre: 'Nombre'
639 } 642 }
640 ], 643 ],
641 titulo:'Búsqueda de cobradores' 644 titulo:'Búsqueda de cobradores'
642 }; 645 };
643 focaModalService.modal(parametrosModal).then( 646 focaModalService.modal(parametrosModal).then(
644 function(cobrador) { 647 function(cobrador) {
645 $scope.$broadcast('addCabecera', { 648 $scope.$broadcast('addCabecera', {
646 label: 'Cobrador:', 649 label: 'Cobrador:',
647 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + 650 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' +
648 cobrador.NOM 651 cobrador.NOM
649 }); 652 });
650 $scope.cobranza.cobrador = cobrador; 653 $scope.cobranza.cobrador = cobrador;
651 }, function() { 654 }, function() {
652 655
653 } 656 }
654 ); 657 );
655 }; 658 };
656 659
657 $scope.getTotalDeuda = function() { 660 $scope.getTotalDeuda = function() {
658 var total = 0; 661 var total = 0;
659 for (var i = 0; i < $scope.cobranza.facturas.length; i++) { 662 for (var i = 0; i < $scope.cobranza.facturas.length; i++) {
660 total += $scope.cobranza.facturas[i].IPA; 663 total += $scope.cobranza.facturas[i].IPA;
661 } 664 }
662 return parseFloat(total.toFixed(2)); 665 return parseFloat(total.toFixed(2));
663 }; 666 };
664 667
665 $scope.getTotalCobrado = function() { 668 $scope.getTotalCobrado = function() {
666 var total = 0; 669 var total = 0;
667 for (var i = 0; i < $scope.cobranza.cobros.length; i++) { 670 for (var i = 0; i < $scope.cobranza.cobros.length; i++) {
668 total += $scope.cobranza.cobros[i].importe; 671 total += $scope.cobranza.cobros[i].importe;
669 } 672 }
670 return parseFloat(total.toFixed(2)); 673 return parseFloat(total.toFixed(2));
671 }; 674 };
672 675
673 $scope.getSubTotal = function() { 676 $scope.getSubTotal = function() {
674 if ($scope.articuloACargar) { 677 if ($scope.articuloACargar) {
675 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 678 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
676 } 679 }
677 }; 680 };
678 //Recibe aviso si el teclado está en uso 681 //Recibe aviso si el teclado está en uso
679 // $rootScope.$on('usarTeclado', function(event, data) { 682 // $rootScope.$on('usarTeclado', function(event, data) {
680 // if(data) { 683 // if(data) {
681 // $scope.mostrarTeclado = true; 684 // $scope.mostrarTeclado = true;
682 // return; 685 // return;
683 // } 686 // }
684 // $scope.mostrarTeclado = false; 687 // $scope.mostrarTeclado = false;
685 // }) 688 // })
686 $scope.selectFocus = function($event) { 689 $scope.selectFocus = function($event) {
687 //Si el teclado esta en uso no selecciona el valor 690 //Si el teclado esta en uso no selecciona el valor
688 // if($scope.mostrarTeclado) { 691 // if($scope.mostrarTeclado) {
689 // return; 692 // return;
690 // } 693 // }
691 $event.target.select(); 694 $event.target.select();
692 }; 695 };
693 696
694 $scope.salir = function() { 697 $scope.salir = function() {
695 $location.path('/'); 698 $location.path('/');
696 }; 699 };
697 700
698 $scope.parsearATexto = function(articulo) { 701 $scope.parsearATexto = function(articulo) {
699 articulo.cantidad = parseFloat(articulo.cantidad); 702 articulo.cantidad = parseFloat(articulo.cantidad);
700 articulo.precio = parseFloat(articulo.precio); 703 articulo.precio = parseFloat(articulo.precio);
701 }; 704 };
702 705
703 $scope.quitarFactura = function(key) { 706 $scope.quitarFactura = function(key) {
704 $scope.cobranza.facturas.splice(key, 1); 707 $scope.cobranza.facturas.splice(key, 1);
705 }; 708 };
706 709
707 $scope.quitarCobro = function(key) { 710 $scope.quitarCobro = function(key) {
708 $scope.cobranza.cobros.splice(key, 1); 711 $scope.cobranza.cobros.splice(key, 1);
709 }; 712 };
710 713
711 function salir() { 714 function salir() {
712 var confirmacion = false; 715 var confirmacion = false;
713 716
714 if (!angular.equals($scope.cobranza, $scope.inicial)) { 717 if (!angular.equals($scope.cobranza, $scope.inicial)) {
715 confirmacion = true; 718 confirmacion = true;
716 } 719 }
717 720
718 if (confirmacion) { 721 if (confirmacion) {
719 focaModalService.confirm( 722 focaModalService.confirm(
720 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 723 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
721 ).then(function(data) { 724 ).then(function(data) {
722 if (data) { 725 if (data) {
723 $location.path('/'); 726 $location.path('/');
724 } 727 }
725 }); 728 });
726 } else { 729 } else {
727 $location.path('/'); 730 $location.path('/');
728 } 731 }
729 } 732 }
730 733
731 function setearCobranza(cobranza) { 734 function setearCobranza(cobranza) {
732 $scope.editando = true; 735 $scope.editando = true;
733 $scope.$broadcast('cleanCabecera'); 736 $scope.$broadcast('cleanCabecera');
734 737
735 if (cobranza.cliente) { 738 if (cobranza.cliente) {
736 $scope.$broadcast('addCabecera', { 739 $scope.$broadcast('addCabecera', {
737 label: 'Cliente:', 740 label: 'Cliente:',
738 valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + 741 valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' +
739 cobranza.cliente.NOM 742 cobranza.cliente.NOM
740 }); 743 });
741 } 744 }
742 if (cobranza.cobrador && cobranza.cobrador.NUM) { 745 if (cobranza.cobrador && cobranza.cobrador.NUM) {
743 $scope.$broadcast('addCabecera', { 746 $scope.$broadcast('addCabecera', {
744 label: 'Cobrador:', 747 label: 'Cobrador:',
745 valor: (cobranza.cobrador.NUM) ? 748 valor: (cobranza.cobrador.NUM) ?
746 $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + 749 $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' +
747 cobranza.cobrador.NOM : cobranza.cobrador 750 cobranza.cobrador.NOM : cobranza.cobrador
748 751
749 }); 752 });
750 } 753 }
751 754
752 $scope.cobranza = cobranza; 755 $scope.cobranza = cobranza;
753 } 756 }
754 757
755 function getLSCobranza() { 758 function getLSCobranza() {
756 var cobranza = JSON.parse($localStorage.cobranza || null); 759 var cobranza = JSON.parse($localStorage.cobranza || null);
757 if (cobranza) { 760 if (cobranza) {
758 setearCobranza(cobranza); 761 setearCobranza(cobranza);
759 delete $localStorage.cobranza; 762 delete $localStorage.cobranza;
760 } 763 }
761 } 764 }
762 } 765 }
763 ]); 766 ]);
764 767