DeclarationTVA/declarationtvaindex.php
Frank Cools 8e71a12000 Phase 1 MVP - Core foundation complete
MVP Database Schema:
- Simplified database schema for MVP development
- Core tables: config, account_mappings, periods, declarations, ca3_lines
- Basic indexes for performance
- Initial configuration data

Core PHP Classes:
- DeclarationTVA: Main class for CA-3 processing
- DeclarationTVA_Config: Configuration management
- DeclarationTVA_Period: Period management
- Complete CRUD operations for all entities

Main Interface:
- declarationtvaindex.php: Main module interface
- Period management and declaration creation
- Status tracking (draft, validated, submitted)
- Basic action handling

Configuration Interface:
- setup_mvp.php: Simplified configuration page
- PCG account mapping for all CA-3 lines
- Account selection from Dolibarr chart of accounts
- VAT rate configuration

Key Features Implemented:
- Basic CA-3 form generation
- PCG account mapping (one account per line for MVP)
- Period management (quarterly)
- Declaration status tracking
- Configuration interface
- Account validation against Dolibarr

Next Steps:
- CA-3 form generation logic
- PDF export functionality
- Testing with sample data

MVP Progress: 60% complete
Core foundation ready for testing and refinement
2025-10-02 16:16:15 +02:00

186 lines
6.7 KiB
PHP

<?php
/**
* DeclarationTVA Main Interface
* French CA-3 VAT Declaration Module for Dolibarr
* MVP Version - Phase 1
*/
// Load Dolibarr environment
if (file_exists('../main.inc.php')) {
$res = @include '../main.inc.php';
} elseif (file_exists('../../main.inc.php')) {
$res = @include '../../main.inc.php';
} else {
$res = 0;
}
if (!$res) {
die("Include of main fails");
}
// Load module classes
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva.class.php';
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_config.class.php';
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_period.class.php';
// Access control
if (!$user->rights->declarationtva->read) {
accessforbidden();
}
// Load language files
$langs->load("declarationtva@declarationtva");
// Initialize objects
$declarationtva = new DeclarationTVA($db, $conf->entity);
$config = new DeclarationTVA_Config($db, $conf->entity);
$period = new DeclarationTVA_Period($db, $conf->entity);
// Handle actions
$action = GETPOST('action', 'alpha');
$declaration_id = GETPOST('declaration_id', 'int');
$period_id = GETPOST('period_id', 'int');
// Process actions
if ($action == 'create_declaration' && $period_id > 0) {
$declaration_id = $declarationtva->createDeclaration($period_id);
if ($declaration_id > 0) {
setEventMessages($langs->trans("DeclarationCreated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorCreatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
}
} elseif ($action == 'validate_declaration' && $declaration_id > 0) {
if ($declarationtva->validateDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorValidatingDeclaration"), null, 'errors');
}
} elseif ($action == 'submit_declaration' && $declaration_id > 0) {
if ($declarationtva->submitDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationSubmitted"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorSubmittingDeclaration"), null, 'errors');
}
}
// Get data for display
$periods = $period->getAllPeriods();
$declarations = array();
// Get declarations for each period
foreach ($periods as $p) {
$sql = "SELECT * FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
WHERE period_id = " . $p['rowid'] . " AND entity = " . $conf->entity . "
ORDER BY created_date DESC";
$result = $db->query($sql);
if ($result) {
while ($obj = $db->fetch_object($result)) {
$declarations[] = array(
'rowid' => $obj->rowid,
'declaration_number' => $obj->declaration_number,
'status' => $obj->status,
'total_vat_collected' => $obj->total_vat_collected,
'total_vat_deductible' => $obj->total_vat_deductible,
'net_vat_due' => $obj->net_vat_due,
'vat_credit' => $obj->vat_credit,
'created_date' => $obj->created_date,
'period_name' => $p['period_name']
);
}
}
}
// Page title
$title = $langs->trans("DeclarationTVAMainInterface");
llxHeader('', $title);
// Print page header
print load_fiche_titre($title, '', 'title_accountancy');
// Print periods section
print '<div class="fiche">';
print '<div class="fichehalfleft">';
print '<div class="titre">' . $langs->trans("DeclarationTVAPeriods") . '</div>';
if (empty($periods)) {
print '<div class="info">' . $langs->trans("NoPeriodsFound") . '</div>';
} else {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("PeriodName") . '</th>';
print '<th>' . $langs->trans("StartDate") . '</th>';
print '<th>' . $langs->trans("EndDate") . '</th>';
print '<th>' . $langs->trans("Status") . '</th>';
print '<th>' . $langs->trans("Actions") . '</th>';
print '</tr>';
foreach ($periods as $p) {
print '<tr>';
print '<td>' . $p['period_name'] . '</td>';
print '<td>' . dol_print_date($p['start_date'], 'day') . '</td>';
print '<td>' . dol_print_date($p['end_date'], 'day') . '</td>';
print '<td>' . $langs->trans("Status" . ucfirst($p['status'])) . '</td>';
print '<td>';
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=create_declaration&period_id=' . $p['rowid'] . '" class="butAction">' . $langs->trans("CreateDeclaration") . '</a>';
print '</td>';
print '</tr>';
}
print '</table>';
}
print '</div>';
print '</div>';
// Print declarations section
print '<div class="fiche">';
print '<div class="fichehalfright">';
print '<div class="titre">' . $langs->trans("DeclarationTVADeclarations") . '</div>';
if (empty($declarations)) {
print '<div class="info">' . $langs->trans("NoDeclarationsFound") . '</div>';
} else {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("DeclarationNumber") . '</th>';
print '<th>' . $langs->trans("Period") . '</th>';
print '<th>' . $langs->trans("Status") . '</th>';
print '<th>' . $langs->trans("NetVATDue") . '</th>';
print '<th>' . $langs->trans("Actions") . '</th>';
print '</tr>';
foreach ($declarations as $d) {
print '<tr>';
print '<td>' . $d['declaration_number'] . '</td>';
print '<td>' . $d['period_name'] . '</td>';
print '<td>' . $langs->trans("Status" . ucfirst($d['status'])) . '</td>';
print '<td>' . price($d['net_vat_due']) . '</td>';
print '<td>';
if ($d['status'] == 'draft') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=validate_declaration&declaration_id=' . $d['rowid'] . '" class="butAction">' . $langs->trans("Validate") . '</a>';
} elseif ($d['status'] == 'validated') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=submit_declaration&declaration_id=' . $d['rowid'] . '" class="butAction">' . $langs->trans("Submit") . '</a>';
}
print '<a href="declarationtva_view.php?id=' . $d['rowid'] . '" class="butAction">' . $langs->trans("View") . '</a>';
print '</td>';
print '</tr>';
}
print '</table>';
}
print '</div>';
print '</div>';
// Print configuration section
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("DeclarationTVAConfiguration") . '</div>';
print '<div class="info">';
print '<a href="admin/setup.php" class="butAction">' . $langs->trans("ConfigureModule") . '</a>';
print '</div>';
print '</div>';
// Print footer
llxFooter();
?>