BrightSide Workbench Full Report + Source Code
SaleProspectWrapper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.crm.zul.sale;
20 
21 import org.turro.string.Strings;
22 import org.turro.action.Plugins;
23 import org.turro.crm.db.CrmPU;
24 import org.turro.crm.entity.SaleProspect;
25 import org.turro.crm.entity.VendorProspect;
26 import org.turro.elephant.util.Messages;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.Dao;
29 import org.turro.jpa.entity.DaoEntity;
30 import org.turro.jpa.entity.EntityCollections;
31 import org.turro.plugin.dossier.ICategory;
32 import org.turro.plugin.dossier.IDossier;
33 
38 public class SaleProspectWrapper extends DaoEntity<SaleProspect, Long> {
39 
41  super(entity);
42  }
43 
44  public String getTabLabel() {
45  return getSelfLabel() + " #" + entity.getId();
46  }
47 
48  public String getSelfLabel() {
49  return I_.get("Sale prospect");
50  }
51 
52  @Override
53  public boolean delete() {
54  Messages.confirmDeletion().show(() -> {
55  if(entity.getCampaign() != null) {
56  EntityCollections.entities(entity.getCampaign().getSaleProspects()).remove(entity);
57  entity.setCampaign(null);
58  entity = save();
59  }
61  });
62  return true;
63  }
64 
65  @Override
66  protected Dao createDao() {
67  return new CrmPU();
68  }
69 
70  @Override
71  public boolean canSave() {
72  return !entity.isEmpty();
73  }
74 
75  @Override
76  public boolean canDelete() {
77  for(VendorProspect vp : entity.getVendorProspects()) {
78  if(!vp.getSaleActions().isEmpty()) {
79  return false;
80  }
81  }
82  return super.canDelete();
83  }
84 
85  public IDossier getDossier() {
86  if(entity.getId() > 0) {
87  IDossier dossier = (IDossier) Plugins.loadImplementation(IDossier.class);//PluginChecker.get("dossier");
88  ICategory cat = dossier.addCategory();
89  cat.setDescription("Customer Relationship");
90  cat.setId(8100);
91  cat = dossier.addCategory();
92  cat.setDescription("Sale Prospects");
93  cat.setId(8101);
94  cat.setParentId(8100);
95  dossier.setDescription(Strings.truncateAndWarn(entity.getDescription(), 50));
96  dossier.setIdCategory(cat.getId());
98  dossier.setSubject(entity.getCustomer().getIContact());
99  return dossier;
100  }
101  return null;
102  }
103 
104  @Override
105  protected boolean shouldLog() {
106  return false;
107  }
108 
109 }
static< T > T loadImplementation(Class< T > jclass)
Definition: Plugins.java:57
static String getObjectPath(Object object)
Definition: CrmPU.java:43
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41
static EntityCollections entities(Collection values)
void setDescription(String description)
void setSubject(IContact subject)
void setIdCategory(Long idCategory)
void setDescription(String description)