/*M!999999\- enable the sandbox mode */ 
-- MariaDB dump 10.19  Distrib 10.11.13-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: doto_yoyaku
-- ------------------------------------------------------
-- Server version	10.11.13-MariaDB-0ubuntu0.24.04.1-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `organizations`
--

DROP TABLE IF EXISTS `organizations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `organizations` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) DEFAULT NULL,
  `organization_group_id` int(11) DEFAULT NULL,
  `branch_id` int(11) DEFAULT NULL,
  `type` enum('company','agency','school','guest','other') DEFAULT 'company',
  `name` varchar(255) NOT NULL,
  `name_kana` varchar(255) DEFAULT NULL,
  `contact_person` varchar(100) DEFAULT NULL,
  `branch_department` varchar(255) DEFAULT NULL COMMENT '支社・部署',
  `contact_email` varchar(255) DEFAULT NULL,
  `contact_phone` varchar(20) DEFAULT NULL,
  `postal_code` varchar(10) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `payment_method` enum('invoice','credit_card','bank_transfer','cash') DEFAULT 'invoice',
  `payment_cycle` enum('per_trip','prepaid','current_month','next_month') DEFAULT 'per_trip',
  `payment_day` int(11) DEFAULT NULL,
  `credit_limit` decimal(10,2) DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `status` enum('active','inactive','deleted') DEFAULT 'active',
  `created_by` int(11) DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `commission_value` decimal(10,2) DEFAULT 0.00 COMMENT '手数料の値',
  `commission_type` enum('fixed','percentage') DEFAULT 'fixed' COMMENT '手数料タイプ: fixed=円, percentage=%',
  PRIMARY KEY (`id`),
  KEY `idx_type` (`type`),
  KEY `idx_status` (`status`),
  KEY `idx_name_kana` (`name_kana`),
  KEY `idx_org_group_id` (`organization_group_id`),
  KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `group_receipt_issues`
--

DROP TABLE IF EXISTS `group_receipt_issues`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `group_receipt_issues` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `group_booking_id` int(11) NOT NULL,
  `receipt_type` enum('regular','reverse') NOT NULL,
  `receipt_number` varchar(50) NOT NULL,
  `issued_at` datetime NOT NULL DEFAULT current_timestamp(),
  `issued_by` int(11) DEFAULT NULL,
  `source` varchar(20) NOT NULL DEFAULT 'admin',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_group_receipt_group` (`group_booking_id`,`receipt_type`,`issued_at`),
  KEY `idx_group_receipt_issued_by` (`issued_by`)
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `group_bookings`
--

DROP TABLE IF EXISTS `group_bookings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `group_bookings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gb_number` char(6) DEFAULT NULL,
  `organization_id` int(11) DEFAULT NULL,
  `branch_id` int(11) DEFAULT NULL,
  `organization_group_id` int(11) DEFAULT NULL,
  `organization_name` varchar(255) NOT NULL,
  `contact_person` varchar(100) DEFAULT NULL,
  `contact_phone` varchar(20) DEFAULT NULL,
  `contact_email` varchar(100) DEFAULT NULL,
  `total_passengers` int(11) NOT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `payment_status` enum('pending','paid','cancelled','refunded') DEFAULT 'pending',
  `payment_method` varchar(50) DEFAULT NULL,
  `payment_date` datetime DEFAULT NULL,
  `booking_status` enum('confirmed','cancelled') DEFAULT 'confirmed',
  `checkin_status` enum('not_checked_in','checked_in') DEFAULT 'not_checked_in',
  `checkin_at` datetime DEFAULT NULL,
  `checkin_by` int(11) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `commission_value` decimal(10,2) DEFAULT 0.00 COMMENT '手数料の値',
  `commission_type` enum('fixed','percentage') DEFAULT 'fixed' COMMENT '手数料タイプ: fixed=円, percentage=%',
  `commission_amount` decimal(10,2) DEFAULT 0.00 COMMENT '計算された手数料金額',
  `subtotal_amount` decimal(10,2) DEFAULT 0.00 COMMENT '小計金額（手数料適用前）',
  `final_amount` decimal(10,2) DEFAULT 0.00 COMMENT '見積合計金額（手数料適用後）',
  PRIMARY KEY (`id`),
  KEY `idx_organization` (`organization_name`),
  KEY `idx_status` (`booking_status`),
  KEY `idx_payment` (`payment_status`)
) ENGINE=InnoDB AUTO_INCREMENT=110 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2026-02-04 14:50:43
