19 package org.turro.financials.entity;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.HashSet;
25 import javax.persistence.Column;
26 import javax.persistence.ElementCollection;
27 import javax.persistence.Entity;
28 import javax.persistence.FetchType;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.ManyToOne;
33 import org.amic.util.date.CheckDate;
34 import org.turro.financials.model.contract.ContractUsualSet;
35 import org.turro.financials.model.contract.ContractWrapper;
36 import org.turro.financials.model.document.AmountTaxable;
37 import org.turro.financials.model.document.DocumentDefinitionWrapper;
38 import org.turro.jpa.entity.IDaoEntity;
39 import org.turro.scheduler.constraints.WeekDay;
49 @GeneratedValue(strategy=GenerationType.IDENTITY)
50 @Column(name=
"IDENTIFIER")
62 private String concept;
64 private int daysToAdd, dayOfWeek;
66 private double percentValue, amountValue;
68 @ElementCollection(fetch=FetchType.EAGER)
69 private Set<Integer> daysOfMonth =
new HashSet<Integer>();
71 @ElementCollection(fetch=FetchType.EAGER)
72 private Set<Integer> excludedMonths =
new HashSet<Integer>();
87 this.contractFlow = contractFlow;
91 return documentDefinition;
95 this.documentDefinition = documentDefinition;
103 this.lineType = lineType;
111 this.concept = concept;
119 this.daysToAdd = daysToAdd;
127 this.daysOfMonth = daysOfMonth;
135 this.dayOfWeek = dayOfWeek;
139 return excludedMonths;
143 this.excludedMonths = excludedMonths;
151 this.percentValue = percentValue;
159 this.amountValue = amountValue;
171 return documentDefinition ==
null ||
172 (percentValue == 0.0d && amountValue == 0.0d);
187 pendingAmount =
appendAmount(document, ndoc, getStore(ndoc), pendingAmount);
192 return pendingAmount;
195 private Date newDate(Date date) {
196 CheckDate d =
new CheckDate(date);
197 d.addDays(daysToAdd);
198 boolean correct =
false;
200 while(isExcluded(d)) {
203 if(!daysOfMonth.isEmpty()) {
204 boolean done =
false;
206 for(Integer i : daysOfMonth) {
207 done = i == d.getDay();
210 if(!done) d.addDays(1);
214 while(d.getDayOfWeek() != WeekDay.map(dayOfWeek)) {
218 correct = !isExcluded(d);
223 private boolean isExcluded(CheckDate d) {
224 for(Integer i : excludedMonths) {
225 if(d.getMonth() == i)
return true;
236 if(concept !=
null) {
237 dl.
setConcept(concept +
" [" + at.getTax() +
"]");
239 pendingAmount = assignAmount(dl, getAmount(at.getAmount()), pendingAmount);
250 if(concept !=
null) {
253 pendingAmount = assignAmount(dl, getAmount(source.
getTotalAmount()), pendingAmount);
260 return pendingAmount;
263 private double getAmount(
double amount) {
264 if(amountValue != 0.0d) {
267 if(percentValue != 0.0d) {
268 return amount * percentValue;
273 private Contract getStore(Document document) {
274 Collection<Contract> stores =
new DocumentDefinitionWrapper(documentDefinition)
275 .getRelatedStores(contractFlow.getContract());
276 if(stores.isEmpty()) {
277 stores =
new DocumentDefinitionWrapper(documentDefinition)
280 ContractWrapper.clearInactives(stores);
281 return stores.isEmpty() ? null :
new ContractUsualSet(stores,
true, document.getUsualPath() +
"st:").iterator().next();
284 private double assignAmount(DocumentLine dl,
double amount,
double pendingAmount) {
285 if(amount > pendingAmount) {
286 amount = pendingAmount;
289 pendingAmount -= amount;
290 return pendingAmount;
Set< Integer > getDaysOfMonth()
void setDaysToAdd(int daysToAdd)
void setDayOfWeek(int dayOfWeek)
void setLineType(LineType lineType)
void setAmountValue(double amountValue)
void setContractFlow(ContractFlow contractFlow)
ContractFlow getContractFlow()
void setDocumentDefinition(DocumentDefinition documentDefinition)
void setDaysOfMonth(Set< Integer > daysOfMonth)
double generateFlow(Document document, double pendingAmount, int count)
double appendAmount(Document source, Document destination, Contract store, double pendingAmount)
void setExcludedMonths(Set< Integer > excludedMonths)
void setConcept(String concept)
Set< Integer > getExcludedMonths()
void setPercentValue(double percentValue)
DocumentDefinition getDocumentDefinition()
void setStore(Contract store)
void setLineOrder(int lineOrder)
void setContractPreference(ContractPreference contractPreference)
void setLineType(LineType lineType)
void setDocument(Document document)
void setConcept(String concept)
void setDescendant(Document descendant)
void setAncestor(Document ancestor)
void setDocumentNumber(String documentNumber)
void setDocumentDate(Date documentDate)
Set< DocumentRelation > getDescendants()
void setContract(Contract contract)
String getDocumentNumber()
void setDraft(boolean draft)
void setCurrency(Currency currency)
ContractPreference getDefaultContractPreference()
Set< DocumentLine > getDocumentLines()
void setDocumentDefinition(DocumentDefinition documentDefinition)
void setReceiptDate(Date receiptDate)
void setNotes(String notes)
DocumentAmounts getAmounts()
AmountTaxableSet getTaxables()