PHP code example of waxwink / laracount

1. Go to this page and download the library: Download waxwink/laracount library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

waxwink / laracount example snippets


use Waxwink\Laracount\AccountingService;

$service = app(AccountingService::class);

$service->deposit($user, 15000);

$service->withdraw($user, 7000);

$service->pay($user, 3000);

$service->pay($user, 3000, $refId);

$service->payTo($user, 3000);

$service->refund($user, 1000);

$service->pay($user, 1000, $refId);

$service->balance($user);

$service->bankBalance();
$service->revenueBalance();
$service->expenseBalance();
$service->bankBalanceByRef($refId);
$service->revenueBalanceByRef($refId);
$service->expenseBalanceByRef($refId);

$service->transactionsList($user);

$service->transactionsList($user, paginate: true, perPage:5, page:2);

$service->transactionsList($user, columns:['balance', 'created_at', 'description']);

$service->transactionsList($user, orderBy: "created_at");
$service->transactionsList($user, orderBy: "created_at", direction:"asc");

$service->transactionsList($user, from:"2017-02-01");
$service->transactionsList($user, from:"2017-02-01", to:"2020-01-01");

use Illuminate\Database\Eloquent\Model;
use Waxwink\Accounting\Contracts\HasAccount;
use Waxwink\Laracount\Concerns\HasAccountTrait;

class User extends Model implements HasAccount
{
    use HasAccountTrait;
    
}


$registrationService= app(\Waxwink\Laracount\AccountRegistrationService::class);
$registrationService->registerAccountFor($user);

class RegisterController extends Controller

    // ..... 
    
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(protected AccountRegistrationService $accountRegistrationService)
    {
        $this->middleware('guest');
    }
    
    // ....
    
    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\Models\User
     */
    protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
        $this->accountRegistrationService->registerAccountFor($user);
        return $user;
    }
    //....
}
shell
php artisan accounting:install