Commit eb24bf2d4306db42c7258084f7c474bbc16518f5

Authored by Jose Pinto
1 parent e10322e079
Exists in master

datos correctos cobrador

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