MyTetra Share
Делитесь знаниями!
Печать начисления замер производительности
Время создания: 08.10.2020 03:33
Раздел: INFO - JOB - rtneo - Работа над задачами
Запись: wwwlir/Tetra/master/base/1602099236o7uqdjt7gv/text.html на raw.githubusercontent.com

import com.haulmont.chile.core.model.MetaClass

import com.haulmont.cuba.core.global.*;

import com.groupstp.rtneo.entity.*;

import com.groupstp.rtneo.service.AccrualService

import com.groupstp.rtneo.service.CompanyService

import java.math.RoundingMode;

import java.text.DecimalFormat;

import java.text.DecimalFormatSymbols;

import com.haulmont.cuba.core.global.ViewRepository;

import com.haulmont.cuba.core.global.View;


def service = AppBeans.get(AccrualService.NAME)

def companyService = AppBeans.get(CompanyService.NAME)


ViewRepository vRep1 = AppBeans.get(ViewRepository.NAME)


View viewAccrual = vRep1.getView(Accrual.class, "_local")

.addProperty("contragent", vRep1.getView(Contragent.class, "_local")


)

.addProperty("contractPosition", vRep1.getView(ContractPosition.class, "_local")

.addProperty("contract", vRep1.getView(Contract.class, "_local")

.addProperty("mainContract", vRep1.getView(Contract.class, "_local")

.addProperty("company", vRep1.getView(Company.class, "_local")

)

)

)

)

// .addProperty("category", vRep1.getView(RealEstateCategory.class, "_local")

// .addProperty("unit", vRep1.getView(Unit.class, "_local"))

// )

// .addProperty("realEstate", vRep1.getView(RealEstate.class, "_local")

//

// )


def params =['number':2121383]


long st = System.currentTimeMillis();

List<Accrual> accruals = dataManager.load(Accrual)

.query('select a from rtneo$Accrual a where a.documentNumber = :documentNumber order by a.period asc')

.parameter("documentNumber", params.number)

.view('accrual-bill')

// .view(viewAccrual)

.list()

long end = System.currentTimeMillis();

log.debug(end-st);


if (accruals.size() == 0) {

throw new RuntimeException(String.format("Начислений по номеру %s не найдено", params.number))

}


Accrual accrual = accruals.get(0)

Contragent contragent = accrual.getContragent()

def result = new LinkedHashMap()


def head = new LinkedHashMap()


//Acts act = getActualAct(contragent.getInn(), contragent.getKpp(), accrual.getPeriod())

//

//if(act == null){

// head['number'] = String.valueOf((int) params.number)

//}else{

// head['number'] = act.getNumber()

//}

head['number'] = String.valueOf((int) params.number)

//a.kotvinskiy /--

//head['billDate'] = getTextDate(accrual.getDocumentDate() == null ? accrual.getCreateTs() : accrual.getDocumentDate())

def monthesRP = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']

//Берем период счета

Date billDate = accrual.getPeriod();

if (billDate==null){

billDate = accrual.getCreateTs()

}

Calendar cal = Calendar.getInstance()

cal.setTime(billDate);

//Устанавливаем дату на последний день предыдущего месяца

//cal.add(Calendar.MONTH, -1);

//Текущего месяца

cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));

head['billDate'] = cal.get(Calendar.DAY_OF_MONTH).toString()

head['billDate']+=" "+monthesRP[cal.get(Calendar.MONTH)]

head['billDate']+=" "+cal.get(Calendar.YEAR).toString()+" г."

//a.kotvinskiy --/



head['name'] = contragent.getName();

head['shortName'] = contragent.getShortName();

if (head['shortName']==null){

head['shortName'] = head['name'];

}

head['inn'] = contragent.getInn();

head['kpp'] = contragent.getKpp();

head['legalAddress'] = contragent.getLegalAddress();


def contract = accrual.contractPosition.contract

if (contract.mainContract != null)

contract = contract.mainContract

def company = contract.company

//a.kotvinskiy /--

//def companyRequisites = companyService.getCompanyRequisites(company, contract.date)

def companyRequisites = companyService.getCompanyRequisites(company, billDate)

//a.kotvinskiy --/


head << ['contractNumber' : contract.number

,'contractDate' : contract.date

,'companyShortName' : company.shortName

,'companyInn':company.inn

,'companyKpp':companyRequisites.kpp

,'companyLegalAddress':companyRequisites.legalAddress

,'companyPhone':company.phone

,'companyBankName':companyRequisites.bankName

,'companyRcbic':companyRequisites.rcbic

,'companyCorrespondentAccount':companyRequisites.correspondentAccount

,'companyBankAccount':companyRequisites.bankAccount

]

result['head'] = head;


result['footer'] = [

'billDate' : head['billDate']

,'contractNumber' : contract.number

,'contractDate' : contract.date

,'shortName' : head['shortName']

,'inn' : contragent.inn

,'kpp' : contragent.kpp

,'companyShortName' : company.shortName

,'companyInn':company.inn

,'companyKpp':companyRequisites.kpp

,'companyManager' : getShortFio(companyRequisites.getManagerName())

,'companyManagerTitle':companyRequisites.managerTitle

,'companyAccountManager' : getShortFio(companyRequisites.managerName)

,'companyManagerDocumentR' : companyRequisites.getManagerDocumentR()]


def items = new LinkedHashMap()

def itemsInRent = new LinkedHashMap()


//

ViewRepository vRep = AppBeans.get(ViewRepository.NAME)

View accrualView = vRep.getView(Accrual.class, "accrual-bill");

accrualView.addProperty("contractPosition", vRep.getView(ContractPosition.class, "_minimal").addProperty("contragentRealEstate", vRep.getView(ContragentRealEstate.class, "_minimal")));

//

for (Accrual a: accruals){

//a.kotvinskiy /--

Boolean isRent = false;


a = dataManager.reload(a, accrualView);


ContractPosition cp = a.getContractPosition();

if(cp.getContragentRealEstate() != null){



// if(cp.getContragentRealEstate().getContragent()==contragent) isRent = true;




// List<RealEstateRenter> rerList = dataManager.load(RealEstateRenter)

// .query('select r from rtneo$RealEstateRenter r where r.renterRecord.id = :renterRecord and r.payOwner = true')

// .parameter("renterRecord", cp.getContragentRealEstate().getId())

// .view('realEstateRenter-edit')

// .list();


Integer countIsRent = dataManager.loadValue('select count(a) from rtneo$Accrual a where a.id = :accrualId and not a.contractPosition.contragent.id = a.contractPosition.contragentRealEstate.contragent.id', Integer.class)

.parameter("accrualId", a.getId())

.optional().orElse(0)

if(countIsRent > 0) isRent = true;

}


if(isRent){

fillItems(itemsInRent, a)

}else{

fillItems(items, a)

}

//a.kotvinskiy --/

}


def itemsArr = []

BigDecimal totalSum = 0

BigDecimal totalSumWoNds = 0

BigDecimal ndsSum = 0

if(items.size()==0){

itemsArr.add(['n':1,

'positionName':'Услуга Регионального оператора по обращению с ТКО за',

'month': getTextPeriod(accruals[0].getPeriod()),

'amount':getRussianNumber(BigDecimal.ZERO.setScale(5, RoundingMode.HALF_UP),5),

'price':getRussianNumber(accruals[0].getPrice()),

'priceWoNDS': getRussianNumber(BigDecimal.ZERO),

'sum': getRussianNumber(BigDecimal.ZERO),

'reductionFactor':getRussianNumber(0),

'totalSum':getRussianNumber(BigDecimal.ZERO),

'totalSumWoNds':getRussianNumber(BigDecimal.ZERO),

'ndsSum':getRussianNumber(BigDecimal.ZERO)]);

}

items.eachWithIndex { entry, i ->

def sum = entry.value.price * entry.value.amount;

itemsArr.add(['n':i+1,

'positionName':'Услуга Регионального оператора по обращению с ТКО за',

'month':entry.value.month,

'amount':getRussianNumber(entry.value.amount.setScale(5, RoundingMode.HALF_UP),5),

'price':getRussianNumber(entry.value.price),

'priceWoNDS': getRussianNumber(entry.value.price/120*100),

'sum': getRussianNumber(entry.value.sum),

'reductionFactor':getRussianNumber(entry.value.sum == 0 ? 0 : entry.value.totalSum/entry.value.sum),

'totalSum':getRussianNumber(entry.value.totalSum),

'totalSumWoNds':getRussianNumber(entry.value.totalSum/120*100),

'ndsSum':getRussianNumber(entry.value.totalSum - (entry.value.totalSum/120*100).setScale(2, RoundingMode.HALF_UP))]);

totalSum+=entry.value.totalSum;

totalSumWoNds+=entry.value.totalSum/120*100

ndsSum+=entry.value.totalSum - (entry.value.totalSum/120*100).setScale(2, RoundingMode.HALF_UP)

}


itemsInRent.eachWithIndex { entry, i ->

def sum = entry.value.price * entry.value.amount;

if(entry.value.sum != 0){

itemsArr.add(['n':2,

'positionName':'Услуга Регионального оператора по обращению с ТКО арендаторов за',

'month':entry.value.month,

'amount':getRussianNumber(entry.value.amount.setScale(5, RoundingMode.HALF_UP),5),

'price':getRussianNumber(entry.value.price),

'priceWoNDS': getRussianNumber(entry.value.price/120*100),

'sum': getRussianNumber(entry.value.sum),

'reductionFactor':getRussianNumber(entry.value.sum == 0 ? 0 : entry.value.totalSum/entry.value.sum),

'totalSum':getRussianNumber(entry.value.totalSum),

'totalSumWoNds':getRussianNumber(entry.value.totalSum/120*100),

'ndsSum':getRussianNumber(entry.value.totalSum - (entry.value.totalSum/120*100).setScale(2, RoundingMode.HALF_UP))]);

totalSum+=entry.value.totalSum;

totalSumWoNds+=entry.value.totalSum/120*100

ndsSum+=entry.value.totalSum - (entry.value.totalSum/120*100).setScale(2, RoundingMode.HALF_UP)

}

}



result['items'] = itemsArr


totalSum = totalSum.setScale(2, RoundingMode.HALF_UP)

result['totals'] = ['totalSum': getRussianNumber(totalSum),

'totalNds': getRussianNumber(ndsSum),

'count': String.valueOf(itemsArr.size()),

'sumText':service.getNumberText(totalSum),

'totalSumWoNds':getRussianNumber(totalSumWoNds)]


return [result]


def fillItems(LinkedHashMap items, Accrual a){

String period = getTextPeriod(a.getPeriod())

if (items[period] == null) {

items[period] = [

"month" : period,

"amount":getNN(a.getAmountBase()),

'price': getNN(a.getPrice()),

'sum': getNN(a.getTotalSumBase()),

'totalSum': getNN(a.getTotalSum())

]

} else {

items[period]['amount']+=getNN(a.getAmountBase())

items[period]['sum']+=getNN(a.getTotalSumBase())

items[period]['totalSum']+=getNN(a.getTotalSum())

}

//return items;

}


def getRussianNumber(Double number, int precision = 2) {

DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance()

symbols.setGroupingSeparator((char) ' ')

symbols.setDecimalSeparator((char) ',')


String formatString = '';

switch(precision){

case 1:

formatString = '###,###,###.#';

break;

case 2:

formatString = '###,###,###.##';

break;

case 3:

formatString = '###,###,###.###';

break;

case 4:

formatString = '###,###,###.####';

break;

case 5:

formatString = '###,###,###.######';

break;

}

DecimalFormat formatter = new DecimalFormat(formatString, symbols);

return(formatter.format(number));


// if (precision == 2){

// DecimalFormat formatter = new DecimalFormat('###,###.##', symbols)

// return(formatter.format(number));

// } else {

// DecimalFormat formatter = new DecimalFormat('###,###.###', symbols)

// return(formatter.format(number));

// }


}


def getTextPeriod(Date date) {

def result=''

if (date != null) {

def monthesRP = ['январь','февраль','март','апрель','май','июнь','июль','август','сентябрь','октябрь','ноябрь','декабрь']

Calendar cal = Calendar.getInstance()

cal.setTime(date);

result+=monthesRP[cal.get(Calendar.MONTH)]

result+=" "+cal.get(Calendar.YEAR).toString()+" г."

}

return result

}



def getTextDate(Date date) {

def result=''

if (date != null) {

def monthesRP = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']

Calendar cal = Calendar.getInstance()

cal.setTime(date);

result = cal.get(Calendar.DAY_OF_MONTH).toString()

result+=" "+monthesRP[cal.get(Calendar.MONTH)]

result+=" "+cal.get(Calendar.YEAR).toString()+" г."

}

return result

}


def getNN(BigDecimal value) {

return value == null ? BigDecimal.ZERO : value;

}


def getShortFio(String fio) {

if (fio == null) return ""

String pattern = "(\\S+\\s)(\\S{1})\\S+\\s(\\S{1})\\S+"

String str = fio.replaceAll(pattern, '$1$2.$3.')

return str

}

private Date getCorrDate(def accrual){

Date corrDate = new Date()


Calendar accrualPeriod = Calendar.getInstance()

accrualPeriod.setTime(accrual.getPeriod());

accrualPeriod.set(Calendar.DAY_OF_MONTH, accrualPeriod.getActualMaximum(Calendar.DAY_OF_MONTH));


Date dateContract = dataManager.loadValue('select e.contractPosition.contract.acceptanceDate from rtneo$Accrual e where e.documentNumber = :documentNumber', Date.class)

.parameter("documentNumber", accrual.getDocumentNumber())

.one()


if(dateContract.after(accrualPeriod.getTime())){

// _("Выводим дату контракта")

corrDate = dateContract;

}else{

// _("Выводим дату окончания периода начисления")

Calendar cal = Calendar.getInstance()

cal.setTime(accrual.getPeriod())

cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH))

corrDate = cal.getTime()

}

return corrDate;

}

private Acts getActualAct(String inn, String kpp, Date period){

List<Acts> acts = dataManager.load(Acts.class)

.query('select a from rtneo$Acts a where a.inn = :inn and a.kpp = :kpp and a.period = :period and a.adjustments is null')

.parameter("inn", inn)

.parameter("kpp", kpp)

.parameter("period" ,period)

.view("acts-view")

.list()


if(acts.size() == 0)return null


return acts.get(0)

}

Так же в этом разделе:
 
MyTetra Share v.0.65
Яндекс индекс цитирования