31 lines
1011 B
JavaScript
31 lines
1011 B
JavaScript
'use strict';
|
|
|
|
const db = require('./db');
|
|
|
|
module.exports = {
|
|
result(req, res, next) {
|
|
db.select().sum('transactions.amount as sum').from('transactions')
|
|
.innerJoin('accounts', 'transactions.account_id', 'accounts.id')
|
|
.innerJoin('tickets', 'transactions.ticket_id', 'tickets.id')
|
|
.whereBetween('tickets.date', ['2015-03-01', '2015-03-31]'])
|
|
.andWhereBetween('accounts.account_type_id', [3, 4])
|
|
.then((res) => {
|
|
console.log(res);
|
|
// console.log(res);
|
|
// const result = res.reduce((result, t) => {
|
|
// console.log(t.amount);
|
|
// console.log(parseFloat(t.amount, 2));
|
|
// result += parseFloat(t.amount, 2);
|
|
|
|
// return result;
|
|
|
|
// }, 0);
|
|
// console.log(result);
|
|
});
|
|
// db.schema.raw(`SELECT * FROM transactions INNER JOIN accounts ON accounts.id = transactions.account_id
|
|
// WHERE accounts.account_type_id = 3;`, (result) => {
|
|
// console.log(result);
|
|
// })
|
|
}
|
|
};
|