Sha256: d89b36f313507ff4e6e87bd25388727f5be2e8a43d78966397182cf7a108b757

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

class Kaui::InvoiceItemsController < Kaui::EngineController
  def index
    if params[:invoice_item_id].present? and params[:invoice_id].present?
      redirect_to invoice_item_path(params[:invoice_item_id], :invoice_id => params[:invoice_id])
    end
  end

  def show
    find_invoice_item
  end

  def edit
    find_invoice_item
  end

  def update
    @invoice_item = Kaui::InvoiceItem.new(params[:invoice_item])
    success = Kaui::KillbillHelper.adjust_invoice(@invoice_item, current_user, params[:reason], params[:comment])
    if success
      flash[:notice] = "Adjustment item created"
      redirect_to invoice_path(@invoice_item.invoice_id)
    else
      flash[:error] = "Unable to create adjustment item"
      render :action => "edit"
    end
  end

  private

  def find_invoice_item
    invoice_item_id = params[:id]
    invoice_id = params[:invoice_id]
    if invoice_item_id.present? and invoice_id.present?
      @invoice_item = Kaui::KillbillHelper.get_invoice_item(invoice_id, invoice_item_id)
      unless @invoice_item.present?
        flash[:error] = "Invoice for id #{invoice_id} and invoice item id #{invoice_item_id} not found"
        render :action => :index
      end
    else
      flash[:error] = "Both invoice item and invoice ids should be specified"
      render :action => :index
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kaui-0.1.3 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.2 app/controllers/kaui/invoice_items_controller.rb