Создание счета и счет-фактур в модуле Bill(выполнение тех же действий что и руками)

Материал из BiTel WiKi

(Различия между версиями)
Перейти к: навигация, поиск
Строка 1: Строка 1:
 +
Создает счета или счет-фактуры в зависимости от выставленных параметров:
 +
 +
счета
 +
<source lang="java">
 +
BillManager pbm = new BillManager( setup, con, mid, moduleSetup );
 +
</source>
 +
 +
счет-фактуры
 +
<source lang="java">
 +
InvoiceManager pbm = new InvoiceManager( setup, con, mid, moduleSetup );
 +
</source>
 +
 +
выполняет те же действия что и если их выставлять руками в соответствии с настройками модуля.
 +
 +
<source lang="java">
<source lang="java">
import bitel.billing.server.util.*;
import bitel.billing.server.util.*;

Версия 00:03, 19 января 2011

Создает счета или счет-фактуры в зависимости от выставленных параметров:

счета

BillManager pbm = new BillManager( setup, con, mid, moduleSetup );

счет-фактуры

InvoiceManager pbm = new InvoiceManager( setup, con, mid, moduleSetup );

выполняет те же действия что и если их выставлять руками в соответствии с настройками модуля.


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;
}
Личные инструменты