company settings update
This commit is contained in:
parent
a2a8ca4262
commit
c8a94f29c5
264
company_settings.php
Normal file
264
company_settings.php
Normal file
@ -0,0 +1,264 @@
|
||||
<?php
|
||||
/**
|
||||
* Company Preferences - Identity & Settings
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$success = false;
|
||||
$error = '';
|
||||
|
||||
// Canadian Provinces
|
||||
$provinces = [
|
||||
'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba',
|
||||
'NB' => 'New Brunswick', 'NL' => 'Newfoundland and Labrador', 'NS' => 'Nova Scotia',
|
||||
'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec',
|
||||
'SK' => 'Saskatchewan', 'NT' => 'Northwest Territories', 'NU' => 'Nunavut', 'YT' => 'Yukon'
|
||||
];
|
||||
|
||||
// Business Sectors
|
||||
$sectors = [
|
||||
'Telecommunications', 'Information Technology', 'Professional Services',
|
||||
'Manufacturing', 'Construction', 'Retail', 'Healthcare', 'Energy', 'Other'
|
||||
];
|
||||
|
||||
// Handle Form Submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$company_name = $_POST['company_name'] ?? '';
|
||||
$address_1 = $_POST['address_1'] ?? '';
|
||||
$address_2 = $_POST['address_2'] ?? '';
|
||||
$city = $_POST['city'] ?? '';
|
||||
$province = $_POST['province'] ?? '';
|
||||
$postal_code = $_POST['postal_code'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$phone_2 = $_POST['phone_2'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$website = $_POST['website'] ?? '';
|
||||
$fiscal_year_end = $_POST['fiscal_year_end'] ?: null;
|
||||
$business_number = $_POST['business_number'] ?? '';
|
||||
$timezone = $_POST['timezone'] ?? '';
|
||||
$sector = $_POST['sector'] ?? '';
|
||||
$notifications_enabled = isset($_POST['notifications_enabled']) ? 1 : 0;
|
||||
|
||||
// Handle Logo Upload
|
||||
$logo_path = $_POST['current_logo'] ?? '';
|
||||
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
|
||||
$upload_dir = __DIR__ . '/assets/images/logo/';
|
||||
if (!is_dir($upload_dir)) {
|
||||
mkdir($upload_dir, 0775, true);
|
||||
}
|
||||
$ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION);
|
||||
$filename = 'company_logo_' . time() . '.' . $ext;
|
||||
$target = $upload_dir . $filename;
|
||||
|
||||
if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) {
|
||||
$logo_path = 'assets/images/logo/' . $filename;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = db()->prepare("
|
||||
UPDATE company_settings
|
||||
SET company_name = ?, address_1 = ?, address_2 = ?, city = ?, province = ?,
|
||||
postal_code = ?, phone = ?, phone_2 = ?, email = ?, website = ?,
|
||||
fiscal_year_end = ?, business_number = ?, timezone = ?, sector = ?,
|
||||
notifications_enabled = ?, logo_path = ?
|
||||
WHERE id = 1
|
||||
");
|
||||
$stmt->execute([
|
||||
$company_name, $address_1, $address_2, $city, $province,
|
||||
$postal_code, $phone, $phone_2, $email, $website,
|
||||
$fiscal_year_end, $business_number, $timezone, $sector,
|
||||
$notifications_enabled, $logo_path
|
||||
]);
|
||||
$success = true;
|
||||
} catch (PDOException $e) {
|
||||
$error = "Error updating settings: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch Current Settings
|
||||
$settings = db()->query("SELECT * FROM company_settings WHERE id = 1")->fetch();
|
||||
|
||||
$pageTitle = "SR&ED Manager - Company Preferences";
|
||||
include __DIR__ . '/includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container py-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-10">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<div>
|
||||
<h2 class="fw-bold mb-1">Company Preferences</h2>
|
||||
<p class="text-muted">Manage your business identity and application-wide settings.</p>
|
||||
</div>
|
||||
<a href="settings.php" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-arrow-left me-1"></i> Back to Settings
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
|
||||
<i class="bi bi-check-circle-fill me-2"></i> Settings updated successfully!
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
|
||||
<i class="bi bi-exclamation-triangle-fill me-2"></i> <?= htmlspecialchars($error) ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" enctype="multipart/form-data" class="row g-4">
|
||||
<input type="hidden" name="current_logo" value="<?= htmlspecialchars($settings['logo_path'] ?? '') ?>">
|
||||
|
||||
<!-- Identity Card -->
|
||||
<div class="col-12">
|
||||
<div class="card border-0 shadow-sm overflow-hidden">
|
||||
<div class="card-header bg-white py-3 border-bottom">
|
||||
<h5 class="mb-0 fw-bold">Company Identity</h5>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-8">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold">Company Legal Name</label>
|
||||
<input type="text" name="company_name" class="form-control" value="<?= htmlspecialchars($settings['company_name'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label small fw-bold">Sector</label>
|
||||
<select name="sector" class="form-select">
|
||||
<option value="">Select Sector...</option>
|
||||
<?php foreach ($sectors as $s): ?>
|
||||
<option value="<?= $s ?>" <?= ($settings['sector'] ?? '') === $s ? 'selected' : '' ?>><?= $s ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label small fw-bold">Business Number (CRA)</label>
|
||||
<input type="text" name="business_number" class="form-control" value="<?= htmlspecialchars($settings['business_number'] ?? '') ?>" placeholder="e.g. 123456789 RT 0001">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 text-center">
|
||||
<label class="form-label small fw-bold d-block">Company Logo</label>
|
||||
<div class="mb-2">
|
||||
<?php if (!empty($settings['logo_path'])): ?>
|
||||
<img src="<?= htmlspecialchars($settings['logo_path']) ?>" alt="Logo" class="img-thumbnail mb-2" style="max-height: 120px;">
|
||||
<?php else: ?>
|
||||
<div class="bg-light rounded d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 120px; height: 120px;">
|
||||
<i class="bi bi-image text-muted fs-1"></i>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<input type="file" name="logo" class="form-control form-control-sm" accept="image/*">
|
||||
<p class="extra-small text-muted mt-2">Recommended: PNG or SVG with transparent background.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Contact & Address Card -->
|
||||
<div class="col-md-7">
|
||||
<div class="card border-0 shadow-sm h-100">
|
||||
<div class="card-header bg-white py-3 border-bottom">
|
||||
<h5 class="mb-0 fw-bold">Address & Contact Info</h5>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold">Address Line 1</label>
|
||||
<input type="text" name="address_1" class="form-control" value="<?= htmlspecialchars($settings['address_1'] ?? '') ?>" placeholder="Street address, P.O. box, company name, c/o">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold">Address Line 2 (Optional)</label>
|
||||
<input type="text" name="address_2" class="form-control" value="<?= htmlspecialchars($settings['address_2'] ?? '') ?>" placeholder="Apartment, suite, unit, building, floor, etc.">
|
||||
</div>
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold">City</label>
|
||||
<input type="text" name="city" class="form-control" value="<?= htmlspecialchars($settings['city'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small fw-bold">Province</label>
|
||||
<select name="province" class="form-select">
|
||||
<option value="">--</option>
|
||||
<?php foreach ($provinces as $code => $name): ?>
|
||||
<option value="<?= $code ?>" <?= ($settings['province'] ?? '') === $code ? 'selected' : '' ?>><?= $code ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small fw-bold">Postal Code</label>
|
||||
<input type="text" name="postal_code" class="form-control" value="<?= htmlspecialchars($settings['postal_code'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-4">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold">Primary Phone</label>
|
||||
<input type="tel" name="phone" class="form-control" value="<?= htmlspecialchars($settings['phone'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold">Secondary Phone</label>
|
||||
<input type="tel" name="phone_2" class="form-control" value="<?= htmlspecialchars($settings['phone_2'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold">Email Address</label>
|
||||
<input type="email" name="email" class="form-control" value="<?= htmlspecialchars($settings['email'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold">Website</label>
|
||||
<input type="url" name="website" class="form-control" value="<?= htmlspecialchars($settings['website'] ?? '') ?>" placeholder="https://">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Operations Card -->
|
||||
<div class="col-md-5">
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-white py-3 border-bottom">
|
||||
<h5 class="mb-0 fw-bold">Operations</h5>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<div class="mb-4">
|
||||
<label class="form-label small fw-bold text-primary">Fiscal Year End</label>
|
||||
<input type="date" name="fiscal_year_end" class="form-control border-primary shadow-sm" value="<?= htmlspecialchars($settings['fiscal_year_end'] ?? '') ?>">
|
||||
<p class="extra-small text-muted mt-2">Important: This date is used for tax reporting and financial summaries.</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label small fw-bold">Application Timezone</label>
|
||||
<select name="timezone" class="form-select">
|
||||
<option value="America/Toronto" <?= ($settings['timezone'] ?? '') === 'America/Toronto' ? 'selected' : '' ?>>Eastern Time (ET)</option>
|
||||
<option value="America/Winnipeg" <?= ($settings['timezone'] ?? '') === 'America/Winnipeg' ? 'selected' : '' ?>>Central Time (CT)</option>
|
||||
<option value="America/Edmonton" <?= ($settings['timezone'] ?? '') === 'America/Edmonton' ? 'selected' : '' ?>>Mountain Time (MT)</option>
|
||||
<option value="America/Vancouver" <?= ($settings['timezone'] ?? '') === 'America/Vancouver' ? 'selected' : '' ?>>Pacific Time (PT)</option>
|
||||
<option value="America/Halifax" <?= ($settings['timezone'] ?? '') === 'America/Halifax' ? 'selected' : '' ?>>Atlantic Time (AT)</option>
|
||||
<option value="America/St_Johns" <?= ($settings['timezone'] ?? '') === 'America/St_Johns' ? 'selected' : '' ?>>Newfoundland Time (NT)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-check form-switch p-3 bg-light rounded shadow-sm border">
|
||||
<input class="form-check-input ms-0 me-2" type="checkbox" name="notifications_enabled" id="notifSwitch" <?= ($settings['notifications_enabled'] ?? 1) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label fw-bold small" for="notifSwitch">Enable Company-wide Notifications</label>
|
||||
<p class="extra-small text-muted mb-0 mt-1">Global toggle for email alerts and system notifications.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2">
|
||||
<button type="submit" class="btn btn-primary btn-lg shadow-sm py-3 fw-bold rounded-3">
|
||||
<i class="bi bi-save me-2"></i> Save All Changes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include __DIR__ . '/includes/footer.php'; ?>
|
||||
24
db/migrations/004_company_settings.sql
Normal file
24
db/migrations/004_company_settings.sql
Normal file
@ -0,0 +1,24 @@
|
||||
CREATE TABLE IF NOT EXISTS company_settings (
|
||||
id INT PRIMARY KEY DEFAULT 1,
|
||||
company_name VARCHAR(255),
|
||||
address_1 VARCHAR(255),
|
||||
address_2 VARCHAR(255),
|
||||
city VARCHAR(100),
|
||||
province VARCHAR(100),
|
||||
postal_code VARCHAR(20),
|
||||
phone VARCHAR(20),
|
||||
phone_2 VARCHAR(20),
|
||||
email VARCHAR(255),
|
||||
website VARCHAR(255),
|
||||
fiscal_year_end DATE,
|
||||
business_number VARCHAR(100),
|
||||
timezone VARCHAR(100),
|
||||
sector VARCHAR(100),
|
||||
notifications_enabled TINYINT(1) DEFAULT 1,
|
||||
logo_path VARCHAR(255),
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT single_row CHECK (id = 1)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- Initialize with default values if not exists
|
||||
INSERT IGNORE INTO company_settings (id, company_name) VALUES (1, 'My ERP Company');
|
||||
@ -67,11 +67,12 @@ $currentPage = basename($_SERVER['PHP_SELF']);
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle <?= in_array($currentPage, ['settings.php', 'system_preferences.php', 'import_suppliers.php', 'import_expenses.php', 'import_labour.php']) ? 'active' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
|
||||
<a class="nav-link dropdown-toggle <?= in_array($currentPage, ['settings.php', 'company_settings.php', 'system_preferences.php', 'import_suppliers.php', 'import_expenses.php', 'import_labour.php']) ? 'active' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
|
||||
Settings
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-menu-item dropdown-item" href="settings.php">Datasets</a></li>
|
||||
<li><a class="dropdown-menu-item dropdown-item" href="company_settings.php">Company Preferences</a></li>
|
||||
<li><a class="dropdown-menu-item dropdown-item" href="system_preferences.php">System Preferences</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-menu-item dropdown-item" href="import_suppliers.php">Import Suppliers</a></li>
|
||||
|
||||
12
settings.php
12
settings.php
@ -256,6 +256,18 @@ include __DIR__ . '/includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Company Configuration -->
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100 border-0 shadow-sm text-white" style="background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);">
|
||||
<div class="card-body d-flex flex-column justify-content-center align-items-center text-center py-5">
|
||||
<i class="bi bi-building fs-1 mb-3"></i>
|
||||
<h5 class="fw-bold">Company Preferences</h5>
|
||||
<p class="small mb-4 opacity-75">Configure your company identity, logo, fiscal year end, and notification settings.</p>
|
||||
<a href="company_settings.php" class="btn btn-light px-4 rounded-pill fw-bold">Manage Company Info</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user