[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4765] trunk
- Subject: SF.net SVN: ledger-smb:[4765] trunk
- From: ..hidden..
- Date: Wed, 23 May 2012 14:35:31 +0000
Revision: 4765
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4765&view=rev
Author: einhverfr
Date: 2012-05-23 14:35:30 +0000 (Wed, 23 May 2012)
Log Message:
-----------
Budgets now display properly and budget reports moved to new reporting framework
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Budget.pm
trunk/LedgerSMB/PGNumber.pm
trunk/LedgerSMB/Scripts/budgets.pm
trunk/UI/budgetting/budget_entry.html
Added Paths:
-----------
trunk/LedgerSMB/DBObject/Report/Budget/
trunk/LedgerSMB/DBObject/Report/Budget/Search.pm
trunk/UI/Reports/filters/budget_search.html
trunk/budget_reports.pl
Removed Paths:
-------------
trunk/UI/budgetting/search_criteria.html
Modified: trunk/LedgerSMB/DBObject/Budget.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Budget.pm 2012-05-23 10:43:16 UTC (rev 4764)
+++ trunk/LedgerSMB/DBObject/Budget.pm 2012-05-23 14:35:30 UTC (rev 4765)
@@ -5,6 +5,7 @@
=cut
package LedgerSMB::DBObject::Budget;
+use LedgerSMB::PGDate;
use strict;
our $VERSION = 0.1;
@@ -28,7 +29,7 @@
=cut
use Moose;
-extends LedgerSMB::DBObject_Moose;
+extends 'LedgerSMB::DBObject_Moose';
=head1 PROPERTIES
@@ -145,7 +146,7 @@
=cut
-has 'lines' => (is => 'rw', isa => 'Maybe[ArrayRef[Hashref[Any]]]');
+has 'lines' => (is => 'rw', isa => 'Maybe[ArrayRef[HashRef[Any]]]');
=over
=item $budget_id int
@@ -199,6 +200,7 @@
sub save {
my ($self) = @_;
my ($ref) = $self->exec_method({funcname => 'budget__save_info'});
+ $self->id($ref->{id});
$self->{details} = [];
for my $line (@{$self->lines}){
my $l_info = [$line->{account_id},
@@ -212,8 +214,54 @@
$self->{dbh}->commit;
}
-=item
+=item from_input
+
+Prepares dates as PGDate formats
+
+=cut
+
+sub from_input {
+ my ($self, $input) = @_;
+ $input->{start_date} = LedgerSMB::PGDate->from_input($input->{start_date});
+ $input->{end_date} = LedgerSMB::PGDate->from_input($input->{end_date});
+ for my $rownum (1 .. $input->{rowcount}){
+ my $line = {};
+ $input->{"debit_$rownum"} = $input->parse_amount(
+ amount => $input->{"debit_$rownum"}
+ );
+ $input->{"debit_$rownum"} = $input->format_amount(
+ {amount => $input->{"debit_$rownum"}, format => '1000.00'}
+ );
+ $input->{"credit_$rownum"} = $input->parse_amount(
+ amount => $input->{"credit_$rownum"}
+ );
+ $input->{"credit_$rownum"} = $input->format_amount(
+ {amount => $input->{"credit_$rownum"}, format => '1000.00'}
+ );
+ if ($input->{"debit_$rownum"} and $input->{"credit_$rownum"}){
+ $input->error($input->{_locale}->text(
+ 'Cannot specify both debits and credits for budget line [_1]',
+ $rownum
+ ));
+ } elsif(!$input->{"debit_$rownum"} and !$input->{"credit_$rownum"}){
+ next;
+ } else {
+ $line->{amount} = $input->{"credit_$rownum"}
+ - $input->{"debit_$rownum"};
+ }
+ my ($accno) = split /--/, $input->{"account_id_$rownum"};
+ my ($ref) = $input->call_procedure(
+ procname => 'account__get_from_accno',
+ args => [$accno]
+ );
+ $line->{description} = $input->{"description_$rownum"};
+ $line->{account_id} = $ref->{id};
+ push @{$input->{lines}}, $line;
+ }
+ return $self->new(%$input);
+}
+
=item search
This method uses the object as the search criteria. Nulls/undefs match all
values. The properties used are:
@@ -276,9 +324,12 @@
my ($info) = $self->call_procedure(
procname => 'budget__get_info', args => [$id]
);
+ $self->prepare_dbhash($info);
$self = $self->new(%$info);
- @{$self->{lines}} = $self->exec_method({funcname => 'budget__get_details'});
+ my @lines = $self->exec_method({funcname => 'budget__get_details'});
+ $self->lines(..hidden..);
@{$self->{notes}} = $self->exec_method({funcname => 'budget__get_notes'});
+ return $self;
}
=item approve
Added: trunk/LedgerSMB/DBObject/Report/Budget/Search.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Budget/Search.pm (rev 0)
+++ trunk/LedgerSMB/DBObject/Report/Budget/Search.pm 2012-05-23 14:35:30 UTC (rev 4765)
@@ -0,0 +1,224 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Reports::Budget::Search - Search for Budgets
+
+=head1 SYNPOSIS
+
+ my $report = LedgerSMB::DBObject::Report::Budget::Search->new(%$request);
+ $report->run;
+ $report->render($request, $format);
+
+=head1 DESCRIPTION
+
+This is a basic search report for budgets.
+
+=cut
+
+package LedgerSMB::DBObject::Report::Budget::Search;
+use Moose;
+extends 'LedgerSMB::DBObject::Report';
+
+use LedgerSMB::App_State;
+my $locale = $LedgerSMB::App_State::Locale;
+
+=head1 PROPERTIES
+
+=over
+
+=item columns
+
+Read only accessor. This provides the columns for the report
+
+=pver
+
+=item start_date
+
+Start date of the budget
+
+=item end_date
+
+End date of the budget
+
+=item reference
+
+Reference/control code of the budget
+
+=item description
+
+Budget description
+
+=item entered_by_name
+
+Who entered the budget
+
+=item approved_by_name
+
+Who approved the budget
+
+=item obsolete_by_name
+
+Who marked the budget obsolete
+
+=back
+
+=cut
+
+sub columns {
+ return [ {col_id => 'start_date',
+ type => 'text',
+ name => $locale->text('Start Date') },
+
+ {col_id => 'end_date',
+ type => 'text',
+ name => $locale->text('End Date') },
+
+ {col_id => 'reference',
+ type => 'href',
+ href_base => 'budgets.pl?action=view_budget&id=',
+ name => $locale->text('Reference') },
+
+
+ {col_id => 'description',
+ type => 'href',
+ href_base => 'budgets.pl?action=view_budget&id=',
+ name => $locale->text('Description') },
+
+ {col_id => 'entered_by_name',
+ type => 'text',
+ name => $locale->text('Entered By') },
+
+ {col_id => 'approved_by_name',
+ type => 'text',
+ name => $locale->text('Approved By') },
+
+ {col_id => 'obsolete_by_name',
+ type => 'text',
+ name => $locale->text('Obsolete By') },
+ ];
+}
+
+
+=item name
+
+Returns the localized name of the template
+
+=cut
+
+sub name {
+ return $locale->text('Budget Search Results');
+}
+
+=item header_lines
+
+Returns the inputs to display on header.
+
+=cut
+
+sub header_lines {
+ return [{name => 'date_from',
+ text => $locale->text('Start Date')},
+ {name => 'date_to',
+ text => $locale->text('End Date')},
+ {name => 'accno',
+ text => $locale->text('Account Number')},
+ {name => 'reference',
+ text => $locale->text('Reference')},
+ {name => 'source',
+ text => $locale->text('Source')}];
+}
+
+=back
+
+=head1 CRITERIA PROPERTIES
+
+=over
+
+=item reference
+
+Matches the beginning of the reference of the budget
+
+=cut
+
+has 'reference' => (is=> 'rw', isa => 'Maybe[Str]');
+
+=item description
+
+Matched using full text rules against the description
+
+=cut
+
+has 'description' => (is=> 'rw', isa => 'Maybe[Str]');
+
+=item start_date
+
+Exact match for the start date
+
+=cut
+
+has 'start_date' => (is=> 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item end_date
+
+Exact match for end date.
+
+=cut
+
+has 'end_date' => (is=> 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item buisness_units
+
+This returns all budgets matching all business units listed here.
+
+=cut
+
+has 'business_units' => (is=> 'rw', isa => 'Maybe[ArrayRef[Int]]');
+
+=head1 METHODS
+
+=over
+
+=item prepare_criteria
+
+Creates criteria from web input to types expected
+
+=cut
+
+sub prepare_criteria {
+ my ($self, $request) = @_;
+ $request->{start_date} = LedgerSMB::PGDate->from_input(
+ $request->{start_date}
+ );
+ $request->{end_date} = LedgerSMB::PGDate->from_input(
+ $request->{end_date}
+ );
+ my @business_units;
+ for my $count(1 .. $request->{bclass_count}){
+ push @business_units, $request->{"business_unit_$count"}
+ if defined $request->{"business_unit_$count"};
+ }
+ $request->{business_units} = ..hidden..;
+}
+
+=item run_report
+
+Runs the report
+
+=cut
+
+sub run_report{
+ my ($self) = @_;
+ my @rows = $self->exec_method({funcname => 'budget__search'});
+ for my $r(@rows){
+ $r->{row_id} = $r->{id};
+ }
+ $self->rows(..hidden..);
+}
+
+
+=back
+
+=head1 COPYRIGHT
+
+=cut
+
+return 1;
Modified: trunk/LedgerSMB/PGNumber.pm
===================================================================
--- trunk/LedgerSMB/PGNumber.pm 2012-05-23 10:43:16 UTC (rev 4764)
+++ trunk/LedgerSMB/PGNumber.pm 2012-05-23 14:35:30 UTC (rev 4765)
@@ -193,7 +193,7 @@
my $dplaces = $places;
$places = 0 unless defined $places and ($places > 0);
my $zfill = ($places > 0) ? 1 : 0;
- $dplaces = 10 unless defined $dplaces;
+ $dplaces = 5 unless defined $dplaces;
my $formatter = new Number::Format(
-thousands_sep => $lsmb_formats->{$format}->{thousands_sep},
-decimal_point => $lsmb_formats->{$format}->{decimal_sep},
Modified: trunk/LedgerSMB/Scripts/budgets.pm
===================================================================
--- trunk/LedgerSMB/Scripts/budgets.pm 2012-05-23 10:43:16 UTC (rev 4764)
+++ trunk/LedgerSMB/Scripts/budgets.pm 2012-05-23 14:35:30 UTC (rev 4765)
@@ -46,17 +46,6 @@
used_amount => $request->{_locale}->text('- Used'),
variance => $request->{_locale}->text('= Variance'),
};
- for my $row(@rows){
- $row->{budget_amount} = $report->format_amount(
- {amount => $row->{budget_amount}, money => 1}
- );
- $row->{used_amount} = $report->format_amount(
- {amount => $row->{used_amount}, money => 1}
- );
- $row->{variance} = $report->format_amount(
- {amount => $row->{variance}, money => 1}
- );
- }
my $template = LedgerSMB::Template->new(
user => $request->{_user},
locale => $request->{_locale},
@@ -81,7 +70,7 @@
sub new_budget {
my ($request) = @_;
- my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+ my $budget = LedgerSMB::DBObject::Budget->from_input($request);
_render_screen($budget);
}
@@ -95,25 +84,19 @@
my $additional_rows = 5;
$additional_rows +=20 unless $budget->{rowcount};
$additional_rows = 0 if $budget->{id};
- $request->{class_id} = 0 unless $request->{class_id};
- $request->{control_code} = '' unless $request->{control_code};
- my $buc = LedgerSMB::DBObject::Business_Unit_Class->new(%$request);
- my $bu = LedgerSMB::DBObject::Business_Unit->new(%$request);
- @{$request->{bu_classes}} = $buc->list(1, 'gl');
- for my $bc (@{$request->{bu_classes}}){
- @{$request->{b_units}->{$bc->{id}}}
+ $budget->{class_id} = 0 unless $budget->{class_id};
+ $budget->{control_code} = '' unless $budget->{control_code};
+ my $buc = LedgerSMB::DBObject::Business_Unit_Class->new(%$budget);
+ my $bu = LedgerSMB::DBObject::Business_Unit->new(%$budget);
+ @{$budget->{bu_classes}} = $buc->list(1, 'gl');
+ for my $bc (@{$budget->{bu_classes}}){
+ @{$budget->{b_units}->{$bc->{id}}}
= $bu->list($bc->{id}, undef, 0, undef);
- for my $bu (@{$request->{b_units}->{$bc->{id}}}){
+ for my $bu (@{$budget->{b_units}->{$bc->{id}}}){
$bu->{text} = $bu->control_code . ' -- '. $bu->description;
}
}
$budget->{rowcount} ||= 0;
- for my $row (@{$budget->{display_rows}}){
- $row->{debit} = $budget->format_amount(amount => $row->{debit},
- money => 1) if $row->{debit} ;
- $row->{credit} = $budget->format_amount(amount => $row->{credit},
- money => 1) if $row->{credit};
- }
for (1 .. $additional_rows) {
push @{$budget->{display_rows}},
{accnoset => 0, index => $_ + $budget->{rowcount}};
@@ -218,7 +201,7 @@
sub view_budget {
my ($request) = @_;
my $budget = LedgerSMB::DBObject::Budget->new(%$request);
- $budget->get($request->{id});
+ $budget = $budget->get($request->{id});
$budget->{display_rows} = [];
for my $line (@{$budget->{lines}}){
my $row = {};
@@ -246,41 +229,7 @@
sub save {
my ($request) = @_;
- my $budget = LedgerSMB::DBObject::Budget->new({base => $request});
- for my $rownum (1 .. $request->{rowcount}){
- my $line = {};
- $request->{"debit_$rownum"} = $request->parse_amount(
- amount => $request->{"debit_$rownum"}
- );
- $request->{"debit_$rownum"} = $request->format_amount(
- {amount => $request->{"debit_$rownum"}, format => '1000.00'}
- );
- $request->{"credit_$rownum"} = $request->parse_amount(
- amount => $request->{"credit_$rownum"}
- );
- $request->{"credit_$rownum"} = $request->format_amount(
- {amount => $request->{"credit_$rownum"}, format => '1000.00'}
- );
- if ($request->{"debit_$rownum"} and $request->{"credit_$rownum"}){
- $request->error($request->{_locale}->text(
- 'Cannot specify both debits and credits for budget line [_1]',
- $rownum
- ));
- } elsif(!$request->{"debit_$rownum"} and !$request->{"credit_$rownum"}){
- next;
- } else {
- $line->{amount} = $request->{"credit_$rownum"}
- - $request->{"debit_$rownum"};
- }
- my ($accno) = split /--/, $request->{"account_id_$rownum"};
- my ($ref) = $request->call_procedure(
- procname => 'account__get_from_accno',
- args => [$accno]
- );
- $line->{description} = $request->{"description_$rownum"};
- $line->{account_id} = $ref->{id};
- push @{$budget->{lines}}, $line;
- }
+ my $budget = LedgerSMB::DBObject::Budget->from_input($request);
$budget->save();
view_budget($budget);
}
@@ -340,24 +289,12 @@
sub begin_search{
my ($request) = @_;
- my $budget = LedgerSMB::DBObject::Budget->new(%$request);
- @{$budget->{projects}} = $budget->list_projects;
- unshift @{$budget->{projects}}, {};
- @{$budget->{departments}} = $budget->list_departments;
- unshift @{$budget->{departments}}, {};
- my $template = LedgerSMB::Template->new(
- user => $request->{_user},
- locale => $request->{_locale},
- path => 'UI/budgetting',
- template => 'search_criteria',
- format => 'HTML'
- );
-
- $template->render($budget);
+ $request->{module_name} = 'gl';
+ $request->{report_name} = 'budget_search';
+ use LedgerSMB::Scripts::reports;
+ LedgerSMB::Scripts::reports::start_report($request);
}
-1;
-
=item search
See LedgerSMB::Budget's search routine for expected inputs.
@@ -439,3 +376,6 @@
General Public License version 2, or at your option any later version. Please
see the included License.txt for details.
+=cut
+
+1;
Copied: trunk/UI/Reports/filters/budget_search.html (from rev 4756, trunk/UI/budgetting/search_criteria.html)
===================================================================
--- trunk/UI/Reports/filters/budget_search.html (rev 0)
+++ trunk/UI/Reports/filters/budget_search.html 2012-05-23 14:35:30 UTC (rev 4765)
@@ -0,0 +1,81 @@
+<?lsmb INCLUDE 'ui-header.html'
+ stylesheet=stylesheet
+ include_stylesheet = ["UI/budgetting/budgetting.css"] ?>
+<?lsmb PROCESS elements.html ?>
+<body>
+<form action="budget_reports.pl" method="get">
+<div class="listtop"><?lsmb text('Search Budgets') ?></div>
+<div class="input_row" id = "reference_row">
+<div class="input_group">
+ <?lsmb INCLUDE input element_data = {
+ name = "reference",
+ value = reference,
+ type = "text",
+ size = "20",
+ class = 'reference',
+ label = text('Reference')
+ } ?>
+</div>
+<div class="input_group">
+ <?lsmb INCLUDE input element_data = {
+ name = "description",
+ value = description,
+ type = "text",
+ size = "50",
+ class = 'description'
+ label = text('Description')
+ }
+ ?>
+</div></div>
+<div class="input_row" id = "date_row">
+<div class="input_group">
+ <?lsmb INCLUDE input element_data = {
+ name = "start_date"
+ value = start_date
+ type = "text"
+ size = "11"
+ class = 'date'
+ label = text('Start Date') #'
+ } ?>
+</div>
+<div class="input_group">
+ <?lsmb INCLUDE input element_data = {
+ name = "end_date"
+ value = end_date
+ type = "text"
+ size = "11"
+ class = 'date'
+ label = text('End Date') #'
+ } ?>
+</div>
+
+</div></div>
+<?lsmb FOREACH BUC IN bu_classes ?>
+<div class="inputrow"><div class="inputgroup">
+ <?lsmb PROCESS select element_data = {
+ name = 'business_unit_' _ loop.count
+ options = b_units.${BUC.id}
+ text_attr = 'text'
+ value_attr = 'id'
+ class = 'business_unit'
+ label = text(BUC.label)
+ } ?>
+</div></div>
+<?lsmb max_class=loop.count; END; # FOREACH BUC
+PROCESS input element_data = {
+ name = 'bclass_count'
+ type = 'hidden'
+ value = max_class
+} ?>
+<div class="input_row" id = "button_row">
+<?lsmb PROCESS button element_data = {
+ text = text('Search')
+ value = 'search'
+ name = 'action'
+ type = 'submit'
+ class = 'submit'
+} ?>
+</div>
+</form>
+</body>
+</html>
Modified: trunk/UI/budgetting/budget_entry.html
===================================================================
--- trunk/UI/budgetting/budget_entry.html 2012-05-23 10:43:16 UTC (rev 4764)
+++ trunk/UI/budgetting/budget_entry.html 2012-05-23 14:35:30 UTC (rev 4765)
@@ -3,7 +3,7 @@
"UI/ajax/scriptaculous/lib/prototype.js",
"UI/ajax/scriptaculous/src/scriptaculous.js?load=builder,effects,dragdrop,controls",
"UI/ajax/helpers.js"]
- stylesheet=stylesheet
+ stylesheet=USER.stylesheet
include_stylesheet = ["UI/budgetting/budgetting.css"];
PROCESS elements.html; ?>
<body>
@@ -57,7 +57,7 @@
</div></div>
-<?FOREACH BUC IN bu_classes ?>
+<?lsmb FOREACH BUC IN bu_classes ?>
<div class="inputrow"><div class="inputgroup">
<?lsmb PROCESS select element_data = {
name = 'business_unit_' _ loop.count
Deleted: trunk/UI/budgetting/search_criteria.html
===================================================================
--- trunk/UI/budgetting/search_criteria.html 2012-05-23 10:43:16 UTC (rev 4764)
+++ trunk/UI/budgetting/search_criteria.html 2012-05-23 14:35:30 UTC (rev 4765)
@@ -1,87 +0,0 @@
-<?lsmb INCLUDE 'ui-header.html'
- stylesheet=stylesheet
- include_stylesheet = ["UI/budgetting/budgetting.css"] ?>
-<?lsmb PROCESS elements.html ?>
-<body>
-<form action="<?lsmb script ?>" method="get">
-<div class="listtop"><?lsmb title ?></div>
-<div class="input_row" id = "reference_row">
-<div class="input_group">
- <?lsmb INCLUDE input element_data = {
- name = "reference",
- value = reference,
- type = "text",
- size = "20",
- class = 'reference',
- label = text('Reference')
- } ?>
-</div>
-<div class="input_group">
- <?lsmb INCLUDE input element_data = {
- name = "description",
- value = description,
- type = "text",
- size = "50",
- class = 'description'
- label = text('Description')
- }
- ?>
-</div></div>
-<div class="input_row" id = "date_row">
-<div class="input_group">
- <?lsmb INCLUDE input element_data = {
- name = "start_date"
- value = start_date
- type = "text"
- size = "11"
- class = 'date'
- label = text('Start Date') #'
- } ?>
-</div>
-<div class="input_group">
- <?lsmb INCLUDE input element_data = {
- name = "end_date"
- value = end_date
- type = "text"
- size = "11"
- class = 'date'
- label = text('End Date') #'
- } ?>
-</div>
-
-</div></div>
-<div class="input_row" id = "description_row">
-<div class="input_group">
- <?lsmb INCLUDE select element_data = {
- text_attr = "description"
- value_attr = "id"
- default_values = [department_id]
- options = departments
- name = "department_id"
- label = text('Department')
- } ?>
-
-</div>
-<div class="input_group">
- <?lsmb INCLUDE select element_data = {
- text_attr = "description"
- value_attr = "id"
- default_values = [project_id]
- options = projects
- name = "project_id"
- label = text('Project')
- } ?>
-
-</div></div>
-<div class="input_row" id = "button_row">
-<?lsmb PROCESS button element_data = {
- text = text('Search')
- value = 'search'
- name = 'action'
- type = 'submit'
- class = 'submit'
-} ?>
-</div>
-</form>
-</body>
-</html>
Added: trunk/budget_reports.pl
===================================================================
--- trunk/budget_reports.pl (rev 0)
+++ trunk/budget_reports.pl 2012-05-23 14:35:30 UTC (rev 4765)
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+
+use FindBin;
+BEGIN {
+ lib->import($FindBin::Bin) unless $ENV{mod_perl}
+}
+
+require 'lsmb-request.pl';
Property changes on: trunk/budget_reports.pl
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.