BrightSide Workbench Full Report + Source Code
FollowUps.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.cart;
20 
21 import java.util.List;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.FollowUp;
26 import org.turro.jpa.Dao;
27 import org.turro.plugin.contacts.IContact;
28 
33 public class FollowUps {
34 
35  public static List<FollowUp> notPrepared(IContact contact) {
36  Dao dao = new FinancialsPU();
37  WhereClause wc = new WhereClause();
38  wc.addClause("select fu from FollowUp as fu");
39  wc.addClause("where preparedDate is null");
40  if(!Application.getApplication().isInRole("finan-contract:delete")) {
41  wc.addClause("and prepareId = :contactId");
42  wc.addNamedValue("contactId", contact.getId());
43  }
44  return dao.getResultList(wc);
45  }
46 
47  public static List<FollowUp> notDelivered(IContact contact) {
48  Dao dao = new FinancialsPU();
49  WhereClause wc = new WhereClause();
50  wc.addClause("select fu from FollowUp as fu");
51  wc.addClause("where deliveredDate is null and preparedDate is not null");
52  if(!Application.getApplication().isInRole("finan-contract:delete")) {
53  wc.addClause("and deliverId = :contactId");
54  wc.addNamedValue("contactId", contact.getId());
55  }
56  return dao.getResultList(wc);
57  }
58 
59  public static long countNotPrepared(IContact contact) {
60  Dao dao = new FinancialsPU();
61  WhereClause wc = new WhereClause();
62  wc.addClause("select count(fu) from FollowUp as fu");
63  wc.addClause("where preparedDate is null");
64  if(!Application.getApplication().isInRole("finan-contract:delete")) {
65  wc.addClause("and prepareId = :contactId");
66  wc.addNamedValue("contactId", contact.getId());
67  }
68  return (long) dao.getSingleResultOrNull(wc);
69  }
70 
71  public static long countNotDelivered(IContact contact) {
72  Dao dao = new FinancialsPU();
73  WhereClause wc = new WhereClause();
74  wc.addClause("select count(fu) from FollowUp as fu");
75  wc.addClause("where deliveredDate is null and preparedDate is not null");
76  if(!Application.getApplication().isInRole("finan-contract:delete")) {
77  wc.addClause("and deliverId = :contactId");
78  wc.addNamedValue("contactId", contact.getId());
79  }
80  return (long) dao.getSingleResultOrNull(wc);
81  }
82 
83 }
void addNamedValue(String name, Object value)
static List< FollowUp > notDelivered(IContact contact)
Definition: FollowUps.java:47
static List< FollowUp > notPrepared(IContact contact)
Definition: FollowUps.java:35
static long countNotDelivered(IContact contact)
Definition: FollowUps.java:71
static long countNotPrepared(IContact contact)
Definition: FollowUps.java:59
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419