Files
itflow/client/recurring_invoices.php
johnnyq 422088fb60 Invoices, quotes and recurring invoices makeover stage 2: per user, per device and per license recurring lines that take their quantity from the client's contacts (all or tagged), devices (ticked types or tagged, lost/stolen/retired left out) or a license's seats (in use or bought), counted again for every invoice with an optional contract minimum, set from a Counted choice on the add row or the full Quantity from section in Edit Line with a live count, marked on each line and listed in a new Seats card with Update now when the client has changed, quarterly frequency alongside monthly and yearly counted as a third in MRR on the dashboard, client pages, client portal and reports, period words {month} {quarter} {year} {period} filled into scope, notes and lines, schedule card showing the period the next invoice covers, recurring_invoice_anchor_day so month-end schedules return to the 31st after a short month, nightly run and Invoice Now consolidated into recurringInvoiceGenerate() which claims the run so it is billed once, refreshes seat counts and takes taxes at current rates, nightly run now bills runs missed by up to 7 days, Invoice Now bills the next run early and moves the schedule on from that run instead of restarting from today, recurring email goes to non-archived primary and billing contacts once per address and stays a draft when outgoing mail is not set up. Fixes portal recurring card ignoring yearly-only clients and counting archived ones, edit recurring invoice resetting the billing day. Adds DB 2.9.1, recurring_invoice_sync and recurring_seat_count handlers, itflowBillingSeatForm(), and updates the 26.11 changelog
2026-10-16 13:09:59 -04:00

119 lines
5.7 KiB
PHP

<?php
/*
* Client Portal
* Invoices for PTC
*/
header("Content-Security-Policy: default-src 'self'");
require_once "includes/inc_all.php";
enforceContactCan('accounting');
$recurring_invoices_sql = mysqli_query($mysqli, "SELECT recurring_invoice_amount, recurring_invoice_frequency, recurring_invoice_id,
recurring_invoice_next_date, recurring_invoice_number, recurring_invoice_prefix,
recurring_invoice_scope, recurring_invoice_status, recurring_payment_id,
recurring_payment_recurring_invoice_id, recurring_payment_saved_payment_id FROM recurring_invoices
LEFT JOIN recurring_payments ON recurring_payment_recurring_invoice_id = recurring_invoice_id
WHERE recurring_invoice_client_id = $session_client_id
AND recurring_invoice_status = 1
ORDER BY recurring_invoice_next_date DESC"
);
// Get Payment Provide Details
$payment_provider_sql = mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_name, payment_provider_threshold FROM payment_providers WHERE payment_provider_active = 1 LIMIT 1");
$row = mysqli_fetch_assoc($payment_provider_sql);
$payment_provider_id = intval($row['payment_provider_id']);
$payment_provider_name = escapeHtml($row['payment_provider_name']);
$payment_provider_threshold = floatval($row['payment_provider_threshold']);
?>
<h3>Recurring Invoices</h3>
<div class="row">
<div class="col-md-10">
<?php if (mysqli_num_rows($recurring_invoices_sql) == 0) { ?>
<?= portalEmptyState('There are no recurring invoices set up on this account.') ?>
<?php } else { ?>
<table class="table table-bordered border border-dark">
<thead class="table-dark">
<tr>
<th>Scope</th>
<th>Amount</th>
<th>Next Bill Date</th>
<th>Frequency</th>
<?php if ($payment_provider_id) { ?>
<th>Auto Pay</th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($recurring_invoices_sql)) {
$recurring_invoice_id = intval($row['recurring_invoice_id']);
$recurring_invoice_prefix = escapeHtml($row['recurring_invoice_prefix']);
$recurring_invoice_number = intval($row['recurring_invoice_number']);
$recurring_invoice_scope = escapeHtml($row['recurring_invoice_scope']);
$recurring_invoice_status = escapeHtml($row['recurring_invoice_status']);
$recurring_invoice_next_date = escapeHtml($row['recurring_invoice_next_date']);
$recurring_invoice_frequency = escapeHtml($row['recurring_invoice_frequency']);
$recurring_invoice_amount = floatval($row['recurring_invoice_amount']);
$recurring_payment_id = intval($row['recurring_payment_id']);
$recurring_payment_recurring_invoice_id = intval($row['recurring_payment_recurring_invoice_id']);
$recurring_payment_saved_payment_id = intval($row['recurring_payment_saved_payment_id']);
if (empty($recurring_invoice_scope)) {
$recurring_invoice_scope_display = "-";
} else {
$recurring_invoice_scope_display = $recurring_invoice_scope;
}
?>
<tr>
<td><?= $recurring_invoice_scope_display ?></td>
<td><?= numfmt_format_currency($currency_format, $recurring_invoice_amount, $session_company_currency) ?></td>
<td><?= $recurring_invoice_next_date ?></td>
<td><?= escapeHtml(recurringInvoiceFrequencies()[$row['recurring_invoice_frequency']] ?? ucfirst($recurring_invoice_frequency)) ?></td>
<?php if ($payment_provider_id) { ?>
<td>
<?php $sql = mysqli_query($mysqli, "SELECT saved_payment_description, saved_payment_id FROM client_saved_payment_methods WHERE saved_payment_client_id = $session_client_id");
if (mysqli_num_rows($sql) > 0) { ?>
<form class="form" action="post.php" method="post">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="set_recurring_payment" value="1">
<input type="hidden" name="recurring_invoice_id" value="<?= $recurring_invoice_id ?>">
<select class="form-select" name="saved_payment_id" data-autosubmit>
<option value="0">Disabled</option>
<?php
while ($row = mysqli_fetch_assoc($sql)) {
$saved_payment_id = intval($row['saved_payment_id']);
$saved_payment_description = escapeHtml($row['saved_payment_description']);
?>
<option <?php if ($recurring_payment_saved_payment_id == $saved_payment_id) { echo "selected"; } ?> value="<?= $saved_payment_id ?>"><?= $saved_payment_description ?></option>
<?php } ?>
</select>
</form>
<?php } else { ?>
<a href="saved_payment_methods.php">Add a Payment Method</a>
<?php } ?>
</td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</div>
</div>
<?php
require_once "includes/footer.php";