Commit 62ce3773672a85abd82d9b94e08e27a2c84d99c7

Authored by Jose Pinto
1 parent 4770decbd8
Exists in master

espacios

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