*
* @param b Description of the Parameter
* @exception Exception Description of the Exception
*/
protected void doExport() {
WorkingDialog workDialog=null;
try{
workDialog = new WorkingDialog(null);
workDialog.setVisible(true);
workDialog.SetProgress(0);
BufferedWriter bufOut=new BufferedWriter(new OutputStreamWriter
(new FileOutputStream(fileDialog.getSelectedFile()), "UTF-8"));
bufOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
bufOut.newLine();
bufOut.write("<lazy8webport version=\"1.00\">");
bufOut.newLine();
Statement st = dc.con.createStatement();
String select = "";
int CompId=0;
String CompName=(String)(comboBox.getSelectedItem());
if(CompName.equals("--- " + Translator.getTranslation("All") + " ---")){
select="SELECT CompId,Name FROM Company";
}else{
CompId=((Integer) comboBox.getSelectedItemsKey()).intValue();
select="SELECT CompId,Name FROM Company WHERE CompId=" + CompId;
}
Log.log(Log.DEBUG, this, "doExport CompName =" + CompName);
ResultSet rsCompany = st.executeQuery(dc.filterSQL(select));
while(rsCompany.next()) {
CompId=rsCompany.getInt(1);
bufOut.write(" <company code=\"" + rsCompany.getInt(1) + "\" name=\"" + XmlEncode(rsCompany.getString(2)) +
"\" lastAbsTransNum=\"" + (new UniqNumGenerator()).GetUniqueNumber("Act_Id", 1, 999999999, CompId) + "\" >");
bufOut.newLine();
select="SELECT APP.Account.Account, AccDesc,AccTypeId, TypeName, SortOrder, IsInBalanceReport " +
" FROM AccountType JOIN Account ON AccountType.AccTypeId=APP.Account.IsAsset WHERE " +
" AccountType.CompId=" + CompId + " AND APP.Account.CompId=" + CompId +
" ORDER BY AccTypeId,APP.Account.Account";
Statement st2 = dc.con.createStatement();
ResultSet rsAccount = st2.executeQuery(dc.filterSQL(select));
int accountType=-99999;
while(rsAccount.next()) {
if (accountType!=rsAccount.getInt(3)){
if (accountType != -99999){
bufOut.write(" </accounttype>");
bufOut.newLine();
}
String isBalance="0";
if(rsAccount.getInt(6)==1)
isBalance="1";
bufOut.write(" <accounttype code=\"" + rsAccount.getInt(3) + "\" name=\"" + XmlEncode(rsAccount.getString(4)) +
"\" sortorder=\"" + rsAccount.getInt(5) + "\" isinbalance=\"" + isBalance + "\" >");
bufOut.newLine();
accountType=rsAccount.getInt(3);
}
bufOut.write(" <account code=\"" + rsAccount.getInt(1) + "\" name=\"" + XmlEncode(rsAccount.getString(2)) + "\" />");
bufOut.newLine();
bufOut.flush();
}
if(accountType!=-99999){
bufOut.write(" </accounttype>");
bufOut.newLine();
}
select="SELECT CustId, CustName, CustDesc, DefaultAcc FROM Customer2 WHERE CompId=" + CompId;
Statement st3 = dc.con.createStatement();
ResultSet rsCustomer = st3.executeQuery(dc.filterSQL(select));
while(rsCustomer.next()) {
bufOut.write(" <customer code=\"" + rsCustomer.getInt(1) + "\" name=\"" + XmlEncode(rsCustomer.getString(2)) +
"\" desc=\"" + XmlEncode(rsCustomer.getString(3)) + "\" accountcode=\"" + rsCustomer.getInt(4) + "\" />");
bufOut.newLine();
}
bufOut.flush();
select="SELECT StartPeriod, EndPeriod FROM AccountingPeriods WHERE CompId=" + CompId + " ORDER BY StartPeriod";
Statement st4 = dc.con.createStatement();
ResultSet rsPeriod = st4.executeQuery(dc.filterSQL(select));
while(rsPeriod.next()) {
select="SELECT MAX(PeriodId) FROM " +
" Activity2 JOIN APP.Amount on Activity2.Act_id=APP.Amount.Act_id WHERE Activity2.CompId=" + CompId +
" AND APP.Amount.CompId=" + CompId + " AND InvDate>=DATE '" + rsPeriod.getDate(1) +
"' AND InvDate<=DATE '" + rsPeriod.getDate(2) + "'";
Statement st5 = dc.con.createStatement();
ResultSet rsPeriodMaxPerId = st5.executeQuery(dc.filterSQL(select));
rsPeriodMaxPerId.next();
bufOut.write(" <period datestart=\"" + rsPeriod.getDate(1) + "\" dateend=\"" + rsPeriod.getDate(2) +
"\" lastperiodtransnum=\"" + rsPeriodMaxPerId.getInt(1) + "\">");
bufOut.newLine();
select="SELECT Activity2.Act_id, RegDate, InvDate, Activity2.Notes, FileInfo," +
" Account, APP.Amount.Amount, IsDebit, Customer, APP.Amount.Notes, PeriodId FROM " +
" Activity2 JOIN APP.Amount on Activity2.Act_id=APP.Amount.Act_id WHERE Activity2.CompId=" + CompId +
" AND APP.Amount.CompId=" + CompId + " AND InvDate>=DATE '" + rsPeriod.getDate(1) +
"' AND InvDate<=DATE '" + rsPeriod.getDate(2) + "' ORDER BY Activity2.Act_id,IsDebit";
Statement st6 = dc.con.createStatement();
ResultSet rsTrans = st6.executeQuery(dc.filterSQL(select));
int actId=-99999;
while(rsTrans.next()) {
if (actId!=rsTrans.getInt(1)){
if (actId != -99999){
bufOut.write(" </transaction>");
bufOut.newLine();
}
bufOut.write(" <transaction code=\"" + rsTrans.getInt(1) + "\" regdate=\"" + rsTrans.getDate(2) +
"\" invdate=\"" + rsTrans.getDate(3) + "\" notes=\"" + XmlEncode(rsTrans.getString(4)) +
"\" fileinfo=\"" + XmlEncode(rsTrans.getString(5)) + "\" periodnum=\"" + rsTrans.getInt(11) + "\" >");
bufOut.newLine();
actId=rsTrans.getInt(1);
}
double amount=rsTrans.getDouble(7);
if(rsTrans.getInt(8)==0)
amount= -amount;
bufOut.write(" <amount accountcode=\"" + rsTrans.getInt(6) + "\" customercode=\"" + rsTrans.getInt(9) +
"\" notes=\"" + XmlEncode(rsTrans.getString(10)) + "\" amount=\"" + amount + "\" />");
bufOut.newLine();
bufOut.flush();
}
if(actId!=-99999){
bufOut.write(" </transaction>");
bufOut.newLine();
}
bufOut.write(" </period>");
bufOut.newLine();
}
bufOut.flush();
bufOut.write(" </company>");
bufOut.newLine();
}
bufOut.write("</lazy8webport>");
bufOut.newLine();
bufOut.flush();
bufOut.close();
workDialog.dispose();
}catch(Exception e){
workDialog.dispose();
Log.log(Log.DEBUG, this, "Failed to export" + e);
e.printStackTrace();
JOptionPane.showMessageDialog(null,
Translator.getTranslation("Failed to export") + " : " + e,
"",