LedgerEntry
in package
implements
JsonSerializable
uses
DatabaseTrait, ActiveRecordTrait
LedgerEntries are the fundamental unit of the Material Ledger.
A LedgerEntry is a movement of material into or out of an account. Ledger Entries can be joined by a transaction
Table of Contents
Interfaces
- JsonSerializable
Properties
- $active_time : string|null
- represents the time the ledger entry was active in the account this is being set when you ask the account for inflows or outflows at a time
- $direction : string|null
- $error_message : string
- $hydrated_event_objects : array<string|int, mixed>|null
- $hydrated_material_attributes : array<string|int, mixed>|null
- $material_name : string|null
- $trace_path : array<string|int, mixed>
- $account : Account|null
- $account_id : int|null
- $allowed_props : array<string|int, mixed>
- $amount : int|null
- $end_balance : string|null
- $end_timestamp : string|null
- $id : int|null
- $material : Type|null
- $material_attributes : string|null
- $material_id : int|null
- $measurementUnit : MeasurementUnit|null
- $object_events : string|null
- $operating_table : string
- $prop_types : array<string|int, mixed>
- $schema : string
- $start_balance : string|null
- $start_timestamp : string|null
- $target_amount : int|null
- $transaction_id : int|null
- $unit_id : int|null
- $unsaved_props : array<string|int, mixed>
Methods
- __construct() : mixed
- __get() : mixed
- If the property is an attribute, then return the attribute object.
- __set() : void
- Set a property for this node, the value will not be saved until the 'save' method is called.
- appendEvent() : void
- Appends an array of event_object_ids into a ledger entry
- closeEntry() : void
- Closes a ledger Entry and its subsequent pair. This will also trigger the accounts parent's class script and look for methods in the MaterialAware Interface.
- configErrorMessage() : string
- Returns the configuration error message.
- createMovement() : void
- Creates a Material Movement
- createOpenFlow() : void
- createTransaction() : int
- delete() : void
- TODO: delete transaction pairs if needed
- generateRelativeName() : string
- Gets the `generate_relative_name_from_display_name`.
- getAccount() : Account
- getAllowedProps() : array<string|int, mixed>
- Get the allowed properties for this Node Return an array intersection of the Class Properties and Table Columns.
- getConfig() : TiqConfig
- Gets the TIQ configuration.
- getDb() : PgSQL
- Gets database instance.
- getMaterial() : Type|null
- getMeasurementUnit() : MeasurementUnit|null
- getMovements() : array<string|int, mixed>
- This returns all immediate LedgerEntries that influenced this one based on direction
- hydrateData() : void
- Populates the relevant data in a ledger entry Decodes the material_attributes column and the object_events column
- isDebug() : bool
- Is debug mode or not.
- jsonSerialize() : array<string|int, mixed>
- Typically used to create a structure that js can turn into an object in the browser minus the DatabaseTrait properties.
- JSONSerializeRecord() : array<string|int, mixed>
- Returns an array that can can easily be json_encoded
- save() : void
- writes updated properties into the database, or creates it if it does not exist.
- verifyMovement() : bool
- Checks if the movement has a valid amount based on the accounts' minimum_movement_amount. Movements cannot be negative, so the default threshold will be 0
- setProps() : void
- Loads all database columns as static variables. To load a variable, it must exist in the class.
Properties
$active_time
represents the time the ledger entry was active in the account this is being set when you ask the account for inflows or outflows at a time
public
string|null
$active_time
= null
$direction
public
string|null
$direction
= null
$error_message
public
static string
$error_message
= 'An issue occurred, please contact ThinkIQ for Support and enable debugging'
- Base error message
$hydrated_event_objects
public
array<string|int, mixed>|null
$hydrated_event_objects
= []
$hydrated_material_attributes
public
array<string|int, mixed>|null
$hydrated_material_attributes
= []
$material_name
public
string|null
$material_name
= null
$trace_path
public
array<string|int, mixed>
$trace_path
= []
$account
protected
Account|null
$account
= null
$account_id
protected
int|null
$account_id
= null
$allowed_props
protected
array<string|int, mixed>
$allowed_props
= []
$amount
protected
int|null
$amount
= null
$end_balance
protected
string|null
$end_balance
= null
$end_timestamp
protected
string|null
$end_timestamp
= null
$id
protected
int|null
$id
= null
$material
protected
Type|null
$material
= null
$material_attributes
protected
string|null
$material_attributes
= null
$material_id
protected
int|null
$material_id
= null
$measurementUnit
protected
MeasurementUnit|null
$measurementUnit
= null
$object_events
protected
string|null
$object_events
= null
$operating_table
protected
string
$operating_table
= 'ledger_entries'
$prop_types
protected
array<string|int, mixed>
$prop_types
= []
$schema
protected
string
$schema
= 'material_ledger'
$start_balance
protected
string|null
$start_balance
= null
$start_timestamp
protected
string|null
$start_timestamp
= null
$target_amount
protected
int|null
$target_amount
= null
$transaction_id
protected
int|null
$transaction_id
= null
$unit_id
protected
int|null
$unit_id
= null
$unsaved_props
protected
array<string|int, mixed>
$unsaved_props
= []
Methods
__construct()
public
__construct([string|int|null $identifier = null ][, array<string|int, mixed> $config = [] ][, array<string|int, mixed> $additionalMethods = [] ]) : mixed
Parameters
- $identifier : string|int|null = null
-
- FQN or ID
- $config : array<string|int, mixed> = []
-
- This array contains the same properties as a record from the corresponding table in the database
- $additionalMethods : array<string|int, mixed> = []
-
- Methods to be call we initiate the class.
Tags
__get()
If the property is an attribute, then return the attribute object.
public
__get(mixed $name) : mixed
Parameters
- $name : mixed
-
- The name of the attribute we want to get.
__set()
Set a property for this node, the value will not be saved until the 'save' method is called.
public
__set(string $prop, mixed $value) : void
Parameters
- $prop : string
-
- The property we want to set.
- $value : mixed
-
- The value we want to set into the property.
appendEvent()
Appends an array of event_object_ids into a ledger entry
public
appendEvent(array<string|int, mixed> $event_ids) : void
TODO: this should be one SQL statement
Parameters
- $event_ids : array<string|int, mixed>
Tags
closeEntry()
Closes a ledger Entry and its subsequent pair. This will also trigger the accounts parent's class script and look for methods in the MaterialAware Interface.
public
closeEntry(DateTimeInterface|null $end_timestamp) : void
Note that there is a flaw here for more than 2 entries in a transaction $this is the open outflow ledger entry
Parameters
- $end_timestamp : DateTimeInterface|null
Tags
configErrorMessage()
Returns the configuration error message.
public
static configErrorMessage() : string
Return values
stringcreateMovement()
Creates a Material Movement
public
static createMovement(Node|Account $source, Node|Account $destination, DateTimeInterface $start_time[, DateTimeInterface|null $end_time = null ][, float|int|null $amount = null ][, int|null $unit_id = null ][, int|null $material_id = null ][, null $material_attributes = null ][, array<string|int, mixed>|null $event_ids = null ]) : void
A Material movement is the sum of at least two ledger entries bound by a transaction. This is a bit of a beast, as a Movement will have many properties.
Parameters
- $source : Node|Account
-
Node that has an account
- $destination : Node|Account
-
Node that has an account
- $start_time : DateTimeInterface
- $end_time : DateTimeInterface|null = null
- $amount : float|int|null = null
- $unit_id : int|null = null
- $material_id : int|null = null
- $material_attributes : null = null
- $event_ids : array<string|int, mixed>|null = null
Tags
createOpenFlow()
public
static createOpenFlow(int $account_id, DateTimeInterface $start, string $direction[, int|null $transaction_id = null ]) : void
Parameters
- $account_id : int
- $start : DateTimeInterface
- $direction : string
- $transaction_id : int|null = null
createTransaction()
public
static createTransaction([string $created_by = '' ][, string $details = '' ]) : int
Parameters
- $created_by : string = ''
- $details : string = ''
Tags
Return values
intdelete()
TODO: delete transaction pairs if needed
public
delete() : void
generateRelativeName()
Gets the `generate_relative_name_from_display_name`.
public
static generateRelativeName(string $displayName[, string|null $typeName = null ][, int|null $partOfId = null ][, int|null $nodeId = null ]) : string
Parameters
- $displayName : string
-
- The display name we are searching.
- $typeName : string|null = null
-
- The type name we are searching.
- $partOfId : int|null = null
-
- The part of ID we are searching.
- $nodeId : int|null = null
-
- The Node ID that we are searching.
Return values
stringgetAccount()
public
getAccount() : Account
Tags
Return values
AccountgetAllowedProps()
Get the allowed properties for this Node Return an array intersection of the Class Properties and Table Columns.
public
getAllowedProps() : array<string|int, mixed>
Return values
array<string|int, mixed>getConfig()
Gets the TIQ configuration.
public
static getConfig() : TiqConfig
Return values
TiqConfiggetDb()
Gets database instance.
public
static getDb() : PgSQL
The database connection is stored in a static property within the DatabaseConnectionManager class, ensuring that it is truly a singleton across the entire application, regardless of which class calls this method.
Return values
PgSQLgetMaterial()
public
getMaterial() : Type|null
Tags
Return values
Type|nullgetMeasurementUnit()
public
getMeasurementUnit() : MeasurementUnit|null
Tags
Return values
MeasurementUnit|nullgetMovements()
This returns all immediate LedgerEntries that influenced this one based on direction
public
getMovements(string $direction) : array<string|int, mixed>
Parameters
- $direction : string
Tags
Return values
array<string|int, mixed>hydrateData()
Populates the relevant data in a ledger entry Decodes the material_attributes column and the object_events column
public
hydrateData() : void
Tags
isDebug()
Is debug mode or not.
public
static isDebug() : bool
Return values
booljsonSerialize()
Typically used to create a structure that js can turn into an object in the browser minus the DatabaseTrait properties.
public
jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>JSONSerializeRecord()
Returns an array that can can easily be json_encoded
public
JSONSerializeRecord() : array<string|int, mixed>
Return values
array<string|int, mixed>save()
writes updated properties into the database, or creates it if it does not exist.
public
save() : void
Tags
verifyMovement()
Checks if the movement has a valid amount based on the accounts' minimum_movement_amount. Movements cannot be negative, so the default threshold will be 0
public
static verifyMovement(Account $source_account, Account $destination_account, int|float|null $amount) : bool
Parameters
Return values
boolsetProps()
Loads all database columns as static variables. To load a variable, it must exist in the class.
protected
setProps([array<string|int, mixed> $config = [] ][, array<string|int, mixed> $additionalMethods = [] ]) : void
If the 'id' property is not set, we still run this function, populating the $allowed_props variable.
Parameters
- $config : array<string|int, mixed> = []
-
- This array contains the same properties as a record from the corresponding table in the database.
- $additionalMethods : array<string|int, mixed> = []
-
- Methods to be call to call when we initiate the class.