WIP Address BMD Export
This commit is contained in:
@@ -165,6 +165,102 @@ class AddressController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function exportBmd() {
|
||||
/*$last_export = new mfConfig("bmd.export.ts");
|
||||
$last_export->type("int");
|
||||
$last_export->value(date("U"));
|
||||
$last_export->save();
|
||||
*/
|
||||
$last_export = 0;
|
||||
|
||||
$export_ts = new mfConfig("bmd.export.ts");
|
||||
if($export_ts->value()) {
|
||||
$last_export = $export_ts->value();
|
||||
}
|
||||
|
||||
$type = "inc";
|
||||
|
||||
if($this->request->type == "full") {
|
||||
$last_export = 0;
|
||||
$type = "full";
|
||||
}
|
||||
|
||||
if(!file_exists(TT_ADDRESS_BMD_EXPORT_PATH)) {
|
||||
$this->layout()->setFlash("Export Pfad (".TT_ADDRESS_BMD_EXPORT_PATH.") nicht gefunden!", "error");
|
||||
}
|
||||
|
||||
$export_ts->value(date('U'));
|
||||
|
||||
$search = ["edit>" => $last_export, "customer_or_fibu_numbers" => true];
|
||||
|
||||
if(!AddressModel::count($search)) {
|
||||
$this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn");
|
||||
$this->redirect("Address");
|
||||
}
|
||||
|
||||
$addresses = [];
|
||||
|
||||
foreach(AddressModel::search($search) as $address) {
|
||||
$a = [];
|
||||
$a["is_supplier"] = (array_key_exists("supplier", $address->types) && $address->types['supplier']) ? "1" : "0";
|
||||
$a["is_customer"] = "1";
|
||||
$a["customer_number"] = $address->customer_number;
|
||||
$a["fibu_account_number"] = $address->fibu_account_number;
|
||||
$a["fibu_supplier_number"] = $address->fibu_supplier_number;
|
||||
$a["fibu_supplier_due"] = $address->fibu_supplier_due;
|
||||
$a["company"] = $address->company;
|
||||
$a["firstname"] = $address->firstname;
|
||||
$a["lastname"] = $address->lastname;
|
||||
$a["street"] = $address->street;
|
||||
$a["zip"] = $address->zip;
|
||||
$a["city"] = $address->city;
|
||||
$a["country"] = $address->country;
|
||||
$a["phone"] = $address->phone;
|
||||
$a["mobile"] = $address->mobile;
|
||||
$a["email"] = $address->email;
|
||||
$a["uid"] = $address->uid;
|
||||
$a["billing_type"] = $address->billing_type;
|
||||
$a["billing_delivery"] = $address->billing_delivery;
|
||||
if(array_key_exists("billing", $address->links) && $address->links["billing"]) {
|
||||
$a["bank"] = $address->links["billing"]->bank_account_bank;
|
||||
$a["bank_owner"] = $address->links["billing"]->bank_account_owner;
|
||||
$a["iban"] = $address->links["billing"]->bank_account_iban;
|
||||
$a["bic"] = $address->links["billing"]->bank_account_bic;
|
||||
} else {
|
||||
$a["bank"] = $address->bank_account_bank;
|
||||
$a["bank_owner"] = $address->bank_account_owner;
|
||||
$a["iban"] = $address->bank_account_iban;
|
||||
$a["bic"] = $address->bank_account_bic;
|
||||
}
|
||||
|
||||
$addresses[] = $a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Address/bmd_export.csv");
|
||||
$tpl->set("addresses", $addresses);
|
||||
$csv_content = $tpl->render();
|
||||
|
||||
$filename = "thetool_address_export_".$type."_".date("Y-m-d-H-i-s").".csv";
|
||||
|
||||
// save to TT_ADDRESS_BMD_EXPORT_PATH
|
||||
$filepath = TT_ADDRESS_BMD_EXPORT_PATH."/".$filename;
|
||||
|
||||
if(!file_put_contents($filepath, $csv_content)) {
|
||||
$this->layout()->setFlash("Datei $filepath konnte nicht gespeichert werden!", "error");
|
||||
} else {
|
||||
$export_ts->save();
|
||||
$this->layout()->setFlash("Adressen erfolgreich exportiert", "success");
|
||||
}
|
||||
|
||||
$this->redirect("Address");
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
@@ -204,6 +300,7 @@ class AddressController extends mfBaseController {
|
||||
} else {
|
||||
$data['fibu_primary_account'] = 0;
|
||||
}
|
||||
$data['fibu_supplier_due'] = ($r->fibu_supplier_due) ? $r->fibu_supplier_due : null;
|
||||
|
||||
|
||||
// billing data
|
||||
|
||||
Reference in New Issue
Block a user