Skip to content

Commit

Permalink
fix: set dates to budget transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero committed Sep 1, 2023
1 parent c00e5bb commit ebf4d76
Show file tree
Hide file tree
Showing 17 changed files with 577 additions and 42 deletions.
4 changes: 2 additions & 2 deletions app/Domains/Budget/Models/BudgetMovement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BudgetMovement extends Model
use HasFactory;
protected $fillable = ['team_id', 'user_id', 'source_category_id', 'destination_category_id', 'amount', 'date'];

public static function registerMovement($monthBudget, $form) {
public static function registerMovement(BudgetMonth $monthBudget, $form) {
DB::beginTransaction();
$session = [
'team_id' => $monthBudget->team_id,
Expand All @@ -38,7 +38,7 @@ public static function registerMovement($monthBudget, $form) {
'source_category_id' => $sourceId,
'destination_category_id' => $destinationId,
'amount' => $amount,
'date' => date('Y-m-d')
'date' => $form['date']
]);

$savedMovement = self::create($formData);
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Finance/BudgetCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Domains\Transaction\Models\Transaction;
use App\Domains\Transaction\Services\ReportService;
use App\Http\Resources\CategoryGroupCollection;
use App\Models\Setting;
use Freesgen\Atmosphere\Http\InertiaController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
Expand All @@ -32,11 +33,9 @@ public function __construct(Category $category)
];
$this->sorts = ['index'];
$this->includes = ['subCategories', 'subCategories.budget', 'subCategories.budgets'];
$dates = $this->getFilterDates();
$this->filters = [
'parent_id' => '$null',
'resource_type' => 'transactions',
'date' => "{$dates['0']}~{$dates['1']}",
];
$this->resourceName= "budgets";
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Finance/FinanceAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Finance;

use App\Domains\Transaction\Services\ReportService;
use App\Models\Setting;
use Freesgen\Atmosphere\Http\InertiaController;
use Freesgen\Atmosphere\Http\Querify;
use Illuminate\Support\Facades\Gate;
Expand Down Expand Up @@ -32,13 +33,13 @@ public function __construct(Account $account, ReportService $reportService)
public function show(Account $account) {
$queryParams = request()->query();
$response = Gate::inspect('show', $account);

$settings = Setting::getByTeam(auth()->user()->current_team_id);
if (!$response->allowed()) {
return redirect(route('finance'));
}

$filters = isset($queryParams['filter']) ? $queryParams['filter'] : [];
[$startDate, $endDate] = $this->getFilterDates($filters);
[$startDate, $endDate] = $this->getFilterDates($filters, $settings["team_timezone"]);

return inertia($this->templates['show'], [
"sectionTitle" => $account->name,
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/Finance/FinanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Domains\Transaction\Models\Transaction;
use App\Domains\Transaction\Services\PlannedTransactionService;
use App\Domains\Transaction\Services\TransactionService;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Laravel\Jetstream\Jetstream;
Expand All @@ -26,9 +27,11 @@ public function __construct(Transaction $transaction, private TransactionService

public function index(Request $request) {
$teamId = $request->user()->current_team_id;
$settings = Setting::getByTeam(auth()->user()->current_team_id);

$queryParams = $request->query();
$filters = isset($queryParams['filter']) ? $queryParams['filter'] : [];
[$startDate, $endDate] = $this->getFilterDates($filters);
[$startDate, $endDate] = $this->getFilterDates($filters, $settings['team_timezone']);

$lastMonthStartDate = Carbon::createFromFormat(self::DateFormat, $startDate)->subMonth()->startOfMonth()->format(self::DateFormat);
$lastMonthEndDate = Carbon::createFromFormat(self::DateFormat, $startDate)->subMonth()->endOfMonth()->format(self::DateFormat);
Expand Down
8 changes: 3 additions & 5 deletions app/Http/Controllers/Finance/FinanceTransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public function __construct(Transaction $transaction, private PlannedTransaction
'counterLine.account'
];
$this->appends = [];
$dates = $this->getFilterDates();
$this->filters = [
'date' => "{$dates['0']}~{$dates['1']}",
'status' => Transaction::STATUS_VERIFIED
];
}
Expand Down Expand Up @@ -67,14 +65,14 @@ protected function list(Request $request) {
transactions.description,
date,
transactions.direction,
transactions.status,
transactions.status,
total,
transactions.account_id,
counter_account_id,
payee_id,
categories.name category_name,
payees.name payee_name,
ca.name counter_account_name,
ca.name counter_account_name,
accounts.name account_name
")
->leftJoin('categories', 'categories.id', 'transactions.category_id')
Expand Down Expand Up @@ -178,7 +176,7 @@ private function getOptionParams() {
return $queryParams;
}


public function bulkDelete(Request $request)
{
$items = $request->post('data');
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/System/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
use App\Domains\Meal\Services\MealService;
use App\Domains\Transaction\Services\ReportService;
use App\Domains\Transaction\Services\TransactionService;
use App\Http\Controllers\Traits\HasEnrichedRequest;
use App\Http\Resources\PlannedMealResource;
use Carbon\Carbon;

class DashboardController {
use HasEnrichedRequest;

public function __construct(private MealService $mealService)
{

}

public function __invoke() {
$request = request();
$startDate = $request->query('startDate', Carbon::now()->startOfMonth()->format('Y-m-d'));
$endDate = $request->query('endDate', Carbon::now()->endOfMonth()->format('Y-m-d'));
[$startDate, $endDate] = $this->getFilterDates();
$team = $request->user()->currentTeam;
$teamId = $request->user()->current_team_id;
$budget = BudgetMonth::getMonthAssignmentTotal($teamId, $startDate);
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Traits/HasEnrichedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Traits;

use App\Models\Setting;
use Illuminate\Support\Carbon;

trait HasEnrichedRequest {
Expand All @@ -27,9 +28,10 @@ protected function getPostData() {
}

protected function getFilterDates($filters = [], $subCount=0) {
$settings = Setting::getByTeam(auth()->user()->current_team_id);
$dates = isset($filters['date']) ? explode("~", $filters['date']) : [
Carbon::now()->subMonths($subCount)->startOfMonth()->format('Y-m-d'),
Carbon::now()->endOfMonth()->format('Y-m-d')
Carbon::now()->setTimezone($settings["team_timezone"])->subMonths($subCount)->startOfMonth()->format('Y-m-d'),
Carbon::now()->setTimezone($settings["team_timezone"])->endOfMonth()->format('Y-m-d')
];
return $dates;
}
Expand Down
Loading

0 comments on commit ebf4d76

Please sign in to comment.