Fix period column display by using declaration's own dates

Database Fix:
- Fixed SQL query to handle declarations with direct dates
- Use declaration's start_date/end_date when period_id is 0
- Fallback to 'Custom Period' when no period name is available
- Period column now shows actual date ranges from declarations

This fixes the empty period column issue.
This commit is contained in:
Frank Cools 2025-10-02 20:08:43 +02:00
parent 522c94093d
commit cbf3e12876

View File

@ -75,7 +75,7 @@ if ($action == 'create_declaration' && $period_id > 0) {
$declarations = array();
// Get all declarations
$sql = "SELECT d.*, p.period_name, p.start_date, p.end_date
$sql = "SELECT d.*, p.period_name, p.start_date as period_start_date, p.end_date as period_end_date
FROM " . MAIN_DB_PREFIX . "declarationtva_declarations d
LEFT JOIN " . MAIN_DB_PREFIX . "declarationtva_periods p ON d.period_id = p.rowid
WHERE d.entity = " . $conf->entity . "
@ -84,6 +84,11 @@ $sql = "SELECT d.*, p.period_name, p.start_date, p.end_date
$result = $db->query($sql);
if ($result) {
while ($obj = $db->fetch_object($result)) {
// Use declaration's own dates if period is not available
$start_date = $obj->start_date ? $obj->start_date : $obj->period_start_date;
$end_date = $obj->end_date ? $obj->end_date : $obj->period_end_date;
$period_name = $obj->period_name ? $obj->period_name : 'Custom Period';
$declarations[] = array(
'rowid' => $obj->rowid,
'declaration_number' => $obj->declaration_number,
@ -93,9 +98,9 @@ if ($result) {
'net_vat_due' => $obj->net_vat_due,
'vat_credit' => $obj->vat_credit,
'created_date' => $obj->created_date,
'period_name' => $obj->period_name,
'start_date' => $obj->start_date,
'end_date' => $obj->end_date
'period_name' => $period_name,
'start_date' => $start_date,
'end_date' => $end_date
);
}
}