Создание счета по таблице позиций
Материал из BiTel WiKi
Работает в 5.0
Глобальный скрипт поведения, создающий счета из таблицы _tmp_bill_diff (cid, pos_id, diff).
import bitel.billing.server.util.*; import java.sql.*; import java.util.*; import java.math.*; import bitel.billing.server.contract.bean.*; import bitel.billing.server.bill.bean.*; import bitel.billing.server.util.*; import ru.bitel.bgbilling.server.util.*; public void main( setup, con, conSlave ) { bill_type = 1; bill_type_title = "обычный"; bill_mid = 6; mm=0; //январь yy=2010; acc_id=1; bill_manager = new BillManager(setup,con,bill_mid, setup.getSetup().getModuleSetup(bill_mid)); cm = new ContractManager( con ); ps = con.prepareStatement("select cid from _tmp_bill_diff group by cid;"); rs = ps.executeQuery(); while(rs.next()) { cid = rs.getInt(1); c = cm.getContractByID( cid ); float sum = 0; bill_doc = new Bill(); bill_doc.setCid(cid); bill_doc.setContractTitle(c.getTitle()); bill_doc.setCreateDate(new Date()); bill_doc.setMm(mm); bill_doc.setTypeId(bill_type); bill_doc.setTypeTitle(bill_type_title); bill_doc.setUid(0); bill_doc.setYy(yy); bill_doc.setAccountId(acc_id); position_value_list = new java.util.ArrayList(); //позиции основного договора ps1 = con.prepareStatement("select pos_id, sum(dif) from _tmp_bill_diff where cid=? group by pos_id;"); ps1.setInt(1,cid); rs1 = ps1.executeQuery(); while(rs1.next()) { pos_id = rs1.getInt(1); dif = rs1.getFloat(2); sum+=dif; posname=setup.getSetup().getModuleSetup(6).getStringValue("bill.pos."+pos_id+".name",""); postitle=setup.getSetup().getModuleSetup(6).getStringValue("bill.pos."+pos_id+".title",""); position = new Position(); position.setId(pos_id); position.setName(posname); position.setSumm(""+dif); position.setTitle(postitle); position_value = new PositionValue(); position_value.setCid(cid); position_value.setName(posname); position_value.setPosition(position); position_value.setPositionId(pos_id); position_value.setSumma(new BigDecimal(dif)); position_value_list.add(position_value); } ps1.close(); print(new BigDecimal(sum)); bill_doc.setSumm(new BigDecimal(sum)); bill_manager.addBillDoc(bill_doc,position_value_list,Collections.emptyList()); } ps.close(); }