Skip to content

Commit e1c074b

Browse files
add: tax deductible boolean to funds (#70)
* add: tax deductible boolean to funds * filter out tax deductible funds for summaries
1 parent a4d9b1c commit e1c074b

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/models/Fund.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export class Fund {
22
public id?: string;
33
public churchId?: string;
44
public name?: string;
5+
public taxDeductible?: boolean;
56
public productId?: string;
67
public amount?: number;
78
}

src/repositories/DonationRepository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class DonationRepository {
5656
const sql = "SELECT d.*, f.id as fundId, f.name as fundName, fd.amount as fundAmount"
5757
+ " FROM donations d"
5858
+ " INNER JOIN fundDonations fd on fd.donationId = d.id"
59-
+ " INNER JOIN funds f on f.id = fd.fundId"
59+
+ " INNER JOIN funds f on f.id = fd.fundId AND f.taxDeductible = 1"
6060
+ " WHERE d.churchId = ? AND d.personId = ?"
6161
+ " ORDER BY d.donationDate DESC";
6262
return DB.query(sql, [churchId, personId]);
@@ -69,7 +69,7 @@ export class DonationRepository {
6969
const sql = "SELECT STR_TO_DATE(concat(year(d.donationDate), ' ', week(d.donationDate, 0), ' Sunday'), '%X %V %W') AS week, SUM(fd.amount) as totalAmount, f.name as fundName"
7070
+ " FROM donations d"
7171
+ " INNER JOIN fundDonations fd on fd.donationId = d.id"
72-
+ " INNER JOIN funds f on f.id = fd.fundId"
72+
+ " INNER JOIN funds f on f.id = fd.fundId AND f.taxDeductible = 1"
7373
+ " WHERE d.churchId=?"
7474
+ " AND d.donationDate BETWEEN ? AND ?"
7575
+ " GROUP BY year(d.donationDate), week(d.donationDate, 0), f.name"
@@ -81,7 +81,7 @@ export class DonationRepository {
8181
const sql = "SELECT d.personId, d.amount as donationAmount, fd.fundId, fd.amount as fundAmount, f.name as fundName"
8282
+ " FROM donations d"
8383
+ " INNER JOIN fundDonations fd on fd.donationId = d.id"
84-
+ " INNER JOIN funds f on f.id = fd.fundId"
84+
+ " INNER JOIN funds f on f.id = fd.fundId AND f.taxDeductible = 1"
8585
+ " WHERE d.churchId=?"
8686
+ " AND d.donationDate BETWEEN ? AND ?";
8787
return DB.query(sql, [churchId, DateHelper.toMysqlDate(startDate), DateHelper.toMysqlDate(endDate)]);

src/repositories/FundRepository.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export class FundRepository {
2222

2323
private async create(fund: Fund) {
2424
fund.id = UniqueIdHelper.shortId();
25-
const sql = "INSERT INTO funds (id, churchId, name, productId, removed) VALUES (?, ?, ?, ?, 0);";
26-
const params = [fund.id, fund.churchId, fund.name, fund.productId];
25+
const sql = "INSERT INTO funds (id, churchId, name, taxDeductible, productId, removed) VALUES (?, ?, ?, ?, ?, 0);";
26+
const params = [fund.id, fund.churchId, fund.name, fund.taxDeductible, fund.productId];
2727
await DB.query(sql, params);
2828
return fund;
2929
}
3030

3131
private async update(fund: Fund) {
32-
const sql = "UPDATE funds SET name=?, productId=? WHERE id=? and churchId=?";
33-
const params = [fund.name, fund.productId, fund.id, fund.churchId];
32+
const sql = "UPDATE funds SET name=?, taxDeductible=?, productId=? WHERE id=? and churchId=?";
33+
const params = [fund.name, fund.taxDeductible, fund.productId, fund.id, fund.churchId];
3434
await DB.query(sql, params);
3535
return fund;
3636
}
@@ -48,7 +48,7 @@ export class FundRepository {
4848
}
4949

5050
public convertToModel(churchId: string, data: any) {
51-
const result: Fund = { id: data.id, name: data.name, churchId: data.churchId, productId: data.productId };
51+
const result: Fund = { id: data.id, name: data.name, churchId: data.churchId, productId: data.productId, taxDeductible: data.taxDeductible };
5252
return result;
5353
}
5454

tools/dbScripts/funds.mysql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE TABLE `funds` (
44
`id` char(11) NOT NULL,
55
`churchId` char(11) DEFAULT NULL,
66
`name` varchar(50) DEFAULT NULL,
7+
`taxDeductible` bit(1) DEFAULT NULL,
78
`productId` varchar(50) DEFAULT Null,
89
`removed` bit(1) DEFAULT NULL,
910
PRIMARY KEY (`id`)

0 commit comments

Comments
 (0)