-- https://www.phpmyadmin.net/
--
-- Czas generowania: 07 Mar 2025, 22:13
-- Wersja serwera: 10.5.26-MariaDB-0+deb11u2
-- Wersja PHP: 7.4.33

START TRANSACTION;



--
-- Baza danych: `domopieki`
--

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

--
-- Struktura tabeli dla tabeli `companies`
--

CREATE TABLE `companies` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `nip` varchar(10) NOT NULL,
  `legal_form` varchar(100) DEFAULT NULL,
  `regon` varchar(20) DEFAULT NULL,
  `krs` varchar(20) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `postal_code` varchar(10) DEFAULT NULL,
  `country` varchar(100) DEFAULT 'Polska',
  `phone` varchar(20) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `bank_name` varchar(255) DEFAULT NULL,
  `bank_account` varchar(50) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `is_active` tinyint(1) DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `companies`
--

INSERT INTO `companies` (`id`, `name`, `nip`, `legal_form`, `regon`, `krs`, `address`, `city`, `postal_code`, `country`, `phone`, `email`, `website`, `bank_name`, `bank_account`, `created_at`, `updated_at`, `is_active`) VALUES
(5, 'Klaubas Sp.z o.o.', '8952170216', 'Sp. z o.o.', '', '', '', '', '', 'Polska', '', '', '', '', '', '2024-10-26 14:07:37', '2024-10-26 14:07:37', 1);

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

--
-- Struktura tabeli dla tabeli `costs`
--

CREATE TABLE `costs` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `cost_type_id` int(11) DEFAULT NULL,
  `amount` decimal(10,2) NOT NULL,
  `date` date NOT NULL,
  `description` text DEFAULT NULL,
  `is_general` tinyint(1) NOT NULL DEFAULT 0,
  `status` enum('opłacone','nieopłacone') NOT NULL DEFAULT 'nieopłacone',
  `created_by` bigint(20) UNSIGNED 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_general_ci;

--
-- Zrzut danych tabeli `costs`
--

INSERT INTO `costs` (`id`, `company_id`, `cost_type_id`, `amount`, `date`, `description`, `is_general`, `status`, `created_by`, `created_at`, `updated_at`) VALUES
(2, 5, 16, '4000.00', '2024-11-07', 'wykarczowanie działki', 0, 'opłacone', NULL, '2024-11-07 16:11:32', '2024-11-07 16:11:32'),
(3, 5, 16, '50.00', '2024-11-25', 'mapki', 0, 'opłacone', NULL, '2024-11-25 11:21:23', '2024-11-25 11:21:23'),
(4, 5, 13, '800.00', '2024-12-09', 'rzeczoznawca', 0, 'opłacone', 9, '2024-12-09 18:19:39', '2024-12-09 18:19:39'),
(5, 5, 17, '500.00', '2024-12-09', 'Akumulator', 0, 'opłacone', 8, '2024-12-09 18:38:47', '2024-12-09 18:38:47'),
(6, 5, 17, '28171.00', '2024-09-23', 'Zakup samochodu', 0, 'opłacone', 8, '2024-12-10 08:18:11', '2024-12-10 08:18:11'),
(7, 5, 17, '3690.00', '2024-09-30', 'Prowizja za sprowadzenie pojazdu', 0, 'opłacone', 8, '2024-12-10 08:22:17', '2024-12-10 08:22:17'),
(8, 5, 17, '6820.00', '2024-10-30', 'Koszt Cło + port', 0, 'opłacone', 8, '2024-12-10 08:26:45', '2024-12-10 08:26:45'),
(9, 5, 17, '2460.00', '2024-12-04', 'Transport z portu pod dom', 0, 'opłacone', 8, '2024-12-10 08:28:29', '2024-12-10 08:29:35'),
(10, 5, 17, '80.00', '2024-12-10', 'Dolny wspornik', 0, 'opłacone', 8, '2024-12-10 13:01:09', '2024-12-16 07:14:06'),
(11, 5, 17, '50.00', '2024-12-11', 'Łapa skrzyni', 0, 'nieopłacone', 8, '2024-12-11 08:36:32', '2024-12-11 08:36:32'),
(12, 5, 17, '250.00', '2024-12-11', 'Rozrusznik', 0, 'opłacone', 8, '2024-12-11 12:36:56', '2024-12-13 08:09:25'),
(13, 5, 17, '200.00', '2024-12-13', 'Belka pod chłodnice', 0, 'opłacone', 8, '2024-12-13 08:09:08', '2024-12-13 08:09:08'),
(14, 5, 17, '1150.00', '2024-12-16', 'Wydech', 0, 'opłacone', 8, '2024-12-16 07:13:14', '2024-12-16 07:13:14'),
(15, 5, 17, '39.00', '2024-12-16', 'zaslepka rozrusznika', 0, 'opłacone', 9, '2024-12-16 16:18:04', '2024-12-16 16:18:04'),
(16, 5, 17, '50.00', '2024-12-16', 'kabel do rozrusznika', 0, 'opłacone', 9, '2024-12-16 16:18:23', '2024-12-16 16:18:23'),
(17, 5, 17, '54.00', '2024-12-18', 'sruby do tłumika', 0, 'opłacone', 9, '2024-12-18 09:36:46', '2024-12-18 09:36:46'),
(18, 5, 4, '220.00', '2024-12-18', 'lampy, połowa ceny', 0, 'opłacone', 9, '2024-12-18 09:37:35', '2024-12-18 09:37:35'),
(19, 5, 1, '738.00', '2025-01-10', 'Tłumaczenia dokumentów i procedura akcyzy', 0, 'opłacone', 5, '2025-01-10 16:17:42', '2025-01-10 16:17:42'),
(20, 5, 1, '5901.00', '2025-01-11', 'AKCYZA', 0, 'opłacone', 8, '2025-01-11 09:38:06', '2025-01-11 09:38:06'),
(21, 5, 17, '780.00', '2025-01-17', 'poduszki', 0, 'opłacone', 9, '2025-01-17 12:53:07', '2025-01-20 11:50:02'),
(22, 5, 17, '4459.00', '2025-01-20', 'sanki oleje i inne ', 0, 'opłacone', 9, '2025-01-20 11:49:33', '2025-01-20 11:49:33'),
(23, 5, 17, '2337.00', '2025-01-21', 'hamulce od finki', 0, 'opłacone', 9, '2025-01-21 13:11:57', '2025-01-21 13:11:57'),
(24, 5, 17, '94.00', '2025-01-27', 'płyn chłodniczy smary', 0, 'opłacone', 9, '2025-01-27 14:00:11', '2025-01-28 10:15:16'),
(25, 5, 17, '119.00', '2025-01-29', 'sruby do hamulców', 0, 'opłacone', 9, '2025-01-29 16:58:42', '2025-01-29 16:58:42'),
(26, 5, 17, '100.00', '2025-01-30', 'Cło za szczęki', 0, 'opłacone', 9, '2025-01-30 13:41:23', '2025-01-30 13:41:23'),
(27, 5, 17, '3150.00', '2025-01-30', 'Felgi', 0, 'opłacone', 9, '2025-01-30 13:43:39', '2025-01-30 13:43:39'),
(28, 5, 17, '340.00', '2025-02-03', 'klocki', 0, 'opłacone', 9, '2025-02-03 12:37:01', '2025-02-03 12:37:01'),
(29, 5, 17, '100.00', '2025-02-04', 'przewody hamulcowe', 0, 'opłacone', 9, '2025-02-04 18:01:40', '2025-02-04 18:01:40'),
(30, 5, 17, '394.00', '2025-02-07', 'belka pod chłodnice', 0, 'opłacone', 9, '2025-02-07 17:04:05', '2025-02-07 17:04:05'),
(32, 5, 17, '160.00', '2025-02-12', 'mocowania do chłodnicy', 0, 'opłacone', 9, '2025-02-12 11:03:08', '2025-02-12 11:03:08'),
(36, 5, 16, '1400.00', '2025-03-05', 'geodeta', 0, 'opłacone', 5, '2025-03-05 12:40:09', '2025-03-05 12:40:09');

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

--
-- Struktura tabeli dla tabeli `cost_files`
--

CREATE TABLE `cost_files` (
  `id` int(11) NOT NULL,
  `cost_id` int(11) NOT NULL,
  `file_path` varchar(255) NOT NULL,
  `file_name` varchar(255) NOT NULL,
  `file_type` varchar(50) DEFAULT NULL,
  `uploaded_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `cost_relations`
--

CREATE TABLE `cost_relations` (
  `id` int(11) NOT NULL,
  `cost_id` int(11) NOT NULL,
  `related_id` int(11) NOT NULL,
  `relation_type` enum('vehicle','equipment','employee','building_project','building_stage') NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `cost_relations`
--

INSERT INTO `cost_relations` (`id`, `cost_id`, `related_id`, `relation_type`, `created_at`) VALUES
(1, 4, 12, 'vehicle', '2024-12-09 18:19:39'),
(2, 5, 12, 'vehicle', '2024-12-09 18:38:47'),
(3, 6, 12, 'vehicle', '2024-12-10 08:18:11'),
(4, 7, 12, 'vehicle', '2024-12-10 08:22:17'),
(5, 8, 12, 'vehicle', '2024-12-10 08:26:45'),
(6, 9, 12, 'vehicle', '2024-12-10 08:28:29'),
(8, 10, 12, 'vehicle', '2024-12-10 13:01:09'),
(9, 11, 12, 'vehicle', '2024-12-11 08:36:32'),
(10, 12, 12, 'vehicle', '2024-12-11 12:36:56'),
(11, 13, 12, 'vehicle', '2024-12-13 08:09:08'),
(13, 14, 12, 'vehicle', '2024-12-16 07:13:14'),
(16, 15, 12, 'vehicle', '2024-12-16 16:18:04'),
(17, 16, 12, 'vehicle', '2024-12-16 16:18:23'),
(18, 17, 12, 'vehicle', '2024-12-18 09:36:46'),
(19, 18, 12, 'vehicle', '2024-12-18 09:37:35'),
(20, 19, 12, 'vehicle', '2025-01-10 16:17:42'),
(21, 20, 12, 'vehicle', '2025-01-11 09:38:06'),
(22, 21, 12, 'vehicle', '2025-01-17 12:53:07'),
(23, 22, 12, 'vehicle', '2025-01-20 11:49:33'),
(25, 23, 12, 'vehicle', '2025-01-21 13:11:57'),
(26, 24, 12, 'vehicle', '2025-01-27 14:00:11'),
(28, 25, 12, 'vehicle', '2025-01-29 16:58:42'),
(29, 26, 12, 'vehicle', '2025-01-30 13:41:23'),
(30, 27, 12, 'vehicle', '2025-01-30 13:43:39'),
(31, 28, 12, 'vehicle', '2025-02-03 12:37:01'),
(32, 29, 12, 'vehicle', '2025-02-04 18:01:40'),
(33, 30, 12, 'vehicle', '2025-02-07 17:04:05'),
(35, 32, 12, 'vehicle', '2025-02-12 11:03:08');

--
-- Wyzwalacze `cost_relations`
--
DELIMITER $$
CREATE TRIGGER `before_insert_cost_relation` BEFORE INSERT ON `cost_relations` FOR EACH ROW BEGIN
    DECLARE is_general_cost BOOLEAN;
    SELECT is_general INTO is_general_cost FROM costs WHERE id = NEW.cost_id;
    IF is_general_cost THEN
        SIGNAL SQLSTATE '45000' 
        SET MESSAGE_TEXT = 'Cannot add relation to a general cost';
    END IF;
END
$$
DELIMITER ;

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

--
-- Struktura tabeli dla tabeli `cost_types`
--

CREATE TABLE `cost_types` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `description` text 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_general_ci;

--
-- Zrzut danych tabeli `cost_types`
--

INSERT INTO `cost_types` (`id`, `name`, `description`, `created_at`, `updated_at`) VALUES
(1, 'Koszty operacyjne', 'Koszty związane z bieżącą działalnością firmy', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(2, 'Koszty pracownicze', 'Wynagrodzenia, składki ZUS, świadczenia pracownicze', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(3, 'Koszty transportu', 'Koszty związane z transportem towarów i osób', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(4, 'Koszty utrzymania sprzętu', 'Naprawy, konserwacje, części zamienne', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(5, 'Koszty marketingu i reklamy', 'Wydatki na promocję i reklamę firmy', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(6, 'Koszty administracyjne', 'Koszty biurowe, opłaty administracyjne', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(7, 'Koszty najmu/dzierżawy', 'Opłaty za wynajem biur, magazynów, sprzętu', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(8, 'Koszty energii i mediów', 'Opłaty za prąd, gaz, wodę, internet', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(9, 'Koszty szkoleń i rozwoju', 'Wydatki na szkolenia i rozwój pracowników', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(10, 'Koszty ubezpieczeń', 'Ubezpieczenia majątkowe, OC, AC', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(11, 'Koszty IT i oprogramowania', 'Licencje na oprogramowanie, sprzęt IT', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(12, 'Koszty materiałów i surowców', 'Zakup materiałów do produkcji lub świadczenia usług', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(13, 'Koszty usług zewnętrznych', 'Wydatki na usługi podwykonawców', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(14, 'Koszty podróży służbowych', 'Delegacje, noclegi, diety', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(15, 'Koszty finansowe', 'Odsetki od kredytów, opłaty bankowe', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(16, 'Działka', 'Koszty związane z przygotowaniem działki', '2024-10-16 17:34:34', '2024-10-16 17:34:34'),
(17, 'cześci samochodowe', NULL, '2024-12-09 18:14:53', '2024-12-09 18:14:53'),
(18, 'koszty budowy', NULL, '2025-02-28 19:02:46', '2025-02-28 19:02:46');

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

--
-- Struktura tabeli dla tabeli `documents`
--

CREATE TABLE `documents` (
  `id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `file_path` varchar(255) NOT NULL,
  `file_type` varchar(50) NOT NULL,
  `category_id` int(11) DEFAULT NULL,
  `company_id` int(11) DEFAULT NULL,
  `related_entity_type` enum('employee','vehicle','equipment','none') DEFAULT 'none',
  `related_entity_id` int(10) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `policy_number` varchar(50) DEFAULT NULL,
  `policy_start_date` date DEFAULT NULL,
  `policy_end_date` date DEFAULT NULL,
  `insurance_company` varchar(100) DEFAULT NULL,
  `is_generated` tinyint(1) DEFAULT 0,
  `template_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `documents`
--

INSERT INTO `documents` (`id`, `title`, `description`, `file_path`, `file_type`, `category_id`, `company_id`, `related_entity_type`, `related_entity_id`, `created_at`, `updated_at`, `created_by`, `policy_number`, `policy_start_date`, `policy_end_date`, `insurance_company`, `is_generated`, `template_id`) VALUES
(26, 'ford dowód amerykanski', 'dowod', '/var/www/html/domopieki/app/routes/../../uploads/documents/67627c0bc2dc3_Skan_20241218.pdf', 'application/pdf', 2, 5, 'vehicle', 12, '2024-12-18 07:38:51', '2024-12-18 07:38:51', 5, NULL, NULL, NULL, NULL, 0, NULL),
(27, 'ford dowód amerykanski', '2 strona', '/var/www/html/domopieki/app/routes/../../uploads/documents/67627c480f8b2_Skan_20241218 (2).pdf', 'application/pdf', 2, 5, 'vehicle', 12, '2024-12-18 07:39:52', '2024-12-18 07:39:52', 5, NULL, NULL, NULL, NULL, 0, NULL),
(28, 'ford fv', 'fv za forda', '/var/www/html/domopieki/app/routes/../../uploads/documents/67627c7031c89_Skan_20241218 (3).pdf', 'application/pdf', 2, 5, 'vehicle', 12, '2024-12-18 07:40:32', '2024-12-18 07:40:41', 5, NULL, NULL, NULL, NULL, 0, NULL),
(29, 'ford cło', 'cło', '/var/www/html/domopieki/app/routes/../../uploads/documents/67627c9e936b7_Skan_20241218 (4).pdf', 'application/pdf', 2, 5, 'vehicle', 12, '2024-12-18 07:41:18', '2024-12-18 07:41:18', 5, NULL, NULL, NULL, NULL, 0, NULL),
(30, 'ford cło', '2 strona', '/var/www/html/domopieki/app/routes/../../uploads/documents/67627cb847d41_Skan_20241218 (5).pdf', 'application/pdf', 2, 5, 'vehicle', 12, '2024-12-18 07:41:44', '2024-12-18 07:41:44', 5, NULL, NULL, NULL, NULL, 0, NULL);

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

--
-- Struktura tabeli dla tabeli `document_categories`
--

CREATE TABLE `document_categories` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text 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_general_ci;

--
-- Zrzut danych tabeli `document_categories`
--

INSERT INTO `document_categories` (`id`, `name`, `description`, `created_at`, `updated_at`) VALUES
(1, 'Dokumenty pracownicze', 'Umowy o pracę, szkolenia BHP, badania lekarskie, certyfikaty i uprawnienia zawodowe, oceny pracownicze', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(2, 'Dokumenty pojazdów', 'Dowody rejestracyjne, polisy ubezpieczeniowe, przeglądy techniczne, karty drogowe, umowy leasingowe', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(3, 'Dokumenty finansowe', 'Faktury zakupowe, faktury sprzedażowe, umowy z kontrahentami, raporty finansowe, dokumenty bankowe', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(4, 'Dokumenty projektowe', 'Projekty budowlane, kosztorysy, harmonogramy prac, pozwolenia na budowę, protokoły odbioru', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(5, 'Dokumenty BHP', 'Oceny ryzyka zawodowego, instrukcje stanowiskowe, protokoły kontroli BHP, karty charakterystyki substancji niebezpiecznych', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(6, 'Dokumenty jakości', 'Certyfikaty jakości materiałów, atesty i deklaracje zgodności, protokoły z testów i badań', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(7, 'Dokumenty prawne', 'Umowy z podwykonawcami, umowy najmu/dzierżawy, pozwolenia i licencje, dokumenty sądowe', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(8, 'Dokumenty marketingowe', 'Materiały promocyjne, prezentacje firmowe, referencje i rekomendacje', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(9, 'Dokumenty techniczne', 'Instrukcje obsługi sprzętu, dokumentacje techniczne, schematy i rysunki techniczne', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(10, 'Dokumenty administracyjne', 'Regulaminy wewnętrzne, procedury firmowe, korespondencja urzędowa', '2024-07-11 14:31:17', '2024-07-11 14:31:17'),
(11, 'Polisa inna', 'Polisy ubezpieczeniowe', '2024-08-05 14:52:49', '2024-08-05 14:55:53'),
(12, 'Polisa OC', 'polisa OC', '2024-08-05 14:55:23', '2024-08-05 14:55:23'),
(13, 'Polisa AC', 'Polisa AC', '2024-08-05 14:55:36', '2024-08-05 14:55:36'),
(14, 'Gwarancje', 'Gwarancje lub inne dokumenty potwierdzające gwarancje oraz jej czas trwania', '2024-08-08 09:17:59', '2024-08-08 09:17:59'),
(15, 'Aneksy', '', '2024-08-13 13:02:54', '2024-08-13 13:02:54');

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

--
-- Struktura tabeli dla tabeli `document_templates`
--

CREATE TABLE `document_templates` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `content` text DEFAULT NULL,
  `category_id` int(11) DEFAULT NULL,
  `editable_fields` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `form_structure` text DEFAULT NULL,
  `html_template` text DEFAULT NULL COMMENT 'Szablon HTML dokumentu',
  `css_styles` text DEFAULT NULL COMMENT 'Style CSS dla dokumentu',
  `background_image` varchar(255) DEFAULT NULL COMMENT 'Ścieżka do obrazu tła'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `document_templates`
--

INSERT INTO `document_templates` (`id`, `name`, `content`, `category_id`, `editable_fields`, `created_at`, `updated_at`, `form_structure`, `html_template`, `css_styles`, `background_image`) VALUES
(3, 'wzór', '<h1>Karta szkolenia wstępnego</h1>\r\n<p>Imię i nazwisko pracownika: {{employee_name}}</p>\r\n<p>Firma: {{company_name}}</p>\r\n<p>Stanowisko: {{position}}</p>\r\n<p>Osoba przeprowadzająca instruktaż: {{instructor_name}}</p>\r\n<p>Data przeprowadzenia instruktażu stanowiskowego: {{workplace_instruction_date}}</p>\r\n<p>Data przeprowadzenia instruktażu ogólnego: {{general_instruction_date}}</p>', 9, '{\r\n  \"EMPLOYEE_NAME\": {\"type\": \"text\", \"label\": \"Imię i nazwisko pracownika\"},\r\n  \"DEPARTMENT\": {\"type\": \"text\", \"label\": \"Nazwa komórki organizacyjnej\"},\r\n  \"GENERAL_INSTRUCTION_DATE\": {\"type\": \"date\", \"label\": \"Data instruktażu ogólnego\"},\r\n  \"GENERAL_INSTRUCTOR_NAME\": {\"type\": \"text\", \"label\": \"Imię i nazwisko instruktora ogólnego\"},\r\n  \"POSITION\": {\"type\": \"text\", \"label\": \"Stanowisko pracy\"},\r\n  \"POSITION_INSTRUCTION_DATE\": {\"type\": \"date\", \"label\": \"Data instruktażu stanowiskowego\"},\r\n  \"POSITION_INSTRUCTOR_NAME\": {\"type\": \"text\", \"label\": \"Imię i nazwisko instruktora stanowiskowego\"}\r\n}', '2024-08-08 14:03:00', '2024-08-14 21:11:28', '[{\"name\":\"employee_name\",\"label\":\"Imi\\u0119 i nazwisko pracownika\",\"type\":\"text\",\"required\":true},{\"name\":\"employee_position\",\"label\":\"Stanowisko pracownika\",\"type\":\"text\",\"required\":true},{\"name\":\"employee_id\",\"label\":\"Numer identyfikacyjny pracownika\",\"type\":\"text\",\"required\":true},{\"name\":\"company_name\",\"label\":\"Nazwa firmy\",\"type\":\"text\",\"required\":true},{\"name\":\"company_address\",\"label\":\"Adres firmy\",\"type\":\"text\",\"required\":true},{\"name\":\"company_nip\",\"label\":\"NIP firmy\",\"type\":\"text\",\"required\":true},{\"name\":\"document_date\",\"label\":\"Data dokumentu\",\"type\":\"date\",\"required\":true},{\"name\":\"document_number\",\"label\":\"Numer dokumentu\",\"type\":\"text\",\"required\":true},{\"name\":\"supervisor_name\",\"label\":\"Imi\\u0119 i nazwisko prze\\u0142o\\u017conego\",\"type\":\"text\",\"required\":true},{\"name\":\"start_date\",\"label\":\"Data rozpocz\\u0119cia\",\"type\":\"date\",\"required\":false},{\"name\":\"end_date\",\"label\":\"Data zako\\u0144czenia\",\"type\":\"date\",\"required\":false},{\"name\":\"salary\",\"label\":\"Wynagrodzenie\",\"type\":\"number\",\"required\":false},{\"name\":\"working_hours\",\"label\":\"Wymiar godzin pracy\",\"type\":\"text\",\"required\":false},{\"name\":\"additional_info\",\"label\":\"Dodatkowe informacje\",\"type\":\"textarea\",\"required\":false}]', '{{employe_first_name}}\r\n{{employe_last_name}}\r\n\r\n\r\n<h1>Umowa o pracę</h1>\r\n<p>Zawarta dnia {{document_date}} pomiędzy:</p>\r\n<p>{{company_name}} z siedzibą w {{company_address}}, NIP: {{company_nip}}</p>\r\n<p>a</p>\r\n<p>{{employee_name}}, zatrudnionym na stanowisku {{employee_position}}</p>\r\n<p>Numer pracownika: {{employee_id}}</p>\r\n<p>Warunki umowy:</p>\r\n<ul>\r\n  <li>Data rozpoczęcia pracy: {{start_date}}</li>\r\n  <li>Wymiar czasu pracy: {{working_hours}}</li>\r\n  <li>Wynagrodzenie: {{salary}} zł brutto</li>\r\n</ul>\r\n<p>Dodatkowe informacje: {{additional_info}}</p>\r\n<p>Podpisy:</p>\r\n<p>Pracodawca: ___________________ Pracownik: ___________________</p>\r\n', 'body {\r\n  font-family: Arial, sans-serif;\r\n  line-height: 1.6;\r\n  color: #333;\r\n}\r\nh1 {\r\n  color: #0056b3;\r\n  text-align: center;\r\n}\r\np {\r\n  margin-bottom: 10px;\r\n}\r\nul {\r\n  margin-left: 20px;\r\n}', '/var/www/html/panel/uploads/background/66b79197ecdc0_Karta szkolenia wstępnego BHP.docx.pdf'),
(6, 'Karta szkolenia wstępnego BHP', NULL, 5, NULL, '2024-08-10 16:10:45', '2024-08-22 11:32:40', '[{\"name\":\"employee_name\",\"label\":\"Imi\\u0119 i nazwisko pracownika\",\"type\":\"text\",\"required\":true},{\"name\":\"company_name\",\"label\":\"Firma pracownika\",\"type\":\"text\",\"required\":true},{\"name\":\"position\",\"label\":\"Stanowisko pracy\",\"type\":\"text\",\"required\":true},{\"name\":\"instructor_name\",\"label\":\"Imi\\u0119 i nazwisko osoby przeprowadzaj\\u0105cej instrukta\\u017c\",\"type\":\"text\",\"required\":true},{\"name\":\"workplace_instruction_date\",\"label\":\"Data przeprowadzenia instrukta\\u017cu stanowiskowego\",\"type\":\"text\",\"required\":true},{\"name\":\"general_instruction_date\",\"label\":\"Data przeprowadzenia instrukta\\u017cu og\\u00f3lnego\",\"type\":\"text\",\"required\":true}]', '<!DOCTYPE html>\r\n<html lang=\"pl\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <title>Karta instruktażu pracownika</title>\r\n</head>\r\n<body>\r\n\r\n        <p class=\"employee-name\"><strong>{{employee_name}}</strong></p>\r\n        <p class=\"company-name\"><strong>{{company_name}}</strong></p>\r\n        <p class=\"position\"><strong>{{position}}</strong></p>\r\n        <p class=\"position2\"><strong>{{position}}</strong></p>    \r\n        <p class=\"instructor-name\"><strong>{{instructor_name}}</strong></p>\r\n        <p class=\"workplace-instruction-date\"><strong>{{workplace_instruction_date}}</strong></p>\r\n        <p class=\"general-instruction-date\"><strong>{{general_instruction_date}}</strong></p>\r\n        <p class=\"instructor-name2\"><strong>{{instructor_name}}</strong></p>\r\n        <p class=\"employee-first-name\"><strong>{{employee_first_name}}</strong></p>\r\n        <p class=\"employee-last-name\"><strong>{{employee_last_name}}</strong></p>\r\n\r\n</body>\r\n</html>', '.employee-name {\r\n    position: absolute;\r\n    top: 180px;\r\n    left: 450px;\r\n}\r\n\r\n.employee-first-name {\r\n    position: absolute;\r\n    top: 505px;\r\n    left: 600px;\r\n}\r\n\r\n.employee-last-name {\r\n    position: absolute;\r\n    top: 525px;\r\n    left: 220px;\r\n}\r\n\r\n.company-name {\r\n    position: absolute;\r\n    top: 244px;\r\n    left: 400px;\r\n}\r\n\r\n.position {\r\n    position: absolute;\r\n    top: 422px;\r\n    left: 470px;\r\n}\r\n.position2 {\r\n    position: absolute;\r\n    top: 548px;\r\n    left: 170px;\r\n}\r\n\r\n.instructor-name {\r\n    position: absolute;\r\n    top: 320px;\r\n    left: 300px;\r\n}\r\n.instructor-name2 {\r\n    position: absolute;\r\n    top: 450px;\r\n    left: 550px;\r\n}\r\n.workplace-instruction-date {\r\n    position: absolute;\r\n    top: 295px;\r\n    left: 430px;\r\n}\r\n\r\n\r\n.general-instruction-date {\r\n    position: absolute;\r\n    top: 445px;\r\n    left: 330px;\r\n}', '/var/www/html/kobas/uploads/background/66bfa34406003_Karta szkolenia wstępnego BHP.docx.pdf');

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

--
-- Struktura tabeli dla tabeli `employee_medical_examinations`
--

CREATE TABLE `employee_medical_examinations` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employee_id` bigint(20) UNSIGNED NOT NULL,
  `examination_date` date NOT NULL,
  `expiration_date` date NOT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `employee_safety_trainings`
--

CREATE TABLE `employee_safety_trainings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employee_id` bigint(20) UNSIGNED NOT NULL,
  `training_date` date NOT NULL,
  `expiration_date` date NOT NULL,
  `training_type` varchar(255) NOT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `employment_periods`
--

CREATE TABLE `employment_periods` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employee_id` bigint(20) UNSIGNED NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED 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_general_ci;

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

--
-- Struktura tabeli dla tabeli `employment_records`
--

CREATE TABLE `employment_records` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `employee_id` bigint(20) UNSIGNED NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `equipment`
--

CREATE TABLE `equipment` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `serial_number` varchar(100) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `purchase_date` date DEFAULT NULL,
  `company_id` int(11) DEFAULT NULL,
  `category` varchar(100) DEFAULT NULL,
  `status` varchar(50) DEFAULT NULL,
  `last_maintenance_date` date DEFAULT NULL,
  `next_maintenance_date` date 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_general_ci;

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

--
-- Struktura tabeli dla tabeli `tasks`
--

CREATE TABLE `tasks` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `priority` enum('low','medium','high') NOT NULL,
  `due_date` date DEFAULT NULL,
  `status` enum('todo','in_progress','done') NOT NULL,
  `assigned_to` bigint(20) UNSIGNED DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED NOT 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_general_ci;

--
-- Zrzut danych tabeli `tasks`
--

INSERT INTO `tasks` (`id`, `title`, `description`, `priority`, `due_date`, `status`, `assigned_to`, `created_by`, `created_at`, `updated_at`) VALUES
(11, 'uzupełnić przeglądy w samochodach', 'serwisowe z toyoty , oraz technicze gdzie nie ma', 'medium', '2024-08-30', 'done', NULL, 5, '2024-08-14 08:00:00', '2024-10-26 08:44:08'),
(12, 'Wykarczować działka', '', 'medium', '2024-11-30', 'done', 8, 8, '2024-10-26 14:08:23', '2024-11-25 11:20:47'),
(13, 'Załatwić zgłoszenie na wykarczowanie', '', 'medium', '2024-10-31', 'done', 9, 8, '2024-10-26 14:09:12', '2024-11-07 14:59:06'),
(14, 'Wytyczyć granice', '', 'medium', '2024-11-08', 'done', 9, 8, '2024-10-26 14:10:06', '2024-11-08 08:22:34');

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

--
-- Struktura tabeli dla tabeli `user_preferences`
--

CREATE TABLE `user_preferences` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `preference_key` varchar(50) NOT NULL,
  `value` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `user_preferences`
--

INSERT INTO `user_preferences` (`id`, `user_id`, `preference_key`, `value`, `created_at`, `updated_at`) VALUES
(1, 5, 'last_company_id', '5', NULL, NULL),
(2, 5, 'last_cost_type_id', '16', NULL, NULL),
(3, 5, 'last_relation_type', 'building_project', NULL, NULL),
(4, 9, 'last_cost_type_id', '17', NULL, NULL),
(5, 9, 'last_company_id', '5', NULL, NULL),
(7, 9, 'last_relation_type', 'vehicle', NULL, NULL),
(18, 8, 'last_cost_type_id', '1', NULL, NULL),
(19, 8, 'last_relation_type', 'vehicle', NULL, NULL),
(21, 8, 'last_company_id', '5', NULL, NULL);

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

--
-- Struktura tabeli dla tabeli `vehicles`
--

CREATE TABLE `vehicles` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `brand` varchar(255) NOT NULL,
  `model` varchar(255) NOT NULL,
  `year` int(11) NOT NULL,
  `registration_number` varchar(255) DEFAULT NULL,
  `vin` varchar(255) NOT NULL,
  `purchase_date` date NOT NULL,
  `company_id` int(11) DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `first_registration_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Zrzut danych tabeli `vehicles`
--

INSERT INTO `vehicles` (`id`, `brand`, `model`, `year`, `registration_number`, `vin`, `purchase_date`, `company_id`, `created_by`, `created_at`, `updated_at`, `first_registration_date`) VALUES
(12, 'ford', 'rs', 2017, NULL, 'WF0DP3TH4H4125892', '2024-11-01', 5, 9, '2024-11-25 11:50:50', '2024-12-11 11:58:49', NULL);

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

--
-- Struktura tabeli dla tabeli `vehicle_inspections`
--

CREATE TABLE `vehicle_inspections` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicle_id` bigint(20) UNSIGNED NOT NULL,
  `inspection_date` date NOT NULL,
  `expiration_date` date NOT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `inspection_type` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `mileage` int(10) UNSIGNED DEFAULT NULL COMMENT 'Przebieg w kilometrach',
  `service_actions` text DEFAULT NULL COMMENT 'Przeprowadzone czynności serwisowe'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `vehicle_monthly_mileages`
--

CREATE TABLE `vehicle_monthly_mileages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicle_id` bigint(20) UNSIGNED NOT NULL,
  `mileage_date` date NOT NULL,
  `mileage` int(10) UNSIGNED NOT NULL,
  `mileage_difference` int(10) UNSIGNED NOT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `vehicle_operating_costs`
--

CREATE TABLE `vehicle_operating_costs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicle_id` bigint(20) UNSIGNED NOT NULL,
  `cost_date` date NOT NULL,
  `mileage` int(10) UNSIGNED DEFAULT NULL,
  `cost_type` varchar(255) NOT NULL,
  `cost_net` decimal(10,2) NOT NULL,
  `cost_gross` decimal(10,2) NOT NULL,
  `description` text DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Struktura tabeli dla tabeli `vehicle_repairs`
--

CREATE TABLE `vehicle_repairs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicle_id` bigint(20) UNSIGNED NOT NULL,
  `repair_date` date NOT NULL,
  `mileage` int(10) UNSIGNED DEFAULT NULL,
  `description` text NOT NULL,
  `cost` decimal(10,2) NOT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

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

--
-- Indeksy dla tabeli `costs`
--
ALTER TABLE `costs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `company_id` (`company_id`),
  ADD KEY `cost_type_id` (`cost_type_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `cost_files`
--
ALTER TABLE `cost_files`
  ADD PRIMARY KEY (`id`),
  ADD KEY `cost_id` (`cost_id`);

--
-- Indeksy dla tabeli `cost_relations`
--
ALTER TABLE `cost_relations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_cost_relation` (`cost_id`,`related_id`,`relation_type`),
  ADD KEY `idx_relation_type` (`relation_type`);

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

--
-- Indeksy dla tabeli `documents`
--
ALTER TABLE `documents`
  ADD PRIMARY KEY (`id`),
  ADD KEY `category_id` (`category_id`),
  ADD KEY `company_id` (`company_id`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `related_entity` (`related_entity_type`,`related_entity_id`),
  ADD KEY `idx_template_id` (`template_id`),
  ADD KEY `idx_is_generated` (`is_generated`);

--
-- Indeksy dla tabeli `document_categories`
--
ALTER TABLE `document_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `name` (`name`);

--
-- Indeksy dla tabeli `document_templates`
--
ALTER TABLE `document_templates`
  ADD PRIMARY KEY (`id`),
  ADD KEY `category_id` (`category_id`);

--
-- Indeksy dla tabeli `employee_medical_examinations`
--
ALTER TABLE `employee_medical_examinations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employee_id` (`employee_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `employee_safety_trainings`
--
ALTER TABLE `employee_safety_trainings`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employee_id` (`employee_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `employment_periods`
--
ALTER TABLE `employment_periods`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employee_id` (`employee_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `employment_records`
--
ALTER TABLE `employment_records`
  ADD PRIMARY KEY (`id`),
  ADD KEY `employee_id` (`employee_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `equipment`
--
ALTER TABLE `equipment`
  ADD PRIMARY KEY (`id`),
  ADD KEY `company_id` (`company_id`);

--
-- Indeksy dla tabeli `tasks`
--
ALTER TABLE `tasks`
  ADD PRIMARY KEY (`id`),
  ADD KEY `assigned_to` (`assigned_to`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `user_preferences`
--
ALTER TABLE `user_preferences`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `user_preference_unique` (`user_id`,`preference_key`);

--
-- Indeksy dla tabeli `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `vin` (`vin`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `fk_vehicles_company` (`company_id`);

--
-- Indeksy dla tabeli `vehicle_inspections`
--
ALTER TABLE `vehicle_inspections`
  ADD PRIMARY KEY (`id`),
  ADD KEY `vehicle_id` (`vehicle_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `vehicle_monthly_mileages`
--
ALTER TABLE `vehicle_monthly_mileages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `vehicle_id` (`vehicle_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `vehicle_operating_costs`
--
ALTER TABLE `vehicle_operating_costs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `vehicle_id` (`vehicle_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indeksy dla tabeli `vehicle_repairs`
--
ALTER TABLE `vehicle_repairs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `vehicle_id` (`vehicle_id`),
  ADD KEY `created_by` (`created_by`);

--
-- AUTO_INCREMENT dla zrzuconych tabel
--

--
-- AUTO_INCREMENT dla tabeli `companies`
--
ALTER TABLE `companies`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT dla tabeli `costs`
--
ALTER TABLE `costs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;

--
-- AUTO_INCREMENT dla tabeli `cost_files`
--
ALTER TABLE `cost_files`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `cost_relations`
--
ALTER TABLE `cost_relations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;

--
-- AUTO_INCREMENT dla tabeli `cost_types`
--
ALTER TABLE `cost_types`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;

--
-- AUTO_INCREMENT dla tabeli `documents`
--
ALTER TABLE `documents`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;

--
-- AUTO_INCREMENT dla tabeli `document_categories`
--
ALTER TABLE `document_categories`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

--
-- AUTO_INCREMENT dla tabeli `document_templates`
--
ALTER TABLE `document_templates`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT dla tabeli `employee_medical_examinations`
--
ALTER TABLE `employee_medical_examinations`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `employee_safety_trainings`
--
ALTER TABLE `employee_safety_trainings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `employment_periods`
--
ALTER TABLE `employment_periods`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

--
-- AUTO_INCREMENT dla tabeli `employment_records`
--
ALTER TABLE `employment_records`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `equipment`
--
ALTER TABLE `equipment`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `tasks`
--
ALTER TABLE `tasks`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15;

--
-- AUTO_INCREMENT dla tabeli `user_preferences`
--
ALTER TABLE `user_preferences`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=125;

--
-- AUTO_INCREMENT dla tabeli `vehicles`
--
ALTER TABLE `vehicles`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;

--
-- AUTO_INCREMENT dla tabeli `vehicle_inspections`
--
ALTER TABLE `vehicle_inspections`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;

--
-- AUTO_INCREMENT dla tabeli `vehicle_monthly_mileages`
--
ALTER TABLE `vehicle_monthly_mileages`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=55;

--
-- AUTO_INCREMENT dla tabeli `vehicle_operating_costs`
--
ALTER TABLE `vehicle_operating_costs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `vehicle_repairs`
--
ALTER TABLE `vehicle_repairs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Ograniczenia dla zrzutów tabel
--

--
-- Ograniczenia dla tabeli `costs`
--
ALTER TABLE `costs`
  ADD CONSTRAINT `costs_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`),
  ADD CONSTRAINT `costs_ibfk_2` FOREIGN KEY (`cost_type_id`) REFERENCES `cost_types` (`id`),
  ADD CONSTRAINT `costs_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `cost_files`
--
ALTER TABLE `cost_files`
  ADD CONSTRAINT `cost_files_ibfk_1` FOREIGN KEY (`cost_id`) REFERENCES `costs` (`id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `cost_relations`
--
ALTER TABLE `cost_relations`
  ADD CONSTRAINT `cost_relations_ibfk_1` FOREIGN KEY (`cost_id`) REFERENCES `costs` (`id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `documents`
--
ALTER TABLE `documents`
  ADD CONSTRAINT `documents_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `document_categories` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `documents_ibfk_2` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `documents_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `fk_document_template` FOREIGN KEY (`template_id`) REFERENCES `document_templates` (`id`);

--
-- Ograniczenia dla tabeli `document_templates`
--
ALTER TABLE `document_templates`
  ADD CONSTRAINT `document_templates_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `document_categories` (`id`) ON DELETE SET NULL;

--
-- Ograniczenia dla tabeli `employee_medical_examinations`
--
ALTER TABLE `employee_medical_examinations`
  ADD CONSTRAINT `employee_medical_examinations_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `employee_medical_examinations_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `employee_safety_trainings`
--
ALTER TABLE `employee_safety_trainings`
  ADD CONSTRAINT `employee_safety_trainings_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `employee_safety_trainings_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `employment_periods`
--
ALTER TABLE `employment_periods`
  ADD CONSTRAINT `employment_periods_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `employment_periods_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `employment_records`
--
ALTER TABLE `employment_records`
  ADD CONSTRAINT `employment_records_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `employment_records_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `equipment`
--
ALTER TABLE `equipment`
  ADD CONSTRAINT `equipment_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE SET NULL;

--
-- Ograniczenia dla tabeli `tasks`
--
ALTER TABLE `tasks`
  ADD CONSTRAINT `tasks_ibfk_1` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `tasks_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ograniczenia dla tabeli `user_preferences`
--
ALTER TABLE `user_preferences`
  ADD CONSTRAINT `fk_user_preferences_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `vehicles`
--
ALTER TABLE `vehicles`
  ADD CONSTRAINT `fk_vehicles_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `vehicles_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `vehicle_inspections`
--
ALTER TABLE `vehicle_inspections`
  ADD CONSTRAINT `vehicle_inspections_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`),
  ADD CONSTRAINT `vehicle_inspections_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `vehicle_monthly_mileages`
--
ALTER TABLE `vehicle_monthly_mileages`
  ADD CONSTRAINT `vehicle_monthly_mileages_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`),
  ADD CONSTRAINT `vehicle_monthly_mileages_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `vehicle_operating_costs`
--
ALTER TABLE `vehicle_operating_costs`
  ADD CONSTRAINT `vehicle_operating_costs_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`),
  ADD CONSTRAINT `vehicle_operating_costs_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Ograniczenia dla tabeli `vehicle_repairs`
--
ALTER TABLE `vehicle_repairs`
  ADD CONSTRAINT `vehicle_repairs_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`),
  ADD CONSTRAINT `vehicle_repairs_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);
COMMIT;

