Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goseisan - Go powered seisan #2

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Gemfile

This file was deleted.

29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,14 @@ Seisan solution for small team.

## Installation

You need a few steps to setup seisan data repository. `example` directory in `enishitech/seisan` will be a good reference for you.

Put `Gemfile`:

```
source 'https://rubygems.org'
Compile from Source.

gem 'rake'
gem 'seisan'
```

Run bundler:

```shell
% bundle
% go get -u github.com/enishitech/seisan
```

Put `Rakefile`:
You need a few steps to setup seisan data repository. `example` directory in `enishitech/seisan` will be a good reference for you.

```
require 'seisan/task'
```
Create `data` directory to store data.

```shell
Expand All @@ -35,7 +21,7 @@ Create `data` directory to store data.
OK, now everything is set up. Run

```shell
% bundle exec rake seisan TARGET=2013/07
% seisan 2013/07
```

Then you will have an empty monthly report (because you have no record in seisan data) at `output/2013-07.xlsx`.
Expand Down Expand Up @@ -83,12 +69,10 @@ data
└── 08-shidara.yaml
```

Put `Rakefile` to your seisan data repository,

Then you can generate seisan report.

```shell
% bundle exec rake seisan TARGET=2013/07
% seisan 2013/07
```

## Contributing
Expand All @@ -101,8 +85,7 @@ Then you can generate seisan report.

-----

© 2013 Enishi Tech Inc.

© 2015 Enishi Tech Inc.

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/enishitech/seisan/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

1 change: 0 additions & 1 deletion Rakefile

This file was deleted.

35 changes: 35 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package config

import (
"io/ioutil"
"os"

"gopkg.in/yaml.v2"
)

type Config struct {
Organization
}

type Organization struct {
Name string
}

func Load(configPath string) (*Config, error) {
var config Config

_, err := os.Stat(configPath)
if err != nil {
return nil, err
}

buf, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(buf, &config)
if err != nil {
return nil, err
}
return &config, nil
}
9 changes: 0 additions & 9 deletions example/Gemfile

This file was deleted.

1 change: 0 additions & 1 deletion example/Rakefile

This file was deleted.

8 changes: 8 additions & 0 deletions expense/expense.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package expense

type Entry struct {
Date string
Applicant string
Amount int
Remarks string
}
101 changes: 101 additions & 0 deletions expense/reporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package expense

import (
"sort"

"github.com/tealeg/xlsx"

"github.com/enishitech/seisan/config"
"github.com/enishitech/seisan/request"
)

type ExpenseReporter struct{}

func NewReporter() *ExpenseReporter {
return &ExpenseReporter{}
}

type ExpenseRequest struct {
Applicant string `yaml:"applicant"`
ExpeneseEntries []Entry `yaml:"expense"`
}

func (reporter ExpenseReporter) renderSummary(sheet *xlsx.Sheet, sumByApplicant map[string]int) {
var row *xlsx.Row
var cell *xlsx.Cell

row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue("立替払サマリー")
row = sheet.AddRow()
for _, heading := range []string{"氏名", "金額"} {
cell = row.AddCell()
cell.SetValue(heading)
}
for key, value := range sumByApplicant {
row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue(key)
cell = row.AddCell()
cell.SetValue(value)
}
row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue("")
}

type ByDate []Entry

func (a ByDate) Len() int { return len(a) }
func (a ByDate) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByDate) Less(i, j int) bool { return a[i].Date < a[j].Date }

func (reporter ExpenseReporter) renderEntries(sheet *xlsx.Sheet, entries []Entry) {
var row *xlsx.Row
var cell *xlsx.Cell

row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue("立替払明細")
row = sheet.AddRow()
for _, heading := range []string{"日付", "立替者", "金額", "摘要", "備考"} {
cell = row.AddCell()
cell.SetValue(heading)
}
for _, detail := range entries {
row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue(detail.Date)
cell = row.AddCell()
cell.SetValue(detail.Applicant)
cell = row.AddCell()
cell.SetValue(detail.Amount)
cell = row.AddCell()
cell.SetValue(detail.Remarks)
}
}

func (reporter ExpenseReporter) Report(sheet *xlsx.Sheet, conf *config.Config, requests []request.Request) error {
entries := make([]Entry, 0)
sumByApplicant := make(map[string]int)
for _, req := range requests {
var er ExpenseRequest
if err := req.Unmarshal(&er); err != nil {
return err
}
if _, ok := sumByApplicant[er.Applicant]; !ok {
sumByApplicant[er.Applicant] = 0
}
for _, entry := range er.ExpeneseEntries {
entry.Applicant = er.Applicant
sumByApplicant[er.Applicant] += entry.Amount
entries = append(entries, entry)
}
}
sort.Sort(ByDate(entries))

reporter.renderSummary(sheet, sumByApplicant)
reporter.renderEntries(sheet, entries)

return nil
}
24 changes: 0 additions & 24 deletions lib/seisan.rb

This file was deleted.

18 changes: 0 additions & 18 deletions lib/seisan/base_renderer.rb

This file was deleted.

51 changes: 0 additions & 51 deletions lib/seisan/expense_renderer.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/seisan/header_renderer.rb

This file was deleted.

Loading