Skip to content

Commit

Permalink
Merge pull request #401 from jesusantguerrero/2.x
Browse files Browse the repository at this point in the history
2.x
  • Loading branch information
jesusantguerrero authored May 2, 2024
2 parents ac780b8 + da4754e commit 1861b51
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 295 deletions.
19 changes: 19 additions & 0 deletions app/Console/Commands/CheckOccurrence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Console\Commands;

use App\Models\Team;
use App\Jobs\RunTeamChecks;
use Illuminate\Console\Command;

class CheckOccurrence extends Command
{
protected $signature = 'app:check-occurrence {teamId}';
protected $description = 'check occurrence for a transaction in a team: test purposes';

public function handle()
{
$team = Team::find($this->argument('teamId'));
RunTeamChecks::dispatchSync($team->id);
}
}
128 changes: 0 additions & 128 deletions app/Domains/Budget/Services/RegisterOccurrence.php

This file was deleted.

28 changes: 15 additions & 13 deletions app/Domains/Housing/Actions/RegisterOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ private function softAdd(Occurrence $occurrence, $date) {
public function add(int $teamId, string $name, string $date)
{
$occurrence = Occurrence::byTeam($teamId)->byName($name)->first();
if ($occurrence && $occurrence->last_date !== $date) {
$this->softAdd($occurrence, $date);
$occurrence->save();
if ($occurrence) {
if ($occurrence->last_date->format('Y-m-d') !== $date) {
$this->softAdd($occurrence, $date);
$occurrence->save();
}
return;
}

Occurrence::create([
'name' => $name,
'team_id' => $teamId,
'last_date' => $date,
'previous_days_count' => 0,
'total_days' => 0,
'avg_days_passed' => 0,
'log' => [],
'name' => $name,
'team_id' => $teamId,
'last_date' => $date,
'previous_days_count' => 0,
'total_days' => 0,
'avg_days_passed' => 0,
'log' => [],
]);
}

Expand All @@ -58,8 +60,8 @@ public function remove(int $id, string $date = null)
$lastDate = $log[count($log) - 1];

$lastDuration = $previousLastDate ? $this->getDaysDifference($lastDate, $previousLastDate) : 0;
$totalDays = $occurrence->total_days - $occurrence->previous_days_count;
$occurrenceCount = $occurrence->occurrence_count - 1;
$occurrenceCount = count($occurrence->log);
$totalDays = $occurrenceCount > 1 ? $this->getDaysDifference($log[0], $lastDate) : $lastDuration;
$avg = $totalDays / $occurrenceCount;

$occurrence->update([
Expand All @@ -68,7 +70,7 @@ public function remove(int $id, string $date = null)
'total_days' => $totalDays,
'avg_days_passed' => $avg,
'occurrence_count' => $occurrenceCount,
'log' => json_encode($log),
'log' => $log,
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(Occurrence $occurrence)
$this->searchable = ['id', 'name'];
$this->includes = [];
$this->appends = [];
$this->resourceName = 'occurrence';
$this->resourceName = 'occurrences';
$this->authorizedTeam = true;
}

Expand Down
8 changes: 4 additions & 4 deletions app/Jobs/RunTeamChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Jobs;

use App\Domains\Housing\Actions\RegisterOccurrence;
use App\Domains\Housing\Models\Occurrence;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Domains\Housing\Models\Occurrence;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Domains\Housing\Actions\RegisterOccurrence;

class RunTeamChecks implements ShouldQueue
{
Expand Down
5 changes: 4 additions & 1 deletion app/Listeners/CheckOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Listeners;

use App\Jobs\RunTeamChecks;
use Insane\Journal\Models\Core\Transaction;
use Insane\Journal\Events\TransactionCreated;

class CheckOccurrence
Expand All @@ -16,6 +17,8 @@ class CheckOccurrence
public function handle(TransactionCreated $event)
{
$transaction = $event->transaction;
RunTeamChecks::dispatch($transaction->team_id);
if ($transaction->status == Transaction::STATUS_VERIFIED) {
RunTeamChecks::dispatch($transaction->team_id);
}
}
}
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ declare module 'vue' {
IMdiBankTransferOut: typeof import('~icons/mdi/bank-transfer-out')['default']
IMdiCallSplit: typeof import('~icons/mdi/call-split')['default']
IMdiCheck: typeof import('~icons/mdi/check')['default']
IMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
IMdiChevronLeft: typeof import('~icons/mdi/chevron-left')['default']
IMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
IMdiChevronUp: typeof import('~icons/mdi/chevron-up')['default']
IMdiClose: typeof import('~icons/mdi/close')['default']
IMdiEdit: typeof import('~icons/mdi/edit')['default']
IMdiEllipsisVertical: typeof import('~icons/mdi/ellipsis-vertical')['default']
Expand Down
4 changes: 0 additions & 4 deletions resources/js/Components/Modules/occurrence/models/index.ts

This file was deleted.

7 changes: 6 additions & 1 deletion resources/js/Components/OccurrenceCheckModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ const tabs = [{
multiple
/>
</section>
<OccurrencePreview v-if="activeTab == 'preview'" :occurrence-id="form.id" :conditions="form.conditions" />
<OccurrencePreview
v-if="activeTab == 'preview'"
:occurrence="formData"
:conditions="form.conditions"
:logs="form.logs"
/>
</section>
</article>

Expand Down
18 changes: 8 additions & 10 deletions resources/js/Components/OccurrencePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import LogerButton from './atoms/LogerButton.vue';
import { transactionDBToTransaction } from '@/domains/transactions';
import { router } from '@inertiajs/vue3';
import { IOccurrenceCheck } from '@/domains/housing/models';
const props = defineProps({
occurrenceId: {
type: Number
},
conditions: {
type: Array
}
})
const props = defineProps<{
occurrence: IOccurrenceCheck;
conditions: any[]
}>();
const transactions = ref([]);
const isCalled = ref(false);
onMounted(async () => {
if (props.occurrenceId && !isCalled.value) {
const data = await fetch(`/housing/occurrences/${props.occurrenceId}/preview`)
if (props.occurrence.id && !isCalled.value) {
const data = await fetch(`/housing/occurrences/${props.occurrence.id}/preview`)
transactions.value = await data.json()
isCalled.value = true
}
Expand Down Expand Up @@ -52,6 +49,7 @@ const load = () => {
:transactions="transactions"
:parser="transactionDBToTransaction"
/>
{{ occurrence }}
</section>
</article>
</template>
8 changes: 4 additions & 4 deletions resources/js/Pages/Dashboard/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WidgetContainer from "@/Components/WidgetContainer.vue";
import NextPaymentsWidget from "@/domains/transactions/components/NextPaymentsWidget.vue";
import MealWidget from "@/domains/meal/components/MealWidget.vue";
import AccountsTracker from "@/domains/transactions/components/AccountsTracker.vue";
import OccurrenceCard from "@/Components/Modules/occurrence/OccurrenceCard.vue";
import OccurrenceWidget from "@/domains/housing/components/OccurrenceWidget.vue";
import DashboardSpending from "./Partials/DashboardSpendings.vue";
import BudgetFundWidget from "./Partials/BudgetFundWidget.vue";
import BudgetWidget from "./Partials/BudgetWidget.vue";
Expand All @@ -20,10 +20,10 @@ import ConfirmationModal from "@/Components/atoms/ConfirmationModal.vue";
import LogerButton from "@/Components/atoms/LogerButton.vue";
import { useAppContextStore } from "@/store";
import { IOccurrenceCheck } from "@/Components/Modules/occurrence/models";
import { useTransactionStore } from "@/store/transactions";
import { IOccurrenceCheck } from "@/domains/housing/models";
import { IAccount, ICategory } from "@/domains/transactions/models";
import { IBudgetStat } from "@/domains/budget/models";
import { useTransactionStore } from "@/store/transactions";
withDefaults(
defineProps<{
Expand Down Expand Up @@ -139,7 +139,7 @@ const deleteBulkTransactions = () => {
<MealWidget :meals="meals?.data" />
</section>
<section class="py-6 space-y-4 md:w-3/12">
<OccurrenceCard :checks="checks" :wrap="true" />
<OccurrenceWidget :checks="checks" :wrap="true" />

<OnboardingSteps
v-if="onboarding.steps"
Expand Down
Loading

0 comments on commit 1861b51

Please sign in to comment.