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

SF.net SVN: ledger-smb:[2799] addons/1.3



Revision: 2799
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2799&view=rev
Author:   einhverfr
Date:     2009-12-04 20:26:21 +0000 (Fri, 04 Dec 2009)

Log Message:
-----------
Correcting asset saving issues

Modified Paths:
--------------
    addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
    addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Class.pm
    addons/1.3/assets/trunk/UI/asset/asset.css
    addons/1.3/assets/trunk/UI/asset/edit_asset.html
    addons/1.3/assets/trunk/scripts/asset.pl
    addons/1.3/assets/trunk/sql/modules/Assets-tables.sql
    addons/1.3/base/trunk/sql/modules/Util.sql

Added Paths:
-----------
    addons/1.3/assets/trunk/UI/asset/asset.js
    addons/1.3/enhanced_tb/
    addons/1.3/enhanced_tb/tags/
    addons/1.3/enhanced_tb/trunk/
    addons/1.3/enhanced_tb/trunk/LedgerSMB/
    addons/1.3/enhanced_tb/trunk/LedgerSMB/DBObject/
    addons/1.3/enhanced_tb/trunk/reports.pl
    addons/1.3/enhanced_tb/trunk/scripts/
    addons/1.3/enhanced_tb/trunk/sql/
    addons/1.3/enhanced_tb/trunk/sql/modules/
    addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql

Modified: addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
===================================================================
--- addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm	2009-12-04 20:26:21 UTC (rev 2799)
@@ -47,8 +47,26 @@
     @{$self->{asset_classes}} = $self->exec_method(funcname => 'asset_class__list');
    @{$self->{locations}} = $self->exec_method(funcname => 'warehouse__list_all');
    @{$self->{departments}} = $self->exec_method(funcname => 'department__list_all');
+    @{$self->{asset_accounts}} = $self->exec_method(funcname => 'asset_class__get_asset_accounts');
+    @{$self->{dep_accounts}} = $self->exec_method(funcname => 'asset_class__get_dep_accounts');
+    for my $acc (@{$self->{asset_accounts}}){
+        $acc->{text} = $acc->{accno} . '--' . $acc->{description};
+    }
+    for my $acc (@{$self->{dep_accounts}}){
+        $acc->{text} = $acc->{accno} . '--' . $acc->{description};
+    }
 }
 
+sub get_next_tag {
+    my ($self) =  @_;
+    my ($ref) = $self->call_procedure(
+          procname => 'setting_increment', 
+          args     => ['asset_tag']
+    );
+    $self->{tag} = $ref->{setting_increment};
+    $self->{dbh}->commit;
+}
+
 sub get_invoice_id {
     my ($self) = @_;
     my ($ref) = $self->exec_method(funcname => 'get_vendor_invoice_id');

Modified: addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Class.pm
===================================================================
--- addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Class.pm	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset_Class.pm	2009-12-04 20:26:21 UTC (rev 2799)
@@ -30,6 +30,12 @@
     @{$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');
+    for my $acc (@{$self->{asset_accounts}}){
+        $acc->{text} = $acc->{accno} . '--' . $acc->{description};
+    }
+    for my $acc (@{$self->{dep_accounts}}){
+        $acc->{text} = $acc->{accno} . '--' . $acc->{description};
+    }
 }
 
 sub get_asset_class {

Modified: addons/1.3/assets/trunk/UI/asset/asset.css
===================================================================
--- addons/1.3/assets/trunk/UI/asset/asset.css	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/UI/asset/asset.css	2009-12-04 20:26:21 UTC (rev 2799)
@@ -6,7 +6,7 @@
 
 span.inputgroup { display: block;
 	float: left;
-	width: 30%;
+	width: 40%;
 }
 
 div.inputrow {

Added: addons/1.3/assets/trunk/UI/asset/asset.js
===================================================================
--- addons/1.3/assets/trunk/UI/asset/asset.js	                        (rev 0)
+++ addons/1.3/assets/trunk/UI/asset/asset.js	2009-12-04 20:26:21 UTC (rev 2799)
@@ -0,0 +1,31 @@
+function setDefaultAccount(){
+    var asset_dropdown = document.getElementById('asset-account-id');
+    var dep_dropdown = document.getElementById('dep-account-id');
+    var old_class = document.getElementById('last-class-id').value;
+    var class_dropdown = document.getElementById('asset-class');
+    var new_class = class_dropdown.options[class_dropdown.selectedIndex].value;;
+    document.getElementById('asset-account-' + old_account).value 
+    = asset_dropdown.options[asset_dropdown.selectedIndex].value;
+    document.getElementById('dep-account-' + old_account).value 
+    = dep_dropdown.options[dep_dropdown.selectedIndex].value;
+
+    set_dropdown(asset_dropdown, 
+                 document.getElementById('asset-account-' + new_account).value);
+    set_dropdown(dep_dropdown,
+                 document.getElementById('dep-account-' + new_account).value);
+}
+
+function set_dropdown (selectElement, newValue){
+    for (var i = 0; i < selectElement.options.length; i++) {
+        if (selectElement.options[i].value = newValue) {
+           selectElement.options[i].selected = true;
+        } else {
+           selectElement.options[i].selected = false;
+        }
+    }
+   
+}
+
+function init(){
+    document.getElementById('asset-class').addEventListener('blur', Function('setDefaultAccount()'), false);
+}

Modified: addons/1.3/assets/trunk/UI/asset/edit_asset.html
===================================================================
--- addons/1.3/assets/trunk/UI/asset/edit_asset.html	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/UI/asset/edit_asset.html	2009-12-04 20:26:21 UTC (rev 2799)
@@ -1,12 +1,35 @@
-<?lsmb INCLUDE 'ui-header.html' include_stylesheet = ["UI/asset/asset.css"] ?>
+<?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>
 <form action="<?lsmb script ?>" method="post">
+<!-- These are for Javascript automation of defaults -CT -->
 <?lsmb PROCESS input element_data = {
 	type = "hidden"
 	name = "id"
 	value = id
 } ?>
+<?lsmb FOR 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 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="tagrow">
 <?lsmb PROCESS input element_data = {
 	type = "text"
@@ -102,6 +125,28 @@
 } ?>
 </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="invoicerow">
 <span class="inputgroup" id="vendorgroup">
 <?lsmb PROCESS input element_data = {

Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/scripts/asset.pl	2009-12-04 20:26:21 UTC (rev 2799)
@@ -88,6 +88,9 @@
     my ($request) = @_;
     my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
     $asset->get_metadata;
+    if (!$asset->{tag}){
+        $asset->get_next_tag;
+    }
     $asset->{title} = $request->{_locale}->text('Add Asset') 
                  unless $asset->{title};
     my $template = LedgerSMB::Template->new(

Modified: addons/1.3/assets/trunk/sql/modules/Assets-tables.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets-tables.sql	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/assets/trunk/sql/modules/Assets-tables.sql	2009-12-04 20:26:21 UTC (rev 2799)
@@ -28,6 +28,11 @@
 	method int references asset_dep_method(id)
 );
 
+COMMENT ON asset_class IS $$
+The account fields here set the defaults for the individual asset items.  They
+are non-authoritative.
+$$;
+
 CREATE TABLE asset_item (
 	id serial not null unique,
 	description text,
@@ -39,11 +44,21 @@
 	location_id int references warehouse(id),
 	department_id int references department(id),
 	invoice_id int references ap(id),
+	asset_account_id int references account(id),
+	dep_account_id int references account(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_note (
+    asset_id int not null references asset_item (id),
+    check (note_class = 3)
+) inherits (note);
+
+INSERT INTO note_class (id, class) values (3, 'Asset');
+ALTER TABLE asset_note alter column note_class default 3;
+
 CREATE TABLE asset_report_class (
 	id int not null unique,
 	class text primary key

Modified: addons/1.3/base/trunk/sql/modules/Util.sql
===================================================================
--- addons/1.3/base/trunk/sql/modules/Util.sql	2009-11-13 19:15:36 UTC (rev 2798)
+++ addons/1.3/base/trunk/sql/modules/Util.sql	2009-12-04 20:26:21 UTC (rev 2799)
@@ -21,3 +21,42 @@
 	RETURN retval;
 END;
 $$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION to_args (in_base text[], in_args text[])
+RETURNS text[] AS
+$$
+SELECT CASE WHEN $2[1] IS NULL OR $2[2] IS NULL THEN $1 
+            ELSE $1 || ($2[1]::text || '=' || $2[2]::text)
+       END;
+$$ language sql;
+
+CREATE AGGREGATE to_args (
+     basetype = text[],
+     sfunc = to_args,
+     stype = text[],
+     INITCOND = '{}'
+);
+
+CREATE OR REPLACE VIEW periods AS
+SELECT 'ytd' as id, 'Year to Date' as label, now()::date as date_to, 
+       (extract('year' from now())::text || '-01-01')::date as date_from
+UNION
+SELECT 'last_year', 'Last Year', 
+       ((extract('YEAR' from now()) - 1)::text || '-12-31')::date as date_to,
+       ((extract('YEAR' from now()) - 1)::text || '-01-01')::date as date_from
+;
+
+GRANT SELECT ON periods TO public;
+
+CREATE OR REPLACE FUNCTION periods_get()
+RETURNS SETOF periods
+AS
+$$
+SELECT * FROM periods ORDER BY id
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION all_years() returns setof int AS
+$$
+SELECT DISTINCT EXTRACT ('YEAR' FROM transdate)::int
+FROM acc_trans;
+$$ language sql;

Added: addons/1.3/enhanced_tb/trunk/reports.pl
===================================================================
--- addons/1.3/enhanced_tb/trunk/reports.pl	                        (rev 0)
+++ addons/1.3/enhanced_tb/trunk/reports.pl	2009-12-04 20:26:21 UTC (rev 2799)
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+
+require "lsmb-request.pl";


Property changes on: addons/1.3/enhanced_tb/trunk/reports.pl
___________________________________________________________________
Added: svn:executable
   + *

Added: addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql
===================================================================
--- addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql	                        (rev 0)
+++ addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql	2009-12-04 20:26:21 UTC (rev 2799)
@@ -0,0 +1,74 @@
+create type tb_row AS (
+   account_id int,
+   account_number text,
+   account_desc text,
+   starting_balance numeric,
+   debits numeric,
+   credits numeric,
+   ending_balance numeric
+);
+CREATE OR REPLACE FUNCTION trial_balance__generate 
+(in_date_from date, in_date_to date, in_heading int, in_accounts int[],
+ in_ignore_yearend text) 
+returns setof tb_row AS
+$$
+DECLARE
+	out_row tb_row;
+	t_checkpoint_date date;
+        include_trans int;
+BEGIN
+        if (in_ignore_yearend = 'last') then
+                select trans_id into include_trans FROM yearend
+                WHERE transdate < in_date_to and transdate > in_date_from
+                order by transdate desc limit 1;
+        end if;
+	SELECT end_date INTO t_checkpoint_date 
+	FROM account_checkpoint
+	WHERE end_date <= in_date_from
+	ORDER BY end_date desc LIMIT 1;
+
+	FOR out_row IN
+		SELECT a.id, a.accno, a.description,
+			(SUM(CASE WHEN ac.transdate < in_date_from 
+                                  THEN ac.amount
+				  ELSE 0 END) + coalesce(cp.amount, 0))
+                                * case when a.contra then -1 else 1 end
+				* case when a.category IN ('A', 'E') THEN -1 
+                                  ELSE 1 END,
+			SUM(CASE WHEN (in_date_from is null 
+			              or in_date_from <= ac.transdate) AND
+                                      ac.amount < 0
+                                 THEN ac.amount ELSE 0 END),
+			SUM(CASE WHEN (in_date_from is null 
+			              or in_date_from <= ac.transdate) AND
+                                      ac.amount > 0
+                                 THEN ac.amount ELSE 0 END),
+                        (SUM(ac.amount) + coalesce(cp.amount, 0))
+                        * case when a.contra then -1 else 1 end
+                        * case when a.category IN ('A', 'E') THEN -1 ELSE 1 END
+		FROM account a 
+		JOIN acc_trans ac ON (a.id = ac.chart_id)
+		JOIN (select id, approved from ar
+		      UNION
+                      select id, approved from gl
+                      UNION
+                      select id, approved from ap) gl ON (ac.trans_id = gl.id)
+            LEFT JOIN yearend y ON (gl.id = y.trans_id)
+            LEFT JOIN (SELECT account_id, amount, end_date 
+                         FROM account_checkpoint 
+                        WHERE end_date = t_checkpoint_date) cp
+                       ON (cp.account_id = a.id)
+                WHERE ac.approved is true and gl.approved is true and
+                      (in_date_to is null or ac.transdate <= in_date_to) and
+                      (cp.end_date is null or ac.transdate > cp.end_date) and
+		      (in_heading is null or a.heading = in_heading or
+                       a.id = any(in_accounts)) and
+                       (in_ignore_yearend = 'none' OR y.id is NULL 
+                       or y.id = include_trans)
+		GROUP BY a.id, a.description, a.accno, a.contra, a.category,
+                         cp.amount
+	LOOP
+		RETURN NEXT out_row;
+	end loop;
+END;
+$$ language plpgsql;


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