32require_once DOL_DOCUMENT_ROOT.
'/core/class/commondocgenerator.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonnumrefgenerator.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
38use Sprain\SwissQrBill;
104 public $atleastonediscount = 0;
108 public $atleastoneratenotnull = 0;
113 public $showAmountBeforeDiscount = 1;
118 public $showDiscountAmount = 1;
134 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
153 abstract public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
172 if (
$object->mode_reglement_code !=
'VIR') {
173 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
177 if (empty(
$object->fk_account)) {
178 $this->error =
'Bank account must be defined to use this experimental feature';
183 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
184 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
185 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
186 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
188 $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;';
193 $qrBill = SwissQrBill\QrBill::create();
196 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
197 $this->emetteur->name,
198 $this->emetteur->address,
199 $this->emetteur->zip .
" " . $this->emetteur->town,
200 $this->emetteur->country_code
202 if (!$address->isValid()) {
203 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
206 $qrBill->setCreditor($address);
209 $account =
new Account($this->db);
210 $account->fetch((
int)
$object->fk_account);
211 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
212 if (!$creditorInformation->isValid()) {
213 $langs->load(
"errors");
214 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
217 $qrBill->setCreditorInformation($creditorInformation);
219 if ($creditorInformation->containsQrIban()) {
220 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
226 $qrBill->setPaymentReference(
227 SwissQrBill\DataGroup\Element\PaymentReference::create(
228 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
232 $currencyinvoicecode =
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency;
235 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode,
$object->total_ttc);
236 if (!$pai->isValid()) {
237 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid", (
string)
$object->total_ttc, (
string) $pai->getViolations());
240 $qrBill->setPaymentAmountInformation($pai);
243 $qrBill->setAdditionalInformation(
244 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
250 if (!empty(
$object->thirdparty->zip) && !empty(
$object->thirdparty->town)) {
251 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
255 $object->thirdparty->country_code
257 if (!$address->isValid()) {
258 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
261 $qrBill->setUltimateDebtor($address);
279 $error = $this->error;
283 if (!empty($error)) {
284 $this->error = $error;
289 return $pagenbr == 1 ? 100 : 0;
310 $pdf->startTransaction();
313 $pdf->SetTextColor(0, 0, 0);
314 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
315 $output->setPrintable(
false)->getPaymentPart();
317 $pdf->rollbackTransaction(
true);
337 abstract public function getNextValue($objsoc, $invoice, $mode =
'next');
if(! $sortfield) if(! $sortorder) $object
Class to manage bank accounts.
Parent class for documents (PDF, ODT, ...) generators.
Parent class for number ref generators.
Class to manage invoices.
Parent class of invoice reference numbering templates.
getExample()
Return an example of numbering.
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
Parent class of invoice document generators.
getSwissQrBill(Facture $object, Translate $langs)
Get the SwissQR object, including validation.
addBottomQRInvoice(TCPDF $pdf, Facture $object, Translate $langs)
Add SwissQR invoice at bottom of page 1.
getHeightForQRInvoice(int $pagenbr, Facture $object, Translate $langs)
Get the height for bottom-page QR invoice in mm, depending on the page number.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Class to manage translations.
getListOfModels($db, $type, $maxfilenamelength=0, $showempty=0)
Return list of activated modules usable for document generation.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.