- Upgraded all plain `require` to `require_once` across 172 api/engine and api/engine_report files to prevent class-redeclaration errors - Added issue button, issue_invoice() with GL toastr, and delete_invoice() to expense/manage_purchase_invoice.php, bringing it in line with po/manage_purchase_invoice.php - Added can_delete role guard (admin/owner only) to trash icons on revenue/invoice.php and expense/purchase_invoice.php, matching the existing pattern in finance/receipt.php and finance/payment.php Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
2.3 KiB
PHP
47 lines
2.3 KiB
PHP
<?php
|
|
session_start();
|
|
require_once '../../../assets/utils/db_auth.php';
|
|
require_once '../../../assets/utils/classes/CompanyProfileManager.php';
|
|
|
|
if ($user_role !== 'owner') { http_response_code(403); exit(json_encode(['success' => 0, 'message' => 'Only the owner can modify this setting.'])); }
|
|
|
|
try {
|
|
$companyProfile = new CompanyProfileManager($pdo1, $company_id);
|
|
|
|
// ── Fetch current image filenames from DB ─────────────────────────────
|
|
$current = $companyProfile->getProfile();
|
|
|
|
// ── Upload directory ──────────────────────────────────────────────────
|
|
$upload_dir = $include_url . 'uploads/company/';
|
|
if (!is_dir($upload_dir)) {
|
|
mkdir($upload_dir, 0755, true);
|
|
}
|
|
|
|
// ── Process images ────────────────────────────────────────────────────
|
|
$logo_action = $data['logo_action'] ?? 'keep';
|
|
$seal_action = $data['seal_action'] ?? 'keep';
|
|
|
|
$new_logo = $companyProfile->handleImageSlot('company_logo', $logo_action, $current['company_logo'] ?? '', $upload_dir, 'logo_');
|
|
$new_seal = $companyProfile->handleImageSlot('company_seal', $seal_action, $current['company_seal'] ?? '', $upload_dir, 'seal_');
|
|
|
|
// ── Persist company profile ───────────────────────────────────────────
|
|
$companyProfile->saveProfile($data, $new_logo, $new_seal);
|
|
|
|
$answer['success'] = 1;
|
|
$answer['message'] = 'Company profile saved.';
|
|
|
|
// Return new filenames only if they changed so client can refresh previews
|
|
if ($logo_action !== 'keep') $answer['company_logo'] = $new_logo;
|
|
if ($seal_action !== 'keep') $answer['company_seal'] = $new_seal;
|
|
|
|
} catch (RuntimeException $e) {
|
|
$answer['message'] = $e->getMessage();
|
|
http_response_code(422);
|
|
} catch (Exception $e) {
|
|
$answer['message'] = 'Failed to save company profile.';
|
|
http_response_code(500);
|
|
}
|
|
|
|
exit(json_encode($answer));
|
|
?>
|