diff --git a/declarationtvaindex.php b/declarationtvaindex.php index e230b8c..f1d997a 100644 --- a/declarationtvaindex.php +++ b/declarationtvaindex.php @@ -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 ); } }