Commit 2501d30e41ff6f5602fd9bcc856acac13dec94b4

Authored by Jose Pinto
1 parent 632d841531
Exists in master

agrego variable saveLoading

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