Files
itflow/agent/modals/client/client_edit.php
johnnyq afaaa5fc32 Taxes stage 1: Admin > Taxes rebuilt (renamed from Tax Rates) listing each rate with its whole percent, parts, description, registration number and usage (invoices, quotes, recurring invoices, products, clients), Current and Archived tabs showing what replaced a rate, Restore, Make default, and Delete only for a rate never used; rates made of parts (state and county, GST and QST) with parts charged on top of the ones above, the whole rate shown as typed, four decimal places and a registration number per rate or part printed with the company details on invoices, quotes and PDFs; changing the percent or parts of a rate on a sent invoice or quote makes a new rate of the same name and archives the old one, so billed lines keep the old rate while products, client rates, the default, recurring invoices and optionally drafts move to the new one, and archiving offers to move whatever still uses it; How lines are taxed settings for the default rate, taxing billed time, trips and expenses, and discounts taken off before tax (on by default, shared across lines by amount, paid, cancelled and answered documents never recalculated); clients get their own tax rate and tax exempt with certificate number and expiry on the Billing tab, new lines defaulting to the client's rate then the product's then the default and to no tax for exempt clients, exempt badge on the client header and overview, a warning with Take the tax off on open documents that still carry taxed lines for an exempt client, and Tax exempt with the certificate under the client on untaxed documents; totals, PDFs, guest and portal views show tax by part; Unbilled Time can bill at each client's usual rate and the ticket, Add Tickets, Add Expenses and Add Trips windows start on it; API client fields for rate and exemption and tax_id default on invoice item create; Tax Collected shows exact percents; demo taxes get parts and registration numbers, demo clients their rates and two nonprofits exemptions; database 3.1.1 makes tax_percent decimal(9,4) and adds tax description, registration and replaced-by, tax_components, client rate and exemption columns and the tax settings; new functions/tax.php and js/tax_form.js; changelog updated
2026-10-17 13:00:54 -04:00

289 lines
15 KiB
PHP

<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_client', 2);
$client_id = intval($_GET['id']);
enforceClientAccess();
$sql = mysqli_query($mysqli, "SELECT client_abbreviation, client_archived_at, client_created_at, client_lead, client_name,
client_net_terms, client_notes, client_rate, client_reminders, client_referral, client_tax_id_number,
client_default_tax_id, client_tax_exempt, client_tax_exempt_number, client_tax_exempt_expires,
client_type, client_website FROM clients WHERE client_id = $client_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$client_tax_row = $row;
$client_name = escapeHtml($row['client_name']);
$client_is_lead = intval($row['client_lead']);
$client_type = escapeHtml($row['client_type']);
$client_website = escapeHtml($row['client_website']);
$client_referral = escapeHtml($row['client_referral']);
$client_net_terms = intval($row['client_net_terms']);
$client_reminders = intval($row['client_reminders'] ?? 1);
$client_tax_id_number = escapeHtml($row['client_tax_id_number']);
$client_abbreviation = escapeHtml($row['client_abbreviation']);
$client_rate = floatval($row['client_rate']);
$client_notes = escapeHtml($row['client_notes']);
$client_created_at = escapeHtml($row['client_created_at']);
$client_archived_at = escapeHtml($row['client_archived_at']);
// Client SLA assignments
$client_sla_assignments = [];
$sql_client_slas = mysqli_query($mysqli, "SELECT sla_assignment_priority, sla_assignment_sla_id FROM sla_assignments WHERE sla_assignment_client_id = $client_id");
while ($client_sla_row = mysqli_fetch_assoc($sql_client_slas)) {
$client_sla_assignments[$client_sla_row['sla_assignment_priority']] = intval($client_sla_row['sla_assignment_sla_id']);
}
// Client Tags
$client_tag_id_array = array();
$sql_client_tags = mysqli_query($mysqli, "SELECT tag_id FROM client_tags WHERE client_id = $client_id");
while ($row = mysqli_fetch_assoc($sql_client_tags)) {
$client_tag_id = intval($row['tag_id']);
$client_tag_id_array[] = $client_tag_id;
}
$net_terms_array = array (
'0'=>'On Receipt',
'7'=>'7 Days',
'10'=>'10 Days',
'15'=>'15 Days',
'30'=>'30 Days',
'45'=>'45 Days',
'60'=>'60 Days',
'90'=>'90 Days'
);
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class='fa fa-fw fa-user-edit me-2'></i>Editing Client: <strong><?= $client_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<ul class="modal-header nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-client-details<?= $client_id ?>">Details</a>
</li>
<?php if ($config_module_enable_accounting) { ?>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-client-billing<?= $client_id ?>">Billing</a>
</li>
<?php } ?>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-client-notes<?= $client_id ?>">Notes</a>
</li>
</ul>
<div class="modal-body">
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-client-details<?= $client_id ?>">
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong> / <span class="text-secondary">Is Lead</span></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-badge"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name or Company" maxlength="200"
value="<?= $client_name ?>" required>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="lead" value="1" <?php if($client_is_lead == 1){ echo "checked"; } ?>>
</div>
</div>
</div>
<div class="mb-3">
<label>Shortened Name</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-badge"></i></span>
<input type="text" class="form-control" name="abbreviation" placeholder="Shortened name for client - Max chars 6" value="<?= $client_abbreviation ?>" maxlength="6" oninput="this.value = this.value.toUpperCase()">
</div>
</div>
<div class="mb-3">
<label>Industry</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-briefcase"></i></span>
<input type="text" class="form-control" name="type" placeholder="Industry" maxlength="200"
value="<?= $client_type ?>">
</div>
</div>
<div class="mb-3">
<label>Referral</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-link"></i></span>
<select class="form-select select2" data-tags="true" name="referral">
<option value="">- Select Referral -</option>
<?php
$referral_sql = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories WHERE category_type = 'Referral' AND (category_archived_at > '$client_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($referral_sql)) {
$referral = escapeHtml($row['category_name']);
?>
<option <?php if ($client_referral == $referral) {
echo "selected";
} ?><?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>>
<?= $referral ?>
</option>
<?php
}
?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Referral">
<i class="fas fa-fw fa-plus"></i>
</button>
</div>
</div>
<div class="mb-3">
<label>Website</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
<input type="text" class="form-control" name="website" placeholder="ex. google.com" maxlength="200"
value="<?= $client_website ?>">
</div>
</div>
<div class="mb-3">
<label>Tags</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
<select class="form-select select2" name="tags[]" data-placeholder="Add some tags" multiple>
<?php
$sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, tag_icon FROM tags WHERE tag_type = 1 ORDER BY tag_name ASC");
while ($row = mysqli_fetch_assoc($sql_tags_select)) {
$tag_id_select = intval($row['tag_id']);
$tag_name_select = escapeHtml($row['tag_name']);
?>
<option value="<?= $tag_id_select ?>" <?php if (in_array($tag_id_select, $client_tag_id_array)) { echo "selected"; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= $tag_name_select ?></option>
<?php } ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New tag" type="button"
data-modal-url="../admin/modals/tag/tag_add.php?type=1">
<i class="fas fa-fw fa-plus"></i>
</button>
</div>
</div>
</div>
<?php if ($config_module_enable_accounting) { ?>
<div class="tab-pane fade" id="pills-client-billing<?= $client_id ?>">
<div class="mb-3">
<label>Hourly Rate</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
<input type="text" class="form-control" inputmode="decimal"
pattern="[0-9]*\.?[0-9]{0,2}" name="rate" placeholder="0.00"
value="<?= number_format($client_rate, 2, '.', '') ?>">
</div>
</div>
<div class="mb-3">
<label>Invoice Net Terms</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<select class="form-select select2" name="net_terms">
<option value="">- Net Terms -</option>
<?php foreach ($net_terms_array as $net_term_value => $net_term_name) { ?>
<option <?php if ($net_term_value == $client_net_terms) {
echo "selected";
} ?> value="<?= $net_term_value ?>">
<?= $net_term_name ?>
</option>
<?php } ?>
</select>
</div>
</div>
<div class="mb-3">
<label>Tax ID</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-balance-scale"></i></span>
<input type="text" class="form-control" name="tax_id_number" maxlength="255"
placeholder="Tax ID Number" value="<?= $client_tax_id_number ?>">
</div>
</div>
<?php
$client_tax = $client_tax_row;
$client_tax_key = $client_id;
require __DIR__ . '/client_tax_fields.php';
?>
<div class="mb-3">
<input type="hidden" name="reminders_field" value="1">
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" name="reminders" value="1" id="clientReminders<?= $client_id ?>" <?= $client_reminders ? 'checked' : '' ?>>
<label class="form-check-label" for="clientReminders<?= $client_id ?>">Payment reminders and statements</label>
</div>
<small class="text-secondary">Emailed as set in Invoice Settings. Off, this client gets neither - invoices can still be sent by hand.</small>
</div>
</div>
<?php } ?>
<div class="tab-pane fade" id="pills-client-notes<?= $client_id ?>">
<div class="mb-3">
<textarea class="form-control" rows="10" placeholder="Enter some notes" name="notes"><?= $client_notes ?></textarea>
</div>
<?php
// Ticket SLA assignments - only offered when active SLAs exist
$sla_options = [];
$sla_options_sql = mysqli_query($mysqli, "SELECT sla_id, sla_name FROM slas WHERE sla_archived_at IS NULL ORDER BY sla_name ASC");
while ($sla_option_row = mysqli_fetch_assoc($sla_options_sql)) {
$sla_options[intval($sla_option_row['sla_id'])] = $sla_option_row['sla_name'];
}
if ($config_module_enable_ticketing && !empty($sla_options)) { ?>
<div class="mb-3">
<label>Ticket SLAs</label>
<div class="row g-2">
<?php foreach (['Low', 'Medium', 'High', 'Urgent'] as $sla_priority) { $sla_current = $client_sla_assignments[$sla_priority] ?? 'default'; ?>
<div class="col-3">
<small class="text-secondary"><?= $sla_priority ?></small>
<select class="form-select" name="client_sla_<?= strtolower($sla_priority) ?>">
<option value="default" <?php if ($sla_current === 'default') { echo "selected"; } ?>>Default</option>
<option value="0" <?php if ($sla_current === 0) { echo "selected"; } ?>>None</option>
<?php foreach ($sla_options as $sla_option_id => $sla_option_name) { ?>
<option value="<?= $sla_option_id ?>" <?php if ($sla_current === $sla_option_id) { echo "selected"; } ?>><?= escapeHtml($sla_option_name) ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
</div>
<small class="text-muted">Default follows the global SLA assignment for each priority.</small>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="edit_client" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';