Sha256: 6c0b4ceae8cfbb2f437cb5dedf9e769298d2ef071af82f99e33a4de57168ab9f

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

class Kaui::InvoiceItemsController < Kaui::EngineController
  def index
    if params[:invoice_item_id].present? and params[:invoice_id].present?
      redirect_to kaui_engine.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])
    begin
      Kaui::KillbillHelper.adjust_invoice(@invoice_item, current_user, params[:reason], params[:comment])
      flash[:notice] = "Adjustment item created"
      redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id)
    rescue => e
      flash[:error] = "Error while updating the invoice item: #{as_string(e)}"
      render :action => "edit"
    end
  end

  def destroy
    begin
      Kaui::KillbillHelper.delete_cba(params[:account_id], params[:invoice_id], params[:id], current_user, params[:reason], params[:comment])
      flash[:notice] = "CBA deleted"
      redirect_to kaui_engine.invoice_path(params[:invoice_id])
    rescue => e
      flash[:error] = "Error while deleting the CBA: #{as_string(e)}"
      redirect_to kaui_engine.invoice_path(params[:invoice_id])
    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?
      begin
        @invoice_item = Kaui::KillbillHelper.get_invoice_item(invoice_id, invoice_item_id)
      rescue => e
        flash[:error] = "Error while trying to find the invoice item: #{as_string(e)}"
      end
      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

13 entries across 13 versions & 1 rubygems

Version Path
kaui-0.2.6 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.5 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.4 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.3 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.2 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.1 app/controllers/kaui/invoice_items_controller.rb
kaui-0.2.0 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.18 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.17 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.16 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.15 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.14 app/controllers/kaui/invoice_items_controller.rb
kaui-0.1.12 app/controllers/kaui/invoice_items_controller.rb