|
|
|
@ -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>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void calcAndUpdateFormTotalPrice(SimpleForm form)
|
|
|
|
|
{
|
|
|
|
|
if (form != null)
|
|
|
|
|
{
|
|
|
|
|
BigDecimal sumTotal = requirementService.calcSumTotalFromItems(this.getDataBean().getItems());
|
|
|
|
|
form.setField("sumTotal", sumTotal);
|
|
|
|
|
BindUtils.postNotifyChange(null, null, form, "*");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
|
@NotifyChange({ "dataBean", "selItemIndex" })
|
|
|
|
|
public void removeItem(@BindingParam("item") RequirementItem item)
|
|
|
|
|
@NotifyChange({ "syncItems", "selItemIndex" })
|
|
|
|
|
public void removeItem(@BindingParam("form") SimpleForm form, @BindingParam("item") RequirementItem item)
|
|
|
|
|
{
|
|
|
|
|
this.getDataBean().getItems().remove(item);
|
|
|
|
|
this.setSelItemIndex(-1);
|
|
|
|
|
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
|
|
|
|
|