diff --git a/Layout/default/Admin/Index.php b/Layout/default/Admin/Index.php index 81b5fd926..2c66cf808 100644 --- a/Layout/default/Admin/Index.php +++ b/Layout/default/Admin/Index.php @@ -29,6 +29,9 @@
">Kundenstatistiken
+
+
">Businesskunden CSV herunterladen
+
">RTR Reporting
diff --git a/application/Admin/AdminController.php b/application/Admin/AdminController.php index 77ecb2ff9..25cc2726b 100644 --- a/application/Admin/AdminController.php +++ b/application/Admin/AdminController.php @@ -80,6 +80,64 @@ class AdminController extends mfBaseController { } + protected function downloadBusinessCustomers() { + $bc_sql = "SELECT COUNT(Contract.id) as contract_count, Address.* FROM `Address` + LEFT JOIN Contract ON (Contract.owner_id = Address.id) + WHERE customer_number > 0 AND company <> '' + AND (Contract.cancel_date IS NULL OR Contract.cancel_date > UNIX_TIMESTAMP()) + GROUP BY Address.id HAVING contract_count > 0 + ORDER BY Address.company, Address.lastname + "; + //$this->log->debug($bc_sql); + $bc_res = $this->db()->query($bc_sql); + + $csv = "customer_number;fibu_account_number;uid;company;firstname;lastname;street;zip;city;country;email;phone;fax;mobile;birthdate;allow_contact;allow_spin\n"; + while($address = $this->db()->fetch_object($bc_res)) { + $country = new Country($address->country_id); + $birthdate = false; + + if($address->birthdate) + try { + $birthdate = new DateTime($address->birthdate); + } catch(Exception $e) { + $birthdate = false; + } + + $csv .= "{$address->customer_number};"; + $csv .= "{$address->fibu_account_number};"; + $csv .= "\"{$address->uid}\";"; + $csv .= "\"{$address->company}\";"; + $csv .= "\"{$address->firstname}\";"; + $csv .= "\"{$address->lastname}\";"; + $csv .= "\"{$address->street}\";"; + $csv .= "\"{$address->zip}\";"; + $csv .= "\"{$address->city}\";"; + if($country->id) { + $csv .= "\"{$country->name}\";"; + } else { + $csv .= ";"; + } + $csv .= "\"{$address->email}\";"; + $csv .= "\"".(string)$address->phone."\";"; + $csv .= "\"".(string)$address->fax."\";"; + $csv .= "\"".(string)$address->mobile."\";"; + if($birthdate) { + $csv .= "\"".$birthdate->format('d.m.Y')."\";"; + } else { + $csv .= ";"; + } + $csv .= "{$address->allow_contact};"; + $csv .= "{$address->allow_spin};"; + $csv .= "\n"; + } + + header("Content-type: text/csv; charset=utf-8"); + header('Content-disposition: attachment; filename="tt-business_customers-'.date('Y-m-d_H-i-s').'.csv"'); + echo $csv; + exit; + + } + protected function rtrReporting() { require_once(realpath(dirname(__FILE__)."/functions")."/RtrReporting.php");