Skip to content

Commit

Permalink
Added exchangeRate parameter to ZugferdDocumentBuilder::setForeignCur…
Browse files Browse the repository at this point in the history
…rency
  • Loading branch information
HorstOeko committed Sep 25, 2024
1 parent f2766ed commit f46e964
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,12 @@ public function initDocumentSummation(): ZugferdDocumentBuilder
* Sets a foreign currency (code) with the tax amount. The exchange rate
* is calculated by tax amounts
*
* @param string $foreignCurrencyCode __BT-6, From BASIC WL__ Foreign currency code
* @param float $foreignTaxAmount __BT-, From __ Required from EXTENDED Tax total amount in the foreign currency
* @param string $foreignCurrencyCode __BT-6, From BASIC WL__ Foreign currency code
* @param float $foreignTaxAmount __BT-, From __ Required from EXTENDED Tax total amount in the foreign currency
* @param float|null $foreignTaxAmount __BT-X-260, From EXTENDED __ Exchange Rate
* @return ZugferdDocumentBuilder
*/
public function setForeignCurrency(string $foreignCurrencyCode, ?float $foreignTaxAmount): ZugferdDocumentBuilder
public function setForeignCurrency(string $foreignCurrencyCode, float $foreignTaxAmount, ?float $exchangeRate = null): ZugferdDocumentBuilder
{
$invoiceCurrencyCode = $this->getObjectHelper()->tryCallByPathAndReturn($this->headerTradeSettlement, "getInvoiceCurrencyCode.value");

Expand Down Expand Up @@ -341,10 +342,15 @@ public function setForeignCurrency(string $foreignCurrencyCode, ?float $foreignT
$this->getObjectHelper()->tryCallByPath($taxTotalAmountForeign, "setCurrencyID", $foreignCurrencyCode);
}

$exchangeRate = round($foreignTaxAmount / $invoiceTaxAmount, 5);
$calculatedExchangeRate = $exchangeRate;

if (is_null($calculatedExchangeRate)) {
$calculatedExchangeRate = round($foreignTaxAmount / $invoiceTaxAmount, 5);
}

$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setTaxCurrencyCode", $this->getObjectHelper()->getIdType($foreignCurrencyCode));
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setTaxApplicableTradeCurrencyExchange", $this->getObjectHelper()->getTaxApplicableTradeCurrencyExchangeType($invoiceCurrencyCode, $foreignCurrencyCode, $exchangeRate));
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setTaxApplicableTradeCurrencyExchange", $this->getObjectHelper()->getTaxApplicableTradeCurrencyExchangeType($invoiceCurrencyCode, $foreignCurrencyCode, $calculatedExchangeRate));

return $this;
}

Expand Down

0 comments on commit f46e964

Please sign in to comment.