stark писал(а):
Вы используете TemplateBillManager ?
угу... по примеру из вики... xmlку видно что пустую генерирует
Код:
//для теста сумм=1000
public String summ="1000";
public void formBill( Connection con ,String cid,String mmS,String yyS)
{
try{
int mid = 6; //mid модуля Бухгалтерии
int accountId =1; // id счета банка
int mmI=Integer.parseInt(mmS)-1;
int yyI=Integer.parseInt(yyS);
Calendar month = new GregorianCalendar();
month.set(Calendar.DAY_OF_MONTH,1);
month.set(Calendar.MONTH, mmI);
month.set(Calendar.YEAR, yyI);
int mm = month.get(Calendar.MONTH);
int yy = month.get(Calendar.YEAR);
BalanceUtils bu = new BalanceUtils( con );
ModuleSetup moduleSetup = setup.getModuleSetup( mid );
TemplateBillManager man = new TemplateBillManager( moduleSetup, con, mid, false );
List<TemplateBill> templateBillList = man.getTemplatePayBillList( moduleSetup, yy, mm, null, cid, null, null );
//делаем
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
Document doc;
docBuilder = dFactory.newDocumentBuilder();
doc = docBuilder.newDocument();
Element bills = doc.createElement("bills");
for( TemplateBill templateBill : templateBillList )
{
Element row = createElement( bills,"bill" );
//row.setAttribute( "rest", Utils.formatBigDecimalSumm( bu.getBalance( month.getTime(), templateBill.getContractId() ) ) );
row.setAttribute( "saldo", bu.getBalance( new Date(), Integer.parseInt(cid)).toString() );
row.setAttribute( "account_id",String.valueOf(accountId ));
BigDecimal billSumm = fillBillData( row, templateBill );
row.setAttribute( "summ", Utils.formatBigDecimalSumm( billSumm ) );
}
//посомтрим что получилось
doc.appendChild(bills);
ByteArrayOutputStream sos = new ByteArrayOutputStream();
//CommonUtils.serializeXML(doc , sos, "UTF-8");
Node n = doc.getFirstChild();
XMLUtils.serialize(n, sos, "UTF-8");
String xml = sos.toString();
//проверим какая хмлка получилась
print(xml);
InputStream is = new ByteArrayInputStream( xml.getBytes( "windows-1251" ) );
BillManager pbm = new BillManager( setup, con, mid, moduleSetup );
pbm.addBillDocs( -1, is, yy, mm, new Date() );
}
catch (Exception e) {}
}
private BigDecimal fillBillData( Element row, TemplateBill templateBill )
{
BigDecimal billSumm = BigDecimal.ZERO;
row.setAttribute( "id", String.valueOf( templateBill.getContractDocTypeId() ) );
row.setAttribute( "type", String.valueOf( templateBill.getDocTypeId() ) );
row.setAttribute( "cid", String.valueOf( templateBill.getContractId() ) );
row.setAttribute( "contract", templateBill.getContractTitle() );
row.setAttribute( "contract_comment", templateBill.getContractComment() );
for( PositionValue value : templateBill.getPositionList() )
{
BigDecimal summ = new BigDecimal (this.summ);
Element posEl = createElement( row, "pos" );BillManager
value.toElement( posEl );
Position pos = value.getPosition();
posEl.setAttribute( "insum", Utils.booleanToStringInt( pos.isInSum() ) );
posEl.setAttribute( "awlz", Utils.booleanToStringInt( pos.isAddWhenLessZero() ) );
posEl.setAttribute( "summ" , this.summ);
if( pos.isInSum() )
{
billSumm = billSumm.add( summ );
}
}
row.setAttribute( "summ", Utils.formatBigDecimalSumm( billSumm ) );
return billSumm;
}
protected Element createElement( Element element, String name )
{
Element newElement = null;
if( element == null )
{
newElement = null;
}
else
{
newElement = element.getOwnerDocument().createElement( name );
element.appendChild( newElement );
}
return newElement;
}