<?php
namespace App\Nova;
use Carbon\Carbon;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;
//use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Number;
use Illuminate\Http\Request;
use App\Nova\Actions\DownloadExcel;
use App\Traits\NovaSearchesRelationsWithArrays;
use PositionPicker\PositionPicker;
class Position extends Resource
{
use NovaSearchesRelationsWithArrays;
public static $searchRelations = [
'user' => [
'name',
'surname',
['surname', 'name'],
],
];
public static $searchRelationsGlobally = false;
public static $model = 'App\Position';
public static $title = 'id';
public static $search = [
'id',
];
public static function label()
{
return 'Должности';
}
public static $with = [
'user',
'department',
'company',
'leader',
'positionName',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Статус', function () {
return $this->status;
}),
BelongsTo::make('Человек', 'user', 'App\Nova\User')->searchable()->prepopulate(),
BelongsTo::make('Отдел', 'department', 'App\Nova\Department')
->searchable()
->prepopulate()
,
PositionPicker::make('Должность', 'positionName', 'App\Nova\PositionName')
->nullable(),
BelongsTo::make('Руководитель', 'leader', 'App\Nova\User')
->searchable()
->nullable(),
BelongsTo::make('Компания', 'company', 'App\Nova\Company')
->searchable()
->prepopulate()
->nullable(),
BelongsTo::make('Вид договора', 'contractType', 'App\Nova\ContractType')
->hideFromIndex(),
Date\Date::make('Дата приёма', 'employment_date')
// ->format('DD.MM.Y')
->nullable()
->hideFromIndex(),
Text::make('Стаж', function () {
if ($first = $this->employment_date) {
$second = $this->dissmissal_date ?? Carbon::today();
return ru_year_month_interval($first->diffInMonths($second));
}
return '—';
})->OnlyOnDetail(),
Date\Date::make('Контрольный срок', 'control_date')
// ->format('DD.MM.Y')
->nullable()
->hideFromIndex(),
Text::make('IP Телефон', 'phone_ip_number')
->rules('max:50')
->hideFromIndex(),
Number::make('Срок подбора', 'recruitment_term')
->step(1)
->hideFromIndex(),
BelongsTo::make('Канал подбора', 'recruitmentChannel', 'App\Nova\RecruitmentChannel')
->searchable()
->prepopulate()
->nullable()
->hideFromIndex(),
Textarea::make('Комментарий подбора', 'recruitment_channel_comment')
->alwaysShow(),
BelongsTo::make('Рекрутёр', 'recruiter', 'App\Nova\User')
->searchable()
->nullable()
->hideFromIndex(),
Date\Date::make('Дата увольнения', 'dissmissal_date')
// ->format('DD.MM.Y')
->nullable()
->hideFromIndex(),
Select::make('Причина увольнения', 'dissmissal_reason')
->options(dissmissal_reason_map())
->displayUsingLabels()
->sortable()
->hideFromIndex(),
Textarea::make('Комментарий', 'dissmissal_comment')
->alwaysShow(),
Boolean::make('Экспортировать в Wiki', 'show_on_wiki')
->hideFromIndex(),
DateTime::make('Последнее изменение', 'updated_at')->onlyOnDetail(),
BelongsTo::make('Последний изменивший', 'updatedBy', 'App\Nova\User')->onlyOnDetail(),
];
}
public function filters(Request $request)
{
return [
new Filters\DepartmentFilter,
new Filters\CompanyFilter,
new Filters\ContractTypeFilter,
new Filters\PositionCategoryFilter,
new Filters\DistributionGroupFilter,
new Filters\WorkExperienceFilter,
new Filters\PositionStatusFilter,
];
}
public function lenses(Request $request)
{
return [
new Lenses\PositionControlDates(new \App\Position),
];
}
public function actions(Request $request)
{
dd($request);
return =
[new DownloadExcel(
[
'user' => 'Сотрудник',
'user_email' => 'Почта',
'company' => 'Компания',
'department' => 'Отдел',
'positionName' => 'Должность',
'positionCategory' => 'Категория сотрудника',
'contractType' => 'Вид договора',
'leader' => 'Руководитель',
'control_date' => 'Контрольный срок',
'employment_date' => 'Дата приёма',
'dissmissal_date' => 'Дата увольнения',
'dissmissal_reason' => 'Причина увольнения',
'dissmissal_comment' => 'Комментарий',
'recruitment_term' => 'Срок подбора',
'recruitmentChannel' => 'Канал подбора',
'recruitment_channel_comment' => 'Комментарий подбора',
'recruiter' => 'Рекрутёр',
'distribution_group' => 'Группа рассылки',
],
'positions',
['control_date', 'employment_date', 'dissmissal_date'],
[
'user' => 'fio',
'user_email' => ['user', 'email'],
'company' => 'name',
'department' => 'name',
'positionName' => 'name',
'positionCategory' => ['positionName', 'positionCategoryName'],
'distribution_group' => ['positionName', 'distributionGroupName'],
'contractType' => 'name',
'leader' => 'fio',
'recruitmentChannel' => 'name',
'recruiter' => 'fio',
],
[
// 'distribution_group' => distribution_group_map(),
'dissmissal_reason' => dissmissal_reason_map(),
]
),
];
}
}