Files
thetool/application/OrderProduct/OrderProduct.php
2021-08-03 21:02:37 +02:00

68 lines
1.3 KiB
PHP

<?php
class OrderProduct extends mfBaseModel {
private $order;
private $product;
private $termination;
private $editor;
private $creator;
public function formatAmount() {
if(!$this->id) {
return 0;
}
$m = [];
if(preg_match('/^(\d*)\.(\d+)$/', $this->amount, $m)) {
$int = $m[1];
$dec = $m[2];
if(!$dec) {
return $int;
}
if(preg_match('/^0+$/', $dec)) {
return $int;
}
$dec = preg_replace('/0+$/', "", $dec);
return "$int.$dec";
}
return 0;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "creator") {
if($this->id) {
$this->creator = new User($this->create_by);
return $this->creator;
} else {
return null;
}
}
if($name == "editor") {
if($this->id) {
$this->editor = new User($this->edit_by);
return $this->editor;
} else {
return null;
}
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}