PHP code example of abather / mini-accounting

1. Go to this page and download the library: Download abather/mini-accounting 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/ */

    

abather / mini-accounting example snippets


return [
    "prevent_duplication" => true,
    "currency_precision" => 2
];



namespace App\Models;

use Abather\MiniAccounting\Traits\HasAccountMovement;
use Illuminate\Database\Eloquent\Model;

class System extends Model
{
    use HasAccountMovement;

    // Your code
}

$system->deposit("Description Of The Transaction", 350, $bill);

$system->deposit("Description Of The Transaction", 350, $bill, "Extra Notes", $json);

$system->balance

$system->balanceAtEndOfMonth(10)
// Returns the system balance at the end of month 10

$system->balanceAtEndOfYear()
// Returns the system balance at the end of this year



namespace App\Models;

use Abather\MiniAccounting\Contracts\Referencable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Bill extends Model implements Referencable
{
    use \Abather\MiniAccounting\Traits\Referencable;
    use HasFactory;

    public function defaultTransactions(): array
    {
        return [];
    }
}

$bill = Bill::first();
$bill->deposit("Deposit", $bill->amount, $bill->market);
$bill->withdraw("Withdraw", $bill->amount, $bill->user);

$bill = Bill::first();
$bill->deposit("Deposit", $bill->amount, $bill->market);
$bill->withdraw("Withdraw", $bill->amount, $bill->user);
$bill->withdraw("Withdraw", $bill->amount * 0.1, $bill->market);
$bill->deposit("Deposit", $bill->amount * 0.1, $system);

public function defaultTransactions(): array
{
    return [
        Withdraw::make($this, "description")
            ->setAccount(Account::make(\App\Models\User::class)->relationship("user"))
            ->setCalculation(Equal::make($this, "amount")),

        Deposit::make($this, "any description")
            ->setAccount(Account::make(\App\Models\Market::class)->relationship("market"))
            ->setCalculation(Equal::make($this, "amount")),

        Withdraw::make($this, "other description")
            ->setAccount(Account::make(\App\Models\Market::class)->relationship("market"))
            ->setCalculation(Percentage::make($this, "amount")
                                ->factor(StaticFactor::make(10))
            ),

        Deposit::make($this, "other description")
            ->setAccount(Account::make(\App\Models\System::class, System::first()))
            ->setCalculation(Percentage::make($this, "amount")
                                 ->factor(DynamicFactor::make($this, 'percentage'))
            ),
    ];
}

$transaction->data = [
    'foo' => 'bar'
];

$transaction->data // ['foo' => 'bar']
  

Account::make(\App\Models\Market::class)->relationship("market");

Account::make(\App\Models\Market::class, $this->market)

public function __call($method, $parameters)
{
    if (in_array($method, ["deposit", 'withdraw'])) {
        return $this->createAccountMovement(strtoupper($method), ...$parameters);
    }

    // Your code ...
    return parent::__call($method, $parameters);
}

public function __call($method, $parameters)
{
    if (str_starts_with($method, "execute") && str_ends_with($method, "Transactions")) {
        $method = str_replace("execute", "", $method);
        $method = lcfirst($method);
        return $this->executeTransactions($method);
    }

    if (in_array($method, ["deposit", 'withdraw'])) {
        return $this->createAccountMovement(strtoupper($method), ...$parameters);
    }

    // Your code ...
    return parent::__call($method, $parameters);
}
bash
php artisan vendor:publish --tag="mini-accounting-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="mini-accounting-config"