-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
- Loading branch information
1 parent
c3a010f
commit 926b77b
Showing
12 changed files
with
350 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
projects/admin/src/app/api/patron-transaction-api.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* RERO ILS UI | ||
* Copyright (C) 2022-2023 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 { ApiService } from '@rero/ng-core'; | ||
import { Observable } from 'rxjs'; | ||
import { FeeFormModel } from '../circulation/patron/patron-transactions/patron-fee/patron-fee.component'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PatronTransactionApiService { | ||
|
||
/** | ||
* Constructor | ||
* @param _httpClient - HttpClient | ||
*/ | ||
constructor( | ||
private _httpClient: HttpClient, | ||
private _apiService: ApiService | ||
) {} | ||
|
||
/** | ||
* Add fee | ||
* @return Observable, array of records | ||
*/ | ||
addFee(model: FeeFormModel): Observable<Object> { | ||
return this._httpClient.post(this._apiService.getEndpointByType('patron_transactions/'), model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...admin/src/app/circulation/patron/patron-transactions/patron-fee/patron-fee.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- | ||
RERO ILS UI | ||
Copyright (C) 2022 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/>. | ||
--> | ||
<div *ngIf="form" class="modal show d-block" role="dialog"> | ||
<div class="modal-dialog modal-dialog-centered" role="fee"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" translate>New fee</h5> | ||
</div> | ||
<div class="modal-body"> | ||
<form [formGroup]="form" (ngSubmit)="submit(model)"> | ||
<formly-form [form]="form" [fields]="formFields" [model]="model"></formly-form> | ||
<div class="text-right"> | ||
<a class="btn btn-sm btn-outline-danger mr-1" (click)="closeModal()" translate>Cancel</a> | ||
<button type="submit" class="btn btn-sm btn-primary" [disabled]="!form.valid" translate>Save</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
216 changes: 216 additions & 0 deletions
216
...s/admin/src/app/circulation/patron/patron-transactions/patron-fee/patron-fee.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/* | ||
* RERO ILS UI | ||
* Copyright (C) 2022 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 { getCurrencySymbol } from '@angular/common'; | ||
import { Component, EventEmitter, Input, OnInit } from '@angular/core'; | ||
import { FormGroup } from '@angular/forms'; | ||
import { FormlyFieldConfig } from '@ngx-formly/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { ApiService, RecordService } from '@rero/ng-core'; | ||
import { UserService } from '@rero/shared'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
import { ToastrService } from 'ngx-toastr'; | ||
import { PatronTransactionApiService } from 'projects/admin/src/app/api/patron-transaction-api.service'; | ||
import { OrganisationService } from 'projects/admin/src/app/service/organisation.service'; | ||
|
||
import { DateTime } from 'luxon'; | ||
|
||
@Component({ | ||
selector: 'admin-patron-fee', | ||
templateUrl: './patron-fee.component.html', | ||
styles: ['.p-inputtext { width: 100%; padding: 0 }'] | ||
}) | ||
export class PatronFeeComponent implements OnInit { | ||
|
||
/** Patron pid */ | ||
@Input() patronPid: string; | ||
|
||
/** Organisation pid */ | ||
@Input() organisationPid: string; | ||
|
||
/** form */ | ||
form: FormGroup = new FormGroup({}); | ||
|
||
/** form fields */ | ||
formFields: FormlyFieldConfig[]; | ||
|
||
/** model */ | ||
model: FeeFormModel; | ||
|
||
/** On submit event */ | ||
onSubmit: EventEmitter<any> = new EventEmitter(); | ||
|
||
/** | ||
* Constructor | ||
* @param _recordService - RecordService | ||
* @param _bsModalRef - BsModalRef | ||
* @param _toastr - ToastrService | ||
* @param _translateService - TranslateService | ||
* @param _organisationService - OrganisationService | ||
* @param _userService - UserService | ||
* @param _patronTransactionApiService - PatronTransactionApiService | ||
* @param _apiService - ApiService | ||
*/ | ||
constructor( | ||
private _recordService: RecordService, | ||
private _bsModalRef: BsModalRef, | ||
private _toastr: ToastrService, | ||
private _translateService: TranslateService, | ||
private _organisationService: OrganisationService, | ||
private _userService: UserService, | ||
private _patronTransactionApiService: PatronTransactionApiService, | ||
private _apiService: ApiService | ||
) { } | ||
|
||
/** OnInit Hook */ | ||
ngOnInit(): void { | ||
if (!this.patronPid) { | ||
this.closeModal(); | ||
} | ||
const librarySchema$ = this._recordService.getSchemaForm('patron_transactions'); | ||
librarySchema$.subscribe((schema: any) => { | ||
this._initForm(schema.schema.properties); | ||
}); | ||
} | ||
|
||
/** | ||
* Submit the form | ||
* @param model - Fee model | ||
*/ | ||
submit(model: FeeFormModel): void { | ||
if (model.creation_date instanceof Date) { | ||
model.creation_date = DateTime.fromObject(model.creation_date).toISO(); | ||
} | ||
this._patronTransactionApiService.addFee(model).subscribe( | ||
() => { | ||
this.onSubmit.next('submit'); | ||
this.closeModal(); | ||
this._toastr.success( | ||
this._translateService.instant('Added a new fee.'), | ||
this._translateService.instant('Patron transaction') | ||
); | ||
}, | ||
() => { | ||
this._toastr.error( | ||
this._translateService.instant('An error has occurred. Please try again.'), | ||
this._translateService.instant('Patron transaction'), | ||
{ disableTimeOut: true } | ||
); | ||
} | ||
); | ||
} | ||
|
||
/** Close modal box */ | ||
closeModal(): void { | ||
this._bsModalRef.hide(); | ||
} | ||
|
||
/** Init form model */ | ||
private _initForm(properties: any): void | ||
{ | ||
this.formFields = [ | ||
{ | ||
key: 'type', | ||
type: 'selectWithSort', | ||
templateOptions: { | ||
label: 'Type', | ||
required: true, | ||
options: properties.type.form.options | ||
} | ||
}, | ||
{ | ||
key: 'total_amount', | ||
type: 'input', | ||
templateOptions: { | ||
type: 'number', | ||
label: 'Amount', | ||
required: true, | ||
addonLeft: { | ||
text: getCurrencySymbol(this._organisationService.organisation.default_currency, 'wide') | ||
} | ||
} | ||
}, | ||
{ | ||
key: 'note', | ||
type: 'input', | ||
templateOptions: { | ||
label: 'Note' | ||
} | ||
}, | ||
{ | ||
key: 'creation_date', | ||
type: 'dateTimePicker', | ||
wrappers: ['form-field'], | ||
templateOptions: { | ||
label: 'Date', | ||
required: true, | ||
dateFormat: 'yy-mm-dd', | ||
} | ||
} | ||
]; | ||
|
||
// Default model value | ||
this.model = { | ||
type: null, | ||
total_amount: null, | ||
creation_date: new Date(), | ||
patron: { | ||
$ref: this._apiService.getRefEndpoint('patrons', this.patronPid) | ||
}, | ||
organisation: { | ||
$ref: this._apiService.getRefEndpoint('organisations', this.organisationPid) | ||
}, | ||
library: { | ||
$ref: this._apiService.getRefEndpoint('libraries', this._userService.user.currentLibrary) | ||
}, | ||
status: 'open', | ||
event: { | ||
operator: { | ||
$ref: this._apiService.getRefEndpoint('patrons', this._userService.user.patronLibrarian.pid) | ||
}, | ||
library: { | ||
$ref: this._apiService.getRefEndpoint('libraries', this._userService.user.currentLibrary) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** Interface to define fields on form */ | ||
export interface FeeFormModel { | ||
type: string; | ||
total_amount: number; | ||
note?: string; | ||
creation_date: any; | ||
patron: { | ||
$ref: string; | ||
}, | ||
library: { | ||
$ref: string | ||
} | ||
organisation: { | ||
$ref: string; | ||
}; | ||
status: string; | ||
event: { | ||
operator: { | ||
$ref: string; | ||
}, | ||
library: { | ||
$ref: string | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.