diff --git a/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.html b/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.html index 21f52ff..604a96e 100644 --- a/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.html +++ b/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.html @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.ts b/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.ts index 72b2db9..26e973a 100644 --- a/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.ts +++ b/Client/src/app/components/contributor-all-reports/contributor-all-reports.component.ts @@ -1,5 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { PrintService } from 'src/app/services/print-service'; +import { UserService } from 'src/app/services/user.service'; +import { TransactionService } from 'src/app/services/transaction.service'; +import { forkJoin } from 'rxjs'; @Component({ selector: 'app-contributor-all-reports', @@ -8,14 +11,36 @@ import { PrintService } from 'src/app/services/print-service'; }) export class ContributorAllReportsComponent implements OnInit { - public contributors: number[] = []; + public contributors: {contributor:{}, transactions:[]}[] = []; - constructor(private printService: PrintService) { } + constructor(private printService: PrintService, private userService: UserService, private transactionService: TransactionService) { } ngOnInit() { - this.contributors.push(1); - this.contributors.push(2); + const query = forkJoin([this.userService.getAll(), this.transactionService.getByYear(2019)]); + + + query.subscribe(res => this.setup(res[0], res[1])); + this.printService.setPrinting(true); } + private setup(contributorResult, transactionResult) { + const contributors = contributorResult.users; + const transactions = transactionResult.transactions; + const contrib = {}; + transactions.forEach(t => { + if (contrib.hasOwnProperty(t.contributorId)) { + contrib[t.contributorId].transactions.push(t); + } else { + const con = contributors.find(c => c.id === t.contributorId); + if (con) { + contrib[con.id] = {contributor: con, transactions: [t]}; + this.contributors.push(contrib[con.id]); + } else { + console.error('coould not find contributor for', t); + } + } + }); + } + } diff --git a/Client/src/app/components/contributor-yearly-report/contributor-yearly-report.component.ts b/Client/src/app/components/contributor-yearly-report/contributor-yearly-report.component.ts index 1b5229f..06d3013 100644 --- a/Client/src/app/components/contributor-yearly-report/contributor-yearly-report.component.ts +++ b/Client/src/app/components/contributor-yearly-report/contributor-yearly-report.component.ts @@ -10,6 +10,7 @@ import { Transaction } from '../add-transaction-page/transaction'; export class ContributorYearlyReportComponent implements OnInit { @Input() index: number; + @Input() contributorTransactions: {contributor: {}, transactions: {}}; public transactions: Transaction[] = []; public contributorName: string = 'Bob and Jill Handerson'; public contributorStreet: string = '7878 Washington St'; @@ -30,30 +31,13 @@ export class ContributorYearlyReportComponent implements OnInit { constructor(public printService: PrintService) { } ngOnInit() { - const t = new Transaction(); - t.amount = 100; - t.checkNumber = '3434'; - t.contributorId = 45; - t.date = '2019-10-20'; - t.description = 'Some description'; - t.fundId = 1; - t.goodsOrServices = false; - t.taxYear = 2019; - t.typeId = 1; - for(let i = 0; i < 90; i++) { - const t2 = new Transaction(); - t2.amount = 300; - t2.checkNumber = 'ghff'; - t2.contributorId = 45; - t2.date = '2019-10-23'; - t2.description = 'Missionary Family'; - t2.fundId = 2; - t2.goodsOrServices = false; - t2.taxYear = 2019; - t2.typeId = 2; - this.transactions.push(t2); - } - this.transactions.push(t); + this.contributorCity = (this.contributorTransactions.contributor).city; + this.contributorName = (this.contributorTransactions.contributor).display; + this.contributorState = (this.contributorTransactions.contributor).state; + this.contributorStreet = (this.contributorTransactions.contributor).street; + this.contributorZip = (this.contributorTransactions.contributor).zip; + this.transactions = this.contributorTransactions.transactions; + } public totalGeneral() { diff --git a/Client/src/app/constants/urls.ts b/Client/src/app/constants/urls.ts index 73cf9df..d78ba85 100644 --- a/Client/src/app/constants/urls.ts +++ b/Client/src/app/constants/urls.ts @@ -14,6 +14,7 @@ export const SERMON_DELETE_URL = environment.baseUrl + "/api2/sermons/a/"; export const SERMON_UPDATE_URL = environment.baseUrl + "/api2/sermons/a/"; export const SERMON_DOWNLOAD_URL = environment.baseUrl + "/api2/sermons/download/"; export const TRANSACTION_CREATE_URL = environment.baseUrl + "/api2/transactions/a/"; +export const TRANSACTION_GET_BY_YEAR_URL = environment.baseUrl + "/api2/transactions/a/"; export const USER_CREATE_URL = environment.baseUrl + "/api2/users/a/"; export const USER_GET_ALL_URL = environment.baseUrl + "/api2/users/a"; export const LOGIN_URL = environment.baseUrl + '/api2/login'; diff --git a/Client/src/app/services/transaction.service.ts b/Client/src/app/services/transaction.service.ts index f4b528d..7153e75 100644 --- a/Client/src/app/services/transaction.service.ts +++ b/Client/src/app/services/transaction.service.ts @@ -4,7 +4,7 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Observable, Subject, throwError, of } from 'rxjs'; import { catchError, map, tap, first } from 'rxjs/operators'; -import { TRANSACTION_CREATE_URL } from '../constants/urls'; +import { TRANSACTION_CREATE_URL, TRANSACTION_GET_BY_YEAR_URL } from '../constants/urls'; import { Transaction } from '../components/add-transaction-page/transaction'; @Injectable() @@ -41,6 +41,11 @@ export class TransactionService { .pipe(tap(res => console.log(res)), catchError(this.handleError)); } + getByYear(taxYear: number) { + return this.httpClient.get(TRANSACTION_GET_BY_YEAR_URL + "?taxYear=" + taxYear, this.options) + .pipe(catchError(this.handleError)); + } + private handleError(error: HttpErrorResponse) { if (error.error instanceof ErrorEvent) { // A client-side or network error occurred. Handle it accordingly. diff --git a/Server/src/app.js b/Server/src/app.js index d6c3bee..12047b7 100644 --- a/Server/src/app.js +++ b/Server/src/app.js @@ -10,6 +10,10 @@ const path = require('path'); const { execFile } = require('child_process'); const fs = require('fs'); +const cors = require('cors'); +app.use(cors({origin:'http://localhost:4200', credentials: true})); +app.options('*', cors()); + app.get('/secret',function(req,res){ res.json("You found the secret!"); }); diff --git a/Server/src/database/transactions.js b/Server/src/database/transactions.js index bcc4d14..8cb867a 100644 --- a/Server/src/database/transactions.js +++ b/Server/src/database/transactions.js @@ -22,6 +22,29 @@ exports.getAll = async function() { return result; } +exports.getByYear = async function(taxYear) { + const queryResult = await connectionAsync.query('SELECT * FROM Transactions WHERE DeletedDate IS NULL AND TaxYear = ?;', taxYear); + const result = []; + if (queryResult && queryResult.rows && queryResult.rows.length > 0) { + for(var i = 0 ; i < queryResult.rows.length; i++) { + const row = queryResult.rows[i]; + const trans = {}; + trans.id = row.Id; + trans.date = row.Date; + trans.typeId = row.TypeId; + trans.checkNumber = row.CheckNumber; + trans.contributorId = row.ContributorId; + trans.fundId = row.FundId; + trans.description = row.Description; + trans.amount = row.Amount; + trans.taxYear = row.TaxYear; + trans.goodsOrServices = row.GoodsOrServices == 1 ? true : false; + result.push(trans); + } + } + return result; +} + exports.addArray = async function(transactions) { let conn = null; try { diff --git a/Server/src/database/users.js b/Server/src/database/users.js index fca79de..65a4751 100644 --- a/Server/src/database/users.js +++ b/Server/src/database/users.js @@ -68,6 +68,7 @@ function rowToUser(row) { user.street = row.Street; user.city = row.City; user.state = row.State; + user.zip = row.Zip; user.country = row.Country; user.emailVerified = row.EmailVerified; user.emailVerificationCode = row.EmailVerificationCode; diff --git a/Server/src/package-lock.json b/Server/src/package-lock.json index 85231f0..1ff42dc 100644 --- a/Server/src/package-lock.json +++ b/Server/src/package-lock.json @@ -146,6 +146,22 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + }, + "dependencies": { + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + } + } + }, "crypto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", diff --git a/Server/src/package.json b/Server/src/package.json index 26fc65f..875c319 100644 --- a/Server/src/package.json +++ b/Server/src/package.json @@ -12,6 +12,7 @@ "async": "^2.5.0", "body-parser": "^1.18.1", "cookie-parser": "^1.4.3", + "cors": "^2.8.5", "crypto": "^1.0.1", "express": "^4.15.4", "moment-timezone": "^0.5.13", diff --git a/Server/src/routes/api/transactions.js b/Server/src/routes/api/transactions.js index b04680e..50b38c0 100644 --- a/Server/src/routes/api/transactions.js +++ b/Server/src/routes/api/transactions.js @@ -14,4 +14,17 @@ router.post("/a/",async function(req,res) { res.status(200).json({"status":200,"message":"transactions added","result":result}); }); +router.get("/a/", async function(req, res) { + + if (!res.locals.user || !res.locals.user.canDo || !res.locals.user.canDo('user_add')) { + res.status(401).json({"status":401,"message":"you are not authorized to add a transaction"}); + return; + } + var trans = []; + if (req.query.taxYear) { + trans = await dbTransactions.getByYear(req.query.taxYear); + } + res.status(201).json({"status":201,"message":"transactions for " + req.query.taxYear,"transactions":trans}); +}); + module.exports = router; \ No newline at end of file diff --git a/Server/src/routes/api/users.js b/Server/src/routes/api/users.js index 0b84ea0..50c3517 100644 --- a/Server/src/routes/api/users.js +++ b/Server/src/routes/api/users.js @@ -12,8 +12,16 @@ router.get("/a/", async function(req, res) { const users = await dbUsers.getAll(); const usersRes = users.map(x => { return { + id: x.id, value: x.id, - display: `${x.lastName} ${x.firstName}` + display: `${x.lastName} ${x.firstName}`, + street: x.street, + city: x.city, + state: x.state, + country: x.country, + zip: x.zip, + firstName: x.firstName, + lastName: x.lastName }; }); res.status(201).json({"status":201,"message":"all users","users":usersRes});