Merge pull request #767 from o-psi/unarchive-for-account-types

Updates for account types
This commit is contained in:
Johnny 2023-10-15 12:09:25 -04:00 committed by GitHub
commit 8d5bda529c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 32 deletions

View File

@ -86,3 +86,17 @@ if (isset($_GET['archive_account_type'])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if (isset($_GET['unarchive_account_type'])) {
$account_type_id = intval($_GET['unarchive_account_type']);
mysqli_query($mysqli,"UPDATE account_types SET account_type_archived_at = NULL WHERE account_type_id = $account_type_id");
//logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Unarchive', log_description = '$account_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent'");
$_SESSION['alert_message'] = "Account Unarchived";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

View File

@ -5,11 +5,39 @@ require_once("inc_all_settings.php");
$sort = "account_type_id";
$order = "ASC";
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";
break;
case "Liabilities":
$account_type_id_min = "20";
$account_type_id_max = "29";
break;
case "Equity":
$account_type_id_min = "30";
$account_type_id_max = "39";
break;
default:
$account_type_id_min = "10";
$account_type_id_max = "39";
}
} else {
$account_type_id_min = "10";
$account_type_id_max = "39";
}
$sql = mysqli_query(
$mysqli,
"SELECT * FROM account_types
WHERE account_type_archived_at IS NULL
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"
);
@ -21,17 +49,61 @@ $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>New 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">
<form autocomplete="off">
<div class="row">
<div class="col-sm-4 mb-2">
<div class="input-group">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) {
echo stripslashes(nullable_htmlentities($q));
} ?>" placeholder="Search Categories">
<div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="btn-group float-right">
<a href="settings_account_types.php" class="btn <?php if (!isset($_GET['account_type']) && !isset($_GET['archived'])) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">All</a>
<a href="?account_type=Assets" class="btn <?php if ($account_type == 'Assets') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Assets</a>
<a href="?account_type=Liabilities" class="btn <?php if ($account_type == 'Liabilities') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Liabilities</a>
<a href="?account_type=Equity" class="btn <?php if ($account_type == 'Equity') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Equity</a>
<a href="?archived=1" class="btn <?php if ($_GET['archived']) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>"><i class="fas fa-fw fa-archive mr-2"></i>Archived</a>
</div>
</div>
</div>
</form>
<form action="post.php" method="post" autocomplete="off">
<table class="table table-striped table-borderless table-hover">
<thead>
<tr>
<th>Account Type ID</th>
<th>Account Type Name</th>
<th>Type Group</th>
<th>Description</th>
<th></th>
</tr>
@ -43,45 +115,47 @@ $num_rows = mysqli_num_rows($sql);
$account_type_id = nullable_htmlentities($row['account_type_id']);
$account_type_name = nullable_htmlentities($row['account_type_name']);
$account_type_description = nullable_htmlentities($row['account_type_description']);
$account_type_group = $row['account_type_id'];
if($account_type_group < 20) {
$account_type_group_name = "Assets";
} elseif($account_type_group < 30) {
$account_type_group_name = "Liabilities";
} elseif($account_type_group < 40) {
$account_type_group_name = "Equity";
} else {
$account_type_group_name = "Other";
}
?>
?>
<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; ?></a></td>
<td><?php echo $account_type_name; ?></td>
<td><?php
echo $account_type_group_name;
?></td>
<td><?php echo $account_type_description; ?></td>
<td><a class="text-dark text-bold" href="#" data-toggle="modal"
data-target="#editAccountTypeModal<?php echo $account_type_id; ?>">
<?php echo $account_type_id; ?>
</a></td>
<td>
<?php echo $account_type_name; ?>
</td>
<td>
<?php echo $account_type_description; ?>
</td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editAccountTypeModal<?php echo $account_type_id; ?>">
<a class="dropdown-item" href="#" data-toggle="modal"
data-target="#editAccountTypeModal<?php echo $account_type_id; ?>">
<i class="fas fa-fw fa-edit mr-2"></i>Edit
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_account_type=<?php echo $account_type_id; ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Archive
</a>
<?php if ($archived == NULL) { ?>
<a class="dropdown-item text-danger confirm-link"
href="post.php?archive_account_type=<?php echo $account_type_id; ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Archive
</a>
<?php } else { ?>
<a class="dropdown-item text-success confirm-link"
href="post.php?unarchive_account_type=<?php echo $account_type_id; ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Unarchive
</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php
<?php
require("settings_account_types_edit_modal.php");
}

View File

@ -16,10 +16,18 @@
<div class="form-group">
<label>Account Type</label>
<select class="form-control select2" name="type">
<option value="">- Select -</option>
<option value="10">Assets</option>
<option value="20">Liabilities</option>
<option value="30">Equity</option>
<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>
</div>
<div class="form-group">

View File

@ -13,7 +13,7 @@
<div>
<label>Type Group</label>
<input type="text" class="form-control" name="type_group" value="<?php echo $account_type_group; ?>" readonly>
<input type="text" class="form-control" name="type_group" value="<?php echo $account_type; ?>" readonly>
</div>
<div class="form-group">