added fixes for budget view and working essential
This commit is contained in:
parent
af6d198c8f
commit
ebcc79fd36
6 changed files with 55 additions and 10 deletions
|
@ -14,7 +14,31 @@ sub post_category_list {
|
|||
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||
my $month_transaction_rs = $c->schema->resultset('ViewQuantisedTransactionCategory' . $driver)->search(
|
||||
my $month_transaction_category_rs = $c->schema->resultset('ViewQuantisedTransactionCategory' . $driver)->search(
|
||||
{
|
||||
purchase_time => {
|
||||
-between => [
|
||||
$dtf->format_datetime($start),
|
||||
$dtf->format_datetime($end),
|
||||
],
|
||||
},
|
||||
buyer_id => $entity->id,
|
||||
},
|
||||
{
|
||||
columns => [
|
||||
{
|
||||
quantised => 'quantised_weeks',
|
||||
value => { sum => 'value' },
|
||||
category_id => 'category_id',
|
||||
essential => 'essential',
|
||||
}
|
||||
],
|
||||
group_by => [ qw/ category_id quantised_weeks / ],
|
||||
order_by => { '-desc' => 'value' },
|
||||
}
|
||||
);
|
||||
|
||||
my $month_transaction_rs = $c->schema->resultset('ViewQuantisedTransaction' . $driver)->search(
|
||||
{
|
||||
purchase_time => {
|
||||
-between => [
|
||||
|
@ -29,27 +53,34 @@ sub post_category_list {
|
|||
{
|
||||
quantised => 'quantised_weeks',
|
||||
value => 'value',
|
||||
category_id => 'category_id',
|
||||
essential => 'essential',
|
||||
}
|
||||
],
|
||||
group_by => [ qw/ category_id quantised_weeks / ],
|
||||
group_by => [ qw/ essential quantised_weeks / ],
|
||||
order_by => { '-desc' => 'value' },
|
||||
}
|
||||
);
|
||||
|
||||
my $data = {};
|
||||
my $data = { categories => {}, essentials => {} };
|
||||
|
||||
for ( $month_transaction_rs->all ) {
|
||||
my $quantised = $c->db_datetime_parser->parse_datetime($_->get_column('quantised'));
|
||||
for my $cat_trans ( $month_transaction_category_rs->all ) {
|
||||
use Devel::Dwarn; Dwarn {$cat_trans->get_columns};
|
||||
my $quantised = $c->db_datetime_parser->parse_datetime($cat_trans->get_column('quantised'));
|
||||
my $days = $c->format_iso_date( $quantised ) || 0;
|
||||
my $category = $_->get_column('category_id') || 0;
|
||||
my $value = ($_->get_column('value') || 0) / 100000;
|
||||
$data->{$days} = [] unless exists $data->{$days};
|
||||
push @{ $data->{$days} }, {
|
||||
my $category = $cat_trans->get_column('category_id') || 0;
|
||||
my $value = ($cat_trans->get_column('value') || 0) / 100000;
|
||||
$data->{categories}->{$days} = [] unless exists $data->{categories}->{$days};
|
||||
push @{ $data->{categories}->{$days} }, {
|
||||
days => $days,
|
||||
value => $value,
|
||||
category => $category,
|
||||
};
|
||||
next unless $cat_trans->get_column('essential');
|
||||
$data->{essentials}->{$days}->{value} += $value;
|
||||
}
|
||||
|
||||
for my $day ( keys $data->{categories} ) {
|
||||
$data->{categories}->{$day} = [ sort { $b->{value} <=> $a->{value} } @{ $data->{categories}->{$day} } ];
|
||||
}
|
||||
|
||||
return $c->render(
|
||||
|
|
|
@ -81,4 +81,14 @@ __PACKAGE__->might_have(
|
|||
"Pear::LocalLoop::Schema::Result::TransactionCategory" => "transaction_id",
|
||||
);
|
||||
|
||||
sub sqlt_deploy_hook {
|
||||
my ( $source_instance, $sqlt_table ) = @_;
|
||||
my $pending_field = $sqlt_table->get_field('essential');
|
||||
if ( $sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
|
||||
$pending_field->{default_value} = 0;
|
||||
} else {
|
||||
$pending_field->{default_value} = \"false";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -15,6 +15,7 @@ SELECT "transactions.value",
|
|||
"transactions.purchase_time",
|
||||
"transactions.buyer_id",
|
||||
"transactions.seller_id",
|
||||
"transactions.essential",
|
||||
"transaction_category.category_id",
|
||||
DATE_TRUNC('hour', "transactions.purchase_time") AS "quantised_hours",
|
||||
DATE_TRUNC('day', "transactions.purchase_time") AS "quantised_days",
|
||||
|
|
|
@ -15,6 +15,7 @@ SELECT "transactions"."value",
|
|||
"transactions"."purchase_time",
|
||||
"transactions"."buyer_id",
|
||||
"transactions"."seller_id",
|
||||
"transactions"."essential",
|
||||
"transaction_category"."category_id",
|
||||
DATETIME(STRFTIME('%Y-%m-%d %H:00:00',"transactions"."purchase_time")) AS "quantised_hours",
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time")) AS "quantised_days",
|
||||
|
|
|
@ -15,6 +15,7 @@ SELECT "value",
|
|||
"purchase_time",
|
||||
"buyer_id",
|
||||
"seller_id",
|
||||
"essential",
|
||||
DATE_TRUNC('hour', "purchase_time") AS "quantised_hours",
|
||||
DATE_TRUNC('day', "purchase_time") AS "quantised_days",
|
||||
DATE_TRUNC('week', "purchase_time") AS "quantised_weeks"
|
||||
|
|
|
@ -15,6 +15,7 @@ SELECT "value",
|
|||
"purchase_time",
|
||||
"buyer_id",
|
||||
"seller_id",
|
||||
"essential",
|
||||
DATETIME(STRFTIME('%Y-%m-%d %H:00:00',"purchase_time")) AS "quantised_hours",
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"purchase_time")) AS "quantised_days",
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"purchase_time", 'weekday 1')) AS "quantised_weeks"
|
||||
|
|
Reference in a new issue