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

SF.net SVN: ledger-smb:[3866] addons/1.3/budgetting/trunk/scripts/budgets. pl



Revision: 3866
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3866&view=rev
Author:   einhverfr
Date:     2011-10-15 00:05:51 +0000 (Sat, 15 Oct 2011)
Log Message:
-----------
More budgetting fixes

Modified Paths:
--------------
    addons/1.3/budgetting/trunk/scripts/budgets.pl

Modified: addons/1.3/budgetting/trunk/scripts/budgets.pl
===================================================================
--- addons/1.3/budgetting/trunk/scripts/budgets.pl	2011-10-14 23:15:44 UTC (rev 3865)
+++ addons/1.3/budgetting/trunk/scripts/budgets.pl	2011-10-15 00:05:51 UTC (rev 3866)
@@ -42,16 +42,84 @@
 sub new_budget {
     my ($request) = @_;
     my $budget = LedgerSMB::DBObject::Budget->new({base => $request});
+    for (1 .. 25) {
+        push @{$budget->{display_rows}}, {accnoset => 0, index => $_};
+    }
+    _render_screen($budget);
+}
+
+
+# Private method _render_screen
+# used by new_budget, view_budget, and update
+# Prepares and renders screen with budget info.
+
+sub _render_screen {
+    my ($budget) = @_;
+    $budget->error('Invalid object') 
+         unless $budget->isa('LedgerSMB::DBObject::Budget');
     @{$budget->{projects}} = $budget->list_projects;
+    unshift @{$budget->{projects}}, {};
     @{$budget->{departments}} = $budget->list_departments;
+    unshift @{$budget->{departments}}, {};
     $budget->{display_rows} = [];
-    for (1 .. 25) {
-        push @{$budget->{display_rows}}, {accnoset => 0, index => $_};
+    # The button logic is kinda complicated here.  The basic idea is that there
+    # are three stages in the handling of the budget:  Initial entry, review and
+    # approval, and review with the possibility of obsolescence.
+    #
+    # In the initial entry, there is no budget yet.  Therefore id is not set.
+    # One can update the screen and save, but nothing else.
+    #
+    # Once id is set, if the budget has not been approved, it can be approved or
+    # rejected.  Rejecting deletes the budgets in the current implementation,
+    # but other options are possible as customizations.
+    #
+    # Once the budget is approved, it can no longer be deleted.  If
+    # circumstances change, however, it can still be marked obsolete.  Obsolete
+    # budgets are available for review, but one would not generally run variance
+    # reports against them.
+    if (!$budget->{id}){
+       $budget->{buttons} = [
+             {   name => 'action',
+                 text => $budget->{_locale}->text('Update'),
+                 type => 'submit',
+                value => 'update',
+                class => 'submit',
+             },
+             {   name => 'action',
+                 text => $budget->{_locale}->text('Save'),
+                 type => 'submit',
+                value => 'save',
+                class => 'submit',
+             },
+       ];
+     } elsif (!$budget->{approved_by}){
+         $budget->{buttons} = [
+             {   name => 'action',
+                 text => $budget->{_locale}->text('Approve'),
+                 type => 'submit',
+                value => 'approve',
+                class => 'submit',
+             },
+             {   name => 'action',
+                 text => $budget->{_locale}->text('Reject'),
+                 type => 'submit',
+                value => 'reject',
+                class => 'submit',
+             },
+         ];
+     } else {
+         $budget->{buttons} = [
+             {   name => 'action',
+                 text => $budget->{_locale}->text('Obsolete'),
+                 type => 'submit',
+                value => 'approve',
+                class => 'submit',
+             },
+        ];
     }
-    # TODO:  Add buttons
     my $template = LedgerSMB::Template->new(
-        user     => $request->{_user},
-        locale   => $request->{_locale},
+        user     => $budget->{_user},
+        locale   => $budget->{_locale},
         path     => 'UI/budgetting',
         template => 'budget_entry',
         format   => 'HTML'
@@ -60,6 +128,15 @@
     $template->render($budget);
 }
 
+=item update
+Updates the screen.  Part of initial entry workflow only.
+
+=cut
+
+sub update {
+    new_budget(@_); 
+}
+
 =item view_budget
 Reuuires id to be set.  Displays a budget for review.
 
@@ -71,17 +148,7 @@
            {base => $request, copy => 'base'}
     );
     $budget->get($request->{id});
-    @{$budget->{projects}} = $budget->list_projects;
-    @{$budget->{departments}} = $budget->list_departments;
-    # TODO:  Add buttons
-    my $template = LedgerSMB::Template->new(
-        user     => $request->{_user},
-        locale   => $request->{_locale},
-        path     => 'UI/budgetting',
-        template => 'budget_entry',
-        format   => 'HTML'
-    );
-    $template->render($budget);
+    _render_screen($budget);
 }
 
 =item save_budget

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