coffeecode12

add-detail-uji-tuntas

Jun 3rd, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.99 KB | None | 0 0
  1. import {
  2. MatDialog,
  3. MatDialogConfig,
  4. MatDialogRef,
  5. MAT_DIALOG_DATA,
  6. } from '@angular/material/dialog';
  7. import { Component, OnInit, Inject } from '@angular/core';
  8. import icClose from '@iconify/icons-ic/twotone-close';
  9. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  10. import { MatSnackBar } from '@angular/material/snack-bar';
  11. import { Validator } from 'src/@vex/utils/validator';
  12. import { DialogComponent } from 'src/app/shared/components/dialog/dialog.component';
  13. import { DocumentFormModel } from 'src/app/model/module/uji-tuntas/uji-tuntas.model';
  14. import { PerencanaanService } from 'src/app/services/module/uji-tuntas/perencanaan.service';
  15. import { FileService } from 'src/app/services/module/uji-tuntas/file.service';
  16. import { UjiTuntasService } from 'src/app/services/module/uji-tuntas/uji-tuntas.service';
  17. import { Utils } from 'src/app/utils/utils';
  18. import { formatDate } from '@angular/common';
  19. import { DialogInfoComponent } from 'src/app/shared/components/dialog-info/dialog-info.component';
  20. import { GenerateFileService } from 'src/app/services/module/uji-tuntas/state/generateFolder.service';
  21. import moment from 'moment';
  22. import { T } from '@angular/cdk/keycodes';
  23.  
  24. @Component({
  25. selector: 'vex-add-edit-detail-uji-tuntas',
  26. templateUrl: './add-edit-detail-uji-tuntas.component.html',
  27. styleUrls: ['./add-edit-detail-uji-tuntas.component.scss'],
  28. })
  29. export class AddEditDetailUjiTuntasComponent implements OnInit {
  30. isConfirmation = false;
  31. icClose = icClose;
  32. formModel: DocumentFormModel = {} as DocumentFormModel;
  33. fileNames: string;
  34. extensions: string;
  35. titleDialog: string;
  36. functionDialog: string;
  37. isLoading = true;
  38. submitted = false;
  39. errMsgFileNull: boolean;
  40. status: any[] = [];
  41. listJenisPemeriksaan: any;
  42. bankStatus: any;
  43. detailUjiTuntasComponent: FormGroup;
  44. currentData: any;
  45. filteredKetuaTim: string[] = [];
  46. listKetuaTim: any;
  47. selectedBank: any;
  48. fileDocument: any;
  49. listBank: any;
  50. listRegisteredBank: any;
  51. listStatus: any;
  52. tempOjk: any = null;
  53. tempPosisiPemeriksaaan: any = null;
  54. tempSuratTugas: any = null;
  55. tempStart: any = null;
  56. tempEnd: any = null;
  57. tempTds: any = null;
  58. loginInfo: any;
  59. disabledField = true;
  60. listOjk: any;
  61. tglOjk: any;
  62. datepickerBoolean = false;
  63. bankId: any;
  64. isRemarkIndikasiFraud = false;
  65. constructor(
  66. @Inject(MAT_DIALOG_DATA) private data: any,
  67. private perencanaanService: PerencanaanService,
  68. private ujituntasService: UjiTuntasService,
  69. private fileService: FileService,
  70. private generateFile: GenerateFileService,
  71. private dialogRef: MatDialogRef<AddEditDetailUjiTuntasComponent>,
  72. private snackbar: MatSnackBar,
  73. private formBuilder: FormBuilder,
  74. private utils: Utils,
  75. public dialog: MatDialog
  76. ) {
  77. this.titleDialog = data.title;
  78. this.currentData = data.modelData;
  79. this.listKetuaTim = data.listKetuaTim;
  80. this.functionDialog = data.function;
  81. this.listJenisPemeriksaan = data.jenis;
  82. this.selectedBank = data.selectedBank;
  83. this.listBank = data.bank;
  84. this.listRegisteredBank = data.registeredBank;
  85. this.listStatus = data.status;
  86.  
  87. }
  88.  
  89. get f() {
  90. return this.detailUjiTuntasComponent.controls;
  91. }
  92.  
  93. ngOnInit(): void {
  94. this.loginInfo = JSON.parse(this.utils.getUserInfo());
  95. this.bankStatus = [{ value: true }, { value: false }];
  96.  
  97. this.initForm();
  98. this.getListOjk();
  99. }
  100.  
  101. public dateFilter = (tglAkhir: Date): boolean => {
  102. const value = this.detailUjiTuntasComponent.value;
  103. return tglAkhir >= value.tglAwalUjiTuntas;
  104. };
  105.  
  106. getListOjk() {
  107. this.ujituntasService.getExtGssk().subscribe((res: any) => {
  108. // console.log('kategori aguanan:', res);
  109. this.listOjk = res.data;
  110. })
  111. }
  112.  
  113. getDataBankTDS() {
  114. this.ujituntasService.getGamrDataBankTds(this.bankId, new Date(this.f.tglAwalUjiTuntas.value).getFullYear()).subscribe((res: any) => {
  115.  
  116. if (res?.data && res?.data[0]) {
  117. let dataBank = res.data[0];
  118. this.f.tglTds.setValue(
  119. dataBank.tglmasuk
  120. ? new Date(dataBank.tglmasuk)
  121. : dataBank.tglmasuk
  122. );
  123. // this.f.tglTds.disable();
  124. }
  125.  
  126. }, (error) => {
  127. const dialogConfigError = new MatDialogConfig();
  128. dialogConfigError.disableClose = true;
  129. dialogConfigError.data = {
  130. dialogTitle: 'Gagal Mendapatkan Data Dockumen Bank TDS',
  131. dialogText: error?.error?.detail,
  132. isLoading: false
  133. };
  134. const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  135. })
  136. }
  137.  
  138. changeBank(bank: any) {
  139. const indexNamaBank = this.listRegisteredBank.findIndex(item => item['bankId'] === bank.bankId);
  140. const dataNamaBank = this.listRegisteredBank[indexNamaBank];
  141. if (indexNamaBank >= 0){
  142. this.bankId = this.listRegisteredBank[indexNamaBank].bankId;
  143. if (this.functionDialog != 'Add'){
  144. this.getDataBankTDS();
  145. }
  146. }
  147.  
  148. // console.log(bank);
  149. // console.log(dataNamaBank);
  150. const indexOjk = this.listOjk.findIndex(item => item['bankId'] === dataNamaBank.bankId);
  151. const dataOjk = this.listOjk[indexOjk];
  152.  
  153. // console.log('dataOjk.noSurat : ', dataOjk.noSurat);
  154. // console.log('dataOjk.tanggalSurat : ', dataOjk.tanggalSurat);
  155.  
  156. if (dataOjk.noSurat) {
  157. this.f.noSuratPendapatanOjk.setValue(dataOjk.noSurat);
  158. this.f.noSuratPendapatanOjk.disable();
  159. } else {
  160. this.f.noSuratPendapatanOjk.setValue(dataOjk.noSurat);
  161. this.f.noSuratPendapatanOjk.enable();
  162. }
  163.  
  164. if (dataOjk.tanggalSurat) {
  165. this.tglOjk = new Date(dataOjk.tanggalSurat).toISOString();
  166. this.f.tglSuratMasukOjk.setValue(this.tglOjk);
  167. this.f.tglSuratMasukOjk.disable();
  168. this.datepickerBoolean = true;
  169.  
  170. // console.log(this.tglOjk);
  171. } else {
  172. this.f.tglSuratMasukOjk.setValue(dataOjk.tanggalSurat);
  173. this.f.tglSuratMasukOjk.enable();
  174. this.tglOjk = null;
  175. this.datepickerBoolean = false;
  176. }
  177.  
  178. }
  179.  
  180. changeTanggalAwalUT() {
  181. if (this.functionDialog != 'Add'){
  182. if (this.f.tglAwalUjiTuntas.value && this.f.tglAwalUjiTuntas.value != null && this.f.tglAwalUjiTuntas.value != '') {
  183. this.getDataBankTDS();
  184. }
  185. }
  186.  
  187. }
  188.  
  189. initForm() {
  190. this.formModel = {
  191. folderPath: 'ICS/Try',
  192. filename: null,
  193. fileContent: null,
  194. fiturId: '157',
  195. };
  196.  
  197. this.detailUjiTuntasComponent = this.formBuilder.group({
  198. noSuratTugas: [''],
  199. tglSuratMasukOjk: [''],
  200. noSuratPendapatanOjk: [''],
  201. tglPosisiPemeriksaan: ['', Validators.required],
  202. tglSuratTugas: [''],
  203. tglAwalUjiTuntas: ['', Validators.required],
  204. tglAkhirUjiTuntas: ['', Validators.required],
  205. tglTds: [''],
  206. bankStatus: [''],
  207. lokasi: [''],
  208. ketuaTim: ['', Validators.required],
  209. remarksPotensi: [''],
  210. remarksTds: [''],
  211. remarkIndikasiFraud: [''],
  212. bank: ['', Validators.required],
  213. jenisPemeriksaanId: ['', Validators.required],
  214. file: [],
  215. });
  216.  
  217. if (this.currentData) {
  218. this.formModel.filename = this.currentData.fileName;
  219.  
  220. const indexBank = this.listBank?.findIndex(
  221. (item) => item['bankId'] === this.currentData.bankId
  222. );
  223.  
  224. const bank = this.listBank[indexBank];
  225.  
  226. this.bankId = this.currentData.bankId
  227.  
  228. const index = this.listKetuaTim?.findIndex(
  229. (item) => item['userId'] === this.currentData.ketuaTimIdString
  230. );
  231. const ketuaTim = index ? this.listKetuaTim[index] : '';
  232. this.f.noSuratTugas.setValue(this.currentData.nomorSuratTugas);
  233. this.f.noSuratPendapatanOjk.setValue(this.currentData.nomorSuratOjk);
  234. this.f.tglSuratMasukOjk.setValue(
  235. this.currentData.tanggalSuratOjk
  236. ? new Date(this.currentData.tanggalSuratOjk)
  237. : this.currentData.tanggalSuratOjk
  238. );
  239. this.f.tglPosisiPemeriksaan.setValue(
  240. this.currentData.tanggalPosisiPemeriksaan
  241. ? new Date(this.currentData.tanggalPosisiPemeriksaan)
  242. : this.currentData.tanggalPosisiPemeriksaan
  243. );
  244. this.f.tglSuratTugas.setValue(
  245. this.currentData.tanggalSuratTugas
  246. ? new Date(this.currentData.tanggalSuratTugas)
  247. : this.currentData.tanggalSuratTugas
  248. );
  249. this.f.tglAwalUjiTuntas.setValue(
  250. this.currentData.tanggalAwalPelaksanaan
  251. ? new Date(this.currentData.tanggalAwalPelaksanaan)
  252. : this.currentData.tanggalAwalPelaksanaan
  253. );
  254. this.f.tglAkhirUjiTuntas.setValue(
  255. this.currentData.tanggalAkhirPelaksanaan
  256. ? new Date(this.currentData.tanggalAkhirPelaksanaan)
  257. : this.currentData.tanggalAkhirPelaksanaan
  258. );
  259.  
  260.  
  261. if (this.functionDialog === 'Add'){
  262. this.f.tglTds.setValue(
  263. this.currentData.tanggalTds
  264. ? new Date(this.currentData.tanggalTds)
  265. : this.currentData.tanggalTds
  266. );
  267. } else {
  268. this.f.tglTds.setValue(
  269. this.currentData.tanggalTds
  270. ? new Date(this.currentData.tanggalTds)
  271. : this.getDataBankTDS()
  272. );
  273. }
  274.  
  275. this.f.lokasi.setValue(this.currentData.lokasi);
  276. this.f.ketuaTim.setValue(ketuaTim ? ketuaTim : '');
  277. this.f.bankStatus.setValue(this.currentData.isPotensiBankGagal);
  278. this.f.remarksPotensi.setValue(this.currentData.remarkPotensiBankGagal);
  279. this.f.remarksTds.setValue(this.currentData.remarkTanggalTds);
  280. this.f.remarkIndikasiFraud.setValue(this.currentData.remarkIndikasiFraud);
  281. this.f.jenisPemeriksaanId.setValue(
  282. this.currentData.masterJenisPemeriksaanId
  283. );
  284. this.f.bank.setValue(bank ? bank : '');
  285. this.getDetailDocument(this.currentData.repositoryId);
  286.  
  287. this.tempOjk = new Date(this.currentData.tanggalSuratOjk);
  288. this.tempPosisiPemeriksaaan = new Date(
  289. this.currentData.tanggalPosisiPemeriksaan
  290. );
  291. this.tempSuratTugas = new Date(this.currentData.tanggalSuratTugas);
  292. this.tempStart = new Date(this.currentData.tanggalAwalPelaksanaan);
  293. this.tempEnd = new Date(this.currentData.tanggalAkhirPelaksanaan);
  294. this.tempTds = new Date(this.currentData.tanggalTds);
  295. }
  296. }
  297.  
  298. onSubmit() {
  299. // console.log(
  300. // 'check',
  301. // this.detailUjiTuntasComponent,
  302. // this.detailUjiTuntasComponent.valid,
  303. // this.formModel
  304. // );
  305.  
  306.  
  307.  
  308.  
  309. this.submitted = true;
  310. // if (
  311. // this.detailUjiTuntasComponent.invalid &&
  312. // (!this.f.file.value || this.f.file.value.length === 0)
  313. // ) {
  314. // this.errMsgFileNull = true;
  315. // return;
  316. // }
  317.  
  318. // if(this.f.file.value?.length === 0){
  319. // this.errMsgFileNull = true;
  320. // return;
  321. // }
  322.  
  323.  
  324. if(this.functionDialog !== 'Add' ){
  325. if (this.f.bankStatus.value){
  326. if( this.f.remarkIndikasiFraud.value=="" || this.f.remarkIndikasiFraud.value==undefined){
  327. this.isRemarkIndikasiFraud = true
  328. return;
  329. }
  330. }else{
  331. this.isRemarkIndikasiFraud = false;
  332. this.f.remarkIndikasiFraud.setErrors(null)
  333. }
  334. }
  335.  
  336.  
  337. if (this.detailUjiTuntasComponent.invalid) {
  338. return;
  339. } else {
  340. this.isConfirmation = true;
  341. this.errMsgFileNull = false;
  342. }
  343. }
  344.  
  345. updateDate(date) {
  346. if (date) {
  347. date.setDate(date.getDate() + 1);
  348. }
  349. return date;
  350. }
  351.  
  352. ojkDateCheck(date) {
  353. if (this.tempOjk.getDate() === date.getDate()) {
  354. return date;
  355. } else {
  356. return this.updateDate(date);
  357. }
  358. }
  359.  
  360. posisiDateCheck(date) {
  361. if (this.tempPosisiPemeriksaaan.getDate() === date.getDate()) {
  362. return date;
  363. } else {
  364. return this.updateDate(date);
  365. }
  366. }
  367.  
  368. stDateCheck(date) {
  369. if (this.tempSuratTugas.getDate() === date.getDate()) {
  370. return date;
  371. } else {
  372. return this.updateDate(date);
  373. }
  374. }
  375.  
  376. startDateCheck(date) {
  377. if (this.tempStart.getDate() === date.getDate()) {
  378. return date;
  379. } else {
  380. return this.updateDate(date);
  381. }
  382. }
  383.  
  384. endDateCheck(date) {
  385. if (this.tempEnd.getDate() === date.getDate()) {
  386. return date;
  387. } else {
  388. return this.updateDate(date);
  389. }
  390. }
  391.  
  392. tdsDateCheck(date) {
  393. if (this.tempTds.getDate() === date.getDate()) {
  394. return date;
  395. } else {
  396. return this.updateDate(date);
  397. }
  398. }
  399.  
  400. monthBefore(date) {
  401. let newDate = new Date(date.getYear(), date.getMonth(), 1);
  402. return new Date (newDate.setDate(newDate.getDate() - 1));
  403. }
  404.  
  405. doSubmit(id) {
  406. const requestBody = {
  407. id: this.currentData ? this.currentData.id : 0,
  408. isDeleted: false,
  409. bankId: this.f.bank.value.bankId,
  410. bankName: this.f.bank.value.bankName,
  411. bankStatus: this.f.bank.value.statusBank,
  412. nomorSuratOjk: this.f.noSuratPendapatanOjk.value.trim(),
  413. tanggalSuratOjk: this.tempOjk ? this.ojkDateCheck(new Date(this.f.tglSuratMasukOjk.value)) : this.updateDate(new Date(this.f.tglSuratMasukOjk.value)),
  414. tanggalPosisiPemeriksaan: this.tempPosisiPemeriksaaan ? this.posisiDateCheck(new Date(this.f.tglPosisiPemeriksaan.value)) : this.updateDate(new Date(this.f.tglPosisiPemeriksaan.value)),
  415. tanggalAwalPelaksanaan: this.tempStart ? this.startDateCheck(new Date(this.f.tglAwalUjiTuntas.value)) : this.updateDate(new Date(this.f.tglAwalUjiTuntas.value)),
  416. tanggalAkhirPelaksanaan: this.tempEnd ? this.endDateCheck(new Date(this.f.tglAkhirUjiTuntas.value)) : this.updateDate(new Date(this.f.tglAkhirUjiTuntas.value)),
  417. tanggalSuratTugas: this.tempSuratTugas ? this.stDateCheck(new Date(this.f.tglSuratTugas.value)) : this.updateDate(new Date(this.f.tglSuratTugas.value)),
  418. tanggalTds: this.functionDialog !== 'Add' ? this.tempTds ? this.tdsDateCheck(new Date(this.f.tglTds.value)) : this.updateDate(new Date(this.f.tglTds.value)) : '',
  419. nomorSuratTugas: this.f.noSuratTugas.value.trim(),
  420. lokasi: this.f.lokasi.value.trim(),
  421. masterBankUjiTuntasId: 7,
  422. ketuaTimIdString: this.f.ketuaTim.value.userId,
  423. ketuaTimNama: '',
  424. ketuaTimUnitKerja: '',
  425. ketuaTimEmail: '',
  426. isPotensiBankGagal: this.f.bankStatus.value,
  427. remarkPotensiBankGagal: this.f.remarksPotensi.value,
  428. remarkTanggalTds: this.f.remarksTds.value,
  429. masterJenisPemeriksaanId: this.f.jenisPemeriksaanId.value,
  430. repositoryId: id ? id : '',
  431. fileName: this.formModel ? this.formModel?.filename : '',
  432. tanggalMasukStatusBDP: formatDate(this.f.bank.value.tanggalMasukStatusBDP, 'yyyy-MM-dd', 'id-ID'),
  433. batasTanggalPenetapanBdp: formatDate(this.f.bank.value.batasTanggalPenetapanBdp, 'yyyy-MM-dd', 'id-ID'),
  434. bankStatusName: this.f.bank.value.keterangan,
  435. remarkIndikasiFraud : this.f.remarkIndikasiFraud.value
  436. };
  437.  
  438.  
  439. if (this.functionDialog === 'Add') {
  440. this.perencanaanService.postPenugasanUt(requestBody).subscribe(
  441. (res: any) => {
  442. this.snackbar.open(res.detail, res.message, {
  443. duration: 10000,
  444. });
  445.  
  446. if (res.status === 200) {
  447. this.dialogRef.close('Add OK');
  448. }
  449. },
  450. (err: any) => {
  451. console.log('error', err);
  452. this.snackbar.open('Opsss.. ' + err.name, 'Error', {
  453. duration: 10000,
  454. });
  455. }
  456. );
  457. } else {
  458. const id = this.currentData.id;
  459. this.perencanaanService.patchPenugasanUt(id, requestBody).subscribe(
  460. (res: any) => {
  461. this.snackbar.open(res.detail, res.message, {
  462. duration: 10000,
  463. });
  464.  
  465. if (res.status === 200) {
  466. this.dialogRef.close('Edit OK');
  467. }
  468. },
  469. (err: any) => {
  470. console.log('error', err);
  471. this.snackbar.open('Opsss.. ' + err.name, 'Error', {
  472. duration: 10000,
  473. });
  474. }
  475. );
  476. }
  477. }
  478.  
  479. displayKetuaTim(ketuaTim) {
  480. return ketuaTim ? ketuaTim.name : undefined;
  481. }
  482.  
  483. getDetailDocument(id) {
  484. if(id != null){
  485. const dialogConfig = new MatDialogConfig();
  486. dialogConfig.disableClose = true;
  487. dialogConfig.data = {
  488. dialogTitle: 'Converting file',
  489. dialogText: 'Silahkan menunggu...',
  490. isLoading: true,
  491. };
  492. const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
  493.  
  494. this.fileService
  495. .downloadDocumentWithoutDownload(id)
  496. .subscribe((res: any) => {
  497. if (res) {
  498. const file = new File([res.fileBlob], res.fileName, {
  499. type: res.fileType,
  500. });
  501. if (file) {
  502. this.f.file.setValue([file]);
  503. dialogRef.close();
  504. }
  505. }
  506. });
  507. }
  508. }
  509.  
  510. public createSave() {
  511. this.isLoading = true;
  512.  
  513. if (this.formModel.fileContent) {
  514. this.convertFiles()
  515. } else {
  516. this.doSubmit(this.currentData?.repositoryId);
  517. }
  518. }
  519.  
  520. convertFile() {
  521. this.fileService.convertFileBase64Try(this.f.file.value , '' ).subscribe((res) => {
  522. if (res) {
  523. this.formModel = {
  524. fileContent: res.formModel.fileContent,
  525. filename: res.formModel.filename,
  526. fiturId: res.formModel.fiturId,
  527. folderPath: res.formModel.folderPath,
  528. fileSize: res.formModel.fileSize
  529. }
  530. }
  531. }, (error) => {
  532. const dialogConfigError = new MatDialogConfig();
  533. dialogConfigError.disableClose = true;
  534. dialogConfigError.data = {
  535. dialogTitle: 'Gagal Convert File',
  536. dialogText: error.error.detail,
  537. isLoading: false
  538. };
  539. const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  540. });
  541. }
  542.  
  543.  
  544.  
  545. async convertFiles() {
  546. const file = this.f.file.value[0];
  547. const folderBank = this.f.bank.value.bankName.replaceAll(' ' , '-') + '-' + moment( this.f.tglAwalUjiTuntas.value).format('MM') + '-' + moment(this.f.tglAwalUjiTuntas.value).format('yy')
  548. let pathArray = []
  549. let fullPath : any = '';
  550.  
  551. pathArray.push(folderBank);
  552. pathArray.push("Penugasan-uji-tuntas");
  553. pathArray.push("Upload-Files");
  554.  
  555. let tempFile = [];
  556. tempFile.push(file);
  557.  
  558. let resp = await this.fileService.generateFolder(pathArray,0,pathArray.length)
  559. resp.subscribe(
  560. async (res : any) => {
  561. await this.generateFile.state.subscribe(
  562. (fileRes : any) => {
  563. fullPath = fileRes
  564. if(fileRes.index == pathArray.length){
  565. this.fileService.convertFileBase64Try(tempFile , fullPath?.pathTo ).subscribe((res) => {
  566.  
  567. if (res) {
  568. this.formModel = {
  569. fileContent: res.formModel.fileContent,
  570. filename: res.formModel.filename,
  571. fiturId: res.formModel.fiturId,
  572. folderPath: res.formModel.folderPath,
  573. fileSize: res.formModel.fileSize
  574. }
  575. this.fileService.uploadFile(this.formModel).subscribe((res: any) => {
  576. if (res) {
  577. console.log(res.repoId)
  578. this.doSubmit(res?.repoId);
  579. tempFile = []
  580. }
  581. });
  582.  
  583. // dialogRef.close();
  584. }
  585.  
  586. }, (error) => {
  587. // dialogRef.close();
  588. const dialogConfigError = new MatDialogConfig();
  589. dialogConfigError.disableClose = true;
  590. dialogConfigError.data = {
  591. dialogTitle: 'Gagal Convert File',
  592. dialogText: error.error.detail,
  593. isLoading: false
  594. };
  595. const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  596. });
  597.  
  598. }
  599.  
  600. }
  601. )
  602. }
  603. )
  604. }
  605.  
  606. }
  607.  
Add Comment
Please, Sign In to add comment