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.
This commit is contained in:
Frank Cools 2025-10-02 18:20:05 +02:00
parent 9b7c460e61
commit 93d68b1095

View File

@ -22,6 +22,41 @@ class DeclarationTVA
*/ */
public $error; 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 * Constructor
* *
@ -34,6 +69,34 @@ class DeclarationTVA
$this->entity = $entity; $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 * Create a new declaration for a period
* *