R/record_pool_reset.R

Defines functions record_pool_reset

Documented in record_pool_reset

#' Write pool reset entries in the ledger.
#' @param date        Date. date of the consumption.
#' @param object      Character. Name of the materials consumed.
#' @param amount      Double. Amount empryin the cost pool or cost object.
#' @param origin      Character. From where the consumption is made.
#' @param destination Character. Where the consumption goes.
#' @return A tibble of journal entries.
#' @importFrom tibble tibble
#' @export


record_pool_reset <- function(date, object, amount, origin, destination){
  
  if (amount < 0){
    altorigin <- destination
    destination <- origin
    origin <- altorigin
    amount = abs(amount)
  }
  
  
  entries <- tibble::tibble(
    date = rep(date, 2),
    label = object,
    account =  c(destination, origin),
    debit = c(amount, NA),
    credit = c(NA, amount)
  )
  
  return(entries)
}
NicolasJBM/simulR documentation built on Feb. 15, 2021, 9:38 a.m.