Fakturovaná částka na objednávkách se nyní počítá z položek.

closes #152, #154
This commit is contained in:
2014-10-15 21:51:39 +02:00
parent 5b380386bd
commit 18920701a7
12 changed files with 107 additions and 4 deletions
@@ -301,8 +301,9 @@ public class Order extends BaseData implements Cloneable
if (rItem != null)
{
String orderNum = rItem.getOrderNum();
boolean isIncluded = !((orderNum == null) || (orderNum.isEmpty()));
return isIncluded;
boolean isIncluded = ((orderNum != null) && !orderNum.isEmpty());
boolean isFromAnotherOrder = (isIncluded && !this.numser.equals(orderNum));
return isFromAnotherOrder;
}
}
@@ -45,6 +45,9 @@ public class OrderItem {
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "TOTALINVOICE", precision = 15, scale = 4)
private BigDecimal totalInvoice;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "REQUIREMENT_ITEM_ID")
private RequirementItem reqItem;
@@ -68,6 +71,7 @@ public class OrderItem {
this.munit = reqItem.getMunit();
this.total = reqItem.getTotal();
this.description = reqItem.getDescription();
this.totalInvoice = BigDecimal.ZERO;
}
public int getId() {
@@ -142,6 +146,16 @@ public class OrderItem {
this.description = description;
}
public BigDecimal getTotalInvoice()
{
return totalInvoice;
}
public void setTotalInvoice(BigDecimal totalInvoice)
{
this.totalInvoice = totalInvoice;
}
public RequirementItem getReqItem() {
return reqItem;
}
@@ -22,5 +22,7 @@ public interface OrderService extends Service<Order> {
public BigDecimal calcSumTotalFromItems(List<OrderItem> items);
public BigDecimal calcSumTotalInvoiceFromItems(List<OrderItem> items);
public void updateApprovedItems(Order order, boolean orderedChanged);
}
@@ -177,6 +177,30 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
return sumTotal;
}
@Override
public BigDecimal calcSumTotalInvoiceFromItems(List<OrderItem> items)
{
BigDecimal sumTotal = BigDecimal.ZERO;
if (items != null)
{
for (OrderItem item : items)
{
if (item != null)
{
BigDecimal total = item.getTotalInvoice();
if (total != null)
{
sumTotal = sumTotal.add(total);
}
}
}
}
return sumTotal;
}
@Transactional
public void updateApprovedItems(Order order, boolean orderedChanged)
{
@@ -278,6 +278,36 @@ public class OrderForm extends FormViewModel<Order>
this.calcAndUpdateFormTotalPrice(form);
}
protected void calcAndUpdateFormTotalInvoicePrice(SimpleForm form)
{
if (form != null)
{
BigDecimal sumTotal = orderService.calcSumTotalInvoiceFromItems(this.getDataBean().getItems());
form.setField("invoiceTotal", sumTotal);
BindUtils.postNotifyChange(null, null, form, "*");
}
}
@Command
@NotifyChange({ "selectedItem", "syncOrderItems" })
public void recalculateTotalInvoice(@BindingParam("form") SimpleForm form, @BindingParam("changed") String source)
{
if (this.selectedItem == null)
{
log.warn("Zavolat z formuláře onFocus pro nastavení vybrané položky!");
return;
}
if ((source != null) && (source.equals("totalInvoice")))
{
// Calculate total price at form
this.calcAndUpdateFormTotalInvoicePrice(form);
return;
}
log.warn("Dopracovat přepočet fakturované částky objednávky i pro další případy!");
}
@Override
protected void doSave()
{