CM91 - RMA update

This commit is contained in:
“VeLiTi”
2024-12-10 11:49:04 +01:00
parent d2cb68ace4
commit b72f329154
16 changed files with 839 additions and 343 deletions

323
rma.php
View File

@@ -6,10 +6,68 @@ if (debug && debug_id == $_SESSION['id']){
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
//__________________________________________
//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_status0_text = '1';
$rma_status1_text = '2';
$rma_status2_text = '3';
$rma_status3_text = '4';
$rma_status4_text = '5';
$rma_sw_version_latest = 'Latest software version';
$rma_servicereport_latest = 'Servicereport created last 7days';
$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 = '';
//__________________________________________
//__________________________________________
//__________________________________________
include_once './assets/functions.php';
include_once './settings/settings.php';
include_once './settings/systemrma.php';
$page = 'rmas';
$page = 'rma';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
@@ -20,154 +78,179 @@ $update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
$view_product = isAllowed('product' ,$_SESSION['profile'],$_SESSION['permission'],'R');
$view_history = isAllowed('history' ,$_SESSION['profile'],$_SESSION['permission'],'C');
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
$rowID = $_GET['rowID'] ?? '';
// Determine the URL
$url = 'index.php?page='.$page.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
if ($rowID !=''){
$url = 'index.php?page=rma&rowID='.$rowID.'';
} else {
$url = 'index.php?page=rmas';
}
// ID param exists, edit an existing product
//CALL TO API
$api_url = '/v2/rma/'.$GET_VALUES;
$api_url = '/v2/rma/rowID='.$_GET['rowID'];
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
$rma = json_decode(json_encode($responses[0]), true);
//GET DETAILS
$rma_header = json_decode($rma['header'],true) ?? '';
$rma_questions = json_decode($rma['questions'],true) ?? '';
//------------------------------
//Variables
//------------------------------
$status_text = 'rma_status'.$rma['status'].'_text';
//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_ct_1;
$success_msg = $message_rma_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_ct_2;
$success_msg = $message_rma_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_ct_3;
$success_msg = $message_rma_3;
}
}
}
if (isset($_GET['download'])){
downloadToExcel('rma',$responses);
}
template_header('RMA', 'rma','manage');
template_header('rma', 'rma' ,'view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-car"></i>
<div class="txt">
<h2>'.$rma_h2.' ('.$query_total.')</h2>
<p>'.$rma_p.'</p>
</div>
</div>
</div>';
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.($rma_h2 ?? 'Return Material Request').' - '.$_GET['rowID'].'</h2>
<a href="index.php?page=rms" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
if ($update_allowed === 1){
$view .= '<a href="index.php?page=rma_manage&rowID='.$_GET['rowID'].'" class="btn">Edit</a>';
}
$view .= '</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="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.'</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>
$view .= '<div class="content-block-wrapper">';
$view .= ' <div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-circle-info"></i></i>'.($rma_information ?? 'RMA details').'
</div>
<div class="order-detail">
<h3>'.$equipment_label3.'</h3>
<p><span class="status id'.$rma['status'].'">'.$$status_text.'</span></p>
</div>
<div class="order-detail">
<h3>'.$equipment_label2.'</h3>
<p>'.$rma_header['serialnumber'].'</p>
</div>
<div class="order-detail">
<h3>'.$product_code.'</h3>
<p>'.(($view_product == 1)? '<a href="index.php?page=product&rowID='.$rma_header['productrowid'].'" class="btn2">'.$rma_header['productcode'].'</a>':'<input type="text" name="header[productcode]" value="'.$rma_header['productcode'].'">').'</p>
</div>
<div class="order-detail">
<h3>'.$product_name.'</h3>
<p>'.(($view_product == 1)? '<a href="index.php?page=product&rowID='.$rma_header['productrowid'].'" class="btn2">'.$rma_header['productname'].'</a>':'<input type="text" name="header[productname]" value="'.$rma_header['productname'].'">').'</p>
</div>
<div class="order-detail">
<h3>'.$equipment_label10.'</h3>
<p><input type="text" name="header[rowID]" value="'.$rma_header['rowID'].'"></p>
</div>
<div class="order-detail">
<h3>'.($rma_sw_version_latest ?? 'Latest software version').'</h3>
<p><select id="sw_version_latest" name="header[sw_version_latest]">
<option value="0" '.($rma_header['sw_version_latest']==0?' selected':'').'>'.$general_no .'</option>
<option value="1" '.($rma_header['sw_version_latest']==1?' selected':'').'>'.$general_yes .'</option>
</select>
</p>
</div>
<div class="order-detail">
<h3>'.($rma_servicereport_latest ?? 'Servicereport created last 7days').'</h3>
<p><select id="servicereport_available" name="header[servicereport_available]">
<option value="0" '.($rma_header['servicereport_available']==0?' selected':'').'>'.$general_no .'</option>
<option value="1" '.($rma_header['servicereport_available']==1?' selected':'').'>'.$general_yes .'</option>
</select>
</p>
</div>
';
$view .='
</div>
';
$view .='<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-user fa-sm"></i>'.$view_asset_partners.'
</div>
<div class="order-detail">
<h3>'.$general_soldto.'</h3>
<p><input type="text" name="header[soldto]" value="'.($rma_header['soldto'] ?? '').'"></p>
</div>
<div class="order-detail">
<h3>'.$general_shipto.'</h3>
<p><input type="text" name="header[shipto]" value="'.($rma_header['shipto'] ?? '').'"></p>
</div>
<div class="order-detail">
<h3>'.$general_location.'</h3>
<p><input type="text" name="header[location]" value="'.($rma_header['location'] ?? '').'"></p>
</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.'" value="" class="responsive-width-100">
<i class="fas fa-search"></i>
</label>
$view .= '</div>';
// -------------------------------
//BUILD TO INPUT FORM BASED ON ARRAY
// ------------------------------
//
$view .='<div class="tabs">
<a href="#" class="active">'.($rma_return_tab1 ?? 'Return reason').'</a>';
if($rma_header['servicereport_available'] == 0 ){
$view .='<a href="#">'.($rma_return_tab2 ?? 'Questions').'</a>';
}
$view .= '</div>';
$view .= '<div class="content-block tab-content active">
<div class="form responsive-width-100">
<div class="order-detail">
<h3>'.($rma_return_reason ?? 'Return reason').'</h3>
<p><select id="return_reason" name="header[return_reason]">
<option value="0" '.($rma_header['return_reason']==0?' selected':'').'>'.$status0_text .'</option>
</select>
</p>
</div>
<div class="order-detail">
<h3>'.($rma_return_reason_note ?? 'Return reason note').'</h3>
<p><textarea id="return_reason_note" name="header[return_reason_note]" placeholder="'.($rma_return_reasons_notes ?? 'Return reason note').'" style="width: 100%;height: 150px;">'.$rma_header['return_reason_note'].'</textarea>
</p>
</div>
</div>
</div>';
$view .= '<div class="content-block tab-content">
<div class="form responsive-width-100">';
$view .= ' </div>
</div>
</form>
</div>
';
</form>';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th class="responsive-hidden">'.$rma_rowID.'</th>
<th>'.$rma_carbrand.'</th>
<th>'.$rma_cartype.'</th>
<th>'.$general_createdby.'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.$message_no_ct.'</td>
</tr>';
}
else {
foreach ($responses as $response){
$view .= '
<tr>
<td class="responsive-hidden">'.$response->rowID.'</td>
<td>'.$response->carbrand.'</td>
<td>'.$response->cartype.'</td>
<td>'.$response->createdby.'</td>
<td><a href="index.php?page=rma&rowID='.$response->rowID.'" class="btn_link">'.$general_view.'</a></td>
</tr>
';
}
}
$view .= '
</tbody>
</table>
</div>
</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;