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

[WIP] #1

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
801d2dd
New documents: credit and debit notes
nan-apps Nov 7, 2018
dbcccce
New bill attribute: custom text
nan-apps Nov 7, 2018
0d2ca8c
path fix
nan-apps Nov 7, 2018
d539408
ajustando algunos margenes
nan-apps Nov 8, 2018
6d52034
Ajuste en nombre de fantasia en encabezado
nan-apps Nov 9, 2018
28faad5
Fixed margins and zoom level WOMM
ceneon Nov 9, 2018
a4af56c
Merge branch 'develop' of github.com:wecodeio/afip_bill into develop
ceneon Nov 9, 2018
af71fc7
Main margin improvements
ceneon Nov 12, 2018
f7d81b2
Compress items' lines to fit more of them
ceneon Nov 12, 2018
9a0d972
Improve alignment for unit prices
ceneon Nov 12, 2018
c83bdec
Merge remote-tracking branch 'origin/develop' into develop
nan-apps Nov 12, 2018
2c8e20e
some width and alignment fixes
nan-apps Nov 13, 2018
02a8a84
different iva's in lines and totals
nan-apps Nov 13, 2018
27df05d
Alignment fix in B notes
nan-apps Nov 13, 2018
fbff3a8
Some small fixes
nan-apps Nov 14, 2018
e4845ab
configuration fix
nan-apps Dec 11, 2018
1301416
condition sale configurable and with default value "Otra" for backwar…
nan-apps Dec 14, 2018
8c3a697
missing space
nan-apps Dec 14, 2018
02d6ce7
fix in logo size
nan-apps Dec 14, 2018
dcde884
preparing for c invoicing
nan-apps Dec 24, 2018
5af2f91
more description space in A invoices lines
nan-apps Jan 9, 2019
67969c7
more descripcion space in all documents and some other adjustments
nan-apps Jan 17, 2019
2e76403
css fix in client address
nan-apps Jan 17, 2019
1ae14b3
adding code parameter to line item
nan-apps Jan 21, 2019
e6bf0dd
small codefix
nan-apps Jan 23, 2019
4c9ad82
gaining more space for companies bank information
nan-apps Jan 30, 2019
3923eeb
lines number formating
nan-apps Jan 30, 2019
2979175
adjusting totals in notes A with new template image
nan-apps Feb 14, 2019
84e38ff
ganing code space from amount and using smaller font when code too long
nan-apps Mar 3, 2019
8eab777
quantity position fix in b template
nan-apps Mar 3, 2019
1b6ab03
fixed width for line descriptions
nan-apps Apr 29, 2019
c0b12f8
related invoice data for notes
nan-apps Sep 29, 2020
86c8ff3
Reorganized footer to display AFIP QR code
Feb 28, 2021
866350e
removed trash css
Feb 28, 2021
c9ffb24
Addes header_obs to invoices (remit number etc)
ceneon Jul 5, 2021
728d715
Added invoice discounts mode
ceneon Sep 10, 2021
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
49 changes: 39 additions & 10 deletions lib/afip_bill/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,74 @@

module AfipBill
class Generator
attr_reader :afip_bill, :bill_type, :user, :line_items, :header_text

attr_reader :afip_bill, :bill_name, :bill_type, :user, :line_items, :header_text
HEADER_PATH = File.dirname(__FILE__) + '/views/shared/_factura_header.html.erb'.freeze
FOOTER_PATH = File.dirname(__FILE__) + '/views/shared/_factura_footer.html.erb'.freeze
BRAVO_CBTE_TIPO = { "01" => "Factura A", "06" => "Factura B" }.freeze
BRAVO_CBTE_TIPO = {
'01' => { directory: 'bills', template: 'factura_a', doc_name: 'factura', doc_type: 'a' },
'06' => { directory: 'bills', template: 'factura_b', doc_name: 'factura', doc_type: 'b' },
'03' => { directory: 'notes', template: 'nota_a', doc_name: 'Nota de crédito', doc_type: 'a' },
'08' => { directory: 'notes', template: 'nota_b', doc_name: 'Nota de crédito', doc_type: 'b' },
'02' => { directory: 'notes', template: 'nota_a', doc_name: 'Nota de débito', doc_type: 'a' },
'07' => { directory: 'notes', template: 'nota_b', doc_name: 'Nota de débito', doc_type: 'b' },
}.freeze
IVA = 21.freeze
Copy link
Member Author

@ceneon ceneon Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nan-apps empresa 1 vende algunos items con IVA 10.5% 😱


def initialize(bill, user, line_items = [], header_text = 'ORIGINAL')
@afip_bill = JSON.parse(bill)
@user = user
@bill_type = type_a_or_b_bill
@bill_name = bill_name_s
@bill_type = bill_type_s
@line_items = line_items
@template_header = ERB.new(File.read(HEADER_PATH)).result(binding)
@template_footer = ERB.new(File.read(FOOTER_PATH)).result(binding)
@header_text = header_text
end

def type_a_or_b_bill
BRAVO_CBTE_TIPO[afip_bill["cbte_tipo"]][-1].downcase
def bill_name_s
BRAVO_CBTE_TIPO[afip_bill["cbte_tipo"]][:doc_name].capitalize
end

def bill_type_s
BRAVO_CBTE_TIPO[afip_bill["cbte_tipo"]][:doc_type]
end

def barcode
@barcode ||= Barby::Code25Interleaved.new(code_numbers)
end

def pdfkit_options
{
zoom: '1.65',
'margin-bottom': '0.05in',
'margin-top': '0.05in',
'margin-left': '0.2in',
'margin-right': '0.2in'
}
end

def generate_pdf_file
tempfile = Tempfile.new("afip_bill.pdf")

PDFKit.new(template).to_file(tempfile.path)
PDFKit.new(template, pdfkit_options).to_file(tempfile.path)
end

def generate_pdf_string
PDFKit.new(template).to_pdf
PDFKit.new(template, pdfkit_options).to_pdf
end

private

def bill_path
File.dirname(__FILE__) + "/views/bills/factura_#{bill_type}.html.erb"
File.dirname(__FILE__) + "/views/#{template_directory}/#{template_name}.html.erb"
end

def template_name
BRAVO_CBTE_TIPO[afip_bill["cbte_tipo"]][:template]
end

def template_directory
BRAVO_CBTE_TIPO[afip_bill["cbte_tipo"]][:directory]
end

def code_numbers
Expand Down
9 changes: 5 additions & 4 deletions lib/afip_bill/line_item.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
module AfipBill
class LineItem
attr_reader :name, :quantity, :imp_unitario
IVA = 21.freeze
attr_reader :name, :quantity, :imp_unitario, :iva
#IVA = 21.freeze

def initialize(name, quantity, imp_unitario)
def initialize(name, quantity, imp_unitario, iva=nil)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

por compatibilidad si esto se va a volver una serie de PRs en el repo original, el default de iva acá debería ser 21

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hecho!

@name = name
@quantity = quantity
@imp_unitario = imp_unitario
@iva = iva
end

def imp_total_unitario
quantity * imp_unitario
end

def imp_iva
imp_total_unitario * IVA / 100
imp_total_unitario * iva / 100
end

def imp_total_unitario_con_iva
Expand Down
16 changes: 10 additions & 6 deletions lib/afip_bill/views/bills/factura_a.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
<div style="left:57.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.name %></span></div>
<div style="width:60px;left:37%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.quantity.to_s.tr(".", ",") %> </span></div>
<div style="left:288.30px;top:<%= top %>px" class="cls_012"><span class="cls_012">unidades</span></div>
<div style="left:360.54px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.imp_unitario.to_s.tr(".", ",") %></span></div>
<div style="left:380px;top:<%= top %>px" class="cls_008"><span class="cls_008" style="position:absolute;right:0"><%= line_item.imp_unitario.to_s.tr(".", ",") %></span></div>
<div style="left:398.43px;top:<%= top %>px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="width:60px;left:70.4%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.imp_total_unitario.round(2).to_s.tr(".", ",") %></span></div>
<div style="left:490.00px;top:<%= top %>px" class="cls_008"><span class="cls_008">21%</span></div>
<div style="left:490.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.iva %>%</span></div>
<div style="width:60px;left:87%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.imp_total_unitario_con_iva.round(2).to_s.tr(".", ",") %></span></div>
<% top += 25 %>
<% top += 15 %>
<% end %>

<div style="left:17.00px;top:450.97px" class="cls_008"><span class="cls_008">
<%= afip_bill["custom_text"] %>
</span></div>

<div style="left:17.00px;top:511.97px" class="cls_010"><span class="cls_010">Otros Tributos</span></div>
<div style="left:21.00px;top:524.54px" class="cls_008"><span class="cls_008">Descripción</span></div>
<div style="left:184.00px;top:524.54px" class="cls_008"><span class="cls_008">Detalle</span></div>
Expand All @@ -45,11 +49,11 @@
<div style="left:18.00px;top:589.63px" class="cls_008"><span class="cls_008">Impuestos Municipales</span></div>
<div style="left:331.43px;top:589.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:456.98px;top:577.41px" class="cls_002"><span class="cls_002">IVA 21%: $</span></div>
<div style="width:60px;left:86.6%;top:577.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_iva"] %></span></div>
<div style="width:60px;left:86.6%;top:577.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_iva_21"] %></span></div>
<div style="left:186.97px;top:602.91px" class="cls_006"><span class="cls_006">Importe Otros Tributos: $</span></div>
<div style="left:329.49px;top:602.91px" class="cls_006"><span class="cls_006">0,00</span></div>
<div style="left:449.48px;top:590.41px" class="cls_002"><span class="cls_002">IVA 10.5%: $</span></div>
<div style="left:557.49px;top:590.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="width:60px; left:449.48px;top:590.41px;" class="cls_002"><span class="cls_002">IVA 10.5%: $</span></div>
<div style="width:60px;left:86.6%;top:590.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_iva_105"] %></span></div>
<div style="left:461.99px;top:603.41px" class="cls_002"><span class="cls_002">IVA 5%: $</span></div>
<div style="left:557.49px;top:603.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:454.48px;top:616.41px" class="cls_002"><span class="cls_002">IVA 2.5%: $</span></div>
Expand Down
34 changes: 20 additions & 14 deletions lib/afip_bill/views/bills/factura_b.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
<%= @template_header %>

<div style="left:19.00px;top:272.04px" class="cls_010"><span class="cls_010">Código</span></div>
<div style="left:60.00px;top:272.04px" class="cls_010"><span class="cls_010">Producto / Servicio</span></div>
<div style="left:211.39px;top:272.04px" class="cls_010"><span class="cls_010">Cantidad</span></div>
<div style="left:263.61px;top:272.04px" class="cls_010"><span class="cls_010">U. Medida</span></div>
<div style="left:324.05px;top:272.66px" class="cls_011"><span class="cls_011">Precio Unit.</span></div>
<div style="left:386.97px;top:272.66px" class="cls_011"><span class="cls_011">% Bonif</span></div>
<div style="left:434.42px;top:272.66px" class="cls_011"><span class="cls_011">Imp. Bonif.</span></div>
<div style="left:520.50px;top:272.66px" class="cls_011"><span class="cls_011">Subtotal</span></div>
<div style="left:19.00px;top:270.04px" class="cls_010"><span class="cls_010">Código</span></div>
<div style="left:60.00px;top:270.04px" class="cls_010"><span class="cls_010">Producto / Servicio</span></div>
<div style="left:211.39px;top:270.04px" class="cls_010"><span class="cls_010">Cantidad</span></div>
<div style="left:263.61px;top:270.04px" class="cls_010"><span class="cls_010">U. Medida</span></div>
<div style="left:324.05px;top:270.66px" class="cls_011"><span class="cls_011">Precio Unit.</span></div>
<div style="left:386.97px;top:270.66px" class="cls_011"><span class="cls_011">% Bonif</span></div>
<div style="left:434.42px;top:270.66px" class="cls_011"><span class="cls_011">Imp. Bonif.</span></div>
<div style="left:520.50px;top:270.66px" class="cls_011"><span class="cls_011">Subtotal</span></div>

<% top = 293 %>
<% @line_items.each_with_index do |line_item, index| %>
<div style="left:18.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= (index + 1).to_s.rjust(3, "0") %></span></div>
<div style="left:57.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.name %></span></div>
<div style="width:60px;left:37.5%;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.quantity.round(2).to_s.tr(".", ",") %></span></div>
<div style="left:268.30px;top:<%= top %>px" class="cls_012"><span class="cls_012">unidades</span></div>
<div style="left:357.54px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.imp_unitario.round(2).to_s.tr(".", ",") %></span></div>
<div style="left:380px;top:<%= top %>px" class="cls_008"><span class="cls_008" style="position:absolute;right:0"><%= line_item.imp_unitario.to_s.tr(".", ",") %></span></div>
<div style="left:392.22px;top:<%= top %>px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:471.43px;top:<%= top %>px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="width:60px;left:91%;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.imp_total_unitario.round(2).to_s.tr(".", ",") %></span></div>
<% top += 25 %>
<% top += 15 %>
<% end %>

<div style="left:444.50px;top:616.59px" class="cls_002"><span class="cls_002">Subtotal: $</span></div>
<div style="width:60px;left:89.6%;top:616.59px" class="cls_002"><span class="cls_002"><%= afip_bill["imp_total"] %></span></div>
<div style="left:17.00px;top:500.97px" class="cls_008"><span class="cls_008">
<%= afip_bill["custom_text"] %>
</span></div>

<div style="left:444.50px;top:616.59px; " class="cls_002">
<span class="cls_002">Subtotal: $</span>
</div>
<div style="text-align: right; width:60px;right: 20.49px;top:616.59px" class="cls_002"><span class="cls_002"><%= afip_bill["imp_total"] %></span></div>
<div style="left:382.49px;top:634.59px" class="cls_002"><span class="cls_002">Importe Otros Tributos: $</span></div>
<div style="left:555.49px;top:634.59px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="text-align: right; width:60px; right: 20.49px;top:634.59px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:415.99px;top:652.54px" class="cls_005"><span class="cls_005">Importe Total: $</span></div>
<div style="width:60px;left:88.8%;top:652.54px" class="cls_005"><span class="cls_005"><%= afip_bill["imp_total"] %></span></div>
<div style="text-align: right; width:60px;right: 20.49px;top:652.54px" class="cls_005"><span class="cls_005"><%= afip_bill["imp_total"] %></span></div>

<%= @template_footer %>
64 changes: 64 additions & 0 deletions lib/afip_bill/views/notes/nota_a.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<%= @template_header %>

<div style="left:484.19px;top:259.63px" class="cls_011"><span class="cls_011">Alicuota</span></div>
<div style="left:19.00px;top:263.04px" class="cls_010"><span class="cls_010">Código</span></div>
<div style="left:59.00px;top:263.04px" class="cls_010"><span class="cls_010">Producto / Servicio</span></div>
<div style="left:239.39px;top:263.04px" class="cls_010"><span class="cls_010">Cantidad</span></div>
<div style="left:285.77px;top:263.66px" class="cls_011"><span class="cls_011">U. medida</span></div>
<div style="left:335.05px;top:263.66px" class="cls_011"><span class="cls_011">Precio Unit.</span></div>
<div style="left:388.47px;top:263.66px" class="cls_011"><span class="cls_011">% Bonif</span></div>
<div style="left:434.50px;top:263.66px" class="cls_011"><span class="cls_011">Subtotal</span></div>
<div style="left:524.27px;top:263.66px" class="cls_011"><span class="cls_011">Subtotal c/IVA</span></div>
<div style="left:492.17px;top:267.68px" class="cls_011"><span class="cls_011">IVA</span></div>

<% top = 283 %>
<% @line_items.each_with_index do |line_item, index| %>
<div style="left:18.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= (index + 1).to_s.rjust(3, "0") %></span></div>
<div style="left:57.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.name %></span></div>
<div style="width:60px;left:37%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.quantity.to_s.tr(".", ",") %> </span></div>
<div style="left:288.30px;top:<%= top %>px" class="cls_012"><span class="cls_012">unidades</span></div>
<div style="left:360.54px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.imp_unitario.to_s.tr(".", ",") %></span></div>
<div style="left:398.43px;top:<%= top %>px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="width:60px;left:70.4%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.imp_total_unitario.round(2).to_s.tr(".", ",") %></span></div>
<div style="left:490.00px;top:<%= top %>px" class="cls_008"><span class="cls_008"><%= line_item.iva %>%</span></div>
<div style="width:60px;left:87%;top:<%= top %>px" class="cls_008"><span style="position:absolute;right:0" class="cls_008"><%= line_item.imp_total_unitario_con_iva.round(2).to_s.tr(".", ",") %></span></div>
<% top += 25 %>
<% end %>

<div style="left:17.00px;top:511.97px" class="cls_010"><span class="cls_010">Otros Tributos</span></div>
<div style="left:21.00px;top:524.54px" class="cls_008"><span class="cls_008">Descripción</span></div>
<div style="left:184.00px;top:524.54px" class="cls_008"><span class="cls_008">Detalle</span></div>
<div style="left:270.61px;top:525.16px" class="cls_012"><span class="cls_012">Alíc. %</span></div>
<div style="left:317.88px;top:524.54px" class="cls_008"><span class="cls_008">Importe</span></div>
<div style="left:18.00px;top:538.63px" class="cls_008"><span class="cls_008">Per./Ret. de Impuesto a las Ganancias</span></div>
<div style="left:331.43px;top:538.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:18.00px;top:556.63px" class="cls_008"><span class="cls_008">Per./Ret. de IVA</span></div>
<div style="left:331.43px;top:556.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:397.98px;top:551.41px" class="cls_002"><span class="cls_002">Importe Neto Gravado: $</span></div>
<div style="width:60px;left:86.6%;top:551.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_neto"] %></span></div>
<div style="left:18.00px;top:567.63px" class="cls_008"><span class="cls_008">Per./Ret. Ingresos Brutos</span></div>
<div style="left:331.43px;top:567.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:456.98px;top:564.41px" class="cls_002"><span class="cls_002">IVA 27%: $</span></div>
<div style="left:557.49px;top:564.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:18.00px;top:578.63px" class="cls_008"><span class="cls_008">Impuestos Internos</span></div>
<div style="left:331.43px;top:578.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:18.00px;top:589.63px" class="cls_008"><span class="cls_008">Impuestos Municipales</span></div>
<div style="left:331.43px;top:589.63px" class="cls_008"><span class="cls_008">0,00</span></div>
<div style="left:456.98px;top:577.41px" class="cls_002"><span class="cls_002">IVA 21%: $</span></div>
<div style="width:60px;left:86.6%;top:577.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_iva_21"] || '0,00' %></span></div>
<div style="left:186.97px;top:602.91px" class="cls_006"><span class="cls_006">Importe Otros Tributos: $</span></div>
<div style="left:329.49px;top:602.91px" class="cls_006"><span class="cls_006">0,00</span></div>
<div style="width:60px;left:449.48px;top:590.41px" class="cls_002"><span class="cls_002">IVA 10.5%: $</span></div>
<div style="width:60px;left:86.6%;top:590.41px" class="cls_002"><span style="position:absolute;right:0" class="cls_002"><%= afip_bill["imp_iva_105"] || '0,00' %></span></div>
<div style="left:461.99px;top:603.41px" class="cls_002"><span class="cls_002">IVA 5%: $</span></div>
<div style="left:557.49px;top:603.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:454.48px;top:616.41px" class="cls_002"><span class="cls_002">IVA 2.5%: $</span></div>
<div style="left:557.49px;top:616.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:461.99px;top:629.41px" class="cls_002"><span class="cls_002">IVA 0%: $</span></div>
<div style="left:557.49px;top:629.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:394.49px;top:642.41px" class="cls_002"><span class="cls_002">Importe Otros Tributos: $</span></div>
<div style="left:557.49px;top:642.41px" class="cls_002"><span class="cls_002">0,00</span></div>
<div style="left:427.99px;top:656.29px" class="cls_005"><span class="cls_005">Importe Total: $</span></div>
<div style="width:60px;left:86.6%;top:656.29px" class="cls_005"><span style="position:absolute;right:0" class="cls_005"><%= afip_bill["imp_total"] %></span></div>

<%= @template_footer %>
Loading