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 OrderHook implements IHookAdd, IHookDelete, IHookEdit, IHookUndelete{

   @Override
   public void signal(DBListPanel<?> panelList, int ID){
      MOrder mOrder = MongoService.ds.find(MOrder.class, MOrder.F_ID, ID).get();
      
      if(mOrder == null){
         return;
      }
      
      
      MongoOrderService.racalculteCounters(mOrder);
      int iPrice = MongoOrderService.racalcultePrice(mOrder);
      
      panelList.table.getItem(ID).getItemProperty("Цена").setValue(DBListPanel.formatPrice(iPrice));
   }
}
