Commit 0eae7c6a1501f74865bf6c169fad348553fefc88

Authored by Eric Fernandez
1 parent 25927158cf
Exists in master

método del servicio correcto

Showing 1 changed file with 1 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', 3 '$scope',
4 '$rootScope', 4 '$rootScope',
5 '$timeout', 5 '$timeout',
6 '$uibModal', 6 '$uibModal',
7 '$location', 7 '$location',
8 'focaCrearCobranzaService', 8 'focaCrearCobranzaService',
9 'focaModalService', 9 'focaModalService',
10 '$filter', 10 '$filter',
11 '$cookies', 11 '$cookies',
12 'focaSeguimientoService', 12 'focaSeguimientoService',
13 'focaBotoneraLateralService', 13 'focaBotoneraLateralService',
14 'APP', 14 'APP',
15 'focaLoginService', 15 'focaLoginService',
16 function($scope, $rootScope, $timeout, $uibModal, $location, focaCrearCobranzaService, 16 function($scope, $rootScope, $timeout, $uibModal, $location, focaCrearCobranzaService,
17 focaModalService, $filter, $cookies, focaSeguimientoService, 17 focaModalService, $filter, $cookies, focaSeguimientoService,
18 focaBotoneraLateralService, APP, loginService) 18 focaBotoneraLateralService, APP, loginService)
19 { 19 {
20 20
21 if(APP === 'cobranza') { 21 if(APP === 'cobranza') {
22 var idCobrador = loginService.getLoginData().vendedorCobrador; 22 var idCobrador = loginService.getLoginData().vendedorCobrador;
23 $scope.botonera = focaCrearCobranzaService.getBotonera(idCobrador); 23 $scope.botonera = focaCrearCobranzaService.getBotonera(idCobrador);
24 focaCrearCobranzaService.getVendedorById(idCobrador).then( 24 focaCrearCobranzaService.getCobradorById(idCobrador).then(
25 function(res) { 25 function(res) {
26 var cobrador = res.data; 26 var cobrador = res.data;
27 $scope.$broadcast('addCabecera', { 27 $scope.$broadcast('addCabecera', {
28 label: 'Cobrador:', 28 label: 'Cobrador:',
29 valor: cobrador.NomVen 29 valor: cobrador.NomVen
30 }); 30 });
31 $scope.cobranza.cobrador = cobrador; 31 $scope.cobranza.cobrador = cobrador;
32 } 32 }
33 ); 33 );
34 }else { 34 }else {
35 $scope.botonera = focaCrearCobranzaService.getBotonera(); 35 $scope.botonera = focaCrearCobranzaService.getBotonera();
36 } 36 }
37 $scope.datepickerAbierto = false; 37 $scope.datepickerAbierto = false;
38 $scope.cobroDeuda = true; 38 $scope.cobroDeuda = true;
39 $scope.show = false; 39 $scope.show = false;
40 $scope.cargando = true; 40 $scope.cargando = true;
41 $scope.dateOptions = { 41 $scope.dateOptions = {
42 maxDate: new Date(), 42 maxDate: new Date(),
43 minDate: new Date(2010, 0, 1) 43 minDate: new Date(2010, 0, 1)
44 }; 44 };
45 45
46 $scope.cobranza = {}; 46 $scope.cobranza = {};
47 47
48 $scope.fecha = new Date(); 48 $scope.fecha = new Date();
49 $scope.puntoVenta = '0000'; 49 $scope.puntoVenta = '0000';
50 $scope.comprobante = '00000000'; 50 $scope.comprobante = '00000000';
51 $scope.facturaTabla = []; 51 $scope.facturaTabla = [];
52 $scope.cobrosTabla = []; 52 $scope.cobrosTabla = [];
53 53
54 focaCrearCobranzaService.getUsuario($cookies.get('idUsuario')).then(function(data) { 54 focaCrearCobranzaService.getUsuario($cookies.get('idUsuario')).then(function(data) {
55 $scope.usuario = data.data; 55 $scope.usuario = data.data;
56 }); 56 });
57 57
58 $timeout(function() { 58 $timeout(function() {
59 focaBotoneraLateralService.showSalir(false); 59 focaBotoneraLateralService.showSalir(false);
60 focaBotoneraLateralService.showPausar(true); 60 focaBotoneraLateralService.showPausar(true);
61 focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); 61 focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza);
62 focaBotoneraLateralService.addCustomButton('Salir', salir); 62 focaBotoneraLateralService.addCustomButton('Salir', salir);
63 }); 63 });
64 64
65 $scope.crearCobranza = function() { 65 $scope.crearCobranza = function() {
66 if(!$scope.cobranza.cliente) { 66 if(!$scope.cobranza.cliente) {
67 focaModalService.alert('Ingrese Cliente'); 67 focaModalService.alert('Ingrese Cliente');
68 return; 68 return;
69 } 69 }
70 if(!$scope.cobranza.cobrador) { 70 if(!$scope.cobranza.cobrador) {
71 focaModalService.alert('Ingrese Cobrador'); 71 focaModalService.alert('Ingrese Cobrador');
72 return; 72 return;
73 } 73 }
74 if($scope.facturaTabla.length < 1) { 74 if($scope.facturaTabla.length < 1) {
75 focaModalService.alert('Ingrese al menos una factura'); 75 focaModalService.alert('Ingrese al menos una factura');
76 return; 76 return;
77 } 77 }
78 if($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { 78 if($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) {
79 focaModalService.alert('La diferencia debe ser ' + 79 focaModalService.alert('La diferencia debe ser ' +
80 $scope.cobranza.moneda.SIMBOLO + '0,00'); 80 $scope.cobranza.moneda.SIMBOLO + '0,00');
81 return; 81 return;
82 } 82 }
83 var cobranza = {}; 83 var cobranza = {};
84 var cheques = []; 84 var cheques = [];
85 var cuerpos = []; 85 var cuerpos = [];
86 //TODO: habilitar edición 86 //TODO: habilitar edición
87 $scope.editando = false; 87 $scope.editando = false;
88 focaBotoneraLateralService.startGuardar(); 88 focaBotoneraLateralService.startGuardar();
89 $scope.saveLoading = true; 89 $scope.saveLoading = true;
90 for(var i = 0; i < $scope.facturaTabla.length; i++) { 90 for(var i = 0; i < $scope.facturaTabla.length; i++) {
91 var cuerpoFactura = { 91 var cuerpoFactura = {
92 CYV: 'V', 92 CYV: 'V',
93 TIP: 'C', 93 TIP: 'C',
94 TCO: 'RC', 94 TCO: 'RC',
95 PVE: $scope.puntoVenta, 95 PVE: $scope.puntoVenta,
96 NCO: $scope.comprobante, 96 NCO: $scope.comprobante,
97 LOP: 'L', 97 LOP: 'L',
98 TIL: $scope.facturaTabla[i].TCO, 98 TIL: $scope.facturaTabla[i].TCO,
99 COM: $scope.facturaTabla[i].numeroFactura + '-' + 99 COM: $scope.facturaTabla[i].numeroFactura + '-' +
100 $scope.rellenar($scope.facturaTabla[i].NCU,2), 100 $scope.rellenar($scope.facturaTabla[i].NCU,2),
101 FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), 101 FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '),
102 IMP: Math.abs($scope.facturaTabla[i].IPA), 102 IMP: Math.abs($scope.facturaTabla[i].IPA),
103 RES: 0,//caja de tesorería 103 RES: 0,//caja de tesorería
104 SUBM: 0 104 SUBM: 0
105 }; 105 };
106 cuerpos.push(cuerpoFactura); 106 cuerpos.push(cuerpoFactura);
107 } 107 }
108 108
109 for (var j = 0; j < $scope.cobrosTabla.length; j++) { 109 for (var j = 0; j < $scope.cobrosTabla.length; j++) {
110 110
111 var efectivo = $scope.cobrosTabla[j].tipo === 'Efectivo' ? true : false; 111 var efectivo = $scope.cobrosTabla[j].tipo === 'Efectivo' ? true : false;
112 112
113 var cuerpoCobros = { 113 var cuerpoCobros = {
114 CYV: 'V', 114 CYV: 'V',
115 TIP: 'C', 115 TIP: 'C',
116 TCO: 'RC', 116 TCO: 'RC',
117 PVE: $scope.puntoVenta, 117 PVE: $scope.puntoVenta,
118 NCO: $scope.comprobante, 118 NCO: $scope.comprobante,
119 LOP: 'P', 119 LOP: 'P',
120 TIL: 'EF', 120 TIL: 'EF',
121 COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : 'ch(' + 121 COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : 'ch(' +
122 $scope.cobrosTabla[j].numero + ')' + $scope.cobrosTabla[j].banco.desbco, 122 $scope.cobrosTabla[j].numero + ')' + $scope.cobrosTabla[j].banco.desbco,
123 FEC: efectivo ? 123 FEC: efectivo ?
124 $scope.cobrosTabla[j].fecha 124 $scope.cobrosTabla[j].fecha
125 .toISOString().slice(0, 19).replace('T', ' ') : 125 .toISOString().slice(0, 19).replace('T', ' ') :
126 $scope.cobrosTabla[j].fechaPresentacion 126 $scope.cobrosTabla[j].fechaPresentacion
127 .toISOString().slice(0, 19).replace('T', ' '), 127 .toISOString().slice(0, 19).replace('T', ' '),
128 IMP: Math.abs($scope.cobrosTabla[j].importe), 128 IMP: Math.abs($scope.cobrosTabla[j].importe),
129 RES: 0,//caja de tesorería 129 RES: 0,//caja de tesorería
130 SUBM: 0 130 SUBM: 0
131 }; 131 };
132 cuerpos.push(cuerpoCobros); 132 cuerpos.push(cuerpoCobros);
133 133
134 if(!efectivo) { 134 if(!efectivo) {
135 var cheque = { 135 var cheque = {
136 BCO: $scope.cobrosTabla[j].banco.ID, 136 BCO: $scope.cobrosTabla[j].banco.ID,
137 NUM: $scope.comprobante, 137 NUM: $scope.comprobante,
138 FEP: $scope.cobrosTabla[j].fechaPresentacion 138 FEP: $scope.cobrosTabla[j].fechaPresentacion
139 .toISOString().slice(0, 19).replace('T', ' '), 139 .toISOString().slice(0, 19).replace('T', ' '),
140 FEE: $scope.cobrosTabla[j].fechaEmision 140 FEE: $scope.cobrosTabla[j].fechaEmision
141 .toISOString().slice(0, 19).replace('T', ' '), 141 .toISOString().slice(0, 19).replace('T', ' '),
142 LUG: $scope.cobrosTabla[j].localidad.NOMBRE, 142 LUG: $scope.cobrosTabla[j].localidad.NOMBRE,
143 IMP: $scope.cobrosTabla[j].importe, 143 IMP: $scope.cobrosTabla[j].importe,
144 LIB: $scope.cobrosTabla[j].librador, 144 LIB: $scope.cobrosTabla[j].librador,
145 EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera 145 EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera
146 PCI: $scope.cobrosTabla[j].provincia.ID, 146 PCI: $scope.cobrosTabla[j].provincia.ID,
147 LPLA: 0, 147 LPLA: 0,
148 PLA: 0, 148 PLA: 0,
149 VEN: $scope.usuario.CodVen,//Id vendedor 149 VEN: $scope.usuario.CodVen,//Id vendedor
150 CCLIE: $scope.cobranza.cliente.COD,//Id cliente 150 CCLIE: $scope.cobranza.cliente.COD,//Id cliente
151 REN: 0, 151 REN: 0,
152 PVEC: $scope.puntoVenta, 152 PVEC: $scope.puntoVenta,
153 NCOC: $scope.comprobante, 153 NCOC: $scope.comprobante,
154 OBSE: $scope.cobrosTabla[j].observaciones, 154 OBSE: $scope.cobrosTabla[j].observaciones,
155 LUV: 0, 155 LUV: 0,
156 ORI: 've', 156 ORI: 've',
157 FER: '', 157 FER: '',
158 BIMP: 0, 158 BIMP: 0,
159 COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, 159 COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante,
160 VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso 160 VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso
161 VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso 161 VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso
162 REC_CAJ: 'D', 162 REC_CAJ: 'D',
163 TIPO_C: 0,//?? 163 TIPO_C: 0,//??
164 SALDO_CAJ: 'S', 164 SALDO_CAJ: 'S',
165 FECHA_INGRESO: $scope.fecha 165 FECHA_INGRESO: $scope.fecha
166 .toISOString().slice(0, 19).replace('T', ' '), 166 .toISOString().slice(0, 19).replace('T', ' '),
167 Vendedor_valor: 0, 167 Vendedor_valor: 0,
168 FAMILIA: 0, 168 FAMILIA: 0,
169 CUIT_LIB: '', 169 CUIT_LIB: '',
170 COD_LUG: $scope.cobrosTabla[j].localidad.ID,//código lugar 170 COD_LUG: $scope.cobrosTabla[j].localidad.ID,//código lugar
171 SEN: '', 171 SEN: '',
172 NRC: 0, 172 NRC: 0,
173 COD_LARGO: '', 173 COD_LARGO: '',
174 VN: 0, 174 VN: 0,
175 ID_LECTOR: 0, 175 ID_LECTOR: 0,
176 NATHB: '' 176 NATHB: ''
177 }; 177 };
178 cheques.push(cheque); 178 cheques.push(cheque);
179 } 179 }
180 } 180 }
181 181
182 cobranza = { 182 cobranza = {
183 recibo: { 183 recibo: {
184 CYV: 'V', 184 CYV: 'V',
185 TIP: 'C', 185 TIP: 'C',
186 TCO: 'RC', 186 TCO: 'RC',
187 PVE: $scope.puntoVenta, //Sucursar, punto de venta 187 PVE: $scope.puntoVenta, //Sucursar, punto de venta
188 NCO: $scope.comprobante, //Numero de comprobante 188 NCO: $scope.comprobante, //Numero de comprobante
189 FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), 189 FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '),
190 CLI: $scope.cobranza.cliente.COD, 190 CLI: $scope.cobranza.cliente.COD,
191 ATO: 0, //número de asiento 191 ATO: 0, //número de asiento
192 CFE: $scope.cobranza.cobrador.NomVen, 192 CFE: $scope.cobranza.cobrador.NomVen,
193 PLA: '',//Numero de planilla, sin uso 193 PLA: '',//Numero de planilla, sin uso
194 ID_MONEDA: $scope.cobranza.moneda.ID, 194 ID_MONEDA: $scope.cobranza.moneda.ID,
195 COTIZACION: $scope.cobranza.cotizacion.VENDEDOR, 195 COTIZACION: $scope.cobranza.cotizacion.VENDEDOR,
196 idCobrador: $scope.cobranza.cobrador.CodVen 196 idCobrador: $scope.cobranza.cobrador.CodVen
197 }, 197 },
198 cuerpo: cuerpos, 198 cuerpo: cuerpos,
199 cheques: cheques, 199 cheques: cheques,
200 acobypag: { 200 acobypag: {
201 CYV: 'V', 201 CYV: 'V',
202 COD: $scope.cobranza.cliente.COD, 202 COD: $scope.cobranza.cliente.COD,
203 FEP: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), 203 FEP: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '),
204 TIP: 'C', 204 TIP: 'C',
205 TCO: 'RC', 205 TCO: 'RC',
206 SUC: $scope.puntoVenta, 206 SUC: $scope.puntoVenta,
207 NCO: $scope.comprobante, 207 NCO: $scope.comprobante,
208 IPA: $scope.getTotalCobrado(), 208 IPA: $scope.getTotalCobrado(),
209 SAL: '',//?? 209 SAL: '',//??
210 TCA: 1, 210 TCA: 1,
211 ZONA: 1, 211 ZONA: 1,
212 FPA: 2,//Forma de pago 212 FPA: 2,//Forma de pago
213 REC: 0, 213 REC: 0,
214 REP: 0, 214 REP: 0,
215 FER: null, 215 FER: null,
216 REM: 0, 216 REM: 0,
217 FRE: null,//?? 217 FRE: null,//??
218 PRO: 'N', 218 PRO: 'N',
219 FEV: $scope.fecha.toISOString().slice(0, 19).replace('T', ' ') 219 FEV: $scope.fecha.toISOString().slice(0, 19).replace('T', ' ')
220 }, 220 },
221 datosCobrador: { 221 datosCobrador: {
222 COD: $scope.cobranza.cobrador.CodVen, 222 COD: $scope.cobranza.cobrador.CodVen,
223 PVE: $scope.puntoVenta, 223 PVE: $scope.puntoVenta,
224 NUM: $scope.comprobante, 224 NUM: $scope.comprobante,
225 EST: 'C', 225 EST: 'C',
226 OBS: 'RC: ' + $scope.comprobante + '-' + $scope.fecha.toLocaleDateString(), 226 OBS: 'RC: ' + $scope.comprobante + '-' + $scope.fecha.toLocaleDateString(),
227 DAT1: 'C', 227 DAT1: 'C',
228 CLI: $scope.cobranza.cliente.COD 228 CLI: $scope.cobranza.cliente.COD
229 } 229 }
230 }; 230 };
231 focaCrearCobranzaService.guardarCobranza(cobranza).then( 231 focaCrearCobranzaService.guardarCobranza(cobranza).then(
232 function(result) { 232 function(result) {
233 focaBotoneraLateralService.endGuardar(true); 233 focaBotoneraLateralService.endGuardar(true);
234 $scope.saveLoading = false; 234 $scope.saveLoading = false;
235 focaModalService.alert('Cobranza guardada con éxito'); 235 focaModalService.alert('Cobranza guardada con éxito');
236 236
237 focaSeguimientoService.guardarPosicion( 237 focaSeguimientoService.guardarPosicion(
238 result.data.numero, 238 result.data.numero,
239 'Cobranza', 239 'Cobranza',
240 'Nº: ' + $filter('comprobante')([ 240 'Nº: ' + $filter('comprobante')([
241 result.data.sucursal, 241 result.data.sucursal,
242 result.data.numero 242 result.data.numero
243 ]) + '<br/>' + 243 ]) + '<br/>' +
244 'Vendedor: ' + $scope.cobranza.cobrador.NomVen + '<br/>' + 244 'Vendedor: ' + $scope.cobranza.cobrador.NomVen + '<br/>' +
245 'Total: ' + $filter('currency')($scope.getTotalCobrado()), 245 'Total: ' + $filter('currency')($scope.getTotalCobrado()),
246 result.data.sucursal 246 result.data.sucursal
247 ); 247 );
248 248
249 $scope.cobranza = { 249 $scope.cobranza = {
250 fecha: new Date() 250 fecha: new Date()
251 }; 251 };
252 setearMonedaPorDefecto(); 252 setearMonedaPorDefecto();
253 obtenerNumeroComprobante(); 253 obtenerNumeroComprobante();
254 254
255 $scope.$broadcast('cleanCabecera'); 255 $scope.$broadcast('cleanCabecera');
256 $scope.fecha = new Date(); 256 $scope.fecha = new Date();
257 $scope.facturaTabla = []; 257 $scope.facturaTabla = [];
258 $scope.cobrosTabla = []; 258 $scope.cobrosTabla = [];
259 }, function(error) { 259 }, function(error) {
260 focaModalService.alert('Hubo un problema al cargar la cobranza'); 260 focaModalService.alert('Hubo un problema al cargar la cobranza');
261 focaBotoneraLateralService.endGuardar(); 261 focaBotoneraLateralService.endGuardar();
262 $scope.saveLoading = false; 262 $scope.saveLoading = false;
263 console.info(error); 263 console.info(error);
264 } 264 }
265 ); 265 );
266 }; 266 };
267 267
268 $scope.seleccionarCobros = function() { 268 $scope.seleccionarCobros = function() {
269 $scope.cobroDeuda = false; 269 $scope.cobroDeuda = false;
270 }; 270 };
271 271
272 $scope.seleccionarComprobantes = function() { 272 $scope.seleccionarComprobantes = function() {
273 $scope.cobroDeuda = true; 273 $scope.cobroDeuda = true;
274 }; 274 };
275 275
276 $scope.seleccionarCobranza = function() { 276 $scope.seleccionarCobranza = function() {
277 277
278 var modalInstance = $uibModal.open( 278 var modalInstance = $uibModal.open(
279 { 279 {
280 ariaLabelledBy: 'Busqueda de Cobranzas', 280 ariaLabelledBy: 'Busqueda de Cobranzas',
281 templateUrl: 'foca-modal-cobranza.html', 281 templateUrl: 'foca-modal-cobranza.html',
282 controller: 'focaModalCobranzaController', 282 controller: 'focaModalCobranzaController',
283 size: 'lg' 283 size: 'lg'
284 } 284 }
285 ); 285 );
286 modalInstance.result.then(function(cobranza) { 286 modalInstance.result.then(function(cobranza) {
287 $scope.editando = true; 287 $scope.editando = true;
288 $scope.facturaTabla = []; 288 $scope.facturaTabla = [];
289 $scope.cobrosTabla = []; 289 $scope.cobrosTabla = [];
290 $scope.$broadcast('cleanCabecera'); 290 $scope.$broadcast('cleanCabecera');
291 291
292 $scope.fecha = new Date(cobranza.fecha); 292 $scope.fecha = new Date(cobranza.fecha);
293 293
294 $scope.$broadcast('addCabecera', { 294 $scope.$broadcast('addCabecera', {
295 label: 'Cliente:', 295 label: 'Cliente:',
296 valor: cobranza.cliente.NOM 296 valor: cobranza.cliente.NOM
297 }); 297 });
298 $scope.$broadcast('addCabecera', { 298 $scope.$broadcast('addCabecera', {
299 label: 'Cobrador:', 299 label: 'Cobrador:',
300 valor: cobranza.cobrador 300 valor: cobranza.cobrador
301 }); 301 });
302 302
303 $scope.facturaTabla = cobranza.facturas; 303 $scope.facturaTabla = cobranza.facturas;
304 $scope.cobrosTabla = cobranza.cobros; 304 $scope.cobrosTabla = cobranza.cobros;
305 }); 305 });
306 }; 306 };
307 307
308 $scope.seleccionarCliente = function() { 308 $scope.seleccionarCliente = function() {
309 309
310 var modalInstance = $uibModal.open( 310 var modalInstance = $uibModal.open(
311 { 311 {
312 ariaLabelledBy: 'Busqueda de Cliente', 312 ariaLabelledBy: 'Busqueda de Cliente',
313 templateUrl: 'foca-busqueda-cliente-modal.html', 313 templateUrl: 'foca-busqueda-cliente-modal.html',
314 controller: 'focaBusquedaClienteModalController', 314 controller: 'focaBusquedaClienteModalController',
315 size: 'lg' 315 size: 'lg'
316 } 316 }
317 ); 317 );
318 modalInstance.result.then( 318 modalInstance.result.then(
319 function(cliente) { 319 function(cliente) {
320 $scope.$broadcast('addCabecera', { 320 $scope.$broadcast('addCabecera', {
321 label: 'Cliente:', 321 label: 'Cliente:',
322 valor: cliente.nom 322 valor: cliente.nom
323 }); 323 });
324 $scope.cobranza.cliente = { 324 $scope.cobranza.cliente = {
325 COD: cliente.cod, 325 COD: cliente.cod,
326 CUIT: cliente.cuit, 326 CUIT: cliente.cuit,
327 NOM: cliente.nom 327 NOM: cliente.nom
328 }; 328 };
329 }, function() { 329 }, function() {
330 330
331 } 331 }
332 ); 332 );
333 }; 333 };
334 334
335 $scope.seleccionarFactura = function() { 335 $scope.seleccionarFactura = function() {
336 if(!$scope.cobranza.cliente) { 336 if(!$scope.cobranza.cliente) {
337 focaModalService.alert('Seleccione primero un cliente'); 337 focaModalService.alert('Seleccione primero un cliente');
338 return; 338 return;
339 } 339 }
340 var modalInstance = $uibModal.open( 340 var modalInstance = $uibModal.open(
341 { 341 {
342 ariaLabelledBy: 'Busqueda de Facturas', 342 ariaLabelledBy: 'Busqueda de Facturas',
343 templateUrl: 'foca-modal-factura.html', 343 templateUrl: 'foca-modal-factura.html',
344 controller: 'focaModalFacturaController', 344 controller: 'focaModalFacturaController',
345 size: 'lg', 345 size: 'lg',
346 resolve: { 346 resolve: {
347 parametrosFactura: function() { 347 parametrosFactura: function() {
348 return { 348 return {
349 cliente: $scope.cobranza.cliente, 349 cliente: $scope.cobranza.cliente,
350 simbolo: $scope.cobranza.moneda.SIMBOLO, 350 simbolo: $scope.cobranza.moneda.SIMBOLO,
351 cotizacion: $scope.cobranza.cotizacion.VENDEDOR, 351 cotizacion: $scope.cobranza.cotizacion.VENDEDOR,
352 moneda: $scope.cobranza.moneda.ID 352 moneda: $scope.cobranza.moneda.ID
353 }; 353 };
354 } 354 }
355 } 355 }
356 } 356 }
357 ); 357 );
358 modalInstance.result.then( 358 modalInstance.result.then(
359 function(facturas) { 359 function(facturas) {
360 $scope.facturaTabla = $scope.facturaTabla.concat(facturas); 360 $scope.facturaTabla = $scope.facturaTabla.concat(facturas);
361 }, function() { 361 }, function() {
362 362
363 } 363 }
364 ); 364 );
365 }; 365 };
366 366
367 $scope.seleccionarCheque = function() { 367 $scope.seleccionarCheque = function() {
368 var modalInstance = $uibModal.open( 368 var modalInstance = $uibModal.open(
369 { 369 {
370 ariaLabelledBy: 'Carga de cheques', 370 ariaLabelledBy: 'Carga de cheques',
371 templateUrl: 'modal-cheque.html', 371 templateUrl: 'modal-cheque.html',
372 controller: 'focaModalChequeController', 372 controller: 'focaModalChequeController',
373 size: 'lg', 373 size: 'lg',
374 resolve: { 374 resolve: {
375 sugerido: function() { 375 sugerido: function() {
376 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 376 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
377 return sugerido < 0 ? sugerido : null; 377 return sugerido < 0 ? sugerido : null;
378 } 378 }
379 } 379 }
380 } 380 }
381 ); 381 );
382 modalInstance.result.then( 382 modalInstance.result.then(
383 function(cheque) { 383 function(cheque) {
384 var cobro = { 384 var cobro = {
385 tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, 385 tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
386 numero: cheque.numero, 386 numero: cheque.numero,
387 banco: cheque.banco, 387 banco: cheque.banco,
388 fecha: cheque.fechaEmision.toLocaleDateString() + '-' + 388 fecha: cheque.fechaEmision.toLocaleDateString() + '-' +
389 cheque.fechaPresentacion.toLocaleDateString(), 389 cheque.fechaPresentacion.toLocaleDateString(),
390 fechaPresentacion: cheque.fechaPresentacion, 390 fechaPresentacion: cheque.fechaPresentacion,
391 fechaEmision: cheque.fechaEmision, 391 fechaEmision: cheque.fechaEmision,
392 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, 392 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR,
393 localidad: cheque.localidad, 393 localidad: cheque.localidad,
394 librador: cheque.librador, 394 librador: cheque.librador,
395 provincia: cheque.provincia, 395 provincia: cheque.provincia,
396 observaciones: cheque.observaciones 396 observaciones: cheque.observaciones
397 }; 397 };
398 $scope.cobrosTabla.push(cobro); 398 $scope.cobrosTabla.push(cobro);
399 }, function() { 399 }, function() {
400 400
401 } 401 }
402 ); 402 );
403 }; 403 };
404 404
405 $scope.seleccionarEfectivo = function() { 405 $scope.seleccionarEfectivo = function() {
406 var modalInstance = $uibModal.open( 406 var modalInstance = $uibModal.open(
407 { 407 {
408 ariaLabelledBy: 'Carga de cheques', 408 ariaLabelledBy: 'Carga de cheques',
409 templateUrl: 'modal-efectivo.html', 409 templateUrl: 'modal-efectivo.html',
410 controller: 'focaModalEfectivoController', 410 controller: 'focaModalEfectivoController',
411 size: 'sm', 411 size: 'sm',
412 resolve: { 412 resolve: {
413 sugerido: function() { 413 sugerido: function() {
414 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 414 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
415 return sugerido < 0 ? sugerido : null; 415 return sugerido < 0 ? sugerido : null;
416 } 416 }
417 } 417 }
418 } 418 }
419 ); 419 );
420 modalInstance.result.then( 420 modalInstance.result.then(
421 function(efectivo) { 421 function(efectivo) {
422 var cobro = { 422 var cobro = {
423 tipo: 'Efectivo', 423 tipo: 'Efectivo',
424 fecha: new Date(), 424 fecha: new Date(),
425 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR 425 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR
426 }; 426 };
427 $scope.cobrosTabla = $scope.cobrosTabla.filter(function(a) { 427 $scope.cobrosTabla = $scope.cobrosTabla.filter(function(a) {
428 return a.tipo !== 'Efectivo'; 428 return a.tipo !== 'Efectivo';
429 }); 429 });
430 $scope.cobrosTabla.push(cobro); 430 $scope.cobrosTabla.push(cobro);
431 }, function() { 431 }, function() {
432 432
433 } 433 }
434 ); 434 );
435 }; 435 };
436 436
437 $scope.seleccionarMoneda = function() { 437 $scope.seleccionarMoneda = function() {
438 var modalInstance = $uibModal.open( 438 var modalInstance = $uibModal.open(
439 { 439 {
440 ariaLabelledBy: 'Busqueda de Moneda', 440 ariaLabelledBy: 'Busqueda de Moneda',
441 templateUrl: 'modal-moneda.html', 441 templateUrl: 'modal-moneda.html',
442 controller: 'focaModalMonedaController', 442 controller: 'focaModalMonedaController',
443 size: 'lg' 443 size: 'lg'
444 } 444 }
445 ); 445 );
446 modalInstance.result.then( 446 modalInstance.result.then(
447 function(moneda) { 447 function(moneda) {
448 $scope.seleccionarCotizacion(moneda); 448 $scope.seleccionarCotizacion(moneda);
449 }, function() { 449 }, function() {
450 450
451 } 451 }
452 ); 452 );
453 }; 453 };
454 454
455 $scope.seleccionarCotizacion = function(moneda) { 455 $scope.seleccionarCotizacion = function(moneda) {
456 var modalInstance = $uibModal.open( 456 var modalInstance = $uibModal.open(
457 { 457 {
458 ariaLabelledBy: 'Busqueda de Cotización', 458 ariaLabelledBy: 'Busqueda de Cotización',
459 templateUrl: 'modal-cotizacion.html', 459 templateUrl: 'modal-cotizacion.html',
460 controller: 'focaModalCotizacionController', 460 controller: 'focaModalCotizacionController',
461 size: 'lg', 461 size: 'lg',
462 resolve: {idMoneda: function() {return moneda.ID;}} 462 resolve: {idMoneda: function() {return moneda.ID;}}
463 } 463 }
464 ); 464 );
465 modalInstance.result.then( 465 modalInstance.result.then(
466 function(cotizacion) { 466 function(cotizacion) {
467 $scope.cobranza.moneda = moneda; 467 $scope.cobranza.moneda = moneda;
468 $scope.cobranza.cotizacion = cotizacion; 468 $scope.cobranza.cotizacion = cotizacion;
469 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 469 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
470 $scope.$broadcast('removeCabecera', 'Moneda:'); 470 $scope.$broadcast('removeCabecera', 'Moneda:');
471 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 471 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
472 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 472 $scope.$broadcast('removeCabecera', 'Cotizacion:');
473 }else { 473 }else {
474 $scope.$broadcast('addCabecera', { 474 $scope.$broadcast('addCabecera', {
475 label: 'Moneda:', 475 label: 'Moneda:',
476 valor: moneda.DETALLE 476 valor: moneda.DETALLE
477 }); 477 });
478 $scope.$broadcast('addCabecera', { 478 $scope.$broadcast('addCabecera', {
479 label: 'Fecha cotizacion:', 479 label: 'Fecha cotizacion:',
480 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 480 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
481 }); 481 });
482 $scope.$broadcast('addCabecera', { 482 $scope.$broadcast('addCabecera', {
483 label: 'Cotizacion:', 483 label: 'Cotizacion:',
484 valor: $filter('number')(cotizacion.VENDEDOR, '2') 484 valor: $filter('number')(cotizacion.VENDEDOR, '2')
485 }); 485 });
486 } 486 }
487 }, function() { 487 }, function() {
488 488
489 } 489 }
490 ); 490 );
491 }; 491 };
492 492
493 $scope.seleccionarCobrador = function() { 493 $scope.seleccionarCobrador = function() {
494 var modalInstance = $uibModal.open( 494 var modalInstance = $uibModal.open(
495 { 495 {
496 ariaLabelledBy: 'Busqueda de Cobradores', 496 ariaLabelledBy: 'Busqueda de Cobradores',
497 templateUrl: 'modal-cobradores.html', 497 templateUrl: 'modal-cobradores.html',
498 controller: 'focaModalCobradoresController', 498 controller: 'focaModalCobradoresController',
499 size: 'lg' 499 size: 'lg'
500 } 500 }
501 ); 501 );
502 modalInstance.result.then( 502 modalInstance.result.then(
503 function(cobrador) { 503 function(cobrador) {
504 $scope.$broadcast('addCabecera', { 504 $scope.$broadcast('addCabecera', {
505 label: 'Cobrador:', 505 label: 'Cobrador:',
506 valor: cobrador.NomVen 506 valor: cobrador.NomVen
507 }); 507 });
508 $scope.cobranza.cobrador = cobrador; 508 $scope.cobranza.cobrador = cobrador;
509 }, function() { 509 }, function() {
510 510
511 } 511 }
512 ); 512 );
513 }; 513 };
514 514
515 $scope.getTotalDeuda = function() { 515 $scope.getTotalDeuda = function() {
516 var total = 0; 516 var total = 0;
517 for (var i = 0; i < $scope.facturaTabla.length; i++) { 517 for (var i = 0; i < $scope.facturaTabla.length; i++) {
518 total += $scope.facturaTabla[i].IPA; 518 total += $scope.facturaTabla[i].IPA;
519 } 519 }
520 return parseFloat(total.toFixed(2)); 520 return parseFloat(total.toFixed(2));
521 }; 521 };
522 522
523 $scope.getTotalCobrado = function() { 523 $scope.getTotalCobrado = function() {
524 var total = 0; 524 var total = 0;
525 for (var i = 0; i < $scope.cobrosTabla.length; i++) { 525 for (var i = 0; i < $scope.cobrosTabla.length; i++) {
526 total += $scope.cobrosTabla[i].importe; 526 total += $scope.cobrosTabla[i].importe;
527 } 527 }
528 return parseFloat(total.toFixed(2)); 528 return parseFloat(total.toFixed(2));
529 }; 529 };
530 530
531 $scope.getSubTotal = function() { 531 $scope.getSubTotal = function() {
532 if($scope.articuloACargar) { 532 if($scope.articuloACargar) {
533 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 533 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
534 } 534 }
535 }; 535 };
536 //Recibe aviso si el teclado está en uso 536 //Recibe aviso si el teclado está en uso
537 // $rootScope.$on('usarTeclado', function(event, data) { 537 // $rootScope.$on('usarTeclado', function(event, data) {
538 // if(data) { 538 // if(data) {
539 // $scope.mostrarTeclado = true; 539 // $scope.mostrarTeclado = true;
540 // return; 540 // return;
541 // } 541 // }
542 // $scope.mostrarTeclado = false; 542 // $scope.mostrarTeclado = false;
543 // }) 543 // })
544 $scope.selectFocus = function($event) { 544 $scope.selectFocus = function($event) {
545 //Si el teclado esta en uso no selecciona el valor 545 //Si el teclado esta en uso no selecciona el valor
546 // if($scope.mostrarTeclado) { 546 // if($scope.mostrarTeclado) {
547 // return; 547 // return;
548 // } 548 // }
549 $event.target.select(); 549 $event.target.select();
550 }; 550 };
551 551
552 $scope.salir = function() { 552 $scope.salir = function() {
553 $location.path('/'); 553 $location.path('/');
554 }; 554 };
555 555
556 $scope.parsearATexto = function(articulo) { 556 $scope.parsearATexto = function(articulo) {
557 articulo.cantidad = parseFloat(articulo.cantidad); 557 articulo.cantidad = parseFloat(articulo.cantidad);
558 articulo.precio = parseFloat(articulo.precio); 558 articulo.precio = parseFloat(articulo.precio);
559 }; 559 };
560 560
561 $scope.rellenar = function(relleno, longitud) { 561 $scope.rellenar = function(relleno, longitud) {
562 relleno = '' + relleno; 562 relleno = '' + relleno;
563 while (relleno.length < longitud) { 563 while (relleno.length < longitud) {
564 relleno = '0' + relleno; 564 relleno = '0' + relleno;
565 } 565 }
566 566
567 return relleno; 567 return relleno;
568 }; 568 };
569 569
570 $scope.quitarFactura = function(key) { 570 $scope.quitarFactura = function(key) {
571 $scope.facturaTabla.splice(key, 1); 571 $scope.facturaTabla.splice(key, 1);
572 }; 572 };
573 573
574 $scope.quitarCobro = function(key) { 574 $scope.quitarCobro = function(key) {
575 $scope.cobrosTabla.splice(key, 1); 575 $scope.cobrosTabla.splice(key, 1);
576 }; 576 };
577 577
578 function setearMonedaPorDefecto() { 578 function setearMonedaPorDefecto() {
579 var monedaPorDefecto; 579 var monedaPorDefecto;
580 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 580 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
581 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { 581 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) {
582 monedaPorDefecto = res.data[0]; 582 monedaPorDefecto = res.data[0];
583 $scope.cobranza.moneda = monedaPorDefecto; 583 $scope.cobranza.moneda = monedaPorDefecto;
584 $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0]; 584 $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0];
585 }); 585 });
586 } 586 }
587 587
588 function obtenerNumeroComprobante() { 588 function obtenerNumeroComprobante() {
589 focaCrearCobranzaService.getNumeroRecibo().then( 589 focaCrearCobranzaService.getNumeroRecibo().then(
590 function(res) { 590 function(res) {
591 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); 591 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4);
592 $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8); 592 $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8);
593 }, 593 },
594 function(err) { 594 function(err) {
595 focaModalService.alert('La terminal no esta configurada correctamente'); 595 focaModalService.alert('La terminal no esta configurada correctamente');
596 console.info(err); 596 console.info(err);
597 } 597 }
598 ); 598 );
599 } 599 }
600 600
601 function salir() { 601 function salir() {
602 var cobranza = { 602 var cobranza = {
603 moneda: $scope.cobranza.moneda, 603 moneda: $scope.cobranza.moneda,
604 cotizacion: $scope.cobranza.cotizacion 604 cotizacion: $scope.cobranza.cotizacion
605 }; 605 };
606 if(JSON.stringify($scope.cobranza) !== JSON.stringify(cobranza)) { 606 if(JSON.stringify($scope.cobranza) !== JSON.stringify(cobranza)) {
607 focaModalService 607 focaModalService
608 .confirm('¿Esta seguro de que desea salir? ' + 608 .confirm('¿Esta seguro de que desea salir? ' +
609 'Se perderán todos los datos cargados.') 609 'Se perderán todos los datos cargados.')
610 .then(function(data) { 610 .then(function(data) {
611 if(data) $location.path('/'); 611 if(data) $location.path('/');
612 }); 612 });
613 }else { 613 }else {
614 $location.path('/'); 614 $location.path('/');
615 } 615 }
616 } 616 }
617 obtenerNumeroComprobante(); 617 obtenerNumeroComprobante();
618 setearMonedaPorDefecto(); 618 setearMonedaPorDefecto();
619 } 619 }
620 ]); 620 ]);
621 621