Code Monkey home page Code Monkey logo

laravel-ledger's People

Contributors

ikidnapmyself avatar nholliday avatar vswarte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-ledger's Issues

LedgerMutation getAmountAttribute Error

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));
}

Bug in LedgerTransaction

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');
}

Allow batch transaction insert as well as creation of transactions without storing them

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

LedgerMutation -> LedgerTransaction

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');
}

Creating a new account throws an error

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.

Getting the Id of a new transaction

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);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.