18 package org.turro.financials.model.register;
20 import java.util.Collections;
21 import java.util.HashSet;
23 import org.turro.string.Strings;
24 import org.turro.financials.entity.*;
25 import org.turro.financials.model.AccountFormat;
26 import org.turro.financials.model.business.CompanyWrapper;
27 import org.turro.math.Round;
28 import org.turro.math.Zero;
37 private int fractionDigits;
44 return fractionDigits;
48 if(
register ==
null) {
55 this.
register =
register;
59 if(!
Zero.
near(balance, fractionDigits)) {
69 String accStr =
"%ctd.%ct",
71 accStr = accStr.replaceAll(
"\\%ctd", asCash)
72 .replaceAll(
"\\%ct",
"" + store.
getId());
80 if(
register ==
null) {
89 if(!(
Zero.
near(debit, fractionDigits))) {
94 re.
setDebit(
new Round(debit).decimals(fractionDigits).value());
96 register.getRegisterEntries().add(re);
99 if(!(
Zero.
near(credit, fractionDigits))) {
106 register.getRegisterEntries().add(re);
112 Set<RegisterEntry>
set = addEntries(view, contract, store, lineType, concept, amount);
113 if(
register ==
null) {
118 register.getRegisterEntries().add(re);
124 if(store ==
null || lineType ==
null || amount == 0)
return Collections.EMPTY_SET;
125 HashSet<RegisterEntry>
set =
new HashSet<RegisterEntry>();
127 if(view ==
null || lta.getView() ==
null || lta.getView().getId() == view.
getId()) {
129 String acc = lta.getPattern();
130 if(acc.indexOf(
"%s") > -1) {
139 acc = convertPattern(acc,
"\\%sct", store.
getId() +
"");
140 acc = convertPattern(acc,
"\\%s", store.
getId() +
"");
142 if(acc.indexOf(
"%ct") > -1) {
151 acc = convertPattern(acc,
"\\%ct", contract.
getId() +
"");
153 acc = convertPattern(acc,
"\\%ltv", convertToString(lta.getTypeValue()));
154 account.
setId(AccountFormat.expand(acc));
160 if(lta.getTypeValue() != 0) {
161 extra =
" (" + lta.getTypeValue() +
")";
172 _amount = amount * lta.getCoefficient();
188 private String convertToString(
double value) {
189 return Double.valueOf(value).intValue() +
"";
192 private String convertPattern(String text, String pattern, String value) {
193 int l = value ==
null ? 0 : value.length();
194 if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%1") && l > 1) {
195 return text.replaceAll(pattern +
"\\%1", value.substring(0, 1));
196 }
else if(text.contains(pattern.replaceAll(
"\\\\",
"") +
"%2") && l > 2) {
197 return text.replaceAll(pattern +
"\\%2", value.substring(0, 2));
199 return text.replaceAll(pattern, value);
void setDescription(String description)
ContractPreference getDefaultContractPreference()
ContractDefinition getContractDefinition()
String getFullDescription()
ContractPreference getContractPreference()
Set< LineTypeAccount > getLineTypeAccounts()
void setAccount(Account account)
void setCredit(double credit)
void setRegister(Register register)
void setConcept(String concept)
void roundIt(int fractionDigits)
void setDebit(double debit)
static Currency getCompanyCurrency()
void setRegister(Register register)
void addAccount(Account account, String concept, double balance)
void addAccount(Account account, String concept, double debit, double credit)
void addAccount(Contract store, String concept, double debit, double credit)
Set< RegisterEntry > addAmount(RegisterView view, Contract contract, Contract store, LineType lineType, String concept, double amount)
static boolean near(double value, int digits)