CMXX - Pricelists
This commit is contained in:
118
api/v2/get/pricelists.php
Normal file
118
api/v2/get/pricelists.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Pricelists
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE accounthierarchy like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'name') {
|
||||
//build up search
|
||||
$clause .= ' AND name like :'.$v[0];
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
//Define Query
|
||||
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM pricelists '.$whereclause.'';
|
||||
}
|
||||
else {
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM pricelists '.$whereclause.' LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':condition')){
|
||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
if ($key == 'search'){
|
||||
$search_value = '%'.$value.'%';
|
||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add paging details
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_pricelists, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_products', $page_rows_pricelists, PDO::PARAM_INT);
|
||||
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
118
api/v2/get/pricelists_items.php
Normal file
118
api/v2/get/pricelists_items.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Pricelists items
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE accounthierarchy like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND product_ID like :'.$v[0];
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
//Define Query
|
||||
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM pricelists_items '.$whereclause.'';
|
||||
}
|
||||
else {
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM pricelists_items '.$whereclause.' LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':condition')){
|
||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
if ($key == 'search'){
|
||||
$search_value = '%'.$value.'%';
|
||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add paging details
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_pricelists, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_products', $page_rows_pricelists, PDO::PARAM_INT);
|
||||
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
@@ -98,7 +98,7 @@ if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_products, PDO::PARAM_INT);
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_translations, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_products', $page_rows_translations, PDO::PARAM_INT);
|
||||
|
||||
//Excute Query
|
||||
|
||||
105
api/v2/post/pricelists.php
Normal file
105
api/v2/post/pricelists.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Pricelists
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//CONTENT FROM API (POST)
|
||||
$post_content = json_decode($input,true);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = ' AND accounthierarchy like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
//SET PARAMETERS FOR QUERY
|
||||
$id = $post_content['rowID'] ?? ''; //check for rowID
|
||||
$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT
|
||||
if (isset($post_content['delete'])){$command = 'delete';} //change command to delete
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
//CREATE EMPTY STRINGS
|
||||
$clause = '';
|
||||
$clause_insert ='';
|
||||
$input_insert = '';
|
||||
|
||||
//BUILD UP PARTNERHIERARCHY FROM USER
|
||||
$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
|
||||
if ($command == 'update'){
|
||||
$post_content['updatedby'] = $username ;
|
||||
|
||||
}
|
||||
elseif ($command == 'insert'){
|
||||
$post_content['createdby'] = $username;
|
||||
$post_content['accounthierarchy'] = $partner_product;
|
||||
}
|
||||
else {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
//CREAT NEW ARRAY AND MAP TO CLAUSE
|
||||
if(isset($post_content) && $post_content!=''){
|
||||
foreach ($post_content as $key => $var){
|
||||
if ($key == 'submit' || $key == 'rowID'){
|
||||
//do nothing
|
||||
}
|
||||
else {
|
||||
$criterias[$key] = $var;
|
||||
$clause .= ' , '.$key.' = ?';
|
||||
$clause_insert .= ' , '.$key.'';
|
||||
$input_insert .= ', ?'; // ? for each insert item
|
||||
$execute_input[]= $var; // Build array for input
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CLEAN UP INPUT
|
||||
$clause = substr($clause, 2); //Clean clause - remove first comma
|
||||
$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma
|
||||
$input_insert = substr($input_insert, 1); //Clean clause - remove first comma
|
||||
|
||||
//QUERY AND VERIFY ALLOWED
|
||||
if ($command == 'update' && isAllowed('pricelists_manage',$profile,$permission,'U') === 1){
|
||||
$sql = 'UPDATE pricelists SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
||||
$execute_input[] = $id;
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($execute_input);
|
||||
}
|
||||
elseif ($command == 'insert' && isAllowed('pricelists_manage',$profile,$permission,'C') === 1){
|
||||
$sql = 'INSERT INTO pricelists('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($execute_input);
|
||||
// Return ID
|
||||
echo json_encode(array('rowID'=> $pdo->lastInsertId()));
|
||||
}
|
||||
elseif ($command == 'delete' && isAllowed('pricelists_manage',$profile,$permission,'D') === 1){
|
||||
$stmt = $pdo->prepare('DELETE FROM pricelists WHERE rowID = ? '.$whereclause.'');
|
||||
$stmt->execute([ $id ]);
|
||||
|
||||
//Add deletion to changelog
|
||||
changelog($dbname,'pricelists',$id,'Delete','Delete',$username);
|
||||
} else
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
?>
|
||||
103
api/v2/post/pricelists_items.php
Normal file
103
api/v2/post/pricelists_items.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Pricelists items
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//CONTENT FROM API (POST)
|
||||
$post_content = json_decode($input,true);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = ' AND accounthierarchy like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
//SET PARAMETERS FOR QUERY
|
||||
$id = $post_content['rowID'] ?? ''; //check for rowID
|
||||
$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT
|
||||
if (isset($post_content['delete'])){$command = 'delete';} //change command to delete
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
//CREATE EMPTY STRINGS
|
||||
$clause = '';
|
||||
$clause_insert ='';
|
||||
$input_insert = '';
|
||||
|
||||
//BUILD UP PARTNERHIERARCHY FROM USER
|
||||
$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
|
||||
if ($command == 'update'){
|
||||
$post_content['updatedby'] = $username ;
|
||||
|
||||
}
|
||||
elseif ($command == 'insert'){
|
||||
$post_content['createdby'] = $username;
|
||||
$post_content['accounthierarchy'] = $partner_product;
|
||||
}
|
||||
else {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
//CREAT NEW ARRAY AND MAP TO CLAUSE
|
||||
if(isset($post_content) && $post_content!=''){
|
||||
foreach ($post_content as $key => $var){
|
||||
if ($key == 'submit' || $key == 'update' || $key == 'add' ||$key == 'rowID'){
|
||||
//do nothing
|
||||
}
|
||||
else {
|
||||
$criterias[$key] = $var;
|
||||
$clause .= ' , '.$key.' = ?';
|
||||
$clause_insert .= ' , '.$key.'';
|
||||
$input_insert .= ', ?'; // ? for each insert item
|
||||
$execute_input[]= $var; // Build array for input
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CLEAN UP INPUT
|
||||
$clause = substr($clause, 2); //Clean clause - remove first comma
|
||||
$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma
|
||||
$input_insert = substr($input_insert, 1); //Clean clause - remove first comma
|
||||
|
||||
//QUERY AND VERIFY ALLOWED
|
||||
if ($command == 'update' && isAllowed('pricelists_manage',$profile,$permission,'U') === 1){
|
||||
$sql = 'UPDATE pricelists_items SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
||||
$execute_input[] = $id;
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($execute_input);
|
||||
}
|
||||
elseif ($command == 'insert' && isAllowed('pricelists_manage',$profile,$permission,'C') === 1){
|
||||
$sql = 'INSERT INTO pricelists_items ('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($execute_input);
|
||||
}
|
||||
elseif ($command == 'delete' && isAllowed('pricelists_manage',$profile,$permission,'D') === 1){
|
||||
$stmt = $pdo->prepare('DELETE FROM pricelists_items WHERE rowID = ? '.$whereclause.'');
|
||||
$stmt->execute([ $id ]);
|
||||
|
||||
//Add deletion to changelog
|
||||
changelog($dbname,'pricelists_items',$id,'Delete','Delete',$username);
|
||||
} else
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
?>
|
||||
154
pricelists.php
Normal file
154
pricelists.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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 = $_SESSION['origin'] = 'pricelists';
|
||||
|
||||
//Check if allowed
|
||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
//GET PARAMETERS
|
||||
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
|
||||
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
|
||||
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
|
||||
|
||||
// Determine the URL
|
||||
$url = 'index.php?page=pricelists'.$status.$search;
|
||||
//GET Details from URL
|
||||
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
||||
//CALL TO API
|
||||
$api_url = '/v2/pricelists/'.$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/pricelists/'.$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_tv_1;
|
||||
}
|
||||
if ($_GET['success_msg'] == 2) {
|
||||
$success_msg = $message_tv_2;
|
||||
}
|
||||
if ($_GET['success_msg'] == 3) {
|
||||
$success_msg = $message_tv_3;
|
||||
}
|
||||
}
|
||||
|
||||
template_header('Pricelists', 'pricelists','view');
|
||||
$view = '
|
||||
<div class="content-title">
|
||||
<div class="title">
|
||||
<i class="fa-solid fa-coins"></i>
|
||||
<div class="txt">
|
||||
<h2>'.($pricelists_h2 ?? '').' ('.$query_total.')</h2>
|
||||
<p>'.($pricelists_p ?? '').'</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">
|
||||
<a href="index.php?page=pricelists_manage" class="btn">'.($button_create_pricelist ?? '').'</a>
|
||||
<form action="" method="get">
|
||||
<input type="hidden" name="page" value="pricelists">
|
||||
<div class="search">
|
||||
<label for="search">
|
||||
<input id="search" type="text" name="search" placeholder="'.($pricelists_search ?? '').'" 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>'.($pricelists_rowID ?? 'rowID').'</th>
|
||||
th>'.($pricelists_status ?? 'status').'</th>
|
||||
<th>'.($pricelists_name ?? 'name').'</th>
|
||||
<th class="responsive-hidden">'.$general_created.'</th>
|
||||
<th>'.$general_actions.'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
';
|
||||
|
||||
if (empty($responses)){
|
||||
|
||||
$view .= '
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:center;">'.($message_no_pricelists ?? '').'</td>
|
||||
</tr>';
|
||||
}
|
||||
else {
|
||||
foreach ($responses as $response){
|
||||
$view .= '
|
||||
<tr>
|
||||
<td>'.$response['rowID'].'</td>
|
||||
<td>'.${'general_status_'.$response['status']}.'</td>
|
||||
<td>'.$response['name'].'</td>
|
||||
<td class="responsive-hidden">'.getRelativeTime($response['created']).'</td>
|
||||
<td><a href="index.php?page=pricelists_manage&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_pricelists) == 0 ? 1 : ceil($query_total / $page_rows_pricelists);
|
||||
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
|
||||
if ($pagination_page * $page_rows_pricelists < $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();
|
||||
?>
|
||||
280
pricelists_manage.php
Normal file
280
pricelists_manage.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
defined(page_security_key) or exit;
|
||||
|
||||
$page = 'pricelists_manage';
|
||||
//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');
|
||||
|
||||
// Default input product values
|
||||
$text_variable = [
|
||||
'rowID' => '',
|
||||
'variable' => '',
|
||||
'created' => '',
|
||||
'createdby' => '',
|
||||
'updated' => '',
|
||||
'updatedby' => '',
|
||||
'accounthierarchy' => ''
|
||||
];
|
||||
|
||||
if (isset($_GET['rowID'])) {
|
||||
//CALL TO API
|
||||
$api_url = '/v2/pricelists/rowID='.$_GET['rowID'];
|
||||
$responses = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
|
||||
|
||||
$pricelists = json_decode(json_encode($responses[0]), true);
|
||||
|
||||
//CALL TO API FOR RELATED pricelists
|
||||
$api_url = '/v2/pricelists_items/pricelist_ID='.$_GET['rowID'];
|
||||
$pricelists_items = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($pricelists_items)){$pricelists_items = json_decode($pricelists_items,true);}else{$pricelists_items = null;}
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['submit'])) {
|
||||
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
$responses = ioServer('/v2/pricelists', $payload);
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=pricelists&success_msg=2');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['add'])) {
|
||||
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
$responses = ioServer('/v2/pricelists_items', $payload);
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
generateLanguageFile($_POST['language_key'],$_SESSION['userkey']);
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$_GET['rowID'].'');
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
if (isset($_POST['update']) && isset($_POST['item'])) {
|
||||
//Indicator if update has errors
|
||||
$NOK_error = 0;
|
||||
|
||||
//RUN through all POST items
|
||||
foreach ($_POST['item'] as $attr){
|
||||
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($attr, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//API call
|
||||
$responses = ioServer('/v2/pricelists_items', $payload);
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
//NOT correct exit procedure
|
||||
$NOK_error++;
|
||||
exit;
|
||||
} else {
|
||||
$attr_language = $attr['language_key'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($NOK_error == 0){
|
||||
//NO errors generatelanguagefile
|
||||
generateLanguageFile($attr_language,$_SESSION['userkey']);
|
||||
}
|
||||
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$_GET['rowID'].'');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete_allowed === 1){
|
||||
if (isset($_POST['delete'])) {
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
$responses = ioServer('/v2/pricelists', $payload);
|
||||
// Redirect and delete product
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=pricelists&success_msg=3');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create a new variable
|
||||
if (isset($_POST['submit']) && $create_allowed === 1) {
|
||||
//GET ALL POST DATA
|
||||
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
$responses = ioServer('/v2/pricelists', $payload);
|
||||
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
//GET ROWID OF CREATED ITEM
|
||||
$variable_rowID = json_decode($responses,true);
|
||||
header('Location: index.php?page=pricelists_manage&rowID='.$variable_rowID['rowID'].'');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
//EMPTY VIEW
|
||||
$view = '';
|
||||
|
||||
// Handle success messages
|
||||
if (isset($_GET['success_msg'])) {
|
||||
if ($_GET['success_msg'] == 0) {
|
||||
$success_msg = $error_msg_0;
|
||||
}
|
||||
}
|
||||
|
||||
template_header('Pricelists', 'pricelists', 'manage');
|
||||
|
||||
if (isset($success_msg)){
|
||||
$view .= ' <div class="msg error">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
<p>'.$success_msg.'</p>
|
||||
<i class="fas fa-times"></i>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$view .='
|
||||
<form action="" method="post">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.($text_variables_h2 ?? '').'</h2>
|
||||
<a href="index.php?page=pricelists" 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 pricelist?\')">';
|
||||
}
|
||||
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="#">'.$tab3.'</a>
|
||||
</div>
|
||||
';
|
||||
|
||||
//Define Service and User enabled
|
||||
$view .= '<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="variable">'.($text_variable_name ?? '').'</label>
|
||||
<input id="variable" type="text" name="variable" placeholder="'.($text_variable_name ?? '').'" value="'.$text_variable['variable'].'" pattern="^\S+$" required">
|
||||
<input type="hidden" name="rowID" value="'.$text_variable['rowID'].'" readonly>
|
||||
';
|
||||
|
||||
$view .= '</div>
|
||||
</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="'.getRelativeTime($text_variable['created']).'" readonly>
|
||||
<label for="">'.$general_createdby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$text_variable['createdby'].'" readonly>
|
||||
<label for="productcode">'.$general_updated.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.getRelativeTime($text_variable['updated']).'" readonly>
|
||||
<label for="productcode">'.$general_updatedby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$text_variable['updatedby'].'" readonly>
|
||||
</div>
|
||||
</div>';
|
||||
$view .= '</form>';
|
||||
|
||||
|
||||
$view .= '
|
||||
<div class="content-block">
|
||||
<button class="btn2" onClick="addNewRow()" > + </button>
|
||||
<form action="" id="update" method="post"></form>
|
||||
<form action="" id="new" method="post"></form>
|
||||
|
||||
<div class="table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>'.($text_variable_translation_languagekey ?? '').'</th>
|
||||
<th>'.($text_variable_translation_translation ?? '').'</th>
|
||||
<th>'.$general_created.'</th>
|
||||
<th>'.$general_actions.'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody">
|
||||
';
|
||||
|
||||
if (empty($pricelists_items)){
|
||||
$view .= '
|
||||
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:center;">'.($message_no_text_variables ?? '').'</td>
|
||||
</tr>';
|
||||
}
|
||||
else {
|
||||
foreach ($pricelists_items as $pricelists_item){
|
||||
$view .= '
|
||||
|
||||
<tr>
|
||||
<td><input form="update" type="text" name="item['.$pricelists_item['rowID'].'][name]" placeholder="'.($text_variable_translation_translation ?? '').'" value="'.$pricelists_item['name'].'"></td>
|
||||
<td>'.getRelativeTime($pricelists_item['created']).'</td>
|
||||
<td><input form="update" type="submit" name="update" value="&" class="btn"></td>
|
||||
<input form="update" type="hidden" name="item['.$pricelists_item['rowID'].'][rowID]" value="'.$pricelists_item['rowID'].'" readonly>
|
||||
<input form="update" type="hidden" name="item['.$pricelists_item['rowID'].'][pricelist_ID]" value="'.$pricelists['rowID'].'" readonly>
|
||||
</tr>
|
||||
</form>';
|
||||
}
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
let rowCounter = 1;
|
||||
|
||||
function addNewRow() {
|
||||
rowCounter++;
|
||||
const tbody = document.getElementById(\'tableBody\');
|
||||
const newRow = document.createElement(\'tr\');
|
||||
|
||||
newRow.innerHTML = `
|
||||
<td><input form="new" type="text" name="name" placeholder="'.($text_variable_translation_translation ?? '').'" value=""></td>
|
||||
<td><input form="new" type="submit" name="add" value="+" class="btn"></td>
|
||||
<input form="new" type="hidden" name="rowID" value="" readonly>
|
||||
<input form="new" type="hidden" name="pricelist_ID" value="'.$pricelists_item['rowID'].'" readonly>
|
||||
`;
|
||||
|
||||
tbody.appendChild(newRow);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
template_footer()
|
||||
?>
|
||||
@@ -13,7 +13,7 @@ $main_menu = array ('dashboard','sales','buildtool','cartests','marketing','equi
|
||||
//Sub menus
|
||||
$equipments_sub = array('equipments','servicereports','rmas','histories','firmwaretool','equipments_mass_update');
|
||||
$sales_sub = array('accounts','contracts');
|
||||
$products_sub = array('products','products_attributes');
|
||||
$products_sub = array('products','products_attributes','pricelists');
|
||||
$admin_sub = array('users','communications','partners','media');
|
||||
$reporting_sub = array('report_build','report_contracts_billing','report_healthindex','report_usage');
|
||||
$settings_sub = array('config','translations','logfile','maintenance','profiles');
|
||||
@@ -74,6 +74,12 @@ $urls = array(
|
||||
"icon" => "fas fa-box-open",
|
||||
"name" => "menu_products_attributes"
|
||||
),
|
||||
"pricelists" => array(
|
||||
"url" => "pricelists",
|
||||
"selected" => "pricelists",
|
||||
"icon" => "fa-solid fa-coins",
|
||||
"name" => "menu_pricelists"
|
||||
),
|
||||
"sales" => array(
|
||||
"url" => "contracts",
|
||||
"selected" => "contracts",
|
||||
@@ -233,6 +239,7 @@ $page_rows_rma = 25; // list RMA
|
||||
$page_rows_translations = 50; //list translation variables
|
||||
$page_rows_products_attributes = 50; //list product attributes
|
||||
$page_rows_media = 25; // list media
|
||||
$page_rows_pricelists = 50;//pricelists
|
||||
|
||||
//------------------------------------------
|
||||
// Languages supported
|
||||
|
||||
@@ -43,6 +43,8 @@ $all_views = [
|
||||
"products_attributes_manage",
|
||||
"product",
|
||||
"product_manage",
|
||||
"pricelists_manage",
|
||||
"product_manage",
|
||||
"servicereports",
|
||||
"servicereport",
|
||||
"admin",
|
||||
|
||||
Reference in New Issue
Block a user