Commit 773cdbeb3d539d31431a49174e247863b8d8355b

Authored by Jose Pinto
1 parent 0de0110d70
Exists in master

aplico modal mail al guardar

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