From 276f50ddd7622e2d26c9de7bb1346d2438f69ba0 Mon Sep 17 00:00:00 2001 From: theenoro Date: Mon, 22 Jan 2024 08:34:38 +0100 Subject: [PATCH] 2024.01.22.08.34 --- src/controller/models/MonthlyReport.ts | 13 +++++++++ src/controller/models/Transaction.ts | 23 +++++++++++++-- src/controller/router/transactions.ts | 13 +++++++-- .../router/transactions/modifyTransaction.ts | 29 +++++++++++++++++++ views/transactions/modifyTransaction.pug | 9 ++++-- 5 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 src/controller/router/transactions/modifyTransaction.ts diff --git a/src/controller/models/MonthlyReport.ts b/src/controller/models/MonthlyReport.ts index b0941e7..31bf3c2 100644 --- a/src/controller/models/MonthlyReport.ts +++ b/src/controller/models/MonthlyReport.ts @@ -92,7 +92,20 @@ class MonthlyReport extends Model total + transaction.Amount, 0); + + console.log(totalAmount) // Create a MonthlyReport entry with the generated data await MonthlyReport.create({ diff --git a/src/controller/models/Transaction.ts b/src/controller/models/Transaction.ts index 4c22f3f..99bd5f9 100644 --- a/src/controller/models/Transaction.ts +++ b/src/controller/models/Transaction.ts @@ -16,7 +16,8 @@ interface TransactionAttributes { Amount: number; Type: 'income' | 'expense' | 'transfer'; AccountID: number; - Refound:boolean + Refound:boolean, + Locked: boolean // Other fields... } @@ -32,6 +33,7 @@ class Transaction extends Model { - + router.get('/modifyTransfer/:id', async (req, res,next ) => { + try { + await listTransactions.GET(req, res, next, { + where: { + AccountID: req.params.acc + } + }) + } catch (err) { + console.error(err); + res.status(500).send('Internal Server Error'); + } }) diff --git a/src/controller/router/transactions/modifyTransaction.ts b/src/controller/router/transactions/modifyTransaction.ts new file mode 100644 index 0000000..45103f4 --- /dev/null +++ b/src/controller/router/transactions/modifyTransaction.ts @@ -0,0 +1,29 @@ +import { Request, NextFunction, Response } from "express"; +import moment from "moment"; +import { Op } from "sequelize"; + +import { Category, Transaction, Account } from "../../models"; +import { convertDateArray } from "../../helper/dateConversion"; +import { getFirstLastDayOfMonth } from "../../helper"; + +const GET = async (req: Request, res: Response, next: NextFunction, data:any = {date:new Date(),where:{}}) => { + try { + const transactions:any = await Transaction.findOne({ + include: [Account,Category], + where:{ + TransactionID: req.params.id + } + }); + const categories = await Category.findAll({}); + const accounts = await Account.findAll({}); + + const arr = convertDateArray(transactions); + + res.render('transactions/modifyTransaction', { title: 'Transactions', transaction: transaction, categories, accounts, cssClass:"fullList" }); + } catch (err) { + console.error(err); + res.status(500).send('Internal Server Error'); + } +} + +export default { GET }; \ No newline at end of file diff --git a/views/transactions/modifyTransaction.pug b/views/transactions/modifyTransaction.pug index 0b4e3fb..7dcc1bb 100644 --- a/views/transactions/modifyTransaction.pug +++ b/views/transactions/modifyTransaction.pug @@ -1,6 +1,6 @@ extends ./transactions.pug block content - form(action="/transactions/addTransaction",method="POST") + form(action=`/transactions/modifyTransaction/${transaction.TransactionID}`,method="POST") div.form-group .text Description .input @@ -28,8 +28,11 @@ block content option(value=account.AccountID)=account.Name div.form-group.half .text Amount - .input - input(type="number",min="0",step="0.01",name="amount",required) + if transaction.locked + input(type="number",min="0",step="0.01",name="amount",disabled) + else + .input + input(type="number",min="0",step="0.01",name="amount",required) div.form-group.half .text Category .input