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);
| Account Type ID | +Account Type Parent | Account Type Name | Description | @@ -112,14 +105,22 @@ $num_rows = mysqli_num_rows($sql); |
|---|---|---|---|---|
| - + |
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 @@
-
-
-
-
-
+
+
+
diff --git a/setup.php b/setup.php
index 45878280..65c22f05 100644
--- a/setup.php
+++ b/setup.php
@@ -249,17 +249,17 @@ if (isset($_POST['add_company_settings'])) {
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_type = '11', account_currency_code = '$currency_code'");
//Create Main Account Types
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Asset', account_type_id= '10', account_type_description = 'Assets are economic resources which are expected to benefit the business in the future.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Liability', account_type_id= '20', account_type_description = 'Liabilities are obligations of the business entity. They are usually classified as current liabilities (due within one year or less) and long-term liabilities (due after one year).'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Equity', account_type_id= '30', account_type_description = 'Equity represents the owners stake in the business after liabilities have been deducted.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Asset', account_type_parent = 1, account_type_description = 'Assets are economic resources which are expected to benefit the business in the future.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Liability', account_type_parent = 2, account_type_description = 'Liabilities are obligations of the business entity. They are usually classified as current liabilities (due within one year or less) and long-term liabilities (due after one year).'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Equity', account_type_parent= 3, account_type_description = 'Equity represents the owners stake in the business after liabilities have been deducted.'");
//Create Secondary Account Types
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Asset', account_type_id= '11', account_type_description = 'Current assets are expected to be consumed within one year or less.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Fixed Asset', account_type_id= '12', account_type_description = 'Fixed assets are expected to benefit the business for more than one year.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Asset', account_type_id= '19', account_type_description = 'Other assets are assets that do not fit into any of the other asset categories.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Asset', account_type_parent = 1, account_type_description = 'Current assets are expected to be consumed within one year or less.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Fixed Asset', account_type_parent = 1, account_type_description = 'Fixed assets are expected to benefit the business for more than one year.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Asset', account_type_parent = 1, account_type_description = 'Other assets are assets that do not fit into any of the other asset categories.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Liability', account_type_id= '21', account_type_description = 'Current liabilities are expected to be paid within one year or less.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Long Term Liability', account_type_id= '22', account_type_description = 'Long term liabilities are expected to be paid after one year.'");
- mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Liability', account_type_id= '29', account_type_description = 'Other liabilities are liabilities that do not fit into any of the other liability categories.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Liability', account_type_parent = 2, account_type_description = 'Current liabilities are expected to be paid within one year or less.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Long Term Liability', account_type_parent = 2, account_type_description = 'Long term liabilities are expected to be paid after one year.'");
+ mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Liability', account_type_parent = 2, account_type_description = 'Other liabilities are liabilities that do not fit into any of the other liability categories.'");
//Create Categories
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue'");
|