Add Gutschrift functionality to ManualInvoice with modal and backend support
This commit is contained in:
@@ -227,4 +227,36 @@ class TTCrudBaseModel {
|
||||
return new static($result->fetch_assoc());
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$data = [];
|
||||
|
||||
$reflection = new ReflectionClass(get_called_class());
|
||||
foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$field = $property->getName();
|
||||
if (property_exists($this, $field)) {
|
||||
$data[$field] = $this->$field;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have an ID, update; otherwise, create
|
||||
if (isset($this->id) && $this->id > 0) {
|
||||
return self::update($data);
|
||||
} else {
|
||||
$newId = self::create($data);
|
||||
$this->id = $newId;
|
||||
return $newId;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteInstance() {
|
||||
if (!isset($this->id)) {
|
||||
throw new Exception("Cannot delete model without ID");
|
||||
}
|
||||
return self::delete($this->id);
|
||||
}
|
||||
|
||||
public static function search($filter = [], $limit = null, $order = ["key" => null]): array {
|
||||
return self::getAll($filter, $limit, 0, $order);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user