18 package org.turro.financials.product;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.List;
24 import org.turro.string.Strings;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.financials.db.FinancialsPU;
27 import org.turro.financials.entity.Contract;
28 import org.turro.financials.entity.ProductByContractor;
36 private String description =
null;
37 private Double cost =
null, costTax =
null, price =
null, priceTax =
null;
42 this.description = description;
46 this.description = description;
47 this.productByContractor = productByContractor;
52 return productByContractor;
57 this.productByContractor = productByContractor;
103 this.description = (String)
id;
107 this.priceTax =
null;
116 wc.
addClause(
"where dl.document.receiptDate = :date");
123 wc.
addClause(
"and dl.productByContractor is null");
124 wc.
addClause(
"and dl.lineType.stockCoefficient <> 0");
126 wc.
addClause(
"and dl.concept = :concept");
144 wc.
addClause(
"select new org.turro.financials.product.Movement");
145 wc.
addClause(
"(dl.document.contract, dl.document.documentDate,");
146 wc.
addClause(
"dl.lineType.stockCoefficient,dl.quantity,dl.price,dl.concept)");
148 wc.
addClause(
"where dl.product is null");
149 wc.
addClause(
"and dl.productByContractor is null");
150 wc.
addClause(
"and dl.concept = :concept");
153 wc.
addClause(
"order by dl.document.receiptDate desc, dl.lineOrder");
160 wc.
addClause(
"select new org.turro.financials.product.Movement");
161 wc.
addClause(
"('Accumulated',coalesce(sum(dl.quantity*dl.lineType.stockCoefficient),0.0),coalesce(sum(dl.quantity*dl.price*dl.lineType.stockCoefficient),0.0))");
163 wc.
addClause(
"where dl.product is null");
168 wc.
addClause(
"and dl.productByContractor is null");
169 wc.
addClause(
"and dl.concept = :concept");
172 wc.
addClause(
"and dl.document.receiptDate < :from2");
174 Collection<Movement> movs =
new FinancialsPU().getResultList(wc);
176 wc.
addClause(
"select new org.turro.financials.product.Movement");
177 wc.
addClause(
"(dl.document.contract, dl.document.documentDate,");
178 wc.
addClause(
"dl.lineType.stockCoefficient,dl.quantity,dl.price,dl.concept)");
180 wc.
addClause(
"where dl.product is null");
185 wc.
addClause(
"and dl.productByContractor is null");
186 wc.
addClause(
"and dl.concept = :concept");
189 wc.
addClause(
"and dl.document.receiptDate >= :from2");
192 wc.
addClause(
"and dl.document.receiptDate <= :to2");
195 wc.
addClause(
"order by dl.document.receiptDate asc, dl.lineOrder");
200 private void loadCostData() {
201 Object d[] = loadData(1);
202 cost = (Double) d[0];
203 costTax = (Double) d[1];
206 private void loadPriceData() {
207 Object d[] = loadData(-1);
208 price = (Double) d[0];
209 priceTax = (Double) d[1];
212 private Object[] loadData(
double coefficient) {
213 WhereClause wc =
new WhereClause();
214 wc.addClause(
"select dl.price, dl.tax");
215 wc.addClause(
"from DocumentLine dl");
216 wc.addClause(
"where dl.product is null");
217 wc.addClause(
"and dl.productByContractor is null");
218 wc.addClause(
"and dl.lineType.stockCoefficient = :coef");
219 wc.addNamedValue(
"coef", coefficient);
220 wc.addClause(
"and dl.concept = :concept");
221 wc.addNamedValue(
"concept", description);
222 wc.addClause(
"and dl.quantity <> 0");
223 wc.addClause(
"order by dl.document.receiptDate desc, dl.lineOrder");
224 List l =
new FinancialsPU().getResultList(wc, 1);
227 d = (Object[]) l.get(0);
229 d =
new Double[] { 0.0, 0.0 };
238 public static List<ProductUncoded>
getProducts(String concept,
boolean equality) {
239 List<ProductUncoded> l =
new ArrayList<ProductUncoded>();
246 public static List<String>
getConcepts(String concept,
boolean equality) {
248 wc.
addClause(
"select distinct dl.concept");
249 getConceptsQuery(wc, concept, equality);
250 List<String> list =
new FinancialsPU().getResultList(wc);
254 private static void getConceptsQuery(
WhereClause wc, String concept,
boolean equality) {
256 wc.
addClause(
"where dl.product is null");
257 wc.
addClause(
"and dl.productByContractor is null");
258 wc.
addClause(
"and dl.lineType.stockCoefficient <> 0");
260 if(!Strings.isBlank(concept)) {
262 wc.
addClause(
"and dl.concept = :concept");
268 wc.
addClause(
"and dl.concept is not null");
void addClause(String clause)
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
double getProductCostTax()
static List< ProductUncoded > getProducts()
static List< String > getConcepts(String concept, boolean equality)
ProductByContractor getProductByContractor()
String getProductCodeStr()
void setProductByContractor(ProductByContractor productByContractor)
ProductUncoded(String description, ProductByContractor productByContractor)
double getProductStock(Date date, Contract store)
String getProductString()
Collection< Movement > getMovements()
Collection< Movement > getMovements(Date from, Date to, Contract store)
ProductUncoded(String description)
static List< ProductUncoded > getProducts(String concept, boolean equality)
double getProductPriceTax()
Object getSingleResultOrNull(SqlClause sc)