58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\AssetExchange\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\AssetExchange\Http\Controllers\Concerns\AuthorizesAssetExchange;
|
|
use Modules\AssetExchange\Models\Listing;
|
|
use Modules\AssetExchange\Services\PipelineService;
|
|
use Modules\AssetExchange\Utils\AssetExchangeUtil;
|
|
|
|
class PipelineController extends Controller
|
|
{
|
|
use AuthorizesAssetExchange;
|
|
|
|
public function __construct(
|
|
protected AssetExchangeUtil $aexUtil,
|
|
protected PipelineService $pipelineService
|
|
) {
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$this->authorizeAexAccess('aex.pipeline.view');
|
|
|
|
$business_id = $this->aexUtil->getBusinessId();
|
|
|
|
$listings = Listing::where('business_id', $business_id)
|
|
->whereNotIn('status', ['withdrawn'])
|
|
->with(['seller:id,name', 'broker:id,first_name,last_name,surname'])
|
|
->orderByDesc('updated_at')
|
|
->limit(200)
|
|
->get();
|
|
|
|
$board = [];
|
|
foreach (PipelineService::STAGES as $stage) {
|
|
$board[$stage] = [
|
|
'label' => PipelineService::STAGE_LABELS[$stage] ?? $stage,
|
|
'listings' => [],
|
|
];
|
|
}
|
|
|
|
foreach ($listings as $listing) {
|
|
$pipeline = $this->pipelineService->getPipelineForListing($listing);
|
|
$stage = $pipeline['current_stage'] ?? 'draft_listing';
|
|
if (! isset($board[$stage])) {
|
|
$stage = 'draft_listing';
|
|
}
|
|
$board[$stage]['listings'][] = [
|
|
'listing' => $listing,
|
|
'pipeline' => $pipeline,
|
|
];
|
|
}
|
|
|
|
return view('assetexchange::pipeline.index', compact('board'));
|
|
}
|
|
}
|