WIP Address BMD Export

This commit is contained in:
Frank Schubert
2024-01-05 13:56:02 +01:00
parent 60f0461f79
commit 7646345779
11 changed files with 308 additions and 9 deletions

View File

@@ -256,6 +256,14 @@
<input type="text" class="form-control" name="fibu_supplier_number" id="fibu_supplier_number" value="<?=$address->fibu_supplier_number?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="fibu_supplier_due">FIBU Lieferanten Zahlungsziel</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="fibu_supplier_due" id="fibu_supplier_due" value="<?=$address->fibu_supplier_due?>" />
<small>Standard: 30 Tage</small>
</div>
</div>
</div>
</div>

View File

@@ -38,7 +38,10 @@
<div class="card-body">
<div class="row">
<div class="col">
<a href="https://thetool.xinon.at/xfarm/" class="btn btn-primary" target="_blank">AR-Merge / Fibu Konten Import</a>
<a href="https://thetool.xinon.at/xfarm/" class="btn btn-primary" target="_blank"><i class="far fa-arrows-to-circle fa-fw"></i> AR-Merge / Fibu Konten Import</a>
<a href="<?=self::getUrl("Address", "exportBmd")?>" class="ml-2 btn btn-outline-primary"><i class="fas fa-down-from-dotted-line fa-fw"></i> Inkrementellen BMD-Export starten</a>
<a href="<?=self::getUrl("Address", "exportBmd", ["type" => "full"])?>" class="btn btn-outline-danger float-right"><i class="fas fa-down-from-line fa-fw"></i> Vollen BMD-Export starten</a>
</div>
</div>
</div>
@@ -47,7 +50,7 @@
<div class="card">
<div class="card-body mb-3">
<h4 class="header-title mb-3">Filter</h4>
<h4 class="header-title mb-3"><i class="fad fa-filter fa-fw"></i> Filter</h4>
<form method="get" action="<?=self::getUrl("Address")?>">
<div class="row">
@@ -157,8 +160,8 @@
<div class="row mt-2">
<div class="col">
<button type="submit" class="btn btn-primary">Filter anwenden</button>
<a class="btn btn-secondary" href="<?=self::getUrl("Address")?>">Filter zurücksetzen</a>
<button type="submit" class="btn btn-primary"><i class="far fa-search fa-fw"></i> Filter anwenden</button>
<a class="btn btn-secondary" href="<?=self::getUrl("Address")?>"><i class="far fa-xmark fa-fw"></i> Filter zurücksetzen</a>
</div>
</div>
</form>

View File

@@ -128,6 +128,9 @@
</tr><tr>
<th>FIBU Lieferanten Konto</th>
<td><?=$address->fibu_supplier_number?></td>
</tr><tr>
<th>FIBU Lieferanten Zahlungsziel</th>
<td><?=$address->fibu_supplier_due?></td>
</tr><tr>
<td colspan="2"><h4>Zusatzdaten</h4></td>
</tr><tr>

View File

@@ -0,0 +1,9 @@
Lieferant;Kunde;Kundenummer;FIBU-Verrechnungsnummer;FIBU Lieferantennummer;Zahlungsziel Lieferant;Firma;Vorname;Nachname;Straße Hausnummer;PLZ;Ort;Land;Telefon;Mobil;Mail;UID;Verrechnungsart;Rechnungsversand;Kreditinstitut;Kontoinhaber;IBAN;BIC
<?php
foreach($addresses as $a):
?>
<?=$a["is_supplier"]?>;<?=$a["is_customer"]?>;<?=$a["customer_number"]?>;<?=$a["fibu_account_number"]?>;<?=$a["fibu_supplier_number"]?>;<?=$a["fibu_supplier_due"]?>;<?=$this->nl2ws($a["company"])?>;<?=$this->nl2ws($a["firstname"])?>;<?=$this->nl2ws($a["lastname"])?>;<?=$this->nl2ws($a["street"])?>;<?=$this->nl2ws($a["$address->zip"])?>;<?=$this->nl2ws($a["city"])?>;<?=$this->nl2ws($a["country"])?>;<?=$this->nl2ws($a["phone"])?>;<?=$this->nl2ws($a["mobile"])?>;<?=$this->nl2ws($a["email"])?>;<?=$this->nl2ws($a["uid"])?>;<?=$a["billing_type"]?>;<?=$a["billing_delivery"]?>;<?=$a["bank_account_bank"]?>;<?=$a["bank_account_owner"]?>;<?=$a["bank_account_iban"]?>;<?=$a["bank_account_bic"]?>
<?php
endforeach;

View File

@@ -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

View File

@@ -397,6 +397,35 @@ class AddressModel {
$where .= " AND parent_id IS NULL";
}
}*/
if(array_key_exists("create>", $filter)) {
$create = $filter['create>'];
if(is_numeric($create)) {
$where .= " AND Address.create > $create";
}
}
if(array_key_exists("create<", $filter)) {
$create = $filter['create<'];
if(is_numeric($create)) {
$where .= " AND Address.create < $create";
}
}
if(array_key_exists("edit>", $filter)) {
$edit = $filter['edit>'];
if(is_numeric($edit)) {
$where .= " AND Address.edit > $edit";
}
}
if(array_key_exists("edit<", $filter)) {
$edit = $filter['edit<'];
if(is_numeric($edit)) {
$where .= " AND Address.edit < $edit";
}
}
//var_dump($filter, $where);exit;
return $where;
}

View File

@@ -0,0 +1,67 @@
<?php
class SystemController extends mfBaseController {
protected function init($reqeust) {
$me = new User();
$me->loadMe();
$this->layout()->set("me",$me);
$this->me = $me;
if(!$me->isAdmin()) {
// all users can call non-action methods
if($this->action != "" || $request != null) {
$this->redirect("Dashboard");
}
}
}
protected function indexAction() {
if(!$this->me->isAdmin()) {
$this->redirect("Dashboard");
}
$this->layout()->setTemplate("System/System");
}
protected function saveAction($request) {
if(!$this->me->isAdmin()) {
$this->redirect("Dashboard");
}
foreach($request as $name => $value) {
$m = [];
if(!preg_match('/^system_(.+)$/',$name,$m)) {
continue;
}
$name = str_replace("_", ".", $m[1]);
$config = new mfConfig($name);
$config->value($value);
$config->save();
}
$this->redirect("System");
}
public function getLastCommit() {
$git_path = BASEDIR."/.git";
$output = [];
if(defined("GIT_BIN_PATH") && GIT_BIN_PATH) {
$git = GIT_BIN_PATH;
} else {
$git = "/usr/bin/git";
}
$cmd = "$git --git-dir $git_path rev-parse HEAD";
if(!exec($cmd, $output)) {
$log = mfLoghandler::singleton();
$log->warn("Cannot read git ref!");
}
$ref = $output[0];
if(strlen($output[0]) > 8) {
$ref = substr($output[0], 0, 8);
}
return $ref;
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddressAddFibuSupplierDue extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Address");
$table->addColumn("fibu_supplier_due", "integer", ["null" => true, "default" => null, "after" => "fibu_supplier_number"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Address");
$table->removeColumn("fibu_supplier_due");
$table->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateSystemTable extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("System");
$table->addColumn("active", "integer", ["null" => false, "default" => 1, "limit" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]);
$table->addColumn("name", "string", ["null" => false, "limit" => 255]);
$table->addColumn("value", "string", ["null" => false, "limit" => 1024]);
$table->addColumn("type", "enum", ["null" => false, "values" => 'int,float,string,json']);
$table->addColumn("create_by", "integer", ["null" => false]);
$table->addColumn("edit_by", "integer", ["null" => false]);
$table->addColumn("create", "integer", ["null" => false]);
$table->addColumn("edit", "integer", ["null" => false]);
$table->create();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("System")->drop();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -43,6 +43,10 @@ class Layout extends mfLayout {
return date("d.m.Y", $int);
}
public function nl2ws($string) {
return str_replace(["\n","\r","\t","\v"], " ", $string);
}
/*
* Gets mfBaseModel object from Cache or gets in from DB and saves it to Cache
*/

View File

@@ -7,6 +7,10 @@ class mfConfig {
private $value;
private $active;
private $type;
public $create_by;
public $edit_by;
public $create;
public $edit;
private $me;
public function __construct($name) {
@@ -15,21 +19,26 @@ class mfConfig {
$name = $this->db->escape($name);
$this->name = $name;
$me = new User();
if(defined("INTERNAL_USER_ID")) {
$me->id = INTERNAL_USER_ID;
$me = new User(INTERNAL_USER_ID);
} else {
$me = new User();
$me->loadMe();
}
$this->me = $me;
$res = $this->db->select("System", "*", "name='$name'");
$res = $this->db->select("System", "*", "name='$name' LIMIT 1");
if($this->db->num_rows($res)) {
$data = $this->db->fetch_object($res);
$this->id = $data->id;
$this->value = $data->value;
$this->active = $data->active;
$this->type = $data->type;
$this->create_by = $data->create_by;
$this->edit_by = $data->edit_by;
$this->create = $data->create;
$this->edit = $data->edit;
} else {
$this->active = 1;
$this->type = "string";
@@ -54,7 +63,6 @@ class mfConfig {
return $this->active;
}
public function save() {
$id = $this->id;