CM89 - contract changes
This commit is contained in:
403
contract.php
403
contract.php
@@ -1,223 +1,258 @@
|
||||
<?php
|
||||
defined(page_security_key) or exit;
|
||||
|
||||
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';
|
||||
|
||||
//SET ORIGIN FOR NAVIGATION
|
||||
$prev_page = $_SESSION['prev_origin'] ?? '';
|
||||
$page = 'contract';
|
||||
|
||||
//create backbutton to prev_origin
|
||||
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">'.$button_back.'</a>':'';
|
||||
|
||||
//Check if allowed
|
||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
//GET PARAMETERS && STORE in SESSION for FURTHER USE/NAVIGATION
|
||||
$pagination_page = $_SESSION['p'] = isset($_GET['p']) ? $_GET['p'] : 1;
|
||||
|
||||
//PAGE Security
|
||||
$page_manage = 'contract_manage';
|
||||
$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');
|
||||
|
||||
// Default input product values
|
||||
$contract = [
|
||||
'rowID' => '',
|
||||
'type' => '',
|
||||
'status' => '',
|
||||
'accountID' => '',
|
||||
'start_date' => '',
|
||||
'duration' => '',
|
||||
'service_count' => '',
|
||||
'contract_details' => '',
|
||||
'created' => '',
|
||||
'createdby' => '',
|
||||
'billing_plan' => '',
|
||||
'pricing' => '',
|
||||
'reference' => '',
|
||||
'servicetool' => '',
|
||||
'assigned_users' => []
|
||||
];
|
||||
$update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'U');
|
||||
$delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D');
|
||||
$create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
|
||||
//GET Details from URL
|
||||
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
||||
$contract_ID = $_GET['rowID'] ?? '';
|
||||
|
||||
if ($contract_ID !=''){
|
||||
$url = 'index.php?page=contract&rowID='.$contract_ID.'';
|
||||
} else {
|
||||
$url = 'index.php?page=contracts';
|
||||
}
|
||||
//CALL TO API FOR General information
|
||||
$api_url = '/v1/contracts/rowID='.$contract_ID;;
|
||||
$responses = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
||||
$responses = $responses[0];
|
||||
|
||||
if (isset($_GET['rowID'])) {
|
||||
//CALL TO API
|
||||
$api_url = '/v1/contracts/rowID='.$contract_ID;
|
||||
$responses = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
||||
|
||||
$contract = json_decode(json_encode($responses[0]), true);
|
||||
//------------------------------
|
||||
//Variables
|
||||
//------------------------------
|
||||
$contract_status_text = 'contract_status'.$responses->status ?? '';
|
||||
$contract_type_text = 'contract_type'.$responses->type ?? '';
|
||||
$servicetools = json_decode($responses->servicetool,true) ?? '';
|
||||
$assigned_users = json_decode($responses->assigned_users,true) ?? '';
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['submit'])) {
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//Partnerdata
|
||||
$partner_data = json_decode($responses->accounthierarchy);
|
||||
$salesid = getPartnerName($partner_data->salesid) ?? $not_specified;
|
||||
$soldto = getPartnerName($partner_data->soldto) ?? '-';
|
||||
$shipto = getPartnerName($partner_data->shipto) ?? '-';
|
||||
$location = getPartnerName($partner_data->location) ?? '-';
|
||||
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
|
||||
//API call
|
||||
$responses = ioServer('/v1/contracts', $payload);
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=contracts&success_msg=2');
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
// Handle success messages
|
||||
if (isset($_GET['success_msg'])) {
|
||||
if ($_GET['success_msg'] == 1) {
|
||||
$success_msg = $message_contract_1;
|
||||
}
|
||||
|
||||
if ($delete_allowed === 1){
|
||||
if (isset($_POST['delete'])) {
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
//API call
|
||||
$responses = ioServer('/v1/contracts', $payload);
|
||||
// Redirect and delete product
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=contracts&success_msg=3');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($_GET['success_msg'] == 2) {
|
||||
$success_msg = $message_contract_2;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create a new product
|
||||
if (isset($_POST['submit']) && $create_allowed === 1) {
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
//API call
|
||||
$responses = ioServer('/v1/contracts', $payload);
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=contracts&success_msg=1');
|
||||
exit;
|
||||
}
|
||||
if ($_GET['success_msg'] == 3) {
|
||||
$success_msg = $message_contract_3;
|
||||
}
|
||||
}
|
||||
|
||||
template_header('Contract', 'contract', 'manage');
|
||||
|
||||
$view ='
|
||||
<form action="" method="post">
|
||||
template_header('Contract', 'contract', 'view');
|
||||
$view = '
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.$contract_h2.'</h2>
|
||||
<a href="index.php?page=contracts" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
<h2 class="responsive-width-100">'.$responses->rowID.'</h2>
|
||||
<a href="index.php?page='.$_SESSION['origin'].'&p='.$_SESSION['p'].'" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
';
|
||||
|
||||
if ($delete_allowed === 1){
|
||||
$view .= '<input type="submit" name="delete" value="Delete" class="btn red mar-right-2" onclick="return confirm(\'Are you sure you want to delete this contract?\')">';
|
||||
|
||||
//------------------------------------
|
||||
//
|
||||
//------------------------------------
|
||||
if ($update_allowed_edit === 1){
|
||||
$view .= '<a href="index.php?page=contract_manage&rowID='.$_GET['rowID'].'" class="btn">Edit</a>';
|
||||
}
|
||||
if ($update_allowed === 1){
|
||||
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
||||
}
|
||||
|
||||
|
||||
$view .= '</div>';
|
||||
|
||||
$view .= '<div class="tabs">
|
||||
<a href="#" class="active">'.$tab1 .'</a>
|
||||
<a href="#">'.$tab2.'</a>
|
||||
<a href="#">'.$tab3.'</a>
|
||||
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-block-wrapper">';
|
||||
|
||||
$view .= ' <div class="content-block order-details">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-circle-info"></i></i>'.($product_data ?? '').'
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_id.'</h3>
|
||||
<p>'.$responses->rowID.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_status.'</h3>
|
||||
<p><span class="status id'.$responses->status.'">'.$$contract_status_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_type.'</h3>
|
||||
<p><span class="status id'.$responses->type.'">'.$$contract_type_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_start_date.'</h3>
|
||||
<p>'.$responses->start_date.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_duration.'</h3>
|
||||
<p>'.$responses->duration.'</p>
|
||||
</div>
|
||||
';
|
||||
if ($responses->duration !='' && $responses->start_date !=''){
|
||||
$date = date('Y-m-d', strtotime('+'.$responses->duration.' months', strtotime($responses->start_date)));
|
||||
|
||||
$view .= '
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_end_date.'</h3>
|
||||
<p>'.$date.'</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_salesid.'</h3>
|
||||
<p>'.$salesid.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$general_soldto.'</h3>
|
||||
<p>'.$soldto.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$general_shipto.'</h3>
|
||||
<p>'.$shipto.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$general_location.'</h3>
|
||||
<p>'.$location.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_reference.'</h3>
|
||||
<p>'.$responses->reference.'</p>
|
||||
</div>
|
||||
|
||||
</div>';
|
||||
$view .= '</div>';
|
||||
|
||||
|
||||
//Usageview
|
||||
|
||||
//get all assigned serialnumbers
|
||||
$url_input = '';
|
||||
foreach($servicetools as $service_tool){
|
||||
$url_input .= $service_tool.',';
|
||||
}
|
||||
|
||||
//Return report_usage_servicereports
|
||||
$api_url = '/v1/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).'/contract_usage_servicereports';
|
||||
$contract_usage_servicereports = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($contract_usage_servicereports)){$contract_usage_servicereports = decode_payload($contract_usage_servicereports);}else{$contract_usage_servicereports = null;}
|
||||
|
||||
$service_events = usageView(json_decode(json_encode($contract_usage_servicereports),true));
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$menu_service_reports.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
'.$service_events.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .='<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_status.'</label>
|
||||
<select name="status">
|
||||
<option value="0" '.($contract['status']==0?' selected':'').'>'.$contract_status0.'</option>
|
||||
<option value="1" '.($contract['status']==1?' selected':'').'>'.$contract_status1.'</option>
|
||||
<option value="2" '.($contract['status']==2?' selected':'').'>'.$contract_status2.'</option>
|
||||
</select>
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$contract_assigned_users.'
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_type.'</label>
|
||||
<select name="type">
|
||||
<option value="0" '.($contract['type']==0?' selected':'').'>'.$contract_type0.'</option>
|
||||
<option value="1" '.($contract['type']==1?' selected':'').'>'.$contract_type1.'</option>
|
||||
<option value="2" '.($contract['type']==2?' selected':'').'>'.$contract_type2.'</option>
|
||||
</select>
|
||||
<div class="table order-table">
|
||||
<table class="sortable">
|
||||
<tbody>';
|
||||
//Check for assigned users
|
||||
foreach ($assigned_users as $user){
|
||||
$view .= '<tr><td>'.$user.'</td><tr>';
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_start_date.'</label>
|
||||
<input type="date" name="start_date" value="'.$contract['start_date'].'" required>
|
||||
</div>';
|
||||
|
||||
//Define end_date based on duration
|
||||
if ($contract['duration'] !='' && $contract['start_date'] !=''){
|
||||
$date = date('Y-m-d', strtotime('+'.$contract['duration'].' months', strtotime($contract['start_date'])));
|
||||
|
||||
$view .= '<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_end_date.'</label>
|
||||
<input type="date" value="'.$date.'" readonly>
|
||||
</div>';
|
||||
}
|
||||
$view .= '<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_duration.'</label>
|
||||
<input type="number" name="duration" value="'.$contract['duration'].'" required>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_reference.'</label>
|
||||
<input type="text" name="reference" value="'.$contract['reference'].'" >
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
|
||||
|
||||
//GET PARTNER DROPDOWN
|
||||
$soldto_dropdown = listAccounts('accountID',$_SESSION['permission'],$contract['accountID']);
|
||||
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_account.'</label>
|
||||
'.$soldto_dropdown.'
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_servicetool.'</label>
|
||||
<input id="name" type="text" name="servicetool" placeholder="'.$contract_servicetool.'" value="'.$contract['servicetool'].'">
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_assigned_users.'</label>';
|
||||
|
||||
|
||||
//Check for assigned users
|
||||
$assigned_users = (is_string($contract['assigned_users']))? json_decode($contract['assigned_users']) : '';
|
||||
|
||||
if (is_array($assigned_users)) {
|
||||
foreach ($assigned_users as $user){
|
||||
$view .= '<input id="assigned_users" type="text" name="assigned_users" placeholder="'.$contract_assigned_users.'" value="'.$user.'">';
|
||||
}
|
||||
} else{
|
||||
$view .= '<input id="assigned_users" type="text" name="assigned_users[]" placeholder="'.$contract_assigned_users.'" value="">';
|
||||
}
|
||||
|
||||
$view .=' </div>
|
||||
<button type="button" class="btn" onclick="addField(\'assigned_users\',\'assigned_users[]\');"> + </button> <small>'.$contract_assigned_users_add.'</small>
|
||||
</div>';
|
||||
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$general_created.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$contract['created'].'" readonly>
|
||||
<label for="">'.$general_createdby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$contract['createdby'].'" readonly>
|
||||
<input id="name" type="hidden" name="rowID" value="'.$contract['rowID'].'" readonly>
|
||||
</div>
|
||||
</div>';
|
||||
';
|
||||
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'. $contract_servicetool.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table class="sortable">
|
||||
<tbody>';
|
||||
//Check for assigned tools
|
||||
foreach ($servicetools as $tools){
|
||||
$view .= '<tr><td>'.$tools.'</td><tr>';
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$tab3.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_created.'</td>
|
||||
<td>'.$responses->created.'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_createdby.'</td>
|
||||
<td>'.$responses->createdby.'</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '</form>';
|
||||
$view .='</div>';
|
||||
|
||||
//OUTPUT
|
||||
echo $view;
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
template_footer()
|
||||
|
||||
template_footer()?>
|
||||
?>
|
||||
Reference in New Issue
Block a user