Skip to content

Commit

Permalink
Added Department Imports and Exports
Browse files Browse the repository at this point in the history
- Update Departments with KFS Data via imports
- Download a template for KFS Data linking in excel
  • Loading branch information
coolsam726 committed Oct 11, 2023
1 parent 6e9ec28 commit f61d1a6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 18 deletions.
6 changes: 0 additions & 6 deletions config/armor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@
'view_any',
'create',
'update',
'restore',
'restore_any',
'replicate',
'reorder',
'delete',
'delete_any',
'force_delete',
'force_delete_any',
],

'page' => 'page',
Expand Down
6 changes: 0 additions & 6 deletions config/vanadi-shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@
'view_any',
'create',
'update',
'restore',
'restore_any',
'replicate',
'reorder',
'delete',
'delete_any',
'force_delete',
'force_delete_any',
],

'page' => 'page',
Expand Down
26 changes: 20 additions & 6 deletions src/Filament/Resources/DepartmentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ public static function form(Form $form): Form
Forms\Components\TextInput::make('short_name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('sync_id')
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('parent_sync_id')
Forms\Components\TextInput::make('chart_code')
->required()
->maxLength(255),
Forms\Components\TextInput::make('name')

Forms\Components\TextInput::make('object_code')
->required()
->maxLength(255),

Forms\Components\TextInput::make('account_number')
->required()
->maxLength(255),

Forms\Components\TextInput::make('sync_id')
->required()
->maxLength(255),
Forms\Components\TextInput::make('parent_sync_id')
->required()
->maxLength(255),
Forms\Components\Toggle::make('is_active')
Expand All @@ -60,10 +72,12 @@ public static function table(Table $table): Table
->searchable()->sortable(),
Tables\Columns\TextColumn::make('name')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('parent.name')
Tables\Columns\TextColumn::make('chart_code')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('object_code')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('account_number')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('hod_username')
->searchable(),
ActiveStatusColumn::make(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

namespace Savannabits\Saas\Filament\Resources\DepartmentResource\Pages;

use Coolsam\FilamentExcel\Actions\ImportField;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ManageRecords;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use pxlrbt\FilamentExcel\Columns\Column;
use Savannabits\Saas\Concerns\Filament\HasExportActions;
use Savannabits\Saas\Concerns\Filament\HasVanadiImports;
use Savannabits\Saas\Filament\Resources\DepartmentResource;
use Savannabits\Saas\Models\Department;
use Savannabits\Saas\Services\Webservice;
Expand All @@ -14,11 +20,15 @@

class ManageDepartments extends ManageRecords
{
use HasExportActions;
use HasVanadiImports;
protected static string $resource = DepartmentResource::class;

protected function getHeaderActions(): array
{
return [
$this->getPageTableExportAction(),
$this->makeHeaderImportAction()->label('Import KFS Linking Data'),
Actions\Action::make('synchronize')->label('Sync from PnC')
->requiresConfirmation()
->color('success')
Expand All @@ -43,4 +53,47 @@ public function synchronize()
->send();
}
}

public static function getExportColumns(): array
{
return [
Column::make('code'),
Column::make('short_name'),
Column::make('name'),
Column::make('account_number'),
Column::make('object_code'),
];
}

public function getImportColumns(): array
{
return [
ImportField::make('code')->required(),
ImportField::make('short_name')->required(),
ImportField::make('account_number')->required(),
ImportField::make('object_code')->required(),
ImportField::make('chart_code')->required(),
];
}
public function importRecord(array $data)
{
$data= collect($this->mutateFieldsForRecordCreation($data));
try {
/**
* @var Department $model
*/
$model = static::getModel()::whereCode($data['code'])->orWhere('short_name',$data['short_name'])->first();
if ($model) {
$model->update([
'chart_code' => Str::of($data['chart_code'])->toString(),
'object_code' => Str::of($data['object_code'])->padLeft(4,'0'),
'account_number' => Str::of($data['account_number'])->padLeft(7,'0'),
]);
}
return $model;
} catch (\Throwable $exception) {
Log::error($exception);
throw $exception;
}
}
}

0 comments on commit f61d1a6

Please sign in to comment.