Author: bbrossaud Date: 2010-08-16 12:15:57 +0200 (Mon, 16 Aug 2010) New Revision: 51 Url: http://chorem.org/repositories/revision/billy/51 Log: the invoice search is ready Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CategorySearchMacro.java trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CompanySearchMacro.java trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/DateSearchMacro.java trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/InvoiceController.java trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/ProjectSearchMacro.java trunk/billy-ui-zk/src/main/webapp/invoicePage.zul Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CategorySearchMacro.java =================================================================== --- trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CategorySearchMacro.java 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CategorySearchMacro.java 2010-08-16 10:15:57 UTC (rev 51) @@ -5,6 +5,7 @@ import java.util.Set; import org.chorem.data.bonzoms.Category; +import org.chorem.data.bonzoms.Invoice; import org.chorem.data.bonzoms.SubCategory; import org.nuiton.wikitty.Criteria; import org.nuiton.wikitty.WikittyProxy; @@ -161,4 +162,16 @@ } }; } + + public void getSearch(Search search) { + if (search == null) { + search = Search.query(); + } + if (subCategories.size() > 0) { + Search searchSubCategories = search.and().or(); + for (String id : subCategories) { + searchSubCategories = searchSubCategories.eq(Invoice.FQ_FIELD_INVOICE_SUBCATEGORY, id); + } + } + } } Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CompanySearchMacro.java =================================================================== --- trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CompanySearchMacro.java 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/CompanySearchMacro.java 2010-08-16 10:15:57 UTC (rev 51) @@ -4,6 +4,7 @@ import java.util.List; import org.chorem.data.bonzoms.Company; +import org.chorem.data.bonzoms.Invoice; import org.nuiton.wikitty.Criteria; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.search.Element; @@ -119,4 +120,16 @@ } }; } + + public void getSearch(Search search) { + if (search == null) { + search = Search.query(); + } + if (companies.size() > 0) { + Search searchCompanies = search.and().or(); + for (String id : companies) { + searchCompanies = searchCompanies.eq(Invoice.FQ_FIELD_INVOICE_COMPANY, id); + } + } + } } Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/DateSearchMacro.java =================================================================== --- trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/DateSearchMacro.java 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/DateSearchMacro.java 2010-08-16 10:15:57 UTC (rev 51) @@ -1,67 +1,139 @@ package org.chorem.billy.ui; +import java.text.ParseException; +import java.util.Date; + +import org.chorem.data.bonzoms.Invoice; +import org.nuiton.wikitty.WikittyUtil; +import org.nuiton.wikitty.search.Search; import org.zkoss.zk.ui.HtmlMacroComponent; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zul.Checkbox; +import org.zkoss.zul.Datebox; public class DateSearchMacro extends HtmlMacroComponent { + protected int isCheck = 0; + @Override public void afterCompose() { super.afterCompose(); + initPostedCheck(); + initExpectedCheck(); + initPaymentCheck(); } -// protected boolean checkPosted(Date start, Date end, Search search) throws ParseException { -// Checkbox check = (Checkbox) getFellow("postedDate"); -// if (!check.isChecked()) { -// return false; -// } -// if (start != null) { -// String formatDate = WikittyUtil.formatDate(start); -// search = search.ge(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); -// } -// if (end != null) { -// String formatDate = WikittyUtil.formatDate(end); -// search = search.le(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); -// } -// search = search.or(); -// return true; -// } -// -// protected boolean expectedPosted(Date start, Date end, Search search, boolean bool) throws ParseException { -// Checkbox check = (Checkbox) getFellow("expectedDate"); -// if (!check.isChecked()) { -// return bool; -// } -// if (bool == false) { -// search = search.or(); -// } -// if (start != null) { -// bool = true; -// String formatDate = WikittyUtil.formatDate(start); -// search = search.ge(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); -// } -// if (end != null) { -// String formatDate = WikittyUtil.formatDate(end); -// search = search.le(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); -// } -// return bool; -// } -// -// -// public Search getSearch(Search src) { -// Search search = src; -// if (search == null) { -// search = Search.query(); -// } -// Datebox startDate = (Datebox) getFellow("startDate"); -// Date start = startDate.getValue(); -// -// Datebox endDate = (Datebox) getFellow("endDate"); -// Date end = endDate.getValue(); -// -// boolean bool = checkPosted(start, end, search); -// bool = checkExpected(start, end, search, bool); -// checkPayment(start, end, search, bool); -// -// return search; -// } + protected void initPostedCheck() { + Checkbox check = (Checkbox) getFellow("postedDate"); + check.addEventListener(Events.ON_CHECK, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + Checkbox check = (Checkbox) event.getTarget(); + if (check.isChecked()) { + ++isCheck; + } else { + --isCheck; + } + } + }); + } + + protected void initExpectedCheck() { + Checkbox check = (Checkbox) getFellow("expectedDate"); + check.addEventListener(Events.ON_CHECK, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + Checkbox check = (Checkbox) event.getTarget(); + if (check.isChecked()) { + ++isCheck; + } else { + --isCheck; + } + } + }); + } + + protected void initPaymentCheck() { + Checkbox check = (Checkbox) getFellow("paymentDate"); + check.addEventListener(Events.ON_CHECK, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + Checkbox check = (Checkbox) event.getTarget(); + if (check.isChecked()) { + ++isCheck; + } else { + --isCheck; + } + } + }); + } + + protected void checkPosted(Date start, Date end, Search search) throws ParseException { + Checkbox check = (Checkbox) getFellow("postedDate"); + if (check.isChecked()) { + Search postedSearch = search.and(); + if (start != null) { + String formatDate = WikittyUtil.formatDate(start); + postedSearch = postedSearch.ge(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); + } + if (end != null) { + String formatDate = WikittyUtil.formatDate(end); + postedSearch = postedSearch.le(Invoice.FQ_FIELD_INVOICE_POSTED, formatDate); + } + } + } + + protected void checkExpected(Date start, Date end, Search search) throws ParseException { + Checkbox check = (Checkbox) getFellow("expectedDate"); + if (check.isChecked()) { + Search expectedSearch = search.and(); + if (start != null) { + String formatDate = WikittyUtil.formatDate(start); + expectedSearch = expectedSearch.ge(Invoice.FQ_FIELD_INVOICE_EXPECTED, formatDate); + } + if (end != null) { + String formatDate = WikittyUtil.formatDate(end); + expectedSearch = expectedSearch.le(Invoice.FQ_FIELD_INVOICE_EXPECTED, formatDate); + } + } + } + + protected void checkPayment(Date start, Date end, Search search) throws ParseException { + Checkbox check = (Checkbox) getFellow("paymentDate"); + if (check.isChecked()) { + Search paymentSearch = search.and(); + if (start != null) { + String formatDate = WikittyUtil.formatDate(start); + paymentSearch = paymentSearch.ge(Invoice.FQ_FIELD_INVOICE_PAYMENT, formatDate); + } + if (end != null) { + String formatDate = WikittyUtil.formatDate(end); + paymentSearch = paymentSearch.le(Invoice.FQ_FIELD_INVOICE_PAYMENT, formatDate); + } + } + } + + public void getSearch(Search search) throws ParseException { + if (search == null) { + search = Search.query(); + } + if (isCheck > 0) { + Datebox startDate = (Datebox) getFellow("startDate"); + Date start = startDate.getValue(); + + Datebox endDate = (Datebox) getFellow("endDate"); + Date end = endDate.getValue(); + if (start != null || end != null) { + Search searchDate = search.or(); + checkPosted(start, end, searchDate); + checkExpected(start, end, searchDate); + checkPayment(start, end, searchDate); + } + } + } } Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/InvoiceController.java =================================================================== --- trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/InvoiceController.java 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/InvoiceController.java 2010-08-16 10:15:57 UTC (rev 51) @@ -1,5 +1,6 @@ package org.chorem.billy.ui; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; @@ -35,6 +36,11 @@ protected WikittyProxy proxy = ChoremDataProxy.getInstance(); protected InvoiceModel invoiceModel = new InvoiceModel(pageSize); + protected ProjectSearchMacro projectSearchMacro; + protected CompanySearchMacro companySearchMacro; + protected CategorySearchMacro categorySearchMacro; + protected DateSearchMacro dateSearchMacro; + protected Paging invoicePaging; @Override @@ -212,6 +218,18 @@ invoiceModel.setActivePage(activePage); } + public void onClick$searchAll() throws ParseException { + Search search = Search.query(); + search = search.eq(Element.ELT_EXTENSION, Invoice.EXT_INVOICE); + dateSearchMacro.getSearch(search); + projectSearchMacro.getSearch(search); + companySearchMacro.getSearch(search); + categorySearchMacro.getSearch(search); + Criteria criteria = search.criteria(); + invoiceModel.setCriteria(criteria); + initPaging(); + } + /* * Getters */ Modified: trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/ProjectSearchMacro.java =================================================================== --- trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/ProjectSearchMacro.java 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/java/org/chorem/billy/ui/ProjectSearchMacro.java 2010-08-16 10:15:57 UTC (rev 51) @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import org.chorem.data.bonzoms.Invoice; import org.chorem.data.bonzoms.Project; import org.nuiton.wikitty.Criteria; import org.nuiton.wikitty.WikittyProxy; @@ -119,4 +120,16 @@ } }; } + + public void getSearch(Search search) { + if (search == null) { + search = Search.query(); + } + if (projects.size() > 0) { + Search searchProjects = search.and().or(); + for (String id : projects) { + searchProjects = searchProjects.eq(Invoice.FQ_FIELD_INVOICE_PROJECT, id); + } + } + } } Modified: trunk/billy-ui-zk/src/main/webapp/invoicePage.zul =================================================================== --- trunk/billy-ui-zk/src/main/webapp/invoicePage.zul 2010-08-13 15:19:56 UTC (rev 50) +++ trunk/billy-ui-zk/src/main/webapp/invoicePage.zul 2010-08-16 10:15:57 UTC (rev 51) @@ -10,6 +10,7 @@ <categorySearchMacro id="categorySearchMacro" /> <companySearchMacro id="companySearchMacro" /> <projectSearchMacro id="projectSearchMacro" /> + <button id="searchAll" label="Search" /> <separator /> </vbox> Invoices: <toolbarbutton id="newInvoice" label="Add new invoice" />