Commit 4ba3587f27b839863a4c7065a6b9c8854f0d6b49

Authored by Jose Pinto
1 parent 5df24d63ac
Exists in master

modal prompt, email = true

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