Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/404 - Filter Transaction Types on the Transaction Select screen when committee is PAC #1848

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<h1>{{ this.title }}</h1>
<p *ngIf="this.debtId">Select the proper transaction type below to report this debt repayment.</p>
<p-accordion muiltiple="false">
<p-accordionTab *ngFor="let transactionGroup of getTransactionGroups()" [header]="transactionGroup">
<div class="grid">
<div class="col-12" *ngFor="let transactionType of getTransactionTypes(transactionGroup)">
<a
*ngIf="!isTransactionDisabled(transactionType); else elseBlock"
[routerLink]="getRouterLink(transactionType)"
[queryParams]="debtId ? { debt: debtId } : undefined"
>{{ transactionType | label : transactionTypeLabels }}</a
>
<ng-template #elseBlock>
<div class="disabled">{{ transactionType | label : transactionTypeLabels }}</div></ng-template
>
<ng-container *ngFor="let transactionGroup of getTransactionGroups()">
<p-accordionTab [header]="transactionGroup" *ngIf="hasTransactions(transactionGroup)">
<div class="grid">
<div class="col-12" *ngFor="let transactionType of getTransactionTypes(transactionGroup)">
<a
*ngIf="!isTransactionDisabled(transactionType); else elseBlock"
[routerLink]="getRouterLink(transactionType)"
[queryParams]="debtId ? { debt: debtId } : undefined"
>
{{ transactionType | label: transactionTypeLabels }}
</a>
<ng-template #elseBlock>
<div class="disabled">
{{ transactionType | label: transactionTypeLabels }}
</div>
</ng-template>
</div>
</div>
</div>
</p-accordionTab>
</p-accordionTab>
</ng-container>
</p-accordion>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
Expand All @@ -16,6 +16,8 @@ import { ScheduleDTransactionTypes } from 'app/shared/models/schd-transaction.mo
import { ReportTypes } from 'app/shared/models/report.model';
import { Form24 } from 'app/shared/models/form-24.model';
import { ScheduleETransactionGroups } from 'app/shared/models/sche-transaction.model';
import { isPAC, isPTY } from 'app/shared/models/committee-account.model';
import { ScheduleATransactionGroups, ScheduleATransactionTypes } from 'app/shared/models/scha-transaction.model';

describe('TransactionTypePickerComponent', () => {
let component: TransactionTypePickerComponent;
Expand All @@ -39,6 +41,7 @@ describe('TransactionTypePickerComponent', () => {
params: of({
catalog: 'receipt',
}),
queryParamMap: of({ get: (key: string) => (key === 'param1' ? 'value1' : undefined) }),
},
},
provideMockStore(testMockStore),
Expand Down Expand Up @@ -96,4 +99,30 @@ describe('TransactionTypePickerComponent', () => {
component.category = 'loans-and-debts';
expect(component.getCategoryTitle()).toEqual('Add loans and debts');
});

it('should get committee account', fakeAsync(() => {
component.ngOnInit();
tick(500);
expect(component.committeeAccount).toBeTruthy();
}));

describe('getTransactionTypes', () => {
it('should limit by PACRestricted if Committee type is PAC', fakeAsync(() => {
component.ngOnInit();
tick(500);
if (component.committeeAccount) component.committeeAccount.committee_type = 'O';
expect(isPAC(component.committeeAccount?.committee_type)).toBeTrue();
const types = component.getTransactionTypes(ScheduleATransactionGroups.TRANSFERS);
expect(types.includes(ScheduleATransactionTypes.IN_KIND_TRANSFER_FEDERAL_ELECTION_ACTIVITY)).toBeFalse();
}));

it('should limit by PTYRestricted if Committee type is PTY', fakeAsync(() => {
component.ngOnInit();
tick(500);
if (component.committeeAccount) component.committeeAccount.committee_type = 'X';
expect(isPTY(component.committeeAccount?.committee_type)).toBeTrue();
const types = component.getTransactionTypes(ScheduleATransactionGroups.OTHER);
expect(types.includes(ScheduleATransactionTypes.INDIVIDUAL_RECEIPT_NON_CONTRIBUTION_ACCOUNT)).toBeFalse();
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
ScheduleBTransactionTypes,
} from 'app/shared/models/schb-transaction.model';
import { LabelList } from 'app/shared/utils/label.utils';
import { TransactionTypeUtils, getTransactionTypeClass } from 'app/shared/utils/transaction-type.utils';
import {
PACRestricted,
PTYRestricted,
TransactionTypeUtils,
getTransactionTypeClass,
} from 'app/shared/utils/transaction-type.utils';
import { DestroyerComponent } from 'app/shared/components/app-destroyer.component';
import {
ScheduleCTransactionGroups,
Expand All @@ -34,6 +39,8 @@ import {
ScheduleETransactionTypeLabels,
ScheduleETransactionTypes,
} from 'app/shared/models/sche-transaction.model';
import { selectCommitteeAccount } from 'app/store/committee-account.selectors';
import { CommitteeAccount, isPAC, isPTY } from 'app/shared/models/committee-account.model';

type Categories = 'receipt' | 'disbursement' | 'loans-and-debts';

Expand All @@ -54,16 +61,27 @@ export class TransactionTypePickerComponent extends DestroyerComponent implement
category: Categories = 'receipt';
title: string = this.getCategoryTitle();
debtId?: string;
committeeAccount?: CommitteeAccount;

constructor(private store: Store, private route: ActivatedRoute, private titleService: Title) {
constructor(
private store: Store,
private route: ActivatedRoute,
private titleService: Title,
) {
super();
}

ngOnInit(): void {
combineLatest([this.store.select(selectActiveReport), this.route.params, this.route.queryParamMap])
combineLatest([
this.store.select(selectActiveReport),
this.route.params,
this.route.queryParamMap,
this.store.select(selectCommitteeAccount),
])
.pipe(takeUntil(this.destroy$))
.subscribe(([report, params, queryParamMap]) => {
.subscribe(([report, params, queryParamMap, committeeAccount]) => {
this.report = report;
this.committeeAccount = committeeAccount;
this.category = params['category'];
this.debtId = queryParamMap.get('debt') ?? undefined;
this.title = this.getCategoryTitle();
Expand Down Expand Up @@ -285,6 +303,10 @@ export class TransactionTypePickerComponent extends DestroyerComponent implement
default:
break;
}
if (isPAC(this.committeeAccount?.committee_type))
transactionTypes = transactionTypes.filter((tt) => !PACRestricted().includes(tt));
if (isPTY(this.committeeAccount?.committee_type))
transactionTypes = transactionTypes.filter((tt) => !PTYRestricted().includes(tt));

if (this.debtId) {
const debtPaymentLines = [
Expand All @@ -300,6 +322,10 @@ export class TransactionTypePickerComponent extends DestroyerComponent implement
return transactionTypes;
}

hasTransactions(group: TransactionGroupTypes): boolean {
return this.getTransactionTypes(group).length > 0;
}

isTransactionDisabled(transactionTypeIdentifier: string): boolean {
return !getTransactionTypeClass(transactionTypeIdentifier);
}
Expand Down
13 changes: 13 additions & 0 deletions front-end/src/app/shared/models/committee-account.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ export class CommitteeAccount extends BaseModel {
return plainToClass(CommitteeAccount, json);
}
}

export function isPAC(committee_type?: string): boolean {
if (!committee_type) return false;
return PAC.includes(committee_type);
}

export function isPTY(committee_type?: string): boolean {
if (!committee_type) return false;
return PTY.includes(committee_type);
}

const PAC = ["O", "U", "D", "N", "Q", "V", "W"];
const PTY = ["X", "Y"];
23 changes: 23 additions & 0 deletions front-end/src/app/shared/models/committee-member.model.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { isPAC, isPTY } from './committee-account.model';
import { CommitteeMember } from './committee-member.model';

describe('CommitteeMember', () => {
it('should create an instance', () => {
expect(new CommitteeMember()).toBeTruthy();
});

it('should be created correctly from JSON', () => {
const json = {
role: 'COMMITTEE_ADMINISTRATOR',
Expand All @@ -19,17 +21,38 @@ describe('CommitteeMember', () => {
expect(member.role).toBe(json['role']);
expect(member.is_active).toBe(json['is_active']);
});

it('should return the correct role label when role is not null', () => {
const member = new CommitteeMember();
member.role = 'COMMITTEE_ADMINISTRATOR';
expect(member.getRoleLabel()).toBe('Committee Administrator');
});

it('should return an empty string for a role label if role is null', () => {
expect(new CommitteeMember().getRoleLabel()).toBe('');
});

it('should return an empty string for a label if the role is not present in the LabelList', () => {
const cUser = new CommitteeMember();
cUser.role = "This Isn't a Real Role";
expect(cUser.getRoleLabel()).toBe('');
});

it('should confirm if committee is PAC', () => {
expect(isPAC()).toBeFalse();
const PAC = ['O', 'U', 'D', 'N', 'Q', 'V', 'W'];
PAC.forEach((entry) => {
expect(isPAC(entry)).toBeTrue();
});
expect(isPAC('X')).toBeFalse();
});

it('should confirm if committee is PTY', () => {
expect(isPTY()).toBeFalse();
const PTY = ['X', 'Y'];
PTY.forEach((entry) => {
expect(isPTY(entry)).toBeTrue();
});
expect(isPTY('O')).toBeFalse();
});
});
23 changes: 22 additions & 1 deletion front-end/src/app/shared/utils/transaction-type.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TransactionTypeUtils, getFromJSON } from './transaction-type.utils';
import { ScheduleATransactionTypes } from '../models/scha-transaction.model';
import { PACRestricted, PTYRestricted, TransactionTypeUtils, getFromJSON } from './transaction-type.utils';

describe('LabelUtils', () => {
it('should create an instance', () => {
Expand Down Expand Up @@ -27,4 +28,24 @@ describe('LabelUtils', () => {
scheduleObject = getFromJSON(testJSON);
expect(scheduleObject.constructor.name).toBe('SchETransaction');
});

it('should return list of Transaction Types PAC does not need access to', () => {
[
ScheduleATransactionTypes.IN_KIND_TRANSFER_FEDERAL_ELECTION_ACTIVITY,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_CONVENTION_ACCOUNT,
].forEach((r) => {
expect(PACRestricted().includes(r));
});
});

it('should return list of Transaction Types PTY does not need access to', () => {
[
ScheduleATransactionTypes.INDIVIDUAL_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.OTHER_COMMITTEE_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.BUSINESS_LABOR_NON_CONTRIBUTION_ACCOUNT,
].forEach((r) => {
expect(PTYRestricted().includes(r));
});
});
});
72 changes: 69 additions & 3 deletions front-end/src/app/shared/utils/transaction-type.utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SchATransaction } from 'app/shared/models/scha-transaction.model';
import { SchBTransaction } from '../models/schb-transaction.model';
import { SchATransaction, ScheduleATransactionTypes } from 'app/shared/models/scha-transaction.model';
import { SchBTransaction, ScheduleBTransactionTypes } from '../models/schb-transaction.model';
import { SchCTransaction } from '../models/schc-transaction.model';
import { SchC1Transaction } from '../models/schc1-transaction.model';
import { SchC2Transaction } from '../models/schc2-transaction.model';
import { SchDTransaction } from '../models/schd-transaction.model';
import { SchETransaction } from '../models/sche-transaction.model';
import { ScheduleIds, ScheduleTransaction } from '../models/transaction.model';
import { ScheduleIds, ScheduleTransaction, TransactionTypes } from '../models/transaction.model';

// Schedule A /////////////////////////////////////////////////////
import { TransactionType } from '../models/transaction-type.model';
Expand Down Expand Up @@ -433,3 +433,69 @@ export function getFromJSON(json: any, depth = 2): ScheduleTransaction { // esli
return SchATransaction.fromJSON(json, depth); // Until 404 resolved
// throw new Error('Fecfile: Missing transaction type identifier when creating a transaction object from a JSON record');
}

export function PACRestricted(): TransactionTypes[] {
return [
ScheduleATransactionTypes.IN_KIND_TRANSFER_FEDERAL_ELECTION_ACTIVITY,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.JF_TRANSFER_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.INDIVIDUAL_RECOUNT_RECEIPT,
ScheduleATransactionTypes.PARTY_RECOUNT_RECEIPT,
ScheduleATransactionTypes.PAC_RECOUNT_RECEIPT,
ScheduleATransactionTypes.TRIBAL_RECOUNT_RECEIPT,
ScheduleATransactionTypes.PARTNERSHIP_RECOUNT_ACCOUNT_RECEIPT,
ScheduleATransactionTypes.INDIVIDUAL_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.PARTY_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.PAC_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.TRIBAL_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.PARTNERSHIP_NATIONAL_PARTY_RECOUNT_ACCOUNT,
ScheduleATransactionTypes.INDIVIDUAL_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.PARTY_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.PAC_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.TRIBAL_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.PARTNERSHIP_NATIONAL_PARTY_HEADQUARTERS_ACCOUNT,
ScheduleATransactionTypes.INDIVIDUAL_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.PARTY_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.PAC_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.TRIBAL_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.PARTNERSHIP_NATIONAL_PARTY_CONVENTION_ACCOUNT,
ScheduleATransactionTypes.EARMARK_RECEIPT_FOR_RECOUNT_ACCOUNT_CONTRIBUTION,
ScheduleATransactionTypes.EARMARK_RECEIPT_FOR_CONVENTION_ACCOUNT_CONTRIBUTION,
ScheduleATransactionTypes.EARMARK_RECEIPT_FOR_HEADQUARTERS_ACCOUNT_CONTRIBUTION,
ScheduleBTransactionTypes.RECOUNT_ACCOUNT_DISBURSEMENT,
ScheduleBTransactionTypes.NATIONAL_PARTY_RECOUNT_ACCOUNT_DISBURSEMENT,
ScheduleBTransactionTypes.NATIONAL_PARTY_HEADQUARTERS_ACCOUNT_DISBURSEMENT,
ScheduleBTransactionTypes.NATIONAL_PARTY_CONVENTION_ACCOUNT_DISBURSEMENT,
ScheduleBTransactionTypes.INDIVIDUAL_REFUND_NP_HEADQUARTERS_ACCOUNT,
ScheduleBTransactionTypes.OTHER_COMMITTEE_REFUND_REFUND_NP_HEADQUARTERS_ACCOUNT,
ScheduleBTransactionTypes.TRIBAL_REFUND_NP_HEADQUARTERS_ACCOUNT,
ScheduleBTransactionTypes.INDIVIDUAL_REFUND_NP_CONVENTION_ACCOUNT,
ScheduleBTransactionTypes.OTHER_COMMITTEE_REFUND_REFUND_NP_CONVENTION_ACCOUNT,
ScheduleBTransactionTypes.TRIBAL_REFUND_NP_CONVENTION_ACCOUNT,
ScheduleBTransactionTypes.INDIVIDUAL_REFUND_NP_RECOUNT_ACCOUNT,
ScheduleBTransactionTypes.OTHER_COMMITTEE_REFUND_REFUND_NP_RECOUNT_ACCOUNT,
ScheduleBTransactionTypes.TRIBAL_REFUND_NP_RECOUNT_ACCOUNT,
ScheduleBTransactionTypes.FEDERAL_ELECTION_ACTIVITY_100PCT_PAYMENT,
ScheduleBTransactionTypes.FEDERAL_ELECTION_ACTIVITY_CREDIT_CARD_PAYMENT,
ScheduleBTransactionTypes.FEDERAL_ELECTION_ACTIVITY_STAFF_REIMBURSEMENT,
ScheduleBTransactionTypes.FEDERAL_ELECTION_ACTIVITY_PAYMENT_TO_PAYROLL,
ScheduleBTransactionTypes.FEDERAL_ELECTION_ACTIVITY_VOID,
ScheduleBTransactionTypes.PAC_IN_KIND_OUT
];
}

export function PTYRestricted(): TransactionTypes[] {
return [
ScheduleATransactionTypes.INDIVIDUAL_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.OTHER_COMMITTEE_RECEIPT_NON_CONTRIBUTION_ACCOUNT,
ScheduleATransactionTypes.BUSINESS_LABOR_NON_CONTRIBUTION_ACCOUNT,
ScheduleBTransactionTypes.NON_CONTRIBUTION_ACCOUNT_DISBURSEMENT,
ScheduleBTransactionTypes.NON_CONTRIBUTION_ACCOUNT_CREDIT_CARD_PAYMENT,
ScheduleBTransactionTypes.NON_CONTRIBUTION_ACCOUNT_STAFF_REIMBURSEMENT,
ScheduleBTransactionTypes.NON_CONTRIBUTION_ACCOUNT_PAYMENT_TO_PAYROLL,
ScheduleBTransactionTypes.INDIVIDUAL_REFUND_NON_CONTRIBUTION_ACCOUNT,
ScheduleBTransactionTypes.OTHER_COMMITTEE_REFUND_NON_CONTRIBUTION_ACCOUNT,
ScheduleBTransactionTypes.BUSINESS_LABOR_REFUND_NON_CONTRIBUTION_ACCOUNT,
];
}