Commit af58d4d5068f8f9dafe89178f66cdce2f4cebc4a

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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