75 lines
2.7 KiB
PHP
75 lines
2.7 KiB
PHP
<?php
|
||
|
||
namespace Leantime\Domain\Bom\Controllers;
|
||
|
||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||
use Leantime\Core\Controller\Controller;
|
||
use Leantime\Domain\Bom\Permissions\BomPermissions;
|
||
use Leantime\Domain\Bom\Services\Bom as BomService;
|
||
use Leantime\Domain\Bom\Services\MasterRef as MasterRefService;
|
||
use Symfony\Component\HttpFoundation\Response;
|
||
|
||
/**
|
||
* 项目引用视图:项目里查看已引用的全局主数据(BOM/工艺文件/工具清单),
|
||
* 并叠加项目级追加列(日期/库存/采购数量等),追加列只存引用层,不回写全局。
|
||
*
|
||
* 路由约定(Frontcontroller 默认 /module/action):
|
||
* GET /bom/refs 项目已引用的主数据列表
|
||
* GET /bom/refs/{id} 单个引用视图(主数据 + 项目级追加列)
|
||
*/
|
||
class Refs extends Controller
|
||
{
|
||
private BomService $bomService;
|
||
private MasterRefService $masterRefService;
|
||
|
||
public function init(BomService $bomService, MasterRefService $masterRefService): void
|
||
{
|
||
$this->bomService = $bomService;
|
||
$this->masterRefService = $masterRefService;
|
||
}
|
||
|
||
#[RequiresPermission(BomPermissions::VIEW)]
|
||
public function get(array $params): Response
|
||
{
|
||
$projectId = (int) session('currentProject');
|
||
$refId = isset($params['id']) ? (int) $params['id'] : 0;
|
||
|
||
// 单个引用视图
|
||
if ($refId > 0) {
|
||
$refDetail = $this->masterRefService->getRefDetail($refId);
|
||
if ($refDetail === false) {
|
||
$this->tpl->setNotification($this->language->__('notification.bom_not_found', '引用不存在'), 'error');
|
||
|
||
return $this->tpl->display('bom.refs', 'app', 404);
|
||
}
|
||
|
||
$master = $this->bomService->getBomDetail((int) $refDetail['ref']['masterId']);
|
||
|
||
$this->tpl->assign('ref', $refDetail['ref']);
|
||
$this->tpl->assign('refColumns', $refDetail['columns']);
|
||
$this->tpl->assign('refValues', $refDetail['values']);
|
||
$this->tpl->assign('master', $master);
|
||
$this->tpl->assign('fixedColumns', BomService::FIXED_COLUMNS);
|
||
$this->tpl->assign('projectId', $projectId);
|
||
|
||
return $this->tpl->display('bom.refDetail');
|
||
}
|
||
|
||
// 项目已引用列表
|
||
$refs = $this->masterRefService->getRefs($projectId);
|
||
$list = [];
|
||
foreach ($refs as $ref) {
|
||
$master = $this->bomService->getBom((int) $ref['masterId']);
|
||
if ($master !== false) {
|
||
$ref['master'] = $master;
|
||
$list[] = $ref;
|
||
}
|
||
}
|
||
|
||
$this->tpl->assign('refs', $list);
|
||
$this->tpl->assign('projectId', $projectId);
|
||
|
||
return $this->tpl->display('bom.refs');
|
||
}
|
||
}
|