|
|||||||
Выгрузка для УПД2
Время создания: 06.07.2020 12:22
Раздел: INFO - JOB - rtneo - Выгрузки - УПД
Запись: wwwlir/Tetra/master/base/1594009357qwepfc5ti6/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.groupstp.rtneo.entity.* import com.haulmont.cuba.core.global.*; import java.text.SimpleDateFormat import org.apache.commons.collections.CollectionUtils DataManager dataManager = AppBeans.get(DataManager.NAME) //BillService billService = AppBeans.get(BillService.NAME) def period1 = '2019-01-01' def period2 = '2019-12-01' def df1 = new SimpleDateFormat("yyyy-MM-dd") period = df1.parse(period1) Calendar periodStart = Calendar.getInstance(); Calendar periodEnd = Calendar.getInstance(); periodStart.setTime(df1.parse(period1)); periodEnd.setTime(df1.parse(period2)); def accrualsGroup = new TreeMap<>(); def contragentsGroup = new TreeMap<>(); def contragentsPayment = dataManager.loadValues('select distinct(e.inn), c.id, sum(e.sum) from rtneo$Payment e join rtneo$Contragent c where e.inn = c.inn group by e.inn, c.id') .properties("inn", "contragentId", "sum") .list(); for(def contragentPayment : contragentsPayment){ while(!periodStart.after(periodEnd)){
List<Accrual> accruals = getBillsOnPeriod(UUID.fromString(contragentPayment.getValue("contragentId").toString()), periodStart.getTime())
for(def accrual : accruals){ tariffNoNDS = accrual.getPrice()*5/6; if(accrualsGroup[accrual.getPeriod()]==null){ accrualsGroup[accrual.getPeriod()] = [ 'period' : accrual.getPeriod(), 'tariff' : tariffNoNDS, 'amountBase' : accrual.getAmountBase(), 'totalSumBaseNoNds' : accrual.getAmountBase()*tariffNoNDS, 'totalSumBase' : accrual.getTotalSumBase(), 'totalSum' : accrual.getTotalSum() ] }else{ accrualsGroup[accrual.getPeriod()]['amountBase'] += accrual.getAmountBase() accrualsGroup[accrual.getPeriod()]['totalSumBaseNoNds'] += accrual.getAmountBase()*tariffNoNDS accrualsGroup[accrual.getPeriod()]['totalSumBase'] += accrual.getTotalSumBase() accrualsGroup[accrual.getPeriod()]['totalSum'] += accrual.getTotalSum() } periodStart.add(Calendar.MONTH, 1) log.debug(periodStart) } } if(contragentsGroup[contragentPayment.getValue("inn")] == null){ contragentsGroup[contragentPayment.getValue("inn")] =[ 'inn' : contragentPayment.getValue("inn"), 'payments' : contragentPayment.getValue("sum"), 'accrual' : accrualsGroup ] }
} return contragentsGroup //========================================================================= public List<Accrual> getBillsOnPeriod(UUID contragentID, Date period) { List<Contract> contracts = dataManager.load(Contract.class) .query('select e from rtneo$Contract e where e.contragent.id = :contragent and e.accepted=true order by e.createTs desc') .parameter("contragent", contragentID) .view("_local") .list(); if (contracts.size() == 0) { contracts = dataManager.load(Contract.class) .query('select e from rtneo$Contract e where e.contragent.id = :contragent order by e.createTs') .parameter("contragent", contragentID) .view("_local") .list(); } if (contracts.size() > 0) { int i = 0; Contract contract = contracts.get(i); if (contract.getFrom() == null) return null; while (contract.getFrom() != null & period.before(contract.getFrom())) { i = i + 1; if (i == contracts.size()) break; contract = contracts.get(i); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (contract.getFrom() != null) { List<Accrual> accruals = dataManager.load(Accrual.class) .query('select e from rtneo$Accrual e where e.contractPosition.contract.id=:contractId and e.period=:period') .parameter("contractId", contract.getId()) .parameter("period", period) .view("_local") .list(); return accruals; } } return null; } |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|