diff --git a/.gitignore b/.gitignore index 413b735..80e923d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ log/ assets/images/products/ settings/config.php settings/settings.php +variable_scan.php diff --git a/api/v1/get/accounts.php b/api/v1/get/accounts.php index 4024c8f..4931208 100644 --- a/api/v1/get/accounts.php +++ b/api/v1/get/accounts.php @@ -12,20 +12,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //NEW ARRAY $criterias = []; diff --git a/api/v1/get/application.php b/api/v1/get/application.php index cf0ca01..772fd9e 100644 --- a/api/v1/get/application.php +++ b/api/v1/get/application.php @@ -29,24 +29,8 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //------------------------------------------ //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 e.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 e.accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //------------------------------------------ //NEW ARRAY diff --git a/api/v1/get/cartests.php b/api/v1/get/cartests.php index 76aa80b..4605eb6 100644 --- a/api/v1/get/cartests.php +++ b/api/v1/get/cartests.php @@ -12,24 +12,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 = []; diff --git a/api/v1/get/communications.php b/api/v1/get/communications.php index 0025932..db1ce91 100644 --- a/api/v1/get/communications.php +++ b/api/v1/get/communications.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 salesID like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclauselvl2('communications',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v1/get/equipment_data.php b/api/v1/get/equipment_data.php index 3777193..66a83cd 100644 --- a/api/v1/get/equipment_data.php +++ b/api/v1/get/equipment_data.php @@ -15,24 +15,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); -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 e.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 e.accounthierarchy like :condition '; - break; -} //------------------------------------------ //NEW ARRAY //------------------------------------------ diff --git a/api/v1/get/equipments.php b/api/v1/get/equipments.php index 68d1246..2b522cb 100644 --- a/api/v1/get/equipments.php +++ b/api/v1/get/equipments.php @@ -16,24 +16,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); -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 e.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 e.accounthierarchy like :condition '; - break; -} //------------------------------------------ //NEW ARRAY //------------------------------------------ diff --git a/api/v1/get/partners.php b/api/v1/get/partners.php index a1dfd72..0dd52a1 100644 --- a/api/v1/get/partners.php +++ b/api/v1/get/partners.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 salesID like :condition'; - break; -} +list($whereclause,$condition) = getWhereclauselvl2('partners',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v1/get/products.php b/api/v1/get/products.php index e90bde7..937c3ce 100644 --- a/api/v1/get/products.php +++ b/api/v1/get/products.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v1/get/products_software.php b/api/v1/get/products_software.php index 355cf17..b589359 100644 --- a/api/v1/get/products_software.php +++ b/api/v1/get/products_software.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v1/get/products_versions.php b/api/v1/get/products_versions.php index e5b0fd0..93c25a1 100644 --- a/api/v1/get/products_versions.php +++ b/api/v1/get/products_versions.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v1/get/profile.php b/api/v1/get/profile.php index f4a9e6c..bf8442f 100644 --- a/api/v1/get/profile.php +++ b/api/v1/get/profile.php @@ -12,24 +12,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('profile',$permission,$partner); -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 partnerhierarchy 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 partnerhierarchy like :condition '; - break; -} //NEW ARRAY $criterias = []; $clause = ''; diff --git a/api/v1/get/users.php b/api/v1/get/users.php index f409588..c832bf3 100644 --- a/api/v1/get/users.php +++ b/api/v1/get/users.php @@ -12,24 +12,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('profile',$permission,$partner); -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 partnerhierarchy 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 partnerhierarchy like :condition '; - break; -} //NEW ARRAY $criterias = []; $clause = ''; diff --git a/api/v1/post/accounts.php b/api/v1/post/accounts.php index 4641908..2b30ba5 100644 --- a/api/v1/post/accounts.php +++ b/api/v1/post/accounts.php @@ -13,21 +13,9 @@ $post_content = json_decode(decode_payload($input),true); //SoldTo is empty if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} -//default whereclause to check if data is owned buy user -$whereclause = ''; +//default whereclause +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); -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 diff --git a/api/v1/post/communications.php b/api/v1/post/communications.php index e773669..f5eb043 100644 --- a/api/v1/post/communications.php +++ b/api/v1/post/communications.php @@ -14,20 +14,8 @@ $post_content = json_decode(decode_payload($input),true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v1/post/contracts.php b/api/v1/post/contracts.php index fd0384a..68e7eb6 100644 --- a/api/v1/post/contracts.php +++ b/api/v1/post/contracts.php @@ -16,22 +16,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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 = ' AND 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 = ' AND accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['rowID'] ?? ''; //check for rowID diff --git a/api/v1/post/equipments.php b/api/v1/post/equipments.php index d0a89b9..5951882 100644 --- a/api/v1/post/equipments.php +++ b/api/v1/post/equipments.php @@ -16,22 +16,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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 = ' AND 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 = ' AND accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['rowID'] ?? ''; //check for rowID diff --git a/api/v1/post/partners.php b/api/v1/post/partners.php index 530b981..65c688d 100644 --- a/api/v1/post/partners.php +++ b/api/v1/post/partners.php @@ -14,20 +14,7 @@ $post_content = json_decode(decode_payload($input),true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause to check if data is owned by user -$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 salesID like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2('partners',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['partnerID'] ?? ''; //check for rowID diff --git a/api/v1/post/products.php b/api/v1/post/products.php index b1b1c2a..b851073 100644 --- a/api/v1/post/products.php +++ b/api/v1/post/products.php @@ -14,20 +14,8 @@ $post_content = json_decode(decode_payload($input),true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v1/post/products_software.php b/api/v1/post/products_software.php index f0893b4..04118ef 100644 --- a/api/v1/post/products_software.php +++ b/api/v1/post/products_software.php @@ -14,20 +14,8 @@ $post_content = json_decode(decode_payload($input),true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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'] != ''){ diff --git a/api/v1/post/products_versions.php b/api/v1/post/products_versions.php index beda5a3..dc63408 100644 --- a/api/v1/post/products_versions.php +++ b/api/v1/post/products_versions.php @@ -14,20 +14,8 @@ $post_content = json_decode(decode_payload($input),true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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'] != ''){ diff --git a/api/v1/post/users.php b/api/v1/post/users.php index 6a4ccf9..314b782 100644 --- a/api/v1/post/users.php +++ b/api/v1/post/users.php @@ -15,24 +15,8 @@ $owner_user = 0; if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause to check if data is owned by user -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('profile',$permission,$partner); -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 = ' AND partnerhierarchy 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 = ' AND partnerhierarchy like "'.$condition.'"'; - break; -} //SET PARAMETERS FOR QUERY $id = (isset($post_content['id'])) ? $post_content['id']: ''; //check for rowID diff --git a/api/v2/get/accounts.php b/api/v2/get/accounts.php index 1ab4634..8a80da3 100644 --- a/api/v2/get/accounts.php +++ b/api/v2/get/accounts.php @@ -12,20 +12,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //NEW ARRAY $criterias = []; diff --git a/api/v2/get/cartests.php b/api/v2/get/cartests.php index 2fbbdb4..d091274 100644 --- a/api/v2/get/cartests.php +++ b/api/v2/get/cartests.php @@ -12,24 +12,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 = []; diff --git a/api/v2/get/categories.php b/api/v2/get/categories.php index 04e55b6..1503b89 100644 --- a/api/v2/get/categories.php +++ b/api/v2/get/categories.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/discounts.php b/api/v2/get/discounts.php index 964a275..f188700 100644 --- a/api/v2/get/discounts.php +++ b/api/v2/get/discounts.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 d.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("discounts",$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/equipment_data.php b/api/v2/get/equipment_data.php index 67df24b..5def010 100644 --- a/api/v2/get/equipment_data.php +++ b/api/v2/get/equipment_data.php @@ -15,24 +15,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); -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 e.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 e.accounthierarchy like :condition '; - break; -} //------------------------------------------ //NEW ARRAY //------------------------------------------ diff --git a/api/v2/get/equipment_healthindex.php b/api/v2/get/equipment_healthindex.php index 8698c96..8925b30 100644 --- a/api/v2/get/equipment_healthindex.php +++ b/api/v2/get/equipment_healthindex.php @@ -15,24 +15,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); -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 e.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 e.accounthierarchy like :condition '; - break; -} //------------------------------------------ //NEW ARRAY //------------------------------------------ diff --git a/api/v2/get/equipments.php b/api/v2/get/equipments.php index 008513c..320ba85 100644 --- a/api/v2/get/equipments.php +++ b/api/v2/get/equipments.php @@ -15,24 +15,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 e.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 e.accounthierarchy like :condition '; - break; -} //------------------------------------------ //NEW ARRAY //------------------------------------------ diff --git a/api/v2/get/invoice.php b/api/v2/get/invoice.php index c38c1f7..b6042c0 100644 --- a/api/v2/get/invoice.php +++ b/api/v2/get/invoice.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 inv.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("invoice",$permission,$partner); //NEW ARRAY $criterias = []; @@ -62,7 +49,8 @@ if(isset($criterias['totals']) && $criterias['totals'] ==''){ } elseif (isset($criterias['list']) && $criterias['list'] =='invoice'){ //SQL for Paging - $sql = 'SELECT tx.*, txi.*, p.productname, inv.id as invoice, inv.created as invoice_created FROM transactions tx + $sql = 'SELECT tx.*, txi.item_id as item_id,txi.item_price as item_price, txi.item_quantity as item_quantity, txi.item_options as item_options, p.productcode, p.productname, inv.id as invoice, inv.created as invoice_created + FROM transactions tx left join invoice inv ON tx.id = inv.txn_id left join transactions_items txi ON tx.id = txi.txn_id left join products p ON p.rowID = txi.item_id '.$whereclause; diff --git a/api/v2/get/media.php b/api/v2/get/media.php index 08e010e..32ec1dc 100644 --- a/api/v2/get/media.php +++ b/api/v2/get/media.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/pricelists.php b/api/v2/get/pricelists.php index 4ed1645..f56e125 100644 --- a/api/v2/get/pricelists.php +++ b/api/v2/get/pricelists.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 pls.accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('pricelist',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/pricelists_items.php b/api/v2/get/pricelists_items.php index e150f39..dc327d9 100644 --- a/api/v2/get/pricelists_items.php +++ b/api/v2/get/pricelists_items.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products.php b/api/v2/get/products.php index fc3c13c..ac0f98a 100644 --- a/api/v2/get/products.php +++ b/api/v2/get/products.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_attributes.php b/api/v2/get/products_attributes.php index d261a32..ec6b003 100644 --- a/api/v2/get/products_attributes.php +++ b/api/v2/get/products_attributes.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_attributes_items.php b/api/v2/get/products_attributes_items.php index 9043616..1792741 100644 --- a/api/v2/get/products_attributes_items.php +++ b/api/v2/get/products_attributes_items.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 pat.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("attributes",$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_categories.php b/api/v2/get/products_categories.php index f6f5939..e87f9d5 100644 --- a/api/v2/get/products_categories.php +++ b/api/v2/get/products_categories.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_configurations.php b/api/v2/get/products_configurations.php index 6a54d20..d1bbcad 100644 --- a/api/v2/get/products_configurations.php +++ b/api/v2/get/products_configurations.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 pc.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("config",$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_software.php b/api/v2/get/products_software.php index 47538d4..39afbed 100644 --- a/api/v2/get/products_software.php +++ b/api/v2/get/products_software.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 p.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("software",$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/products_versions.php b/api/v2/get/products_versions.php index 9316ecb..cd95647 100644 --- a/api/v2/get/products_versions.php +++ b/api/v2/get/products_versions.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/rma.php b/api/v2/get/rma.php index c54f6b7..d8c0cc3 100644 --- a/api/v2/get/rma.php +++ b/api/v2/get/rma.php @@ -11,24 +11,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 = []; diff --git a/api/v2/get/rma_history.php b/api/v2/get/rma_history.php index e16196f..99378d4 100644 --- a/api/v2/get/rma_history.php +++ b/api/v2/get/rma_history.php @@ -11,24 +11,8 @@ $pdo = dbConnect($dbname); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 = []; diff --git a/api/v2/get/shipping.php b/api/v2/get/shipping.php index c2d80ea..ebaf988 100644 --- a/api/v2/get/shipping.php +++ b/api/v2/get/shipping.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/taxes.php b/api/v2/get/taxes.php index 8a845b2..5dd0a90 100644 --- a/api/v2/get/taxes.php +++ b/api/v2/get/taxes.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/transactions.php b/api/v2/get/transactions.php index 935039b..286974b 100644 --- a/api/v2/get/transactions.php +++ b/api/v2/get/transactions.php @@ -12,20 +12,7 @@ $pdo = dbConnect($dbname); 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 tx.accounthierarchy like "'.$condition.'"'; - break; -} +$whereclause = getWhereclauselvl2("transactions",$permission,$partner); //NEW ARRAY $criterias = []; @@ -62,8 +49,16 @@ if(isset($get_content) && $get_content!=''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM transactions '.$whereclause.''; + $sql = 'SELECT count(*) as count FROM transactions tx '.$whereclause.''; } +elseif (isset($criterias['list']) && $criterias['list'] =='order'){ + //SQL for Paging + $sql = 'SELECT tx.*, txi.item_id as item_id,txi.item_price as item_price, txi.item_quantity as item_quantity, txi.item_options as item_options, p.productcode, p.productname, inv.id as invoice, inv.created as invoice_created + FROM transactions tx + left join invoice inv ON tx.id = inv.txn_id + left join transactions_items txi ON tx.id = txi.txn_id + left join products p ON p.rowID = txi.item_id '.$whereclause; +} else { //SQL for Paging $sql = 'SELECT * FROM transactions tx '.$whereclause.' LIMIT :page,:num_products'; @@ -95,6 +90,12 @@ if(isset($criterias['totals']) && $criterias['totals']==''){ $stmt->execute(); $messages = $stmt->fetch(); $messages = $messages[0]; +} +elseif (isset($criterias['list']) && $criterias['list']=='order'){ + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + $messages = transformOrderData($messages); } else { $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; diff --git a/api/v2/get/transactions_items.php b/api/v2/get/transactions_items.php index f63f05c..cd24231 100644 --- a/api/v2/get/transactions_items.php +++ b/api/v2/get/transactions_items.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/translations.php b/api/v2/get/translations.php index f068a3d..a57549a 100644 --- a/api/v2/get/translations.php +++ b/api/v2/get/translations.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/translations_details.php b/api/v2/get/translations_details.php index 6abd3ec..e8aa87b 100644 --- a/api/v2/get/translations_details.php +++ b/api/v2/get/translations_details.php @@ -14,18 +14,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //NEW ARRAY $criterias = []; diff --git a/api/v2/get/users.php b/api/v2/get/users.php index 797231b..b497dd0 100644 --- a/api/v2/get/users.php +++ b/api/v2/get/users.php @@ -12,24 +12,8 @@ $partner = json_decode($partnerhierarchy); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('profile',$permission,$partner); -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 partnerhierarchy 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 partnerhierarchy like :condition '; - break; -} //NEW ARRAY $criterias = []; $clause = ''; diff --git a/api/v2/post/accounts.php b/api/v2/post/accounts.php index bbe1688..4d694fc 100644 --- a/api/v2/post/accounts.php +++ b/api/v2/post/accounts.php @@ -13,21 +13,8 @@ $post_content = json_decode($input,true); //SoldTo is empty if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} -//default whereclause to check if data is owned buy user -$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; -} +//default whereclause +list($whereclause,$condition) = getWhereclause('equipment',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['rowID'] ?? ''; //check for rowID diff --git a/api/v2/post/categories.php b/api/v2/post/categories.php index 046cd58..ce818a8 100644 --- a/api/v2/post/categories.php +++ b/api/v2/post/categories.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +$whereclause = getWhereclauselvl2("categories",$permission,$partner); -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 c.accounthierarchy like "'.$condition.'"'; - break; -} //BUILD UP PARTNERHIERARCHY FROM USER $partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); diff --git a/api/v2/post/contracts.php b/api/v2/post/contracts.php index 072c2bf..0860704 100644 --- a/api/v2/post/contracts.php +++ b/api/v2/post/contracts.php @@ -16,22 +16,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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 = ' AND 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 = ' AND accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['rowID'] ?? ''; //check for rowID diff --git a/api/v2/post/discounts.php b/api/v2/post/discounts.php index 8c17d4c..faaa9f2 100644 --- a/api/v2/post/discounts.php +++ b/api/v2/post/discounts.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //BUILD UP PARTNERHIERARCHY FROM USER $partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); diff --git a/api/v2/post/equipments.php b/api/v2/post/equipments.php index 612f15b..3e58a59 100644 --- a/api/v2/post/equipments.php +++ b/api/v2/post/equipments.php @@ -16,22 +16,7 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el //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 = ' AND 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 = ' AND accounthierarchy like "'.$condition.'"'; - break; -} +list($whereclause,$condition) = getWhereclause('',$permission,$partner); //SET PARAMETERS FOR QUERY $id = $post_content['rowID'] ?? ''; //check for rowID diff --git a/api/v2/post/invoice.php b/api/v2/post/invoice.php index b229643..c3fa5f4 100644 --- a/api/v2/post/invoice.php +++ b/api/v2/post/invoice.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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['id'] ?? ''; //check for rowID diff --git a/api/v2/post/media.php b/api/v2/post/media.php index c15ce55..256440c 100644 --- a/api/v2/post/media.php +++ b/api/v2/post/media.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/placeorder.php b/api/v2/post/placeorder.php index 67acfae..b6e7b37 100644 --- a/api/v2/post/placeorder.php +++ b/api/v2/post/placeorder.php @@ -110,6 +110,11 @@ if (isset($post_content['cart']) && isset($post_content['checkout_input']) && is $stmt->execute([$transaction_id, $product['id'], $product['options_price'], $product['quantity'], $options]); } + //CHECK IF GIFTCARD IS USED AND THEN DISABLE IT + if ($checkout_input['discount_code'] !=''){ + useGiftCart($pdo,$checkout_input['discount_code'],$partner_product); + } + //Return to checkout page $messages = [ "id" => $transaction_id, diff --git a/api/v2/post/pricelists.php b/api/v2/post/pricelists.php index 2bae067..97068a3 100644 --- a/api/v2/post/pricelists.php +++ b/api/v2/post/pricelists.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/pricelists_items.php b/api/v2/post/pricelists_items.php index 08a84ca..7af14da 100644 --- a/api/v2/post/pricelists_items.php +++ b/api/v2/post/pricelists_items.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/products.php b/api/v2/post/products.php index 017f800..f6670e4 100644 --- a/api/v2/post/products.php +++ b/api/v2/post/products.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/products_attributes.php b/api/v2/post/products_attributes.php index ccc68a6..a8d4d19 100644 --- a/api/v2/post/products_attributes.php +++ b/api/v2/post/products_attributes.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/products_attributes_items.php b/api/v2/post/products_attributes_items.php index 0a0cb86..72b30c5 100644 --- a/api/v2/post/products_attributes_items.php +++ b/api/v2/post/products_attributes_items.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/products_categories.php b/api/v2/post/products_categories.php index bbc1fda..3c83365 100644 --- a/api/v2/post/products_categories.php +++ b/api/v2/post/products_categories.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //CHECK IF PRODUCT ID IS SEND if (isset($post_content['product_id']) && $post_content['product_id'] != ''){ diff --git a/api/v2/post/products_configurations.php b/api/v2/post/products_configurations.php index b50bb20..32f3a53 100644 --- a/api/v2/post/products_configurations.php +++ b/api/v2/post/products_configurations.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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'] != ''){ diff --git a/api/v2/post/products_software.php b/api/v2/post/products_software.php index 50edf4a..fdb37d8 100644 --- a/api/v2/post/products_software.php +++ b/api/v2/post/products_software.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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'] != ''){ diff --git a/api/v2/post/products_versions.php b/api/v2/post/products_versions.php index 2355dd3..8940d9b 100644 --- a/api/v2/post/products_versions.php +++ b/api/v2/post/products_versions.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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'] != ''){ diff --git a/api/v2/post/shipping.php b/api/v2/post/shipping.php index dc0b8c3..e887738 100644 --- a/api/v2/post/shipping.php +++ b/api/v2/post/shipping.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //BUILD UP PARTNERHIERARCHY FROM USER $partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); diff --git a/api/v2/post/transactions.php b/api/v2/post/transactions.php index a8ea78c..fcf2de4 100644 --- a/api/v2/post/transactions.php +++ b/api/v2/post/transactions.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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; -} //WEBSHOP UPDATE CAN SEND TXN_ID ONLY if (isset($post_content['txn_id']) && $post_content['txn_id'] != '' && !isset($post_content['id'])){ @@ -65,6 +53,20 @@ $partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$par //ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE if ($command == 'update'){ + //CHECK IF PAYMENT STATUS is PAID (1) + if(isset($post_content['payment_status']) && $post_content['payment_status'] == 1){ + + //check if GIFTCARD ID IS PROVIDED AND NOT EMPTY + if(isset($post_content['giftcard_categoryID']) && $post_content['giftcard_categoryID'] != ''){ + + //CHECK FOR GIFTCARDS IN ORDER AND CREATE WHEN AVAILABLE AND NOT CREATED YET + createGiftCart($pdo, $post_content['id'], $post_content['giftcard_categoryID'],$partner_product); + + //remove giftcard_categoryID from $post_content array + unset($post_content['giftcard_categoryID']); + } + } + } elseif ($command == 'insert'){ $post_content['accounthierarchy'] = $partner_product; diff --git a/api/v2/post/translations.php b/api/v2/post/translations.php index 924dbfd..144ab57 100644 --- a/api/v2/post/translations.php +++ b/api/v2/post/translations.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/translations_details.php b/api/v2/post/translations_details.php index 84b4bb6..040d4a2 100644 --- a/api/v2/post/translations_details.php +++ b/api/v2/post/translations_details.php @@ -14,20 +14,8 @@ $post_content = json_decode($input,true); if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} //default whereclause -$whereclause = ''; +list($whereclause,$condition) = getWhereclause('',$permission,$partner); -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 diff --git a/api/v2/post/users.php b/api/v2/post/users.php index be1b8ef..92e209c 100644 --- a/api/v2/post/users.php +++ b/api/v2/post/users.php @@ -14,25 +14,9 @@ $owner_user = 0; //SoldTo is empty if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} -//default whereclause to check if data is owned by user -$whereclause = ''; +//default whereclause +list($whereclause,$condition) = getWhereclause('profile',$permission,$partner); -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 = ' AND partnerhierarchy 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 = ' AND partnerhierarchy like "'.$condition.'"'; - break; -} //SET PARAMETERS FOR QUERY $id = (isset($post_content['id'])) ? $post_content['id']: ''; //check for rowID diff --git a/assets/functions.php b/assets/functions.php index a88acaf..099dff3 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -190,6 +190,7 @@ function menu($selected,$selected_child){ } return $menu; } + //------------------------------------------ // Template Header //------------------------------------------ @@ -642,6 +643,89 @@ function ioAPIv2($api_call, $data, $token){ return $resp; } +//------------------------------------------ +// DEFINE WHERECLAUSE BASED ON ACCOUNTHIERARCHY ALL +//------------------------------------------ + +function getWhereclause($table_name,$permission,$partner){ + + //api_name converter to table + $table =[ + "equipment" => "e.accounthierarchy", + "profile" => "partnerhierarchy" + ]; + + $table = ($table_name != '') ? $table[$table_name] : 'accounthierarchy'; + + //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; + case '2': + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; + $whereclause = 'WHERE '.$table.' 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 '.$table.' like :condition '; + break; + } + + return array($whereclause,$condition); +} + +//------------------------------------------ +// DEFINE WHERECLAUSE BASED ON ACCOUNTHIERARCHY SALES AND SOLD +//------------------------------------------ +function getWhereclauselvl2($table_name,$permission,$partner){ + + //api_name converter to table + $table =[ + "pricelist" => "pls.accounthierarchy", + "communications" => "salesID", + "partners" => "salesID", + "discounts" => "d.accounthierarchy", + "invoice" => "inv.accounthierarchy", + "attributes" => "pat.accounthierarchy", + "config" => "pc.accounthierarchy", + "software" => "p.accounthierarchy", + "transactions" => "tx.accounthierarchy", + "categories" => "c.accounthierarchy" + ]; + + $table = ($table_name != '') ? $table[$table_name] : 'accounthierarchy'; + + //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 '.$table.' like "'.$condition.'"'; + break; +} + + return array($whereclause,$condition); +} + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //get user profile||$profile=settings, $permision = userright() //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -3439,14 +3523,26 @@ function transformOrderData(array $orderData): array { $firstRow = $orderData[0]; $result = [ + 'header' => [ + "id" => $firstRow['id'], + "txn_id" => $firstRow['txn_id'], + "payment_status" => $firstRow['payment_status'], + "payment_method" => $firstRow['payment_method'], + "shipping_method" => $firstRow['shipping_method'], + "discount_code" => $firstRow['discount_code'], + "created" => $firstRow['created'], + "updated " => $firstRow['updated'] + ], 'customer' => [ + 'account_id' => $firstRow['account_id'], 'email' => $firstRow['payer_email'], 'name' => $firstRow['first_name'] . ' ' . $firstRow['last_name'], 'street' => $firstRow['address_street'], 'zip' => $firstRow['address_zip'], + 'state' => $firstRow['address_state'], 'city' => $firstRow['address_city'], - 'country' => $firstRow['address_country'] - + 'country' => $firstRow['address_country'], + 'phone' => $firstRow['address_phone'] ], 'products' => [], 'invoice' => [ @@ -3477,6 +3573,7 @@ function transformOrderData(array $orderData): array { // Add product information $result['products'][] = [ 'item_id' => $row['item_id'], + 'productcode' => $row['productcode'], 'product_name' => $row['productname'], 'options' => $itemOptions, 'quantity' => $row['item_quantity'], @@ -3493,4 +3590,67 @@ function transformOrderData(array $orderData): array { $result['pricing']['payment_amount'] = number_format(floatval($result['pricing']['payment_amount']), 2, '.', ''); return $result; +} + +//============================================= +// Use giftcart +//============================================= + +function useGiftCart($pdo, $discount_code, $accounthierarchy){ + + // Get the current date + $end_date = date("Y-m-d H:i:s"); + + //Check if Giftcard already exists + $stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ? AND accounthierarchy = ?'); + $stmt->execute([$discount_code,$accounthierarchy]); + $discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC); + + if (!empty($discount_exist) || $discount_exist != '') { + //Update Giftcard end data + $stmt = $pdo->prepare('UPDATE discounts SET end_date = ? WHERE discount_code = ? AND accounthierarchy = ?'); + $stmt->execute([$end_date,$discount_code, $accounthierarchy]); + } +} + +function createGiftCart($pdo, $orderID, $giftcard_categoryID,$accounthierarchy){ + + //Check if Giftcard is ordered + $stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, t.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.txn_id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND ti.txn_id = ? AND accounthierarchy = ?'); + $stmt->execute([$giftcard_categoryID,$orderID,$accounthierarchy]); + $giftcards = $stmt->fetchAll(PDO::FETCH_ASSOC); + + if ($giftcards) { + foreach ($giftcards as $giftcard) { + + //For each quantity + $x = 0; + + while ($x < $giftcard['item_quantity']){ + + //Generate discount code = TXN/ID/X + $discount_code = $giftcard['txn'].'#'.$giftcard['id'].'#'.$x; + $value = $giftcard['item_price']; + + // Get the current date + $start_date = date("Y-m-d H:i:s"); + $end_date = date("Y-m-d H:i:s", strtotime("+5 years"));; + + //Check if Giftcard already exists + $stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ? AND accounthierarchy = ?'); + $stmt->execute([$discount_code,$accounthierarchy]); + $discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC); + + if (empty($discount_exist) || $discount_exist == '') { + //Insert Giftcard + $discount_type = 0; //Fixed + //SQL Insert + $stmt = $pdo->prepare('INSERT INTO discounts (discount_code,discount_type,discount_value,start_date,end_date,accounthierarchy) VALUES (?,?,?,?,?,?)'); + $stmt->execute([$discount_code, $discount_type, $value, $start_date, $end_date,$accounthierarchy]); + } + $x++; + } + } + + } } \ No newline at end of file diff --git a/categories.php b/categories.php index 3229530..2ece3c7 100644 --- a/categories.php +++ b/categories.php @@ -62,7 +62,7 @@ function admin_populate_categories($categories, $parent_id = 0, $n = 0) {
'.$success_msg.'
+ +=$order['id']?>
+' . $order['header']['id'] . '
=$order['txn_id']?>
-' . $order['header']['txn_id'] . '
+=$order['shipping_method'] ? htmlspecialchars($order['shipping_method'], ENT_QUOTES) : '--'?>
-' . htmlspecialchars($order['header']['shipping_method'], ENT_QUOTES) . '
+=$order['payment_method']?>
+' . $order['header']['payment_method'] . '
=$order['payment_status']?>
+' . $order['header']['payment_status'] . '
=date('F j, Y H:ia', strtotime($order['created']))?>
-'.getRelativeTime($order['header']['created']). '
+=htmlspecialchars($order['discount_code'], ENT_QUOTES)?>
-' . htmlspecialchars($order['header']['discount_code'], ENT_QUOTES) . '
+ '; +} +$view .=' '; + +// Account Details Block +$view .='=htmlspecialchars($order['email'], ENT_QUOTES)?>
+' . htmlspecialchars($order['customer']['email'], ENT_QUOTES) . '
=htmlspecialchars($order['a_first_name'], ENT_QUOTES)?> =htmlspecialchars($order['a_last_name'], ENT_QUOTES)?>
+' . htmlspecialchars($order['customer']['name'], ENT_QUOTES) . '
=htmlspecialchars($order['a_address_street'], ENT_QUOTES)?>
- =htmlspecialchars($order['a_address_city'], ENT_QUOTES)?>
- =htmlspecialchars($order['a_address_state'], ENT_QUOTES)?>
- =htmlspecialchars($order['a_address_zip'], ENT_QUOTES)?>
- =htmlspecialchars($order['a_address_country'], ENT_QUOTES)?>
-
' . htmlspecialchars($order['customer']['street'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['city'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['state'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['zip'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['country'], ENT_QUOTES) . '
=htmlspecialchars($order['a_address_phone'], ENT_QUOTES)?> -
-The order is not associated with an account.
- - +' . htmlspecialchars($order['customer']['phone'], ENT_QUOTES) . '
+ '; +} else { + $view .='The order is not associated with an account.
'; +} +$view .=' '; + +// Customer Details Block +$view .='=htmlspecialchars($order['payer_email'], ENT_QUOTES)?>
+' . htmlspecialchars($order['customer']['email'], ENT_QUOTES) . '
=htmlspecialchars($order['first_name'], ENT_QUOTES)?> =htmlspecialchars($order['last_name'], ENT_QUOTES)?>
+' . htmlspecialchars($order['customer']['name'], ENT_QUOTES) . '
=htmlspecialchars($order['address_street'], ENT_QUOTES)?>
- =htmlspecialchars($order['address_city'], ENT_QUOTES)?>
- =htmlspecialchars($order['address_state'], ENT_QUOTES)?>
- =htmlspecialchars($order['address_zip'], ENT_QUOTES)?>
- =htmlspecialchars($order['address_country'], ENT_QUOTES)?>
-
' . htmlspecialchars($order['customer']['street'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['city'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['state'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['zip'], ENT_QUOTES) . '
+ ' . htmlspecialchars($order['customer']['country'], ENT_QUOTES) . '
=htmlspecialchars($order['a_address_phone'], ENT_QUOTES)?> -
+' . htmlspecialchars($order['customer']['phone'], ENT_QUOTES) . '
| Value | ||||
| There are no order items | -||||
| =$giftcard['discount_code']?> | -=$current_date >= strtotime($giftcard['start_date']) && $current_date <= strtotime($giftcard['end_date']) ? 'Yes' : 'No'?> | -=currency_code?>=number_format($giftcard['discount_value'], 2)?> | -' . $giftcard['discount_code'] . ' | +' . ($current_date >= strtotime($giftcard['start_date']) && $current_date <= strtotime($giftcard['end_date']) ? 'Yes' : 'No') . ' | +' . number_format($giftcard['discount_value'], 2) . ' | + '; + } +} + +$view .='
| - - | -- - | -- - | -
| + + | ++ + | ++ + | +
=$order['id']?>
+=$order['txn_id']?>
+=$order['shipping_method'] ? htmlspecialchars($order['shipping_method'], ENT_QUOTES) : '--'?>
+=$order['payment_method']?>
+=$order['payment_status']?>
+=date('F j, Y H:ia', strtotime($order['created']))?>
+=htmlspecialchars($order['discount_code'], ENT_QUOTES)?>
+=htmlspecialchars($order['a_first_name'], ENT_QUOTES)?> =htmlspecialchars($order['a_last_name'], ENT_QUOTES)?>
+=htmlspecialchars($order['a_address_street'], ENT_QUOTES)?>
+ =htmlspecialchars($order['a_address_city'], ENT_QUOTES)?>
+ =htmlspecialchars($order['a_address_state'], ENT_QUOTES)?>
+ =htmlspecialchars($order['a_address_zip'], ENT_QUOTES)?>
+ =htmlspecialchars($order['a_address_country'], ENT_QUOTES)?>
+
=htmlspecialchars($order['a_address_phone'], ENT_QUOTES)?> +
+The order is not associated with an account.
+ +=htmlspecialchars($order['payer_email'], ENT_QUOTES)?>
+=htmlspecialchars($order['first_name'], ENT_QUOTES)?> =htmlspecialchars($order['last_name'], ENT_QUOTES)?>
+=htmlspecialchars($order['address_street'], ENT_QUOTES)?>
+ =htmlspecialchars($order['address_city'], ENT_QUOTES)?>
+ =htmlspecialchars($order['address_state'], ENT_QUOTES)?>
+ =htmlspecialchars($order['address_zip'], ENT_QUOTES)?>
+ =htmlspecialchars($order['address_country'], ENT_QUOTES)?>
+
=htmlspecialchars($order['a_address_phone'], ENT_QUOTES)?> +
+| Product | +Options | +Qty | +Price | +Total | +
| There are no order items | +||||
| =$item['productcode']?> =$item['name'] ? htmlspecialchars($item['name'], ENT_QUOTES) : '(Product ' . $item['item_id'] . ')'?> | +=$item['item_options'] ? htmlspecialchars(str_replace(',', ', ', $item['item_options']), ENT_QUOTES) : '--'?> | +=$item['item_quantity']?> | +=currency_code?>=number_format($item['item_price'], 2)?> | +=currency_code?>=number_format($item['item_price']*$item['item_quantity'], 2)?> | +
| + | ||||
| Subtotal | +=currency_code?>=number_format($subtotal, 2)?> | +|||
| Shipping | +=currency_code?>=number_format($order['shipping_amount'], 2)?> | +|||
| Discount | +=currency_code?>=number_format(($order['payment_amount']+$order['shipping_amount'])-($subtotal), 2)?> | +|||
| VAT | +=currency_code?>=number_format($order['tax_amount'], 2)?> | +|||
| Total | +=currency_code?>=number_format($order['payment_amount'], 2)?> | +|||
| Giftcard | +Valid | +Value | +||
| There are no order items | +||||
| =$giftcard['discount_code']?> | +=$current_date >= strtotime($giftcard['start_date']) && $current_date <= strtotime($giftcard['end_date']) ? 'Yes' : 'No'?> | +=currency_code?>=number_format($giftcard['discount_value'], 2)?> | +||
| + | ||||
| + + | ++ + | ++ + | +
View, create, and search orders.
+'.($orders_p ?? '').'
=$success_msg?>
- -'.$success_msg.'
+ +| # | -Customer | -Products | -Total | -Method | -Status | -Date | -Actions | +'.($orders_id ?? '#').' | +'.($orders_customer ?? 'name').' | +'.($orders_payment_amount ?? 'Total').' | +'.($orders_method ?? 'Method').' | +'.($orders_status ?? 'Status').' | +'.($orders_created ?? 'Created').' | +'.$general_actions.' | |
| There are no orders | -|||||||||||||||
| =$i['id']?> | -=htmlspecialchars($i['first_name'], ENT_QUOTES)?> =htmlspecialchars($i['last_name'], ENT_QUOTES)?> | -=htmlspecialchars($i['payer_email'], ENT_QUOTES)?> | -=$i['total_products']?> | -=currency_code?>=number_format($i['payment_amount'], 2)?> | -=$i['payment_method']?> | -=$i['payment_status']?> | -=date('F j, Y', strtotime($i['created']))?> | -View Edit | -|||||||
| '.($message_no_orders ?? 'There are no orders').' | +|||||||||||||||
| '.$order['id'].' | +'.$order['first_name'].' '.$order['last_name'].' | +'.number_format($order['payment_amount'], 2).' | +'.$order['payment_method'].' | +'.$order['payment_status'].' | +'.getRelativeTime($order['created']).' | +'.$general_view.' | +|||||||||