Refactor API endpoints and update invoice generation
- 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.
This commit is contained in:
@@ -15,7 +15,6 @@ if ($action !=''){
|
||||
//Connect to DB
|
||||
//------------------------------------------
|
||||
$pdo = dbConnect($dbname);
|
||||
$pdo2 = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//CONTENT FROM API (POST)
|
||||
@@ -99,224 +98,108 @@ switch ($action) {
|
||||
];
|
||||
|
||||
$description = json_encode($history_description, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// --------------------------------------------
|
||||
// Check if multiple serialnumbers are provided
|
||||
// --------------------------------------------
|
||||
if(is_array($post_content['sn'])){
|
||||
foreach ($post_content['sn'] as $sn){
|
||||
//Get equipmentid based on rowID
|
||||
$rowID = getrowID($dbname,'rowID','equipment','serialnumber="'.$sn.'"');
|
||||
|
||||
if ($rowID){
|
||||
//check if under warranty
|
||||
$warranty = getrowID($dbname,'rowID','equipment_history','equipmentid="'.$rowID['rowID'].'" && (type="'.$type9.'" || type="'.$type10.'" || type="'.$type11.'" || type="'.$type12.'")');
|
||||
if ($warranty){
|
||||
// --------------------------------------------
|
||||
// Already under contract
|
||||
// --------------------------------------------
|
||||
//Serialnumber under warranty
|
||||
$message_box[] = $sn.' - '.$register_message_2;
|
||||
$communication_check = 1;
|
||||
} else
|
||||
{
|
||||
// --------------------------------------------
|
||||
// Not under warranty
|
||||
// --------------------------------------------
|
||||
//Send user firmware account
|
||||
$firmware_account_send = 1;
|
||||
//create history
|
||||
// Prepare queries
|
||||
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby,updatedby) VALUES (?,?,?,?,?,?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email'],$post_content['email']]);
|
||||
// Normalize input to always be an array
|
||||
$serial_numbers = is_array($post_content['sn']) ? $post_content['sn'] : [$post_content['sn']];
|
||||
|
||||
//GET PARTNER DETAILS OF EQUIPMENT
|
||||
$partner_equipment = getrowID($dbname,'accounthierarchy','equipment','rowID="'.$rowID['rowID'].'"');
|
||||
$partner_equipment = json_decode($partner_equipment['accounthierarchy']);
|
||||
|
||||
//Setup partnerhierarchy (salesID)
|
||||
$partnerhierarchy =[
|
||||
"salesid"=>$partner_equipment->salesid,
|
||||
"soldto"=>$partner_equipment->soldto
|
||||
];
|
||||
|
||||
//Setup variables for partner
|
||||
$partnername = $post_content['organization'];
|
||||
$partnernotes = 'created based on user registration';
|
||||
$salesID = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
$createdby = 'system';
|
||||
|
||||
//Check if shipto is empty and if empty search partner or create
|
||||
if ($partner_equipment->shipto == ''){
|
||||
$partner_shipto = getrowID($dbname,'partnerID','partner','partnername = "'.$partnername.'" && partnertype="'.$partnertype3.'"');
|
||||
if ($partner_shipto){
|
||||
//Partner exists - Use it
|
||||
$partnerhierarchy['shipto'] = $partner_shipto['partnerID'].'-'.$partnername;
|
||||
} else {
|
||||
//Partner does not exist create
|
||||
$sql = 'INSERT INTO partner (partnertype,partnername,salesID,createdby,status) VALUES (?,?,?,?,?)';
|
||||
$stmt = $pdo2->prepare($sql);
|
||||
$stmt->execute([$partnertype3,$partnername,$salesID,$createdby,'1']);
|
||||
|
||||
//Get rowID of created partner and use it
|
||||
$partner_rowid = $pdo2->lastInsertId();
|
||||
$partnerhierarchy['shipto'] = $partner_rowid.'-'.$partnername;
|
||||
}
|
||||
} else {
|
||||
// Shipto exist use it
|
||||
$partnerhierarchy['shipto'] = $partner_equipment->shipto;
|
||||
}
|
||||
//Check if location is empty and if empty search partner or create
|
||||
if ($partner_equipment->location == ''){
|
||||
$partner_location = getrowID($dbname,'partnerID','partner','partnername = "'.$partnername.'" && partnertype="'.$partnertype4.'"');
|
||||
if ($partner_location){
|
||||
//Partner exists - Use it
|
||||
$partnerhierarchy['location'] = $partner_location['partnerID'].'-'.$partnername;
|
||||
|
||||
} else {
|
||||
//Partner does not exist create
|
||||
$sql = 'INSERT INTO partner (partnertype,partnername,salesID,createdby,status) VALUES (?,?,?,?,?)';
|
||||
$stmt = $pdo2->prepare($sql);
|
||||
$stmt->execute([$partnertype4,$partnername,$salesID,$createdby,'1']);
|
||||
|
||||
//Get rowID of created partner and use it
|
||||
$partner_rowid = $pdo2->lastInsertId();
|
||||
$partnerhierarchy['location'] = $partner_rowid.'-'.$partnername;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Location exist use it
|
||||
$partnerhierarchy['location'] = $partner_equipment->location;
|
||||
}
|
||||
|
||||
$shipto = $partnerhierarchy['shipto'] ?? '';
|
||||
$partnerhierarchy = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
// --------------------------------------------
|
||||
// Update equipment record warranty_date, partnerhierarchy, status equipment
|
||||
// --------------------------------------------
|
||||
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ?,updatedby = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$username,$rowID['rowID']]);
|
||||
|
||||
//Add warranty to changelog
|
||||
$warranty_user = $post_content['email'] ?? 'system';
|
||||
changelog($dbname,'equipment',$rowID['rowID'],'Warranty',$warranty_extended,$warranty_user);
|
||||
|
||||
//Serialnumber recognized
|
||||
$message_box[] = $sn.' - '.$register_message_3;
|
||||
$communication_check = 1;
|
||||
}
|
||||
} else {
|
||||
//Serialnumber not recognized
|
||||
$message_box[] = $sn.' - '.$register_message_1;
|
||||
}
|
||||
foreach ($serial_numbers as $sn) {
|
||||
// Get equipment ID based on serial number
|
||||
$rowID = getrowID($dbname, 'rowID', 'equipment', 'serialnumber="' . $sn . '"');
|
||||
|
||||
if (!$rowID) {
|
||||
// Serial number not recognized
|
||||
$message_box[] = $sn . ' - ' . $register_message_1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// --------------------------------------------
|
||||
//Get equipmentid based on rowID
|
||||
// --------------------------------------------
|
||||
$rowID = getrowID($dbname,'rowID','equipment','serialnumber="'.$post_content['sn'].'"');
|
||||
if ($rowID){
|
||||
//check if under warranty
|
||||
$warranty = getrowID($dbname,'rowID','equipment_history','equipmentid="'.$rowID['rowID'].'" && (type="'.$type9.'" || type="'.$type10.'" || type="'.$type11.'" || type="'.$type12.'")');
|
||||
if ($warranty){
|
||||
// --------------------------------------------
|
||||
|
||||
// Check if under warranty
|
||||
$warranty_types = [$type9, $type10, $type11, $type12];
|
||||
$warranty_condition = 'equipmentid="' . $rowID['rowID'] . '" && (type="' . implode('" || type="', $warranty_types) . '")';
|
||||
$warranty = getrowID($dbname, 'rowID', 'equipment_history', $warranty_condition);
|
||||
|
||||
if ($warranty) {
|
||||
// Already under contract
|
||||
// --------------------------------------------
|
||||
//Serialnumber not recognized
|
||||
$message_box[] = $post_content['sn'].' - '.$register_message_2;
|
||||
} else
|
||||
{
|
||||
// --------------------------------------------
|
||||
// Not under warranty
|
||||
// --------------------------------------------
|
||||
$firmware_account_send = 1;
|
||||
//create history
|
||||
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby, updatedby) VALUES (?,?,?,?,?,?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email'],$post_content['email']]);
|
||||
|
||||
//GET PARTNER DETAILS OF EQUIPMENT
|
||||
$partner_equipment = getrowID($dbname,'accounthierarchy','equipment','rowID="'.$rowID['rowID'].'"');
|
||||
$partner_equipment = json_decode($partner_equipment['accounthierarchy']);
|
||||
|
||||
//Setup partnerhierarchy (salesID)
|
||||
$partnerhierarchy =[
|
||||
"salesid"=>$partner_equipment->salesid,
|
||||
"soldto"=>$partner_equipment->soldto
|
||||
];
|
||||
|
||||
//Setup variables for partner
|
||||
$partnername = $post_content['organization'];
|
||||
$partnernotes = 'created based on user registration';
|
||||
$salesID = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
$createdby = 'system';
|
||||
|
||||
//Check if shipto is empty and if empty search partner or create
|
||||
if ($partner_equipment->shipto == ''){
|
||||
$partner_shipto = getrowID($dbname,'partnerID','partner','partnername = "'.$partnername.'" && partnertype="'.$partnertype3.'"');
|
||||
if ($partner_shipto){
|
||||
//Partner exists - Use it
|
||||
$partnerhierarchy['shipto'] = $partner_shipto['partnerID'].'-'.$partnername;
|
||||
} else {
|
||||
//Partner does not exist create
|
||||
$sql = 'INSERT INTO partner (partnertype, partnername,salesID,createdby,status) VALUES (?,?,?,?,?)';
|
||||
$stmt = $pdo2->prepare($sql);
|
||||
$stmt->execute([$partnertype3,$partnername,$salesID,$createdby,'1']);
|
||||
|
||||
//Get rowID of created partner and use it
|
||||
$partner_rowid = $pdo2->lastInsertId();
|
||||
$partnerhierarchy['shipto'] = $partner_rowid.'-'.$partnername;
|
||||
}
|
||||
} else {
|
||||
// Shipto exist use it
|
||||
$partnerhierarchy['shipto'] = $partner_equipment->shipto;
|
||||
}
|
||||
//Check if location is empty and if empty search partner or create
|
||||
if ($partner_equipment->location == ''){
|
||||
$partner_location = getrowID($dbname,'partnerID','partner','partnername = "'.$partnername.'" && partnertype="'.$partnertype4.'"');
|
||||
if ($partner_location){
|
||||
//Partner exists - Use it
|
||||
$partnerhierarchy['location'] = $partner_location['partnerID'].'-'.$partnername;
|
||||
|
||||
} else {
|
||||
//Partner does not exist create
|
||||
$sql = 'INSERT INTO partner (partnertype,partnername,salesID,createdby,status) VALUES (?,?,?,?,?)';
|
||||
$stmt = $pdo2->prepare($sql);
|
||||
$stmt->execute([$partnertype4,$partnername,$salesID,$createdby,'1']);
|
||||
|
||||
//Get rowID of created partner and use it
|
||||
$partner_rowid = $pdo2->lastInsertId();
|
||||
$partnerhierarchy['location'] = $partner_rowid.'-'.$partnername;
|
||||
}
|
||||
} else {
|
||||
// Location exist use it
|
||||
$partnerhierarchy['location'] = $partner_equipment->location;
|
||||
}
|
||||
|
||||
$partnerhierarchy = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// --------------------------------------------
|
||||
// Update equipment record warranty_date, partnerhierarchy, status equipment
|
||||
// --------------------------------------------
|
||||
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ?, updatedby = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$username,$rowID['rowID']]);
|
||||
|
||||
//Add warranty to changelog
|
||||
$warranty_user = $post_content['email'] ?? 'system';
|
||||
changelog($dbname,'equipment',$rowID['rowID'],'Warranty',$warranty_extended,$warranty_user);
|
||||
|
||||
//Serialnumber recognized
|
||||
$message_box[] = $post_content['sn'].' - '.$register_message_3;
|
||||
}
|
||||
$message_box[] = $sn . ' - ' . $register_message_2;
|
||||
$communication_check = 1;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
//Serialnumber not recognized
|
||||
$message_box[] = $post_content['sn'].' - '.$register_message_1;
|
||||
}
|
||||
}
|
||||
|
||||
// Not under warranty - process registration
|
||||
$firmware_account_send = 1;
|
||||
|
||||
// Create history entry
|
||||
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby, updatedby) VALUES (?,?,?,?,?,?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
$rowID['rowID'],
|
||||
$type9,
|
||||
$description,
|
||||
$timestamp,
|
||||
$post_content['email'],
|
||||
$post_content['email']
|
||||
]);
|
||||
|
||||
// Get partner details of equipment
|
||||
$partner_equipment = getrowID($dbname, 'accounthierarchy', 'equipment', 'rowID="' . $rowID['rowID'] . '"');
|
||||
$partner_equipment = json_decode($partner_equipment['accounthierarchy']);
|
||||
|
||||
// Setup partner hierarchy
|
||||
$partnerhierarchy = [
|
||||
"salesid" => $partner_equipment->salesid,
|
||||
"soldto" => $partner_equipment->soldto
|
||||
];
|
||||
|
||||
// Setup variables for partner
|
||||
$partnername = $post_content['organization'];
|
||||
$salesID = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
$createdby = 'system';
|
||||
|
||||
// Helper function to get or create partner
|
||||
$getOrCreatePartner = function($partnertype) use ($dbname, $partnername, $salesID, $createdby, $pdo) {
|
||||
$partner = getrowID($dbname, 'partnerID', 'partner', 'partnername = "' . $partnername . '" && partnertype="' . $partnertype . '"');
|
||||
|
||||
if ($partner) {
|
||||
return $partner['partnerID'] . '-' . $partnername;
|
||||
}
|
||||
|
||||
// Partner does not exist - create
|
||||
$sql = 'INSERT INTO partner (partnertype, partnername, salesID, createdby, status) VALUES (?,?,?,?,?)';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$partnertype, $partnername, $salesID, $createdby, '1']);
|
||||
|
||||
$partner_rowid = $pdo->lastInsertId();
|
||||
return $partner_rowid . '-' . $partnername;
|
||||
};
|
||||
|
||||
// Handle shipto
|
||||
$partnerhierarchy['shipto'] = empty($partner_equipment->shipto)
|
||||
? $getOrCreatePartner($partnertype3)
|
||||
: $partner_equipment->shipto;
|
||||
|
||||
// Handle location
|
||||
$partnerhierarchy['location'] = empty($partner_equipment->location)
|
||||
? $getOrCreatePartner($partnertype4)
|
||||
: $partner_equipment->location;
|
||||
|
||||
$partnerhierarchy_json = json_encode($partnerhierarchy, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// Update equipment record
|
||||
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ?, updatedby = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['4', $warranty_extended, $partnerhierarchy_json, $username, $rowID['rowID']]);
|
||||
|
||||
// Add warranty to changelog
|
||||
$warranty_user = $post_content['email'] ?? 'system';
|
||||
changelog($dbname, 'equipment', $rowID['rowID'], 'Warranty', $warranty_extended, $warranty_user);
|
||||
|
||||
// Serial number recognized
|
||||
$message_box[] = $sn . ' - ' . $register_message_3;
|
||||
$communication_check = 1;
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
// Send generic account to user for software updates
|
||||
|
||||
Reference in New Issue
Block a user