Complete CA-3 Structure Update: - Added Section B: Décompte de la TVA due (VAT Due Calculation) - Added 4 new CA-3 lines for VAT due calculations - Updated all language files with new section and lines Section B - VAT Due Calculation: - Line 08: TVA due au taux de 20% (VAT due at 20% rate) - Line 09: TVA due au taux de 10% (VAT due at 10% rate) - Line 9B: TVA due aux taux réduits (VAT due at reduced rates 5,5% and 2,1%) - Line 17: TVA due au titre des acquisitions intracommunautaires (VAT due on intra-EU acquisitions) Enhanced Configuration: - Added section B header with proper description - Added all 4 VAT due calculation lines - Updated PCG account mappings for VAT due lines - Enhanced form layout to show both sections A and B Language Support: - Added English translations for Section B and all lines - Added French translations for Section B and all lines - Updated section headers in both languages Documentation: - Updated PLANNING.md with complete CA-3 structure - Added Section B documentation with all lines - Complete Notice 4722 compliance The module now includes the complete CA-3 structure with both sections A and B!
313 lines
11 KiB
PHP
313 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* DeclarationTVA_Config Class
|
|
* Configuration management for DeclarationTVA module
|
|
* MVP Version - Phase 1
|
|
*/
|
|
|
|
class DeclarationTVA_Config
|
|
{
|
|
/**
|
|
* @var DoliDB Database handler
|
|
*/
|
|
public $db;
|
|
|
|
/**
|
|
* @var int Entity ID
|
|
*/
|
|
public $entity;
|
|
|
|
/**
|
|
* @var string Error message
|
|
*/
|
|
public $error;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param DoliDB $db Database handler
|
|
* @param int $entity Entity ID
|
|
*/
|
|
public function __construct($db, $entity = 1)
|
|
{
|
|
$this->db = $db;
|
|
$this->entity = $entity;
|
|
}
|
|
|
|
/**
|
|
* Get configuration value
|
|
*
|
|
* @param string $key Configuration key
|
|
* @param mixed $default Default value
|
|
* @return mixed Configuration value
|
|
*/
|
|
public function get($key, $default = null)
|
|
{
|
|
$sql = "SELECT config_value FROM " . MAIN_DB_PREFIX . "declarationtva_config
|
|
WHERE entity = " . $this->entity . " AND config_key = '" . $this->db->escape($key) . "'";
|
|
|
|
$result = $this->db->query($sql);
|
|
if ($result && $this->db->num_rows($result) > 0) {
|
|
$obj = $this->db->fetch_object($result);
|
|
return $obj->config_value;
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* Set configuration value
|
|
*
|
|
* @param string $key Configuration key
|
|
* @param mixed $value Configuration value
|
|
* @return bool Success
|
|
*/
|
|
public function set($key, $value)
|
|
{
|
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "declarationtva_config
|
|
(entity, config_key, config_value, created_date)
|
|
VALUES (" . $this->entity . ", '" . $this->db->escape($key) . "',
|
|
'" . $this->db->escape($value) . "', NOW())
|
|
ON DUPLICATE KEY UPDATE config_value = '" . $this->db->escape($value) . "'";
|
|
|
|
$result = $this->db->query($sql);
|
|
return $result !== false;
|
|
}
|
|
|
|
/**
|
|
* Get account mapping for a CA-3 line
|
|
*
|
|
* @param string $ca3_line CA-3 line code
|
|
* @return array|false Account mapping or false if not found
|
|
*/
|
|
public function getAccountMapping($ca3_line)
|
|
{
|
|
$sql = "SELECT * FROM " . MAIN_DB_PREFIX . "declarationtva_account_mappings
|
|
WHERE entity = " . $this->entity . " AND ca3_line = '" . $this->db->escape($ca3_line) . "'";
|
|
|
|
$result = $this->db->query($sql);
|
|
if ($result && $this->db->num_rows($result) > 0) {
|
|
return $this->db->fetch_array($result);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Update account mapping
|
|
*
|
|
* @param string $ca3_line CA-3 line code
|
|
* @param string $account_code Account code
|
|
* @param string $account_label Account label
|
|
* @param float $vat_rate VAT rate
|
|
* @return bool Success
|
|
*/
|
|
public function updateAccountMapping($ca3_line, $account_code, $account_label, $vat_rate)
|
|
{
|
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "declarationtva_account_mappings
|
|
(entity, ca3_line, account_code, account_label, vat_rate, is_active, created_date)
|
|
VALUES (" . $this->entity . ", '" . $this->db->escape($ca3_line) . "',
|
|
'" . $this->db->escape($account_code) . "', '" . $this->db->escape($account_label) . "',
|
|
" . $vat_rate . ", 1, NOW())
|
|
ON DUPLICATE KEY UPDATE
|
|
account_code = '" . $this->db->escape($account_code) . "',
|
|
account_label = '" . $this->db->escape($account_label) . "',
|
|
vat_rate = " . $vat_rate;
|
|
|
|
$result = $this->db->query($sql);
|
|
return $result !== false;
|
|
}
|
|
|
|
/**
|
|
* Get all account mappings
|
|
*
|
|
* @return array Account mappings
|
|
*/
|
|
public function getAllAccountMappings()
|
|
{
|
|
$sql = "SELECT * FROM " . MAIN_DB_PREFIX . "declarationtva_account_mappings
|
|
WHERE entity = " . $this->entity . " AND is_active = 1
|
|
ORDER BY ca3_line";
|
|
|
|
$result = $this->db->query($sql);
|
|
$mappings = array();
|
|
|
|
if ($result) {
|
|
while ($obj = $this->db->fetch_object($result)) {
|
|
$mappings[] = array(
|
|
'rowid' => $obj->rowid,
|
|
'ca3_line' => $obj->ca3_line,
|
|
'account_code' => $obj->account_code,
|
|
'account_label' => $obj->account_label,
|
|
'vat_rate' => $obj->vat_rate,
|
|
'is_active' => $obj->is_active
|
|
);
|
|
}
|
|
}
|
|
|
|
return $mappings;
|
|
}
|
|
|
|
/**
|
|
* Get available accounting accounts from Dolibarr
|
|
*
|
|
* @return array Accounting accounts
|
|
*/
|
|
public function getAccountingAccounts()
|
|
{
|
|
$sql = "SELECT account_number, label FROM " . MAIN_DB_PREFIX . "accounting_account
|
|
WHERE active = 1
|
|
ORDER BY account_number";
|
|
|
|
$result = $this->db->query($sql);
|
|
$accounts = array();
|
|
|
|
if ($result) {
|
|
while ($obj = $this->db->fetch_object($result)) {
|
|
$accounts[] = array(
|
|
'account_number' => $obj->account_number,
|
|
'label' => $obj->label
|
|
);
|
|
}
|
|
}
|
|
|
|
return $accounts;
|
|
}
|
|
|
|
/**
|
|
* Get CA-3 line definitions (Notice 4722 - Latest Official Structure)
|
|
*
|
|
* @return array CA-3 line definitions
|
|
*/
|
|
public function getCA3LineDefinitions()
|
|
{
|
|
return array(
|
|
// A. Opérations imposables (Taxable Operations) - Notice 4722
|
|
'A1' => array(
|
|
'label' => 'Montant HT des opérations imposables normales (biens + services imposables en France à 20%, 10%, 5,5%, 2,1%)',
|
|
'type' => 'base',
|
|
'section' => 'A',
|
|
'description' => 'HT amount of all taxable operations that form normal sales (goods + services taxable in France at 20%, 10%, 5,5%, 2,1%)',
|
|
'pcg_accounts' => 'Sales: 7xxxx; VAT: 44571x / 44572x / 44573x / 44574x'
|
|
),
|
|
'A2' => array(
|
|
'label' => 'Montant HT des opérations imposables spéciales ne relevant pas du CA courant (cessions d\'immobilisations, livraisons à soi-même)',
|
|
'type' => 'base',
|
|
'section' => 'A',
|
|
'description' => 'HT amount of special taxable operations not part of ordinary turnover (e.g. cessions d\'immobilisations, livraisons à soi-même)',
|
|
'pcg_accounts' => '775xxx (gains on disposal), 72xxx (production immobilisée), VAT: 44571x'
|
|
),
|
|
'A3' => array(
|
|
'label' => 'Montant HT des services achetés à des prestataires non établis en France mais imposables en France (autoliquidation services étrangers)',
|
|
'type' => 'base',
|
|
'section' => 'A',
|
|
'description' => 'HT amount of services purchased from providers not established in France but taxable in France (reverse charge for foreign services)',
|
|
'pcg_accounts' => '6xxxx (services purchased), 4452xxx (TVA due autoliquidée)'
|
|
),
|
|
'A4' => array(
|
|
'label' => 'Montant HT des importations imposables en France (hors UE), à l\'exclusion des produits pétroliers',
|
|
'type' => 'base',
|
|
'section' => 'A',
|
|
'description' => 'HT amount of imports taxable in France (non-EU), excluding petroleum products',
|
|
'pcg_accounts' => '6xxxx / 2xxxx purchases or assets; VAT: 4452xxx (import VAT)'
|
|
),
|
|
'A5' => array(
|
|
'label' => 'Montant HT des opérations imposables à la sortie d\'un régime fiscal suspensif (régimes douaniers, zones franches, etc.)',
|
|
'type' => 'base',
|
|
'section' => 'A',
|
|
'description' => 'HT amount of taxable operations at exit from a suspensive fiscal regime (customs regimes, free zones, etc.)',
|
|
'pcg_accounts' => 'Specific 6xxxx/2xxxx depending on goods; VAT: 4452xxx'
|
|
),
|
|
|
|
// B. Décompte de la TVA due (VAT Due Calculation) - Notice 4722
|
|
'08' => array(
|
|
'label' => 'TVA due au taux de 20%',
|
|
'type' => 'vat',
|
|
'section' => 'B',
|
|
'description' => 'VAT amounts due, calculated on A1/A2 bases at 20% rate',
|
|
'pcg_accounts' => '44571x (TVA collectée à 20%)'
|
|
),
|
|
'09' => array(
|
|
'label' => 'TVA due au taux de 10%',
|
|
'type' => 'vat',
|
|
'section' => 'B',
|
|
'description' => 'VAT amounts due, calculated on A1/A2 bases at 10% rate',
|
|
'pcg_accounts' => '44572x (TVA collectée à 10%)'
|
|
),
|
|
'9B' => array(
|
|
'label' => 'TVA due aux taux réduits (5,5% et 2,1%)',
|
|
'type' => 'vat',
|
|
'section' => 'B',
|
|
'description' => 'VAT amounts due, calculated on A1/A2 bases at reduced rates (5,5% and 2,1%)',
|
|
'pcg_accounts' => '44573x (5,5%) / 44574x (2,1%) (TVA collectée aux taux réduits)'
|
|
),
|
|
'17' => array(
|
|
'label' => 'TVA due au titre des acquisitions intracommunautaires (autoliquidation)',
|
|
'type' => 'vat',
|
|
'section' => 'B',
|
|
'description' => 'VAT due on intra-EU acquisitions (autoliquidation)',
|
|
'pcg_accounts' => '4452xxx (TVA due intracommunautaire)'
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get CA-3 section headers (Notice 4722)
|
|
*
|
|
* @return array Section headers
|
|
*/
|
|
public function getCA3SectionHeaders()
|
|
{
|
|
return array(
|
|
'A' => array(
|
|
'title' => 'A. Opérations imposables (Taxable Operations)',
|
|
'description' => 'HT amounts of all taxable operations according to Notice 4722 (3310-CA3-SD)',
|
|
'notice' => 'Notice 4722 - Summary Table CA3 (3310-CA3-SD)'
|
|
),
|
|
'B' => array(
|
|
'title' => 'B. Décompte de la TVA due (VAT Due Calculation)',
|
|
'description' => 'VAT amounts due, calculated on A1/A2 bases per applicable rate',
|
|
'notice' => 'Notice 4722 - VAT Due Calculation'
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get supported VAT rates
|
|
*
|
|
* @return array VAT rates
|
|
*/
|
|
public function getVATRates()
|
|
{
|
|
return array(
|
|
'20.00' => '20%',
|
|
'10.00' => '10%',
|
|
'5.50' => '5.5%',
|
|
'2.10' => '2.1%',
|
|
'0.00' => '0%'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Validate account mapping
|
|
*
|
|
* @param string $ca3_line CA-3 line code
|
|
* @param string $account_code Account code
|
|
* @return bool Valid
|
|
*/
|
|
public function validateAccountMapping($ca3_line, $account_code)
|
|
{
|
|
// Check if account exists in Dolibarr
|
|
$sql = "SELECT COUNT(*) as count FROM " . MAIN_DB_PREFIX . "accounting_account
|
|
WHERE account_number = '" . $this->db->escape($account_code) . "' AND active = 1";
|
|
|
|
$result = $this->db->query($sql);
|
|
if ($result && $this->db->num_rows($result) > 0) {
|
|
$obj = $this->db->fetch_object($result);
|
|
return $obj->count > 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|