PHP code example of ffhs / filament-package_ffhs_approvals

1. Go to this page and download the library: Download ffhs/filament-package_ffhs_approvals library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ffhs / filament-package_ffhs_approvals example snippets


use Ffhs\Approvals\Contracts\HasApprovalStatuses;  
  
enum MyApprovalStatus: string  implements HasApprovalStatuses  
{  
    case APPROVED = 'approved';  
    case INCOMPLETE = 'incomplete';  
    case DENIED = 'denied';  
  
    public static function getApprovedStatuses(): array  
    {  
        return [self::APPROVED];  
    }  
  
    public static function getDeniedStatuses(): array  
    {  
        return [self::DENIED];  
    }  
  
    public static function getPendingStatuses(): array  
    {  
        return [self::INCOMPLETE];  
    }  
}

namespace App\Models;

class MyModel extends Model implements Approvable{
	use HasApprovals;

	public function getApprovalFlows(): array  
	{
		return [
			'managment_aproved' => SimpleApprovalFlow::make()
				->category('any_catergory');  
				->approvalStatus(ApplicationApprovalStatus::cases())
				->aprovalBy([
					SimpleApprovalBy::make('employee')
						->any(),
						
					SimpleApprovalBy::make('manager')
						->permission('can_approve_for_manager'),
						
					SimpleApprovalBy::make('hr')
						->role('hr_role')
						->atLeast(2)
					
				])
		];
	}
}

// MyModelView.php

ApprovalActions::make('managment_aproved')

// MyModelView.php
ApprovalActions::make('managment_aproved')
    ->mall)
    ->alignRight()
    ->groupLabels([
        'employee' => 'Any',
        'manager' => 'Manager',
        'hr' => 'HR',
    ])
    ->casesIcons([
        MyApprovalStatus::APPROVED->value => 'heroicon-m-check',
        MyApprovalStatus::INCOMPLETE->value => 'heroicon-o-arrow-right',
        MyApprovalStatus::DENIED->value => 'heroicon-m-no-symbol',
    ])
    ->casesSelectedColors([
        MyApprovalStatus::APPROVED->value => Color::Green,
        MyApprovalStatus::INCOMPLETE->value => Color::Orange,
        MyApprovalStatus::DENIED->value => Color::Red,
    ])
    ->casesToolTips([
        MyApprovalStatus::APPROVED->value => 'This section has been approved for validation.',
        MyApprovalStatus::INCOMPLETE->value => 'This section has been returned for revision.',
        MyApprovalStatus::DENIED->value => 'This section has been rejected, which also rejects the application.',
    ])
    ->notificationOnResetApproval('The approval status for this section has been reset.')
    ->notificationOnSetApproval(fn($status) => match ($status) {
        MyApprovalStatus::APPROVED->value => 'This section has been approved.',
        MyApprovalStatus::INCOMPLETE->value => 'This section has been returned for revision.',
        MyApprovalStatus::DENIED->value => 'This section has been rejected.',
    })
    ->casesDisabled(fn(MyModel $record) => [
        MyApprovalStatus::INCOMPLETE->value => $record->state::class !== Received::class,
    ])
    ->disabled(function (MyModel $record) {
        return match ($record->state::class) {
            Open::class,
            PaymentFailed::class,
            Aborted::class,
            Rejected::class,
            Withdrawn::class,
            WithdrawnAfterEnrolled::class => true,
            default => false,
        };
    });
bash  
php artisan vendor:publish --tag="filament-package_ffhs_approvals-migrations"  
php artisan migrate