17 lines
911 B
PHP
17 lines
911 B
PHP
<?php
|
|
namespace App\Modules\Purchasing;
|
|
|
|
use Tempo\Purchasing\Embedded\Models\Supplier;
|
|
|
|
/** Explicit fixture bindings and suppliers actually prepared in this company/unit. */
|
|
final class SupplierAccess
|
|
{
|
|
public static function scope(string $context):string{return hash('sha256',substr($context,0,strrpos($context,':')));}
|
|
public static function query(array $binding,string $context){
|
|
return Supplier::query()->where(function($q)use($binding,$context){
|
|
$q->whereIn('suppliers.id',$binding['supplier_ids']??[]);
|
|
if(config('receipt_qa.suppliers_enabled')===true)$q->orWhereExists(fn($a)=>$a->selectRaw('1')->from('audit_logs as sa')->whereColumn('sa.tenant_id','suppliers.tenant_id')->where('sa.action','sgf.supplier.command')->where('sa.after->supplier_scope',self::scope($context))->whereRaw("sa.after->'result'->>'supplier_id'=suppliers.id::text"));
|
|
});
|
|
}
|
|
}
|