<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $bodyTemplate = <<<'HTML'
<h2 style="text-align:center; margin-bottom:16px; font-size:20px; font-weight:bold; letter-spacing:2px;">지 출 결 의 서</h2>
<table style="width:100%; border-collapse:collapse; margin-bottom:12px; font-size:13px;">
  <tr>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold; width:110px;">지출형식</td>
    <td style="border:1px solid #999; padding:6px 10px;" colspan="5">
      &#9744; 법인카드 &nbsp;&nbsp; &#9744; 송금 &nbsp;&nbsp; &#9744; 현금/가지급정산 &nbsp;&nbsp; &#9744; 복지카드
    </td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold;">세금계산서</td>
    <td style="border:1px solid #999; padding:6px 10px;" colspan="5">
      &#9744; 일반 &nbsp;&nbsp; &#9744; 이월발행
    </td>
  </tr>
</table>
<table style="width:100%; border-collapse:collapse; margin-bottom:12px; font-size:13px;">
  <tr>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold; width:110px;">작성일자</td>
    <td style="border:1px solid #999; padding:6px 10px; width:22%;"></td>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold; width:80px;">지출부서</td>
    <td style="border:1px solid #999; padding:6px 10px; width:22%;"></td>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold; width:60px;">이름</td>
    <td style="border:1px solid #999; padding:6px 10px;"></td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:6px 10px; background:#f8f9fa; font-weight:bold;">제목</td>
    <td style="border:1px solid #999; padding:6px 10px;" colspan="5"></td>
  </tr>
</table>
<table style="width:100%; border-collapse:collapse; margin-bottom:12px; font-size:13px;">
  <thead>
    <tr style="background:#e9ecef;">
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:90px;">년/월/일</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center;">내용</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:90px;">금액</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:90px;">업체명</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:70px;">지급은행</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:100px;">계좌번호</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:60px;">예금주</th>
      <th style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center; width:60px;">비고</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px; text-align:right;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
    </tr>
    <tr>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px; text-align:right;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
    </tr>
    <tr>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px; text-align:right;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
    </tr>
    <tr>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px; text-align:right;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
      <td style="border:1px solid #999; padding:6px 8px;"></td>
    </tr>
  </tbody>
  <tfoot>
    <tr style="background:#f8f9fa;">
      <td style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:center;" colspan="2">합 계</td>
      <td style="border:1px solid #999; padding:6px 8px; font-weight:bold; text-align:right;"></td>
      <td style="border:1px solid #999; padding:6px 8px;" colspan="5"></td>
    </tr>
  </tfoot>
</table>
<p style="font-size:13px; color:#666;">첨부서류:</p>
HTML;

        DB::table('approval_forms')
            ->where('tenant_id', 1)
            ->where('code', 'expense')
            ->update([
                'body_template' => $bodyTemplate,
                'updated_at' => now(),
            ]);
    }

    public function down(): void
    {
        // 이전 body_template으로 복원
        $oldBodyTemplate = <<<'HTML'
<table style="width:100%; border-collapse:collapse; font-size:14px; border:2px solid #333;">
  <colgroup>
    <col style="width:15%;">
    <col style="width:35%;">
    <col style="width:15%;">
    <col style="width:35%;">
  </colgroup>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px; background:#f5f5f5; font-weight:bold;">지출일자</td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px; background:#f5f5f5; font-weight:bold;">부서</td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px; background:#f5f5f5; font-weight:bold;">거래처</td>
    <td style="border:1px solid #999; padding:8px 12px;" colspan="3"></td>
  </tr>
  <tr style="background:#e8e8e8;">
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:center;">계정과목</td>
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:center;">적요</td>
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:center;">금액</td>
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:center;">비고</td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px; text-align:right;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px; text-align:right;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
    <td style="border:1px solid #999; padding:8px 12px; text-align:right;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
  </tr>
  <tr style="background:#f5f5f5;">
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:center;" colspan="2">합계</td>
    <td style="border:1px solid #999; padding:8px 12px; font-weight:bold; text-align:right;"></td>
    <td style="border:1px solid #999; padding:8px 12px;"></td>
  </tr>
  <tr>
    <td style="border:1px solid #999; padding:8px 12px; background:#f5f5f5; font-weight:bold;">지출 사유</td>
    <td style="border:1px solid #999; padding:8px 12px; min-height:60px;" colspan="3"></td>
  </tr>
</table>
HTML;

        DB::table('approval_forms')
            ->where('tenant_id', 1)
            ->where('code', 'expense')
            ->update([
                'body_template' => $oldBodyTemplate,
                'updated_at' => now(),
            ]);
    }
};
