Commit 6895f4b3 authored by Nigel Kukard's avatar Nigel Kukard

Reworked tax mode usage and error checking

parent 789b0608
......@@ -751,16 +751,16 @@ sub linkSupplierInvoiceItem
# Get ready for calculating tax
my ($taxAmount,$taxMode) = wiaflos::server::core::Tax::getTaxAmount($detail->{'TaxMode'},$taxRate,$totalPrice);
if (!defined($taxMode)) {
if (!defined($taxAmount) || !defined($taxMode)) {
setError(wiaflos::server::core::Tax::Error());
return $taxType;
return ERR_USAGE;
}
# Calculate discount
if (!$discount->is_zero()) {
# Set discountAmount depending on tax mode
my $discountAmount = $totalPrice->copy();
$discountAmount->bsub($taxAmount) if ($detail->{'TaxMode'} eq "incl");
$discountAmount->bsub($taxAmount) if ($detail->{'TaxMode'} eq "1");
# Get discount multiplier
my $tmpDisc = $discount->copy();
......@@ -913,13 +913,14 @@ sub postSupplierInvoice
$quantity->precision(-4);
$quantity->badd($row->{'Quantity'});
# Calculate final prices
my $itemInclPrice = Math::BigFloat->new($row->{'Price'});
$itemInclPrice->badd($row->{'TaxAmount'}) if ($row->{'TaxMode'} eq "2");
# Calculate the Excl price, subtract tax if the tax is included
my $itemExclPrice = Math::BigFloat->new($row->{'Price'});
$itemExclPrice->bsub($row->{'TaxAmount'}) if ($row->{'TaxMode'} eq "1");
# Calculate the Excl price, add tax if the tax is excluded
my $itemInclPrice = Math::BigFloat->new($row->{'Price'});
$itemInclPrice->badd($row->{'TaxAmount'}) if ($row->{'TaxMode'} eq "2");
# Pull in tax GL account and addup what we need to post
if (defined($taxEntries{$row->{'TaxGLAccountID'}})) {
$taxEntries{$row->{'TaxGLAccountID'}}->badd($row->{'TaxAmount'});
......
......@@ -979,16 +979,18 @@ sub postSupplierCreditNote
my $itemInclPrice = $crnUnitPrice->copy();
my $itemExclPrice = $crnUnitPrice->copy();
# Work out tax amount
my ($taxAmount) = wiaflos::server::core::Tax::getTaxAmount($fi->{'TaxMode'},$fi->{'TaxRate'},$crnUnitPrice->bstr());
# Adjust tax on item if its already including
if ($fi->{'TaxMode'} eq "2") {
$itemInclPrice->badd($taxAmount);
} elsif ($fi->{'TaxMode'} eq "1") {
$itemExclPrice->bsub($taxAmount);
} else {
setError("TaxMode '".$fi->{'TaxMode'}."' invalid");
my ($taxAmount,$taxMode) = wiaflos::server::core::Tax::getTaxAmount($fi->{'TaxMode'},$fi->{'TaxRate'},$crnUnitPrice->bstr());
if (!defined($taxAmount) || !defined($taxMode)) {
setError(wiaflos::server::core::Tax::Error());
DBRollback();
return ERR_UNKNOWN;
return ERR_USAGE;
}
# If tax is including, work out the excl price by subtracting the tax amount
if ($taxMode eq "1") {
$itemExclPrice->bsub($taxAmount);
# If tax is excluding, work out the incl price by adding the tax amount
} elsif ($taxMode eq "2") {
$itemInclPrice->badd($taxAmount);
}
my $itemTaxAmount = Math::BigFloat->new($taxAmount);
......@@ -1014,7 +1016,7 @@ sub postSupplierCreditNote
$crnItemPriceBalance->bsub($allocatePrice);
my $totalTaxAmount = Math::BigFloat->new($itemTaxAmount)->bmul($allocateQty);
# Tax hack, if the price is including tax, we need to equal out the item price balance
if ($fi->{'TaxMode'} eq "1") {
if ($taxMode eq "1") {
$crnItemPriceBalance->bsub($totalTaxAmount);
}
......@@ -1094,7 +1096,7 @@ sub postSupplierCreditNote
$crnItemPriceBalance->bsub($allocatePrice);
my $totalTaxAmount = Math::BigFloat->new($itemTaxAmount)->bmul($allocateQty);
# Tax hack, if the price is including tax, we need to equal out the item price balance
if ($fi->{'TaxMode'} eq "1") {
if ($taxMode eq "1") {
$crnItemPriceBalance->bsub($totalTaxAmount);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment