##############################################################################
# Packages
library(exams)
library(manacc)
library(tidyverse)
library(knitr)
library(kableExtra)
library(randomNames)


##############################################################################
# Initialization
question_id <- "EN00000032"
wdir <- getwd()
parameters <- teachR::param_quest(wdir, question_id, alttype = "mcq", altlevel = "3 Apply")
for (i in 1:length(parameters)) assign(names(parameters)[[i]], parameters[[i]])
options(xtable.comment = FALSE, xtable.floating = FALSE, xtable.timestamp = "")
set.seed(seed)


##############################################################################
# Preparation
basepar <- manacc::income_statements(basevol = 5000, profitable = c(TRUE,TRUE))
company <- basepar$company[[1]]
product <- basepar$product[[1]]
singular <- basepar$singular[[1]]
plural <- basepar$plural[[1]]

person <- manacc::make_persons(2)
currentmonth <- lubridate::month(Sys.Date(), label = TRUE, abbr = FALSE)
lastmonth <- lubridate::month(Sys.Date()-30, label = TRUE, abbr = FALSE)

cis <- basepar %>%
  mutate(
    reference = paste(reference, product, sep = " "),
    vc = -vc,
    fc = -fc
  ) %>%
  select(reference, Volumes = vol, Revenues = rev, 'Variable costs' = vc, 'Contribution margin' = cm,'Fixed costs' = fc, 'Operating income' = oi) %>%
  tibble::column_to_rownames("reference") %>%
  t() %>%
  as.data.frame() %>%
  tibble::rownames_to_column("Account")

cis$Total <- cis[,2] + cis[,3]
tgt <- ceiling((cis[6,2] + cis[6,3])*(runif(1)+0.5)/100)*100
tgt_fmt <- writR::dbl(tgt)
cis[,2] <- writR::dbl(cis[,2])
cis[,3] <- writR::dbl(cis[,3])
cis[,4] <- writR::dbl(cis[,4])
cis[c(5,6),c(2,3)] <- ""

tp_multiprod <- manacc::cvp_bktp(vols = basepar$vol, ps = basepar$p, uvcs = basepar$uvc, fc = sum(basepar$fc), tgt = tgt)

##############################################################################
# Answers

if (reqexpl != "" & exasolu == "exam" & type_table != "html") lines <- paste0("\\vspace{",7.5,"cm}") else lines <- rep(" \\ ", 2)
#lines <- rep("\\ ", 2)

rightrev <- paste0(currencysymb, writR::dbl(tp_multiprod$solution["bktp_rev"]),".")
wrongrev <- sample(paste0(currencysymb, writR::dbl(tp_multiprod$wrong_rev), "."),4)

questions <- c(rightrev, wrongrev)

solutions <- c(TRUE, rep(FALSE,4))

explanations <- c(
  "",
  "",
  "",
  "",
  ""
)


##############################################################################
# Randomize order (do not edit)
alea <- sample(c(1, sample(2:length(questions), (alternatives-1))), alternatives)
questions <- questions[alea]
solutions <- solutions[alea]
explanations <- explanations[alea]

Question

r txt_question_id r person$first_name[[1]] r person$last_name[[1]] is the management accountant of r company, a company producing r product. Based on the results of r lastmonth, r person$pronoun[[1]] created the following contribution income statement for the two products of the company:

if (type_table == "html"){
  cis %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrrr") %>%
    kable_styling(bootstrap_options = c("striped", "hover")) %>%
    row_spec(c(1,3,5), underline = TRUE) %>%
    row_spec(c(2,4,6), bold = TRUE)
} else {
  cis %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrrr") %>%
    kable_styling(latex_options = c("striped","scale_down")) %>%
    row_spec(c(3,5), underline = TRUE) %>%
    row_spec(c(2,4,6), bold = TRUE)
}

\ The CEO of the company, r person$title[[2]] r person$last_name[[2]], wants to achieve a profit of r currencysymb r tgt_fmt in r currentmonth. Assuming that all the assumptions of cost-volume-profit analyses are valid, what is the total revenue for which the CEO's objective is achieved? r reqexpl r points

if (reqexpl == "") exams::answerlist(questions, markup = "markdown") else writeLines(lines)

Solution

Since we are interested in a revenue at target profit, the first step consists in computing the weighted average contribution margin ratio (WCMR). Since prices, unit variable costs, fixed costs and product mix are assumed constant, the WCMR is the total contribution margin divided the total revenues for the current product mix:

$$ WCMR = \frac{\text{Total contribution margin}}{\text{Total revenues}} = \frac{r cis[4,4]}{r cis[2,4]} = r writR::pct(tp_multiprod$solution["wcmr"])\% $$

Then, to compute the revenue at target profit, treat the target profit as an additional fixed cost to be covered by the contribution margin:

$$ R_{TP} = \frac{\text{Fixed Costs} + \text{Target Profit}}{WCMR} = \frac{r writR::dbl(sum(basepar$fc)) + r tgt_fmt}{r writR::pct(tp_multiprod$solution["wcmr"])\%} = r writR::dbl(tp_multiprod$solution["bktp_rev"]) $$

if (reqexpl == "") exams::answerlist(ifelse(solutions, "True", "False"), explanations, markup = "markdown") else writeLines(c("\\ ","\\ "))

Meta-information

extype: r extype exsolution: r exams::mchoice2string(solutions, single = TRUE) exname: r question_id



NicolasJBM/manacc documentation built on Jan. 16, 2020, 1:42 p.m.