Closed yamyoume closed 3 years ago
I was able to correct the rounding by editing vat.php
and minusvat like this
Although I think {amount} minus VAT should be something else like what's the amount needed when adding the 7.75% vat will equal the original {amount} like if 100 is the original amount, and let's say the vat is 7.75% so the answer should be 92.80742459 because if you take the "VAT 92.80742459" it will give you 100
This is useful for TTC (which means all taxes included in the price) so if you see a product priced at $100 and you know the vat is 7.75% the {amount} minus vat should give you $92.80742459 which is the product price before adding the tax
I found another thing 😅 I'm calculating this vat so the rounded final answer should be $13.73 but with VAT 12.47 I'm getting $13.72
so I fixed the precision by doing this
I made {amount} minus VAT to equal the TTC thing so with this, if you put vat 100, then 100 minus vat will give you the price of the product before the vat was added to it, so if you take that number and you use vat {that number} again then, {amount} plus VAT will give you the original number
all the changes I have made were to the getVatOf function, it's located in ( ~/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.C378AFE7-8701-4C25-B8B6-B6716AA3F957/workflow ) and here it is
public function getVatOf($amount)
{
$query = $amount;
$percent = $this->percent;
$processed = false;
if (empty($query)) {
return $this->output($processed);
}
// $percent = (int) $percent;
$percent = (float) $percent; // <--- change here
$amount = $this->cleanupNumber($query);
$result = ($percent / 100) * $amount;
// $result = (fmod($result, 1) !== 0.00 ? bcdiv($result, 1, 2) : $result);
$result = (fmod($result, 1) !== 0.00 ? bcdiv($result, 1, 3) : $result); // <--- change here
if ($result && $result > 0) {
$processed = true;
$plusvat = $amount + $result;
// $minusvat = $amount / ((float) "1.$percent");
$minusvat = $amount/(1+($percent/100)); // <--- change here
$lang = $this->lang;
$result = $this->formatNumber($result);
$plusvat = $this->formatNumber($plusvat, -1, true);
$minusvat = $this->formatNumber($minusvat, -1, true);
$amount = $this->formatNumber($amount);
$processed = [
'result' => [
'title' => sprintf($lang['result'], $amount, $result),
'subtitle' => sprintf($lang['subtitle'], "{$percent}%"),
'value' => $result
],
'plusvat' => [
'title' => sprintf($lang['plus'], $amount, $plusvat),
'subtitle' => sprintf($lang['subtitle'], "{$percent}%"),
'value' => $plusvat
],
'minusvat' => [
'title' => sprintf($lang['minus'], $amount, $minusvat),
'subtitle' => sprintf($lang['minus_subtitle'], $amount, "{$percent}%"),
'value' => $minusvat
],
];
}
return $processed;
}
you can also get to the file location by double click on vat and clicking this button
Thank you @yamyoume i'll include this fix in the next update.
This has been fixed in the latest version
Again, thank you for your help.
If you have a problem with the workflow please answer the following questions.
Describe the bug A clear and concise description of what the bug is. Vat is not accurate
To Reproduce Steps to reproduce the behavior: ca Set Vat was set to 7.75 Vat 100 produce VAT of 100 = 7 should be 7.75 100 plus VAT = 107, should be 107.75 100 minus VAT = 58.82 This doesn't make sense
Expected behavior A clear and concise description of what you expected to happen.
Debug Output
Please enable debug (see image) open Alfred and type the conversion that it's not working, you will see that the debug window is populated with a lot of text, please paste that text in here.
System information:
Additional context Add any other context about the problem here.