diff --git a/post/account_type.php b/post/account_type.php index 7c3fb256..07fc39bd 100644 --- a/post/account_type.php +++ b/post/account_type.php @@ -10,42 +10,7 @@ if (isset($_POST['add_account_type'])) { $type = intval($_POST['type']); $description = sanitizeInput($_POST['description']); - switch ($type) { - case 10: - $type_name = "Assets"; - $result = mysqli_query($mysqli,"SELECT account_type_id FROM account_types"); - $account_type_id = 10; - while ($row = mysqli_fetch_array($result)) { - if ($row['account_type_id'] == $account_type_id) { - $account_type_id++; - } - } - mysqli_query($mysqli,"INSERT INTO account_types SET account_type_id = $account_type_id, account_type_name = '$name', account_type_description = '$description'"); - break; - case 20: - $type_name = "Liabilities"; - $result = mysqli_query($mysqli,"SELECT account_type_id FROM account_types"); - $account_type_id = 20; - while ($row = mysqli_fetch_array($result)) { - if ($row['account_type_id'] == $account_type_id) { - $account_type_id++; - } - } - mysqli_query($mysqli,"INSERT INTO account_types SET account_type_id = $account_type_id, account_type_name = '$name', account_type_description = '$description'"); - break; - case 30: - $type_name = "Equity"; - $result = mysqli_query($mysqli,"SELECT account_type_id FROM account_types"); - $account_type_id = 30; - while ($row = mysqli_fetch_array($result)) { - if ($row['account_type_id'] == $account_type_id) { - $account_type_id++; - } - } - mysqli_query($mysqli,"INSERT INTO account_types SET account_type_id = $account_type_id, account_type_name = '$name', account_type_description = '$description'"); - break; - } - + mysqli_query($mysqli,"INSERT INTO account_types SET account_type_parent = $type, account_type_name = '$name', account_type_description = '$description'"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Create', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); @@ -60,9 +25,10 @@ if (isset($_POST['edit_account_type'])) { $account_type_id = intval($_POST['account_type_id']); $name = sanitizeInput($_POST['name']); + $type = intval($_POST['type']); $description = sanitizeInput($_POST['description']); - mysqli_query($mysqli,"UPDATE account_types SET account_type_name = '$name', account_type_description = '$description' WHERE account_type_id = $account_type_id"); + mysqli_query($mysqli,"UPDATE account_types SET account_type_parent = $type, account_type_name = '$name', account_type_description = '$description' WHERE account_type_id = $account_type_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Edit', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); diff --git a/settings_account_types.php b/settings_account_types.php index 69674c37..b9eeb25f 100644 --- a/settings_account_types.php +++ b/settings_account_types.php @@ -9,36 +9,28 @@ if (isset($_GET['account_type'])) { $account_type = sanitizeInput($_GET['account_type']); switch ($account_type) { case "Assets": - $account_type_id_min = "10"; - $account_type_id_max = "19"; + $account_type_parent = "1"; break; case "Liabilities": - $account_type_id_min = "20"; - $account_type_id_max = "29"; + $account_type_parent = "2"; break; case "Equity": - $account_type_id_min = "30"; - $account_type_id_max = "39"; + $account_type_parent = "3"; break; default: - $account_type_id_min = "10"; - $account_type_id_max = "39"; + $account_type_parent = "1"; } } else { - $account_type_id_min = "10"; - $account_type_id_max = "39"; + $account_type_parent = "%"; } - - $sql = mysqli_query( $mysqli, "SELECT * FROM account_types WHERE account_type_$archive_query - AND account_type_id >= $account_type_id_min - AND account_type_id <= $account_type_id_max - AND (account_type_name LIKE '%$q%' OR account_type_description LIKE '%$q%' OR account_type_id LIKE '%$q%') - ORDER BY $sort $order" + AND account_type_parent LIKE '$account_type_parent' + AND (account_type_name LIKE '%$q%' OR account_type_description LIKE '%$q%') + ORDER BY account_type_parent ASC, $sort $order" ); $num_rows = mysqli_num_rows($sql); @@ -49,8 +41,9 @@ $num_rows = mysqli_num_rows($sql);

Finance Account Types

- +
@@ -102,7 +95,7 @@ $num_rows = mysqli_num_rows($sql); - + @@ -112,14 +105,22 @@ $num_rows = mysqli_num_rows($sql);
Account Type IDAccount Type Parent Account Type Name Description
- + diff --git a/settings_account_types_add_modal.php b/settings_account_types_add_modal.php index 141c25e0..7afd7645 100644 --- a/settings_account_types_add_modal.php +++ b/settings_account_types_add_modal.php @@ -15,19 +15,11 @@
- + + + +
diff --git a/settings_account_types_edit_modal.php b/settings_account_types_edit_modal.php index a82b2081..486a08e1 100644 --- a/settings_account_types_edit_modal.php +++ b/settings_account_types_edit_modal.php @@ -11,16 +11,20 @@