95 abstract public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
114 if (
$object->mode_reglement_code !=
'VIR') {
115 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
119 if (empty(
$object->fk_account)) {
120 $this->error =
'Bank account must be defined to use this experimental feature';
125 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
126 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
127 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
128 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
130 $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;';
135 $qrBill = SwissQrBill\QrBill::create();
138 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
139 $this->emetteur->name,
140 $this->emetteur->address,
141 $this->emetteur->zip .
" " . $this->emetteur->town,
142 $this->emetteur->country_code
144 if (!$address->isValid()) {
145 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
148 $qrBill->setCreditor($address);
151 $account =
new Account($this->db);
152 $account->fetch(
$object->fk_account);
153 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
154 if (!$creditorInformation->isValid()) {
155 $langs->load(
"errors");
156 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
159 $qrBill->setCreditorInformation($creditorInformation);
161 if ($creditorInformation->containsQrIban()) {
162 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
168 $qrBill->setPaymentReference(
169 SwissQrBill\DataGroup\Element\PaymentReference::create(
170 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
174 $currencyinvoicecode =
$object->multicurrency_code ?
$object->multicurrency_code : $conf->currency;
177 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode,
$object->total_ttc);
178 if (!$pai->isValid()) {
179 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid",
$object->total_ttc, (
string) $pai->getViolations());
182 $qrBill->setPaymentAmountInformation($pai);
185 $qrBill->setAdditionalInformation(
186 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
192 if (!empty(
$object->thirdparty->zip) && !empty(
$object->thirdparty->town)) {
193 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
197 $object->thirdparty->country_code
199 if (!$address->isValid()) {
200 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
203 $qrBill->setUltimateDebtor($address);
252 $pdf->startTransaction();
255 $pdf->SetTextColor(0, 0, 0);
256 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
257 $output->setPrintable(
false)->getPaymentPart();
259 $pdf->rollbackTransaction(
true);