Updated Account Types liasting and posting to use the new account_type_parent field, also update setup to inset the correct account types into the correct account_type_parent

This commit is contained in:
johnnyq
2023-10-20 15:40:52 -04:00
parent fcc49c2b40
commit 762dafab7e
5 changed files with 48 additions and 85 deletions

View File

@@ -10,42 +10,7 @@ if (isset($_POST['add_account_type'])) {
$type = intval($_POST['type']); $type = intval($_POST['type']);
$description = sanitizeInput($_POST['description']); $description = sanitizeInput($_POST['description']);
switch ($type) { mysqli_query($mysqli,"INSERT INTO account_types SET account_type_parent = $type, account_type_name = '$name', account_type_description = '$description'");
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;
}
//Logging //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"); 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']); $account_type_id = intval($_POST['account_type_id']);
$name = sanitizeInput($_POST['name']); $name = sanitizeInput($_POST['name']);
$type = intval($_POST['type']);
$description = sanitizeInput($_POST['description']); $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 //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"); 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");

View File

@@ -9,36 +9,28 @@ if (isset($_GET['account_type'])) {
$account_type = sanitizeInput($_GET['account_type']); $account_type = sanitizeInput($_GET['account_type']);
switch ($account_type) { switch ($account_type) {
case "Assets": case "Assets":
$account_type_id_min = "10"; $account_type_parent = "1";
$account_type_id_max = "19";
break; break;
case "Liabilities": case "Liabilities":
$account_type_id_min = "20"; $account_type_parent = "2";
$account_type_id_max = "29";
break; break;
case "Equity": case "Equity":
$account_type_id_min = "30"; $account_type_parent = "3";
$account_type_id_max = "39";
break; break;
default: default:
$account_type_id_min = "10"; $account_type_parent = "1";
$account_type_id_max = "39";
} }
} else { } else {
$account_type_id_min = "10"; $account_type_parent = "%";
$account_type_id_max = "39";
} }
$sql = mysqli_query( $sql = mysqli_query(
$mysqli, $mysqli,
"SELECT * FROM account_types "SELECT * FROM account_types
WHERE account_type_$archive_query WHERE account_type_$archive_query
AND account_type_id >= $account_type_id_min AND account_type_parent LIKE '$account_type_parent'
AND account_type_id <= $account_type_id_max AND (account_type_name LIKE '%$q%' OR account_type_description LIKE '%$q%')
AND (account_type_name LIKE '%$q%' OR account_type_description LIKE '%$q%' OR account_type_id LIKE '%$q%') ORDER BY account_type_parent ASC, $sort $order"
ORDER BY $sort $order"
); );
$num_rows = mysqli_num_rows($sql); $num_rows = mysqli_num_rows($sql);
@@ -49,8 +41,9 @@ $num_rows = mysqli_num_rows($sql);
<div class="card-header py-3"> <div class="card-header py-3">
<h3 class="card-title"><i class="fas fa-fw fa-money-bill-wave mr-2"></i>Finance Account Types</h3> <h3 class="card-title"><i class="fas fa-fw fa-money-bill-wave mr-2"></i>Finance Account Types</h3>
<div class="card-tools"> <div class="card-tools">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAccountTypeModal"><i <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAccountTypeModal">
class="fas fa-plus mr-2"></i>Create Account Type</button> <i class="fas fa-plus mr-2"></i>Create Account Type
</button>
</div> </div>
</div> </div>
<div class="card-body"> <div class="card-body">
@@ -102,7 +95,7 @@ $num_rows = mysqli_num_rows($sql);
<table class="table table-striped table-borderless table-hover"> <table class="table table-striped table-borderless table-hover">
<thead> <thead>
<tr> <tr>
<th>Account Type ID</th> <th>Account Type Parent</th>
<th>Account Type Name</th> <th>Account Type Name</th>
<th>Description</th> <th>Description</th>
<th></th> <th></th>
@@ -112,14 +105,22 @@ $num_rows = mysqli_num_rows($sql);
<?php <?php
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$account_type_id = nullable_htmlentities($row['account_type_id']); $account_type_id = intval($row['account_type_id']);
$account_type_parent = intval($row['account_type_parent']);
if($account_type_parent == 1) {
$account_type_parent_name = "Assets";
} elseif($account_type_parent == 2) {
$account_type_parent_name = "Liabilities";
} else {
$account_type_parent_name = "Equity";
}
$account_type_name = nullable_htmlentities($row['account_type_name']); $account_type_name = nullable_htmlentities($row['account_type_name']);
$account_type_description = nullable_htmlentities($row['account_type_description']); $account_type_description = nullable_htmlentities($row['account_type_description']);
?> ?>
<tr> <tr>
<td><a class="text-dark text-bold" href="#" data-toggle="modal" <td><a class="text-dark text-bold" href="#" data-toggle="modal"
data-target="#editAccountTypeModal<?php echo $account_type_id; ?>"> data-target="#editAccountTypeModal<?php echo $account_type_id; ?>">
<?php echo $account_type_id; ?> <?php echo $account_type_parent_name; ?>
</a></td> </a></td>
<td> <td>
<?php echo $account_type_name; ?> <?php echo $account_type_name; ?>

View File

@@ -15,19 +15,11 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Account Type</label> <label>Account Type</label>
<select class="form-control select2" name="type"> <select class="form-control select2" name="type" required>
<option value=""<?php if ($account_type == NULL) <option value="" <?php if ($account_type == NULL) echo "selected"; ?>>- Select -</option>
echo ' selected'; <option value="1" <?php if ($account_type == 'Assets') echo "selected"; ?>>Assets</option>
?>>- Select -</option> <option value="2" <?php if ($account_type == 'Liabilities') echo "selected"; ?>>Liabilities</option>
<option value="10"<?php if ($account_type == 'Assets') <option value="3" <?php if ($account_type == 'Equity') echo "selected"; ?>>Equity</option>
echo ' selected';
?>>Assets</option>
<option value="20"<?php if ($account_type == 'Liabilities')
echo ' selected';
?>>Liabilities</option>
<option value="30"<?php if ($account_type == 'Equity')
echo ' selected';
?>>Equity</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -11,16 +11,20 @@
<input type="hidden" name="account_type_id" value="<?php echo $account_type_id; ?>"> <input type="hidden" name="account_type_id" value="<?php echo $account_type_id; ?>">
<div class="modal-body bg-white"> <div class="modal-body bg-white">
<div>
<label>Type Group</label>
<input type="text" class="form-control" name="type_group" value="<?php echo $account_type; ?>" readonly>
</div>
<div class="form-group"> <div class="form-group">
<label>Name <strong class="text-danger">*</strong></label> <label>Name <strong class="text-danger">*</strong></label>
<input type="text" class="form-control" name="name" value="<?php echo $account_type_name; ?>" required> <input type="text" class="form-control" name="name" value="<?php echo $account_type_name; ?>" required>
</div> </div>
<div class="form-group">
<label>Account Type</label>
<select class="form-control select2" name="type" required>
<option value="1" <?php if ($account_parent == 1) echo 'selected'; ?>>Assets</option>
<option value="2" <?php if ($account_parent == 2) echo 'selected'; ?>>Liabilities</option>
<option value="3" <?php if ($account_parent == 3) echo 'selected'; ?>>Equity</option>
</select>
</div>
<div class="form-group"> <div class="form-group">
<label>Description</label> <label>Description</label>
<textarea class="form-control" name="description" placeholder="Description"><?php echo $account_type_description; ?></textarea> <textarea class="form-control" name="description" placeholder="Description"><?php echo $account_type_description; ?></textarea>

View File

@@ -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'"); mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_type = '11', account_currency_code = '$currency_code'");
//Create Main Account Types //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 = '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_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 = '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_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 = '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 //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 = '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_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 = '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_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 = '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 = '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_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 = '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_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 = '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 //Create Categories
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue'"); mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue'");