30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commondocgenerator.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
35 use Sprain\SwissQrBill;
61 public $atleastonediscount = 0;
62 public $atleastoneratenotnull = 0;
78 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
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);
206 $error = $this->error;
210 if (!empty($error)) {
211 $this->error = $error;
216 return $pagenbr == 1 ? 100 : 0;
237 $pdf->startTransaction();
240 $pdf->SetTextColor(0, 0, 0);
241 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
242 $output->setPrintable(
false)->getPaymentPart();
244 $pdf->rollbackTransaction(
true);
282 $langs->load(
"bills");
283 return $langs->trans(
"NoDescription");
294 $langs->load(
"bills");
295 return $langs->trans(
"NoExample");
320 return $langs->trans(
"NotAvailable");
331 $langs->load(
"admin");
333 if ($this->version ==
'development') {
334 return $langs->trans(
"VersionDevelopment");
335 } elseif ($this->version ==
'experimental') {
336 return $langs->trans(
"VersionExperimental");
337 } elseif ($this->version ==
'dolibarr') {
339 } elseif ($this->version) {
340 return $this->version;
342 return $langs->trans(
"NotAvailable");