Commit f8d2c78a5328e55f8420d424f2c283e9696f7bc2

Authored by Jose Pinto
1 parent 35e80fb797
Exists in master

si tiene datos cargados, confirmar para salir

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