DeclarationTVA/sql/dolibarr_allversions.sql
Frank Cools 18e5a68b7b Major CA-3 VAT Declaration Module Updates
- Added comprehensive field naming documentation (CA3_FIELD_NAMING.md)
- Implemented PDFTK-based PDF form filling with FDF generation
- Added PDFTK installation guide for Linux/Mac/Windows
- Enhanced PDF generation with company data integration
- Added new CA-3 lines: F1, F2 (intracom acquisitions), E1-E6, F6-F8, line 18
- Updated section structure: merged Section C into Section B as sub-section
- Added lines 19, 20 to TVA DÉDUCTIBLE sub-section
- Updated all field descriptions to match official CA-3 form
- Improved visual hierarchy with dark blue section headers
- Enhanced calculation logic for VAT deductible amounts
- Added comprehensive language translations
- Updated database schema with new fields
- Fixed font settings to use Courier New 9pt for official documents
2025-10-03 13:22:43 +02:00

135 lines
6.5 KiB
SQL

--
-- DeclarationTVA MVP Database Schema
-- Phase 1 - Basic CA-3 Declaration System
-- Simplified for MVP development
--
-- =====================================================
-- 1. CORE MVP TABLES (Simplified)
-- =====================================================
-- Basic configuration table
CREATE TABLE IF NOT EXISTS `llx_declarationtva_config` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`entity` int(11) NOT NULL DEFAULT 1,
`config_key` varchar(64) NOT NULL,
`config_value` text,
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_config_entity_key` (`entity`, `config_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- PCG account mappings (multiple accounts per CA-3 line supported)
CREATE TABLE IF NOT EXISTS `llx_declarationtva_account_mappings` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`entity` int(11) NOT NULL DEFAULT 1,
`ca3_line` varchar(8) NOT NULL COMMENT 'A1, A2, A3, A4, A5, 08, 09, 9B, 17, 20, 21, 22, 25, 26, 28, 29',
`account_code` varchar(32) NOT NULL COMMENT 'PCG account code',
`account_label` varchar(255) DEFAULT NULL,
`vat_rate` decimal(5,2) DEFAULT NULL,
`is_active` tinyint(1) DEFAULT 1,
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_mapping_entity_line_account` (`entity`, `ca3_line`, `account_code`),
KEY `idx_ca3_line` (`ca3_line`),
KEY `idx_account_code` (`account_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Declaration periods (quarterly only for MVP)
CREATE TABLE IF NOT EXISTS `llx_declarationtva_periods` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`entity` int(11) NOT NULL DEFAULT 1,
`period_name` varchar(32) NOT NULL COMMENT 'Q1-2024, Q2-2024, etc.',
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`status` varchar(32) DEFAULT 'draft' COMMENT 'draft, validated, submitted',
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_period_entity_name` (`entity`, `period_name`),
KEY `idx_period_dates` (`start_date`, `end_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Main declarations table (simplified)
CREATE TABLE IF NOT EXISTS `llx_declarationtva_declarations` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`entity` int(11) NOT NULL DEFAULT 1,
`period_id` int(11) NOT NULL,
`declaration_number` varchar(32) NOT NULL,
`status` varchar(32) DEFAULT 'draft' COMMENT 'draft, validated, submitted',
`total_vat_collected` decimal(15,2) DEFAULT 0.00,
`total_vat_deductible` decimal(15,2) DEFAULT 0.00,
`net_vat_due` decimal(15,2) DEFAULT 0.00,
`vat_credit` decimal(15,2) DEFAULT 0.00,
`submission_date` datetime DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_declaration_entity_number` (`entity`, `declaration_number`),
KEY `idx_period_id` (`period_id`),
CONSTRAINT `fk_declaration_period` FOREIGN KEY (`period_id`) REFERENCES `llx_declarationtva_periods` (`rowid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- CA-3 form lines (simplified)
CREATE TABLE IF NOT EXISTS `llx_declarationtva_ca3_lines` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`declaration_id` int(11) NOT NULL,
`ca3_line` varchar(8) NOT NULL,
`line_label` varchar(255) DEFAULT NULL,
`base_amount` decimal(15,2) DEFAULT 0.00,
`vat_amount` decimal(15,2) DEFAULT 0.00,
`total_amount` decimal(15,2) DEFAULT 0.00,
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_declaration_line` (`declaration_id`, `ca3_line`),
CONSTRAINT `fk_ca3_declaration` FOREIGN KEY (`declaration_id`) REFERENCES `llx_declarationtva_declarations` (`rowid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- =====================================================
-- 2. INITIAL DATA FOR MVP
-- =====================================================
-- Insert default configuration
INSERT INTO `llx_declarationtva_config` (`entity`, `config_key`, `config_value`, `created_date`) VALUES
(1, 'module_version', '1.0.0-mvp', NOW()),
(1, 'default_period_type', 'quarterly', NOW()),
(1, 'vat_rates', '20.00,10.00,5.50,2.10,0.00', NOW()),
(1, 'declaration_language', 'fr', NOW());
-- Insert default CA-3 line mappings (simplified)
INSERT INTO `llx_declarationtva_account_mappings` (`entity`, `ca3_line`, `account_code`, `account_label`, `vat_rate`, `created_date`) VALUES
(1, 'A1', '701000', 'Ventes HT 20%', 20.00, NOW()),
(1, 'A2', '701000', 'Opérations spéciales', 20.00, NOW()),
(1, 'B1', '445710', 'TVA collectée 20%', 20.00, NOW()),
(1, 'B2', '445720', 'TVA collectée 10%', 10.00, NOW()),
(1, 'B3', '445730', 'TVA collectée 5.5%', 5.50, NOW()),
(1, 'B4', '445740', 'TVA collectée 2.1%', 2.10, NOW()),
(1, '17', '445200', 'TVA due intra-EU', 20.00, NOW()),
(1, '18', '445200', 'TVA due Monaco', 20.00, NOW()),
(1, '19', '445620', 'TVA déductible immobilisations', 20.00, NOW()),
(1, '20', '445660', 'TVA déductible autres', 20.00, NOW()),
(1, '21', '445660', 'TVA déductible autres', 20.00, NOW()),
(1, '22', '445670', 'Crédit TVA', 0.00, NOW()),
(1, 'E1', '701000', 'Exportations hors UE', 0.00, NOW()),
(1, 'E2', '701000', 'Autres opérations non imposables', 0.00, NOW()),
(1, 'E3', '701000', 'Ventes à distance B to C', 0.00, NOW()),
(1, 'E4', '601000', 'Importations (autres que produits pétroliers)', 0.00, NOW()),
(1, 'E5', '601000', 'Sorties régime fiscal suspensif', 0.00, NOW()),
(1, 'E6', '601000', 'Importations régime fiscal suspensif', 0.00, NOW()),
(1, 'F1', '601000', 'Acquisitions intra-EU HT', 0.00, NOW()),
(1, 'F2', '445200', 'TVA due autoliquidée intra-EU', 20.00, NOW()),
(1, 'F6', '601000', 'Achats en franchise', 0.00, NOW()),
(1, 'F7', '701000', 'Ventes non établi France', 0.00, NOW()),
(1, 'F8', '445000', 'Régularisations', 0.00, NOW()),
(1, '28', '445510', 'TVA nette à payer', 0.00, NOW()),
(1, '29', '445670', 'Crédit TVA à reporter', 0.00, NOW());
-- =====================================================
-- 3. BASIC INDEXES FOR PERFORMANCE
-- =====================================================
CREATE INDEX `idx_declarationtva_periods_dates` ON `llx_declarationtva_periods` (`start_date`, `end_date`);
CREATE INDEX `idx_declarationtva_declarations_period` ON `llx_declarationtva_declarations` (`period_id`);
CREATE INDEX `idx_declarationtva_account_mappings_line` ON `llx_declarationtva_account_mappings` (`ca3_line`);
-- =====================================================
-- END OF MVP SCHEMA
-- =====================================================