@ -5,22 +5,27 @@ import info.bukova.isspst.data.AddressEmb;
import info.bukova.isspst.data.Order ;
import info.bukova.isspst.data.Order ;
import info.bukova.isspst.data.OrderItem ;
import info.bukova.isspst.data.OrderItem ;
import info.bukova.isspst.services.addressbook.AdbService ;
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.services.settings.GlobalSettingsService ;
import info.bukova.isspst.ui.FormViewModel ;
import info.bukova.isspst.ui.FormViewModel ;
import info.bukova.isspst.validators.OrderFormValidator ;
import info.bukova.isspst.validators.OrderFormValidator ;
import java.math.BigDecimal ;
import java.util.List ;
import java.util.List ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
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.Command ;
import org.zkoss.bind.annotation.Init ;
import org.zkoss.bind.annotation.Init ;
import org.zkoss.bind.annotation.NotifyChange ;
import org.zkoss.bind.annotation.NotifyChange ;
import org.zkoss.zk.ui.select.annotation.WireVariable ;
import org.zkoss.zk.ui.select.annotation.WireVariable ;
import org.zkoss.zul.impl.InputElement ;
public class OrderForm extends FormViewModel < Order >
public class OrderForm extends FormViewModel < Order >
{
{
@SuppressWarnings ( "unused" )
private final static Logger log = LoggerFactory . getLogger ( OrderForm . class . getName ( ) ) ;
private final static Logger log = LoggerFactory . getLogger ( OrderForm . class . getName ( ) ) ;
@WireVariable
@WireVariable
@ -29,6 +34,9 @@ public class OrderForm extends FormViewModel<Order>
@WireVariable
@WireVariable
protected GlobalSettingsService settingsService ;
protected GlobalSettingsService settingsService ;
@WireVariable
protected OrderService orderService ;
protected OrderFormValidator orderFormValidator ;
protected OrderFormValidator orderFormValidator ;
protected OrderItem selectedItem ;
protected OrderItem selectedItem ;
@ -41,6 +49,8 @@ public class OrderForm extends FormViewModel<Order>
protected String deliveryCompany ;
protected String deliveryCompany ;
protected List < OrderItem > syncOrderItems ;
@Init ( superclass = true )
@Init ( superclass = true )
public void initOrderForm ( )
public void initOrderForm ( )
{
{
@ -66,6 +76,8 @@ public class OrderForm extends FormViewModel<Order>
{
{
this . getDataBean ( ) . setAddress ( new AddressEmb ( ) ) ;
this . getDataBean ( ) . setAddress ( new AddressEmb ( ) ) ;
}
}
this . syncOrderItems = this . getDataBean ( ) . getItems ( ) ;
}
}
public OrderFormValidator getOrderFormValidator ( )
public OrderFormValidator getOrderFormValidator ( )
@ -143,6 +155,16 @@ public class OrderForm extends FormViewModel<Order>
this . deliveryCompany = deliveryCompany ;
this . deliveryCompany = deliveryCompany ;
}
}
public List < OrderItem > getSyncOrderItems ( )
{
return syncOrderItems ;
}
public void setSyncOrderItems ( List < OrderItem > syncOrderItems )
{
this . syncOrderItems = syncOrderItems ;
}
@Command
@Command
@NotifyChange ( "dataBean" )
@NotifyChange ( "dataBean" )
public void doFillSuppAddress ( )
public void doFillSuppAddress ( )
@ -184,4 +206,50 @@ public class OrderForm extends FormViewModel<Order>
this . getDataBean ( ) . setDeliveryAddress ( addr ) ;
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 ) ;
}
}
}