feat: Enhance software tool with country selection and tax calculation
- Added a helper function to generate country select options in software tool. - Updated user info modal and payment modal to use country dropdowns instead of text inputs. - Implemented tax calculation based on selected country in payment modal. - Improved software options loading behavior in debug mode. - Enhanced description formatting in payment modal. - Added log modal for equipment updates with a link to view logs. - Introduced a new countries settings file with tax rates for various countries. - Minor adjustments to various PHP files for better handling of equipment and payment processes.
This commit is contained in:
@@ -1264,8 +1264,10 @@ function ioServer($api_call, $data){
|
||||
$http_status = curl_getinfo($curl) ?? '200';
|
||||
curl_close($curl);
|
||||
|
||||
if(debug){
|
||||
debuglog($date." - ioServer: URL=$url, HTTP Code=$http_status, Response=" . substr($resp, 0, 500) . (strlen($resp) > 500 ? '...' : ''));
|
||||
|
||||
if (debug) {
|
||||
$resp_log = $date . " - ioServer: URL=$url, HTTP Code= ". ($http_status['http_code'] ?? 'unknown') . ", Response=" . substr($resp, 0, 500) . (strlen($resp) > 500 ? '...' : '');
|
||||
debuglog(json_encode($resp_log));
|
||||
}
|
||||
|
||||
//Check If errorcode is returned
|
||||
@@ -1728,33 +1730,38 @@ function getPartnerID($str){
|
||||
// overview Indicators
|
||||
//------------------------------------------
|
||||
function overviewIndicators($warranty, $service, $sw_version, $sw_version_latest){
|
||||
include dirname(__FILE__,2).'/settings/settings_redirector.php';
|
||||
include dirname(__FILE__,2).'/settings/systemfirmware.php';
|
||||
$indicator ='';
|
||||
//In warranty
|
||||
if (!empty($warranty ) && $warranty > $warrantydate){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">W</span>';
|
||||
} else {
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">W</span>';
|
||||
}
|
||||
//Out of Service
|
||||
if (!empty($service) && $service < $servicedate){
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">S</span>';
|
||||
} else {
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">S</span>';
|
||||
}
|
||||
|
||||
include dirname(__FILE__,2).'/settings/settings_redirector.php';
|
||||
include dirname(__FILE__,2).'/settings/systemfirmware.php';
|
||||
|
||||
$indicator ='';
|
||||
$current_date = date('Y-m-d');
|
||||
|
||||
//In warranty
|
||||
if (!empty($warranty ) && $warranty >= $current_date){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">W</span>';
|
||||
} else {
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">W</span>';
|
||||
}
|
||||
//Out of Service
|
||||
if (!empty($service) && $service >= $current_date){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">S</span>';
|
||||
} else {
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">S</span>';
|
||||
}
|
||||
|
||||
//Firmware
|
||||
if (isset($sw_version_latest)){
|
||||
if($sw_version_latest == 1){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">F</span>';
|
||||
if($sw_version_latest == 1){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">F</span>';
|
||||
}
|
||||
else {
|
||||
if ($sw_version == ''){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">F</span>';
|
||||
} else {
|
||||
if ($sw_version == ''){
|
||||
$indicator .= '<span class="dot" style="background-color: #13b368;">F</span>';
|
||||
} else {
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">F</span>';
|
||||
}
|
||||
$indicator .= '<span class="dot" style="background-color: #eb8a0d;">F</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $indicator;
|
||||
@@ -1783,11 +1790,12 @@ function warrantyStatus($input){
|
||||
}
|
||||
|
||||
$warranty_date_due ='<span class="status">Unknown</span>';
|
||||
|
||||
if (!empty($input) && $input < $warrantydate){
|
||||
$warranty_date_due = '<span class="status warranty_outdated">'.$warranty_outdated_text.'</span>';
|
||||
$current_date = date('Y-m-d');
|
||||
|
||||
if (!empty($input) && $input >= $current_date){
|
||||
$warranty_date_due = '<span class="">'.$warranty_recent.' ('.$input.')</span>';
|
||||
} else {
|
||||
$warranty_date_due = '<span class="">'.$warranty_recent.' ('.date('Y-m-d', strtotime($input. ' + 365 days')).')</span>';
|
||||
$warranty_date_due = '<span class="status warranty_outdated">'.$warranty_outdated_text.'</span>';
|
||||
}
|
||||
|
||||
return $warranty_date_due;
|
||||
@@ -1814,13 +1822,15 @@ function serviceStatus($input){
|
||||
else {
|
||||
include dirname(__FILE__,2).'/settings/translations/translations_US.php';
|
||||
}
|
||||
|
||||
|
||||
$current_date = date('Y-m-d');
|
||||
$service_date_due ='<span class="status">Unknown</span>';
|
||||
|
||||
if (!empty($input) && $input < $servicedate){
|
||||
$service_date_due = '<span class="status service_renewal">'.$service_renewal_text.'</span>';
|
||||
if (!empty($input) && $input >= $current_date){
|
||||
$service_date_due ='<span class="">'.$service_recent.' ('.$input.')</span>';
|
||||
} else {
|
||||
$service_date_due ='<span class="">'.$service_recent.' ('.date('Y-m-d', strtotime($input. ' + 365 days')).')</span>';
|
||||
$service_date_due = '<span class="status service_renewal">'.$service_renewal_text.'</span>';
|
||||
|
||||
}
|
||||
|
||||
return $service_date_due;
|
||||
@@ -2976,20 +2986,29 @@ function showlog($object,$objectID){
|
||||
$stmt->execute([$object,$objectID]);
|
||||
$changes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$view = '<label for="productcode">Changelog</label>';
|
||||
foreach($changes as $change){
|
||||
|
||||
$object_value = $change['object_value'];
|
||||
|
||||
//UPDATE TO HUMANREADABLE STATUS
|
||||
if ($object == 'equipment' && $change['object_field'] == 'status'){
|
||||
$object_text = 'status'.$change['object_value'].'_text';
|
||||
$object_value = $$object_text;
|
||||
$view = '<div class="reg-fields">';
|
||||
if ($changes) {
|
||||
foreach ($changes as $change) {
|
||||
$object_value = $change['object_value'];
|
||||
// Human-readable status
|
||||
if ($object == 'equipment' && $change['object_field'] == 'status') {
|
||||
$object_text = 'status' . $change['object_value'] . '_text';
|
||||
if (isset($$object_text)) {
|
||||
$object_value = $$object_text;
|
||||
}
|
||||
}
|
||||
$entry = htmlspecialchars( $object_value . ' - ' . $change['created'] . ' - ' . $change['createdby']);
|
||||
$view .= ' <div class="reg-field">
|
||||
<label>'.$change['object_field'].'</label>
|
||||
<p>'.$entry.'</p>
|
||||
</div>';
|
||||
|
||||
}
|
||||
} else {
|
||||
$view .= '<div style="color:#888;font-size:13px;padding:8px;">No changelog entries found.</div>';
|
||||
}
|
||||
$view .= '<input id="name" type="text" value="'.$change['object_field'].' - '.$object_value.' - '.$change['created'].' - '.$change['createdby'].'" readonly>';
|
||||
}
|
||||
|
||||
return $view;
|
||||
$view .= '</div>';
|
||||
return $view;
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
@@ -5577,4 +5596,48 @@ function updateSoftwareLatestFlags($pdo, $version_id, $hw_version) {
|
||||
$stmt->execute([$version['rowID']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Generate Countries File from Taxes API +++++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function generateCountriesFile($token){
|
||||
|
||||
//API call to get all taxes
|
||||
$api_url = '/v2/taxes';
|
||||
$response = ioAPIv2($api_url, '', $token);
|
||||
|
||||
if(!empty($response)){
|
||||
//decode the API response
|
||||
$taxes = json_decode($response, true);
|
||||
|
||||
if(!empty($taxes) && is_array($taxes)){
|
||||
//Build the countries array - id as key, with country name and tax rate
|
||||
$countries = [];
|
||||
foreach($taxes as $tax){
|
||||
$countries[$tax['id']] = [
|
||||
'country' => $tax['country'] ?? '',
|
||||
'taxes' => $tax['rate'] ?? 0
|
||||
];
|
||||
}
|
||||
|
||||
//Generate PHP file content
|
||||
$fileContent = "<?php\n";
|
||||
$fileContent .= "// Auto-generated countries file from taxes API\n";
|
||||
$fileContent .= "// Generated on: " . date('Y-m-d H:i:s') . "\n\n";
|
||||
$fileContent .= "\$countries = [\n";
|
||||
foreach($countries as $id => $data){
|
||||
$fileContent .= " " . $id . " => ['country' => '" . addslashes($data['country']) . "', 'taxes' => " . $data['taxes'] . "],\n";
|
||||
}
|
||||
$fileContent .= "];\n";
|
||||
|
||||
//Write to settings/countries.php
|
||||
$filePath = dirname(__FILE__, 2) . '/settings/countries.php';
|
||||
$result = file_put_contents($filePath, $fileContent);
|
||||
|
||||
return ($result !== false);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user