needlogin=true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); if(!$me->is(["Admin"])) { $this->redirect("Dashboard"); } } protected function indexAction() { $this->layout()->setTemplate("Admin/Index"); } protected function createNetworkAddressForNetowner() { $i = 0; foreach(NetworkModel::getAll() as $network) { $netaddress = NetworkAddressModel::getFirst(["network_id" => $network->id, "address_id" => $network->owner_id, "addresstype" => "netowner"]); if(!$netaddress) { $netaddress = NetworkAddressModel::create([ 'network_id' => $network->id, 'address_id' => $network->owner_id, 'type' => "netowner" ]); $netaddress->save(); $i++; } } $this->layout()->setFlash("$i NetworkAddress Objekte angelegt.", "success"); $this->redirect("Admin"); } protected function ivtImportMatchProductsAction() { $this->layout()->setTemplate("Admin/ivtimport_product_match"); $filter_name = MFAPPNAME.'-Admin-ivtimport_product-filter'; if($this->request->resetFilter) { unset($_SESSION[$filter_name]); } $filter = []; if(is_array($this->request->filter)) { $filter = $this->request->filter; $_SESSION[$filter_name] = $filter; } else { if(array_key_exists($filter_name, $_SESSION) && count($_SESSION[$filter_name])) { $filter = $_SESSION[$filter_name]; } } $this->layout->set("filter", $filter); //$filter = $this->getPreparedFilter($filter); // pagination defaults $pagination = []; $pagination['start'] = 0; $pagination['count'] = 80; $pagination['maxItems'] = 0; if(is_numeric($this->request->s)) { $pagination['start'] = intval($this->request->s); } $filter["customer_product_id"] = true; //var_dump($filter);exit; $pagination['maxItems'] = IvtProductModel::count($filter); $ivtproducts = IvtProductModel::search($filter, $pagination); $this->layout()->set("pagination", $pagination); $this->layout()->set("ivtproducts", $ivtproducts); $this->layout()->set("products", ProductModel::getAll()); } protected function saveIvtImportMatchProducts() { $r = $this->request; //var_dump($r);exit; if(!is_array($r->product) || !count($r->product)) { $this->layout()->setFlash("Nichts zu Speichern.", "info"); $this->redirect("Admin", "ivtImportMatchProducts"); } foreach($r->product as $ivt_product_id => $product_id) { if(!$ivt_product_id || !$product_id) continue; // find IvtProductMatch by ivt product id ... $match = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_product_id]); if(!$match) { // ... or create it $ivt_product = new IvtProduct($ivt_product_id); if(!$ivt_product->id) { $this->layout()->setFlash("Ivt Product $ivt_product_id not found.", "error"); $this->redirect("Admin", "ivtImportMatchProducts"); } $match = IvtProductMatchModel::create([ "ivt_product_id" => $ivt_product_id, "ivt_product_name" => $ivt_product->name ]); } // save product_id to IvtProductMatch $match->product_id = $product_id; if(!$match->save()) { $this->layout()->setFlash("Fehler beim Speichern.", "error"); } } $this->layout()->setFlash("Erfolgreich gespeichert.", "success"); if(is_numeric($r->s) && $r->s) { $this->redirect("Admin", "ivtImportMatchProducts", ["s" => $r->s]); } $this->redirect("Admin", "ivtImportMatchProducts"); } protected function ivtDownloadActiveProducts() { $ivtproducts = IvtProductModel::getAll(); $products = []; foreach($ivtproducts as $product) { $active_count = IvtCustomerProductModel::count(['pid' => $product->id]); if(!$active_count) continue; $new_product = []; $new_product["product"] = $product; $new_product["count"] = $active_count; $new_product["customer"] = false; if($active_count == 1) { $cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]); //var_dump($cp);exit; $customer = $cp->customer; //var_dump($customer);exit; $new_product["customer"] = ($customer->company) ? $customer->company : $customer->firstname." ".$customer->surname; } $products[$product->id] = $new_product; } $this->layout()->setTemplate("Admin/ivt_active_products.csv"); $this->layout()->set("products", $products); } protected function ivtContractImportAction() { exit; $doit = false; if($this->request->doit == 1) { $doit = true; } require_once(realpath(dirname(__FILE__)."/functions")."/IvtContractImport.php"); if(class_exists("Admin_IvtContractImport")) { $import = new Admin_IvtContractImport($this->request); $data = $import->run($doit); $this->layout()->setTemplate("Admin/IvtContractImport"); $this->layout()->set("data", $data); if($doit) { $this->layout()->setFlash((count($data['contracts']) - $data['ignore'])." Contracts aus IVT importiert!", "success"); } } } protected function ivtCreditImportAction() { $doit = false; if($this->request->doit == 1) { $doit = true; } require_once(realpath(dirname(__FILE__)."/functions")."/IvtCreditImport.php"); if(class_exists("Admin_IvtCreditImport")) { $import = new Admin_IvtCreditImport($this->request); $data = $import->run($doit); $this->layout()->setTemplate("Admin/IvtCreditImport"); $this->layout()->set("data", $data); if($doit) { $this->layout()->setFlash((count($data['contracts']) - $data['ignore'])." Gutschriften aus IVT importiert!", "success"); } } } }