store-manage/app/Admin/Controllers/Hr/OvertimeController.php

137 lines
7.0 KiB
PHP

<?php
namespace App\Admin\Controllers\Hr;
use App\Admin\Controllers\AdminController;
use App\Admin\Services\OvertimeApplyService;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Admin;
use App\Enums\{CheckStatus, EmployeeStatus};
use App\Models\OvertimeApply;
use App\Traits\HasCheckActions;
/**
* 加班管理
*/
class OvertimeController extends AdminController
{
use HasCheckActions;
protected string $serviceName = OvertimeApplyService::class;
public function list(): Page
{
$crud = $this->baseCRUD()
->tableLayout('fixed')
->headerToolbar([
$this->createTypeButton('drawer', 'xl')->visible(Admin::user()->can('admin.hr.overtime.create')),
...$this->baseHeaderToolBar(),
])
->bulkActions([])
->filter($this->baseFilter()->body([
amis()->GroupControl()->mode('horizontal')->body([
amisMake()->SelectControl()->name('store_id')->label(__('overtime_apply.store_id'))
->source(admin_url('api/stores?_all=1'))
->labelField('title')
->valueField('id')
->searchable()
->columnRatio(3)
->clearable(),
amisMake()->TextControl()->name('employee_name')->label(__('overtime_apply.employee_id'))
->placeholder(__('employee.name').'/'.__('employee.phone'))
->columnRatio(3)
->clearable(),
amisMake()->DateRangeControl()->name('date_range')->label(__('overtime_apply.date'))
->columnRatio(3)
->clearable(),
amisMake()->SelectControl()->name('check_status')->label(__('overtime_apply.check_status'))
->options(CheckStatus::options())
->columnRatio(3)
->clearable(),
]),
]))
->columns([
amisMake()->TableColumn()->name('store.title')->label(__('overtime_apply.store_id')),
amisMake()->TableColumn()->name('employee.name')->label(__('overtime_apply.employee_id')),
amisMake()->TableColumn()->name('date')->label(__('overtime_apply.date')),
amisMake()->TableColumn()->name('hours')->label(__('overtime_apply.hours')),
amisMake()->TableColumn()->name('workflow.check_status')->label(__('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::options()),
amisMake()->TableColumn()->name('created_at')->label(__('overtime_apply.created_at')),
$this->rowActions([
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.overtime.view')),
$this->rowEditTypeButton('drawer', 'xl')
->visible(Admin::user()->can('admin.hr.overtime.update'))
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
$this->rowDeleteButton()
->visible(Admin::user()->can('admin.hr.overtime.delete'))
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
$this->applyAction(),
$this->cancelAction(),
]),
]);
return $this->baseList($crud);
}
public function form($edit): Form
{
return $this->baseForm()->title('')->body([
amisMake()->SelectControl()->name('employee_id')->label(__('overtime_apply.employee_id'))
->source(admin_url('api/employees?_all=1&store_id_gt=0&employee_status='.EmployeeStatus::Online->value))
->labelField('name')
->valueField('id')
->searchable()
->joinValues(false)
->extractValue()
->required(),
amisMake()->InputDatetimeRange()
->name('datetime_range')
->label(__('overtime_apply.date'))
->required(),
amisMake()->TextControl()->name('reason')->label(__('overtime_apply.reason')),
]);
}
public function detail(): Form
{
$detail = amisMake()->Property()->items([
['label' => __('overtime_apply.store_id'), 'content' => '${store.title}'],
['label' => __('overtime_apply.employee_id'), 'content' => '${employee.name}'],
['label' => __('overtime_apply.date'), 'content' => '${date}'],
['label' => __('overtime_apply.start_at'), 'content' => '${start_at}'],
['label' => __('overtime_apply.end_at'), 'content' => '${end_at}'],
['label' => __('overtime_apply.hours'), 'content' => '${hours}'],
['label' => __('overtime_apply.created_at'), 'content' => '${created_at}'],
['label' => __('overtime_apply.reason'), 'content' => '${reason}', 'span' => 2],
['label' => __('workflow_log.check_status'), 'content' => amisMake()->Mapping()->name('workflow.check_status')->map(CheckStatus::options())],
['label' => __('workflow_log.checked_at'), 'content' => '${workflow.checked_at}'],
['label' => __('workflow_log.remarks'), 'content' => '${workflow.check_remarks}'],
]);
$table = amisMake()->Service()
->id('overtime-checklog-table')
->initFetch(false)
->api(admin_url('api/workflow/logs') . '?id=${workflow.id}')
->body(
amisMake()->Table()->columnsTogglable(false)->itemActions([
$this->succesAction()->reload('overtime-detail'),
$this->failAction()->reload('overtime-detail'),
])->columns([
amisMake()->TableColumn()->name('batch_id')->label(__('workflow_log.batch_id')),
amisMake()->TableColumn()->name('check_name')->label(__('workflow_log.check_name')),
amisMake()->TableColumn()->name('check_user.name')->label(__('workflow_log.check_user_id')),
amisMake()->TableColumn()->name('check_status')->label(__('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::options()),
amisMake()->TableColumn()->name('checked_at')->label(__('workflow_log.checked_at')),
amisMake()->TableColumn()->name('remarks')->label(__('workflow_log.remarks')),
])
);
return $this->baseDetail()->id('overtime-detail')->title('')->onEvent([
'inited' => [
'actions' => [
['actionType' => 'reload', 'componentId' => 'overtime-checklog-table'],
]
]
])->body([$detail, amisMake()->Divider(), $table]);
}
}