Download the PHP package abather/mini-accounting without Composer
On this page you can find all versions of the php package abather/mini-accounting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abather/mini-accounting
More information about abather/mini-accounting
Files in abather/mini-accounting
Package mini-accounting
Short Description Create accounts for any model to withdraw and deposit to it.
License MIT
Homepage https://github.com/abather/mini-accounting
Informations about the package mini-accounting
Create accounts for any model to withdraw and deposit to it
Adding an Account to Your Models and Tracking Transactions
To seamlessly integrate account functionality into your Laravel models and keep track of transactions, follow the steps outlined below.
Installation
Begin by installing the package via Composer:
Next, publish and run the migrations:
You can also publish the configuration file:
The contents of the published configuration file (config/mini-accounting.php
) will look like this:
Usage
This package links two entities: Accountable (a model with an account) and Referencable (a document triggering account deposits or withdrawals).
Accountable
To make a model accountable, use the HasAccountMovement
trait:
Now you can deposit or withdraw any amount from it by referring to any reference model:
You can also provide notes or extra data in JSON format to any transaction:
To get the model's current balance:
You can also retrieve the model's balance at the end of any month:
you can also pass the year for this function if you went any year other than this year balanceAtEndOfMonth(6, 1990)
also you can get the balance for any given year:
as end of month balance you can specify the year balanceAtEndOfYear(1990)
Referencable
Make any model referencable by using the Referencable
trait and implementing the Referencable
interface:
Define the defaultTransactions(): array
method. This method will be described later. Similar to the accountable model,
you can deposit and withdraw from the referencable model, affecting different accounts simultaneously. For example, when
a user buys from a market, the bill will deposit the amount into the market's account and withdraw the same amount from
the user's account:
Assuming you have another transaction caused by the bill, such as a commission, your code would be:
To simplify, define the default transactions for each referencable model using the defaultTransactions
method:
For each object (either Deposit
or Withdraw
), set the affected account and the calculation method used to determine the transaction amount.
-
you can have meta-Data with the transactions using :
- also you can add note to the transaction via
Account
Refer to the desired account in three ways: direct relationship from the current model, using a foreign key from the current model, or giving it any ID for reference:
In this example, specify the model in the make
method; during calculation, the account will be the market linked with
the current entity ($bill->market
). Other settings include:
variable('market_id')
: Provide any key from your model referring to the entity ($bill->market_id
).static(3)
: Lock the record with the ID3
. Also, pass a second parameter to themake()
method to specify the entity being referred to:
In this way, you do not need to provide any other functions.
Calculation
For calculation, use the following objects:
Abather\MiniAccounting\Objects\Calculations\Equal
Abather\MiniAccounting\Objects\Calculations\Subtraction
Abather\MiniAccounting\Objects\Calculations\Addition
Abather\MiniAccounting\Objects\Calculations\Percentage
For each object, provide make($resource, $attribute)
. In our previous example, make($this, "amount")
means
the calculation will be on $bill->amount
. Except for Equal
, you must also define factor
, which is the other side
of each equation. Factor
can be either dynamic or a static value:
StaticFactor::make(10)
: The other side of the equation is 10 (e.g.,$bill->amount - 10
).DynamicFactor::make($this, 'percentage')
: The other side of the equation is$bill->percentage
.
After defining defaultTransactions()
, use it by calling executeDefaultTransactions()
. You are free to define as
many transactions
methods as needed. Keep in mind that the name of each method should end with Transactions
, and you
can run these transactions by calling the function with "execute" at the beginning of the method name (
e.g., cancelTransactions()
runs transactions using executeCancelTransactions()
).
Note:
If you ever use __call($method, $parameters)
in
your Accountable
or Referencable
models, please add the following lines:
-
Accountable:
- Referencable:
This documentation pertains to a Laravel package designed to enhance models' capabilities by linking them to their accounts. Additionally, it establishes links with other models to serve as reference documents, such as bills or refunds.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Abather
- JoDeveloper
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of mini-accounting with dependencies
illuminate/contracts Version ^10.0
laravel/framework Version ^10.10
spatie/laravel-package-tools Version ^1.14.0