19 package org.turro.erp.workorder.valuation;
21 import java.util.Arrays;
22 import org.turro.erp.entity.OrderReference;
23 import org.turro.erp.entity.RequiredUsage;
24 import org.turro.erp.entity.Task;
25 import org.turro.erp.entity.WorkOrder;
26 import org.turro.financials.entity.Company;
27 import org.turro.financials.entity.Department;
28 import org.turro.financials.entity.Headquarters;
29 import org.turro.financials.entity.Service;
30 import org.turro.financials.model.business.CompanyWrapper;
31 import org.turro.math.Round;
32 import org.turro.valuation.*;
43 this.workOrder = workOrder;
45 model.setMarginModes(Arrays.asList(MarginOverCostMode.values()));
46 model.setPriceModes(Arrays.asList(PropossedPriceMode.values()));
52 getChildren().clear();
59 for(Value value :
model.getRootValues()) {
60 if(value.getData() instanceof
NodeData) {
67 private void createModel() {
69 model =
new ValuationModel(
model.getMarginModes(),
model.getPriceModes());
71 model =
new ValuationModel();
74 if(or.isEmpty())
continue;
75 Value vor =
new Value(or.getId() +
"",
"reference", or.getSomeDescription());
76 vor.setData(
new NodeData(
false, or));
77 vor.setOrder(or.getOrderRef());
78 vor.setExpressedUnits(or.getQuantity());
79 if(or.getCustomerOrder() !=
null && or.getCustomerOrder().isWantBudget()) {
80 vor.setOfferedPrice(or.getCustomerOrder().getAmount());
83 for(Task t : or.getTasks()) {
84 Value vt =
new Value(t.getId() +
"",
"task", t.getName());
87 for(RequiredUsage ru : t.getRequiredUsages()) {
89 if(ru.hasResource()) {
90 usage =
new Usage(ru.getResource().getId() +
"",
"resource",
91 ru.getResource().getName());
93 Resource rru =
new Resource(ru.getResourceId() +
"",
95 ru.isHumanResourceType() ? ru.getHumanResourceAptitude().getName() : ru.getName(),
97 rru.setData(
new NodeData(
false, ru));
98 rru.setEstimatedCostUnit(ru.getEstimatedUnitCost());
99 rru.setExpectedCostUnit(ru.getExpectedUnitCost());
100 rru.setEstimatedUnits(ru.getEstimatedUnits());
101 rru.setExpectedUnits(ru.getExpectedUnits());
102 rru.setPriceUnit(ru.getUnitPrice());
103 rru.setRealCostUnit(ru.getRealUnitCost());
104 rru.setRealUnits(ru.getRealUnits());
106 addVariables(rru, t);
112 private void addVariables(Resource resource, Task task) {
113 if(task.getDepartment() !=
null) {
114 Department department = task.getDepartment().getDepartment();
115 resource.addVariableRef(department.getId() +
"",
"b_department", department.getFullName(),
116 department.getStructureMargin(), department.getProfitMargin(), department.isAlwaysApply(), 3);
117 Headquarters headquarters = department.getHeadquarters();
118 resource.addVariableRef(headquarters.getId() +
"",
"b_headquarters", headquarters.getName(),
119 headquarters.getStructureMargin(), headquarters.getProfitMargin(), headquarters.isAlwaysApply(), 2);
120 Company company = headquarters.getCompany();
121 resource.addVariableRef(company.getId() +
"",
"b_company", company.getName(),
122 company.getStructureMargin(), company.getProfitMargin(), company.isAlwaysApply(), 0);
124 if(task.getOrderReference().getService() !=
null) {
125 Service service = task.getOrderReference().getService().getService();
126 resource.addVariableRef(service.getId() +
"",
"b_service", service.getFullName(),
127 service.getStructureMargin(), service.getProfitMargin(), service.isAlwaysApply(), 1);
129 addAlwaysApplyVariables(resource);
132 private void addAlwaysApplyVariables(Resource resource) {
133 Company c = CompanyWrapper.getDefaultCompany();
135 if(c.isAlwaysApply()) {
136 resource.addVariableRef(c.getId() +
"",
"b_company", c.getName(),
137 c.getStructureMargin(), c.getProfitMargin(), c.isAlwaysApply(), 0);
139 for(Service s : c.getServices()) {
140 if(s.isAlwaysApply()) {
141 resource.addVariableRef(s.getId() +
"",
"b_service", s.getFullName(),
142 s.getStructureMargin(), s.getProfitMargin(), s.isAlwaysApply(), 1);
145 for(Headquarters h : c.getHeadquarters()) {
146 if(h.isAlwaysApply()) {
147 resource.addVariableRef(h.getId() +
"",
"b_headquarters", h.getName(),
148 h.getStructureMargin(), h.getProfitMargin(), h.isAlwaysApply(), 2);
150 for(Department d : h.getDepartments()) {
151 if(d.isAlwaysApply()) {
152 resource.addVariableRef(d.getId() +
"",
"b_department", d.getFullName(),
153 d.getStructureMargin(), d.getProfitMargin(), d.isAlwaysApply(), 3);
void setPrice(double price)
Set< OrderReference > getOrderReferences()
void setWorkOrder(WorkOrder workOrder)
Round decimals(int digits)