Files
thetool/application/Order/Order.php
2021-10-07 22:31:12 +02:00

135 lines
3.0 KiB
PHP

<?php
class Order extends mfBaseModel {
private $owner;
private $billingaddress;
private $products;
private $terminations;
private $files;
private $creator;
private $editor;
public function getNewPos() {
if(!$this->id) {
return 0;
}
$products = $this->getProperty("products");
if(!is_array($products) || !count($products)) {
return 1;
}
$p = end($products);
return ++$p->pos;
}
public function getTerminations() {
if(!$this->id) {
return false;
}
$products = $this->getProperty("products");
if(!is_array($products) || !count($products)) {
return false;
}
$terminations = [];
foreach($products as $product) {
if($product->termination_id) {
$terminations[] = $product->termination;
}
}
//var_dump($this->terminations);exit;
return $terminations;
}
public function createIvtCustomer($data) {
}
public function deletePositions() {
if(!is_array($this->getProperty("products")) || !count($this->getProperty("products"))) {
return true;
}
foreach($this->getProperty("products") as $position) {
$position->delete();
}
}
public function deleteFiles() {
if(!is_array($this->getProperty("files")) || !count($this->getProperty("files"))) {
return true;
}
//var_dump($this->files);exit;
foreach($this->getProperty("files") as $file) {
$file->file->delete();
$file->delete();
}
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "owner") {
$this->owner = new Address($this->owner_id);
return $this->owner;
}
if($name == "contact") {
$this->contact = new Address($this->contact_id);
return $this->contact;
}
if($name == "billingaddress") {
$this->billingaddress = new Address($this->billingaddress_id);
return $this->billingaddress;
}
if($name == "products") {
$this->products = OrderProductModel::search(["order_id" => $this->id]);
return $this->products;
}
if($name == "terminations") {
$this->terminations = $this->getTerminations();
return $this->terminations;
}
if($name == "files") {
$this->files = OrderFileModel::search(['order_id' => $this->id]);
return $this->files;
}
if($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$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;
}
}