[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2818] addons/1.3/assets/trunk
- Subject: SF.net SVN: ledger-smb:[2818] addons/1.3/assets/trunk
- From: ..hidden..
- Date: Fri, 11 Dec 2009 17:00:54 +0000
Revision: 2818
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2818&view=rev
Author: einhverfr
Date: 2009-12-11 17:00:54 +0000 (Fri, 11 Dec 2009)
Log Message:
-----------
Assets are now editable
Modified Paths:
--------------
addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
addons/1.3/assets/trunk/UI/asset/asset.css
addons/1.3/assets/trunk/UI/asset/asset.js
addons/1.3/assets/trunk/scripts/asset.pl
addons/1.3/assets/trunk/sql/modules/Assets.sql
Modified: addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm
===================================================================
--- addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm 2009-12-10 22:38:23 UTC (rev 2817)
+++ addons/1.3/assets/trunk/LedgerSMB/DBObject/Asset.pm 2009-12-11 17:00:54 UTC (rev 2818)
@@ -26,7 +26,7 @@
return $ref if $self->{dbh}->commit;
}
-sub get_asset {
+sub get {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset__get');
$self->merge($ref);
Modified: addons/1.3/assets/trunk/UI/asset/asset.css
===================================================================
--- addons/1.3/assets/trunk/UI/asset/asset.css 2009-12-10 22:38:23 UTC (rev 2817)
+++ addons/1.3/assets/trunk/UI/asset/asset.css 2009-12-11 17:00:54 UTC (rev 2818)
@@ -13,3 +13,7 @@
overflow: auto;
width: 100%;
}
+
+.invisible {
+ display: none;
+}
Modified: addons/1.3/assets/trunk/UI/asset/asset.js
===================================================================
--- addons/1.3/assets/trunk/UI/asset/asset.js 2009-12-10 22:38:23 UTC (rev 2817)
+++ addons/1.3/assets/trunk/UI/asset/asset.js 2009-12-11 17:00:54 UTC (rev 2818)
@@ -35,4 +35,6 @@
function init(){
document.getElementById('asset-class').addEventListener('blur', Function('setDefaultAccount()'), false);
setDefaultAccount();
+ document.getElementById('update-accounts').setAttribute('class', 'generic');
+ document.getElementById('update-accounts').addEventListener('click', 'return false', false);
}
Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl 2009-12-10 22:38:23 UTC (rev 2817)
+++ addons/1.3/assets/trunk/scripts/asset.pl 2009-12-11 17:00:54 UTC (rev 2818)
@@ -115,6 +115,17 @@
});
}
+sub asset_edit {
+ my ($request) = @_;
+ my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
+ $asset->get();
+ for my $label (qw(purchase_value salvage_value usable_life)){
+ $asset->{$label} = $asset->format_amount({amount => $asset->{$label}});
+ }
+ asset_screen($asset);
+}
+
+
sub asset_screen {
my ($request) = @_;
my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
@@ -170,10 +181,13 @@
my $rows = [];
for my $item (@items){
my $ref = {};
- for my $label (qw(id tag description purchase_date purchase_value
+ for my $label (qw(id description purchase_date purchase_value
usable_life)){
$ref->{$label} = $item->{$label};
}
+ $ref->{tag} = { href => "asset.pl?action=asset_edit&id=$item->{id}",
+ text => $item->{tag},
+ };
for my $label (qw(purchase_value usable_life)){
$ref->{$label} = $asset->format_amount({amount => $ref->{$label}});
}
Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql 2009-12-10 22:38:23 UTC (rev 2817)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql 2009-12-11 17:00:54 UTC (rev 2818)
@@ -5,16 +5,52 @@
$$ language sql;
CREATE OR REPLACE FUNCTION asset_dep__used_months
-(in_last_dep date, in_dep_date date, in_total_used numeric, in_usable_life numeric)
+(in_last_dep date, in_dep_date date, in_usable_life numeric)
RETURNS numeric AS
$$
select CASE WHEN extract('MONTHS' FROM (date_trunc('day', $2) - date_trunc('day', $1)))
- > $4
- THEN $4
+ > $3
+ THEN $3
ELSE extract('MONTHS' FROM (date_trunc('day', $2) - date_trunc('day', $1)))::numeric
END;
$$ language sql;
+CREATE OR REPLACE FUNCTION asset_dep_get_usable_life_yr
+(in_usable_life numeric, in_start_date date, in_last_dep_date date)
+returns numeric as
+$$
+ SELECT CASE WHEN $3 IS NULL then $1
+ ELSE $1 - get_fractional_year($2, $3)
+ END;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION asset_dep_straight_line_yr
+(in_asset_ids int[], in_dep_date date, in_report_id int)
+RETURNS numeric AS
+$$
+ INSERT INTO asset_report_line (asset_id, report_id, amount, department_id,
+ warehouse_id)
+ SELECT ai.id, $3,
+ asset_dep__straight_line_base(
+ asset_dep_get_usable_life_yr(
+ ai.usable_life,
+ coalesce(
+ ai.start_depreciation,
+ ai.purchase_date
+ ),
+ max(rep.report_date)
+ ),
+ get_fractional_year(max(rep.report_date), $2),
+ ai.purchase_value - ai.salvage_value
+ ),
+ ai.department_id, ai.location_id
+ FROM asset_item ai
+ LEFT JOIN asset_report_line repline ON (rep.asset_id = ai.id)
+ LEFT JOIN asset_report rep ON (repline.report_id = rep.id)
+ WHERE ai.id = ANY ($1)
+ GROUP BY
+$$ language sql;
+
CREATE OR REPLACE FUNCTION asset_report__generate_gl(in_report_id int)
RETURNS INT AS
$$
@@ -160,7 +196,8 @@
$$
DECLARE ret_val asset_item;
BEGIN
- SELECT * into ret_val from asset_item WHERE id = in_id and in_tag = tag;
+ SELECT * into ret_val from asset_item WHERE id = in_id OR in_tag = tag
+ ORDER BY id desc limit 1;
return ret_val;
END;
$$ language plpgsql;
@@ -306,7 +343,7 @@
item record;
method_text text;
BEGIN
- DELETE FROM asset_item where report_id = in_id;
+ DELETE FROM asset_report_line where report_id = in_id;
UPDATE asset_report
set asset_class = in_asset_class,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.