18 package org.turro.financials.product;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.DocumentLine;
26 import org.turro.financials.entity.LineType;
27 import org.turro.financials.entity.Product;
28 import org.turro.financials.entity.ProductByContractor;
29 import org.turro.util.Chars;
38 if(
id < 1)
return null;
43 if(Strings.isBlank(
id))
return null;
45 "select prod from Product prod " +
46 "where prod.productCode = ?",
66 public static IProduct getProduct(
long productId,
long providerId,
long providerProductId, String description) {
67 if(providerProductId > 0) {
76 if(!Strings.isBlank(description)) {
83 if(contractorId < 1 || Strings.isBlank(contractorCode))
return null;
85 wc.
addClause(
"select pbc from ProductByContractor pbc");
86 wc.
addClause(
"where pbc.contract.id = :id");
88 wc.
addClause(
"and pbc.contractorCode = :code");
91 if(l !=
null && !l.isEmpty()) {
98 if(contractorId < 1 || product ==
null)
return;
100 wc.
addClause(
"select pbc from ProductByContractor pbc");
101 wc.
addClause(
"where pbc.contract.id = :id");
103 wc.
addClause(
"and pbc.product.productCode = :code");
106 if(l !=
null && !l.isEmpty()) {
111 public static List<IProduct>
getProducts(
long contractorId, String input) {
112 List<IProduct> list =
new ArrayList<>();
115 if(input.matches(
"\\##.*")) {
116 product =
getProduct(contractorId, input.substring(2));
117 if(product !=
null) list.add(product);
119 }
else if(input.matches(
"\\#.*")) {
121 if(product !=
null) list.add(product);
126 if(product !=
null) list.add(product);
128 if(product !=
null) list.add(product);
139 if(list.size() < 10) {
143 if(list.size() < 10) {
150 String parts[] = text.split(Chars.forward().regexp().spaced().toString());
151 if(parts.length == 2) {
152 if(parts[0].startsWith(
"##")) {
153 return getProduct(contractorId, parts[0].substring(2));
154 }
else if(parts[0].startsWith(
"#")) {
159 }
else if(!Strings.isBlank(text)) {
162 if(text.matches(
"\\##.*")) {
163 prod =
getProduct(contractorId, text.substring(2));
165 }
else if(text.matches(
"\\#.*")) {
void addClause(String clause)
void addNamedValue(String name, Object value)
void setPrice(double price)
double getStockCoefficient()
static List< Product > getProducts()
long getProviderProductId()
String getProductDescription()
static IProduct getProduct(String id)
static IProduct getProduct(long contractorId, String contractorCode)
static IProduct getProduct(long id)
static IProduct getProductFromText(long contractorId, String text)
static void setPriceTax(DocumentLine dl, IProduct prod)
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< IProduct > getProducts(long contractorId, String input)
static IProduct getProduct(IProductKey productKey)
static List< ProductUncoded > getProducts()
Object getSingleResultOrNull(SqlClause sc)
double getProductCostTax()
String getProductCodeStr()
void setProductByContractor(ProductByContractor pbc)
double getProductPriceTax()