# changeFunc.anals544.r 


##   According to James K, "Downloaded Ringtone" & "Pre Cut Ringtone" are treated 
##     the same by Accounting reports.  They are only distinguished in analytics.
##
##  transac_typeid transac_type_abbr        transac_type
##               4                DR Downloaded Ringtone
##              26                PR    Pre Cut Ringtone
##


changeFunc.anals544 <- function(DT.anals) {
## changeFunc.anals544 is an internal function used for changeAndAggregate() called on DT.anals

  ## Change date to MonthFloor or for iTunes to 544
  DT.anals[storeid == 1, download_activity_date := convertDateToiTunes544(download_activity_date)]
  DT.anals[storeid != 1, download_activity_date := monthFloor(download_activity_date)]

  ## rename the column to date
  setnames(DT.anals, "download_activity_date", "date")
  
  ## Check which stores do NOT use royalty dolalr and remove those
  addStoreUsesRD_(DT.anals, newCol="store_uses_royaltydollar")
  ## Safety-check. Confirm that store_uses_royaltydollar is correct
  if (!all(DT.anals[storeid %in% c(1, 187, 496), store_uses_royaltydollar]))
    warning ("Something went wrong with addStoreUsesRD_() which was called inside of changeFunc.anals544()  -- itself possibly called from changeAndAggregate()\nThe store_uses_royaltydollar is NOT TRUE for expected stores")

  DT.anals[!(store_uses_royaltydollar), revenue := NA]
  DT.anals[, store_uses_royaltydollar := NULL]

  ## Clean ringtone transac -- this is business knowledge from James K
  if ("transid" %in% names(DT.anals))
    DT.anals[transid == 26,  transid := 4]
  setInfo(DT.anals, appendInfo("date is 544 of download_activity_date", getInfo(DT.anals, quietly=TRUE), "DT.anals", DT.anals, showWarnings=FALSE))
}
