added Business customer csv download in /Admin

This commit is contained in:
Frank Schubert
2025-12-04 21:51:43 +01:00
parent b0a64b8184
commit 1045492773
2 changed files with 61 additions and 0 deletions

View File

@@ -29,6 +29,9 @@
<div class="row col-12">
<div><a href="<?=self::getUrl("Admin", "customerStatistics")?>">Kundenstatistiken</a></div>
</div>
<div class="row col-12">
<div><a href="<?=self::getUrl("Admin", "downloadBusinessCustomers")?>">Businesskunden CSV herunterladen</a></div>
</div>
<div class="row col-12">
<div><a href="<?=self::getUrl("Admin", "RtrReporting")?>">RTR Reporting</a></div>
</div>

View File

@@ -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");