Added methods to check and retrieve economic invoice draft and booked IDs, improving invoice tracking functionality. Introduced a new method in the economic endpoint to fetch booked invoice details using external IDs. Additionally, updated the object property class to handle integer values during SQL updates.
79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
class object_property
|
|
{
|
|
public int $id; // The table of the objects in the database (e.g. users)
|
|
private string $table; // The id of the object in the database
|
|
private string $column; // The column name of the field in the database table (e.g. id, name, email)
|
|
private string $type; // The data type of the field in the database table (e.g. int, varchar, text)
|
|
private bool $required; // Whether the field is required or not
|
|
private mixed $default; // The default value of the field
|
|
|
|
public function __construct(string $table, int $id, string $column, string $type, bool $required = false, mixed $default = null)
|
|
{
|
|
$this->table = $table;
|
|
$this->id = $id;
|
|
$this->column = $column;
|
|
$this->type = $type;
|
|
$this->required = $required;
|
|
$this->default = $default;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
// Return the value of the field in the database table
|
|
return $this->value();
|
|
}
|
|
|
|
/**
|
|
* Get the value of the field in the database table
|
|
* @return mixed The value of the field in the database table
|
|
*/
|
|
public function value(): mixed
|
|
{
|
|
// Get the value of the field in the database table
|
|
global $db;
|
|
$sql = "SELECT $this->column FROM $this->table WHERE id = $this->id";
|
|
$result = $db->query($sql);
|
|
$row = $db->fetch_assoc($result);
|
|
return $row[$this->column];
|
|
}
|
|
|
|
/**
|
|
* Set the value of the field in the database table
|
|
* @param mixed $value The value of the field in the database table
|
|
*/
|
|
public function set(mixed $value): void
|
|
{
|
|
// Set the value of the field in the database table
|
|
global /** @var db $db */
|
|
$db;
|
|
|
|
// If the value is null, set it to null
|
|
if ($value === null) {
|
|
$sql = "UPDATE $this->table SET $this->column = NULL WHERE id = $this->id";
|
|
} // If the value is an integer, set it to the integer value
|
|
elseif (is_int($value)) {
|
|
$sql = "UPDATE $this->table SET $this->column = $value WHERE id = $this->id";
|
|
} // If the value is a string, escape it
|
|
else {
|
|
$value = $db->escape_string($value);
|
|
$sql = "UPDATE $this->table SET $this->column = '$value' WHERE id = $this->id";
|
|
}
|
|
$db->query($sql);
|
|
}
|
|
|
|
/**
|
|
* Nullify the value of the field in the database table
|
|
*/
|
|
public function nullify(): void
|
|
{
|
|
// Set the value of the field in the database table to null
|
|
global /** @var db $db */
|
|
$db;
|
|
$sql = "UPDATE $this->table SET $this->column = NULL WHERE id = $this->id";
|
|
$db->query($sql);
|
|
}
|
|
} |