First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
122
www/intern/scripts/trainer/rechnung/ajax-neu_qr_rechnung.php
Normal file
122
www/intern/scripts/trainer/rechnung/ajax-neu_qr_rechnung.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_trainer']) || $_SESSION['access_granted_trainer'] !== true || empty($_SESSION['passcodetrainer_id']) || $_SESSION['passcodetrainer_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_POST['preis']) || !isset($_POST['name']) || !isset($_POST['vorname']) || !isset($_POST['strasse']) || !isset($_POST['plz']) || !isset($_POST['ort']) || !isset($_POST['hausnummer'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid input']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) $baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
|
||||
require $baseDir . '/../composer/vendor/autoload.php';
|
||||
|
||||
use Sprain\SwissQrBill as QrBill;
|
||||
|
||||
|
||||
// This is an example how to create a typical qr bill:
|
||||
// - with reference number
|
||||
// - with known debtor
|
||||
// - with specified amount
|
||||
// - with human-readable additional information
|
||||
// - using your QR-IBAN
|
||||
//
|
||||
// Likely the most common use-case in the business world.
|
||||
|
||||
// Create a new instance of QrBill, containing default headers with fixed values
|
||||
$qrBill = QrBill\QrBill::create();
|
||||
|
||||
$name = trim((string)($rechnungenVorname ?? '') . ' ' . (string)($rechnungenName ?? ''));
|
||||
$strasse = (string)($rechnungenStrasse ?? '');
|
||||
$hausnr = (string)($rechnungenHausnummer ?? '');
|
||||
$plz = (string)($rechnungenPostleitzahl ?? '');
|
||||
$ort = (string)($rechnungenOrt ?? '');
|
||||
|
||||
$qrBill->setCreditor(
|
||||
QrBill\DataGroup\Element\StructuredAddress::createWithStreet(
|
||||
$name,
|
||||
$strasse,
|
||||
$hausnr,
|
||||
$plz,
|
||||
$ort,
|
||||
'CH'
|
||||
)
|
||||
);
|
||||
|
||||
$iban = strtoupper(str_replace(' ', '', (string)($rechnungenIBAN ?? '')));
|
||||
|
||||
$qrBill->setCreditorInformation(
|
||||
QrBill\DataGroup\Element\CreditorInformation::create($iban)
|
||||
);
|
||||
|
||||
// Add debtor information
|
||||
// Who has to pay the invoice? This part is optional.
|
||||
$qrBill->setUltimateDebtor(
|
||||
QrBill\DataGroup\Element\StructuredAddress::createWithStreet(
|
||||
$_POST['vorname'] . ' ' . $_POST['name'],
|
||||
$_POST['strasse'],
|
||||
$_POST['hausnummer'],
|
||||
$_POST['plz'],
|
||||
$_POST['ort'],
|
||||
'CH'
|
||||
)
|
||||
);
|
||||
|
||||
// Add payment amount information
|
||||
// What amount is to be paid?
|
||||
$qrBill->setPaymentAmountInformation(
|
||||
QrBill\DataGroup\Element\PaymentAmountInformation::create(
|
||||
'CHF',
|
||||
$totalPreis
|
||||
)
|
||||
);
|
||||
|
||||
// Add payment reference
|
||||
// This is what you will need to identify incoming payments.
|
||||
$qrBill->setPaymentReference(
|
||||
QrBill\DataGroup\Element\PaymentReference::create(
|
||||
QrBill\DataGroup\Element\PaymentReference::TYPE_SCOR,
|
||||
QrBill\Reference\RfCreditorReferenceGenerator::generate($dbresult['order_id'])
|
||||
)
|
||||
);
|
||||
|
||||
$month = date('m');
|
||||
|
||||
if ($month < 6){
|
||||
$jahr = date('Y');
|
||||
} else {
|
||||
$jahr = date('Y') + 1;
|
||||
}
|
||||
|
||||
$referenz = "Startgebühren ". $wkName. " ".$jahr;
|
||||
|
||||
// Optionally, add some human-readable information about what the bill is for.
|
||||
$qrBill->setAdditionalInformation(
|
||||
QrBill\DataGroup\Element\AdditionalInformation::create(
|
||||
$referenz
|
||||
)
|
||||
);
|
||||
|
||||
// Now get the QR code image and save it as a file.
|
||||
/*try {
|
||||
$qrBill->getQrCode()->writeFile(__DIR__ . '/qrneu.png');
|
||||
$qrBill->getQrCode()->writeFile(__DIR__ . '/qrneu.svg');
|
||||
} catch (\Throwable $e) {
|
||||
foreach ($qrBill->getViolations() as $violation) {
|
||||
print $violation->getMessage()."\n";
|
||||
}
|
||||
// Also print exception message when available
|
||||
error_log('QR bill error: ' . $e->getMessage());
|
||||
exit;
|
||||
}*/
|
||||
|
||||
// Next: Output full payment parts, depending on the format you want to use:
|
||||
//
|
||||
// - FpdfOutput/fpdf-example.php
|
||||
// - HtmlOutput/html-example.php
|
||||
// - TcPdfOutput/tcpdf-example.php
|
||||
Reference in New Issue
Block a user