mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +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 @@ module Admin
|
|||
class InvoicesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_invoice, only: [:forward, :download_pdf]
|
||||
|
||||
def new
|
||||
@deposit = Deposit.new
|
||||
end
|
||||
|
@ -28,33 +26,16 @@ module Admin
|
|||
@invoices = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@invoice = Invoice.find(params[:id])
|
||||
end
|
||||
def show; end
|
||||
|
||||
def cancel
|
||||
@invoice.cancel
|
||||
redirect_to [:admin, @invoice], notice: t('.cancelled')
|
||||
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('registrar/invoices/pdf', layout: false))
|
||||
flash[:notice] = t(:invoice_forwared)
|
||||
redirect_to([:admin, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_forward_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
pdf = @invoice.pdf(render_to_string('registrar/invoices/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
|
||||
|
@ -62,9 +43,5 @@ module Admin
|
|||
def deposit_params
|
||||
params.require(:deposit).permit(:amount, :description, :registrar_id)
|
||||
end
|
||||
|
||||
def set_invoice
|
||||
@invoice = Invoice.find(params[:invoice_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue