Při mazání položek se aktualizuje grid okamžitě.
Výpočty položek a celkové částky přesunuty do RequirementService. BigDecimal converter sjednocen s bází. closes #146
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface RequirementService extends RequirementBaseService<Requirement>
|
||||
{
|
||||
public void loadGroups(Requirement req);
|
||||
|
||||
public BigDecimal calcTotalFromItem(RequirementItem item);
|
||||
|
||||
public RequirementItem calcTotalInItem(RequirementItem item);
|
||||
|
||||
public RequirementItem calcItemValuesFromItemTotal(RequirementItem item);
|
||||
|
||||
public BigDecimal calcSumTotalFromItems(List<RequirementItem> items);
|
||||
}
|
||||
|
||||
+107
-27
@@ -17,9 +17,8 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class RequirementServiceImpl extends
|
||||
RequirementBaseServiceImpl<Requirement> implements RequirementService,
|
||||
RequirementBaseService<Requirement> {
|
||||
public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement>
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private RequirementTypeService reqTypeService;
|
||||
@@ -27,7 +26,8 @@ public class RequirementServiceImpl extends
|
||||
private OrderService orderService;
|
||||
|
||||
@Override
|
||||
protected Requirement createEntity() {
|
||||
protected Requirement createEntity()
|
||||
{
|
||||
Requirement entity = new Requirement();
|
||||
|
||||
entity.setReqDate(new Date());
|
||||
@@ -38,44 +38,51 @@ public class RequirementServiceImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean autoApprove(Requirement entity) {
|
||||
protected boolean autoApprove(Requirement entity)
|
||||
{
|
||||
List<User> approvers = this.getNextApprover(entity);
|
||||
Workflow nextWf = this.getNextWorkflow(entity);
|
||||
|
||||
if (approvers == null || approvers.isEmpty() || nextWf == null || nextWf.getLimit() == null) {
|
||||
|
||||
if (approvers == null || approvers.isEmpty() || nextWf == null || nextWf.getLimit() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1) {
|
||||
|
||||
if (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1)
|
||||
{
|
||||
approve(entity, approvers.get(0));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canAdd(Requirement entity) {
|
||||
if (entity.getWorkgroup() != null
|
||||
&& entity.getWorkgroup().getLimit() != null
|
||||
&& entity.getWorkgroup().getLimit().compareTo(BigDecimal.ZERO) != 0) {
|
||||
|
||||
protected boolean canAdd(Requirement entity)
|
||||
{
|
||||
if (entity.getWorkgroup() != null && entity.getWorkgroup().getLimit() != null && entity.getWorkgroup().getLimit().compareTo(BigDecimal.ZERO) != 0)
|
||||
{
|
||||
|
||||
BigDecimal total = orderService.totalOrderedForWorkgroup(entity.getWorkgroup());
|
||||
|
||||
if (total == null) {
|
||||
|
||||
if (total == null)
|
||||
{
|
||||
total = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
|
||||
total = total.add(entity.getSumTotal());
|
||||
|
||||
if (total.compareTo(entity.getWorkgroup().getLimit()) <= 0) {
|
||||
|
||||
if (total.compareTo(entity.getWorkgroup().getLimit()) <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
throw new AddRequirementException("LimitExceeded");
|
||||
}
|
||||
|
||||
@@ -97,9 +104,9 @@ public class RequirementServiceImpl extends
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Requirement reqDb = this.getById(req.getId());
|
||||
|
||||
|
||||
// Načíst položky požadavku
|
||||
List<RequirementItem> items = reqDb.getItems();
|
||||
|
||||
@@ -128,4 +135,77 @@ public class RequirementServiceImpl extends
|
||||
// materiálů a služeb konzistentní
|
||||
req.setItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal calcTotalFromItem(RequirementItem item)
|
||||
{
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
total = item.getQuantity().multiply(item.getUnitPrice());
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementItem calcTotalInItem(RequirementItem item)
|
||||
{
|
||||
RequirementItem newItem = item;
|
||||
|
||||
if (newItem != null)
|
||||
{
|
||||
BigDecimal total = this.calcTotalFromItem(newItem);
|
||||
newItem.setTotal(total);
|
||||
}
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementItem calcItemValuesFromItemTotal(RequirementItem item)
|
||||
{
|
||||
RequirementItem newItem = item;
|
||||
|
||||
if (newItem != null)
|
||||
{
|
||||
BigDecimal quantity = newItem.getQuantity();
|
||||
|
||||
if (quantity.equals(BigDecimal.ZERO))
|
||||
{
|
||||
newItem.setUnitPrice(BigDecimal.ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
newItem.setUnitPrice(newItem.getTotal().divide(quantity, 2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
}
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal calcSumTotalFromItems(List<RequirementItem> items)
|
||||
{
|
||||
BigDecimal sumTotal = BigDecimal.ZERO;
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
for (RequirementItem item : items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
BigDecimal total = item.getTotal();
|
||||
|
||||
if (total != null)
|
||||
{
|
||||
sumTotal = sumTotal.add(total);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sumTotal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class FormViewModel<T extends DataModel> extends DocumentViewModel
|
||||
private ServiceConstraint<T> constraint;
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("selected") T selected, @ExecutionArgParam("service") Service<T> service)
|
||||
public void initFormViewModel(@ExecutionArgParam("selected") T selected, @ExecutionArgParam("service") Service<T> service)
|
||||
{
|
||||
super.initDocumentViewModel();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ReqMaterialForm extends RequirementForm
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Init(superclass = true)
|
||||
public void init()
|
||||
public void initReqMaterialForm()
|
||||
{
|
||||
// Získat seznam všech skupin materiálu pro výběr z comba
|
||||
this.setRequirementGroups((List<RequirementSubject>) (List<?>) materialService.getAll());
|
||||
|
||||
@@ -9,7 +9,6 @@ import info.bukova.isspst.services.requirement.RequirementService;
|
||||
import info.bukova.isspst.services.requirement.RequirementTypeService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.BigDecimalConverter;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
import info.bukova.isspst.validators.RequirementFormValidator;
|
||||
|
||||
@@ -64,8 +63,6 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
|
||||
private int selItemIndex;
|
||||
|
||||
private BigDecimalConverter bigDecimalConverter;
|
||||
|
||||
private RequirementFormValidator requirementFormValidator;
|
||||
|
||||
private List<RequirementItem> syncItems;
|
||||
@@ -97,16 +94,6 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
this.selItemIndex = selItemIndex;
|
||||
}
|
||||
|
||||
public BigDecimalConverter getBigDecimalConverter()
|
||||
{
|
||||
return bigDecimalConverter;
|
||||
}
|
||||
|
||||
public void setBigDecimalConverter(BigDecimalConverter bigDecimalConverter)
|
||||
{
|
||||
this.bigDecimalConverter = bigDecimalConverter;
|
||||
}
|
||||
|
||||
public RequirementFormValidator getRequirementFormValidator()
|
||||
{
|
||||
return requirementFormValidator;
|
||||
@@ -121,7 +108,6 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
public void initRequirementForm()
|
||||
{
|
||||
this.setSelItemIndex(-1);
|
||||
this.setBigDecimalConverter(new BigDecimalConverter());
|
||||
this.setRequirementFormValidator(new RequirementFormValidator());
|
||||
this.setSyncItems(this.getDataBean().getItems());
|
||||
requirementService.loadType(getDataBean());
|
||||
@@ -150,12 +136,26 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "dataBean", "selItemIndex" })
|
||||
public void removeItem(@BindingParam("item") RequirementItem item)
|
||||
protected void calcAndUpdateFormTotalPrice(SimpleForm form)
|
||||
{
|
||||
this.getDataBean().getItems().remove(item);
|
||||
this.setSelItemIndex(-1);
|
||||
if (form != null)
|
||||
{
|
||||
BigDecimal sumTotal = requirementService.calcSumTotalFromItems(this.getDataBean().getItems());
|
||||
form.setField("sumTotal", sumTotal);
|
||||
BindUtils.postNotifyChange(null, null, form, "*");
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "syncItems", "selItemIndex" })
|
||||
public void removeItem(@BindingParam("form") SimpleForm form, @BindingParam("item") RequirementItem item)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
this.getDataBean().getItems().remove(item);
|
||||
this.setSelItemIndex(-1);
|
||||
this.calcAndUpdateFormTotalPrice(form);
|
||||
}
|
||||
}
|
||||
|
||||
@GlobalCommand("insertSelectedItem")
|
||||
@@ -207,35 +207,15 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
// Recalculate selected item
|
||||
if ((source != null) && (source.equals("total")))
|
||||
{
|
||||
BigDecimal quantity = this.selectedItem.getQuantity();
|
||||
|
||||
if (quantity.equals(BigDecimal.ZERO))
|
||||
{
|
||||
this.selectedItem.setUnitPrice(BigDecimal.ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.selectedItem.setUnitPrice(this.selectedItem.getTotal().divide(quantity, 2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
this.selectedItem = requirementService.calcItemValuesFromItemTotal(this.selectedItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.selectedItem.setTotal(this.selectedItem.getQuantity().multiply(this.selectedItem.getUnitPrice()));
|
||||
this.selectedItem = requirementService.calcTotalInItem(this.selectedItem);
|
||||
}
|
||||
|
||||
// Calculate total price at form
|
||||
if (form != null)
|
||||
{
|
||||
BigDecimal sumTotal = new BigDecimal(0);
|
||||
|
||||
for (RequirementItem item : this.getDataBean().getItems())
|
||||
{
|
||||
sumTotal = sumTotal.add(item.getTotal());
|
||||
}
|
||||
|
||||
form.setField("sumTotal", sumTotal);
|
||||
BindUtils.postNotifyChange(null, null, form, "*");
|
||||
}
|
||||
this.calcAndUpdateFormTotalPrice(form);
|
||||
}
|
||||
|
||||
@Command
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
id="idSumTotal"
|
||||
readonly="true"
|
||||
width="150px"
|
||||
value="@bind(fx.sumTotal) @converter(vm.bigDecimalConverter)" />
|
||||
value="@bind(fx.sumTotal) @converter(vm.standardBigDecimalConverter)" />
|
||||
</cell>
|
||||
</row>
|
||||
<row>
|
||||
@@ -168,7 +168,7 @@
|
||||
sclass="grid-textbox-max-right"
|
||||
onFocus="@command('onFocusItem', item=each, ctrl=self)"
|
||||
onChange="@command('recalculate', form=fx, changed='quantity')"
|
||||
value="@bind(each.quantity) @converter(vm.bigDecimalConverter)" />
|
||||
value="@bind(each.quantity) @converter(vm.standardBigDecimalConverter)" />
|
||||
</listcell>
|
||||
<listcell>
|
||||
<textbox
|
||||
@@ -184,7 +184,7 @@
|
||||
sclass="grid-textbox-max-right"
|
||||
onFocus="@command('onFocusItem', item=each, ctrl=self)"
|
||||
onChange="@command('recalculate', form=fx, changed='unitprice')"
|
||||
value="@bind(each.unitPrice) @converter(vm.bigDecimalConverter)" />
|
||||
value="@bind(each.unitPrice) @converter(vm.standardBigDecimalConverter)" />
|
||||
</listcell>
|
||||
<listcell>
|
||||
<textbox
|
||||
@@ -192,7 +192,7 @@
|
||||
sclass="grid-textbox-max-right"
|
||||
onFocus="@command('onFocusItem', item=each, ctrl=self)"
|
||||
onChange="@command('recalculate', form=fx, changed='total')"
|
||||
value="@bind(each.total) @converter(vm.bigDecimalConverter)" />
|
||||
value="@bind(each.total) @converter(vm.standardBigDecimalConverter)" />
|
||||
</listcell>
|
||||
<listcell>
|
||||
<textbox
|
||||
@@ -207,7 +207,7 @@
|
||||
<button
|
||||
image="~./zul/img/misc/drag-disallow.png"
|
||||
label="${labels.RemoveItem}"
|
||||
onClick="@command('removeItem', item=each, ctrl=self)"
|
||||
onClick="@command('removeItem', item=each, form=fx, ctrl=self)"
|
||||
sclass="nicebutton" />
|
||||
</listcell>
|
||||
</listitem>
|
||||
|
||||
Reference in New Issue
Block a user