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:
@@ -44,12 +44,16 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
$updateObject_visual = 0; //update visual inspection object
|
||||
$sendServiceReport = 0; //send service report via email
|
||||
$transfercartest = 0; //Update cartest table with incoming data
|
||||
$create_software_license = 0; //Create software license
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//SET DEFAULT PARAMETERS
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$user = $username;
|
||||
$account = $partnerhierarchy; //string
|
||||
$current_date = date("Y-m-d");
|
||||
$service_date = date("Y-m-d", strtotime("+" . SERVICE_MONTHS . " months"));
|
||||
$warranty_date = date("Y-m-d", strtotime("+" . WARRANTY_MONTHS . " months"));
|
||||
$order_send_date = date("Y-m-d");
|
||||
$input_type = $post_content['type'];
|
||||
$testdetails = json_encode($post_content['payload']);
|
||||
$serial = $post_content['sn'];
|
||||
@@ -146,6 +150,11 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
$transfercartest = 1;
|
||||
break;
|
||||
|
||||
case 12: //customer_consent
|
||||
$historytype = 'Customer_consent';
|
||||
$create_software_license = 1;
|
||||
break;
|
||||
|
||||
case 'firmware': //update from Portal
|
||||
$historytype = $HistoryType_2;
|
||||
$equipmentUpdate = 1;
|
||||
@@ -164,14 +173,14 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//Connect to DB
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
//Get whereclause based on serialnumber
|
||||
$whereclause = checkSerial($serial);
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//CHECK if EQUIPMENT EXISTS
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$sql = "SELECT count(rowID) as total, rowID FROM equipment $whereclause";
|
||||
$sql = "SELECT count(rowID) as total, rowID, hw_version FROM equipment $whereclause";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$total = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
@@ -182,9 +191,9 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
// Create equipment when not exist +++++++++++++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
if ($equipmentCreate == 1 && $total_equipment == 0){
|
||||
$sql = 'INSERT INTO equipment (productrowid,created,createdby,status,accounthierarchy,serialnumber,service_date,warranty_date) VALUES (?,?,?,?,?,?,?,?)';
|
||||
$sql = 'INSERT INTO equipment (productrowid,created,createdby,status,accounthierarchy,serialnumber,service_date,warranty_date,order_send_date) VALUES (?,?,?,?,?,?,?,?,?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$productrowid,$date,$user,$status0,$account,$serial,$current_date,$current_date]);
|
||||
$stmt->execute([$productrowid,$date,$user,$status0,$account,$serial,$service_date,$warranty_date,$order_send_date]);
|
||||
$rowID = $pdo->lastInsertId();
|
||||
}
|
||||
|
||||
@@ -305,7 +314,7 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
//Update Equipment record
|
||||
$sql = "UPDATE equipment SET service_date = ? $whereclause";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$current_date]);
|
||||
$stmt->execute([$service_date]);
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
@@ -357,6 +366,49 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos
|
||||
if ($transfercartest == 1){
|
||||
convertCartest();
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// create software license ++++++++++++++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
if ($create_software_license == 1){
|
||||
// Generate unique license key
|
||||
$license_key = generateUniqueLicenseKey();
|
||||
|
||||
$sw_version_consent = strtolower($post_content['testdetails']['logdetails']['FW'] ?? '');// version_id
|
||||
$eq_version_hw = strtolower($rowID['hw_version'] ?? '');
|
||||
|
||||
//GET VERSION_ID FROM VERSION TABLE
|
||||
$sql = 'SELECT rowID FROM products_software_versions WHERE version = ? and hw_version = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$sw_version_consent, $eq_version_hw]);
|
||||
$version_row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
//GET VERSION_ID or use WILDCARD
|
||||
$sw_version_consent = $version_row['rowID'] ?? '9999999';
|
||||
|
||||
// Create license
|
||||
$sql = 'INSERT INTO products_software_licenses
|
||||
(version_id, license_type, license_key, status, starts_at, expires_at, transaction_id, created, createdby)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
$sw_version_consent,
|
||||
1, // license_type (1 = upgrade)
|
||||
$license_key,
|
||||
1, // status = active
|
||||
date('Y-m-d H:i:s'),
|
||||
'2099-12-31 23:59:59', // effectively permanent
|
||||
'Customer_consent',
|
||||
date('Y-m-d H:i:s'),
|
||||
$user
|
||||
]);
|
||||
|
||||
// Update equipment.sw_version_license
|
||||
$sql = 'UPDATE equipment SET sw_version_license = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$license_key, $rowID]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user