105 lines
4.6 KiB
PHP
105 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\AssetExchange\Http\Controllers;
|
|
|
|
use App\Business;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\AssetExchange\Http\Controllers\Concerns\AuthorizesAssetExchange;
|
|
use Modules\AssetExchange\Utils\AssetExchangeUtil;
|
|
|
|
class SettingsController extends Controller
|
|
{
|
|
use AuthorizesAssetExchange;
|
|
|
|
public function __construct(
|
|
protected AssetExchangeUtil $aexUtil
|
|
) {
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->authorizeAexAccess('aex.access');
|
|
|
|
$business_id = $this->aexUtil->getBusinessId();
|
|
$settings = array_merge($this->defaultSettings(), $this->aexUtil->getAexSettings($business_id));
|
|
|
|
return view('assetexchange::settings.index', compact('settings'));
|
|
}
|
|
|
|
public function update(Request $request)
|
|
{
|
|
$this->authorizeAexAccess('aex.access');
|
|
|
|
$business_id = $this->aexUtil->getBusinessId();
|
|
$existing = array_merge($this->defaultSettings(), $this->aexUtil->getAexSettings($business_id));
|
|
|
|
$data = $request->validate([
|
|
'listing_code_prefix' => 'nullable|string|max:20',
|
|
'appraisal_number_prefix' => 'nullable|string|max:20',
|
|
'deal_code_prefix' => 'nullable|string|max:20',
|
|
'valuation_method' => 'nullable|in:hybrid,replacement_cost,market_comp,depreciation',
|
|
'appraisal_fee_default' => 'nullable|integer|min:0',
|
|
'appraisal_valid_days' => 'nullable|integer|min:1|max:3650',
|
|
'default_commission_percent' => 'nullable|numeric|min:0|max:100',
|
|
'comp_pricing_method' => 'nullable|in:median,average',
|
|
'require_appraisal_before_deal' => 'sometimes|boolean',
|
|
'auto_create_cmms_on_acquire' => 'sometimes|boolean',
|
|
'portal_listings_enabled' => 'sometimes|boolean',
|
|
'auto_start_research_on_intake' => 'sometimes|boolean',
|
|
'inquiry_sla_hours' => 'nullable|integer|min:1|max:720',
|
|
'inquiry_sla_warning_percent' => 'nullable|integer|min:1|max:99',
|
|
'research_task_sla_days' => 'nullable|integer|min:1|max:365',
|
|
]);
|
|
|
|
$settings = array_merge($existing, [
|
|
'listing_code_prefix' => $data['listing_code_prefix'] ?? 'AEX',
|
|
'appraisal_number_prefix' => $data['appraisal_number_prefix'] ?? 'AAPR',
|
|
'deal_code_prefix' => $data['deal_code_prefix'] ?? 'ADL',
|
|
'valuation_method' => $data['valuation_method'] ?? 'hybrid',
|
|
'appraisal_fee_default' => (int) ($data['appraisal_fee_default'] ?? 0),
|
|
'appraisal_valid_days' => (int) ($data['appraisal_valid_days'] ?? 90),
|
|
'default_commission_percent' => (float) ($data['default_commission_percent'] ?? 0),
|
|
'comp_pricing_method' => $data['comp_pricing_method'] ?? 'median',
|
|
'require_appraisal_before_deal' => $request->boolean('require_appraisal_before_deal', true),
|
|
'auto_create_cmms_on_acquire' => $request->boolean('auto_create_cmms_on_acquire', true),
|
|
'portal_listings_enabled' => $request->boolean('portal_listings_enabled', false),
|
|
'auto_start_research_on_intake' => $request->boolean('auto_start_research_on_intake', true),
|
|
'inquiry_sla_hours' => (int) ($data['inquiry_sla_hours'] ?? 48),
|
|
'inquiry_sla_warning_percent' => (int) ($data['inquiry_sla_warning_percent'] ?? 75),
|
|
'research_task_sla_days' => (int) ($data['research_task_sla_days'] ?? 7),
|
|
]);
|
|
|
|
if (\Illuminate\Support\Facades\Schema::hasColumn('business', 'aex_settings')) {
|
|
Business::where('id', $business_id)->update([
|
|
'aex_settings' => json_encode($settings),
|
|
]);
|
|
}
|
|
|
|
return redirect()
|
|
->action([self::class, 'index'])
|
|
->with('status', __('assetexchange::lang.settings_saved'));
|
|
}
|
|
|
|
protected function defaultSettings(): array
|
|
{
|
|
return [
|
|
'listing_code_prefix' => 'AEX',
|
|
'appraisal_number_prefix' => 'AAPR',
|
|
'deal_code_prefix' => 'ADL',
|
|
'valuation_method' => 'hybrid',
|
|
'appraisal_fee_default' => 0,
|
|
'appraisal_valid_days' => 90,
|
|
'default_commission_percent' => 0,
|
|
'comp_pricing_method' => 'median',
|
|
'require_appraisal_before_deal' => true,
|
|
'auto_create_cmms_on_acquire' => true,
|
|
'portal_listings_enabled' => false,
|
|
'auto_start_research_on_intake' => true,
|
|
'inquiry_sla_hours' => 48,
|
|
'inquiry_sla_warning_percent' => 75,
|
|
'research_task_sla_days' => 7,
|
|
];
|
|
}
|
|
}
|