Advertisement
coffeecode12

sampling

Feb 16th, 2022
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import icDoneAll from '@iconify/icons-ic/twotone-done-all';
  3. import icArrowDownward from '@iconify/icons-ic/arrow-downward';
  4. import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
  5. import icAdd from '@iconify/icons-ic/twotone-add';
  6. import icSearch from '@iconify/icons-ic/twotone-search';
  7. import icMoreHoriz from '@iconify/icons-ic/twotone-more-horiz';
  8. import icEdit from '@iconify/icons-ic/twotone-edit';
  9. import icAccess from '@iconify/icons-ic/twotone-dns';
  10. import icPageView from '@iconify/icons-ic/twotone-pageview';
  11. import { samplingVoucherList } from 'src/app/shared/services/uji-tuntas/config';
  12. import { SamplingCabangComponent } from './sampling-cabang/sampling-cabang.component';
  13. import icDelete from '@iconify/icons-ic/twotone-delete';
  14. import { RepositoryService } from 'src/app/shared/services/repository.service';
  15. import {  TableRequest } from './model/simulasi-jumlah-sampling.model';
  16. import { UjiTuntasService } from 'src/app/shared/services/uji-tuntas/uji-tuntas.service';
  17. import { MatSnackBar } from '@angular/material/snack-bar';
  18. import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
  19. import { ActivatedRoute } from '@angular/router';
  20. import icUploadFile from '@iconify/icons-ic/twotone-cloud-upload';
  21. import { DocumentFormModel } from '../../model/detail-uji-tuntas.model';
  22.  
  23. @Component({
  24.   selector: 'vex-simulasi-jumlah-sampling',
  25.   templateUrl: './simulasi-jumlah-sampling.component.html',
  26.   styleUrls: ['./simulasi-jumlah-sampling.component.scss']
  27. })
  28. export class SimulasiJumlahSamplingComponent implements OnInit {
  29.   icDoneAll = icDoneAll;
  30.   icArrowDownward = icArrowDownward;
  31.   icUploadFile = icUploadFile;
  32.   isConfirmation = false;
  33.   formModel: DocumentFormModel = {} as DocumentFormModel;
  34.   public rows: Array<object> = [];
  35.   public columns: Array<object>;
  36.   public pageSize: number;
  37.   public recordsTotal: number = 0;
  38.   public paramRequest: TableRequest;
  39.   public isLoading = true;
  40.   icSearch = icSearch;
  41.   icAdd = icAdd;
  42.   icMoreHoriz = icMoreHoriz;
  43.   icEdit = icEdit;
  44.   icDelete = icDelete;
  45.   icAccess = icAccess;
  46.   icPageView = icPageView;
  47.   selectRow: any;
  48.   sort: string;
  49.   search: string;
  50.   token: string;
  51.   listAttribute: any;
  52.   debounceTimer: any;
  53.   debounceTime = 500;
  54.   typeId: any;
  55.   idAttr:any
  56.   asumsiNominalForm:FormGroup;
  57.   submitted = false;
  58.   sortField: string;
  59.   index: any;
  60.   colsName: any = [];
  61.   load= false
  62.   currentLink: string;
  63.   previousLink: string;
  64.   rootLink: string;
  65.   crumbsValue: any[] = [];
  66.   idSelect:any
  67.   isCheckedEdit:boolean= false
  68.   public last:any = 0;
  69.   constructor(
  70.     private repositoryService: RepositoryService,
  71.     private ujituntasService: UjiTuntasService,
  72.     public dialog: MatDialog,
  73.     private snackbar: MatSnackBar,
  74.     private formBuilder: FormBuilder,
  75.     private route: ActivatedRoute,
  76.   ) {
  77.     this.route.params.subscribe((params) => {
  78.       this.idSelect = params['id'];
  79.       localStorage.setItem('id',this.idSelect)
  80.    
  81.   });
  82.   }
  83.  
  84.  
  85.   ngOnInit(): void {
  86.     console.log('window.location.href : ', window.location.href);
  87.     // init route
  88.     this.currentLink = window.location.pathname;
  89.     this.previousLink = this.currentLink.split('simulasi-jumlah-sampling')[0];
  90.     this.rootLink = this.previousLink.split('detail-uji-tuntas')[0];
  91.     this.crumbsValue = [
  92.         { label: 'GPEB', route: this.rootLink },
  93.         { label: 'Perencanaan Uji Tuntas', route: this.rootLink },
  94.         { label: 'Data BDPI dan BDPK', route: this.rootLink },
  95.         { label: 'Detail Uji Tuntas', route: this.previousLink.split('atur-tim-uji-tuntas')[0] },
  96.         { label: 'Atur Tim Uji Tuntas', route: this.previousLink },
  97.         { label: 'Simulasi Jumlah Sampling', route: this.currentLink },
  98.     ];
  99.  
  100.     this.sortField = 'no Rekening';
  101.     this.idAttr =''
  102.     this.token = localStorage.getItem('token');
  103.     this.columns = [
  104.       { name: 'No Rekening', field: 'no Rekening' },
  105.       { name: 'No Nasabah', field: 'no Nasabah"' },
  106.       { name: 'Nama Kantor', field: 'nama Kantor' },
  107.       { name: 'Kd Kualitas', field: 'kd Kualitas' },
  108.       { name: 'Jumlah Bulan Laporan Net', field: 'jumlah Bulan Laporan Net' },
  109.       { name: 'Kd Gol Nasabah', field: 'kdGolNasabah' },
  110.       { name: 'Gol Nasabah', field: 'golNasabah' },
  111.       { name: 'Jenis Penggunaan', field: 'jenisPenggunaan' },
  112.       { name: 'Jenis Kredit', field: 'jenis_Kredit' },
  113.       { name: 'Jenis Valuta', field: 'jenisValuta' },
  114.     ];
  115.  
  116.  
  117.     this.pageSize = 10;
  118.     this.paramRequest = {
  119.       start: 0,
  120.       length: this.pageSize,
  121.     };
  122.     // this.getDataJson(this.paramRequest)
  123.     this.getAttribute();
  124.     this.initForm();
  125.  
  126.  
  127.   }
  128.  
  129.   get f() {
  130.     return this.asumsiNominalForm.controls;
  131. }
  132.  
  133.  
  134. form: FormGroup = new FormGroup({
  135.   name: new FormControl('',Validators.required),
  136.   samplingSaldo: new FormControl('', Validators.required),
  137.   keterangan: new FormControl(''),
  138. });
  139.  
  140. initForm() {
  141.   this.asumsiNominalForm = this.formBuilder.group({
  142.       // name:['',[Validators.required]],
  143.       isCheckedEdit: [false],
  144.       samplingSaldo: ['', [Validators.required]],
  145.       keterangan: [''],
  146.   });
  147.    {
  148.     this.f.samplingSaldo.setValue('');
  149.     this.f.keterangan.setValue('');
  150.     this.f.isCheckedEdit.setValue(this.isCheckedEdit ? this.isCheckedEdit : false);
  151.   }
  152. }
  153.  
  154.  
  155. onClear() {
  156.   this.asumsiNominalForm.reset();
  157.   this.idAttr= ''
  158. }
  159.  
  160. onSubmit() {
  161.   console.log('check', this.asumsiNominalForm, this.asumsiNominalForm.valid);
  162.   this.submitted = true;
  163.   if (this.asumsiNominalForm.invalid) {
  164.     return;
  165.   } else {
  166.     this.isConfirmation = true;
  167.   }
  168. }
  169.  
  170.  
  171. postAsumsiNominal() {
  172.   let reqBody = {
  173.     samplingSaldo:this.f.samplingSaldo.value,
  174.     id: this.idAttr ? this.idAttr : '',
  175.     keterangan: this.f.keterangan.value,
  176.   }
  177.   this.repositoryService.postDataWithToken(samplingVoucherList.asumsiNominal, reqBody, this.token, null).subscribe((data: any) => {
  178.       this.snackbar.open(data.detail, data.message, {
  179.         duration: 10000,
  180.       });  
  181.       if (data.status === 200) {
  182.         // this.dialogRef.close('Add OK');
  183.         console.log('Add OK')
  184.       }
  185.    
  186.     (err: any) => {
  187.       console.log('error', err);
  188.       this.snackbar.open('Opsss.. ' + err.name, 'Error', {
  189.         duration: 10000,
  190.       });
  191.     }
  192.  
  193.   },
  194.   )
  195.  
  196. }
  197.  
  198. list_att :any = [];
  199. objectValue:any
  200. onChangeUser(evt:Event) {
  201.   const index = this.listAttribute.findIndex(item => item['id'] === evt);
  202.   const modelDataUser = this.listAttribute[index];
  203.     this.idAttr = modelDataUser.name
  204.     this.objectValue = modelDataUser.id
  205.     this.list_att.push(this.idAttr)
  206.     console.log(this.idAttr,modelDataUser.id)
  207.  
  208.     // this.listAttribute.map(items => {
  209.     //   this.list_att.push(this.idAttr,modelDataUser.id)
  210.     //   console.log(items.id,items.name)
  211.  
  212.     // })
  213. }
  214.  
  215. removeListAttr(index:number){
  216.   this.list_att.splice(index, 1);
  217.   console.log(index)
  218. }
  219.  
  220.  
  221.   getAttribute() {
  222.     this.isLoading = true;
  223.     this.repositoryService.getDataWithToken(samplingVoucherList.attribut, this.token).subscribe(
  224.       (value: any) => {
  225.         this.listAttribute = value.data;
  226.         this.idAttr =value.data.id
  227.         this.isLoading = false;
  228.       }, error => {
  229.         this.isLoading = false;
  230.         console.log('error', error);
  231.        
  232.         this.snackbar.open("Opss.. "+error['name'], 'Error', {
  233.           duration: 7000
  234.         });
  235.       }
  236.     );
  237.   }
  238.  
  239.  
  240. getDataJson(param: TableRequest) {
  241.     this.isLoading = true;
  242.     const index = this.index ? this.index : 0;
  243.     const formData = new FormData();
  244.     formData.append('start', param.start.toString());
  245.     formData.append('length', param.length.toString());
  246.         formData.append('search[value]', this.search ? this.search.toString() : '');    
  247.         formData.append('search[regex]', 'false');
  248.         formData.append('columns['+index+'][data]', index+1);
  249.         formData.append('columns['+index+'][orderable]', 'true');
  250.         formData.append('columns['+index+'][searchable]', 'true');
  251.         formData.append('columns['+index+'][name]', this.sortField);
  252.         formData.append('order[0][column]', index+1);
  253.         formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
  254.         this.repositoryService.postDataWithToken(samplingVoucherList.samplingVoucherList+"/" + this.idSelect , formData, this.token, null).subscribe((res: any) => {
  255.           this.recordsTotal = res.data.recordsFiltered as number;
  256.           this.rows = res.data.data;
  257.           this.colsName = res.data.colsName.split(', ');
  258.           this.isLoading = false;
  259.         });
  260.  
  261. }
  262.  
  263. getDataJsonFilterAsumsi(param: TableRequest) {
  264.   this.isLoading = true;
  265.   const index = this.index ? this.index : 0;
  266.   const formData = new FormData();
  267.   formData.append('start', param.start.toString());
  268.   formData.append('length', param.length.toString());
  269.   formData.append('search[value]', this.search ? this.search.toString() : '');    
  270.   formData.append('search[regex]', 'false');
  271.   formData.append('columns['+index+'][data]', index+1);
  272.   formData.append('columns['+index+'][orderable]', 'true');
  273.   formData.append('columns['+index+'][searchable]', 'true');
  274.   formData.append('columns['+index+'][name]', this.sortField);
  275.   formData.append('order[0][column]', index+1);
  276.   formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
  277.   this.repositoryService.postDataWithToken(samplingVoucherList.filterAsumsiNominal+"/" + this.idSelect +'/'+this.f.samplingSaldo.value+'/'+this.idAttr,formData, this.token, null).subscribe((res: any) =>  {
  278.         this.recordsTotal = res.data.recordsFiltered as number;
  279.         this.rows = res.data.data;
  280.         this.colsName = res.data.colsName.split(', ');
  281.         this.isLoading = false;
  282.       });
  283.  
  284. }
  285.  
  286. btnUploadDftrNomintafi(event:any){
  287.   this.isLoading = true
  288.   if (event.target.files.length > 0) {
  289.     const file = event.target.files[0];
  290.     this.formModel.fileContent = file;
  291.  }
  292.  const formData = new FormData();
  293.  formData.append('',this.formModel.fileContent)
  294.  formData.append('masterPenugasanUtid',this.idSelect)
  295.  this.repositoryService.postDataWithToken(samplingVoucherList.sampleImportExcel, formData, this.token,null).subscribe((data: any) => {
  296.   this.snackbar.open(data.detail, data.message, {
  297.     duration: 10000,
  298.   });  
  299.   if (data.status === 200) {
  300.    this.getDataJson(this.paramRequest)
  301.     console.log('Add OK')
  302.   }
  303.  
  304. (err: any) => {
  305.   console.log('error', err);
  306.   this.snackbar.open('Opsss.. ' + err.name, 'Error', {
  307.     duration: 10000,
  308.   });
  309. }
  310.  
  311. },
  312. )
  313. }
  314.  
  315. loadTableAsumsi(){
  316.    this.pageSize = 10;
  317.     this.paramRequest = {
  318.       start: 0,
  319.       length: this.pageSize,
  320.     };
  321.  
  322.     if(this.load = true){
  323.       this.getDataJsonFilterAsumsi(this.paramRequest)
  324.     }else{
  325.       this.load = false
  326.       this.getDataJson(this.paramRequest);
  327.     }
  328.  
  329. }
  330.  
  331. daftarNominatif(){
  332.   this.pageSize = 10;
  333.   this.paramRequest = {
  334.     start: 0,
  335.     length: this.pageSize,
  336.   };
  337.   this.load = true
  338.   this.getDataJson(this.paramRequest)
  339. }
  340.  
  341.  
  342.  
  343. // onChangeType(val: any){
  344. //   this.typeId = val;
  345. //   this.paramRequest = {
  346. //     start: 0,
  347. //     length: this.pageSize,
  348. //   };
  349.  
  350. //   this.getDataJson(this.paramRequest);
  351. // }
  352.  
  353.  
  354.  
  355. sortPage(page: any) {
  356.   this.index = this.colsName?.findIndex(item => item == page.sortField);
  357.   this.sort = page?.sortOrder === 1 ? 'asc' : 'desc';
  358.   this.sortField = page?.sortField ? page.sortField : 'id';
  359. }
  360.  
  361. updatePage(page: any) {
  362.   if (page && page.sortField && page.sortOrder) {
  363.     this.sortPage(page);
  364.   }
  365.  
  366.   this.paramRequest = {
  367.     start: page.first / page.rows,
  368.     length: page.rows,
  369.   };
  370.  
  371.   this.getDataJson(this.paramRequest);
  372.  
  373. }
  374.  
  375.   samplingCabangDialog() {
  376.     const dialogConfig = new MatDialogConfig();
  377.     dialogConfig.disableClose = true;
  378.     dialogConfig.width = '1200px';
  379.     const dialogRef = this.dialog.open(SamplingCabangComponent, dialogConfig);
  380.     dialogRef.afterClosed().subscribe(result => {
  381.       console.log(`Dialog result: ${result}`);
  382.     });
  383.   }
  384.  
  385.  
  386. }
  387.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement