2024.01.22.08.34
This commit is contained in:
parent
489b05886b
commit
276f50ddd7
@ -92,7 +92,20 @@ class MonthlyReport extends Model<MonthlyReportAttributes, MonthlyReportCreation
|
|||||||
}
|
}
|
||||||
console.log(transactions)
|
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);
|
const totalAmount = transactions.reduce((total, transaction) => total + transaction.Amount, 0);
|
||||||
|
|
||||||
|
|
||||||
console.log(totalAmount)
|
console.log(totalAmount)
|
||||||
// Create a MonthlyReport entry with the generated data
|
// Create a MonthlyReport entry with the generated data
|
||||||
await MonthlyReport.create({
|
await MonthlyReport.create({
|
||||||
|
@ -16,7 +16,8 @@ interface TransactionAttributes {
|
|||||||
Amount: number;
|
Amount: number;
|
||||||
Type: 'income' | 'expense' | 'transfer';
|
Type: 'income' | 'expense' | 'transfer';
|
||||||
AccountID: number;
|
AccountID: number;
|
||||||
Refound:boolean
|
Refound:boolean,
|
||||||
|
Locked: boolean
|
||||||
// Other fields...
|
// Other fields...
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -32,6 +33,7 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
|
|||||||
public Amount!: number;
|
public Amount!: number;
|
||||||
public Type!: 'income' | 'expense' | 'transfer';
|
public Type!: 'income' | 'expense' | 'transfer';
|
||||||
public Refound!: boolean;
|
public Refound!: boolean;
|
||||||
|
public Locked!:boolean;
|
||||||
// Other fields...
|
// Other fields...
|
||||||
|
|
||||||
public UserID!: number;
|
public UserID!: number;
|
||||||
@ -75,6 +77,10 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
|
|||||||
Refound:{
|
Refound:{
|
||||||
type:DataTypes.BOOLEAN,
|
type:DataTypes.BOOLEAN,
|
||||||
defaultValue:false
|
defaultValue:false
|
||||||
|
},
|
||||||
|
Locked:{
|
||||||
|
type:DataTypes.BOOLEAN,
|
||||||
|
defaultValue:false
|
||||||
}
|
}
|
||||||
// Other fields...
|
// Other fields...
|
||||||
},
|
},
|
||||||
@ -90,7 +96,7 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
|
|||||||
if (attributes.Type == "expense") {
|
if (attributes.Type == "expense") {
|
||||||
attributes.Amount = -0 - attributes.Amount;
|
attributes.Amount = -0 - attributes.Amount;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -129,6 +135,19 @@ class Transaction extends Model<TransactionAttributes, TransactionCreationAttrib
|
|||||||
AccountID: toAccountID
|
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{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,8 +23,17 @@ export class TransactionRouter {
|
|||||||
router.post('/addTransfer', addTransfer.POST)
|
router.post('/addTransfer', addTransfer.POST)
|
||||||
router.get('/addTransfer', addTransfer.GET)
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
29
src/controller/router/transactions/modifyTransaction.ts
Normal file
29
src/controller/router/transactions/modifyTransaction.ts
Normal 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 };
|
@ -1,6 +1,6 @@
|
|||||||
extends ./transactions.pug
|
extends ./transactions.pug
|
||||||
block content
|
block content
|
||||||
form(action="/transactions/addTransaction",method="POST")
|
form(action=`/transactions/modifyTransaction/${transaction.TransactionID}`,method="POST")
|
||||||
div.form-group
|
div.form-group
|
||||||
.text Description
|
.text Description
|
||||||
.input
|
.input
|
||||||
@ -28,8 +28,11 @@ block content
|
|||||||
option(value=account.AccountID)=account.Name
|
option(value=account.AccountID)=account.Name
|
||||||
div.form-group.half
|
div.form-group.half
|
||||||
.text Amount
|
.text Amount
|
||||||
.input
|
if transaction.locked
|
||||||
input(type="number",min="0",step="0.01",name="amount",required)
|
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
|
div.form-group.half
|
||||||
.text Category
|
.text Category
|
||||||
.input
|
.input
|
||||||
|
Loading…
Reference in New Issue
Block a user