- Updated API calls in equipment.php, equipment_manage.php, and equipments_mass_update.php to use v2 endpoints. - Changed payload decoding from decode_payload to json_decode for consistency. - Enhanced invoice generation in factuur.php and webhook files to use a new email template and PDF structure. - Added new email and PDF templates for invoices to improve formatting and readability. - Improved marketing folder handling in marketing.php with better payload management. - Updated CSS for marketing to enhance UI interactions. - Added JavaScript checks for browser compatibility in softwaretool.php. - Adjusted user permissions in settingsprofiles.php to reflect new features.
150 lines
4.2 KiB
PHP
150 lines
4.2 KiB
PHP
<?php
|
|
defined(page_security_key) or exit;
|
|
|
|
if (debug && debug_id == $_SESSION['id']) {
|
|
ini_set('display_errors', '1');
|
|
ini_set('display_startup_errors', '1');
|
|
error_reporting(E_ALL);
|
|
}
|
|
|
|
include_once './assets/functions.php';
|
|
include_once './settings/settings_redirector.php';
|
|
|
|
// Check if allowed
|
|
if (isAllowed('order', $_SESSION['profile'], $_SESSION['permission'], 'R') === 0) {
|
|
header('location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// Get transaction ID from POST or GET (for HTML output)
|
|
$order_number = $_POST['txn_id'] ?? $_GET['txn_id'] ?? '';
|
|
|
|
if (empty($order_number)) {
|
|
header('Location: index.php?page=orders');
|
|
exit;
|
|
}
|
|
|
|
// Connect to database
|
|
$pdo = dbConnect($dbname);
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Get detailed invoice data
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
$api_url = '/v2/invoice/list=invoice&txn_id=' . $order_number;
|
|
$invoice_data = ioServer($api_url, '');
|
|
$invoice_data = json_decode($invoice_data, true);
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Determine invoice language
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
$available_languages = [
|
|
'NL' => 'NL',
|
|
'BE' => 'NL',
|
|
'US' => 'US',
|
|
'GB' => 'US',
|
|
'DE' => 'DE',
|
|
'FR' => 'FR',
|
|
'ES' => 'ES'
|
|
];
|
|
|
|
$invoice_language = 'US'; // Default
|
|
if (!empty($invoice_data['customer']['language'])) {
|
|
$invoice_language = strtoupper($invoice_data['customer']['language']);
|
|
} elseif (!empty($invoice_data['customer']['country']) && isset($available_languages[strtoupper($invoice_data['customer']['country'])])) {
|
|
$invoice_language = $available_languages[strtoupper($invoice_data['customer']['country'])];
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Generate invoice HTML
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
list($message,$pdf, $customer_email, $order_id) = generateSoftwareInvoice($invoice_data, $order_number, $invoice_language);
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Check for HTML output request
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
if (isset($_GET['output']) && $_GET['output'] === 'html') {
|
|
// Output HTML directly to browser
|
|
echo $message;
|
|
exit;
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Initialize DomPDF
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
use Dompdf\Dompdf;
|
|
use Dompdf\Options;
|
|
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', true);
|
|
$dompdf = new Dompdf($options);
|
|
|
|
// Load HTML content
|
|
$dompdf->loadHtml($pdf);
|
|
|
|
// Setup paper size and orientation
|
|
$dompdf->setPaper('A4', 'portrait');
|
|
|
|
// Render the HTML as PDF
|
|
$dompdf->render();
|
|
|
|
$file_name = 'Factuur - ' . $order_id;
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Handle different actions
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// Email invoice to customer
|
|
if (isset($_POST['email_invoice'])) {
|
|
$to = $customer_email;
|
|
$subject = 'Factuur - ' . $order_id;
|
|
$attachment = $dompdf->output();
|
|
$attachment_name = $file_name . '.pdf';
|
|
|
|
$header_redirect = 'Location: index.php?page=order&id=' . $order_id . '&success=invoice_sent';
|
|
|
|
// Send to PHPMailer
|
|
send_mail($to, $subject, $message, $attachment, $attachment_name);
|
|
|
|
header($header_redirect);
|
|
exit;
|
|
}
|
|
|
|
// Email invoice to admin/bookkeeping
|
|
if (isset($_POST['email_invoice_to_admin'])) {
|
|
$to = $customer_email;
|
|
$subject = 'Factuur - ' . $order_id;
|
|
$attachment = $dompdf->output();
|
|
$attachment_name = $file_name . '.pdf';
|
|
|
|
$header_redirect = 'Location: index.php?page=order&id=' . $order_id . '&success=invoice_sent_admin';
|
|
|
|
// Send to bookkeeping if configured
|
|
if (invoice_bookkeeping && email_bookkeeping) {
|
|
send_mail(email_bookkeeping, $subject, $message, $attachment, $attachment_name);
|
|
}
|
|
|
|
header($header_redirect);
|
|
exit;
|
|
}
|
|
|
|
// Show invoice in browser
|
|
if (isset($_GET['show_invoice'])) {
|
|
// Clean output buffer to prevent corrupted PDF
|
|
if (ob_get_level()) {
|
|
ob_end_clean();
|
|
}
|
|
|
|
// Stream PDF to browser
|
|
$dompdf->stream($file_name . ".pdf", array("Attachment" => false));
|
|
exit;
|
|
}
|
|
|
|
// If no action specified, redirect back
|
|
header('Location: index.php?page=order&id=' . $order_number);
|
|
exit;
|
|
|
|
?>
|