Add VAT number handling in order processing and invoice templates

This commit is contained in:
“VeLiTi”
2026-01-27 18:36:21 +01:00
parent f7a91737bc
commit f7733b4113
14 changed files with 81 additions and 9 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -468,6 +468,16 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
]; ];
} }
// Sort output: is_current = true first, then by price low to high
usort($output, function($a, $b) {
// First priority: is_current (true comes before false)
if ($a['is_current'] !== $b['is_current']) {
return $b['is_current'] - $a['is_current'];
}
// Second priority: price (low to high)
return floatval($a['price']) - floatval($b['price']);
});
$messages = $output; $messages = $output;
if (debug && !empty($output)) { if (debug && !empty($output)) {

View File

@@ -46,7 +46,8 @@ if (isset($post_content['cart']) && isset($post_content['checkout_input']) && is
'address_state' => $post_content['customer_details']['address_state'] ?? '', 'address_state' => $post_content['customer_details']['address_state'] ?? '',
'address_zip' => $post_content['customer_details']['address_zip'] ?? '', 'address_zip' => $post_content['customer_details']['address_zip'] ?? '',
'address_country' => $post_content['customer_details']['address_country'] ?? '', 'address_country' => $post_content['customer_details']['address_country'] ?? '',
'address_phone' => $post_content['customer_details']['address_phone'] ?? '' 'address_phone' => $post_content['customer_details']['address_phone'] ?? '',
'vat_number' => $post_content['customer_details']['vat_number'] ?? ''
]; ];
//Initialize calculator //Initialize calculator
@@ -75,7 +76,7 @@ if (isset($post_content['cart']) && isset($post_content['checkout_input']) && is
$txn_id = strtoupper(uniqid('SC') . substr(md5(mt_rand()), 0, 5)); $txn_id = strtoupper(uniqid('SC') . substr(md5(mt_rand()), 0, 5));
// Insert transaction header // Insert transaction header
$stmt = $pdo->prepare('INSERT INTO transactions (txn_id, payment_amount, payment_status, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_phone, account_id, payment_method, shipping_method, shipping_amount, discount_amount, discount_code, tax_amount,accounthierarchy) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); $stmt = $pdo->prepare('INSERT INTO transactions (txn_id, payment_amount, payment_status, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_phone, account_id, payment_method, shipping_method, shipping_amount, discount_amount, discount_code, tax_amount,accounthierarchy, vat_number) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
$stmt->execute([ $stmt->execute([
$txn_id, $txn_id,
$total, $total,
@@ -96,7 +97,8 @@ if (isset($post_content['cart']) && isset($post_content['checkout_input']) && is
$discounttotal, $discounttotal,
$checkout_input['discount_code'], $checkout_input['discount_code'],
$taxtotal, $taxtotal,
$partner_product $partner_product,
$customer_details['vat_number']
]); ]);
// Get order ID // Get order ID
$transaction_id = $pdo->lastInsertId(); $transaction_id = $pdo->lastInsertId();

BIN
assets/.DS_Store vendored

Binary file not shown.

View File

@@ -4559,6 +4559,7 @@ function transformOrderData(array $orderData): array {
'country' => $firstRow['address_country'], 'country' => $firstRow['address_country'],
'phone' => $firstRow['address_phone'], 'phone' => $firstRow['address_phone'],
'language' => $firstRow['user_language'], 'language' => $firstRow['user_language'],
'vat_number' => $firstRow['vat_number']
], ],
'products' => [], 'products' => [],
'invoice' => [ 'invoice' => [

View File

@@ -1,4 +1,5 @@
<?php <?php
$payment_method = 'payment_method_'.$invoice_data['header']['payment_method'];
$message = ' $message = '
<!DOCTYPE html> <!DOCTYPE html>
@@ -30,12 +31,29 @@ $message = '
5061 JR OISTERWIJK<br> 5061 JR OISTERWIJK<br>
Nederland Nederland
</td> </td>
<td width="50%" style="vertical-align: top; text-align: right;"> <td width="50%" style="vertical-align: top; text-align: left;">
<!-- Contact details if needed --> <strong style="color: #2c5f5d; font-size: 14px;">contact-details</strong><br>
Ralf Adams<br>
+31 13 8221480<br>
ralfadams@totalsafetysolutions.nl
</td> </td>
</tr> </tr>
</table> </table>
<!-- Customer -->
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-bottom: 25px;">
<tr>
<td width="50%" style="vertical-align: top; font-size: 13px; line-height: 1.5;">
<strong style="color: #2c5f5d; font-size: 14px;">Customer</strong><br>
'.$invoice_data['customer']['name'].'<br>
'.$invoice_data['customer']['street'].'<br>
'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].'<br>
'.$invoice_data['customer']['country'].'
</td>
</tr>
</table>
<!-- Invoice Details --> <!-- Invoice Details -->
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-bottom: 25px; font-size: 13px;"> <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-bottom: 25px; font-size: 13px;">
<tr> <tr>
@@ -49,6 +67,10 @@ $message = '
<td style="padding: 3px 0;"><strong>Invoice Number:</strong></td> <td style="padding: 3px 0;"><strong>Invoice Number:</strong></td>
<td style="padding: 3px 0;">' . htmlspecialchars($order_id) . '</td> <td style="padding: 3px 0;">' . htmlspecialchars($order_id) . '</td>
</tr> </tr>
<tr>
<td style="padding: 3px 0;"><strong>Your Vat Number:</strong></td>
<td style="padding: 3px 0;">' . htmlspecialchars($invoice_data['customer']['vat_number'] ?? '') . '</td>
</tr>
</table> </table>
</td> </td>
<td width="50%" style="vertical-align: top; padding-left: 10px;"> <td width="50%" style="vertical-align: top; padding-left: 10px;">
@@ -61,6 +83,10 @@ $message = '
<td style="padding: 3px 0;"><strong>Order number:</strong></td> <td style="padding: 3px 0;"><strong>Order number:</strong></td>
<td style="padding: 3px 0;">' . htmlspecialchars($order_id) . '</td> <td style="padding: 3px 0;">' . htmlspecialchars($order_id) . '</td>
</tr> </tr>
<tr>
<td style="padding: 3px 0;"><strong>Payment Methodr:</strong></td>
<td style="padding: 3px 0;">' . (${$payment_method} ?? $invoice_data['header']['payment_method'] ). '</td>
</tr>
</table> </table>
</td> </td>
</tr> </tr>

View File

@@ -1,4 +1,5 @@
<?php <?php
$payment_method = 'payment_method_'.$invoice_data['header']['payment_method'];
$pdf = '<!DOCTYPE html> $pdf = '<!DOCTYPE html>
<html lang="' . strtolower($language) . '"> <html lang="' . strtolower($language) . '">
@@ -217,6 +218,20 @@ $pdf = '<!DOCTYPE html>
<p>Nederland</p> <p>Nederland</p>
</div> </div>
<div class="contact-details"> <div class="contact-details">
<h3>contact-details</h3>
<p>Ralf Adams</p>
<p>+31 13 8221480</p>
<p>ralfadams@totalsafetysolutions.nl</p>
</div>
</div>
<div class="company-header">
<div class="company-info">
<h3>Customer</h3>
<p>'.$invoice_data['customer']['name'].'</p>
<p>'.$invoice_data['customer']['street'].'</p>
<p>'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].'</p>
<p>'.$invoice_data['customer']['country'].'</p>
</div> </div>
</div> </div>
@@ -230,6 +245,10 @@ $pdf = '<!DOCTYPE html>
<div class="detail-label">Invoice Number</div> <div class="detail-label">Invoice Number</div>
<div class="detail-value">: ' . htmlspecialchars($order_id) . '</div> <div class="detail-value">: ' . htmlspecialchars($order_id) . '</div>
</div> </div>
<div class="detail-row">
<div class="detail-label">Your Vat Number</div>
<div class="detail-value">: ' . htmlspecialchars($invoice_data['customer']['vat_number'] ?? '') . '</div>
</div>
</div> </div>
<div class="invoice-right"> <div class="invoice-right">
<div class="detail-row"> <div class="detail-row">
@@ -240,6 +259,10 @@ $pdf = '<!DOCTYPE html>
<div class="detail-label">Order number</div> <div class="detail-label">Order number</div>
<div class="detail-value">: ' . htmlspecialchars($order_id) . '</div> <div class="detail-value">: ' . htmlspecialchars($order_id) . '</div>
</div> </div>
<div class="detail-row">
<div class="detail-label">Payment Method</div>
<div class="detail-value">: ' . (${$payment_method} ?? $invoice_data['header']['payment_method'] ). '</div>
</div>
</div> </div>
</div> </div>

View File

@@ -1280,6 +1280,11 @@ function showPaymentModal(option) {
</div> </div>
</div> </div>
<div>
<label style="display: block; margin-bottom: 5px; color: #333; font-weight: 500;">VAT Number</label>
<input type="text" name="vat_number" id="paymentVatNumber" placeholder="Optional" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;">
</div>
<div> <div>
<label style="display: block; margin-bottom: 5px; color: #333; font-weight: 500;">Payment Method *</label> <label style="display: block; margin-bottom: 5px; color: #333; font-weight: 500;">Payment Method *</label>
<select name="payment_method" required style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;"> <select name="payment_method" required style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;">
@@ -1354,6 +1359,7 @@ function showPaymentModal(option) {
if (customerData.address) document.getElementById("paymentAddress").value = customerData.address; if (customerData.address) document.getElementById("paymentAddress").value = customerData.address;
if (customerData.city) document.getElementById("paymentCity").value = customerData.city; if (customerData.city) document.getElementById("paymentCity").value = customerData.city;
if (customerData.postal) document.getElementById("paymentPostal").value = customerData.postal; if (customerData.postal) document.getElementById("paymentPostal").value = customerData.postal;
if (customerData.vat_number) document.getElementById("paymentVatNumber").value = customerData.vat_number;
if (customerData.country) { if (customerData.country) {
document.getElementById("paymentCountry").value = customerData.country; document.getElementById("paymentCountry").value = customerData.country;
updateTaxDisplay(); // Calculate tax based on saved country updateTaxDisplay(); // Calculate tax based on saved country
@@ -1392,6 +1398,7 @@ function showPaymentModal(option) {
city: formData.get("city"), city: formData.get("city"),
postal: formData.get("postal"), postal: formData.get("postal"),
country: formData.get("country"), country: formData.get("country"),
vat_number: formData.get("vat_number") || '',
payment_method: paymentMethod, payment_method: paymentMethod,
payment_provider: paymentProvider, payment_provider: paymentProvider,
version_id: option.version_id, version_id: option.version_id,
@@ -1408,7 +1415,8 @@ function showPaymentModal(option) {
address: paymentData.address, address: paymentData.address,
city: paymentData.city, city: paymentData.city,
postal: paymentData.postal, postal: paymentData.postal,
country: paymentData.country country: paymentData.country,
vat_number: paymentData.vat_number
})); }));
await processPayment(paymentData, option, modal); await processPayment(paymentData, option, modal);

View File

@@ -827,5 +827,6 @@ $dealer_type_1 = 'Professionell';
$dealer_type_2 = 'Unternehmens';$user_information_required = 'Benutzerinformationen Erforderlich'; $dealer_type_2 = 'Unternehmens';$user_information_required = 'Benutzerinformationen Erforderlich';
$user_information_description = 'Bitte geben Sie Ihre Daten ein, um mit Software-Updates fortzufahren'; $user_information_description = 'Bitte geben Sie Ihre Daten ein, um mit Software-Updates fortzufahren';
$general_continue = 'Fortfahren'; $general_continue = 'Fortfahren';
$payment_method_1 = 'Debit/Credit';
$payment_method_3 = 'PayPal'; $payment_method_3 = 'PayPal';
?> ?>

View File

@@ -833,5 +833,6 @@ $dealer_type_2 = 'Corporativo';
$user_information_required = 'Información del Usuario Requerida'; $user_information_required = 'Información del Usuario Requerida';
$user_information_description = 'Por favor proporcione su información para continuar con las actualizaciones de software'; $user_information_description = 'Por favor proporcione su información para continuar con las actualizaciones de software';
$general_continue = 'Continuar'; $general_continue = 'Continuar';
$payment_method_1 = 'Debit/Credit';
$payment_method_3 = 'PayPal'; $payment_method_3 = 'PayPal';
?> ?>

View File

@@ -977,7 +977,6 @@ $payment_status_101 = 'In behandeling';
$payment_status_102 = 'Mislukt'; $payment_status_102 = 'Mislukt';
$payment_status_103 = 'Verlopen'; $payment_status_103 = 'Verlopen';
$payment_status_999 = 'Geannuleerd'; $payment_status_999 = 'Geannuleerd';
$payment_method_3 = ' Debit/Credit';
$contract_billing4 = ' Eenmalig vooraf'; $contract_billing4 = ' Eenmalig vooraf';
$message_build = ' Gelieve opnieuw in te loggen'; $message_build = ' Gelieve opnieuw in te loggen';
$username_enter = 'Vul je gebruikersnaam in'; $username_enter = 'Vul je gebruikersnaam in';

View File

@@ -767,5 +767,6 @@ $general_modifier_1 = '+';
$user_information_required = 'Wymagane Informacje o Użytkowniku'; $user_information_required = 'Wymagane Informacje o Użytkowniku';
$user_information_description = 'Podaj swoje dane, aby kontynuować aktualizacje oprogramowania'; $user_information_description = 'Podaj swoje dane, aby kontynuować aktualizacje oprogramowania';
$general_continue = 'Kontynuuj'; $general_continue = 'Kontynuuj';
$payment_method_1 = 'Debit/Credit';
$payment_method_3 = 'PayPal'; $payment_method_3 = 'PayPal';
?> ?>

View File

@@ -833,5 +833,6 @@ $dealer_type_2 = 'Corporativo';
$user_information_required = 'Informações do Usuário Obrigatórias'; $user_information_required = 'Informações do Usuário Obrigatórias';
$user_information_description = 'Por favor, forneça suas informações para continuar com as atualizações de software'; $user_information_description = 'Por favor, forneça suas informações para continuar com as atualizações de software';
$general_continue = 'Continuar'; $general_continue = 'Continuar';
$payment_method_1 = 'Debit/Credit';
$payment_method_3 = 'PayPal'; $payment_method_3 = 'PayPal';
?> ?>

View File

@@ -844,7 +844,6 @@ $shipping_zip = 'Zip';
$shipping_country = 'Country'; $shipping_country = 'Country';
$shipping_phone = 'Phone'; $shipping_phone = 'Phone';
$payment_method = 'Payment Method'; $payment_method = 'Payment Method';
$payment_method_1 = 'Debit (NL/BE customers)';
$payment_method_2 = 'Pay on delivery'; $payment_method_2 = 'Pay on delivery';
$h2_shoppingcart = 'Shopping Cart'; $h2_shoppingcart = 'Shopping Cart';
$discount_label = 'Discount Code'; $discount_label = 'Discount Code';
@@ -991,7 +990,7 @@ $payment_status_101 = 'Pending';
$payment_status_102 = 'Failed'; $payment_status_102 = 'Failed';
$payment_status_103 = 'Expired'; $payment_status_103 = 'Expired';
$payment_status_999 = 'Cancelled'; $payment_status_999 = 'Cancelled';
$payment_method_3 = 'Debit/Credit'; $payment_method_1 = 'Debit/Credit';
$contract_billing4 = ' Onetime upfront'; $contract_billing4 = ' Onetime upfront';
$message_build = ' Please login again'; $message_build = ' Please login again';
$username_enter = 'Please enter username'; $username_enter = 'Please enter username';