Commit 25cb79b9b6e7e3c309be71aeb6489ecf2bf9eb9f

Authored by Nicolás Guarnieri
1 parent 9d9072f420
Exists in master

agregar cuotas al COM

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