diff --git a/.travis.yml b/.travis.yml index 1f82f07b02..102eb830b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,12 @@ php: - 5.5 - 5.6 +addons: + code_climate: + repo_token: 26489f9e854fcdf7e7660ba29c1455694685465b1f90329a79f7d2bf448acb61 + install: + - rm composer.lock - composer install script: @@ -13,4 +18,7 @@ script: - php vendor/bin/codecept run --coverage --coverage-xml after_script: + - cp -v tests/_output/coverage.xml build/logs/clover.xml - php vendor/bin/coveralls + - vendor/bin/test-reporter --stdout > codeclimate.json + - "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports" \ No newline at end of file diff --git a/README.md b/README.md index 2a83d210a2..a65289f98f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -Firefly III +Firefly III (v3.2.5) =========== [](https://travis-ci.org/JC5/firefly-iii) [](http://stillmaintained.com/JC5/firefly-iii) [](https://coveralls.io/r/JC5/firefly-iii?branch=master) [](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) +[](https://codeclimate.com/github/JC5/firefly-iii) +[](https://codeclimate.com/github/JC5/firefly-iii) [](https://packagist.org/packages/grumpydictator/firefly-iii) [](https://packagist.org/packages/grumpydictator/firefly-iii) diff --git a/_sql/firefly-iii-reference-3.2.5.sql b/_sql/firefly-iii-reference-3.2.5.sql new file mode 100644 index 0000000000..b2ad69f707 --- /dev/null +++ b/_sql/firefly-iii-reference-3.2.5.sql @@ -0,0 +1,607 @@ +# ************************************************************ +# Sequel Pro SQL dump +# Version 4096 +# +# http://www.sequelpro.com/ +# http://code.google.com/p/sequel-pro/ +# +# Host: 127.0.0.1 (MySQL 5.6.19-0ubuntu0.14.04.1) +# Database: homestead +# Generation Time: 2015-01-31 05:33:30 +0000 +# ************************************************************ + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + + +# Dump of table account_meta +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `account_meta`; + +CREATE TABLE `account_meta` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `account_id` int(10) unsigned NOT NULL, + `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `data` text COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `account_meta_account_id_name_unique` (`account_id`,`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table account_types +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `account_types`; + +CREATE TABLE `account_types` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `type` varchar(30) COLLATE utf8_unicode_ci NOT NULL, + `editable` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `account_types_type_unique` (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +LOCK TABLES `account_types` WRITE; +/*!40000 ALTER TABLE `account_types` DISABLE KEYS */; + +INSERT INTO `account_types` (`id`, `created_at`, `updated_at`, `type`, `editable`) +VALUES + (1,'2015-01-31 05:33:21','2015-01-31 05:33:21','Default account',1), + (2,'2015-01-31 05:33:21','2015-01-31 05:33:21','Cash account',0), + (3,'2015-01-31 05:33:21','2015-01-31 05:33:21','Asset account',1), + (4,'2015-01-31 05:33:21','2015-01-31 05:33:21','Expense account',1), + (5,'2015-01-31 05:33:21','2015-01-31 05:33:21','Revenue account',1), + (6,'2015-01-31 05:33:21','2015-01-31 05:33:21','Initial balance account',0), + (7,'2015-01-31 05:33:21','2015-01-31 05:33:21','Beneficiary account',1), + (8,'2015-01-31 05:33:21','2015-01-31 05:33:21','Import account',0); + +/*!40000 ALTER TABLE `account_types` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table accounts +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `accounts`; + +CREATE TABLE `accounts` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `user_id` int(10) unsigned NOT NULL, + `account_type_id` int(10) unsigned NOT NULL, + `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `active` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `accounts_user_id_account_type_id_name_unique` (`user_id`,`account_type_id`,`name`), + KEY `accounts_account_type_id_foreign` (`account_type_id`), + CONSTRAINT `accounts_account_type_id_foreign` FOREIGN KEY (`account_type_id`) REFERENCES `account_types` (`id`) ON DELETE CASCADE, + CONSTRAINT `accounts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table bills +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `bills`; + +CREATE TABLE `bills` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `user_id` int(10) unsigned NOT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `match` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `amount_min` decimal(10,2) NOT NULL, + `amount_max` decimal(10,2) NOT NULL, + `date` date NOT NULL, + `active` tinyint(1) NOT NULL, + `automatch` tinyint(1) NOT NULL, + `repeat_freq` enum('daily','weekly','monthly','quarterly','half-year','yearly') COLLATE utf8_unicode_ci NOT NULL, + `skip` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uid_name_unique` (`user_id`,`name`), + CONSTRAINT `bills_uid_for` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table budget_limits +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `budget_limits`; + +CREATE TABLE `budget_limits` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `budget_id` int(10) unsigned DEFAULT NULL, + `startdate` date NOT NULL, + `amount` decimal(10,2) NOT NULL, + `repeats` tinyint(1) NOT NULL, + `repeat_freq` enum('daily','weekly','monthly','quarterly','half-year','yearly') COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_bl_combi` (`budget_id`,`startdate`,`repeat_freq`), + CONSTRAINT `bid_foreign` FOREIGN KEY (`budget_id`) REFERENCES `budgets` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table budget_transaction_journal +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `budget_transaction_journal`; + +CREATE TABLE `budget_transaction_journal` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `budget_id` int(10) unsigned NOT NULL, + `transaction_journal_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `budid_tjid_unique` (`budget_id`,`transaction_journal_id`), + KEY `budget_transaction_journal_transaction_journal_id_foreign` (`transaction_journal_id`), + CONSTRAINT `budget_transaction_journal_transaction_journal_id_foreign` FOREIGN KEY (`transaction_journal_id`) REFERENCES `transaction_journals` (`id`) ON DELETE CASCADE, + CONSTRAINT `budget_transaction_journal_budget_id_foreign` FOREIGN KEY (`budget_id`) REFERENCES `budgets` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table budgets +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `budgets`; + +CREATE TABLE `budgets` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `user_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `budgets_user_id_name_unique` (`user_id`,`name`), + CONSTRAINT `budgets_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table categories +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `categories`; + +CREATE TABLE `categories` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `user_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `categories_user_id_name_unique` (`user_id`,`name`), + CONSTRAINT `categories_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table category_transaction_journal +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `category_transaction_journal`; + +CREATE TABLE `category_transaction_journal` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `category_id` int(10) unsigned NOT NULL, + `transaction_journal_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `catid_tjid_unique` (`category_id`,`transaction_journal_id`), + KEY `category_transaction_journal_transaction_journal_id_foreign` (`transaction_journal_id`), + CONSTRAINT `category_transaction_journal_transaction_journal_id_foreign` FOREIGN KEY (`transaction_journal_id`) REFERENCES `transaction_journals` (`id`) ON DELETE CASCADE, + CONSTRAINT `category_transaction_journal_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table components +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `components`; + +CREATE TABLE `components` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `user_id` int(10) unsigned NOT NULL, + `class` varchar(20) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `components_user_id_class_name_unique` (`user_id`,`class`,`name`), + CONSTRAINT `components_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table limit_repetitions +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `limit_repetitions`; + +CREATE TABLE `limit_repetitions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `budget_limit_id` int(10) unsigned NOT NULL, + `startdate` date NOT NULL, + `enddate` date NOT NULL, + `amount` decimal(10,2) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `limit_repetitions_limit_id_startdate_enddate_unique` (`budget_limit_id`,`startdate`,`enddate`), + CONSTRAINT `limit_repetitions_limit_id_foreign` FOREIGN KEY (`budget_limit_id`) REFERENCES `budget_limits` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table migrations +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `migrations`; + +CREATE TABLE `migrations` ( + `migration` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `batch` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +LOCK TABLES `migrations` WRITE; +/*!40000 ALTER TABLE `migrations` DISABLE KEYS */; + +INSERT INTO `migrations` (`migration`, `batch`) +VALUES + ('2014_06_27_163032_create_users_table',1), + ('2014_06_27_163145_create_account_types_table',1), + ('2014_06_27_163259_create_accounts_table',1), + ('2014_06_27_163817_create_components_table',1), + ('2014_06_27_163818_create_piggybanks_table',1), + ('2014_06_27_164042_create_transaction_currencies_table',1), + ('2014_06_27_164512_create_transaction_types_table',1), + ('2014_06_27_164619_create_recurring_transactions_table',1), + ('2014_06_27_164620_create_transaction_journals_table',1), + ('2014_06_27_164836_create_transactions_table',1), + ('2014_06_27_165344_create_component_transaction_table',1), + ('2014_07_05_171326_create_component_transaction_journal_table',1), + ('2014_07_06_123842_create_preferences_table',1), + ('2014_07_09_204843_create_session_table',1), + ('2014_07_17_183717_create_limits_table',1), + ('2014_07_19_055011_create_limit_repeat_table',1), + ('2014_08_06_044416_create_component_recurring_transaction_table',1), + ('2014_08_12_173919_create_piggybank_repetitions_table',1), + ('2014_08_18_100330_create_piggybank_events_table',1), + ('2014_08_23_113221_create_reminders_table',1), + ('2014_11_10_172053_create_account_meta_table',1), + ('2014_11_29_135749_create_transaction_groups_table',1), + ('2014_11_29_140217_create_transaction_group_transaction_journal_table',1), + ('2014_12_13_190730_changes_for_v321',1), + ('2014_12_24_191544_changes_for_v322',1), + ('2015_01_18_082406_changes_for_v325',1); + +/*!40000 ALTER TABLE `migrations` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table piggy_bank_events +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `piggy_bank_events`; + +CREATE TABLE `piggy_bank_events` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `piggy_bank_id` int(10) unsigned NOT NULL, + `transaction_journal_id` int(10) unsigned DEFAULT NULL, + `date` date NOT NULL, + `amount` decimal(10,2) NOT NULL, + PRIMARY KEY (`id`), + KEY `piggybank_events_piggybank_id_foreign` (`piggy_bank_id`), + KEY `piggybank_events_transaction_journal_id_foreign` (`transaction_journal_id`), + CONSTRAINT `piggybank_events_transaction_journal_id_foreign` FOREIGN KEY (`transaction_journal_id`) REFERENCES `transaction_journals` (`id`) ON DELETE SET NULL, + CONSTRAINT `piggybank_events_piggybank_id_foreign` FOREIGN KEY (`piggy_bank_id`) REFERENCES `piggy_banks` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table piggy_bank_repetitions +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `piggy_bank_repetitions`; + +CREATE TABLE `piggy_bank_repetitions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `piggy_bank_id` int(10) unsigned NOT NULL, + `startdate` date DEFAULT NULL, + `targetdate` date DEFAULT NULL, + `currentamount` decimal(10,2) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `piggybank_repetitions_piggybank_id_startdate_targetdate_unique` (`piggy_bank_id`,`startdate`,`targetdate`), + CONSTRAINT `piggybank_repetitions_piggybank_id_foreign` FOREIGN KEY (`piggy_bank_id`) REFERENCES `piggy_banks` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table piggy_banks +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `piggy_banks`; + +CREATE TABLE `piggy_banks` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `account_id` int(10) unsigned NOT NULL, + `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `targetamount` decimal(10,2) NOT NULL, + `startdate` date DEFAULT NULL, + `targetdate` date DEFAULT NULL, + `repeats` tinyint(1) NOT NULL, + `rep_length` enum('day','week','quarter','month','year') COLLATE utf8_unicode_ci DEFAULT NULL, + `rep_every` smallint(5) unsigned NOT NULL, + `rep_times` smallint(5) unsigned DEFAULT NULL, + `reminder` enum('day','week','quarter','month','year') COLLATE utf8_unicode_ci DEFAULT NULL, + `reminder_skip` smallint(5) unsigned NOT NULL, + `remind_me` tinyint(1) NOT NULL, + `order` int(10) unsigned NOT NULL, + `deleted_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `piggybanks_account_id_name_unique` (`account_id`,`name`), + CONSTRAINT `piggybanks_account_id_foreign` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table preferences +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `preferences`; + +CREATE TABLE `preferences` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `user_id` int(10) unsigned NOT NULL, + `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `data` text COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `preferences_user_id_name_unique` (`user_id`,`name`), + CONSTRAINT `preferences_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table reminders +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `reminders`; + +CREATE TABLE `reminders` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `user_id` int(10) unsigned NOT NULL, + `startdate` date NOT NULL, + `enddate` date DEFAULT NULL, + `active` tinyint(1) NOT NULL, + `notnow` tinyint(1) NOT NULL DEFAULT '0', + `remindersable_id` int(10) unsigned DEFAULT NULL, + `remindersable_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `reminders_user_id_foreign` (`user_id`), + CONSTRAINT `reminders_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table sessions +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `sessions`; + +CREATE TABLE `sessions` ( + `id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `payload` text COLLATE utf8_unicode_ci NOT NULL, + `last_activity` int(11) NOT NULL, + UNIQUE KEY `sessions_id_unique` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table transaction_currencies +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transaction_currencies`; + +CREATE TABLE `transaction_currencies` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `code` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `name` varchar(48) COLLATE utf8_unicode_ci DEFAULT NULL, + `symbol` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `transaction_currencies_code_unique` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +LOCK TABLES `transaction_currencies` WRITE; +/*!40000 ALTER TABLE `transaction_currencies` DISABLE KEYS */; + +INSERT INTO `transaction_currencies` (`id`, `created_at`, `updated_at`, `deleted_at`, `code`, `name`, `symbol`) +VALUES + (1,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'EUR','Euro','€'), + (2,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'USD','US Dollar','$'), + (3,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'HUF','Hungarian forint','Ft'); + +/*!40000 ALTER TABLE `transaction_currencies` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table transaction_group_transaction_journal +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transaction_group_transaction_journal`; + +CREATE TABLE `transaction_group_transaction_journal` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `transaction_group_id` int(10) unsigned NOT NULL, + `transaction_journal_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `tt_joined` (`transaction_group_id`,`transaction_journal_id`), + KEY `tr_trj_id` (`transaction_journal_id`), + CONSTRAINT `tr_trj_id` FOREIGN KEY (`transaction_journal_id`) REFERENCES `transaction_journals` (`id`) ON DELETE CASCADE, + CONSTRAINT `tr_grp_id` FOREIGN KEY (`transaction_group_id`) REFERENCES `transaction_groups` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table transaction_groups +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transaction_groups`; + +CREATE TABLE `transaction_groups` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `user_id` int(10) unsigned NOT NULL, + `relation` enum('balance') COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + KEY `transaction_groups_user_id_foreign` (`user_id`), + CONSTRAINT `transaction_groups_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table transaction_journals +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transaction_journals`; + +CREATE TABLE `transaction_journals` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `user_id` int(10) unsigned NOT NULL, + `transaction_type_id` int(10) unsigned NOT NULL, + `bill_id` int(10) unsigned DEFAULT NULL, + `transaction_currency_id` int(10) unsigned NOT NULL, + `description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, + `completed` tinyint(1) NOT NULL, + `date` date NOT NULL, + `encrypted` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `transaction_journals_user_id_foreign` (`user_id`), + KEY `transaction_journals_transaction_type_id_foreign` (`transaction_type_id`), + KEY `transaction_journals_transaction_currency_id_foreign` (`transaction_currency_id`), + KEY `bill_id_foreign` (`bill_id`), + CONSTRAINT `bill_id_foreign` FOREIGN KEY (`bill_id`) REFERENCES `bills` (`id`) ON DELETE SET NULL, + CONSTRAINT `transaction_journals_transaction_currency_id_foreign` FOREIGN KEY (`transaction_currency_id`) REFERENCES `transaction_currencies` (`id`) ON DELETE CASCADE, + CONSTRAINT `transaction_journals_transaction_type_id_foreign` FOREIGN KEY (`transaction_type_id`) REFERENCES `transaction_types` (`id`) ON DELETE CASCADE, + CONSTRAINT `transaction_journals_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table transaction_types +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transaction_types`; + +CREATE TABLE `transaction_types` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `transaction_types_type_unique` (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +LOCK TABLES `transaction_types` WRITE; +/*!40000 ALTER TABLE `transaction_types` DISABLE KEYS */; + +INSERT INTO `transaction_types` (`id`, `created_at`, `updated_at`, `deleted_at`, `type`) +VALUES + (1,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'Withdrawal'), + (2,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'Deposit'), + (3,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'Transfer'), + (4,'2015-01-31 05:33:21','2015-01-31 05:33:21',NULL,'Opening balance'); + +/*!40000 ALTER TABLE `transaction_types` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table transactions +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `transactions`; + +CREATE TABLE `transactions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `deleted_at` timestamp NULL DEFAULT NULL, + `account_id` int(10) unsigned NOT NULL, + `transaction_journal_id` int(10) unsigned NOT NULL, + `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `amount` decimal(10,2) NOT NULL, + PRIMARY KEY (`id`), + KEY `transactions_account_id_foreign` (`account_id`), + KEY `transactions_transaction_journal_id_foreign` (`transaction_journal_id`), + CONSTRAINT `transactions_account_id_foreign` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE, + CONSTRAINT `transactions_transaction_journal_id_foreign` FOREIGN KEY (`transaction_journal_id`) REFERENCES `transaction_journals` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + +# Dump of table users +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `users`; + +CREATE TABLE `users` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL, + `reset` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, + `remember_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `users_email_unique` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/app/controllers/BillController.php b/app/controllers/BillController.php index 521c21736b..0fdd0f7309 100644 --- a/app/controllers/BillController.php +++ b/app/controllers/BillController.php @@ -5,8 +5,7 @@ use FireflyIII\Exception\FireflyException; /** * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("NPathComplexity") + * * Class BillController * */ @@ -120,9 +119,9 @@ class BillController extends BaseController */ public function show(Bill $bill) { - $journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get(); + $journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get(); $bill->nextExpectedMatch = $this->_repository->nextExpectedMatch($bill); - $hideBill = true; + $hideBill = true; return View::make('bills.show', compact('journals', 'hideBill', 'bill'))->with( @@ -136,7 +135,7 @@ class BillController extends BaseController */ public function store() { - $data = Input::all(); + $data = Input::except(['_token', 'post_submit_action']); $data['user_id'] = Auth::user()->id; @@ -149,17 +148,19 @@ class BillController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not store bill: ' . $messages['errors']->first()); + + return Redirect::route('bills.create')->withInput(); } // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if (Input::get('post_submit_action') == 'validate_only') { return Redirect::route('bills.create')->withInput(); } // store $this->_repository->store($data); Session::flash('success', 'Bill "' . e($data['name']) . '" stored.'); - if ($data['post_submit_action'] == 'store') { + if (Input::get('post_submit_action') == 'store') { return Redirect::route('bills.index'); } @@ -176,8 +177,8 @@ class BillController extends BaseController public function update(Bill $bill) { $data = Input::except('_token'); - $data['active'] = isset($data['active']) ? 1 : 0; - $data['automatch'] = isset($data['automatch']) ? 1 : 0; + $data['active'] = intval(Input::get('active')); + $data['automatch'] = intval(Input::get('automatch')); $data['user_id'] = Auth::user()->id; // always validate: @@ -189,10 +190,12 @@ class BillController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update bill: ' . $messages['errors']->first()); + + return Redirect::route('bills.edit', $bill->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('bills.edit', $bill->id)->withInput(); } diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 500ed85573..5a42967adc 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -8,9 +8,6 @@ use FireflyIII\Shared\Preferences\PreferencesInterface as Pref; * Class BudgetController * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("TooManyMethods") // I'm also fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove. * */ class BudgetController extends BaseController @@ -45,7 +42,7 @@ class BudgetController extends BaseController $date = Session::get('start', Carbon::now()->startOfMonth()); $limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount); - return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition->id]); + return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]); } @@ -148,6 +145,8 @@ class BudgetController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param Budget $budget * @param LimitRepetition $repetition * @@ -184,10 +183,11 @@ class BudgetController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not validate budget: ' . $messages['errors']->first()); + return Redirect::route('budgets.create')->withInput(); } // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('budgets.create')->withInput(); } @@ -222,10 +222,11 @@ class BudgetController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update budget: ' . $messages['errors']->first()); + return Redirect::route('budgets.edit', $budget->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('budgets.edit', $budget->id)->withInput(); } diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php index 8459b4c40f..bc5d0846f1 100644 --- a/app/controllers/CategoryController.php +++ b/app/controllers/CategoryController.php @@ -6,7 +6,6 @@ use FireflyIII\Exception\FireflyException; /** * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. * * Class CategoryController */ @@ -106,6 +105,7 @@ class CategoryController extends BaseController } /** + * * @return $this * @throws FireflyException */ @@ -123,10 +123,11 @@ class CategoryController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not store category: ' . $messages['errors']->first()); + return Redirect::route('categories.create')->withInput(); } // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('categories.create')->withInput(); } @@ -141,6 +142,7 @@ class CategoryController extends BaseController } /** + * * @param Category $category * * @return $this @@ -160,10 +162,11 @@ class CategoryController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update category: ' . $messages['errors']->first()); + return Redirect::route('categories.edit', $category->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('categories.edit', $category->id)->withInput(); } diff --git a/app/controllers/CurrencyController.php b/app/controllers/CurrencyController.php index d8c2d5b5d6..9b55132333 100644 --- a/app/controllers/CurrencyController.php +++ b/app/controllers/CurrencyController.php @@ -4,7 +4,6 @@ use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository; /** * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. * * Class CurrencyController */ @@ -123,6 +122,8 @@ class CurrencyController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @return $this|\Illuminate\Http\RedirectResponse */ public function store() @@ -174,10 +175,11 @@ class CurrencyController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update currency: ' . $messages['errors']->first()); + return Redirect::route('currency.edit', $currency->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('currency.edit', $currency->id)->withInput(); } diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index f413c9c5a3..efafc28d6b 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -6,10 +6,6 @@ use Grumpydictator\Gchart\GChart as GChart; /** * Class GoogleChartController * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("TooManyMethods") // I'm also fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("MethodLength") // There is one with 45 lines and im gonna move it. - * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove. */ class GoogleChartController extends BaseController { @@ -46,6 +42,7 @@ class GoogleChartController extends BaseController { $this->_chart->addColumn('Day of month', 'date'); $this->_chart->addColumn('Balance for ' . $account->name, 'number'); + $this->_chart->addCertainty(1); $start = $this->_start; $end = $this->_end; @@ -65,7 +62,7 @@ class GoogleChartController extends BaseController $current = clone $start; while ($end >= $current) { - $this->_chart->addRow(clone $current, Steam::balance($account, $current)); + $this->_chart->addRow(clone $current, Steam::balance($account, $current), false); $current->addDay(); } @@ -76,7 +73,7 @@ class GoogleChartController extends BaseController } /** - * This method renders the b + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. */ public function allAccountsBalanceChart() { @@ -88,19 +85,25 @@ class GoogleChartController extends BaseController /** @var \FireflyIII\Database\Account\Account $acct */ $acct = App::make('FireflyIII\Database\Account\Account'); - $accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAssetAccounts(); + $accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']); + $index = 1; /** @var Account $account */ foreach ($accounts as $account) { $this->_chart->addColumn('Balance for ' . $account->name, 'number'); + $this->_chart->addCertainty($index); + $index++; } $current = clone $this->_start; $current->subDay(); - + $today = Carbon::now(); while ($this->_end >= $current) { - $row = [clone $current]; + $row = [clone $current]; + $certain = $current < $today; foreach ($accounts as $account) { + $row[] = Steam::balance($account, $current); + $row[] = $certain; } $this->_chart->addRowArray($row); $current->addDay(); @@ -112,6 +115,49 @@ class GoogleChartController extends BaseController } + /** + * @param int $year + * + * @return $this|\Illuminate\Http\JsonResponse + */ + public function allBudgetsAndSpending($year) + { + try { + new Carbon('01-01-' . $year); + } catch (Exception $e) { + return View::make('error')->with('message', 'Invalid year.'); + } + /** @var \FireflyIII\Database\Budget\Budget $budgetRepository */ + $budgetRepository = App::make('FireflyIII\Database\Budget\Budget'); + $budgets = $budgetRepository->get(); + $budgets->sortBy('name'); + $this->_chart->addColumn('Month', 'date'); + foreach ($budgets as $budget) { + $this->_chart->addColumn($budget->name, 'number'); + } + $start = Carbon::createFromDate(intval($year), 1, 1); + $end = clone $start; + $end->endOfYear(); + + + while ($start <= $end) { + $row = [clone $start]; + foreach ($budgets as $budget) { + $spent = $budgetRepository->spentInMonth($budget, $start); + //$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start); + $row[] = $spent; + } + $this->_chart->addRowArray($row); + $start->addMonth(); + } + + + $this->_chart->generate(); + + return Response::json($this->_chart->getData()); + + } + /** * @return \Illuminate\Http\JsonResponse */ @@ -121,8 +167,6 @@ class GoogleChartController extends BaseController $this->_chart->addColumn('Budgeted', 'number'); $this->_chart->addColumn('Spent', 'number'); - Log::debug('Now in allBudgetsHomeChart()'); - /** @var \FireflyIII\Database\Budget\Budget $bdt */ $bdt = App::make('FireflyIII\Database\Budget\Budget'); $budgets = $bdt->get(); @@ -130,18 +174,13 @@ class GoogleChartController extends BaseController /** @var Budget $budget */ foreach ($budgets as $budget) { - Log::debug('Now working budget #' . $budget->id . ', ' . $budget->name); - /** @var \LimitRepetition $repetition */ $repetition = $bdt->repetitionOnStartingOnDate($budget, $this->_start); - if (is_null($repetition)) { - \Log::debug('Budget #' . $budget->id . ' has no repetition on ' . $this->_start->format('Y-m-d')); - // use the session start and end for our search query + if (is_null($repetition)) { // use the session start and end for our search query $searchStart = $this->_start; $searchEnd = $this->_end; $limit = 0; // the limit is zero: } else { - \Log::debug('Budget #' . $budget->id . ' has a repetition on ' . $this->_start->format('Y-m-d') . '!'); // use the limit's start and end for our search query $searchStart = $repetition->startdate; $searchEnd = $repetition->enddate; @@ -149,7 +188,6 @@ class GoogleChartController extends BaseController } $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1; - \Log::debug('Expenses in budget ' . $budget->name . ' before ' . $searchEnd->format('Y-m-d') . ' and after ' . $searchStart . ' are: ' . $expenses); if ($expenses > 0) { $this->_chart->addRow($budget->name, $limit, $expenses); } @@ -289,47 +327,56 @@ class GoogleChartController extends BaseController /** * - * @param Budget $budget - * @param $year + * @param Budget $budget * * @return \Illuminate\Http\JsonResponse */ - public function budgetsAndSpending(Budget $budget, $year) + public function budgetsAndSpending(Budget $budget, $year = 0) { - try { - new Carbon('01-01-' . $year); - } catch (Exception $e) { - return View::make('error')->with('message', 'Invalid year.'); - } - /** @var \FireflyIII\Database\Budget\Budget $budgetRepository */ $budgetRepository = App::make('FireflyIII\Database\Budget\Budget'); $this->_chart->addColumn('Month', 'date'); $this->_chart->addColumn('Budgeted', 'number'); $this->_chart->addColumn('Spent', 'number'); + if ($year == 0) { + // grab the first budgetlimit ever: + $firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first(); + if ($firstLimit) { + $start = new Carbon($firstLimit->startdate); + } else { + $start = Carbon::now()->startOfYear(); + } + + // grab the last budget limit ever: + $lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first(); + if ($lastLimit) { + $end = new Carbon($lastLimit->startdate); + } else { + $end = Carbon::now()->endOfYear(); + } + } else { + $start = Carbon::createFromDate(intval($year), 1, 1); + $end = clone $start; + $end->endOfYear(); + } + - $start = new Carbon('01-01-' . $year); - $end = clone $start; - $end->endOfYear(); while ($start <= $end) { $spent = $budgetRepository->spentInMonth($budget, $start); $repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start); if ($repetition) { $budgeted = floatval($repetition->amount); - \Log::debug('Found a repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name.'!'); + \Log::debug('Found a repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name . '!'); } else { - \Log::debug('No repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name); + \Log::debug('No repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name); $budgeted = null; } - $this->_chart->addRow(clone $start, $budgeted, $spent); - $start->addMonth(); } - $this->_chart->generate(); return Response::json($this->_chart->getData()); diff --git a/app/controllers/HelpController.php b/app/controllers/HelpController.php index 813b8faf5c..dbb9f7a2aa 100644 --- a/app/controllers/HelpController.php +++ b/app/controllers/HelpController.php @@ -1,9 +1,10 @@ There is no help for this route!
'; - $helpTitle = 'Help'; + $content = [ + 'text' => 'There is no help for this route!
', + 'title' => 'Help', + ]; + if (!Route::has($route)) { \Log::error('No such route: ' . $route); - return Response::json(['title' => $helpTitle, 'text' => $helpText]); - } - if (Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text')) { - $helpText = Cache::get('help.' . $route . '.text'); - $helpTitle = Cache::get('help.' . $route . '.title'); - - return Response::json(['title' => $helpTitle, 'text' => $helpText]); + return Response::json($content); } - $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md'; - \Log::debug('URL is: ' . $uri); + if ($this->_inCache($route)) { + $content = [ + 'text' => Cache::get('help.' . $route . '.text'), + 'title' => Cache::get('help.' . $route . '.title'), + ]; + + return Response::json($content); + } + $content = $this->_getFromGithub($route); + + + Cache::put('help.' . $route . '.text', $content['text'], 10080); // a week. + Cache::put('help.' . $route . '.title', $content['title'], 10080); + + return Response::json($content); + + } + + /** + * @param $route + * + * @return bool + */ + protected function _inCache($route) + { + return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text'); + } + + /** + * @param $route + * + * @return array + */ + protected function _getFromGithub($route) + { + $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md'; + $content = [ + 'text' => 'There is no help for this route!
', + 'title' => $route, + ]; try { - $helpText = file_get_contents($uri); + $content['text'] = file_get_contents($uri); } catch (ErrorException $e) { \Log::error(trim($e->getMessage())); } - \Log::debug('Found help for ' . $route); - \Log::debug('Help text length for route ' . $route . ' is ' . strlen($helpText)); - \Log::debug('Help text IS: "' . $helpText . '".'); - if (strlen(trim($helpText)) == 0) { - $helpText = 'There is no help for this route.
'; + if (strlen(trim($content['text'])) == 0) { + $content['text'] = 'There is no help for this route.
'; } + $content['text'] = \Michelf\Markdown::defaultTransform($content['text']); - $helpText = \Michelf\Markdown::defaultTransform($helpText); - $helpTitle = $route; + return $content; - Cache::put('help.' . $route . '.text', $helpText, 10080); // a week. - Cache::put('help.' . $route . '.title', $helpTitle, 10080); - - return Response::json(['title' => $helpTitle, 'text' => $helpText]); } -} +} + diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 33bd974e5e..e97bf24bdc 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -33,7 +33,7 @@ class HomeController extends BaseController /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */ $preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface'); - $count = $acct->countAssetAccounts(); + $count = $acct->countAccountsByType(['Default account', 'Asset account']); $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); @@ -42,7 +42,7 @@ class HomeController extends BaseController // get the preference for the home accounts to show: $frontPage = $preferences->get('frontPageAccounts', []); if ($frontPage->data == []) { - $accounts = $acct->getAssetAccounts(); + $accounts = $acct->getAccountsByType(['Default account', 'Asset account']); } else { $accounts = $acct->getByIds($frontPage->data); } @@ -77,8 +77,11 @@ class HomeController extends BaseController $preferences->set('viewRange', $range); Session::forget('range'); } - - return Redirect::intended('/'); + if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) { + return Redirect::back(); + } else { + return Redirect::intended(); + } } /** @@ -88,7 +91,14 @@ class HomeController extends BaseController { Navigation::next(); - return Redirect::intended('/'); + if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === 0) { + Log::debug('Redirect back'); + return Redirect::back(); + } else { + Log::debug('Redirect intended'); + return Redirect::intended(); + } + } /** @@ -98,6 +108,12 @@ class HomeController extends BaseController { Navigation::prev(); - return Redirect::intended('/'); + if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === 0) { + Log::debug('Redirect back'); + return Redirect::back(); + } else { + Log::debug('Redirect intended'); + return Redirect::intended(); + } } } diff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.php index fedc5768d2..a0e6f08262 100644 --- a/app/controllers/JsonController.php +++ b/app/controllers/JsonController.php @@ -36,7 +36,7 @@ class JsonController extends BaseController { /** @var \FireflyIII\Database\Account\Account $accounts */ $accounts = App::make('FireflyIII\Database\Account\Account'); - $list = $accounts->getExpenseAccounts(); + $list = $accounts->getAccountsByType(['Expense account', 'Beneficiary account']); $return = []; foreach ($list as $entry) { $return[] = $entry->name; @@ -53,7 +53,7 @@ class JsonController extends BaseController { /** @var \FireflyIII\Database\Account\Account $accounts */ $accounts = App::make('FireflyIII\Database\Account\Account'); - $list = $accounts->getRevenueAccounts(); + $list = $accounts->getAccountsByType(['Revenue account']); $return = []; foreach ($list as $entry) { $return[] = $entry->name; diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index 69222f22fa..673a2c31f0 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -8,9 +8,6 @@ use Illuminate\Support\Collection; /** * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("TooManyMethods") // I'm also fine with this. - * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove. * * * Class PiggyBankController @@ -62,7 +59,7 @@ class PiggyBankController extends BaseController $acct = App::make('FireflyIII\Database\Account\Account'); $periods = Config::get('firefly.piggy_bank_periods'); - $accounts = FFForm::makeSelectList($acct->getAssetAccounts()); + $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account'])); $subTitle = 'Create new piggy bank'; $subTitleIcon = 'fa-plus'; @@ -96,6 +93,8 @@ class PiggyBankController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param PiggyBank $piggyBank * * @return $this @@ -107,7 +106,7 @@ class PiggyBankController extends BaseController $acct = App::make('FireflyIII\Database\Account\Account'); $periods = Config::get('firefly.piggy_bank_periods'); - $accounts = FFForm::makeSelectList($acct->getAssetAccounts()); + $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account'])); $subTitle = 'Edit piggy bank "' . e($piggyBank->name) . '"'; $subTitleIcon = 'fa-pencil'; @@ -291,11 +290,12 @@ class PiggyBankController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not store piggy bank: ' . $messages['errors']->first()); + return Redirect::route('piggy_banks.create')->withInput(); } // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('piggy_banks.create')->withInput(); } @@ -335,10 +335,11 @@ class PiggyBankController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update piggy bank: ' . $messages['errors']->first()); + return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput(); } diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.php index b1a5ca0fc7..d0d62d797d 100644 --- a/app/controllers/PreferencesController.php +++ b/app/controllers/PreferencesController.php @@ -3,7 +3,6 @@ /** * Class PreferencesController * - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. * */ class PreferencesController extends BaseController @@ -29,7 +28,7 @@ class PreferencesController extends BaseController /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */ $preferences = App::make('FireflyIII\Shared\Preferences\Preferences'); - $accounts = $acct->getAssetAccounts(); + $accounts = $acct->getAccountsByType(['Default account', 'Asset account']); $viewRange = $preferences->get('viewRange', '1M'); $viewRangeValue = $viewRange->data; $frontPage = $preferences->get('frontPageAccounts', []); diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.php index e9b397833c..8ac759f571 100644 --- a/app/controllers/ProfileController.php +++ b/app/controllers/ProfileController.php @@ -1,8 +1,7 @@ _validatePassword(Input::get('old'), Input::get('new1'), Input::get('new2')); + if (!($result === true)) { + Session::flash('error', $result); return View::make('profile.change-password'); } @@ -66,4 +55,31 @@ class ProfileController extends BaseController return Redirect::route('profile'); } + /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * + * @param string $old + * @param string $new1 + * @param string $new2 + * + * @return string|bool + */ + protected function _validatePassword($old, $new1, $new2) + { + if (strlen($new1) == 0 || strlen($new2) == 0) { + return 'Do fill in a password!'; + + } + if ($new1 == $old) { + return 'The idea is to change your password.'; + } + + if ($new1 !== $new2) { + return 'New passwords do not match!'; + } + + return true; + + } + } diff --git a/app/controllers/RelatedController.php b/app/controllers/RelatedController.php index 747dad5e3f..fb77ee320c 100644 --- a/app/controllers/RelatedController.php +++ b/app/controllers/RelatedController.php @@ -3,6 +3,8 @@ use FireflyIII\Helper\Related\RelatedInterface; use Illuminate\Support\Collection; /** + * @SuppressWarnings("CamelCase") // I'm fine with this. + * * Class RelatedController */ class RelatedController extends BaseController @@ -10,6 +12,9 @@ class RelatedController extends BaseController protected $_repository; + /** + * @param RelatedInterface $repository + */ public function __construct(RelatedInterface $repository) { $this->_repository = $repository; @@ -17,6 +22,8 @@ class RelatedController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param TransactionJournal $journal * * @return \Illuminate\Http\JsonResponse @@ -91,6 +98,8 @@ class RelatedController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param TransactionJournal $parentJournal * @param TransactionJournal $childJournal * diff --git a/app/controllers/RepeatedExpenseController.php b/app/controllers/RepeatedExpenseController.php index 652e255578..73494b0377 100644 --- a/app/controllers/RepeatedExpenseController.php +++ b/app/controllers/RepeatedExpenseController.php @@ -6,8 +6,6 @@ use FireflyIII\Exception\FireflyException; /** * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove. * * Class RepeatedExpenseController */ @@ -34,7 +32,7 @@ class RepeatedExpenseController extends BaseController /** @var \FireflyIII\Database\Account\Account $acct */ $acct = App::make('FireflyIII\Database\Account\Account'); $periods = Config::get('firefly.piggy_bank_periods'); - $accounts = FFForm::makeSelectList($acct->getAssetAccounts()); + $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account'])); return View::make('repeatedExpense.create', compact('accounts', 'periods'))->with('subTitle', 'Create new repeated expense')->with( 'subTitleIcon', 'fa-plus' @@ -79,7 +77,7 @@ class RepeatedExpenseController extends BaseController $acct = App::make('FireflyIII\Database\Account\Account'); $periods = Config::get('firefly.piggy_bank_periods'); - $accounts = FFForm::makeSelectList($acct->getAssetAccounts()); + $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account'])); $subTitle = 'Edit repeated expense "' . e($repeatedExpense->name) . '"'; $subTitleIcon = 'fa-pencil'; @@ -137,7 +135,7 @@ class RepeatedExpenseController extends BaseController } /** - * + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. */ public function store() { @@ -152,7 +150,6 @@ class RepeatedExpenseController extends BaseController $data['remind_me'] = isset($data['remind_me']) ? 1 : 0; $data['order'] = 0; - // always validate: $messages = $this->_repository->validate($data); Session::flash('warnings', $messages['warnings']); @@ -160,11 +157,12 @@ class RepeatedExpenseController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not store repeated expense: ' . $messages['errors']->first()); + return Redirect::route('repeated.create')->withInput(); } // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('repeated.create')->withInput(); } @@ -180,6 +178,8 @@ class RepeatedExpenseController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param PiggyBank $repeatedExpense * * @return $this @@ -196,7 +196,6 @@ class RepeatedExpenseController extends BaseController $data['remind_me'] = isset($data['remind_me']) ? 1 : 0; $data['user_id'] = Auth::user()->id; - // always validate: $messages = $this->_repository->validate($data); Session::flash('warnings', $messages['warnings']); @@ -204,10 +203,11 @@ class RepeatedExpenseController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update repeated expense: ' . $messages['errors']->first()); + return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput(); } // return to update screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput(); } diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 29be01240f..ed4821c449 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -48,13 +48,15 @@ class ReportController extends BaseController } catch (Exception $e) { return View::make('error')->with('message', 'Invalid date'); } - $date = new Carbon($year . '-' . $month . '-01'); - $dayEarly = clone $date; - $dayEarly = $dayEarly->subDay(); - $accounts = $this->_repository->getAccountListBudgetOverview($date); - $budgets = $this->_repository->getBudgetsForMonth($date); + $date = new Carbon($year . '-' . $month . '-01'); + $dayEarly = clone $date; + $subTitle = 'Budget report for ' . $date->format('F Y'); + $subTitleIcon = 'fa-calendar'; + $dayEarly = $dayEarly->subDay(); + $accounts = $this->_repository->getAccountListBudgetOverview($date); + $budgets = $this->_repository->getBudgetsForMonth($date); - return View::make('reports.budget', compact('date', 'accounts', 'budgets', 'dayEarly')); + return View::make('reports.budget', compact('subTitle', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly')); } @@ -126,7 +128,8 @@ class ReportController extends BaseController $groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15); return View::make( - 'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') + 'reports.year', + compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') ); } diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index a7c9b12e71..f4384d6d12 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -9,10 +9,6 @@ use Illuminate\Support\Collection; /** * * @SuppressWarnings("CamelCase") // I'm fine with this. - * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. - * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove. - * @SuppressWarnings("TooManyMethods") // I'm also fine with this. - * @SuppressWarnings("ExcessiveClassComplexity") * * Class TransactionController * @@ -166,6 +162,8 @@ class TransactionController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's 7. More than 5 but alright. + * * @param $what * * @return $this @@ -198,7 +196,6 @@ class TransactionController extends BaseController } - /** * @param TransactionJournal $journal * @@ -235,6 +232,8 @@ class TransactionController extends BaseController } /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * * @param $what * * @return $this|\Illuminate\Http\RedirectResponse @@ -243,35 +242,31 @@ class TransactionController extends BaseController public function store($what) { $data = Input::except('_token'); + $transactionType = $this->_repository->getJournalType($what); - $transactionCurrency = $this->_repository->getJournalCurrency('EUR'); + $transactionCurrency = $this->_repository->getJournalCurrencyById(intval($data['amount_currency_id'])); $data['transaction_type_id'] = $transactionType->id; $data['transaction_currency_id'] = $transactionCurrency->id; $data['completed'] = 0; $data['what'] = $what; - $data['currency'] = 'EUR'; - - // always validate: - $messages = $this->_repository->validate($data); + $messages = $this->_repository->validate($data); Session::flash('warnings', $messages['warnings']); Session::flash('successes', $messages['successes']); Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not store transaction: ' . $messages['errors']->first()); - } - // return to create screen: - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { return Redirect::route('transactions.create', $data['what'])->withInput(); } - // store + if ($data['post_submit_action'] == 'validate_only') { + return Redirect::route('transactions.create', $data['what'])->withInput(); + } + $journal = $this->_repository->store($data); Event::fire('transactionJournal.store', [$journal, Input::get('piggy_bank_id')]); // new and used. - /* - * Also trigger on both transactions. - */ + /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { Event::fire('transaction.store', [$transaction]); @@ -295,10 +290,9 @@ class TransactionController extends BaseController public function update(TransactionJournal $journal) { $data = Input::except('_token'); - $data['currency'] = 'EUR'; $data['what'] = strtolower($journal->transactionType->type); $data['transaction_type_id'] = $journal->transaction_type_id; - $data['transaction_currency_id'] = $journal->transaction_currency_id; + $data['transaction_currency_id'] = intval($data['amount_currency_id']); $data['completed'] = 1; $messages = $this->_repository->validate($data); @@ -307,8 +301,10 @@ class TransactionController extends BaseController Session::flash('errors', $messages['errors']); if ($messages['errors']->count() > 0) { Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first()); + + return Redirect::route('transactions.edit', $journal->id)->withInput(); } - if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) { + if ($data['post_submit_action'] == 'validate_only') { return Redirect::route('transactions.edit', $journal->id)->withInput(); } $this->_repository->update($journal, $data); diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 82309e2460..702ffe991b 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -77,7 +77,12 @@ class UserController extends BaseController $user = $repository->register(Input::all()); if ($user) { - $email->sendVerificationMail($user); + $result = $email->sendVerificationMail($user); + if ($result === false && Config::get('mail.pretend') === false) { + $user->delete(); + + return View::make('error')->with('message', 'The email message could not be send. See the log files.'); + } return View::make('user.verification-pending'); } @@ -121,6 +126,11 @@ class UserController extends BaseController */ public function register() { + if ((Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '') + && Config::get('mail.pretend') === false + ) { + return View::make('error')->with('message', 'Configuration error inapp/config/' . App::environment() . '/mail.php');
+ }
return View::make('user.register');
}
diff --git a/app/database/migrations/2014_06_27_163032_create_users_table.php b/app/database/migrations/2014_06_27_163032_create_users_table.php
index 3c72c3ab6c..cd554148db 100644
--- a/app/database/migrations/2014_06_27_163032_create_users_table.php
+++ b/app/database/migrations/2014_06_27_163032_create_users_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateUsersTable
*/
class CreateUsersTable extends Migration
diff --git a/app/database/migrations/2014_06_27_163145_create_account_types_table.php b/app/database/migrations/2014_06_27_163145_create_account_types_table.php
index 7d90098389..783ec4d15d 100644
--- a/app/database/migrations/2014_06_27_163145_create_account_types_table.php
+++ b/app/database/migrations/2014_06_27_163145_create_account_types_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountTypesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163259_create_accounts_table.php b/app/database/migrations/2014_06_27_163259_create_accounts_table.php
index 71d3cd8a37..3fb5541655 100644
--- a/app/database/migrations/2014_06_27_163259_create_accounts_table.php
+++ b/app/database/migrations/2014_06_27_163259_create_accounts_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163817_create_components_table.php b/app/database/migrations/2014_06_27_163817_create_components_table.php
index 2c4852f02c..465b1ecaff 100644
--- a/app/database/migrations/2014_06_27_163817_create_components_table.php
+++ b/app/database/migrations/2014_06_27_163817_create_components_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
index 5ac466d43e..67d527a66d 100644
--- a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
+++ b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggybanksTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php b/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
index a6444da219..809a837bc9 100644
--- a/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
+++ b/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionCurrenciesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php b/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
index 77a3d9924c..746f037a84 100644
--- a/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
+++ b/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionTypesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php b/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
index c3e9aea81b..724059c859 100644
--- a/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
+++ b/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateRecurringTransactionsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php b/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
index b44af8769c..44ede35eb0 100644
--- a/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
+++ b/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionJournalsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164836_create_transactions_table.php b/app/database/migrations/2014_06_27_164836_create_transactions_table.php
index 74765c1910..66b2772534 100644
--- a/app/database/migrations/2014_06_27_164836_create_transactions_table.php
+++ b/app/database/migrations/2014_06_27_164836_create_transactions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
index d5f73f8444..6eee751926 100644
--- a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
+++ b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentTransactionTable
*
*/
diff --git a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
index 2069e961a9..e6de376c42 100644
--- a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
+++ b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentTransactionJournalTable
*
*/
diff --git a/app/database/migrations/2014_07_06_123842_create_preferences_table.php b/app/database/migrations/2014_07_06_123842_create_preferences_table.php
index 61f12090a2..7cd7069c8e 100644
--- a/app/database/migrations/2014_07_06_123842_create_preferences_table.php
+++ b/app/database/migrations/2014_07_06_123842_create_preferences_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePreferencesTable
*
*/
diff --git a/app/database/migrations/2014_07_09_204843_create_session_table.php b/app/database/migrations/2014_07_09_204843_create_session_table.php
index e09703979a..240f66ba88 100644
--- a/app/database/migrations/2014_07_09_204843_create_session_table.php
+++ b/app/database/migrations/2014_07_09_204843_create_session_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateSessionTable
*
*/
diff --git a/app/database/migrations/2014_07_17_183717_create_limits_table.php b/app/database/migrations/2014_07_17_183717_create_limits_table.php
index fc39882c7b..f6c507216a 100644
--- a/app/database/migrations/2014_07_17_183717_create_limits_table.php
+++ b/app/database/migrations/2014_07_17_183717_create_limits_table.php
@@ -4,6 +4,9 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)\
+ *
+ *
* Class CreateLimitsTable
*
*/
diff --git a/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php b/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
index 1240cf3657..46edc87ac9 100644
--- a/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
+++ b/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateLimitRepeatTable
*
*/
diff --git a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
index 512387e29b..6105817f64 100644
--- a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
+++ b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentRecurringTransactionTable
*
*/
diff --git a/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php b/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
index d285d99487..341d36a9d8 100644
--- a/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
+++ b/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggyInstance
*
*/
diff --git a/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php b/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
index 480f09d658..8eebf01388 100644
--- a/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
+++ b/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggybankEventsTable
*
*/
diff --git a/app/database/migrations/2014_08_23_113221_create_reminders_table.php b/app/database/migrations/2014_08_23_113221_create_reminders_table.php
index 8d231aac04..1aaa49fb0a 100644
--- a/app/database/migrations/2014_08_23_113221_create_reminders_table.php
+++ b/app/database/migrations/2014_08_23_113221_create_reminders_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateRemindersTable
*
*/
diff --git a/app/database/migrations/2014_11_10_172053_create_account_meta_table.php b/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
index 0cbc84ae4d..1febb05a1b 100644
--- a/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
+++ b/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountMetaTable
*
*/
diff --git a/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php b/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
index acba3c84ce..c3d2e3af49 100644
--- a/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
+++ b/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionGroupsTable
*
*/
diff --git a/app/database/migrations/2014_12_13_190730_changes_for_v321.php b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
index 4a9a743178..9d5242189d 100644
--- a/app/database/migrations/2014_12_13_190730_changes_for_v321.php
+++ b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
@@ -5,6 +5,9 @@ use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName) // method names are mandated by laravel.
+ * @SuppressWarnings("TooManyMethods") // I'm fine with this
+ *
* Down:
* 1. Create new Components based on Budgets.
* 2. Create new Components based on Categories
diff --git a/app/database/migrations/2014_12_24_191544_changes_for_v322.php b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
index 0714ea25fe..5b5e7abff2 100644
--- a/app/database/migrations/2014_12_24_191544_changes_for_v322.php
+++ b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
@@ -4,6 +4,10 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ * @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
+
+ *
* Class ChangesForV322
*/
class ChangesForV322 extends Migration
diff --git a/app/database/migrations/2015_01_18_082406_changes_for_v325.php b/app/database/migrations/2015_01_18_082406_changes_for_v325.php
new file mode 100644
index 0000000000..5015a35e21
--- /dev/null
+++ b/app/database/migrations/2015_01_18_082406_changes_for_v325.php
@@ -0,0 +1,71 @@
+dropIndex('unique_ci_combo');
+ $table->dropUnique('unique_ci_combi');
+
+ }
+ );
+ } catch (QueryException $e) {
+ // don't care.
+ } catch (PDOException $e) {
+ // don't care.
+ } catch (\Exception $e) {
+ // don't care either.
+ }
+
+ // allow journal descriptions to be encrypted.
+ Schema::table(
+ 'transaction_journals', function (Blueprint $table) {
+ $table->boolean('encrypted')->default(0);
+
+ }
+ );
+ try {
+ DB::update('ALTER TABLE `transaction_journals` MODIFY `description` VARCHAR(1024)');
+ } catch (QueryException $e) {
+ // don't care.
+ } catch (PDOException $e) {
+ // don't care.
+ } catch (\Exception $e) {
+ // don't care either.
+ }
+
+ }
+
+}
diff --git a/app/database/seeds/AccountTypeSeeder.php b/app/database/seeds/AccountTypeSeeder.php
index f0fd27b341..93523755ac 100644
--- a/app/database/seeds/AccountTypeSeeder.php
+++ b/app/database/seeds/AccountTypeSeeder.php
@@ -10,31 +10,14 @@ class AccountTypeSeeder extends Seeder
{
DB::table('account_types')->delete();
- AccountType::create(
- ['type' => 'Default account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Cash account', 'editable' => false]
- );
- AccountType::create(
- ['type' => 'Asset account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Expense account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Revenue account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Initial balance account', 'editable' => false]
- );
- AccountType::create(
- ['type' => 'Beneficiary account', 'editable' => true]
- );
-
- AccountType::create(
- ['type' => 'Import account', 'editable' => false]
- );
+ AccountType::create(['type' => 'Default account', 'editable' => true]);
+ AccountType::create(['type' => 'Cash account', 'editable' => false]);
+ AccountType::create(['type' => 'Asset account', 'editable' => true]);
+ AccountType::create(['type' => 'Expense account', 'editable' => true]);
+ AccountType::create(['type' => 'Revenue account', 'editable' => true]);
+ AccountType::create(['type' => 'Initial balance account', 'editable' => false]);
+ AccountType::create(['type' => 'Beneficiary account', 'editable' => true]);
+ AccountType::create(['type' => 'Import account', 'editable' => false]);
}
diff --git a/app/database/seeds/DatabaseSeeder.php b/app/database/seeds/DatabaseSeeder.php
index 29319ca38c..f357dfd6ec 100644
--- a/app/database/seeds/DatabaseSeeder.php
+++ b/app/database/seeds/DatabaseSeeder.php
@@ -18,8 +18,10 @@ class DatabaseSeeder extends Seeder
$this->call('AccountTypeSeeder');
$this->call('TransactionCurrencySeeder');
$this->call('TransactionTypeSeeder');
- $this->call('DefaultUserSeeder');
- $this->call('TestContentSeeder');
+
+ if (App::environment() == 'testing') {
+ $this->call('TestDataSeeder');
+ }
}
}
diff --git a/app/database/seeds/DefaultUserSeeder.php b/app/database/seeds/DefaultUserSeeder.php
deleted file mode 100644
index 1b40e29097..0000000000
--- a/app/database/seeds/DefaultUserSeeder.php
+++ /dev/null
@@ -1,22 +0,0 @@
-delete();
- if (App::environment() == 'testing' || App::environment() == 'homestead') {
-
- User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'acceptance@example.com', 'password' => 'acceptance', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
-
- }
-
- }
-
-}
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestDataSeeder.php
similarity index 70%
rename from app/database/seeds/TestContentSeeder.php
rename to app/database/seeds/TestDataSeeder.php
index e2cdebf7d7..6ef7c64842 100644
--- a/app/database/seeds/TestContentSeeder.php
+++ b/app/database/seeds/TestDataSeeder.php
@@ -1,14 +1,15 @@
first();
-
- // create initial accounts and various other stuff:
- $this->createAssetAccounts($user);
- $this->createBudgets($user);
- $this->createCategories($user);
- $this->createPiggyBanks($user);
- $this->createReminders($user);
- $this->createRecurringTransactions($user);
- $this->createBills($user);
- $this->createExpenseAccounts($user);
- $this->createRevenueAccounts($user);
-
- // get some objects from the database:
- $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
- $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
- $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
- $television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
- $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
- $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
+ User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
+ User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
- $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
- $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
+ $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
+ Log::debug('Created users.');
+ // create initial accounts and various other stuff:
+ $this->createAssetAccounts($user);
+ Log::debug('Created asset accounts.');
+ $this->createBudgets($user);
+ Log::debug('Created budgets.');
+ $this->createCategories($user);
+ Log::debug('Created categories.');
+ $this->createPiggyBanks($user);
+ Log::debug('Created piggy banks.');
+ $this->createReminders($user);
+ Log::debug('Created reminders.');
+ $this->createRecurringTransactions($user);
+ Log::debug('Created recurring transactions.');
+ $this->createBills($user);
+ Log::debug('Created bills.');
+ $this->createExpenseAccounts($user);
+ Log::debug('Created expense accounts.');
+ $this->createRevenueAccounts($user);
+ Log::debug('Created revenue accounts.');
- $house = Category::whereName('House')->orderBy('id', 'DESC')->first();
+ // get some objects from the database:
+ $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
+ Log::debug('Found checking: ' . json_encode($checking));
+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
+ Log::debug('Found savings: ' . json_encode($savings));
+ $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
+ Log::debug('Found landlord: ' . json_encode($landLord));
+ $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
+ Log::debug('Found utilities: ' . json_encode($utilities));
+ $television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
+ Log::debug('Found tv company: ' . json_encode($television));
+ $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
+ Log::debug('Found phone company: ' . json_encode($phone));
+ $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
+ Log::debug('Found employer: ' . json_encode($employer));
- $withdrawal = TransactionType::whereType('Withdrawal')->first();
- $deposit = TransactionType::whereType('Deposit')->first();
- $transfer = TransactionType::whereType('Transfer')->first();
+ $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
+ Log::debug('Found bills budget: ' . json_encode($bills));
+ $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
+ Log::debug('Found groceries budget: ' . json_encode($groceries));
- $euro = TransactionCurrency::whereCode('EUR')->first();
-
- $rentBill = Bill::where('name', 'Rent')->first();
+ $house = Category::whereName('House')->orderBy('id', 'DESC')->first();
+ Log::debug('Found house category: ' . json_encode($checking));
- $current = clone $this->_yearAgoStartOfMonth;
- while ($current <= $this->_startOfMonth) {
- $cur = $current->format('Y-m-d');
- $formatted = $current->format('F Y');
+ $withdrawal = TransactionType::whereType('Withdrawal')->first();
+ Log::debug('Found withdrawal: ' . json_encode($withdrawal));
+ $deposit = TransactionType::whereType('Deposit')->first();
+ Log::debug('Found deposit: ' . json_encode($deposit));
+ $transfer = TransactionType::whereType('Transfer')->first();
+ Log::debug('Found transfer: ' . json_encode($transfer));
- // create expenses for rent, utilities, TV, phone on the 1st of the month.
- $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);
- $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);
- $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);
- $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+ Log::debug('Found euro: ' . json_encode($euro));
- // two transactions. One without a budget, one without a category.
- $this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);
- $this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);
-
- // income from job:
- $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);
- $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
-
- $this->createGroceries($current);
- $this->createBigExpense(clone $current);
-
- echo 'Created test-content for ' . $current->format('F Y') . "\n";
- $current->addMonth();
- }
+ $rentBill = Bill::where('name', 'Rent')->first();
+ Log::debug('Found bill "rent": ' . json_encode($rentBill));
- // piggy bank event
- // add money to this piggy bank
- // create a piggy bank event to match:
- $piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
- $intoPiggy = $this->createTransaction($checking, $savings, 100, $transfer, 'Money for piggy', $this->yaeom, $euro, $groceries, $house);
- PiggyBankEvent::create(
- [
- 'piggy_bank_id' => $piggyBank->id,
- 'transaction_journal_id' => $intoPiggy->id,
- 'date' => $this->yaeom,
- 'amount' => 100
- ]
- );
+ $current = clone $this->_yearAgoStartOfMonth;
+ while ($current <= $this->_startOfMonth) {
+ $cur = $current->format('Y-m-d');
+ $formatted = $current->format('F Y');
+ Log::debug('Now at: ' . $cur);
+
+ // create expenses for rent, utilities, TV, phone on the 1st of the month.
+ $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);
+ Log::debug('Created rent.');
+ $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);
+ Log::debug('Created utilities.');
+ $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);
+ Log::debug('Created TV.');
+ $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);
+ Log::debug('Created phone bill.');
+
+ // two transactions. One without a budget, one without a category.
+ $this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);
+ Log::debug('Created extra charges no budget.');
+ $this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);
+ Log::debug('Created extra charges no category.');
+
+ // income from job:
+ $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);
+ Log::debug('Created income.');
+ $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
+ Log::debug('Created savings.');
+
+ $this->createGroceries($current);
+ Log::debug('Created groceries range.');
+ $this->createBigExpense(clone $current);
+ Log::debug('Created big expense.');
+
+ echo 'Created test-content for ' . $current->format('F Y') . "\n";
+ $current->addMonth();
}
+
+
+ // piggy bank event
+ // add money to this piggy bank
+ // create a piggy bank event to match:
+ $piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
+ $intoPiggy = $this->createTransaction($checking, $savings, 100, $transfer, 'Money for piggy', $this->yaeom, $euro, $groceries, $house);
+ PiggyBankEvent::create(
+ [
+ 'piggy_bank_id' => $piggyBank->id,
+ 'transaction_journal_id' => $intoPiggy->id,
+ 'date' => $this->yaeom,
+ 'amount' => 100
+ ]
+ );
}
/**
@@ -181,6 +218,9 @@ class TestContentSeeder extends Seeder
}
/**
+ * @SuppressWarnings(PHPMD.ShortVariable)
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
+ *
* @param Account $from
* @param Account $to
* @param $amount
@@ -202,15 +242,24 @@ class TestContentSeeder extends Seeder
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
$billID = is_null($bill) ? null : $bill->id;
-
+ Log::debug('String length of encrypted description ("'.$description.'") is: ' . strlen(Crypt::encrypt($description)));
/** @var TransactionJournal $journal */
$journal = TransactionJournal::create(
[
- 'user_id' => $user->id, 'transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'bill_id' => $billID,
- 'description' => $description, 'completed' => 1, 'date' => $date
+ 'user_id' => $user->id,
+ 'transaction_type_id' => $type->id,
+ 'transaction_currency_id' => $currency->id,
+ 'bill_id' => $billID,
+ 'description' => $description,
+ 'completed' => 1,
+ 'date' => $date
]
);
+ //Log::debug('Journal valid: ' . Steam::boolString($journal->isValid()));
+ //Log::debug('Journal errors: ' . json_encode($journal->getErrors()));
+ //Log::debug('Journal created: ' . json_encode($journal));
+
Transaction::create(['account_id' => $from->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount * -1]);
Transaction::create(['account_id' => $to->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount]);
@@ -411,16 +460,8 @@ class TestContentSeeder extends Seeder
{
// bill
Bill::create(
- [
- 'user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord',
- 'amount_min' => 700,
- 'amount_max' => 900,
- 'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- ]
+ ['user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord', 'amount_min' => 700, 'amount_max' => 900, 'date' => $this->som,
+ 'active' => 1, 'automatch' => 1, 'repeat_freq' => 'monthly', 'skip' => 0,]
);
// bill
@@ -429,13 +470,10 @@ class TestContentSeeder extends Seeder
'user_id' => $user->id,
'name' => 'Gas licht',
'match' => 'no,match',
- 'amount_min' => 500,
- 'amount_max' => 700,
+ 'amount_min' => 500, 'amount_max' => 700,
'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
+ 'active' => 1, 'automatch' => 1,
+ 'repeat_freq' => 'monthly', 'skip' => 0,
]
);
@@ -557,5 +595,8 @@ class TestContentSeeder extends Seeder
);
$group->transactionjournals()->save($one);
$group->transactionjournals()->save($two);
+ $group->save();
}
-}
+
+
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index 368aeecac6..7562946ac8 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -41,47 +41,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
return $this->getUser()->accounts()->accountTypeIn($types)->count();
}
- /**
- * @return int
- */
- public function countAssetAccounts()
- {
- return $this->countAccountsByType(['Default account', 'Asset account']);
- }
-
- /**
- * @return int
- */
- public function countExpenseAccounts()
- {
- return $this->countAccountsByType(['Expense account', 'Beneficiary account']);
- }
-
- /**
- * Counts the number of total revenue accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countRevenueAccounts()
- {
- return $this->countAccountsByType(['Revenue account']);
- }
-
- /**
- * @param \Account $account
- *
- * @return \Account|null
- */
- public function findInitialBalanceAccount(\Account $account)
- {
- /** @var \FireflyIII\Database\AccountType\AccountType $acctType */
- $acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
-
- $accountType = $acctType->findByWhat('initial');
-
- return $this->getUser()->accounts()->where('account_type_id', $accountType->id)->where('name', 'LIKE', $account->name . '%')->first();
- }
-
/**
* @param array $types
*
@@ -93,7 +52,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
* Basic query:
*/
$query = $this->getUser()->accounts()->accountTypeIn($types)->withMeta()->orderBy('name', 'ASC');;
- $set = $query->get(['accounts.*']);
+ $set = $query->get(['accounts.*', 'account_meta.data as accountRole']);
$set->each(
function (\Account $account) {
@@ -101,63 +60,13 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
* Get last activity date.
*/
$account->lastActivityDate = $this->getLastActivity($account);
+ $account->accountRole = \Config::get('firefly.accountRoles.' . json_decode($account->accountRole));
}
);
return $set;
}
- /**
- * Get all asset accounts. Optional JSON based parameters.
- *
- * @param array $metaFilter
- *
- * @return Collection
- */
- public function getAssetAccounts($metaFilter = [])
- {
- $list = $this->getAccountsByType(['Default account', 'Asset account']);
- $list->each(
- function (\Account $account) {
-
- // get accountRole:
-
- /** @var \AccountMeta $entry */
- $accountRole = $account->accountmeta()->whereName('accountRole')->first();
- if (!$accountRole) {
- $accountRole = new \AccountMeta;
- $accountRole->account_id = $account->id;
- $accountRole->name = 'accountRole';
- $accountRole->data = 'defaultExpense';
- $accountRole->save();
-
- }
- $account->accountRole = $accountRole->data;
- }
- );
-
- return $list;
-
- }
-
- /**
- * @return Collection
- */
- public function getExpenseAccounts()
- {
- return $this->getAccountsByType(['Expense account', 'Beneficiary account']);
- }
-
- /**
- * Get all revenue accounts.
- *
- * @return Collection
- */
- public function getRevenueAccounts()
- {
- return $this->getAccountsByType(['Revenue account']);
- }
-
/**
* @param \Account $account
*
@@ -180,51 +89,32 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
{
$opposingData = ['name' => $account->name . ' Initial Balance', 'active' => 0, 'what' => 'initial'];
$opposingAccount = $this->store($opposingData);
-
- /*
- * Create a journal from opposing to account or vice versa.
- */
- $balance = floatval($data['openingbalance']);
- $date = new Carbon($data['openingbalancedate']);
- /** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $tj */
- $tj = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
+ $balance = floatval($data['openingBalance']);
+ $date = new Carbon($data['openingBalanceDate']);
+ /** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journals */
+ $journals = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
+ $fromAccount = $opposingAccount;
+ $toAccount = $account;
if ($balance < 0) {
- // first transaction draws money from the new account to the opposing
- $from = $account;
- $to = $opposingAccount;
- } else {
- // first transaction puts money into account
- $from = $opposingAccount;
- $to = $account;
+ $fromAccount = $account;
+ $toAccount = $opposingAccount;
}
-
// data for transaction journal:
$balance = $balance < 0 ? $balance * -1 : $balance;
- // find the account type:
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
$type = $typeRepository->findByWhat('opening');
+ $currency = $journals->getJournalCurrencyById(intval($data['balance_currency_id']));
+ //$currency = \Amount::getDefaultCurrency();
- // find the currency.
- $currency = \Amount::getDefaultCurrency();
+ $opening = ['transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'amount' => $balance, 'from' => $fromAccount,
+ 'completed' => 0, 'what' => 'opening', 'to' => $toAccount, 'date' => $date,
+ 'description' => 'Opening balance for new account ' . $account->name,];
- $opening = [
- 'transaction_type_id' => $type->id,
- 'transaction_currency_id' => $currency->id,
- 'amount' => $balance,
- 'from' => $from,
- 'completed' => 0,
- 'currency' => 'EUR',
- 'what' => 'opening',
- 'to' => $to,
- 'date' => $date,
- 'description' => 'Opening balance for new account ' . $account->name,];
-
-
- $validation = $tj->validate($opening);
+ $validation = $journals->validate($opening);
if ($validation['errors']->count() == 0) {
- $tj->store($opening);
+ $journals->store($opening);
return true;
} else {
@@ -233,45 +123,68 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
\App::abort(500);
}
+ return false;
}
/**
+ * @param \Account $account
+ *
+ * @return int
+ */
+ public function getLastActivity(\Account $account)
+ {
+ $lastActivityKey = 'account.' . $account->id . '.lastActivityDate';
+ if (\Cache::has($lastActivityKey)) {
+ return \Cache::get($lastActivityKey);
+ }
+
+ $transaction = $account->transactions()
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ ->orderBy('transaction_journals.date', 'DESC')->first();
+ if ($transaction) {
+ $date = $transaction->transactionJournal->date;
+ } else {
+ $date = 0;
+ }
+ \Cache::forever($lastActivityKey, $date);
+
+ return $date;
+ }
+
+ /**
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot make it shorter because of query.
* @param Eloquent $model
*
* @return bool
*/
public function destroy(Eloquent $model)
{
-
- // delete piggy banks
- // delete journals:
- $journals = \TransactionJournal::whereIn(
+ $journals = \TransactionJournal::whereIn(
'id', function (QueryBuilder $query) use ($model) {
$query->select('transaction_journal_id')
- ->from('transactions')->whereIn(
- 'account_id', function (QueryBuilder $query) use ($model) {
- $query
- ->select('id')
- ->from('accounts')
- ->where(
- function (QueryBuilder $q) use ($model) {
- $q->where('id', $model->id);
- $q->orWhere(
- function (QueryBuilder $q) use ($model) {
- $q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
- $q->where('accounts.account_type_id', 3);
- $q->where('accounts.active', 0);
- }
- );
- }
- )->where('accounts.user_id', $this->getUser()->id);
- }
- )->get();
+ ->from('transactions')
+ ->whereIn(
+ 'account_id', function (QueryBuilder $query) use ($model) {
+ $query
+ ->select('accounts.id')
+ ->from('accounts')
+ ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
+ ->where(
+ function (QueryBuilder $q) use ($model) {
+ $q->where('accounts.id', $model->id);
+ $q->orWhere(
+ function (QueryBuilder $q) use ($model) {
+ $q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
+ $q->where('account_types.type', 'Initial balance account');
+ $q->where('accounts.active', 0);
+ }
+ );
+ }
+ )->where('accounts.user_id', $this->getUser()->id);
+ }
+ )->get();
}
)->get();
- /*
- * Get all transactions.
- */
$transactions = [];
/** @var \TransactionJournal $journal */
foreach ($journals as $journal) {
@@ -281,25 +194,26 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
$journal->delete();
}
- // also delete transactions.
if (count($transactions) > 0) {
\Transaction::whereIn('id', $transactions)->delete();
}
-
-
- /*
- * Trigger deletion:
- */
\Event::fire('account.destroy', [$model]);
- // delete accounts:
+ // get account type:
+ /** @var \FireflyIII\Database\AccountType\AccountType $acctType */
+ $acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
+
+ $accountType = $acctType->findByWhat('initial');
+
+ //$q->where('account_types.type', '');
+
\Account::where(
- function (EloquentBuilder $q) use ($model) {
+ function (EloquentBuilder $q) use ($model, $accountType) {
$q->where('id', $model->id);
$q->orWhere(
- function (EloquentBuilder $q) use ($model) {
+ function (EloquentBuilder $q) use ($model, $accountType) {
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
- $q->where('accounts.account_type_id', 3);
+ $q->where('accounts.account_type_id', $accountType->id);
$q->where('accounts.active', 0);
}
);
@@ -318,9 +232,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
public function store(array $data)
{
- /*
- * Find account type.
- */
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
@@ -330,7 +241,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
$data['account_type_id'] = $accountType->id;
$data['active'] = isset($data['active']) && $data['active'] === '1' ? 1 : 0;
-
$data = array_except($data, ['_token', 'what']);
$account = new \Account($data);
if (!$account->isValid()) {
@@ -339,7 +249,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
\App::abort(500);
}
$account->save();
- if (isset($data['openingbalance']) && floatval($data['openingbalance']) != 0) {
+ if (isset($data['openingBalance']) && floatval($data['openingBalance']) != 0) {
$this->storeInitialBalance($account, $data);
}
@@ -379,15 +289,15 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
$model->save();
- if (isset($data['openingbalance']) && isset($data['openingbalancedate']) && strlen($data['openingbalancedate']) > 0) {
+ if (isset($data['openingBalance']) && isset($data['openingBalanceDate']) && strlen($data['openingBalanceDate']) > 0) {
/** @noinspection PhpParamsInspection */
$openingBalance = $this->openingBalanceTransaction($model);
if (is_null($openingBalance)) {
$this->storeInitialBalance($model, $data);
} else {
- $openingBalance->date = new Carbon($data['openingbalancedate']);
+ $openingBalance->date = new Carbon($data['openingBalanceDate']);
$openingBalance->save();
- $amount = floatval($data['openingbalance']);
+ $amount = floatval($data['openingBalance']);
/** @var \Transaction $transaction */
foreach ($openingBalance->transactions as $transaction) {
if ($transaction->account_id == $model->id) {
@@ -453,14 +363,14 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
* Opening balance and opening balance date.
*/
if (isset($model['what']) && $model['what'] == 'asset') {
- if (isset($model['openingbalance']) && strlen($model['openingbalance']) > 0 && !is_numeric($model['openingbalance'])) {
- $errors->add('openingbalance', 'This is not a number.');
+ if (isset($model['openingBalance']) && strlen($model['openingBalance']) > 0 && !is_numeric($model['openingBalance'])) {
+ $errors->add('openingBalance', 'This is not a number.');
}
- if (isset($model['openingbalancedate']) && strlen($model['openingbalancedate']) > 0) {
+ if (isset($model['openingBalanceDate']) && strlen($model['openingBalanceDate']) > 0) {
try {
- new Carbon($model['openingbalancedate']);
+ new Carbon($model['openingBalanceDate']);
} catch (\Exception $e) {
- $errors->add('openingbalancedate', 'This date is invalid.');
+ $errors->add('openingBalanceDate', 'This date is invalid.');
}
}
}
@@ -469,11 +379,11 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
if (!$errors->has('name')) {
$successes->add('name', 'OK');
}
- if (!$errors->has('openingbalance')) {
- $successes->add('openingbalance', 'OK');
+ if (!$errors->has('openingBalance')) {
+ $successes->add('openingBalance', 'OK');
}
- if (!$errors->has('openingbalancedate')) {
- $successes->add('openingbalancedate', 'OK');
+ if (!$errors->has('openingBalanceDate')) {
+ $successes->add('openingBalanceDate', 'OK');
}
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
@@ -492,6 +402,9 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ * @codeCoverageIgnore
+ *
* @param $what
*
* @throws NotImplementedException
@@ -507,6 +420,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function get()
{
@@ -531,14 +445,14 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function firstExpenseAccountOrCreate($name)
{
- /** @var \FireflyIII\Database\AccountType\AccountType $accountTypeRepository */
- $accountTypeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
+ /** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
+ $typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
- $accountType = $accountTypeRepository->findByWhat('expense');
+ $accountType = $typeRepository->findByWhat('expense');
// if name is "", find cash account:
if (strlen($name) == 0) {
- $cashAccountType = $accountTypeRepository->findByWhat('cash');
+ $cashAccountType = $typeRepository->findByWhat('cash');
// find or create cash account:
return \Account::firstOrCreate(
@@ -560,10 +474,20 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function firstRevenueAccountOrCreate($name)
{
- /** @var \FireflyIII\Database\AccountType\AccountType $accountTypeRepository */
- $accountTypeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
+ /** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
+ $typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
- $accountType = $accountTypeRepository->findByWhat('revenue');
+ $accountType = $typeRepository->findByWhat('revenue');
+
+ // if name is "", find cash account:
+ if (strlen($name) == 0) {
+ $cashAccountType = $typeRepository->findByWhat('cash');
+
+ // find or create cash account:
+ return \Account::firstOrCreate(
+ ['name' => 'Cash account', 'account_type_id' => $cashAccountType->id, 'active' => 0, 'user_id' => $this->getUser()->id,]
+ );
+ }
$data = ['user_id' => $this->getUser()->id, 'account_type_id' => $accountType->id, 'name' => $name, 'active' => 1];
@@ -571,57 +495,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
- /**
- * @param \Account $account
- * @param int $limit
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getAllTransactionJournals(\Account $account, $limit = 50)
- {
- $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
- $set = $this->getUser()->transactionJournals()->withRelevantData()->leftJoin(
- 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
- )->where('transactions.account_id', $account->id)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
- $count = $this->getUser()->transactionJournals()->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->orderBy('date', 'DESC')->where('transactions.account_id', $account->id)->count();
- $items = [];
- foreach ($set as $entry) {
- $items[] = $entry;
- }
-
- return \Paginator::make($items, $count, $limit);
-
-
- }
-
- /**
- * @param \Account $account
- *
- * @return int
- */
- public function getLastActivity(\Account $account)
- {
- $lastActivityKey = 'account.' . $account->id . '.lastActivityDate';
- if (\Cache::has($lastActivityKey)) {
- return \Cache::get($lastActivityKey);
- }
-
- $transaction = $account->transactions()
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->orderBy('transaction_journals.date', 'DESC')->first();
- if ($transaction) {
- $date = $transaction->transactionJournal->date;
- } else {
- $date = 0;
- }
- \Cache::forever($lastActivityKey, $date);
-
- return $date;
- }
-
/**
* @param \Account $account
* @param int $limit
@@ -656,24 +529,4 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
- /**
- * @param \Account $account
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getTransactionJournalsInRange(\Account $account, Carbon $start, Carbon $end)
- {
- $set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->leftJoin(
- 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
- )->where('transactions.account_id', $account->id)->before($end)->after($start)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
-
- return $set;
-
- }
-
-
}
diff --git a/app/lib/FireflyIII/Database/Account/AccountInterface.php b/app/lib/FireflyIII/Database/Account/AccountInterface.php
index 336df90401..c9d21ba229 100644
--- a/app/lib/FireflyIII/Database/Account/AccountInterface.php
+++ b/app/lib/FireflyIII/Database/Account/AccountInterface.php
@@ -21,34 +21,6 @@ interface AccountInterface
*/
public function countAccountsByType(array $types);
- /**
- * Counts the number of total asset accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countAssetAccounts();
-
- /**
- * Counts the number of total expense accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countExpenseAccounts();
-
- /**
- * Counts the number of total revenue accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countRevenueAccounts();
-
- /**
- * @param \Account $account
- *
- * @return \Account|null
- */
- public function findInitialBalanceAccount(\Account $account);
-
/**
* Get all accounts of the selected types. Is also capable of handling DataTables' parameters.
*
@@ -58,24 +30,6 @@ interface AccountInterface
*/
public function getAccountsByType(array $types);
- /**
- * Get all asset accounts. The parameters are optional and are provided by the DataTables plugin.
- *
- * @return Collection
- */
- public function getAssetAccounts();
-
- /**
- * @return Collection
- */
- public function getExpenseAccounts();
-
- /**
- * Get all revenue accounts.
- *
- * @return Collection
- */
- public function getRevenueAccounts();
/**
* @param \Account $account
diff --git a/app/lib/FireflyIII/Database/AccountType/AccountType.php b/app/lib/FireflyIII/Database/AccountType/AccountType.php
index 58f6cebb13..2b30ea3e25 100644
--- a/app/lib/FireflyIII/Database/AccountType/AccountType.php
+++ b/app/lib/FireflyIII/Database/AccountType/AccountType.php
@@ -19,9 +19,11 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function destroy(Eloquent $model)
{
@@ -30,9 +32,11 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param array $data
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function store(array $data)
{
@@ -42,9 +46,11 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
* @param array $data
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function update(Eloquent $model, array $data)
{
@@ -52,6 +58,8 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Validates an array. Returns an array containing MessageBags
* errors/warnings/successes.
*
@@ -59,6 +67,7 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
*
* @return array
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function validate(array $model)
{
@@ -66,12 +75,15 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function find($objectId)
{
@@ -88,34 +100,27 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
*/
public function findByWhat($what)
{
- switch ($what) {
- case 'expense':
- return \AccountType::whereType('Expense account')->first();
- break;
- case 'asset':
- return \AccountType::whereType('Asset account')->first();
- break;
- case 'revenue':
- return \AccountType::whereType('Revenue account')->first();
- break;
- case 'cash':
- return \AccountType::whereType('Cash account')->first();
- break;
- case 'initial':
- return \AccountType::whereType('Initial balance account')->first();
- break;
- default:
- throw new FireflyException('Cannot find account type described as "' . e($what) . '".');
- break;
-
+ $typeMap = [
+ 'expense' => 'Expense account',
+ 'asset' => 'Asset account',
+ 'revenue' => 'Revenue account',
+ 'cash' => 'Cash account',
+ 'initial' => 'Initial balance account',
+ ];
+ if (isset($typeMap[$what])) {
+ return \AccountType::whereType($typeMap[$what])->first();
}
+ throw new FireflyException('Cannot find account type described as "' . e($what) . '".');
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function get()
{
@@ -123,10 +128,13 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
diff --git a/app/lib/FireflyIII/Database/Bill/Bill.php b/app/lib/FireflyIII/Database/Bill/Bill.php
index 6e17ffe827..75b4800497 100644
--- a/app/lib/FireflyIII/Database/Bill/Bill.php
+++ b/app/lib/FireflyIII/Database/Bill/Bill.php
@@ -114,7 +114,7 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
$warnings = new MessageBag;
$successes = new MessageBag;
$errors = new MessageBag;
- if (isset($model['amount_min']) && isset($model['amount_max']) && floatval($model['amount_min']) > floatval($model['amount_max'])) {
+ if (floatval($model['amount_min']) > floatval($model['amount_max'])) {
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
}
@@ -133,12 +133,15 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function find($objectId)
{
@@ -146,12 +149,15 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -169,39 +175,18 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
throw new NotImplementedException;
}
- /**
- * Returns all objects.
- *
- * @return Collection
- */
- public function getActive()
- {
- return $this->getUser()->bills()->where('active', 1)->get();
- }
-
- /**
- * @param \Bill $bill
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return \TransactionJournal|null
- */
- public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end)
- {
- return $this->getUser()->transactionjournals()->where('bill_id', $bill->id)->after($start)->before($end)->first();
-
- }
-
/**
* @param \Bill $bill
*
@@ -218,15 +203,14 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \Bill $bill
*
* @return Carbon|null
*/
public function nextExpectedMatch(\Bill $bill)
{
- /*
- * The date Firefly tries to find. If this stays null, it's "unknown".
- */
$finalDate = null;
if ($bill->active == 0) {
return $finalDate;
@@ -238,10 +222,6 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
*/
$today = \DateKit::addPeriod(new Carbon, $bill->repeat_freq, 0);
- /*
- * FF3 loops from the $start of the bill, and to make sure
- * $skip works, it adds one (for modulo).
- */
$skip = $bill->skip + 1;
$start = \DateKit::startOfPeriod(new Carbon, $bill->repeat_freq);
/*
diff --git a/app/lib/FireflyIII/Database/Bill/BillInterface.php b/app/lib/FireflyIII/Database/Bill/BillInterface.php
index f6dca6325f..ec75dd1167 100644
--- a/app/lib/FireflyIII/Database/Bill/BillInterface.php
+++ b/app/lib/FireflyIII/Database/Bill/BillInterface.php
@@ -11,18 +11,6 @@ use Carbon\Carbon;
*/
interface BillInterface
{
- /**
- * @param \Bill $bill
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return null|\TransactionJournal
- * @internal param Carbon $current
- * @internal param Carbon $currentEnd
- *
- */
- public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end);
-
/**
* @param \Bill $bill
*
diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php
index 05f712a259..86d3f0b5f8 100644
--- a/app/lib/FireflyIII/Database/Budget/Budget.php
+++ b/app/lib/FireflyIII/Database/Budget/Budget.php
@@ -8,9 +8,9 @@ use FireflyIII\Database\SwitchUser;
use FireflyIII\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Database\Eloquent\Model as Eloquent;
+use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
-use Illuminate\Database\Query\Builder as QueryBuilder;
/**
* Class Budget
@@ -97,6 +97,71 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
}
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function expenseNoBudget(Carbon $start, Carbon $end)
+ {
+ // Add expenses that have no budget:
+ return $this->getUser()
+ ->transactionjournals()
+ ->whereNotIn(
+ 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
+ $query
+ ->select('transaction_journals.id')
+ ->from('transaction_journals')
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
+ ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
+ }
+ )
+ ->before($end)
+ ->after($start)
+ ->lessThan(0)
+ ->transactionTypes(['Withdrawal'])
+ ->get();
+ }
+
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function journalsNoBudget(Carbon $start, Carbon $end)
+ {
+ $set = $this->getUser()
+ ->transactionjournals()
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->whereNull('budget_transaction_journal.id')
+ ->before($end)
+ ->after($start)
+ ->orderBy('transaction_journals.date')
+ ->get(['transaction_journals.*']);
+
+ return $set;
+ }
+
+ /**
+ * This method includes the time because otherwise, SQLite does not understand it.
+ *
+ * @param \Budget $budget
+ * @param Carbon $date
+ *
+ * @return \LimitRepetition|null
+ */
+ public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
+ {
+ return \LimitRepetition::
+ leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
+ ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
+ ->where('budget_limits.budget_id', $budget->id)
+ ->first(['limit_repetitions.*']);
+ }
+
/**
* Returns an object with id $id.
*
@@ -110,12 +175,15 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -135,10 +203,13 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
@@ -190,116 +261,6 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
return $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']);
}
- /**
- * @param \Budget $budget
- * @param int $limit
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getTransactionJournals(\Budget $budget, $limit = 50)
- {
- $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
- $set = $budget->transactionJournals()->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']);
- $count = $budget->transactionJournals()->count();
- $items = [];
- foreach ($set as $entry) {
- $items[] = $entry;
- }
-
- return \Paginator::make($items, $count, $limit);
-
- }
-
- /**
- * @param \Budget $budget
- * @param \LimitRepetition $repetition
- * @param int $limit
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getTransactionJournalsInRepetition(\Budget $budget, \LimitRepetition $repetition, $limit = 50)
- {
- $start = $repetition->startdate;
- $end = $repetition->enddate;
-
- $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
- $set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
- $count = $budget->transactionJournals()->before($end)->after($start)->count();
- $items = [];
- foreach ($set as $entry) {
- $items[] = $entry;
- }
-
- return \Paginator::make($items, $count, $limit);
- }
-
- /**
- * This method includes the time because otherwise, SQLite does not understand it.
- *
- * @param \Budget $budget
- * @param Carbon $date
- *
- * @return \LimitRepetition|null
- */
- public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
- {
- return \LimitRepetition::
- leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
- ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
- ->where('budget_limits.budget_id', $budget->id)
- ->first(['limit_repetitions.*']);
- }
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function expenseNoBudget(Carbon $start, Carbon $end)
- {
- // Add expenses that have no budget:
- return $this->getUser()
- ->transactionjournals()
- ->whereNotIn(
- 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
- $query
- ->select('transaction_journals.id')
- ->from('transaction_journals')
- ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
- ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
- }
- )
- ->before($end)
- ->after($start)
- ->lessThan(0)
- ->transactionTypes(['Withdrawal'])
- ->get();
- }
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function journalsNoBudget(Carbon $start, Carbon $end)
- {
- $set = $this->getUser()
- ->transactionjournals()
- ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->whereNull('budget_transaction_journal.id')
- ->before($end)
- ->after($start)
- ->orderBy('transaction_journals.date')
- ->get(['transaction_journals.*']);
-
- return $set;
- }
-
/**
* @param \Budget $budget
* @param Carbon $date
@@ -316,20 +277,6 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
return $sum;
}
- /**
- * @param \Budget $budget
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return float
- */
- public function spentInPeriod(\Budget $budget, Carbon $start, Carbon $end)
- {
- $sum = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
-
- return $sum;
- }
-
/**
* This method updates the amount (envelope) for the given date and budget. This results in a (new) limit (aka an envelope)
* for that budget. Returned to the user is the new limit repetition.
@@ -343,7 +290,7 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
*/
public function updateLimitAmount(\Budget $budget, Carbon $date, $amount)
{
- /** @var \Limit $limit */
+ /** @var \BudgetLimit $limit */
$limit = $this->limitOnStartingOnDate($budget, $date);
if (!$limit) {
// create one!
@@ -381,7 +328,7 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
* @param \Budget $budget
* @param Carbon $date
*
- * @return \Limit
+ * @return \BudgetLimit
*/
public function limitOnStartingOnDate(\Budget $budget, Carbon $date)
{
diff --git a/app/lib/FireflyIII/Database/Category/Category.php b/app/lib/FireflyIII/Database/Category/Category.php
index 873ac9c312..7c94a818eb 100644
--- a/app/lib/FireflyIII/Database/Category/Category.php
+++ b/app/lib/FireflyIII/Database/Category/Category.php
@@ -99,12 +99,15 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function find($objectId)
{
@@ -112,12 +115,15 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -125,6 +131,8 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
@@ -135,10 +143,13 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
@@ -195,19 +206,6 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
return $set;
}
- /**
- * @param \Category $category
- * @param Carbon $date
- *
- * @return null
- * @throws NotImplementedException
- * @internal param \Category $budget
- */
- public function repetitionOnStartingOnDate(\Category $category, Carbon $date)
- {
- throw new NotImplementedException;
- }
-
/**
* @param \Category $category
* @param Carbon $date
diff --git a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
index b77f9246bb..6490b96d9b 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
@@ -21,7 +21,6 @@ class PiggyBank extends PiggyBankShared implements CUDInterface, CommonDatabaseC
*
* @return mixed
* @throws FireflyException
- * @throws NotImplementedException
*/
public function findRepetitionByDate(\PiggyBank $piggyBank, Carbon $date)
{
@@ -30,13 +29,10 @@ class PiggyBank extends PiggyBankShared implements CUDInterface, CommonDatabaseC
if ($reps->count() == 1) {
return $reps->first();
}
- if ($reps->count() == 0) {
- throw new FireflyException('Should always find a piggy bank repetition.');
- }
// should filter the one we need:
$repetitions = $reps->filter(
function (\PiggyBankRepetition $rep) use ($date) {
- if ($date >= $rep->startdate && $date <= $rep->targetdate) {
+ if ($date->between($rep->startdate, $rep->targetdate)) {
return $rep;
}
diff --git a/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php b/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
index 5a878e37f4..212e3b77db 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
@@ -58,12 +58,15 @@ class PiggyBankShared
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -75,14 +78,11 @@ class PiggyBankShared
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
- return \PiggyBank::
- leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->whereIn('piggy_banks.id', [$ids])->where(
- 'accounts.user_id', $this->getUser()->id
- )
- ->first(['piggy_banks.*']);
+ throw new NotImplementedException;
}
/**
@@ -123,6 +123,8 @@ class PiggyBankShared
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param Eloquent $model
* @param array $data
*
diff --git a/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php b/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
index 171b4c7a88..bf22ca509c 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
@@ -17,6 +17,8 @@ class RepeatedExpense extends PiggyBankShared implements CUDInterface, CommonDat
{
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* Based on the piggy bank, the reminder-setting and
* other variables this method tries to divide the piggy bank into equal parts. Each is
* accommodated by a reminder (if everything goes to plan).
diff --git a/app/lib/FireflyIII/Database/Transaction/Transaction.php b/app/lib/FireflyIII/Database/Transaction/Transaction.php
index a92f110d2e..d8c2ea909d 100644
--- a/app/lib/FireflyIII/Database/Transaction/Transaction.php
+++ b/app/lib/FireflyIII/Database/Transaction/Transaction.php
@@ -22,9 +22,11 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function destroy(Eloquent $model)
{
@@ -59,11 +61,14 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
* @param array $data
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function update(Eloquent $model, array $data)
{
@@ -92,12 +97,15 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function find($objectId)
{
@@ -105,12 +113,15 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -122,6 +133,7 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function get()
{
@@ -129,10 +141,13 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
diff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
index 55b7c5f502..3eeb6eb5f9 100644
--- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
+++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
@@ -89,23 +89,27 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
- * @throws NotImplementedException
*
* @return \Eloquent
*/
public function find($objectId)
{
- throw new NotImplementedException;
+ return \TransactionCurrency::find($objectId);
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
* @throws NotImplementedException
+ * @codeCoverageIgnore
*
* @return \AccountType|null
*/
@@ -125,8 +129,11 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $objectIds
* @throws NotImplementedException
+ * @codeCoverageIgnore
*
* @return Collection
*/
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index beb7b13df2..b7feb1f15b 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -63,12 +63,13 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
*/
public function store(array $data)
{
- $currency = $this->getJournalCurrency($data['currency']);
- $journal = new \TransactionJournal(
+ $journal = new \TransactionJournal(
[
'transaction_type_id' => $data['transaction_type_id'],
- 'transaction_currency_id' => $currency->id, 'user_id' => $this->getUser()->id,
- 'description' => $data['description'], 'date' => $data['date'], 'completed' => 0]
+ 'transaction_currency_id' => $data['transaction_currency_id'],
+ 'user_id' => $this->getUser()->id,
+ 'description' => $data['description'],
+ 'date' => $data['date'], 'completed' => 0]
);
$journal->save();
@@ -102,7 +103,7 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
public function update(Eloquent $model, array $data)
{
$journalType = $this->getJournalType($data['what']);
- $currency = $this->getJournalCurrency($data['currency']);
+ $currency = $this->getJournalCurrencyById($data['transaction_currency_id']);
$model->description = $data['description'];
$model->date = $data['date'];
@@ -117,9 +118,6 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$this->storeBudget($data, $model);
$this->storeCategory($data, $model);
- /*
- * Now we can update the transactions related to this journal.
- */
$amount = floatval($data['amount']);
/** @var \Transaction $transaction */
foreach ($model->transactions()->get() as $transaction) {
@@ -164,109 +162,29 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
if (!isset($model['what'])) {
$errors->add('description', 'Internal error: need to know type of transaction!');
}
- /*
- * Amount
- */
- if (isset($model['amount']) && floatval($model['amount']) < 0.01) {
- $errors->add('amount', 'Amount must be > 0.01');
- } else {
- if (!isset($model['amount'])) {
- $errors->add('amount', 'Amount must be set!');
- } else {
- $successes->add('amount', 'OK');
+ if (strlen($model['description']) == 0) {
+ $errors->add('description', 'The description field is required.');
+ }
+ $errors = $errors->merge($this->_validateAmount($model));
+ $errors = $errors->merge($this->_validateBudget($model));
+ $errors = $errors->merge($this->_validateAccount($model));
+
+ $list = ['date', 'description', 'amount', 'budget_id', 'from', 'to', 'account_from_id', 'account_to_id', 'category', 'account_id', 'expense_account',
+ 'revenue_account'];
+ foreach ($list as $entry) {
+ if (!$errors->has($entry)) {
+ $successes->add($entry, 'OK');
}
}
- /*
- * Budget
- */
- if (isset($model['budget_id']) && !ctype_digit($model['budget_id'])) {
- $errors->add('budget_id', 'Invalid budget');
- } else {
- $successes->add('budget_id', 'OK');
- }
-
- $successes->add('category', 'OK');
-
- /*
- * Many checks to catch invalid or not-existing accounts.
- */
- switch (true) {
- // this combination is often seen in withdrawals.
- case (isset($model['account_id']) && isset($model['expense_account'])):
- if (intval($model['account_id']) < 1) {
- $errors->add('account_id', 'Invalid account.');
- } else {
- $successes->add('account_id', 'OK');
- }
- $successes->add('expense_account', 'OK');
- break;
- case (isset($model['account_id']) && isset($model['revenue_account'])):
- if (intval($model['account_id']) < 1) {
- $errors->add('account_id', 'Invalid account.');
- } else {
- $successes->add('account_id', 'OK');
- }
- $successes->add('revenue_account', 'OK');
- break;
- case (isset($model['account_from_id']) && isset($model['account_to_id'])):
- if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
- $errors->add('account_from_id', 'Invalid account selected.');
- $errors->add('account_to_id', 'Invalid account selected.');
-
- } else {
- if (intval($model['account_from_id']) == intval($model['account_to_id'])) {
- $errors->add('account_to_id', 'Cannot be the same as "from" account.');
- $errors->add('account_from_id', 'Cannot be the same as "to" account.');
- } else {
- $successes->add('account_from_id', 'OK');
- $successes->add('account_to_id', 'OK');
- }
- }
- break;
-
- case (isset($model['to']) && isset($model['from'])):
- if (is_object($model['to']) && is_object($model['from'])) {
- $successes->add('from', 'OK');
- $successes->add('to', 'OK');
- }
- break;
-
- default:
- throw new FireflyException('Cannot validate accounts for transaction journal.');
- break;
- }
-
-
- /*
- * Add "OK"
- */
- if (!$errors->has('description')) {
- $successes->add('description', 'OK');
- }
- if (!$errors->has('date')) {
- $successes->add('date', 'OK');
- }
-
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
}
/**
- * @param $currency
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*
- * @return null|\TransactionCurrency
- */
- public function getJournalCurrency($currency)
- {
- /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
- $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
-
- return $currencyRepository->findByCode($currency);
- }
-
- /**
* @param array $data
*
* @return array
@@ -377,25 +295,133 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return $typeRepository->findByWhat($type);
}
+ /**
+ * @param int $currencyId
+ *
+ * @return null|\TransactionCurrency
+ */
+ public function getJournalCurrencyById($currencyId)
+ {
+ /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
+ $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
+
+ return $currencyRepository->find($currencyId);
+ }
+
+ /**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
+ * @param array $model
+ *
+ * @return MessageBag
+ */
+ protected function _validateAmount(array $model)
+ {
+ $errors = new MessageBag;
+ if (isset($model['amount']) && floatval($model['amount']) < 0.01) {
+ $errors->add('amount', 'Amount must be > 0.01');
+ } else {
+ if (!isset($model['amount'])) {
+ $errors->add('amount', 'Amount must be set!');
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
+ * @param array $model
+ *
+ * @return MessageBag
+ */
+ protected function _validateBudget(array $model)
+ {
+ /*
+ * Budget (is not in rules)
+ */
+ $errors = new MessageBag;
+ if (isset($model['budget_id']) && !ctype_digit($model['budget_id'])) {
+ $errors->add('budget_id', 'Invalid budget');
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
+ * @param array $model
+ *
+ * @return MessageBag
+ * @throws FireflyException
+ */
+ protected function _validateAccount(array $model)
+ {
+ $errors = new MessageBag;
+ switch (true) {
+ // this combination is often seen in withdrawals.
+ case (isset($model['account_id']) && isset($model['expense_account'])):
+ if (intval($model['account_id']) < 1) {
+ $errors->add('account_id', 'Invalid account.');
+ }
+ break;
+ // often seen in deposits
+ case (isset($model['account_id']) && isset($model['revenue_account'])):
+ if (intval($model['account_id']) < 1) {
+ $errors->add('account_id', 'Invalid account.');
+ }
+ break;
+ // often seen in transfers
+ case (isset($model['account_from_id']) && isset($model['account_to_id'])):
+ if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
+ $errors->add('account_from_id', 'Invalid account selected.');
+ $errors->add('account_to_id', 'Invalid account selected.');
+
+ } else {
+ if (intval($model['account_from_id']) == intval($model['account_to_id'])) {
+ $errors->add('account_to_id', 'Cannot be the same as "from" account.');
+ $errors->add('account_from_id', 'Cannot be the same as "to" account.');
+ }
+ }
+ break;
+ case (isset($model['from']) && isset($model['to'])):
+ break;
+ default:
+ throw new FireflyException('Cannot validate accounts for transaction journal.');
+ break;
+ }
+
+ return $errors;
+ }
+
/**
* Returns an object with id $id.
*
* @param int $objectId
*
+ * @codeCoverageIgnore
+ * @throws NotImplementedException
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @return \Eloquent
*/
public function find($objectId)
{
- return $this->getUser()->transactionjournals()->find($objectId);
+ throw new NotImplementedException;
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
*
* @return \AccountType|null
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function findByWhat($what)
{
@@ -406,11 +432,11 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
* Returns all objects.
*
* @return Collection
+ * @codeCoverageIgnore
*/
public function get()
{
- return $this->getUser()->transactionjournals()->with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accountType'])
- ->get();
+ throw new NotImplementedException;
}
/**
@@ -444,17 +470,6 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return $this->getUser()->transactionjournals()->orderBy('date', 'ASC')->first();
}
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function getInDateRange(Carbon $start, Carbon $end)
- {
- return $this->getuser()->transactionjournals()->withRelevantData()->before($end)->after($start)->get();
- }
-
/**
* @param Carbon $date
*
@@ -539,6 +554,19 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return $query;
}
+ /**
+ * @param $currency
+ *
+ * @return null|\TransactionCurrency
+ */
+ public function getJournalCurrency($currency)
+ {
+ /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
+ $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
+
+ return $currencyRepository->findByCode($currency);
+ }
+
/**
* @param int $limit
*
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournalInterface.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournalInterface.php
index 0268d53d81..264aeb5200 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournalInterface.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournalInterface.php
@@ -19,14 +19,6 @@ interface TransactionJournalInterface
*/
public function first();
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function getInDateRange(Carbon $start, Carbon $end);
-
/**
* @param Carbon $date
*
diff --git a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
index b3b5191de4..cd202a3c2d 100644
--- a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
+++ b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
@@ -20,10 +20,13 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
{
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function destroy(Eloquent $model)
{
@@ -31,10 +34,13 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $data
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function store(array $data)
{
@@ -42,11 +48,14 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
* @param array $data
*
* @return bool
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function update(Eloquent $model, array $data)
{
@@ -54,6 +63,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Validates an array. Returns an array containing MessageBags
* errors/warnings/successes.
*
@@ -61,6 +72,7 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
*
* @return array
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function validate(array $model)
{
@@ -68,12 +80,15 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
*
* @return \Eloquent
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function find($objectId)
{
@@ -96,17 +111,21 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
'withdrawal' => 'Withdrawal',
'deposit' => 'Deposit',
];
- if(!isset($translation[$what])) {
+ if (!isset($translation[$what])) {
throw new FireflyException('Cannot find transaction type described as "' . e($what) . '".');
}
+
return \TransactionType::whereType($translation[$what])->first();
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function get()
{
@@ -114,10 +133,13 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
* @throws NotImplementedException
+ * @codeCoverageIgnore
*/
public function getByIds(array $ids)
{
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index 5c1960a170..9273f5c600 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -34,6 +34,8 @@ class PiggyBank
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \TransactionJournal $journal
*
* @throws \FireflyIII\Exception\FireflyException
@@ -109,6 +111,8 @@ class PiggyBank
*/
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \TransactionJournal $journal
* @param int $piggyBankId
*/
@@ -176,6 +180,8 @@ class PiggyBank
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's 6. More than 5 but alright.
+ *
* Validates the presence of repetitions for all repeated expenses!
*/
public function validateRepeatedExpenses()
@@ -185,32 +191,24 @@ class PiggyBank
}
/** @var \FireflyIII\Database\PiggyBank\RepeatedExpense $repository */
$repository = \App::make('FireflyIII\Database\PiggyBank\RepeatedExpense');
-
$list = $repository->get();
$today = Carbon::now();
-
/** @var \PiggyBank $entry */
foreach ($list as $entry) {
- $start = $entry->startdate;
- $target = $entry->targetdate;
- // find a repetition on this date:
- $count = $entry->piggyBankrepetitions()->starts($start)->targets($target)->count();
+ $count = $entry->piggyBankrepetitions()->starts($entry->startdate)->targets($entry->targetdate)->count();
if ($count == 0) {
$repetition = new \PiggyBankRepetition;
$repetition->piggyBank()->associate($entry);
- $repetition->startdate = $start;
- $repetition->targetdate = $target;
+ $repetition->startdate = $entry->startdate;
+ $repetition->targetdate = $entry->targetdate;
$repetition->currentamount = 0;
$repetition->save();
}
- // then continue and do something in the current relevant time frame.
-
- $currentTarget = clone $target;
+ $currentTarget = clone $entry->startdate;
$currentStart = null;
while ($currentTarget < $today) {
$currentStart = \DateKit::subtractPeriod($currentTarget, $entry->rep_length, 0);
$currentTarget = \DateKit::addPeriod($currentTarget, $entry->rep_length, 0);
- // create if not exists:
$count = $entry->piggyBankRepetitions()->starts($currentStart)->targets($currentTarget)->count();
if ($count == 0) {
$repetition = new \PiggyBankRepetition;
diff --git a/app/lib/FireflyIII/FF3ServiceProvider.php b/app/lib/FireflyIII/FF3ServiceProvider.php
index 879313a2d2..5940441dda 100644
--- a/app/lib/FireflyIII/FF3ServiceProvider.php
+++ b/app/lib/FireflyIII/FF3ServiceProvider.php
@@ -32,6 +32,7 @@ class FF3ServiceProvider extends ServiceProvider
/**
* Return the services bla bla.
*
+ * @CodeCoverageIgnore
* @return array
*/
public function provides()
diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php
index 68409ab2df..59a28f7828 100644
--- a/app/lib/FireflyIII/Form/Form.php
+++ b/app/lib/FireflyIII/Form/Form.php
@@ -24,169 +24,15 @@ class Form
*/
public static function ffAmount($name, $value = null, array $options = [])
{
+ $label = self::label($name, $options);
+ $options = self::expandOptionArray($name, $label, $options);
+ $classes = self::getHolderClasses($name);
+ $value = self::fillFieldValue($name, $value);
$options['step'] = 'any';
$options['min'] = '0.01';
-
- return self::ffInput('amount', $name, $value, $options);
-
- }
-
- /**
- * @param $type
- * @param $name
- * @param null $value
- * @param array $options
- * @param array $list
- *
- * @return string
- * @throws FireflyException
- */
- public static function ffInput($type, $name, $value = null, array $options = [], $list = [])
- {
- /*
- * add some defaults to this method:
- */
- $options['class'] = 'form-control';
- $options['id'] = 'ffInput_' . $name;
- $options['autocomplete'] = 'off';
- $label = self::label($name, $options);
-
- /*
- * Make label and placeholder look nice.
- */
- $options['placeholder'] = ucfirst($name);
-
- /*
- * Get pre filled value:
- */
- if (\Session::has('preFilled')) {
- $preFilled = \Session::get('preFilled');
- $value = isset($preFilled[$name]) && is_null($value) ? $preFilled[$name] : $value;
-
- }
-
- /*
- * Get the value.
- */
- if (!is_null(\Input::old($name))) {
- /*
- * Old value overrules $value.
- */
- $value = \Input::old($name);
- }
-
- /*
- * Get errors, warnings and successes from session:
- */
- /** @var MessageBag $errors */
- $errors = \Session::get('errors');
-
- /** @var MessageBag $warnings */
- $warnings = \Session::get('warnings');
-
- /** @var MessageBag $successes */
- $successes = \Session::get('successes');
-
-
- /*
- * If errors, add some more classes.
- */
- switch (true) {
- case (!is_null($errors) && $errors->has($name)):
- $classes = 'form-group has-error has-feedback';
- break;
- case (!is_null($warnings) && $warnings->has($name)):
- $classes = 'form-group has-warning has-feedback';
- break;
- case (!is_null($successes) && $successes->has($name)):
- $classes = 'form-group has-success has-feedback';
- break;
- default:
- $classes = 'form-group';
- break;
- }
-
- /*
- * Add some HTML.
- */
- $html = '' . e($errors->first($name)) . '
'; - } - } - unset($errors); - /* - * If warnings, respond to them: - */ - - if (!is_null($warnings)) { - if ($warnings->has($name)) { - $html .= ''; - $html .= '' . e($warnings->first($name)) . '
'; - } - } - unset($warnings); - - /* - * If successes, respond to them: - */ - - if (!is_null($successes)) { - if ($successes->has($name)) { - $html .= ''; - $html .= '' . e($successes->first($name)) . '
'; - } - } - unset($successes); - - $html .= '