Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2658 invoice externalization in a specifc directory #3349

Closed
wants to merge 12 commits into from
882 changes: 442 additions & 440 deletions .classpath

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base/build.xml
Expand Up @@ -70,6 +70,7 @@
<src path="../org.adempiere.request/src/main/java"/>
<src path="../org.adempiere.project/src/main/java"/>
<src path="../org.adempiere.crm/src/main/java"/>
<src path="../com.klst.einvoice/src/main/java"/>
<src path="${src}"/>
<src path="${looksSrc}"/>
<src path="../glassfishfacet/src"/>
Expand Down
25 changes: 25 additions & 0 deletions base/src/org/compiere/model/MInvoice.java
Expand Up @@ -32,6 +32,8 @@
import java.util.function.BiFunction;
import java.util.logging.Level;

import org.adempiere.einvoice.AbstractEinvoice;
import org.adempiere.einvoice.InterfaceEinvoice;
import org.adempiere.engine.CostEngineFactory;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.BPartnerNoAddressException;
Expand Down Expand Up @@ -1245,6 +1247,29 @@ public String getDocStatusName()
return MRefList.getListName(getCtx(), 131, getDocStatus());
} // getDocStatusName

@Override
public byte[] externalize() {
String xmlSchema = MSysConfig.getValue(InterfaceEinvoice.XML_SCHEMA_NAME, "", getAD_Client_ID());
log.config("to "+InterfaceEinvoice.XML_SCHEMA_NAME+"='" + xmlSchema+"'" + " isSOTrx="+isSOTrx());
if(xmlSchema.isEmpty() || isSOTrx()==false) { // default
return super.externalize();
}

byte[] xmlData = null;
try
{
InterfaceEinvoice eInvoice = AbstractEinvoice.createEinvoice(xmlSchema);
if(eInvoice==null) {
return null;
}
xmlData = eInvoice.tranformToXML(this);
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
return xmlData;
}

/**************************************************************************
* Create PDF
Expand Down
12 changes: 12 additions & 0 deletions base/src/org/compiere/model/PO.java
Expand Up @@ -4121,6 +4121,18 @@ private boolean lobSave ()
return retValue;
} // saveLOB


/**
* externalize Object to a given xml representation (non adempiere)
*
* to be implemented in subclass / used for e-invoicing, @see https://github.com/adempiere/adempiere/issues/2658
*
* @return xmldata
*/
public byte[] externalize() {
return null;
}

/**
* Get Object xml representation as string
* @param xml optional string buffer
Expand Down
21 changes: 20 additions & 1 deletion base/src/org/spin/util/ExportFormatXML.java
Expand Up @@ -28,6 +28,8 @@

import javax.xml.transform.stream.StreamResult;

import org.compiere.model.I_C_Invoice;
import org.compiere.model.MInvoice;
import org.compiere.print.ReportEngine;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
Expand Down Expand Up @@ -84,6 +86,18 @@ public BufferedWriter convertFile(File file) {
return new BufferedWriter(fileWriter);
}

private byte[] externalize(int Table_ID) {
int table_ID = this.getPrintInfo().getAD_Table_ID();
if(Table_ID==table_ID) {
int record_ID = this.getPrintInfo().getRecord_ID();
String trxName = null;
MInvoice mInvoice = new MInvoice(this.getCtx(), record_ID, trxName);
return mInvoice.externalize();
}

return null;
}

/**
* Write XML to writer
* @param writer writer
Expand All @@ -94,7 +108,12 @@ public boolean createXML(Writer writer) {
return false;
}
try {
getPrintData().createXML(new StreamResult(writer));
byte[] xmldata = externalize(I_C_Invoice.Table_ID);
if(xmldata==null) {
getPrintData().createXML(new StreamResult(writer));
} else {
writer.append(new String(xmldata));
}
writer.flush();
writer.close();
return true;
Expand Down
69 changes: 69 additions & 0 deletions com.klst.einvoice/build.xml
@@ -0,0 +1,69 @@
<project name="E-invoice" default="dist" basedir=".">
<description>
Building E-Invoice.jar
copied from org.spin.store as template
</description>
<!-- set global properties for this build -->
<import file="../utils_dev/properties.xml"/>
<property name="src" location="src/main/java"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>

<path id="lib.class.path">
<fileset dir="../lib">
<include name="*.jar"/>
</fileset>
<fileset dir="../packages">
<include name="*.jar"/>
</fileset>
</path>
<path id="compile.classpath">
<pathelement location="${basedir}/build"/>
<fileset dir="../lib">
<include name="*.jar"/>
</fileset>
<fileset dir="../packages">
<include name="*.jar"/>
</fileset>
</path>

<target name="init" depends="clean">
<echo message="Trunk location: .."/>
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac encoding="UTF-8" srcdir="${src}" sourcepath="${base}" destdir="${build}">
<classpath refid="lib.class.path"/>
</javac>

</target>

<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/E-Invoice.jar" basedir="${build}"/>

<mkdir dir="${env.ADEMPIERE_HOME}/packages/E-Invoice/lib"/>

<copy file="${dist}/lib/E-Invoice.jar" todir="${env.ADEMPIERE_HOME}/packages/E-Invoice/lib"/>
<copy file="${dist}/lib/E-Invoice.jar" todir="../packages/"/>

</target>


<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>