18 package org.turro.financials.model;
20 import java.util.Collections;
21 import java.util.HashSet;
23 import org.turro.string.Strings;
24 import org.turro.financials.entity.*;
32 private final Contract contract, store;
38 this.documentLine = documentLine;
40 this.store = documentLine.
getStore();
47 if(store ==
null || lineType ==
null || documentLine.
getSubtotal() == 0)
return Collections.EMPTY_SET;
49 HashSet<RegisterEntry>
set =
new HashSet<>();
51 if((view ==
null || lta.getView() ==
null || lta.getView().
getId() == view.
getId()) &&
54 String acc = lta.getPattern();
55 if(acc.contains(
"%s")) {
57 !acc.contains(
"%sctt") && !acc.contains(
"%sctr")) {
65 acc = convertPattern(acc,
"\\%sct", store.
getId() +
"");
66 acc = convertPattern(acc,
"\\%s", store.
getId() +
"");
68 if(acc.contains(
"%ct")) {
70 !acc.contains(
"%ctt") && !acc.contains(
"%ctr") && !acc.contains(
"%ctq")) {
74 acc = convertPattern(acc,
"\\%cte", contractPreference.
getAsOperating(contract));
76 acc = convertPattern(acc,
"\\%ctt", contractPreference.
getAsTax(contract));
77 acc = convertPattern(acc,
"\\%ctr", contractPreference.
getAsRetention(contract));
78 acc = convertPattern(acc,
"\\%ct", contract.
getId() +
"");
80 acc = convertPattern(acc,
"\\%ltv", convertToString(lta.getTypeValue()));
81 acc = convertPattern(acc,
"\\%ldv", convertToString(documentLine.
getTax()));
83 acc = convertPattern(acc,
"\\%ldr", convertToString(documentLine.
getRetention()));
90 if(lta.getTypeValue() != 0) {
91 extra =
" (" + lta.getTypeValue() +
")";
92 }
else if(documentLine.
getTax() != 0) {
93 extra =
" (" + documentLine.
getTax() +
")";
96 if(lta.getTypeValue() != 0) {
97 extra =
" (" + lta.getTypeValue() +
")";
102 if(lta.getTypeValue() != 0) {
103 extra =
" (" + lta.getTypeValue() +
")";
117 amount =
getAmount(documentLine) * lta.getCoefficient();
120 amount =
getTaxable(documentLine) * lta.getCoefficient();
122 if(lta.getTypeValue() == 0 || lta.getTypeValue() == documentLine.
getTax()) {
124 amount =
getTaxValue(documentLine) * lta.getCoefficient();
132 if(lta.getTypeValue() == 0 || lta.getTypeValue() == documentLine.
getRetention()) {
134 amount =
getRetained(documentLine) * lta.getCoefficient();
138 amount =
getDiscount(documentLine) * lta.getCoefficient();
150 bookDefs.add(bf.
getId());
160 private String convertToString(
double value) {
164 private String convertPattern(String text, String pattern, String value) {
165 int l = value ==
null ? 0 : value.length();
166 if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%1") && l > 1) {
167 return text.replaceAll(pattern +
"\\%1", value.substring(0, 1));
168 }
else if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%2") && l > 2) {
169 return text.replaceAll(pattern +
"\\%2", value.substring(0, 2));
170 }
else if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%3") && l > 3) {
171 return text.replaceAll(pattern +
"\\%3", value.substring(0, 3));
173 if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%-1") && l > 1) {
174 return text.replaceAll(pattern +
"\\%-1", value.substring(1));
175 }
else if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%-2") && l > 2) {
176 return text.replaceAll(pattern +
"\\%-2", value.substring(2));
177 }
else if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%-3") && l > 3) {
178 return text.replaceAll(pattern +
"\\%-3", value.substring(3));
180 return value ==
null ? text : text.replaceAll(pattern, value);
void setDescription(String description)
ContractPreference getDefaultContractPreference()
ContractDefinition getContractDefinition()
OperatingModifier getOperatingModifier()
String getFullDescription()
Double getEquivalenceSurchargeValue()
ContractPreference getContractPreference()
double getEquivalenceSurcharge()
Set< LineTypeAccount > getLineTypeAccounts()
BookDefinition getBookDefinition()
void setAccount(Account account)
void setCredit(double credit)
void setConcept(String concept)
void setDebit(double debit)
static String convertToString(double value)
AccountsForDocumentLine(DocumentLine documentLine)
double getSubtotal(DocumentLine line)
double getRetained(DocumentLine line)
Set< RegisterEntry > getEntries(RegisterView view, Set< Long > bookDefs)
double getDiscount(DocumentLine line)
Double getTaxValue(DocumentLine line)
Double getTaxable(DocumentLine line)
Double getEquivalenceSurchargeValue(DocumentLine line)
Double getAmount(DocumentLine line)