144 abstract public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
163 if (
$object->mode_reglement_code !=
'VIR') {
164 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
168 if (empty(
$object->fk_account)) {
169 $this->error =
'Bank account must be defined to use this experimental feature';
174 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
175 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
176 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
177 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
179 $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;';
184 $qrBill = SwissQrBill\QrBill::create();
187 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
188 $this->emetteur->name,
189 $this->emetteur->address,
190 $this->emetteur->zip .
" " . $this->emetteur->town,
191 $this->emetteur->country_code
193 if (!$address->isValid()) {
194 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
197 $qrBill->setCreditor($address);
200 $account =
new Account($this->db);
201 $account->fetch(
$object->fk_account);
202 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
203 if (!$creditorInformation->isValid()) {
204 $langs->load(
"errors");
205 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
208 $qrBill->setCreditorInformation($creditorInformation);
210 if ($creditorInformation->containsQrIban()) {
211 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
217 $qrBill->setPaymentReference(
218 SwissQrBill\DataGroup\Element\PaymentReference::create(
219 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
223 $currencyinvoicecode =
$object->multicurrency_code ?
$object->multicurrency_code : $conf->currency;
226 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode,
$object->total_ttc);
227 if (!$pai->isValid()) {
228 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid", (
string)
$object->total_ttc, (
string) $pai->getViolations());
231 $qrBill->setPaymentAmountInformation($pai);
234 $qrBill->setAdditionalInformation(
235 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
241 if (!empty(
$object->thirdparty->zip) && !empty(
$object->thirdparty->town)) {
242 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
246 $object->thirdparty->country_code
248 if (!$address->isValid()) {
249 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
252 $qrBill->setUltimateDebtor($address);
301 $pdf->startTransaction();
304 $pdf->SetTextColor(0, 0, 0);
305 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
306 $output->setPrintable(
false)->getPaymentPart();
308 $pdf->rollbackTransaction(
true);