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

TeamsFinances: Export transaction data in CSV #6805

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
TeamsFinances: Export transaction data in CSV
  • Loading branch information
paulbert committed Jul 10, 2020
commit 95907800fbf03854dd4a7f471374a6aa898605bc
6 changes: 3 additions & 3 deletions src/app/shared/csv.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class CsvService {
}
}

exportCSV({ data, title }: { data: any[], title: string }) {
exportCSV({ data, title, columns }: { data: any[], title: string, columns?: string[] }) {
const options = { title, filename: `Report of ${title} on ${new Date().toDateString()}`, showTitle: true };
const formattedData = data.map(({ _id, _rev, resourceId, type, createdOn, parentCode, data: d, hasInfo, ...dataToDisplay }) => {
return Object.entries(dataToDisplay).reduce(
(object, [ key, value ]: [ string, any ]) => ({ ...object, [markdownToPlainText(key)]: this.formatValue(key, value) }),
return (columns || Object.keys(dataToDisplay)).reduce(
(object, column) => ({ ...object, [markdownToPlainText(column)]: this.formatValue(column, dataToDisplay[column]) }),
{}
);
});
Expand Down
1 change: 1 addition & 0 deletions src/app/teams/teams-view-finances.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="action-buttons">
<button mat-raised-button color="primary" i18n (click)="openEditTransactionDialog()" *ngIf="editable">Add Transaction</button>
<button mat-raised-button color="primary" i18n (click)="exportTransactions()" *ngIf="editable" [disabled]="finances.length === 0">Export Transactions</button>
<mat-form-field>
<input matInput [matDatepicker]="dateFilterStart" [(ngModel)]="startDate" (dateInput)="transactionFilter()" i18n-placeholder placeholder="Pick Start Date">
<mat-datepicker-toggle matSuffix [for]="dateFilterStart"></mat-datepicker-toggle>
Expand Down
11 changes: 11 additions & 0 deletions src/app/teams/teams-view-finances.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DialogsFormService } from '../shared/dialogs/dialogs-form.service';
import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service';
import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.component';
import { millisecondsToDay } from '../meetups/constants';
import { CsvService } from '../shared/csv.service';

@Component({
selector: 'planet-teams-view-finances',
Expand Down Expand Up @@ -38,6 +39,7 @@ export class TeamsViewFinancesComponent implements OnInit, OnChanges {
private planetMessageService: PlanetMessageService,
private dialogsFormService: DialogsFormService,
private dialogsLoadingService: DialogsLoadingService,
private csvService: CsvService,
private dialog: MatDialog
) {
this.couchService.currentTime().subscribe((date) => this.dateNow = date);
Expand Down Expand Up @@ -182,4 +184,13 @@ export class TeamsViewFinancesComponent implements OnInit, OnChanges {
this.emptyTable = this.table.data.length <= 1;
}

exportTransactions() {
const data = this.setTransactionsTable(this.finances).slice(1);
this.csvService.exportCSV({
data,
title: `${this.team.name} Financial Report`,
columns: [ 'date', 'description', 'credit', 'debit', 'balance' ]
});
}

}