Add Movement !

This commit is contained in:
Paolo Arena
2022-09-03 13:06:58 +02:00
parent 6bee366547
commit d262f94315
18 changed files with 599 additions and 323 deletions

View File

@@ -85,6 +85,30 @@ MovementSchema.statics.executeQueryTable = function(idapp, params) {
return tools.executeQueryTable(this, 0, params);
};
MovementSchema.statics.addMov = async function(accountFromId, accountToId, amount, causal) {
const {Account} = require('../models/account');
let mymov = Movement(
{
transactionDate: new Date(),
accountFromId,
accountToId,
amount,
causal,
residual: 0,
// expiringDate:
}
);
// Update saldo dell'Account
Account.addtoSaldo(accountToId, amount);
Account.addtoSaldo(accountFromId, -amount);
return mymov.save();
};
const Movement = mongoose.model('Movement', MovementSchema);
module.exports = {Movement};