Class: DhanHQ::Models::LedgerEntry
- Defined in:
- lib/DhanHQ/models/ledger_entry.rb
Overview
Model representing a single ledger entry in the Trading Account Ledger Report.
The Ledger Report contains all credit and debit transaction details for a particular time interval. Each entry represents a single transaction with details such as narration, voucher information, debit/credit amounts, and running balance.
Constant Summary collapse
- HTTP_PATH =
Base path for ledger endpoint.
"/v2/ledger"
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.all(from_date:, to_date:) ⇒ Array<LedgerEntry>
Retrieves Trading Account Ledger Report entries for the specified date range.
-
.resource ⇒ DhanHQ::Resources::Statements
Provides a shared instance of the Statements resource.
Instance Method Summary collapse
-
#to_h ⇒ Hash{Symbol => String}
Converts the LedgerEntry model attributes to a hash representation.
Methods inherited from BaseModel
api, api_type, #assign_attributes, attributes, create, #delete, #destroy, find, #id, #initialize, #new_record?, #optionchain_api?, parse_collection_response, #persisted?, resource_path, #save, #save!, #to_request_params, #update, #valid?, validate_attributes, validation_contract, #validation_contract, where
Methods included from APIHelper
Methods included from AttributeHelper
#camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys
Methods included from ValidationHelper
#valid?, #validate!, #validate_params!
Methods included from RequestHelper
Constructor Details
This class inherits a constructor from DhanHQ::BaseModel
Class Method Details
.all(from_date:, to_date:) ⇒ Array<LedgerEntry>
This is a GET request with query parameters. No body required.
The ledger report represents historical data dumps and entries are returned as-is without additional validation.
Retrieves Trading Account Ledger Report entries for the specified date range.
Fetches all credit and debit transaction details for the given time interval. The ledger entries include transaction descriptions, voucher information, amounts, and running balances.
97 98 99 100 101 102 103 104 105 |
# File 'lib/DhanHQ/models/ledger_entry.rb', line 97 def all(from_date:, to_date:) response = resource.ledger(from_date: from_date, to_date: to_date) return [] unless response.is_a?(Array) response.map do |entry| new(entry, skip_validation: true) end end |
.resource ⇒ DhanHQ::Resources::Statements
Provides a shared instance of the Statements resource.
41 42 43 |
# File 'lib/DhanHQ/models/ledger_entry.rb', line 41 def resource @resource ||= DhanHQ::Resources::Statements.new end |
Instance Method Details
#to_h ⇒ Hash{Symbol => String}
Converts the LedgerEntry model attributes to a hash representation.
Useful for serialization, logging, or passing ledger entry data to other methods.
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/DhanHQ/models/ledger_entry.rb', line 133 def to_h { dhan_client_id: dhan_client_id, narration: narration, voucherdate: voucherdate, exchange: exchange, voucherdesc: voucherdesc, vouchernumber: vouchernumber, debit: debit, credit: credit, runbal: runbal } end |