Added a days-of-the-week report, under -w
This commit is contained in:
parent
b20ddba1d5
commit
a4f5abe860
4 changed files with 106 additions and 58 deletions
7
Makefile
7
Makefile
|
|
@ -85,12 +85,12 @@ include make.deps
|
|||
# These next rules are for my own use.
|
||||
|
||||
README.html: README
|
||||
(cd $(HOME)/src/muse && \
|
||||
(cd $(HOME)/Projects/muse && \
|
||||
./publish --html $(shell pwd)/README && \
|
||||
mv README.html $(shell pwd))
|
||||
|
||||
ledger.texi: README
|
||||
(cd $(HOME)/src/muse && \
|
||||
(cd $(HOME)/Projects/muse && \
|
||||
./publish --texi $(shell pwd)/README && \
|
||||
cat README.texi | sed 's/README\.info/ledger.info/g' \
|
||||
> $(shell pwd)/ledger.texi && \
|
||||
|
|
@ -101,7 +101,8 @@ VERSION = $(shell scripts/version)
|
|||
dist:
|
||||
rm -fr /tmp/ledger-$(VERSION)
|
||||
rsync -av --exclude=".*" --exclude="TAGS" --exclude="version" \
|
||||
--exclude="_darcs/" --exclude="ledger.dat" \
|
||||
--exclude="_darcs/" --exclude="ledger.dat" --exclude="CVS/" \
|
||||
--exclude="1.7/" --exclude="gmon.out" --exclude="prof.out" \
|
||||
$(shell pwd)/ /tmp/ledger-$(VERSION)
|
||||
(cd /tmp/ledger-$(VERSION) && \
|
||||
make fullclean && \
|
||||
|
|
|
|||
24
main.cc
24
main.cc
|
|
@ -163,12 +163,12 @@ int main(int argc, char * argv[])
|
|||
std::string total_expr = "T";
|
||||
std::time_t interval_begin = 0;
|
||||
|
||||
bool show_subtotals = true;
|
||||
bool show_expanded = false;
|
||||
bool show_related = false;
|
||||
bool show_inverted = false;
|
||||
bool show_empty = false;
|
||||
|
||||
bool show_subtotals = true;
|
||||
bool show_expanded = false;
|
||||
bool show_related = false;
|
||||
bool show_inverted = false;
|
||||
bool show_empty = false;
|
||||
bool days_of_the_week = false;
|
||||
bool show_revalued = false;
|
||||
bool show_revalued_only = false;
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ int main(int argc, char * argv[])
|
|||
int c, index;
|
||||
while (-1 !=
|
||||
(c = getopt(argc, argv,
|
||||
"+ABb:Ccd:DEe:F:f:Ghi:JjL:l:MnOo:P:p:QRrS:sT:t:UVvWXYy:Zz:"))) {
|
||||
"+ABb:Ccd:DEe:F:f:Ghi:JjL:l:MnOo:P:p:QRrS:sT:t:UVvWwXYy:Zz:"))) {
|
||||
switch (char(c)) {
|
||||
// Basic options
|
||||
case 'h':
|
||||
|
|
@ -347,6 +347,10 @@ int main(int argc, char * argv[])
|
|||
report_interval.reset(new interval_t(604800, 0, 0));
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
days_of_the_week = true;
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
report_interval.reset(new interval_t(0, 1, 0));
|
||||
break;
|
||||
|
|
@ -745,12 +749,18 @@ int main(int argc, char * argv[])
|
|||
// interval_transactions is like subtotal_transactions, but it
|
||||
// subtotals according to time intervals rather than totalling
|
||||
// everything.
|
||||
//
|
||||
// dow_transactions is like interval_transactions, except that it
|
||||
// reports all the transactions that fall on each subsequent day
|
||||
// of the week.
|
||||
if (show_expanded)
|
||||
formatter.reset(new subtotal_transactions(formatter.release()));
|
||||
else if (report_interval.get())
|
||||
formatter.reset(new interval_transactions(formatter.release(),
|
||||
*report_interval.get(),
|
||||
interval_begin));
|
||||
else if (days_of_the_week)
|
||||
formatter.reset(new dow_transactions(formatter.release()));
|
||||
|
||||
// related_transactions will pass along all transactions related
|
||||
// to the transaction received. If `show_all_related' is true,
|
||||
|
|
|
|||
35
walk.cc
35
walk.cc
|
|
@ -117,19 +117,24 @@ void changed_value_transactions::operator()(transaction_t * xact)
|
|||
last_xact = xact;
|
||||
}
|
||||
|
||||
void subtotal_transactions::flush()
|
||||
void subtotal_transactions::flush(const char * spec_fmt)
|
||||
{
|
||||
entry_t * entry = new entry_t;
|
||||
|
||||
char buf[256];
|
||||
std::string fmt = "- ";
|
||||
fmt += format_t::date_format;
|
||||
|
||||
// Make sure the end date is inclusive
|
||||
if (start != finish)
|
||||
finish -= 86400;
|
||||
if (! spec_fmt) {
|
||||
std::string fmt = "- ";
|
||||
fmt += format_t::date_format;
|
||||
|
||||
std::strftime(buf, 255, fmt.c_str(), std::gmtime(&finish));
|
||||
// Make sure the end date is inclusive
|
||||
if (start != finish)
|
||||
finish -= 86400;
|
||||
|
||||
std::strftime(buf, 255, fmt.c_str(), std::gmtime(&finish));
|
||||
} else {
|
||||
std::strftime(buf, 255, spec_fmt, std::gmtime(&finish));
|
||||
}
|
||||
|
||||
entry_t * entry = new entry_t;
|
||||
entry->payee = buf;
|
||||
|
||||
entry_temps.push_back(entry);
|
||||
|
|
@ -211,4 +216,16 @@ void interval_transactions::operator()(transaction_t * xact)
|
|||
last_xact = xact;
|
||||
}
|
||||
|
||||
void dow_transactions::flush()
|
||||
{
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (transactions_deque::iterator d = days_of_the_week[i].begin();
|
||||
d != days_of_the_week[i].end();
|
||||
d++)
|
||||
subtotal_transactions::operator()(*d);
|
||||
subtotal_transactions::flush("%As");
|
||||
days_of_the_week[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ledger
|
||||
|
|
|
|||
98
walk.h
98
walk.h
|
|
@ -47,6 +47,44 @@ struct compare_items {
|
|||
typedef std::deque<transaction_t *> transactions_deque;
|
||||
typedef std::deque<entry_t *> entries_deque;
|
||||
|
||||
inline void walk_transactions(transactions_list::iterator begin,
|
||||
transactions_list::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (transactions_list::iterator i = begin; i != end; i++)
|
||||
handler(*i);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_list& list,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_transactions(list.begin(), list.end(), handler);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_deque::iterator begin,
|
||||
transactions_deque::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (transactions_deque::iterator i = begin; i != end; i++)
|
||||
handler(*i);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_deque& deque,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_transactions(deque.begin(), deque.end(), handler);
|
||||
}
|
||||
|
||||
inline void walk_entries(entries_list::iterator begin,
|
||||
entries_list::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (entries_list::iterator i = begin; i != end; i++)
|
||||
walk_transactions((*i)->transactions, handler);
|
||||
}
|
||||
|
||||
inline void walk_entries(entries_list& list,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_entries(list.begin(), list.end(), handler);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ignore_transactions : public item_handler<transaction_t>
|
||||
{
|
||||
public:
|
||||
|
|
@ -267,7 +305,7 @@ class subtotal_transactions : public item_handler<transaction_t>
|
|||
delete *i;
|
||||
}
|
||||
|
||||
virtual void flush();
|
||||
virtual void flush(const char * spec_fmt = NULL);
|
||||
virtual void operator()(transaction_t * xact);
|
||||
};
|
||||
|
||||
|
|
@ -292,6 +330,26 @@ class interval_transactions : public subtotal_transactions
|
|||
virtual void operator()(transaction_t * xact);
|
||||
};
|
||||
|
||||
class dow_transactions : public subtotal_transactions
|
||||
{
|
||||
transactions_deque days_of_the_week[7];
|
||||
|
||||
public:
|
||||
dow_transactions(item_handler<transaction_t> * handler)
|
||||
: subtotal_transactions(handler) {}
|
||||
|
||||
virtual ~dow_transactions() {
|
||||
flush();
|
||||
}
|
||||
|
||||
virtual void flush();
|
||||
|
||||
virtual void operator()(transaction_t * xact) {
|
||||
struct std::tm * desc = std::gmtime(&xact->entry->date);
|
||||
days_of_the_week[desc->tm_wday].push_back(xact);
|
||||
}
|
||||
};
|
||||
|
||||
class related_transactions : public item_handler<transaction_t>
|
||||
{
|
||||
bool also_matching;
|
||||
|
|
@ -321,44 +379,6 @@ class related_transactions : public item_handler<transaction_t>
|
|||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void walk_transactions(transactions_list::iterator begin,
|
||||
transactions_list::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (transactions_list::iterator i = begin; i != end; i++)
|
||||
handler(*i);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_list& list,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_transactions(list.begin(), list.end(), handler);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_deque::iterator begin,
|
||||
transactions_deque::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (transactions_deque::iterator i = begin; i != end; i++)
|
||||
handler(*i);
|
||||
}
|
||||
|
||||
inline void walk_transactions(transactions_deque& deque,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_transactions(deque.begin(), deque.end(), handler);
|
||||
}
|
||||
|
||||
inline void walk_entries(entries_list::iterator begin,
|
||||
entries_list::iterator end,
|
||||
item_handler<transaction_t>& handler) {
|
||||
for (entries_list::iterator i = begin; i != end; i++)
|
||||
walk_transactions((*i)->transactions, handler);
|
||||
}
|
||||
|
||||
inline void walk_entries(entries_list& list,
|
||||
item_handler<transaction_t>& handler) {
|
||||
walk_entries(list.begin(), list.end(), handler);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue