Administrátor nyní může na formuláři objednávky upravovat množství,

jednotkovou cenu nebo celkovou cenu položky. Změnou hodnoty se vyvolá
přepočet částky ve formuláři.
Pro ostatní jsou položky objednávky pouze pro čtení.

closes #150
multitenant
František Přibyl 10 years ago
parent a06b2cbb14
commit 6e62ea2070

@ -1,16 +1,25 @@
package info.bukova.isspst.services.approved;
import java.math.BigDecimal;
import java.util.List;
import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.OrderItem;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.Service;
import java.math.BigDecimal;
import java.util.List;
public interface OrderService extends Service<Order> {
public Order createOrder(List<JoinedItem> items);
public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup);
public BigDecimal calcTotalFromItem(OrderItem item);
public OrderItem calcTotalInItem(OrderItem item);
public OrderItem calcItemValuesFromItemTotal(OrderItem item);
public BigDecimal calcSumTotalFromItems(List<OrderItem> items);
}

@ -4,6 +4,7 @@ import info.bukova.isspst.data.AddressEmb;
import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.OrderItem;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.LazyLoader;
import info.bukova.isspst.services.settings.GlobalSettingsService;
@ -17,8 +18,6 @@ import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.data.Workgroup;
public class OrderServiceImpl extends AbstractOwnedService<Order> implements
OrderService {
@ -99,4 +98,77 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
Hibernate.initialize(o.getItems());
order.setItems(o.getItems());
}
@Override
public BigDecimal calcTotalFromItem(OrderItem item)
{
BigDecimal total = BigDecimal.ZERO;
if (item != null)
{
total = item.getQuantity().multiply(item.getUnitPrice());
}
return total;
}
@Override
public OrderItem calcTotalInItem(OrderItem item)
{
OrderItem newItem = item;
if (newItem != null)
{
BigDecimal total = this.calcTotalFromItem(newItem);
newItem.setTotal(total);
}
return newItem;
}
@Override
public OrderItem calcItemValuesFromItemTotal(OrderItem item)
{
OrderItem 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<OrderItem> items)
{
BigDecimal sumTotal = BigDecimal.ZERO;
if (items != null)
{
for (OrderItem item : items)
{
if (item != null)
{
BigDecimal total = item.getTotal();
if (total != null)
{
sumTotal = sumTotal.add(total);
}
}
}
}
return sumTotal;
}
}

@ -5,22 +5,27 @@ import info.bukova.isspst.data.AddressEmb;
import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.OrderItem;
import info.bukova.isspst.services.addressbook.AdbService;
import info.bukova.isspst.services.approved.OrderService;
import info.bukova.isspst.services.settings.GlobalSettingsService;
import info.bukova.isspst.ui.FormViewModel;
import info.bukova.isspst.validators.OrderFormValidator;
import java.math.BigDecimal;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.SimpleForm;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.impl.InputElement;
public class OrderForm extends FormViewModel<Order>
{
@SuppressWarnings("unused")
private final static Logger log = LoggerFactory.getLogger(OrderForm.class.getName());
@WireVariable
@ -29,6 +34,9 @@ public class OrderForm extends FormViewModel<Order>
@WireVariable
protected GlobalSettingsService settingsService;
@WireVariable
protected OrderService orderService;
protected OrderFormValidator orderFormValidator;
protected OrderItem selectedItem;
@ -41,6 +49,8 @@ public class OrderForm extends FormViewModel<Order>
protected String deliveryCompany;
protected List<OrderItem> syncOrderItems;
@Init(superclass = true)
public void initOrderForm()
{
@ -66,6 +76,8 @@ public class OrderForm extends FormViewModel<Order>
{
this.getDataBean().setAddress(new AddressEmb());
}
this.syncOrderItems = this.getDataBean().getItems();
}
public OrderFormValidator getOrderFormValidator()
@ -143,6 +155,16 @@ public class OrderForm extends FormViewModel<Order>
this.deliveryCompany = deliveryCompany;
}
public List<OrderItem> getSyncOrderItems()
{
return syncOrderItems;
}
public void setSyncOrderItems(List<OrderItem> syncOrderItems)
{
this.syncOrderItems = syncOrderItems;
}
@Command
@NotifyChange("dataBean")
public void doFillSuppAddress()
@ -184,4 +206,50 @@ public class OrderForm extends FormViewModel<Order>
this.getDataBean().setDeliveryAddress(addr);
}
@Command
public void onFocusItem(@BindingParam("item") OrderItem item, @BindingParam("ctrl") InputElement ctrl)
{
// this.selItemIndex = this.getDataBean().getItems().indexOf(item);
this.selectedItem = item;
if (ctrl != null)
{
ctrl.select();
}
}
protected void calcAndUpdateFormTotalPrice(SimpleForm form)
{
if (form != null)
{
BigDecimal sumTotal = orderService.calcSumTotalFromItems(this.getDataBean().getItems());
form.setField("total", sumTotal);
BindUtils.postNotifyChange(null, null, form, "*");
}
}
@Command
@NotifyChange({ "selectedItem", "syncOrderItems" })
public void recalculate(@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;
}
// Recalculate selected item
if ((source != null) && (source.equals("total")))
{
this.selectedItem = orderService.calcItemValuesFromItemTotal(this.selectedItem);
}
else
{
this.selectedItem = orderService.calcTotalInItem(this.selectedItem);
}
// Calculate total price at form
this.calcAndUpdateFormTotalPrice(form);
}
}

@ -1,4 +1,6 @@
<?page title="${labels.Order}" contentType="text/html;charset=UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?taglib uri="/WEB-INF/security.tld" prefix="sec"?>
<zk>
<window
id="editWin"
@ -493,7 +495,7 @@
<listbox
vflex="1"
selectedItem="@bind(vm.selectedItem)"
model="@load(fx.items)">
model="@load(vm.syncOrderItems)">
<listhead menupopup="auto">
<listheader
hflex="7"
@ -536,10 +538,34 @@
<listcell label="@load(each.code)" />
<listcell label="@load(each.name)" />
<listcell label="@load(each.textItem)" />
<listcell label="@load(each.quantity) @converter(vm.standardBigDecimalConverter)" />
<listcell>
<textbox
inplace="true"
sclass="grid-textbox-max-right"
readonly="${not sec:isAllGranted('ROLE_ADMIN')}"
onFocus="@command('onFocusItem', item=each, ctrl=self)"
onChange="@command('recalculate', form=fx, changed='quantity')"
value="@bind(each.quantity) @converter(vm.standardBigDecimalConverter)" />
</listcell>
<listcell label="@load(each.munit.name)" />
<listcell label="@load(each.unitPrice) @converter(vm.standardBigDecimalConverter)" />
<listcell label="@load(each.total) @converter(vm.standardBigDecimalConverter)" />
<listcell>
<textbox
inplace="true"
sclass="grid-textbox-max-right"
readonly="${not sec:isAllGranted('ROLE_ADMIN')}"
onFocus="@command('onFocusItem', item=each, ctrl=self)"
onChange="@command('recalculate', form=fx, changed='unitPrice')"
value="@bind(each.unitPrice) @converter(vm.standardBigDecimalConverter)" />
</listcell>
<listcell>
<textbox
inplace="true"
sclass="grid-textbox-max-right"
readonly="${not sec:isAllGranted('ROLE_ADMIN')}"
onFocus="@command('onFocusItem', item=each, ctrl=self)"
onChange="@command('recalculate', form=fx, changed='total')"
value="@bind(each.total) @converter(vm.standardBigDecimalConverter)" />
</listcell>
<listcell label="@load(each.description)" />
</listitem>
</template>

Loading…
Cancel
Save