diff --git a/thanasoft-back/database/seeders/InterventionSeeder.php b/thanasoft-back/database/seeders/InterventionSeeder.php index db3cf71..c6e2a52 100644 --- a/thanasoft-back/database/seeders/InterventionSeeder.php +++ b/thanasoft-back/database/seeders/InterventionSeeder.php @@ -20,18 +20,30 @@ class InterventionSeeder extends Seeder $products = Product::query() ->whereHas('category', fn ($query) => $query->where('intervention', true)) ->get(); - $deceasedCollection = Deceased::query()->get(); $practitioners = Thanatopractitioner::query()->get(); $clients = Client::query()->limit(12)->get(); $creatorId = User::query()->value('id'); $types = ['thanatopraxie', 'toilette_mortuaire', 'exhumation', 'retrait_pacemaker', 'retrait_bijoux', 'autre']; $statuses = ['demande', 'planifie', 'en_cours', 'termine', 'annule']; - if ($products->isEmpty() || $deceasedCollection->isEmpty() || $clients->isEmpty()) { + if ($products->isEmpty() || $clients->isEmpty()) { return; } foreach ($clients as $index => $client) { + $deceased = Deceased::updateOrCreate( + [ + 'last_name' => sprintf('Défunt Client %d', $client->id), + 'first_name' => 'Dossier', + ], + [ + 'birth_date' => now()->subYears(55 + $index)->subDays($index)->format('Y-m-d'), + 'death_date' => now()->subDays($index + 1)->format('Y-m-d'), + 'place_of_death' => $client->billing_city ?: 'Antananarivo', + 'notes' => sprintf('Défunt de démonstration lié au client #%d pour les interventions seedées.', $client->id), + ] + ); + $location = ClientLocation::updateOrCreate( [ 'client_id' => $client->id, @@ -54,7 +66,7 @@ class InterventionSeeder extends Seeder 'type' => $types[$index % count($types)], ], [ - 'deceased_id' => optional($deceasedCollection->get($index % $deceasedCollection->count()))->id, + 'deceased_id' => $deceased->id, 'order_giver' => $faker->name, 'location_id' => $location->id, 'product_id' => optional($products->get($index % $products->count()))->id, diff --git a/thanasoft-front/src/components/Organism/Defunts/DefuntPresentation.vue b/thanasoft-front/src/components/Organism/Defunts/DefuntPresentation.vue index 677e3fa..6fb0ce7 100644 --- a/thanasoft-front/src/components/Organism/Defunts/DefuntPresentation.vue +++ b/thanasoft-front/src/components/Organism/Defunts/DefuntPresentation.vue @@ -4,13 +4,58 @@ - + + + + + + + + + + + + + + + + + - + @@ -20,19 +65,110 @@ import addButton from "@/components/molecules/new-button/addButton.vue"; import FilterTable from "@/components/molecules/Tables/FilterTable.vue"; import TableAction from "@/components/molecules/Tables/TableAction.vue"; import DefuntsList from "@/components/molecules/Defunts/DefuntsList.vue"; -import { defineProps } from "vue"; +import SoftInput from "@/components/SoftInput.vue"; +import SoftPagination from "@/components/SoftPagination.vue"; +import SoftPaginationItem from "@/components/SoftPaginationItem.vue"; +import { computed, defineEmits, defineProps } from "vue"; import { useRouter } from "vue-router"; const router = useRouter(); -defineProps({ +const emit = defineEmits(["page-change", "search-change"]); + +const props = defineProps({ defunts: { type: Array, required: true, }, + loading: { + type: Boolean, + default: false, + }, + pagination: { + type: Object, + default: () => ({ + current_page: 1, + last_page: 1, + per_page: 10, + total: 0, + from: 0, + to: 0, + }), + }, + search: { + type: String, + default: "", + }, }); const add = () => { router.push({ name: "Add Defunts" }); }; + +const changePage = (page) => { + if (typeof page !== "number") return; + if (page < 1 || page > (props.pagination?.last_page || 1)) return; + if (page === props.pagination?.current_page) return; + emit("page-change", page); +}; + +const visiblePages = computed(() => { + if (!props.pagination) return []; + + const currentPage = props.pagination.current_page || 1; + const lastPage = props.pagination.last_page || 1; + + if (lastPage <= 7) { + return Array.from({ length: lastPage }, (_, index) => index + 1); + } + + const pages = [1]; + let start = Math.max(2, currentPage - 1); + let end = Math.min(lastPage - 1, currentPage + 1); + + if (currentPage < 4) { + start = 2; + end = 4; + } + + if (currentPage > lastPage - 3) { + start = lastPage - 3; + end = lastPage - 1; + } + + for (let page = start; page <= end; page++) { + pages.push(page); + } + + if (!pages.includes(lastPage)) { + pages.push(lastPage); + } + + return [...new Set(pages)].filter( + (page) => typeof page === "number" && page >= 1 && page <= lastPage + ); +}); + + diff --git a/thanasoft-front/src/components/molecules/Defunts/DefuntsList.vue b/thanasoft-front/src/components/molecules/Defunts/DefuntsList.vue index 531d40f..6c8f82a 100644 --- a/thanasoft-front/src/components/molecules/Defunts/DefuntsList.vue +++ b/thanasoft-front/src/components/molecules/Defunts/DefuntsList.vue @@ -1,6 +1,13 @@ - - + + + + Chargement... + + Chargement des défunts... + + + Aucun défunt trouvé @@ -10,22 +17,37 @@ - - handleAction(action, defunt)" - /> - + + + + + handleAction(action, defunt)" + /> + + + + + + Affichage de {{ safeFrom }} à {{ safeTo }} sur + {{ pagination.total || defunts.length }} défunts + + + @@ -81,8 +103,7 @@
Chargement des défunts...