Giter VIP home page Giter VIP logo

afip_bill's Introduction

AfipBill

AfipBill allows you to generate an AFIP bill in PDF format.

The end result will look like this: bill_sample.pdf

Installation

Include the gem in your Gemfile

gem 'afip_bill'

Install it

$ bundle install

Setup

In order to have the bills fully complete, you will need to setup some configuration about your business. If you're in a Rails application you can place that in config/initializers/afip_bill.rb

AfipBill.configuration[:header_business_name] = "Company Name"
AfipBill.configuration[:business_name] = "CompanyName SRL"
AfipBill.configuration[:business_address] = "Address 1234"
AfipBill.configuration[:business_start_date] = "01/01/2016"
AfipBill.configuration[:business_cuit] = "1234567890"
AfipBill.configuration[:city] = "Ciudad de Buenos Aires"
AfipBill.configuration[:ingresos_brutos] = "123-456789-0"
AfipBill.configuration[:iva] = "IVA Responsable Inscripto"
AfipBill.configuration[:sale_point] = "0001"

Also, one of the main things that you need to have, is a JSON for each of your bills. It must contain at least these attributes:

json_bill = {
  cae: "1234567890123",       # CAE number
  cae_due_date: "20171125",   # CAE expiry date
  doc_num: "12345678901",     # CUIT number
  cbte_tipo: "01",            # Bill type (01 = A, 06 = B, 11 = C)
  cbte_fch: "20170125",       # Bill date
  imp_neto: 220.0,            # Net amount
  imp_iva: 46.2,              # IVA amount
  imp_total: 266.2,           # Total amount
  cbte_hasta: 1,              # Voucher number
  fch_serv_desde: "20170101", # Invoiced from
  fch_serv_hasta: "20170131", # Invoiced to
  fch_vto_pago: "20170115"    # CAE expiration date
}.to_json

In OmbuShop, we like to automatically generate this JSON using Bravo.

Usage

There are three important classes that you need to use: AfipBill::User, AfipBill::LineItem and AfipBill::Generator.

AfipBill::User

You should create a new instance of this class to provide some information about the bill. It receives four parameters: Company name, Owner name, Address, and Tax category.

user = AfipBill::User.new("Bill company name",
                          "Bill owner name",
                          "Bill address",
                          "Bill tax category")

AfipBill::LineItem

With this class you can define the line items for your bill. It receives three parameters: Name, Quantity, and Unit amount.

item_1 = AfipBill::LineItem.new("Item 1", 1, 100)
item_2 = AfipBill::LineItem.new("Item 2", 1, 120)
...

AfipBill::Generator

This class will generate the PDF bill. It receives three parameters: the json bill, the user, and the array of line items (all the parameters were defined above)

generator = AfipBill::Generator.new(json_bill, user, [item_1, item_2])

And finally you can render the PDF by using the generate_pdf_string method

generator.generate_pdf_string

Or if you're in a Rails app you can render it like this:

respond_to do |format|
  format.pdf { render text: generator.generate_pdf_string }
end

Special Thanks

AfipBill was inspired in code by nubis and gastonconcilio.

Initial development of this gem was sponsored by OmbuShop.

Thank you!

License

The gem is available as open source under the terms of the MIT License.

afip_bill's People

Contributors

bronzdoc avatar dependabot[bot] avatar emafriedrich avatar etagwerker avatar kostiantynpopovych avatar lubc avatar mauro-oto avatar

Stargazers

 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

afip_bill's Issues

Fix currency formatting for line items

We should properly format the line items currencies:

40237324-85402360-5a86-11e8-9a97-d5700359bfbc

It seems that we are doing it for the subtotals + totals:

40237435-cf3c2bc6-5a86-11e8-8d3d-a0650766e10b

So we should try to be consistent and display money values like: $23.368,99

Facturas duplicadas (req. de la AFIP)

Se me presentó la necesidad de hacer el duplicado de la factura, es requisito de la AFIP según entiendo. Lo solucioné a medias, como no soy bueno con ERB directo y por los tiempos que tenía, agregando una option a la generación de la factura, para mostrar "DUPLICADO" en lugar de original. Pero esto hace que el user deba imprimir el duplicado aparte, un horror. Creo el issue si alguien lo hace antes, sino luego con tiempo trato de hacerlo en un solo pdf.

Refactor views

We should refactor the views in order to avoid using fixed positions for the elements.
For instance:

<div style="left:263.78px;top:22.31px" class="cls_003">
  <span class="cls_003">ORIGINAL</span>
</div>

That was made by a PDF to HTML website but it's not a very flexible way to manage the views. Currently we can't work on #2 or #4 because of that.

Fork para soporte de facturas "C"

Hola.
Hice un fork para agregar soporte a facturas C https://github.com/emafriedrich/afip_bill

No se me ocurrió nada mejor que copiar la imagen de la factura b y su html para no tocar demasiado el código base, y no hacer malabares para mostrar la letra "C" en vez de la "B".

Como bravo no tiene soporte para emisión de facturas C también tuve que forkearlo.

https://github.com/emafriedrich/bravo

Así que como afip_bill va de la mano con bravo, me parece bien comentarlo.

Multi-page support

Currently, if there's more than 9 items on the bill, the layout will look broken. We should look into adding support for multi-page bills, so that if there's 10 or more items, those are displayed in subsequent pages.

screen shot 2017-05-17 at 10 26 02 am

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.