mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +02:00
- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is changed to `rake 'invoices:cancel_overdue'`. - `invoices.payment_term` database column is removed and its value is hardcoded in UI. - `invoices.paid_at` is removed as unused - `invoices.due_date` column's type is now `date`. - `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice` interface to get a list of items is unified. - Default date format in UI. - Default translations are used. - Tests improved. - Specs converted to tests and removed along with factories. - Database structure improved.
58 lines
1.5 KiB
Ruby
58 lines
1.5 KiB
Ruby
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)
|
|
|
|
normalize_search_parameters do
|
|
@q = invoices.search(params[:q])
|
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
|
@invoices = @q.result.page(params[:page])
|
|
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 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
|
|
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]
|
|
yield
|
|
end
|
|
end
|
|
end
|