mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Refactor invoice PDF generation, download and delivery
- Remove `Que::Mailer` (#895) - Extract controllers - Extract translations - Convert HAML to ERB - Add mailer preview - Improve UI - Remove unused routes - Add tests
This commit is contained in:
parent
7e0fd30125
commit
27ea790b28
30 changed files with 288 additions and 138 deletions
|
@ -26,9 +26,6 @@ class Invoice < ActiveRecord::Base
|
|||
|
||||
scope :overdue, -> { unpaid.non_cancelled.where('due_date < ?', Time.zone.today) }
|
||||
|
||||
attr_accessor :billing_email
|
||||
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
|
||||
|
||||
validates :issue_date, presence: true
|
||||
validates :due_date, :currency, :seller_name,
|
||||
:seller_iban, :buyer_name, :items, presence: true
|
||||
|
@ -84,23 +81,6 @@ class Invoice < ActiveRecord::Base
|
|||
"Order nr. #{number}"
|
||||
end
|
||||
|
||||
def pdf(html)
|
||||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
end
|
||||
|
||||
def pdf_name
|
||||
"invoice-#{number}.pdf"
|
||||
end
|
||||
|
||||
def forward(html)
|
||||
return false unless valid?
|
||||
return false unless billing_email.present?
|
||||
|
||||
InvoiceMailer.invoice_email(id, html, billing_email).deliver
|
||||
true
|
||||
end
|
||||
|
||||
def subtotal
|
||||
items.map(&:item_sum_without_vat).reduce(:+)
|
||||
end
|
||||
|
@ -119,6 +99,11 @@ class Invoice < ActiveRecord::Base
|
|||
items.each { |item| yield item }
|
||||
end
|
||||
|
||||
def as_pdf
|
||||
generator = PdfGenerator.new(self)
|
||||
generator.as_pdf
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def apply_default_vat_rate
|
||||
|
@ -132,4 +117,4 @@ class Invoice < ActiveRecord::Base
|
|||
def calculate_total
|
||||
self.total = subtotal + vat_amount
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue