Skip to content

Commit

Permalink
Update: Complete automatic foreign balance translation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmungai committed Jun 20, 2021
1 parent bc729c7 commit 6e66c37
Show file tree
Hide file tree
Showing 34 changed files with 3,920 additions and 1,185 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,18 +459,18 @@ In the above example:
use IFRS\Reports\AccountStatement;
use IFRS\Reports\AccountSchedule;

$statement = new AccountStatement($clientAccount)->getTransactions();
$transactions = new AccountStatement($clientAccount)->getTransactions();

dd($statement->transactions);
dd($transactions);

array:2[
["transaction" => ClientInvoice, "debit" => 120, "credit" => 0, "balance" => 120],
["transaction" => ClientReceipt, "debit" => 0, "credit" => 50, "balance" => 70]
]

$schedule = new AccountSchedule($clientAccount, $currency)->getTransactions();
$transactions = new AccountSchedule($clientAccount, $currency)->getTransactions();

dd($schedule->transactions);
dd($transactions);

array:1[
["transaction" => ClientInvoice, "amount" => 120, "cleared" => 50, "balance" => 70],
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"minimum-stability" : "dev",
"require" : {
"php" : "^7.3.0",
"illuminate/database" : "^7.0|^8.0",
"illuminate/auth" : "^7.0|^8.0",
"illuminate/database" : "^7.0|^8.40.0",
"illuminate/auth" : "^7.0|^8.40.0",
"calebporzio/parental" : "^0.11.0",
"doctrine/dbal": "^2.10.1"
},
Expand Down
2,845 changes: 1,793 additions & 1,052 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions database/migrations/2021_03_04_194118_add_entity_locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddEntityLocale extends Migration
Expand Down Expand Up @@ -30,6 +31,9 @@ public function down()
Schema::table(
config('ifrs.table_prefix') . 'entities', function(BLueprint $table)
{
if (config('database.default') == 'sqlite') {
DB::statement('PRAGMA foreign_keys = OFF;'); // sqlite needs to drop the entire table to remove a column, which fails because the table is already referenced
}
$table->dropColumn('locale');
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

class CreateClosingRatesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(config('ifrs.table_prefix') . 'closing_rates', function (Blueprint $table) {
$table->bigIncrements('id');

// relationships
$table->unsignedBigInteger('entity_id');
$table->unsignedBigInteger('reporting_period_id');
$table->unsignedBigInteger('exchange_rate_id');

// constraints
$table->foreign('entity_id')->references('id')->on(config('ifrs.table_prefix') . 'entities');
$table->foreign('reporting_period_id')->references('id')->on(config('ifrs.table_prefix') . 'reporting_periods');
$table->foreign('exchange_rate_id')->references('id')->on(config('ifrs.table_prefix') . 'exchange_rates');

// *permanent* deletion
$table->dateTime('destroyed_at')->nullable();

//soft deletion
$table->softDeletes();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists(config('ifrs.table_prefix') .'closing_rates');
}
}
37 changes: 37 additions & 0 deletions database/migrations/2021_06_11_202626_add_closing_rate_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddClosingRateColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(config('ifrs.table_prefix') . 'reporting_periods',
function (Blueprint $table) {
$table->dateTime('closing_date', 0)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('ifrs.table_prefix') . 'reporting_periods', function (Blueprint $table) {
if (config('database.default') == 'sqlite') {
DB::statement('PRAGMA foreign_keys = OFF;'); // sqlite needs to drop the entire table to remove a column, which fails because the table is already referenced
}
$table->dropColumn('closing_date');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

class CreateClosingTransactionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(config('ifrs.table_prefix') . 'closing_transactions', function (Blueprint $table) {
$table->bigIncrements('id');

// relationships
$table->unsignedBigInteger('entity_id');
$table->unsignedBigInteger('reporting_period_id');
$table->unsignedBigInteger('transaction_id');
$table->unsignedBigInteger('currency_id');

// constraints
$table->foreign('entity_id')->references('id')->on(config('ifrs.table_prefix') . 'entities');
$table->foreign('reporting_period_id')->references('id')->on(config('ifrs.table_prefix') . 'reporting_periods');
$table->foreign('transaction_id')->references('id')->on(config('ifrs.table_prefix') . 'transactions');
$table->foreign('currency_id')->references('id')->on(config('ifrs.table_prefix') . 'currencies');

// *permanent* deletion
$table->dateTime('destroyed_at')->nullable();

//soft deletion
$table->softDeletes();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists(config('ifrs.table_prefix') .'closing_transactions');
}
}
49 changes: 20 additions & 29 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">tests/Feature</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
29 changes: 29 additions & 0 deletions src/Exceptions/DuplicateClosingRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Eloquent IFRS Accounting
*
* @author Edward Mungai
* @copyright Edward Mungai, 2021, Germany
* @license MIT
*/

namespace IFRS\Exceptions;

class DuplicateClosingRate extends IFRSException
{
/**
* Duplicate Closing Rate Exception
*
* @param string $currencyCode
* @param int $year
* @param string $message
* @param int $code
*/
public function __construct(string $currencyCode, int $year, string $message = null, int $code = null)
{
$error = "A Closing Rate already exists for " . $currencyCode . " for " . $year;

parent::__construct($error . $message, $code);
}
}
10 changes: 6 additions & 4 deletions src/Exceptions/InvalidAccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ class InvalidAccountType extends IFRSException
/**
* Invalid Account Type Exception
*
* @param string $accountName
* @param array|string $accountTypes
* @param string $message
* @param int $code
*/
public function __construct($accountTypes, string $message = null, int $code = null)
{
public function __construct($accountName, $accountTypes, string $message = null, int $code = null)
{
$error = $accountName.' Account';
if (is_array($accountTypes)) {
$accountTypes = Account::getTypes($accountTypes);
$error = "Schedule Account Type must be one of: " . implode(", ", $accountTypes);
$error .= " Type must be one of: " . implode(", ", $accountTypes);
} else {
$accountTypes = Account::getType($accountTypes);
$error = "Vat Account must be of Type " . $accountTypes;
$error .= " must be of Type " . $accountTypes;
}

parent::__construct($error . ' ' . $message, $code);
Expand Down
29 changes: 29 additions & 0 deletions src/Exceptions/InvalidPeriodStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Eloquent IFRS Accounting
*
* @author Edward Mungai
* @copyright Edward Mungai, 2021, Germany
* @license MIT
*/

namespace IFRS\Exceptions;

use IFRS\Models\ReportingPeriod;

class InvalidPeriodStatus extends IFRSException
{
/**
* Invalid Period Status Exception
*
* @param string $message
* @param int $code
*/
public function __construct(string $message = null, int $code = null)
{
$error = "Reporting Period must have " . config('ifrs')['reporting_period_status'][ReportingPeriod::ADJUSTING] . " status to translate foreign balances";

parent::__construct($error . $message, $code);
}
}
28 changes: 28 additions & 0 deletions src/Exceptions/MissingClosingRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* Eloquent IFRS Accounting
*
* @author Edward Mungai
* @copyright Edward Mungai, 2021, Germany
* @license MIT
*/

namespace IFRS\Exceptions;

class MissingClosingRate extends IFRSException
{
/**
* Missing Closing Rate Exception
*
* @param $currencyCode
* @param string $message
* @param int $code
*/
public function __construct(string $currencyCode, string $message = null, int $code = null)
{
$error = "Closing Rate for " . $currencyCode . " is missing ";

parent::__construct($error . $message, $code);
}
}
Loading

0 comments on commit 6e66c37

Please sign in to comment.