99 if ($object->mode_reglement_code !=
'VIR') {
100 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
104 if (empty($object->fk_account)) {
105 $this->error =
'Bank account must be defined to use this experimental feature';
110 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
111 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
112 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
113 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
115 $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;';
120 $qrBill = SwissQrBill\QrBill::create();
123 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
124 $this->emetteur->name,
125 $this->emetteur->address,
126 $this->emetteur->zip .
" " . $this->emetteur->town,
127 $this->emetteur->country_code
129 if (!$address->isValid()) {
130 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
133 $qrBill->setCreditor($address);
136 $account =
new Account($this->db);
137 $account->fetch($object->fk_account);
138 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
139 if (!$creditorInformation->isValid()) {
140 $langs->load(
"errors");
141 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
144 $qrBill->setCreditorInformation($creditorInformation);
146 if ($creditorInformation->containsQrIban()) {
147 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
153 $qrBill->setPaymentReference(
154 SwissQrBill\DataGroup\Element\PaymentReference::create(
155 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
159 $currencyinvoicecode = $object->multicurrency_code ? $object->multicurrency_code : $conf->currency;
162 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode, $object->total_ttc);
163 if (!$pai->isValid()) {
164 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid", $object->total_ttc, (
string) $pai->getViolations());
167 $qrBill->setPaymentAmountInformation($pai);
170 $qrBill->setAdditionalInformation(
171 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
177 if (!empty($object->thirdparty->zip) && !empty($object->thirdparty->town)) {
178 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
179 $object->thirdparty->name,
180 $object->thirdparty->address,
181 $object->thirdparty->zip .
" " . $object->thirdparty->town,
182 $object->thirdparty->country_code
184 if (!$address->isValid()) {
185 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
188 $qrBill->setUltimateDebtor($address);