Commit cc1e379f15876b7c324341036456cee7568fe3fe

Authored by Eric Fernandez
1 parent 1aaa68ab6e
Exists in master

fix parametros

Showing 1 changed file with 2 additions and 2 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearCobranza') .controller('cobranzaController', 1 angular.module('focaCrearCobranza') .controller('cobranzaController',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$rootScope', 4 '$rootScope',
5 '$timeout', 5 '$timeout',
6 '$uibModal', 6 '$uibModal',
7 '$location', 7 '$location',
8 'focaCrearCobranzaService', 8 'focaCrearCobranzaService',
9 'focaModalService', 9 'focaModalService',
10 '$cookies',
11 '$filter', 10 '$filter',
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.nombre,
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.id
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.id,
203 PVE: $scope.puntoVenta, 203 PVE: $scope.puntoVenta,
204 NUM: $scope.comprobante, 204 NUM: $scope.comprobante,
205 EST: 'C', 205 EST: 'C',
206 OBS: 'RC: ' + $scope.comprobante + '-' + $scope.fecha.toLocaleDateString(), 206 OBS: 'RC: ' + $scope.comprobante + '-' + $scope.fecha.toLocaleDateString(),
207 DAT1: 'C', 207 DAT1: 'C',
208 CLI: $scope.cobranza.cliente.COD 208 CLI: $scope.cobranza.cliente.COD
209 } 209 }
210 }; 210 };
211 focaCrearCobranzaService.guardarCobranza(cobranza).then( 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.nombre + '<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 286
287 $scope.seleccionarCliente = function() { 287 $scope.seleccionarCliente = function() {
288 288
289 var modalInstance = $uibModal.open( 289 var modalInstance = $uibModal.open(
290 { 290 {
291 ariaLabelledBy: 'Busqueda de Cliente', 291 ariaLabelledBy: 'Busqueda de Cliente',
292 templateUrl: 'foca-busqueda-cliente-modal.html', 292 templateUrl: 'foca-busqueda-cliente-modal.html',
293 controller: 'focaBusquedaClienteModalController', 293 controller: 'focaBusquedaClienteModalController',
294 size: 'lg' 294 size: 'lg'
295 } 295 }
296 ); 296 );
297 modalInstance.result.then( 297 modalInstance.result.then(
298 function(cliente) { 298 function(cliente) {
299 $scope.$broadcast('addCabecera', { 299 $scope.$broadcast('addCabecera', {
300 label: 'Cliente:', 300 label: 'Cliente:',
301 valor: cliente.nom 301 valor: cliente.nom
302 }); 302 });
303 $scope.cobranza.cliente = { 303 $scope.cobranza.cliente = {
304 COD: cliente.cod, 304 COD: cliente.cod,
305 CUIT: cliente.cuit, 305 CUIT: cliente.cuit,
306 NOM: cliente.nom 306 NOM: cliente.nom
307 }; 307 };
308 }, function() { 308 }, function() {
309 309
310 } 310 }
311 ); 311 );
312 }; 312 };
313 313
314 $scope.seleccionarFactura = function() { 314 $scope.seleccionarFactura = function() {
315 if(!$scope.cobranza.cliente) { 315 if(!$scope.cobranza.cliente) {
316 focaModalService.alert('Seleccione primero un cliente'); 316 focaModalService.alert('Seleccione primero un cliente');
317 return; 317 return;
318 } 318 }
319 var modalInstance = $uibModal.open( 319 var modalInstance = $uibModal.open(
320 { 320 {
321 ariaLabelledBy: 'Busqueda de Facturas', 321 ariaLabelledBy: 'Busqueda de Facturas',
322 templateUrl: 'foca-modal-factura.html', 322 templateUrl: 'foca-modal-factura.html',
323 controller: 'focaModalFacturaController', 323 controller: 'focaModalFacturaController',
324 size: 'lg', 324 size: 'lg',
325 resolve: { 325 resolve: {
326 parametrosFactura: function() { 326 parametrosFactura: function() {
327 return { 327 return {
328 cliente: $scope.cobranza.cliente.COD, 328 cliente: $scope.cobranza.cliente.COD,
329 simbolo: $scope.cobranza.moneda.SIMBOLO, 329 simbolo: $scope.cobranza.moneda.SIMBOLO,
330 cotizacion: $scope.cobranza.cotizacion.VENDEDOR, 330 cotizacion: $scope.cobranza.cotizacion.VENDEDOR,
331 moneda: $scope.cobranza.moneda.ID 331 moneda: $scope.cobranza.moneda.ID
332 }; 332 };
333 } 333 }
334 } 334 }
335 } 335 }
336 ); 336 );
337 modalInstance.result.then( 337 modalInstance.result.then(
338 function(facturas) { 338 function(facturas) {
339 $scope.facturaTabla = $scope.facturaTabla.concat(facturas); 339 $scope.facturaTabla = $scope.facturaTabla.concat(facturas);
340 }, function() { 340 }, function() {
341 341
342 } 342 }
343 ); 343 );
344 }; 344 };
345 345
346 $scope.seleccionarCheque = function() { 346 $scope.seleccionarCheque = function() {
347 var modalInstance = $uibModal.open( 347 var modalInstance = $uibModal.open(
348 { 348 {
349 ariaLabelledBy: 'Carga de cheques', 349 ariaLabelledBy: 'Carga de cheques',
350 templateUrl: 'modal-cheque.html', 350 templateUrl: 'modal-cheque.html',
351 controller: 'focaModalChequeController', 351 controller: 'focaModalChequeController',
352 size: 'lg' 352 size: 'lg'
353 } 353 }
354 ); 354 );
355 modalInstance.result.then( 355 modalInstance.result.then(
356 function(cheque) { 356 function(cheque) {
357 var cobro = { 357 var cobro = {
358 tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, 358 tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
359 numero: cheque.numero, 359 numero: cheque.numero,
360 banco: cheque.banco, 360 banco: cheque.banco,
361 fecha: cheque.fechaEmision.toLocaleDateString() + '-' + 361 fecha: cheque.fechaEmision.toLocaleDateString() + '-' +
362 cheque.fechaPresentacion.toLocaleDateString(), 362 cheque.fechaPresentacion.toLocaleDateString(),
363 fechaPresentacion: cheque.fechaPresentacion, 363 fechaPresentacion: cheque.fechaPresentacion,
364 fechaEmision: cheque.fechaEmision, 364 fechaEmision: cheque.fechaEmision,
365 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, 365 importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR,
366 localidad: cheque.localidad, 366 localidad: cheque.localidad,
367 librador: cheque.librador, 367 librador: cheque.librador,
368 provincia: cheque.provincia, 368 provincia: cheque.provincia,
369 observaciones: cheque.observaciones 369 observaciones: cheque.observaciones
370 }; 370 };
371 $scope.cobrosTabla.push(cobro); 371 $scope.cobrosTabla.push(cobro);
372 }, function() { 372 }, function() {
373 373
374 } 374 }
375 ); 375 );
376 }; 376 };
377 377
378 $scope.seleccionarEfectivo = function() { 378 $scope.seleccionarEfectivo = function() {
379 var modalInstance = $uibModal.open( 379 var modalInstance = $uibModal.open(
380 { 380 {
381 ariaLabelledBy: 'Carga de cheques', 381 ariaLabelledBy: 'Carga de cheques',
382 templateUrl: 'modal-efectivo.html', 382 templateUrl: 'modal-efectivo.html',
383 controller: 'focaModalEfectivoController', 383 controller: 'focaModalEfectivoController',
384 size: 'sm', 384 size: 'sm',
385 resolve: { 385 resolve: {
386 sugerido: function() { 386 sugerido: function() {
387 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 387 var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
388 return sugerido < 0 ? sugerido : null ; 388 return sugerido < 0 ? sugerido : null ;
389 } 389 }
390 } 390 }
391 } 391 }
392 ); 392 );
393 modalInstance.result.then( 393 modalInstance.result.then(
394 function(efectivo) { 394 function(efectivo) {
395 var cobro = { 395 var cobro = {
396 tipo: 'Efectivo', 396 tipo: 'Efectivo',
397 fecha: new Date(), 397 fecha: new Date(),
398 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR 398 importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR
399 }; 399 };
400 $scope.cobrosTabla = $scope.cobrosTabla.filter(function(a) { 400 $scope.cobrosTabla = $scope.cobrosTabla.filter(function(a) {
401 return a.tipo !== 'Efectivo'; 401 return a.tipo !== 'Efectivo';
402 }); 402 });
403 $scope.cobrosTabla.push(cobro); 403 $scope.cobrosTabla.push(cobro);
404 }, function() { 404 }, function() {
405 405
406 } 406 }
407 ); 407 );
408 }; 408 };
409 409
410 $scope.seleccionarMoneda = function() { 410 $scope.seleccionarMoneda = function() {
411 var modalInstance = $uibModal.open( 411 var modalInstance = $uibModal.open(
412 { 412 {
413 ariaLabelledBy: 'Busqueda de Moneda', 413 ariaLabelledBy: 'Busqueda de Moneda',
414 templateUrl: 'modal-moneda.html', 414 templateUrl: 'modal-moneda.html',
415 controller: 'focaModalMonedaController', 415 controller: 'focaModalMonedaController',
416 size: 'lg' 416 size: 'lg'
417 } 417 }
418 ); 418 );
419 modalInstance.result.then( 419 modalInstance.result.then(
420 function(moneda) { 420 function(moneda) {
421 $scope.seleccionarCotizacion(moneda); 421 $scope.seleccionarCotizacion(moneda);
422 }, function() { 422 }, function() {
423 423
424 } 424 }
425 ); 425 );
426 }; 426 };
427 427
428 $scope.seleccionarCotizacion = function(moneda) { 428 $scope.seleccionarCotizacion = function(moneda) {
429 var modalInstance = $uibModal.open( 429 var modalInstance = $uibModal.open(
430 { 430 {
431 ariaLabelledBy: 'Busqueda de Cotización', 431 ariaLabelledBy: 'Busqueda de Cotización',
432 templateUrl: 'modal-cotizacion.html', 432 templateUrl: 'modal-cotizacion.html',
433 controller: 'focaModalCotizacionController', 433 controller: 'focaModalCotizacionController',
434 size: 'lg', 434 size: 'lg',
435 resolve: {idMoneda: function() {return moneda.ID;}} 435 resolve: {idMoneda: function() {return moneda.ID;}}
436 } 436 }
437 ); 437 );
438 modalInstance.result.then( 438 modalInstance.result.then(
439 function(cotizacion) { 439 function(cotizacion) {
440 $scope.cobranza.moneda = moneda; 440 $scope.cobranza.moneda = moneda;
441 $scope.cobranza.cotizacion = cotizacion; 441 $scope.cobranza.cotizacion = cotizacion;
442 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 442 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
443 $scope.$broadcast('removeCabecera', 'Moneda:'); 443 $scope.$broadcast('removeCabecera', 'Moneda:');
444 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 444 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
445 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 445 $scope.$broadcast('removeCabecera', 'Cotizacion:');
446 }else { 446 }else {
447 $scope.$broadcast('addCabecera', { 447 $scope.$broadcast('addCabecera', {
448 label: 'Moneda:', 448 label: 'Moneda:',
449 valor: moneda.DETALLE 449 valor: moneda.DETALLE
450 }); 450 });
451 $scope.$broadcast('addCabecera', { 451 $scope.$broadcast('addCabecera', {
452 label: 'Fecha cotizacion:', 452 label: 'Fecha cotizacion:',
453 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 453 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
454 }); 454 });
455 $scope.$broadcast('addCabecera', { 455 $scope.$broadcast('addCabecera', {
456 label: 'Cotizacion:', 456 label: 'Cotizacion:',
457 valor: cotizacion.VENDEDOR 457 valor: cotizacion.VENDEDOR
458 }); 458 });
459 } 459 }
460 }, function() { 460 }, function() {
461 461
462 } 462 }
463 ); 463 );
464 }; 464 };
465 465
466 $scope.seleccionarCobrador = function() { 466 $scope.seleccionarCobrador = function() {
467 var modalInstance = $uibModal.open( 467 var modalInstance = $uibModal.open(
468 { 468 {
469 ariaLabelledBy: 'Busqueda de Cobradores', 469 ariaLabelledBy: 'Busqueda de Cobradores',
470 templateUrl: 'modal-cobradores.html', 470 templateUrl: 'modal-cobradores.html',
471 controller: 'focaModalCobradoresController', 471 controller: 'focaModalCobradoresController',
472 size: 'lg' 472 size: 'lg'
473 } 473 }
474 ); 474 );
475 modalInstance.result.then( 475 modalInstance.result.then(
476 function(cobrador) { 476 function(cobrador) {
477 $scope.$broadcast('addCabecera', { 477 $scope.$broadcast('addCabecera', {
478 label: 'Cobrador:', 478 label: 'Cobrador:',
479 valor: cobrador.nombre 479 valor: cobrador.nombre
480 }); 480 });
481 $scope.cobranza.cobrador = cobrador; 481 $scope.cobranza.cobrador = cobrador;
482 }, function() { 482 }, function() {
483 483
484 } 484 }
485 ); 485 );
486 }; 486 };
487 487
488 $scope.getTotalDeuda = function() { 488 $scope.getTotalDeuda = function() {
489 var total = 0; 489 var total = 0;
490 for (var i = 0; i < $scope.facturaTabla.length; i++) { 490 for (var i = 0; i < $scope.facturaTabla.length; i++) {
491 total += $scope.facturaTabla[i].IPA; 491 total += $scope.facturaTabla[i].IPA;
492 } 492 }
493 return parseFloat(total.toFixed(2)); 493 return parseFloat(total.toFixed(2));
494 }; 494 };
495 495
496 $scope.getTotalCobrado = function() { 496 $scope.getTotalCobrado = function() {
497 var total = 0; 497 var total = 0;
498 for (var i = 0; i < $scope.cobrosTabla.length; i++) { 498 for (var i = 0; i < $scope.cobrosTabla.length; i++) {
499 total += $scope.cobrosTabla[i].importe; 499 total += $scope.cobrosTabla[i].importe;
500 } 500 }
501 return parseFloat(total.toFixed(2)); 501 return parseFloat(total.toFixed(2));
502 }; 502 };
503 503
504 $scope.getSubTotal = function() { 504 $scope.getSubTotal = function() {
505 if($scope.articuloACargar) { 505 if($scope.articuloACargar) {
506 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 506 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
507 } 507 }
508 }; 508 };
509 //Recibe aviso si el teclado está en uso 509 //Recibe aviso si el teclado está en uso
510 // $rootScope.$on('usarTeclado', function(event, data) { 510 // $rootScope.$on('usarTeclado', function(event, data) {
511 // if(data) { 511 // if(data) {
512 // $scope.mostrarTeclado = true; 512 // $scope.mostrarTeclado = true;
513 // return; 513 // return;
514 // } 514 // }
515 // $scope.mostrarTeclado = false; 515 // $scope.mostrarTeclado = false;
516 // }) 516 // })
517 $scope.selectFocus = function($event) { 517 $scope.selectFocus = function($event) {
518 //Si el teclado esta en uso no selecciona el valor 518 //Si el teclado esta en uso no selecciona el valor
519 // if($scope.mostrarTeclado) { 519 // if($scope.mostrarTeclado) {
520 // return; 520 // return;
521 // } 521 // }
522 $event.target.select(); 522 $event.target.select();
523 }; 523 };
524 524
525 $scope.salir = function() { 525 $scope.salir = function() {
526 $location.path('/'); 526 $location.path('/');
527 }; 527 };
528 528
529 $scope.parsearATexto = function(articulo) { 529 $scope.parsearATexto = function(articulo) {
530 articulo.cantidad = parseFloat(articulo.cantidad); 530 articulo.cantidad = parseFloat(articulo.cantidad);
531 articulo.precio = parseFloat(articulo.precio); 531 articulo.precio = parseFloat(articulo.precio);
532 }; 532 };
533 533
534 $scope.rellenar = function(relleno, longitud) { 534 $scope.rellenar = function(relleno, longitud) {
535 relleno = '' + relleno; 535 relleno = '' + relleno;
536 while (relleno.length < longitud) { 536 while (relleno.length < longitud) {
537 relleno = '0' + relleno; 537 relleno = '0' + relleno;
538 } 538 }
539 539
540 return relleno; 540 return relleno;
541 }; 541 };
542 542
543 $scope.quitarFactura = function(key) { 543 $scope.quitarFactura = function(key) {
544 $scope.facturaTabla.splice(key, 1); 544 $scope.facturaTabla.splice(key, 1);
545 }; 545 };
546 546
547 $scope.quitarCobro = function(key) { 547 $scope.quitarCobro = function(key) {
548 $scope.cobrosTabla.splice(key, 1); 548 $scope.cobrosTabla.splice(key, 1);
549 }; 549 };
550 550
551 function setearMonedaPorDefecto() { 551 function setearMonedaPorDefecto() {
552 var monedaPorDefecto; 552 var monedaPorDefecto;
553 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 553 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
554 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { 554 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) {
555 monedaPorDefecto = res.data[0]; 555 monedaPorDefecto = res.data[0];
556 $scope.cobranza.moneda = monedaPorDefecto; 556 $scope.cobranza.moneda = monedaPorDefecto;
557 $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0]; 557 $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0];
558 }); 558 });
559 } 559 }
560 560
561 function obtenerNumeroComprobante() { 561 function obtenerNumeroComprobante() {
562 focaCrearCobranzaService.getNumeroRecibo().then( 562 focaCrearCobranzaService.getNumeroRecibo().then(
563 function(res) { 563 function(res) {
564 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); 564 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4);
565 $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8); 565 $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8);
566 }, 566 },
567 function(err) { 567 function(err) {
568 focaModalService.alert('La terminal no esta configurada correctamente'); 568 focaModalService.alert('La terminal no esta configurada correctamente');
569 console.info(err); 569 console.info(err);
570 } 570 }
571 ); 571 );
572 } 572 }
573 obtenerNumeroComprobante(); 573 obtenerNumeroComprobante();
574 setearMonedaPorDefecto(); 574 setearMonedaPorDefecto();
575 } 575 }
576 ]); 576 ]);