const currentMonthRevenue = db
.select({ currentMonthRevenue: sum(accountingTransactions.amount) })
.from(accountingTransactions)
.innerJoin(
chartOfAccounts,
eq(accountingTransactions.creditAccountId, chartOfAccounts.id)
)
.where(
and(
eq(chartOfAccounts.type, "REVENUE"),
eq(
sql`DATE_TRUNC('month', ${accountingTransactions}.date)`,
sql`DATE_TRUNC('month', CURRENT_DATE)`
)
)
);
const lastMonthRevenue = db
.select({ currentMonthRevenue: sum(accountingTransactions.amount) })
.from(accountingTransactions)
.innerJoin(
chartOfAccounts,
eq(accountingTransactions.creditAccountId, chartOfAccounts.id)
)
.where(
and(
eq(chartOfAccounts.type, "REVENUE"),
eq(
sql`DATE_TRUNC('month', ${accountingTransactions}.date)`,
sql`DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')`
)
)
);
const currentMonthRevenue = db
.select({ currentMonthRevenue: sum(accountingTransactions.amount) })
.from(accountingTransactions)
.innerJoin(
chartOfAccounts,
eq(accountingTransactions.creditAccountId, chartOfAccounts.id)
)
.where(
and(
eq(chartOfAccounts.type, "REVENUE"),
eq(
sql`DATE_TRUNC('month', ${accountingTransactions}.date)`,
sql`DATE_TRUNC('month', CURRENT_DATE)`
)
)
);
const lastMonthRevenue = db
.select({ currentMonthRevenue: sum(accountingTransactions.amount) })
.from(accountingTransactions)
.innerJoin(
chartOfAccounts,
eq(accountingTransactions.creditAccountId, chartOfAccounts.id)
)
.where(
and(
eq(chartOfAccounts.type, "REVENUE"),
eq(
sql`DATE_TRUNC('month', ${accountingTransactions}.date)`,
sql`DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')`
)
)
);