store/resources/js/pages/admin/manage/purchases/Index.vue
Yoga Pangestu 15e2b7ec5b
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (8.3) (push) Waiting to run
tests / ci (8.4) (push) Waiting to run
tests / ci (8.5) (push) Waiting to run
feat: add material_result field to CuttingMaterial and CuttingMaterialCombination; update validation rules and service logic to handle new material result calculations; enhance frontend components for displaying material results in cutting management
2026-07-04 23:14:37 +07:00

91 lines
2.5 KiB
Vue

<script setup lang="ts">
import { Head } from '@inertiajs/vue3';
import { computed, ref, watch } from 'vue';
import CreateButton from '@/components/button/CreateButton.vue';
import { Card, CardContent } from '@/components/ui/card';
import { useCan } from '@/composables/useCan';
import {
useDataTableQuery,
useDataTableQuerySync,
} from '@/composables/useDataTableQuery';
import AdminLayout from '@/layouts/AdminLayout.vue';
import { index, create } from '@/routes/admin/manage/purchases';
import type { PaginatedPurchases } from '@/types/purchase';
import PurchaseGroupedTable from './table/PurchaseGroupedTable.vue';
const props = defineProps<{
purchases: PaginatedPurchases;
filters: {
search: string;
sort?: string;
direction?: 'asc' | 'desc';
};
}>();
const { can } = useCan();
const search = ref(props.filters.search ?? '');
const { setSearch, resetFilters, syncFromServer } = useDataTableQuery({
url: index.url(),
initial: { ...props.filters },
});
useDataTableQuerySync(() => props.filters, syncFromServer);
const tablePagination = computed(() => ({
currentPage: props.purchases.current_page,
perPage: props.purchases.per_page,
lastPage: props.purchases.last_page,
total: props.purchases.total,
}));
const firstItem = computed(() =>
props.purchases.data.length > 0
? (props.purchases.current_page - 1) * props.purchases.per_page + 1
: 0,
);
watch(search, (value) => {
setSearch(value);
});
watch(
() => props.filters.search,
(value) => {
search.value = value ?? '';
},
);
</script>
<template>
<Head title="Belanja" />
<AdminLayout>
<div
class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"
>
<div class="space-y-1">
<h2 class="text-2xl font-bold tracking-tight">Belanja</h2>
</div>
<CreateButton
v-if="can('purchases.create')"
:href="create.url()"
/>
</div>
<Card class="min-w-0">
<CardContent class="min-w-0">
<PurchaseGroupedTable
v-model:search="search"
:purchases="purchases.data"
:first-item="firstItem"
:pagination="tablePagination"
:pagination-links="purchases.links"
@filters-reset="resetFilters"
/>
</CardContent>
</Card>
</AdminLayout>
</template>