Add Movement !
This commit is contained in:
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user