migration helper
This commit is contained in:
parent
5d19464acc
commit
ca0ec303e6
1 changed files with 227 additions and 0 deletions
|
|
@ -0,0 +1,227 @@
|
|||
package com.alexanderlogistics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.imixs.workflow.exceptions.PluginException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class MigrationMahnerAusziffern {
|
||||
|
||||
List<Rechnung> rechnungen = new ArrayList<Rechnung>();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws PluginException {
|
||||
List<Rechnung> rechnungen = new ArrayList<Rechnung>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Diese Test Method wandelt die Datei OPD_migration_230126.csv in eine EXTV
|
||||
* Datev Datei um, welche wir dann für einen einmaligen Import der
|
||||
* Rechnugnsdaten verwenden können.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void anlysiere() {
|
||||
|
||||
System.out.println("***********************");
|
||||
System.out.println("* OP Listen Auszifferliste *");
|
||||
System.out.println("***********************");
|
||||
|
||||
String filename_input = "datev/OPD_migration_230126.csv";
|
||||
|
||||
FileInputStream fis;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||
File inputFile = new File(classLoader.getResource(filename_input).getFile());
|
||||
Assert.assertTrue(inputFile.exists());
|
||||
fis = new FileInputStream(inputFile);
|
||||
DataInputStream in = new DataInputStream(fis);
|
||||
br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
|
||||
|
||||
// read the first line containing the field names
|
||||
String fieldnames = br.readLine();
|
||||
|
||||
Assert.assertTrue(fieldnames.contains("Kontonummer"));
|
||||
|
||||
|
||||
|
||||
String line;
|
||||
int count = 0;
|
||||
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
|
||||
String[] data = line.split(";(?=([^\"]*\"[^\"]*\")*[^\"]*$)", 999);
|
||||
|
||||
if (data.length != 90) {
|
||||
System.out.println("Fehlerhafte Daten in Zeile " + count);
|
||||
System.out.println(line);
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
analyzeLine(data,count);
|
||||
count++;
|
||||
|
||||
// if (count>25) {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
System.out.println("... fininshed - read " + count + " lines.");
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prüft eine einzelen Datenzeile
|
||||
*
|
||||
* @param writer
|
||||
* @param data
|
||||
* @throws IOException
|
||||
*/
|
||||
private void analyzeLine(String[] data, int line) throws IOException {
|
||||
|
||||
String rechnungsNummer = data[2];
|
||||
String rechnungsDatum=data[3];
|
||||
String faelligkeit=data[4];
|
||||
String saldo=data[7];
|
||||
String zahlung=data[6];
|
||||
// vertasuchen
|
||||
if (faelligkeit.length()==8) {
|
||||
faelligkeit=faelligkeit.substring(4,8)+faelligkeit.substring(2,4)+faelligkeit.substring(0,2);
|
||||
} else {
|
||||
faelligkeit="20230125";
|
||||
}
|
||||
String text=data[18];
|
||||
String basisumsatz = "0,00";
|
||||
String umsatz = data[5];
|
||||
if ("0,00".equals(umsatz)) {
|
||||
umsatz = data[6];
|
||||
}
|
||||
if ("0,00".equals(umsatz)) {
|
||||
System.out.println("ACHTUNG - Fehler in Spalte 5 bzw. 6 in zeile " + line);
|
||||
}
|
||||
String sh = data[8];
|
||||
|
||||
String wkz = data[9];
|
||||
if (isEmpty(wkz)) {
|
||||
wkz = "\"EUR\"";
|
||||
} else {
|
||||
umsatz = data[10];
|
||||
basisumsatz = data[5];
|
||||
if ("0,00".equals(basisumsatz)) {
|
||||
basisumsatz = data[6];
|
||||
}
|
||||
|
||||
}
|
||||
String kurs = data[11];
|
||||
|
||||
String gegenkonto = data[0];
|
||||
String konto = data[12];
|
||||
|
||||
boolean skip=false;
|
||||
|
||||
// umdrehen von sh
|
||||
if ("\"H\"".equals(sh)) {
|
||||
sh="\"S\"";
|
||||
} else {
|
||||
sh="\"H\"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// cache diese Information
|
||||
Rechnung rech=new Rechnung(gegenkonto,rechnungsNummer,umsatz,sh, wkz);
|
||||
|
||||
Rechnung matchingRech=findMatch(rech);
|
||||
if (matchingRech!=null) {
|
||||
System.out.println(" Bitte Ausziffern : "+rech.konto + " = " +rech.rechnungsNummer + " -> "+matchingRech.rechnungsNummer);
|
||||
}
|
||||
|
||||
rechnungen.add(rech);
|
||||
|
||||
}
|
||||
|
||||
private boolean isEmpty(String data) {
|
||||
return (data.isEmpty() || "\"\"".equals(data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hilfsmethdoe die prüft ob es zu diesr Rechnung shcon eine passende Gegenrechnung gibt.
|
||||
* @param rech
|
||||
* @return
|
||||
*/
|
||||
private Rechnung findMatch(Rechnung rech) {
|
||||
|
||||
// gehen über all rechnungen und vergleiche alle eigenschaften
|
||||
for (Rechnung matchRech: rechnungen) {
|
||||
|
||||
if (rech.rechnungsNummer.equals(matchRech.rechnungsNummer)) {
|
||||
System.out.println(" !! Rechnungsnummer Doppelt : " +rech.rechnungsNummer);
|
||||
}
|
||||
|
||||
if (rech.konto.equals(matchRech.konto )
|
||||
&& rech.umsatz.equals(matchRech.umsatz)
|
||||
&& rech.wkz.equals(matchRech.wkz)
|
||||
&& !rech.sh.equals(matchRech.sh)) {
|
||||
// Hurrar wir habne eine treffer
|
||||
return matchRech;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// nix gefunden
|
||||
return null;
|
||||
}
|
||||
|
||||
class Rechnung {
|
||||
String konto;
|
||||
String rechnungsNummer;
|
||||
String umsatz;
|
||||
String sh;
|
||||
String wkz;
|
||||
public Rechnung(String konto, String rechnungsNummer, String umsatz, String sh, String wkz) {
|
||||
super();
|
||||
this.konto = konto;
|
||||
this.rechnungsNummer = rechnungsNummer;
|
||||
this.umsatz = umsatz;
|
||||
this.sh = sh;
|
||||
this.wkz = wkz;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue