ronaldkwandy

Untitled

Aug 2nd, 2020
1,850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, EventEmitter, Output, OnDestroy, ViewChild } from '@angular/core';
  2. import { FormGroup, FormBuilder, FormArray } from '@angular/forms';
  3.  
  4. import { Subject } from 'rxjs';
  5. import { takeUntil } from 'rxjs/operators';
  6.  
  7. import { GaResponse } from '../../../../../gaji-id-resources/gaji-id-api-response.model';
  8. import { MatAccordion } from '@angular/material';
  9.  
  10. import { TunjanganPotonganDetail } from '../../../../../gaji-id-resources/resources/payroll/transaction/tunjangan-potongan/tunjangan-potongan-detail.model';
  11. import { TunjanganPotonganView } from '../../../../../gaji-id-resources/resources/payroll/transaction/tunjangan-potongan/tunjangan-potongan-view.model';
  12. import { TunjanganPotonganViewService, TunjanganPotonganViewSearchParams, TunjanganPotonganViewSorts } from '../../../../../gaji-id-resources/resources/payroll/transaction/tunjangan-potongan/tunjangan-potongan-view.service';
  13.  
  14. import { Employee } from '../../../../../gaji-id-resources/resources/employee/data/employee/employee.model';
  15. import { EmployeeService } from '../../../../../gaji-id-resources/resources/employee/data/employee/employee.service';
  16. import { PayrollGroup } from '../../../../../gaji-id-resources/resources/master/payroll-group/payroll-group.model';
  17. import { PayrollGroupService } from '../../../../../gaji-id-resources/resources/master/payroll-group/payroll-group.service';
  18. import { Position } from '../../../../../gaji-id-resources/resources/master/position/position.model';
  19. import { PositionService } from '../../../../../gaji-id-resources/resources/master/position/position.service';
  20.  
  21. import { ContentAlertService } from '../../../../../components/messages/alerts/content-alert/content-alert.service';
  22. import { ConfirmDialogService } from '../../../../../components/confirm-dialog/confirm-dialog.service';
  23. import { SnackBarService } from '../../../../../components/messages/snackbar/snackbar.service';
  24. import { UiBlockService } from '../../../../../components/ui-block/ui-block.service';
  25.  
  26. import { JExcelComponent } from '../../../../../components/jexcel/jexcel.component';
  27. import { JExcelValidation, JExcelOptions } from '../../../../../components/jexcel/jexcel';
  28.  
  29. @Component({
  30.   selector: 'app-tunjangan-potongan-browse',
  31.   templateUrl: './tunjangan-potongan-browse.component.html'
  32. })
  33. export class TunjanganPotonganBrowseComponent implements OnInit, OnDestroy {
  34.  
  35.   @ViewChild('filterPanel') filterPanel: MatAccordion;
  36.   @ViewChild('jexcel') public jexcel: JExcelComponent;
  37.  
  38.   @Output() public onInputTunjangan: EventEmitter<any> = new EventEmitter();
  39.   @Output() public onInputPotongan: EventEmitter<any> = new EventEmitter();
  40.   @Output() public onEditHapusMassal: EventEmitter<any> = new EventEmitter();
  41.   @Output() public onEdit: EventEmitter<any> = new EventEmitter();
  42.  
  43.   public searchParams: TunjanganPotonganViewSearchParams = {};
  44.   public sorts: TunjanganPotonganViewSorts = { karyawanName: 'asc' };
  45.   public options: JExcelOptions;
  46.   public isLoadingResults: boolean = false;
  47.  
  48.   public dataTables: TunjanganPotonganView[];
  49.   public customBrowseTbl: any[];
  50.  
  51.   public employeeList: Employee[] = [];
  52.   public mstPayrollGroups: PayrollGroup[] = [];
  53.   public mstPositions: Position[] = [];
  54.   public filterForm: FormGroup;
  55.   private ngUnsubscribe: Subject<boolean> = new Subject();
  56.  
  57.   constructor(
  58.     private fb: FormBuilder,
  59.     private contentAlertService: ContentAlertService,
  60.     private confirmDialogService: ConfirmDialogService,
  61.     private uiBlockService: UiBlockService,
  62.     private employeeService: EmployeeService,
  63.     private payrollGroupService: PayrollGroupService,
  64.     private positionService: PositionService,
  65.     private tunjanganPotonganViewService: TunjanganPotonganViewService
  66.   ) { }
  67.  
  68.   ngOnInit() {
  69.     this.initFilterForm();
  70.     this.initOptions();
  71.     this.initPayrollGroups();
  72.     this.initPositions();
  73.     this.filter();
  74.     this.jexcel.setSpreadsheet(this.options, this.customBrowseTbl, false);
  75.   }
  76.  
  77.   public ngOnDestroy() {
  78.     this.ngUnsubscribe.next(true);
  79.     this.ngUnsubscribe.complete();
  80.   }
  81.  
  82.   private initFilterForm() {
  83.     this.filterForm = this.fb.group({
  84.       karyawan: null,
  85.       mstPayrollGroup: null,
  86.       mstPosition: null,
  87.       beginYearMonth: null,
  88.       endYearMonth: null,
  89.     });
  90.   }
  91.  
  92.   private initOptions() {
  93.     this.options = {
  94.       columns: [
  95.         { type: 'text', columnName: 'karyawan.name', headerText: 'Karyawan', validations: [], readOnly: true },
  96.         { type: 'yearmonth', columnName: 'tahunBulanGaji', headerText: 'Bulan', validations: [], readOnly: true }
  97.       ],
  98.       editable: false,
  99.       columnResize: true,
  100.       allowInsertColumn: false,
  101.       allowInsertRow: false,
  102.       allowManualInsertColumn: false,
  103.       allowManualInsertRow: false,
  104.       allowDeleteColumn: false,
  105.       allowDeleteRow: false,
  106.       toolbar: false
  107.     };
  108.   }
  109.  
  110.   public onKaryawanLazyLoad(name: string) {
  111.     this.isLoadingResults = true;
  112.     this.employeeService.search({ name: name })
  113.       .pipe(takeUntil(this.ngUnsubscribe))
  114.       .subscribe(
  115.         (result) => {
  116.           this.isLoadingResults = false;
  117.           this.employeeList = result.data;
  118.         },
  119.         (error) => {
  120.           this.isLoadingResults = false;
  121.           this.contentAlertService.error(error.errors);
  122.         },
  123.         () => { this.isLoadingResults = false; }
  124.       );
  125.   }
  126.  
  127.   private initPayrollGroups() {
  128.     this.uiBlockService.showUiBlock();
  129.     this.payrollGroupService.search({ isActive: true }).pipe(takeUntil(this.ngUnsubscribe)).subscribe(
  130.       (result) => {
  131.         this.uiBlockService.hideUiBlock();
  132.         this.mstPayrollGroups = result.data;
  133.       },
  134.       (error) => {
  135.         this.uiBlockService.hideUiBlock();
  136.         this.contentAlertService.error(error.errors);
  137.       },
  138.       () => { this.uiBlockService.hideUiBlock(); }
  139.     );
  140.   }
  141.  
  142.   private initPositions() {
  143.     this.uiBlockService.showUiBlock();
  144.     this.positionService.search({ active: true }).pipe(takeUntil(this.ngUnsubscribe)).subscribe(
  145.       (result) => {
  146.         this.uiBlockService.hideUiBlock();
  147.         this.mstPositions = result.data;
  148.       },
  149.       (error) => {
  150.         this.uiBlockService.hideUiBlock();
  151.         this.contentAlertService.error(error.errors);
  152.       },
  153.       () => { this.uiBlockService.hideUiBlock(); }
  154.     );
  155.   }
  156.  
  157.   public addTunjangan() {
  158.     this.onInputTunjangan.next();
  159.   }
  160.  
  161.   public addPotongan() {
  162.     this.onInputPotongan.next();
  163.   }
  164.  
  165.   public editMassal() {
  166.     this.onEditHapusMassal.next();
  167.   }
  168.  
  169.   public edit() {
  170.     this.onEdit.next();
  171.   }
  172.  
  173.   public filter() {
  174.     this.filterPanel.closeAll();
  175.  
  176.     var karyawanIdFilter = null;
  177.     var mstPayrollGroupIdFilter = null;
  178.     var karyawanPositionIdFilter = null;
  179.  
  180.     if (this.filterForm.value.karyawan) {
  181.       karyawanIdFilter = this.filterForm.value.karyawan.id;
  182.     }
  183.  
  184.     if (this.filterForm.value.mstPayrollGroup) {
  185.       mstPayrollGroupIdFilter = this.filterForm.value.mstPayrollGroup.id;
  186.     }
  187.  
  188.     if (this.filterForm.value.mstPosition) {
  189.       karyawanPositionIdFilter = this.filterForm.value.mstPosition.id;
  190.     }
  191.  
  192.     if ((this.filterForm.value.beginYearMonth) && (this.filterForm.value.endYearMonth)) {
  193.       this.searchParams = {
  194.         karyawanId: karyawanIdFilter,
  195.         kelompokPayrollId: mstPayrollGroupIdFilter,
  196.         karyawanPositionId: karyawanPositionIdFilter,
  197.         tahunBulanGajiFrom: this.filterForm.value.beginYearMonth,
  198.         tahunBulanGajiTo: this.filterForm.value.endYearMonth
  199.       };
  200.     }
  201.  
  202.     this.uiBlockService.showUiBlock();
  203.     this.tunjanganPotonganViewService
  204.       .searchView(this.searchParams, this.sorts)
  205.       .pipe(takeUntil(this.ngUnsubscribe))
  206.       .subscribe(
  207.         (result: GaResponse<TunjanganPotonganView[]>) => {
  208.           this.uiBlockService.hideUiBlock();
  209.  
  210.           this.dataTables = result.data;
  211.           this.customBrowseTbl = [];
  212.           this.initOptions();
  213.           var listHeader = {};
  214.           for (let i = 0; i < result.data.length; i++) {
  215.             const dataTblRow: any = {};
  216.             dataTblRow.karyawan = result.data[i].karyawan;
  217.             dataTblRow.tahunBulanGaji = result.data[i].tahunBulanGaji;
  218.             for (let j = 0; j < result.data[i].listPendapatanPotonganKaryawan.length; j++) {
  219.               const newHeaderName = result.data[i].listPendapatanPotonganKaryawan[j].pendapatanPotongan.name;
  220.               const newHeaderCode = result.data[i].listPendapatanPotonganKaryawan[j].pendapatanPotongan.code;
  221.               const newHeaderValue = result.data[i].listPendapatanPotonganKaryawan[j].totalNilaiAkhir;
  222.               dataTblRow[newHeaderCode] = newHeaderValue;
  223.               if (!listHeader[newHeaderName]) {
  224.                 listHeader[newHeaderName] = newHeaderName;
  225.                 this.options.columns.push({ type: 'numeric', columnName: newHeaderCode, headerText: newHeaderName, validations: [], readOnly: true });
  226.               }
  227.             }
  228.  
  229.             this.customBrowseTbl.push(dataTblRow);
  230.           }
  231.           this.jexcel.updateSettings(this.options, this.customBrowseTbl, false);
  232.         },
  233.         (error) => {
  234.           this.uiBlockService.hideUiBlock();
  235.           this.contentAlertService.error(error.errors);
  236.         },
  237.         () => { this.uiBlockService.hideUiBlock(); }
  238.       );
  239.   }
  240. }
  241.  
Advertisement
Add Comment
Please, Sign In to add comment