fannypack / ledger
laravel 的 ledger 实现
1.21
2019-09-05 08:58 UTC
Requires
- illuminate/database: ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0
- illuminate/routing: ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0
- illuminate/support: ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0
- illuminate/validation: ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0
- nesbot/carbon: ^1.26.3 || ^2.0
This package is auto-updated.
Last update: 2024-09-05 20:25:50 UTC
README
这是laravel 5中一个简单的基本账本的实现
支持的操作
- 记录借方
- 记录贷方
- 计算余额
安装
git clone https://github.com/mpaannddreew/laravel-ledger.git
注册服务提供者
FannyPack\Ledger\LedgerServiceProvider::class,
注册外观服务提供者
'Ledger' => FannyPack\Ledger\Facades\Ledger::class,
服务提供者注册后运行此命令
php artisan vendor:publish --tag=ledger
运行迁移
php artisan migrate
此命令将库的vue组件复制到您的代码库中
在您的应用的路由提供者中注册包路由
Ledger::routes();
用法
与模型一起使用,添加
namespace App; use FannyPack\Ledger\Traits\Ledgerable; use Illuminate\Database\Eloquent\Model; class Account extends Model { use Ledgerable; }
显示可用余额
$account = Account::find(1); $balance = Ledger::balance($account);
或
$account = Account::find(1); $balance = $account->balance();
记录贷方条目
$account = Account::find(1); Ledger::credit($account, $to, $amount, $reason);
或
$account = Account::find(1); $account->credit($to, $amount, $reason);
记录借方条目
$account = Account::find(1); Ledger::debit($account, $from, $amount, $reason);
或
$account = Account::find(1); $account->debit($from, $amount, $reason);
在一次事务中记录借方和贷方
$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);
或
$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);
检索账本可记录的所有条目
$account = Account::find(1); $entries = $account->entries();
检索账本可记录的所有借方条目
$account = Account::find(1); debits = $account->debits();
检索账本可记录的所有贷方条目
$account = Account::find(1); debits = $account->credits();
在blade模板中使用提供的 Ledger.vue 组件
<ledger></ledger>
错误
对于发现的任何错误,请通过andrewmvp007@gmail.com给我发邮件或在问题中注册问题