-- Borç tahsilat kayıtları ve işlem logları
CREATE TABLE IF NOT EXISTS `borc_tahsilatlari` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ekspertiz_id` int(11) unsigned NOT NULL,
  `bayi_id` int(11) unsigned NOT NULL,
  `user_id` int(11) unsigned DEFAULT NULL COMMENT 'Tahsilatı yapan kullanıcı',
  `tutar` decimal(12,2) NOT NULL DEFAULT 0.00,
  `odeme_turu` varchar(30) NOT NULL DEFAULT '',
  `aciklama` varchar(500) NOT NULL DEFAULT '',
  `onceki_borc_kalan` decimal(12,2) NOT NULL DEFAULT 0.00,
  `yeni_borc_kalan` decimal(12,2) NOT NULL DEFAULT 0.00,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_borc_tahsilat_ekspertiz` (`ekspertiz_id`),
  KEY `idx_borc_tahsilat_bayi` (`bayi_id`),
  KEY `idx_borc_tahsilat_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `borc_tahsilat_loglari` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `tahsilat_id` int(11) unsigned NOT NULL,
  `ekspertiz_id` int(11) unsigned NOT NULL,
  `bayi_id` int(11) unsigned NOT NULL,
  `user_id` int(11) unsigned DEFAULT NULL,
  `islem` varchar(20) NOT NULL DEFAULT 'tahsilat' COMMENT 'tahsilat',
  `tutar` decimal(12,2) NOT NULL DEFAULT 0.00,
  `odeme_turu` varchar(30) NOT NULL DEFAULT '',
  `aciklama` varchar(500) NOT NULL DEFAULT '',
  `onceki_borc_kalan` decimal(12,2) NOT NULL DEFAULT 0.00,
  `yeni_borc_kalan` decimal(12,2) NOT NULL DEFAULT 0.00,
  `rapor_no` varchar(50) NOT NULL DEFAULT '',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_borc_tahsilat_log_bayi` (`bayi_id`),
  KEY `idx_borc_tahsilat_log_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
