Код:
import bitel.billing.server.util.*;
import ru.bitel.bgbilling.server.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.math.BigDecimal;
import bitel.billing.server.bill.bean.*;
import bitel.billing.server.contract.bean.*;
import bitel.billing.common.*;
import java.io.StringWriter;
import bitel.billing.server.bill.bean.BillManager;
public void main( setup, con, conSlave )
{
int mid = 65; //mid модуля Бухгалтерии
int accountId =1; // id счета банка
Calendar month = new GregorianCalendar();
int mm = month.get(Calendar.MONTH);
int yy = month.get(Calendar.YEAR);
month.set(Calendar.DAY_OF_MONTH,1);
BalanceUtils bu = new BalanceUtils( conSlave );
ModuleSetup moduleSetup = setup.getModuleSetup( mid );
TemplateBillManager man = new TemplateBillManager( moduleSetup, conSlave, mid, false );
List templateBillList = man.getTemplatePayBillList( moduleSetup, yy, mm, null, null, null, null );
print("doc for create = "+templateBillList.size());
//делаем
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element bills = doc.createElement("bills");
doc.appendChild(bills);
for( TemplateBill templateBill : templateBillList )
{
Element row = createElement( bills,"bill" );
BigDecimal subBillSumm = BigDecimal.ZERO;
row.setAttribute( "rest", Utils.formatBigDecimalSumm( bu.getBalance( month.getTime(), templateBill.getContractId() ) ) );
row.setAttribute( "account_id",String.valueOf(accountId ));
BigDecimal billSumm = fillBillData( row, templateBill );
if( templateBill.getSubBillList() != null )
{
for( TemplateBill templateSubBill : templateBill.getSubBillList() )
{
Element subBill = createElement( row, "sub_bill" );
subBillSumm = subBillSumm.add( fillBillData( subBill, templateSubBill ) );
}
}
row.setAttribute( "sub_bill_summ", Utils.formatBigDecimalSumm( subBillSumm ) );
row.setAttribute( "summ", Utils.formatBigDecimalSumm( billSumm.add( subBillSumm ) ) );
}
//посомтрим что получилось
ByteArrayOutputStream sos = new ByteArrayOutputStream();
CommonUtils.serializeXML(doc , sos, "windows-1251");
String xml = sos.toString();
//print(xml);
InputStream is = new ByteArrayInputStream( xml.getBytes( "cp1251" ) );
BillManager pbm = new BillManager( setup, con, mid, moduleSetup );
pbm.addBillDocs( -1, is, yy, mm, new Date() );
}
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 = value.getSumma();
Element posEl = createElement( row, "pos" );
value.toElement( posEl );
Position pos = value.getPosition();
posEl.setAttribute( "insum", Utils.booleanToStringInt( pos.isInSum() ) );
posEl.setAttribute( "awlz", Utils.booleanToStringInt( pos.isAddWhenLessZero() ) );
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;
}
счета
Код:
BillManager pbm = new BillManager( setup, con, mid, moduleSetup );
счетфактуры
Код:
InvoiceManager pbm = new InvoiceManager( setup, con, mid, moduleSetup );
и все

нада на вики запостить будет

_________________
Код:
Клиент: вер. 6.2.714 / 25.05.2015 17:27:15
os: Linux; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_45
Сервер: вер. 6.2.881 / 22.05.2015 17:56:55
os: Linux; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_45
Помощь по администрированию bgbilling в jabber конференции или Группа в telegramСтиль программирования - пьяный мастерстер
Разработка мобильных приложений