|
|
@@ -3,9 +3,12 @@
|
|
|
namespace App;
|
|
|
|
|
|
use App\Traits\ModelTimeFormat;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
use App\Traits\ModelLogChanging;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class Procurement extends Model
|
|
|
{
|
|
|
@@ -35,6 +38,21 @@ class Procurement extends Model
|
|
|
'code','owner_material_id', 'supplier_id', 'quantity','amount','unit_price','cost_price','status','initiator','type'
|
|
|
];
|
|
|
|
|
|
+ protected static function booted()
|
|
|
+ {
|
|
|
+ /** @var User $user */
|
|
|
+ $user = Auth::user();
|
|
|
+ if ($user && !$user->isSuperAdmin()) {
|
|
|
+ /** @var \stdClass $user */
|
|
|
+ $ids = array_column(DB::select(DB::raw("SELECT supplier_id FROM supplier_user WHERE user_id = ?"),[$user->id]),"supplier_id");
|
|
|
+ if (count($ids)>0){
|
|
|
+ static::addGlobalScope('supplier', function (Builder $builder)use ($ids) {
|
|
|
+ $builder->whereIn('supplier_id', $ids);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function ownerMaterial(){
|
|
|
return $this->hasOne('App\OwnerMaterial','id','owner_material_id');
|
|
|
}
|