@SuppressWarnings("serial")
public class TableListCouponUsed extends JTable implements ITableMain {

  private List<CouponUsed> listCouponUsed;
  private TableModelCouponUsed mdTbPromotionUsed;
  private ClientContext clientContext = ClientContext.getInstance();
  private PromotionServiceClient client = clientContext.getBean(PromotionServiceClient.class);
  private int index, size;

  public TableListCouponUsed() {
    try {
      listCouponUsed = client.getCouponUsed();
    } catch (Exception e) {
      e.printStackTrace();
      listCouponUsed = new ArrayList<CouponUsed>();
    }
    mdTbPromotionUsed = new TableModelCouponUsed(new ArrayList<CouponUsed>());
    setModel(mdTbPromotionUsed);
  }

  @Override
  public void click() {}

  @Override
  public int getListSize() {
    return listCouponUsed.size();
  }

  @Override
  public List<Integer> getColumnSum() {
    List<Integer> list = new ArrayList<Integer>();
    list.add(7);
    list.add(8);
    return list;
  }

  @Override
  public DefaultTableModel loadTable(int index, int pageSize) {
    this.index = index;
    this.size = pageSize;
    try {
      mdTbPromotionUsed.setData(listCouponUsed.subList(index, pageSize), index);
    } catch (Exception e) {
      mdTbPromotionUsed = new TableModelCouponUsed(new ArrayList<CouponUsed>());
    }
    return mdTbPromotionUsed;
  }

  @Override
  public boolean delete() {
    return false;
  }

  @Override
  public boolean isDelete() {
    return false;
  }
}
 public HashMap<String, List<Table>> getTables(boolean reload) throws Exception {
   if (tableMap == null || reload) {
     tableMap = new HashMap<String, List<Table>>();
     RestaurantServiceClient restaurantServiceClient =
         clientContext.getBean(RestaurantServiceClient.class);
     List<Table> tables = restaurantServiceClient.getTables();
     for (Table table : tables) {
       String location = table.getLocationCode();
       List<Table> holder = this.tableMap.get(location);
       if (holder == null) {
         holder = new ArrayList<Table>();
         holder.add(table);
         this.tableMap.put(location, holder);
       } else {
         holder.add(table);
         this.tableMap.put(location, holder);
       }
     }
   }
   return tableMap;
 }
 public Account login(String loginId, String password) throws Exception {
   AccountServiceClient accountServiceClient = clientContext.getBean(AccountServiceClient.class);
   return accountServiceClient.login(loginId, password);
 }
public class POSModelManager {
  private static POSModelManager instance = new POSModelManager();

  private ClientContext clientContext = ClientContext.getInstance();
  private AccountingServiceClient clientAccounting =
      clientContext.getBean(AccountingServiceClient.class);
  private ProductServiceClient warehouseClient = clientContext.getBean(ProductServiceClient.class);
  private RestaurantServiceClient restaurantClient =
      clientContext.getBean(RestaurantServiceClient.class);

  private HashMap<String, List<Table>> tableMap;
  private HashMap<String, List<ProductTag>> productTagMap;

  private POSModelManager() {}

  public List<ProductPrice> searchProducts(String terms) throws Exception {
    ProductPriceType productPriceType =
        warehouseClient.getProductPriceTypeByType("Bang gia thuong");
    List<ProductPrice> productPrices =
        warehouseClient.findByProductPriceByType(productPriceType.getType());
    return productPrices;
  }

  public List<ProductPrice> searchProductTags(String tag) throws Exception {
    ProductPriceType productPriceType =
        warehouseClient.getProductPriceTypeByType("Bang gia thuong");
    List<ProductPrice> productPrices =
        warehouseClient.findByProductPriceByType(productPriceType.getType());
    return productPrices;
  }

  public Table saveTable(Table table) throws Exception {
    return restaurantClient.saveTable(table);
  }

  public HashMap<String, List<Table>> getTables(boolean reload) throws Exception {
    if (tableMap == null || reload) {
      tableMap = new HashMap<String, List<Table>>();
      RestaurantServiceClient restaurantServiceClient =
          clientContext.getBean(RestaurantServiceClient.class);
      List<Table> tables = restaurantServiceClient.getTables();
      for (Table table : tables) {
        String location = table.getLocationCode();
        List<Table> holder = this.tableMap.get(location);
        if (holder == null) {
          holder = new ArrayList<Table>();
          holder.add(table);
          this.tableMap.put(location, holder);
        } else {
          holder.add(table);
          this.tableMap.put(location, holder);
        }
      }
    }
    return tableMap;
  }

  public HashMap<String, List<ProductTag>> getProductTags(boolean reload) throws Exception {
    if (productTagMap == null || reload) {
      productTagMap = new HashMap<String, List<ProductTag>>();

      List<ProductTag> productTags = warehouseClient.getProductTags();

      List<ProductTag> holder = new ArrayList<ProductTag>();
      productTagMap.put("All", holder);
      for (ProductTag productTag : productTags) {
        holder.add(productTag);
      }
    }
    return productTagMap;
  }

  public Account login(String loginId, String password) throws Exception {
    AccountServiceClient accountServiceClient = clientContext.getBean(AccountServiceClient.class);
    return accountServiceClient.login(loginId, password);
  }

  public InvoiceDetail createInvoiceDetail(InvoiceDetail invoiceDetail) throws Exception {
    return clientAccounting.saveInvoiceDetail(invoiceDetail);
  }

  public FilterResult<InvoiceDetail> query(FilterQuery query) throws Exception {
    return clientAccounting.query(query);
  }

  public List<Tax> getTaxs() throws Exception {
    return warehouseClient.getTaxs();
  }

  public Tax saveTax(Tax tax) throws Exception {
    return warehouseClient.saveTax(tax);
  }

  public static POSModelManager getInstance() {
    return instance;
  }
}
 public void saveSettings() {
   ClientContext.getInstance();
 }
public class LocaleModelManager {

  private static LocaleModelManager instance = new LocaleModelManager();

  private ClientContext clientContext = ClientContext.getInstance();
  private LocaleServiceClient clientCore = clientContext.getBean(LocaleServiceClient.class);

  private LocaleModelManager() {}

  public void saveSettings() {
    ClientContext.getInstance();
  }

  public static LocaleModelManager getInstance() {
    return instance;
  }

  public List<Country> getCountries() throws Exception {
    return clientCore.getCountries();
  }

  public Country getCountry(String code) throws Exception {
    return clientCore.getCountry(code);
  }

  public Country saveCountry(Country country) throws Exception {
    return clientCore.saveCountry(country);
  }

  public boolean deleteCountry(Country country) throws Exception {
    return clientCore.deleteCountry(country);
  }

  public List<Currency> getCurrencies() throws Exception {
    return clientCore.getCurrencies();
  }

  public Currency getCurrencyByCode(String code) {
    try {
      return clientCore.getCurrency(code);
    } catch (Exception e) {
      return null;
    }
  }

  public Currency saveCurrency(Currency c) throws Exception {
    return clientCore.saveCurrency(c);
  }

  public boolean deleteCurrency(Currency c) throws Exception {
    return clientCore.deleteCurrency(c);
  }

  public List<ProductUnit> getProductUnits() throws Exception {
    return clientCore.getProductUnits();
  }

  public ProductUnit getProductUnitByCode(String code) {
    try {
      return clientCore.getProductUnit(code);
    } catch (Exception e) {
      return null;
    }
  }

  public ProductUnit getProductUnitByDefault() {
    try {

      ProductUnit pU = LocaleModelManager.getInstance().getProductUnitByCode("dv");
      if (pU == null) {
        pU = new ProductUnit();
        pU.setCode("dv");
        pU.setName("Đơn vị");
        pU.setDescription("dv");
        pU.setRate(1);
      }
      return pU;
    } catch (Exception ex) {
      return null;
    }
  }

  public ProductUnit saveProductUnit(ProductUnit productUnit) throws Exception {
    return clientCore.saveProductUnit(productUnit);
  }

  public boolean deleteProductUnit(ProductUnit productUnit) throws Exception {
    return clientCore.deleteProductUnit(productUnit);
  }

  public void deleteTest(String test) throws Exception {
    List<Country> countries = getCountries();
    for (int i = 0; i < countries.size(); i++) {
      if (countries.get(i).getName().indexOf(test) >= 0) {
        clientCore.deleteCountry(countries.get(i));
      }
    }

    List<Currency> cities = getCurrencies();
    for (int i = 0; i < cities.size(); i++) {
      if (cities.get(i).getName().indexOf(test) >= 0) {
        clientCore.deleteCurrency(cities.get(i));
      }
    }

    List<ProductUnit> productUnits = getProductUnits();
    for (int i = 0; i < productUnits.size(); i++) {
      if (productUnits.get(i).getName().indexOf(test) >= 0) {
        clientCore.deleteProductUnit(productUnits.get(i));
      }
    }
  }
}