import com.haulmont.cuba.core.entity.Entity
import com.haulmont.cuba.core.global.*
import com.groupstp.rtneo.entity.*
import com.groupstp.rtneo.service.*
import com.groupstp.rtneo.core.bean.*
import com.haulmont.cuba.core.*
import java.util.stream.Collectors
import com.haulmont.cuba.core.global.ViewRepository;
import com.haulmont.cuba.core.global.View;
import java.util.function.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.stream.Collectors
BillService service = AppBeans.get(BillService.NAME)
ViewRepository vRep = AppBeans.get(ViewRepository.NAME)
DataManager dataManager = AppBeans.get(DataManager.NAME)
View viewAccrual = vRep.getView(Accrual.class, "_local")
.addProperty("category", vRep.getView(RealEstateCategory.class, "_local")
.addProperty("unit", vRep.getView(Unit.class, "_local"))
)
.addProperty("realEstate", vRep.getView(RealEstate.class, "_local")
)
.addProperty("bill", vRep.getView(Bill.class, "_local")
)
CommitContext commitContext = new CommitContext()
Contragent contragent = dataManager.load(Contragent.class).id(UUID.fromString('8a57cc2c-0e2f-ecce-f5a3-a2180515f7d9')).one()
List<Contract> contracts = dataManager.load(Contract.class)
.query('select c from rtneo$Contract c where c.contragent.id = :contragent_id and c.accepted = true order by c.createTs')
.parameter("contragent_id", contragent.getId())
.view('_local')
.list()
for(Contract contract : contracts){
List<Accrual> accruals = dataManager.load(Accrual.class)
.query('select a from rtneo$Accrual a where a.contractPosition.contract.id = :contract_id')
.parameter("contract_id", contract.getId())
.view(viewAccrual)
.list()
service.createBills(contragent, contract, accruals, commitContext)
}
dataManager.commit(commitContext)
service.redefinitionBills(contragent)
//service.createBills(Contragent contragent, Contract contract, List<Accrual> accruals, CommitContext commitContext)