User company addded

This commit is contained in:
2024-11-09 18:49:54 +05:00
parent 95c6d5746b
commit a566b7ac61
8 changed files with 175 additions and 10 deletions

3
F.MD Normal file
View 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.

View File

@@ -0,0 +1 @@
# F

View File

@@ -3,21 +3,27 @@
namespace App\Filament\Resources\Company;
use App\Filament\Resources\Company\UserCompanyResource\Pages;
use App\Modules\Bank\Repositories\BankRepository;
use App\Modules\UserCompany\Models\UserCompany;
use App\Modules\UserCompany\Types\CompanyType;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
class UserCompanyResource extends Resource
{
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
{
@@ -30,6 +36,9 @@ class UserCompanyResource extends Resource
->default(CompanyType::default())
->required(),
TextInput::make('name')
->required(),
TextInput::make('ssb')
->label('Şahsy salgyt belgisi')
->unique(ignoreRecord: true)
@@ -41,10 +50,15 @@ class UserCompanyResource extends Resource
->required(),
Select::make('bank_id')
->relationship(name: 'bank', titleAttribute: 'name')
->label('Bank')
->native(false)
->options(BankRepository::make()->options())
->searchable()
->preload()
->required(),
Toggle::make('default')
->default(false)
->label('Is default'),
]);
}
@@ -54,14 +68,20 @@ class UserCompanyResource extends Resource
->columns([
TextColumn::make('company_type')
->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)),
// 'ssb'
// 'hb'
// 'bank_id'
TextColumn::make('ssb')
->label('Şahsy salgyt belgisi')
->searchable(),
TextColumn::make('hb')
->label('HB'),
ToggleColumn::make('default'),
])
->filters([
//
Filter::make('default'),
])
->actions([
Tables\Actions\EditAction::make(),

View 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);
}
}

View File

@@ -2,4 +2,44 @@
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,
]),
);
}
}

View File

@@ -20,6 +20,9 @@ return new class extends Migration
->nullable()
->comment('types: tel, hk, hj');
$table->string('name')
->index();
$table->string('ssb')
->nullable()
->comment('Şahsy salgyt belgisi');
@@ -30,6 +33,8 @@ return new class extends Migration
$table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->boolean('default')->default(false);
$table->timestamps();
});
}

View File

@@ -7,8 +7,32 @@ use App\Modules\Bank\Models\Bank;
use Illuminate\Database\Eloquent\Model;
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
{
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'default' => 'boolean',
];
}
/**
* User
*

View File

@@ -31,6 +31,11 @@ enum CompanyType: string
];
}
public static function option(?string $key = ''): string
{
return self::options()[$key] ?? '-';
}
/**
* Default option
*/
@@ -56,7 +61,7 @@ enum CompanyType: string
/**
* Get status
*/
public static function statusClass(?string $key): string
public static function statusClass(?string $key = ''): string
{
return self::statusClasses()[$key] ?? 'danger';
}