@@ -288,6 +288,15 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="client_statement.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "client_statement.php") { echo "active"; } ?>">
|
||||||
|
<i class="nav-icon fas fa-file-invoice-dollar"></i>
|
||||||
|
<p>
|
||||||
|
Statement
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="client_trips.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "client_trips.php") { echo "active"; } ?>">
|
<a href="client_trips.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "client_trips.php") { echo "active"; } ?>">
|
||||||
<i class="nav-icon fas fa-route"></i>
|
<i class="nav-icon fas fa-route"></i>
|
||||||
|
|||||||
188
client_statement.php
Normal file
188
client_statement.php
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once "inc_all.php";
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_GET['client_id'])) {
|
||||||
|
|
||||||
|
$client_id = intval($_GET['client_id']);
|
||||||
|
|
||||||
|
$sql_client_details = "
|
||||||
|
SELECT
|
||||||
|
client_name,
|
||||||
|
client_type,
|
||||||
|
client_website,
|
||||||
|
client_net_terms
|
||||||
|
FROM
|
||||||
|
clients
|
||||||
|
WHERE
|
||||||
|
client_id = $client_id";
|
||||||
|
|
||||||
|
$result_client_details = mysqli_query($mysqli, $sql_client_details);
|
||||||
|
$row_client_details = mysqli_fetch_assoc($result_client_details);
|
||||||
|
|
||||||
|
$client_name = nullable_html_entities($row_client_details['client_name']);
|
||||||
|
$client_type = nullable_html_entities($row_client_details['client_type']);
|
||||||
|
$client_website = nullable_html_entities($row_client_details['client_website']);
|
||||||
|
$client_net_terms = intval($row_client_details['client_net_terms']);
|
||||||
|
|
||||||
|
$sql_client_unpaid_invoices = "
|
||||||
|
SELECT
|
||||||
|
invoice_id,
|
||||||
|
invoice_number,
|
||||||
|
invoice_prefix,
|
||||||
|
invoice_date,
|
||||||
|
invoice_due,
|
||||||
|
invoice_amount
|
||||||
|
FROM
|
||||||
|
invoices
|
||||||
|
WHERE
|
||||||
|
invoice_client_id = $client_id
|
||||||
|
AND invoice_status NOT LIKE 'Draft'
|
||||||
|
AND invoice_status NOT LIKE 'Cancelled'
|
||||||
|
AND invoice_status NOT LIKE 'Paid'";
|
||||||
|
|
||||||
|
$result_client_unpaid_invoices = mysqli_query($mysqli, $sql_client_unpaid_invoices);
|
||||||
|
|
||||||
|
$currency_code = getSettingValue($mysqli, "company_currency");
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<ol class="breadcrumb d-print-none">
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="clients.php">Clients</a>
|
||||||
|
</li>
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="client_invoices.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="card card-dark">
|
||||||
|
<div class="card-header py-2">
|
||||||
|
<h3 class="card-title mt-2"><i class="fas fa-fw fa-balance-scale mr-2"></i>Statement for <?php echo $client_name ?></h3>
|
||||||
|
<div class="card-tools">
|
||||||
|
<button type="button" class="btn btn-primary d-print-none" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body p-0">
|
||||||
|
<div>
|
||||||
|
<div class="table-responsive-sm">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<!-- Past Due Payments -->
|
||||||
|
<thead class="text-dark">
|
||||||
|
<tr>
|
||||||
|
<th>Invoice Number</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Due Date</th>
|
||||||
|
<th>Amount</th>
|
||||||
|
<th>Balance</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
while ($row = mysqli_fetch_assoc($result_client_unpaid_invoices)) {
|
||||||
|
$invoice_number = intval($row['invoice_number']);
|
||||||
|
$invoice_id = intval($row['invoice_id']);
|
||||||
|
$invoice_prefix = nullable_html_entities($row['invoice_prefix']);
|
||||||
|
$invoice_date = nullable_html_entities($row['invoice_date']);
|
||||||
|
$invoice_amount = floatval($row['invoice_amount']);
|
||||||
|
$invoice_amount_formatted = numfmt_format_currency($currency_format, $invoice_amount, $currency_code);
|
||||||
|
$invoice_url = "invoice.php?invoice_id=$invoice_id";
|
||||||
|
$invoice_due = nullable_html_entities($row['invoice_due']);
|
||||||
|
|
||||||
|
$invoice_balance = floatval(calculateInvoiceBalance($mysqli, $invoice_id));
|
||||||
|
$invoice_balance_formatted = numfmt_format_currency($currency_format, $invoice_balance, $currency_code);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="<?php echo $invoice_url; ?>" target="_blank"><?php echo $invoice_prefix . $invoice_number; ?></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice_date; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice_due; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice_amount_formatted; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice_balance_formatted; ?>
|
||||||
|
</td>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive-sm">
|
||||||
|
<!-- Previous Payments -->
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead class="text-dark">
|
||||||
|
<tr>
|
||||||
|
<th>Payment Reference</th>
|
||||||
|
<th>Payment Date</th>
|
||||||
|
<th>Payment Amount</th>
|
||||||
|
<th>Invoice Number</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$sql_client_payments = "
|
||||||
|
SELECT
|
||||||
|
payments.payment_date,
|
||||||
|
payments.payment_amount,
|
||||||
|
payments.payment_reference,
|
||||||
|
invoices.invoice_number,
|
||||||
|
invoices.invoice_prefix
|
||||||
|
FROM
|
||||||
|
payments
|
||||||
|
LEFT JOIN
|
||||||
|
invoices ON payments.payment_invoice_id = invoices.invoice_id
|
||||||
|
WHERE
|
||||||
|
payment_account_id = $client_id
|
||||||
|
AND payment_archived_at IS NULL
|
||||||
|
ORDER BY
|
||||||
|
payment_date DESC";
|
||||||
|
|
||||||
|
$result_client_payments = mysqli_query($mysqli, $sql_client_payments);
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_assoc($result_client_payments)) {
|
||||||
|
$payment_date = nullable_html_entities($row['payment_date']);
|
||||||
|
$payment_amount = floatval($row['payment_amount']);
|
||||||
|
$payment_reference = nullable_html_entities($row['payment_reference']);
|
||||||
|
$invoice_number = nullable_html_entities($row['invoice_prefix'].$row['invoice_number']);
|
||||||
|
$payment_amount_formatted = numfmt_format_currency($currency_format, $payment_amount, $currency_code);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<?php echo $payment_reference; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $payment_date; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $payment_amount_formatted; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice_number; ?>
|
||||||
|
</td>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once "footer.php";
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
5
debug.php
Normal file
5
debug.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
@@ -850,7 +850,7 @@ function calculateAccountBalance($mysqli, $account_id) {
|
|||||||
$sql_account = mysqli_query($mysqli, "SELECT * FROM accounts LEFT JOIN account_types ON accounts.account_type = account_types.account_type_id WHERE account_archived_at IS NULL AND account_id = $account_id ORDER BY account_name ASC; ");
|
$sql_account = mysqli_query($mysqli, "SELECT * FROM accounts LEFT JOIN account_types ON accounts.account_type = account_types.account_type_id WHERE account_archived_at IS NULL AND account_id = $account_id ORDER BY account_name ASC; ");
|
||||||
$row = mysqli_fetch_array($sql_account);
|
$row = mysqli_fetch_array($sql_account);
|
||||||
$opening_balance = floatval($row['opening_balance']);
|
$opening_balance = floatval($row['opening_balance']);
|
||||||
$account_id = $row['account_id'];
|
$account_id = intval($row['account_id']);
|
||||||
|
|
||||||
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
|
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
|
||||||
$row = mysqli_fetch_array($sql_payments);
|
$row = mysqli_fetch_array($sql_payments);
|
||||||
@@ -870,5 +870,24 @@ function calculateAccountBalance($mysqli, $account_id) {
|
|||||||
$balance = '0.00';
|
$balance = '0.00';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateInvoiceBalance($mysqli, $invoice_id) {
|
||||||
|
$sql_invoice = mysqli_query($mysqli, "SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||||
|
$row = mysqli_fetch_array($sql_invoice);
|
||||||
|
$invoice_amount = floatval($row['invoice_amount']);
|
||||||
|
$invoice_id = intval($row['invoice_id']);
|
||||||
|
|
||||||
|
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_invoice_id = $invoice_id");
|
||||||
|
$row = mysqli_fetch_array($sql_payments);
|
||||||
|
$total_payments = floatval($row['total_payments']);
|
||||||
|
|
||||||
|
$balance = $invoice_amount - $total_payments;
|
||||||
|
|
||||||
|
if ($balance == '') {
|
||||||
|
$balance = '0.00';
|
||||||
|
}
|
||||||
|
|
||||||
return $balance;
|
return $balance;
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
$formatted_behind_amount = numfmt_format_currency($currency_format, $behind_amount, $config_currency_code);
|
$formatted_behind_amount = numfmt_format_currency($currency_format, $behind_amount, $config_currency_code);
|
||||||
|
|
||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
echo "<td><a href='client_overview.php?client_id=$client_id'>$client_name</a></td>";
|
echo "<td><a href='client_statement.php?client_id=$client_id'>$client_name</a></td>";
|
||||||
echo "<td>$formatted_balance</td>";
|
echo "<td>$formatted_balance</td>";
|
||||||
echo "<td>$billing_contact_phone</td>";
|
echo "<td>$billing_contact_phone</td>";
|
||||||
echo "<td>$formatted_recurring_monthly_total</td>";
|
echo "<td>$formatted_recurring_monthly_total</td>";
|
||||||
|
|||||||
Reference in New Issue
Block a user