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;
125 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
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);
270 $error = $this->error;
274 if (!empty($error)) {
275 $this->error = $error;
280 return $pagenbr == 1 ? 100 : 0;
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);
328 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, $showempty=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...