2
0
mirror of https://github.com/frappe/books.git synced 2025-01-02 22:50:14 +00:00

incr: get top expenses to display

This commit is contained in:
18alantom 2022-05-17 13:38:12 +05:30
parent 07c923c6b1
commit 67f35b5f79
4 changed files with 35 additions and 29 deletions

View File

@ -32,13 +32,11 @@ export class BespokeQueries {
const topExpenses = await db const topExpenses = await db
.knex!.select({ .knex!.select({
total: db.knex!.raw('sum(cast(?? as real)) - sum(cast(?? as real))', [ total: db.knex!.raw('sum(cast(debit as real) - cast(credit as real))'),
'debit',
'credit',
]),
}) })
.select('account') .select('account')
.from('AccountingLedgerEntry') .from('AccountingLedgerEntry')
.where('reverted', false)
.where('account', 'in', expenseAccounts) .where('account', 'in', expenseAccounts)
.whereBetween('date', [fromDate, toDate]) .whereBetween('date', [fromDate, toDate])
.groupBy('account') .groupBy('account')
@ -89,7 +87,7 @@ export class BespokeQueries {
) { ) {
const income = await db.knex!.raw( const income = await db.knex!.raw(
` `
select sum(credit - debit) as balance, strftime('%Y-%m', date) as yearmonth select sum(cast(credit as real) - cast(debit as real)) as balance, strftime('%Y-%m', date) as yearmonth
from AccountingLedgerEntry from AccountingLedgerEntry
where where
reverted = false and reverted = false and
@ -105,7 +103,7 @@ export class BespokeQueries {
const expense = await db.knex!.raw( const expense = await db.knex!.raw(
` `
select sum(debit - credit) as balance, strftime('%Y-%m', date) as yearmonth select sum(cast(debit as real) - cast(credit as real)) as balance, strftime('%Y-%m', date) as yearmonth
from AccountingLedgerEntry from AccountingLedgerEntry
where where
reverted = false and reverted = false and

View File

@ -2,16 +2,14 @@
<div class="flex flex-col"> <div class="flex flex-col">
<PageHeader :title="t`Dashboard`" /> <PageHeader :title="t`Dashboard`" />
<div class="mx-4 overflow-y-scroll no-scrollbar"> <div class="mx-4 overflow-y-scroll no-scrollbar flex flex-col gap-8">
<Cashflow class="mt-5" /> <Cashflow class="" />
<hr class="border-t mt-10" /> <hr />
<UnpaidInvoices class="mt-10" /> <UnpaidInvoices />
<hr class="border-t mt-10" /> <hr />
<div class="flex justify-between mx-auto mt-10 ml-4 mr-4 gap-10"> <div class="flex gap-8">
<ProfitAndLoss class="w-1/2" /> <ProfitAndLoss class="w-full" />
<!-- <Expenses class="w-full" />
<Expenses class="w-1/2" />
-->
</div> </div>
</div> </div>
</div> </div>
@ -20,7 +18,7 @@
<script> <script>
import PageHeader from 'src/components/PageHeader'; import PageHeader from 'src/components/PageHeader';
import Cashflow from './Cashflow'; import Cashflow from './Cashflow';
// import Expenses from './Expenses'; import Expenses from './Expenses';
import ProfitAndLoss from './ProfitAndLoss'; import ProfitAndLoss from './ProfitAndLoss';
import UnpaidInvoices from './UnpaidInvoices'; import UnpaidInvoices from './UnpaidInvoices';
@ -31,9 +29,7 @@ export default {
UnpaidInvoices, UnpaidInvoices,
Cashflow, Cashflow,
ProfitAndLoss, ProfitAndLoss,
/*
Expenses, Expenses,
*/
}, },
}; };
</script> </script>

View File

@ -7,9 +7,11 @@
</template> </template>
</SectionHeader> </SectionHeader>
<div class="flex relative" v-show="hasData"> <div class="flex relative" v-show="hasData">
<div class="w-1/2"> <!-- Chart Legend -->
<div class="w-1/2 flex flex-col gap-5 mt-8">
<!-- Ledgend Item -->
<div <div
class="mt-5 flex justify-between items-center text-sm" class="flex justify-between items-center text-sm"
v-for="(d, i) in expenses" v-for="(d, i) in expenses"
:key="d.name" :key="d.name"
> >
@ -18,8 +20,12 @@
@mouseover="active = i" @mouseover="active = i"
@mouseleave="active = null" @mouseleave="active = null"
> >
<div class="w-3 h-3 rounded-sm" :class="d.class"></div> <div class="w-3 h-3 rounded-sm flex-shrink-0" :class="d.class" />
<div class="ml-3">{{ d.account }}</div> <p
class="ml-2 w-24 overflow-x-scroll whitespace-nowrap no-scrollbar"
>
{{ d.account }}
</p>
</div> </div>
<p class="whitespace-nowrap"> <p class="whitespace-nowrap">
{{ fyo.format(d.total, 'Currency') }} {{ fyo.format(d.total, 'Currency') }}
@ -38,6 +44,8 @@
@change="(value) => (active = value)" @change="(value) => (active = value)"
/> />
</div> </div>
<!-- Empty Message -->
<div <div
v-if="expenses.length === 0" v-if="expenses.length === 0"
class="flex-1 w-full h-full flex-center my-20" class="flex-1 w-full h-full flex-center my-20"
@ -52,7 +60,7 @@
<script> <script>
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
import theme from 'src/theme'; import theme from 'src/theme';
import { getDatesAndPeriodicity } from 'src/utils/misc'; import { getDatesAndPeriodList } from 'src/utils/misc';
import DonutChart from '../../components/Charts/DonutChart.vue'; import DonutChart from '../../components/Charts/DonutChart.vue';
import PeriodSelector from './PeriodSelector'; import PeriodSelector from './PeriodSelector';
import SectionHeader from './SectionHeader'; import SectionHeader from './SectionHeader';
@ -94,8 +102,12 @@ export default {
}, },
methods: { methods: {
async setData() { async setData() {
const { fromDate, toDate } = await getDatesAndPeriodicity(this.period); const { fromDate, toDate } = await getDatesAndPeriodList(this.period);
let topExpenses = await fyo.db.getTopExpenses(fromDate, toDate); let topExpenses = await fyo.db.getTopExpenses(
fromDate.toISO(),
toDate.toISO()
);
const shades = [ const shades = [
{ class: 'bg-gray-800', hex: theme.backgroundColor.gray['800'] }, { class: 'bg-gray-800', hex: theme.backgroundColor.gray['800'] },
{ class: 'bg-gray-600', hex: theme.backgroundColor.gray['600'] }, { class: 'bg-gray-600', hex: theme.backgroundColor.gray['600'] },

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="flex justify-between gap-10"> <div class="flex justify-between gap-8">
<div <div
class="flex-col justify-between flex-1" class="flex-col justify-between flex-1"
v-for="(invoice, i) in invoices" v-for="(invoice, i) in invoices"
@ -152,8 +152,8 @@ export default {
barWidth: 60, barWidth: 60,
}, },
], ],
salesInvoicePeriod: 'This Month', salesInvoicePeriod: 'This Year',
purchaseInvoicePeriod: 'This Month', purchaseInvoicePeriod: 'This Year',
}), }),
watch: { watch: {
salesInvoicePeriod: 'calculateInvoiceTotals', salesInvoicePeriod: 'calculateInvoiceTotals',