package kz.cafe.admin.hooks;

import kz.cafe.admin.panels.*;
import kz.cafe.db.*;
import kz.cafe.db.model.*;
import kz.cafe.db.service.*;

public class OrderItemHook implements IHookAdd, IHookDelete, IHookEdit, IHookUndelete{
   
   private final DBListPanel<?> panelOrders;
   
   

   public OrderItemHook(DBListPanel<?> pnlParent){
      super();
      this.panelOrders = pnlParent;
   }



   @Override
   public void signal(DBListPanel<?> panelList, int ID){
      MOrderItem mOrderItem = MongoService.ds.find(MOrderItem.class, MOrderItem.F_ID, ID).get();
      
      int iPriceItem = MongoOrderService.racalculteOrderItemPrice(mOrderItem);     
      panelList.table.getItem(ID).getItemProperty("Цена").setValue(DBListPanel.formatPrice(iPriceItem));

      
      MOrder mOrder = MongoService.ds.find(MOrder.class, MOrder.F_ID, mOrderItem.OID).get();
      int iPriceOrder = MongoOrderService.racalcultePrice(mOrder);
      panelOrders.table.getItem(panelOrders.table.getValue()).getItemProperty("Цена").setValue(DBListPanel.formatPrice(iPriceOrder));
   }
}
