[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2750] addons



Revision: 2750
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2750&view=rev
Author:   einhverfr
Date:     2009-08-17 15:48:07 +0000 (Mon, 17 Aug 2009)

Log Message:
-----------
adding addons directory

Added Paths:
-----------
    addons/
    addons/1.3/
    addons/1.3/assets/
    addons/1.3/assets/LedgerSMB/
    addons/1.3/assets/LedgerSMB/DBObject/
    addons/1.3/assets/LedgerSMB/DBObject/Asset.pm
    addons/1.3/assets/LedgerSMB/DBObject/Asset_Class.pm
    addons/1.3/assets/LedgerSMB/DBObject/Asset_Report.pm
    addons/1.3/assets/UI/
    addons/1.3/assets/UI/asset/
    addons/1.3/assets/UI/asset/edit_asset.html
    addons/1.3/assets/UI/asset/edit_class.html
    addons/1.3/assets/UI/asset/search_asset.html
    addons/1.3/assets/UI/asset/search_class.html
    addons/1.3/assets/asset.pl
    addons/1.3/assets/scripts/
    addons/1.3/assets/scripts/asset.pl
    addons/1.3/assets/sql/
    addons/1.3/assets/sql/modules/
    addons/1.3/assets/sql/modules/Assets-Roles.sql
    addons/1.3/assets/sql/modules/Assets-tables.sql
    addons/1.3/assets/sql/modules/Assets.sql

Added: addons/1.3/assets/LedgerSMB/DBObject/Asset.pm
===================================================================
--- addons/1.3/assets/LedgerSMB/DBObject/Asset.pm	                        (rev 0)
+++ addons/1.3/assets/LedgerSMB/DBObject/Asset.pm	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,49 @@
+package LedgerSMB::DBObject::Asset;
+
+=head1 NAME
+
+LedgerSMB::DBObject::Asset.pm, LedgerSMB Base Class for Fixed Assets
+
+=head1 SYNOPSIS
+
+This library contains the base utility functions for creating, saving, and
+retrieving fixed assets for depreciation
+
+=cut
+
+use base qw(LedgerSMB::DBObject);
+use strict;
+
+sub save {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'asset__save');
+    $self->merge($ref);
+    $self->{dbh}->commit || $self->error(
+                  $self->{_locale}->text("Unable to save [_1] object", 
+                          $self->{_locale}->text('Asset'))
+    );
+    return $ref if $self->{dbh}->commit;
+}
+
+sub get_asset {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'asset__get');
+    $self->merge($ref);
+    return $ref;
+}
+
+sub search_assets {
+    my ($self) = @_;
+    my @results = $self->exec_method(funcname => 'asset__search');
+    $self->{search_results} = ..hidden..;
+    return @results;
+}
+
+
+sub get_metadata {
+    my ($self) = @_;
+    @{$self->{asset_classes}} = $self->exec_method(funcname => 'asset_class__list');
+}
+
+
+1;

Added: addons/1.3/assets/LedgerSMB/DBObject/Asset_Class.pm
===================================================================
--- addons/1.3/assets/LedgerSMB/DBObject/Asset_Class.pm	                        (rev 0)
+++ addons/1.3/assets/LedgerSMB/DBObject/Asset_Class.pm	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,49 @@
+package LedgerSMB::DBObject::Asset_Class;
+
+=head1 NAME
+
+LedgerSMB::DBObject::Asset_Class.pm, LedgerSMB Base Class for Asset Classes
+
+=head1 SYNOPSIS
+
+This library contains the base utility functions for creating, saving, and
+retrieving depreciation categories of assets.
+
+=cut
+
+use base qw(LedgerSMB::DBObject);
+use strict;
+
+sub save {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'asset_class__save');
+    $self->merge($ref);
+    $self->{dbh}->commit || $self->error(
+                  $self->{_locale}->text("Unable to save [_1] object", 
+                          $self->{_locale}->text('Asset Class'))
+    );
+    return $ref if $self->{dbh}->commit;
+}
+
+sub get_metadata {
+    my ($self) = @_;
+    @{$self->{asset_accounts}} = $self->exec_method(funcname => 'asset_class__get_asset_accounts');
+    @{$self->{dep_accounts}} = $self->exec_method(funcname => 'asset_class__get_dep_accounts');
+    @{$self->{dep_methods}} = $self->exec_method(funcname => 'asset_class__get_dep_methods');
+}
+
+sub get_asset_class {
+    my ($self) = @_;
+    my ($ref) = $self->exec_method(funcname => 'asset_class__get');
+    $self->merge($ref);
+    return $ref;
+}
+
+sub list_asset_classes {
+    my ($self) = @_;
+    my @refs = $self->exec_method(funcname => 'asset_class__list');
+    $self->{classes} = ..hidden..;
+    return @refs;
+}
+
+1;

Added: addons/1.3/assets/LedgerSMB/DBObject/Asset_Report.pm
===================================================================
--- addons/1.3/assets/LedgerSMB/DBObject/Asset_Report.pm	                        (rev 0)
+++ addons/1.3/assets/LedgerSMB/DBObject/Asset_Report.pm	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,24 @@
+
+package LedgerSMB::DBObject::Asset_Report;
+
+=head1 NAME
+
+LedgerSMB::DBObject::Asset_Report.pm, LedgerSMB Base Class for Asset Reports
+
+=head1 SYNOPSIS
+
+This library contains the base utility functions for creating, saving, and
+retrieving depreciation categories of asset depreciation and disposal reports.
+
+=cut
+
+use base qw(LedgerSMB::DBObject);
+use strict;
+
+sub create_report {
+}
+
+sub get_report {
+}
+
+1;

Added: addons/1.3/assets/UI/asset/edit_asset.html
===================================================================
--- addons/1.3/assets/UI/asset/edit_asset.html	                        (rev 0)
+++ addons/1.3/assets/UI/asset/edit_asset.html	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,92 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS 'elements.html' ?>
+<div class="listtop"><?lsmb title ?></div>
+<form action="<?lsmb script ?>" method="post">
+<?lsmb PROCESS input element_data = {
+	type = "hidden"
+	name = "id"
+	value = id
+} ?>
+<div class="inputrow" id="tagrow">
+<?lsmb PROCESS input element_data = {
+	type = "text"
+	class = "control_code"
+	name = "tag"
+	value = tag
+	label = text('Tag:')
+	size = 32
+} ?>
+<div class="inputrow" id="classrow">
+<?lsmb PROCESS select element_data = {
+	name = "asset_class"
+	class = "class"
+	options = asset_classes
+	default_options = [asset_class]
+	text_attr = "label"
+	value_attr = "id"
+	label = text("Asset Class:") #"
+} ?>
+</div>
+<div class="inputrow" id="descrow">
+<?lsmb PROCESS input element_data = {
+	label = text("Description:")
+	name = "description"
+	class = "description"
+	value = description
+	type = "text"
+} ?>
+<div class="inputrow" id="purchaserow">
+<span class="inputgroup" id="purchasedategroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Purchase Date:") #"
+	name = "purchase_date"
+	class = "date"
+	value = purchase_date
+	type = "text"
+	size = 12
+} ?>
+</span>
+<span class="inputgroup" id="purchasevaluegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Purchase Value:") #"
+	name = "purchase_value"
+	class = "money"
+	value = purchase_value
+	type = "text"
+	size = 16
+} ?>
+</span>
+</div>
+<div class="inputrow" id="salvagerow">
+<span class="inputgroup" id="usablelifegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Usable Life") #"
+	name = "usable_life"
+	value = usable_life
+	type = "text"
+	size = 10
+} ?>
+</span>
+<span class="inputgroup" id="salvagevaluegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Salvage Value:") #"
+	name = "salvage_value"
+	class = "money"
+	value = salvage_value
+	type = "text"
+	size = 16
+} ?>
+</span>
+</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>

Added: addons/1.3/assets/UI/asset/edit_class.html
===================================================================
--- addons/1.3/assets/UI/asset/edit_class.html	                        (rev 0)
+++ addons/1.3/assets/UI/asset/edit_class.html	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,65 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS 'elements.html' ?>
+<div class="listtop"><?lsmb title ?></div>
+<form action="<?lsmb script ?>" method="post">
+<?lsmb PROCESS input element_data = {
+	type = "hidden"
+	name = "id"
+	value = id
+} ?>
+<div class="inputrow" id="labelrow">
+<?lsmb PROCESS input element_data = {
+	type = "text"
+	name = "label"
+	value = label
+	class = "control_code"
+	size = 32
+	label = text('Label:')
+} ?>
+</div>
+<div class="inputrow" id="methodrow">
+<span class="inputgroup" id="methodgroup">
+<?lsmb PROCESS select element_data = {
+	label = text('Depreciation Method') #'
+	options = dep_methods
+	value_attr = 'id'
+	text_attr = 'method'
+	default_values = [method_id]
+	name = 'method_id'
+} ?>
+</span>
+</div>
+<div class="inputrow" id="accountsrow">
+<span class="inputgroup" id="assetaccgroup">
+<?lsmb PROCESS select element_data = {
+	label = text('Asset Account') #'
+	options = asset_accounts
+	name = "asset_account_id"
+	default_values = [asset_account_id]
+	value_attr = 'id'
+	text_attr = 'text'
+} ?>
+</span>
+<span class="inputgroup" id="depaccgroup">
+<?lsmb PROCESS select element_data = {
+	label = text('Depreciation Account') #'
+	options = dep_accounts
+	name = "dep_account_id"
+	default_values = [dep_account_id]
+	value_attr = 'id'
+	text_attr = 'text'
+} ?>
+</span>
+</div>
+<div class="inputrow" id="buttonrow">
+<?lsmb PROCESS button element_data = {
+	text = text("Save")
+	type = "submit"
+	class = "submit"
+	name = "action"
+	value = "asset_category_save"
+} ?>
+</div>
+</form>
+</body>
+</html>

Added: addons/1.3/assets/UI/asset/search_asset.html
===================================================================
--- addons/1.3/assets/UI/asset/search_asset.html	                        (rev 0)
+++ addons/1.3/assets/UI/asset/search_asset.html	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,91 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS 'elements.html' ?>
+<div class="listtop"><?lsmb text('Search Assets') ?></div>
+<form action="<?lsmb script ?>" method="post">
+<div class="inputrow" id="tagrow">
+<?lsmb PROCESS input element_data = {
+	type = "text"
+	class = "control_code"
+	name = "tag"
+	value = tag
+	label = text('Tag:')
+} ?>
+<div class="inputrow" id="classrow">
+<?lsmb asset_classes.push({});
+	PROCESS select element_data = {
+	name = "asset_class"
+	class = "class"
+	options = asset_classes
+	default_options = [asset_class]
+	text_attr = "label"
+	value_attr = "id"
+	label = text("Asset Class:") #"
+} ?>
+</div>
+<div class="inputrow" id="descrow">
+<?lsmb PROCESS input element_data = {
+	label = text("Description:")
+	name = "description"
+	class = "description"
+	value = description
+	type = "text"
+} ?>
+<div class="inputrow" id="purchaserow">
+<span class="inputgroup" id="purchasedategroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Purchase Date:") #"
+	name = "purchase_date"
+	class = "date"
+	value = purchase_date
+	type = "text"
+} ?>
+</span>
+<span class="inputgroup" id="purchasevaluegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Purchase Value:") #"
+	name = "purchase_value"
+	class = "money"
+	value = purchase_value
+	type = "text"
+} ?>
+</span>
+</div>
+<div class="inputrow" id="salvagerow">
+<span class="inputgroup" id="usablelifegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Usable Life") #"
+	name = "usable_life"
+	value = usable_life
+	type = "text"
+} ?>
+</span>
+<span class="inputgroup" id="salvagevaluegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Salvage Value:") #"
+	name = "salvage_value"
+	class = "money"
+	value = salvage_value
+	type = "text"
+} ?>
+</span>
+<span class="inputgroup" id="usablelifegroup">
+<?lsmb PROCESS input element_data = {
+	label = text("Usable Life:") #"
+	name = "usable_life"
+	class = "money"
+	value = usable_life
+	type = "text"
+} ?>
+</div>
+<div class="inputrow" id="buttonrow">
+<?lsmb PROCESS button element_data = {
+	text = text("Search")
+	type = "submit"
+	class = "submit"
+	name = "action"
+	value = "asset_results"
+} ?>
+</div>
+</form>
+</body>
+</html>

Added: addons/1.3/assets/UI/asset/search_class.html
===================================================================
--- addons/1.3/assets/UI/asset/search_class.html	                        (rev 0)
+++ addons/1.3/assets/UI/asset/search_class.html	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,74 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS 'elements.html' ?>
+<div class="listtop"><?lsmb text('Search Asset Class') ?></div>
+<form action="<?lsmb script ?>" method="post">
+<div class="inputrow" id="labelrow">
+<?lsmb PROCESS input element_data = {
+	type = "text"
+	name = "label"
+	value = label
+	class = "control_code"
+	size = 32
+	label = text('Label:')
+} ?>
+</div>
+<div class="inputrow" id="methodrow">
+<span class="inputgroup" id="methodgroup">
+<?lsmb dep_methods.push({}); 
+	PROCESS select element_data = {
+	label = text('Depreciation Method') #'
+	options = dep_methods
+	value_attr = 'id'
+	text_attr = 'method'
+	default_values = [method_id]
+	name = 'method_id'	
+} ?>
+</span>
+<span class="inputgroup" id="Units">
+<?lsmb life_units.push({});
+	PROCESS select element_data = {
+	label = text('Lifetime Measured In') #'
+	options = life_units
+	name = "life_unit"
+	default_values = [life_unit]
+	text_attr = "unit"
+	value_atr = "id"
+} ?>
+</span>
+</div>
+<div class="inputrow" id="accountsrow">
+<span class="inputgroup" id="assetaccgroup">
+<?lsmb asset_accounts.push({});
+	PROCESS select element_data = {
+	label = text('Asset Account') #'
+	options = asset_accounts
+	name = "asset_account_id"
+	default_values = [asset_account_id]
+	value_attr = 'id'
+	text_attr = 'text'
+} ?>
+</span>
+<span class="inputgroup" id="depaccgroup">
+<?lsmb dep_accounts.push({});
+	PROCESS select element_data = {
+	label = text('Depreciation Account') #'
+	options = dep_accounts
+	name = "dep_account_id"
+	default_values = [dep_account_id]
+	value_attr = 'id'
+	text_attr = 'text'
+} ?>
+</span>
+</div>
+<div class="inputrow" id="buttonrow">
+<?lsmb PROCESS button element_data = {
+	text = text("Search")
+	type = "submit"
+	class = "submit"
+	name = "action"
+	value = "asset_class_results"
+} ?>
+</div>
+</form>
+</body>
+</html>

Added: addons/1.3/assets/asset.pl
===================================================================
--- addons/1.3/assets/asset.pl	                        (rev 0)
+++ addons/1.3/assets/asset.pl	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,9 @@
+#!/usr/bin/perl
+
+require "lsmb-request.pl";
+#!/usr/bin/perl
+
+require "lsmb-request.pl";
+#!/usr/bin/perl
+
+require "lsmb-request.pl";


Property changes on: addons/1.3/assets/asset.pl
___________________________________________________________________
Added: svn:executable
   + 

Added: addons/1.3/assets/scripts/asset.pl
===================================================================
--- addons/1.3/assets/scripts/asset.pl	                        (rev 0)
+++ addons/1.3/assets/scripts/asset.pl	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,187 @@
+package LedgerSMB::Scripts::asset;
+use LedgerSMB::Template;
+use LedgerSMB::DBObject::Asset_Class;
+use LedgerSMB::DBObject::Asset;
+use LedgerSMB::DBObject::Asset_Report;
+
+
+sub asset_category_screen {
+    my ($request) = @_;
+    if ($request->{id}){
+        $request->{title} = $request->{_locale}->text('Edit Asset Class');
+    } else {
+        $request->{title} = $request->{_locale}->text('Add Asset Class');
+    } 
+    my $ac = LedgerSMB::DBObject::Asset_Class->new(base => $request);
+    $ac->get_metadata;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'edit_class',
+        format => 'HTML'
+    );
+    $template->render($ac);
+}
+
+sub asset_category_save {
+    my ($request) = @_;
+    my $ac = LedgerSMB::DBObject::Asset_Class->new(base => $request);
+    $ac->save;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'edit_class',
+        format => 'HTML'
+    );
+    $template->render($ac);
+}
+
+sub asset_category_search {
+    my ($request) = @_;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'search_class',
+        format => 'HTML'
+    );
+    $template->render($request);
+}
+
+sub asset_category_results {
+    my ($request) = @_;
+    my $ac = LedgerSMB::DBObject::Asset_Class->new(base => $request);
+    my @classes = $ac->search();
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI',
+        template => 'form-dynatable',
+        format => 'HTML'
+    );
+    @$columns = qw(id label dep_method life_unit asset_account dep_account);
+
+    my $rows = [];
+
+    for my $ac (@classes) {
+        my $href = "assets.pl?edit_asset_class";
+        my $row = {
+             id            => $ac->{id},
+             label         => {
+                               text => $ac->{label},
+                               href => "$href&class_id=$ac->{id}",
+                              },
+             dep_method    => $ac->{dep_method},
+             life_unit     => $ac->{life_unit}, 
+             asset_account => $ac->{asset_account_accno} . "--". 
+                              $ac->{asset_account_desciption,},
+             dep_account   => $ac->{dep_account_accno} . "--" . 
+                              $ac->{dep_account_description},
+		};
+        push @$rows, @row;
+    }
+}
+
+sub asset_screen {
+    my ($request) = @_;
+    my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
+    $asset->get_metadata;
+    $asset->{title} = $request->{_locale}->text('Add Asset') 
+                 unless $asset->{title};
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'edit_asset',
+        format => 'HTML'
+    );
+    $template->render($asset);
+}
+
+sub asset_save {
+    my ($request) = @_;
+    my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
+    $asset->debug({file => '/tmp/asset'});
+    $asset->save;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'edit_asset',
+        format => 'HTML'
+    );
+    $asset->get_metadata;
+    $template->render(
+	{title => $asset->{_locale}->text('Add Asset'),
+	asset_classes => $asset->{asset_classes}});
+}
+
+sub asset_search {
+    my ($request) = @_;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'search_asset',
+        format => 'HTML'
+    );
+    $template->render($request);
+}
+
+sub asset_results {
+    my ($request) = @_;
+}
+
+sub new_report {
+    my ($request) = @_;
+    my $report = LedgerSMB::DBObject::Asset_Report->new(base => $request);
+    $report->get_metadata;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'report_criteria',
+        format => 'HTML'
+    );
+    $template->render($report);
+}
+
+sub generate_report {
+    my ($request) = @_;
+    my $report = LedgerSMB::DBObject::Asset_Report->new(base => $request);
+    $report->generate;
+    display_report($request);
+}
+
+sub save_report {
+    my ($request) = @_;
+    my $report = LedgerSMB::DBObject::Asset_Report->new(base => $request);
+    $report->save;
+    display_report($request);
+}
+
+sub search_reports {
+    my ($request) = @_;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'report_criteria',
+        format => 'HTML'
+    );
+    $template->render($request);
+}
+
+sub report_results {
+    my ($request) = @_;
+    # Use Form-dynatable
+}
+
+sub display_report {
+    my ($request) = @_;
+    # use Form-dynatable
+}
+
+1;

Added: addons/1.3/assets/sql/modules/Assets-Roles.sql
===================================================================
--- addons/1.3/assets/sql/modules/Assets-Roles.sql	                        (rev 0)
+++ addons/1.3/assets/sql/modules/Assets-Roles.sql	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,24 @@
+CREATE ROLE "lsmb_<?lsmb dbname ?>__assets_administer" NOLOGIN INHERIT;
+
+GRANT INSERT, UPDATE, SELECT, DELETE ON asset_class 
+TO "lsmb_<?lsmb dbname ?>__assets_administer";
+GRANT SELECT, UPDATE ON asset_class_id_seq
+TO "lsmb_<?lsmb dbname ?>__assets_administer";
+
+CREATE ROLE "lsmb_<?lsmb dbname ?>__assets_enter" NOLOGIN INHERIT;
+
+GRANT INSERT, UPDATE ON asset_item
+TO "lsmb_<?lsmb dbname ?>__assets_enter";
+
+CREATE ROLE "lsmb_<?lsmb dbname ?>__assets_depreciate" NOLOGIN INHERIT;
+GRANT SELECT, INSERT ON asset_report, asset_report_line, asset_item, asset_class
+TO "lsmb_<?lsmb dbname ?>__assets_depreciate";
+
+CREATE ROLE "lsmb_<?lsmb dbname ?>__assets_approve" NOLOGIN INHERIT;
+GRANT SELECT ON asset_report, asset_report_line, asset_item, asset_class
+TO "lsmb_<?lsmb dbname ?>__assets_approve";
+GRANT EXECUTE ON FUNCTION  asset_report__approve(int)
+TO "lsmb_<?lsmb dbname ?>__assets_approve";
+
+GRANT SELECT ON asset_unit_class TO public;
+GRANT SELECT ON asset_dep_method TO public;

Added: addons/1.3/assets/sql/modules/Assets-tables.sql
===================================================================
--- addons/1.3/assets/sql/modules/Assets-tables.sql	                        (rev 0)
+++ addons/1.3/assets/sql/modules/Assets-tables.sql	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,79 @@
+CREATE TABLE asset_unit_class (
+	id int not null unique,
+	class text primary key
+);
+
+INSERT INTO asset_unit_class (id, class) values (1, 'time');
+INSERT INTO asset_unit_class (id, class) values (2, 'production'); 
+-- production-based depreciation is unlikely to be supported initially
+
+CREATE TABLE asset_dep_method(
+	id serial unique not null,
+	method text primary key,
+        sproc text not null unique,
+	unit_class int not null references asset_unit_class(id) 
+);
+
+comment on column asset_dep_method.method IS 
+$$ These are keyed to specific stored procedures.  Currently only "straight_line" is supported$$;
+
+INSERT INTO asset_dep_method(method, unit_class, sproc) 
+values ('Straight Line', 1, 'asset_dep_straight_line');
+
+CREATE TABLE asset_class (
+	id serial not null unique,
+	label text primary key,
+	asset_account_id int references account(id),
+	dep_account_id int references account(id),
+	method int references asset_dep_method(id)
+);
+
+CREATE TABLE asset_item (
+	id serial not null unique,
+	description text,
+	tag text primary key,
+	purchase_value numeric,
+	salvage_value numeric,
+	usable_life numeric,
+	purchase_date date  not null,
+	location_id int references warehouse(id),
+	department_id int references department(id),
+	invoice_id int references ap(id),
+	asset_class_id int references asset_class(id)
+);
+
+COMMENT ON column asset_item.tag IS $$ This can be plugged into other routines to generate it automatically via ALTER TABLE .... SET DEFAULT.....$$;
+
+CREATE TABLE asset_report_class (
+	id int not null unique,
+	class text primary key
+);
+
+INSERT INTO asset_report_class (id, class) values (1, 'depreciation');
+INSERT INTO asset_report_class (id, class) values (2, 'disposal');
+
+CREATE TABLE asset_report (
+	id serial primary key,
+	report_date date,
+	gl_id bigint references gl(id) unique,
+	asset_class bigint references asset_class(id),
+	report_class int references asset_report_class(id),
+	entered_by bigint not null references entity(id),
+	approved_by bigint references entity(id),
+	entered_at timestamp default now(),
+	approved_at timestamp,
+	depreciated_qty numeric,
+	submitted bool not null default false
+);
+
+CREATE TABLE asset_report_line(
+	asset_id bigint references asset_item(id),
+        report_id bigint references asset_report(id),
+	amount numeric,
+	department_id int references department(id),
+	warehouse_id int references warehouse(id),
+	PRIMARY KEY(asset_id, report_id)
+);
+
+COMMENT ON asset_report_line.department_id IS
+$$ In case assets are moved between departments, we have to store this here.$$;

Added: addons/1.3/assets/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/sql/modules/Assets.sql	                        (rev 0)
+++ addons/1.3/assets/sql/modules/Assets.sql	2009-08-17 15:48:07 UTC (rev 2750)
@@ -0,0 +1,299 @@
+CREATE OR REPLACE FUNCTION asset_dep__straight_line
+(in_report_id int, in_asset_id int)
+returns numeric as $$
+DECLARE 
+	annual_amount numeric;
+	depreciation_interval interval;
+	depreciation_years numeric;
+	retval numeric;
+	value_left numeric;
+	depreciation_amount numeric;
+BEGIN
+	SELECT (purchase_amount - salvage_amount) / usable_life::numeric  
+	INTO annual_amount 
+	FROM asset_item 
+	WHERE id = in_asset_id;
+
+	SELECT purchase_amount - salvage_amount - sum(amount) 
+	INTO value_left
+	FROM asset_item i 
+	JOIN asset_report_line l ON (i.id = l.asset_id)
+	GROUP BY puchase_amount, salvage_amount;
+
+	SELECT (select report_date FROM asset_report where id = in_id) - 
+		CASE WHEN report_date > purchase_date THEN report_date
+	             ELSE purchase_date END
+	INTO depreciation_interval
+	FROM asset_item i 
+	LEFT JOIN asset_report_line l ON (i.id = l.asset_id)
+	LEFT JOIN asset_report r ON (l.report_id = r.id)
+	WHERE r.approved IS NULL OR r.approved IS TRUE
+	ORDER BY r.report_date limit 1;
+
+	depreciation_years := extract('years' from depreciation_interval);
+	depreciation_years := depreciation_years + 
+                              extract('months' from depreciation_interval) / 12;
+	depreciation_years := depreciation_yers +
+                              extract('days' from depreciation_interval) / 365;
+
+	depreciation_amount := annual_amount * depreciation_years;
+
+	INSERT INTO asset_report_line (asset_id, report_id, amount)
+	VALUES (in_asst_id, in_report_id, depreciation_amount);
+	RETURN NULL;
+end;	
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset_class__get (in_id int) RETURNS asset_class AS
+$$
+DECLARE ret_val asset_class;
+BEGIN 
+	SELECT * INTO ret_val FROM asset_class WHERE id = in_id;
+	RETURN ret_val;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset_class__list() RETURNS SETOF asset_class AS
+$$
+SELECT * FROM asset_class ORDER BY label;
+$$ LANGUAGE SQL;
+
+CREATE TYPE asset_class_result AS (
+	id int,
+	asset_account_id int,
+	asset_accno text,
+	asset_description text,
+	dep_account_id int,
+	dep_accno text,
+	dep_description text,
+	method text, 
+	method_id int, 
+	label text
+);
+
+CREATE OR REPLACE FUNCTION asset_class__search
+(in_asset_account_id int, in_dep_account_id int, 
+in_method int, in_label text)
+RETURNS SETOF asset_class_result AS
+$$
+DECLARE out_var asset_class_result;
+BEGIN
+	FOR out_var IN
+		SELECT ac.id, ac.asset_account_id, aa.accno, aa.description, 
+			ad.accno, ad.description, m.method, ac.method,
+			ac.label
+		FROM asset_class ac
+		JOIN account aa ON (aa.id = ac.asset_account_id)
+		JOIN account ad ON (ad.id = ac.dep_account_id)
+		JOIN asset_dep_method m ON (ac.method = m.id)
+		WHERE 
+			(in_asset_account_id is null 
+				or in_asset_account_id = ac.asset_account_id)
+			AND (in_dep_account_id is null OR
+				in_dep_account_id = ac.dep_account_id)
+			AND (in_method is null OR in_method = ac.method)
+			AND (in_label IS NULL OR ac.label LIKE 
+				'%' || in_label || '%')
+	LOOP
+		RETURN NEXT out_var;
+	END LOOP;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset_class__get_dep_methods() 
+RETURNS SETOF asset_dep_method as $$
+SELECT * FROM asset_dep_method ORDER BY method;
+$$ LANGUAGE sql;
+
+CREATE OR REPLACE FUNCTION asset_class__save
+(in_id int, in_asset_account_id int, in_dep_account_id int, 
+in_method int, in_label text)
+RETURNS asset_class AS
+$$
+DECLARE ret_val asset_class;
+BEGIN
+	UPDATE asset_class 
+	SET asset_account_id = in_asset_account_id,
+		dep_account_id = in_dep_account_id,
+		method = in_method,
+		label = in_label
+	WHERE id = in_id;
+
+	IF FOUND THEN
+		SELECT * INTO ret_val FROM asset_class where id = in_id;
+		RETURN ret_val;
+	END IF;
+
+	INSERT INTO asset_class (asset_account_id, dep_account_id, method,
+		label)
+	VALUES (in_asset_account_id, in_dep_account_id, in_method, 
+		in_label);
+
+	SELECT * INTO ret_val FROM asset_class 
+	WHERE id = currval('asset_class_id_seq');
+
+	RETURN ret_val;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset__get (in_id int, in_tag text)
+RETURNS asset_item AS
+$$
+DECLARE ret_val asset_item;
+BEGIN
+	SELECT * into ret_val from asset_item WHERE id = in_id and in_tag = tag;
+	return ret_val;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset__search
+(in_asset_class int, in_description text, in_tag text, 
+in_purchase_date date, in_purchase_value numeric,
+in_usable_life numeric, in_salvage_value numeric)
+RETURNS SETOF asset_item AS $$
+DECLARE out_val asset_item;
+BEGIN
+	FOR out_val IN
+		SELECT * FROM asset_item
+		WHERE (in_asset_class is null 
+			or asset_class_id = in_asset_class)
+			AND (in_description is null or description 
+				LIKE '%' || in_description || '%')
+			and (in_tag is not null or tag like '%'||in_tag||'%')
+			AND (in_purchase_date is null 
+				or purchase_date = in_purchase_date)
+			AND (in_purchase_value is null
+				or in_purchase_value = purchase_value)
+			AND (in_usable_life is null
+				or in_usable_life = usable_life)
+			AND (in_salvage_value is null
+				OR in_salvage_value = salvage_value)
+	LOOP
+		RETURN NEXT out_val;
+	END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION asset_class__get_asset_accounts()
+RETURNS SETOF account AS $$
+SELECT * FROM account 
+WHERE id IN 
+	(select account_id from account_link where description = 'Fixed_Asset')
+ORDER BY accno;
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION asset_class__get_dep_accounts()
+RETURNS SETOF account AS $$
+SELECT * FROM account 
+WHERE id IN 
+	(select account_id from account_link where description = 'Asset_Dep')
+ORDER BY accno;
+$$ LANGUAGE SQL;
+
+
+CREATE OR REPLACE FUNCTION asset__save
+(in_id int, in_asset_class int, in_description text, in_tag text, 
+in_purchase_date date, in_purchase_value numeric,
+in_usable_life numeric, in_salvage_value numeric, in_location_id int, 
+in_department_id int, in_invoice_id int)
+returns asset_item AS
+$$
+DECLARE ret_val asset_item;
+BEGIN
+	UPDATE asset_item
+	SET asset_class_id = in_asset_class,
+		description = in_description,
+		tag = in_tag,
+		purchase_date = in_purchase_date,
+		purchase_value = in_purchase_value,
+		usable_life = in_usable_life,
+		location_id = in_location_id,
+		department_id = in_department_id,
+		invoice_id = in_invoice_id,
+		salvage_value = in_salvage_value
+	WHERE id = in_id;
+	IF FOUND THEN
+		SELECT * INTO ret_val WHERE id = in_id;
+		return ret_val;
+	END IF;
+
+	INSERT INTO asset_item (asset_class_id, description, tag, purchase_date,
+		purchase_value, usable_life, salvage_value, department_id,
+		warehouse_id, invoice_id)
+	VALUES (in_asset_class, in_description, in_tag, in_purchase_date,
+		in_purchase_value, in_usable_life, in_salvage_value,
+		in_department_id, in_warehouse_id, in_invoice_id);
+
+	SELECT * INTO ret_val FROM asset_item 
+	WHERE id = currval('asset_item_id_seq');
+	RETURN ret_val;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset_report__save
+(in_id int, in_asset_class int, in_report_date date, in_report_class int,
+in_submit bool, in_asset_items int[])
+RETURNS asset_report AS
+$$
+DECLARE 
+	ret_val asset_report;
+	item record;
+	method_sproc text;
+BEGIN
+	DELETE FROM asset_item where report_id = in_id;
+
+	UPDATE asset_report 
+	set asset_class = in_asset_class,
+		report_class = in_report_class,
+		report_date = in_report_date,
+		submitted = (in_submitted or submitted)
+	WHERE id = in_id;
+
+	IF FOUND THEN
+		SELECT * INTO ret_val FROM asset_report WHERE id = in_id;
+	ELSE 
+		INSERT INTO asset_report(report_class, asset_class, report_date,
+			submitted)
+		values (in_report_class, in_asset_class, in_report_date, 
+			in_submitted);
+
+		SELECT * INTO ret_val FROM asset_report 
+		WHERE id = currval('asset_report_id_seq');
+	END IF;
+
+	SELECT sproc INTO method_text FROM asset_dep_method 
+	WHERE id = (select method FROM asset_class 
+		where id = ret_val.asset_class);
+
+	FOR item IN 
+		SELECT in_asset_items[generate_series] AS id
+		FROM generate_series(array_lower(in_asset_items, 1), 
+			array_upper(in_asset_items, 1))
+	LOOP
+		EXECUTE $E$PERFORM $E$ || quote_ident(method_text) || $E$($E$ ||
+			quote_literal(ret_val.id) || $E$, $E$ || 
+			quote_literal(item.id) ||$E$)
+		$E$; 
+	END LOOP;
+	RETURN ret_val;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION asset_report__approve
+(in_id int)
+RETURNS asset_report AS
+$$
+DECLARE ret_val asset_report;
+BEGIN
+	UPDATE gl SET approved = true 
+	where id = (select gl_id from asset_report where id = in_id);
+
+	UPDATE asset_report SET approved = TRUE
+	where id = in_id;
+
+	SELECT * INTO ret_val FROM asset_report WHERE id = in_id;
+
+	RETURN ret_val;
+end;
+$$ language plpgsql;
+revoke execute on function asset_report__approve(int) from public;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.