[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[5104] trunk
- Subject: SF.net SVN: ledger-smb:[5104] trunk
- From: ..hidden..
- Date: Mon, 06 Aug 2012 08:57:42 +0000
Revision: 5104
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5104&view=rev
Author: einhverfr
Date: 2012-08-06 08:57:41 +0000 (Mon, 06 Aug 2012)
Log Message:
-----------
Invoices ported to one fx rate per transaction
Modified Paths:
--------------
trunk/LedgerSMB/IR.pm
trunk/LedgerSMB/IS.pm
trunk/LedgerSMB/Setting.pm
trunk/bin/ir.pl
trunk/bin/is.pl
Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm 2012-08-06 06:36:33 UTC (rev 5103)
+++ trunk/LedgerSMB/IR.pm 2012-08-06 08:57:41 UTC (rev 5104)
@@ -207,10 +207,7 @@
$form->{transdate}, 'sell' );
}
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount( $myconfig, $form->{exchangerate} );
+ $form->{exchangerate} = $form->parse_amount( $myconfig, $form->{exchangerate} );
my $taxformfound=IR->taxform_exist($form,$form->{"vendor_id"});#tshvr this always returns true!!
@@ -416,6 +413,7 @@
{
chart_id => $form->{"inventory_accno_id_$i"},
amount => $amount,
+ fxlinetotal => $fxlinetotal,
fxgrossamount => $fxlinetotal +
$form->round_amount( $fxtax, 2 ),
grossamount => $grossamount,
@@ -439,6 +437,7 @@
{
chart_id => $form->{"expense_accno_id_$i"},
amount => $amount,
+ fxlinetotal => $fxlinetotal,
fxgrossamount => $fxlinetotal +
$form->round_amount( $fxtax, 2 ),
grossamount => $grossamount,
@@ -502,16 +501,22 @@
@{ $form->{acc_trans}{lineitems} } )
{
- $amount = $ref->{amount} + $diff + $fxdiff;
+ $amount = $ref->{amount} + $diff;
+ $fxlinetotal = $ref->{fxlinetotal} + $diff/$form->{exchangerate};
$query = qq|
INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, invoice_id)
- VALUES (?, ?, ?, ?, ?)|;
+ transdate, invoice_id, fx_transaction)
+ VALUES (?, ?, ?, ?, ?, ?)|;
$sth = $dbh->prepare($query);
$sth->execute(
- $form->{id}, $ref->{chart_id}, $amount * -1,
- $form->{transdate}, $ref->{invoice_id}
+ $form->{id}, $ref->{chart_id}, $fxlinetotal * -1,
+ $form->{transdate}, $ref->{invoice_id}, 0
) || $form->dberror($query);
+ $sth->execute(
+ $form->{id}, $ref->{chart_id}, ($amount - $fxlinetotal) * -1,
+ $form->{transdate}, $ref->{invoice_id}, 1
+ ) || $form->dberror($query);
+
$diff = 0;
$fxdiff = 0;
for my $cls(@{$form->{bu_class}}){
@@ -570,13 +575,19 @@
$query = qq|
INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate)
+ transdate, fx_transaction)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
- ?, ?)|;
+ ?, ?, ?)|;
$sth = $dbh->prepare($query);
- $sth->execute( $form->{id}, $accno, $form->{payables},
- $form->{transdate} )
+ $sth->execute( $form->{id}, $accno,
+ $form->{payables}/$form->{exchangerate},
+ $form->{transdate} , 0)
|| $form->dberror($query);
+ $sth->execute( $form->{id}, $accno,
+ $form->{payables} -
+ ($form->{payables}/$form->{exchangerate}),
+ $form->{transdate} , 0)
+ || $form->dberror($query);
}
foreach my $trans_id ( keys %{ $form->{acc_trans} } ) {
Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm 2012-08-06 06:36:33 UTC (rev 5103)
+++ trunk/LedgerSMB/IS.pm 2012-08-06 08:57:41 UTC (rev 5104)
@@ -1008,16 +1008,8 @@
if ( $form->{currency} eq $form->{defaultcurrency} ) {
$form->{exchangerate} = 1;
}
- else {
- $exchangerate =
- $form->check_exchangerate( $myconfig, $form->{currency},
- $form->{transdate}, 'buy' );
- }
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount( $myconfig, $form->{exchangerate} );
+ $form->{exchangerate} = $form->parse_amount( $myconfig, $form->{exchangerate} );
my $return_cid = 0;
if ($LedgerSMB::Sysconfig::return_accno and !$form->{void}){
@@ -1105,14 +1097,13 @@
$form->round_amount( $fxsellprice * $form->{"discount_$i"},
$decimalplaces );
- # linetotal
- my $fxlinetotal =
- $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
- 2 );
+ # linetotal - removing rounding due to fx issues
+ my $fxlinetotal = $form->{"sellprice_$i"} * $form->{"qty_$i"};
$amount = $fxlinetotal * $form->{exchangerate};
my $linetotal = $form->round_amount( $amount, 2 );
$fxdiff += $amount - $linetotal;
+ $fxlinediff = $amount - $fxlinetotal;
if (!$form->{manual_tax}){
@taxaccounts = Tax::init_taxes(
$form,
@@ -1162,7 +1153,8 @@
amount => $amount,
fxgrossamount => $fxlinetotal + $fxtax,
grossamount => $grossamount,
- project_id => $project_id
+ project_id => $project_id,
+ fxdiff => $fxlinediff
};
$ndx = $#{ @{ $form->{acc_trans}{lineitems} } };
@@ -1357,16 +1349,19 @@
@{ $form->{acc_trans}{lineitems} } )
{
- $amount = $ref->{amount} + $diff + $fxdiff;
+ $amount = $ref->{amount} + $diff; # Subtracting included taxes
$query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
- transdate, invoice_id)
- VALUES (?, ?, ?, ?, ?)|;
+ transdate, invoice_id, fx_transaction)
+ VALUES (?, ?, ?, ?, ?, ?)|;
$sth = $dbh->prepare($query);
- $sth->execute( $form->{id}, $ref->{chart_id}, $amount,
- $form->{transdate}, $ref->{invoice_id} )
+ $sth->execute( $form->{id}, $ref->{chart_id}, $amount - $ref->{fxdiff},
+ $form->{transdate}, $ref->{invoice_id}, 0)
|| $form->dberror($query);
+ $sth->execute( $form->{id}, $ref->{chart_id}, $ref->{fxdiff},
+ $form->{transdate}, $ref->{invoice_id}, 1)
+ || $form->dberror($query);
$diff = 0;
$fxdiff = 0;
for my $cls(@{$form->{bu_class}}){
@@ -1423,14 +1418,18 @@
$query = qq|
INSERT INTO acc_trans
- (trans_id, chart_id, amount, transdate)
+ (trans_id, chart_id, amount, transdate,
+ fx_transaction)
VALUES (?, (SELECT id FROM account WHERE accno = ?),
- ?, ?)|;
+ ?, ?, ?)|;
$sth = $dbh->prepare($query);
- $sth->execute( $form->{id}, $accno, $form->{receivables},
- $form->{transdate} )
+ $sth->execute( $form->{id}, $accno, $form->{receivables} / $form->{exchangerate},
+ $form->{transdate}, 0)
|| $form->dberror($query);
+ $sth->execute( $form->{id}, $accno, $form->{receivables} -
+ $form->{receivables} / $form->{exchangerate},
+ $form->{transdate}, 1) || $form->dberror($query);
}
foreach my $trans_id ( keys %{ $form->{acc_trans} } ) {
Modified: trunk/LedgerSMB/Setting.pm
===================================================================
--- trunk/LedgerSMB/Setting.pm 2012-08-06 06:36:33 UTC (rev 5103)
+++ trunk/LedgerSMB/Setting.pm 2012-08-06 08:57:41 UTC (rev 5104)
@@ -53,10 +53,10 @@
sub get {
my $self = shift;
my ($key) = @_;
- $key ||= $self->{key};
+ $key = $self->{key} unless $key;
my ($hashref) = $self->call_procedure( procname => 'setting_get',
args => [$key]) ;
- $self->{value} = $hashref->{value} if $self->{key};
+ $self->{value} = $hashref->{value} if eval {$self->{key} };
return $hashref->{value};
}
Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl 2012-08-06 06:36:33 UTC (rev 5103)
+++ trunk/bin/ir.pl 2012-08-06 08:57:41 UTC (rev 5104)
@@ -391,22 +391,12 @@
if ( $form->{defaultcurrency}
&& $form->{currency} ne $form->{defaultcurrency} )
{
- if ( $form->{forex} ) {
- $exchangerate .= qq|
+ $exchangerate .= qq|
<th align=right nowrap>|
. $locale->text('Exchange Rate')
. qq|</th>
- <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
-|;
- }
- else {
- $exchangerate .= qq|
- <th align=right nowrap>|
- . $locale->text('Exchange Rate')
- . qq|</th>
<td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
|;
- }
}
$exchangerate .= qq|
<input type=hidden name=forex value=$form->{forex}>
Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl 2012-08-06 06:36:33 UTC (rev 5103)
+++ trunk/bin/is.pl 2012-08-06 08:57:41 UTC (rev 5104)
@@ -369,18 +369,10 @@
if ( $form->{defaultcurrency}
&& $form->{currency} ne $form->{defaultcurrency} )
{
- if ( $form->{forex} ) {
- $exchangerate .=
+ $exchangerate .=
qq|<th align=right>|
. $locale->text('Exchange Rate')
- . qq|</th><td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
- }
- else {
- $exchangerate .=
- qq|<th align=right>|
- . $locale->text('Exchange Rate')
. qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
- }
}
$exchangerate .= qq|
<input type=hidden name="forex" value="$form->{forex}">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.