Skip to content

Commit

Permalink
math dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPetrasek committed Jun 23, 2024
1 parent eefe433 commit ffec55a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{
"doctrine/orm": "^2.17",
"doctrine/doctrine-bundle": "^2.11",
"twig/twig": "^3.10"
"twig/twig": "^3.10",
"psys/utils": "^1.0"
}
}
42 changes: 41 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/Model/OrderManager/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Psys\OrderInvoiceManagerBundle\Entity\Product;
use Psys\Utils\Math;
use Symfony\Component\Filesystem\Filesystem;


Expand All @@ -16,6 +17,7 @@ public function __construct
private EntityManagerInterface $entityManager,
private LoggerInterface $vLogger,
private Filesystem $filesystem,
private Math $math,
private $projectDir,
)
{}
Expand Down Expand Up @@ -111,14 +113,14 @@ private function calculateProductTotals (Product $product) : array
// Calculate price exclusive of VAT from price inclusive of VAT
if (!empty($priceVatIncluded))
{
$priceVatExcludedRes = $this->subtractPercentage ($priceVatIncluded, $product->getVatRate());
$priceVatExcludedRes = $this->math->subtractPercentage($priceVatIncluded, $product->getVatRate());
$product->setPriceVatExcluded($priceVatExcludedRes);
}

// Calculate price inclusive of VAT from price exclusive of VAT
else if (!empty($priceVatExcluded))
{
$priceVatIncluded = ($priceVatExcluded * (100 + $product->getVatRate())) / 100;
$priceVatIncluded = $this->math->addPercentage($priceVatExcluded, $product->getVatRate());
$product->setPriceVatIncluded($priceVatIncluded);
}

Expand All @@ -130,11 +132,6 @@ private function calculateProductTotals (Product $product) : array
'priceVatExcluded' => $priceVatExcluded,
];
}

private function subtractPercentage ($number, $percentage)
{
return $number / ('1.'.$percentage);
}
}

?>

0 comments on commit ffec55a

Please sign in to comment.