Skip to content

Commit

Permalink
acquisition: rollover
Browse files Browse the repository at this point in the history
* Removes the budget change on the organisation.
* Removes all actions in the budget resource.
* Disables actions on the acquisition resources.
* Fixes the title on receipt order lines.
* Closes rero/rero-ils#2929.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Aug 10, 2022
1 parent 8723e4c commit 14f95b6
Show file tree
Hide file tree
Showing 52 changed files with 1,014 additions and 459 deletions.
16 changes: 8 additions & 8 deletions projects/admin/src/app/acquisition/api/acq-order-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Record, RecordService, RecordUiService } from '@rero/ng-core';
import { BaseApi } from '@rero/shared';
import { Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { Notification } from '../../classes/notification';
Expand All @@ -34,11 +35,9 @@ import {
@Injectable({
providedIn: 'root'
})
export class AcqOrderApiService {
export class AcqOrderApiService extends BaseApi {

// SERVICES ATTRIBUTES ======================================================
/** The resource name of acquisition account */
resourceName = 'acq_orders';

/** Default values */
public readonly orderDefaultData = {
Expand Down Expand Up @@ -77,7 +76,9 @@ export class AcqOrderApiService {
private _http: HttpClient,
private _recordService: RecordService,
private _recordUiService: RecordUiService
) { }
) {
super();
}

// SERVICE PUBLIC FUNCTIONS =================================================
/**
Expand All @@ -86,10 +87,9 @@ export class AcqOrderApiService {
* @return: the corresponding AcqOrder
*/
getOrder(orderPid: string): Observable<IAcqOrder> {
const apiUrl = `/api/${this.resourceName}/${orderPid}`;
return this._http.get<any>(apiUrl).pipe(
map(data => ({...this.orderDefaultData, ...data.metadata}) )
);
return this._recordService.getRecord('acq_orders', orderPid, 0, BaseApi.reroJsonheaders).pipe(
map(data => ({...this.orderDefaultData, ...data.metadata}) )
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Record, RecordService, RecordUiService } from '@rero/ng-core';
import { Observable, of, Subject } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { BaseApi } from '../../../../../shared/src/lib/api/base-api';
import { IAcqOrder } from '../classes/order';
import { IAcqReceipt, IAcqReceiptLine } from '../classes/receipt';
import { AcqResponseReceiptLineStatus, ICreateLineMessage, IResponseReceiptLine } from '../components/receipt/receipt-form/order-receipt';

Expand Down Expand Up @@ -225,6 +224,4 @@ export class AcqReceiptApiService {
}
});
}


}
1 change: 1 addition & 0 deletions projects/admin/src/app/acquisition/classes/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface IAcqOrder extends IAcqBaseResource, IAcqResourceWithNotes {
receipt_date: Date,
}[];
vendor: IObjectReference;
is_current_budget: boolean;
}

// ORDER LINES ================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ng-container *ngIf="organisation && esRecord$ | async as account">
<!-- ROLLOVER INFO -->
<div *ngIf="!account.is_active" class="fiscal-year-closed" translate>Fiscal year closed</div>
<h1 class="mb-3">{{ account.name }}</h1>
<!-- Account general informations -->
<div class="card my-2">
Expand All @@ -24,10 +26,6 @@ <h6 class="card-header" translate>Details</h6>
<dl class="row">
<dt class="col-3 label-title" translate>Account number</dt>
<dd class="col-9">{{ account.number }}</dd>
<dt class="col-3 label-title" translate>Is active</dt>
<dd class="col-9">
<i class="fa fa-circle" [class]="{'text-danger': !account.is_active, 'text-success': account.is_active}"></i>
</dd>
<dt class="col-3 label-title" translate>Budget</dt>
<dd class="col-9">{{ account.budget.pid | getRecord: 'budgets': 'field': 'name' | async }}</dd>
<dt class="col-3 label-title" translate>Library</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
*/

import { Component, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ResultItem } from '@rero/ng-core';

@Component({
selector: 'admin-budgets-brief-view',
template: `
<h5 class="card-title mb-0 rero-ils-person">
<i
class="fa fa-circle mr-2"
[title]="title"
[ngClass]="{'text-success': record.metadata.is_active, 'text-danger': !record.metadata.is_active}"
></i>
<a [routerLink]="[detailUrl.link]" class="pr-1">{{ record.metadata.name }}</a>
</h5>
<ng-container *ngIf="record.metadata.is_active; else inactive">
<i class="fa fa-circle text-success"></i> {{ 'Active' | translate }}
</ng-container>
<ng-template #inactive>
<i class="fa fa-circle text-danger"></i> {{ 'Inactive' | translate }}
</ng-template>
`,
styles: []
})
Expand All @@ -42,4 +42,20 @@ export class BudgetsBriefViewComponent implements ResultItem {
@Input() type: string;
/** The URL to the detail view of the record */
@Input() detailUrl: { link: string, external: boolean };

/**
* Constructor
* @param _translateService - TranslateService
*/
public constructor(private _translateService: TranslateService) {}

/**
* Status of the bugdet on bullet title
* @returns string - status
*/
get title() {
return this.record.metadata.is_active
? this._translateService.instant('Active')
: this._translateService.instant('Inactive');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ng-container *ngIf="record$ | async as record">
<header class="row">
<h1 class="mb-1">{{ record.metadata.name }}</h1>
<!-- ROLLOVER INFO -->
<div *ngIf="!record.metadata.is_active" class="fiscal-year-closed" translate>Fiscal year closed</div>
<header>
<h1>{{ record.metadata.name }}</h1>
</header>
<section>
<dl class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* 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 { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { DetailRecord } from '@rero/ng-core/lib/record/detail/view/detail-record';
import { Observable } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { OrganisationService } from 'projects/admin/src/app/service/organisation.service';
import { Observable, Subscription } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { AcqBudgetApiService } from '../../../api/acq-budget-api.service';

@Component({
selector: 'admin-budget-detail-view',
templateUrl: './budget-detail-view.component.html'
})
export class BudgetDetailViewComponent implements DetailRecord, OnInit {
export class BudgetDetailViewComponent implements DetailRecord, OnInit, OnDestroy {

// COMPONENT ATTRIBUTES =====================================================
/** Record observable */
Expand All @@ -36,12 +36,10 @@ export class BudgetDetailViewComponent implements DetailRecord, OnInit {
/** Budget total allocated amount */
totalAmount = 0;

// GETTER & SETTER ==========================================================
/** Get the current language used for the interface */
get language(): string {
return this._translateService.currentLang;
}
/** all component subscription */
private _subscriptions = new Subscription();

// GETTER & SETTER ==========================================================
/** Get the currency code used for the current loaded organisation */
get currencyCode(): string {
return this._organisationService.organisation.default_currency;
Expand All @@ -50,20 +48,22 @@ export class BudgetDetailViewComponent implements DetailRecord, OnInit {
// CONSTRUCTOR & HOOKS ======================================================
/**
* Constructor
* @param _translateService - TranslateService
* @param _budgetApiService - AcqBudgetApiService
* @param _organisationService - OrganisationService
*/
constructor(
private _translateService: TranslateService,
private _budgetApiService: AcqBudgetApiService,
private _organisationService: OrganisationService
) {}

/** OnInit hook */
ngOnInit() {
this.record$.subscribe(record => {
this._budgetApiService.getBudgetTotalAmount(record.metadata.pid).subscribe(total => this.totalAmount = total);
});
this._subscriptions.add(this.record$.pipe(
switchMap((record: any) => this._budgetApiService.getBudgetTotalAmount(record.metadata.pid))
).subscribe(total => this.totalAmount = total));
}

ngOnDestroy(): void {
this._subscriptions.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ export class OrderBriefViewComponent implements ResultItem, OnInit {
// We only need to keep the notes from itself.
metadata.notes = metadata.notes.filter(note => note.source.type === 'acor');
this.order = metadata;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<!-- Place order button -->
<section *ngIf="order && order.pid" class="float-right mt-2 mr-n4 btn-additional-action">
<section *ngIf="order?.is_current_budget && order?.pid" class="float-right mt-2 mr-n4 btn-additional-action">
<a *ngIf="permissions && permissions.update.can && order.status === acqOrderStatus.PENDING"
(click)="placeOrderDialog()"
class="btn btn-sm btn-primary"
Expand All @@ -28,6 +28,9 @@
</section>

<div *ngIf="order && order.pid" class="container">
<!-- ROLLOVER INFO -->
<div *ngIf="!order.is_current_budget" class="fiscal-year-closed" translate>Fiscal year closed</div>

<h1 class="mb-3">{{ order.reference }}</h1>

<!-- ORDER SUMMARY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
Expand All @@ -46,7 +49,7 @@ <h1 class="mb-3">{{ order.reference }}</h1>
<!-- ORDER DETAIL VIEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<tab heading="{{ 'Order' | translate }}">
<!-- ORDER LINES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<admin-order-lines class="row" [order]="order" [permissions]="permissions"></admin-order-lines>
<admin-order-lines class="row" [order]="order" [permissions]="permissions" *ngIf="isPermissionsLoaded"></admin-order-lines>
<!-- ORDER NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<div class="row mt-3" *ngIf="order.notes && order.notes.length > 0">
<a id="notes"></a>
Expand All @@ -73,8 +76,7 @@ <h5 class="m-0">
</tab>
<!-- RECEIPTS DETAIL VIEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<tab heading="{{ 'Reception' | translate }}" [disabled]="!canViewReceipts">
<admin-receipt-list class="row" [order]="order" [permissions]="permissions" *ngIf="permissions"></admin-receipt-list>
<admin-receipt-list class="row" [order]="order" [permissions]="permissions" *ngIf="isPermissionsLoaded"></admin-receipt-list>
</tab>
</tabset>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ViewportScroller } from '@angular/common';
import { Component, OnInit, ViewChild } from '@angular/core';
import { RecordService, RecordUiService } from '@rero/ng-core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { DetailRecord } from '@rero/ng-core/lib/record/detail/view/detail-record';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { TabsetComponent } from 'ngx-bootstrap/tabs';
import { RecordPermissions } from 'projects/admin/src/app/classes/permissions';
import { RecordPermissionService } from 'projects/admin/src/app/service/record-permission.service';
import { CurrentLibraryPermissionValidator } from 'projects/admin/src/app/utils/permissions';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { AcqOrderStatus, IAcqOrder } from '../../../classes/order';
import { PlaceOrderFormComponent } from '../place-order-form/place-order-form.component';
Expand All @@ -34,7 +32,7 @@ import { PlaceOrderFormComponent } from '../place-order-form/place-order-form.co
templateUrl: './order-detail-view.component.html',
styleUrls: ['./order-detail-view.component.scss']
})
export class OrderDetailViewComponent implements OnInit, DetailRecord {
export class OrderDetailViewComponent implements DetailRecord, OnInit, OnDestroy {

// COMPONENT ATTRIBUTES =====================================================
/** Observable resolving record data */
Expand All @@ -48,11 +46,17 @@ export class OrderDetailViewComponent implements OnInit, DetailRecord {
/** reference to AcqOrderStatus class */
acqOrderStatus = AcqOrderStatus;
/** order permissions */
permissions: RecordPermissions;
permissions?: RecordPermissions;

/** Is permissions loaded */
isPermissionsLoaded = false;

/** modal reference */
private _modalRef: BsModalRef;

/** all component subscription */
private _subscriptions = new Subscription();

// GETTER & SETTER ==========================================================
/** Determine if the order could be "placed/ordered" */
get canPlaceOrder(): boolean {
Expand All @@ -66,16 +70,12 @@ export class OrderDetailViewComponent implements OnInit, DetailRecord {

// CONSTRUCTOR & HOOKS ======================================================
/** Constructor
* @param _recordService - RecordService
* @param _recordUiService - RecordUiService
* @param _scroller - ViewportScroller
* @param _modalService - BsModalService
* @param _recordPermissionService - RecordPermissionService
* @param _permissionValidator - CurrentLibraryPermissionValidator
*/
constructor(
private _recordService: RecordService,
private _recordUiService: RecordUiService,
private _scroller: ViewportScroller,
private _modalService: BsModalService,
private _recordPermissionService: RecordPermissionService,
Expand All @@ -84,12 +84,19 @@ export class OrderDetailViewComponent implements OnInit, DetailRecord {

/** OnInit hook */
ngOnInit() {
this.record$.subscribe(
this._subscriptions.add(this.record$.subscribe(
(record: any) => {
this.order = record.metadata;
this._recordPermissionService.getPermission('acq_orders', this.order.pid)
if (this.order.is_current_budget) {
this._subscriptions.add(this._recordPermissionService.getPermission('acq_orders', this.order.pid)
.pipe(map((permissions) => this._permissionValidator.validate(permissions, this.order.library.pid)))
.subscribe((permissions) => this.permissions = permissions);
.subscribe((permissions) => {
this.permissions = permissions;
this.isPermissionsLoaded = true;
}));
} else {
this.isPermissionsLoaded = true;
}

/* UPDATE 'EDIT' BUTTON
* if the related order has the PENDING status, then a new action 'place order' button should be
Expand All @@ -104,7 +111,12 @@ export class OrderDetailViewComponent implements OnInit, DetailRecord {
}
});
}
);
));
}

/** OnDestroy hook */
ngOnDestroy(): void {
this._subscriptions.unsubscribe();
}

// COMPONENT FUNCTIONS =======================================================
Expand Down
Loading

0 comments on commit 14f95b6

Please sign in to comment.