Code Monkey home page Code Monkey logo

invoice_printer's Introduction

 

Super simple PDF invoicing. InvoicePrinter is a server, command line program and pure Ruby library to generate PDF invoices in no time. You can use Ruby or JSON as the invoice representation to build the final PDF.

Philosophy

  • Simple, no styling required, no calculation, no money formatting (bring your own)
  • Pure Ruby, no dependency on system libraries or browsers
  • Fast, so you can render invoices on the fly during requests

Examples

Simple invoice

See more usecases in the examples/ directory.

Features

  • A4 and US letter paper size
  • Invoice/document name and number
  • Purchaser and provider boxes with addresses and identificaton numbers
  • Payment method box showing banking details including SWIFT and IBAN fields
  • Issue/due dates box
  • Configurable items' table with item description, breakdown, quantity, unit, price per unit, tax and item's total amount fields
  • Description above the table
  • Final subtotal/tax/total info box
  • Page numbers
  • Configurable field labels & sublabels (optional little labels)
  • Configurable font file
  • Logotype (as image scaled to fit 50px of height)
  • Background (as image)
  • Stamp & signature (as image)
  • Note
  • JSON format
  • CLI
  • Server
  • Well tested

Documentation

Support

I am developing InvoicePrinter as a free and MIT-licensed library for several years now.

Please consider buying my book or SaaS starter kit so I can work more on Open Source.

Copyright

Copyright 2015-2023 © Josef Strzibny. MIT licensed.

invoice_printer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

invoice_printer's Issues

multilines notes

When notes are more than 1 line the pdf print is not shown correctly.
I have Write a test to demostrate the problem:

  # test/note_test.rb
  def test_setting_a_note_with_multiple_lines

    note = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.\nLorem Ipsum has been the industry's standard dummy text ever since the\n    1500s, when an unknown printer took a galley of type and scrambled it to\n    make a type specimen book. It has survived not only five centuries, but also\n    the leap into electronic typesetting, remaining essentially unchanged."

    params = default_document_params.merge(
      note: note
    )
    invoice = InvoicePrinter::Document.new(**params)
    rendered_pdf = InvoicePrinter.render(document: invoice)
    pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)

    assert_equal true, pdf_analysis.strings.include?(note)
  end

output:

$ rake test                                                                
/home/cristiano/.rvm/rubies/ruby-3.0.0/bin/ruby -w -I"lib:test" /home/cristiano/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb "test/api_test.rb" "test/background_test.rb" "test/cli_test.rb" "test/dates_box_test.rb" "test/examples_test.rb" "test/inputs_test.rb" "test/invoice_printer_test.rb" "test/items_table_test.rb" "test/labels_test.rb" "test/notes_test.rb" "test/page_numbers_test.rb" "test/payment_box_test.rb" 
/home/cristiano/code/invoice_printer/test/payment_box_test.rb:56: warning: method redefined; discarding old test_setting_bank_account_number_and_iban
/home/cristiano/code/invoice_printer/test/payment_box_test.rb:38: warning: previous definition of test_setting_bank_account_number_and_iban was here
Run options: --seed 43778

# Running:

...............................F.....

Finished in 21.031516s, 1.7593 runs/s, 4.6121 assertions/s.

  1) Failure:
NotesTest#test_setting_a_note_with_multiple_lines [/home/cristiano/code/invoice_printer/test/notes_test.rb:28]:
Expected: true
  Actual: false

37 runs, 97 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test" /home/cristiano/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb "test/api_test.rb" "test/background_test.rb" "test/cli_test.rb" "test/dates_box_test.rb" "test/examples_test.rb" "test/inputs_test.rb" "test/invoice_printer_test.rb" "test/items_table_test.rb" "test/labels_test.rb" "test/notes_test.rb" "test/page_numbers_test.rb" "test/payment_box_test.rb" ]

Tasks: TOP => test
(See full trace by running task with --trace)

item date

Is it possible to add a Date field to the "item" so that each item can have a date associated with it?
I am trying to use it for a consulting type invoice, and date of service is critical for the invoice.

Option to load from JSON file.

Add a parameter --document_path or detect it automatically if a document or file is passed, and load the document from a JSON file.

Custom layout options?

The logo's current position is bottom-left and is kind of counter-intuitive in my opinion.

Would it be helpful to implement a feature that lets the user decide where to place certain components(like logo) on the invoice, change background opacity, etc?

Include tax fields

  • Each item row should have a tax field
  • There should be a tax info associated with the total amount
    • subtotal / taxable / tax rate / tax due / total due

a place for an "introductory sentence" and a QR code

Hi,

I've checked out different command line tools to generate pdf invoices from the command line and yours looks most promising for me :) But (there's always a "but") would it be possible to add

  • an introductory sentence to the table of items and
  • a suitable place for a QR code?

Introductory sentence

I mean something along the lines of We invoice you for... or In accordance with the Contract No 2021/56844 we are sending you... A similar section is called "Additional information" in the example below:

Invoice sample

QR code

This would really be a great addition, it's becoming more and more popular and my clients would certainly appreciate not having to copy the data from the invoice by hand. I don't mean writing extra code to generate such an image (I use qrencode for that), just a suitable place for a QR code image.

Thanks for your great work!

Simplify Document Class

The instance variables that describe the provider and purchaser are identical, providing a lot of repetition in the attr_reader calls, and the initialize method. It should be possible to create a class that describes both of these items, and store them as @Provider and @purchaser within the Document class. This would certainly clean up the code, as well as make it easier for users to call Document.new. If you agree that this is useful, I would like to work on it myself.

US letter version for envelopes

I have a question that I haven't found answered in the readme. How can I handle the following localization issues with invoice_printer:

  • A4 vs. US letter
  • placement of recipient and seller address (i.e. for envelopes with window)
  • formatting of date value
  • formatting of money values - if there is any...? (the example code is a bit inconsistent, sometimes it includes $ sign, sometimes not)

Thanks, Oliver

Implement breakdowns of items

Every item in the table should be able to specify a breakdown with a simple free-form item.breakdown field.

Example:

Delivery gift busket
- Including extra roses: $40
- Including extra pralines: $15

Support more options for buyer and seller boxes

Coming from #25 we should be able to support some variety for buyer and seller boxes:

One other comment/suggestion I would have is to simplify/unify the content
of the Buyer and Seller boxes.  I find my use case putting different data
in the fields than you intended.  One contributing factor is that different
locales use different ways of representing addresses.  Also (as in my case)
I am just using email addresses for purchaser, so your fields dont fit my
use case.
Instead of calling the fields "street/city/postcode/etc."  just call them
line1, line2, line3, etc, and let the user put whatever data they want.  No
real need to format this data.

Raise expection if stamp image is not found, similar to logo

$ ruby pokus.rb
/home/strzibny/.gem/ruby/gems/invoice_printer-1.0.0.rc1/lib/invoice_printer/pdf_document.rb:74:in `initialize': Logotype file not found at prawn.png (InvoicePrinter::PDFDocument::LogoFileNotFound)
	from /home/strzibny/.gem/ruby/gems/invoice_printer-1.0.0.rc1/lib/invoice_printer.rb:66:in `new'
	from /home/strzibny/.gem/ruby/gems/invoice_printer-1.0.0.rc1/lib/invoice_printer.rb:66:in `print'
	from pokus.rb:59:in `<main>'

$ ruby pokus.rb
/home/strzibny/.gem/ruby/gems/prawn-2.1.0/lib/prawn/images.rb:142:in `verify_and_open_image': stamp.png not found (ArgumentError)

Ruby 3 keywords arguments

We are getting the following warning:

/home/strzibny/.gem/ruby/2.7.0/gems/invoice_printer_server-2.0.0/bin/invoice_printer_server:65: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

additional notes run off the page

It appears the template only leaves room for one line of notes. If you write too much, it will word wrap, but the additional lines of words won't appear on the page. If you use explicit new lines in the note section than those lines won't appear either.

Hard to discover options / configurations

The only way I've found options for the json document is one CLI input example, but it's not clear whether those are all the options, whether they are extensible, etc.

Am I missing some documentation or should I just read the code?

how start?

generally with praw the pdf start with

respond_to do |format|
    format.html
     format.pdf do
        pdf = InvoicePdf.new
       send_data.to_s pdf.render, filename: "invoice_#{@invoice.id}.pdf", type: 'application/pdf'
     end
  end

and on pdf

include ActionView::Helpers::NumberHelper

class InvoicePdf < Prawn::Document

  def initialize(boutique, invoice, order, buyer, product)
    super({:page_size => 'A4'})
 
    @invoice = invoice
    @order = order

    @product = product
    text "FATURA ##{@invoice.id}"
    move_down 10
    body
  end


but with invoice_printer did not start. thanks

release new gem version

Hi,

is it possible to cut a new version of this gem to be current with what is committed to the master branch of this repository? I am unable to pull in my Gemfile directly from GitHub.

Thanks!

Deprecate old address fields

  • remove deprecated fields
  • remove warning
  • edit and regenerate promo.rb example
  • update simple_invoice.rb example
  • update benchmarks/render.yml

Keeping some information private

I have shared tax and bank info separately with my clients and would rather not repeat it in every emailed invoice. However, if I don't put a bank account number, the invoice says "Payment in cash", but I would rather specify "By bank deposit" or nothing at all.

New totals table

Let's switch the alignment of labels to the left and values to the right, and remove the table container (and not so much working width calculations)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.