User company addded
This commit is contained in:
3
F.MD
Normal file
3
F.MD
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Fuck your feelings, no one cares. Fuck you. Prove yourself mother fucker.
|
||||||
|
|
||||||
|
Make user companies better. Move to "Company" navigation at the moment.
|
||||||
@@ -3,21 +3,27 @@
|
|||||||
namespace App\Filament\Resources\Company;
|
namespace App\Filament\Resources\Company;
|
||||||
|
|
||||||
use App\Filament\Resources\Company\UserCompanyResource\Pages;
|
use App\Filament\Resources\Company\UserCompanyResource\Pages;
|
||||||
|
use App\Modules\Bank\Repositories\BankRepository;
|
||||||
use App\Modules\UserCompany\Models\UserCompany;
|
use App\Modules\UserCompany\Models\UserCompany;
|
||||||
use App\Modules\UserCompany\Types\CompanyType;
|
use App\Modules\UserCompany\Types\CompanyType;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Columns\ToggleColumn;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
class UserCompanyResource extends Resource
|
class UserCompanyResource extends Resource
|
||||||
{
|
{
|
||||||
protected static ?string $model = UserCompany::class;
|
protected static ?string $model = UserCompany::class;
|
||||||
|
|
||||||
protected static ?string $navigationIcon = 'heroicon-o-briefcase';
|
protected static ?string $navigationGroup = 'Company';
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-building-office';
|
||||||
|
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
@@ -30,6 +36,9 @@ class UserCompanyResource extends Resource
|
|||||||
->default(CompanyType::default())
|
->default(CompanyType::default())
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
|
TextInput::make('name')
|
||||||
|
->required(),
|
||||||
|
|
||||||
TextInput::make('ssb')
|
TextInput::make('ssb')
|
||||||
->label('Şahsy salgyt belgisi')
|
->label('Şahsy salgyt belgisi')
|
||||||
->unique(ignoreRecord: true)
|
->unique(ignoreRecord: true)
|
||||||
@@ -41,10 +50,15 @@ class UserCompanyResource extends Resource
|
|||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
Select::make('bank_id')
|
Select::make('bank_id')
|
||||||
->relationship(name: 'bank', titleAttribute: 'name')
|
->label('Bank')
|
||||||
|
->native(false)
|
||||||
|
->options(BankRepository::make()->options())
|
||||||
->searchable()
|
->searchable()
|
||||||
->preload()
|
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
|
Toggle::make('default')
|
||||||
|
->default(false)
|
||||||
|
->label('Is default'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,14 +68,20 @@ class UserCompanyResource extends Resource
|
|||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('company_type')
|
TextColumn::make('company_type')
|
||||||
->badge()
|
->badge()
|
||||||
->formatStateUsing(fn (string $state): string => CompanyType::options()[$state])
|
->formatStateUsing(fn (string $state): string => CompanyType::option($state))
|
||||||
->color(fn (string $state): string => CompanyType::statusClass($state)),
|
->color(fn (string $state): string => CompanyType::statusClass($state)),
|
||||||
// 'ssb'
|
|
||||||
// 'hb'
|
TextColumn::make('ssb')
|
||||||
// 'bank_id'
|
->label('Şahsy salgyt belgisi')
|
||||||
|
->searchable(),
|
||||||
|
|
||||||
|
TextColumn::make('hb')
|
||||||
|
->label('HB'),
|
||||||
|
|
||||||
|
ToggleColumn::make('default'),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
//
|
Filter::make('default'),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal file
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\AppHelpers\Repositories;
|
||||||
|
|
||||||
|
class CacheRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cache name
|
||||||
|
*/
|
||||||
|
protected string $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value
|
||||||
|
*/
|
||||||
|
protected mixed $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time
|
||||||
|
*/
|
||||||
|
protected int $time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache repo
|
||||||
|
*/
|
||||||
|
public function __construct(string $name, mixed $value, int $time = 600)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->value = $value;
|
||||||
|
$this->time = $time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache Repo
|
||||||
|
*
|
||||||
|
* @param string $name key
|
||||||
|
* @param mixed $value value
|
||||||
|
* @param int|int $time time in seconds
|
||||||
|
*/
|
||||||
|
public static function make(string $name, mixed $value, int $time = 600): mixed
|
||||||
|
{
|
||||||
|
$repo = new self($name, $value, $time);
|
||||||
|
|
||||||
|
return $repo->handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle cache
|
||||||
|
*/
|
||||||
|
public function handle(): mixed
|
||||||
|
{
|
||||||
|
return cache()->has($this->name)
|
||||||
|
? cache($this->name)
|
||||||
|
: cache()->remember(
|
||||||
|
key: $this->name,
|
||||||
|
ttl: $this->time,
|
||||||
|
callback: fn () => is_callable($this->value) ? call_user_func($this->value) : $this->value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forget the key from cache
|
||||||
|
*/
|
||||||
|
public static function forget(string $name): void
|
||||||
|
{
|
||||||
|
cache()->forget($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,4 +2,44 @@
|
|||||||
|
|
||||||
namespace App\Modules\Bank\Repositories;
|
namespace App\Modules\Bank\Repositories;
|
||||||
|
|
||||||
class BankRepository {}
|
use App\Modules\AppHelpers\Repositories\CacheRepository;
|
||||||
|
use App\Modules\Bank\Models\Bank;
|
||||||
|
use App\Modules\Makeable;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class BankRepository
|
||||||
|
{
|
||||||
|
use Makeable;
|
||||||
|
|
||||||
|
/** @var Builder<Bank> */
|
||||||
|
protected Builder $query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache name
|
||||||
|
*/
|
||||||
|
protected static string $cacheName = 'BANK_REPOSITORY';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank repository
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->query = Bank::query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return available options
|
||||||
|
*
|
||||||
|
* @return Collection<array-key, mixed>|array<string, string>
|
||||||
|
*/
|
||||||
|
public function options(): Collection|array
|
||||||
|
{
|
||||||
|
return CacheRepository::make(
|
||||||
|
name: static::$cacheName.'_options',
|
||||||
|
value: fn () => $this->query->get(['id', 'name', 'bab'])->mapWithKeys(fn ($item) => [
|
||||||
|
$item->id => $item->name.' - '.$item->bab,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ return new class extends Migration
|
|||||||
->nullable()
|
->nullable()
|
||||||
->comment('types: tel, hk, hj');
|
->comment('types: tel, hk, hj');
|
||||||
|
|
||||||
|
$table->string('name')
|
||||||
|
->index();
|
||||||
|
|
||||||
$table->string('ssb')
|
$table->string('ssb')
|
||||||
->nullable()
|
->nullable()
|
||||||
->comment('Şahsy salgyt belgisi');
|
->comment('Şahsy salgyt belgisi');
|
||||||
@@ -30,6 +33,8 @@ return new class extends Migration
|
|||||||
$table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete();
|
$table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete();
|
||||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
|
||||||
|
$table->boolean('default')->default(false);
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,32 @@ use App\Modules\Bank\Models\Bank;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id [primary,unique]
|
||||||
|
* @property \App\Modules\UserCompany\Types\CompanyType $company_type
|
||||||
|
* @property string $name
|
||||||
|
* @property string $ssb [unique]
|
||||||
|
* @property string $hb [unique]
|
||||||
|
* @property bool $default [default: false]
|
||||||
|
* @property int $user_id
|
||||||
|
* @property int $bank_id
|
||||||
|
* @property \Illuminate\Support\Carbon $created_at
|
||||||
|
* @property \Illuminate\Support\Carbon $updated_at
|
||||||
|
*/
|
||||||
class UserCompany extends Model
|
class UserCompany extends Model
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get the attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User
|
* User
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ enum CompanyType: string
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function option(?string $key = ''): string
|
||||||
|
{
|
||||||
|
return self::options()[$key] ?? '-';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default option
|
* Default option
|
||||||
*/
|
*/
|
||||||
@@ -56,7 +61,7 @@ enum CompanyType: string
|
|||||||
/**
|
/**
|
||||||
* Get status
|
* Get status
|
||||||
*/
|
*/
|
||||||
public static function statusClass(?string $key): string
|
public static function statusClass(?string $key = ''): string
|
||||||
{
|
{
|
||||||
return self::statusClasses()[$key] ?? 'danger';
|
return self::statusClasses()[$key] ?? 'danger';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user