vswarte / laravel-ledger Goto Github PK
View Code? Open in Web Editor NEWgeneric financial ledger to keep track of monetary transactions
generic financial ledger to keep track of monetary transactions
The getAmountAttribute function seems to throw an error when called. Fixed by adding the 'new' keyword:
public function getAmountAttribute($value)
{
return new Money($value, new Currency($this->currency));
}
public function mutations()
{
return $this->hasMany(LedgerTransaction::class, 'ledger_transaction_id');
}
Should surely be:
public function mutations()
{
return $this->hasMany(LedgerMutation::class, 'ledger_transaction_id');
}
The current database interaction process for inserts is entangled in the factory class. This makes no sense from an SRP perspective and it also means you cannot create a transaction without storing it immediately and you cannot insert multiple transactions in batch (meaning you cannot enforce that either all or none of the transactions happen).
Needs reworking
Hi,
I'm trying to access a LedgerMutation's description but the description field in the ledger_mutations table is null, and there doesn't seem to be any way of directly accessing a LedgerMutation's transaction.
Should there be a relation on the LedgerMutation model linking to the relevant LedgerTransaction?
Maybe something like:
public function transaction()
{
return $this->belongsTo(LedgerTransaction::class, 'ledger_transaction_id');
}
When creating a new account from an existing user :
$user = User::find(1);
$account = $user->createAccount("example", "description");
Throws an error in the Accountable
trait:
Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, array given, called in ..../vendor/vswarte/laravel-ledger/src/Accountable.php on line 21
This is because the trait calls save
on the model, which expects a Model
, but an array is passed. Changing the method to create
allows for passing arrays.
It would be handy to be able to get the id of the transaction created by the createTransaction function of the TransactionFactory, so that for example it can be logged against another model to which it relates.
Perhaps the following would work:
public static function createTransaction(
array $mutations,
string $description
) {
return DB::transaction(function () use ($mutations, $description) {
$transaction = LedgerTransaction::create([
'description' => $description,
])->fresh();
$transaction->mutations()->saveMany($mutations);
return $transaction->id;
}, 5);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.