PHP code example of ringlesoft / laravel-accounting
1. Go to this page and download the library: Download ringlesoft/laravel-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/ */
ringlesoft / laravel-accounting example snippets
use RingleSoft\LaravelAccounting\Contracts\PostableModel;
use RingleSoft\LaravelAccounting\Traits\Postable;
use RingleSoft\LaravelAccounting\Attributes\DefaultAccountingTemplate;
use RingleSoft\LaravelAccounting\Templates\CreditSaleTemplate;
#[DefaultAccountingTemplate(CreditSaleTemplate::class)]
class Invoice extends Model implements PostableModel
{
use Postable;
public function getPostableAmount(): float // You must implement this
{
return $this->total;
}
}
use RingleSoft\LaravelAccounting\Facades\LaravelAccounting;
LaravelAccounting::posting()->cashSale($sale, auth()->id());
LaravelAccounting::posting()->purchaseOnAccount($purchase, auth()->id());
LaravelAccounting::posting()->payroll($payrollRun, auth()->id());
$invoice->createJournal(); // draft only
$draft = $invoice->journalEntry;
if ($draft->canBePosted()) {
$invoice->postJournal();
}
$purchase->postWithTemplate(
(new CashPurchaseTemplate())->resolveAccount(AccountPreset::COST_OF_GOODS_SOLD, $cogsSubAccount)
);
use RingleSoft\LaravelAccounting\Contracts\ResolvesAccountPresets;
#[DefaultAccountingTemplate(PrepaidExpenseTemplate::class)]
class Invoice extends Model implements PostableModel, ResolvesAccountPresets
{
use Postable;
public function resolveAccountForPreset(AccountPreset $preset): Account|int|string|null
{
return $preset === AccountPreset::COST_OF_GOODS_SOLD ? $this->department->cogsAccount : null;
}
}
$entry = JournalEntry::find(1);
if ($entry->canBeReversed()) { // true once posted
$reversal = $entry->reverse('Correction needed');
}
use RingleSoft\LaravelAccounting\Facades\LaravelAccounting;
use RingleSoft\LaravelAccounting\Models\FiscalYear;
$year = FiscalYear::create(['name' => '2026', 'start_date' => '2026-01-01', 'end_date' => '2026-12-31']);
$periods = LaravelAccounting::periods()->createPeriodsForYear($year); // generates periods per fiscal_periods_count
LaravelAccounting::periods()->closePeriod($periods[0]); // recalculates & caches balances, then closes
LaravelAccounting::periods()->lockPeriod($periods[0]); // freezes it completely (only unlock() can undo)
use RingleSoft\LaravelAccounting\Facades\LaravelAccounting;
$preview = LaravelAccounting::closing()->preview($period); // pure read, nothing posted
$preview->netIncome; // signed: positive = profit, negative = loss
$preview->closeRevenue; // the exact VoucherData that would be posted, or null if nothing to close
$result = LaravelAccounting::closing()->commit($period); // posts all four steps, through the normal JournalService path, in one transaction
use Illuminate\Support\Facades\Schedule;
Schedule::command('accounting:close-period')->dailyAt('01:00');