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

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



Revision: 2851
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2851&view=rev
Author:   einhverfr
Date:     2010-01-27 18:51:31 +0000 (Wed, 27 Jan 2010)

Log Message:
-----------
Making the addon script a little smarter

Modified Paths:
--------------
    addons/1.3/assets/trunk/scripts/asset.pl
    addons/1.3/assets/trunk/sql/modules/Assets.sql
    addons/apply_addon.sh

Added Paths:
-----------
    addons/1.3/assets/trunk/UI/asset/search_reports.html

Added: addons/1.3/assets/trunk/UI/asset/search_reports.html
===================================================================
--- addons/1.3/assets/trunk/UI/asset/search_reports.html	                        (rev 0)
+++ addons/1.3/assets/trunk/UI/asset/search_reports.html	2010-01-27 18:51:31 UTC (rev 2851)
@@ -0,0 +1,75 @@
+<?lsmb INCLUDE 'ui-header.html' 
+      include_stylesheet = ["UI/asset/asset.css"] 
+?>
+<?lsmb PROCESS 'elements.html' ?>
+<body>
+<div class="listtop"><?lsmb title ?></div>
+<form action="<?lsmb script ?>" method="post">
+<div class="inputrow" id="classrow">
+<div class="inputgroup" id="classgroup">
+<?lsmb asset_classes.unshift({});
+PROCESS select element_data = {
+	 label = text('Asset Class') #'
+          name = asset_class
+default_values = [asset_class]
+         class = "class"
+       options = asset_classes
+    value_attr = 'id' 
+     text_attr = "label"
+} ?>
+</div>
+</div>
+<div class="inputrow" id="daterow">
+<div class="inputgroup" id="start-dategroup">
+<?lsmb PROCESS input element_data = {
+           label = text('From')
+           class = "date"
+            name = "start_date"
+           value = start_date
+            size = 12
+} ?>
+</div>
+<div class="inputgroup" id="end-dategroup">
+<?lsmb PROCESS input element_data = {
+           label = text('To')
+           class = "date"
+            name = "end_date"
+           value = end_date
+            size = 12
+} ?>
+</div>
+</div>
+<div class="inputrow" id="userrow">
+<!--
+<div class="inputgroup" id="createdbygrp">
+<?lsmb report_users.unshift({});
+PROCESS select element_data = {
+	 label = text('Created By') #'
+          name = "created_by"
+default_values = [created_by]
+         class = "users"
+       options = report_users
+    value_attr = 'entity_id' 
+     text_attr = "login"
+} ?>
+</div>
+-->
+<div class="inputgroup" id="approvedgroup">
+<?lsmb IF approved; approved = 'CHECKED'; END;
+PROCESS input element_data = {
+       label = text('Approved')
+        type = "checkbox"
+       value = approved
+} ?>
+</div>
+<div class="inputrow" id="buttonrow">
+<?lsmb PROCESS button element_data = {
+       name = "action"
+      value = "report_results"
+      text  = text('Search')
+      class = "submit"
+      type  = "submit"
+} ?>
+</form>
+</body>
+</html>

Modified: addons/1.3/assets/trunk/scripts/asset.pl
===================================================================
--- addons/1.3/assets/trunk/scripts/asset.pl	2010-01-27 18:42:26 UTC (rev 2850)
+++ addons/1.3/assets/trunk/scripts/asset.pl	2010-01-27 18:51:31 UTC (rev 2851)
@@ -344,6 +344,7 @@
                                             type  => 'text',
                                             class => 'amount',
                                             value => $request->{"amount_$asset->{id}"},
+                                            size  => 20,
                                           },
                                 },
             };
@@ -386,4 +387,77 @@
     });
 }
 
+sub search_reports {
+    my ($request) = @_;
+    $request->{title} = $request->{_locale}->text('Search reports');
+    my $ar = LedgerSMB::DBObject::Asset_Report->new(base => $request);
+    $ar->get_metadata;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI/asset',
+        template => 'search_reports',
+        format => 'HTML'
+    );
+    $template->render($ar);
+}
+
+sub report_results {
+    my ($request) = @_;
+    my $locale = $request->{_locale};
+    my $ar = LedgerSMB::DBObject::Asset_Report->new(base => $request);
+    $ar->get_metadata;
+    my @results = $ar->search;
+    my $cols = [];
+    @$cols = qw(select id report_date type asset_class entered_at 
+                   approved_at); 
+    my $header = {
+                        id => $locale->text('ID'),
+               report_date => $locale->text('Date'),
+                      type => $locale->text('Type'),
+               asset_class => $locale->text('Asset Class'),
+                entered_at => $locale->type('Entered at'),
+               approved_at => $locale->type('Approved at'),
+    };
+    my $rows = [];
+    my $hiddens = {};
+    my $count = 0;
+    for my $r (@results){
+        $hidden->{"id_$count"} = $r->{id};
+        my $ref = {
+              select         => {input => { name    => "report_$count",
+                                            checked => $asset->{checked},
+                                            type    => "checkbox",
+                                            value   => '1',
+                                          },
+                                },
+               id             => $r->{id},
+               report_date    => $r->{report_date},
+               entered_at     => $r->{entered_at},
+               approved_at    => $r->{approved_at},
+        };
+        for my $ac (@{$ar->{asset_classes}}){
+            if ($ac->{id} = $r->{asset_class}){
+                $ref->{asset_class} = $ac->{label};
+            }
+        }
+        if ($r->{depreciation}){
+           $r->{type} = $locale->text('Depreciation');
+        } else {
+           $r->{type} = $locale->text('Disposal');
+        }
+        ++$count;
+    }
+    my $buttons = [{
+                   text  => $locale->text('Approve'),
+                   type  => 'submit',
+                   class => 'submit',
+                   action => 'approve'
+                   },
+    ];
+}
+
+sub report_results_approve {
+}
+
 1;

Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-01-27 18:42:26 UTC (rev 2850)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql	2010-01-27 18:51:31 UTC (rev 2851)
@@ -432,6 +432,35 @@
     SELECT * FROM account__get_by_link_desc('asset_loss');
 $$ language sql;
 
+CREATE OR REPLACE FUNCTION asset_report__get(in_id int)
+RETURNS asset_report
+AS
+$$
+select * from asset_report where id = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION asset_report__get_lines(in_id int)
+RETURNS SETOF asset_report_line
+as $$
+select * from asset_report_line where id = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION asset_report__search
+(in_start_date date, in_end_date date, in_asset_class int, in_approved bool,
+ in_entered_by int)
+returns setof asset_report AS $$
+
+SELECT * 
+  FROM asset_report
+ where ($1 is null or $1 >= report_date)
+       and ($2 is null or $2 <= report_date)
+       and ($3 is null or $3 = asset_class)
+       and ($4 is null 
+            or ($4 is true and approved_by is not null)
+            or ($4 is false and approved_by is null))
+       and ($5 is null or $5 = entered_by);
+$$ language sql;
+
 CREATE OR REPLACE FUNCTION asset_report__generate
 (in_depreciation bool, in_asset_class int, in_report_date date) 
 RETURNS SETOF asset_item AS
@@ -470,16 +499,30 @@
 
 $$ language plpgsql;
 
+create or replace function asset_report__record_approve(in_id int)
+returns asset_report
+as $$
+UPDATE asset_report 
+   set approved_by = person__get_my_entity_id(),
+       approved_at = now()
+ where id = $1
+       and approved_by is null;
+
+select * from asset_report where id = $1;
+
+$$ language sql;
+
+
+declare retval asset_report;
+$$ language plpgsql;
+
 create or replace function asset_depreciation__approve(in_report_id int, in_expense_acct int)
 returns asset_report
 as $$
 declare retval asset_report;
 begin
 
-UPDATE asset_report 
-   set approved_by = person__get_my_entity_id(),
-       approved_at = now()
- where id = in_report_id;
+retval := asset_report__record_approve(in_report_id)
 
 INSERT INTO gl (reference, description, approved)
 select 'Asset Report ' || in_id, 'Asset Depreciation Report for ' || report_date,
@@ -517,18 +560,13 @@
    iter record;
 begin
 
-UPDATE asset_report 
-   set approved_by = person__get_my_entity_id(),
-       approved_at = now()
- where id = in_report_id;
+retval := asset_report__record_approve(in_report_id)
 
 INSERT INTO gl (reference, description, approved)
 select 'Asset Report ' || in_id, 'Asset Depreciation Report for ' || report_date,
        false
  FROM asset_report where id = in_id;
 
-SELECT * INTO retval FROM asset_report WHERE id = in_id;
-
 -- REMOVING ASSETS FROM ACCOUNT
 insert into acc_trans (trans_id, chart_id, amount, approved, transdate)
 SELECT currval('id'), a.asset_account_id, a.purchase_value, true, r.report_date

Modified: addons/apply_addon.sh
===================================================================
--- addons/apply_addon.sh	2010-01-27 18:42:26 UTC (rev 2850)
+++ addons/apply_addon.sh	2010-01-27 18:51:31 UTC (rev 2851)
@@ -1,9 +1,20 @@
 #!/bin/sh
+if test -z $1; then
+   echo 'Usage:  (from lsmb root directory)'
+   echo "sh addons/apply_addons.sh [addon] [tag]"
+fi
+
+if test -z $2; then 
+   branch='trunk'
+else
+   branch="tags/$2"
+fi
+
 for a in `
-        find addons/1.3/$1/trunk -type f | 
+        find addons/1.3/$1/$branch -type f | 
              grep -v .svn | 
-             sed -e "s|addons/1.3/$1/trunk/||"
+             sed -e "s|addons/1.3/$1/$branch/||"
         `; 
 do 
-         cp -r addons/1.3/$1/trunk/$a $a; 
+         cp -r addons/1.3/$1/$branch/$a $a; 
 done 


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