Commit b6bd36d78a35e9c9de4318e95f7db70277c222e4

Authored by Eric Fernandez
1 parent 5543f68954
Exists in master

guardo posición

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