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;
59 public $atleastonediscount = 0;
60 public $atleastoneratenotnull = 0;
77 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
96 abstract public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
115 if (
$object->mode_reglement_code !=
'VIR') {
116 $this->error = $langs->transnoentities(
"SwissQrOnlyVIR");
120 if (empty(
$object->fk_account)) {
121 $this->error =
'Bank account must be defined to use this experimental feature';
126 if (file_exists(DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php')) {
127 require_once DOL_DOCUMENT_ROOT.
'/includes/sprain/swiss-qr-bill/autoload.php';
128 } elseif (file_exists(DOL_DOCUMENT_ROOT.
'/includes/autoload.php')) {
129 require_once DOL_DOCUMENT_ROOT.
'/includes/autoload.php';
131 $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;';
136 $qrBill = SwissQrBill\QrBill::create();
139 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
140 $this->emetteur->name,
141 $this->emetteur->address,
142 $this->emetteur->zip .
" " . $this->emetteur->town,
143 $this->emetteur->country_code
145 if (!$address->isValid()) {
146 $this->error = $langs->transnoentities(
"SwissQrCreditorAddressInvalid", (
string) $address->getViolations());
149 $qrBill->setCreditor($address);
152 $account =
new Account($this->db);
153 $account->fetch(
$object->fk_account);
154 $creditorInformation = SwissQrBill\DataGroup\Element\CreditorInformation::create($account->iban);
155 if (!$creditorInformation->isValid()) {
156 $langs->load(
"errors");
157 $this->error = $langs->transnoentities(
"SwissQrCreditorInformationInvalid", $account->iban, (
string) $creditorInformation->getViolations());
160 $qrBill->setCreditorInformation($creditorInformation);
162 if ($creditorInformation->containsQrIban()) {
163 $this->error = $langs->transnoentities(
"SwissQrIbanNotImplementedYet", $account->iban);
169 $qrBill->setPaymentReference(
170 SwissQrBill\DataGroup\Element\PaymentReference::create(
171 SwissQrBill\DataGroup\Element\PaymentReference::TYPE_NON
175 $currencyinvoicecode =
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency;
178 $pai = SwissQrBill\DataGroup\Element\PaymentAmountInformation::create($currencyinvoicecode,
$object->total_ttc);
179 if (!$pai->isValid()) {
180 $this->error = $langs->transnoentities(
"SwissQrPaymentInformationInvalid",
$object->total_ttc, (
string) $pai->getViolations());
183 $qrBill->setPaymentAmountInformation($pai);
186 $qrBill->setAdditionalInformation(
187 SwissQrBill\DataGroup\Element\AdditionalInformation::create(
193 if (!empty(
$object->thirdparty->zip) && !empty(
$object->thirdparty->town)) {
194 $address = SwissQrBill\DataGroup\Element\CombinedAddress::create(
198 $object->thirdparty->country_code
200 if (!$address->isValid()) {
201 $this->error = $langs->transnoentities(
"SwissQrDebitorAddressInvalid", (
string) $address->getViolations());
204 $qrBill->setUltimateDebtor($address);
222 $error = $this->error;
226 if (!empty($error)) {
227 $this->error = $error;
232 return $pagenbr == 1 ? 100 : 0;
253 $pdf->startTransaction();
256 $pdf->SetTextColor(0, 0, 0);
257 $output =
new SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, in_array($langs->shortlang, [
'de',
'fr',
'it']) ? $langs->shortlang :
'en', $pdf);
258 $output->setPrintable(
false)->getPaymentPart();
260 $pdf->rollbackTransaction(
true);
280 abstract public function getNextValue($objsoc, $invoice, $mode =
'next');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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)
Return list of activated modules usable for document generation.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...