[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2982] addons/1.3/assets/trunk
- Subject: SF.net SVN: ledger-smb:[2982] addons/1.3/assets/trunk
- From: ..hidden..
- Date: Tue, 13 Apr 2010 21:43:17 +0000
Revision: 2982
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2982&view=rev
Author: einhverfr
Date: 2010-04-13 21:42:59 +0000 (Tue, 13 Apr 2010)
Log Message:
-----------
NBV and import logic committed
Modified Paths:
--------------
addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
addons/1.3/assets/trunk/scripts/asset.pl
addons/1.3/assets/trunk/sql/modules/Assets.sql
Added Paths:
-----------
addons/1.3/assets/trunk/UI/asset/import_asset.html
Modified: addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
===================================================================
--- addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm 2010-04-12 21:12:14 UTC (rev 2981)
+++ addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm 2010-04-13 21:42:59 UTC (rev 2982)
@@ -25,6 +25,17 @@
return $ref if $self->{dbh}->commit;
}
+sub import_file {
+
+ my $self = shift @_;
+
+ my $csv = LedgerSMB::Assets::CSV->new(base=>$self);
+ $self->{import_entries} = $csv->process($self, 'import_file');
+
+ return @{$self->{import_entries}};
+}
+
+
sub get {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset__get');
@@ -70,7 +81,6 @@
for my $acc (@{$self->{exp_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
- $self->debug({file => '/tmp/asset2'});
}
sub get_next_tag {
Added: addons/1.3/assets/trunk/UI/asset/import_asset.html
===================================================================
--- addons/1.3/assets/trunk/UI/asset/import_asset.html (rev 0)
+++ addons/1.3/assets/trunk/UI/asset/import_asset.html 2010-04-13 21:42:59 UTC (rev 2982)
@@ -0,0 +1,58 @@
+<?lsmb INCLUDE 'ui-header.html'
+ include_stylesheet = ["UI/asset/asset.css"]
+ include_script = ["UI/asset/asset.js"]
+?>
+<?lsmb PROCESS 'elements.html' ?>
+<body onLoad="init()">
+<div class="listtop"><?lsmb title ?></div>
+<div class="info"><?lsmb info ?></div>
+<form action="<?lsmb script ?>" method="post" enctype="multipart/form-data">
+<!-- These are for Javascript automation of defaults -CT -->
+<?lsmb PROCESS input element_data = {
+ type = "hidden"
+ name = "id"
+ value = id
+} ?>
+<?lsmb FOREACH a_class IN asset_classes -?>
+<?lsmb PROCESS input element_data = {
+ type = "hidden",
+ name = "asset_account_default_$a_class.id",
+ value = a_class.asset_account_id,
+} ?>
+<?lsmb PROCESS input element_data = {
+ type = "hidden",
+ name = "dep_account_default_$a_class.id",
+ value = a_class.dep_account_id,
+} ?>
+<?lsmb PROCESS input element_data = {
+ type = "hidden",
+ name = "unit_label_$a_class.id",
+ value = dep_method.${a_class.id}.unit_label,
+} ?>
+<?lsmb- END # For a_class ?>
+<?lsmb PROCESS input element_data = {
+ type = "hidden"
+ name = "last_class_id"
+ value = asset_class
+} ?>
+<!-- end set for javascript automation -CT -->
+<div class="inputrow" id="filerow">
+<?lsmb PROCESS input element_data = {
+ name = "import_file"
+ type = "file"
+ label = text('From File') #'
+ class = "file"
+} ?>
+</div>
+<div class="inputrow" id="buttonrow">
+<?lsmb PROCESS button element_data = {
+ text = text("Save")
+ type = "submit"
+ class = "submit"
+ name = "action"
+ value = "asset_save"
+} ?>
+</div>
+</form>
+</body>
+</html>
Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl 2010-04-12 21:12:14 UTC (rev 2981)
+++ addons/1.3/assets/trunk/scripts/asset.pl 2010-04-13 21:42:59 UTC (rev 2982)
@@ -756,4 +756,81 @@
}
+sub begin_nbv {
+ my ($request) = @_;
+ my $template = LedgerSMB::Template->new(
+ user =>$request->{_user},
+ locale => $request->{_locale},
+ path => 'UI/asset',
+ template => 'nbv_filter',
+ format => 'HTML'
+ );
+ $template->render($request);
+}
+
+sub display_nbv {
+ my ($request) = @_;
+ my $locale = $request->{locale};
+ my $report = LedgerSMB::DBObject::Asset_Report->new({base => $request });
+ my @cols = qw(id tag description begin_depreciation method remaining_life basis salvage_value
+ through_date accum_depreciation net_book_value percent_depreciated);
+ my $header = {
+ id => $locale->text('ID'),
+ tag => $locale->text('Tag'),
+ description => $locale->text('Description'),
+ begin_depreciation => $locale->text('In Svc.'),
+ method => $locale->text('Method'),
+ remaining_life => $locale->text('Rem. Life'),
+ basis => $locale->text('Basis'),
+ salvage_value => $locale->text('(+) Salvage Value'),
+ through_date => $locale->text('Dep. through'),
+ accum_depreciation => $locale->text('(-) Accum. Dep.'),
+ net_book_value => $locale->text('(=) NBV'),
+ percent_depreciated => $locale->text('Pct. Dep.'),
+ };
+ my @results = $report->get_nbv;
+ my $rows = [];
+ for my $r(@results){
+ for my $amt (qw(basis salvage_value accum_depreciation net_book_value
+ percent_depreciated)){
+ $r->{$amt} = $r->format_amount({amount => $r->{$amt}});
+ }
+ push @$rows, $r;
+ }
+ my $template = LedgerSMB::Template->new(
+ user =>$request->{_user},
+ locale => $request->{_locale},
+ path => 'UI',
+ template => 'form-dynatable',
+ format => 'HTML'
+ );
+ $template->render({form => $report,
+ columns => ..hidden..,
+ heading => $header,
+ rows => $rows,
+ });
+}
+
+sub begin_import {
+ my ($request) = @_;
+ my $template = LedgerSMB::Template->new(
+ user =>$request->{_user},
+ locale => $request->{_locale},
+ path => 'UI/asset',
+ template => 'import_asset',
+ format => 'HTML'
+ );
+ $template->render($request);
+}
+
+sub import {
+ my ($request) = @_;
+ my $asset = LedgerSMB::DBObject::Asset->new({base => $request});
+ for my $ai ($asset->import_file($request->{import_file})){
+ $ai->save;
+ }
+ $request->{info} = $request->{_locale}->text('File Imported');
+ begin_import($request);
+}
+
1;
Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql 2010-04-12 21:12:14 UTC (rev 2981)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql 2010-04-13 21:42:59 UTC (rev 2982)
@@ -492,6 +492,50 @@
ORDER BY ai.id, ai.tag;
$$ language sql;
+CREATE TYPE asset_nbv_line AS (
+ id int,
+ tag text,
+ description text,
+ begin_depreciation date,
+ method text,
+ remaining_life numeric,
+ basis numeric,
+ salvage_value numeric,
+ through_date date,
+ accum_depreciation numeric,
+ net_book_value numeric,
+ percent_depreciated numeric
+);
+
+
+create function asset_nbv_report ()
+returns setof asset_nbv_line AS
+$$
+ SELECT ai.id, ai.tag, ai.description, coalesce(ai.start_depreciation, ai.purchase_date),
+ adm.short_label, ai.usable_life
+ - months_passed(coalesce(ai.start_depreciation, ai.purchase_date),
+ coalesce(max(r.report_date),
+ ai.start_depreciation,
+ ai.purchase_date))/ 12,
+ ai.purchase_value - ai.salvage_value, ai.salvage_value, max(r.report_date),
+ sum(rl.amount), ai.purchase_value - sum(rl.amount), (1 - (ai.usable_life
+ - months_passed(coalesce(ai.start_depreciation, ai.purchase_date),
+ coalesce(max(r.report_date),
+ ai.start_depreciation,
+ ai.purchase_date))/ 12)/ai.usable_life) * 100
+ FROM asset_item ai
+ JOIN asset_class ac ON (ai.asset_class = ac.id)
+ JOIN asset_dep_method adm ON (adm.id = ac.dep_method)
+LEFT JOIN asset_report_line rl ON (ai.id = rl.asset_id),
+LEFT JOIN asset_report r on (rl.report_id = r.id)
+ GROUP BY ai.id, ai.tag, ai.description, ai.start_depreciation, ai.purchase_date,
+ adm.short_label, ai.usable_life, ai.purchase_value
+ HAVING NOT 2 = ANY(as_array(r.report_class)) AND NOT 4 = ANY(as_array(r.report_class))
+ ORDER BY ai.id, ai.tag, ai.description;
+$$ language sql;
+
+$$ language sql;
+
CREATE TYPE partial_disposal_line AS (
id int,
tag text,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.