それぞれのモデルに、どのようなメソッドを持たせて、そのメソッドで何をさせるか

ユースケースとして、

  1. ユーザー新規登録
  2. 会計年度作成
  3. BusinessUnit作成
  4. 期首の設定
  5. 仕訳帳の登録

まで、考えてみる。

ユーザー新規登録

// Jetstream に任せて
$user = User::create([
]);

会計年度作成

$fiscalYear = $user->createFiscalYear( YYYY );

BusinessUnit作成

$businessUnit = $fiscalYear->createBusinessUnit( BusinessUnit::GENERAL);

// 将来的には
// $fiscalYear->createBusinessUnit( BusinessUnit::AGRICULTURE); // 農業
// $fiscalYear->createBusinessUnit( BusinessUnit::REAL_ESTATE); // 不動産
// なども用意したい

BusinessUnit が作られるタイミングで、デフォルトの Account, SubAccount も作成する。(AccountはBusinessUnitに所属するので)

期首の設定

  • 現金
  • 普通預金

は登録したい

$businessUnit->registerOpeningBalances([
    '現金' => 100000,
    '普通預金' => 200000,
]);

仕訳帳の登録

日々日々の業務。

単一仕訳は

// 33,000円(10%消費税)の売り上げ

$businessUnit->registerTransaction(
    date: '2025-01-01',
    description: 'お正月福袋Aの売り上げ',
    entries: [
        [
            'type'       => 'debit',
            'account'    => '現金',
            'amount'     => 33000,
            'tax_amount' => 0,
            'tax_type'   => TaxType::NON_TAXABLE,
        ],
        [
            'type'       => 'credit',
            'account'    => '売上',
            'amount'     => 30000,
            'tax_amount' => 3000,
            'tax_type'   => TaxType::TAXABLE_SALES_10,
        ],
    ]
);
// 33,000円の備品(テーブル)を購入

$unit->registerTransaction(
    date: '2025-02-01',
    description: '備品購入(現金支払・課税10%)',
    entries: [
        [
            'type'       => 'debit',
            'account'    => '備品費',
            'amount'     => 30000,
            'tax_amount' => 3000,
            'tax_type'   => TaxType::TAXABLE_PURCHASES_10,
        ],
        [
            'type'       => 'credit',
            'account'    => '現金',
            'amount'     => 33000,
            'tax_amount' => 0,
            'tax_type'   => TaxType::NON_TAXABLE,
        ],
    ]
);

複合仕訳はこのような感じ

$businessUnit->registerTransaction(
    date: '2025-03-01',
    description: 'Amazonで備品・書籍購入(クレジット決済)',
    entries: [
        [
            'type'       => 'debit',
            'account'    => '備品費',
            'amount'     => 5000,  // 税抜
            'tax_amount' => 500,   // 10%
            'tax_type'   => TaxType::TAXABLE_PURCHASES_10,
        ],
        [
            'type'       => 'debit',
            'account'    => '図書費',
            'amount'     => 3000,  // 税抜
            'tax_amount' => 300,   // 10%
            'tax_type'   => TaxType::TAXABLE_PURCHASES_10,
        ],
        [
            'type'       => 'credit',
            'account'    => '未払金',
            'amount'     => 8800,  // 税込合計
            'tax_amount' => 0,
            'tax_type'   => TaxType::NON_TAXABLE,
        ],
    ]
);