mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +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
|
@ -2,8 +2,6 @@ class Registrar
|
|||
class InvoicesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_invoice, only: [:show, :forward, :download_pdf]
|
||||
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
invoices = current_registrar_user.registrar.invoices.includes(:items, :account_activity)
|
||||
|
@ -15,40 +13,20 @@ class Registrar
|
|||
end
|
||||
end
|
||||
|
||||
def show;
|
||||
end
|
||||
|
||||
def forward
|
||||
@invoice.billing_email = @invoice.buyer.billing_email
|
||||
|
||||
return unless request.post?
|
||||
|
||||
@invoice.billing_email = params[:invoice][:billing_email]
|
||||
|
||||
if @invoice.forward(render_to_string('pdf', layout: false))
|
||||
flash[:notice] = t(:invoice_forwared)
|
||||
redirect_to([:registrar, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_forward_invoice)
|
||||
end
|
||||
end
|
||||
def show; end
|
||||
|
||||
def cancel
|
||||
@invoice.cancel
|
||||
redirect_to [:registrar, @invoice], notice: t('.cancelled')
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
|
||||
send_data pdf, filename: @invoice.pdf_name
|
||||
def download
|
||||
filename = "invoice-#{@invoice.number}.pdf"
|
||||
send_data @invoice.as_pdf, filename: filename
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_invoice
|
||||
@invoice = Invoice.find(params[:id])
|
||||
end
|
||||
|
||||
def normalize_search_parameters
|
||||
params[:q][:total_gteq].gsub!(',', '.') if params[:q][:total_gteq]
|
||||
params[:q][:total_lteq].gsub!(',', '.') if params[:q][:total_lteq]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue