@Transactional
  public OffersInfo updateOffersInfo(int companyId, int offerId, OffersInfo offersInfo)
      throws Exception {
    try {
      OfferInfoPrimaryKey id = Conversions.getOfferInfoPrimaryKey(companyId, offerId);
      OfferInfoDbType dbEntry = offersInfoDao.find(id);

      updateOfferInfoDbEntry(dbEntry, offersInfo);

      return offersInfo;
    } catch (Exception e) {
      logger.error(
          "error updating offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
      throw new Exception(
          "error updating offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
    }
  }
  @Transactional
  public OffersInfo addOffersInfo(int companyId, OffersInfo offersInfo) throws Exception {
    try {
      int offerId = offersInfoDao.getMaxIdValue(companyId) + 1;
      OfferInfoDbType offerInfoDbType =
          Conversions.getOfferInfoDbEntry(companyId, offersInfo.getBranchId(), offerId, offersInfo);
      offersInfoDao.add(offerInfoDbType);

      offersInfo.setOfferId(offerId);
      return offersInfo;
    } catch (Exception e) {
      logger.error(
          "error adding offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
      throw new Exception(
          "error adding offers for : "
              + companyId
              + " and : "
              + offersInfo.getBranchId()
              + " : "
              + e.getMessage());
    }
  }
    public static OfferInfoDbType getOfferInfoDbEntry(
        int companyId, int branchId, int offerId, OffersInfo offersInfo) {
      OfferInfoDbType dbEntry = new OfferInfoDbType();

      dbEntry.setId(getOfferInfoPrimaryKey(companyId, offerId));

      dbEntry.setType(offersInfo.getType());
      dbEntry.setDetails(offersInfo.getDetails());
      dbEntry.setBranchId(branchId);

      dbEntry.setStartTS(offersInfo.getStart());
      dbEntry.setEndTS(offersInfo.getEnd());

      dbEntry.setRecurrenceDay(offersInfo.getRecurrenceDay());
      dbEntry.setRecurrence(offersInfo.isRecurrence());
      dbEntry.setHourlyPush(offersInfo.isHourlyPush());
      dbEntry.setClientAppVisibility(offersInfo.isClientAppVisibility());

      return dbEntry;
    }
    public static OffersInfo getOffersInfo(OfferInfoDbType dbEntry) {
      OffersInfo offersInfo = new OffersInfo();

      offersInfo.setBranchId(dbEntry.getBranchId());
      offersInfo.setOfferId(dbEntry.getId().getOfferId());
      offersInfo.setType(dbEntry.getType());
      offersInfo.setDetails(dbEntry.getDetails());

      offersInfo.setStart(dbEntry.getStartTS());
      offersInfo.setEnd(dbEntry.getEndTS());

      offersInfo.setRecurrenceDay(dbEntry.getRecurrenceDay());
      offersInfo.setRecurrence(dbEntry.isRecurrence());
      offersInfo.setHourlyPush(dbEntry.isHourlyPush());
      offersInfo.setClientAppVisibility(dbEntry.isClientAppVisibility());

      return offersInfo;
    }
  private void updateOfferInfoDbEntry(OfferInfoDbType dbEntry, OffersInfo offersInfo) {
    boolean updated = false;
    if (!dbEntry.getType().equals(offersInfo.getType())) {
      dbEntry.setType(offersInfo.getType());
      updated = true;
    }
    if (!dbEntry.getDetails().equals(offersInfo.getDetails())) {
      dbEntry.setDetails(offersInfo.getDetails());
      updated = true;
    }
    if (!dbEntry.getStartTS().equals(offersInfo.getStart())) {
      dbEntry.setStartTS(offersInfo.getStart());
      updated = true;
    }
    if (!dbEntry.getEndTS().equals(offersInfo.getEnd())) {
      dbEntry.setEndTS(offersInfo.getEnd());
      updated = true;
    }
    if (dbEntry.getRecurrenceDay() != offersInfo.getRecurrenceDay()) {
      dbEntry.setRecurrenceDay(offersInfo.getRecurrenceDay());
      updated = true;
    }
    if (dbEntry.isRecurrence() != offersInfo.isRecurrence()) {
      dbEntry.setRecurrence(offersInfo.isRecurrence());
      updated = true;
    }
    if (dbEntry.isHourlyPush() != offersInfo.isHourlyPush()) {
      dbEntry.setHourlyPush(offersInfo.isHourlyPush());
      updated = true;
    }
    if (dbEntry.isClientAppVisibility() != offersInfo.isClientAppVisibility()) {
      dbEntry.setClientAppVisibility(offersInfo.isClientAppVisibility());
      updated = true;
    }

    if (updated == true) {
      offersInfoDao.update(dbEntry);
    }
  }