From 93d68b1095c676342988f11af07d33faab682b84 Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 18:20:05 +0200 Subject: [PATCH] Add fetch method and properties to DeclarationTVA class Class Enhancement: - Added missing properties: rowid, period_id, declaration_number, declaration_name, start_date, end_date, status - Added fetch() method to retrieve declaration by ID - Method populates object properties from database - Returns 1 if found, 0 if not found, -1 if error This fixes the 'Call to undefined method fetch()' error in declarationtva_view.php. --- core/class/declarationtva.class.php | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index b2ac3a9..dca1478 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -22,6 +22,41 @@ class DeclarationTVA */ public $error; + /** + * @var int Declaration ID + */ + public $rowid; + + /** + * @var int Period ID + */ + public $period_id; + + /** + * @var string Declaration number + */ + public $declaration_number; + + /** + * @var string Declaration name + */ + public $declaration_name; + + /** + * @var string Start date + */ + public $start_date; + + /** + * @var string End date + */ + public $end_date; + + /** + * @var string Status + */ + public $status; + /** * Constructor * @@ -34,6 +69,34 @@ class DeclarationTVA $this->entity = $entity; } + /** + * Fetch declaration by ID + * + * @param int $id Declaration ID + * @return int 1 if found, 0 if not found, -1 if error + */ + public function fetch($id) + { + $sql = "SELECT * FROM " . MAIN_DB_PREFIX . "declarationtva_declarations + WHERE rowid = " . (int)$id . " AND entity = " . $this->entity; + + $result = $this->db->query($sql); + if ($result) { + $obj = $this->db->fetch_object($result); + if ($obj) { + $this->rowid = $obj->rowid; + $this->period_id = $obj->period_id; + $this->declaration_number = $obj->declaration_number; + $this->declaration_name = $obj->declaration_name; + $this->start_date = $obj->start_date; + $this->end_date = $obj->end_date; + $this->status = $obj->status; + return 1; + } + } + return 0; + } + /** * Create a new declaration for a period *