Sha256: 7491f8dc12c27919860825b31275a5d8d76d9ea26227bc2b9a972f83d66fc9bd

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

module MnoEnterprise
  class Jpi::V1::Admin::InvoicesController < Jpi::V1::Admin::BaseResourceController

    # GET /mnoe/jpi/v1/admin/invoices
    def index
      @invoices = MnoEnterprise::Invoice.all
    end

    # GET /mnoe/jpi/v1/admin/invoices/1
    def show
      @invoice = MnoEnterprise::Invoice.find(params[:id])
    end

    # GET /mnoe/jpi/v1/admin/invoices/current_billing_amount
    def current_billing_amount
      # Backward compatibility with old MnoHub (<= v1.0.2)
      # TODO: Remove once all mnohub are migrated to newer versions
      tenant.respond_to?(:current_billing_amount) && current_billing = tenant.current_billing_amount

      render json: {current_billing_amount: format_money(current_billing)}
    end

    # GET /mnoe/jpi/v1/admin/invoices/last_invoicing_amount
    def last_invoicing_amount
      tenant_billing = tenant.last_customers_invoicing_amount
      render json: {last_invoicing_amount: format_money(tenant_billing)}
    end

    # GET /mnoe/jpi/v1/admin/invoices/outstanding_amount
    def outstanding_amount
      tenant_billing = tenant.last_customers_outstanding_amount
      render json: {outstanding_amount: format_money(tenant_billing)}
    end

    # GET /mnoe/jpi/v1/admin/invoices/last_portfolio_amount
    def last_portfolio_amount
      tenant_billing = tenant.last_portfolio_amount
      render json: {last_portfolio_amount: format_money(tenant_billing)}
    end

    # GET /mnoe/jpi/v1/admin/invoices/last_commission_amount
    def last_commission_amount
      tenant_billing = tenant.last_commission_amount
      render json: {last_commission_amount: format_money(tenant_billing)}
    end

    private

    def tenant
      @tenant ||= MnoEnterprise::Tenant.show
    end

    def format_money(money)
      if money
        {amount: money.amount, currency: money.currency_as_string}
      else
        {amount: 'N/A', currency: ''}
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mno-enterprise-api-3.3.3 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.3.2 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.2.1 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.3.1 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.3.0 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.2.0 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.1.4 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.0.7 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.1.3 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.0.6 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.1.2 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb
mno-enterprise-api-3.0.5 app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb