Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, ViewEncapsulation } from '@angular/core';
- import { fuseAnimations } from '../../../../core/animations';
- import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
- import { ControlFacturasService } from '../control-facturas.service';
- import { Observable } from 'rxjs/Observable';
- import { map, startWith } from 'rxjs/operators';
- @Component({
- selector: 'app-detail-factura',
- templateUrl: './detail-factura.component.html',
- styleUrls: ['./detail-factura.component.scss'],
- animations: fuseAnimations,
- encapsulation: ViewEncapsulation.None
- })
- export class DetailFacturaComponent implements OnInit {
- proveedores;
- optionsRut: any;
- subCuentas: any[];
- cuentas;
- rutCtrl: FormControl = new FormControl();
- controlFactura: FormGroup;
- tipoDocumentos;
- filteredOptionsRut: Observable<string[]>;
- constructor(private formBuilder: FormBuilder, private controlFacturaService: ControlFacturasService) {
- this.controlFactura = this.createContactForm();
- Promise.all([
- this.controlFacturaService.getTipoDocumentos().take(1).toPromise(),
- this.controlFacturaService.getCuentas().take(1).toPromise(),
- this.controlFacturaService.getProveedores().take(1).toPromise()
- ]).then((res: any[]) => {
- Observable.forkJoin([
- res[0],
- res[1],
- res[2],
- ])
- .subscribe((response) => {
- this.tipoDocumentos = response[0];
- this.cuentas = response[1];
- this.proveedores = response[2];
- });
- });
- }
- ngOnInit() {
- this.filteredOptionsRut = this.rutCtrl.valueChanges
- .pipe(
- startWith(''),
- map((val: any) =>
- this.filter(val)
- )
- );
- }
- filter(val: string): string[] {
- return this.proveedores.filter(proveedor =>
- proveedor.toLowerCase().indexOf(val.toLowerCase()) === 0);
- }
- onCuentaChange(event) {
- this.controlFacturaService.getSubCuentas(event.value).subscribe(subCuentas => {
- this.subCuentas = subCuentas;
- });
- }
- createContactForm() {
- return this.formBuilder.group({
- fecha: new Date(),
- tipoDoc: '',
- NfacturaBoleta: '000',
- rutProv: '',
- proveedor: '',
- montoTotal: '',
- pagadoPor: 'colegio',
- glosa: '',
- cuenta: '',
- subCuenta: '',
- rutProv2: ''
- });
- }
- newFactura(formValue) {
- this.controlFacturaService
- .addProveedor(
- {
- rut: this.rutCtrl.value
- }
- );
- this.controlFacturaService.addFactura(formValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment