import com.groupstp.rtneo.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.service.*;
import com.groupstp.rtneo.core.bean.*
import java.text.SimpleDateFormat
def service = AppBeans.get(CalculationWorker.NAME)
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy")
//def contragent = dataManager.load(Contragent.class).id(UUID.fromString('29c5140d-6f1a-7f98-1342-b910d1d2c396')).view("_local").one();
//Contract baseContract = dataManager.load(Contract.class)
// .query('select c from rtneo$Contract c where c.mainContract is null and c.contragent.id=:contragent order by c.createTs desc')
// .parameter("contragent", contragent.getId())
// .view("contract-edit")
// .optional()
// .orElse(null);
def baseContract = dataManager.load(Contract.class).id(UUID.fromString('ba56a182-ccc6-6da3-ede5-de96a421f3c1')).view("contract-browse").one();
def contragent = dataManager.load(Contragent.class).id(baseContract.getContragent().getId()).view("_local").one();
Date fromDate = format.parse("01.01.2020")
Date beforeDate = format.parse("29.02.2020")
log.debug("baseContract")
log.debug(baseContract.getNumber())
Date currentDate = new Date()
def listAccrual = service.calculateAccruals(fromDate, beforeDate, contragent, currentDate, baseContract, false);
for(def accrual : listAccrual){
log.debug(accrual)
}
public Contract getLastContract(Contragent contragent, Contract baseContract){
return dataManager.load(Contract.class)
.query('select c from rtneo$Contract c where c.mainContract.id = :id and c.accepted = true and ( c.isFactRecalculation is null or not c.isFactRecalculation = true ) order by c.number desc')
.parameter("id", baseContract.getId())
.view("contract-edit")
.firstResult(0)
.maxResults(1)
.optional().orElse(null);
}