-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from adriangoris/master
Adds fields currency fields, convert currency fields from strings to floats, modified the balance calculator
- Loading branch information
Showing
5 changed files
with
72 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,137 +8,117 @@ This is a simple/basic implementation of a ledger in laravel 5 | |
- BALANCE COMPUTATION | ||
|
||
## Installation | ||
git clone https://github.com/mpaannddreew/laravel-ledger.git | ||
|
||
#### 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, | ||
``` | ||
|
||
You can use the facade for shorter code. Add this to your aliases: | ||
|
||
Register Facade | ||
Register service provider | ||
```php | ||
'Ledger' => FannyPack\Ledger\Facades\Ledger::class, | ||
``` | ||
#### Migrations | ||
|
||
Finally, you'll also need to run migration on the package: | ||
``` | ||
php artisan vendor:publish | ||
``` | ||
|
||
#### Vue | ||
Optionally, this command will copy the library's vue components into your codebase. You can publish with this command: | ||
After the service provider is registered run this command | ||
``` | ||
php artisan vendor:publish --tag=ledger | ||
``` | ||
|
||
Using the provided `Ledger.vue` component in your blade templates | ||
```php | ||
<ledger></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` boot method | ||
Register package routes in your app's RouteServiceProvider | ||
``` | ||
public function boot() { | ||
Ledger::routes(); | ||
} | ||
Ledger::routes(); | ||
``` | ||
|
||
## Usage | ||
|
||
Add `Ledgerable` trait to your model. See the following example: | ||
|
||
Using it with your models, add | ||
```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 | ||
|
||
``` | ||
or | ||
```php | ||
$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 | ||
|
||
``` | ||
or | ||
```php | ||
$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 | ||
|
||
``` | ||
or | ||
```php | ||
$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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters