# B2B見積受発注システム 論理データモデル

以下に、B2B見積受発注システムの論理データモデルをmermaid形式で示します。このモデルは添付された機能要件一覧、画面一覧、およびプロセスフローから抽出されたエンティティとその関連を表しています。

```mermaid
erDiagram
    User ||--o{ Quote_Request : "creates"
    User ||--o{ Order : "places"
    User ||--o{ Quote_Response : "reviews"
    User ||--o{ Delivery_Schedule : "receives"
    User ||--o{ Approval_Task : "processes"
    User ||--o{ Approval_History : "generates"
    
    Company ||--o{ User : "employs"
    Company ||--o{ Supplier : "can be"
    Company ||--o{ Buyer : "can be"
    Company ||--o{ Manufacturer : "can be"
    
    Role ||--o{ User : "assigned to"
    
    Department ||--o{ User : "belongs to"
    
    Quote_Request ||--o{ Quote_Question : "may have"
    Quote_Request ||--o{ Quote_Response : "results in"
    Quote_Request ||--o{ AI_Analysis : "analyzed by"
    Quote_Request ||--o{ Manufacturer_Quote_Request : "may generate"
    Quote_Request {
        string request_id PK
        string buyer_id FK
        string supplier_id FK
        datetime request_date
        string status
        string product_type
        text requirements
        date desired_delivery_date
        string pattern_type
    }
    
    Quote_Question ||--o{ Quote_Answer : "has"
    Quote_Question {
        string question_id PK
        string request_id FK
        string question_content
        datetime question_date
        string question_status
        string asked_by_user_id FK
    }
    
    Quote_Answer {
        string answer_id PK
        string question_id FK
        text answer_content
        datetime answer_date
        string answered_by_user_id FK
    }
    
    AI_Analysis {
        string analysis_id PK
        string request_id FK
        text analysis_result
        datetime analysis_date
        json unclear_points
    }
    
    Manufacturer_Quote_Request ||--o{ Manufacturer_Quote_Response : "results in"
    Manufacturer_Quote_Request {
        string manufacturer_request_id PK
        string request_id FK
        string manufacturer_id FK
        datetime sent_date
        string status
        text customization_details
    }
    
    Manufacturer_Quote_Response {
        string manufacturer_response_id PK
        string manufacturer_request_id FK
        decimal quoted_price
        datetime response_date
        string status
        json quoted_items
        date estimated_delivery_date
    }
    
    Quote_Response ||--o{ Approval_Task : "requires"
    Quote_Response ||--o{ Order : "may lead to"
    Quote_Response {
        string response_id PK
        string request_id FK
        decimal total_price
        decimal shipping_cost
        datetime response_date
        string status
        json quoted_items
        date estimated_delivery_date
        string created_by_user_id FK
        string approved_by_user_id FK
    }
    
    Approval_Task {
        string task_id PK
        string response_id FK
        string approver_id FK
        datetime assigned_date
        datetime due_date
        string status
        text comments
    }
    
    Approval_History {
        string history_id PK
        string task_id FK
        string action
        datetime action_date
        string acted_by_user_id FK
        text comments
    }
    
    Order ||--o{ Order_Item : "contains"
    Order ||--o{ Manufacturer_Order : "may generate"
    Order ||--o{ Order_Confirmation : "has"
    Order ||--o{ Delivery_Schedule : "has"
    Order {
        string order_id PK
        string response_id FK
        string buyer_id FK
        string supplier_id FK
        datetime order_date
        string status
        decimal total_amount
        date requested_delivery_date
    }
    
    Order_Item {
        string item_id PK
        string order_id FK
        string product_id FK
        integer quantity
        decimal unit_price
        decimal total_price
        string customization_details
    }
    
    Manufacturer_Order ||--o{ Manufacturer_Order_Confirmation : "has"
    Manufacturer_Order {
        string manufacturer_order_id PK
        string order_id FK
        string manufacturer_id FK
        datetime sent_date
        string status
        json order_details
    }
    
    Manufacturer_Order_Confirmation {
        string confirmation_id PK
        string manufacturer_order_id FK
        datetime confirmation_date
        string status
        date estimated_delivery_date
    }
    
    Order_Confirmation {
        string confirmation_id PK
        string order_id FK
        datetime confirmation_date
        string status
        text notes
    }
    
    Delivery_Schedule ||--o{ Delivery_Status : "tracks"
    Delivery_Schedule {
        string schedule_id PK
        string order_id FK
        string shipping_company_id FK
        date scheduled_date
        string status
        string tracking_number
    }
    
    Delivery_Status {
        string status_id PK
        string schedule_id FK
        string status
        datetime status_date
        json location_data
        datetime estimated_arrival_time
    }
    
    Shipping_Company {
        string company_id PK
        string name
        string contact_info
        string service_type
        json service_areas
        json pricing_structure
    }
    
    Product ||--o{ Order_Item : "ordered as"
    Product {
        string product_id PK
        string name
        string description
        string category
        string type
        decimal base_price
        boolean customizable
        string manufacturer_id FK
        integer stock_quantity
    }
    
    Inventory {
        string inventory_id PK
        string product_id FK
        integer quantity
        string warehouse_id FK
        string status
        date last_updated
    }
    
    Warehouse {
        string warehouse_id PK
        string name
        string location
        string contact_info
    }
    
    Notification {
        string notification_id PK
        string type
        string reference_id
        string recipient_id FK
        datetime sent_date
        string status
        text content
        string template_id FK
    }
    
    Notification_Template {
        string template_id PK
        string name
        string type
        text subject_template
        text body_template
    }
    
    Dashboard_Widget {
        string widget_id PK
        string name
        string type
        string data_source
        json configuration
        string user_id FK
    }
    
    User {
        string user_id PK
        string company_id FK
        string username
        string email
        string name
        string role_id FK
        string department_id FK
        string status
        datetime created_date
        datetime last_login
    }
    
    Role {
        string role_id PK
        string name
        json permissions
    }
    
    Department {
        string department_id PK
        string company_id FK
        string name
    }
    
    Company {
        string company_id PK
        string name
        string type
        string contact_info
        string address
        datetime registration_date
        string status
    }
    
    Buyer {
        string buyer_id PK
        string company_id FK
        string payment_terms
        string shipping_preferences
    }
    
    Supplier {
        string supplier_id PK
        string company_id FK
        string service_terms
        json shipping_capabilities
    }
    
    Manufacturer {
        string manufacturer_id PK
        string company_id FK
        json production_capabilities
        string lead_time
    }
```

## エンティティの説明

### 1. User (ユーザー)
システムを利用するすべてのユーザーを表します。バイヤー企業の担当者、卸売企業の営業担当者や上長、メーカーの担当者などが含まれます。ユーザー認証、権限管理、個人設定の保存などに使用します。

### 2. Company (企業)
システムに登録されているすべての企業を表します。1つの企業が複数の役割（バイヤー、サプライヤー、メーカーなど）を持つことができます。

### 3. Role (役割)
システム内でのユーザーの役割を定義します。営業担当者、承認者、管理者などの役割があり、それぞれに異なる権限が付与されます。

### 4. Department (部署)
企業内の部署を表します。ユーザーは特定の部署に所属し、部署ごとに異なる業務や承認フローが設定されることがあります。

### 5. Quote_Request (見積依頼)
バイヤーからサプライヤーへの見積依頼を表します。商品仕様、希望納期、数量などの情報が含まれます。また、商品パターン（規定商品/カスタマイズ商品）も記録されます。

### 6. Quote_Question (見積質問)
見積依頼に関する質問を表します。AIによる分析で抽出された不明点や確認事項が質問として登録され、バイヤーとサプライヤー間でやり取りされます。

### 7. Quote_Answer (見積回答)
見積質問に対する回答を表します。質問と回答の履歴を追跡し、見積プロセスの透明性を確保します。

### 8. AI_Analysis (AI分析)
AIによる見積依頼内容の自動分析結果を保存します。不明点の抽出や商品パターンの自動判別などの情報が含まれます。

### 9. Manufacturer_Quote_Request (メーカー見積依頼)
サプライヤーからメーカーへの見積依頼を表します。カスタマイズ商品の場合に生成され、メーカーに対して詳細な仕様や条件が送信されます。

### 10. Manufacturer_Quote_Response (メーカー見積回答)
メーカーからの見積回答を表します。見積金額、納期、カスタマイズ詳細などの情報が含まれます。

### 11. Quote_Response (見積回答)
サプライヤーからバイヤーへの見積回答を表します。商品金額、配送料、納期などの情報が含まれ、承認ワークフローの対象となります。

### 12. Approval_Task (承認タスク)
見積回答に対する承認タスクを表します。承認者、期限、ステータスなどの情報が含まれます。

### 13. Approval_History (承認履歴)
承認プロセスの履歴を記録します。誰がいつ何をしたか（承認、差し戻し、コメントなど）の記録が保存されます。

### 14. Order (注文)
バイヤーからサプライヤーへの注文を表します。見積回答に基づいて生成され、注文商品、金額、配送先、希望納期などの情報が含まれます。

### 15. Order_Item (注文商品)
注文に含まれる個々の商品を表します。商品ID、数量、単価などの情報が含まれます。

### 16. Manufacturer_Order (メーカー注文)
サプライヤーからメーカーへの注文を表します。カスタマイズ商品の場合に生成され、メーカーに対して発注情報が送信されます。

### 17. Manufacturer_Order_Confirmation (メーカー注文請書)
メーカーからの注文請書を表します。注文受領確認、製造予定、納期などの情報が含まれます。

### 18. Order_Confirmation (注文請書)
サプライヤーからバイヤーへの注文請書を表します。注文受領確認、処理状況、配送予定などの情報が含まれます。

### 19. Delivery_Schedule (配送スケジュール)
注文の配送スケジュールを表します。配送予定日、配送業者、追跡番号などの情報が含まれます。

### 20. Delivery_Status (配送状況)
配送の現在の状況を表します。リアルタイムの位置情報、ステータス更新、予定到着時刻などの情報が含まれます。

### 21. Shipping_Company (配送業者)
配送サービスを提供する企業を表します。会社名、連絡先、サービスタイプ、対応エリア、料金体系などの情報が含まれます。

### 22. Product (商品)
システムで扱われるすべての商品を表します。名称、説明、カテゴリ、タイプ（規定/カスタマイズ）、基本価格などの情報が含まれます。

### 23. Inventory (在庫)
商品の在庫状況を表します。商品ID、数量、倉庫、状態などの情報が含まれます。

### 24. Warehouse (倉庫)
商品を保管する倉庫を表します。名称、場所、連絡先などの情報が含まれます。

### 25. Notification (通知)
システムから送信される通知を表します。見積依頼通知、質問通知、承認依頼通知、注文通知、配送通知などが含まれます。

### 26. Notification_Template (通知テンプレート)
通知の内容テンプレートを表します。件名テンプレート、本文テンプレートなどが含まれ、通知タイプごとに異なるテンプレートが使用されます。

### 27. Dashboard_Widget (ダッシュボードウィジェット)
ユーザーのダッシュボードに表示されるウィジェットを表します。見積管理ダッシュボード、注文管理ダッシュボードなどのデータ表示に使用されます。

### 28. Buyer (バイヤー)
購入者としての企業の特性を表します。支払い条件、配送先設定などの情報が含まれます。

### 29. Supplier (サプライヤー)
卸売業者としての企業の特性を表します。サービス条件、配送能力などの情報が含まれます。

### 30. Manufacturer (メーカー)
製造業者としての企業の特性を表します。製造能力、リードタイムなどの情報が含まれます。

このデータモデルは、B2B見積受発注システムの主要なエンティティとその関連を網羅しており、見積依頼から注文、配送までの全プロセスをサポートします。また、AIによる分析や承認ワークフローなどの高度な機能も考慮されています。
