fix : 모델 및 자재관리 수정

This commit is contained in:
2025-08-27 18:13:49 +09:00
parent 58016ea662
commit 028af8fbfa
4 changed files with 28 additions and 4 deletions

View File

@@ -7,6 +7,7 @@
use App\Models\Qualitys\Lot;
use App\Traits\ModelTrait;
use App\Traits\BelongsToTenant;
use Filament\Forms\Components\Hidden;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -22,6 +23,10 @@ class Material extends Model
'options' => 'array',
];
protected $hidden = [
'deleted_at',
];
// 자재 입고 내역
public function receipts()
{

View File

@@ -16,7 +16,7 @@ class Product extends Model
protected $fillable = [
'tenant_id','code','name','category_id',
'product_type', // 라벨/분류용
'product_type', // 라벨/분류용
'attributes','description','is_active',
'is_sellable','is_purchasable','is_producible',
'created_by','updated_by'
@@ -30,6 +30,10 @@ class Product extends Model
'is_producible' => 'boolean',
];
protected $hidden = [
'deleted_at',
];
// 분류
public function category() { return $this->belongsTo(Category::class, 'category_id'); }

View File

@@ -46,7 +46,7 @@ public function getMaterials(array $params)
});
}
$q->orderByDesc('id');
$q->orderBy('id');
$perPage = $p['per_page'] ?? 20;
$page = $p['page'] ?? null;

View File

@@ -72,7 +72,9 @@ public function index(array $params)
$productType = $params['product_type'] ?? null; // PRODUCT|PART|SUBASSEMBLY...
$active = $params['active'] ?? null; // 1/0
$query = Product::query()->where('tenant_id', $tenantId);
$query = Product::query()
->with('category:id,name') // 필요한 컬럼만 가져오기
->where('tenant_id', $tenantId);
if ($q !== '') {
$query->where(function ($w) use ($q) {
@@ -85,7 +87,20 @@ public function index(array $params)
if ($productType) $query->where('product_type', $productType);
if ($active !== null && $active !== '') $query->where('is_active', (int)$active);
return $query->orderByDesc('id')->paginate($size);
$paginator = $query->orderBy('id')->paginate($size);
// 날짜 형식을 위해 분리
$paginator->setCollection(
$paginator->getCollection()->transform(function ($item) {
$arr = $item->toArray();
$arr['created_at'] = $item->created_at
? $item->created_at->format('Y-m-d')
: null;
return $arr;
})
);
return $paginator;
}
// 생성