From aa373b5f4e34f2e0428e81e9b8e4a5296811c4d5 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 23 Feb 2023 13:06:04 +0100 Subject: [PATCH] Contract WIP --- Layout/default/Address/View.php | 325 ++++++++++-------- Layout/default/Contract/View.php | 46 ++- application/Address/Address.php | 8 + application/Contract/Contract.php | 6 + application/Contract/ContractModel.php | 36 ++ application/ContractFile/ContractFile.php | 5 + .../ContractFile/ContractFileModel.php | 149 ++++++++ .../Contractjournal/Contractjournal.php | 59 ++++ .../Contractjournal/ContractjournalModel.php | 128 +++++++ public/assets/css/thetool.css | 16 + 10 files changed, 624 insertions(+), 154 deletions(-) create mode 100644 application/ContractFile/ContractFile.php create mode 100644 application/ContractFile/ContractFileModel.php create mode 100644 application/Contractjournal/Contractjournal.php create mode 100644 application/Contractjournal/ContractjournalModel.php diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php index db316cd22..bd4cf24a0 100644 --- a/Layout/default/Address/View.php +++ b/Layout/default/Address/View.php @@ -27,163 +27,187 @@ -
-
-

getCompanyOrName()?>customer_number) ? " [".$address->customer_number."]" : ""?>

+
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Kundennummercustomer_number?>
Firmennamecompany)?>
Vornamefirstname?>
Nachnamelastname?>
Straßestreet?>
PLZ / Ortzip?> city?>
Landcountry?>
Telefonphone?>
Mobilmobile?>
Faxfax?>
Emailemail?>
Service PINspin?>
Einwilligungen -

"> Informationen per Post/Email/Telefon

-

">Auskunft mit Service PIN

-
Rollen - types) && count($address->types)): ?> - -
    - types)): ?> -
  • +
    +
    +

    getCompanyOrName()?>customer_number) ? " [".$address->customer_number."]" : ""?>

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Kundennummercustomer_number?>
    Firmennamecompany)?>
    Vornamefirstname?>
    Nachnamelastname?>
    Straßestreet?>
    PLZ / Ortzip?> city?>
    Landcountry?>
    Telefonphone?>
    Mobilmobile?>
    Faxfax?>
    Emailemail?>
    Service PINspin?>
    Einwilligungen +

    "> Informationen per Post/Email/Telefon

    +

    ">Auskunft mit Service PIN

    +
    Rollen + types) && count($address->types)): ?> + +
      + types)): ?> +
    • + +
    + - - - -

    Verrechnungsdaten

    UIDuid?>
    Verrechnungsartbilling_type == "sepa") ? "SEPA Bankeinzug" : "Rechnung"?>
    Rechnungsversandbilling_delivery == "paper") ? "POST" : "Email"?>
    Kreditinstitutbank_account_bank?>
    Kontoinhaberbank_account_owner?>
    IBANbank_account_iban?>
    BICbank_account_bic?>

    Zusatzdaten

    RTR Codeattributes['rtrcode']->value?>
    - -

    Verknüpfungen

    - links) && count($address->links)): ?> -
    -
    - - - linked_as) && count($address->linked_as)): ?> -

    Verknüpft als

    - - +
    +
    +
    +
    + Aktive Produkte (Contracts) +
    + contracts) && count($address->contracts)): ?> + + +
    + +
    - contracts) && count($address->contracts)): ?> -
    + active_contracts) && count($address->active_contracts)): ?> +
    +
    + Verträge +
    -

    Verträge

    @@ -194,9 +218,8 @@ - - contracts as $contract): ?> + active_contracts as $contract): ?> - +
    Bestelldatum Fertigstellung Kündigung
    "> $contract->id])?>"> @@ -213,9 +236,7 @@ ">order_date) ? date('d.m.Y', $contract->order_date) : ""?> ">finish_date) ? date('d.m.Y', $contract->finish_date) : ""?> ">cancel_date) ? date('d.m.Y', $contract->cancel_date) : ""?> - $contract->id])?>" onclick="if(!confirm('Verknüpfung wirklich entfernen?')) return false;" class="text-danger" title="Verknüpfung entfernen"> -
    diff --git a/Layout/default/Contract/View.php b/Layout/default/Contract/View.php index c0d242cf2..1a92304cf 100644 --- a/Layout/default/Contract/View.php +++ b/Layout/default/Contract/View.php @@ -27,7 +27,7 @@
    -
    +
    finish_date || $contract->finish_date > date('U')): ?>

    In Herstellung

    @@ -215,8 +215,50 @@
    + journals) && count($contract->journals)): ?> +
    +
    +
    Journaleinträge
    +
    +
    +
    +
    + + + + journals as $j): ?> + + + + + + +
    create)?> (creator?>) + type == "text"):?> + text), 128)?> + type == "phone"): ?> + text), 128)?> + type == "file"): ?> + text): ?> + text), 128)?>
    + + $j->contractfile->file_id])?>"> contractfile->name?> + type == "created_from"): ?> + value == "manual"): ?> + Vertrag manuell angelegt. + + +
    + $j->id])?>" title="Journaleintrag bearbeiten"> +
    +
    +
    +
    +
    + + linkFrom) && count($contract->linkFrom)) || (is_array($contract->linkTo) && count($contract->linkTo))): ?> -
    +

    Verknüpfte Verträge $contract->id])?>">Neuen Contract anlegen

    diff --git a/application/Address/Address.php b/application/Address/Address.php index 889de6ae3..e4a79b023 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -10,6 +10,7 @@ class Address extends mfBaseModel { private $attributes; private $permissions; private $contracts; + private $active_contracts; private $phoneparts; @@ -190,6 +191,13 @@ class Address extends mfBaseModel { return $this->contracts; } + if($name == "active_contracts") { + $owning = ContractModel::searchActive(['owner_id' => $this->id]); + $billing = ContractModel::searchActive(['billingaddress_id' => $this->id]); + $this->contracts = array_merge($owning, $billing); + return $this->contracts; + } + /* if($name == "links_to") { $links = AddressLinkModel::search(['address_id' => $this->id]); diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index 50c120017..eb35dfcbf 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -11,6 +11,7 @@ class Contract extends mfBaseModel { private $contractConfigItems; private $configgroups; private $isCancelled; + private $journals; private $links; private $linkFrom; private $linkTo; @@ -188,6 +189,11 @@ class Contract extends mfBaseModel { return $this->contractConfigItems; } + if($name == "journals") { + $this->journals = array_reverse(ContractjournalModel::search(["contract_id" => $this->id])); + return $this->journals; + } + if($name == "links") { $this->links = ContractLinkModel::includesContractId($this->id, ["type" => $link]); //var_dump($this->links);exit; diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php index 67fabb5f9..c05182549 100644 --- a/application/Contract/ContractModel.php +++ b/application/Contract/ContractModel.php @@ -116,6 +116,42 @@ class ContractModel { return 0; } + public static function searchActive($filter, $limit = false) { + //var_dump($filter);exit; + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT Contract.* FROM Contract + LEFT JOIN Address ON (Contract.owner_id = Address.id) + LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id) + LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id) + LEFT JOIN Product ON (Contract.product_id = Product.id) + WHERE $where + AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP()) + GROUP BY Contract.id + ORDER BY Contract.owner_id,Contract.`create`"; + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($count)) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new Contract($data); + } + } + + return $items; + } + public static function search($filter, $limit = false) { //var_dump($filter);exit; $items = []; diff --git a/application/ContractFile/ContractFile.php b/application/ContractFile/ContractFile.php new file mode 100644 index 000000000..f8f88ebda --- /dev/null +++ b/application/ContractFile/ContractFile.php @@ -0,0 +1,5 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + if($model->create_by === null) { + $model->create_by = $me->id; + } + if($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("ContractFile", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ContractFile($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("ContractFile", "*", "1=1 ORDER BY contract_id, `create`"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new ContractFile($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("ContractFile", "*", "$where ORDER BY contract_id, `create`"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ContractFile($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + + $sql = "SELECT ContractFile.* FROM ContractFile + LEFT JOIN File ON (ContractFile.file_id = File.id) + WHERE $where + ORDER BY contract_id, `create`"; + + $res = $db->query($sql); + + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new ContractFile($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + + if(array_key_exists("file_id", $filter)) { + $file_id = $filter['file_id']; + if(is_numeric($file_id)) { + $where .= " AND file_id=$file_id"; + } + } + + if(array_key_exists("contract_id", $filter)) { + $contract_id = $filter['contract_id']; + if(is_numeric($contract_id)) { + $where .= " AND contract_id=$contract_id"; + } + } + + //var_dump($filter);exit; + if(array_key_exists("name", $filter)) { + $name = FronkDB::singleton()->escape($filter['name']); + if($name) { + $where .= " AND name='$name'"; + } + } + + if(array_key_exists("filename", $filter)) { + $filename = FronkDB::singleton()->escape($filter['filename']); + if($filename) { + $where .= " AND File.filename='$filename'"; + } + } + + if(array_key_exists("subfolder", $filter)) { + $subfolder = FronkDB::singleton()->escape($filter['subfolder']); + if($subfolder) { + $where .= " AND File.subfolder='$subfolder'"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Contractjournal/Contractjournal.php b/application/Contractjournal/Contractjournal.php new file mode 100644 index 000000000..055ea31d4 --- /dev/null +++ b/application/Contractjournal/Contractjournal.php @@ -0,0 +1,59 @@ +$name == null) { + + if($name == "contractfile") { + if(!is_numeric($this->value)) return null; + $this->contractfile = new ContractFile($this->value); + return $this->contractfile; + } + + if($name == "creator") { + $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); + if($this->creator === null) { + $this->creator = new User($this->create_by); + if($this->creator->id) { + mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); + } + } + return $this->creator; + } + + if($name == "editor") { + $this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); + if($this->editor === null) { + $this->editor = new User($this->edit_by); + if($this->editor->id) { + mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); + } + } + return $this->editor; + } + + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + + } + + return $this->$name; + } +} \ No newline at end of file diff --git a/application/Contractjournal/ContractjournalModel.php b/application/Contractjournal/ContractjournalModel.php new file mode 100644 index 000000000..33007cd43 --- /dev/null +++ b/application/Contractjournal/ContractjournalModel.php @@ -0,0 +1,128 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + if($model->create_by === null) { + $model->create_by = $me->id; + } + if($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Contractjournal", "*", "1=1 ORDER BY contract_id,`create`"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Contractjournal($data); + } + } + return $items; + + } + + public static function getFirst($filter = false) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Contractjournal", "*", "$where ORDER BY contract_id,`create`"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Contractjournal($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + /* + $sql = "SELECT Contractjournal.* FROM Contractjournal + LEFT JOIN File ON (Contractjournal.file_id = File.id) + WHERE $where + ORDER BY order_id, name"; + + $res = $db->query($sql); + */ + $res = $db->select("Contractjournal", "*", $where); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Contractjournal($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + + if(array_key_exists("contract_id", $filter)) { + $contract_id = $filter['contract_id']; + if(is_numeric($contract_id)) { + $where .= " AND contract_id=$contract_id"; + } + } + + if(array_key_exists("order_id", $filter)) { + $order_id = $filter['order_id']; + if(is_numeric($order_id)) { + $where .= " AND order_id=$order_id"; + } + } + + if(array_key_exists("type", $filter)) { + $type = FronkDB::singleton()->escape($filter['type']); + if($type) { + $where .= " AND type='$type'"; + } + } + + if(array_key_exists("value", $filter)) { + $value = FronkDB::singleton()->escape($filter['value']); + if($value) { + $where .= " AND value='$value'"; + } + } + + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/public/assets/css/thetool.css b/public/assets/css/thetool.css index 341894cbd..3b6ec51fd 100644 --- a/public/assets/css/thetool.css +++ b/public/assets/css/thetool.css @@ -71,6 +71,22 @@ h1, h2, h3, h4, h5, h6 { border-color: #f0f0f0; box-shadow: 3px 3px 2px #a0a0a0; } +.card.border-top-primary { + border-top: 2px solid #007bff; +} +.card.border-top-danger { + border-top: 2px solid #f1556c; +} +.card.border-top-success { + border-top: 2px solid #25b343; +} +.card.border-top-warning { + border-top: 2px solid #f7b84b; +} +/* +.card-header.underline-danger { + border-bottom: 2px solid #f1556c; +}*/ #topnav { box-shadow: 2px 2px 1px #a0a0a0;