Skip to content

Commit

Permalink
fee
Browse files Browse the repository at this point in the history
  • Loading branch information
nbittich committed Jan 27, 2024
1 parent 6dc7a4e commit 82812b3
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AdministrativeDocumentService } from '@core/service/administrative-docu
import { AdministrativeDocument } from '@core/models/administrative-document';
import { DocumentEditorComponent } from '@feature/administrative-document/document-editor/document-editor.component';
import { FileService } from '@core/service/file.service';
import { User } from '@core/models/user';

@Component({
selector: 'app-dossier-form',
Expand All @@ -36,6 +37,11 @@ export class DossierFormComponent implements OnInit, OnDestroy {
recallForModification: boolean = false;
@Input()
labels: Label[];
@Input()
user: User;
get hasRoleAdmin(): boolean {
return this.user.authorities.includes('ADMIN');
}
searchExpense: string;

vatTotal: number = 0;
Expand Down Expand Up @@ -294,6 +300,7 @@ export class DossierFormComponent implements OnInit, OnDestroy {

openFeeDetail(f: Fee) {
const modalRef = this.modalService.open(FeeDetailComponent, { size: 'xl' });
modalRef.componentInstance.user = this.user;
modalRef.componentInstance.fee = f;
}

Expand Down
16 changes: 8 additions & 8 deletions src/app/features/fee/fee-detail/fee-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
fee.subject | titlecase
}}
<ng-container *ngIf="fee.imported">
<ng-template #infoFrontend>
Imported on {{fee.importedDate | date:'dd/MM/yyyy HH:mm'}}
</ng-template>
<button (click)="$event.stopPropagation();" type="button" class="ps-0 ms-0 me-0 btn btn-link text-dark"
<ng-template #infoFrontend> Imported on {{ fee.importedDate | date: 'dd/MM/yyyy HH:mm' }} </ng-template>
<button (click)="$event.stopPropagation()" type="button" class="ps-0 ms-0 me-0 btn btn-link text-dark"
[ngbTooltip]="infoFrontend" triggers="click:blur">
<fa-icon [icon]="['fas', 'info-circle']"></fa-icon>
</button>
Expand Down Expand Up @@ -65,7 +63,8 @@
{{ a.originalFilename }}
</button>
<div class="btn-group">
<button class="btn btn-link" [disabled]="fee.attachmentIds.length <= 1 || fee.archived"
<button *ngIf="hasRoleAdmin" class="btn btn-link"
[disabled]="fee.attachmentIds.length <= 1 || fee.archived"
(click)="removeAttachment($event, a)">
<fa-icon [icon]="['fas', 'times']" class="text-danger"></fa-icon>
</button>
Expand All @@ -86,16 +85,17 @@
<a ngbNavLink>Costs</a>
<ng-template ngbNavContent>
<div class="mt-2">
<app-update-price [fee]="fee" (updatePriceSubmitted)="updatePrice($event)"></app-update-price>
<app-update-price [fee]="fee" [user]="user"
(updatePriceSubmitted)="updatePrice($event)"></app-update-price>
</div>
</ng-template>
</li>
<li ngbNavItem>
<a ngbNavLink>Tag</a>
<ng-template ngbNavContent>
<div class="mt-2">
<app-tag-form [hideCancelButton]="true" [selectedTag]="fee.tagId" [tags]="tags"
(tagSubmitted)="updateTag(fee, $event)" [isDisabled]="fee.archived"></app-tag-form>
<app-tag-form [hideCancelButton]="true" [selectedTag]="fee.tagId" [tags]="tags" [user]="user"
(tagSubmitted)="updateTag(fee, $event)" [isDisabled]="fee.archived || !hasRoleAdmin"></app-tag-form>
</div>
</ng-template>
</li>
Expand Down
21 changes: 18 additions & 3 deletions src/app/features/fee/fee-detail/fee-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ImageViewerComponent } from '@shared/image-viewer/image-viewer.componen
import { LabelService } from '@core/service/label.service';
import { ToastService } from '@core/service/toast.service';
import { firstValueFrom } from 'rxjs';
import { User } from '@core/models/user';

@Component({
selector: 'app-fee-detail',
Expand All @@ -20,16 +21,21 @@ export class FeeDetailComponent implements OnInit {
fee: Fee;
@Output()
feeUpdated: EventEmitter<Fee> = new EventEmitter<Fee>();
@Input()
user: User;

get hasRoleAdmin(): boolean {
return this.user.authorities.includes('ADMIN');
}
tags: Label[];
constructor(
@Optional() public activeModal: NgbActiveModal,
private feeService: FeeService,
private labelService: LabelService,
private modalService: NgbModal,
private toastService: ToastService,
private fileService: FileService
) {}
private fileService: FileService,
) { }

ngOnInit(): void {
this.load();
Expand All @@ -48,7 +54,7 @@ export class FeeDetailComponent implements OnInit {
this.tags = labels;
}

downloadAttachment(evt, a: FileUpload) {
downloadAttachment(evt: any, a: FileUpload) {
evt.stopPropagation();
this.fileService.download(a);
}
Expand All @@ -64,6 +70,9 @@ export class FeeDetailComponent implements OnInit {

removeAttachment($event: MouseEvent, a: FileUpload) {
$event.stopPropagation();
if (!this.hasRoleAdmin) {
return;
}
this.feeService.removeAttachment(this.fee.id, a.id).subscribe((f) => {
this.feeUpdated.emit(f);
this.fee = f;
Expand Down Expand Up @@ -98,6 +107,9 @@ export class FeeDetailComponent implements OnInit {
}

updatePrice(request: FeeUpdatePriceRequest) {
if (!this.hasRoleAdmin) {
return;
}
this.feeService.updatePrice(request.id, request.priceHVAT, request.vat).subscribe((f) => {
this.fee = f;
this.load();
Expand All @@ -107,6 +119,9 @@ export class FeeDetailComponent implements OnInit {
}

updateTag(fee: Fee, $event: Label) {
if (!this.hasRoleAdmin) {
return;
}
this.feeService.updateTag([fee.id], $event).subscribe((data) => {
if (data?.length !== 1) {
console.error('response not equals to 1!!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
</div>
</div>
<div class="d-block">
<app-tag-form [tags]="tags" (tagSubmitted)="saveTag($event)" *ngIf="showTagForm && selectedRows.length">
<app-tag-form [user]="user" [tags]="tags" (tagSubmitted)="saveTag($event)"
*ngIf="showTagForm && selectedRows.length">
</app-tag-form>
</div>
<div class="d-block pb-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class FeeTableResultComponent implements OnInit, OnApplicationEvent {
scrollable: true,
backdrop: 'static',
});
modalRef.componentInstance.user = this.user;
modalRef.componentInstance.fee = f;
modalRef.componentInstance.feeUpdated.subscribe((_f: any) => {
this.load();
Expand Down
12 changes: 3 additions & 9 deletions src/app/features/fee/tag-form/tag-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
<div class="card-body">
<div class="mb-1">
<label for="tagSelect">Select a tag &nbsp;</label>
<select
class="form-select"
id="tagSelect"
[(ngModel)]="selectedTag"
name="tagSelect"
required="required"
[disabled]="isDisabled"
>
<select class="form-select" id="tagSelect" [(ngModel)]="selectedTag" name="tagSelect" required="required"
[disabled]="isDisabled">
<option *ngFor="let t of tags" [ngValue]="t.id">{{ t.name | titlecase }}</option>
</select>
</div>
<div class="d-flex justify-content-end">
<div class="d-flex justify-content-end" *ngIf="hasRoleAdmin">
<button (click)="submit()" class="btn btn-primary mt-1 me-1" [disabled]="!selectedTag || isDisabled">
<fa-icon [icon]="['fas', 'check']"></fa-icon>
Set
Expand Down
14 changes: 11 additions & 3 deletions src/app/features/fee/tag-form/tag-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Label } from '@core/models/fee';
import { User } from '@core/models/user';

@Component({
selector: 'app-tag-form',
Expand All @@ -20,12 +21,19 @@ export class TagFormComponent implements OnInit {
isDisabled: boolean;
@Input()
hideCancelButton: boolean;
@Input()
user: User;
get hasRoleAdmin(): boolean {
return this.user.authorities.includes('ADMIN');
}
constructor() { }

constructor() {}

ngOnInit(): void {}
ngOnInit(): void { }

submit() {
if (!this.hasRoleAdmin) {
return;
}
if (this.selectedTag) {
const tag = this.tags.find((l) => l.id === this.selectedTag);
this.tagSubmitted.emit(tag);
Expand Down
8 changes: 4 additions & 4 deletions src/app/features/fee/update-price/update-price.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<form [formGroup]="form" (submit)="submit()">
<div class="mb-1">
<label for="priceHVat">Price HVAT</label>
<input type="number" class="form-control" formControlName="priceHVat" id="priceHVat" name="priceHVat">
<input type="number" class="form-control" formControlName="priceHVat" id="priceHVat" name="priceHVat" />
</div>
<div class="mb-1">
<label for="vat">VAT</label>
<input type="number" class="form-control" formControlName="vat" id="vat" name="vat">
<input type="number" class="form-control" formControlName="vat" id="vat" name="vat" />
</div>
<div class="d-flex justify-content-end">
<p class="text-danger">Total VAT incl.: {{priceHVat + vat | currency:'€'}}</p>
<p class="text-danger">Total VAT incl.: {{ priceHVat + vat | currency: '€' }}</p>
</div>
<div class="d-flex justify-content-end">
<div class="d-flex justify-content-end" *ngIf="hasRoleAdmin">
<button class="btn btn-primary" type="submit" [disabled]="!form.valid">Submit</button>
<span class="text-success my-auto" *ngIf="saved">&nbsp;Saved!</span>
</div>
Expand Down
17 changes: 14 additions & 3 deletions src/app/features/fee/update-price/update-price.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Fee, FeeUpdatePriceRequest } from '@core/models/fee';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { User } from '@core/models/user';

@Component({
selector: 'app-update-price',
Expand All @@ -11,18 +12,28 @@ export class UpdatePriceComponent implements OnInit {
@Input()
fee: Fee;

@Input()
user: User;
get hasRoleAdmin(): boolean {
return this.user.authorities.includes('ADMIN');
}
@Output()
updatePriceSubmitted: EventEmitter<FeeUpdatePriceRequest> = new EventEmitter<FeeUpdatePriceRequest>();
form: UntypedFormGroup;
saved: boolean;

constructor(private fb: UntypedFormBuilder) {}
constructor(private fb: UntypedFormBuilder) { }

ngOnInit(): void {
this.form = this.fb.group({
id: new UntypedFormControl({ value: this.fee.id, disabled: true }, [Validators.required]),
priceHVat: new UntypedFormControl({ value: this.fee.priceHVAT, disabled: this.fee?.archived }, [Validators.required]),
vat: new UntypedFormControl({ value: this.fee.vat, disabled: this.fee?.archived }, [Validators.required]),
priceHVat: new UntypedFormControl(
{ value: this.fee.priceHVAT, disabled: this.fee?.archived || !this.hasRoleAdmin },
[Validators.required],
),
vat: new UntypedFormControl({ value: this.fee.vat, disabled: this.fee?.archived || !this.hasRoleAdmin }, [
Validators.required,
]),
priceTot: new UntypedFormControl({ value: this.fee.priceTot, disabled: true }, [Validators.required]),
});
}
Expand Down

0 comments on commit 82812b3

Please sign in to comment.