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

SF.net SVN: ledger-smb:[5750] trunk



Revision: 5750
          http://sourceforge.net/p/ledger-smb/code/5750
Author:   einhverfr
Date:     2013-05-10 05:15:16 +0000 (Fri, 10 May 2013)
Log Message:
-----------
Fixing numerous budget module problems

Modified Paths:
--------------
    trunk/LedgerSMB/Budget.pm
    trunk/LedgerSMB/Report/Budget/Variance.pm
    trunk/LedgerSMB/Scripts/budgets.pm
    trunk/UI/budgetting/budget_entry.html
    trunk/sql/modules/Budgetting.sql
    trunk/sql/modules/Roles.sql

Modified: trunk/LedgerSMB/Budget.pm
===================================================================
--- trunk/LedgerSMB/Budget.pm	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/LedgerSMB/Budget.pm	2013-05-10 05:15:16 UTC (rev 5750)
@@ -1,10 +1,10 @@
 =head1 NAME
 
-LedgerSMB::DBObject::Budget
+LedgerSMB::Budget
 
 =cut
 
-package LedgerSMB::DBObject::Budget;
+package LedgerSMB::Budget;
 use LedgerSMB::PGDate;
 use strict;
 our $VERSION = 0.1;
@@ -14,7 +14,7 @@
 This module provides budget management routines, such as entering budgets,
 approving or rejecting them, and marking them obsolete.  It does not include
 more free-form areas like reporting.  For those, see
-LedgerSMB::DBObject::Budget_Report.
+LedgerSMB::Budget_Report.
 
 =head1 INHERITANCE
 
@@ -22,7 +22,7 @@
 
 =item LedgerSMB
 
-=item LedgerSMB::DBObject
+=item LedgerSMB::DBObject_Moose
 
 =back
 
@@ -158,6 +158,9 @@
 =item $accno text
    The account number for the coa entry
 
+=item $acc_desc text
+   Description of COA entry.
+
 =item $amount numeric
    The amount budgetted
 
@@ -246,16 +249,20 @@
          } elsif(!$input->{"debit_$rownum"} and !$input->{"credit_$rownum"}){
              next;
          } else {
-             $line->{amount} = $input->{"credit_$rownum"} 
-                             - $input->{"debit_$rownum"};
+             $line->{amount} =   $input->{"credit_$rownum"} 
+                               - $input->{"debit_$rownum"};
+             $line->{credit} = $line->{amount} if $line->{amount} > 0;
+             $line->{debit}  = $line->{amount} * -1 if $line->{amount} < 0;
          }
-         my ($accno) = split /--/, $input->{"account_id_$rownum"};
+         my ($accno) = split /--/, $input->{"accno_$rownum"};
          my ($ref) = $input->call_procedure(
                        procname => 'account__get_from_accno',
                            args => [$accno]
           );
          $line->{description} = $input->{"description_$rownum"};
          $line->{account_id} = $ref->{id};
+         $line->{accno} = $ref->{accno};
+         $line->{acc_desc} = $ref->{description};
          push @{$input->{lines}}, $line;
     }
     return $self->new(%$input);
@@ -382,10 +389,8 @@
 
 =item LedgerSMB
 
-=item LedgerSMB::DBObject
+=item LedgerSMB::DBObject_Moose
 
-=item LedgerSMB::DBObject::Budget_Report
-
 =back
 
 =head1 COPYRIGHT AND LICENSE
@@ -397,7 +402,4 @@
 =cut
 
 __PACKAGE__->meta->make_immutable;
-return 1;
 
-
-

Modified: trunk/LedgerSMB/Report/Budget/Variance.pm
===================================================================
--- trunk/LedgerSMB/Report/Budget/Variance.pm	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/LedgerSMB/Report/Budget/Variance.pm	2013-05-10 05:15:16 UTC (rev 5750)
@@ -20,6 +20,7 @@
 package LedgerSMB::Report::Budget::Variance;
 use Moose;
 extends 'LedgerSMB::Report';
+use LedgerSMB::Budget;
 
 =head1 PROPERTIES
 
@@ -179,9 +180,8 @@
 
 sub for_budget_id {
     my ($self, $id) = @_;
-    use LedgerSMB::DBObject::Budget;
 
-    my $budget = LedgerSMB::DBObject::Budget->get($id);
+    my $budget = LedgerSMB::Budget->get($id);
     my $report = $self->new(%$budget); 
     return $report;
 }

Modified: trunk/LedgerSMB/Scripts/budgets.pm
===================================================================
--- trunk/LedgerSMB/Scripts/budgets.pm	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/LedgerSMB/Scripts/budgets.pm	2013-05-10 05:15:16 UTC (rev 5750)
@@ -28,14 +28,14 @@
 =over
 
 =item new_budget 
-No inputs provided.  LedgerSMB::DBObject::Budget properties can be used to set
+No inputs provided.  LedgerSMB::Budget properties can be used to set
 defaults however.
 
 =cut
 
 sub new_budget {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->from_input($request);
+    my $budget = LedgerSMB::Budget->from_input($request);
     _render_screen($budget);
 }
 
@@ -47,12 +47,12 @@
 sub _render_screen {
     my ($budget) = @_;
     my $additional_rows = 5;
-    $additional_rows +=20 unless $budget->{rowcount};
-    $additional_rows = 0 if $budget->{id};
-    $budget->{class_id} = 0 unless $budget->{class_id};
-    $budget->{control_code} = '' unless $budget->{control_code};
-    my $buc = LedgerSMB::Business_Unit_Class->new(%$budget);
-    my $bu = LedgerSMB::Business_Unit->new(%$budget);
+    $additional_rows +=20 unless $budget->lines;
+    $additional_rows = 0 if $budget->id;
+    my $buc = LedgerSMB::Business_Unit_Class->new(
+           control_code => '', class_id => 0
+    );
+    my $bu = LedgerSMB::Business_Unit->new(control_code => '', class_id => 0);
     @{$budget->{bu_classes}} = $buc->list(1, 'gl');
     for my $bc (@{$budget->{bu_classes}}){
         @{$budget->{b_units}->{$bc->{id}}}
@@ -63,12 +63,14 @@
     }
     $budget->{rowcount} ||= 0;
     for (1 .. $additional_rows) {
-        push @{$budget->{display_rows}}, 
+        my $lines = $budget->lines;
+        push @{$lines}, 
              {accnoset => 0, index => $_ + $budget->{rowcount}};
         ++$budget->{rowcount};
+        $budget->lines($lines);
     }
     $budget->error('Invalid object') 
-         unless $budget->isa('LedgerSMB::DBObject::Budget');
+         unless $budget->isa('LedgerSMB::Budget');
     # 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.
@@ -145,6 +147,7 @@
 
 sub update {
     my ($request) = @_;
+    $request->{display_rows} = [];
     for (1 .. $request->{rowcount}){
         push @{$request->{display_rows}}, 
              { account_id => $request->{"account_id_$_"},
@@ -154,7 +157,7 @@
              } if ($request->{"debit_$_"} or $request->{"credit_$_"});
              
     }
-    $request->{rowcount} = scalar @{$request->{display_rows}};
+    $request->{rowcount} = scalar @{$request->{display_rows}} + 1;
     new_budget(@_); 
 }
 
@@ -165,7 +168,7 @@
 
 sub view_budget {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+    my $budget = LedgerSMB::Budget->new(%$request);
     $budget = $budget->get($request->{id});
     $budget->{display_rows} = [];
     for my $line (@{$budget->{lines}}){
@@ -187,14 +190,14 @@
 }
 
 =item save
-LedgerSMB::DBObject::Budget properties required.  Lines represented by
+LedgerSMB::Budget properties required.  Lines represented by
 [property]_[line number] notation.
 
 =cut
 
 sub save {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->from_input($request);
+    my $budget = LedgerSMB::Budget->from_input($request);
     $budget->save();
     view_budget($budget); 
 } 
@@ -206,7 +209,7 @@
 
 sub approve {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+    my $budget = LedgerSMB::Budget->new(%$request);
     $budget->approve;
     view_budget($request);
 } 
@@ -218,7 +221,7 @@
 
 sub reject {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+    my $budget = LedgerSMB::Budget->new(%$request);
     $budget->reject;
     begin_search($request);
 } 
@@ -230,7 +233,7 @@
 
 sub obsolete {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+    my $budget = LedgerSMB::Budget->new(%$request);
     $budget->obsolete;
     view_budget($request);
 } 
@@ -242,7 +245,7 @@
 
 sub add_note {
     my ($request) = @_;
-    my $budget = LedgerSMB::DBObject::Budget->new(%$request);
+    my $budget = LedgerSMB::Budget->new(%$request);
     $budget->save_note($request->{subject}, $request->{note});
     view_budget($request);
 } 

Modified: trunk/UI/budgetting/budget_entry.html
===================================================================
--- trunk/UI/budgetting/budget_entry.html	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/UI/budgetting/budget_entry.html	2013-05-10 05:15:16 UTC (rev 5750)
@@ -71,26 +71,26 @@
 	  <th class="listheading"><?lsmb text('Credit') ?></th>
 	  <th class="listheading"><?lsmb text('Description') ?></th>
 	</tr>
-	<?lsmb FOREACH displayrow IN display_rows ?> 
+	<?lsmb FOREACH displayrow IN lines ?> 
 	<tr>
 		<?lsmb INDEX= loop.count ?>
 		  <td>
 			<?lsmb IF displayrow.accnoset == 0 ?>
               			<?lsmb PROCESS ajaxselect element_data = {
-		                     name = "account_id_$INDEX"
-		                     initial_value = ${"accno_$INDEX"}
+		                     name = "accno_$INDEX"
+		                     initial_value = displayrow.accno
 		                     text_attr = 'accno'
-		                     value_attr = 'id'
+		                     value_attr = 'accno'
 		                     ajax_target = 'journal.pl'
 		              } ?> 
 			   
 			  <?lsmb ELSE ?>
 			      
 				      <?lsmb PROCESS input element_data = {
-					label = displayrow.account_id
+					label = displayrow.accno _ '--' _ displayrow.acc_desc
                                         type = "hidden"
-                                        value = displayrow.account_id
-                                        name = "account_id_$INDEX"
+                                        value = displayrow.accno
+                                        name = "accno_$INDEX"
 					id = "acc_$INDEX"
 				      } ?>
 			      
@@ -170,24 +170,7 @@
 }
 ?>
 </div></div>
-<div class="input_group"><?lsmb INCLUDE input element_data = {
-     name="subject"
-     size="50"
-     type="text"
-    class="subject" 
-} ?></div>
-    
-<div class="input_group"> <?lsmb INCLUDE textarea element_data={
-							name = "notes"
-							rows = form.rowsnotes
-							cols = form.colsnotes
-							value = form.notes
-							id = "not_1"
-    							label = text('Notes')
-                                                 	    } 
-			       ?></div>
 <div class="inputrow">
-<div class="inputgroup">
 <?lsmb PROCESS button element_data = {
         name = "action"
        value = 'add_note'
@@ -196,7 +179,7 @@
         text = text('Add Note') #'
 }
 ?>
-</div></div>
+</div>
 </form>
 <?lsmb END # IF id ?>
 <?lsmb FOREACH note IN notes ?>

Modified: trunk/sql/modules/Budgetting.sql
===================================================================
--- trunk/sql/modules/Budgetting.sql	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/sql/modules/Budgetting.sql	2013-05-10 05:15:16 UTC (rev 5750)
@@ -195,10 +195,31 @@
 where each entry is {int account_id, text description, numeric amount}.  The
 in_id parameter is the budget_id.$$;
 
+DROP TYPE IF EXISTS budget_line_details CASCADE;
+
+CREATE TYPE budget_line_details AS (
+    budget_id int,
+    account_id int,
+    description text,
+    amount numeric,
+    accno text,
+    acc_desc text,
+    debit numeric,
+    credit numeric
+);
+
+
+DROP FUNCTION IF EXISTS budget__get_details(int) CASCADE;
 CREATE OR REPLACE FUNCTION budget__get_details(in_id int)
-RETURNS SETOF budget_line AS
+RETURNS SETOF budget_line_details AS
 $$
-  SELECT * FROM budget_line where budget_id = $1;
+  SELECT l.budget_id, l.account_id, l.description, l.amount,
+         a.accno, a.description,
+         CASE WHEN l.amount < 0 THEN l.amount * -1 ELSE NULL END,
+         CASE WHEN l.amount > 0 THEN l.amount ELSE NULL END
+    FROM budget_line l
+    JOIN account a ON a.id = l.account_id
+   where budget_id = $1;
 $$ language sql;
 
 COMMENT ON FUNCTION budget__get_details(in_id int) IS

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2013-05-08 09:42:25 UTC (rev 5749)
+++ trunk/sql/modules/Roles.sql	2013-05-10 05:15:16 UTC (rev 5750)
@@ -5,6 +5,9 @@
 CREATE ROLE "lsmb_<?lsmb dbname ?>__budget_approve" WITH INHERIT NOLOGIN
 IN ROLE "lsmb_<?lsmb dbname ?>__budget_view";
 
+GRANT INSERT ON budget_info, budget_to_business_unit, budget_line, budget_note 
+TO "lsmb_<?lsmb dbname ?>__budget_enter";
+
 CREATE ROLE "lsmb_<?lsmb dbname ?>__budget_obsolete" WITH INHERIT NOLOGIN
 IN ROLE "lsmb_<?lsmb dbname ?>__budget_view";
 

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