BrightSide Workbench Full Report + Source Code
org.turro.financials.product.ProductFactory Class Reference

Static Public Member Functions

static IProduct getProduct (long id)
 
static IProduct getProduct (String id)
 
static IProduct getProduct (long contractorId, String contractorCode)
 
static IProduct getProduct (IProductKey productKey)
 
static IProduct getProduct (long productId, long providerId, long providerProductId, String description)
 
static ProductByContractor getContractorProduct (long contractorId, String contractorCode)
 
static void setContractorProduct (IProduct product, long contractorId)
 
static List< IProductgetProducts (long contractorId, String input)
 
static IProduct getProductFromText (long contractorId, String text)
 
static void setPriceTax (DocumentLine dl, IProduct prod)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 35 of file ProductFactory.java.

Member Function Documentation

◆ getContractorProduct()

static ProductByContractor org.turro.financials.product.ProductFactory.getContractorProduct ( long  contractorId,
String  contractorCode 
)
static

Definition at line 82 of file ProductFactory.java.

82  {
83  if(contractorId < 1 || Strings.isBlank(contractorCode)) return null;
84  WhereClause wc = new WhereClause();
85  wc.addClause("select pbc from ProductByContractor pbc");
86  wc.addClause("where pbc.contract.id = :id");
87  wc.addNamedValue("id", contractorId);
88  wc.addClause("and pbc.contractorCode = :code");
89  wc.addNamedValue("code", contractorCode);
90  List l = new FinancialsPU().getResultList(wc, 1);
91  if(l != null && !l.isEmpty()) {
92  return (ProductByContractor) l.get(0);
93  }
94  return null;
95  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProduct() [1/5]

static IProduct org.turro.financials.product.ProductFactory.getProduct ( IProductKey  productKey)
static

Definition at line 61 of file ProductFactory.java.

61  {
62  return getProduct(productKey.getProductId(), productKey.getProviderId(),
63  productKey.getProviderProductId(), productKey.getProductDescription());
64  }
Here is the call graph for this function:

◆ getProduct() [2/5]

static IProduct org.turro.financials.product.ProductFactory.getProduct ( long  contractorId,
String  contractorCode 
)
static

Definition at line 51 of file ProductFactory.java.

51  {
52  IProduct product = null;
53  ProductByContractor pbc = getContractorProduct(contractorId, contractorCode);
54  if(pbc != null) {
55  product = pbc.getProduct();
56  product.setProductByContractor(pbc);
57  }
58  return product;
59  }
static ProductByContractor getContractorProduct(long contractorId, String contractorCode)
Here is the call graph for this function:

◆ getProduct() [3/5]

static IProduct org.turro.financials.product.ProductFactory.getProduct ( long  id)
static

Definition at line 37 of file ProductFactory.java.

37  {
38  if(id < 1) return null;
39  return new FinancialsPU().find(Product.class, (Long) id);
40  }
Here is the caller graph for this function:

◆ getProduct() [4/5]

static IProduct org.turro.financials.product.ProductFactory.getProduct ( long  productId,
long  providerId,
long  providerProductId,
String  description 
)
static

Definition at line 66 of file ProductFactory.java.

66  {
67  if(providerProductId > 0) {
68  ProductByContractor pbc = new FinancialsPU().find(ProductByContractor.class, providerProductId);
69  if(pbc != null) {
70  return pbc.getProduct();
71  }
72  }
73  if(productId > 0) {
74  return getProduct(productId);
75  }
76  if(!Strings.isBlank(description)) {
77  return getProductFromText(providerId, description);
78  }
79  return null;
80  }
static IProduct getProductFromText(long contractorId, String text)
Here is the call graph for this function:

◆ getProduct() [5/5]

static IProduct org.turro.financials.product.ProductFactory.getProduct ( String  id)
static

Definition at line 42 of file ProductFactory.java.

42  {
43  if(Strings.isBlank(id)) return null;
44  return (IProduct) new FinancialsPU().getSingleResultOrNull(
45  "select prod from Product prod " +
46  "where prod.productCode = ?",
47  new Object[] { id }
48  );
49  }
Here is the call graph for this function:

◆ getProductFromText()

static IProduct org.turro.financials.product.ProductFactory.getProductFromText ( long  contractorId,
String  text 
)
static

Definition at line 149 of file ProductFactory.java.

149  {
150  String parts[] = text.split(Chars.forward().regexp().spaced().toString());
151  if(parts.length == 2) { // program generated
152  if(parts[0].startsWith("##")) {
153  return getProduct(contractorId, parts[0].substring(2));
154  } else if(parts[0].startsWith("#")) {
155  IProduct prod = getProduct(parts[0].substring(1));
156  setContractorProduct(prod, contractorId);
157  return prod;
158  }
159  } else if(!Strings.isBlank(text)) { // manual input
160  IProduct prod;
161  // Contractor coded
162  if(text.matches("\\##.*")) {
163  prod = getProduct(contractorId, text.substring(2));
164  // Coded
165  } else if(text.matches("\\#.*")) {
166  prod = getProduct(text.substring(1));
167  setContractorProduct(prod, contractorId);
168  // Coded or Contractor coded
169  } else {
170  prod = getProduct(text);
171  setContractorProduct(prod, contractorId);
172  if(prod == null) {
173  prod = getProduct(contractorId, text);
174  }
175  }
176  if(prod != null) {
177  return prod;
178  }
179  return new ProductUncoded(text);
180  }
181  return null;
182  }
static void setContractorProduct(IProduct product, long contractorId)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProducts()

static List<IProduct> org.turro.financials.product.ProductFactory.getProducts ( long  contractorId,
String  input 
)
static

Definition at line 111 of file ProductFactory.java.

111  {
112  List<IProduct> list = new ArrayList<>();
113  IProduct product;
114  // Contractor coded
115  if(input.matches("\\##.*")) {
116  product = getProduct(contractorId, input.substring(2));
117  if(product != null) list.add(product);
118  // Coded
119  } else if(input.matches("\\#.*")) {
120  product = getProduct(input.substring(1));
121  if(product != null) list.add(product);
122  // Coded or Contractor coded
123  } else {
124  product = getProduct(input);
125  setContractorProduct(product, contractorId);
126  if(product != null) list.add(product);
127  product = getProduct(contractorId, input);
128  if(product != null) list.add(product);
129  }
130  // Product description
131  if(list.isEmpty()) {
132  list.addAll(Product.getProducts(input, true));
133  }
134  // Concept description
135  if(list.isEmpty()) {
136  list.addAll(ProductUncoded.getProducts(input, true));
137  }
138  // Product similarities
139  if(list.size() < 10) {
140  list.addAll(Product.getProducts(input, false));
141  }
142  // Concept similarities
143  if(list.size() < 10) {
144  list.addAll(ProductUncoded.getProducts(input, false));
145  }
146  return list;
147  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setContractorProduct()

static void org.turro.financials.product.ProductFactory.setContractorProduct ( IProduct  product,
long  contractorId 
)
static

Definition at line 97 of file ProductFactory.java.

97  {
98  if(contractorId < 1 || product == null) return;
99  WhereClause wc = new WhereClause();
100  wc.addClause("select pbc from ProductByContractor pbc");
101  wc.addClause("where pbc.contract.id = :id");
102  wc.addNamedValue("id", contractorId);
103  wc.addClause("and pbc.product.productCode = :code");
104  wc.addNamedValue("code", product.getProductCodeStr());
105  List l = new FinancialsPU().getResultList(wc, 1);
106  if(l != null && !l.isEmpty()) {
107  product.setProductByContractor((ProductByContractor) l.get(0));
108  }
109  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPriceTax()

static void org.turro.financials.product.ProductFactory.setPriceTax ( DocumentLine  dl,
IProduct  prod 
)
static

Definition at line 184 of file ProductFactory.java.

184  {
185  if(dl.getPrice() == 0.0 && dl.getTax() == 0.0) {
186  LineType lt = dl.getLineType();
187  if(lt != null) {
188  if(lt.getStockCoefficient() == -1) {
189  dl.setPrice(prod.getProductPrice());
190  dl.setTax(prod.getProductPriceTax());
191  } else if(lt.getStockCoefficient() == 1) {
192  dl.setPrice(prod.getProductCost());
193  dl.setTax(prod.getProductCostTax());
194  }
195  }
196  }
197  }
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: