feat: Implement invoice generation and emailing functionality
- Added invoice generation logic using DomPDF. - Integrated invoice data retrieval from the API. - Implemented language determination for invoices based on customer data. - Added options to email invoices to customers and admin. - Included HTML output option for direct viewing in the browser. - Ensured proper redirection and error handling throughout the process.
This commit is contained in:
BIN
api/.DS_Store
vendored
BIN
api/.DS_Store
vendored
Binary file not shown.
BIN
api/v1/.DS_Store
vendored
BIN
api/v1/.DS_Store
vendored
Binary file not shown.
BIN
api/v2/.DS_Store
vendored
BIN
api/v2/.DS_Store
vendored
Binary file not shown.
BIN
api/v2/get/.DS_Store
vendored
BIN
api/v2/get/.DS_Store
vendored
Binary file not shown.
@@ -143,6 +143,10 @@ if(isset($get_content) && $get_content!=''){
|
||||
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'validate') {
|
||||
// Set validation mode flag
|
||||
$validation_mode = true;
|
||||
}
|
||||
elseif ($v[0] == 'firmware') {
|
||||
//Assets with firmaware upgrade = 0 (1=latest version, 2=No software)
|
||||
$clause .= ' AND e.status != 5 AND e.sw_version_latest = 0';
|
||||
@@ -161,7 +165,7 @@ if(isset($get_content) && $get_content!=''){
|
||||
}
|
||||
}
|
||||
|
||||
if ($sw_version_latest_update == 1){
|
||||
if ($sw_version_latest_update == 1 || $clause == ''){
|
||||
//------------------------------------------
|
||||
//UPDATE SW_STATUS
|
||||
//------------------------------------------
|
||||
@@ -175,6 +179,10 @@ if (isset($criterias['download']) && $criterias['download'] ==''){
|
||||
//Request for download
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID';
|
||||
}
|
||||
elseif (isset($validation_mode) && $validation_mode === true) {
|
||||
// Validation mode - return count only for serial validation
|
||||
$sql = "SELECT count(rowID) as rowID from equipment e $whereclause";
|
||||
}
|
||||
elseif (isset($criterias['totals']) && $criterias['totals'] =='' && !isset($criterias['type'])){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.'';
|
||||
@@ -314,7 +322,19 @@ if (debug){
|
||||
//------------------------------------------
|
||||
//Add paging details
|
||||
//------------------------------------------
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
if (isset($validation_mode) && $validation_mode === true) {
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
|
||||
if ($messages[0] == 1) {
|
||||
echo json_encode(array('SN'=> TRUE));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('SN'=> FALSE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
elseif(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
|
||||
@@ -136,10 +136,22 @@ else {
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Clean up nested JSON in description fields before final encoding
|
||||
if (!isset($criterias['totals']) || $criterias['totals'] != '') {
|
||||
foreach ($messages as &$message) {
|
||||
if (isset($message['description']) && is_string($message['description'])) {
|
||||
$decoded = json_decode($message['description'], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$message['description'] = json_encode($decoded, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
@@ -51,7 +51,7 @@ elseif (isset($criterias['list']) && $criterias['list'] =='invoice'){
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT tx.*, txi.item_id as item_id,txi.item_price as item_price, txi.item_quantity as item_quantity, txi.item_options as item_options, p.productcode, p.productname, inv.id as invoice, inv.created as invoice_created, i.language as user_language
|
||||
FROM transactions tx
|
||||
left join invoice inv ON tx.id = inv.txn_id
|
||||
left join invoice inv ON tx.txn_id = inv.txn_id
|
||||
left join transactions_items txi ON tx.id = txi.txn_id
|
||||
left join products p ON p.rowID = txi.item_id
|
||||
left join identity i ON i.userkey = tx.account_id '.$whereclause;
|
||||
|
||||
@@ -161,6 +161,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$debug['decision'] = 'No active software assignments found';
|
||||
}
|
||||
} else {
|
||||
$available_upgrades = 0;
|
||||
$has_priced_options = false;
|
||||
$has_latest_version_different = false;
|
||||
|
||||
@@ -242,6 +243,8 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
|
||||
if ($show_version) {
|
||||
$available_upgrades++;
|
||||
|
||||
//Check if there's a valid license for this upgrade
|
||||
if ($final_price > 0 && $sw_version_license) {
|
||||
//Check if the license is valid
|
||||
@@ -286,23 +289,18 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the logic:
|
||||
// 1. If there are priced options -> "yes"
|
||||
// 2. If no priced options but current version != latest flagged version -> "yes"
|
||||
// 3. Default -> "no"
|
||||
if ($has_priced_options) {
|
||||
// Simple logic: if any upgrades are available to show, return "yes"
|
||||
if ($available_upgrades > 0) {
|
||||
$software_available = "yes";
|
||||
$availability_reason = "Has priced upgrade options available";
|
||||
} elseif ($has_latest_version_different) {
|
||||
$software_available = "yes";
|
||||
$availability_reason = "Has free latest version available";
|
||||
$availability_reason = "Software upgrades available";
|
||||
} else {
|
||||
$software_available = "no";
|
||||
$availability_reason = "No upgrades available or already on latest";
|
||||
$availability_reason = "No upgrades available";
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
$debug['final_decision'] = [
|
||||
'available_upgrades' => $available_upgrades,
|
||||
'has_priced_options' => $has_priced_options,
|
||||
'has_latest_version_different' => $has_latest_version_different,
|
||||
'software_available' => $software_available,
|
||||
|
||||
@@ -133,6 +133,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
JOIN products_software_versions psv ON psa.software_version_id = psv.rowID
|
||||
WHERE psa.product_id = ?
|
||||
AND psa.status = 1
|
||||
AND psv.latest = 1
|
||||
AND (psv.hw_version = ? OR psv.hw_version IS NULL OR psv.hw_version = "")';
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
@@ -212,16 +213,13 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$decision_reason = 'Skipped - is current version but no upgrades scenario';
|
||||
}
|
||||
} else {
|
||||
//Check if this is the current version and should be shown as disabled
|
||||
if ($is_current_version && $has_paid_upgrade_from_current && $version['latest'] == 1) {
|
||||
//Show current version as disabled only if it's the latest AND there's a paid upgrade available
|
||||
//Check if this is the current version - always show it
|
||||
if ($is_current_version) {
|
||||
$show_version = true;
|
||||
$is_current = true;
|
||||
$final_price = '0.00';
|
||||
$final_currency = '';
|
||||
$decision_reason = 'Showing as CURRENT - is latest version with paid upgrade available';
|
||||
} else if ($is_current_version && !($has_paid_upgrade_from_current && $version['latest'] == 1)) {
|
||||
$decision_reason = 'Skipped - is current version but not (latest + has_paid_upgrade)';
|
||||
$decision_reason = 'Showing as CURRENT - always show current version';
|
||||
} else if (!$is_current_version) {
|
||||
//Check if this version is part of ANY upgrade path system (either FROM or TO)
|
||||
$sql = 'SELECT COUNT(*) as path_count
|
||||
|
||||
BIN
api/v2/post/.DS_Store
vendored
BIN
api/v2/post/.DS_Store
vendored
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// History
|
||||
//------------------------------------------
|
||||
@@ -209,9 +210,8 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){
|
||||
if ($equipmentUpdate == 1){
|
||||
//get HW + SW from PortalAPI
|
||||
if ($post_content['type'] == 'firmware'){
|
||||
$test = json_decode($post_content['payload']);
|
||||
$hw_version = $test->HW;
|
||||
$sw_version = $test->HEX_FW;
|
||||
$hw_version = $post_content['payload']['HW'];
|
||||
$sw_version = $post_content['payload']['HEX_FW'];
|
||||
}
|
||||
else {
|
||||
//GET HW + SW from object
|
||||
|
||||
@@ -14,7 +14,7 @@ $post_content = json_decode($input,true);
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
list($whereclause,$condition) = getWhereclauselvl2("software_upgrade_paths",$permission,$partner,'');
|
||||
list($whereclause,$condition) = getWhereclauselvl2("",$permission,$partner,'');
|
||||
|
||||
//SET PARAMETERS FOR QUERY
|
||||
$id = $post_content['rowID'] ?? ''; //check for rowID
|
||||
|
||||
Reference in New Issue
Block a user