Skip to content

Commit

Permalink
Merge pull request #182 from horstoeko/Issue_181
Browse files Browse the repository at this point in the history
#181 Add method for adding payment terms in special XRechnung-Syntax
  • Loading branch information
horstoeko authored Nov 25, 2024
2 parents 31fc364 + a8ae46f commit 98a89ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/XRechnung3Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
->addDocumentTax("S", "VAT", 275.0, 19.25, 7.0)
->addDocumentTax("S", "VAT", 198.0, 37.62, 19.0)
->setDocumentSummation(529.87, 529.87, 473.00, 0.0, 0.0, 473.00, 56.87, null, 0.0)
->addDocumentPaymentTerm("14 Prozent Skonto innerhalb von 28 Tagen\n#SKONTO#TAGE=28#PROZENT=14.00#\n")
->addDocumentPaymentTermXRechnung("Zahlungsbedingungen", [30, 28, 14], [0, 14, 7], [529.87, 529.87, 529.87])
->addNewPosition("1")
->setDocumentPositionNote("Bemerkung zu Zeile 1")
->setDocumentPositionProductDetails("Trennblätter A4", "", "TB100A4")
Expand Down
46 changes: 46 additions & 0 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,52 @@ public function addDiscountTermsToPaymentTerms(?float $calculationPercent = null
return $this;
}

/**
* Add a payment term in XRechnung-Style (in the Form #SKONTO#TAGE=14#PROZENT=1.00#BASISBETRAG=2.53#)
*
* @param string $description __BT-20, From _EN 16931 XRECHNUNG__ Text to add
* @param int[] $paymentDiscountDays __BT-20, BR-DE-18, From _EN 16931 XRECHNUNG__ Array of Payment discount days (array of integer)
* @param float[] $paymentDiscountPercents __BT-20, BR-DE-18, From _EN 16931 XRECHNUNG__ Array of Payment discount percents (array of decimal)
* @param float[] $paymentDiscountBaeeAmounts __BT-20, BR-DE-18, From _EN 16931 XRECHNUNG__ Array of Payment discount base amounts (array of decimal)
* @param DateTime|null $dueDate __BT-9, From EN 16931 XRECHNUNG__ The date by which payment is due Note: The payment due date reflects the net payment due date. In the case of partial payments, this indicates the first due date of a net payment. The corresponding description of more complex payment terms can be given in BT-20.
* @param string|null $directDebitMandateID __BT-89, From EN 16931 XRECHNUNG__ Unique identifier assigned by the payee to reference the direct debit authorization.
* @return ZugferdDocumentBuilder
*/
public function addDocumentPaymentTermXRechnung(string $description, array $paymentDiscountDays = [], array $paymentDiscountPercents = [], array $paymentDiscountBaeeAmounts = [], ?DateTime $dueDate = null, ?string $directDebitMandateID = null): ZugferdDocumentBuilder
{
$paymentTermsDescription = [];

if ($this->getObjectHelper()->isNullOrEmpty($description)) {
return $this;
}

$paymentDiscountDays = array_filter($paymentDiscountDays, function ($_, $k) use ($paymentDiscountPercents) {
return isset($paymentDiscountPercents[$k]);
}, ARRAY_FILTER_USE_BOTH);

if (empty($paymentDiscountDays)) {
return $this->addDocumentPaymentTerm(trim($description), $dueDate, $directDebitMandateID);
}

foreach ($paymentDiscountDays as $paymentDiscountDayIndex => $paymentDiscountDay) {
$paymentTermsDescription[] =
sprintf(
!isset($paymentDiscountBaeeAmounts[$paymentDiscountDayIndex])
? "#SKONTO#TAGE=%s#PROZENT=%s#"
: "#SKONTO#TAGE=%s#PROZENT=%s#BASISBETRAG=%s#",
number_format($paymentDiscountDay, 0, ".", ""),
number_format($paymentDiscountPercents[$paymentDiscountDayIndex] ?? 0.0, 2, ".", ""),
number_format($paymentDiscountBaeeAmounts[$paymentDiscountDayIndex] ?? 0.0, 2, ".", "")
);
}

return $this->addDocumentPaymentTerm(
trim(sprintf("%s\n%s", implode("\n", $paymentTermsDescription), $description)),
$dueDate,
$directDebitMandateID
);
}

/**
* Add information on the booking reference
*
Expand Down

0 comments on commit 98a89ec

Please sign in to comment.