Example usage for org.hibernate.criterion Restrictions ilike

List of usage examples for org.hibernate.criterion Restrictions ilike

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ilike.

Prototype

public static Criterion ilike(String propertyName, String value, MatchMode matchMode) 

Source Link

Document

A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode

Usage

From source file:com.ut.tekir.invoice.PurchaseInvoiceBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(Invoice.class);

    crit.createAlias("this.contact", "contact");

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("serial", filterModel.getSerial(), MatchMode.START));
    }//from ww  w.  j  a  v a 2 s. c o m

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("date", filterModel.getEndDate()));
    }

    /*
    if( filterModel.getWarehouse() != null ){
    crit.add( Restrictions.eq("warehouse", filterModel.getWarehouse() ));
    }
            
    */

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.START));
    }

    crit.add(Restrictions.eq("action", TradeAction.Purchase));
    crit.addOrder(Order.desc("serial"));

    return crit;
}

From source file:com.ut.tekir.invoice.SaleInvoiceBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(Invoice.class);

    crit.createAlias("this.contact", "contact");

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("serial", filterModel.getSerial(), MatchMode.START));
    }/*from   w w w  .  j  a  v a 2 s.com*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("date", filterModel.getEndDate()));
    }

    /*
    if( filterModel.getWarehouse() != null ){
    crit.add( Restrictions.eq("warehouse", filterModel.getWarehouse() ));
    }
     */

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.START));
    }

    crit.add(Restrictions.eq("action", TradeAction.Sale));
    crit.addOrder(Order.desc("serial"));

    return crit;
}

From source file:com.ut.tekir.invoice.yeni.PurchaseInvoiceBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirInvoice.class);

    crit.createAlias("this.contact", "contact");
    crit.createAlias("this.warehouse", "warehouse");

    crit.setProjection(Projections.projectionList().add(Projections.property("contact"), "contact")
            .add(Projections.property("warehouse"), "warehouse").add(Projections.property("serial"), "serial")
            .add(Projections.property("reference"), "reference").add(Projections.property("code"), "code")
            .add(Projections.property("date"), "date").add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("tradeAction"), "tradeAction")
            .add(Projections.property("documentType"), "documentType").add(Projections.property("id"), "id")
            .add(Projections.property("info"), "info")
            .add(Projections.property("totalBeforeTax.localAmount"), "totalBeforeTaxLocalAmount")
            .add(Projections.property("totalBeforeTax.value"), "totalBeforeTaxValue")
            .add(Projections.property("totalBeforeTax.currency"), "totalBeforeTaxCurrency")
            .add(Projections.property("totalTax.localAmount"), "totalTaxLocalAmount")
            .add(Projections.property("totalTax.value"), "totalTaxValue")
            .add(Projections.property("totalTax.currency"), "totalTaxCurrency")
            .add(Projections.property("grandTotal.localAmount"), "grandTotalLocalAmount")
            .add(Projections.property("grandTotal.value"), "grandTotalValue")
            .add(Projections.property("grandTotal.currency"), "grandTotalCurrency")
            .add(Projections.property("workBunch"), "workBunch"));

    crit.setResultTransformer(Transformers.aliasToBean(InvoiceFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }/*w  ww.j  a va2 s  .  com*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.ANYWHERE));
    }

    if (isNotEmpty(filterModel.getInfo())) {
        crit.add(Restrictions.ilike("this.info", filterModel.getInfo(), MatchMode.ANYWHERE));
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    if (filterModel.getReturned() != null) {
        if (filterModel.getReturned()) {
            crit.add(Restrictions.eq("this.tradeAction", TradeAction.SaleReturn));
        } else {
            crit.add(Restrictions.eq("this.tradeAction", TradeAction.Purchase));
        }
    } else {
        crit.add(Restrictions.or(Restrictions.eq("this.tradeAction", TradeAction.SaleReturn),
                Restrictions.eq("this.tradeAction", TradeAction.Purchase)));
    }

    crit.add(Restrictions.or(Restrictions.eq("this.documentType", DocumentType.PurchaseInvoice),
            Restrictions.eq("this.documentType", DocumentType.PurchaseShipmentInvoice)));

    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.invoice.yeni.RetailSaleInvoiceBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirInvoice.class);

    crit.createAlias("this.contact", "contact");

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("serial", filterModel.getSerial(), MatchMode.START));
    }/* w ww . j av a 2s.com*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("date", filterModel.getEndDate()));
    }

    /*
    if( filterModel.getWarehouse() != null ){
    crit.add( Restrictions.eq("warehouse", filterModel.getWarehouse() ));
    }
     */

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.START));
    }

    crit.add(Restrictions.eq("tradeAction", TradeAction.Sale));
    crit.add(Restrictions.eq("documentType", DocumentType.RetailSaleShipmentInvoice));

    crit.addOrder(Order.desc("serial"));

    return crit;
}

From source file:com.ut.tekir.invoice.yeni.SaleInvoiceBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirInvoice.class);

    crit.createAlias("this.contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info"), "info").add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.company"), "contactCompany")
            .add(Projections.property("contact.person"), "contactPerson")
            .add(Projections.property("documentType"), "documentType")
            .add(Projections.property("tradeAction"), "tradeAction")
            .add(Projections.property("totalBeforeTax.value"), "totalBeforeTaxValue")
            .add(Projections.property("totalBeforeTax.currency"), "totalBeforeTaxCurrency")
            .add(Projections.property("totalTax.value"), "totalTaxValue")
            .add(Projections.property("totalTax.currency"), "totalTaxCurrency")
            .add(Projections.property("grandTotal.value"), "grandTotalValue")
            .add(Projections.property("grandTotal.currency"), "grandTotalCurrency")
            .add(Projections.property("workBunch"), "workBunch"));

    crit.setResultTransformer(Transformers.aliasToBean(InvoiceFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }/*w ww  .j a va  2 s  .  c  o m*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getInfo())) {
        crit.add(Restrictions.ilike("this.info", filterModel.getInfo(), MatchMode.ANYWHERE));
    }

    if (filterModel.getActive() != null) {
        crit.add(Restrictions.eq("this.active", filterModel.getActive()));
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    if (filterModel.getReturned() != null) {
        if (filterModel.getReturned()) {
            crit.add(Restrictions.eq("this.tradeAction", TradeAction.PurchseReturn));
        } else {
            crit.add(Restrictions.eq("this.tradeAction", TradeAction.Sale));
        }
    } else {
        crit.add(Restrictions.or(Restrictions.eq("this.tradeAction", TradeAction.PurchseReturn),
                Restrictions.eq("this.tradeAction", TradeAction.Sale)));
    }

    if (filterModel.getProformaInvoice() != null) {
        if (filterModel.getProformaInvoice()) {
            crit.add(Restrictions.eq("this.documentType", DocumentType.SaleProformaInvoice));
        } else {
            crit.add(Restrictions.in("this.documentType", new DocumentType[] { DocumentType.SaleInvoice,
                    DocumentType.SaleShipmentInvoice, DocumentType.RetailSaleShipmentInvoice }));
        }
    } else {
        crit.add(Restrictions.in("this.documentType",
                new DocumentType[] { DocumentType.SaleInvoice, DocumentType.SaleShipmentInvoice,
                        DocumentType.RetailSaleShipmentInvoice, DocumentType.SaleProformaInvoice }));
    }

    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.report.AccountStatusReportBean.java

License:LGPL

public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(AccountTxn.class);

    crit.createAlias("account", "account");

    crit.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("account.code"), "accountCode")
            .add(Projections.groupProperty("account.name"), "accountName")
            .add(Projections.groupProperty("amount.currency"), "currency")
            .add(Projections.sum("amount.value"), "amount")
            .add(Projections.sum("amount.localAmount"), "localAmount")
            .add(Projections.property("this.processType"), "processType")
            .add(Projections.sqlGroupProjection(
                    "{alias}.CCY as currency, sum( ( case {alias}.finance_action when 0 then 1 else -1 end ) * {alias}.CCYVAL ) as AMOUNT, sum( case {alias}.finance_action when 0 then {alias}.CCYVAL else 0 end ) as DEBIT, sum( case {alias}.finance_action when 0 then 0 else {alias}.CCYVAL end ) as CREDIT",
                    "CCY", new String[] { "currency", "amount", "debit", "credit" },
                    new Type[] { Hibernate.STRING, Hibernate.BIG_DECIMAL, Hibernate.BIG_DECIMAL,
                            Hibernate.BIG_DECIMAL })));

    crit.add(Restrictions.eq("active", true));

    if (code != null && code.length() > 0) {
        crit.add(Restrictions.ilike("code", code, MatchMode.START));

    }/*from  ww w  . j  ava  2 s .com*/

    if (account != null) {
        crit.add(Restrictions.eq("account", account));
    }

    if (beginDate != null) {
        crit.add(Restrictions.ge("date", beginDate));
    }

    if (endDate != null) {
        crit.add(Restrictions.le("date", endDate));
    }

    if (getDocumentType() != null && getDocumentType() != DocumentType.Unknown) {
        crit.add(Restrictions.eq("documentType", getDocumentType()));
    }

    if (getProcessType() != null) {
        crit.add(Restrictions.eq("this.processType", getProcessType()));
    }

    if (getWorkBunch() != null) {
        crit.add(Restrictions.eq("workBunch", getWorkBunch()));
    }

    crit.addOrder(Order.asc("account.code"));

    return crit;
}

From source file:com.ut.tekir.report.AccountTxnReportBean.java

License:LGPL

public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(AccountTxn.class);

    crit.createAlias("account", "account");

    crit.add(Restrictions.eq("active", true));

    if (getSerial() != null && getSerial().length() > 0) {
        crit.add(Restrictions.ilike("serial", getSerial(), MatchMode.START));
    }//from  w ww . j a v a  2s.c  o  m

    if (getReference() != null && getReference().length() > 0) {
        crit.add(Restrictions.ilike("reference", getReference(), MatchMode.START));
    }

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.ilike("code", getCode(), MatchMode.START));
    }

    if (getAccount() != null) {
        crit.add(Restrictions.eq("account", getAccount()));
    }

    if (getDocumentType() != null && getDocumentType() != DocumentType.Unknown) {
        crit.add(Restrictions.eq("documentType", getDocumentType()));
    }

    if (getBeginDate() != null) {
        crit.add(Restrictions.ge("date", getBeginDate()));
    }

    if (getEndDate() != null) {
        crit.add(Restrictions.le("date", getEndDate()));
    }

    if (getProcessType() != null) {
        crit.add(Restrictions.eq("processType", getProcessType()));
    }

    if (getWorkBunch() != null) {
        crit.add(Restrictions.eq("workBunch", getWorkBunch()));
    }

    if (getAdverseCode() != null && getAdverseCode().length() > 0) {
        crit.add(Restrictions.ilike("this.adverseCode", getAdverseCode(), MatchMode.START));
    }

    if (getAdverseName() != null && getAdverseName().length() > 0) {
        crit.add(Restrictions.ilike("this.adverseName", getAdverseName(), MatchMode.START));
    }

    if (getCurrency() != null) {
        crit.add(Restrictions.eq("this.amount.currency", getCurrency()));
    }

    crit.add(Restrictions.eq("this.active", true));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.id"));
    //crit.addOrder(Order.desc("this.serial"));
    //crit.addOrder(Order.asc("account.code"));
    //crit.addOrder(Order.asc("documentType"));

    return crit;
}

From source file:com.ut.tekir.report.BankStatusReportBean.java

License:LGPL

public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(BankTxn.class);

    crit.createAlias("bankAccount", "bankAccount");
    crit.createAlias("bankAccount.bankBranch", "bankBranch");
    crit.createAlias("bankAccount.bankBranch.bank", "bank");

    crit.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("bankAccount.accountNo"), "bankAccount")
            .add(Projections.groupProperty("bankBranch.name"), "bankBranchName")
            .add(Projections.groupProperty("bank.name"), "bankName")
            .add(Projections.groupProperty("amount.currency"), "currency")
            .add(Projections.sum("amount.value"), "amount")
            .add(Projections.property("processType"), "processType")
            .add(Projections.sum("amount.localAmount"), "localAmount")
            .add(Projections.sqlGroupProjection(
                    "{alias}.CCY as currency, sum( ( case {alias}.action when 0 then 1 else -1 end ) * {alias}.CCYVAL ) as AMOUNT, sum( case {alias}.action when 0 then {alias}.CCYVAL else 0 end ) as DEBIT, sum( case {alias}.action when 0 then 0 else {alias}.CCYVAL end ) as CREDIT",
                    "{alias}.CCY", new String[] { "currency", "amount", "debit", "credit" },
                    new Type[] { Hibernate.STRING, Hibernate.BIG_DECIMAL, Hibernate.BIG_DECIMAL,
                            Hibernate.BIG_DECIMAL })));

    crit.add(Restrictions.eq("active", true));

    if (bankAccount != null) {
        crit.add(Restrictions.eq("this.bankAccount", bankAccount));
    } else {//w  w  w .  ja  va  2  s . co m

        if (bankBranch != null) {
            crit.add(Restrictions.eq("bankAccount.bankBranch", bankBranch));
        } else {
            if (bank != null) {
                crit.add(Restrictions.eq("bankBranch.bank", bank));
            }
        }
    }

    if (code != null && code.length() > 0) {
        crit.add(Restrictions.ilike("code", code, MatchMode.START));
    }

    if (beginDate != null) {
        crit.add(Restrictions.ge("date", beginDate));
    }

    if (endDate != null) {
        crit.add(Restrictions.le("date", endDate));
    }

    if (getWorkBunch() != null) {
        crit.add(Restrictions.eq("workBunch", getWorkBunch()));
    }

    if (getDocumentType() != null && getDocumentType() != DocumentType.Unknown) {
        crit.add(Restrictions.eq("documentType", getDocumentType()));
    }

    if (getProcessType() != null) {
        crit.add(Restrictions.eq("this.processType", getProcessType()));
    }

    crit.addOrder(Order.asc("bankAccount.name"));

    return crit;
}

From source file:com.ut.tekir.report.BankTxnReportBean.java

License:LGPL

public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(BankTxn.class);

    crit.createAlias("bankAccount", "bankAccount");

    if (getBankAccount() != null) {
        crit.add(Restrictions.eq("bankAccount", getBankAccount()));
    } else {//  w w w .  j av  a 2  s .co m

        if (getBankBranch() != null) {
            crit.createAlias("bankAccount.bankBranch", "bankBranch");
            crit.add(Restrictions.eq("bankAccount.bankBranch", getBankBranch()));

        } else {
            if (getBank() != null) {
                crit.createAlias("bankAccount.bankBranch", "bankBranch");
                crit.createAlias("bankAccount.bankBranch.bank", "bank");
                crit.add(Restrictions.eq("bankBranch.bank", getBank()));
            }
        }
    }

    if (getSerial() != null && getSerial().length() > 0) {
        crit.add(Restrictions.ilike("serial", getSerial(), MatchMode.START));
    }

    if (getReference() != null && getReference().length() > 0) {
        crit.add(Restrictions.ilike("reference", getReference(), MatchMode.START));
    }

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.ilike("code", getCode(), MatchMode.START));
    }

    if (getDocumentType() != null && getDocumentType() != DocumentType.Unknown) {
        crit.add(Restrictions.eq("documentType", getDocumentType()));
    }

    if (getBeginDate() != null) {
        crit.add(Restrictions.ge("date", getBeginDate()));
    }

    if (getEndDate() != null) {
        crit.add(Restrictions.le("date", getEndDate()));
    }

    if (getAdverseCode() != null) {
        crit.add(Restrictions.ilike("adverseCode", getAdverseCode(), MatchMode.START));
    }

    if (getAdverseName() != null) {
        crit.add(Restrictions.ilike("adverseName", getAdverseName(), MatchMode.START));
    }

    if (getWorkBunch() != null) {
        crit.add(Restrictions.eq("workBunch", getWorkBunch()));
    }

    if (getProcessType() != null) {
        crit.add(Restrictions.eq("this.processType", getProcessType()));
    }

    crit.add(Restrictions.eq("this.active", true));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));
    crit.addOrder(Order.desc("this.id"));
    //crit.addOrder(Order.asc("documentType"));
    //crit.addOrder(Order.asc("bankAccount"));

    return crit;
}

From source file:com.ut.tekir.report.ContactStatusReportBean.java

License:LGPL

public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(FinanceTxn.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.groupProperty("contact.code"), "concode")
            .add(Projections.groupProperty("contact.fullname"), "conname")
            .add(Projections.groupProperty("contact.company"), "company")
            .add(Projections.groupProperty("contact.person"), "person")
            //.add( Projections.groupProperty("action"), "action" )
            //.add( Projections.groupProperty("amount.currency"), "currency" )
            .add(Projections.sum("amount.value"), "amount")
            .add(Projections.sum("amount.localAmount"), "localAmount")
            .add(Projections.sqlGroupProjection(
                    "{alias}.CCY as currency, sum( case {alias}.finance_action when 0 then {alias}.CCYVAL else 0 end ) as DEBIT, sum( case {alias}.finance_action when 0 then 0 else {alias}.CCYVAL end ) as CREDIT",
                    "{alias}.CCY", new String[] { "currency", "debit", "credit" },
                    new Type[] { Hibernate.STRING, Hibernate.BIG_DECIMAL, Hibernate.BIG_DECIMAL })));

    if (fm.getActive() != null) {
        crit.add(Restrictions.eq("active", fm.getActive()));
    }/*from   w  w  w.  ja v  a 2 s .  c o m*/

    if (StringUtils.isNotEmpty(fm.getCode())) {
        crit.add(Restrictions.ilike("contact.code", fm.getCode(), MatchMode.START));
    }

    if (StringUtils.isNotEmpty(fm.getName())) {
        crit.add(Restrictions.ilike("contact.name", fm.getName(), MatchMode.START));
    }

    if (fm.getCategory() != null) {
        crit.add(Restrictions.eq("contact.category", fm.getCategory()));
    }

    if (fm.getBeginDate() != null) {
        crit.add(Restrictions.ge("date", fm.getBeginDate()));
    }

    if (fm.getEndDate() != null) {
        crit.add(Restrictions.le("date", fm.getEndDate()));
    }

    if (fm.getCompanyType() != null && !fm.getCompanyType().equals("All")) {
        if (fm.getCompanyType().equals("Person")) {
            crit.add(Restrictions.eq("contact.person", Boolean.TRUE));
        } else
            crit.add(Restrictions.eq("contact.person", Boolean.FALSE));
    }

    if (fm.getType() != null && fm.getType() != ContactType.All) {
        crit.add(Restrictions.eq("contact." + fm.getType().toString().toLowerCase() + "Type", Boolean.TRUE));
    }

    if (StringUtils.isNotEmpty(fm.getExCode1())) {
        crit.add(Restrictions.ilike("contact.exCode1", fm.getExCode1(), MatchMode.START));
    }

    if (StringUtils.isNotEmpty(fm.getExCode2())) {
        crit.add(Restrictions.ilike("contact.exCode2", fm.getExCode2(), MatchMode.START));
    }

    if (fm.getOrganization() != null) {
        crit.add(Restrictions.eq("contact.organization", fm.getOrganization()));
    }

    if (StringUtils.isNotEmpty(fm.getDocCode())) {
        crit.add(Restrictions.ilike("code", fm.getDocCode(), MatchMode.START));
    }

    if (fm.getDocumentType() != null && fm.getDocumentType() != DocumentType.Unknown) {
        crit.add(Restrictions.eq("this.documentType", fm.getDocumentType()));
    }

    if (fm.getProcessType() != null) {
        crit.add(Restrictions.eq("this.processType", fm.getProcessType()));
    }

    if (fm.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", fm.getWorkBunch()));
    }

    if (fm.getContact() != null) {
        crit.add(Restrictions.eq("contact.id", fm.getContact().getId()));
    }

    /*
    crit.addOrder( Order.asc("date"));
    crit.addOrder( Order.asc("serial"));
     * 
     */
    crit.addOrder(Order.asc("contact.code"));
    crit.addOrder(Order.asc("amount.currency"));

    log.debug("Sonu : #0", crit);

    return crit;
}