Advertisement
coffeecode12

rekomen by atribbute

Feb 17th, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { MatSnackBar } from '@angular/material/snack-bar';
  3. import { RepositoryService } from 'src/app/shared/services/repository.service';
  4. import { samplingVoucherList } from 'src/app/shared/services/uji-tuntas/config';
  5. import { ProductService } from '../../../../../../../../shared/services/products/productservice';
  6. import { TableRequest } from '../model/simulasi-jumlah-sampling.model';
  7. import icSearch from '@iconify/icons-ic/twotone-search';
  8. import { Form, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
  9. import { ActivatedRoute } from '@angular/router';
  10. import { HttpParams } from '@angular/common/http';
  11. @Component({
  12.   selector: 'vex-rekomen-by-attribute',
  13.   templateUrl: './rekomen-by-attribute.component.html',
  14.   styleUrls: ['./rekomen-by-attribute.component.scss']
  15. })
  16. export class RekomenByAttributeComponent implements OnInit {
  17.   icSearch = icSearch;
  18.   public rows: Array<object> = [];
  19.   public columns: Array<object>;
  20.   public pageSize: number;
  21.   public recordsTotal: number;
  22.   public paramRequest: TableRequest;
  23.   selectRow: any;
  24.   sort: string;
  25.   search: string;
  26.   token: string;
  27.   debounceTimer: any;
  28.   debounceTime = 500;
  29.   submitted=false
  30.   isLoading = true;
  31.   listAttribute: any;
  32.   listRekapAttribute:any;
  33.   listBalance: any;
  34.   listPresentase:any;
  35.   idAttr:any;
  36.   isConfirmation = false;
  37.   rekapByAttrForm:FormGroup
  38.   loadTable= false
  39.   idBalance:any
  40.   idSelect:any;
  41.   colsName: any = [];
  42.   sortField: string;
  43.   index: any;
  44.   constructor(
  45.     private productService: ProductService,
  46.     private repositoryService: RepositoryService,
  47.     private snackbar: MatSnackBar,
  48.     private formBuilder: FormBuilder,
  49.     private route: ActivatedRoute,
  50.   ) {
  51.     this.route.params.subscribe((params) => {
  52.       this.idSelect = params['id'];
  53.   });
  54.   }
  55.  
  56.   ngOnInit(): void {
  57.     this.sortField = 'id';
  58.     this.token = localStorage.getItem('token');
  59.     this.columns = [
  60.       { name: 'No Rekening', field: 'noRekening' },
  61.       { name: 'No Nasabah', field: 'noNasabah' },
  62.       { name: 'Nama Kantor', field: 'namaKantor' },
  63.       { name: 'Kd Kualitas', field: 'kdKualitas' },
  64.       { name: 'Jumlah Laporan perBulan', field: 'jmlBulLap' },
  65.       { name: 'Kd Gol Nasabah', field: 'kdGolNasabah' },
  66.       { name: 'Gol Nasabah', field: 'golNasabah' },
  67.       { name: 'Jenis Penggunaan', field: 'jenisPenggunaan' },
  68.       { name: 'Jenis Kredit', field: 'jenisKredit' },
  69.       { name: 'Jenis Valuta', field: 'jenisValuta' },
  70.       // { name: 'Presentase Sampling', field: 'persentaseSampling' }
  71.     ];
  72.  
  73.     this.pageSize = 10;
  74.     this.paramRequest = {
  75.       start: 0,
  76.       length: this.pageSize,
  77.     };
  78.     this.getRekapAttribute();
  79.    this.getDataJson1(this.paramRequest)
  80.     this.initForm();
  81.   }
  82.  
  83.   // BUAT SORT BALANCE
  84.   items = [
  85.     {
  86.       id:0,
  87.       name: 'Sort',
  88.      
  89.     }, {
  90.       id:1,
  91.       name: 'Random',
  92.     }
  93.   ];
  94.  
  95.   form: FormGroup = new FormGroup({
  96.     name: new FormControl('',Validators.required),
  97.     presentase: new FormControl('', Validators.required),
  98.     // balance: new FormControl('',  Validators.required)
  99.   });
  100.  
  101.   initForm() {
  102.     this.rekapByAttrForm = this.formBuilder.group({
  103.         name:['',[Validators.required]],
  104.         presentase: ['', [Validators.required]],
  105.         // balance: ['', [Validators.required]],
  106.     });
  107.      {
  108.       this.f.presentase.setValue('')
  109.     }
  110.   }
  111.  
  112.   get f() {
  113.     return this.rekapByAttrForm.controls;
  114. }
  115.  
  116.  
  117. onSubmit() {
  118.   console.log('check', this.rekapByAttrForm, this.rekapByAttrForm.valid);
  119.   this.submitted = true;
  120.   if (this.rekapByAttrForm.invalid) {
  121.     return;
  122.   } else {
  123.     this.isConfirmation = true;
  124.   }
  125. }
  126.  
  127. onChangeUser(evt:Event) {
  128.   const index = this.listRekapAttribute.findIndex(item => item['id'] === evt);
  129.   const modelDataUser = this.listRekapAttribute[index];
  130.     this.idAttr = modelDataUser.id
  131.     console.log(this.idAttr)
  132.     this.getPresentase();
  133.   }
  134.  
  135.   onChanges(evt:any) {
  136.     const index = this.items.findIndex(item => item['name'] === evt);
  137.     const modelDataUser = this.items[index];
  138.       this.idBalance = modelDataUser.name
  139.       console.log(this.idAttr)
  140. }
  141.  
  142.  
  143.   getAttribute() {
  144.     this.isLoading = true;
  145.     this.repositoryService.getDataWithToken(samplingVoucherList.attribut , this.token).subscribe(
  146.       (value: any) => {
  147.         this.listAttribute = value.data;
  148.         this.isLoading = false;
  149.       }, error => {
  150.         this.isLoading = false;
  151.         console.log('error', error);
  152.        
  153.         this.snackbar.open("Opss.. "+error['name'], 'Error', {
  154.           duration: 7000
  155.         });
  156.       }
  157.     );
  158.   }
  159.  
  160.   getRekapAttribute() {
  161.     // this.isLoading = true;
  162.     this.repositoryService.getDataWithToken(samplingVoucherList.rekapAttribut , this.token).subscribe(
  163.       (value: any) => {
  164.         this.listRekapAttribute = value.data;
  165.         this.isLoading = false;
  166.       }, error => {
  167.         this.isLoading = false;
  168.         console.log('error', error);
  169.         this.snackbar.open("Opss.. "+error['name'], 'Error', {
  170.           duration: 7000
  171.         });
  172.       }
  173.     );
  174.   }
  175.  
  176.  
  177.  
  178.   getPresentase() {
  179.     // this.isLoading = true;
  180.     this.repositoryService.getDataWithToken(samplingVoucherList.presentaseAttribut + this.idAttr , this.token).subscribe(
  181.       (value: any) => {
  182.         this.listPresentase = value.data;
  183.         this.isLoading = false;
  184.       }, error => {
  185.         this.isLoading = false;
  186.         console.log('error', error);
  187.        
  188.         this.snackbar.open("Opss.. "+error['name'], 'Error', {
  189.           duration: 7000
  190.         });
  191.       }
  192.     );
  193.   }
  194.  
  195.  
  196.  
  197.  
  198.   getDataJson(param: TableRequest) {
  199.     this.isLoading = true;
  200.     const token = localStorage.getItem('token');
  201.     const formData = new FormData();
  202.     let params = new HttpParams();
  203.     params = params.append('nominal', 5000);
  204.     params = params.append('cmbRekapid', this.idAttr );
  205.     params = params.append('cmbValue', this.f.presentase.value);
  206.     formData.append('start', param.start.toString());
  207.     formData.append('length', param.length.toString());
  208.         formData.append('search[value]', this.search ? this.search.toString() : '');
  209.         formData.append('search[regex]', 'false');
  210.         formData.append('columns[0][data]', '1');
  211.         formData.append('columns[0][orderable]', 'true');
  212.         formData.append('columns[0][searchable]', 'true');
  213.         formData.append('columns[0][name]', 'id');
  214.         formData.append('order[0][column]', '1');
  215.         formData.append('order[0][dir]', this.sort ? this.sort.toString() : 'desc');
  216.         this.repositoryService.postDataWithToken(samplingVoucherList.sampleVouchingRekomenListAtttibute+ this.idSelect+'?'+params,formData, token, null).subscribe((res: any) => {
  217.           this.recordsTotal = res.data.recordsFiltered as number;
  218.           this.rows = res.data.data;
  219.           this.isLoading = false;
  220.         });
  221. }
  222.  
  223. getDataJson1(param: TableRequest) {
  224.   this.isLoading = true;
  225.   const token = localStorage.getItem('token');
  226.   const formData = new FormData();
  227.   formData.append('start', param.start.toString());
  228.   formData.append('length', param.length.toString());
  229.   formData.append('search[value]', this.search ? this.search.toString() : '');
  230.   formData.append('search[regex]', 'false');
  231.   formData.append('columns[0][data]', '1');
  232.   formData.append('columns[0][orderable]', 'true');
  233.   formData.append('columns[0][searchable]', 'true');
  234.   formData.append('columns[0][name]', 'id');
  235.   formData.append('order[0][column]', '1');
  236.   formData.append('order[0][dir]', this.sort ? this.sort.toString() : 'desc');
  237.       this.repositoryService.postDataWithToken(samplingVoucherList.sampleVouchingRekomenListAtttibute+ this.idSelect,formData, token, null).subscribe((res: any) => {
  238.         this.recordsTotal = res.data.recordsFiltered as number;
  239.         this.rows = res.data.data;
  240.         this.isLoading = false;
  241.       });
  242. }
  243.  
  244.  
  245.  
  246.  
  247. sortPage(page: any) {
  248.   this.index = this.colsName?.findIndex(item => item == page.sortField);
  249.   this.sort = page?.sortOrder === 1 ? 'asc' : 'desc';
  250.   this.sortField = page?.sortField ? page.sortField : 'id';
  251. }
  252.  
  253. updatePage(page: any) {
  254.   if (page && page.sortField && page.sortOrder) {
  255.     this.sortPage(page);
  256.   }
  257.  
  258.   this.paramRequest = {
  259.     start: page.first / page.rows,
  260.     length: page.rows,
  261.   };
  262.  
  263.   this.getDataJson1(this.paramRequest);
  264.  
  265. }
  266.  
  267.  
  268.  
  269.   getBalance() {
  270.     this.isLoading = true;
  271.     this.repositoryService.getDataWithToken(samplingVoucherList.balance, this.token).subscribe(
  272.       (value: any) => {
  273.         this.listBalance = value.data;
  274.         this.isLoading = false;
  275.       }, error => {
  276.         this.isLoading = false;
  277.         console.log('error', error);
  278.        
  279.         this.snackbar.open("Opss.. "+error['name'], 'Error', {
  280.           duration: 7000
  281.         });
  282.       }
  283.     );
  284.   }
  285.  
  286.   getAttributeTable(){
  287.     this.loadTable = true
  288.     this.pageSize = 10;
  289.     this.paramRequest = {
  290.       start: 0,
  291.       length: this.pageSize,
  292.     };
  293.     this.getDataJson(this.paramRequest)
  294.   }
  295.  
  296.  
  297.   getAttr() {
  298.     this.repositoryService.getDataWithToken(samplingVoucherList.attribut, this.token).subscribe((res: any) => {
  299.         this.listAttribute = res.data
  300.        
  301.     },
  302.     (error) => {
  303.         console.log('error', error);
  304.  
  305.         this.snackbar.open(error['message'], 'Error', {
  306.           duration: 7000,
  307.         });
  308.     })
  309. }
  310.  
  311.  
  312. onClear() {
  313.   this.rekapByAttrForm.reset();
  314. }
  315.  
  316.  
  317.  
  318. }
  319.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement