Skip to content

Commit

Permalink
Merge pull request #3 from byjg/bump
Browse files Browse the repository at this point in the history
Bump
  • Loading branch information
byjg committed May 21, 2023
2 parents f7636b3 + 39f0a6e commit a9b3037
Show file tree
Hide file tree
Showing 26 changed files with 2,032 additions and 1,456 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PHPUnit
on:
push:
branches:
- master
tags:
- "*.*.*"
pull_request:
branches:
- master

jobs:
Build:
runs-on: 'ubuntu-latest'
container: 'byjg/php:${{ matrix.php-version }}-cli'
strategy:
matrix:
php-version:
- "8.1"
- "8.0"
- "7.4"
- "7.3"
- "7.2"
- "7.1"

services:
mysql:
image: bitnami/mysql:8.0.20
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
ports:
- "3306:3306"
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=20s
--health-retries=10
env:
MYSQL_TEST_URI: "mysql://root:password@mysql/accounttest"

steps:
- uses: actions/checkout@v2
- run: composer install
- run: ./vendor/bin/phpunit

# Documentation:
# runs-on: 'ubuntu-latest'
# needs: Build
# if: github.ref == 'refs/heads/master'
# env:
# DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
# steps:
# - uses: actions/checkout@v2
# - run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php accounts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor
/src/*.db
node_modules
.usdocker
.phpunit.result.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug current Script in Console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "PHPUnit Debug",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"cwd": "${workspaceFolder}",
"port": 9003,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,87 @@
[WIP] Basic PHP Account Statements
# Basic PHP Account Statements

This is a simple PHP application that allows you to create and manage account statements. It consists of a set of classes to allow control and get statements of any account.

It supports the following features:

- Multiple accounts per user;
- Multiple currencies per account
- Transaction history to avoid changes in the balance;

## How to use

### Installation

```bash
composer require "byjg/account-statements"
```

### Basic usage

```php
use ByJG\AccountStatements\Bll\AccountBLL;
use ByJG\AccountStatements\Bll\AccountTypeBLL;
use ByJG\AccountStatements\Bll\StatementBLL;
use ByJG\AccountStatements\Entity\AccountTypeEntity;
use ByJG\AccountStatements\Repository\AccountRepository;
use ByJG\AccountStatements\Repository\AccountTypeRepository;
use ByJG\AccountStatements\Repository\StatementRepository;
use ByJG\AccountStatements\DTO\StatementDTO;


// Initiate Repositories
$accountTypeRepo = new AccountTypeRepository($this->dbDriver);
$statementRepo = new StatementRepository($this->dbDriver);
$accountRepo = new AccountRepository($this->dbDriver);

// Initiate BLLs
$accountTypeBLL = new AccountTypeBLL($accountTypeRepo);
$statementBLL = new StatementBLL($statementRepo, $accountRepo);
$accountBLL = new AccountBLL($accountRepo, $accountTypeBLL, $statementBLL);

// Create a new Account Type
$accountType = new AccountTypeEntity();
$accountType->setAccountTypeId('USD');
$accountType->setName('Dollar Account');

$accountTypeBLL = new AccountTypeBLL($accountTypeRepo);
$accountTypeBLL->update($accountType);

// Create a new Account
$accountRepo = new AccountRepository($this->dbDriver);
$accountId = $accountBLL->createAccount($accountType->getAccountTypeId(), '34', 0);

// Add 200 USD to the account
$statement = new StatementDTO($accountId, 200);
$statementBLL->addFunds($statement);

// Withdraw 100 USD from the account
$statement = new StatementDTO($accountId, 100);
$statementBLL->withdrawFunds($statement);

// Add 50 USD hold to the account
$statement = new StatementDTO($accountId, 50);
$statementId = $statementBLL->reserveFundsForDeposit($statement);

// Accept the hold
$statementBLL->acceptFundsById($statementId);
```

## Installation

```bash
composer require byjg/account-statements
```

## Testing

```bash
docker run --name mysql-container --rm -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8.0
vendor/bin/phpunit
```




@todo Documentation
@todo Rest
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"license": "MIT",
"require": {
"ext-pdo": "*",
"byjg/micro-orm": "4.1.*"
"byjg/micro-orm": "4.9.*"
},
"autoload": {
"psr-4": {
"ByJG\\AccountStatements\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*",
"byjg/migration": "4.1.*"
"phpunit/phpunit": "5.7.*|7.4.*|^9.5",
"byjg/migration": "4.9.*"
}
}
46 changes: 23 additions & 23 deletions db/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ DROP TABLE IF EXISTS `account`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `account` (
`idaccount` int(11) NOT NULL AUTO_INCREMENT,
`idaccounttype` varchar(20) COLLATE utf8_bin NOT NULL,
`iduser` int(11) NOT NULL,
`accountid` int(11) NOT NULL AUTO_INCREMENT,
`accounttypeid` varchar(20) COLLATE utf8_bin NOT NULL,
`userid` varchar(100) NOT NULL,
`grossbalance` decimal(15,5) DEFAULT '0.00000',
`uncleared` decimal(15,5) DEFAULT '0.00000',
`netbalance` decimal(15,5) DEFAULT '0.00000',
`price` decimal(15,5) NOT NULL DEFAULT '1.00000',
`extra` text COLLATE utf8_bin,
`minvalue` decimal(15,5) NOT NULL DEFAULT '0.00000',
`entrydate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`idaccount`),
UNIQUE KEY `unique_userid_type` (`iduser`,`idaccounttype`),
KEY `fk_account_accounttype_idx` (`idaccounttype`),
CONSTRAINT `fk_account_accounttype` FOREIGN KEY (`idaccounttype`) REFERENCES `accounttype` (`idaccounttype`) ON DELETE NO ACTION ON UPDATE NO ACTION
PRIMARY KEY (`accountid`),
UNIQUE KEY `unique_userid_type` (`userid`,`accounttypeid`),
KEY `fk_account_accounttype_idx` (`accounttypeid`),
CONSTRAINT `fk_account_accounttype` FOREIGN KEY (`accounttypeid`) REFERENCES `accounttype` (`accounttypeid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand All @@ -48,9 +48,9 @@ DROP TABLE IF EXISTS `accounttype`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `accounttype` (
`idaccounttype` varchar(20) COLLATE utf8_bin NOT NULL,
`accounttypeid` varchar(20) COLLATE utf8_bin NOT NULL,
`name` varchar(45) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`idaccounttype`)
PRIMARY KEY (`accounttypeid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand All @@ -62,27 +62,27 @@ DROP TABLE IF EXISTS `statement`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `statement` (
`idstatement` int(11) NOT NULL AUTO_INCREMENT,
`idaccount` int(11) NOT NULL,
`idaccounttype` varchar(20) COLLATE utf8_bin NOT NULL,
`idtype` enum('B','D','W','DB','WB','R') COLLATE utf8_bin NOT NULL COMMENT 'B: Balance - Inicia um novo valor desprezando os antigos\nD: Deposit: Adiciona um valor imediatamente ao banco\nW: Withdrawal\nR: Reject\nWD: Withdrawal (blocked, uncleared)\n',
`statementid` int(11) NOT NULL AUTO_INCREMENT,
`accountid` int(11) NOT NULL,
`accounttypeid` varchar(20) COLLATE utf8_bin NOT NULL,
`typeid` enum('B','D','W','DB','WB','R') COLLATE utf8_bin NOT NULL COMMENT 'B: Balance - Inicia um novo valor desprezando os antigos\nD: Deposit: Adiciona um valor imediatamente ao banco\nW: Withdrawal\nR: Reject\nWD: Withdrawal (blocked, uncleared)\n',
`amount` decimal(15,5) NOT NULL,
`price` decimal(15,5) DEFAULT '1.00000',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`grossbalance` decimal(15,5) DEFAULT NULL,
`uncleared` decimal(15,5) DEFAULT NULL,
`netbalance` decimal(15,5) DEFAULT NULL,
`description` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`idstatementparent` int(11) DEFAULT NULL,
`reference` varchar(45) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`idstatement`),
KEY `fk_statement_account1_idx` (`idaccount`),
KEY `fk_statement_statement1_idx` (`idstatementparent`),
KEY `idx_statement_idtype_date` (`idtype`,`date`) USING BTREE COMMENT 'Índice para filtros com tipo e ordenação por data decrescente',
KEY `fk_statement_accounttype_idx` (`idaccounttype`),
CONSTRAINT `fk_statement_accounttype` FOREIGN KEY (`idaccounttype`) REFERENCES `accounttype` (`idaccounttype`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_statement_account1` FOREIGN KEY (`idaccount`) REFERENCES `account` (`idaccount`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_statement_statement1` FOREIGN KEY (`idstatementparent`) REFERENCES `statement` (`idstatement`) ON DELETE NO ACTION ON UPDATE NO ACTION
`statementparentid` int(11) DEFAULT NULL,
`reference` varchar(100) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`statementid`),
KEY `fk_statement_account1_idx` (`accountid`),
KEY `fk_statement_statement1_idx` (`statementparentid`),
KEY `idx_statement_typeid_date` (`typeid`,`date`) USING BTREE COMMENT 'Índice para filtros com tipo e ordenação por data decrescente',
KEY `fk_statement_accounttype_idx` (`accounttypeid`),
CONSTRAINT `fk_statement_accounttype` FOREIGN KEY (`accounttypeid`) REFERENCES `accounttype` (`accounttypeid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_statement_account1` FOREIGN KEY (`accountid`) REFERENCES `account` (`accountid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_statement_statement1` FOREIGN KEY (`statementparentid`) REFERENCES `statement` (`statementid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand Down
2 changes: 1 addition & 1 deletion db/migrations/down/00000.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE `account`
CHANGE COLUMN `iduser` `iduser` INT(11) NOT NULL ;
CHANGE COLUMN `userid` `userid` INT(11) NOT NULL ;
2 changes: 1 addition & 1 deletion db/migrations/up/00001.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE `account`
CHANGE COLUMN `iduser` `iduser` INT(11) NULL ;
CHANGE COLUMN `userid` `userid` varchar(50) NULL ;
10 changes: 9 additions & 1 deletion db/migrations/up/00002.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
ALTER TABLE `statement`
ADD COLUMN `code` CHAR(3) NULL AFTER `netbalance`;
ADD COLUMN `code` CHAR(5) NULL AFTER `netbalance`;

ALTER TABLE `statement`
RENAME COLUMN `reference` TO `referenceid`;

ALTER TABLE `statement`
ADD COLUMN `referencesource` VARCHAR(50) NULL AFTER `referenceid`,
ADD INDEX `fk_statement_referenceid_idx` (`referenceid`),
ADD INDEX `fk_statement_referencesource_idx` (`referencesource`);

0 comments on commit a9b3037

Please sign in to comment.