Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/do php #340

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/Console/Commands/FixLiabilitiesSpent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Console\Commands;

use DateTime;
use App\Models\Team;
use Illuminate\Console\Command;

use App\Domains\Transaction\Services\TransactionService;

class FixLiabilitiesSpent extends Command
{

protected $signature = 'app:fix-liabilities-spent {teamId}';


protected $description = 'change counter account for liability transactions';

public function handle(TransactionService $transactionService)
{

$transactions = $transactionService->getCreditCardSpentTransactions($this->argument('teamId'));
dd($transactions->sum('total'));
foreach ($transactions as $transaction) {
$transactions->id;
}
}
}
4 changes: 2 additions & 2 deletions app/Domains/AppCore/Policies/FinanceAccountPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class FinanceAccountPolicy
{
public function show(User $user, Account $account)
public function show(User $user)
{
return $user->current_team_id === $account->team_id
return $user->current_team_id
? Response::allow()
: Response::deny('You do not own this account.');
}
Expand Down
11 changes: 6 additions & 5 deletions app/Domains/Journal/Actions/AccountStatementShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Facades\Gate;
use Insane\Journal\Contracts\AccountStatementShows;
use Insane\Journal\Helpers\ReportHelper;
use Insane\Journal\Models\Core\Account;
use Insane\Journal\Helpers\ReportHelper;
use Insane\Journal\Contracts\AccountStatementShows;

class AccountStatementShow implements AccountStatementShows
{
public function show(User $user, string $reportName, ?int $accountId): array
{
$this->validate($user);
$filters= [
'account_id' => $accountId
];

return ReportHelper::getGeneralLedger($user->current_team_id, $reportName, [
'account_id' => $accountId,
]);
return ReportHelper::getGeneralLedger($user->current_team_id, $reportName, $filters);
}

public function validate(mixed $user)
Expand Down
34 changes: 33 additions & 1 deletion app/Domains/Transaction/Services/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public static function getNetWorth($teamId, $startDate, $endDate)
", [
'teamId' => $teamId,
'monthDate' => $endDate
// 'detailTypes' => implode(',', AccountDetailType::ALL)
]);
}

Expand Down Expand Up @@ -432,4 +431,37 @@ public static function getBareSplits($teamId, $options)
->whereBetween('date', [$options['startDate'], $options['endDate']])
->when(isset($options['limit']), fn ($query) => $query->limit($options['limit']));
}

public function getCreditCardSpentTransactions(int $teamId) {
return DB::table(DB::raw('categories g'))
->selectRaw('SUM(transaction_lines.amount * transaction_lines.type) as total,
accounts.id account_id,
date_format(transactions.date, "%Y-%m-01") as date,
accounts.display_id account_display_id,
accounts.name account_name,
accounts.alias account_alias,
categories.name,
categories.id,
categories.display_id,
categories.alias,
g.display_id groupName,
g.alias groupAlias,
MONTH(transactions.date) as months'
)
->groupByRaw('transactions.id')
->join('categories', 'g.id', '=', 'categories.parent_id')
->join('accounts', 'accounts.category_id', '=', 'categories.id')
->join('transaction_lines', 'transaction_lines.account_id', '=', 'accounts.id')
->join('transactions', fn ($q)=> $q->on('transactions.id', 'transaction_lines.transaction_id'))
->orderByRaw('g.index,categories.index, accounts.index,accounts.number')
->where(fn ($q) => $q->where([
'transactions.status' => Transaction::STATUS_VERIFIED,
'accounts.team_id' => $teamId
])->orWhereNull('transactions.status')
)
->where([
'g.display_id' => 'liabilities',
])
->get();
}
}
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare module 'vue' {
IMdiMinus: typeof import('~icons/mdi/minus')['default']
IMdiPencil: typeof import('~icons/mdi/pencil')['default']
IMdiPlus: typeof import('~icons/mdi/plus')['default']
IMdiPrinter: typeof import('~icons/mdi/printer')['default']
IMdiSearch: typeof import('~icons/mdi/search')['default']
IMdiSort: typeof import('~icons/mdi/sort')['default']
IMdiStar: typeof import('~icons/mdi/star')['default']
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"engines": {
"node": "^18.x"
"node": ">=18"
},
"scripts": {
"dev": "vite",
Expand Down
195 changes: 195 additions & 0 deletions resources/js/Pages/Journal/Accounts/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<script setup>
import { format as formatDate } from "date-fns";
import AppLayout from "@/Components/templates/AppLayout.vue";
import IconAdd from "@/Components/icons/IconAdd.vue";
import cols from "./cols";
import AccountModal from "@/Components/shared/AccountModal.vue";
import {
ElTabs,
ElTabPane,
ElDropdown,
ElDropdownItem,
ElDropdownMenu,
} from "element-plus";
import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
import { AtButton } from "atmosphere-ui";
import { onMounted, ref, computed } from "vue";

import AtTable from "@/Components/AtTable.vue";
import AppButton from "@/Components/shared/AppButton.vue";

import AccountingSectionNav from "../Partials/AccountingSectionNav.vue";

const props = defineProps({
accounts: {
type: Array,
},
categories: {
type: Array,
},
});

const selectedAccount = ref(null);
const searchText = ref("");
const activeName = ref([]);
const activeAccountSection = ref("");
const accountsCategories = ref([]);

onMounted(() => {
getAccounts();
});

const formatDateFilter = (date) => {
return formatDate(date, "YYYY-MM-DD");
};

const section = computed(() => {
return "accounts";
});

const mainCategories = computed(() => {
return props.categories.map((group) => {
group.name.replace(/[d]/i);
return group;
});
});

const getAccounts = () => {
accountsCategories.value = props.categories;
activeAccountSection.value =
mainCategories.value && mainCategories.value.length ? mainCategories.value[0].id : "";
};

const editAccount = () => {};

const rowClick = (command, service) => {
switch (command) {
case "edit":
editAccount(service);
break;
default:
break;
}
};

const isAccountModalOpen = ref(false);
const accountToEdit = ref({});
const openAccountModal = (account = {}) => {
accountToEdit.value = account;
isAccountModalOpen.value = true;
};
</script>

<template>
<AppLayout title="Cuentas">
<template #header>
<AccountingSectionNav>
<template #actions>
<AppButton @click="isAccountModalOpen = true" variant="inverse">
<IconAdd />
</AppButton>
</template>
</AccountingSectionNav>
</template>

<div class="w-full py-10 mx-auto sm:px-6 lg:px-8">
<div class="w-full px-5 py-5 bg-white rounded-md shadow-md">
<ElTabs v-model="activeAccountSection">
<ElTabPane
:label="`${category.alias || category.name} (${
category.subcategories.length
})`"
:title="`${category.alias || category.name} (${category.number})`"
:name="category.id"
v-for="category in mainCategories"
:key="category.id"
class="w-full bg-white"
>
<!-- subCategories -->
<template v-if="category.subcategories.length">
<Disclosure
v-for="subCategory in category.subcategories"
:key="subCategory.id"
>
<DisclosureButton
class="flex justify-between w-full px-4 py-2 text-sm font-medium text-left text-blue-900 bg-blue-100 hover:bg-blue-200 focus:outline-none focus-visible:ring focus-visible:ring-blue-500 focus-visible:ring-opacity-75"
v-slot="{ open }"
>
<span class="text-lg font-bold">
{{ subCategory.number }} - {{ subCategory.alias || subCategory.name }}
</span>

<i
class="fa fa-chevron-down"
:class="open ? 'transform rotate-180' : ''"
/>
</DisclosureButton>
<DisclosurePanel class="font-bold text-gray-500">
<!-- accounts -->
<AtTable
:cols="cols(' ')"
:tableData="subCategory.accounts"
:empty-text="'No hay cuentas en esta categoria'"
hide-headers
>
<template v-slot:name="{ scope: { row } }">
<div>
<div class="font-bold">{{ row.alias || row.name }}</div>
<div class="italic font-normal" v-if="row.last_transaction_date">
Last transaction on: {{ row.last_transaction_date.date }}
</div>
</div>
</template>
<template v-slot:actions="{ scope: { row } }">
<button @click="openAccountModal(row)">Edit</button>
</template>
</AtTable>
<!-- accounts -->
</DisclosurePanel>
</Disclosure>
</template>
<!-- subCategories -->
</ElTabPane>
</ElTabs>
</div>

<AccountModal
v-if="isAccountModalOpen"
:show="isAccountModalOpen"
:max-width="modalMaxWidth"
:form-data="accountToEdit"
@close="isAccountModalOpen = false"
/>
</div>
</AppLayout>
</template>

<style lang="scss" scoped>
.body-section {
background: white;
padding: 15px;
}

.el-table th {
font-weight: bolder;
color: #222 !important;
}

.section-actions {
display: flex;

.app-search__container {
width: 80%;
margin-right: 15px;
}

.action-buttons {
width: 20%;
display: flex;

button {
margin-left: auto;
}
}
}
</style>
28 changes: 28 additions & 0 deletions resources/js/Pages/Journal/Accounts/cols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default name => {
return [
{
label: name || "Account Name",
name: "display_id",
width: 200,
type: "custom",
render(row) {
return `${row.number} - ${row.alias || row.name}`
}
},
{
label: "",
name: "display_id",
width: 300
},
{
label: "",
name: "description"
},
{
label: "",
name: "actions",
width: 300,
type: "custom"
}
];
};
32 changes: 32 additions & 0 deletions resources/js/Pages/Journal/Invoices/Create.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="py-10 mx-auto max-w-7xl sm:px-6 lg:px-8">
<InvoiceTemplate
ref="InvoiceTemplateForm"
:is-editing="true"
:clients="clients"
:products="products"
:invoice-data="invoice"
:available-taxes="availableTaxes"
/>
</div>
</template>

<script lang="ts" setup>
import { provide, ref } from "vue";
import InvoiceTemplate from "./Partials/InvoiceTemplate.vue";

const props = defineProps([
"invoice",
"clients",
"products",
"categories",
"availableTaxes",
]);

const InvoiceTemplateForm = ref();
const saveForm = (isApplied: boolean) => {
InvoiceTemplateForm.value.saveForm(isApplied);
};

provide("categories", props.categories);
</script>
Loading
Loading