18 package org.turro.financials.entity;
21 import javax.persistence.*;
22 import org.turro.string.Strings;
23 import org.turro.action.Contacts;
24 import org.turro.elephant.calendar.Periodicity;
25 import org.turro.elephant.db.IdUtils;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.financials.db.FinancialsPU;
28 import org.turro.jpa.Dao;
29 import org.turro.jpa.entity.IDaoEntity;
30 import org.turro.plugin.contacts.ContactList;
31 import org.turro.plugin.contacts.IContact;
32 import org.turro.reflection.MappingSet;
33 import org.turro.util.PhraseBuilder;
43 @Column(name=
"IDENTIFIER")
46 private String globalId;
48 private String contractor;
52 private boolean stock, cash, active, useContractorCode;
56 private String grouping;
68 @Column(name=
"START_DATE")
69 @Temporal(value = TemporalType.TIMESTAMP)
70 private Date startDate;
72 @Column(name=
"END_DATE")
73 @Temporal(value = TemporalType.TIMESTAMP)
80 private Currency currency;
82 private boolean equivalenceSurcharge;
84 @ManyToOne(fetch=FetchType.LAZY)
87 @OneToMany(fetch = FetchType.EAGER)
88 private Set<ContractPreference> contractPreferences =
new HashSet<ContractPreference>();
90 @OneToMany(mappedBy =
"contract", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=
true)
91 private Set<RelatedContractStore> relatedContractStores =
new HashSet<RelatedContractStore>();
93 @OneToMany(mappedBy =
"contract", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
94 @OrderBy(value=
"name")
95 private Set<ContractParticipant> participants =
new HashSet<ContractParticipant>();
97 @OneToMany(mappedBy =
"contract", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
98 private Set<ContractFlow> contractFlows =
new HashSet<ContractFlow>();
100 @OneToMany(mappedBy =
"contract", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
101 private Set<Tax> taxes =
new HashSet<Tax>();
103 @OneToMany(mappedBy =
"contract", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
104 private Set<Contracted> contracted =
new HashSet<Contracted>();
106 @OneToOne(cascade = CascadeType.ALL)
114 this.active = active;
127 if(
id > 0 && dao.
isNotLoaded(contractDefinition)) {
128 contractDefinition = dao.lazyLoader(
Contract.class,
this,
"contractDefinition").contractDefinition;
130 return contractDefinition;
134 this.contractDefinition = contractDefinition;
138 return contractFlows;
142 this.contractFlows = contractFlows;
146 return contractPreferences;
150 this.contractPreferences = contractPreferences;
158 this.contractor = contractor;
162 if(currency ==
null) {
163 currency = Currency.getInstance(
"EUR");
169 this.currency = currency;
177 this.department = department;
185 this.endDate = endDate;
189 return equivalenceSurcharge;
193 this.equivalenceSurcharge = equivalenceSurcharge;
201 this.globalId = globalId;
229 return operatingModifier;
233 this.operatingModifier = operatingModifier;
241 this.grouping = grouping;
257 this.periodicity = periodicity;
265 this.participants = participants;
270 if(
id > 0 && dao.
isNotLoaded(relatedContractStores)) {
271 relatedContractStores = dao.lazyLoader(
Contract.class,
this,
"relatedContractStores").relatedContractStores;
273 return relatedContractStores;
277 this.relatedContractStores = relatedContractStores;
285 this.service = service;
293 this.startDate = startDate;
317 this.contracted = contracted;
321 return useContractorCode;
325 this.useContractorCode = useContractorCode;
329 return contractHandshake;
333 this.contractHandshake = contractHandshake;
356 if(operatingModifier ==
null) {
377 if(!Strings.isBlank(contractor)) {
384 StringBuilder sb =
new StringBuilder();
385 if(!Strings.isBlank(globalId)) {
392 StringBuilder sb =
new StringBuilder();
393 if(department !=
null) {
394 sb.append(department.getFullName());
396 }
else if(service !=
null) {
397 sb.append(service.getFullName());
406 PhraseBuilder pb =
new PhraseBuilder();
407 pb.addWord(contractDefinition.
getName());
408 pb.addPendingSeparator(
": ");
410 pb.addWord(cp.getName());
411 pb.addPendingSeparator(
",");
415 sb.append(
" " + pb.toString());
421 if(globalId !=
null) {
422 sb.append(
" " + globalId);
424 return sb.toString();
428 ArrayList<ContractFlow> flows =
new ArrayList<>();
441 wc.
addClause(
"select d from Document d");
442 wc.
addClause(
"where d.contract = :contract");
445 return dao.getResultList(
Document.class, wc);
450 List<Contract> list = dao.getResultList(
451 "select contract from Contract as contract");
460 private transient ContactList _participants, _docParticipants;
463 if(_participants ==
null) {
470 return _participants;
474 if(_docParticipants ==
null) {
477 if(cp.getInterventionType().isSendDocuments()) {
483 return _docParticipants;
489 if(documentDefinition !=
null) {
492 documentDefinition.
getId() +
"-";
500 MappingSet
set =
new MappingSet();
502 new String[] {
"id",
"globalId",
"contractor",
"name" },
503 new String[] {
"stock",
"cash",
"active",
"useContractorCode",
"operatingModifier",
504 "startDate",
"endDate",
"notes",
"department",
"service",
"contractDefinition",
505 "contractPreferences",
"relatedContractStores",
"participants",
"currency",
506 "taxes",
"equivalenceSurcharge",
"contractFlows",
"contractHandshake",
507 "grouping",
"fee",
"periodicity",
"contracted" });
509 new String[] {
"id",
"name" },
511 set.addMapping(
Service.class, 2,
512 new String[] {
"id",
"name" },
515 new String[] {
"id",
"name" },
518 new String[] {
"id",
"name" },
521 new String[] {
"allowed" },
522 new String[] {
"documentDefinition",
"store" });
524 new String[] {
"id",
"name" },
527 new String[] {
"id",
"name" },
530 new String[] {
"name",
"interventionType" },
532 set.addMapping(Currency.class, 2,
533 new String[] {
"currencyCode" },
535 set.addMapping(
Tax.class, 2,
536 new String[] {
"taxType",
"tax",
"equivalenceSurcharge" },
539 new String[] {
"description" },
540 new String[] {
"documentDefinition",
"contractExpiries" });
542 new String[] {
"concept",
"daysToAdd",
"dayOfWeek",
"percentValue",
"amountValue" },
543 new String[] {
"documentDefinition",
"lineType",
"daysOfMonth",
"excludedMonths" });
545 new String[] {
"id",
"name" },
548 new String[] {
"name" },
550 set.addMapping(Integer.class, 4,
551 new String[] {
"this" },
554 new String[] {
"remoteId",
"remoteName",
"remoteServer" },
557 new String[] {
"concept",
"price",
"quantity" },
558 new String[] {
"product" });
559 set.addMapping(
Product.class, 3,
560 new String[] {
"id",
"productCode" },
561 new String[] {
"description" });
static long getNewLongIdFromLong(Dao dao, String table, String field)
void addClause(String clause)
void addNamedValue(String name, Object value)
Collection< IContact > getIParticipants()
void setService(Service service)
void setTaxes(Set< Tax > taxes)
Periodicity getPeriodicity()
Set< ContractParticipant > getParticipants()
String getPartialDescription()
Collection< IContact > getIParticipantsEmail()
void setEquivalenceSurcharge(boolean equivalenceSurcharge)
ContractHandshake getContractHandshake()
void setOperatingModifier(OperatingModifier operatingModifier)
Department getDepartment()
ContractDefinition getContractDefinition()
Collection< ContractFlow > getFlowFor(Document document)
void setActive(boolean active)
void setStock(boolean stock)
void setRelatedContractStores(Set< RelatedContractStore > relatedContractStores)
void setDepartment(Department department)
void setStartDate(Date startDate)
void setContractor(String contractor)
void setEndDate(Date endDate)
String getUsualPath(DocumentDefinition documentDefinition)
OperatingModifier getOperatingModifier()
void setName(String name)
void setNotes(String notes)
boolean isEquivalenceSurcharge()
void setContractHandshake(ContractHandshake contractHandshake)
void setGrouping(String grouping)
Set< ContractPreference > getContractPreferences()
Collection< Collection > collections()
void setContractPreferences(Set< ContractPreference > contractPreferences)
void setPeriodicity(Periodicity periodicity)
MappingSet getSerializerMappings()
void setGlobalId(String globalId)
IContact getIContractor()
Set< RelatedContractStore > getRelatedContractStores()
void setCurrency(Currency currency)
void setCash(boolean cash)
List< Document > getDocuments()
void setContracted(Set< Contracted > contracted)
void setParticipants(Set< ContractParticipant > participants)
Set< ContractFlow > getContractFlows()
void setUseContractorCode(boolean useContractorCode)
void setContractDefinition(ContractDefinition contractDefinition)
void setContractFlows(Set< ContractFlow > contractFlows)
Set< Contracted > getContracted()
String getFullDescription()
boolean isUseContractorCode()
DocumentDefinition getDocumentDefinition()
boolean isNotLoaded(Object o, String attribute)
default void prepareSave()