From 22d46c74df463df7ec20b62df38bf5289fbdd030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Mon, 2 Dec 2024 17:28:13 +0100 Subject: [PATCH] CM91 - RMA - 1st commit --- api/v2/get/rma.php | 141 +++++++++++++++++++++++++++++ api/v2/get/rma_history.php | 141 +++++++++++++++++++++++++++++ api/v2/post/rma.php | 91 +++++++++++++++++++ api/v2/post/rma_history.php | 90 +++++++++++++++++++ rma.php | 175 ++++++++++++++++++++++++++++++++++++ settings/settingsmenu.php | 1 + settings/settingsviews.php | 5 ++ 7 files changed, 644 insertions(+) create mode 100644 api/v2/get/rma.php create mode 100644 api/v2/get/rma_history.php create mode 100644 api/v2/post/rma.php create mode 100644 api/v2/post/rma_history.php create mode 100644 rma.php diff --git a/api/v2/get/rma.php b/api/v2/get/rma.php new file mode 100644 index 0000000..c54f6b7 --- /dev/null +++ b/api/v2/get/rma.php @@ -0,0 +1,141 @@ +soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} + +//default whereclause +$whereclause = ''; + +switch ($permission) { + case '4': + $whereclause = ''; + break; + case '3': + $whereclause = ''; + break; + case '2': + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; + $whereclause = 'WHERE accounthierarchy like :condition '; + break; + default: + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%'; + $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] =='download' || $v[0] =='list'|| $v[0] =='success_msg'){ + //do nothing + } + elseif ($v[0] == 'search') { + //build up search + $clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].' OR rowID 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 rma '.$whereclause; +} + +elseif(isset($criterias['download']) && $criterias['download'] ==''){ + //Request for total rows + $sql = 'SELECT * FROM rma '.$whereclause; +} +else { + //SQL for Paging + $sql = "SELECT * from rma $whereclause ORDER BY rowID DESC 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); + } + } + } +} + +//------------------------------------------ +// Debuglog +//------------------------------------------ +if (debug){ + $message = $date.';'.$sql.';'.$username; + debuglog($message); +} + +//Add paging details +if(isset($criterias['totals']) && $criterias['totals']==''){ + $stmt->execute(); + $messages = $stmt->fetch(); + $messages = $messages[0]; +} +elseif (isset($criterias['download']) && $criterias['download'] ==''){ + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +} +else { + $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; + $stmt->bindValue('page', ($current_page - 1) * $page_rows_rma, PDO::PARAM_INT); + $stmt->bindValue('num_products', $page_rows_rma, 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; + +?> \ No newline at end of file diff --git a/api/v2/get/rma_history.php b/api/v2/get/rma_history.php new file mode 100644 index 0000000..e16196f --- /dev/null +++ b/api/v2/get/rma_history.php @@ -0,0 +1,141 @@ +soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} + +//default whereclause +$whereclause = ''; + +switch ($permission) { + case '4': + $whereclause = ''; + break; + case '3': + $whereclause = ''; + break; + case '2': + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; + $whereclause = 'WHERE accounthierarchy like :condition '; + break; + default: + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%'; + $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] =='download' || $v[0] =='list'|| $v[0] =='success_msg'){ + //do nothing + } + elseif ($v[0] == 'search') { + //build up search + $clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].' OR rowID 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 rma_history '.$whereclause; +} + +elseif(isset($criterias['download']) && $criterias['download'] ==''){ + //Request for total rows + $sql = 'SELECT * FROM rma_history '.$whereclause; +} +else { + //SQL for Paging + $sql = "SELECT * from rma_history $whereclause ORDER BY rowID DESC 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); + } + } + } +} + +//------------------------------------------ +// Debuglog +//------------------------------------------ +if (debug){ + $message = $date.';'.$sql.';'.$username; + debuglog($message); +} + +//Add paging details +if(isset($criterias['totals']) && $criterias['totals']==''){ + $stmt->execute(); + $messages = $stmt->fetch(); + $messages = $messages[0]; +} +elseif (isset($criterias['download']) && $criterias['download'] ==''){ + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +} +else { + $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; + $stmt->bindValue('page', ($current_page - 1) * $page_rows_rma, PDO::PARAM_INT); + $stmt->bindValue('num_products', $page_rows_rma, 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; + +?> \ No newline at end of file diff --git a/api/v2/post/rma.php b/api/v2/post/rma.php new file mode 100644 index 0000000..3172784 --- /dev/null +++ b/api/v2/post/rma.php @@ -0,0 +1,91 @@ +$partner->salesid, + "soldto"=>$partner->soldto, + "shipto"=>$partner->shipto, + "location"=>$partner->location +); + +// CREATE ACCOUNTHIERARCHY JSON FROM ACCOUNT ARRAY +$accounthierarchy = json_encode($account, JSON_UNESCAPED_UNICODE); +// add to post_content +$post_content['accounthierarchy'] = $accounthierarchy; + +//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE +$post_content['updatedby'] = $username; + +if ($command == 'insert'){ + $post_content['createdby'] = $username; +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'delete' || $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' && $rma_id !=0 && isAllowed('rma',$profile,$permission,'U') === 1){ + $sql = 'UPDATE rma SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && $rma_id !=0 && isAllowed('rma',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO rma ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('rma',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM rma WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'rma',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/api/v2/post/rma_history.php b/api/v2/post/rma_history.php new file mode 100644 index 0000000..c52a8ba --- /dev/null +++ b/api/v2/post/rma_history.php @@ -0,0 +1,90 @@ +$partner->salesid, + "soldto"=>$partner->soldto, + "shipto"=>$partner->shipto, + "location"=>$partner->location +); + +// CREATE ACCOUNTHIERARCHY JSON FROM ACCOUNT ARRAY +$accounthierarchy = json_encode($account, JSON_UNESCAPED_UNICODE); +// add to post_content +$post_content['accounthierarchy'] = $accounthierarchy; + +//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE +$post_content['updatedby'] = $username; + +if ($command == 'insert'){ + $post_content['createdby'] = $username; +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'delete' || $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('rma_history',$profile,$permission,'U') === 1){ + $sql = 'UPDATE rma_history SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('rma_history',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO rma_history ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('rma_history',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM rma_history WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'rma_history',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/rma.php b/rma.php new file mode 100644 index 0000000..6875f6d --- /dev/null +++ b/rma.php @@ -0,0 +1,175 @@ + +
'.$rma_p.'
+'.$success_msg.'
+ +| '.$rma_rowID.' | +'.$rma_carbrand.' | +'.$rma_cartype.' | +'.$general_createdby.' | +'.$general_actions.' | +|||
|---|---|---|---|---|---|---|---|
| '.$message_no_ct.' | +|||||||
| '.$response->rowID.' | +'.$response->carbrand.' | +'.$response->cartype.' | +'.$response->createdby.' | +'.$general_view.' | +|||