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