From 1e167c447ae85fa42bf0079246a160c3ad707331 Mon Sep 17 00:00:00 2001 From: Rahaf Date: Wed, 22 Apr 2026 10:52:08 +0300 Subject: [PATCH] Edit profits for owner --- app/owner/profits/page.js | 1008 +++++++++++++++---------------------- 1 file changed, 419 insertions(+), 589 deletions(-) diff --git a/app/owner/profits/page.js b/app/owner/profits/page.js index e03d79a..1f92d86 100644 --- a/app/owner/profits/page.js +++ b/app/owner/profits/page.js @@ -3,59 +3,38 @@ // import { useState, useEffect } from 'react'; // import { motion } from 'framer-motion'; // import { useRouter } from 'next/navigation'; -// import Link from 'next/link'; -// import { -// DollarSign, -// TrendingUp, -// TrendingDown, -// Calendar, -// Home, -// Building, -// Download, -// Filter, -// ChevronLeft, -// ChevronRight, -// ArrowLeft, -// Loader2, -// Eye, -// PieChart, -// BarChart, -// LineChart, +// import { +// DollarSign, +// TrendingUp, // Wallet, -// CreditCard, -// Clock, -// CheckCircle, -// XCircle +// Star, +// Eye, +// Download, +// CalendarDays // } from 'lucide-react'; // import toast, { Toaster } from 'react-hot-toast'; -// import AuthService from '../../services/AuthService'; +// import AuthService from '@/app/services/AuthService'; -// const StatCard = ({ title, value, change, icon: Icon, color, trend }) => { +// const StatCard = ({ title, value, icon: Icon, color }) => { // return ( // -//
+//
//
// //
-//
-// {trend === 'up' ? : } -// {Math.abs(change)}% -//
//
-//

{title}

+//

{title}

//
{value}
// // ); // }; // const PropertyProfitCard = ({ property, onViewDetails }) => { -// const formatCurrency = (amount) => { -// return amount?.toLocaleString() + ' ل.س'; -// }; +// const formatCurrency = (amount) => `$${amount?.toLocaleString()}`; // return ( // //
//
-//

{property.title}

-//

{property.location}

+//

{property.title}

+// {property.isNotSeized && ( +// +// غير محجوز +// +// )} //
-// -// {property.status === 'active' ? 'نشط' : 'غير نشط'} -// +// {property.location} //
-//
-//
-// -//
إجمالي الأرباح
-//
{formatCurrency(property.totalProfit)}
+//
+//
+//
الإيرادات
+//
{formatCurrency(property.revenue)}
//
-//
-// -//
عدد الحجوزات
-//
{property.totalBookings}
+//
+//
العمولة
+//
{formatCurrency(property.commission)}
+//
+//
+//
المتبقي
+//
{formatCurrency(property.remaining)}
//
//
-//
-//
-// هذا الشهر -// {formatCurrency(property.monthlyProfit)} +//
+//
+// +// التقييم العام: +// {property.valuation} //
-//
-// الأسبوع الماضي -// {formatCurrency(property.weeklyProfit)} -//
-//
-// متوسط السعر اليومي -// {formatCurrency(property.avgDailyPrice)} +//
+// +// مؤجر {property.rentedCount} مرة //
//
// -//
+//
+//
+//

+// +// {monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()} +//

+//
+// +// //
+//
-//
-//
-//
-//
{formatCurrency(property.totalProfit)}
-//
إجمالي الأرباح
-//
-//
-//
{property.totalBookings}
-//
عدد الحجوزات
-//
-//
-//
{property.occupancyRate}%
-//
نسبة الإشغال
-//
-//
-//
{formatCurrency(property.avgDailyPrice)}
-//
متوسط السعر اليومي
-//
-//
+//
+// {weekDays.map(day => ( +//
{day}
+// ))} +//
-//
-//

الأرباح الشهرية

-//
-// {monthlyData.map((data, index) => ( -//
-//
-// {data.month} -// {formatCurrency(data.profit)} -//
-//
-// -//
-//
-// ))} -//
-//
- -//
-//

آخر الحجوزات

-//
-// {property.recentBookings?.map((booking, index) => ( -//
-//
-//

{booking.tenantName}

-//

{booking.startDate} - {booking.endDate}

-//
-//
-//

{formatCurrency(booking.amount)}

-//

{booking.status === 'completed' ? 'مكتمل' : 'قيد التنفيذ'}

-//
-//
-// ))} -//
-//
-//
-// -// +//
+// {cells} +//
+//
// ); // }; // export default function OwnerProfitsPage() { // const router = useRouter(); // const [user, setUser] = useState(null); -// const [properties, setProperties] = useState([]); -// const [filteredProperties, setFilteredProperties] = useState([]); // const [isLoading, setIsLoading] = useState(true); -// const [selectedProperty, setSelectedProperty] = useState(null); -// const [dateRange, setDateRange] = useState({ start: '', end: '' }); -// const [selectedPeriod, setSelectedPeriod] = useState('month'); -// useEffect(() => { +// const [summary] = useState({ +// totalRevenue: 4290, +// totalCommission: 644, +// remainingBalance: 3647, +// }); + +// const [properties] = useState([ +// { +// id: 1, +// title: 'Damascus Olive Residence', +// location: 'دمشق، المزة', +// isNotSeized: true, +// revenue: 3240, +// commission: 486, +// remaining: 2754, +// valuation: 'جيد جدا', +// rentedCount: 18, +// }, +// ]); + +// useEffect(() => { +// if (AuthService.isGuest()) { +// router.push('/auth/choose-role'); +// return; +// } +// if (!AuthService.isOwner()) { +// router.push('/'); +// return; +// } + // const authUser = AuthService.getUser(); -// if (authUser && AuthService.isOwner()) { +// if (authUser) { // setUser({ // name: authUser.name || authUser.email, // email: authUser.email, -// role: 'owner', // }); -// loadData(); -// } else { -// router.push('/auth/choose-role'); -// } -// }, [router]); // month, year, all - - - -// const loadProfitsData = () => { -// const storedProfits = localStorage.getItem('ownerProfits'); -// if (storedProfits) { -// setProperties(JSON.parse(storedProfits)); -// setFilteredProperties(JSON.parse(storedProfits)); -// } else { -// const mockProperties = [ -// { -// id: 1, -// title: 'فيلا فاخرة في المزة', -// location: 'دمشق، المزة', -// status: 'active', -// totalProfit: 12500000, -// totalBookings: 24, -// monthlyProfit: 3200000, -// weeklyProfit: 850000, -// avgDailyPrice: 500000, -// occupancyRate: 78, -// recentBookings: [ -// { tenantName: 'أحمد محمد', startDate: '2024-03-10', endDate: '2024-03-15', amount: 2500000, status: 'completed' }, -// { tenantName: 'سارة أحمد', startDate: '2024-03-05', endDate: '2024-03-08', amount: 1500000, status: 'completed' } -// ] -// }, -// { -// id: 2, -// title: 'شقة حديثة في الشهباء', -// location: 'حلب، الشهباء', -// status: 'active', -// totalProfit: 5800000, -// totalBookings: 18, -// monthlyProfit: 1500000, -// weeklyProfit: 400000, -// avgDailyPrice: 250000, -// occupancyRate: 65, -// recentBookings: [ -// { tenantName: 'محمد علي', startDate: '2024-03-12', endDate: '2024-03-14', amount: 750000, status: 'completed' } -// ] -// }, -// { -// id: 3, -// title: 'بيت عائلي في بابا عمرو', -// location: 'حمص، بابا عمرو', -// status: 'active', -// totalProfit: 8400000, -// totalBookings: 12, -// monthlyProfit: 2100000, -// weeklyProfit: 525000, -// avgDailyPrice: 350000, -// occupancyRate: 45, -// recentBookings: [] -// } -// ]; -// setProperties(mockProperties); -// setFilteredProperties(mockProperties); -// localStorage.setItem('ownerProfits', JSON.stringify(mockProperties)); // } // setIsLoading(false); +// }, [router]); + +// const formatCurrency = (amount) => `$${amount?.toLocaleString()}`; + +// const handleViewDetails = (property) => { +// toast.info(`عرض تفاصيل ${property.title}`); // }; -// const totalStats = { -// totalProfit: properties.reduce((sum, p) => sum + p.totalProfit, 0), -// totalBookings: properties.reduce((sum, p) => sum + p.totalBookings, 0), -// avgOccupancy: Math.round(properties.reduce((sum, p) => sum + p.occupancyRate, 0) / properties.length), -// activeProperties: properties.filter(p => p.status === 'active').length -// }; - -// const formatCurrency = (amount) => { -// if (amount >= 1000000) { -// return (amount / 1000000).toFixed(1) + ' مليون ل.س'; -// } -// return amount?.toLocaleString() + ' ل.س'; +// const handleExportReport = () => { +// toast.success('جاري تصدير التقرير...'); // }; // if (isLoading) { // return ( -//
+//
//
-// -//

جاري تحميل بيانات الأرباح...

+//
+//

جاري التحميل...

//
//
// ); @@ -339,324 +231,129 @@ // return ( //
// - -// setSelectedProperty(null)} -// /> +//
+//
+//

دفتر الحسابات

+//

نظرة عامة على أرباح المالك

+//
-//
-// -//
-//

الأرباح والإحصائيات

-//

مرحباً {user?.name}، إليك ملخص أرباحك

-//
- -//
-// -// {/* */} -//
-//
- -//
+//
// +// +// -// -// -// //
-//
-//
-//

أرباح العقارات

-//
-// -//
+//
+//

عقاراتي

+//
+// {properties.map((property) => ( +// +// ))} //
- -// {filteredProperties.length === 0 ? ( -//
-//
-// -//
-//

لا توجد بيانات

-//

لا توجد أرباح مسجلة حتى الآن

-//
-// ) : ( -//
-// {filteredProperties.map((property) => ( -// -// ))} -//
-// )} //
-// -//
-//
-//

احصل على المزيد من الأرباح

-//

أضف عقارات جديدة وحسّن أسعارك لزيادة الإشغال

-//
-// -// إضافة عقار جديد -// -//
-//
+//
+//

تقويم العقار

+// +//
+ +// {/*
+// +//
*/} //
//
// ); // } - - 'use client'; import { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { useRouter } from 'next/navigation'; -import { - DollarSign, - TrendingUp, - Wallet, - Star, - Eye, - Download, - CalendarDays -} from 'lucide-react'; +import { Download, Loader2 } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; +import * as XLSX from 'xlsx'; import AuthService from '@/app/services/AuthService'; -const StatCard = ({ title, value, icon: Icon, color }) => { - return ( - -
-
- -
-
-

{title}

-
{value}
-
- ); -}; - -const PropertyProfitCard = ({ property, onViewDetails }) => { - const formatCurrency = (amount) => `$${amount?.toLocaleString()}`; - - return ( - -
-
-
-

{property.title}

- {property.isNotSeized && ( - - غير محجوز - - )} -
- {property.location} -
- -
-
-
الإيرادات
-
{formatCurrency(property.revenue)}
-
-
-
العمولة
-
{formatCurrency(property.commission)}
-
-
-
المتبقي
-
{formatCurrency(property.remaining)}
-
-
- -
-
- - التقييم العام: - {property.valuation} -
-
- - مؤجر {property.rentedCount} مرة -
-
- - -
-
- ); -}; - -const PropertyCalendar = ({ year, month }) => { - const [currentMonth, setCurrentMonth] = useState(new Date(year, month - 1)); - const monthNames = ['يناير', 'فبراير', 'مارس', 'إبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر']; - const weekDays = ['إثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة', 'سبت', 'أحد']; - - const getDaysInMonth = (date) => { - return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); - }; - - const getFirstDayOfMonth = (date) => { - const day = new Date(date.getFullYear(), date.getMonth(), 1).getDay(); - return day === 0 ? 6 : day - 1; - }; - - const daysInMonth = getDaysInMonth(currentMonth); - const firstDayIndex = getFirstDayOfMonth(currentMonth); - - const cells = []; - for (let i = 0; i < firstDayIndex; i++) { - cells.push(
); - } - for (let d = 1; d <= daysInMonth; d++) { - cells.push( -
- {d} -
- ); - } - - return ( -
-
-

- - {monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()} -

-
- - -
-
- -
- {weekDays.map(day => ( -
{day}
- ))} -
- -
- {cells} -
-
- ); -}; - export default function OwnerProfitsPage() { const router = useRouter(); const [user, setUser] = useState(null); const [isLoading, setIsLoading] = useState(true); + const [tableData, setTableData] = useState([]); - const [summary] = useState({ - totalRevenue: 4290, - totalCommission: 644, - remainingBalance: 3647, - }); - - const [properties] = useState([ + const sampleData = [ { id: 1, - title: 'Damascus Olive Residence', - location: 'دمشق، المزة', - isNotSeized: true, - revenue: 3240, - commission: 486, - remaining: 2754, - valuation: 'جيد جدا', - rentedCount: 18, + property: 'A000000001', + bookingNumber: 'XX-101', + fromDate: '2025-05-01', + toDate: '2025-05-07', + amountReceived: 500, + platformCommission: 0, + transferredToOwner: 0, + transferReceipt: '—', }, - ]); + { + id: 2, + property: 'A000000002', + bookingNumber: 'XX-202', + fromDate: '2025-05-10', + toDate: '2025-05-15', + amountReceived: 300, + platformCommission: 0, + transferredToOwner: 0, + transferReceipt: '—', + }, + { + id: 3, + property: 'A000000003', + bookingNumber: 'XX-309', + fromDate: '2025-06-01', + toDate: '2025-06-05', + amountReceived: 800, + platformCommission: 150, + transferredToOwner: 0, + transferReceipt: 'قيد الانتظار', + }, + ]; + + + const computeRows = (data) => { + return data.map((item) => { + const platformProfit = item.amountReceived * 0.05; + const ownerDue = item.amountReceived - platformProfit; + return { + ...item, + platformProfit, + ownerDue, + }; + }); + }; useEffect(() => { if (AuthService.isGuest()) { @@ -675,87 +372,220 @@ export default function OwnerProfitsPage() { email: authUser.email, }); } + + const stored = localStorage.getItem('ownerProfitsTable'); + if (stored) { + setTableData(computeRows(JSON.parse(stored))); + } else { + setTableData(computeRows(sampleData)); + localStorage.setItem('ownerProfitsTable', JSON.stringify(sampleData)); + } setIsLoading(false); }, [router]); - const formatCurrency = (amount) => `$${amount?.toLocaleString()}`; - - const handleViewDetails = (property) => { - toast.info(`عرض تفاصيل ${property.title}`); - }; + const totals = tableData.reduce( + (acc, row) => { + acc.totalAmountReceived += row.amountReceived; + acc.totalCommission += row.platformCommission; + acc.totalPlatformProfit += row.platformProfit; + acc.totalOwnerDue += row.ownerDue; + acc.totalTransferred += row.transferredToOwner; + return acc; + }, + { + totalAmountReceived: 0, + totalCommission: 0, + totalPlatformProfit: 0, + totalOwnerDue: 0, + totalTransferred: 0, + } + ); const handleExportReport = () => { - toast.success('جاري تصدير التقرير...'); + try { + const exportData = tableData.map((row) => ({ + 'العقار': row.property, + 'رقم الحجز': row.bookingNumber, + 'من تاريخ': row.fromDate, + 'حتى تاريخ': row.toDate, + 'العروض المستلم': row.amountReceived, + 'عمولة المنصة': row.platformCommission, + 'ربح المنصة (5%)': row.platformProfit, + 'المستحق للمالك': row.ownerDue, + 'تم التحويل للمالك': row.transferredToOwner, + 'رقم وصل التحويل': row.transferReceipt, + })); + + exportData.push({ + 'العقار': 'الإجمالي العام', + 'رقم الحجز': '', + 'من تاريخ': '', + 'حتى تاريخ': '', + 'العروض المستلم': totals.totalAmountReceived, + 'عمولة المنصة': totals.totalCommission, + 'ربح المنصة (5%)': totals.totalPlatformProfit, + 'المستحق للمالك': totals.totalOwnerDue, + 'تم التحويل للمالك': totals.totalTransferred, + 'رقم وصل التحويل': '—', + }); + + const worksheet = XLSX.utils.json_to_sheet(exportData); + const colWidths = [ + { wch: 15 }, + { wch: 12 }, + { wch: 12 }, + { wch: 12 }, + { wch: 14 }, + { wch: 14 }, + { wch: 16 }, + { wch: 16 }, + { wch: 16 }, + { wch: 18 }, + ]; + worksheet['!cols'] = colWidths; + + const workbook = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(workbook, worksheet, 'أرباح المالك'); + + XLSX.writeFile(workbook, `تقرير_الأرباح_${new Date().toISOString().slice(0,19).replace(/:/g, '-')}.xlsx`); + + toast.success('تم تصدير التقرير بنجاح!'); + } catch (error) { + console.error('خطأ في التصدير:', error); + toast.error('حدث خطأ أثناء تصدير التقرير'); + } }; if (isLoading) { return ( -
+
-
-

جاري التحميل...

+ +

جاري تحميل بيانات الأرباح...

); } return ( -
+
-
-
-

دفتر الحسابات

-

نظرة عامة على أرباح المالك

-
- -
- - - -
- -
-

عقاراتي

-
- {properties.map((property) => ( - - ))} +
+ +
+

أرباح المالك

+

+ مرحباً {user?.name} +

-
- -
-

تقويم العقار

- -
- - {/*
-
*/} + + + +
+ + + + + + + + + + + + + + + + + {tableData.map((row, idx) => ( + + + + + + + + + + + + + ))} + + + + + + + + + + + + +
العقاررقم الحجزمن تاريخحتى تاريخالعروض المستلمعمولة المنصة + ربح المنصة (5% من العربون) + المستحق للمالكتم التحويل للمالكرقم وصل التحويل
+ {row.property} + + {row.bookingNumber} + + {row.fromDate} + + {row.toDate} + + {row.amountReceived} + + {row.platformCommission} + + {row.platformProfit} + + {row.ownerDue} + + {row.transferredToOwner} + + {row.transferReceipt} +
+ الإجمالي العام + + {totals.totalAmountReceived} + + {totals.totalCommission} + + {totals.totalPlatformProfit} + + {totals.totalOwnerDue} + + {totals.totalTransferred} +
+
+ +
+ ملاحظة: + ربح المنصة يُحتسب تلقائياً بنسبة 5% من قيمة «العروض المستلم». +
+
);