# invoices

## 概要

<details>
<summary><strong>テーブル定義</strong></summary>

```sql
CREATE TABLE `invoices` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '請求書ID',
  `invoice_number` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '請求書番号',
  `company_id` bigint unsigned NOT NULL,
  `issue_date` date DEFAULT NULL COMMENT '発行日',
  `billing_period_start` date DEFAULT NULL COMMENT '請求期間開始日',
  `billing_period_end` date DEFAULT NULL COMMENT '請求期間終了日',
  `due_date` date DEFAULT NULL COMMENT '支払期限',
  `total_amount` decimal(12,2) DEFAULT NULL COMMENT '税抜合計',
  `tax_amount` decimal(12,2) DEFAULT NULL COMMENT '消費税額',
  `total_with_tax` decimal(12,2) DEFAULT NULL COMMENT '税込合計',
  `status` enum('下書き','発行済','送信済','入金済') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '下書き' COMMENT '請求ステータス',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `invoices_invoice_number_unique` (`invoice_number`),
  KEY `invoices_company_id_foreign` (`company_id`),
  CONSTRAINT `invoices_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
```

</details>

## カラム一覧

| 名前 | タイプ | デフォルト値 | NULL許可 | Extra Definition | 子テーブル | 親テーブル | コメント |
| ---- | ------ | ------------ | -------- | ---------------- | ---------- | ---------- | -------- |
| id | bigint unsigned |  | false | auto_increment | [invoice_items](invoice_items.md) [payments](payments.md) |  | 請求書ID |
| invoice_number | varchar(255) |  | false |  |  |  | 請求書番号 |
| company_id | bigint unsigned |  | false |  |  | [companies](companies.md) |  |
| issue_date | date |  | true |  |  |  | 発行日 |
| billing_period_start | date |  | true |  |  |  | 請求期間開始日 |
| billing_period_end | date |  | true |  |  |  | 請求期間終了日 |
| due_date | date |  | true |  |  |  | 支払期限 |
| total_amount | decimal(12,2) |  | true |  |  |  | 税抜合計 |
| tax_amount | decimal(12,2) |  | true |  |  |  | 消費税額 |
| total_with_tax | decimal(12,2) |  | true |  |  |  | 税込合計 |
| status | enum('下書き','発行済','送信済','入金済') | 下書き | false |  |  |  | 請求ステータス |
| created_at | timestamp |  | true |  |  |  |  |
| updated_at | timestamp |  | true |  |  |  |  |

## 制約一覧

| 名前 | タイプ | 定義 |
| ---- | ---- | ---------- |
| invoices_company_id_foreign | FOREIGN KEY | FOREIGN KEY (company_id) REFERENCES companies (id) |
| invoices_invoice_number_unique | UNIQUE | UNIQUE KEY invoices_invoice_number_unique (invoice_number) |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## INDEX一覧

| 名前 | 定義 |
| ---- | ---------- |
| invoices_company_id_foreign | KEY invoices_company_id_foreign (company_id) USING BTREE |
| PRIMARY | PRIMARY KEY (id) USING BTREE |
| invoices_invoice_number_unique | UNIQUE KEY invoices_invoice_number_unique (invoice_number) USING BTREE |

## ER図

![er](invoices.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
