68 lines
2.1 KiB
Plaintext
68 lines
2.1 KiB
Plaintext
---
|
|
title: "Untitled"
|
|
author: "Matt"
|
|
date: "April 7, 2016"
|
|
output: html_document
|
|
---
|
|
|
|
```{r setup, include=FALSE}
|
|
knitr::opts_chunk$set(echo = TRUE)
|
|
```
|
|
|
|
Should use this document for actual operations and keep actual functions in another document for the public [GitHub repo](https://github.com/mattbk/ledgerr). Shiny will be set up at https://www.shinyapps.io/admin/#/dashboard.
|
|
|
|
```{r}
|
|
# Use https://github.com/maxconway/gsheet
|
|
library(gsheet)
|
|
|
|
# Pull Google sheet locations from another file (journal1, journal2, etc.)
|
|
source("config.R")
|
|
|
|
# Combine bank accounts
|
|
journal<-rbind(journal1,journal2)
|
|
|
|
## Clean up
|
|
# Date is date
|
|
journal$Date<-as.Date(journal$Date,format="%m/%d/%Y")
|
|
# Replace empty classes
|
|
journal$Class[journal$Class==""]<-c("unclassified")
|
|
# Class is a factor
|
|
journal$Class<-as.factor(journal$Class)
|
|
# Empty class should be NA
|
|
# Debit and Credit are numeric, without commas
|
|
journal$Debit<-as.numeric(sub(",","",journal$Debit))
|
|
journal$Credit<-as.numeric(sub(",","",journal$Credit))
|
|
|
|
## Temp function location
|
|
# All time net, takes journal and class name(s) as an argument
|
|
net<-function(journ,classselect="all"){
|
|
if("all" %in% classselect)
|
|
classselect<-levels(journ$Class)
|
|
print(classselect)
|
|
net<-sum(journ$Credit[journ$Class %in% classselect],
|
|
na.rm=T)-sum(journ$Debit[journ$Class %in% classselect],
|
|
na.rm=T)
|
|
return(net)
|
|
}
|
|
|
|
# Net by class and date range
|
|
# TODO should be function that uses the net function above
|
|
# List of classes
|
|
classes<-levels(journal$Class)
|
|
# Set up data frame
|
|
net.byclass<-data.frame(Class=character(),
|
|
Net=numeric(),
|
|
stringsAsFactors=FALSE)
|
|
# Loop through classes, calculate net, and add to data frame
|
|
for (i in 1:length(classes))
|
|
{ net.byclass[i,] <- c(as.character(classes[i]),
|
|
sum(journal$Credit[journal$Class==classes[i]],
|
|
na.rm=T)-sum(journal$Debit[journal$Class==classes[i]],
|
|
na.rm=T))
|
|
}
|
|
# Add total net row
|
|
net.byclass[nrow(net.byclass)+1,]<-c("Total",net.calc(journal))
|
|
|
|
# See other reports in QB and Ledger
|
|
|
|
``` |