Skip to content

Commit

Permalink
Merge pull request #3 from mpaannddreew/dev-master
Browse files Browse the repository at this point in the history
Dev master
  • Loading branch information
mpaannddreew authored Oct 30, 2017
2 parents b94fb1f + eabb41d commit 1f1c417
Showing 1 changed file with 51 additions and 37 deletions.
88 changes: 51 additions & 37 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,137 @@ This is a simple/basic implementation of a ledger in laravel 5
- BALANCE COMPUTATION

## Installation

#### Composer
Above installation can also be simplify by using the following command:

```php
composer require fannypack/ledger
```

#### Service Provider and Facade

Add `FannyPack\Ledger\LedgerServiceProvider::class` to your application service providers in `config/app.php` file:

Register service provider
```php
FannyPack\Ledger\LedgerServiceProvider::class,
```
Register Facade
Register service provider

You can use the facade for shorter code. Add this to your aliases:

```php
'Ledger' => FannyPack\Ledger\Facades\Ledger::class,
```
#### Migrations

After the service provider is registered run this command
Finally, you'll also need to run migration on the package:
```
php artisan vendor:publish --tag=ledger
php artisan vendor:publish
```
Run migrations

#### Vue
Optionally, this command will copy the library's vue components into your codebase. You can publish with this command:
```
php artisan migrate
php artisan vendor:publish --tag=ledger
```
This command will copy the library's vue components into your codebase

Register package routes in your app's RouteServiceProvider boot method
Using the provided `Ledger.vue` component in your blade templates
```php
<ledger></ledger>
```
public function boot()
{
//

parent::boot();
Register package routes in your app's `RouteServiceProvider` boot method
```
public function boot() {
Ledger::routes();
}
```

## Usage
Using it with your models, add

Add `Ledgerable` trait to your model. See the following example:

```php
namespace App;

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

class Account extends Model
{
class Account extends Model {
use Ledgerable;
}
```

Show available balance
#### Show available balance
```php
$account = Account::find(1);
$balance = Ledger::balance($account);
```
or
```php

// or

$account = Account::find(1);
$balance = $account->balance();
```
Record a credit entry
#### Record a credit entry
```php
$account = Account::find(1);
Ledger::credit($account, $to, $amount, $reason);
```
or
```php

// or

$account = Account::find(1);
$account->credit($to, $amount, $reason);
```
Record a debit entry
#### Record a debit entry
```php
$account = Account::find(1);
Ledger::debit($account, $from, $amount, $reason);
```
or
```php

// or

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

Recording debits and credits in one transaction
#### Recording debits and credits in one transaction
```php
$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

```php
$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
#### Retrieving all entries of a ledgerable
```php
$account = Account::find(1);
$entries = $account->entries();
```
Retrieving all debits of a ledgerable
#### Retrieving all debits of a ledgerable
```php
$account = Account::find(1);
debits = $account->debits();
```
Retrieving all credits of a ledgerable
#### Retrieving all credits of a ledgerable
```php
$account = Account::find(1);
debits = $account->credits();
```
Using the provided Ledger.vue component in your blade templates
```php
<ledger></ledger>
```

## Bugs
For any bugs found, please email me at [email protected] or register an issue at [issues](https://github.com/mpaannddreew/laravel-ledger/issues)

0 comments on commit 1f1c417

Please sign in to comment.