diff --git a/api/v1/get/products_versions.php b/api/v1/get/products_versions.php new file mode 100644 index 0000000..e5b0fd0 --- /dev/null +++ b/api/v1/get/products_versions.php @@ -0,0 +1,140 @@ +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 productcode like :'.$v[0]; + } + else {//create clause + $clause .= ' AND '.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$criterias['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + + //Define Query + if(isset($criterias['totals']) && $criterias['totals'] ==''){ + //Request for total rows + $sql = 'SELECT count(*) as count FROM products_versions '.$whereclause.''; + } + elseif (isset($criterias['list']) && $criterias['list'] =='') { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + else { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + + $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]; + } + elseif(isset($criterias['list']) && $criterias['list']==''){ + //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_products, PDO::PARAM_INT); + //$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT); + + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + } + //Encrypt results + $messages = generate_payload($messages); + + //Send results + echo $messages; + } +} +?> \ No newline at end of file diff --git a/api/v1/post/equipments.php b/api/v1/post/equipments.php index 42a231e..b985e06 100644 --- a/api/v1/post/equipments.php +++ b/api/v1/post/equipments.php @@ -62,8 +62,8 @@ if ($id != ''){ $owner_equipment = (($equipment_data['createdby'] == $username)? 1 : 0); - if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$salesid_new, "soldto"=>$soldto_new, @@ -71,7 +71,18 @@ if ($id != ''){ "location"=>$location_new, "section"=>$section_new ); - } else { + } + elseif ($permission == 3) { + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$equipment_old->salesid, + "soldto"=>$soldto_new, + "shipto"=>$shipto_new, + "location"=>$location_new, + "section"=>$section_new + ); + } + else { $account = array( "salesid"=>$equipment_old->salesid, "soldto"=>$equipment_old->soldto, @@ -83,7 +94,7 @@ if ($id != ''){ } else { //ID is empty => INSERT / NEW RECORD - if ($permission == 3 || $permission == 4){ + if ($permission == 4){ $account = array( "salesid"=>$post_content['salesid'], "soldto"=>$post_content['soldto'], @@ -92,7 +103,17 @@ else { "section"=>$post_content['section'] ); - } else { + } + elseif ($permission == 3){ + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$post_content['soldto'], + "shipto"=>$post_content['shipto'], + "location"=>$post_content['location'], + "section"=>$post_content['section'] + + ); + }else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, diff --git a/api/v1/post/products_versions.php b/api/v1/post/products_versions.php new file mode 100644 index 0000000..beda5a3 --- /dev/null +++ b/api/v1/post/products_versions.php @@ -0,0 +1,105 @@ +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; +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($post_content['productrowid']) && $post_content['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = 'SELECT * FROM products WHERE rowID = ? '.$whereclause.''; + $stmt = $pdo->prepare($sql); + $stmt->execute([$post_content['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + //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 = ''; + + if ($command == 'insert'){ + $post_content['created'] = $date; + $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 == '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('products_versions',$profile,$permission,'U') === 1){ + $sql = 'UPDATE products_versions SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'insert' && isAllowed('products_versions',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO products_versions ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'delete' && isAllowed('products_versions',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM products_versions WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'products_versions',$id,'Delete','Delete',$username); + } else + { + //do nothing + } + } +} +?> \ No newline at end of file diff --git a/api/v1/post/users.php b/api/v1/post/users.php index 2c898fd..993256d 100644 --- a/api/v1/post/users.php +++ b/api/v1/post/users.php @@ -64,15 +64,24 @@ $soldto_new = ((isset($post_content['soldto']) && $post_content['soldto'] != '' $shipto_new = (($post_content['shipto'] != '' && $post_content['shipto'] != $partnerhierarchy_old->shipto)? $post_content['shipto'] : $partnerhierarchy_old->shipto); $location_new = (($post_content['location'] != '' && $post_content['location'] != $partnerhierarchy_old->location)? $post_content['location'] : $partnerhierarchy_old->location); -if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$salesid_new, "soldto"=>$soldto_new, "shipto"=>$shipto_new, "location"=>$location_new ); - } else { + }elseif ($permission == 3) { + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$soldto_new, + "shipto"=>$shipto_new, + "location"=>$location_new + ); + } + else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, @@ -82,15 +91,25 @@ if ($permission == 3 || $permission == 4){ } } elseif ($command == 'insert') { //ID is empty => INSERT / NEW RECORD - if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$post_content['salesid'], "soldto"=>$post_content['soldto'], "shipto"=>$post_content['shipto'], "location"=>$post_content['location'] ); - } else { + } + elseif ($permission == 3){ + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$post_content['soldto'], + "shipto"=>$post_content['shipto'], + "location"=>$post_content['location'] + ); + } + else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, diff --git a/api/v2/get/products_versions.php b/api/v2/get/products_versions.php new file mode 100644 index 0000000..e7702fa --- /dev/null +++ b/api/v2/get/products_versions.php @@ -0,0 +1,142 @@ +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 productcode like :'.$v[0]; + } + else {//create clause + $clause .= ' AND '.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$criterias['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + + //Define Query + if(isset($criterias['totals']) && $criterias['totals'] ==''){ + //Request for total rows + $sql = 'SELECT count(*) as count FROM products_versions '.$whereclause.''; + } + elseif (isset($criterias['list']) && $criterias['list'] =='') { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + else { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + + $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]; + } + elseif(isset($criterias['list']) && $criterias['list']==''){ + //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_products, PDO::PARAM_INT); + //$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT); + + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + } + //------------------------------------------ + //JSON_DECODE + //------------------------------------------ + $messages = json_encode($messages, JSON_UNESCAPED_UNICODE); + + //Send results + echo $messages; + } +} +?> \ No newline at end of file diff --git a/api/v2/post/products_versions.php b/api/v2/post/products_versions.php new file mode 100644 index 0000000..2355dd3 --- /dev/null +++ b/api/v2/post/products_versions.php @@ -0,0 +1,105 @@ +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; +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($post_content['productrowid']) && $post_content['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$post_content['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + //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 = ''; + + if ($command == 'insert'){ + $post_content['created'] = $date; + $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 == '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('products_versions',$profile,$permission,'U') === 1){ + $sql = 'UPDATE products_versions SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'insert' && isAllowed('products_versions',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO products_versions ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'delete' && isAllowed('products_versions',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM products_versions WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'products_versions',$id,'Delete','Delete',$username); + } else + { + //do nothing + } + } +} +?> \ No newline at end of file diff --git a/assets/functions.php b/assets/functions.php index 2e9f181..c8565af 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -1968,20 +1968,20 @@ function changeLogVisual($totals,$details){ $totalcount += $total['total']; } - //GET SERIALNUMBERS - $url_input = ''; //used to collect serialnumber for onclick event - foreach ($details as $detail){ - $url_input .= $detail['serialnumber'].','; - } - - $view = '
+ $view = '
'; @@ -2228,4 +2228,84 @@ $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); //Excute Query $stmt->execute(); } +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// ML data preparations +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +function traintotalMeasurement($messages){ + +//total measurement internal array +$total_measurement = []; + +foreach ($messages as $message){ + //Cleanup input array + $dataset = json_decode($message['description'],true); + $dataset = $dataset["doubletestvalues"]; + foreach ($dataset as $measure){ + //Filter out correct measurements + if ($measure['pass'] === true){ + $measurementid = $message['equipmentid'].'-'.$message['rowID']; + $total_measurement[$measure['name']][$measurementid] = $measure['measure']; + } + } + } +return $total_measurement; +} + +function statisticalAnalyses($total_measurement){ + + //result array + $total_results = []; + + //STATISTICAL ANALYSES INTERNAL ARRAY + foreach ($total_measurement as $key => $value){ + $average = $total_results[$key]['average'] = average($value); + $median = $total_results[$key]['median'] = calculateMedian($value); + $stdev = $total_results[$key]['stdev'] = standDeviation($value); + $total_results[$key]['n'] = count($value); + + //GET STDEV -/+ + $total_results[$key]['stdev-1'] = $average - $stdev; + $total_results[$key]['stdev+1'] = $average + $stdev; + $total_results[$key]['stdev-2'] = $average - (2*$stdev); + $total_results[$key]['stdev+2'] = $average + (2*$stdev); + $total_results[$key]['stdev-3'] = $average - (3*$stdev); + $total_results[$key]['stdev+3'] = $average + (3*$stdev); + } + + return $total_results; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Main statiscal functions for ML +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +function standDeviation($arr) +{ + $num_of_elements = count($arr); + $variance = 0.0; + // Calculate mean using array_sum() method + $average = array_sum($arr) / $num_of_elements; + foreach($arr as $i) + { + // Sum of squares of differences between all numbers and means. + $variance += pow(($i - $average), 2); + } + return (float)sqrt($variance / $num_of_elements); +} +function average($arr) +{ + $num_of_elements = count($arr); + $average = array_sum($arr) / $num_of_elements; + return $average; +} +function calculateMedian($array) { + if (empty($array)) { + return null; + } else { + sort($array); + $lowMiddle = $array[floor((count($array) - 1) / 2)]; + $highMiddle = $array[ceil((count($array) - 1) / 2)]; + return ($lowMiddle + $highMiddle) / 2; + } } \ No newline at end of file diff --git a/dev.php b/dev.php index 6aec4b5..1eca3f1 100644 --- a/dev.php +++ b/dev.php @@ -9,40 +9,84 @@ include './settings/config.php'; //Connect to DB $pdo = dbConnect($dbname); -$sql = 'SELECT description FROM history where type="Maintenance_Test" and description like "%doubletestvalues%"'; + + +//GET +$sql = 'SELECT rowID, description, equipmentid FROM history where type="Maintenance_Test" and description like "%doubletestvalues%"'; $stmt = $pdo->prepare($sql); $stmt->execute(); $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); -//total measurement internal array -$total_measurement = []; -foreach ($messages as $message){ - //Cleanup input array - $message = json_decode($message['description'],true); - $message = $message["doubletestvalues"]; - foreach ($message as $measure){ - //Filter out correct measurements - if ($measure['pass'] === true){ - $total_measurement[$measure['name']][] = $measure['measure']; +$watchlist_byproduct = []; +$watchlist_bytest = []; +$watchlist_totals = []; + +//train the model +$total_measurement = traintotalMeasurement($messages); + +//get statics on results +$total_results = statisticalAnalyses($total_measurement); + +//COMPARISON -- CHECK DEVIATIONS FROM STANDARD +foreach ($total_measurement as $measurement => $values){ + foreach($total_results as $total_result => $measured_values){ + if ($measurement == $total_result){ + foreach ($values as $id => $measured_value){ + if (($measured_value <= $total_results[$total_result]['stdev-3']) && ($measured_value >= $total_results[$total_result]['stdev+3'])){ + $watchlist_byproduct[$id][] = array( + "measurement" => $measurement, + "value" => $measured_value, + "deviation" => 3 + ); + $watchlist_bytest[$measurement][] = array( + "equipmentid" => $id, + "value" => $measured_value, + "deviation" => 3 + ); + } + elseif ((($measured_value <= $total_results[$total_result]['stdev-2']) && ($measured_value >= $total_results[$total_result]['stdev-3'])) || (($measured_value >= $total_results[$total_result]['stdev+2']) && ($measured_value <= $total_results[$total_result]['stdev+3']))){ + $watchlist_byproduct[$id][] = array( + "measurement" => $measurement, + "value" => $measured_value, + "deviation" => 2 + ); + $watchlist_bytest[$measurement][] = array( + "equipmentid" => $id, + "value" => $measured_value, + "deviation" => 2 + ); + } + elseif ((($measured_value <= $total_results[$total_result]['stdev-1']) && ($measured_value >= $total_results[$total_result]['stdev-2'])) || (($measured_value >= $total_results[$total_result]['stdev+1']) && ($measured_value <= $total_results[$total_result]['stdev+2']))){ + /*$watchlist_byproduct[$id][] = array( + "measurement" => $measurement, + "value" => $measured_value, + "deviation" => 1 + ); + $watchlist_bytest[$measurement][] = array( + "equipmentid" => $id, + "value" => $measured_value, + "deviation" => 1 + ); + */ + } + } } } } -//result array -$total_results = []; -//print "
";
-//print_r($total_measurement);
-//print "
"; - -foreach ($total_measurement as $key => $value){ - $total_results[$key]['average'] = average($value); - $total_results[$key]['median'] = calculateMedian($value); - $total_results[$key]['stdev'] = standDeviation($value); +//GET WATCHLIST SUMMARY +foreach ($watchlist_bytest as $test => $value){ + $watchlist_totals[$test]['n_deviation'] = count($value); + //calculate percentage + //$watchlist_totals[$test]['percentage'] = ($watchlist_totals[$test]['n_deviation'] / $watchlist_totals[$test]['n_total'])*100; } + print "
";
 print_r($total_results);
 print "
"; + +/*MAIN STATISCAL FUNCTION function standDeviation($arr) { $num_of_elements = count($arr); @@ -72,6 +116,6 @@ function calculateMedian($array) { return ($lowMiddle + $highMiddle) / 2; } } - +*/ ?> \ No newline at end of file diff --git a/equipments.php b/equipments.php index 67ce204..e4ae432 100644 --- a/equipments.php +++ b/equipments.php @@ -37,12 +37,13 @@ $servicedate = $_SESSION['servicedate'] = isset($_GET['servicedate']) ? '&servic $warrantydate = $_SESSION['warrantydate'] = isset($_GET['warrantydate']) ? '&warrantydate='.$_GET['warrantydate'] : ''; $partnerid = $_SESSION['partnerid'] = isset($_GET['partnerid']) ? '&partnerid='.$_GET['partnerid'] : ''; $productselected = $_SESSION['productcode'] = isset($_GET['productcode']) ? '&productcode='.$_GET['productcode'] : ''; +$serialnumber_input = $_SESSION['serialnumber'] = isset($_GET['serialnumber']) ? '&serialnumber='.$_GET['serialnumber'] : ''; //GET PARAMETERS FOR FILTERS $filter = urlGETdetailsFilter($_GET) ?? ''; // Determine the URL -$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected; +$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected.$serialnumber_input; //GET Details from URL $GET_VALUES = urlGETdetails($_GET) ?? ''; //CALL TO API diff --git a/product.php b/product.php index 147ad87..e87f31b 100644 --- a/product.php +++ b/product.php @@ -1,207 +1,249 @@ '.$button_back.'':''; + //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 = 'product_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'); +$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'); -// Default input product values -$product = [ - 'rowID' => '', - 'productcode' => '', - 'productname' => '', - 'productdescription' => '', - 'softwareversion' => 'v1.0', - 'created' => '', - 'createdby' => $_SESSION['username'], - 'parttype' => 1, - 'price' => '0', - 'salesflag' => 0, - 'updated' => '', - 'updatedby' => $_SESSION['username'], - 'product_category' => '', - 'status' => 1, - 'build' => 1, - 'partnerhierarchy' => '', - 'sn' =>'' -]; +//GET Details from URL +$GET_VALUES = urlGETdetails($_GET) ?? ''; -if (isset($_GET['id'])) { - // ID param exists, edit an existing product - //CALL TO API - $api_url = '/v1/products/rowID='.$_GET['id']; - $responses = ioServer($api_url,''); - //Decode Payload - if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} - - $product = json_decode(json_encode($responses[0]), true); - - if ($update_allowed === 1){ - if (isset($_POST['file_upload'])){ - uploadProduct($_POST['productcode']); - } - if (isset($_POST['submit'])) { - //GET ALL POST DATA - $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); - //Secure data - $payload = generate_payload($data); - //API call - $responses = ioServer('/v1/products', $payload); - if ($responses === 'NOK'){ +//CALL TO API FOR General information +$api_url = '/v1/products/'.$GET_VALUES; +$responses = ioServer($api_url,''); +//Decode Payload +if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} +$responses = $responses[0]; - } else { - header('Location: index.php?page=products&status=1&success_msg=2'); - exit; - - } - } +//CALL TO API FOR Product_versions +$api_url = '/v1/products_versions/productrowid='.$_GET['rowID']; +$product_versions = ioServer($api_url,''); +//Decode Payload +if (!empty($product_versions)){$product_versions = decode_payload($product_versions);}else{$product_versions = null;} + +//------------------------------ +//Variables +//------------------------------ +$status_text = 'prod_status_'.$responses->status ?? ''; +$product_category_text = 'product_category'.$responses->product_category ?? ''; +$parttype_text = 'part_type'.$responses->parttype ?? ''; + +// Handle success messages +if (isset($_GET['success_msg'])) { + if ($_GET['success_msg'] == 1) { + $success_msg = $message_pr_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/products', $payload); - if ($responses === 'NOK'){ - - } else { - // Redirect and delete product - header('Location: index.php?page=products&status=1&success_msg=3'); - exit; - } - } + if ($_GET['success_msg'] == 2) { + $success_msg = $message_pr_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/products', $payload); - if ($responses === 'NOK'){ - - } - else { - header('Location: index.php?page=products&success_msg=1'); - exit; - } + if ($_GET['success_msg'] == 3) { + $success_msg = $message_pr_3; } } -template_header('Product', 'product', 'manage'); - -$view =' -
+template_header('Product', 'product', 'view'); +$view = '
-

'.$product_h2.'

- '.$button_cancel.' +

'.$responses->productcode.' - '.$responses->productname.'

+ '.$button_cancel.' '; -if ($delete_allowed === 1){ - $view .= ''; + +//------------------------------------ +// +//------------------------------------ +if ($update_allowed_edit === 1){ + $view .= 'Edit'; } -if ($update_allowed === 1){ - $view .= ''; -} - + $view .= '
'; -$view .= ' - '; +if (isset($success_msg)){ + $view .= '
+ +

'.$success_msg.'

+ +
'; +} -$view .= '
-
- - - - - - - - - - - - - - - - - +$view .= '
'; + +$view .= '
+
+ '.($product_data ?? '').' +
+
+

'.$product_status.'

+

'.$$status_text.'

+
+
+

'.$product_category.'

+

'.$$product_category_text.'

+
+
+

'.$product_parttype.'

+

'.$$parttype_text.'

+
+
+

'.$product_code.'

+

'.$responses->productcode.'

+
+
+

'.$product_name.'

+

'.$responses->productname.'

+
'; + +$view .='
-
'; - - -$view .= '
-
- - - - - - -
-
'; - -$view .= '
-
- - - - - - - - -
-
'; -$view .= ''; - -$view .= '
- - - -
'; -//Output -echo $view; -template_footer()?> \ No newline at end of file +$view .='
+
+ +
'; + $picture = glob("./assets/images/products/".$responses->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE); + if (!empty($picture)){ + $view .=' +
+ +
+ '; + } +$view .=' +
+'; +$view .= '
'; +$view .= '
+
+ '.$product_description.' +
+
+ '.$responses->productdescription.' +
+
+ '; + + + +$view .= '
+
+ '.($product_version ?? '').' + + +
'; + if (!empty($product_versions)){ + $view .= ' +
+ + + + + + + + + + '; + foreach ($product_versions as $version){ + $view .= ' + + + + + '; + } + $view .= ' + +
'.$product_version_number.''.$product_version_version.''.$product_version_software .''.$general_actions.'
'.$version->rowID.''.$version->version.''.$version->software.''.$general_view.'
+
+ '; + } + +$view .= ' +
+'; + +$view .= '
+
+ '.$tab4.' +
+
+ + + + + + + + + + + + + +
'.$product_serialized.''.(($responses->sn == 1)? $enabled : $disabled).'
'.$product_sales.''.(($responses->salesflag == 1)? $enabled : $disabled).'
'.$product_build.''.(($responses->build == 1)? $enabled : $disabled).'
+
+
+'; + +$view .= '
+
+ '.$tab3.' +
+
+ + + + + + + + + + + + + + + + + +
'.$general_created.''.$responses->created.'
'.$general_createdby.''.$responses->createdby.'
'.$general_updated.''.$responses->updated.'
'.$general_updatedby.''.$responses->updatedby.'
+
+
+'; + +$view .='
'; + +//OUTPUT +echo $view; + +template_footer() + +?> \ No newline at end of file diff --git a/product_manage.php b/product_manage.php new file mode 100644 index 0000000..8ea1b2a --- /dev/null +++ b/product_manage.php @@ -0,0 +1,214 @@ + '', + 'productcode' => '', + 'productname' => '', + 'productdescription' => '', + 'softwareversion' => 'v1.0', + 'created' => '', + 'createdby' => $_SESSION['username'], + 'parttype' => 1, + 'price' => '0', + 'salesflag' => 0, + 'updated' => '', + 'updatedby' => $_SESSION['username'], + 'product_category' => '', + 'status' => 1, + 'build' => 1, + 'partnerhierarchy' => '', + 'sn' =>'' +]; + +if (isset($_GET['id'])) { + // ID param exists, edit an existing product + //CALL TO API + $api_url = '/v1/products/rowID='.$_GET['id']; + $responses = ioServer($api_url,''); + //Decode Payload + if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} + + $product = json_decode(json_encode($responses[0]), true); + + if ($update_allowed === 1){ + if (isset($_POST['file_upload'])){ + uploadProduct($_POST['productcode']); + } + if (isset($_POST['submit'])) { + //GET ALL POST DATA + $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); + //Secure data + $payload = generate_payload($data); + //API call + $responses = ioServer('/v1/products', $payload); + if ($responses === 'NOK'){ + + } else { + header('Location: index.php?page=product&rowID='.$_GET['id'].'&success_msg=2'); + exit; + + } + } + } + + 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/products', $payload); + if ($responses === 'NOK'){ + + } else { + // Redirect and delete product + header('Location: index.php?page=products&success_msg=3'); + exit; + } + } + } + +} 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/products', $payload); + if ($responses === 'NOK'){ + + } + else { + header('Location: index.php?page=products&success_msg=1'); + exit; + } + } +} + +template_header('Product', 'product', 'manage'); + +$view =' +
+
+

'.$product_h2.'

+ '.$button_cancel.' +'; + +if ($delete_allowed === 1){ + $view .= ''; +} +if ($update_allowed === 1){ + $view .= ''; +} + +$view .= '
'; + +$view .= ' + '; + +$view .= '
+
+ + + + + + + + + + + + + + + + + +
+
'; + + +$view .= '
+
+ + + + + + +
+
'; + +$view .= '
+
+ + + + + + + + +
+
'; +$view .= '
'; + +$view .= '
+ + + +
+'; + +//Output +echo $view; +template_footer()?> \ No newline at end of file diff --git a/products.php b/products.php index ed7424a..8c72b16 100644 --- a/products.php +++ b/products.php @@ -8,8 +8,12 @@ defined(page_security_key) or exit; include_once './assets/functions.php'; include_once './settings/settings.php'; +//SET ORIGIN FOR NAVIGATION +$prev_page = $_SESSION['prev_origin'] ?? ''; +$page = $_SESSION['origin'] = 'products'; + //Check if allowed -if (isAllowed('products',$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ +if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ header('location: index.php'); exit; } @@ -69,7 +73,7 @@ $view .= '
} $view .= '
- '.$button_create_product.' + '.$button_create_product.'
@@ -130,7 +134,7 @@ $view .= ' '.(($picture)?'' : '').' '.$response->productname.' - '.$general_view .' + '.$general_view .' '; } diff --git a/products_versions.php b/products_versions.php new file mode 100644 index 0000000..6f1a69d --- /dev/null +++ b/products_versions.php @@ -0,0 +1,160 @@ + '', + 'productrowid' => '', + 'status' => '', + 'version' => '', + 'software' => '', + 'created' => '', + 'createdby' => $_SESSION['username'], + 'measurement' => '', +]; + +//productrowid is required by api +$productrowid = $_GET['productrowid'] ?? ''; + +if (isset($_GET['rowID'])) { + // ID param exists, edit an existing product + //CALL TO API + $api_url = '/v1/products_versions/rowID='.$_GET['rowID'].'&productrowid='.$productrowid; + $responses = ioServer($api_url,''); + + //Decode Payload + if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} + + $products_versions = json_decode(json_encode($responses[0]), true); + + + if ($update_allowed === 1){ + if (isset($_POST['submit'])) { + //GET ALL POST DATA + $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); + //Secure data + $payload = generate_payload($data); + //API call + $responses = ioServer('/v1/products_versions', $payload); + if ($responses === 'NOK'){ + + } else { + header('Location: index.php?page=product&rowID='.$productrowid.'&success_msg=2'); + exit; + + } + } + } + + 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/products_versions', $payload); + if ($responses === 'NOK'){ + + } else { + // Redirect and delete product + header('Location: index.php?page=product&rowID='.$productrowid.'&success_msg=3'); + exit; + } + } + } + +} 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/products_versions', $payload); + if ($responses === 'NOK'){ + + } + else { + header('Location: index.php?page=product&rowID='.$productrowid.'&success_msg=1'); + exit; + } + } +} + +template_header('Products versions', 'products_versions', 'manage'); + +$view =' + +
+

'.$product_version_version.'

+ '.$button_cancel.' +'; + +if ($delete_allowed === 1){ + $view .= ''; +} +if ($update_allowed === 1){ + $view .= ''; +} + +$view .= '
'; + +$view .= ' + '; + +$view .= '
+
+ + + + + + + + '; + + if (isset($_GET['rowID']) && $_GET['rowID'] !=''){ + $view .= ' + + + '; + } +$view .= ' + + +
+
'; + +$view .= '
+
+ + + + +
+
'; +$view .= ''; + +//Output +echo $view; +template_footer() +?> \ No newline at end of file diff --git a/report_build.php b/report_build.php index c371e99..4b8420e 100644 --- a/report_build.php +++ b/report_build.php @@ -34,9 +34,9 @@ if (!empty($query_total_sfg)){$query_total_sfg = decode_payload($query_total_sfg //Return FINISH GOODS from API $api_url = '/v1/equipments/productrowid=0&status=2&totals='; -$query_total_sfg = ioServer($api_url,''); +$query_total_fg = ioServer($api_url,''); //Decode Payload -if (!empty($query_total_sfg)){$query_total_sfg = decode_payload($query_total_sfg);}else{$query_total_sfg = null;} +if (!empty($query_total_fg)){$query_total_fg = decode_payload($query_total_fg);}else{$query_total_fg = null;} //Return warranty from API $api_url = '/v1/equipments/status=2&totals='; @@ -46,7 +46,7 @@ if (!empty($query_total_onstock)){$query_total_onstock = decode_payload($query_t -$startdate = date("Y-m-d", strtotime("-900 days")); +$startdate = date("Y-m-d", strtotime("-7 days")); $enddate = date("Y-m-d"); //Return SFG from API - total @@ -56,13 +56,13 @@ $query_SFG_total = ioServer($api_url,''); if (!empty($query_SFG_total)){$query_SFG_total = decode_payload($query_SFG_total);}else{$query_SFG_total = null;} //Return SFG from API - details -$api_url = '/v1/changelog/object_field=status&object_value=2&reporttype=2&between='.$startdate.'||'.$enddate; +$api_url = '/v1/changelog/object_field=status&object_value=1&reporttype=2&between='.$startdate.'||'.$enddate; $query_SFG_details = ioServer($api_url,''); //Decode Payload if (!empty($query_SFG_details)){$query_SFG_details = decode_payload($query_SFG_details);}else{$query_SFG_details = null;} //Return FG from API - totals -$api_url = '/v1/changelog/object_field=status&object_value=1&reporttype=1&between='.$startdate.'||'.$enddate; +$api_url = '/v1/changelog/object_field=status&object_value=2&reporttype=1&between='.$startdate.'||'.$enddate; $query_FG_total = ioServer($api_url,''); //Decode Payload if (!empty($query_FG_total)){$query_FG_total = decode_payload($query_FG_total);}else{$query_FG_total = null;} @@ -111,7 +111,7 @@ $view .= '

'.$product_location_FG.'

-

'.$query_total_sfg.'

+

'.$query_total_fg.'