Class: MOCO::PurchaseBudget

Inherits:
BaseEntity show all
Defined in:
lib/moco/entities/purchase_budget.rb

Overview

Represents a MOCO purchase budget (Ausgaben – Budgets) Read-only budget tracking for expense categories

Read-only attributes:

id, title, year, target, exhausted, remaining,
created_at, updated_at

Helper methods:

remaining_percentage   - Percentage of budget remaining
exhausted_percentage   - Percentage of budget used

Example:

budgets = moco.purchase_budgets.all
budgets.each do |budget|
  puts "#{budget.title}: #{budget.remaining_percentage}% remaining"
end

Note:

Purchase budgets are configured in MOCO's admin interface.
This endpoint provides read-only access for tracking.

Instance Attribute Summary

Attributes inherited from BaseEntity

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEntity

#==, #association, #destroy, #eql?, #has_many, #hash, #id, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update

Constructor Details

This class inherits a constructor from MOCO::BaseEntity

Class Method Details

.entity_pathObject

Custom path since it’s nested under purchases



27
28
29
# File 'lib/moco/entities/purchase_budget.rb', line 27

def self.entity_path
  "purchases/budgets"
end

Instance Method Details

#exhausted_percentageObject



41
42
43
44
45
# File 'lib/moco/entities/purchase_budget.rb', line 41

def exhausted_percentage
  return 0 if target.to_f.zero?

  (exhaused.to_f / target.to_f * 100).round(1)
end

#remaining_percentageObject



35
36
37
38
39
# File 'lib/moco/entities/purchase_budget.rb', line 35

def remaining_percentage
  return 0 if target.to_f.zero?

  (remaining.to_f / target.to_f * 100).round(1)
end

#to_sObject



31
32
33
# File 'lib/moco/entities/purchase_budget.rb', line 31

def to_s
  "PurchaseBudget #{id}: #{title} (#{year})"
end