110 lines
4.2 KiB
TypeScript
110 lines
4.2 KiB
TypeScript
import { Component, inject, Inject } from '@angular/core';
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
import { AngularMaterialModule } from '../../shared/module/angular-material.module';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { CarnetService } from '../../core/services/carnet/carnet.service';
|
|
import { Fees } from '../../core/models/carnet/fee';
|
|
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
|
|
import { NotificationService } from '../../core/services/common/notification.service';
|
|
|
|
@Component({
|
|
selector: 'app-fees-dialog',
|
|
imports: [AngularMaterialModule, CommonModule, FormsModule],
|
|
template: `
|
|
<h3 mat-dialog-title>Fees and Charges</h3>
|
|
<mat-dialog-content>
|
|
<p> The following fees apply:</p>
|
|
<ul>
|
|
<li *ngIf="estimatedFees.basicFee">Basic fee: {{estimatedFees.basicFee | currency}}</li>
|
|
<li *ngIf="estimatedFees.counterFoilFee">Counterfoil Fee: {{estimatedFees.counterFoilFee | currency}}
|
|
</li>
|
|
<li *ngIf="estimatedFees.continuationSheetFee">Continuation sheet fee:
|
|
{{estimatedFees.continuationSheetFee | currency}}</li>
|
|
<li *ngIf="estimatedFees.expeditedFee">Expedited fee: {{estimatedFees.expeditedFee | currency}}</li>
|
|
<li *ngIf="estimatedFees.shippingFee">Shipping fee: {{estimatedFees.shippingFee | currency}}</li>
|
|
<li *ngIf="estimatedFees.bondPremium">{{bondPremiumLabel}}: {{estimatedFees.bondPremium | currency}}</li>
|
|
<li *ngIf="estimatedFees.cargoPremium">Cargo Premium: {{estimatedFees.cargoPremium | currency}}</li>
|
|
<li *ngIf="estimatedFees.ldiPremium">LDI Premium: {{estimatedFees.ldiPremium | currency}}</li>
|
|
</ul>
|
|
<hr/>
|
|
<p>Additional Charges:</p>
|
|
<ul>
|
|
<li *ngIf="estimatedFees.securityAmount">Security Amount: {{estimatedFees.securityAmount | currency}}</li>
|
|
<li *ngIf="estimatedFees.insuredValue">Insured Value: {{estimatedFees.insuredValue | currency}}</li>
|
|
</ul>
|
|
<hr/>
|
|
<p class="total">Total: {{total | currency}}</p>
|
|
</mat-dialog-content>
|
|
<mat-dialog-actions>
|
|
<button mat-raised-button color="primary" (click)="onClose()">
|
|
Ok
|
|
</button>
|
|
</mat-dialog-actions>
|
|
`,
|
|
styles: [`
|
|
li {
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.total {
|
|
font-weight: bold;
|
|
margin-top: 12px;
|
|
}
|
|
`]
|
|
})
|
|
export class FeesDialogComponent {
|
|
estimatedFees: Fees = {};
|
|
headerid: number | null = null;
|
|
bondPremiumLabel: string = 'Bond Premium';
|
|
total: number = 0;
|
|
|
|
private carnetService = inject(CarnetService);
|
|
private notificationService = inject(NotificationService);
|
|
private errorHandler = inject(ApiErrorHandlerService);
|
|
|
|
constructor(
|
|
public dialogRef: MatDialogRef<FeesDialogComponent>,
|
|
@Inject(MAT_DIALOG_DATA) public data: { headerid: any }
|
|
) {
|
|
this.headerid = data.headerid;
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
if (this.headerid && this.headerid > 0) {
|
|
this.carnetService.getEstimatedFees(this.headerid).subscribe({
|
|
next: (data: Fees) => {
|
|
if (data) {
|
|
this.estimatedFees = data;
|
|
|
|
if (this.estimatedFees.securityType === 'B') {
|
|
this.bondPremiumLabel = 'Bond Premium';
|
|
} else if (this.estimatedFees.securityType === 'C') {
|
|
this.bondPremiumLabel = 'Cash Deposit';
|
|
} else if (this.estimatedFees.securityType === 'G') {
|
|
this.bondPremiumLabel = 'Refundable claim deposit';
|
|
}
|
|
|
|
this.calculateTotal();
|
|
}
|
|
},
|
|
error: (error: any) => {
|
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get estimated fees');
|
|
this.notificationService.showError(errorMessage);
|
|
console.error('Error getting estimated fees:', error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
calculateTotal(): void {
|
|
const validFees = Object.values(this.estimatedFees).filter(
|
|
(fee): fee is number => typeof fee === 'number'
|
|
);
|
|
this.total = validFees.reduce((total, fee) => total + fee, 0);
|
|
}
|
|
|
|
onClose(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
} |