diff --git a/src/app/shared/debit-credit.pipe.ts b/src/app/shared/debit-credit.pipe.ts new file mode 100644 index 0000000..f950539 --- /dev/null +++ b/src/app/shared/debit-credit.pipe.ts @@ -0,0 +1,40 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { Account } from './account'; + +@Pipe({name: 'debitCredit'}) +export class DebitCreditPipe implements PipeTransform { + debitNames: any; + creditNames: any; + + + constructor() { + this.debitNames = { + 'Assets': 'Deposit', + 'Liabilities': 'Payment', + 'Equity': 'Decrease', + 'Income': 'Deduction', + 'Expenses': 'Expense' + }; + + this.creditNames = { + 'Assets': 'Withdrawal', + 'Liabilities': 'Charge', + 'Equity': 'Increase', + 'Income': 'Income', + 'Expenses': 'Refund' + }; + } + + transform(account: Account, type: string): string { + if(!account) { + return type === 'credit' ? 'Credit' : 'Debit'; + } + + let parent = account.fullName.split(':')[0]; + if(type === 'credit') { + return this.creditNames[parent]; + } else { + return this.debitNames[parent]; + } + } +} \ No newline at end of file diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 443284f..5f37e3e 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -4,11 +4,12 @@ import { CurrencyFormatPipe } from './currency-format.pipe'; import { AccountNamePipe } from './account-name.pipe'; import { AccountBalancePipe } from './account-balance.pipe'; import { DateTzPipe } from './datetz.pipe'; +import { DebitCreditPipe } from './debit-credit.pipe'; @NgModule({ imports: [], - declarations: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe], - exports: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe], + declarations: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe, DebitCreditPipe], + exports: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe, DebitCreditPipe], providers: [DecimalPipe, CurrencyFormatPipe] }) export class SharedModule { } \ No newline at end of file diff --git a/src/app/transaction/list.html b/src/app/transaction/list.html index f3fccd8..d6421de 100644 --- a/src/app/transaction/list.html +++ b/src/app/transaction/list.html @@ -19,10 +19,10 @@ Transfer
- Debit + {{account | debitCredit:'debit'}}
- Credit + {{account | debitCredit:'credit'}}
Balance