-- https://www.phpmyadmin.net/
--
-- Czas generowania: 08 Maj 2025, 12:00
-- Wersja serwera: 10.5.28-MariaDB-0+deb11u1
-- Wersja PHP: 7.4.33

START TRANSACTION;



--
-- Baza danych: `kobas`
--

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

--
-- 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
(1, 'Kobas Budownictwo BMR Sp. z o.o.', '8952223668', '', '', '', 'Zagajnikowa 57', 'Wrocław', '51-523', 'Polska', '', 'kobas.budownictwo@gmail.com', '', '', '', '2024-06-30 10:37:10', '2024-08-12 16:54:42', 1),
(3, 'Kobas Budownictwo Sp. z o.o.', '8952201709', '', '', '', 'ul.Zagajnikowa 57', 'Wrocław', '51-523', 'Polska', '', 'kobas.budownictwo@gmail.com', '', '', '', '2024-06-30 11:24:22', '2024-08-12 16:55:26', 1),
(4, 'Klaubas Sp. z o.o.', '8952170216', 'Sp. z o.o.', '', '', 'Zagajnikowa 57', 'Wrocław', '51-523', 'Polska', '', 'kobas.budownictwo@gmail.com', '', '', '', '2024-08-12 16:53:56', '2024-08-12 16:55:11', 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;

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

--
-- 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') NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- 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');

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

--
-- 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
(3, 'polisa', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66b0e6d463d10_Polisa.pdf', 'application/pdf', 12, 3, 'vehicle', 4, '2024-08-05 14:51:00', '2024-10-15 14:37:31', 5, NULL, NULL, '2025-06-16', NULL, 0, NULL),
(5, 'polisa OC + AC ', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66ba3ffcf1e6a_polisaDW8J214.pdf', 'application/pdf', 12, 3, 'vehicle', 1, '2024-08-12 17:01:49', '2024-08-12 17:01:49', 5, NULL, NULL, '2025-03-02', NULL, 0, NULL),
(6, 'polisa', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66ba438e2c191_polisa.rar', 'application/octet-stream', 12, 3, 'vehicle', 8, '2024-08-12 17:17:02', '2024-08-12 17:17:02', 5, NULL, NULL, '2024-11-22', NULL, 0, NULL),
(7, 'polisa ', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66bb05fb50ab1_potwierdzenie_ubezpieczenia.pdf', 'application/pdf', 12, 3, 'vehicle', 3, '2024-08-13 07:06:35', '2024-08-13 07:06:35', 5, NULL, NULL, '2025-02-15', NULL, 0, NULL),
(8, 'polisa - TOYOTA PROACE', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66bb0743e23f2_polisatoyota-1.pdf', 'application/pdf', 12, 3, 'vehicle', 7, '2024-08-13 07:12:03', '2024-08-13 07:14:46', 5, NULL, NULL, '2025-03-02', NULL, 0, NULL),
(9, 'NOTATKA REMAR', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66bb593a0c76e_Skan_20240813.png', 'image/png', 3, 1, 'none', NULL, '2024-08-13 13:01:46', '2024-08-13 13:01:46', 5, NULL, NULL, NULL, NULL, 0, NULL),
(10, 'Aneks REMAR', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66bb599325277_Skan_20240813 (2).png', 'image/png', 15, 1, 'none', NULL, '2024-08-13 13:03:15', '2024-08-13 13:03:15', 5, NULL, NULL, NULL, NULL, 0, NULL),
(13, 'Polisa', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66e2daf2451f5_document.pdf', 'application/pdf', 12, 1, 'vehicle', 10, '2024-09-12 12:13:38', '2024-09-12 12:13:38', 5, NULL, NULL, NULL, NULL, 0, NULL),
(14, 'faktura za opony i hamulce - TOYOTA PROACE', 'Wymiana opon tarcz i klocków przód', '/var/www/html/kobas/app/routes/../../uploads/documents/66e2f90b5c2f9_17261508141612366196369166868432.jpg', 'image/jpeg', 3, 1, 'vehicle', 7, '2024-09-12 14:22:03', '2024-09-17 08:19:04', 7, NULL, NULL, NULL, NULL, 0, NULL),
(16, 'Polisa ', '', '/var/www/html/kobas/app/routes/../../uploads/documents/66f11f874ae11_Skan_20240916.pdf', 'application/pdf', 12, 1, 'vehicle', 11, '2024-09-23 07:57:59', '2024-09-23 07:58:06', 7, NULL, '2024-09-12', '2025-09-11', NULL, 0, NULL),
(19, 'fv za serwis forda', 'serwis forda', '/var/www/html/kobas/app/routes/../../uploads/documents/670ceee737e4a_FV 00028_10_2024.pdf', 'application/pdf', 3, 1, 'vehicle', 8, '2024-10-14 10:13:59', '2024-10-14 10:20:30', 5, NULL, NULL, NULL, NULL, 0, NULL),
(20, 'Polisa Ford', 'Polisa 920046703726', '/var/www/html/kobas/app/routes/../../uploads/documents/670e83f587dac_ACFrOgAlr78aTej2nUm_QcrbqPx9d5kgd3_QNcLJehxKlwkrL0-qt4W6gNqn6qIqu3qQZafvHuOVjcGPDYp8QfeNMs8iPtzlVgTv6v76sKdTPujgtyCIEigk1b44IbncRxCjAerO8_rzGD4-fqhA.pdf', 'application/pdf', 12, 3, 'vehicle', 8, '2024-10-15 15:02:13', '2024-10-15 15:02:13', 7, NULL, '2024-11-22', '2025-11-22', NULL, 0, NULL),
(21, 'Karta szkolenia wstępnego BHP - Przemysław Kubiak', 'Automatycznie wygenerowany dokument', '/var/www/html/kobas/uploads/documents/670f5efb2f669.pdf', 'application/pdf', 5, 1, 'employee', 25, '2024-10-16 06:36:43', '2024-10-16 06:36:43', 7, NULL, NULL, NULL, NULL, 1, 6),
(22, 'Aneks Piontkowski braniborska', 'Aneks do umowy budowa braniborska', '/var/www/html/kobas/app/routes/../../uploads/documents/6710d99766123_Skan_20241017.pdf', 'application/pdf', 15, 1, 'none', NULL, '2024-10-17 09:32:07', '2024-10-17 09:32:07', 7, NULL, NULL, NULL, NULL, 0, NULL),
(23, 'Protokół odbioru pokoi zagajnikowa 26', 'Protokół odbioru pokoi przez nową firmę ', '/var/www/html/kobas/app/routes/../../uploads/documents/671227ea24b4d_Skan_20241018.pdf', 'application/pdf', 9, 4, 'none', NULL, '2024-10-18 09:18:34', '2024-10-18 09:18:34', 7, NULL, NULL, NULL, NULL, 0, NULL),
(24, 'Protokół przekazania kluczy ', 'Przekazanie kluczy z ilością nowi lokatorzy zagajnikowa 26', '/var/www/html/kobas/app/routes/../../uploads/documents/67122847b15f4_Skan_20241018 (2).pdf', 'application/pdf', 10, 4, 'none', NULL, '2024-10-18 09:20:07', '2024-10-18 09:20:07', 7, NULL, NULL, NULL, NULL, 0, NULL),
(25, 'polisa x5', '', '/var/www/html/kobas/app/routes/../../uploads/documents/67192d0c85725_polsa x5.pdf', 'application/pdf', 13, 3, 'vehicle', 4, '2024-10-23 17:06:20', '2024-10-23 17:06:58', 5, NULL, '2024-10-17', '2025-10-17', NULL, 0, NULL),
(26, 'Polisa Ford', '', '/var/www/html/kobas/app/routes/../../uploads/documents/6720bc87501f0_polisa+920046703726.pdf', 'application/pdf', 12, 3, 'vehicle', 8, '2024-10-29 10:44:23', '2024-10-29 10:44:23', 7, NULL, '2023-11-23', '2024-11-22', NULL, 0, NULL),
(27, 'Karta szkolenia wstępnego BHP - Klaudiusz Kwak', 'Automatycznie wygenerowany dokument', '/var/www/html/kobas/uploads/documents/677e67d02e88c.pdf', 'application/pdf', 5, 3, 'employee', 26, '2025-01-08 11:56:00', '2025-03-12 11:38:44', 5, NULL, NULL, '2025-03-27', NULL, 1, 6),
(28, 'aneks nr 2 Piontkowski ', 'Aneks dotyczy dopłaty 10 gr/kg powyżej stanu 0 ', '/var/www/html/kobas/app/routes/../../uploads/documents/678786753aa14_ilovepdf_merged (10).pdf', 'application/pdf', 15, 1, 'none', NULL, '2025-01-15 09:57:09', '2025-01-15 09:57:28', 7, NULL, NULL, NULL, NULL, 0, NULL),
(29, 'Dokument pojazdu - TOYOTA PROACE', 'Dowód rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fad1463905_ilovepdf_merged (11).pdf', 'application/pdf', 2, 1, 'vehicle', 7, '2025-01-21 14:20:04', '2025-01-21 14:20:04', 7, NULL, NULL, NULL, NULL, 0, NULL),
(30, 'Dokument pojazdu - Opel Combo', 'Dowod rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fadea6c972_ilovepdf_merged (14).pdf', 'application/pdf', 2, 1, 'vehicle', 5, '2025-01-21 14:23:38', '2025-01-21 14:23:38', 7, NULL, NULL, NULL, NULL, 0, NULL),
(31, 'Dokument pojazdu - VOLKSWAGEN CADDY', 'Dowód rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678faed24383b_ilovepdf_merged (15).pdf', 'application/pdf', 2, 3, 'vehicle', 11, '2025-01-21 14:27:30', '2025-01-21 14:27:30', 7, NULL, NULL, NULL, NULL, 0, NULL),
(32, 'Dokument pojazdu - VOLKSWAGEN CADDY', 'Dowod rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fb014dde27_ilovepdf_merged (17).pdf', 'application/pdf', 2, 1, 'vehicle', 10, '2025-01-21 14:32:52', '2025-01-21 14:32:52', 7, NULL, NULL, NULL, NULL, 0, NULL),
(33, 'Dokument pojazdu - VOLKSWAGEN CADDY', 'Dowod rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fb017d7c04_ilovepdf_merged (17).pdf', 'application/pdf', 2, 1, 'vehicle', 10, '2025-01-21 14:32:55', '2025-01-21 14:32:55', 7, NULL, NULL, NULL, NULL, 0, NULL),
(34, 'Dokument pojazdu - MERCEDES A 220 4MATIC', 'Dowód rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fb04a358db_ilovepdf_merged (18).pdf', 'application/pdf', 2, 3, 'vehicle', 1, '2025-01-21 14:33:46', '2025-01-21 14:33:46', 7, NULL, NULL, NULL, NULL, 0, NULL),
(35, 'Dokument pojazdu - VOLKSWAGEN CADDY', 'Dowód rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fb12306c1e_ilovepdf_merged (20).pdf', 'application/pdf', 2, 1, 'vehicle', 6, '2025-01-21 14:37:23', '2025-01-21 14:37:23', 7, NULL, NULL, NULL, NULL, 0, NULL),
(36, 'Dokument pojazdu - FORD tourneo custom', 'Dowód rejestracyjny ', '/var/www/html/kobas/app/routes/../../uploads/documents/678fb18c7af50_ilovepdf_merged (21).pdf', 'application/pdf', 2, 1, 'vehicle', 8, '2025-01-21 14:39:08', '2025-01-21 14:39:08', 7, NULL, NULL, NULL, NULL, 0, NULL),
(37, 'Dokument pojazdu - MERCEDES A 220 4MATIC', 'Polisa oc ac', '/var/www/html/kobas/app/routes/../../uploads/documents/67ab39c5cfe97_polisa+920050296177.pdf', 'application/pdf', 11, 3, 'vehicle', 1, '2025-02-11 11:51:33', '2025-02-11 11:51:33', 5, NULL, '2025-03-01', '2026-02-28', NULL, 0, NULL),
(39, 'Karta szkolenia wstępnego BHP - Łukasz  Błażejewski ', 'Automatycznie wygenerowany dokument', '/var/www/html/kobas/uploads/documents/67d96c7ff329a.pdf', 'application/pdf', 5, 1, 'employee', 15, '2025-03-18 12:52:16', '2025-03-18 12:52:16', 7, NULL, NULL, NULL, NULL, 1, 6),
(40, 'Dokument pracownika - Robert  Szymikowski', 'Szkolenie wstępne BHP', '/var/www/html/kobas/app/routes/../../uploads/documents/67d96d766b118_szkolenie-szymikowski.jpg', 'image/jpeg', 5, 1, 'employee', 29, '2025-03-18 12:56:22', '2025-03-18 12:56:22', 7, NULL, '2025-03-11', '2025-09-10', NULL, 0, NULL),
(41, 'Dokument pracownika - Kyrylo Kostenko', 'Szkolenie wstępne BHP', '/var/www/html/kobas/app/routes/../../uploads/documents/67d96de575efb_kostek-szkolenie.jpg', 'image/jpeg', 5, 1, 'employee', 28, '2025-03-18 12:58:13', '2025-03-18 12:58:13', 7, NULL, '2025-03-11', '2025-09-10', 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;

--
-- Zrzut danych tabeli `employment_periods`
--

INSERT INTO `employment_periods` (`id`, `employee_id`, `start_date`, `end_date`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 3, '2021-01-01', '2024-02-01', 5, '2024-06-27 12:19:56', '2024-07-10 10:00:46'),
(2, 4, '2022-04-26', NULL, 5, '2024-06-27 12:57:08', '2024-06-27 12:57:08'),
(3, 5, '2004-11-11', NULL, 5, '2024-06-27 13:49:39', '2024-08-20 11:10:35'),
(4, 6, '2022-05-27', NULL, 5, '2024-06-28 17:48:27', '2025-03-12 09:52:37'),
(5, 7, '2022-04-27', NULL, 5, '2024-06-28 18:05:02', '2024-06-28 18:05:02'),
(6, 10, '2022-03-28', NULL, 7, '2024-06-30 14:02:41', '2024-06-30 14:02:41'),
(7, 11, '2020-01-24', NULL, 7, '2024-06-30 14:28:48', '2024-06-30 14:28:48'),
(8, 1, '2000-01-01', '2024-06-30', 7, '2024-06-30 14:47:51', '2024-06-30 14:50:18'),
(9, 1, '2024-07-01', '2024-07-18', 7, '2024-06-30 14:50:44', '2024-07-08 19:29:04'),
(10, 3, '2024-07-01', NULL, 7, '2024-07-01 16:22:50', '2024-08-20 11:11:00'),
(11, 12, '2024-07-10', '2024-07-12', 5, '2024-07-08 13:47:10', '2024-08-20 11:07:47'),
(12, 14, '2024-07-11', '2025-02-28', 5, '2024-07-08 18:13:33', '2025-03-17 16:18:28'),
(14, 16, '2024-02-19', NULL, 7, '2024-07-09 20:40:09', '2024-07-09 20:40:09'),
(15, 18, '2024-04-02', NULL, 7, '2024-07-09 20:42:40', '2024-07-09 20:42:40'),
(16, 19, '2024-07-01', '2024-09-12', 7, '2024-07-09 20:44:24', '2024-09-25 08:42:13'),
(17, 20, '2024-07-01', '2024-12-31', 7, '2024-07-09 20:45:17', '2025-01-08 11:52:54'),
(18, 21, '2024-08-05', NULL, 7, '2024-08-20 11:09:58', '2024-08-20 11:09:58'),
(19, 22, '2021-01-01', NULL, 7, '2024-08-20 11:13:46', '2024-08-20 11:13:46'),
(20, 23, '2024-04-29', '2024-09-16', 7, '2024-08-20 11:17:27', '2024-09-25 08:43:07'),
(21, 24, '2023-11-13', '2025-02-13', 7, '2024-08-20 11:20:32', '2025-03-17 16:19:19'),
(22, 25, '2024-10-07', '2024-12-31', 7, '2024-10-16 06:36:23', '2025-01-08 11:52:33'),
(23, 26, '2024-09-23', NULL, 5, '2025-01-08 11:54:35', '2025-01-08 11:54:35'),
(24, 27, '2024-09-18', '2025-03-17', 7, '2025-03-17 16:20:56', '2025-03-17 16:21:12'),
(25, 28, '2025-03-10', '2025-03-30', 7, '2025-03-18 12:50:31', '2025-03-18 12:56:56'),
(26, 29, '2025-03-10', '2025-03-30', 7, '2025-03-18 12:51:41', '2025-03-18 12:53:44');

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

--
-- 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', 'todo', NULL, 5, '2024-08-14 08:00:00', '2024-08-14 08:00:27');

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

--
-- 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', '3', NULL, NULL),
(2, 5, 'last_cost_type_id', '1', NULL, NULL),
(3, 5, 'last_relation_type', 'none', 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
(1, 'MERCEDES', 'A 220 4MATIC', 2016, 'DW 8J214', 'WDD1760471J563499', '2020-03-05', 3, 7, '2024-07-01 13:08:51', '2025-02-11 11:50:29', '2016-12-15'),
(3, 'MERCEDES', 'MARCO POLO', 2023, 'DW 3YA73', 'W1VVNKTZ4P4227555', '2024-02-16', 3, 7, '2024-07-01 13:28:01', '2024-07-10 07:09:18', '2024-02-16'),
(4, 'BMW', 'X5', 2021, 'D0 KOBAS', 'WBACV410509G21878', '2021-05-21', 3, 5, '2024-07-04 14:31:50', '2024-08-20 11:38:09', '2020-05-21'),
(5, 'Opel', 'Combo', 2015, 'DW1JS41', 'W0L6VYC1AF9570955', '2000-06-04', 1, 7, '2024-07-05 08:19:35', '2025-03-24 13:20:54', '2015-05-08'),
(6, 'VOLKSWAGEN', 'CADDY', 2024, 'SK 4A628', 'WV2ZZZSK8RX073946', '2024-04-16', 1, 5, '2024-07-09 20:20:47', '2025-05-05 06:54:21', '2024-04-11'),
(7, 'TOYOTA', 'PROACE', 2021, 'DW2ME47', 'YARVAYHVKGZ191755', '2021-03-03', 1, 7, '2024-07-09 20:47:46', '2025-04-26 07:15:45', '2021-04-15'),
(8, 'FORD', 'tourneo custom', 2020, 'DW 1LC76', 'WF01XXTTG1LL34850', '2020-11-23', 1, 7, '2024-07-09 20:50:28', '2025-05-05 11:55:02', '2020-11-23'),
(9, 'BMW ', 'M340i', 2020, 'DW 8LN69', 'WBA5U91080FK02852', '2021-01-16', 3, 5, '2024-07-10 07:15:57', '2024-07-10 07:15:57', '2021-01-16'),
(10, 'VOLKSWAGEN', 'CADDY', 2016, 'DW 1TT46', 'WV2ZZZ2KZHX037353', '2016-09-12', 1, 7, '2024-09-05 13:33:40', '2025-01-21 14:30:34', '2016-09-12'),
(11, 'VOLKSWAGEN', 'CADDY', 2016, 'DW 7RS98 ', 'WV2ZZZ2KZHXQ35216', '2016-09-13', 3, 7, '2024-09-09 08:46:26', '2025-03-18 12:59:03', '2016-09-13');

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

--
-- 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;

--
-- Zrzut danych tabeli `vehicle_inspections`
--

INSERT INTO `vehicle_inspections` (`id`, `vehicle_id`, `inspection_date`, `expiration_date`, `created_by`, `created_at`, `updated_at`, `inspection_type`, `notes`, `mileage`, `service_actions`) VALUES
(13, 4, '2024-06-13', '2026-05-21', 5, '2024-07-10 07:04:47', '2024-07-10 07:13:55', 'techniczny', '', 62000, ''),
(14, 3, '2024-02-16', '2027-02-16', 5, '2024-07-10 07:10:51', '2024-07-10 07:13:31', 'techniczny', '', 0, ''),
(15, 9, '2024-05-14', '2026-01-18', 5, '2024-07-10 07:17:13', '2024-07-10 07:17:13', 'techniczny', '', 60000, ''),
(16, 9, '2024-06-17', '2025-06-17', 7, '2024-07-10 08:53:46', '2024-07-10 08:53:56', 'serwisowy', '', 64000, 'wymiana klocków przód i tył'),
(17, 4, '2024-06-06', '2025-06-06', 7, '2024-07-10 08:54:38', '2024-07-10 08:54:38', 'serwisowy', '', 60000, 'Wymiana olejów i filtrów'),
(18, 3, '2024-06-06', '2025-06-06', 7, '2024-07-10 08:55:14', '2024-07-10 08:55:14', 'serwisowy', '', 11000, 'wymiana oleju i filtra'),
(19, 5, '2023-09-20', '2024-09-20', 5, '2024-07-11 06:49:53', '2024-07-11 06:49:53', 'techniczny', '', 0, ''),
(20, 6, '2024-05-09', '2027-04-11', 7, '2024-08-20 11:33:25', '2024-08-20 11:33:25', 'techniczny', '', 8133, ''),
(21, 8, '2023-10-27', '2025-10-27', 7, '2024-08-20 11:35:39', '2024-08-20 11:35:39', 'techniczny', '', 92116, ''),
(22, 1, '2024-01-15', '2026-01-15', 7, '2024-08-20 11:36:19', '2025-02-11 11:50:21', 'techniczny', '', 82028, ''),
(23, 7, '2024-04-12', '2026-04-12', 7, '2024-08-20 11:37:05', '2024-08-20 11:37:05', 'techniczny', '', 32244, ''),
(24, 7, '2024-07-17', '2025-07-17', 7, '2024-08-20 11:42:44', '2024-08-20 11:42:44', 'serwisowy', '', 34109, ''),
(25, 10, '2024-09-04', '2025-09-04', 7, '2024-09-05 13:34:11', '2024-09-09 08:49:50', 'techniczny', '', 303264, ''),
(26, 11, '2024-09-05', '2025-09-05', 7, '2024-09-09 08:47:47', '2024-09-09 08:47:47', 'techniczny', '', 159128, ''),
(27, 11, '2024-09-05', '2025-09-05', 7, '2024-09-09 08:48:27', '2024-09-09 08:48:27', 'serwisowy', '', 159128, 'Wymiana oleju i filtrów '),
(28, 10, '2024-09-03', '2025-09-03', 7, '2024-09-09 08:49:16', '2024-09-09 08:49:16', 'serwisowy', '', 303264, 'Wymiana oleju filtrow i klockow hamulcowych przód '),
(29, 5, '2024-09-18', '2025-09-18', 7, '2024-09-23 07:42:34', '2024-09-23 07:42:34', 'techniczny', '', 0, ''),
(30, 8, '2024-10-14', '2025-10-14', 5, '2024-10-14 10:12:12', '2024-10-14 11:04:22', 'serwisowy', 'GTC serwis swojczyce czy jakoś tak, koszt 1800', 96000, 'Wymiana klocków przód tył + wszystkie filtry i olej');

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

--
-- 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;

--
-- Zrzut danych tabeli `vehicle_monthly_mileages`
--

INSERT INTO `vehicle_monthly_mileages` (`id`, `vehicle_id`, `mileage_date`, `mileage`, `mileage_difference`, `created_by`, `created_at`, `updated_at`) VALUES
(22, 4, '2024-05-31', 62610, 62610, 7, '2024-07-10 10:23:41', '2024-07-10 10:23:41'),
(23, 8, '2024-04-30', 92116, 92116, 5, '2024-07-15 18:14:08', '2024-07-15 18:14:08'),
(24, 8, '2024-05-31', 92731, 615, 5, '2024-07-15 18:14:50', '2024-07-15 18:14:50'),
(25, 8, '2024-06-30', 93144, 413, 5, '2024-07-15 18:15:06', '2024-07-15 18:15:06'),
(26, 7, '2024-04-30', 32244, 32244, 5, '2024-07-15 18:25:27', '2024-07-15 18:25:27'),
(27, 7, '2024-05-31', 33400, 1156, 5, '2024-07-15 18:26:34', '2024-07-15 18:26:34'),
(28, 7, '2024-06-30', 33631, 231, 5, '2024-07-15 18:27:27', '2024-07-15 18:27:27'),
(29, 6, '2024-05-31', 2128, 2128, 5, '2024-07-15 18:38:39', '2024-07-15 18:38:39'),
(30, 3, '2024-04-30', 9500, 9500, 5, '2024-07-15 18:52:55', '2024-07-15 18:52:55'),
(31, 3, '2024-05-31', 11627, 2127, 5, '2024-07-15 18:53:30', '2024-07-15 18:53:30'),
(32, 3, '2024-06-30', 14600, 2973, 5, '2024-07-15 18:53:41', '2024-07-15 18:53:41'),
(33, 1, '2024-04-30', 82028, 82028, 5, '2024-07-15 19:07:39', '2024-07-15 19:07:39'),
(34, 6, '2024-06-30', 6478, 4350, 5, '2024-07-15 19:08:15', '2024-07-15 19:08:15'),
(35, 3, '2024-07-31', 17354, 2754, 7, '2024-08-02 18:12:43', '2024-08-02 18:12:43'),
(36, 4, '2024-07-31', 64606, 1996, 7, '2024-08-02 18:13:17', '2024-08-03 18:32:24'),
(37, 9, '2024-07-31', 67400, 67400, 5, '2024-08-04 16:16:41', '2024-08-04 16:16:41'),
(38, 7, '2024-07-31', 34109, 478, 7, '2024-08-20 11:30:21', '2024-08-20 11:30:21'),
(39, 6, '2024-07-31', 8133, 1655, 7, '2024-08-20 11:30:47', '2024-08-20 11:30:47'),
(40, 4, '2024-08-31', 66051, 1445, 5, '2024-09-06 09:07:48', '2024-09-06 09:07:48'),
(41, 3, '2024-08-31', 17843, 489, 5, '2024-09-06 09:08:14', '2024-09-06 09:08:14'),
(42, 9, '2024-08-31', 69000, 1600, 5, '2024-09-07 07:41:03', '2024-09-07 07:41:03'),
(43, 10, '2024-09-30', 303264, 303264, 7, '2024-09-09 08:50:19', '2024-09-09 08:50:19'),
(44, 11, '2024-09-30', 159128, 159128, 7, '2024-09-09 08:50:36', '2024-09-09 08:50:36'),
(45, 7, '2024-08-31', 34448, 339, 7, '2024-09-09 08:51:09', '2024-09-09 08:51:09'),
(46, 8, '2024-08-31', 94688, 736, 7, '2024-09-09 08:51:27', '2024-09-10 08:26:08'),
(47, 6, '2024-08-31', 9078, 945, 7, '2024-09-09 08:51:45', '2024-09-09 08:51:45'),
(48, 8, '2024-07-31', 93952, 808, 7, '2024-09-10 08:07:56', '2024-09-10 08:07:56'),
(49, 4, '2024-09-30', 67900, 1849, 7, '2024-10-14 08:32:18', '2024-10-14 08:32:18'),
(50, 9, '2024-09-30', 70200, 1200, 7, '2024-10-14 10:18:58', '2024-10-14 10:18:58'),
(51, 3, '2024-09-30', 18060, 217, 7, '2024-10-15 08:37:57', '2024-10-15 08:37:57'),
(52, 8, '2024-09-30', 95560, 95560, 7, '2024-10-16 06:32:59', '2024-12-06 09:38:29'),
(53, 6, '2024-09-30', 10306, 1228, 7, '2024-10-16 06:33:14', '2024-10-16 06:33:14'),
(54, 7, '2024-09-30', 34911, 463, 7, '2024-10-16 06:33:30', '2024-10-16 06:33:30'),
(55, 7, '2024-10-31', 35401, 490, 7, '2024-11-07 09:54:19', '2024-11-07 09:54:19'),
(56, 8, '2024-10-31', 96283, 633, 7, '2024-11-07 09:54:35', '2024-11-07 09:54:35'),
(57, 6, '2024-10-31', 12745, 2439, 7, '2024-11-08 08:07:49', '2024-11-08 08:07:49'),
(58, 4, '2024-10-31', 69320, 1420, 5, '2024-11-25 12:17:44', '2024-11-25 12:17:44'),
(59, 4, '2024-11-30', 70448, 1128, 5, '2024-11-25 12:18:06', '2024-11-25 12:18:06'),
(60, 9, '2024-10-31', 71500, 1300, 5, '2024-11-25 12:18:37', '2024-11-25 12:18:37'),
(61, 9, '2024-11-30', 73010, 1510, 5, '2024-11-25 12:19:06', '2024-11-25 12:19:06'),
(62, 3, '2024-10-31', 19100, 1040, 5, '2024-11-25 12:19:47', '2024-11-25 12:19:47'),
(63, 7, '2024-11-30', 35728, 327, 7, '2024-12-05 23:34:32', '2024-12-05 23:34:32'),
(64, 6, '2024-11-30', 14395, 1650, 7, '2024-12-05 23:35:11', '2024-12-05 23:35:11'),
(65, 8, '2024-11-30', 97003, 720, 7, '2024-12-06 09:36:17', '2024-12-06 09:36:17'),
(66, 7, '2024-12-31', 35947, 219, 7, '2025-01-15 11:22:36', '2025-01-15 11:22:36'),
(67, 6, '2024-12-31', 15836, 1441, 7, '2025-01-15 11:22:50', '2025-01-15 11:22:50'),
(68, 8, '2024-12-31', 97530, 527, 7, '2025-02-18 12:38:11', '2025-02-18 12:38:11'),
(69, 8, '2025-01-31', 97996, 466, 7, '2025-02-18 12:38:24', '2025-02-18 12:38:24'),
(70, 6, '2025-01-31', 16986, 1150, 7, '2025-02-18 12:38:39', '2025-02-18 12:38:39'),
(71, 6, '2025-02-28', 17774, 788, 7, '2025-03-17 16:12:47', '2025-03-17 16:12:47'),
(72, 7, '2025-02-28', 36548, 601, 7, '2025-03-17 16:13:22', '2025-03-17 16:13:22'),
(73, 7, '2025-01-31', 36409, 462, 7, '2025-03-17 16:13:42', '2025-03-17 16:13:42'),
(74, 8, '2025-02-28', 98600, 604, 7, '2025-03-17 16:14:22', '2025-03-17 16:14:22'),
(75, 6, '2025-03-31', 19459, 1685, 7, '2025-04-26 07:13:09', '2025-04-26 07:13:09'),
(76, 7, '2025-03-31', 36742, 194, 7, '2025-04-26 07:13:46', '2025-04-26 07:13:46'),
(77, 8, '2025-03-31', 99323, 723, 7, '2025-04-26 07:14:24', '2025-04-26 07:14:24'),
(78, 6, '2025-04-30', 21090, 21090, 7, '2025-05-05 06:54:16', '2025-05-05 07:00:57'),
(79, 7, '2025-04-30', 36742, 0, 7, '2025-05-05 06:55:29', '2025-05-05 06:55:29'),
(80, 8, '2025-04-30', 99980, 657, 7, '2025-05-05 11:55:11', '2025-05-05 11:55:11'),
(81, 4, '2024-12-31', 71428, 980, 5, '2025-05-07 10:22:48', '2025-05-07 10:22:48'),
(83, 4, '2025-01-31', 72635, 1207, 5, '2025-05-07 10:24:48', '2025-05-07 10:24:48'),
(84, 4, '2025-02-28', 73790, 1155, 5, '2025-05-07 10:25:30', '2025-05-07 10:25:30'),
(85, 4, '2025-03-31', 75180, 1390, 5, '2025-05-07 10:26:11', '2025-05-07 10:26:11'),
(86, 4, '2025-04-30', 76980, 1800, 5, '2025-05-07 10:26:30', '2025-05-07 10:26:30'),
(87, 3, '2024-12-31', 19650, 550, 5, '2025-05-07 10:29:53', '2025-05-07 10:29:53'),
(88, 3, '2025-01-31', 20370, 720, 5, '2025-05-07 10:30:31', '2025-05-07 10:30:31'),
(89, 3, '2025-02-28', 21028, 658, 5, '2025-05-07 10:31:01', '2025-05-07 10:31:01'),
(90, 3, '2025-03-31', 21569, 541, 5, '2025-05-07 10:31:24', '2025-05-07 10:31:24'),
(91, 3, '2025-04-30', 22371, 802, 5, '2025-05-07 10:32:00', '2025-05-07 10:32:00'),
(92, 3, '2024-11-30', 19305, 205, 5, '2025-05-07 10:32:58', '2025-05-07 10:32:58');

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

--
-- 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;

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

--
-- Struktura tabeli dla tabeli `vehicle_trips`
--

CREATE TABLE `vehicle_trips` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vehicle_id` bigint(20) UNSIGNED NOT NULL,
  `trip_date` date NOT NULL,
  `route` varchar(255) NOT NULL,
  `purpose` varchar(255) NOT NULL,
  `kilometers` decimal(10,2) NOT NULL,
  `rate` decimal(10,2) DEFAULT NULL,
  `notes` text 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;

--
-- 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`);

--
-- 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`);

--
-- Indeksy dla tabeli `vehicle_trips`
--
ALTER TABLE `vehicle_trips`
  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=5;

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

--
-- 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 dla tabeli `cost_types`
--
ALTER TABLE `cost_types`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

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

--
-- 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=27;

--
-- 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=12;

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

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

--
-- 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=93;

--
-- 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;

--
-- AUTO_INCREMENT dla tabeli `vehicle_trips`
--
ALTER TABLE `vehicle_trips`
  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`);

--
-- Ograniczenia dla tabeli `vehicle_trips`
--
ALTER TABLE `vehicle_trips`
  ADD CONSTRAINT `vehicle_trips_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `vehicle_trips_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);
COMMIT;

