-- https://www.phpmyadmin.net/
--
-- Wersja serwera: 10.4.32-MariaDB
-- Wersja PHP: 8.2.12

START TRANSACTION;



--
-- Database: `slicehub_pro_v2`
--

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_categories`
--

CREATE TABLE `sh_categories` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `ascii_key` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `is_menu` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_categories`
--

INSERT INTO `sh_categories` (`id`, `tenant_id`, `name`, `ascii_key`, `is_menu`, `display_order`, `is_active`, `is_deleted`, `updated_at`) VALUES
(1, 1, 'Pizze Testowe', 'CAT_PIZZE', 1, 1, 1, 0, '2026-04-06 20:23:59'),
(2, 1, 'ad', '', 1, 0, 1, 0, '2026-04-07 22:01:20'),
(3, 1, 'weg', '', 1, 0, 1, 0, '2026-04-07 22:03:37'),
(4, 1, 'asfasf', '', 1, 0, 1, 0, '2026-04-07 22:05:56'),
(5, 1, 'asf', '', 1, 0, 1, 0, '2026-04-07 22:40:45'),
(6, 1, 'adfs', '', 1, 0, 1, 0, '2026-04-07 23:03:30');

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_item_modifiers`
--

CREATE TABLE `sh_item_modifiers` (
  `item_id` int(11) NOT NULL,
  `group_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_item_modifiers`
--

INSERT INTO `sh_item_modifiers` (`item_id`, `group_id`) VALUES
(1, 11),
(1, 12),
(2, 12);

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_modifiers`
--

CREATE TABLE `sh_modifiers` (
  `id` int(11) NOT NULL,
  `group_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `ascii_key` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `action_type` enum('NONE','ADD','REMOVE') NOT NULL DEFAULT 'NONE',
  `linked_warehouse_sku` varchar(50) DEFAULT NULL,
  `linked_quantity` decimal(10,3) NOT NULL DEFAULT 0.000,
  `is_default` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_modifiers`
--

INSERT INTO `sh_modifiers` (`id`, `group_id`, `name`, `ascii_key`, `is_active`, `is_deleted`, `updated_at`, `action_type`, `linked_warehouse_sku`, `linked_quantity`, `is_default`) VALUES
(1, 1, 'sos czosnkowy', 'OPT_SOS_CZOSNKOWY', 1, 1, '2026-04-07 18:26:01', 'NONE', NULL, 0.000, 0),
(2, 1, 'sos pomidorowy', 'OPT_SOS_POMIDOROWY', 1, 1, '2026-04-07 18:26:01', 'NONE', NULL, 0.000, 0),
(3, 1, 'sos czosnkowy', 'OPT_SOS_CZOSNKOWY', 1, 0, '2026-04-07 18:26:01', 'NONE', NULL, 0.000, 0),
(4, 1, 'sos pomidorowy', 'OPT_SOS_POMIDOROWY', 1, 0, '2026-04-07 18:26:01', 'NONE', NULL, 0.000, 0),
(5, 2, 'czosnkowy', 'OPT_CZOSNKOWY', 1, 0, '2026-04-07 18:29:18', 'NONE', NULL, 0.000, 0),
(6, 3, 'asdaa', 'OPT_ASDAA', 1, 0, '2026-04-07 18:43:58', 'NONE', NULL, 0.000, 0),
(7, 4, 'asdfv', 'OPT_ASDFV', 1, 1, '2026-04-07 18:45:12', 'NONE', NULL, 0.000, 0),
(8, 4, 'asdfv', 'OPT_ASDFV', 1, 0, '2026-04-07 18:45:12', 'NONE', NULL, 0.000, 0),
(9, 5, 'Czosnkowy', 'OPT_CZOSNKOWY', 1, 0, '2026-04-07 18:56:15', 'NONE', NULL, 0.000, 0),
(10, 5, 'Pomidorowy', 'OPT_POMIDOROWY', 1, 0, '2026-04-07 18:56:15', 'NONE', NULL, 0.000, 0),
(11, 6, 'asd', 'OPT_ASD', 1, 1, '2026-04-07 18:57:16', 'NONE', NULL, 0.000, 0),
(12, 6, 'asd', 'OPT_ASD', 1, 0, '2026-04-07 18:57:16', 'NONE', NULL, 0.000, 0),
(13, 7, 'fd', 'OPT_FD', 1, 0, '2026-04-07 22:24:23', 'NONE', NULL, 0.000, 0),
(14, 8, 'asdfsaf', 'OPT_ASDFSAF', 1, 0, '2026-04-07 22:41:06', 'NONE', NULL, 0.000, 0),
(15, 9, 'asfdgdsgds', 'OPT_ASFDGDSGDS', 1, 0, '2026-04-07 22:59:52', 'NONE', NULL, 0.000, 0),
(16, 10, 'sfa', 'OPT_SFA', 1, 0, '2026-04-07 23:03:45', 'NONE', NULL, 0.000, 0),
(17, 11, 'asdasfsa', 'OPT_ASDASFSA', 1, 1, '2026-04-07 23:12:27', 'NONE', NULL, 0.000, 0),
(18, 11, 'asdasfsa', 'OPT_ASDASFSA', 1, 0, '2026-04-07 23:12:27', 'ADD', 'SKU_SER_MOZZ', 2.000, 0),
(19, 12, 'pomidorowy', 'OPT_POMIDOROWY', 1, 0, '2026-04-08 16:59:29', 'NONE', NULL, 0.000, 0),
(20, 12, 'majonezowy', 'OPT_MAJONEZOWY', 1, 0, '2026-04-08 16:59:29', 'NONE', NULL, 0.000, 0);

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_modifier_groups`
--

CREATE TABLE `sh_modifier_groups` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `min_selection` int(11) NOT NULL DEFAULT 0,
  `max_selection` int(11) NOT NULL DEFAULT 10,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `ascii_key` varchar(50) DEFAULT NULL,
  `allow_multi_qty` tinyint(1) NOT NULL DEFAULT 0,
  `is_locked_by_hq` tinyint(1) NOT NULL DEFAULT 0,
  `publication_status` enum('Draft','Live','Archived') NOT NULL DEFAULT 'Draft',
  `valid_from` datetime DEFAULT NULL,
  `valid_to` datetime DEFAULT NULL,
  `free_limit` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_modifier_groups`
--

INSERT INTO `sh_modifier_groups` (`id`, `tenant_id`, `name`, `min_selection`, `max_selection`, `is_active`, `is_deleted`, `updated_at`, `ascii_key`, `allow_multi_qty`, `is_locked_by_hq`, `publication_status`, `valid_from`, `valid_to`, `free_limit`) VALUES
(1, 1, 'sosy', 0, 10, 1, 0, '2026-04-07 18:25:52', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(2, 1, 'sosy', 0, 1, 1, 0, '2026-04-07 18:29:18', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(3, 1, 'asd', 0, 1, 1, 0, '2026-04-07 18:43:58', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(4, 1, 'acd', 0, 1, 1, 0, '2026-04-07 18:45:09', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(5, 1, 'Sosy', 0, 20, 1, 0, '2026-04-07 18:56:15', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(6, 1, 'Sosy', 0, 1, 1, 0, '2026-04-07 18:57:09', NULL, 0, 0, 'Draft', NULL, NULL, 0),
(7, 1, 'Sosy', 0, 1, 1, 0, '2026-04-07 22:24:23', 'GRP_SOSY', 0, 0, 'Draft', NULL, NULL, 0),
(8, 1, 'asdasd', 0, 1, 1, 0, '2026-04-07 22:41:06', 'GRP_ASDASD', 0, 0, 'Draft', NULL, NULL, 0),
(9, 1, 'asdasd', 0, 1, 1, 0, '2026-04-07 22:59:52', 'GRP_ASDASD', 0, 0, 'Draft', NULL, NULL, 0),
(10, 1, 'adssaf', 0, 1, 1, 0, '2026-04-07 23:03:45', 'GRP_ADSSAF', 0, 0, 'Draft', NULL, NULL, 0),
(11, 1, 'asffsdg', 0, 1, 1, 0, '2026-04-07 23:12:17', 'GRP_ASFFSDG', 0, 0, 'Draft', NULL, NULL, 0),
(12, 1, 'SOSY test', 0, 5, 1, 0, '2026-04-08 16:59:29', 'GRP_SOSY_TEST', 1, 0, 'Draft', NULL, NULL, 0);

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_orders`
--

CREATE TABLE `sh_orders` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `uuid` varchar(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `order_number` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `source` enum('local','online','kiosk','delivery_aggregator') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'local',
  `type` enum('dine_in','takeaway','delivery') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'dine_in',
  `status` enum('new','pending','preparing','ready','in_delivery','completed','cancelled') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'new',
  `payment_method` enum('cash','card','online','mixed') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'cash',
  `payment_status` enum('unpaid','paid','refunded') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'unpaid',
  `total_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `table_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `customer_name` varchar(150) DEFAULT NULL,
  `customer_phone` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `address` text DEFAULT NULL,
  `nip` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_order_items`
--

CREATE TABLE `sh_order_items` (
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `menu_item_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `snapshot_name` varchar(150) NOT NULL,
  `quantity` decimal(10,2) NOT NULL DEFAULT 1.00,
  `unit_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `vat_rate` decimal(5,2) NOT NULL DEFAULT 8.00,
  `course_id` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_order_item_modifiers`
--

CREATE TABLE `sh_order_item_modifiers` (
  `id` int(11) NOT NULL,
  `order_item_id` int(11) NOT NULL,
  `modifier_type` enum('ADDED','REMOVED') CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `modifier_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `snapshot_name` varchar(150) NOT NULL,
  `price_change` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_price_tiers`
--

CREATE TABLE `sh_price_tiers` (
  `id` int(11) NOT NULL,
  `target_type` enum('ITEM','MODIFIER') NOT NULL,
  `target_sku` varchar(50) NOT NULL,
  `channel` enum('POS','Takeaway','Delivery') NOT NULL,
  `price` decimal(10,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_price_tiers`
--

INSERT INTO `sh_price_tiers` (`id`, `target_type`, `target_sku`, `channel`, `price`) VALUES
(1, 'MODIFIER', 'OPT_FD', 'POS', 1.00),
(2, 'MODIFIER', 'OPT_FD', 'Takeaway', 1.00),
(3, 'MODIFIER', 'OPT_FD', 'Delivery', 1.00),
(4, 'MODIFIER', 'OPT_ASDFSAF', 'POS', 0.00),
(5, 'MODIFIER', 'OPT_ASDFSAF', 'Takeaway', 0.00),
(6, 'MODIFIER', 'OPT_ASDFSAF', 'Delivery', 0.00),
(7, 'ITEM', 'PIZZA_DI_PARMA', 'POS', 70.24),
(8, 'ITEM', 'PIZZA_DI_PARMA', 'Takeaway', 23.00),
(9, 'ITEM', 'PIZZA_DI_PARMA', 'Delivery', 34.00),
(10, 'MODIFIER', 'OPT_ASFDGDSGDS', 'POS', 1.00),
(11, 'MODIFIER', 'OPT_ASFDGDSGDS', 'Takeaway', 1.00),
(12, 'MODIFIER', 'OPT_ASFDGDSGDS', 'Delivery', 2.00),
(13, 'MODIFIER', 'OPT_SFA', 'POS', 10.00),
(14, 'MODIFIER', 'OPT_SFA', 'Takeaway', 0.00),
(15, 'MODIFIER', 'OPT_SFA', 'Delivery', 0.00),
(16, 'MODIFIER', 'OPT_ASDASFSA', 'POS', 1.00),
(17, 'MODIFIER', 'OPT_ASDASFSA', 'Takeaway', 0.00),
(18, 'MODIFIER', 'OPT_ASDASFSA', 'Delivery', 0.00),
(22, 'ITEM', 'ITM_MARGHERITA', 'POS', 10.00),
(36, 'MODIFIER', 'OPT_POMIDOROWY', 'POS', 4.00),
(37, 'MODIFIER', 'OPT_POMIDOROWY', 'Takeaway', 4.00),
(38, 'MODIFIER', 'OPT_POMIDOROWY', 'Delivery', 4.00),
(39, 'MODIFIER', 'OPT_MAJONEZOWY', 'POS', 4.00),
(40, 'MODIFIER', 'OPT_MAJONEZOWY', 'Takeaway', 4.00),
(41, 'MODIFIER', 'OPT_MAJONEZOWY', 'Delivery', 4.00),
(46, 'ITEM', 'ITM_MARGHERITA', 'Takeaway', 0.00),
(47, 'ITEM', 'ITM_MARGHERITA', 'Delivery', 0.00);

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_recipes`
--

CREATE TABLE `sh_recipes` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `menu_item_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `warehouse_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `quantity_base` decimal(10,3) NOT NULL,
  `waste_percent` decimal(5,2) NOT NULL DEFAULT 0.00,
  `is_packaging` tinyint(1) NOT NULL DEFAULT 0,
  `valid_from` date DEFAULT NULL,
  `valid_to` date DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_recipes`
--

INSERT INTO `sh_recipes` (`id`, `tenant_id`, `menu_item_sku`, `warehouse_sku`, `quantity_base`, `waste_percent`, `is_packaging`, `valid_from`, `valid_to`, `updated_at`) VALUES
(13, 1, 'ITM_MARGHERITA', 'SKU_MAKA_00', 2.000, 0.00, 0, NULL, NULL, '2026-04-07 00:34:48'),
(14, 1, 'ITM_MARGHERITA', 'SKU_SER_MOZZ', 1.000, 0.00, 0, NULL, NULL, '2026-04-07 00:34:48'),
(15, 1, 'ITM_MARGHERITA', 'SKU_SOS_MUTTI', 2.000, 0.00, 0, NULL, NULL, '2026-04-07 00:34:48');

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_recipe_steps`
--

CREATE TABLE `sh_recipe_steps` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `menu_item_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `step_order` int(11) NOT NULL DEFAULT 1,
  `instruction` text NOT NULL,
  `ccp_temp_min` decimal(5,2) DEFAULT NULL,
  `ccp_temp_max` decimal(5,2) DEFAULT NULL,
  `prep_time_seconds` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_tables`
--

CREATE TABLE `sh_tables` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `table_number` varchar(10) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `qr_key` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `status` enum('free','occupied','dirty','reserved') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'free',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_tenants`
--

CREATE TABLE `sh_tenants` (
  `id` int(11) NOT NULL,
  `nip` varchar(20) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `name` varchar(100) NOT NULL,
  `primary_color` varchar(7) CHARACTER SET ascii COLLATE ascii_bin DEFAULT '#e63946',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sh_tenants`
--

INSERT INTO `sh_tenants` (`id`, `nip`, `name`, `primary_color`, `is_active`, `is_deleted`, `created_at`, `updated_at`) VALUES
(1, NULL, 'Centrala SliceHub', '#e63946', 1, 0, '2026-04-06 20:23:59', '2026-04-06 20:23:59');

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sh_work_sessions`
--

CREATE TABLE `sh_work_sessions` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `start_time` datetime NOT NULL,
  `end_time` datetime DEFAULT NULL,
  `total_time` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `sys_items`
--

CREATE TABLE `sys_items` (
  `sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `name` varchar(150) NOT NULL,
  `base_unit` varchar(10) NOT NULL DEFAULT 'szt',
  `vat_rate_purchase` decimal(5,2) NOT NULL DEFAULT 23.00,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `search_aliases` varchar(255) DEFAULT NULL COMMENT 'Odmiany po przecinku, np. mąką, mące, mąki'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sys_items`
--

INSERT INTO `sys_items` (`sku`, `tenant_id`, `name`, `base_unit`, `vat_rate_purchase`, `is_active`, `is_deleted`, `updated_at`, `search_aliases`) VALUES
('SKU_KARTON_32', 1, 'Karton do Pizzy 32cm', 'szt', 23.00, 1, 0, '2026-04-06 21:38:06', NULL),
('SKU_MAKA_00', 1, 'Mąka Typ 00', 'kg', 0.00, 1, 0, '2026-04-06 22:57:46', 'mąka,mąką,mące,mąki'),
('SKU_SER_MOZZ', 1, 'Ser Mozzarella', 'kg', 5.00, 1, 0, '2026-04-06 22:57:46', 'ser,serem,sera,serze,mozzarellą,mozzarelli'),
('SKU_SOS_MUTTI', 1, 'Sos Pomidorowy Mutti', 'l', 8.00, 1, 0, '2026-04-06 22:57:46', 'sos,sosem,sosu,pomidorowym');

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `wh_inventory_docs`
--

CREATE TABLE `wh_inventory_docs` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `doc_number` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `doc_type` enum('PZ','WZ','RW','IN') CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `supplier_name` varchar(150) DEFAULT NULL,
  `supplier_invoice_number` varchar(50) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `wh_inventory_doc_items`
--

CREATE TABLE `wh_inventory_doc_items` (
  `id` int(11) NOT NULL,
  `doc_id` int(11) NOT NULL,
  `sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `quantity` decimal(10,3) NOT NULL,
  `unit_price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `lot_number` varchar(50) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `expiration_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `wh_ksef_mapping`
--

CREATE TABLE `wh_ksef_mapping` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `external_name` varchar(255) NOT NULL,
  `internal_sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `wh_stock`
--

CREATE TABLE `wh_stock` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `sku` varchar(50) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `quantity` decimal(10,3) NOT NULL DEFAULT 0.000,
  `lot_number` varchar(50) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `expiration_date` date DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indeksy dla zrzutów tabel
--

--
-- Indeksy dla tabeli `sh_categories`
--
ALTER TABLE `sh_categories`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`);

--
-- Indeksy dla tabeli `sh_item_modifiers`
--
ALTER TABLE `sh_item_modifiers`
  ADD PRIMARY KEY (`item_id`,`group_id`),
  ADD KEY `fk_item_mod_group` (`group_id`);

--
-- Indeksy dla tabeli `sh_modifiers`
--
ALTER TABLE `sh_modifiers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_mod_group` (`group_id`);

--
-- Indeksy dla tabeli `sh_modifier_groups`
--
ALTER TABLE `sh_modifier_groups`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `sh_orders`
--
ALTER TABLE `sh_orders`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_order_uuid` (`uuid`),
  ADD KEY `tenant_id` (`tenant_id`),
  ADD KEY `table_id` (`table_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `sh_order_items`
--
ALTER TABLE `sh_order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_id` (`order_id`),
  ADD KEY `menu_item_sku` (`menu_item_sku`);

--
-- Indeksy dla tabeli `sh_order_item_modifiers`
--
ALTER TABLE `sh_order_item_modifiers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_item_id` (`order_item_id`);

--
-- Indeksy dla tabeli `sh_price_tiers`
--
ALTER TABLE `sh_price_tiers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_tier_idx` (`target_type`,`target_sku`,`channel`);

--
-- Indeksy dla tabeli `sh_recipes`
--
ALTER TABLE `sh_recipes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_recipes_menu_v3` (`menu_item_sku`),
  ADD KEY `fk_recipes_wh_v3` (`warehouse_sku`);

--
-- Indeksy dla tabeli `sh_recipe_steps`
--
ALTER TABLE `sh_recipe_steps`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_steps_menu` (`menu_item_sku`);

--
-- Indeksy dla tabeli `sh_tables`
--
ALTER TABLE `sh_tables`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`);

--
-- Indeksy dla tabeli `sh_tenants`
--
ALTER TABLE `sh_tenants`
  ADD PRIMARY KEY (`id`);

--
-- Indeksy dla tabeli `sh_work_sessions`
--
ALTER TABLE `sh_work_sessions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indeksy dla tabeli `sys_items`
--
ALTER TABLE `sys_items`
  ADD PRIMARY KEY (`sku`),
  ADD KEY `tenant_id` (`tenant_id`);

--
-- Indeksy dla tabeli `wh_inventory_docs`
--
ALTER TABLE `wh_inventory_docs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`),
  ADD KEY `fk_whdocs_user` (`created_by`);

--
-- Indeksy dla tabeli `wh_inventory_doc_items`
--
ALTER TABLE `wh_inventory_doc_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `doc_id` (`doc_id`),
  ADD KEY `sku` (`sku`);

--
-- Indeksy dla tabeli `wh_ksef_mapping`
--
ALTER TABLE `wh_ksef_mapping`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`),
  ADD KEY `internal_sku` (`internal_sku`);

--
-- Indeksy dla tabeli `wh_stock`
--
ALTER TABLE `wh_stock`
  ADD PRIMARY KEY (`id`),
  ADD KEY `tenant_id` (`tenant_id`),
  ADD KEY `sku` (`sku`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `sh_categories`
--
ALTER TABLE `sh_categories`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT for table `sh_modifiers`
--
ALTER TABLE `sh_modifiers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

--
-- AUTO_INCREMENT for table `sh_modifier_groups`
--
ALTER TABLE `sh_modifier_groups`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;

--
-- AUTO_INCREMENT for table `sh_orders`
--
ALTER TABLE `sh_orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sh_order_items`
--
ALTER TABLE `sh_order_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sh_order_item_modifiers`
--
ALTER TABLE `sh_order_item_modifiers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sh_price_tiers`
--
ALTER TABLE `sh_price_tiers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=48;

--
-- AUTO_INCREMENT for table `sh_recipes`
--
ALTER TABLE `sh_recipes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

--
-- AUTO_INCREMENT for table `sh_recipe_steps`
--
ALTER TABLE `sh_recipe_steps`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sh_tables`
--
ALTER TABLE `sh_tables`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sh_tenants`
--
ALTER TABLE `sh_tenants`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `sh_work_sessions`
--
ALTER TABLE `sh_work_sessions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `wh_inventory_docs`
--
ALTER TABLE `wh_inventory_docs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `wh_inventory_doc_items`
--
ALTER TABLE `wh_inventory_doc_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `wh_ksef_mapping`
--
ALTER TABLE `wh_ksef_mapping`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `wh_stock`
--
ALTER TABLE `wh_stock`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `sh_categories`
--
ALTER TABLE `sh_categories`
  ADD CONSTRAINT `fk_categories_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sh_item_modifiers`
--
ALTER TABLE `sh_item_modifiers`
  ADD CONSTRAINT `fk_item_mod_group` FOREIGN KEY (`group_id`) REFERENCES `sh_modifier_groups` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_item_mod_item` FOREIGN KEY (`item_id`) REFERENCES `sh_menu_items` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sh_modifiers`
--
ALTER TABLE `sh_modifiers`
  ADD CONSTRAINT `fk_mod_group` FOREIGN KEY (`group_id`) REFERENCES `sh_modifier_groups` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sh_orders`
--
ALTER TABLE `sh_orders`
  ADD CONSTRAINT `fk_orders_table` FOREIGN KEY (`table_id`) REFERENCES `sh_tables` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_orders_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_orders_user` FOREIGN KEY (`created_by`) REFERENCES `sh_users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `sh_order_items`
--
ALTER TABLE `sh_order_items`
  ADD CONSTRAINT `fk_orderitems_order` FOREIGN KEY (`order_id`) REFERENCES `sh_orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_orderitems_sku` FOREIGN KEY (`menu_item_sku`) REFERENCES `sh_menu_items` (`ascii_key`) ON DELETE CASCADE;

--
-- Constraints for table `sh_order_item_modifiers`
--
ALTER TABLE `sh_order_item_modifiers`
  ADD CONSTRAINT `fk_modifiers_orderitem` FOREIGN KEY (`order_item_id`) REFERENCES `sh_order_items` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sh_recipes`
--
ALTER TABLE `sh_recipes`
  ADD CONSTRAINT `fk_recipes_menu_v3` FOREIGN KEY (`menu_item_sku`) REFERENCES `sh_menu_items` (`ascii_key`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_recipes_wh_v3` FOREIGN KEY (`warehouse_sku`) REFERENCES `sys_items` (`sku`) ON DELETE CASCADE;

--
-- Constraints for table `sh_recipe_steps`
--
ALTER TABLE `sh_recipe_steps`
  ADD CONSTRAINT `fk_steps_menu` FOREIGN KEY (`menu_item_sku`) REFERENCES `sh_menu_items` (`ascii_key`) ON DELETE CASCADE;

--
-- Constraints for table `sh_tables`
--
ALTER TABLE `sh_tables`
  ADD CONSTRAINT `fk_tables_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sh_work_sessions`
--
ALTER TABLE `sh_work_sessions`
  ADD CONSTRAINT `fk_session_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_session_user` FOREIGN KEY (`user_id`) REFERENCES `sh_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sys_items`
--
ALTER TABLE `sys_items`
  ADD CONSTRAINT `fk_sysitems_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `wh_inventory_docs`
--
ALTER TABLE `wh_inventory_docs`
  ADD CONSTRAINT `fk_whdocs_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_whdocs_user` FOREIGN KEY (`created_by`) REFERENCES `sh_users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `wh_inventory_doc_items`
--
ALTER TABLE `wh_inventory_doc_items`
  ADD CONSTRAINT `fk_whdocitems_doc` FOREIGN KEY (`doc_id`) REFERENCES `wh_inventory_docs` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_whdocitems_sku` FOREIGN KEY (`sku`) REFERENCES `sys_items` (`sku`) ON DELETE CASCADE;

--
-- Constraints for table `wh_ksef_mapping`
--
ALTER TABLE `wh_ksef_mapping`
  ADD CONSTRAINT `fk_ksef_sku` FOREIGN KEY (`internal_sku`) REFERENCES `sys_items` (`sku`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_ksef_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `wh_stock`
--
ALTER TABLE `wh_stock`
  ADD CONSTRAINT `fk_whstock_sku` FOREIGN KEY (`sku`) REFERENCES `sys_items` (`sku`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_whstock_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `sh_tenants` (`id`) ON DELETE CASCADE;
COMMIT;

