Skip to content

Commit

Permalink
Merge pull request #311 from jesusantguerrero/fix/round-1
Browse files Browse the repository at this point in the history
Fix/round 1
  • Loading branch information
jesusantguerrero authored Nov 1, 2023
2 parents 10fd79e + 77463fd commit 4c2206b
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 248 deletions.
6 changes: 1 addition & 5 deletions app/Console/Commands/MonthlyRollover.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace App\Console\Commands;

use App\Domains\AppCore\Models\Category;
use App\Domains\Budget\Data\BudgetReservedNames;
use App\Domains\Budget\Services\BudgetRolloverService;
use Illuminate\Console\Command;

use Illuminate\Support\Facades\DB;
use App\Domains\Budget\Services\BudgetRolloverService;

class MonthlyRollover extends Command
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Facades\Gate;
use Insane\Journal\Contracts\TransactionBulkDeletes;
use Insane\Journal\Models\Core\Transaction;
use Insane\Journal\Contracts\TransactionBulkDeletes;

class TransactionBulkDelete implements TransactionBulkDeletes
{
public function validate(User $user)
{
Gate::forUser($user)->authorize('bulk-delete', Transaction::class);
Gate::forUser($user)->authorize('deleteBulk', Transaction::class);
}

public function deleteAllDrafts(User $user)
Expand Down
5 changes: 5 additions & 0 deletions app/Domains/Journal/Policies/TransactionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function updateBulk(User $user)
return $user->current_team_id;
}

public function deleteBulk(User $user)
{
return $user->current_team_id;
}

public function delete(User $user, Transaction $transaction)
{
return $user->current_team_id == $transaction->team_id;
Expand Down
13 changes: 7 additions & 6 deletions app/Domains/Transaction/Services/BHDService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace App\Domains\Transaction\Services;

use Exception;
use Insane\Journal\Models\Core\Account;
use App\Domains\Integration\Actions\BHD;
use App\Domains\Automation\Models\Automation;
use App\Domains\Automation\Data\AutomationData;
use App\Domains\Transaction\Models\Transaction;
use App\Domains\Integration\Actions\GmailReceived;
use App\Domains\Automation\Enums\AutomationTaskType;
use App\Domains\Automation\Helpers\AutomationBuilder;
use App\Domains\Automation\Models\Automation;
use App\Domains\Integration\Actions\BHD;
use App\Domains\Integration\Actions\GmailReceived;
use App\Domains\Integration\Actions\TransactionCreateEntry;
use App\Domains\Transaction\Models\Transaction;
use Exception;
use Insane\Journal\Models\Core\Account;

class BHDService
{
Expand Down Expand Up @@ -49,6 +49,7 @@ public static function parseTypes($type)
'Compra' => 1,
'compra' => 1,
'retiro de efectivo' => 1,
"reserva de fondos (hold)" => 1
];

return $types[$type];
Expand Down
4 changes: 2 additions & 2 deletions app/Domains/Transaction/Services/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function revenueReport($teamId, $methodName = 'payments')
return $results;
}

public static function generateExpensesByPeriod($teamId, $startDate, $timeUnitDiff = 2, $timeUnit = 'month')
public static function generateExpensesByPeriod($teamId, $startDate, $timeUnitDiff = 2, $timeUnit = 'month', $categories = null)
{
$rangeEndAt = Carbon::createFromFormat('Y-m-d', $startDate)->endOfMonth()->format('Y-m-d');
$rangeStartAt = Carbon::now()->subMonth($timeUnitDiff)->startOfMonth()->format('Y-m-d');

$results = self::getExpensesByCategoriesInPeriod($teamId, $rangeStartAt, $rangeEndAt);
$results = self::getExpensesByCategoriesInPeriod($teamId, $rangeStartAt, $rangeEndAt, $categories);
$resultGroup = $results->groupBy('date');

return $resultGroup->map(function ($monthItems) {
Expand Down
11 changes: 9 additions & 2 deletions app/Domains/Transaction/Traits/TransactionLineTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ public function scopeExpenseCategories($query, array $categories = null)
$query->whereNot('categories.name', BudgetReservedNames::READY_TO_ASSIGN->value)
->join('categories', 'transaction_lines.category_id', '=', 'categories.id');

if ($categories) {
$query->whereIn('transaction_lines.category_id', $categories);
$categories = collect($categories);
$excluded = $categories->filter( fn ($id) => $id < 0)->all();
$included = $categories->filter( fn ($id) => $id > 0)->all();

if (count($excluded)) {
$query->whereNotIn('transaction_lines.category_id', $excluded);
}
if (count($included)) {
$query->whereIn('transaction_lines.category_id', $included);
}

return $query;
Expand Down
17 changes: 11 additions & 6 deletions app/Domains/Transaction/Traits/TransactionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Domains\Transaction\Traits;

use App\Domains\Budget\Data\BudgetReservedNames;
use Illuminate\Support\Facades\DB;
use Insane\Journal\Models\Core\Transaction;
use App\Domains\Budget\Data\BudgetReservedNames;

trait TransactionTrait
{
Expand Down Expand Up @@ -81,12 +81,17 @@ public function scopeCategories($query, array $categories)

public function scopeExpenseCategories($query, array $categories = null)
{
$query->whereNot('categories.name', BudgetReservedNames::READY_TO_ASSIGN->value)
->join('categories', 'transactions.category_id', '=', 'categories.id');
$categories = collect($categories);
$excluded = $categories->filter( fn ($id) => $id < 0)->map(fn ($id) => abs($id))->all();
$included = $categories->filter( fn ($id) => $id > 0)->all();

if ($categories) {
$query->whereIn('category_id', $categories);
}

$query->whereNot('categories.name', BudgetReservedNames::READY_TO_ASSIGN->value)
->join('categories', 'transactions.category_id', '=', 'categories.id')
->where(fn ($q) =>
$q->when(count($excluded),fn ($q) => $q->whereNotIn('categories.id', $excluded))
->when(count($included), fn ($q) => $q->whereIn('categories.id', $included))
);

return $query;
}
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Finance/FinanceTrendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ public function spendingYear()
$filters = isset($queryParams['filter']) ? $queryParams['filter'] : [];
[$startDate, $endDate] = $this->getFilterDates($filters);
$teamId = request()->user()->current_team_id;
$excludedAccounts = null;
if (isset($filters['category'])) {
$excludedAccounts = collect(explode(',', $filters['category']))->map(fn ($id) => "-$id")->all();
}

return [
'data' => ReportService::generateExpensesByPeriod($teamId, $startDate, 12),
'data' => ReportService::generateExpensesByPeriod($teamId, $startDate, 12, 'month', $excludedAccounts),
'metaData' => [
'name' => 'spendingYear',
'title' => 'Expenses',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function share(Request $request)
]);
},
'locale' => app()->getLocale(),
'settings' => $team ? $team->settings->mapWithKeys(fn ($setting) => [$setting['name'] => $setting['value']]) : [],
'accountDetailTypes' => AccountDetailType::all(),
'trialEndsAt' => $team ? $team->trial_ends_at : null,
'unreadNotifications' => function () use ($user) {
Expand Down
43 changes: 14 additions & 29 deletions app/Providers/JournalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,31 @@

namespace App\Providers;

use App\Domains\Journal\Actions\AccountCatalogCreate;
use Insane\Journal\Journal;
use Illuminate\Support\ServiceProvider;
use App\Domains\Journal\Actions\CategoryList;
use App\Domains\Journal\Actions\AccountCreate;
use App\Domains\Journal\Actions\AccountDelete;
use App\Domains\Journal\Actions\AccountDetailTypesCreate;
use App\Domains\Journal\Actions\AccountUpdate;
use App\Domains\Journal\Actions\TransactionList;
use App\Domains\Journal\Actions\TransactionShow;
use App\Domains\Journal\Actions\InvoicePaymentPay;
use App\Domains\Journal\Actions\TransactionCreate;
use App\Domains\Journal\Actions\TransactionDelete;
use App\Domains\Journal\Actions\TransactionUpdate;
use App\Domains\Journal\Actions\TransactionApprove;
use App\Domains\Journal\Actions\AccountCatalogCreate;
use App\Domains\Journal\Actions\AccountStatementList;
use App\Domains\Journal\Actions\AccountStatementShow;
use App\Domains\Journal\Actions\AccountUpdate;
use App\Domains\Journal\Actions\CategoryList;
use App\Domains\Journal\Actions\InvoicePaymentCreate;
use App\Domains\Journal\Actions\InvoicePaymentDelete;
use App\Domains\Journal\Actions\InvoicePaymentPay;
use App\Domains\Journal\Actions\TransactionApprove;
use App\Domains\Journal\Actions\TransactionBulkApprove;
use App\Domains\Journal\Actions\TransactionBulkDelete;
use App\Domains\Journal\Actions\TransactionBulkApprove;
use App\Domains\Journal\Actions\AccountDetailTypesCreate;
use App\Domains\Journal\Actions\TransactionCategoriesCreate;
use App\Domains\Journal\Actions\TransactionCreate;
use App\Domains\Journal\Actions\TransactionDelete;
use App\Domains\Journal\Actions\TransactionList;
use App\Domains\Journal\Actions\TransactionShow;
use App\Domains\Journal\Actions\TransactionUpdate;
use Illuminate\Support\ServiceProvider;
use Insane\Journal\Journal;

class JournalServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Journal::createAccountCatalogUsing(AccountCatalogCreate::class);
Expand Down
Loading

0 comments on commit 4c2206b

Please sign in to comment.