Advertisement
coffeecode12

result sampling

Feb 17th, 2022
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import icSearch from '@iconify/icons-ic/twotone-search';
  3. import { TableRequest } from '../model/simulasi-jumlah-sampling.model';
  4. import { RepositoryService } from 'src/app/shared/services/repository.service';
  5. import { samplingVoucherList } from 'src/app/shared/services/uji-tuntas/config';
  6. import { UjiTuntasService } from 'src/app/shared/services/uji-tuntas/uji-tuntas.service';
  7. import { ActivatedRoute } from '@angular/router';
  8. @Component({
  9.   selector: 'vex-rekomen-result-sampling',
  10.   templateUrl: './rekomen-result-sampling.component.html',
  11.   styleUrls: ['./rekomen-result-sampling.component.scss']
  12. })
  13. export class RekomenResultSamplingComponent implements OnInit {
  14.  
  15.   icSearch = icSearch;
  16.   public rows: Array<object> = [];
  17.   public columns: Array<object>;
  18.   public pageSize: number;
  19.   public recordsTotal: number;
  20.   public paramRequest: TableRequest;
  21.   public isLoading = true;
  22.   selectRow: any;
  23.   sort: string;
  24.   search: string;
  25.   token: string;
  26.   debounceTimer: any;
  27.   debounceTime = 500;
  28.   idSelect:any;
  29.   colsName: any = [];
  30.   sortField: string;
  31.   index: any;
  32.   constructor(
  33.     private repositoryService: RepositoryService,
  34.     private ujituntasService: UjiTuntasService,
  35.     private route: ActivatedRoute,
  36.   ) {
  37.     this.route.params.subscribe((params) => {
  38.       this.idSelect = params['id'];
  39.   });
  40.    }
  41.  
  42.   ngOnInit(): void {
  43.     this.sortField = 'id';
  44.     this.token = localStorage.getItem('token');
  45.     this.columns = [
  46.       { name: 'No Rekening', field: 'noRekening' },
  47.       { name: 'No Nasabah', field: 'noNasabah' },
  48.       { name: 'No Kantor', field: 'namaKantor' },
  49.       { name: ' Kd Kualitas', field: 'kdKualitas' },
  50.       { name: 'Laporan Net', field: 'jmlBulLap' },
  51.       { name: 'Kd Gol Nasabah', field: 'kdGolNasabah' },
  52.       { name: 'Gol Nasabah', field: 'golNasabah' },
  53.       { name: 'Jenis Penggunaan', field: 'jenisPenggunaan' },
  54.       { name: 'Jenis Kredit', field: 'jenisKredit' },
  55.       { name: 'Sampling Cabang', field: 'samplingCabang' },
  56.       { name: 'Sampling Saldo Minimum', field: 'samplingSaldoMinimum' },
  57.       { name: 'Sampling Gol Nasabah',field: 'samplingGolNasabah' },
  58.       { name: 'Sampling Jenis Valuta', field: 'samplingJenisValuta' },
  59.       { name: 'Sampling Jenis Kredit', field: 'samplingFinalDebitur' },
  60.       { name: 'Sampling Final', field: 'samplingFinal' },
  61.     ];
  62.    
  63.     this.pageSize = 10;
  64.     this.paramRequest = {
  65.       start: 0,
  66.       length: this.pageSize,
  67.     };
  68.  
  69.     this.getDataJson(this.paramRequest);
  70.   }
  71.  
  72.  
  73.   getDataJson(param: TableRequest) {
  74.     const token = localStorage.getItem('token');
  75.     this.isLoading = true;
  76.     const index = this.index ? this.index : 0;
  77.     const formData = new FormData();
  78.     formData.append('start', param.start.toString());
  79.     formData.append('length', param.length.toString());
  80.         formData.append('search[value]', this.search ? this.search.toString() : '');    
  81.         formData.append('search[regex]', 'false');
  82.         formData.append('columns['+index+'][data]', index+1);
  83.         formData.append('columns['+index+'][orderable]', 'true');
  84.         formData.append('columns['+index+'][searchable]', 'true');
  85.         formData.append('columns['+index+'][name]', this.sortField);
  86.         formData.append('order[0][column]', index+1);
  87.         formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
  88.         this.repositoryService.postDataWithToken(samplingVoucherList.sampleVouchingRekomenByResultSampling+"/" + this.idSelect,formData, token, null).subscribe((res: any) => {
  89.           this.recordsTotal = res.data.recordsFiltered as number;
  90.           this.colsName = res.data.colsName.split(', ');
  91.           this.rows = res.data.data;
  92.           this.isLoading = false;
  93.         });
  94. }
  95.  
  96.  
  97.  
  98. sortPage(page: any) {
  99.   this.index = this.colsName?.findIndex(item => item == page.sortField);
  100.   this.sort = page?.sortOrder === 1 ? 'asc' : 'desc';
  101.   this.sortField = page?.sortField ? page.sortField : 'id';
  102. }
  103.  
  104. updatePage(page: any) {
  105.   if (page && page.sortField && page.sortOrder) {
  106.     this.sortPage(page);
  107.   }
  108.  
  109.   this.paramRequest = {
  110.     start: page.first / page.rows,
  111.     length: page.rows,
  112.   };
  113.  
  114.   this.getDataJson(this.paramRequest);
  115.  
  116. }
  117. refresh(){
  118.   this.pageSize = 10;
  119.   this.paramRequest = {
  120.     start: 0,
  121.     length: this.pageSize,
  122.   };
  123.  
  124.   this.getDataJson(this.paramRequest);
  125. }
  126. downloadExcel() {
  127.   this.ujituntasService.downloadXls2(samplingVoucherList.sampleVouchingXlsx+"/" + this.idSelect, this.token,'application/x-www-form-urlencoded')
  128.       .subscribe((value: any) => {
  129.   let url = window.URL.createObjectURL(value);
  130.   let a = document.createElement('a');
  131.   document.body.appendChild(a);
  132.   a.setAttribute('style', 'display: none');
  133.   a.href = url;
  134.   a.download = 'samplevouching.xlsx';
  135.   a.click();
  136.   window.URL.revokeObjectURL(url);
  137.       },
  138.       (err) => {
  139.           console.log(err);
  140.       });
  141. }
  142.  
  143. }
  144.  
  145.  
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement