feat:테넌트설정 API 및 다수 서비스 개선

- TenantSetting CRUD API 추가
- Calendar, Entertainment, VAT 서비스 개선
- 5130 BOM 계산 로직 수정
- quote_items에 item_type 컬럼 추가
- tenant_settings 테이블 마이그레이션
- Swagger 문서 업데이트
This commit is contained in:
2026-01-26 20:29:22 +09:00
parent f2da990771
commit 6d05ab815f
54 changed files with 2090 additions and 110 deletions

View File

@@ -157,12 +157,22 @@ public function scopeProducts($query)
/**
* Materials 타입만 (SM, RM, CS)
* join 시 ambiguous 에러 방지를 위해 테이블 prefix 사용
*
* @deprecated Use scopeByItemTypes() with tenant settings instead
*/
public function scopeMaterials($query)
{
return $query->whereIn('items.item_type', self::MATERIAL_TYPES);
}
/**
* 특정 품목유형만 조회 (테넌트 설정 연동용)
*/
public function scopeByItemTypes($query, array $types)
{
return $query->whereIn('items.item_type', $types);
}
/**
* 활성 품목만
*/

View File

@@ -12,7 +12,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
/**

View File

@@ -16,6 +16,7 @@ class QuoteItem extends Model
'tenant_id',
// 품목 정보
'item_id',
'item_type',
'item_code',
'item_name',
'specification',

View File

@@ -45,18 +45,25 @@ class ExpenseAccount extends Model
// 계정 유형 상수
public const TYPE_WELFARE = 'welfare';
public const TYPE_ENTERTAINMENT = 'entertainment';
public const TYPE_TRAVEL = 'travel';
public const TYPE_OFFICE = 'office';
// 세부 유형 상수 (복리후생)
public const SUB_TYPE_MEAL = 'meal';
public const SUB_TYPE_HEALTH = 'health';
public const SUB_TYPE_EDUCATION = 'education';
// 결제 수단 상수
public const PAYMENT_CARD = 'card';
public const PAYMENT_CASH = 'cash';
public const PAYMENT_TRANSFER = 'transfer';
/**
@@ -90,4 +97,4 @@ public function scopeInPeriod($query, string $startDate, string $endDate)
{
return $query->whereBetween('expense_date', [$startDate, $endDate]);
}
}
}

View File

@@ -221,4 +221,4 @@ public function getRecurrenceRuleLabelAttribute(): ?string
return self::RECURRENCE_RULES[$this->recurrence_rule] ?? $this->recurrence_rule;
}
}
}

View File

@@ -15,6 +15,7 @@ class ShipmentItem extends Model
'tenant_id',
'shipment_id',
'seq',
'item_id',
'item_code',
'item_name',
'floor_unit',
@@ -28,6 +29,7 @@ class ShipmentItem extends Model
protected $casts = [
'seq' => 'integer',
'item_id' => 'integer',
'quantity' => 'decimal:2',
'shipment_id' => 'integer',
'stock_lot_id' => 'integer',

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Models\Tenants;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
/**
* 테넌트 설정 모델
*
* @property int $id
* @property int $tenant_id
* @property string $setting_group
* @property string $setting_key
* @property array|null $setting_value
* @property string|null $description
* @property int|null $updated_by
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class TenantSetting extends Model
{
use BelongsToTenant, ModelTrait;
protected $table = 'tenant_settings';
protected $fillable = [
'tenant_id',
'setting_group',
'setting_key',
'setting_value',
'description',
'updated_by',
];
protected $casts = [
'setting_value' => 'array',
];
/**
* 특정 그룹의 모든 설정 조회
*/
public function scopeGroup($query, string $group)
{
return $query->where('setting_group', $group);
}
/**
* 특정 키의 설정 조회
*/
public function scopeKey($query, string $key)
{
return $query->where('setting_key', $key);
}
/**
* 그룹과 키로 설정 조회
*/
public static function getValue(int $tenantId, string $group, string $key, $default = null)
{
$setting = static::withoutGlobalScope('tenant')
->where('tenant_id', $tenantId)
->where('setting_group', $group)
->where('setting_key', $key)
->first();
return $setting ? $setting->setting_value : $default;
}
/**
* 그룹과 키로 설정 저장/업데이트
*/
public static function setValue(int $tenantId, string $group, string $key, $value, ?string $description = null, ?int $updatedBy = null): self
{
return static::withoutGlobalScope('tenant')->updateOrCreate(
[
'tenant_id' => $tenantId,
'setting_group' => $group,
'setting_key' => $key,
],
[
'setting_value' => $value,
'description' => $description,
'updated_by' => $updatedBy,
]
);
}
}