18 package org.turro.erp.entity;
20 import java.util.Date;
21 import java.util.EnumSet;
22 import java.util.HashSet;
24 import javax.persistence.*;
25 import org.turro.string.Strings;
26 import org.turro.erp.db.ErpPU;
27 import org.turro.erp.resource.ResourceAptitude;
28 import org.turro.erp.task.UsageValuation;
29 import org.turro.financials.db.FinancialsPU;
30 import org.turro.financials.entity.Contract;
31 import org.turro.financials.entity.LineType;
32 import org.turro.financials.entity.Product;
33 import org.turro.financials.entity.ProductByContractor;
34 import org.turro.financials.entity.RegisterView;
35 import org.turro.financials.model.document.LineTypeDescription;
36 import org.turro.financials.product.IProduct;
37 import org.turro.financials.product.ProductFactory;
38 import org.turro.hr.humanres.HumanResourceAptitude;
39 import org.turro.jpa.Dao;
40 import org.turro.jpa.entity.CachedEntity;
41 import org.turro.math.Zero;
42 import org.turro.util.PhraseBuilder;
52 @GeneratedValue(strategy=GenerationType.IDENTITY)
53 @Column(name=
"IDENTIFIER")
56 private double units, cost, price, dedication, purchaseLag;
58 private long providerId, providerProductId, productId, lineTypeId, contractPreferenceId, viewId;
60 private boolean providerFixed, costMaximum, canChange, representHours;
62 private String productDescription;
66 private String description;
69 private org.turro.erp.entity.Task task;
72 private org.turro.erp.entity.HumanResource humanResource;
75 private org.turro.erp.entity.Resource resource;
85 @Temporal(value = TemporalType.DATE)
86 private Date purchaseDate;
89 private org.turro.erp.entity.Task purchaseTask;
91 @OneToMany(mappedBy =
"requiredUsage", fetch = FetchType.LAZY)
92 private Set<OrderItem> orderItems =
new HashSet<OrderItem>();
107 this.costMaximum = costMaximum;
115 this.dedication = dedication;
123 this.description = description;
135 return aptitudeDegree;
139 this.aptitudeDegree = aptitudeDegree;
143 return aptitudeAssesment;
147 this.aptitudeAssesment = aptitudeAssesment;
155 this.canChange = canChange;
159 return humanResource;
163 this.humanResource = resource;
169 orderItems = dao.lazyLoader(
RequiredUsage.class,
this,
"orderItems").orderItems;
177 orderItems = dao.lazyLoader(
RequiredUsage.class,
this,
"orderItems").orderItems;
183 this.orderItems = orderItems;
195 return productDescription;
199 this.productDescription = productDescription;
207 this.productId = productId;
211 return providerFixed;
215 this.providerFixed = providerFixed;
223 this.providerId = providerId;
227 return providerProductId;
231 this.providerProductId = providerProductId;
243 this.lineTypeId = lineTypeId;
247 return contractPreferenceId;
251 this.contractPreferenceId = contractPreferenceId;
255 this.purchaseDate = purchaseDate;
263 this.purchaseLag = purchaseLag;
271 this.purchaseMode = purchaseMode;
279 this.purchaseTask = purchaseTask;
283 return representHours;
287 this.representHours = representHours;
295 this.resource = resource;
319 this.viewId = viewId;
324 private transient CachedEntity<Contract, Long> provider =
325 new CachedEntity<Contract, Long>() {
327 protected Dao createDao() {
333 return provider.getEntity(providerId);
337 providerId = this.provider.setEntity(provider);
340 private transient CachedEntity<Product, Long> product =
341 new CachedEntity<Product, Long>() {
343 protected Dao createDao() {
349 return product.getEntity(productId);
353 productId = this.product.setEntity(product);
361 if(product !=
null) {
366 productId = ((
Product) product).getId();
376 private transient CachedEntity<ProductByContractor, Long> providerProduct =
377 new CachedEntity<ProductByContractor, Long>() {
379 protected Dao createDao() {
385 return providerProduct.getEntity(providerProductId);
389 providerProductId = this.providerProduct.setEntity(providerProduct);
392 private transient CachedEntity<LineType, Long> lineType =
393 new CachedEntity<LineType, Long>() {
395 protected Dao createDao() {
401 LineType lt = lineType.getEntity(lineTypeId);
407 lineTypeId = this.lineType.setEntity(lineType);
410 private transient CachedEntity<RegisterView, Long> view =
411 new CachedEntity<RegisterView, Long>() {
413 protected Dao createDao() {
419 return view.getEntity(viewId);
423 viewId = this.view.setEntity(view);
431 return ((providerProductId > 0 || productId > 0) ||
432 !Strings.isEmpty(productDescription)) ||
preparedType == 2;
436 return (humanResource !=
null && aptitudeDegree !=
null) ||
preparedType == 1;
444 providerProductId = 0;
452 humanResource =
null;
453 aptitudeDegree =
null;
477 PhraseBuilder pb =
new PhraseBuilder();
488 pb.addWord(
"(" + ltype +
")");
490 return pb.toString();
515 aptitudeAssesment ==
null ? aptitudeDegree : aptitudeAssesment);
530 return this.humanResource !=
null &&
531 ((this.humanResource.
getId() == humanResource.
getId()) ||
532 humanResource.
fits(aptitudeDegree,
new Date()));
536 return (humanResource !=
null && humanResource.
isInternal()) ||
540 private transient double orderUnits = 0.0d;
547 this.orderUnits = orderUnits;
609 if(realUnits == 0.0d) {
610 if(expectedUnits != 0.0d) {
616 if(realUnits >= estimatedUnits) {
668 double q = 0.0d, d = 0.0d;
672 d += oi.getUnits() * oi.getDedication();
675 return q != 0.0d ? d / q : 1.0d;
679 double q = 0.0d, d = 0.0d;
684 d += ri.getUnits() * ri.getDedication();
688 return q != 0.0d ? d / q : 1.0d;
693 return (units * dedication) + (
718 q += oi.getUnits() * oi.getDedication();
719 if(oi.getRelated() !=
null) {
720 q += oi.getRelated().getUnits() * oi.getRelated().getDedication();
734 if(oi.getRelated() !=
null) {
735 q += oi.getRelated().getAmount();
744 q += oi.getRealUnits();
745 if(oi.getRelated() !=
null) {
746 q += oi.getRelated().getRealUnits();
756 return Double.isNaN(result) ? 0.0d : result;
762 q += oi.getRealAmount();
763 if(oi.getRelated() !=
null) {
764 q += oi.getRelated().getRealAmount();
791 if(mostRealCost == 0.0) {
794 if(mostRealCost == 0.0) {
boolean fits(IContact contact)
void setDocumentDate(Date documentDate)
void setDescription(String description)
void setCost(double cost)
void setDocumentNumber(String documentNumber)
void setDelivery(Date delivery)
void setProviderProductId(long providerProductId)
void setUnits(double units)
void setDedication(double dedication)
void setProductDescription(String productDescription)
void setSent(boolean sent)
void setProviderId(long providerId)
void setRequiredUsage(RequiredUsage requiredUsage)
void setProductId(long productId)
void setCostMaximum(boolean costMaximum)
void setProviderFixed(boolean providerFixed)
void setMaxCost(double maxCost)
void setHumanResource(HumanResource humanResource)
void setRelated(OrderItem related)
void setResource(Resource resource)
void setHumanResource(HumanResource resource)
void setProduct(Product product)
double getEstimatedPrice()
AptitudeDegree getAptitudeDegree()
void setResource(Resource resource)
PurchaseMode getPurchaseMode()
double getExpectedUnits()
void setCostMaximum(boolean costMaximum)
void setHumanResourceAptitude(HumanResourceAptitude hro)
void setProviderFixed(boolean providerFixed)
double getExpectedDuration()
double getExpectedDedication()
boolean fits(HumanResource humanResource)
void setOrderItems(Set< OrderItem > orderItems)
void setPurchaseDate(Date purchaseDate)
long getProviderProductId()
double getEstimatedDuration()
void setLineType(LineType lineType)
void setProductId(long productId)
void setPurchaseMode(PurchaseMode purchaseMode)
void setView(RegisterView view)
void setUnits(double units)
void setAptitudeAssesment(AptitudeDegree aptitudeAssesment)
void setResourceAptitude(ResourceAptitude ro)
double getEstimatedUnits()
void setProductDescription(String productDescription)
ProductByContractor getProviderProduct()
void setPrice(double price)
HumanResource getHumanResource()
void setProviderProductId(long providerProductId)
void setProviderId(long providerId)
HumanResourceAptitude getHumanResourceAptitude()
double convertToReal(double convertedUnits)
AptitudeDegree getAptitudeAssesment()
boolean isHumanResourceType()
void setDedication(double dedication)
void setPurchaseLag(double purchaseLag)
transient int preparedType
boolean isProviderFixed()
boolean isRepresentHours()
void setDescription(String description)
HumanResourceAptitude getHumanResourceAptitudeAssest()
void setContractPreferenceId(long contractPreferenceId)
String getProductDescription()
Set< OrderItem > getOrderItems()
void prepareHumanResource()
OrderItem startOrder(double orderUnits)
Set< OrderItem > getUpdatedOrderItems()
double getProposedPrice()
void setAptitudeDegree(AptitudeDegree aptitudeDegree)
void setOrderUnits(double orderUnits)
double getEstimatedUnitCost()
void setIProduct(IProduct product)
void setCost(double cost)
double getExpectedUnitCost()
ResourceAptitude getResourceAptitude()
long getContractPreferenceId()
void setLineTypeId(long lineTypeId)
double getCalculatedUnitCost()
double getEstimatedCost()
void setViewId(long viewId)
void setPurchaseTask(Task purchaseTask)
double getRealDedication()
void setProviderProduct(ProductByContractor providerProduct)
void setRepresentHours(boolean representHours)
void setProvider(Contract provider)
void setCanChange(boolean canChange)
AptitudeDegree getAptitudeDegree()
void setContractPreference(ContractPreference contractPreference)
static IProduct getProduct(long id)
HumanResource getHumanResource()
AptitudeDegree getAptitudeDegree()
boolean isNotLoaded(Object o, String attribute)
static boolean near(double value, int digits)
String getProductString()
String getProductCodeStr()
ProductByContractor getProductByContractor()
void setProductByContractor(ProductByContractor pbc)