s-mcdonald / luca-accounts

PHP的双式记账交易

1.4.2 2023-05-05 12:04 UTC

This package is auto-updated.

Last update: 2024-09-05 14:49:28 UTC


README

Source Source

Luca会计是一个可以轻松集成到您应用程序中的双式会计系统。它在提交到数据库之前验证和排序交易。

        // Create a Transaction
        $txn = new Transaction( $date , 'Capital Contribution', 
            [
                new TransactionLine($cash_account_1, 100.00,  00.00),
                new TransactionLine($eqty_account_2,  00.00, 100.00),                
            ]
        );

        // Process the Transaction
        $system->transact($txn);

文档

特性

  1. 遵循基于双式会计规则。
  2. 内置交易验证。
  3. 在提交到数据库之前自动对交易(借|贷)条目进行排序。
  4. 分别处理借方和贷方条目。

安装

通过Composer。从项目根目录运行以下命令。

composer require s-mcdonald/luca-accounts

依赖关系

  • Php 8.1

快速开始

  1. 扩展抽象的AccountSystem类,然后在Account模型或实体中实现AccountInterface
      // Your\App\AccountSystem.php
      class AccountSystem extends \SamMcDonald\LucaAccounts\AbstractAccountSystem {
        ...
      }

      // Your\App\Account.php
      class Account implements \SamMcDonald\LucaAccounts\Contracts\AccountInterface {
        ...
      }

示例

<?php 

namespace Your\App;

use Your\App\AccountSystem;
use SamMcDonald\LucaAccounts\Components\Transaction;
use SamMcDonald\LucaAccounts\Components\TransactionLine;

class YourAccountingProgram
{
    public static function simpleTransaction() 
    {
        // Get a new instance of the Accounting System
        $system = new AccountSystem();

        // Register the transact function
        $system->register('transact', static function(Transaction $txn) {
             // Your logic to commit the transaction to DB
        });

        /*
         * Load the accounts you want to use in the Transaction.
         * This will most likely be a Model or Entity object.
         */
        $acc1 = Account::fetch('cash-account'); 
        $acc2 = Account::fetch('acc-rec-account'); 
        $acc3 = Account::fetch('inventory-account'); 

        /*
         * Make a purchase of stock request
         */
        $txn = new Transaction( new DateTimeImmutable('now') , 'Purchase of inventory', 
            [
                new TransactionLine($acc1, 000.00,  50.00),
                new TransactionLine($acc2, 000.00, 150.00),
                new TransactionLine($acc3, 200.00,   0.00),                 
            ]
        );

        /*
         * Perform the transaction
         */
        $system->transact($txn);
    } 
}

文件

s-mcdonald/luca-accounts/
            │    
            └ src/
              │    
              ├── Components/
              │   │
              │   ├── Transaction.php
              │   │            
              │   └── TransactionLine.php
              │            
              │            
              ├── Contracts/
              │   │
              │   ├── AccountInterface.php
              │   │            
              │   ├── TransactionInterface.php
              │   │
              │   └── TransactionLineInterface.php
              │            
              │  
              ├── Exceptions/
              │   │
              │   └── DoubleEntryException.php
              │   │
              │   └── InvalidTransactionLineEntryException.php
              │
              │
              ├── Enums/
              │   │
              │   └── AccountType.php 
              │    
              ├── Util/
              │   │
              │   └── EntryFormatter.php
              │
              │
              └── AbstractAccountSystem.php

许可

Luca-Accounts根据MIT许可证的条款许可(有关详细信息,请参阅LICENSE文件)。

Luca的名称

Luca-Accounting以Luca Pacioli(会计之父)的名字命名。他普及了双式簿记系统。