Advertisement
coffeecode12

detail-kredit-tiga-pilar.ts

Jul 1st, 2022
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnDestroy, OnInit } from '@angular/core';
  2. import icAdd from '@iconify/icons-ic/twotone-add';
  3. import icDelete from '@iconify/icons-ic/delete';
  4. import icDone from '@iconify/icons-ic/done';
  5. import icSave from '@iconify/icons-ic/save';
  6. import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
  7. import { UploadKreditTigaComponent } from './upload-kredit-tiga/upload-kredit-tiga.component';
  8. import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
  9. import { TambahKreditTigaComponent } from './tambah-kredit-tiga/tambah-kredit-tiga.component';
  10. import { ActivatedRoute } from '@angular/router';
  11. import { DialogComponent } from '../../../../../../../shared/components/dialog/dialog.component';
  12. import { DialogInfoComponent } from '../../../../../../../shared/components/dialog-info/dialog-info.component';
  13. import { Observable, Subject } from 'rxjs';
  14. import { SubmitKreditTigaComponent } from './submit-kredit-tiga/submit-kredit-tiga.component';
  15. import { TableRequest } from 'src/app/model/module/uji-tuntas/uji-tuntas.model';
  16. import { UjiTuntasService } from 'src/app/services/module/uji-tuntas/uji-tuntas.service';
  17. import { KreditService } from 'src/app/services/module/uji-tuntas/kredit.service';
  18. import { PelaksanaanService } from 'src/app/services/module/uji-tuntas/pelaksanaan.service';
  19. import { takeUntil } from 'rxjs/operators';
  20.  
  21. @Component({
  22.   selector: 'vex-detail-kredit-tiga',
  23.   templateUrl: './detail-kredit-tiga.component.html',
  24.   styleUrls: ['./detail-kredit-tiga.component.scss']
  25. })
  26. export class DetailKreditTigaComponent implements OnInit, OnDestroy {
  27.   private readonly unsubs: Subject<void> = new Subject<void>();
  28.  
  29.   icAdd = icAdd;
  30.   icDelete = icDelete;
  31.   icDone = icDone;
  32.   icSave = icSave;
  33.   isSimpan = false;
  34.  
  35.   public currentLink: string;
  36.   public previousLink: string;
  37.   public crumbsValue: any[] = [];
  38.   form: FormGroup;
  39.   formPenilaian: FormGroup;
  40.   informasiNasabahFormGroup: FormGroup;
  41.  
  42.   public paramRequest: TableRequest;
  43.   public rows: any[] = [];
  44.   public rowsPenilaian: Array<any> = [];
  45.   public columns: any[] = [];
  46.   public rowsKualitasPembiayaan: any[] = [];
  47.   public columnsKualitasPembiayaan: any[] = [];
  48.   rowsInformasiAgunan: any[] = [];
  49.   recordsTotal: number = 0;
  50.   listPemeriksaan: any;
  51.   listNasabah: any;
  52.   pageSize: number = 5;
  53.   isLoading: boolean = false;
  54.   id: any;
  55.   masterPenugasanUtId: any;
  56.   pemeriksaanId: any;
  57.   idNasabah: any;
  58.   bankName: any;
  59.   tanggalUt: any;
  60.   isCheckedAll: boolean = false;
  61.   tampungArraySelected: any = [];
  62.  
  63.   summaryFormGroup: FormGroup;
  64.   isSummarySaved: boolean = false;
  65.  
  66.   index: any;
  67.   search: string;
  68.   sortField: string;
  69.   firstPage: string = "1";
  70.   sort: string;
  71.   colsName: any = [];
  72.   public rowsTemplate = [];
  73.   public listKolPemeriksa = [];
  74.  
  75.   totalNilaiagunan :any;
  76.   totalPPA:any;
  77.   constructor(
  78.     private formBuilder: FormBuilder,
  79.     public dialog: MatDialog,
  80.     private router: ActivatedRoute,
  81.     private ujiTuntasService: UjiTuntasService,
  82.     private pelaksanaanService: PelaksanaanService,
  83.     private kreditService: KreditService,
  84.   ) {
  85.     this.router.params.subscribe((params) => {
  86.       this.id = params['PemeriksaanUtKreditNasabahID'];
  87.       this.masterPenugasanUtId = params['id'];
  88.       this.pemeriksaanId = params['pemeriksaanId'];
  89.     });
  90.   }
  91.  
  92.  
  93.   ngOnInit(): void {
  94.  
  95.     this.currentLink = window.location.href;
  96.     this.previousLink = this.currentLink.split('tiga-pilar')[0];
  97.  
  98.     this.crumbsValue = [
  99.       { label: 'GPEB', route: this.currentLink },
  100.       { label: 'Pelaksanaan Uji Tuntas', route: this.currentLink },
  101.       { label: 'Laporan Pemeriksaan Kredit', route: this.previousLink },
  102.       { label: 'Kredit Tiga Pilar', route: this.currentLink },
  103.     ];
  104.  
  105.     this.columnsKualitasPembiayaan = [
  106.       { name: 'Faktor Penilaian Kualitas Pembiayaan', field: 'kualitasPembiayaan' },
  107.       { name: 'Kol Pemeriksa', field: 'pemeriksa' },
  108.       { name: 'Catatan', field: 'catatan' },
  109.       { name: 'Dokumen Pendukung', field: 'upload' },
  110.     ];
  111.  
  112.     this.columns = [
  113.       { name: 'id', field: 'id' },
  114.     ];
  115.  
  116.     this.sortField = 'id';
  117.     this.pageSize = 5;
  118.     this.paramRequest = {
  119.       start: 0,
  120.       length: this.pageSize,
  121.     };
  122.  
  123.     this.form = this.formBuilder.group({
  124.       isCheckedAll: [false],
  125.     });
  126.  
  127.     this.fc.isCheckedAll.setValue(this.isCheckedAll ? this.isCheckedAll : false);
  128.  
  129.     this.getLastStatus();
  130.     this.getInformasiAgunan(this.paramRequest);
  131.     this.ngInitForm();
  132.     this.getDummyData();
  133.     this.getInfoNasabah();
  134.     this.getDataPenilaian();
  135.     this.getInfoPemeriksa();
  136.   }
  137.  
  138.   ngInitForm() {
  139.  
  140.     this.listKolPemeriksa = [
  141.       { id: "1", name: 1 },
  142.       { id: "2", name: 2 },
  143.       { id: "3", name: 3 },
  144.       { id: "4", name: 4 },
  145.       { id: "5", name: 5 }
  146.     ]
  147.  
  148.     this.formPenilaian = this.formBuilder.group({
  149.       penilaianList: this.formBuilder.array([])
  150.     });
  151.  
  152.     this.clearFormArrayPenilaian();
  153.  
  154.     this.summaryFormGroup = this.formBuilder.group({
  155.       KolNasabahPemeriksaSummary: [{ value: '', disabled: false }],
  156.       PPABankSummary: [{ value: '', disabled: true }],
  157.       KolNasabahBankSummary: [{ value: '', disabled: true }],
  158.       PlafonSummary: [{ value: '', disabled: false }, [Validators.required]],
  159.       BakiDebetSummary: [{ value: '', disabled: false }, [Validators.required]],
  160.       PPAPemeriksaSummary: [{ value: '', disabled: false }, [Validators.required]],
  161.       CatatanPemeriksaSummary: [{ value: '', disabled: false }]
  162.     })
  163.  
  164.     this.informasiNasabahFormGroup = this.formBuilder.group({
  165.       nasabahBergerakdiBidang: [{ value: '', disabled: false }, [Validators.required]],
  166.       mulaiBeroperasiSejak: [{ value: '', disabled: false }, [Validators.required]],
  167.       nasabahMenPembiayaanBankSejak: [{ value: '', disabled: false }, [Validators.required]],
  168.       denganPlafonAwal: [{ value: '', disabled: false }, [Validators.required]],
  169.       pernahMenRestrukturSebanyak: [{ value: '', disabled: false }, [Validators.required]]
  170.     })
  171.   }
  172.  
  173.  
  174.  
  175.   clearFormArrayPenilaian() {
  176.     const arr = this.formPenilaian.controls['penilaianList'] as FormArray;
  177.     arr.controls = [];
  178.   }
  179.  
  180.   get listPenilaian() {
  181.     return this.formPenilaian.controls['penilaianList'] as FormArray;
  182.   }
  183.  
  184.   get fc() {
  185.     return this.form.controls;
  186.   }
  187.  
  188.   get summaryForm() {
  189.     return this.summaryFormGroup.controls;
  190.   }
  191.  
  192.   get informasiNasabahForm() {
  193.     return this.informasiNasabahFormGroup.controls;
  194.   }
  195.  
  196.   getDataPenilaian() {
  197.     this.isLoading = true;
  198.     this.kreditService.getListPenilaian(this.id).pipe(takeUntil(this.unsubs)).subscribe((data: any) => {
  199.       if (data.data) {
  200.         data.data.forEach(value => {
  201.           this.addRowPenilaian(value);
  202.         });
  203.         this.isLoading = false;
  204.       } else {
  205.         this.simpanPenilaian("baru", false)
  206.       }
  207.     },
  208.       (error) => {
  209.         console.log('error', error);
  210.         this.isLoading = false;
  211.       }
  212.     );
  213.   }
  214.  
  215.  
  216.   addRowPenilaian(dataRow?: any) {
  217.     let penilaianForm: any;
  218.     penilaianForm = this.formBuilder.group({
  219.       id: [dataRow ? dataRow.id : 0],
  220.       faktorPenilaian: [dataRow ? dataRow.faktorPenilaian : ''],
  221.       kolPemeriksa: [dataRow ? dataRow.kolPemeriksa : ''],
  222.       catatan: [dataRow ? dataRow.catatan : false]
  223.     });
  224.  
  225.     this.listPenilaian.push(penilaianForm);
  226.     this.rowsPenilaian = [];
  227.     this.rowsPenilaian.push(penilaianForm.value);
  228.   }
  229.  
  230.   simpanPenilaian(type: any, isKirim: boolean) {
  231.     const dialogConfig = new MatDialogConfig();
  232.     this.isLoading = true;
  233.     let submitObservable: Observable<any> = null;
  234.     const templateForm: any[] = [];
  235.  
  236.     if (type == "update") {
  237.       this.listPenilaian.controls.forEach(value => {
  238.         templateForm.push({
  239.           id: value.get('id').value,
  240.           pemeriksaanUtkreditNasabahID: this.id,
  241.           kolPemeriksa: value.get('kolPemeriksa').value,
  242.           catatan: value.get('catatan').value,
  243.           faktorPenilaian: value.get('faktorPenilaian').value
  244.         });
  245.       });
  246.     } else if (type == "baru") {
  247.       templateForm.push({
  248.         id: 0,
  249.         pemeriksaanUtkreditNasabahID: this.id,
  250.         kolPemeriksa: "1",
  251.         catatan: "",
  252.         faktorPenilaian: "Prospek Usaha"
  253.       });
  254.       templateForm.push({
  255.         id: 0,
  256.         pemeriksaanUtkreditNasabahID: this.id,
  257.         kolPemeriksa: "1",
  258.         catatan: "",
  259.         faktorPenilaian: "Kinerja Debitur/Nasabah"
  260.       });
  261.       templateForm.push({
  262.         id: 0,
  263.         pemeriksaanUtkreditNasabahID: this.id,
  264.         kolPemeriksa: "1",
  265.         catatan: "",
  266.         faktorPenilaian: "Kemampuan Membayar"
  267.       });
  268.     }
  269.  
  270.  
  271.  
  272.     submitObservable = this.kreditService.savePenilaian(templateForm);
  273.     submitObservable.pipe(takeUntil(this.unsubs)).subscribe(res => {
  274.       if (res) {
  275.         if (type == "update") {
  276.           if (!isKirim) {
  277.             dialogConfig.disableClose = true;
  278.             dialogConfig.data = {
  279.               dialogTitle: 'Save sukses',
  280.               dialogText: res.detail,
  281.               isLoading: false
  282.             };
  283.             const dialogRef = this.dialog.open(DialogInfoComponent, dialogConfig);
  284.           } else {
  285.             this.saveInformasiNasabah(true)
  286.           }
  287.         }
  288.  
  289.         this.isLoading = false;
  290.         this.clearFormArrayPenilaian();
  291.         this.getDataPenilaian();
  292.       }
  293.     }, error => {
  294.       this.isLoading = false;
  295.       if (type == "update") {
  296.         dialogConfig.disableClose = true;
  297.         dialogConfig.data = {
  298.           dialogTitle: 'Save gagal',
  299.           dialogText: error.error.detail,
  300.           isLoading: false
  301.         };
  302.         const dialogRef = this.dialog.open(DialogInfoComponent, dialogConfig);
  303.       }
  304.       console.log('error', error)
  305.     });
  306.   }
  307.  
  308.  
  309.   getLastStatus() {
  310.     this.kreditService.getNasabah(this.id).pipe(takeUntil(this.unsubs)).subscribe((res: any) => {
  311.  
  312.       if (res.data) {
  313.         const status = res.data.status;
  314.  
  315.         if (status == 0 || status == 3)
  316.           this.isSimpan = false;
  317.         else if (status == 1 || status == 2)
  318.           this.isSimpan = true;
  319.  
  320.       }
  321.     })
  322.   }
  323.  
  324.   submit() {
  325.     if (this.summaryFormGroup.invalid || this.informasiNasabahFormGroup.invalid) {
  326.       this.summaryForm.PlafonSummary.markAsTouched();
  327.       this.summaryForm.BakiDebetSummary.markAsTouched();
  328.       this.summaryForm.KolNasabahPemeriksaSummary.markAsTouched();
  329.       this.summaryForm.PPAPemeriksaSummary.markAsTouched();
  330.       this.summaryForm.CatatanPemeriksaSummary.markAsTouched();
  331.  
  332.       this.informasiNasabahForm.nasabahBergerakdiBidang.markAsTouched();
  333.       this.informasiNasabahForm.mulaiBeroperasiSejak.markAsTouched();
  334.       this.informasiNasabahForm.nasabahMenPembiayaanBankSejak.markAsTouched();
  335.       this.informasiNasabahForm.denganPlafonAwal.markAsTouched();
  336.       this.informasiNasabahForm.pernahMenRestrukturSebanyak.markAsTouched();
  337.  
  338.       const dialogConfig = new MatDialogConfig();
  339.       dialogConfig.disableClose = true;
  340.       dialogConfig.data = {
  341.         dialogTitle: 'Tidak Bisa Kirim',
  342.         dialogText: 'Data harus dilengkapi terlebih dahulu',
  343.         isLoading: false
  344.       };
  345.       const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
  346.  
  347.     } else {
  348.       this.simpanPenilaian("update", true)
  349.  
  350.       const dialogConfig = new MatDialogConfig();
  351.  
  352.       dialogConfig.disableClose = true;
  353.       dialogConfig.width = '500px';
  354.       dialogConfig.data = {
  355.         title: "Kredit Tiga Pilar",
  356.         function: "Add",
  357.         masterPenugasanUtId: this.masterPenugasanUtId,
  358.         idNasabah: this.id
  359.       }
  360.  
  361.       const dialogRef = this.dialog.open(SubmitKreditTigaComponent, dialogConfig);
  362.       dialogRef.afterClosed().pipe(takeUntil(this.unsubs)).subscribe(result => {
  363.         console.log(`Dialog result: ${result}`);
  364.  
  365.         if (result.status == "success" || result.status == "fail") {
  366.           dialogRef.close()
  367.           dialogConfig.disableClose = true;
  368.           dialogConfig.data = {
  369.             dialogTitle: result.title,
  370.             dialogText: result.message,
  371.             isLoading: false
  372.           };
  373.           const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfig);
  374.           this.getLastStatus();
  375.           this.getInfoNasabah();
  376.           this.clearFormArrayPenilaian();
  377.           this.getDataPenilaian();
  378.         }
  379.  
  380.       });
  381.     }
  382.   }
  383.  
  384.   getInfoPemeriksa() {
  385.     this.isLoading = true;
  386.     this.pelaksanaanService.getPemeriksaanUt(this.pemeriksaanId).pipe(takeUntil(this.unsubs)).subscribe((res: any) => {
  387.       if (res.data) {
  388.         this.isLoading = false;
  389.         this.bankName = res.data?.bankName;
  390.         this.tanggalUt = res.data?.tanggalAwalPelaksanaan;
  391.         this.listPemeriksaan = [
  392.           { name: 'Nama Pemeriksa', value: res.data?.pemeriksa },
  393.           { name: 'Nama Reviewer', value: res.data?.reviewer },
  394.           { name: 'Posisi Pemeriksaan', value: res.data?.jenisPemeriksaanUT },
  395.           { name: 'Tanggal', value: res.data?.posisiPemeriksaan },
  396.         ]
  397.       }
  398.     },
  399.       (error) => {
  400.         console.log('error', error);
  401.         this.isLoading = false;
  402.       }
  403.     );
  404.   }
  405.  
  406.   getInfoNasabah() {
  407.  
  408.     this.kreditService.getNasabahSummaryTiga(this.id).pipe(takeUntil(this.unsubs)).subscribe((res: any) => {
  409.       this.summaryForm.PlafonSummary.setValue(res.data?.plafonSummary);
  410.       this.summaryForm.BakiDebetSummary.setValue(res.data?.bakiDebetSummary);
  411.       this.summaryForm.KolNasabahPemeriksaSummary.setValue(res.data?.kolNasabahPemeriksaSummary);
  412.       this.summaryForm.PPAPemeriksaSummary.setValue(res.data?.ppaPemeriksaSummary);
  413.       this.summaryForm.CatatanPemeriksaSummary.setValue(res.data?.catatanPemeriksaSummary);
  414.       this.summaryForm.PPABankSummary.setValue(res.data?.ppaBankSummary);
  415.       this.summaryForm.KolNasabahBankSummary.setValue(res.data?.kolNasabahBankSummary);
  416.       this.informasiNasabahForm.nasabahBergerakdiBidang.setValue(res.data?.nasabahBergerakdiBidang);
  417.       this.informasiNasabahForm.mulaiBeroperasiSejak.setValue(res.data?.mulaiBeroperasiSejak);
  418.       this.informasiNasabahForm.nasabahMenPembiayaanBankSejak.setValue(res.data?.nasabahMenPembiayaanBankSejak);
  419.       this.informasiNasabahForm.denganPlafonAwal.setValue(res.data?.denganPlafonAwal);
  420.       this.informasiNasabahForm.pernahMenRestrukturSebanyak.setValue(res.data?.pernahMenRestrukturSebanyak);
  421.  
  422.       this.listNasabah = [
  423.         { name: 'Nama Nasabah', value: res.data?.namaNasabah },
  424.         { name: 'Total Plafond', value: res.data?.totalPlafond },
  425.         { name: 'Total Baki Debet', value: res.data?.totalBakiDebet },
  426.         { name: 'Tunggakan Pokok', value: res.data?.tunggakanPokok },
  427.         { name: 'Tunggakan Bunga/Margin/Bagi Hasil', value: res.data?.tunggakanBungaMarginBagiHasil },
  428.         { name: 'DPD (hari)', value: res.data?.dpDhari },
  429.       ]
  430.  
  431.  
  432.       if (res.data != null && res.data?.plafonSummary != null && res.data?.bakiDebetSummary != null && res.data?.kolNasabahPemeriksaSummary != null &&
  433.         res.data?.ppaPemeriksaSummary != null && res.data?.catatanPemeriksaSummary != null) {
  434.         this.summaryForm.PlafonSummary.disable();
  435.         this.summaryForm.BakiDebetSummary.disable();
  436.         this.summaryForm.KolNasabahPemeriksaSummary.disable();
  437.         this.summaryForm.PPAPemeriksaSummary.disable();
  438.         this.summaryForm.CatatanPemeriksaSummary.disable();
  439.  
  440.         this.isSummarySaved = true;
  441.       }
  442.     })
  443.   }
  444.  
  445.   updateDate(date) {
  446.     if (date) {
  447.       date.setDate(date.getDate() + 1);
  448.     }
  449.     return date;
  450.   }
  451.  
  452.   saveInformasiNasabah(isKirim: boolean) {
  453.     if (this.informasiNasabahFormGroup.invalid) {
  454.       this.informasiNasabahForm.nasabahBergerakdiBidang.markAsTouched();
  455.       this.informasiNasabahForm.mulaiBeroperasiSejak.markAsTouched();
  456.       this.informasiNasabahForm.nasabahMenPembiayaanBankSejak.markAsTouched();
  457.       this.informasiNasabahForm.denganPlafonAwal.markAsTouched();
  458.       this.informasiNasabahForm.pernahMenRestrukturSebanyak.markAsTouched();
  459.     } else {
  460.       const requestBody = {
  461.         id: this.id,
  462.         masterPenugasanUtId: this.masterPenugasanUtId,
  463.         nasabahBergerakdiBidang: this.informasiNasabahForm.nasabahBergerakdiBidang.value,
  464.         mulaiBeroperasiSejak: this.informasiNasabahForm.mulaiBeroperasiSejak.value,
  465.         nasabahMenPembiayaanBankSejak: this.updateDate(new Date(this.informasiNasabahForm.nasabahMenPembiayaanBankSejak.value)),
  466.         denganPlafonAwal: this.informasiNasabahForm.denganPlafonAwal.value,
  467.         pernahMenRestrukturSebanyak: this.informasiNasabahForm.pernahMenRestrukturSebanyak.value
  468.       }
  469.  
  470.       const dialogConfig = new MatDialogConfig();
  471.       this.kreditService.saveInfoNasabahTiga(requestBody).pipe(takeUntil(this.unsubs)).subscribe((res) => {
  472.  
  473.         if (!isKirim) {
  474.           dialogConfig.disableClose = true;
  475.           dialogConfig.data = {
  476.             dialogTitle: 'Simpan Berhasil',
  477.             dialogText: 'Berhasil Simpan Data',
  478.             isLoading: false
  479.           };
  480.           const dialogRef = this.dialog.open(DialogInfoComponent, dialogConfig);
  481.           this.getInfoNasabah();
  482.         } else {
  483.           this.saveSummary(true);
  484.         }
  485.       },
  486.         (error) => {
  487.           console.log('error', error);
  488.           if (!isKirim) {
  489.             dialogConfig.disableClose = true;
  490.             dialogConfig.data = {
  491.               dialogTitle: 'Simpan Gagal',
  492.               dialogText: error.error.detail,
  493.               isLoading: false
  494.             };
  495.             const dialogRef = this.dialog.open(DialogInfoComponent, dialogConfig);
  496.           }
  497.         })
  498.     }
  499.   }
  500.  
  501.   saveSummary(isKirim: boolean) {
  502.     if (this.summaryFormGroup.invalid) {
  503.  
  504.       this.summaryForm.PlafonSummary.markAsTouched();
  505.       this.summaryForm.BakiDebetSummary.markAsTouched();
  506.       this.summaryForm.KolNasabahPemeriksaSummary.markAsTouched();
  507.       this.summaryForm.PPAPemeriksaSummary.markAsTouched();
  508.       this.summaryForm.CatatanPemeriksaSummary.markAsTouched();
  509.  
  510.  
  511.       const dialogConfig = new MatDialogConfig();
  512.       dialogConfig.disableClose = true;
  513.       dialogConfig.data = {
  514.         dialogTitle: 'Data Kosong',
  515.         dialogText: 'Data Summary tidak boleh kosong',
  516.         isLoading: false
  517.       };
  518.       const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
  519.     } else {
  520.       const requestBody = {
  521.         pemeriksaanUTKreditNasabahId: this.id,
  522.         plafon: this.summaryForm.PlafonSummary.value,
  523.         bakiDebet: this.summaryForm.BakiDebetSummary.value,
  524.         kolNasabahPemeriksa: this.summaryForm.KolNasabahPemeriksaSummary.value,
  525.         ppaPemeriksa: this.summaryForm.PPAPemeriksaSummary.value,
  526.         catatan: this.summaryForm.CatatanPemeriksaSummary.value,
  527.       }
  528.  
  529.       const dialogConfig = new MatDialogConfig();
  530.       dialogConfig.disableClose = true;
  531.       dialogConfig.data = {
  532.         dialogTitle: 'Loading',
  533.         dialogText: 'Silahkan menunggu...',
  534.         isLoading: true
  535.       };
  536.       const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
  537.       this.kreditService.saveAnalisisTiga(requestBody).pipe(takeUntil(this.unsubs)).subscribe((res) => {
  538.         dialogRef.close();
  539.         if (!isKirim) {
  540.           const dialogConfigError = new MatDialogConfig();
  541.           dialogConfigError.disableClose = true;
  542.           dialogConfigError.data = {
  543.             dialogTitle: 'Simpan Berhasil',
  544.             dialogText: 'Berhasil Simpan Data',
  545.             isLoading: false
  546.           };
  547.           this.getInfoNasabah();
  548.         }
  549.  
  550.         this.summaryForm.PlafonSummary.disable();
  551.         this.summaryForm.BakiDebetSummary.disable();
  552.         this.summaryForm.KolNasabahPemeriksaSummary.disable();
  553.         this.summaryForm.PPAPemeriksaSummary.disable();
  554.         this.summaryForm.CatatanPemeriksaSummary.disable();
  555.  
  556.         this.isSummarySaved = true;
  557.       },
  558.         (error) => {
  559.           console.log('error', error);
  560.           const dialogConfigError = new MatDialogConfig();
  561.           dialogRef.close();
  562.           dialogConfigError.disableClose = true;
  563.           dialogConfigError.data = {
  564.             dialogTitle: 'Simpan Gagal',
  565.             dialogText: error.error.detail,
  566.             isLoading: false
  567.           };
  568.           const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  569.         })
  570.     }
  571.   }
  572.  
  573.   editSummary() {
  574.     this.isSummarySaved = false;
  575.  
  576.     this.summaryForm.PlafonSummary.enable();
  577.     this.summaryForm.BakiDebetSummary.enable();
  578.     this.summaryForm.KolNasabahPemeriksaSummary.enable();
  579.     this.summaryForm.PPAPemeriksaSummary.enable();
  580.     this.summaryForm.CatatanPemeriksaSummary.enable();
  581.   }
  582.  
  583.   getInformasiAgunan(param: TableRequest) {
  584.     let TotalNilaiAgunan = '0'
  585.     let TotalPPA = '0'
  586.     this.isLoading = true;
  587.  
  588.     const index = this.index ? this.index : 0;
  589.     const formData = new FormData();
  590.  
  591.     formData.append('start', param.start.toString());
  592.     formData.append('length', param.length.toString());
  593.     formData.append('search[value]', this.search ? this.search.toString() : '');
  594.     formData.append('search[regex]', 'false');
  595.     formData.append('columns[' + index + '][data]', index + 1);
  596.     formData.append('columns[' + index + '][orderable]', 'true');
  597.     formData.append('columns[' + index + '][searchable]', 'true');
  598.     formData.append('columns[' + index + '][name]', this.sortField);
  599.     formData.append('order[0][column]', index + 1);
  600.     formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
  601.  
  602.     this.kreditService.postListAgunanTiga(this.id, formData)
  603.       .pipe(takeUntil(this.unsubs))
  604.       .subscribe((res: any) => {
  605.         if (res.data.data) {
  606.           this.rowsInformasiAgunan = res.data.data;
  607.           this.recordsTotal = res.data.recordsTotal;
  608.           this.rowsInformasiAgunan.map((item) => {
  609.             TotalNilaiAgunan += item.nilaiAgunanYgDiAkui.toString();
  610.             TotalPPA += item.agunanPengurangPPA.toString();
  611.             console.log('totalPPA',item.agunanPengurangPPA.toString())
  612.           });
  613.  
  614.           this.totalNilaiagunan = TotalNilaiAgunan
  615.           this.totalPPA = TotalPPA
  616.  
  617.           this.colsName = res.data.colsName.split(', ');
  618.           this.checkUncheckAll(false)
  619.           this.isLoading = false;
  620.         } else {
  621.           this.rowsInformasiAgunan = [];
  622.           this.isLoading = false;
  623.         }
  624.       },
  625.         (err) => {
  626.           console.log('error : ', err);
  627.         });
  628.   }
  629.  
  630.   getDataTable(param: TableRequest) {
  631.     // this.isLoading = true;
  632.     // const index = this.index ? this.index : 0;
  633.     // const formData = new FormData();
  634.     // // formData.append('filter[bank]', this.kodeBank ? this.kodeBank: '');
  635.     // // formData.append('filter[status]', this.idStatus ? this.idStatus: '');
  636.     // // formData.append('filter[from]', this.tanggalAwal ? new Date(this.tanggalAwal).toDateString() : '');
  637.     // // formData.append('filter[to]', this.tanggalAkhir ? new Date(this.tanggalAkhir).toDateString()  : '');
  638.     // formData.append('start', param.start.toString());
  639.     // formData.append('length', param.length.toString());
  640.     // formData.append('search[value]', this.search ? this.search.toString() : '');
  641.     // formData.append('search[regex]', 'false');
  642.     // formData.append('columns[' + index + '][data]', index + 1);
  643.     // formData.append('columns[' + index + '][orderable]', 'true');
  644.     // formData.append('columns[' + index + '][searchable]', 'true');
  645.     // formData.append('columns[' + index + '][name]', this.sortField);
  646.     // formData.append('order[0][column]', index + 1);
  647.     // formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
  648.     // console.log('id : ', this.id);
  649.     // this.ujituntasService.postDataWithToken(pelaksanaan.listBap + '?masterPenugasanUtId=' + this.id, formData, this.token, null).subscribe((res: any) => {
  650.     //   this.recordsTotal = res.data.recordsFiltered as number;
  651.     //   this.colsName = res.data.colsName.split(', ');
  652.     //   console.log('data : ', res.data.data);
  653.     //   // res.data.data.map(item => {
  654.     //   //     item.bankId = item.masterPenugasanUt.detailPenugasan.bankId
  655.     //   //     item.id = item.id
  656.     //   //     item.masterPenugasanUtid = item.masterPenugasanUt?.detailPenugasan?.id
  657.     //   //     item.name = item.masterJenisPemeriksaanUt?.name
  658.     //   //     item.bankName = item.masterPenugasanUt?.detailPenugasan?.bankName
  659.     //   //     item.tanggalAwalPelaksanaan = item.masterPenugasanUt?.detailPenugasan?.tanggalAwalPelaksanaan
  660.     //   //     item.tanggalAkhirPelaksanaan = item.masterPenugasanUt?.detailPenugasan?.tanggalAkhirPelaksanaan
  661.     //   //     item.nomorSuratTugas = item.masterPenugasanUt?.detailPenugasan?.nomorSuratTugas
  662.     //   // })
  663.     //   this.rows = res.data.data;
  664.     //   this.isLoading = false;
  665.     // },
  666.     // (err: any) => {
  667.     //     console.log('error', err);
  668.     //     this.isLoading = false;
  669.     //     this.snackbar.open('Opsss.. ' + err.name, 'Error', {
  670.     //     duration: 10000,
  671.     //     });
  672.     // });
  673.   }
  674.  
  675.   tambahInfoAgunan() {
  676.     const dialogConfig = new MatDialogConfig();
  677.     dialogConfig.disableClose = true;
  678.     dialogConfig.width = '1200px';
  679.     dialogConfig.data = {
  680.       function: 'Add',
  681.       pemeriksaanUtkreditNasabahId: this.id,
  682.     };
  683.  
  684.     const dialogRef = this.dialog.open(TambahKreditTigaComponent, dialogConfig);
  685.     dialogRef.afterClosed().pipe(takeUntil(this.unsubs)).subscribe(result => {
  686.       console.log(`Dialog result: ${result}`);
  687.       if (result == true) {
  688.         console.log('huhuhu')
  689.         this.getInformasiAgunan(this.paramRequest);
  690.       }
  691.     });
  692.   }
  693.  
  694.   editInfoAgunan(id: any) {
  695.     const index = this.rowsInformasiAgunan.findIndex(item => item['id'] === id);
  696.     const modelData = this.rowsInformasiAgunan[index];
  697.     // console.log(id, modelData);
  698.  
  699.     const dialogConfig = new MatDialogConfig();
  700.     dialogConfig.disableClose = true;
  701.     dialogConfig.width = '1200px';
  702.     dialogConfig.data = {
  703.       function: 'Edit',
  704.       pemeriksaanUtkreditNasabahId: this.id,
  705.       modelData: modelData,
  706.     };
  707.  
  708.     const dialogRef = this.dialog.open(TambahKreditTigaComponent, dialogConfig);
  709.     dialogRef.afterClosed().pipe(takeUntil(this.unsubs)).subscribe(result => {
  710.       console.log(`Dialog result: ${result}`);
  711.       if (result == true) {
  712.         this.getInformasiAgunan(this.paramRequest);
  713.       }
  714.     });
  715.   }
  716.  
  717.   upload(data) {
  718.     const dialogConfig = new MatDialogConfig();
  719.     dialogConfig.disableClose = true;
  720.     dialogConfig.width = '900px';
  721.     dialogConfig.data = {
  722.       id: data.id,
  723.       faktorPenilaian: data.faktorPenilaian,
  724.       bankName: this.bankName,
  725.       tanggalUt: this.tanggalUt
  726.     }
  727.  
  728.     const dialogRef = this.dialog.open(UploadKreditTigaComponent, dialogConfig);
  729.   }
  730.  
  731.   getDummyData() {
  732.  
  733.     this.rows = [
  734.       { id: 'id' },
  735.     ];
  736.  
  737.     this.rowsKualitasPembiayaan = [
  738.       { kualitasPembiayaan: 'Prospek Usaha', pemeriksa: '3' },
  739.       { kualitasPembiayaan: 'Kinerja Debitur/Nasabah', pemeriksa: '3' },
  740.       { kualitasPembiayaan: 'Kemampuan Membayar', pemeriksa: '2' },
  741.     ];
  742.  
  743.     // this.listPemeriksaan = [
  744.     //   { name: 'Nama Pemeriksa', value: 'Rahmad Sanjaya' },
  745.     //   { name: 'Nama Reviewer', value: 'Muh Arief Radul Fiqri' },
  746.     //   { name: 'Posisi Pemeriksaan', value: 'Uji Tuntas' },
  747.     //   { name: 'Tanggal', value: '03 Mar 2022' },
  748.     // ]
  749.  
  750.     this.listNasabah = [
  751.       { name: 'Nama Nasabah', value: 'Abd Khadir' },
  752.       { name: 'Total Plafond', value: '1000000' },
  753.       { name: 'Total Baki Debet', value: '1000000' },
  754.       { name: 'Tunggakan Pokok', value: '0' },
  755.       { name: 'Tunggakan Bunga/Margin/Bagi Hasil', value: '0' },
  756.       { name: 'DPD (hari)', value: '0' },
  757.     ]
  758.   }
  759.  
  760.   sortPage(page: any) {
  761.     let sortField = page.sortField.toLowerCase();
  762.     this.index = this.colsName?.findIndex(item => item == sortField);
  763.     this.sort = page?.sortOrder === 1 ? 'asc' : 'desc';
  764.     this.sortField = sortField ? sortField : 'id';
  765.   }
  766.  
  767.   updatePage(event: any) {
  768.     if (event && event.sortField && event.sortOrder) {
  769.       this.sortPage(event);
  770.     }
  771.  
  772.     this.paramRequest = {
  773.       start: event.first / event.rows,
  774.       length: event.rows,
  775.     };
  776.  
  777.     this.getInformasiAgunan(this.paramRequest);
  778.   }
  779.  
  780.   deleteAgunan() {
  781.     const dialogConfigError = new MatDialogConfig();
  782.     this.isLoading = true
  783.  
  784.     this.kreditService.postDeleteAgunanTiga(this.id, this.isCheckedAll, this.tampungArraySelected).pipe(takeUntil(this.unsubs)).subscribe((res: any) => {
  785.  
  786.       if (res.status === 200) {
  787.         this.isLoading = false;
  788.         dialogConfigError.disableClose = true;
  789.         dialogConfigError.data = {
  790.           dialogTitle: 'Hapus',
  791.           dialogText: 'Data Berhasil Di Hapus',
  792.           isLoading: false
  793.         };
  794.         const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  795.         this.tampungArraySelected = []
  796.         this.getInformasiAgunan(this.paramRequest);
  797.       }
  798.       (err: any) => {
  799.         this.isLoading = true
  800.         console.log('error', err);
  801.         dialogConfigError.disableClose = true;
  802.         dialogConfigError.data = {
  803.           dialogTitle: 'Hapus',
  804.           dialogText: err.err.detail,
  805.           isLoading: false
  806.         };
  807.         const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  808.       }
  809.  
  810.     },
  811.     )
  812.  
  813.   }
  814.  
  815.   checkboxSelected(event: any, objectValue: any) {
  816.  
  817.     if (event.checked) {
  818.       if (this.rows.find((res) => res.id === objectValue.id) === undefined) {
  819.         if (this.isCheckedAll) {
  820.           var index = this.tampungArraySelected.indexOf(objectValue);
  821.           if (index !== -1) {
  822.             this.tampungArraySelected.splice(index, 1);
  823.           }
  824.         } else {
  825.           this.tampungArraySelected.push(
  826.             objectValue
  827.           )
  828.         }
  829.       }
  830.     } else {
  831.  
  832.       if (this.isCheckedAll) {
  833.         this.tampungArraySelected.push(
  834.           objectValue
  835.         )
  836.       } else {
  837.         var index = this.tampungArraySelected.indexOf(objectValue);
  838.         if (index !== -1) {
  839.           this.tampungArraySelected.splice(index, 1);
  840.         }
  841.       }
  842.     }
  843.   }
  844.  
  845.   checkUncheckAll(clearArray: boolean) {
  846.     this.isCheckedAll = this.fc.isCheckedAll.value;
  847.  
  848.     if (clearArray)
  849.       this.tampungArraySelected = []
  850.  
  851.     this.rowsInformasiAgunan.map(items => {
  852.       items.sampling = this.isCheckedAll;
  853.  
  854.       if (this.tampungArraySelected.length > 0) {
  855.         if (this.isCheckedAll) {
  856.           var index = this.tampungArraySelected.indexOf(items.id);
  857.           if (index !== -1) {
  858.             items.sampling = false;
  859.           }
  860.         } else {
  861.           var index = this.tampungArraySelected.indexOf(items.id);
  862.           if (index !== -1) {
  863.             items.sampling = true;
  864.           }
  865.         }
  866.       }
  867.     })
  868.   }
  869.  
  870.   ngOnDestroy(): void {
  871.     this.unsubs.next()
  872.     this.unsubs.complete()
  873.   }
  874.  
  875. }
  876.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement