CakeAccounting/config/Seeds/SeedLookupTablesSeed.php

176 lines
5.9 KiB
PHP

<?php
declare(strict_types=1);
use Migrations\AbstractSeed;
/**
* SeedLookupTables seed.
*/
class SeedLookupTablesSeed extends AbstractSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*
* @return void
*/
public function run(): void
{
// base types
$stmt = $this->query('SELECT * FROM de_base_types'); // returns PDOStatement
$existing = $stmt->fetchAll(); // returns the result as an array
if (!$existing) {
$baseTypes = [
[
'de_code' => DE_TYPE_CREDIT,
'name' => 'Credit',
],
[
'de_code' => DE_TYPE_DEBIT,
'name' => 'Debit',
],
];
$table = $this->table('de_base_types');
$table->insert($baseTypes)->save();
}
// entity types
$stmt = $this->query('SELECT * FROM de_entity_types'); // returns PDOStatement
$existing = $stmt->fetchAll(); // returns the result as an array
if (!$existing) {
$entityTypes = [
[
'entity_type_code' => DE_ENTITY_TYPE_PERSON,
'name' => 'Person',
],
[
'entity_type_code' => DE_ENTITY_TYPE_ORGANIZATION,
'name' => 'Organization',
],
[
'entity_type_code' => DE_ENTITY_TYPE_PROPERTY,
'name' => 'Property',
],
[
'entity_type_code' => DE_ENTITY_TYPE_BANK_ACCOUNT,
'name' => 'Bank Account',
],
];
$table = $this->table('de_entity_types');
$table->insert($entityTypes)->save();
}
// transaction types
$stmt = $this->query('SELECT * FROM de_transaction_types'); // returns PDOStatement
$existing = $stmt->fetchAll(); // returns the result as an array
if (!$existing) {
$transactionTypes = [
[
'transaction_type_code' => DE_TRANSACTION_TYPE_ADJUST_CREDIT,
'name' => 'Adjust Credit',
],
[
'transaction_type_code' => DE_TRANSACTION_TYPE_ADJUST_DEBIT,
'name' => 'Adjust Debit',
],
[
'transaction_type_code' => DE_TRANSACTION_TYPE_DEPOSIT,
'name' => 'Deposit',
],
[
'transaction_type_code' => DE_TRANSACTION_TYPE_WITHDRAW,
'name' => 'Withdrawal',
],
[
'transaction_type_code' => DE_TRANSACTION_TYPE_ESTIMATE_CREDIT,
'name' => 'Estimate Credit',
],
[
'transaction_type_code' => DE_TRANSACTION_TYPE_ESTIMATE_DEBIT,
'name' => 'Estimate Debit',
]
];
$table = $this->table('de_transaction_types');
$table->insert($transactionTypes)->save();
}
// bank account types
$stmt = $this->query('SELECT * FROM de_bank_account_types'); // returns PDOStatement
$existing = $stmt->fetchAll(); // returns the result as an array
if (!$existing) {
$bankAccountTypes = [
[
'bank_account_type_code' => DE_BANK_ACCOUNT_TYPE_CHECKING,
'de_code' => DE_TYPE_CREDIT,
'name' => 'Checking',
],
[
'bank_account_type_code' => DE_BANK_ACCOUNT_TYPE_SAVINGS,
'de_code' => DE_TYPE_CREDIT,
'name' => 'Savings',
],
[
'bank_account_type_code' => DE_BANK_ACCOUNT_TYPE_LINE_OF_CREDIT,
'de_code' => DE_TYPE_DEBIT,
'name' => 'Line of Credit',
],
[
'bank_account_type_code' => DE_BANK_ACCOUNT_TYPE_MORTGAGE,
'de_code' => DE_TYPE_DEBIT,
'name' => 'Mortgage',
],
];
$table = $this->table('de_bank_account_types');
$table->insert($bankAccountTypes)->save();
}
// account types
$stmt = $this->query('SELECT * FROM de_account_types'); // returns PDOStatement
$existing = $stmt->fetchAll(); // returns the result as an array
if (!$existing) {
$internalAccountTypes = [
[
'account_type_code' => DE_ACCOUNT_TYPE_ASSET,
'name' => 'Asset',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_LIABILITY,
'name' => 'Liability',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_REVENUE,
'name' => 'Revenue',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_EXPENSES,
'name' => 'Expenses',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_EQUITY,
'name' => 'Equity',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_GAIN,
'name' => 'Gain',
],
[
'account_type_code' => DE_ACCOUNT_TYPE_LOSS,
'name' => 'Loss',
],
];
$table = $this->table('de_account_types');
$table->insert($internalAccountTypes)->save();
}
}
}