2024.01.22.08.34

This commit is contained in:
Theenoro 2024-01-22 08:34:38 +01:00
parent 489b05886b
commit 276f50ddd7
5 changed files with 80 additions and 7 deletions

View File

@ -92,7 +92,20 @@ class MonthlyReport extends Model<MonthlyReportAttributes, MonthlyReportCreation
}
console.log(transactions)
for(let i=0;i<transactions.length;i++){
await Transaction.update({
Locked:true
},{
where:{
TransactionID:transactions[i].TransactionID
}
})
}
const totalAmount = transactions.reduce((total, transaction) => total + transaction.Amount, 0);
console.log(totalAmount)
// Create a MonthlyReport entry with the generated data
await MonthlyReport.create({

View File

@ -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<TransactionAttributes, TransactionCreationAttrib
public Amount!: number;
public Type!: 'income' | 'expense' | 'transfer';
public Refound!: boolean;
public Locked!:boolean;
// Other fields...
public UserID!: number;
@ -75,6 +77,10 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
Refound:{
type:DataTypes.BOOLEAN,
defaultValue:false
},
Locked:{
type:DataTypes.BOOLEAN,
defaultValue:false
}
// Other fields...
},
@ -90,7 +96,7 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
if (attributes.Type == "expense") {
attributes.Amount = -0 - attributes.Amount;
}
},
}
}
}
);
@ -129,6 +135,19 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
AccountID: toAccountID
})
}
static async changeTransaction(id:number,amount:number,Description:string, CategoryID:number, AccountID:number){
let foundTransaction = await Transaction.findOne({where:{
TransactionID:id
}})
if(foundTransaction!=null){
if(foundTransaction.Locked == false){
}else{
}
}
}
}

View File

@ -23,8 +23,17 @@ export class TransactionRouter {
router.post('/addTransfer', addTransfer.POST)
router.get('/addTransfer', addTransfer.GET)
router.get('/modifyTransfer', async (req, res) => {
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');
}
})

View File

@ -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 };

View File

@ -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