Updated hopefully everywhere for account so account_archived works properly also do not allow archiving of account if equals online payment account

This commit is contained in:
johnnyq 2023-08-27 17:50:10 -04:00
parent 1c5398d85e
commit a959f588f3
11 changed files with 72 additions and 24 deletions

View File

@ -13,6 +13,7 @@ $sql = mysqli_query(
$mysqli,
"SELECT SQL_CALC_FOUND_ROWS * FROM accounts
WHERE account_name LIKE '%$q%'
AND account_archived_at IS NULL
ORDER BY $sort $order LIMIT $record_from, $record_to"
);
@ -85,7 +86,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editAccountModal<?php echo $account_id; ?>">
<i class="fas fa-fw fa-edit mr-2"></i>Edit
</a>
<?php if ($balance == 0) { //Cannot Archive an Account until it reaches 0 Balance ?>
<?php if ($balance == 0 && $account_id != $config_stripe_account) { //Cannot Archive an Account until it reaches 0 Balance and cant be selected as an online account ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="post.php?archive_account=<?php echo $account_id; ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Archive

View File

@ -59,7 +59,7 @@ $receivables = $invoice_totals_all_years - $total_payments_to_invoices_all_years
$profit = $total_income - $total_expenses;
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts");
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
$sql_latest_invoice_payments = mysqli_query(
$mysqli,

View File

@ -44,7 +44,7 @@
<select class="form-control select2" name="account" required>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance FROM accounts ORDER BY account_name ASC");
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id_select = intval($row['account_id']);
$account_name_select = nullable_htmlentities($row['account_name']);
@ -64,7 +64,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($expense_account_id == $account_id_select) { ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<option <?php if ($expense_account_id == $account_id_select) { echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<?php
}

View File

@ -45,11 +45,17 @@
<select class="form-control select2" name="account" required>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance FROM accounts WHERE (account_archived_at > '$expense_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC");
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance, account_archived_at FROM accounts WHERE (account_archived_at > '$expense_created_at' OR account_archived_at IS NULL) ORDER BY account_archived_at ASC, account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id_select = intval($row['account_id']);
$account_name_select = nullable_htmlentities($row['account_name']);
$opening_balance = floatval($row['opening_balance']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id_select");
$row = mysqli_fetch_array($sql_payments);
@ -66,7 +72,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($expense_account_id == $account_id_select) { ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<option <?php if ($expense_account_id == $account_id_select) { ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo "$account_archived_display$account_name_select"; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<?php
}

View File

@ -112,6 +112,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$client_id = intval($row['client_id']);
$client_name = nullable_htmlentities($row['client_name']);
$account_name = nullable_htmlentities($row['account_name']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
?>
@ -123,7 +129,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $payment_amount, $payment_currency_code); ?></td>
<td><?php echo $payment_method; ?></td>
<td><?php echo $payment_reference_display; ?></td>
<td><?php echo $account_name; ?></td>
<td><?php echo "$account_archived_display$account_name"; ?></td>
</tr>
<?php } ?>

View File

@ -86,11 +86,17 @@
<select class="form-control select2" name="account" required>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance FROM accounts WHERE (account_archived_at > '$expense_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC");
$sql_accounts = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance, account_archived_at FROM accounts WHERE (account_archived_at > '$expense_created_at' OR account_archived_at IS NULL) ORDER BY account_archived_at ASC, account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id_select = intval($row['account_id']);
$account_name_select = nullable_htmlentities($row['account_name']);
$opening_balance = floatval($row['opening_balance']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id_select");
$row = mysqli_fetch_array($sql_payments);
@ -107,7 +113,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($recurring_expense_account_id == $account_id_select) { ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<option <?php if ($recurring_expense_account_id == $account_id_select) { ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo "$account_archived_display$account_name_select"; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<?php
}

View File

@ -62,13 +62,18 @@
<option value="">- Account -</option>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$revenue_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC");
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$revenue_created_at' OR account_archived_at IS NULL) ORDER BY account_archived_at ASC, account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id_select = intval($row['account_id']);
$account_name_select = nullable_htmlentities($row['account_name']);
$account_currency_code_select = nullable_htmlentities($row['account_currency_code']);
$opening_balance = floatval($row['opening_balance']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id_select");
$row = mysqli_fetch_array($sql_payments);
$total_payments = floatval($row['total_payments']);
@ -84,7 +89,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($account_id == $account_id_select) { echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [ <?php echo numfmt_format_currency($currency_format, $balance, $account_currency_code_select); ?> ]</option>
<option <?php if ($account_id == $account_id_select) { echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_archived_display; ?> <?php echo $account_name_select; ?> [ <?php echo numfmt_format_currency($currency_format, $balance, $account_currency_code_select); ?> ]</option>
<?php
}

View File

@ -50,7 +50,7 @@ require_once("inc_all_settings.php"); ?>
<option value="0">- None -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM accounts ORDER BY account_name ASC");
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql)) {
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']); ?>
@ -71,7 +71,7 @@ require_once("inc_all_settings.php"); ?>
<option value="0">- None -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM accounts ORDER BY account_name ASC");
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql)) {
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']); ?>
@ -92,7 +92,7 @@ require_once("inc_all_settings.php"); ?>
<option value="0">- None -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM accounts ORDER BY account_name ASC");
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql)) {
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']); ?>
@ -113,7 +113,7 @@ require_once("inc_all_settings.php"); ?>
<option value="0">- None -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM accounts ORDER BY account_name ASC");
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql)) {
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']); ?>
@ -180,7 +180,7 @@ require_once("inc_all_settings.php"); ?>
<hr>
<button type="submit" name="edit_default_settings" class="btn btn-primary text-bold"><i class="fa fa-check"></i> Save</button>
<button type="submit" name="edit_default_settings" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>
</form>
</div>

View File

@ -49,7 +49,7 @@ require_once("inc_all_settings.php");
<select class="form-control select2" name="config_stripe_account" required>
<option value="">- Account -</option>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts");
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']);

View File

@ -47,11 +47,17 @@
<select class="form-control select2" name="account_from" required>
<?php
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$transfer_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC");
$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$transfer_created_at' OR account_archived_at IS NULL) ORDER BY account_archived_at ASC, account_name ASC");
while ($row = mysqli_fetch_array($sql_accounts)) {
$account_id_select = intval($row['account_id']);
$account_name_select = nullable_htmlentities($row['account_name']);
$opening_balance = floatval($row['opening_balance']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id_select");
$row = mysqli_fetch_array($sql_payments);
@ -68,7 +74,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($transfer_account_from == $account_id_select) { echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<option <?php if ($transfer_account_from == $account_id_select) { echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo "$account_archived_display$account_name_select"; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<?php
}
@ -85,11 +91,17 @@
<select class="form-control select2" name="account_to" required>
<?php
$sql2 = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$transfer_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC");
$sql2 = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$transfer_created_at' OR account_archived_at IS NULL) ORDER BY account_archived_at ASC, account_name ASC");
while ($row = mysqli_fetch_array($sql2)) {
$account_id2 = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']);
$opening_balance = floatval($row['opening_balance']);
$account_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_archived_at)) {
$account_archived_display = "";
} else {
$account_archived_display = "Archived - ";
}
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id2");
$row = mysqli_fetch_array($sql_payments);
@ -106,7 +118,7 @@
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if ($transfer_account_to == $account_id2) { echo "selected"; } ?> value="<?php echo $account_id2; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<option <?php if ($transfer_account_to == $account_id2) { echo "selected"; } ?> value="<?php echo $account_id2; ?>"><?php echo "$account_archived_display$account_name"; ?> [$<?php echo number_format($balance, 2); ?>]</option>
<?php
}

View File

@ -111,16 +111,28 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$sql_from = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_id = $transfer_account_from");
$row = mysqli_fetch_array($sql_from);
$account_name_from = nullable_htmlentities($row['account_name']);
$account_from_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_from_archived_at)) {
$account_from_archived_display = "";
} else {
$account_from_archived_display = "Archived - ";
}
$sql_to = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_id = $transfer_account_to");
$row = mysqli_fetch_array($sql_to);
$account_name_to = nullable_htmlentities($row['account_name']);
$account_to_archived_at = nullable_htmlentities($row['account_archived_at']);
if (empty($account_to_archived_at)) {
$account_to_archived_display = "";
} else {
$account_to_archived_display = "Archived - ";
}
?>
<tr>
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editTransferModal<?php echo $transfer_id; ?>"><?php echo $transfer_date; ?></a></td>
<td><?php echo $account_name_from; ?></td>
<td><?php echo $account_name_to; ?></td>
<td><?php echo "$account_from_archived_display$account_name_from"; ?></td>
<td><?php echo "$account_to_archived_display$account_name_to"; ?></td>
<td><?php echo $transfer_notes_display; ?></td>
<td class="text-bold text-right"><?php echo numfmt_format_currency($currency_format, $transfer_amount, $session_company_currency); ?></td>
<td>