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

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



Revision: 3442
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3442&view=rev
Author:   einhverfr
Date:     2011-07-05 10:22:27 +0000 (Tue, 05 Jul 2011)

Log Message:
-----------
Editable tax lines ready for beta testing

Modified Paths:
--------------
    trunk/LedgerSMB/IR.pm
    trunk/LedgerSMB/IS.pm
    trunk/bin/ir.pl
    trunk/bin/is.pl

Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm	2011-07-05 08:52:42 UTC (rev 3441)
+++ trunk/LedgerSMB/IR.pm	2011-07-05 10:22:27 UTC (rev 3442)
@@ -222,34 +222,35 @@
             my $linetotal = $form->round_amount( $amount, $moneyplaces );
             $fxdiff += $amount - $linetotal;
 
-            @taxaccounts = Tax::init_taxes(
-                $form,
-                $form->{"taxaccounts_$i"},
-                $form->{'taxaccounts'}
-            );
+            if (!$form->{manual_tax}){
+                @taxaccounts = Tax::init_taxes(
+                    $form,
+                    $form->{"taxaccounts_$i"},
+                    $form->{'taxaccounts'}
+                );
 
-            $tax   = Math::BigFloat->bzero();
-            $fxtax = Math::BigFloat->bzero();
+                $tax   = Math::BigFloat->bzero();
+                $fxtax = Math::BigFloat->bzero();
+    
+                if ( $form->{taxincluded} ) {
+                    $tax += $amount =
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
 
-            if ( $form->{taxincluded} ) {
-                $tax += $amount =
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
+                    $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+                }
+                else {
+                    $tax += $amount =
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
+    
+                    $fxtax +=
+                      Tax::calculate_taxes( ..hidden.., $form, $fxlinetotal, 0 );
+                }
 
-                $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+                for (@taxaccounts) {
+                    $form->{acc_trans}{ $form->{id} }{ $_->account }{amount} +=
+                      $_->value;
+                }
             }
-            else {
-                $tax += $amount =
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
-
-                $fxtax +=
-                  Tax::calculate_taxes( ..hidden.., $form, $fxlinetotal, 0 );
-            }
-
-            for (@taxaccounts) {
-                $form->{acc_trans}{ $form->{id} }{ $_->account }{amount} +=
-                  $_->value;
-            }
-
             $grossamount = $form->round_amount( $linetotal, $moneyplaces );
 
             if ( $form->{taxincluded} ) {
@@ -583,7 +584,40 @@
         $form->update_exchangerate( $dbh, $form->{currency}, $form->{transdate},
             0, $form->{exchangerate} );
     }
+    if ($form->{manual_tax}){
+        my $ac_sth = $dbh->prepare(
+              "INSERT INTO acc_trans (chart_id, trans_id, amount, source, memo)
+                    VALUES ((select id from account where accno = ?), 
+                            ?, ?, ?, ?)"
+        );
+        my $tax_sth = $dbh->prepare(
+              "INSERT INTO tax_extended (entry_id, tax_basis, rate)
+                    VALUES (currval('acc_trans_entry_id_seq'), ?, ?)"
+        );
+        for $taccno (split / /, $form->{taxaccounts}){
+            $form->error('Must enter tax amount') 
+                        unless $form->{"mt_amount_$taccno"};
+            my $taxamount;
+            my $taxbasis;
+            my $fx = $form->{exchangerate} || 1;
+            $taxamount = $form->parse_amount($myconfig, 
+                                             $form->{"mt_amount_$taccno"});
+            $taxbasis = $form->parse_amount($myconfig,
+                                           $form->{"mt_basis_$taccno"});
+            my $fx_taxamount = $taxamount * $fx;
+            my $fx_taxbasis = $taxbasis * $fx;
+            $form->{payables} += $fx_taxamount;
+            $invamount += $fx_taxamount;
+            $ac_sth->execute($taccno, $form->{id}, $fx_taxamount * -1, 
+                             $form->{"mt_ref_$taccno"}, 
+                             $form->{"mt_desc_$taccno"});
+            $tax_sth->execute($fx_taxbasis * -1, $form->{"mt_rate_$taccno"});
+        }
+        $ac_sth->finish;
+        $tax_sth->finish;
+    }
 
+
     # record payable
     if ( $form->{payables} ) {
         ($accno) = split /--/, $form->{AP};
@@ -1035,6 +1069,23 @@
 
     if ( $form->{id} ) {
 
+        my $tax_sth = $dbh->prepare(
+                  qq| SELECT amount, source, memo, tax_basis, rate, accno
+                        FROM acc_trans ac
+                        JOIN tax_extended t USING(entry_id)
+                        JOIN account c ON c.id = ac.chart_id
+                       WHERE ac.trans_id = ?|);
+        $tax_sth->execute($form->{id});
+        while (my $taxref = $tax_sth->fetchrow_hashref('NAME_lc')){
+              $form->{manual_tax} = 1;
+              my $taccno = $taxref->{accno};
+              $form->{"mt_amount_$taccno"} = $taxref->{amount} * -1;
+              $form->{"mt_rate_$taccno"}  = $taxref->{rate};
+              $form->{"mt_basis_$taccno"} = $taxref->{tax_basis} * -1;
+              $form->{"mt_memo_$taccno"}  = $taxref->{memo};
+              $form->{"mt_ref_$taccno"}  = $taxref->{source};
+        }
+
         # get default accounts and last invoice number
         $query = qq|
 			SELECT (select c.accno FROM account c 

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2011-07-05 08:52:42 UTC (rev 3441)
+++ trunk/LedgerSMB/IS.pm	2011-07-05 10:22:27 UTC (rev 3442)
@@ -153,6 +153,7 @@
     my $pth = $dbh->prepare($query) || $form->dberror($query);
 
     my $sortby;
+                        
 
     # sort items by project and partsgroup
     for $i ( 1 .. $form->{rowcount} - 1 ) {
@@ -1063,42 +1064,45 @@
             $amount = $fxlinetotal * $form->{exchangerate};
             my $linetotal = $form->round_amount( $amount, 2 );
             $fxdiff += $amount - $linetotal;
-            @taxaccounts = Tax::init_taxes(
-                $form,
-                $form->{"taxaccounts_$i"},
-                $form->{"taxaccounts"}
-            );
-            $ml    = 1;
-            $tax   = Math::BigFloat->bzero();
-            $fxtax = Math::BigFloat->bzero();
+            if (!$form->{manual_tax}){
+                @taxaccounts = Tax::init_taxes(
+                    $form,
+                    $form->{"taxaccounts_$i"},
+                    $form->{"taxaccounts"}
+                );
+                $ml    = 1;
+                $tax   = Math::BigFloat->bzero();
+                $fxtax = Math::BigFloat->bzero();
 
-            if ( $form->{taxincluded} ) {
-                $tax += $amount =
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
-                $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+                if ( $form->{taxincluded} ) {
+                    $tax += $amount =
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
+                    $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+    
+                    $fxtax +=
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
+                }
+                else {
+                    $tax += $amount =
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
+                    $fxtax +=
+                      Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
+                }
+                for (@taxaccounts) {
+                    $form->{acc_trans}{ $form->{id} }{ $_->account }{amount} +=
+                      $_->value;
+                }
 
-                $fxtax +=
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
-            }
-            else {
-                $tax += $amount =
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
-                $fxtax +=
-                  Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
-            }
-            for (@taxaccounts) {
-                $form->{acc_trans}{ $form->{id} }{ $_->account }{amount} +=
-                  $_->value;
-            }
+                $grossamount = $form->round_amount( $linetotal, 2 );
 
-            $grossamount = $form->round_amount( $linetotal, 2 );
-
-            if ( $form->{taxincluded} ) {
-                $amount = $form->round_amount( $tax, 2 );
-                $linetotal -= $form->round_amount( $tax - $diff, 2 );
-                $diff = ( $amount - $tax );
-            }
-
+                if ( $form->{taxincluded} ) {
+                    $amount = $form->round_amount( $tax, 2 );
+                    $linetotal -= $form->round_amount( $tax - $diff, 2 );
+                    $diff = ( $amount - $tax );
+                }
+            } 
+            $grossamount ||= $form->round_amount( $linetotal, 2 ); 
+            $fxtax ||=0;
             # add linetotal to income
             $amount = $form->round_amount( $linetotal, 2 );
 
@@ -1311,6 +1315,39 @@
 
     delete $form->{acc_trans}{lineitems};
 
+    if ($form->{manual_tax}){
+        my $ac_sth = $dbh->prepare(
+              "INSERT INTO acc_trans (chart_id, trans_id, amount, source, memo)
+                    VALUES ((select id from account where accno = ?), 
+                            ?, ?, ?, ?)"
+        );
+        my $tax_sth = $dbh->prepare(
+              "INSERT INTO tax_extended (entry_id, tax_basis, rate)
+                    VALUES (currval('acc_trans_entry_id_seq'), ?, ?)"
+        );
+        for $taccno (split / /, $form->{taxaccounts}){
+            $form->error('Must enter tax amount') 
+                        unless $form->{"mt_amount_$taccno"};
+            my $taxamount;
+            my $taxbasis;
+            my $fx = $form->{exchangerate} || 1;
+            $taxamount = $form->parse_amount($myconfig, 
+                                             $form->{"mt_amount_$taccno"});
+            $taxbasis = $form->parse_amount($myconfig,
+                                           $form->{"mt_basis_$taccno"});
+            my $fx_taxamount = $taxamount * $fx;
+            my $fx_taxbasis = $taxbasis * $fx;
+            $form->{receivables} -= $fx_taxamount;
+            $invamount += $fx_taxamount;
+            $ac_sth->execute($taccno, $form->{id}, $fx_taxamount, 
+                             $form->{"mt_ref_$taccno"}, 
+                             $form->{"mt_desc_$taccno"});
+            $tax_sth->execute($fx_taxbasis, $form->{"mt_rate_$taccno"});
+        }
+        $ac_sth->finish;
+        $tax_sth->finish;
+    }
+
     # update exchangerate
     if ( ( $form->{currency} ne $form->{defaultcurrency} ) && !$exchangerate ) {
         $form->update_exchangerate( $dbh, $form->{currency}, $form->{transdate},
@@ -2039,6 +2076,24 @@
         for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
         $sth->finish;
 
+        my $tax_sth = $dbh->prepare(
+                  qq| SELECT amount, source, memo, tax_basis, rate, accno
+                        FROM acc_trans ac
+                        JOIN tax_extended t USING(entry_id)
+                        JOIN account c ON c.id = ac.chart_id
+                       WHERE ac.trans_id = ?|);
+        $tax_sth->execute($form->{id});
+        while (my $taxref = $tax_sth->fetchrow_hashref('NAME_lc')){
+              $form->{manual_tax} = 1;
+              my $taccno = $taxref->{accno};
+              $form->{"mt_amount_$taccno"} = $taxref->{amount};
+              $form->{"mt_rate_$taccno"}  = $taxref->{rate};
+              $form->{"mt_basis_$taccno"} = $taxref->{tax_basis};
+              $form->{"mt_memo_$taccno"}  = $taxref->{memo};
+              $form->{"mt_ref_$taccno"}  = $taxref->{source};
+        }
+
+
         # get shipto
         $query = qq|SELECT ns.*, l.* FROM new_shipto ns JOIN location l ON ns.location_id = l.id WHERE ns.trans_id = ?|;
         $sth   = $dbh->prepare($query);

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2011-07-05 08:52:42 UTC (rev 3441)
+++ trunk/bin/ir.pl	2011-07-05 10:22:27 UTC (rev 3442)
@@ -571,21 +571,19 @@
                 <th align=right>$form->{"${taccno}_description"}</th>
                 <td><input type="text" name="mt_amount_$item"
                         id="mt-amount-$item" value="|
-                        .$form->{"mt_amount_$item"} .qq|" /></td>
+                        .$form->{"mt_amount_$item"} .qq|" size="10"/></td>
                 <td><input type="text" name="mt_rate_$item"
                          id="mt-rate-$item" value="|
-                        .$form->{"mt_rate_$item"} .qq|" /></td>
+                        .$form->{"mt_rate_$item"} .qq|" size="6"/></td>
                 <td><input type="text" name="mt_basis_$item"
                          id="mt-basis-$item" value="|
-                        .$form->{"mt_basis_$item"} .qq|" /></td>
+                        .$form->{"mt_basis_$item"} .qq|" size="10" /></td>
                 <td><input type="text" name="mt_ref_$item"
                          id="mt-ref-$item" value="|
-                        .$form->{"mt_ref_$item"} .qq|" /></td>
+                        .$form->{"mt_ref_$item"} .qq|" size="10"/></td>
                 <td><input type="text" name="mt_memo_$item"
                          id="mt-memo-$item" value="|
-                        .$form->{"mt_memo_$item"} .qq|" /></td>
-                <td><button id="mt-calc-$item name="mt_calc_$item"
-                    >|.$locale->text('Calc').qq|</button></td>
+                        .$form->{"mt_memo_$item"} .qq|" size="10"/></td>
                </tr>|;
             }  else {
     	        $form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2011-07-05 08:52:42 UTC (rev 3441)
+++ trunk/bin/is.pl	2011-07-05 10:22:27 UTC (rev 3442)
@@ -1210,7 +1210,6 @@
 }
 
 sub post {
-
     $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
     $form->isblank( "customer",  $locale->text('Customer missing!') );
 


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