- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
@Override
List search(Long ownerId, Long projectId, String docnumber, String ctr1, String ctr2, Long dateFrom, Long dateTo, String contract,
Double amountFrom, Double amountTo, Double vatAmountFrom, Double vatAmountTo, Double withVatAmountFrom,
Double withVatAmountTo, Boolean defect, DocumentDefect d, Long vatId, Integer limit, String sortField, String order, String docType) {
// доступные проекты
List projects = projectDAO.findAll(ownerId)
if(!projects){
logger.warn("Ошибка отображения списка документов: нет доступных проектов: ownerId:$ownerId")
return []
}
Criteria criteria = currentSession.createCriteria(DocumentView)
.createAlias("document", "d")//
.createAlias("d.project", "p")//
.add(Restrictions.in("p.id", projects.id))//
// if(projectId)
// criteria.add(Restrictions.eq("d.project.id", projectId))
if (docnumber)
criteria.add(Restrictions.ilike("docNumber", docnumber, MatchMode.ANYWHERE))
if (ctr1)
criteria.add(Restrictions.ilike("supplierName", ctr1, MatchMode.ANYWHERE))
if (ctr2)
criteria.add(Restrictions.ilike("customerName", ctr2, MatchMode.ANYWHERE))
if (dateFrom) {
Calendar date1 = Calendar.instance
date1.setTime(new Date(dateFrom))
criteria.add(Restrictions.ge("docDate", date1))
}
if (dateTo) {
Calendar date1 = Calendar.instance
date1.setTime(new Date(dateTo))
date1.add(Calendar.DAY_OF_MONTH, 1)
criteria.add(Restrictions.lt("docDate", date1))
}
if (contract)
criteria.add(Restrictions.ilike("contract", contract, MatchMode.ANYWHERE))
if (amountFrom)
criteria.add(Restrictions.ge("amount", amountFrom))
if (amountTo)
criteria.add(Restrictions.le("amount", amountTo))
if (vatAmountFrom)
criteria.add(Restrictions.ge("vatAmount", vatAmountFrom))
if (vatAmountTo)
criteria.add(Restrictions.le("vatAmount", vatAmountTo))
if (withVatAmountFrom)
criteria.add(Restrictions.ge("totalAmount", withVatAmountFrom))
if (withVatAmountTo)
criteria.add(Restrictions.le("totalAmount", withVatAmountTo))
if (defect) {
criteria.add(Restrictions.isNotNull("defect"))
if (d)
criteria.add(Restrictions.eq("defect", d))
}
// if (vatId)
// criteria.add(Restrictions.eq("d.", withVatAmountTo))
if (docType) {
def dt = DocumentType.values().find { it.link == docType || it.code == docType }
if (dt)
criteria.add(Restrictions.like("docLink", dt.code, MatchMode.START))
else
logger.error("Неправильное значение параметра фильтрации по виду документа [d_t:$docType]. Допустимые значения ${DocumentType.values().code}")
}
// получаем общее кол-во записей без ограничений по странице
def rowCount = criteria.setProjection(Projections.rowCount()).uniqueResult() as Integer
List result = criteria.setProjection(null)//
.setResultTransformer(Criteria.ROOT_ENTITY)//
.addOrder(Order."$order"(sortField))//
.setMaxResults(limit)//
.list()
[rowCount, result]
}