Commit db9685cb010066e30a4fae68b041d91f6335bb7d

Authored by Jose Pinto
1 parent 2501d30e41
Exists in master

ok modal cliente

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