0
0

Go言語で簡単に請求書を生成:Invoice Generatorリポジトリの紹介

Posted at

請求書作成をもっと簡単にしたいと思いませんか?

Quail が提供する Invoice Generator を使えば、プロフェッショナルな請求書を簡単に生成できます。この強力で使いやすいライブラリをGo言語で活用して、請求書作成プロセスを効率化しましょう。

なぜこのInvoice Generatorを選ぶべきか?

1. Go言語とシームレスに統合

  • 既存のGoプロジェクトに簡単に統合可能。
  • すぐに始められるサンプルコードが提供されています。

2. カスタマイズ可能なフォント

  • CJK文字を含むカスタムフォントをサポート。
  • ブランドのスタイルに合わせて請求書をパーソナライズ可能。

3. PDF出力

  • 高品質なPDF請求書を生成。
  • デジタル配布や印刷に最適。

始め方

リポジトリには、ライブラリの設定方法と使用方法が詳細に説明されています。以下は、すぐに使える包括的なコードサンプルです:

func main() {
    // 請求書のヘッダーを設定
	builder, err := invoice.NewBuilder(Config{},"./sample-params-1.yaml")
	if err != nil {
		log.Panic("failed to create builder")
	}

    // 新しい請求書を作成
	buf, err := builder.GenerateInvoice()
	if buf == nil || err != nil {
		log.Panic("failed to generate invoice")
	}

    // PDF請求書を生成
	filename := "sample-invoice.pdf"
	if err := os.WriteFile(filename, buf, 0666); err != nil {
		log.Panic("failed to write to file")
	}
}

カスタムフォントの設定例

CJK文字を正しく表示するために、NotoSansCJK-JPでビルダーを設定する方法の例:

builder, _ := invoice.NewBuilder(
	Config{
		FontName:       "noto-sans-cjk",
		FontNormal:     "./fonts/NotoSansCJK-JP/NotoSansCJKjp-Regular.ttf",
		FontItalic:     "./fonts/NotoSansCJK-JP/NotoSansCJKjp-Italic.ttf",
		FontBold:       "./fonts/NotoSansCJK-JP/NotoSansCJKjp-Bold.ttf",
		FontBoldItalic: "./fonts/NotoSansCJK-JP/NotoSansCJKjp-BoldItalic.ttf",
	},
	"./sample-params-2.yaml")

サンプル設定ファイル

以下は、請求書の設定ファイルのサンプルです:

id: "20240210-SAMPLE"
date: 2024-02-10
currency: "JPY"
company_name: "春日町株式会社"
company_addr: "Cocoro BG 404, Shinbashi 1-2-3\nTokyo, Japan, 100-1234"
company_email: "hi@hruhimachi.com"
company_seal: "sample-seal.png"
tax_number: "T1234567890000"
bill_to: "湯ちち株式会社\nShinbashi 4-2-1, Tokyo, Japan, 100-0001"
summary:
  period_start: 2024-01-01
  period_end: 2024-02-29
  title: "System Development and Design Service"
  total_exclude_tax: 500000
  tax_rate: 0.1
detail_items:
  - date: 2024-01-31
    title: "Implementation of the System"
    desc: "Implementing the system based on the requirements."
    url:
    total_exclude_tax: 0
  - date: 2024-01-01
    title: "System Design Draft"
    desc: "Drafting the system design document."
    url: https://github.com/hruhimachi/project-draft
    total_exclude_tax: 0
payment:
  receive_account_bank: "三井住友銀行"
  receive_account_branch: "本店営業部(001)"
  receive_account_number: "12345678"

詳細な設定情報については、リポジトリをご覧ください。今日から請求書作成プロセスを効率化しましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0