From dbe2df3cb5f8f843c124a086eeab96c132382f22 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sat, 18 Jan 2020 13:00:15 +0300 Subject: [PATCH 1/3] model caching --- app/Abstracts/Model.php | 3 +- composer.json | 1 + composer.lock | 412 +++++++++++++++++++++++-------- config/laravel-model-caching.php | 13 + 4 files changed, 324 insertions(+), 105 deletions(-) create mode 100644 config/laravel-model-caching.php diff --git a/app/Abstracts/Model.php b/app/Abstracts/Model.php index 3e555cbbd..6919e828f 100644 --- a/app/Abstracts/Model.php +++ b/app/Abstracts/Model.php @@ -5,12 +5,13 @@ namespace App\Abstracts; use App\Scopes\Company; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Eloquent\SoftDeletes; +use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Kyslik\ColumnSortable\Sortable; use Lorisleiva\LaravelSearchString\Concerns\SearchString; abstract class Model extends Eloquent { - use SearchString, SoftDeletes, Sortable; + use Cachable, SearchString, SoftDeletes, Sortable; protected $dates = ['deleted_at']; diff --git a/composer.json b/composer.json index def723201..ffafdd888 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "dingo/api": "2.4.*", "doctrine/dbal": "2.9.*", "fideloper/proxy": "4.2.*", + "genealabs/laravel-model-caching": "0.7.*", "guzzlehttp/guzzle": "6.5.*", "intervention/image": "2.5.*", "jenssegers/date": "3.5.*", diff --git a/composer.lock b/composer.lock index ec85e062d..911b7b2dd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1833d7d2fe4dd91486f71b8f08ffb15d", + "content-hash": "da7fd36fd1e0ebe5d9534e3db6ce40d5", "packages": [ { "name": "akaunting/firewall", - "version": "1.2.5", + "version": "1.2.6", "source": { "type": "git", "url": "https://github.com/akaunting/firewall.git", - "reference": "924529c4ae1db454745aa59a2731679e8ff287b8" + "reference": "b6a3850cd2accaafd142f2d05e7a2f56b06454fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/akaunting/firewall/zipball/924529c4ae1db454745aa59a2731679e8ff287b8", - "reference": "924529c4ae1db454745aa59a2731679e8ff287b8", + "url": "https://api.github.com/repos/akaunting/firewall/zipball/b6a3850cd2accaafd142f2d05e7a2f56b06454fb", + "reference": "b6a3850cd2accaafd142f2d05e7a2f56b06454fb", "shasum": "" }, "require": { @@ -67,7 +67,7 @@ "waf", "xss" ], - "time": "2020-01-04T18:36:44+00:00" + "time": "2020-01-16T23:50:11+00:00" }, { "name": "akaunting/language", @@ -784,16 +784,16 @@ }, { "name": "composer/ca-bundle", - "version": "1.2.5", + "version": "1.2.6", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "62e8fc2dc550e5d6d8c9360c7721662670f58149" + "reference": "47fe531de31fca4a1b997f87308e7d7804348f7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/62e8fc2dc550e5d6d8c9360c7721662670f58149", - "reference": "62e8fc2dc550e5d6d8c9360c7721662670f58149", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/47fe531de31fca4a1b997f87308e7d7804348f7e", + "reference": "47fe531de31fca4a1b997f87308e7d7804348f7e", "shasum": "" }, "require": { @@ -836,20 +836,20 @@ "ssl", "tls" ], - "time": "2019-12-11T14:44:42+00:00" + "time": "2020-01-13T10:02:55+00:00" }, { "name": "composer/composer", - "version": "1.9.1", + "version": "1.9.2", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "bb01f2180df87ce7992b8331a68904f80439dd2f" + "reference": "7a04aa0201ddaa0b3cf64d41022bd8cdcd7fafeb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/bb01f2180df87ce7992b8331a68904f80439dd2f", - "reference": "bb01f2180df87ce7992b8331a68904f80439dd2f", + "url": "https://api.github.com/repos/composer/composer/zipball/7a04aa0201ddaa0b3cf64d41022bd8cdcd7fafeb", + "reference": "7a04aa0201ddaa0b3cf64d41022bd8cdcd7fafeb", "shasum": "" }, "require": { @@ -916,28 +916,27 @@ "dependency", "package" ], - "time": "2019-11-01T16:20:17+00:00" + "time": "2020-01-14T15:30:32+00:00" }, { "name": "composer/semver", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "46d9139568ccb8d9e7cdd4539cab7347568a5e2e" + "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/46d9139568ccb8d9e7cdd4539cab7347568a5e2e", - "reference": "46d9139568ccb8d9e7cdd4539cab7347568a5e2e", + "url": "https://api.github.com/repos/composer/semver/zipball/c6bea70230ef4dd483e6bbcab6005f682ed3a8de", + "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.5 || ^5.0.5", - "phpunit/phpunit-mock-objects": "2.3.0 || ^3.0" + "phpunit/phpunit": "^4.5 || ^5.0.5" }, "type": "library", "extra": { @@ -978,7 +977,7 @@ "validation", "versioning" ], - "time": "2019-03-19T17:25:45+00:00" + "time": "2020-01-13T12:06:48+00:00" }, { "name": "composer/spdx-licenses", @@ -1979,16 +1978,16 @@ }, { "name": "egulias/email-validator", - "version": "2.1.13", + "version": "2.1.14", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "834593d5900615639208417760ba6a17299e2497" + "reference": "c4b8d12921999d8a561004371701dbc2e05b5ece" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/834593d5900615639208417760ba6a17299e2497", - "reference": "834593d5900615639208417760ba6a17299e2497", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/c4b8d12921999d8a561004371701dbc2e05b5ece", + "reference": "c4b8d12921999d8a561004371701dbc2e05b5ece", "shasum": "" }, "require": { @@ -2032,53 +2031,7 @@ "validation", "validator" ], - "time": "2019-12-30T08:14:25+00:00" - }, - { - "name": "erusev/parsedown", - "version": "1.7.4", - "source": { - "type": "git", - "url": "https://github.com/erusev/parsedown.git", - "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3", - "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35" - }, - "type": "library", - "autoload": { - "psr-0": { - "Parsedown": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Emanuil Rusev", - "email": "hello@erusev.com", - "homepage": "http://erusev.com" - } - ], - "description": "Parser for Markdown.", - "homepage": "http://parsedown.org", - "keywords": [ - "markdown", - "parser" - ], - "time": "2019-12-30T22:54:17+00:00" + "time": "2020-01-05T14:11:20+00:00" }, { "name": "fideloper/proxy", @@ -2134,6 +2087,120 @@ ], "time": "2019-12-20T13:11:11+00:00" }, + { + "name": "genealabs/laravel-model-caching", + "version": "0.7.4", + "source": { + "type": "git", + "url": "https://github.com/GeneaLabs/laravel-model-caching.git", + "reference": "aa0253e3a5a6dfc5482b68cb177f50a746c30661" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GeneaLabs/laravel-model-caching/zipball/aa0253e3a5a6dfc5482b68cb177f50a746c30661", + "reference": "aa0253e3a5a6dfc5482b68cb177f50a746c30661", + "shasum": "" + }, + "require": { + "genealabs/laravel-pivot-events": "^0.2.1", + "illuminate/cache": "^6.0", + "illuminate/config": "^6.0", + "illuminate/console": "^6.0", + "illuminate/container": "^6.0", + "illuminate/database": "^6.0", + "illuminate/http": "^6.0", + "illuminate/support": "^6.0" + }, + "require-dev": { + "fzaninotto/faker": "^1.4", + "mockery/mockery": "^1.3", + "orchestra/testbench": "^4.0", + "orchestra/testbench-browser-kit": "^4.0", + "php-coveralls/php-coveralls": "^2.2", + "phpmd/phpmd": "^2.7", + "phpunit/phpunit": "^8.0", + "predis/predis": "^1.1", + "sebastian/phpcpd": "^4.1", + "squizlabs/php_codesniffer": "^3.4", + "symfony/thanks": "^1.2" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "GeneaLabs\\LaravelModelCaching\\Providers\\Service" + ] + } + }, + "autoload": { + "psr-4": { + "GeneaLabs\\LaravelModelCaching\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike Bronner", + "email": "hello@genealabs.com" + } + ], + "description": "Automatic caching for Eloquent models.", + "time": "2019-12-22T19:33:20+00:00" + }, + { + "name": "genealabs/laravel-pivot-events", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/GeneaLabs/laravel-pivot-events.git", + "reference": "c31bc7cb6b89741d5d2f52284ddd6f22064e2ed0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GeneaLabs/laravel-pivot-events/zipball/c31bc7cb6b89741d5d2f52284ddd6f22064e2ed0", + "reference": "c31bc7cb6b89741d5d2f52284ddd6f22064e2ed0", + "shasum": "" + }, + "require": { + "illuminate/database": "^6.0", + "illuminate/support": "^6.0" + }, + "require-dev": { + "orchestra/testbench": "^4.0", + "symfony/thanks": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeneaLabs\\LaravelPivotEvents\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike Bronner", + "email": "hello@genealabs.com", + "homepage": "https://genealabs.com", + "role": "Developer" + } + ], + "description": "This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.", + "homepage": "https://github.com/fico7489/laravel-pivot", + "keywords": [ + "eloquent events", + "eloquent extra events", + "laravel BelongsToMany events", + "laravel pivot events", + "laravel sync events" + ], + "time": "2019-09-14T00:26:49+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.5.2", @@ -2888,26 +2955,27 @@ }, { "name": "laravel/framework", - "version": "v6.9.0", + "version": "v6.11.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "60610be97ca389fa4b959d4d13fb3690970d9fb7" + "reference": "17af23842c259edcfd8c5b9e6a7c86596e040034" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/60610be97ca389fa4b959d4d13fb3690970d9fb7", - "reference": "60610be97ca389fa4b959d4d13fb3690970d9fb7", + "url": "https://api.github.com/repos/laravel/framework/zipball/17af23842c259edcfd8c5b9e6a7c86596e040034", + "reference": "17af23842c259edcfd8c5b9e6a7c86596e040034", "shasum": "" }, "require": { "doctrine/inflector": "^1.1", "dragonmantank/cron-expression": "^2.0", "egulias/email-validator": "^2.1.10", - "erusev/parsedown": "^1.7", "ext-json": "*", "ext-mbstring": "*", "ext-openssl": "*", + "league/commonmark": "^1.1", + "league/commonmark-ext-table": "^2.1", "league/flysystem": "^1.0.8", "monolog/monolog": "^1.12|^2.0", "nesbot/carbon": "^2.0", @@ -2967,14 +3035,13 @@ "filp/whoops": "^2.4", "guzzlehttp/guzzle": "^6.3", "league/flysystem-cached-adapter": "^1.0", - "mockery/mockery": "^1.2.3", + "mockery/mockery": "^1.3.1", "moontoast/math": "^1.1", "orchestra/testbench-core": "^4.0", "pda/pheanstalk": "^4.0", - "phpunit/phpunit": "^8.3", + "phpunit/phpunit": "^8.4|^9.0", "predis/predis": "^1.1.1", - "symfony/cache": "^4.3", - "true/punycode": "^2.1" + "symfony/cache": "^4.3.4" }, "suggest": { "aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.0).", @@ -2992,6 +3059,7 @@ "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).", "moontoast/math": "Required to use ordered UUIDs (^1.1).", + "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", "pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).", @@ -3030,7 +3098,7 @@ "framework", "laravel" ], - "time": "2019-12-19T18:16:22+00:00" + "time": "2020-01-14T15:12:09+00:00" }, { "name": "laravel/tinker", @@ -3163,6 +3231,142 @@ "homepage": "https://laravelcollective.com", "time": "2019-10-02T00:37:39+00:00" }, + { + "name": "league/commonmark", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/commonmark.git", + "reference": "34cf4ddb3892c715ae785c880e6691d839cff88d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/34cf4ddb3892c715ae785c880e6691d839cff88d", + "reference": "34cf4ddb3892c715ae785c880e6691d839cff88d", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^7.1" + }, + "replace": { + "colinodell/commonmark-php": "*" + }, + "require-dev": { + "cebe/markdown": "~1.0", + "commonmark/commonmark.js": "0.29.1", + "erusev/parsedown": "~1.0", + "ext-json": "*", + "michelf/php-markdown": "~1.4", + "mikehaertl/php-shellcommand": "^1.4", + "phpstan/phpstan-shim": "^0.11.5", + "phpunit/phpunit": "^7.5", + "scrutinizer/ocular": "^1.5", + "symfony/finder": "^4.2" + }, + "suggest": { + "league/commonmark-extras": "Library of useful extensions including smart punctuation" + }, + "bin": [ + "bin/commonmark" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "League\\CommonMark\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "PHP Markdown parser based on the CommonMark spec", + "homepage": "https://commonmark.thephpleague.com", + "keywords": [ + "commonmark", + "markdown", + "parser" + ], + "time": "2020-01-16T01:18:13+00:00" + }, + { + "name": "league/commonmark-ext-table", + "version": "v2.1.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/commonmark-ext-table.git", + "reference": "3228888ea69636e855efcf6636ff8e6316933fe7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/commonmark-ext-table/zipball/3228888ea69636e855efcf6636ff8e6316933fe7", + "reference": "3228888ea69636e855efcf6636ff8e6316933fe7", + "shasum": "" + }, + "require": { + "league/commonmark": "~0.19.3|^1.0", + "php": "^7.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.14", + "phpstan/phpstan": "~0.11", + "phpunit/phpunit": "^7.0|^8.0", + "symfony/var-dumper": "^4.0", + "vimeo/psalm": "^3.0" + }, + "type": "commonmark-extension", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-4": { + "League\\CommonMark\\Ext\\Table\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Martin HasoĊˆ", + "email": "martin.hason@gmail.com" + }, + { + "name": "Webuni s.r.o.", + "homepage": "https://www.webuni.cz" + }, + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com" + } + ], + "description": "Table extension for league/commonmark", + "homepage": "https://github.com/thephpleague/commonmark-ext-table", + "keywords": [ + "commonmark", + "extension", + "markdown", + "table" + ], + "time": "2019-09-26T13:28:33+00:00" + }, { "name": "league/flysystem", "version": "1.0.63", @@ -5121,16 +5325,16 @@ }, { "name": "seld/phar-utils", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/Seldaek/phar-utils.git", - "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a" + "reference": "84715761c35808076b00908a20317a3a8a67d17e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/phar-utils/zipball/7009b5139491975ef6486545a39f3e6dad5ac30a", - "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a", + "url": "https://api.github.com/repos/Seldaek/phar-utils/zipball/84715761c35808076b00908a20317a3a8a67d17e", + "reference": "84715761c35808076b00908a20317a3a8a67d17e", "shasum": "" }, "require": { @@ -5161,7 +5365,7 @@ "keywords": [ "phra" ], - "time": "2015-10-13T18:44:15+00:00" + "time": "2020-01-13T10:41:09+00:00" }, { "name": "simshaun/recurr", @@ -7240,16 +7444,16 @@ }, { "name": "filp/whoops", - "version": "2.7.0", + "version": "2.7.1", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5" + "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/4c97f814aa2f0dd4d5bedc89181c10ef12c004c5", - "reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5", + "url": "https://api.github.com/repos/filp/whoops/zipball/fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130", + "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130", "shasum": "" }, "require": { @@ -7297,7 +7501,7 @@ "throwable", "whoops" ], - "time": "2019-12-29T10:00:00+00:00" + "time": "2020-01-15T10:00:00+00:00" }, { "name": "fzaninotto/faker", @@ -7464,16 +7668,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.4", + "version": "1.9.5", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "579bb7356d91f9456ccd505f24ca8b667966a0a7" + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/579bb7356d91f9456ccd505f24ca8b667966a0a7", - "reference": "579bb7356d91f9456ccd505f24ca8b667966a0a7", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef", + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef", "shasum": "" }, "require": { @@ -7508,7 +7712,7 @@ "object", "object graph" ], - "time": "2019-12-15T19:12:40+00:00" + "time": "2020-01-17T21:11:47+00:00" }, { "name": "nunomaduro/collision", @@ -7993,16 +8197,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.1", + "version": "8.5.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2" + "reference": "018b6ac3c8ab20916db85fa91bf6465acb64d1e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7870c78da3c5e4883eaef36ae47853ebb3cb86f2", - "reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/018b6ac3c8ab20916db85fa91bf6465acb64d1e0", + "reference": "018b6ac3c8ab20916db85fa91bf6465acb64d1e0", "shasum": "" }, "require": { @@ -8072,7 +8276,7 @@ "testing", "xunit" ], - "time": "2019-12-25T14:49:39+00:00" + "time": "2020-01-08T08:49:49+00:00" }, { "name": "scrivo/highlight.php", diff --git a/config/laravel-model-caching.php b/config/laravel-model-caching.php new file mode 100644 index 000000000..44aab632f --- /dev/null +++ b/config/laravel-model-caching.php @@ -0,0 +1,13 @@ + env('MODEL_CACHE_PREFIX', 'model'), + + 'enabled' => env('MODEL_CACHE_ENABLED', true), + + 'use-database-keying' => env('MODEL_CACHE_USE_DATABASE_KEYING', true), + + 'store' => env('MODEL_CACHE_STORE', 'array'), + +]; From 78ede398f248f0f9332175b62eff1bd37c3499f0 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sat, 18 Jan 2020 13:03:07 +0300 Subject: [PATCH 2/3] styling --- app/Abstracts/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/Model.php b/app/Abstracts/Model.php index 6919e828f..1f1779c5c 100644 --- a/app/Abstracts/Model.php +++ b/app/Abstracts/Model.php @@ -3,9 +3,9 @@ namespace App\Abstracts; use App\Scopes\Company; +use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Eloquent\SoftDeletes; -use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Kyslik\ColumnSortable\Sortable; use Lorisleiva\LaravelSearchString\Concerns\SearchString; From ead2256589e43cb6ad8032d54cf33ca79e93b9a3 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sat, 18 Jan 2020 13:11:19 +0300 Subject: [PATCH 3/3] updated reports --- app/Abstracts/Report.php | 4 +++- app/Http/Controllers/Common/Reports.php | 8 ++++---- app/Reports/ExpenseSummary.php | 4 ++-- app/Reports/IncomeExpenseSummary.php | 6 +++--- app/Reports/IncomeSummary.php | 4 ++-- app/Reports/ProfitLoss.php | 6 +++--- app/Reports/TaxSummary.php | 8 +++----- app/Utilities/Recurring.php | 9 +++++---- resources/views/common/reports/index.blade.php | 4 ++-- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 885680b23..5bf8617d1 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -7,7 +7,9 @@ use App\Events\Common\ReportFilterApplying; use App\Events\Common\ReportGroupApplying; use App\Events\Common\ReportGroupShowing; use App\Exports\Common\Reports as Export; +use App\Models\Banking\Transaction; use App\Models\Common\Report as Model; +use App\Models\Sale\Invoice; use App\Traits\Charts; use App\Traits\DateTime; use App\Utilities\Chartjs; @@ -317,7 +319,7 @@ abstract class Report $this->totals[$table][$date] += $amount; } else { - $type = (($item->getTable() == 'invoices') || (($item->getTable() == 'transactions') && ($item->type == 'income'))) ? 'income' : 'expense'; + $type = (($item instanceof Invoice) || (($item instanceof Transaction) && ($item->type == 'income'))) ? 'income' : 'expense'; if ($type == 'income') { $this->rows[$table][$item->$id_field][$date] += $amount; diff --git a/app/Http/Controllers/Common/Reports.php b/app/Http/Controllers/Common/Reports.php index e85805e51..a5052ed27 100644 --- a/app/Http/Controllers/Common/Reports.php +++ b/app/Http/Controllers/Common/Reports.php @@ -19,7 +19,7 @@ class Reports extends Controller */ public function index() { - $classes = $categories = []; + $totals = $icons = $categories = []; $reports = Report::all(); @@ -30,12 +30,12 @@ class Reports extends Controller $class = Utility::getClassInstance($report); - $classes[$report->id] = $class; - + $totals[$report->id] = $class->getTotal(); + $icons[$report->id] = $class->getIcon(); $categories[$class->getCategory()][] = $report; } - return view('common.reports.index', compact('categories', 'classes')); + return view('common.reports.index', compact('categories', 'totals', 'icons')); } /** diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index ab3343cd8..9d756284b 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -41,11 +41,11 @@ class ExpenseSummary extends Report default: // Bills $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); - Recurring::reflect($bills, 'bill', 'billed_at'); + Recurring::reflect($bills, 'billed_at'); $this->setTotals($bills, 'billed_at'); // Payments - Recurring::reflect($payments, 'payment', 'paid_at'); + Recurring::reflect($payments, 'paid_at'); $this->setTotals($payments, 'paid_at'); break; diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 1996ce070..ace5fb31f 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -31,11 +31,11 @@ class IncomeExpenseSummary extends Report default: // Invoices $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); - Recurring::reflect($invoices, 'invoice', 'invoiced_at'); + Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at', true); // Income Transactions - Recurring::reflect($income_transactions, 'transaction', 'paid_at'); + Recurring::reflect($income_transactions, 'paid_at'); $this->setTotals($income_transactions, 'paid_at', true); // Bills @@ -44,7 +44,7 @@ class IncomeExpenseSummary extends Report $this->setTotals($bills, 'billed_at', true); // Expense Transactions - Recurring::reflect($expense_transactions, 'transaction', 'paid_at'); + Recurring::reflect($expense_transactions, 'paid_at'); $this->setTotals($expense_transactions, 'paid_at', true); break; diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index 8c0c60e1e..8cfa4c899 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -41,11 +41,11 @@ class IncomeSummary extends Report default: // Invoices $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); - Recurring::reflect($invoices, 'invoice', 'invoiced_at'); + Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at'); // Transactions - Recurring::reflect($transactions, 'transaction', 'paid_at'); + Recurring::reflect($transactions, 'paid_at'); $this->setTotals($transactions, 'paid_at'); break; diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index fc5767893..89c43e152 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -79,11 +79,11 @@ class ProfitLoss extends Report default: // Invoices $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); - Recurring::reflect($invoices, 'invoice', 'invoiced_at'); + Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at', true, $this->tables['income']); // Income Transactions - Recurring::reflect($income_transactions, 'transaction', 'paid_at'); + Recurring::reflect($income_transactions, 'paid_at'); $this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']); // Bills @@ -92,7 +92,7 @@ class ProfitLoss extends Report $this->setTotals($bills, 'billed_at', true, $this->tables['expense']); // Expense Transactions - Recurring::reflect($expense_transactions, 'transaction', 'paid_at'); + Recurring::reflect($expense_transactions, 'paid_at'); $this->setTotals($expense_transactions, 'paid_at', true, $this->tables['expense']); break; diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 8fdf3b0d3..547df5783 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -62,12 +62,12 @@ class TaxSummary extends Report default: // Invoices $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); - Recurring::reflect($invoices, 'invoice', 'invoiced_at'); + Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at'); // Bills $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); - Recurring::reflect($bills, 'bill', 'billed_at'); + Recurring::reflect($bills, 'billed_at'); $this->setTotals($bills, 'billed_at'); break; @@ -80,7 +80,7 @@ class TaxSummary extends Report // Make groups extensible $item = $this->applyGroups($item); - $db_table = $item->getTable(); + $type = (($item instanceof Invoice) || (($item instanceof Transaction) && ($item->type == 'income'))) ? 'income' : 'expense'; $date = $this->getFormattedDate(Date::parse($item->$date_field)); @@ -97,8 +97,6 @@ class TaxSummary extends Report continue; } - $type = (($db_table == 'invoices') || (($db_table == 'transactions') && ($item->type == 'income'))) ? 'income' : 'expense'; - if (!isset($this->rows[$item_total->name][$type][$date]) || !isset($this->totals[$item_total->name][$date])) { diff --git a/app/Utilities/Recurring.php b/app/Utilities/Recurring.php index 94085ff93..1ddd772d3 100644 --- a/app/Utilities/Recurring.php +++ b/app/Utilities/Recurring.php @@ -2,12 +2,13 @@ namespace App\Utilities; +use App\Models\Purchase\Bill; +use App\Models\Sale\Invoice; use Date; class Recurring { - - public static function reflect(&$items, $type, $issued_date_field) + public static function reflect(&$items, $issued_date_field) { foreach ($items as $key => $item) { if (!$item->recurring || !empty($item->parent_id)) { @@ -30,7 +31,7 @@ class Recurring $start_date = Date::parse($start->format('Y-m-d')); - if (($type == 'invoice') || ($type == 'bill')) { + if (($item instanceof Invoice) || ($item instanceof Bill)) { // Days between invoiced/billed and due date $diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at)); @@ -45,4 +46,4 @@ class Recurring } } } -} \ No newline at end of file +} diff --git a/resources/views/common/reports/index.blade.php b/resources/views/common/reports/index.blade.php index c450dc1c7..97dbdfaf8 100644 --- a/resources/views/common/reports/index.blade.php +++ b/resources/views/common/reports/index.blade.php @@ -42,13 +42,13 @@