Merge branch 'fronkdev' into 'master'

BMD export update / address Skonto

See merge request fronk/thetool!176
This commit is contained in:
Frank Schubert
2024-01-16 18:23:21 +00:00
7 changed files with 264 additions and 43 deletions

View File

@@ -1,4 +1,3 @@
<?php //var_dump($address->parent->types);exit;?>
<?php
$urlfilter = [];
if($s) {
@@ -257,19 +256,34 @@
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="fibu_supplier_number">FIBU Lieferanten Nummer</label>
<label class="col-lg-2 col-form-label" for="fibu_supplier_number">FIBU Lieferantennummer</label>
<div class="col-lg-10">
<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>
<label class="col-lg-2 col-form-label" for="fibu_supplier_due">Lieferant 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: <?=TT_ADDRESS_DEFAULT_SUPPLIER_DUE?> Tage</small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="fibu_supplier_skonto">Lieferant Skontotage</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="fibu_supplier_skonto" id="fibu_supplier_skonto" value="<?=$address->fibu_supplier_skonto?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="fibu_supplier_skonto_rate">Lieferant Skonto %</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="fibu_supplier_skonto_rate" id="fibu_supplier_skonto_rate" value="<?=$address->fibu_supplier_skonto_rate?>" />
</div>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -1,9 +1,10 @@
Lieferant;Kunde;address_id;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
$header = "FIBU Kontonummber;Zahlungsziel Lieferant;Skontotage;Skontoprozent;Vorname;Nachname;Straße Hausnummer;PLZ;Ort;Land;Telefon;Mail;UID;SEPA;Kontoinhaber;IBAN;BIC;customer_numbers\n";
$this->setReturnValue(["header" => $header]);
foreach($addresses as $a):
?>
<?=$a["is_supplier"]?>;<?=$a["is_customer"]?>;<?=$a["id"]?>;<?=$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"]?>;<?=$a["owner"]?>;<?=$a["iban"]?>;<?=$a["bic"]?>
<?=$a["fibu_account_number"]?>;<?=$a["fibu_supplier_due"]?>;<?=$a["fibu_supplier_skonto"]?>;<?=$a["fibu_supplier_skonto_rate"]?>;<?=$this->nl2ws($a["firstname"])?>;<?=$this->nl2ws($a["lastname"])?>;<?=$this->nl2ws($a["street"])?>;<?=$this->nl2ws($a["zip"])?>;<?=$this->nl2ws($a["city"])?>;<?=$this->nl2ws($a["countrycode"])?>;<?=$this->nl2ws($a["phone"])?>;<?=$this->nl2ws($a["email"])?>;<?=$this->nl2ws($a["uid"])?>;<?=$a["billing_type"]?>;<?=$a["bank_owner"]?>;<?=$a["iban"]?>;<?=$a["bic"]?>;<?=implode(" ",$a["customer_numbers"])?>
<?php
endforeach;

View File

@@ -192,17 +192,22 @@ class AddressController extends mfBaseController {
$last_export = $export_ts->value();
}
$type = "inc";
if(!file_exists(TT_ADDRESS_BMD_EXPORT_PATH)) {
$this->layout()->setFlash("Export Pfad (".TT_ADDRESS_BMD_EXPORT_PATH.") nicht gefunden!", "error");
}
$filepath = TT_ADDRESS_BMD_EXPORT_PATH."/".TT_ADDRESS_BMD_EXPORT_FILENAME;
$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");
// delete export file if export if full
if($last_export == 0 && file_exists($filepath)) {
unlink($filepath);
}
$export_ts->value(date('U'));
$search = ["edit>" => $last_export, "customer_or_fibu_numbers" => true];
@@ -215,7 +220,11 @@ class AddressController extends mfBaseController {
$addresses = [];
foreach(AddressModel::search($search) as $address) {
// if supplier -> add it as extra line
if($address->fibu_supplier_number) {
$addresses[$address->fibu_supplier_number] = $address;
if(!$address->fibu_account_number) continue;
}
// if is primary -> use it
if($address->fibu_account_number && $address->fibu_primary_account) {
@@ -271,53 +280,108 @@ class AddressController extends mfBaseController {
continue;
}
// if supplier -> use it
if($address->fibu_supplier_number) {
$addresses[$address->fibu_supplier_number] = $address;
continue;
}
}
$country_code_errors = [];
$export_addresses = [];
foreach($addresses as $address) {
foreach($addresses as $fibu_num => $address) {
$a = [];
$a["id"] = $address->id;
$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["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"] = $fibu_num;
//$a["fibu_supplier_number"] = $address->fibu_supplier_number;
$a["fibu_supplier_due"] = (is_numeric($address->fibu_supplier_due)) ? $address->fibu_supplier_due : TT_ADDRESS_DEFAULT_SUPPLIER_DUE;
$a["company"] = $address->company;
$a["firstname"] = $address->firstname;
$a["lastname"] = $address->lastname;
$a["fibu_supplier_skonto"] = $address->fibu_supplier_skonto;
$a["fibu_supplier_skonto_rate"] = $address->fibu_supplier_skonto_rate;
$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;
if(strlen($address->country) == 2) {
$a["countrycode"] = trim($address->country);
} else {
$a["countrycode"] = "AT";
if(trim($address->country)) {
$acountry = strtolower(trim($address->country));
$cc = __($acountry, "cc");
$this->log->debug("is $cc == cc.$acountry");
$this->log->debug("last translation failed: ".(__last_translation_failed() ? "true" : "false"));
if(__last_translation_failed()) {
//if($cc == "cc.".$acountry) {
$a["countrycode"] = "AT";
// email to buchhaltung
$country_code_errors[$fibu_num] = $address;
} else {
$a["countrycode"] = $cc;
}
}
}
$a["phone"] = "";
if($address->mobile) $a["phone"] = $address->mobile;
if($address->phone) $a["phone"] = $address->phone;
$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;
$a["billing_type"] = ($address->billing_type == "sepa") ? "1" : "0";
//$a["billing_delivery"] = $address->billing_delivery;
if($address->company) {
$a["firstname"] = "";
$a["lastname"] = $address->company;
} else {
$a["firstname"] = $address->firstname;
$a["lastname"] = $address->lastname;
}
if(array_key_exists("billing", $address->links) && $address->links["billing"][0] && $address->links["billing"][0]->address_id) {
//var_dump($address->links);exit;
$bill = $address->links["billing"][0]->address;
$a["bank"] = $bill->bank_account_bank;
$a["bank_owner"] = $bill->bank_account_owner;
$a["iban"] = $bill->bank_account_iban;
$a["bic"] = $bill->bank_account_bic;
$a["email"] = $bill->email;
} 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;
$a["email"] = $address->email;
}
$a["customer_numbers"] = [];
$a["customer_numbers"][] = $address->customer_number;
// add all customer numbers to customer_numbers
if($address->fibu_account_number) {
foreach(AddressModel::search(["fibu_account_number" => $address->fibu_account_number]) as $secondary) {
if($secondary->customer_number && !in_array($secondary->customer_number, $a["customer_numbers"])) {
$a["customer_numbers"][] = $secondary->customer_number;
}
}
}
$export_addresses[] = $a;
}
if(count($country_code_errors)) {
$msg = "Hallo,\r\n\r\ndas in thetool eingetragene Land von folgenden Kunden/Lieferanten konnte nicht in einen ISO-Code übersetzt werden:\r\n\r\n";
foreach($country_code_errors as $fibu_num => $address) {
$msg .= "$fibu_num (".$address->getCompanyOrName()."): ".$address->country."\r\n";
}
$email = new Emailnotification();
$email->setFrom(TT_OUTGOING_EMAIL, "thetool");
$email->setTo(TT_FIBU_EMAIL_TO);
$email->setSubject("[BMD-Export] Fehlerhaftes Land");
$email->setBody($msg);
$email->send();
}
@@ -325,13 +389,20 @@ class AddressController extends mfBaseController {
$tpl->setTemplate("Address/bmd_export.csv");
$tpl->set("addresses", $export_addresses);
$csv_content = $tpl->render();
$return_values = $tpl->getReturnedValue();
$csv_header = $return_values['header'];
$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)) {
if(file_exists($filepath)) {
// if file exists, append new content
$result = file_put_contents($filepath, $csv_content, FILE_APPEND);
} else {
// else, add content with csv header
$result = file_put_contents($filepath, $csv_header.$csv_content);
}
if($result === false) {
$this->layout()->setFlash("Datei $filepath konnte nicht gespeichert werden!", "error");
} else {
$export_ts->save();
@@ -385,6 +456,8 @@ class AddressController extends mfBaseController {
$data['fibu_primary_account'] = 0;
}
$data['fibu_supplier_due'] = ($r->fibu_supplier_due) ? $r->fibu_supplier_due : null;
$data['fibu_supplier_skonto'] = ($r->fibu_supplier_skonto) ? $r->fibu_supplier_skonto : null;
$data['fibu_supplier_skonto_rate'] = ($r->fibu_supplier_skonto_rate) ? $r->fibu_supplier_skonto_rate : null;
}

View File

@@ -5,6 +5,9 @@ class AddressModel {
public $customer_number;
public $fibu_account_number;
public $fibu_supplier_number;
public $fibu_supplier_due;
public $fibu_supplier_skonto;
public $fibu_supplier_skonto_rate;
public $fibu_primary_account;
public $spin;
public $company;

View File

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

View File

@@ -32,7 +32,7 @@ $l['connected-b'] = "Rohr im Haus";
$l['created-t'] = "Erstellt";
$l['planned-t'] = "Faserplan vorhanden";
$l['assigned-t'] = "Bauauftrag zugeteilt";
$l['passed-t'] = "Fasern im Gebäude";
$l['passed-t'] = "Fasern im Gebaeude";
$l['connected-t'] = "Passiv erschlossen";
$l['active-t'] = "Internetprodukt aktiv";
@@ -56,4 +56,87 @@ $l['contract.downgrade'] = "Downgrade";
$l['contract.relocation'] = "Umzug";
$l['contract.productchange'] = "Produktwechsel";
$l['cc.oesterreich'] = "AT";
$l['cc.oestereich'] = "AT";
$l['cc.osterreich'] = "AT";
$l['cc.oesterreich'] = "AT";
$l['cc.austria'] = "AT";
$l['cc.at'] = "AT";
$l["cc.bulgarien"] = "BG";
$l["cc.bulgaria"] = "BG";
$l["cc.schweiz"] = "CH";
$l["cc.switzerland"] = "CH";
$l["cc.zypern"] = "CY";
$l["cc.cyprus"] = "CY";
$l["cc.tschechien"] = "CZ";
$l["cc.czechia"] = "CZ";
$l["cc.tschechische republik"] = "CZ";
$l["cc.czech republic"] = "CZ";
$l["cc.Česká republika"] = "CZ";
$l["cc.deutschland"] = "DE";
$l["cc.germany"] = "DE";
$l["cc.frankreich"] = "FR";
$l["cc.france"] = "FR";
$l["cc.francaise"] = "FR";
$l["cc.République française"] = "FR";
$l["cc.Republique francaise"] = "FR";
$l["cc.großbritannien"] = "GB";
$l["cc.grossbritannien"] = "GB";
$l["cc.britain"] = "GB";
$l["cc.great britain"] = "GB";
$l["cc.uk"] = "GB";
$l["cc.united kingdom"] = "GB";
$l["cc.United Kingdom of Great Britain and Northern Ireland"] = "GB";
$l["cc.Vereinigtes Koenigreich"] = "GB";
$l["cc.Vereinigtes Koenigreich Großbritannien und Nordirland"] = "GB";
$l["cc.Vereinigtes Koenigreich Grossbritannien und Nordirland"] = "GB";
$l["cc.ungarn"] = "HU";
$l["cc.hungary"] = "HU";
$l["cc.irland"] = "IE";
$l["cc.ireland"] = "IE";
$l["cc.republic of ireland"] = "IE";
$l["cc.italien"] = "IT";
$l["cc.italia"] = "IT";
$l["cc.japan"] = "JP";
$l["cc.jpn"] = "JP";
$l["cc.nippon"] = "JP";
$l["cc.nihon"] = "JP";
$l["cc.日本"] = "JP";
$l["cc.日本国"] = "JP";
$l["cc.luxemburg"] = "LU";
$l["cc.großherzogtum luxemburg"] = "LU";
$l["cc.grossherzogtum luxemburg"] = "LU";
$l["cc.luxembourg"] = "LU";
$l["cc.grand duchy of luxembourg"] = "LU";
$l["cc.groussherzogtum lëtzebuerg"] = "LU";
$l["cc.groussherzogtum letzebuerg"] = "LU";
$l["cc.niederlande"] = "NL";
$l["cc.netherlands"] = "NL";
$l["cc.nederland"] = "NL";
$l["cc.holland"] = "NL";
$l["cc.polen"] = "PL";
$l["cc.poland"] = "PL";
$l["cc.polska"] = "PL";
$l["cc.rumaenien"] = "RO";
$l["cc.rumaenien"] = "RO";
$l["cc.romania"] = "RO";
$l["cc.slowenien"] = "SL";
$l["cc.slovenia"] = "SL";
$l["cc.slowakei"] = "SK";
$l["cc.slovakia"] = "SK";
$l["cc.slowakische republik"] = "SK";
$l["cc.Slovak Republic"] = "SK";
$l["cc.Vereinigte Staaten"] = "US";
$l["cc.Vereinigte Staaten von Amerika"] = "US";
$l["cc.usa - vereinigte staaten"] = "US";
$l["cc.Amerika"] = "US";
$l["cc.US"] = "US";
$l["cc.USA"] = "US";
$l["cc.U.S.A."] = "US";
$l["cc.America"] = "US";
$l["cc.United States"] = "US";
$l["cc.United States of America"] = "US";
$l["cc.mm"] = "CW";
$lang['de'] = $l;

View File

@@ -261,7 +261,7 @@ function mfLayoutInclude($filename, $folder = "") {
global $mfLayoutPackage;
if($folder) {
$folder = $fodler."/";
$folder = $folder."/";
}
$inc_path = VIEWDIR . "/" . LAYOUT_DEFAULTPACKAGE . "/" . $folder . $filename;
@@ -279,8 +279,15 @@ if(!isset($lang)) {
$lang = [];
}
function __($string, $prefix = null) {
$last_translation_failed = false;
function __($_string, $prefix = null) {
global $lang;
global $last_translation_failed;
$last_translation_failed = false;
$string = str_replace(["Ä","Ö","Ü","ß","ä","ö","ü","ss"], ["ae","oe","ue"], strtolower($_string));
if(!$lang) {
//mfLoghandler::singleton()->debug("Loading language file for __() function");
@@ -294,6 +301,11 @@ function __($string, $prefix = null) {
if (array_key_exists($string, $lang['de'])) {
return $lang['de'][$string];
}
$last_translation_failed = true;
return $string;
}
function __last_translation_failed() {
global $last_translation_failed;
return $last_translation_failed;
}