diff --git a/src/quick/ZugferdQuickDescriptor.php b/src/quick/ZugferdQuickDescriptor.php index d488602..a6c5b07 100644 --- a/src/quick/ZugferdQuickDescriptor.php +++ b/src/quick/ZugferdQuickDescriptor.php @@ -57,6 +57,13 @@ class ZugferdQuickDescriptor extends ZugferdDocumentBuilder */ protected $totalPrepaidAmount = 0.0; + /** + * Internal flag to see if the totals are alread calculated + * + * @var boolean + */ + protected $totalsAreCalculated = false; + /** * Returns the profile of the descriptor * @@ -1035,6 +1042,10 @@ public function doSetPrepaidAmount(float $totalPrepaidAmount = 0.0): ZugferdQuic */ protected function doCalcTotals(): ZugferdQuickDescriptor { + if ($this->totalsAreCalculated !== false) { + return $this; + } + $this->writeVatBreakDown(); $this->setDocumentSummation( $this->summarizeVatTableElement(self::VT_BASISAMOUNT) + $this->summarizeVatTableElement(self::VT_CALCULATEDAMOUNT), @@ -1047,6 +1058,9 @@ protected function doCalcTotals(): ZugferdQuickDescriptor 0.0, $this->totalPrepaidAmount ); + + $this->totalsAreCalculated = true; + return $this; }