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

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



Revision: 3134
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3134&view=rev
Author:   einhverfr
Date:     2011-04-22 15:41:54 +0000 (Fri, 22 Apr 2011)

Log Message:
-----------

Fixes for reconciliation regarding reconciliation of non-asset accounts (and appropriate code cleanup there)
Vouchers in batches now editable

Modified Paths:
--------------
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/AM.pm
    trunk/LedgerSMB/DBObject/Reconciliation.pm
    trunk/LedgerSMB/GL.pm
    trunk/bin/aa.pl
    trunk/bin/gl.pl
    trunk/scripts/recon.pl
    trunk/scripts/vouchers.pl
    trunk/sql/modules/Reconciliation.sql
    trunk/sql/modules/Voucher.sql

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/LedgerSMB/AA.pm	2011-04-22 15:41:54 UTC (rev 3134)
@@ -303,8 +303,21 @@
            # delete detail records
 
 	    $dbh->do($query) || $form->dberror($query);
+            $query = qq|
+				DELETE FROM ac_tax_form
+                                       WHERE entry_id IN 
+                                             (SELECT entry_id FROM acc_trans
+				              WHERE trans_id = $id)|;
 
+            $dbh->do($query) || $form->dberror($query);
             $query = qq|
+				DELETE FROM voucher
+                                       WHERE trans_id = $id 
+                                             and batch_class in (1,2)|;
+
+            $dbh->do($query) || $form->dberror($query);
+
+            $query = qq|
 				DELETE FROM acc_trans
 				 WHERE trans_id = $id|;
 
@@ -707,9 +720,12 @@
     );
 
     $form->audittrail( $dbh, "", \%audittrail );
+    my $query = qq|DELETE FROM ac_tax_form WHERE entry_id IN
+                   SELECT entry_id FROM acc_trans WHERE trans_id = ?|;
+    $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
 
-    my $query = qq|DELETE FROM $table WHERE id = $form->{id}|;
-    $dbh->do($query) || $form->dberror($query);
+    $query = qq|DELETE FROM $table WHERE id = ?|;
+    $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
 
     $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
     $dbh->prepare($query)->execute( $form->{id} ) || $form->dberror($query);

Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/LedgerSMB/AM.pm	2011-04-22 15:41:54 UTC (rev 3134)
@@ -776,6 +776,9 @@
     }
 
     $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+    my $sth = $dbh->prepare("SELECT currval('business_id_seq')");
+    $sth->execute();
+    ($form->{id}) = $sth->fetchrow_array;
     $dbh->commit;
 
 }

Modified: trunk/LedgerSMB/DBObject/Reconciliation.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Reconciliation.pm	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/LedgerSMB/DBObject/Reconciliation.pm	2011-04-22 15:41:54 UTC (rev 3134)
@@ -328,6 +328,13 @@
     @{$self->{report_lines}} = $self->exec_method(
 		funcname=>'reconciliation__report_details'
     );
+    ($ref) = $self->exec_method(funcname=>'account_get', 
+                                args => [$self->{chart_id}]);
+    my $neg = 1;
+    if ($self->{account_info}->{category} =~ /(A|E)/){
+        $neg = -1;
+    }
+    $self->{account_info} = $ref;
     ($ref) = $self->exec_method(
                 funcname=>'reconciliation__get_cleared_balance'
     );
@@ -346,8 +353,8 @@
 
     for my $line (@{$self->{report_lines}}){
         if ($line->{cleared}){
-            $our_balance += $line->{our_balance};
-            $self->{cleared_total} += $line->{our_balance};
+            $our_balance += ($neg * $line->{our_balance});
+            $self->{cleared_total} += ($neg * $line->{our_balance});
 	}elsif ((($self->{their_balance} != '0')
 		and ($self->{their_balance} != $self->{our_balance}))
 		or $line->{our_balance} == 0){
@@ -377,6 +384,10 @@
        }
     }
     $self->{format_amount} = sub { return $self->format_amount(@_); };
+    if ($self->{account_info}->{category} =~ /(A|E)/){
+       $self->{our_total} *= -1;
+       $self->{mismatch_their_total} *= -1;
+    }
 }
 
 sub get_accounts {

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/LedgerSMB/GL.pm	2011-04-22 15:41:54 UTC (rev 3134)
@@ -94,6 +94,11 @@
 				DELETE FROM acc_trans WHERE trans_id = $id|;
 
             $dbh->do($query) || $form->dberror($query);
+            $query = qq|
+				DELETE FROM voucher WHERE trans_id = $id
+                                            and batch_class = 5|;
+
+            $dbh->do($query) || $form->dberror($query);
         }
     }
 

Modified: trunk/bin/aa.pl
===================================================================
--- trunk/bin/aa.pl	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/bin/aa.pl	2011-04-22 15:41:54 UTC (rev 3134)
@@ -981,9 +981,12 @@
 
         if ($form->{separate_duties} || $form->{batch_id}){
             $button{post}->{value} = $locale->text('Save');
+            $button{print_and_post}->{value} = $locale->text('Save and Post');
+            $button{post_as_new}->{value} = $locale->text('Save as New');
+            $button{print_and_post_as_new}->{value} = $locale->text('Save and Post as New');
             $form->hide_form('separate_duties');
         }
-        if ( $form->{id} ) {
+        if ( $form->{id} && ($form->{approved} || !$form->{batch_id})) {
             if ( $form->{locked} || ( $transdate && $transdate <= $closedto ) )
             {
                 for ( "post", "print_and_post", "delete" ) {
@@ -998,7 +1001,7 @@
             }
 
         }
-        else {
+        elsif (!$form->{id}) {
 
             for ( "post_as_new", "print_and_post_as_new", "delete","save_info" ) {
                 delete $button{$_};
@@ -2066,7 +2069,10 @@
             push @projects, @{$ref->{inv_projects}};
             $ref->{projectnumber} = join '<br />', @projects;
             $ref->{projectnumber} =~ s/(<br \/>)+/<br \/>/;
-        } else { $form->error($ref->{ac_projects} . $ref->{inv_projects})}
+        } else { $form->error($locale->text('Invalid Project Data:'). 
+                              $ref->{ac_projects} . $ref->{inv_projects}
+                             )
+        }
         if ( $form->{l_subtotal} eq 'Y' ) {
             if ( $sameitem ne $ref->{ $form->{sort} } ) {
                 &subtotal;

Modified: trunk/bin/gl.pl
===================================================================
--- trunk/bin/gl.pl	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/bin/gl.pl	2011-04-22 15:41:54 UTC (rev 3134)
@@ -264,7 +264,7 @@
 		  $button{post}->{value} = $locale->text('Save'); 
 	      }
 	      %a = ();
-	      if ( $form->{id} ) {
+	      if ( $form->{id} && ($form->{approved} || !$form->{batch_id})) {
 
 		  for ( 'update', 'post_as_new', 'schedule' ) { $a{$_} = 1 }
 
@@ -275,7 +275,7 @@
 		  }
 
 	      }
-	      else {
+	      elsif (!$form->{id}){
 		  if ( $transdate > $closedto ) {
 		      for ( "post", "schedule" ) { $a{$_} = 1 }
 		  }

Modified: trunk/scripts/recon.pl
===================================================================
--- trunk/scripts/recon.pl	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/scripts/recon.pl	2011-04-22 15:41:54 UTC (rev 3134)
@@ -359,25 +359,31 @@
         $recon->{total_cleared_debits} = $recon->parse_amount(amount => 0);
         $recon->{total_uncleared_credits} = $recon->parse_amount(amount => 0);
         $recon->{total_uncleared_debits} = $recon->parse_amount(amount => 0);
+        my $neg_factor = 1;
+        if ($recon->{account_info}->{category} =~ /(A|E)/){
+           $recon->{their_total} *= -1;
+           $neg_factor = -1;
+           
+        }
 
 
         # Credit/Debit separation (useful for some)
         for my $l (@{$recon->{report_lines}}){
-            if ($l->{their_balance} < 0){
+            if ($l->{their_balance} > 0){
                $l->{their_debits} = $recon->parse_amount(amount => 0);
-               $l->{their_credits} = $l->{their_balance}->bneg;
+               $l->{their_credits} = $l->{their_balance};
             }
             else {
                $l->{their_credits} = $recon->parse_amount(amount => 0);
-               $l->{their_debits} = $l->{their_balance};
+               $l->{their_debits} = $l->{their_balance}->bneg;
             }
-            if ($l->{our_balance} < 0){
+            if ($l->{our_balance} > 0){
                $l->{our_debits} = $recon->parse_amount(amount => 0);
-               $l->{our_credits} = $l->{our_balance}->bneg;
+               $l->{our_credits} = $l->{our_balance};
             }
             else {
                $l->{our_credits} = $recon->parse_amount(amount => 0);
-               $l->{our_debits} = $l->{our_balance};
+               $l->{our_debits} = $l->{our_balance}->bneg;
             }
 
             if ($l->{cleared}){
@@ -398,8 +404,11 @@
 
 	$recon->{zero_string} = $recon->format_amount({amount => 0, money => 1});
 
-	$recon->{statement_gl_calc} = $recon->{their_total} 
-		+ $recon->{outstanding_total} + $recon->{mismatch_our_total};
+	$recon->{statement_gl_calc} = $neg_factor * 
+                ($recon->{their_total}
+		+ $recon->{outstanding_total} 
+                + $recon->{mismatch_our_total});
+        print STDERR "debug: $recon->{their_total} - $recon->{our_total}\n";
 	$recon->{out_of_balance} = $recon->{their_total} - $recon->{our_total};
         $recon->{cleared_total} = $recon->format_amount({amount => $recon->{cleared_total}, money => 1});
         $recon->{outstanding_total} = $recon->format_amount({amount => $recon->{outstanding_total}, money => 1});
@@ -433,6 +442,9 @@
 		{amount => $recon->{beginning_balance}, money => 1});
 	$recon->{out_of_balance} = $recon->format_amount(
 		{amount => $recon->{out_of_balance}, money => 1});
+        if ($recon->{account_info}->{category} =~ /(A|E)/){
+           $recon->{their_total} *= -1;
+        }
 
         return $template->render($recon);
 }

Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/scripts/vouchers.pl	2011-04-22 15:41:54 UTC (rev 3134)
@@ -306,6 +306,8 @@
 sub get_batch {
     my ($request)  = @_;
     $request->{action} = 'get_batch';
+    my $callback = "vouchers.pl?action=get_batch&batch_id=$request->{batch_id}";
+    $callback = $request->escape(string => $callback);
     my $batch = LedgerSMB::Batch->new(base => $request);
     $batch->close_form;
     $batch->open_form;
@@ -316,6 +318,7 @@
     $batch->{id} ||= $batch->{batch_id};
     # $batch->get;
     my @vouchers = $batch->list_vouchers;
+    my $edit_base= "batch_id=$batch->{batch_id}&action=edit&callback=$callback";
 
     my $base_href = "vouchers.pl?action=get_batch&batch_id=$batch->{batch_id}";
 
@@ -337,6 +340,21 @@
     for my $row (@vouchers) {
        $classcount = ($classcount + 1) % 2;
        $classcount ||= 0;
+       my $escript = undef;
+       if ($row->{batch_class} eq 'Receivable'){
+           $escript = 'ar.pl';
+       } elsif ($row->{batch_class} eq 'Payable'){
+           $escript = 'ap.pl';
+       } elsif ($row->{batch_class} eq 'GL'){
+           $escript = 'gl.pl';
+       } 
+       if (defined $escript){
+           $row->{reference} = { 
+                     text => $row->{reference},
+                     href => "$escript?id=$row->{transaction_id}&"
+                             . $edit_base
+                     };
+       }
        push @$rows, {
            description => $row->{description},
            id          => $row->{id},

Modified: trunk/sql/modules/Reconciliation.sql
===================================================================
--- trunk/sql/modules/Reconciliation.sql	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/sql/modules/Reconciliation.sql	2011-04-22 15:41:54 UTC (rev 3134)
@@ -105,7 +105,7 @@
 CREATE OR REPLACE FUNCTION reconciliation__get_cleared_balance(in_chart_id int)
 RETURNS numeric AS
 $$
-	select CASE WHEN c.category = 'A' THEN sum(ac.amount) * -1 ELSE
+	select CASE WHEN c.category in('A', 'E') THEN sum(ac.amount) * -1 ELSE
 		sum(ac.amount) END
 	FROM account c
 	JOIN acc_trans ac ON (ac.chart_id = c.id)
@@ -339,7 +339,7 @@
 		SELECT in_report_id, 
 		       COALESCE(ac.source, gl.ref),
 		       0, 
-		       sum(amount) * -1 AS amount,
+		       sum(amount) AS amount,
 				(select entity_id from users 
 				where username = CURRENT_USER),
 			ac.voucher_id, min(ac.entry_id), ac.transdate

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2011-04-18 18:20:18 UTC (rev 3133)
+++ trunk/sql/modules/Voucher.sql	2011-04-22 15:41:54 UTC (rev 3134)
@@ -123,7 +123,7 @@
 		UNION ALL
 		SELECT v.id, g.reference, g.description, 
 			v.batch_id, v.trans_id,
-			sum(a.amount), g.transdate, 'gl'
+			sum(a.amount), g.transdate, 'GL'
 		FROM voucher v
 		JOIN gl g ON (g.id = v.trans_id)
 		JOIN acc_trans a ON (v.trans_id = a.trans_id)


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