luisruiz

Untitled

Jan 31st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import { Component, OnInit, ViewEncapsulation } from '@angular/core';
  2. import { fuseAnimations } from '../../../../core/animations';
  3. import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
  4. import { ControlFacturasService } from '../control-facturas.service';
  5. import { Observable } from 'rxjs/Observable';
  6. import { map, startWith } from 'rxjs/operators';
  7.  
  8. @Component({
  9. selector: 'app-detail-factura',
  10. templateUrl: './detail-factura.component.html',
  11. styleUrls: ['./detail-factura.component.scss'],
  12. animations: fuseAnimations,
  13. encapsulation: ViewEncapsulation.None
  14.  
  15. })
  16. export class DetailFacturaComponent implements OnInit {
  17. proveedores;
  18.  
  19. optionsRut: any;
  20.  
  21.  
  22.  
  23. subCuentas: any[];
  24. cuentas;
  25. rutCtrl: FormControl = new FormControl();
  26. controlFactura: FormGroup;
  27.  
  28.  
  29. tipoDocumentos;
  30.  
  31. filteredOptionsRut: Observable<string[]>;
  32.  
  33.  
  34. constructor(private formBuilder: FormBuilder, private controlFacturaService: ControlFacturasService) {
  35.  
  36. this.controlFactura = this.createContactForm();
  37.  
  38. Promise.all([
  39. this.controlFacturaService.getTipoDocumentos().take(1).toPromise(),
  40. this.controlFacturaService.getCuentas().take(1).toPromise(),
  41. this.controlFacturaService.getProveedores().take(1).toPromise()
  42.  
  43. ]).then((res: any[]) => {
  44.  
  45.  
  46. Observable.forkJoin([
  47. res[0],
  48. res[1],
  49. res[2],
  50. ])
  51. .subscribe((response) => {
  52. this.tipoDocumentos = response[0];
  53. this.cuentas = response[1];
  54. this.proveedores = response[2];
  55.  
  56.  
  57. });
  58.  
  59.  
  60. });
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68. ngOnInit() {
  69. this.filteredOptionsRut = this.rutCtrl.valueChanges
  70. .pipe(
  71. startWith(''),
  72. map((val: any) =>
  73. this.filter(val)
  74. )
  75. );
  76. }
  77.  
  78.  
  79. filter(val: string): string[] {
  80. return this.proveedores.filter(proveedor =>
  81. proveedor.toLowerCase().indexOf(val.toLowerCase()) === 0);
  82. }
  83.  
  84. onCuentaChange(event) {
  85.  
  86. this.controlFacturaService.getSubCuentas(event.value).subscribe(subCuentas => {
  87. this.subCuentas = subCuentas;
  88. });
  89.  
  90. }
  91. createContactForm() {
  92. return this.formBuilder.group({
  93. fecha: new Date(),
  94. tipoDoc: '',
  95. NfacturaBoleta: '000',
  96. rutProv: '',
  97. proveedor: '',
  98. montoTotal: '',
  99. pagadoPor: 'colegio',
  100. glosa: '',
  101. cuenta: '',
  102. subCuenta: '',
  103. rutProv2: ''
  104.  
  105.  
  106. });
  107. }
  108.  
  109. newFactura(formValue) {
  110.  
  111.  
  112.  
  113. this.controlFacturaService
  114. .addProveedor(
  115. {
  116. rut: this.rutCtrl.value
  117. }
  118. );
  119. this.controlFacturaService.addFactura(formValue);
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment