Commit a9397e00029f138600a8b7aa81ad0747463a782e

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master

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