Skip to content

Commit

Permalink
circulation: fix several problems
Browse files Browse the repository at this point in the history
* The patron fees total amount in now returned by the circulation
  informations API. Updates code to reflect this change.
* Creates services to communicate with the backend Loan API to get the
  preview overdue linked to a loan.
* Closes rero/rero-ils#1389

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Mar 5, 2021
1 parent 432b90a commit 51d2903
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 179 deletions.
38 changes: 38 additions & 0 deletions projects/admin/src/app/api/loan-api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';

import { LoanApiService } from './loan-api.service';

describe('LoanApiService', () => {
let service: LoanApiService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
});
service = TestBed.inject(LoanApiService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
44 changes: 44 additions & 0 deletions projects/admin/src/app/api/loan-api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* RERO ILS UI
* Copyright (C) 2021 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { LoanOverduePreview } from '../classes/loans';

@Injectable({
providedIn: 'root'
})
export class LoanApiService {

/**
* Constructor
* @param _http - HttpClient
*/
constructor(
private _http: HttpClient
) {}


/**
* Get the preview overdue fees related to a specific loan
* @param loanPid - string: the Loan pid
*/
getPreviewOverdue(loanPid: string): Observable<LoanOverduePreview> {
const url = `/api/loan/${loanPid}/overdue/preview`;
return this._http.get<LoanOverduePreview>(url);
}
}
20 changes: 7 additions & 13 deletions projects/admin/src/app/circulation/item/item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ItemComponent implements OnInit {
loan: Loan;
/** Is collapsed */
isCollapsed = true;
/** Total amount of fee */
/** Fees related to the item/loan */
totalAmountOfFee = 0;
/** Notifications related to the current loan */
notifications$: Observable<any>;
Expand All @@ -70,10 +70,10 @@ export class ItemComponent implements OnInit {
// CONSTRUCTOR & HOOKS ====================================================
/**
* Constructor
* @param _recordService: Record Service
* @param _organisationService: Organisation Service
* @param _patronTransactionService: Patron transaction Service
* @param _itemService: Item Service
* @param _recordService - Record Service
* @param _organisationService - Organisation Service
* @param _patronTransactionService - Patron transaction Service
* @param _itemService - Item Service
*/
constructor(
private _recordService: RecordService,
Expand All @@ -96,14 +96,8 @@ export class ItemComponent implements OnInit {
}
);
this.notifications$ = this._recordService.getRecords(
'notifications',
`loan.pid:${loanPid}`,
1,
RecordService.MAX_REST_RESULTS_SIZE,
[],
{},
null,
'mostrecent'
'notifications', `loan.pid:${loanPid}`, 1, RecordService.MAX_REST_RESULTS_SIZE,
[], {}, null, 'mostrecent'
).pipe(
map((results: any) => results.hits.hits)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
[routerLinkActiveOptions]="{exact: true}"
[routerLink]="['/circulation', 'patron', patron.patron.barcode[0], 'fees']">
{{ 'Fees' | translate }}
<span *ngIf="transactionsTotalAmount > 0" class="badge badge-warning font-weight-normal">
{{ transactionsTotalAmount | currency: organisation.default_currency }}
<span *ngIf="feesTotalAmount > 0" class="badge badge-warning font-weight-normal">
{{ feesTotalAmount | currency: organisation.default_currency }}
</span>
</a>
</li>
Expand Down
28 changes: 15 additions & 13 deletions projects/admin/src/app/circulation/patron/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export class MainComponent implements OnInit, OnDestroy {

/** the current logged patron */
patron: User = undefined;
/** the total amount of all 'open' patron transactions for the current patron */
transactionsTotalAmount = 0;
/** the total amount of all fees related to the current patron */
feesTotalAmount = 0;

/** Subscription to 'open' patron transactions */
private _patronTransactionSubscription$: Subscription;
/** Subsription to current patron */
/** Subscription to current patron */
private _patronSubscription$: Subscription;
/** Subscription to the fees accounting operation subject (allowing to know if some fees are paid, deleted, ...) */
private _patronFeesOperationSubscription$: Subscription;


// GETTER & SETTER ====================================================
Expand Down Expand Up @@ -130,26 +130,28 @@ export class MainComponent implements OnInit, OnDestroy {
this._unregisterShortcuts();
this._registerShortcuts();
this._patronService.getCirculationInformations(patron.pid).subscribe((data) => {
this.feesTotalAmount = data.fees.engaged + data.fees.preview;
this._parseStatistics(data.statistics || {});
for (const message of (data.messages || [])) {
this.patron.addCirculationMessage(message as any);
}
// subscribe to fees accounting operations for this patron
this._patronFeesOperationSubscription$ = this._patronTransactionService.patronFeesOperationSubject$.subscribe(
(amount) => {
const total = this.feesTotalAmount + amount;
this.feesTotalAmount = (total > 0) ? total : 0;
}
);
});
this._patronTransactionSubscription$ = this._patronTransactionService.patronTransactionsSubject$.subscribe(
(transactions) => {
this.transactionsTotalAmount = this._patronTransactionService.computeTotalTransactionsAmount(transactions);
}
);
this._patronTransactionService.emitPatronTransactionByPatron(patron.pid, undefined, 'open');
}
});
}

/** OnDestroy hook */
ngOnDestroy() {
this._unregisterShortcuts();
if (this._patronTransactionSubscription$) {
this._patronTransactionSubscription$.unsubscribe();
if (this._patronFeesOperationSubscription$) {
this._patronFeesOperationSubscription$.unsubscribe();
}
if (this._patronSubscription$) {
this._patronSubscription$.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
<ul>
<li [class.open-tab]="tabs.engagedFees.isOpen">
<button class="btn btn-link btn-block clearfix" (click)="openTab(tabs.engagedFees)">
<strong translate>Engaged fees</strong>
<ng-container translate>Engaged fees</ng-container>
<span class="badge badge-warning float-right" *ngIf="tabs.engagedFees.totalAmount > 0">
{{ tabs.engagedFees.totalAmount | currency: organisation.default_currency }}
</span>
</button>
</li>
<li [class.open-tab]="tabs.overduePreviewFees.isOpen">
<button class="btn btn-link btn-block clearfix" (click)="openTab(tabs.overduePreviewFees); loadFeesHistory()">
<strong translate>Overdue preview fees</strong>
<ng-container translate>Overdue preview fees</ng-container>
<span class="badge badge-secondary badge-opacity-30 float-right" *ngIf="tabs.overduePreviewFees.totalAmount > 0">
{{ tabs.overduePreviewFees.totalAmount | currency: organisation.default_currency }}
</span>
</button>
</li>
<li [class.open-tab]="tabs.historyFees.isOpen">
<button class="btn btn-link btn-block clearfix" (click)="openTab(tabs.historyFees); loadFeesHistory()">
<strong translate>History</strong>
<ng-container translate>History</ng-container>
</button>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TranslateService } from '@ngx-translate/core';
import { RecordService } from '@rero/ng-core';
import { Record } from '@rero/ng-core/lib/record/record';
import { ToastrService } from 'ngx-toastr';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { UserService } from '@rero/shared';
import { RouteToolService } from '../../routes/route-tool.service';
Expand All @@ -37,6 +37,8 @@ export class PatronTransactionService {

/** subject containing current loaded PatronTransactions */
patronTransactionsSubject$: BehaviorSubject<Array<PatronTransaction>> = new BehaviorSubject([]);
/** subject emitting accounting transaction about patron fees */
patronFeesOperationSubject$: Subject<number> = new Subject();

constructor(
private _recordService: RecordService,
Expand Down Expand Up @@ -192,6 +194,7 @@ export class PatronTransactionService {
record.type = PatronTransactionEventType.PAYMENT;
record.subtype = paymentMethod;
record.amount = amount;
this.patronFeesOperationSubject$.next(0 - amount);
this._createTransactionEvent(record, transaction.patron.pid);
}

Expand All @@ -217,6 +220,7 @@ export class PatronTransactionService {
record.type = PatronTransactionEventType.CANCEL;
record.amount = amount;
record.note = reason;
this.patronFeesOperationSubject$.next(0 - amount);
this._createTransactionEvent(record, transaction.patron.pid);
}

Expand Down
Loading

0 comments on commit 51d2903

Please sign in to comment.