96 if (
$object->mode_reglement_code !=
'VIR') {
97 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
101 if (empty(
$object->fk_account)) {
102 $this->error =
'Bank account must be defined to use this experimental feature';
107 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
108 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
109 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
110 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
112 $this->error =
'PHP library sprain/swiss-qr-bill was not found. Please install it with:<br>cd '.dirname(DOL_DOCUMENT_ROOT).
'; cp composer.json.disabled composer.json; composer require sprain/swiss-qr-bill;';
117 $qrBill = SwissQrBill\QrBill::create();
120 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
121 $this->emetteur->name,
122 $this->emetteur->address,
123 $this->emetteur->zip .
" " . $this->emetteur->town,
124 $this->emetteur->country_code
126 if (!$address->isValid()) {
127 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
130 $qrBill->setCreditor($address);
133 $account =
new Account($this->db);
134 $account->fetch(
$object->fk_account);
135 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
136 if (!$creditorInformation->isValid()) {
137 $langs->load(
"errors");
138 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
141 $qrBill->setCreditorInformation($creditorInformation);
143 if ($creditorInformation->containsQrIban()) {
144 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
150 $qrBill->setPaymentReference(
151 SwissQrBill\DataGroup\Element\PaymentReference::create(
152 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
156 $currencyinvoicecode =
$object->multicurrency_code ?
$object->multicurrency_code : $conf->currency;
159 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode,
$object->total_ttc);
160 if (!$pai->isValid()) {
161 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid",
$object->total_ttc, (
string) $pai->getViolations());
164 $qrBill->setPaymentAmountInformation($pai);
167 $qrBill->setAdditionalInformation(
168 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
174 if (!empty(
$object->thirdparty->zip) && !empty(
$object->thirdparty->town)) {
175 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
179 $object->thirdparty->country_code
181 if (!$address->isValid()) {
182 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
185 $qrBill->setUltimateDebtor($address);
234 $pdf->startTransaction();
237 $pdf->SetTextColor(0, 0, 0);
238 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
239 $output->setPrintable(
false)->getPaymentPart();
241 $pdf->rollbackTransaction(
true);