Files
assetmgt/rmas.php
2024-12-12 15:28:39 +01:00

242 lines
7.7 KiB
PHP

<?php
defined(page_security_key) or exit;
//__________________________________________
//MOVE TO TRANSLATION FILES:
//__________________________________________
$button_create_rma = 'Create RMA';
//RMA
$rmas_h2 = 'Return Material';
$rmas_p = 'View, manage, and search RMA details.';
$rma_h2 = 'Return Material Request';
$message_rma_1 = 'RMA created successfully!';
$message_rma_2 = 'RMA updated successfully!';
$message_rma_3 = 'RMA deleted successfully!';
$message_no_rma = 'There is no RMA';
$rma_search = 'Search RMA...';
$rma_rowID = 'Request number';
$rma_status = 'Status';
$rma_sw_version_latest = 'Latest software version';
$rma_servicereport_latest = 'Servicereport created last 7days';
$rma_status0_text = '1';
$rma_status1_text = '2';
$rma_status2_text = '3';
$rma_status3_text = '4';
$rma_status4_text = '5';
$rma_information = 'RMA information';
$rma_return_reason = 'Return reason';
$rma_return_reason0_text = '';
$rma_return_reason1_text = '';
$rma_return_reason2_text = '';
$rma_return_reason3_text = '';
$rma_return_reason4_text = '';
$rma_return_reason5_text = '';
$rma_return_reasons_notes = 'Return reason notes';
$rma_return_tab1 = 'Return reason';
$rma_return_tab2 = 'Questions';
$rma_question_allowed_label1 = 'Yes';
$rma_question_allowed_label2 = 'No';
$rma_question_header_1 = '';
$rma_question_1 = 'Batteries working?';
$rma_question_2 = 'Button correctly working';
$rma_question_3 = '';
$rma_question_4 = '';
$rma_question_5 = '';
$rma_question_6 = '';
$rma_question_7 = '';
//__________________________________________
//__________________________________________
//__________________________________________
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
include_once './assets/functions.php';
include_once './settings/settings.php';
$page = 'rmas';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
// Determine the URL
$url = 'index.php?page='.$page.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/rma/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
//Return QueryTotal from API
$api_url = '/v2/rma/'.$GET_VALUES.'&totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = null;}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_rma_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_rma_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_rma_3;
}
}
if (isset($_GET['download'])){
downloadToExcel('rma',$responses);
}
template_header('rma', 'rma' ,'view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-car"></i>
<div class="txt">
<h2>'.($rmas_h2 ?? 'Return Material').' ('.$query_total.')</h2>
<p>'.($rmas_p ?? 'View, manage, and search RMA details.').'</p>
</div>
</div>
</div>';
if (isset($success_msg)){
$view .= ' <div class="msg success">
<i class="fas fa-check-circle"></i>
<p>'.$success_msg.'</p>
<i class="fas fa-times"></i>
</div>';
}
$view .= '
<div class="content-header responsive-flex-column pad-top-5">';
if ($create_allowed ===1){
$view .= '<a href="index.php?page=rma_manage" class="btn">'.($button_create_rma ?? 'Create RMA').'</a>';
}
$view .= '
<form action="" method="get">
<input type="hidden" name="page" value="rma">
<div class="filters">
<a href="#"><i class="fa-solid fa-filter"></i>'.$general_filters.'</a>
<div class="list">
<select name="status">
<option value="" disabled selected>Active</option>
<option value="0">'.$disabled.'</option>
<option value="1">'.$enabled.'</option>
</select>
<button type="submit">'.$button_apply.'</button>
</div>
</div>';
//SHOW DOWNLOAD TO EXCELL OPTION ONLY TO ADMIN USERS
if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){
$view .='<div class="filters">
<a href="index.php?page=rma&download="><i class="fa-solid fa-download"></i></a>
</div>';
}
$view .= '<div class="search">
<label for="search">
<input id="search" type="text" name="search" placeholder="'.($rma_search ?? 'Search RMA...').'" value="" class="responsive-width-100">
<i class="fas fa-search"></i>
</label>
</div>
</form>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th class="responsive-hidden">'.($rma_rowID ?? 'Request number').'</th>
<th>'.($rma_status ?? 'Status').'</th>
<th>'.getRelativeTime($general_created).'</th>
<th>'.$general_createdby.'</th>
<th>'.getRelativeTime($general_updated).'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.($message_no_rma ?? 'There is no RMA').'</td>
</tr>';
}
else {
foreach ($responses as $response){
//------------------------------
//Variables
//------------------------------
$status_text = 'rma_status'.$response['status'].'_text';
$view .= '
<tr>
<td class="responsive-hidden">'.$response['rowID'].'</td>
<td>'.$$status_text.'</td>
<td>'.$response['created'].'</td>
<td>'.$response['createdby'].'</td>
<td>'.$response['updated'].'</td>
<td><a href="index.php?page=rma&rowID='.$response['rowID'].'" class="btn_link">'.$general_view.'</a></td>
</tr>
';
}
}
$view .= '
</tbody>
</table>
</div>
</div>
';
$view.='<div class="pagination">';
if ($pagination_page > 1) {
$page = $pagination_page-1;
$view .= '<a href="'.$url.'&p=1">'.$general_first.'</a>';
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_prev.'</a>';
}
$totals = ceil($query_total / $page_rows_rma) == 0 ? 1 : ceil($query_total / $page_rows_rma);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_rma < $query_total){
$page = $pagination_page+1;
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_next.'</a>';
$view .= '<a href="'.$url.'&p='.$totals.'">'.$general_last.'</a>';
}
$view .= '</div>';
//OUTPUT
echo $view;
template_footer();
?>