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']);
$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");

View File

@ -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);
<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>
<div class="card-tools">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAccountTypeModal"><i
class="fas fa-plus mr-2"></i>Create Account Type</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAccountTypeModal">
<i class="fas fa-plus mr-2"></i>Create Account Type
</button>
</div>
</div>
<div class="card-body">
@ -102,7 +95,7 @@ $num_rows = mysqli_num_rows($sql);
<table class="table table-striped table-borderless table-hover">
<thead>
<tr>
<th>Account Type ID</th>
<th>Account Type Parent</th>
<th>Account Type Name</th>
<th>Description</th>
<th></th>
@ -112,14 +105,22 @@ $num_rows = mysqli_num_rows($sql);
<?php
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_description = nullable_htmlentities($row['account_type_description']);
?>
<tr>
<td><a class="text-dark text-bold" href="#" data-toggle="modal"
data-target="#editAccountTypeModal<?php echo $account_type_id; ?>">
<?php echo $account_type_id; ?>
<?php echo $account_type_parent_name; ?>
</a></td>
<td>
<?php echo $account_type_name; ?>

View File

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

View File

@ -11,16 +11,20 @@
<input type="hidden" name="account_type_id" value="<?php echo $account_type_id; ?>">
<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">
<label>Name <strong class="text-danger">*</strong></label>
<input type="text" class="form-control" name="name" value="<?php echo $account_type_name; ?>" required>
</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">
<label>Description</label>
<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'");
//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'");