Giter Club home page Giter Club logo

laravel-ledger-1's Introduction

About this library

This is a simple/basic implementation of a ledger in laravel 5

Actions supported

  • RECORDING DEBITS
  • RECORDING CREDITS
  • BALANCE COMPUTATION

Installation

git clone https://github.com/mpaannddreew/laravel-ledger.git

Register service provider

FannyPack\Ledger\LedgerServiceProvider::class,

Register Facade Register service provider

'Ledger' => FannyPack\Ledger\Facades\Ledger::class,

After the service provider is registered run this command

php artisan vendor:publish --tag=ledger

Run migrations

php artisan migrate

This command will copy the library's vue components into your codebase

Register package routes in your app's RouteServiceProvider

Ledger::routes();

Usage

Using it with your models, add

namespace App;

use FannyPack\Ledger\Traits\Ledgerable;
use Illuminate\Database\Eloquent\Model;

class Account extends Model
{
    use Ledgerable;
}

Show available balance

$account = Account::find(1);
$balance = Ledger::balance($account);

or

$account = Account::find(1);
$balance = $account->balance();

Record a credit entry

$account = Account::find(1);
Ledger::credit($account, $to, $amount, $reason);

or

$account = Account::find(1);
$account->credit($to, $amount, $reason);

Record a debit entry

$account = Account::find(1);
Ledger::debit($account, $from, $amount, $reason);

or

$account = Account::find(1);
$account->debit($from, $amount, $reason);

Recording debits and credits in one transaction

$account = Account::find(1);
$account2 = Account::find(2);
$account3 = Account::find(3);
Ledger::transfer($account, [$account2, $account3], $amount, $reason);
// or
Ledger::transfer($account, $account2, $amount, $reason);
Ledger::transfer($account, $account3, $amount, $reason);

or

$account = Account::find(1);
$account2 = Account::find(2);
$account3 = Account::find(3);
$account->transfer([$account2, $account3], $amount, $reason);
// or
$account->transfer($account2, $amount, $reason);
$account->transfer($account3, $amount, $reason);

Retrieving all entries of a ledgerable

$account = Account::find(1);
$entries = $account->entries();

Retrieving all debits of a ledgerable

$account = Account::find(1);
debits = $account->debits();

Retrieving all credits of a ledgerable

$account = Account::find(1);
debits = $account->credits();

Using the provided Ledger.vue component in your blade templates

<ledger></ledger>

Bugs

For any bugs found, please email me at [email protected] or register an issue at issues

laravel-ledger-1's People

Contributors

mpaannddreew avatar adriangoris avatar kristories avatar

Watchers

James Cloos avatar  avatar

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.