commit4
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\Modules\Workshop;
|
||||
use Illuminate\Support\Facades\{DB,Schema};
|
||||
final class WorkshopCommercialState {
|
||||
public static function linked(string $area,int $id): bool {
|
||||
if(!Schema::hasTable('wb_generations'))return false;$column=$area==='service_drafts'?'service_draft_id':'billing_draft_id';
|
||||
if(DB::table('wb_generations')->where($column,$id)->exists())return true;
|
||||
if(!Schema::hasTable('wc_applications'))return false;
|
||||
return DB::table('wc_applications')->where($area==='service_drafts'?'new_service_id':'new_billing_id',$id)->exists();
|
||||
}
|
||||
public static function state(string $area,int $id): ?string {
|
||||
if(!self::linked($area,$id))return null;if(!Schema::hasTable('wc_applications'))return 'current';
|
||||
$event=DB::table('wc_applications')->where($area==='service_drafts'?'old_service_id':'old_billing_id',$id)->first();
|
||||
return $event?($event->kind==='replace'?'superseded':'cancelled'):'current';
|
||||
}
|
||||
public static function assertCurrent(string $area,int $id): void {
|
||||
$state=self::state($area,$id);abort_if($state!==null&&$state!=='current',409,'Preparação comercial substituída ou cancelada; apenas consulta histórica.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user