/*
* IODocTabSep.java
*
* Created on 31 de Julho de 2007, 0:49
*/
package com.m16e.mpbiz.b2b;
import com.m16e.mpbiz.common.bizclasses.MpBizException;
import com.m16e.mpbiz.common.MpBizFactory;
import com.m16e.mpbiz.docs.MpBizDoc;
import com.m16e.mpbiz.docs.MpBizDocLin;
import com.m16e.mpbiz.docs.MpDocFactory;
import com.m16e.mpbiz.prods.MpBizProd;
import com.m16e.mpbiz.tables.DbDoc;
import com.m16e.mpbiz.tables.DbDocLin;
import com.m16e.mpbiz.tables.DbEnt;
import com.m16e.tools.Tools;
import com.m16e.tools.db.DatabaseException;
import com.m16e.tools.files.MpFileUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
////////////////////////////////////////////////////////////
/**
*
* @author carlos@m16e.com
*/
public class IODocAdonix
implements IODoc
{
static SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMdd" );
////////////////////////////////////////////////////////////
/** Creates a new instance of IODocTabSep */
public IODocAdonix()
{
}
////////////////////////////////////////////////////////////
public String exportDoc( MpBizDoc bizDoc )
throws SQLException, MpBizException, FileNotFoundException, IOException, DatabaseException
{
DbEnt ent = new DbEnt();
ent.setEntId( bizDoc.getEntId() );
if( !ent.getById() )
throw new MpBizException( "NO SUCH ENT: " + bizDoc.getEntId() + "in ( " + bizDoc.toString() + ")" );
StringBuffer sb = new StringBuffer();
sb.append( "C;" + bizDoc.getDocId() + ";" );
sb.append( dateFormat.format( bizDoc.getDataDoc().getDate() ) + ";" );
sb.append( ent.getNif() + ";" );
DbDoc doc = bizDoc.getDoc();
DbDoc req =
MpBizDoc.getDocByWebOrderId(
bizDoc.getTipoEntId(), MpDocFactory.TDOC_REQUEST,
doc.getWebOrderId() );
if( req != null )
sb.append( req.getExtCcusto() );
sb.append( ";" );
sb.append( Tools.roundDouble( bizDoc.getDoc().getTotalSemTaxas(), 2 ) + ";" );
sb.append(
Tools.roundDouble(
bizDoc.getDoc().getTotalComTaxas() - bizDoc.getDoc().getTotalSemTaxas(),
2 ) +
";" );
sb.append( ";;;;\r\n" );
for( MpBizDocLin mdl : bizDoc.getDocLines() )
{
DbDocLin dl = mdl.getDocLin();
if( dl.getOrgDocLinId() == 0 )
continue;
sb.append( "L;" );
DbDocLin orgDocLin =
MpBizDoc.getOrgDocLin( dl, MpDocFactory.TDOC_REQUEST );
DbDoc orgDoc = null;
if( orgDocLin != null )
{
orgDoc =
MpBizDoc.getDocByDocId(
orgDocLin.getTipoEntId(), orgDocLin.getTipoDocId(), orgDocLin.getDocId() );
}
String aux = null;
if( orgDoc != null )
aux = orgDoc.getExtCcusto();
if( aux != null )
sb.append( aux );
sb.append( ";" );
if( orgDoc != null )
aux = orgDoc.getWebOrderId();
if( aux != null )
sb.append( aux );
sb.append( ";" );
sb.append( dl.getOrgDocId() + ";" );
MpBizProd prod = MpBizProd.getByProdId( dl.getItemId() );
sb.append( prod.getUseAlfaCode() + ';' );
sb.append( dl.getDescricao() + ";" );
sb.append( dl.getQuant() + ";" );
sb.append( MpBizFactory.getUniMovMnemonicaByProdId( dl.getItemId() ) + ";" );
sb.append( dl.getPrecoUni() + ";" );
sb.append( dl.getTotalSemTaxa() + ";" );
sb.append( ";;;;\r\n" );
}
String filename = "fat" + bizDoc.getDocId() + ".csv";
return MpFileUtils.writeFileToDesktop( filename, sb.toString(), "ISO-8859-15" );
}
////////////////////////////////////////////////////////////
public void importDoc( String externalDoc )
{
}
}
|