Commit 8858004eec03e8ee8a8cd10231a485da0f3b1d2b

Authored by Nicolás Guarnieri
1 parent 0cf3df0ce6
Exists in master

moneda para modal de factura

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