Added categories and Filter widget
This commit is contained in:
@@ -8,6 +8,7 @@ __PACKAGE__->add_column("credId" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("account");
|
||||
__PACKAGE__->add_column("date" => { data_type => 'DATE' });
|
||||
__PACKAGE__->add_column("purpose");
|
||||
__PACKAGE__->add_column("category", { is_nullable => 1 });
|
||||
__PACKAGE__->add_column("value" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("spent" => { data_type => 'INTEGER', default => 0 });
|
||||
__PACKAGE__->set_primary_key("credId");
|
||||
@@ -26,6 +27,11 @@ __PACKAGE__->has_many(
|
||||
{ 'foreign.targetCredit' => 'self.credId' }
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
category_row => 'TrsrDB::Category',
|
||||
{ 'foreign.ID' => 'self.category' }
|
||||
);
|
||||
|
||||
__PACKAGE__->many_to_many(
|
||||
paid_bills => 'outgoings' => 'debit'
|
||||
);
|
||||
|
||||
@@ -8,6 +8,7 @@ __PACKAGE__->add_column("billId");
|
||||
__PACKAGE__->add_column("debtor");
|
||||
__PACKAGE__->add_column("date" => { data_type => 'DATE' });
|
||||
__PACKAGE__->add_column("purpose");
|
||||
__PACKAGE__->add_column("category", { is_nullable => 1 });
|
||||
__PACKAGE__->add_column("value" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("paid" => { data_type => 'INTEGER', default => 0 });
|
||||
__PACKAGE__->set_primary_key("billId");
|
||||
@@ -26,6 +27,11 @@ __PACKAGE__->belongs_to(
|
||||
{ 'foreign.credId' => 'self.targetCredit' }
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
category_row => 'TrsrDB::Category',
|
||||
{ 'foreign.ID' => 'self.category' }
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
incomings => 'TrsrDB::Transfer', 'billId'
|
||||
);
|
||||
|
||||
@@ -58,10 +58,7 @@ sub startup {
|
||||
$self->helper(sql_trace => \&get_trace);
|
||||
}
|
||||
else {
|
||||
$self->helper(sql_trace => sub {
|
||||
return "No SQL trace shown here, because environment variable "
|
||||
. "DBIC_TRACE is not set."
|
||||
});
|
||||
$self->helper(sql_trace => \&_get_trace_placeholder);
|
||||
}
|
||||
|
||||
if ( my $l = $ENV{LOG} ) {
|
||||
@@ -90,7 +87,9 @@ sub startup {
|
||||
})->get('/');
|
||||
$check->get('/bankStatement' => sub {
|
||||
my $c = shift;
|
||||
$c->stash( records => $c->app->db->resultset("ReconstructedBankStatement") );
|
||||
my $records = $c->app->db->resultset("ReconstructedBankStatement")
|
||||
->search( process_table_filter_widget($c) );
|
||||
$c->stash( records => $records );
|
||||
$c->render('bankStatement');
|
||||
});
|
||||
|
||||
@@ -299,6 +298,50 @@ sub render_online_help {
|
||||
|
||||
}
|
||||
|
||||
sub process_table_filter_widget {
|
||||
my $c = shift;
|
||||
my %query = $_[0] ? %{$_[0]} : ();
|
||||
my %options = $_[1] ? %{$_[1]} : ();
|
||||
$options{rows} //= $c->param("rows") // 100;
|
||||
|
||||
if ( my $category = $c->param('category') ) {
|
||||
$query{category} = $category;
|
||||
}
|
||||
|
||||
if ( my $purpose = $c->param('purpose') ) {
|
||||
$query{purpose} //= { -like => "%$purpose%" };
|
||||
}
|
||||
|
||||
my $until;
|
||||
if ( $until = $c->param('until') ) {
|
||||
$query{date} = { '<=' => $until };
|
||||
}
|
||||
|
||||
if ( my $from = $c->param('from') ) {
|
||||
if ( $until ) {
|
||||
$query{date}{'>='} = $from;
|
||||
}
|
||||
elsif ( $from =~ m{ \A \d{4} (-\d\d)? }xms ) {
|
||||
$query{date} = { -like => "$from%" };
|
||||
}
|
||||
else {
|
||||
$query{date} = { '>=' => $from };
|
||||
}
|
||||
}
|
||||
|
||||
if ( my $page = $c->param("page") ) {
|
||||
$options{page} = $page;
|
||||
}
|
||||
|
||||
return \%query, \%options;
|
||||
|
||||
}
|
||||
|
||||
sub _get_trace_placeholder { \<<'EOF'
|
||||
In this area, the server can trace SQL commands executed to fulfill your request. If the admin wants that, they can run the server with environment variable DBIC_TRACE=1.
|
||||
All substantial logic of Treasure DB is done in the scope of the database itself. In consequence, you could do without this HTTP interface and input all SQL commands shown here directly in a general-purpose SQLite3 user interface. Thus you will get roughly the same results.
|
||||
EOF
|
||||
}
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
@@ -59,9 +59,17 @@ sub upsert {
|
||||
|
||||
sub history {
|
||||
my $self = shift;
|
||||
my $history = $self->app->db->resultset("History")->search({
|
||||
account => $self->stash("account")
|
||||
}, { order_by => { -desc => [qw/date/] } });
|
||||
my %query = ( account => $self->stash("account") );
|
||||
if ( my $p = $self->param("purpose") ) {
|
||||
# ...
|
||||
}
|
||||
my $history = $self->app->db->resultset("History")->search(
|
||||
TrsrDB::HTTP::process_table_filter_widget(
|
||||
$self, \%query,
|
||||
{ order_by => { -desc => [qw/date/] } }
|
||||
)
|
||||
);
|
||||
|
||||
$self->stash( history => $history );
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ sub list {
|
||||
}
|
||||
|
||||
my $rs = $account->search_related(
|
||||
credits => {}, { order_by => { -desc => [qw/date/] } }
|
||||
credits => TrsrDB::HTTP::process_table_filter_widget(
|
||||
$self, {}, { order_by => { -desc => [qw/date/] }}
|
||||
)
|
||||
);
|
||||
$self->stash( credits => $rs );
|
||||
|
||||
@@ -39,14 +41,20 @@ sub upsert {
|
||||
account => $self->stash("account"),
|
||||
date => strftime("%Y-%m-%d", localtime)
|
||||
});
|
||||
$self->stash( credit => $credit );
|
||||
$self->stash(
|
||||
credit => $credit,
|
||||
categories => $db->resultset("Category")->search_rs({}, {
|
||||
order_by => { -asc => [qw/ID/] }
|
||||
})
|
||||
);
|
||||
|
||||
if ( $self->req->method eq 'GET' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
for my $field ( qw/account date purpose value/ ) {
|
||||
for my $field ( qw/account date purpose category value/ ) {
|
||||
my $value = $self->param($field);
|
||||
$value = undef if !length $value;
|
||||
$credit->$field($value);
|
||||
}
|
||||
$credit->update_or_insert();
|
||||
|
||||
@@ -20,7 +20,9 @@ sub list {
|
||||
}
|
||||
|
||||
my $rs = $account->search_related(
|
||||
debits => {}, { order_by => { -desc => [qw/date/] }}
|
||||
debits => TrsrDB::HTTP::process_table_filter_widget(
|
||||
$self, {}, { order_by => { -desc => [qw/date/] }}
|
||||
)
|
||||
);
|
||||
$self->stash( debits => $rs );
|
||||
|
||||
@@ -33,7 +35,7 @@ sub upsert {
|
||||
|
||||
my $db = $self->app->db;
|
||||
my $id = $self->stash("id");
|
||||
my @FIELDS = qw/billId date purpose value targetCredit/;
|
||||
my @FIELDS = qw/billId date purpose category value targetCredit/;
|
||||
my $debtor = $self->stash("account") // $self->param("debtor");
|
||||
if ( $self->req->method eq 'POST' && $debtor =~ s{^@}{} ) {
|
||||
|
||||
@@ -74,7 +76,14 @@ sub upsert {
|
||||
}
|
||||
);
|
||||
my @targets = map { [ $_->credId, $_->account->ID, $_->purpose ] } $targets->all;
|
||||
$self->stash( targets => \@targets, targets_count => $targets->count );
|
||||
my $categories = $db->resultset("Category")->search_rs({}, {
|
||||
order_by => { -asc => [qw/ID/] }
|
||||
});
|
||||
$self->stash(
|
||||
categories => $categories,
|
||||
targets => \@targets,
|
||||
targets_count => $targets->count
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package TrsrDB::History;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('History');
|
||||
__PACKAGE__->add_columns(qw/date purpose account credId credit debit contra billId note/);
|
||||
__PACKAGE__->add_columns(qw/date purpose category account credId credit debit contra billId note/);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
|
||||
@@ -4,6 +4,6 @@ package TrsrDB::ReconstructedBankStatement;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('ReconstructedBankStatement');
|
||||
__PACKAGE__->add_columns(qw/date purpose account credit debit/);
|
||||
__PACKAGE__->add_columns(qw/date purpose category account credit debit/);
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user