قنور قيبطتل روطملا
Prompt
يتاعيبم قنور" قيبطتل روطملا ليلد" ةماع ةرظن ةرادإ ماظن وهو ،"يتاعيبم قنور" قيبطت عيسوتو ريوطت ىلع نولمعيس نيذلا نيروطملل الماش اليلد مدقي دنتسملا اذه ةعباتم ،نوزخملا ةرادإ ،تاعيبملا ميظنت ىلإ قيبطتلا فدهي .قارعلا يف رجاتملا باحصأل يرصعو يكذ يلخاد تاعيبم نيفظوملا ةبقارمو ،نويدلا. عورشملا لكيه rawnaq_sales/ ├── src/ # يسيئرلا ردصملا دلجم │ ├── models/ # تانايبلا ةدعاق جذامن │ │ ├── __init__.py # كرتشملا تانايبلا ةدعاق نئاك فيرعت │ │ ├── product.py # تائفلاو تاجتنملا جذومن │ │ ├── sale.py # نويدلاو تاعيبملا جذومن │ │ ├── user.py # نيمدختسملا جذومن │ │ └── relationships.py # جذامنلا نيب تاقالعلا فيرعت │ ├── routes/ # ةيجمرب تاهجاو API │ │ ├── product.py # تاجتنملا تاهجاو │ │ ├── sale.py # نويدلاو تاعيبملا تاهجاو │ │ └── user.py # نيمدختسملا تاهجاو │ ├── static/ # ةتباث تافلم (HTML, CSS, JS) │ │ └── index.html # ةيسيئرلا ةحفصلا │ └── main.py # قيبطتلل لوخدلا ةطقن ├── venv/ # (رادصإلاب مكحتلا يف نمضت ال) ةيضارتفالا ةئيبلا ├── requirements.txt # قيبطتلا تابلطتم ├── app_design.md # قيبطتلا ميمصت ةقيثو ├── todo.md # تازيملاو ماهملا ةمئاق └── README.md # فلملا اذه ةمدختسملا تاينقتلا يلاحلا يلوألا جذومنلا (Web) ةيفلخلا ةهجاولا: Flask (Python) تانايبلا ةدعاق: SQLAlchemy عم MySQL • • ةيمامألا ةهجاولا: HTML, CSS, JavaScript عم Bootstrap 5 هل ططخملا يئاهنلا قيبطتلا ةيمامألا ةهجاولا: Flutter (معدل Android و iOS) ةيفلخلا تامدخلاو تانايبلا ةدعاق: Firebase (Firestore ةيحلا ةنمازملل، Authentication نيمدختسملل) تاراعشإلا: Firebase Cloud Messaging (FCM) وأ Flutter Local Notifications ريوطتلاب ءدبلا 1. ريوطتلا ةئيب دادعإ يلوألا جذومنلل (Web) # عورشملا خاسنتسا gitclone<repository-url> cdrawnaq_sales # ةيضارتفا ةئيب ءاشنإ python-mvenvvenv sourcevenv/bin/activate# كام/سكنيل # وأ venv\Scripts\activate# زودنيو # تابلطتملا تيبثت pipinstall-rrequirements.txt # قيبطتلا ليغشت cdsrc pythonmain.py يئاهنلا قيبطتلل (Flutter) # تيبثت Flutter SDK # عجار https://flutter.dev/docs/get-started/install # عورشم ءاشنإ Flutter ديدج fluttercreate--project-nameronaq_mabiaty--orgcom.example./ ronaq_mabiaty_app # ةبولطملا مزحلا ةفاضإ • • • • cd ronaq_mabiaty_app f lutter pub add firebase_core firebase_auth cloud_firestore intl provider 2. تانايبلا ةدعاق لكيه يلوألا جذومنلا (SQLAlchemy) • • • • • • User: (نيفظوملاو ءاردملا) نيمدختسملا جذومن Product: تاجتنملا جذومن Category: تاجتنملا ماسقأ جذومن Sale: عيبلا تايلمع جذومن SaleItem: (ةعابملا تاجتنملا) عيبلا رصانع جذومن Debt: نويدلا جذومن يئاهنلا قيبطتلا (Firestore) فلم عجار app_design.md تانايب ةدعاق لكيه ىلع عالطالل Firestore حرتقملا. ريوطتلا ةطخ (يلاحلا) يلوألا جذومنلا ريوطت :1 ةلحرملا • • • • [x] يساسألا عورشملا لكيه ءاشنإ [x] تانايبلا ةدعاق جذامن ريوطت [x] تاهجاو ريوطت API ةيساسألا [x] ةيساسألا مدختسملا ةهجاو ريوطت قيبطت ريوطت :2 ةلحرملا Flutter • • • • • [ ] عورشم دادعإ Flutter [ ] دادعإ Firebase (Authentication, Firestore) [ ] يف تانايبلا جذامن ريوطت Flutter [ ] ةيساسألا مدختسملا تاهجاو ريوطت [ ] ـب قيبطتلا طبر Firebase ةمدقتملا تازيملا ريوطت :3 ةلحرملا • [ ] تاهيبنتلاو تاراعشإلا ماظن [ ] تايئاصحإلاو ريراقتلا • [ ] ةداعتسالاو يطايتحالا خسنلا • • [ ] ةددعتملا تاغللا معد ريوطتلا تاداشرإ 1. زيمرتلا بولسأ • • • • مدختسا PEP 8 دوكل Python مدختسا Dart Style Guide دوكل Flutter ةدقعملا ءازجألل ةيحيضوت تاقيلعت بتكا لاجملاب ةطبترملا تاريغتملاو تاقيلعتلل ةيبرعلا ةغللا مدختسا 2. يف ةلاحلا ةرادإ Flutter مادختساب ىصوي Provider وأ Riverpod يف قيبطتلا ةلاح ةرادإل Flutter. 3. يف عورشملا لكيه Flutter lib/ ├── models/ # تانايبلا جذامن ├── services/ # تامدخ (Firebase, خلإ ،تاراعشإلا) ├── screens/ # قيبطتلا تاشاش ├── widgets/ # مادختسالا ةداعإل ةلباقلا مدختسملا ةهجاو رصانع ├── utils/ # ةدعاسم تاودأ ├── localization/ # ةمجرتلا تافلم └── main.dart # قيبطتلل لوخدلا ةطقن 4. نامأ دعاوق Firestore يف ةمراص نامأ دعاوق قيبطت بجي Firestore ةبسانملا تانايبلا ىلإ طقف مهل حرصملا نيمدختسملا لوصو نامضل. رابتخالا يلوألا جذومنلا رابتخا # قيبطتلا ليغشت cd src python main.py # قيبطتلا ىلإ لوصولا # ىلع حفصتملا حتفا http://localhost:5000 قيبطت رابتخا Flutter # حيحصتلا عضو يف قيبطتلا ليغشت f lutter run # ةددعتم ةزهجأ ىلع رابتخا f lutter run-d all عجارملاو دراوملا • • • • قئاثو Flutter قئاثو Firebase قئاثو Flask قئاثو SQLAlchemy ةمهاسملا 1. 2. 3. 4. حالصإ وأ ةزيم لكل ديدج عرف ءاشنإب مق ديدجلا دوكلل تارابتخا بتكا تارابتخالا عيمج زايتجا نم دكأت تارييغتلل لصفم فصو عم بحس بلط لاسرإب مق معدلاو لاصتالا ربع ريوطتلا قيرف عم لصاوتلا ىجري ،ةدعاسملا وأ ةلئسألل:- ينورتكلإلا ديربلا: [example@example.com]- ةانق Slack: [#rawnaq-dev]
Generated Result
More Recommendations
View Allإنشاء صفحة تسجيل دخول PHP
اريد عمل صفحة php لتسجيل دخول طلاب مدرسة
برنامج سلفيات الموظفين
اصنع برنامج سلفيات الموظفين بالاعلى على اليمين يوجد زر صغير باسم " مستخدم جديد " وزر على اليسار لتغيير اللغة من اللغة العربية الى اللغة الانجليزية والعكس بحيث عند اختيار اللغة العربية يكون اتجاة الحروف من اليمين وعند اختيار اللغة الانجليزي يكون اتجاة الحروف من اليسار مع تثبيت اماكن الازرار العنوان الرئيسي في المنتصف بالخط العريض جدا وباللون الاحمر " بن مرشد " عند اختيار اللغة العربية و " Bin Murshid " عند اختيار اللغة الانجليزي وتحت العنوان بخط عادي باللون الازرق " سلفيات الموظفين " اولا شاشة " تسجيل الدخول: " خانة اسم المستخدم عبارة قائمة منسدلة بها جميع المستخدمين مع امكانية البحث ايضا وخانة كلمة المرور مشفرة زر دخول وزر خروج لا تظهر الشاشة التالية الا عند كتابة كلمة المرور ثانيا شاشة " تسجيل سلفة " خانة اسم الموظف عبارة عن قائمة منسدلة بها جميع الموظفين مع امكانية البحث ايضا يظهر تحتها باللون الاحمر كلمة " الرصيد الحالي : " حيث يتم تجميع سلفيات كل موظف على حدى خانة المبلغ خانة ملاحظات زر حفظ وزر خروج
تحويل الأرقام العربية إلى غربية
(function(Scratch) { "use strict"; class InventoryManagement { constructor() { this.inventory = []; this.borrowers = []; this.profits = 0; this.mainWindow = null; this.titleBar = null; this.contentArea = null; this.inventoryList = null; this.borrowersList = null; this.currentView = 'inventory'; this.storageKey = 'inventory_management_data'; this.darkMode = false; this.transactionHistory = []; this.initTheme(); } getInfo() { return { id: 'inventoryManagement', name: 'إدارة المخزون', color1: '#2ecc71', color2: '#27ae60', color3: '#229954', blocks: [ { opcode: 'showMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إظهار نافذة إدارة المخزون' }, { opcode: 'hideMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إخفاء نافذة إدارة المخزون' }, { opcode: 'getTotalProfits', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي الأرباح' }, { opcode: 'getInventoryCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد العناصر في المخزون' }, { opcode: 'getBorrowersCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد المقترضين' }, { opcode: 'getTotalCapital', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي رأس المال المستثمر' }, { opcode: 'getNetProfit', blockType: Scratch.BlockType.REPORTER, text: 'صافي الأرباح' }, { opcode: 'resetProfits', blockType: Scratch.BlockType.COMMAND, text: 'إعادة تعيين الأرباح' } ], menus: {} }; } initTheme() { const savedTheme = localStorage.getItem(`${this.storageKey}_theme`); this.darkMode = savedTheme === 'dark'; this.applyTheme(); } applyTheme() { if (this.darkMode) { document.documentElement.style.setProperty('--bg-color', '#1a1a1a'); document.documentElement.style.setProperty('--text-color', '#ffffff'); document.documentElement.style.setProperty('--card-bg', '#2d2d2d'); document.documentElement.style.setProperty('--border-color', '#444'); document.documentElement.style.setProperty('--input-bg', '#333'); document.documentElement.style.setProperty('--input-text', '#fff'); } else { document.documentElement.style.setProperty('--bg-color', '#f8f9fa'); document.documentElement.style.setProperty('--text-color', '#333333'); document.documentElement.style.setProperty('--card-bg', '#ffffff'); document.documentElement.style.setProperty('--border-color', '#ddd'); document.documentElement.style.setProperty('--input-bg', '#fff'); document.documentElement.style.setProperty('--input-text', '#333'); } } toggleDarkMode() { this.darkMode = !this.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); this.updateWindowStyles(); } updateWindowStyles() { if (!this.mainWindow) return; if (this.darkMode) { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#1e8449'; } else { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#27ae60'; } } showMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'block'; return; } this.mainWindow = document.createElement('div'); this.mainWindow.style.position = 'fixed'; this.mainWindow.style.top = '50%'; this.mainWindow.style.left = '50%'; this.mainWindow.style.transform = 'translate(-50%, -50%)'; this.mainWindow.style.width = '700px'; this.mainWindow.style.maxWidth = '90%'; this.mainWindow.style.height = '600px'; this.mainWindow.style.maxHeight = '90vh'; this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.mainWindow.style.borderRadius = '15px'; this.mainWindow.style.boxShadow = '0 8px 16px rgba(0, 0, 0, 0.2)'; this.mainWindow.style.zIndex = '9999'; this.mainWindow.style.overflow = 'hidden'; this.mainWindow.style.display = 'block'; this.mainWindow.style.fontFamily = 'Arial, sans-serif'; this.titleBar = document.createElement('div'); this.titleBar.style.backgroundColor = this.darkMode ? '#1e8449' : '#27ae60'; this.titleBar.style.color = 'white'; this.titleBar.style.padding = '15px 20px'; this.titleBar.style.display = 'flex'; this.titleBar.style.justifyContent = 'space-between'; this.titleBar.style.alignItems = 'center'; this.titleBar.style.borderTopLeftRadius = '15px'; this.titleBar.style.borderTopRightRadius = '15px'; const titleText = document.createElement('span'); titleText.textContent = 'إدارة المخزون والمقترضين'; titleText.style.fontWeight = 'bold'; titleText.style.fontSize = '20px'; const profitsText = document.createElement('span'); profitsText.id = 'profits-display'; profitsText.textContent = `الأرباح: ${this.profits} د.ج`; profitsText.style.marginLeft = 'auto'; profitsText.style.marginRight = '20px'; profitsText.style.fontSize = '16px'; profitsText.style.color = '#fff'; const themeToggleBtn = this.createIconButton( this.darkMode ? '🌞' : '🌙', this.darkMode ? 'الوضع الفاتح' : 'الوضع الداكن', '#ffffff', () => this.toggleDarkMode() ); themeToggleBtn.style.fontSize = '18px'; themeToggleBtn.style.marginLeft = '15px'; const addItemBtn = this.createIconButton('➕', 'إضافة سلعة', '#ffffff', () => this.showAddItemModal()); addItemBtn.style.fontSize = '18px'; const addBorrowerBtn = this.createIconButton('👥', 'إضافة مقترض', '#ffffff', () => this.showAddBorrowerModal()); addBorrowerBtn.style.fontSize = '18px'; addBorrowerBtn.style.marginLeft = '15px'; const historyBtn = this.createIconButton('📜', 'سجل العمليات', '#ffffff', () => this.showHistoryModal()); historyBtn.style.fontSize = '18px'; historyBtn.style.marginLeft = '15px'; const saveBtn = this.createIconButton('💾', 'حفظ البيانات', '#ffffff', () => this.saveData()); saveBtn.style.fontSize = '18px'; saveBtn.style.marginLeft = '15px'; const loadBtn = this.createIconButton('📂', 'تحميل البيانات', '#ffffff', () => this.showLoadModal()); loadBtn.style.fontSize = '18px'; loadBtn.style.marginLeft = '15px'; const resetBtn = this.createIconButton('🔄', 'إعادة تعيين الأرباح', '#ffffff', () => this.resetProfits()); resetBtn.style.fontSize = '18px'; resetBtn.style.marginLeft = '15px'; const closeBtn = this.createIconButton('✖', 'إغلاق', '#ffffff', () => this.hideMainWindow()); closeBtn.style.fontSize = '18px'; closeBtn.style.marginLeft = '15px'; this.titleBar.appendChild(titleText); this.titleBar.appendChild(profitsText); this.titleBar.appendChild(themeToggleBtn); this.titleBar.appendChild(addItemBtn); this.titleBar.appendChild(addBorrowerBtn); this.titleBar.appendChild(historyBtn); this.titleBar.appendChild(saveBtn); this.titleBar.appendChild(loadBtn); this.titleBar.appendChild(resetBtn); this.titleBar.appendChild(closeBtn); this.contentArea = document.createElement('div'); this.contentArea.style.height = 'calc(100% - 50px)'; this.contentArea.style.overflow = 'hidden'; this.contentArea.style.display = 'flex'; this.contentArea.style.flexDirection = 'column'; const tabs = document.createElement('div'); tabs.style.display = 'flex'; tabs.style.borderBottom = '1px solid var(--border-color)'; tabs.style.backgroundColor = this.darkMode ? '#333' : '#ecf0f1'; const inventoryTab = document.createElement('button'); inventoryTab.textContent = 'المخزون'; inventoryTab.style.padding = '12px 20px'; inventoryTab.style.border = 'none'; inventoryTab.style.background = this.currentView === 'inventory' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); inventoryTab.style.cursor = 'pointer'; inventoryTab.style.fontWeight = 'bold'; inventoryTab.style.fontSize = '16px'; inventoryTab.style.color = this.darkMode ? '#fff' : '#333'; inventoryTab.addEventListener('click', () => this.switchView('inventory')); const borrowersTab = document.createElement('button'); borrowersTab.textContent = 'المقترضين'; borrowersTab.style.padding = '12px 20px'; borrowersTab.style.border = 'none'; borrowersTab.style.background = this.currentView === 'borrowers' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); borrowersTab.style.cursor = 'pointer'; borrowersTab.style.fontSize = '16px'; borrowersTab.style.color = this.darkMode ? '#fff' : '#333'; borrowersTab.addEventListener('click', () => this.switchView('borrowers')); tabs.appendChild(inventoryTab); tabs.appendChild(borrowersTab); this.inventoryList = document.createElement('div'); this.inventoryList.style.overflowY = 'auto'; this.inventoryList.style.flexGrow = '1'; this.inventoryList.style.padding = '15px'; this.inventoryList.style.display = 'grid'; this.inventoryList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.inventoryList.style.gap = '15px'; this.borrowersList = document.createElement('div'); this.borrowersList.style.overflowY = 'auto'; this.borrowersList.style.flexGrow = '1'; this.borrowersList.style.padding = '15px'; this.borrowersList.style.display = 'none'; this.borrowersList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.borrowersList.style.gap = '15px'; this.contentArea.appendChild(tabs); this.contentArea.appendChild(this.inventoryList); this.contentArea.appendChild(this.borrowersList); this.mainWindow.appendChild(this.titleBar); this.mainWindow.appendChild(this.contentArea); document.body.appendChild(this.mainWindow); this.addAnimations(); this.loadData(); } createIconButton(icon, title, color, clickHandler) { const btn = document.createElement('button'); btn.innerHTML = `${icon} ${title}`; btn.style.background = 'none'; btn.style.border = 'none'; btn.style.color = color; btn.style.cursor = 'pointer'; btn.style.display = 'flex'; btn.style.alignItems = 'center'; btn.title = title; btn.addEventListener('click', clickHandler); return btn; } addAnimations() { const style = document.createElement('style'); style.textContent = ` @keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -45%); } to { opacity: 1; transform: translate(-50%, -50%); } } `; document.head.appendChild(style); } hideMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'none'; } } switchView(view) { this.currentView = view; if (view === 'inventory') { this.inventoryList.style.display = 'grid'; this.borrowersList.style.display = 'none'; this.renderInventory(); } else { this.inventoryList.style.display = 'none'; this.borrowersList.style.display = 'grid'; this.renderBorrowers(); } } showAddItemModal() { const modal = this.createModal('إضافة سلعة جديدة', '#27ae60'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم السلعة:', 'text'); const quantityInput = this.createInputField('الكمية:', 'number'); quantityInput.input.min = '0'; const alertInput = this.createInputField('التنبيه عند:', 'number'); alertInput.input.min = '0'; const priceInput = this.createInputField('سعر البيع:', 'number'); priceInput.input.min = '0'; const costInput = this.createInputField('تكلفة الشراء:', 'number'); costInput.input.min = '0'; costInput.input.value = '0'; form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(quantityInput.label); form.appendChild(quantityInput.input); form.appendChild(alertInput.label); form.appendChild(alertInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(costInput.label); form.appendChild(costInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#27ae60', () => { const item = { id: Date.now(), name: nameInput.input.value, quantity: parseInt(quantityInput.input.value) || 0, alertAt: parseInt(alertInput.input.value) || 0, price: parseInt(priceInput.input.value) || 0, cost: parseInt(costInput.input.value) || 0, originalQuantity: parseInt(quantityInput.input.value) || 0 }; this.inventory.push(item); this.logTransaction('إضافة سلعة', `تم إضافة ${item.name} - الكمية: ${item.quantity}`); this.renderInventory(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showAddBorrowerModal() { const modal = this.createModal('إضافة مقترض جديد', '#3498db'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم المقترض:', 'text'); const itemInput = this.createInputField('السلعة:', 'text'); const priceInput = this.createInputField('السعر:', 'number'); priceInput.input.min = '0'; const dateInput = this.createInputField('تاريخ الإقتراض:', 'date'); const dueDateInput = this.createInputField('تاريخ الاستحقاق:', 'date'); form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(itemInput.label); form.appendChild(itemInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(dateInput.label); form.appendChild(dateInput.input); form.appendChild(dueDateInput.label); form.appendChild(dueDateInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#3498db', () => { const borrower = { id: Date.now(), name: nameInput.input.value, item: itemInput.input.value, price: parseInt(priceInput.input.value) || 0, date: dateInput.input.value || new Date().toISOString().split('T')[0], dueDate: dueDateInput.input.value || '', returned: false }; this.borrowers.push(borrower); this.logTransaction('إضافة مقترض', `تم إضافة ${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } createModal(title, color) { const modal = document.createElement('div'); modal.style.position = 'fixed'; modal.style.top = '50%'; modal.style.left = '50%'; modal.style.transform = 'translate(-50%, -50%)'; modal.style.width = '450px'; modal.style.maxWidth = '90%'; modal.style.backgroundColor = 'var(--card-bg)'; modal.style.color = 'var(--text-color)'; modal.style.padding = '20px'; modal.style.borderRadius = '10px'; modal.style.boxShadow = '0 5px 15px rgba(0, 0, 0, 0.2)'; modal.style.zIndex = '10000'; modal.style.fontFamily = 'Arial, sans-serif'; const closeBtn = document.createElement('button'); closeBtn.innerHTML = '✖'; closeBtn.style.position = 'absolute'; closeBtn.style.top = '10px'; closeBtn.style.right = '10px'; closeBtn.style.background = 'none'; closeBtn.style.border = 'none'; closeBtn.style.cursor = 'pointer'; closeBtn.style.fontSize = '18px'; closeBtn.style.color = '#7f8c8d'; closeBtn.addEventListener('click', () => modal.remove()); const titleElement = document.createElement('h3'); titleElement.textContent = title; titleElement.style.margin = '0 0 15px 0'; titleElement.style.color = color; titleElement.style.textAlign = 'center'; titleElement.style.fontSize = '18px'; const content = document.createElement('div'); modal.appendChild(closeBtn); modal.appendChild(titleElement); modal.appendChild(content); return { element: modal, content: content }; } createInputField(labelText, inputType) { const label = document.createElement('label'); label.textContent = labelText; label.style.display = 'block'; label.style.marginBottom = '5px'; label.style.fontWeight = '600'; label.style.color = this.darkMode ? '#fff' : '#2c3e50'; label.style.fontSize = '14px'; const input = document.createElement('input'); input.type = inputType; input.style.width = '100%'; input.style.padding = '10px'; input.style.border = '1px solid var(--border-color)'; input.style.borderRadius = '5px'; input.style.fontSize = '14px'; input.style.backgroundColor = 'var(--input-bg)'; input.style.color = 'var(--input-text)'; return { label, input }; } createActionButton(text, color, clickHandler) { const button = document.createElement('button'); button.textContent = text; button.style.padding = '10px 20px'; button.style.border = 'none'; button.style.background = color; button.style.color = 'white'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; button.style.fontSize = '14px'; button.style.fontWeight = 'bold'; button.addEventListener('click', clickHandler); return button; } renderInventory() { this.inventoryList.innerHTML = ''; if (this.inventory.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد عناصر في المخزون'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.inventoryList.appendChild(emptyMessage); return; } const capitalElement = document.createElement('div'); capitalElement.style.padding = '10px'; capitalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#8e44ad'; capitalElement.style.color = 'white'; capitalElement.style.borderRadius = '5px'; capitalElement.style.marginBottom = '10px'; capitalElement.style.fontWeight = 'bold'; capitalElement.style.textAlign = 'center'; capitalElement.style.gridColumn = '1 / -1'; const totalCapital = this.getTotalCapital(); capitalElement.textContent = `رأس المال المستثمر: ${totalCapital} د.ج`; this.inventoryList.appendChild(capitalElement); this.inventory.forEach(item => { const itemElement = document.createElement('div'); itemElement.className = 'item-card'; itemElement.style.padding = '15px'; itemElement.style.border = '1px solid var(--border-color)'; itemElement.style.borderRadius = '8px'; itemElement.style.backgroundColor = item.quantity <= item.alertAt ? (this.darkMode ? '#3a1a1a' : '#ffebee') : 'var(--card-bg)'; itemElement.style.display = 'flex'; itemElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = item.name; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const quantityElement = document.createElement('div'); quantityElement.textContent = `الكمية: ${item.quantity}/${item.originalQuantity}`; quantityElement.style.marginBottom = '5px'; quantityElement.style.color = item.quantity <= item.alertAt ? '#e74c3c' : (this.darkMode ? '#ddd' : '#34495e'); quantityElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `سعر البيع: ${item.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const costElement = document.createElement('div'); costElement.textContent = `تكلفة الشراء: ${item.cost} د.ج`; costElement.style.marginBottom = '5px'; costElement.style.color = this.darkMode ? '#ddd' : '#34495e'; costElement.style.fontSize = '14px'; const profit = item.price - item.cost; const profitElement = document.createElement('div'); profitElement.textContent = `الربح: ${profit} د.ج`; profitElement.style.marginBottom = '5px'; profitElement.style.color = profit > 0 ? '#27ae60' : '#e74c3c'; profitElement.style.fontWeight = profit > 0 ? 'bold' : 'normal'; profitElement.style.fontSize = '14px'; const alertElement = document.createElement('div'); alertElement.textContent = `التنبيه عند: ${item.alertAt}`; alertElement.style.marginBottom = '10px'; alertElement.style.color = '#e67e22'; alertElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.inventory = this.inventory.filter(i => i.id !== item.id); this.logTransaction('حذف سلعة', `تم حذف ${item.name}`); this.renderInventory(); }); deleteBtn.style.fontSize = '16px'; const increaseBtn = this.createIconButton('➕', 'زيادة', '#27ae60', () => { item.quantity++; this.logTransaction('زيادة كمية', `${item.name} - الكمية الجديدة: ${item.quantity}`); this.renderInventory(); }); increaseBtn.style.fontSize = '16px'; const decreaseBtn = this.createIconButton('➖', 'نقصان', '#f39c12', () => { if (item.quantity > 0) { item.quantity--; this.profits += item.price; this.logTransaction('بيع سلعة', `${item.name} - الكمية المتبقية: ${item.quantity} - السعر: ${item.price} د.ج`); this.updateProfitsDisplay(); this.renderInventory(); } }); decreaseBtn.style.fontSize = '16px'; actionsDiv.appendChild(decreaseBtn); actionsDiv.appendChild(increaseBtn); actionsDiv.appendChild(deleteBtn); itemElement.appendChild(nameElement); itemElement.appendChild(quantityElement); itemElement.appendChild(priceElement); itemElement.appendChild(costElement); itemElement.appendChild(profitElement); itemElement.appendChild(alertElement); itemElement.appendChild(actionsDiv); this.inventoryList.appendChild(itemElement); }); } renderBorrowers() { this.borrowersList.innerHTML = ''; const totalElement = document.createElement('div'); totalElement.style.padding = '10px'; totalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#3498db'; totalElement.style.color = 'white'; totalElement.style.borderRadius = '5px'; totalElement.style.marginBottom = '10px'; totalElement.style.fontWeight = 'bold'; totalElement.style.textAlign = 'center'; totalElement.style.gridColumn = '1 / -1'; const total = this.borrowers.reduce((sum, borrower) => sum + borrower.price, 0); totalElement.textContent = `إجمالي القروض: ${total} د.ج`; this.borrowersList.appendChild(totalElement); if (this.borrowers.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد سجلات للمقترضين'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.borrowersList.appendChild(emptyMessage); return; } const today = new Date(); today.setHours(0, 0, 0, 0); this.borrowers.forEach(borrower => { const dueDate = borrower.dueDate ? new Date(borrower.dueDate) : null; dueDate?.setHours(0, 0, 0, 0); const isOverdue = dueDate && dueDate < today; const isDueToday = dueDate && dueDate.getTime() === today.getTime(); const borrowerElement = document.createElement('div'); borrowerElement.className = 'borrower-card'; borrowerElement.style.padding = '15px'; borrowerElement.style.border = '1px solid var(--border-color)'; borrowerElement.style.borderRadius = '8px'; borrowerElement.style.backgroundColor = isOverdue ? (this.darkMode ? '#3a1a1a' : '#ffebee') : isDueToday ? (this.darkMode ? '#3a2e0f' : '#fff3e0') : (this.darkMode ? '#1a2a3a' : '#e3f2fd'); borrowerElement.style.display = 'flex'; borrowerElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = `اسم المقترض: ${borrower.name}`; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const itemElement = document.createElement('div'); itemElement.textContent = `السلعة: ${borrower.item}`; itemElement.style.marginBottom = '5px'; itemElement.style.color = this.darkMode ? '#ddd' : '#34495e'; itemElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `السعر: ${borrower.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const dateElement = document.createElement('div'); dateElement.textContent = `تاريخ الإقتراض: ${borrower.date}`; dateElement.style.marginBottom = '5px'; dateElement.style.color = '#7f8c8d'; dateElement.style.fontSize = '14px'; const dueDateElement = document.createElement('div'); dueDateElement.textContent = `تاريخ الاستحقاق: ${borrower.dueDate || 'غير محدد'}`; dueDateElement.style.marginBottom = '5px'; dueDateElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#7f8c8d'; dueDateElement.style.fontWeight = isOverdue || isDueToday ? 'bold' : 'normal'; dueDateElement.style.fontSize = '14px'; const statusElement = document.createElement('div'); statusElement.textContent = `الحالة: ${isOverdue ? 'متأخر' : isDueToday ? 'ينتهي اليوم' : 'جاري'}`; statusElement.style.marginBottom = '10px'; statusElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#27ae60'; statusElement.style.fontWeight = 'bold'; statusElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.logTransaction('حذف مقترض', `${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); }); deleteBtn.style.fontSize = '16px'; const returnBtn = this.createIconButton('🔄', 'تسديد', '#27ae60', () => { borrower.returned = true; this.profits += borrower.price; this.logTransaction('تسديد قرض', `${borrower.name} - المبلغ: ${borrower.price} د.ج`); this.updateProfitsDisplay(); this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.renderBorrowers(); }); returnBtn.style.fontSize = '16px'; actionsDiv.appendChild(returnBtn); actionsDiv.appendChild(deleteBtn); borrowerElement.appendChild(nameElement); borrowerElement.appendChild(itemElement); borrowerElement.appendChild(priceElement); borrowerElement.appendChild(dateElement); borrowerElement.appendChild(dueDateElement); borrowerElement.appendChild(statusElement); borrowerElement.appendChild(actionsDiv); this.borrowersList.appendChild(borrowerElement); }); } updateProfitsDisplay() { if (this.titleBar) { const profitsDisplay = document.getElementById('profits-display'); if (profitsDisplay) { profitsDisplay.textContent = `الأرباح: ${this.profits} د.ج`; } } } resetProfits() { this.logTransaction('إعادة تعيين الأرباح', `تم إعادة التعيين من ${this.profits} إلى 0`); this.profits = 0; this.updateProfitsDisplay(); this.showNotification('تم إعادة تعيين الأرباح بنجاح', '#3498db'); } saveData() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `inventory_data_${new Date().toISOString().split('T')[0]}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); this.showNotification('تم حفظ البيانات بنجاح!', '#27ae60'); } showLoadModal() { const modal = this.createModal('تحميل البيانات', '#3498db'); const infoText = document.createElement('p'); infoText.textContent = 'اختر طريقة تحميل البيانات:'; infoText.style.textAlign = 'center'; infoText.style.marginBottom = '20px'; infoText.style.color = this.darkMode ? '#fff' : '#2c3e50'; infoText.style.fontSize = '15px'; modal.content.appendChild(infoText); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.flexDirection = 'column'; buttonsDiv.style.gap = '10px'; const loadLocalBtn = this.createActionButton('تحميل من التخزين المحلي', '#2ecc71', () => { this.loadData(); modal.element.remove(); this.showNotification('تم تحميل البيانات من التخزين المحلي', '#2ecc71'); }); loadLocalBtn.style.width = '100%'; loadLocalBtn.style.padding = '12px'; const loadFileBtn = this.createActionButton('تحميل من ملف', '#3498db', () => { this.showFilePicker(); modal.element.remove(); }); loadFileBtn.style.width = '100%'; loadFileBtn.style.padding = '12px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); cancelBtn.style.width = '100%'; cancelBtn.style.padding = '12px'; buttonsDiv.appendChild(loadLocalBtn); buttonsDiv.appendChild(loadFileBtn); buttonsDiv.appendChild(cancelBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showFilePicker() { const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.style.display = 'none'; input.addEventListener('change', (event) => { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { try { const data = JSON.parse(e.target.result); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } this.showNotification('تم تحميل البيانات من الملف بنجاح', '#2ecc71'); } catch (error) { console.error('Error loading file:', error); this.showNotification('حدث خطأ أثناء تحميل الملف', '#e74c3c'); } }; reader.readAsText(file); }); document.body.appendChild(input); input.click(); document.body.removeChild(input); } loadData() { const savedData = localStorage.getItem(this.storageKey); if (savedData) { try { const data = JSON.parse(savedData); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } } catch (e) { console.error('Failed to parse saved data', e); } } } showNotification(message, color) { const notification = document.createElement('div'); notification.textContent = message; notification.style.position = 'fixed'; notification.style.bottom = '20px'; notification.style.left = '50%'; notification.style.transform = 'translateX(-50%)'; notification.style.backgroundColor = color; notification.style.color = 'white'; notification.style.padding = '10px 20px'; notification.style.borderRadius = '5px'; notification.style.zIndex = '10001'; notification.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)'; notification.style.fontSize = '14px'; notification.style.fontWeight = 'bold'; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } logTransaction(action, details) { const transaction = { id: Date.now(), timestamp: new Date().toISOString(), action, details }; this.transactionHistory.push(transaction); this.autoSave(); } autoSave() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); } showHistoryModal() { const modal = this.createModal('سجل العمليات', '#9b59b6'); const historyContainer = document.createElement('div'); historyContainer.style.maxHeight = '400px'; historyContainer.style.overflowY = 'auto'; historyContainer.style.padding = '10px'; historyContainer.style.border = '1px solid var(--border-color)'; historyContainer.style.borderRadius = '5px'; historyContainer.style.marginBottom = '15px'; if (this.transactionHistory.length === 0) { historyContainer.innerHTML = '<p style="text-align:center;color:#7f8c8d">لا توجد عمليات مسجلة</p>'; } else { this.transactionHistory.slice().reverse().forEach(transaction => { const entry = document.createElement('div'); entry.style.padding = '8px'; entry.style.borderBottom = '1px solid var(--border-color)'; entry.style.fontSize = '13px'; const date = new Date(transaction.timestamp); const dateStr = date.toLocaleString('ar-EG', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); entry.innerHTML = ` <div style="display:flex;justify-content:space-between"> <strong>${transaction.action}</strong> <span style="color:#7f8c8d">${dateStr}</span> </div> <div style="margin-top:3px;color:#555">${transaction.details}</div> `; historyContainer.appendChild(entry); }); } modal.content.appendChild(historyContainer); const closeBtn = this.createActionButton('إغلاق', '#7f8c8d', () => modal.element.remove()); closeBtn.style.width = '100%'; modal.content.appendChild(closeBtn); document.body.appendChild(modal.element); } getTotalProfits() { return this.profits; } getInventoryCount() { return this.inventory.length; } getBorrowersCount() { return this.borrowers.length; } getTotalCapital() { return this.inventory.reduce((total, item) => total + (item.cost || 0), 0); } getNetProfit() { return this.profits - this.getTotalCapital(); } } Scratch.extensions.register(new InventoryManagement()); })(Scratch); المرجو تغيير ارقام جدول التاريخ من ارقام العربيه الى ارقام الغربيه ............وهذا الكود اريد تحويله الى سكراتش
تحويل أرقام الجدول
(function(Scratch) { "use strict"; class InventoryManagement { constructor() { this.inventory = []; this.borrowers = []; this.profits = 0; this.mainWindow = null; this.titleBar = null; this.contentArea = null; this.inventoryList = null; this.borrowersList = null; this.currentView = 'inventory'; this.storageKey = 'inventory_management_data'; this.darkMode = false; this.transactionHistory = []; this.initTheme(); } getInfo() { return { id: 'inventoryManagement', name: 'إدارة المخزون', color1: '#2ecc71', color2: '#27ae60', color3: '#229954', blocks: [ { opcode: 'showMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إظهار نافذة إدارة المخزون' }, { opcode: 'hideMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إخفاء نافذة إدارة المخزون' }, { opcode: 'getTotalProfits', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي الأرباح' }, { opcode: 'getInventoryCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد العناصر في المخزون' }, { opcode: 'getBorrowersCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد المقترضين' }, { opcode: 'getTotalCapital', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي رأس المال المستثمر' }, { opcode: 'getNetProfit', blockType: Scratch.BlockType.REPORTER, text: 'صافي الأرباح' }, { opcode: 'resetProfits', blockType: Scratch.BlockType.COMMAND, text: 'إعادة تعيين الأرباح' } ], menus: {} }; } initTheme() { const savedTheme = localStorage.getItem(`${this.storageKey}_theme`); this.darkMode = savedTheme === 'dark'; this.applyTheme(); } applyTheme() { if (this.darkMode) { document.documentElement.style.setProperty('--bg-color', '#1a1a1a'); document.documentElement.style.setProperty('--text-color', '#ffffff'); document.documentElement.style.setProperty('--card-bg', '#2d2d2d'); document.documentElement.style.setProperty('--border-color', '#444'); document.documentElement.style.setProperty('--input-bg', '#333'); document.documentElement.style.setProperty('--input-text', '#fff'); } else { document.documentElement.style.setProperty('--bg-color', '#f8f9fa'); document.documentElement.style.setProperty('--text-color', '#333333'); document.documentElement.style.setProperty('--card-bg', '#ffffff'); document.documentElement.style.setProperty('--border-color', '#ddd'); document.documentElement.style.setProperty('--input-bg', '#fff'); document.documentElement.style.setProperty('--input-text', '#333'); } } toggleDarkMode() { this.darkMode = !this.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); this.updateWindowStyles(); } updateWindowStyles() { if (!this.mainWindow) return; if (this.darkMode) { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#1e8449'; } else { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#27ae60'; } } showMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'block'; return; } this.mainWindow = document.createElement('div'); this.mainWindow.style.position = 'fixed'; this.mainWindow.style.top = '50%'; this.mainWindow.style.left = '50%'; this.mainWindow.style.transform = 'translate(-50%, -50%)'; this.mainWindow.style.width = '700px'; this.mainWindow.style.maxWidth = '90%'; this.mainWindow.style.height = '600px'; this.mainWindow.style.maxHeight = '90vh'; this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.mainWindow.style.borderRadius = '15px'; this.mainWindow.style.boxShadow = '0 8px 16px rgba(0, 0, 0, 0.2)'; this.mainWindow.style.zIndex = '9999'; this.mainWindow.style.overflow = 'hidden'; this.mainWindow.style.display = 'block'; this.mainWindow.style.fontFamily = 'Arial, sans-serif'; this.titleBar = document.createElement('div'); this.titleBar.style.backgroundColor = this.darkMode ? '#1e8449' : '#27ae60'; this.titleBar.style.color = 'white'; this.titleBar.style.padding = '15px 20px'; this.titleBar.style.display = 'flex'; this.titleBar.style.justifyContent = 'space-between'; this.titleBar.style.alignItems = 'center'; this.titleBar.style.borderTopLeftRadius = '15px'; this.titleBar.style.borderTopRightRadius = '15px'; const titleText = document.createElement('span'); titleText.textContent = 'إدارة المخزون والمقترضين'; titleText.style.fontWeight = 'bold'; titleText.style.fontSize = '20px'; const profitsText = document.createElement('span'); profitsText.id = 'profits-display'; profitsText.textContent = `الأرباح: ${this.profits} د.ج`; profitsText.style.marginLeft = 'auto'; profitsText.style.marginRight = '20px'; profitsText.style.fontSize = '16px'; profitsText.style.color = '#fff'; const themeToggleBtn = this.createIconButton( this.darkMode ? '🌞' : '🌙', this.darkMode ? 'الوضع الفاتح' : 'الوضع الداكن', '#ffffff', () => this.toggleDarkMode() ); themeToggleBtn.style.fontSize = '18px'; themeToggleBtn.style.marginLeft = '15px'; const addItemBtn = this.createIconButton('➕', 'إضافة سلعة', '#ffffff', () => this.showAddItemModal()); addItemBtn.style.fontSize = '18px'; const addBorrowerBtn = this.createIconButton('👥', 'إضافة مقترض', '#ffffff', () => this.showAddBorrowerModal()); addBorrowerBtn.style.fontSize = '18px'; addBorrowerBtn.style.marginLeft = '15px'; const historyBtn = this.createIconButton('📜', 'سجل العمليات', '#ffffff', () => this.showHistoryModal()); historyBtn.style.fontSize = '18px'; historyBtn.style.marginLeft = '15px'; const saveBtn = this.createIconButton('💾', 'حفظ البيانات', '#ffffff', () => this.saveData()); saveBtn.style.fontSize = '18px'; saveBtn.style.marginLeft = '15px'; const loadBtn = this.createIconButton('📂', 'تحميل البيانات', '#ffffff', () => this.showLoadModal()); loadBtn.style.fontSize = '18px'; loadBtn.style.marginLeft = '15px'; const resetBtn = this.createIconButton('🔄', 'إعادة تعيين الأرباح', '#ffffff', () => this.resetProfits()); resetBtn.style.fontSize = '18px'; resetBtn.style.marginLeft = '15px'; const closeBtn = this.createIconButton('✖', 'إغلاق', '#ffffff', () => this.hideMainWindow()); closeBtn.style.fontSize = '18px'; closeBtn.style.marginLeft = '15px'; this.titleBar.appendChild(titleText); this.titleBar.appendChild(profitsText); this.titleBar.appendChild(themeToggleBtn); this.titleBar.appendChild(addItemBtn); this.titleBar.appendChild(addBorrowerBtn); this.titleBar.appendChild(historyBtn); this.titleBar.appendChild(saveBtn); this.titleBar.appendChild(loadBtn); this.titleBar.appendChild(resetBtn); this.titleBar.appendChild(closeBtn); this.contentArea = document.createElement('div'); this.contentArea.style.height = 'calc(100% - 50px)'; this.contentArea.style.overflow = 'hidden'; this.contentArea.style.display = 'flex'; this.contentArea.style.flexDirection = 'column'; const tabs = document.createElement('div'); tabs.style.display = 'flex'; tabs.style.borderBottom = '1px solid var(--border-color)'; tabs.style.backgroundColor = this.darkMode ? '#333' : '#ecf0f1'; const inventoryTab = document.createElement('button'); inventoryTab.textContent = 'المخزون'; inventoryTab.style.padding = '12px 20px'; inventoryTab.style.border = 'none'; inventoryTab.style.background = this.currentView === 'inventory' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); inventoryTab.style.cursor = 'pointer'; inventoryTab.style.fontWeight = 'bold'; inventoryTab.style.fontSize = '16px'; inventoryTab.style.color = this.darkMode ? '#fff' : '#333'; inventoryTab.addEventListener('click', () => this.switchView('inventory')); const borrowersTab = document.createElement('button'); borrowersTab.textContent = 'المقترضين'; borrowersTab.style.padding = '12px 20px'; borrowersTab.style.border = 'none'; borrowersTab.style.background = this.currentView === 'borrowers' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); borrowersTab.style.cursor = 'pointer'; borrowersTab.style.fontSize = '16px'; borrowersTab.style.color = this.darkMode ? '#fff' : '#333'; borrowersTab.addEventListener('click', () => this.switchView('borrowers')); tabs.appendChild(inventoryTab); tabs.appendChild(borrowersTab); this.inventoryList = document.createElement('div'); this.inventoryList.style.overflowY = 'auto'; this.inventoryList.style.flexGrow = '1'; this.inventoryList.style.padding = '15px'; this.inventoryList.style.display = 'grid'; this.inventoryList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.inventoryList.style.gap = '15px'; this.borrowersList = document.createElement('div'); this.borrowersList.style.overflowY = 'auto'; this.borrowersList.style.flexGrow = '1'; this.borrowersList.style.padding = '15px'; this.borrowersList.style.display = 'none'; this.borrowersList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.borrowersList.style.gap = '15px'; this.contentArea.appendChild(tabs); this.contentArea.appendChild(this.inventoryList); this.contentArea.appendChild(this.borrowersList); this.mainWindow.appendChild(this.titleBar); this.mainWindow.appendChild(this.contentArea); document.body.appendChild(this.mainWindow); this.addAnimations(); this.loadData(); } createIconButton(icon, title, color, clickHandler) { const btn = document.createElement('button'); btn.innerHTML = `${icon} ${title}`; btn.style.background = 'none'; btn.style.border = 'none'; btn.style.color = color; btn.style.cursor = 'pointer'; btn.style.display = 'flex'; btn.style.alignItems = 'center'; btn.title = title; btn.addEventListener('click', clickHandler); return btn; } addAnimations() { const style = document.createElement('style'); style.textContent = ` @keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -45%); } to { opacity: 1; transform: translate(-50%, -50%); } } `; document.head.appendChild(style); } hideMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'none'; } } switchView(view) { this.currentView = view; if (view === 'inventory') { this.inventoryList.style.display = 'grid'; this.borrowersList.style.display = 'none'; this.renderInventory(); } else { this.inventoryList.style.display = 'none'; this.borrowersList.style.display = 'grid'; this.renderBorrowers(); } } showAddItemModal() { const modal = this.createModal('إضافة سلعة جديدة', '#27ae60'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم السلعة:', 'text'); const quantityInput = this.createInputField('الكمية:', 'number'); quantityInput.input.min = '0'; const alertInput = this.createInputField('التنبيه عند:', 'number'); alertInput.input.min = '0'; const priceInput = this.createInputField('سعر البيع:', 'number'); priceInput.input.min = '0'; const costInput = this.createInputField('تكلفة الشراء:', 'number'); costInput.input.min = '0'; costInput.input.value = '0'; form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(quantityInput.label); form.appendChild(quantityInput.input); form.appendChild(alertInput.label); form.appendChild(alertInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(costInput.label); form.appendChild(costInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#27ae60', () => { const item = { id: Date.now(), name: nameInput.input.value, quantity: parseInt(quantityInput.input.value) || 0, alertAt: parseInt(alertInput.input.value) || 0, price: parseInt(priceInput.input.value) || 0, cost: parseInt(costInput.input.value) || 0, originalQuantity: parseInt(quantityInput.input.value) || 0 }; this.inventory.push(item); this.logTransaction('إضافة سلعة', `تم إضافة ${item.name} - الكمية: ${item.quantity}`); this.renderInventory(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showAddBorrowerModal() { const modal = this.createModal('إضافة مقترض جديد', '#3498db'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم المقترض:', 'text'); const itemInput = this.createInputField('السلعة:', 'text'); const priceInput = this.createInputField('السعر:', 'number'); priceInput.input.min = '0'; const dateInput = this.createInputField('تاريخ الإقتراض:', 'date'); const dueDateInput = this.createInputField('تاريخ الاستحقاق:', 'date'); form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(itemInput.label); form.appendChild(itemInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(dateInput.label); form.appendChild(dateInput.input); form.appendChild(dueDateInput.label); form.appendChild(dueDateInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#3498db', () => { const borrower = { id: Date.now(), name: nameInput.input.value, item: itemInput.input.value, price: parseInt(priceInput.input.value) || 0, date: dateInput.input.value || new Date().toISOString().split('T')[0], dueDate: dueDateInput.input.value || '', returned: false }; this.borrowers.push(borrower); this.logTransaction('إضافة مقترض', `تم إضافة ${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } createModal(title, color) { const modal = document.createElement('div'); modal.style.position = 'fixed'; modal.style.top = '50%'; modal.style.left = '50%'; modal.style.transform = 'translate(-50%, -50%)'; modal.style.width = '450px'; modal.style.maxWidth = '90%'; modal.style.backgroundColor = 'var(--card-bg)'; modal.style.color = 'var(--text-color)'; modal.style.padding = '20px'; modal.style.borderRadius = '10px'; modal.style.boxShadow = '0 5px 15px rgba(0, 0, 0, 0.2)'; modal.style.zIndex = '10000'; modal.style.fontFamily = 'Arial, sans-serif'; const closeBtn = document.createElement('button'); closeBtn.innerHTML = '✖'; closeBtn.style.position = 'absolute'; closeBtn.style.top = '10px'; closeBtn.style.right = '10px'; closeBtn.style.background = 'none'; closeBtn.style.border = 'none'; closeBtn.style.cursor = 'pointer'; closeBtn.style.fontSize = '18px'; closeBtn.style.color = '#7f8c8d'; closeBtn.addEventListener('click', () => modal.remove()); const titleElement = document.createElement('h3'); titleElement.textContent = title; titleElement.style.margin = '0 0 15px 0'; titleElement.style.color = color; titleElement.style.textAlign = 'center'; titleElement.style.fontSize = '18px'; const content = document.createElement('div'); modal.appendChild(closeBtn); modal.appendChild(titleElement); modal.appendChild(content); return { element: modal, content: content }; } createInputField(labelText, inputType) { const label = document.createElement('label'); label.textContent = labelText; label.style.display = 'block'; label.style.marginBottom = '5px'; label.style.fontWeight = '600'; label.style.color = this.darkMode ? '#fff' : '#2c3e50'; label.style.fontSize = '14px'; const input = document.createElement('input'); input.type = inputType; input.style.width = '100%'; input.style.padding = '10px'; input.style.border = '1px solid var(--border-color)'; input.style.borderRadius = '5px'; input.style.fontSize = '14px'; input.style.backgroundColor = 'var(--input-bg)'; input.style.color = 'var(--input-text)'; return { label, input }; } createActionButton(text, color, clickHandler) { const button = document.createElement('button'); button.textContent = text; button.style.padding = '10px 20px'; button.style.border = 'none'; button.style.background = color; button.style.color = 'white'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; button.style.fontSize = '14px'; button.style.fontWeight = 'bold'; button.addEventListener('click', clickHandler); return button; } renderInventory() { this.inventoryList.innerHTML = ''; if (this.inventory.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد عناصر في المخزون'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.inventoryList.appendChild(emptyMessage); return; } const capitalElement = document.createElement('div'); capitalElement.style.padding = '10px'; capitalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#8e44ad'; capitalElement.style.color = 'white'; capitalElement.style.borderRadius = '5px'; capitalElement.style.marginBottom = '10px'; capitalElement.style.fontWeight = 'bold'; capitalElement.style.textAlign = 'center'; capitalElement.style.gridColumn = '1 / -1'; const totalCapital = this.getTotalCapital(); capitalElement.textContent = `رأس المال المستثمر: ${totalCapital} د.ج`; this.inventoryList.appendChild(capitalElement); this.inventory.forEach(item => { const itemElement = document.createElement('div'); itemElement.className = 'item-card'; itemElement.style.padding = '15px'; itemElement.style.border = '1px solid var(--border-color)'; itemElement.style.borderRadius = '8px'; itemElement.style.backgroundColor = item.quantity <= item.alertAt ? (this.darkMode ? '#3a1a1a' : '#ffebee') : 'var(--card-bg)'; itemElement.style.display = 'flex'; itemElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = item.name; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const quantityElement = document.createElement('div'); quantityElement.textContent = `الكمية: ${item.quantity}/${item.originalQuantity}`; quantityElement.style.marginBottom = '5px'; quantityElement.style.color = item.quantity <= item.alertAt ? '#e74c3c' : (this.darkMode ? '#ddd' : '#34495e'); quantityElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `سعر البيع: ${item.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const costElement = document.createElement('div'); costElement.textContent = `تكلفة الشراء: ${item.cost} د.ج`; costElement.style.marginBottom = '5px'; costElement.style.color = this.darkMode ? '#ddd' : '#34495e'; costElement.style.fontSize = '14px'; const profit = item.price - item.cost; const profitElement = document.createElement('div'); profitElement.textContent = `الربح: ${profit} د.ج`; profitElement.style.marginBottom = '5px'; profitElement.style.color = profit > 0 ? '#27ae60' : '#e74c3c'; profitElement.style.fontWeight = profit > 0 ? 'bold' : 'normal'; profitElement.style.fontSize = '14px'; const alertElement = document.createElement('div'); alertElement.textContent = `التنبيه عند: ${item.alertAt}`; alertElement.style.marginBottom = '10px'; alertElement.style.color = '#e67e22'; alertElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.inventory = this.inventory.filter(i => i.id !== item.id); this.logTransaction('حذف سلعة', `تم حذف ${item.name}`); this.renderInventory(); }); deleteBtn.style.fontSize = '16px'; const increaseBtn = this.createIconButton('➕', 'زيادة', '#27ae60', () => { item.quantity++; this.logTransaction('زيادة كمية', `${item.name} - الكمية الجديدة: ${item.quantity}`); this.renderInventory(); }); increaseBtn.style.fontSize = '16px'; const decreaseBtn = this.createIconButton('➖', 'نقصان', '#f39c12', () => { if (item.quantity > 0) { item.quantity--; this.profits += item.price; this.logTransaction('بيع سلعة', `${item.name} - الكمية المتبقية: ${item.quantity} - السعر: ${item.price} د.ج`); this.updateProfitsDisplay(); this.renderInventory(); } }); decreaseBtn.style.fontSize = '16px'; actionsDiv.appendChild(decreaseBtn); actionsDiv.appendChild(increaseBtn); actionsDiv.appendChild(deleteBtn); itemElement.appendChild(nameElement); itemElement.appendChild(quantityElement); itemElement.appendChild(priceElement); itemElement.appendChild(costElement); itemElement.appendChild(profitElement); itemElement.appendChild(alertElement); itemElement.appendChild(actionsDiv); this.inventoryList.appendChild(itemElement); }); } renderBorrowers() { this.borrowersList.innerHTML = ''; const totalElement = document.createElement('div'); totalElement.style.padding = '10px'; totalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#3498db'; totalElement.style.color = 'white'; totalElement.style.borderRadius = '5px'; totalElement.style.marginBottom = '10px'; totalElement.style.fontWeight = 'bold'; totalElement.style.textAlign = 'center'; totalElement.style.gridColumn = '1 / -1'; const total = this.borrowers.reduce((sum, borrower) => sum + borrower.price, 0); totalElement.textContent = `إجمالي القروض: ${total} د.ج`; this.borrowersList.appendChild(totalElement); if (this.borrowers.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد سجلات للمقترضين'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.borrowersList.appendChild(emptyMessage); return; } const today = new Date(); today.setHours(0, 0, 0, 0); this.borrowers.forEach(borrower => { const dueDate = borrower.dueDate ? new Date(borrower.dueDate) : null; dueDate?.setHours(0, 0, 0, 0); const isOverdue = dueDate && dueDate < today; const isDueToday = dueDate && dueDate.getTime() === today.getTime(); const borrowerElement = document.createElement('div'); borrowerElement.className = 'borrower-card'; borrowerElement.style.padding = '15px'; borrowerElement.style.border = '1px solid var(--border-color)'; borrowerElement.style.borderRadius = '8px'; borrowerElement.style.backgroundColor = isOverdue ? (this.darkMode ? '#3a1a1a' : '#ffebee') : isDueToday ? (this.darkMode ? '#3a2e0f' : '#fff3e0') : (this.darkMode ? '#1a2a3a' : '#e3f2fd'); borrowerElement.style.display = 'flex'; borrowerElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = `اسم المقترض: ${borrower.name}`; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const itemElement = document.createElement('div'); itemElement.textContent = `السلعة: ${borrower.item}`; itemElement.style.marginBottom = '5px'; itemElement.style.color = this.darkMode ? '#ddd' : '#34495e'; itemElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `السعر: ${borrower.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const dateElement = document.createElement('div'); dateElement.textContent = `تاريخ الإقتراض: ${borrower.date}`; dateElement.style.marginBottom = '5px'; dateElement.style.color = '#7f8c8d'; dateElement.style.fontSize = '14px'; const dueDateElement = document.createElement('div'); dueDateElement.textContent = `تاريخ الاستحقاق: ${borrower.dueDate || 'غير محدد'}`; dueDateElement.style.marginBottom = '5px'; dueDateElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#7f8c8d'; dueDateElement.style.fontWeight = isOverdue || isDueToday ? 'bold' : 'normal'; dueDateElement.style.fontSize = '14px'; const statusElement = document.createElement('div'); statusElement.textContent = `الحالة: ${isOverdue ? 'متأخر' : isDueToday ? 'ينتهي اليوم' : 'جاري'}`; statusElement.style.marginBottom = '10px'; statusElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#27ae60'; statusElement.style.fontWeight = 'bold'; statusElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.logTransaction('حذف مقترض', `${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); }); deleteBtn.style.fontSize = '16px'; const returnBtn = this.createIconButton('🔄', 'تسديد', '#27ae60', () => { borrower.returned = true; this.profits += borrower.price; this.logTransaction('تسديد قرض', `${borrower.name} - المبلغ: ${borrower.price} د.ج`); this.updateProfitsDisplay(); this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.renderBorrowers(); }); returnBtn.style.fontSize = '16px'; actionsDiv.appendChild(returnBtn); actionsDiv.appendChild(deleteBtn); borrowerElement.appendChild(nameElement); borrowerElement.appendChild(itemElement); borrowerElement.appendChild(priceElement); borrowerElement.appendChild(dateElement); borrowerElement.appendChild(dueDateElement); borrowerElement.appendChild(statusElement); borrowerElement.appendChild(actionsDiv); this.borrowersList.appendChild(borrowerElement); }); } updateProfitsDisplay() { if (this.titleBar) { const profitsDisplay = document.getElementById('profits-display'); if (profitsDisplay) { profitsDisplay.textContent = `الأرباح: ${this.profits} د.ج`; } } } resetProfits() { this.logTransaction('إعادة تعيين الأرباح', `تم إعادة التعيين من ${this.profits} إلى 0`); this.profits = 0; this.updateProfitsDisplay(); this.showNotification('تم إعادة تعيين الأرباح بنجاح', '#3498db'); } saveData() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `inventory_data_${new Date().toISOString().split('T')[0]}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); this.showNotification('تم حفظ البيانات بنجاح!', '#27ae60'); } showLoadModal() { const modal = this.createModal('تحميل البيانات', '#3498db'); const infoText = document.createElement('p'); infoText.textContent = 'اختر طريقة تحميل البيانات:'; infoText.style.textAlign = 'center'; infoText.style.marginBottom = '20px'; infoText.style.color = this.darkMode ? '#fff' : '#2c3e50'; infoText.style.fontSize = '15px'; modal.content.appendChild(infoText); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.flexDirection = 'column'; buttonsDiv.style.gap = '10px'; const loadLocalBtn = this.createActionButton('تحميل من التخزين المحلي', '#2ecc71', () => { this.loadData(); modal.element.remove(); this.showNotification('تم تحميل البيانات من التخزين المحلي', '#2ecc71'); }); loadLocalBtn.style.width = '100%'; loadLocalBtn.style.padding = '12px'; const loadFileBtn = this.createActionButton('تحميل من ملف', '#3498db', () => { this.showFilePicker(); modal.element.remove(); }); loadFileBtn.style.width = '100%'; loadFileBtn.style.padding = '12px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); cancelBtn.style.width = '100%'; cancelBtn.style.padding = '12px'; buttonsDiv.appendChild(loadLocalBtn); buttonsDiv.appendChild(loadFileBtn); buttonsDiv.appendChild(cancelBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showFilePicker() { const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.style.display = 'none'; input.addEventListener('change', (event) => { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { try { const data = JSON.parse(e.target.result); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } this.showNotification('تم تحميل البيانات من الملف بنجاح', '#2ecc71'); } catch (error) { console.error('Error loading file:', error); this.showNotification('حدث خطأ أثناء تحميل الملف', '#e74c3c'); } }; reader.readAsText(file); }); document.body.appendChild(input); input.click(); document.body.removeChild(input); } loadData() { const savedData = localStorage.getItem(this.storageKey); if (savedData) { try { const data = JSON.parse(savedData); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } } catch (e) { console.error('Failed to parse saved data', e); } } } showNotification(message, color) { const notification = document.createElement('div'); notification.textContent = message; notification.style.position = 'fixed'; notification.style.bottom = '20px'; notification.style.left = '50%'; notification.style.transform = 'translateX(-50%)'; notification.style.backgroundColor = color; notification.style.color = 'white'; notification.style.padding = '10px 20px'; notification.style.borderRadius = '5px'; notification.style.zIndex = '10001'; notification.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)'; notification.style.fontSize = '14px'; notification.style.fontWeight = 'bold'; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } logTransaction(action, details) { const transaction = { id: Date.now(), timestamp: new Date().toISOString(), action, details }; this.transactionHistory.push(transaction); this.autoSave(); } autoSave() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); } showHistoryModal() { const modal = this.createModal('سجل العمليات', '#9b59b6'); const historyContainer = document.createElement('div'); historyContainer.style.maxHeight = '400px'; historyContainer.style.overflowY = 'auto'; historyContainer.style.padding = '10px'; historyContainer.style.border = '1px solid var(--border-color)'; historyContainer.style.borderRadius = '5px'; historyContainer.style.marginBottom = '15px'; if (this.transactionHistory.length === 0) { historyContainer.innerHTML = '<p style="text-align:center;color:#7f8c8d">لا توجد عمليات مسجلة</p>'; } else { this.transactionHistory.slice().reverse().forEach(transaction => { const entry = document.createElement('div'); entry.style.padding = '8px'; entry.style.borderBottom = '1px solid var(--border-color)'; entry.style.fontSize = '13px'; const date = new Date(transaction.timestamp); const dateStr = date.toLocaleString('ar-EG', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); entry.innerHTML = ` <div style="display:flex;justify-content:space-between"> <strong>${transaction.action}</strong> <span style="color:#7f8c8d">${dateStr}</span> </div> <div style="margin-top:3px;color:#555">${transaction.details}</div> `; historyContainer.appendChild(entry); }); } modal.content.appendChild(historyContainer); const closeBtn = this.createActionButton('إغلاق', '#7f8c8d', () => modal.element.remove()); closeBtn.style.width = '100%'; modal.content.appendChild(closeBtn); document.body.appendChild(modal.element); } getTotalProfits() { return this.profits; } getInventoryCount() { return this.inventory.length; } getBorrowersCount() { return this.borrowers.length; } getTotalCapital() { return this.inventory.reduce((total, item) => total + (item.cost || 0), 0); } getNetProfit() { return this.profits - this.getTotalCapital(); } } Scratch.extensions.register(new InventoryManagement()); })(Scratch); المرجو تغيير ارقام جدول التاريخ من ارقام العربيه الى ارقام الغربيه ............وهذا الكود اريد تحويله الى سكراتش
إدارة المخزون بلغة عربية
(function(Scratch) { "use strict"; class InventoryManagement { constructor() { this.inventory = []; this.borrowers = []; this.profits = 0; this.mainWindow = null; this.titleBar = null; this.contentArea = null; this.inventoryList = null; this.borrowersList = null; this.currentView = 'inventory'; this.storageKey = 'inventory_management_data'; this.darkMode = false; this.transactionHistory = []; this.initTheme(); } getInfo() { return { id: 'inventoryManagement', name: 'إدارة المخزون', color1: '#2ecc71', color2: '#27ae60', color3: '#229954', blocks: [ { opcode: 'showMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إظهار نافذة إدارة المخزون' }, { opcode: 'hideMainWindow', blockType: Scratch.BlockType.COMMAND, text: 'إخفاء نافذة إدارة المخزون' }, { opcode: 'getTotalProfits', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي الأرباح' }, { opcode: 'getInventoryCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد العناصر في المخزون' }, { opcode: 'getBorrowersCount', blockType: Scratch.BlockType.REPORTER, text: 'عدد المقترضين' }, { opcode: 'getTotalCapital', blockType: Scratch.BlockType.REPORTER, text: 'إجمالي رأس المال المستثمر' }, { opcode: 'getNetProfit', blockType: Scratch.BlockType.REPORTER, text: 'صافي الأرباح' }, { opcode: 'resetProfits', blockType: Scratch.BlockType.COMMAND, text: 'إعادة تعيين الأرباح' } ], menus: {} }; } initTheme() { const savedTheme = localStorage.getItem(`${this.storageKey}_theme`); this.darkMode = savedTheme === 'dark'; this.applyTheme(); } applyTheme() { if (this.darkMode) { document.documentElement.style.setProperty('--bg-color', '#1a1a1a'); document.documentElement.style.setProperty('--text-color', '#ffffff'); document.documentElement.style.setProperty('--card-bg', '#2d2d2d'); document.documentElement.style.setProperty('--border-color', '#444'); document.documentElement.style.setProperty('--input-bg', '#333'); document.documentElement.style.setProperty('--input-text', '#fff'); } else { document.documentElement.style.setProperty('--bg-color', '#f8f9fa'); document.documentElement.style.setProperty('--text-color', '#333333'); document.documentElement.style.setProperty('--card-bg', '#ffffff'); document.documentElement.style.setProperty('--border-color', '#ddd'); document.documentElement.style.setProperty('--input-bg', '#fff'); document.documentElement.style.setProperty('--input-text', '#333'); } } toggleDarkMode() { this.darkMode = !this.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); this.updateWindowStyles(); } updateWindowStyles() { if (!this.mainWindow) return; if (this.darkMode) { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#1e8449'; } else { this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.titleBar.style.backgroundColor = '#27ae60'; } } showMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'block'; return; } this.mainWindow = document.createElement('div'); this.mainWindow.style.position = 'fixed'; this.mainWindow.style.top = '50%'; this.mainWindow.style.left = '50%'; this.mainWindow.style.transform = 'translate(-50%, -50%)'; this.mainWindow.style.width = '700px'; this.mainWindow.style.maxWidth = '90%'; this.mainWindow.style.height = '600px'; this.mainWindow.style.maxHeight = '90vh'; this.mainWindow.style.backgroundColor = 'var(--bg-color)'; this.mainWindow.style.color = 'var(--text-color)'; this.mainWindow.style.borderRadius = '15px'; this.mainWindow.style.boxShadow = '0 8px 16px rgba(0, 0, 0, 0.2)'; this.mainWindow.style.zIndex = '9999'; this.mainWindow.style.overflow = 'hidden'; this.mainWindow.style.display = 'block'; this.mainWindow.style.fontFamily = 'Arial, sans-serif'; this.titleBar = document.createElement('div'); this.titleBar.style.backgroundColor = this.darkMode ? '#1e8449' : '#27ae60'; this.titleBar.style.color = 'white'; this.titleBar.style.padding = '15px 20px'; this.titleBar.style.display = 'flex'; this.titleBar.style.justifyContent = 'space-between'; this.titleBar.style.alignItems = 'center'; this.titleBar.style.borderTopLeftRadius = '15px'; this.titleBar.style.borderTopRightRadius = '15px'; const titleText = document.createElement('span'); titleText.textContent = 'إدارة المخزون والمقترضين'; titleText.style.fontWeight = 'bold'; titleText.style.fontSize = '20px'; const profitsText = document.createElement('span'); profitsText.id = 'profits-display'; profitsText.textContent = `الأرباح: ${this.profits} د.ج`; profitsText.style.marginLeft = 'auto'; profitsText.style.marginRight = '20px'; profitsText.style.fontSize = '16px'; profitsText.style.color = '#fff'; const themeToggleBtn = this.createIconButton( this.darkMode ? '🌞' : '🌙', this.darkMode ? 'الوضع الفاتح' : 'الوضع الداكن', '#ffffff', () => this.toggleDarkMode() ); themeToggleBtn.style.fontSize = '18px'; themeToggleBtn.style.marginLeft = '15px'; const addItemBtn = this.createIconButton('➕', 'إضافة سلعة', '#ffffff', () => this.showAddItemModal()); addItemBtn.style.fontSize = '18px'; const addBorrowerBtn = this.createIconButton('👥', 'إضافة مقترض', '#ffffff', () => this.showAddBorrowerModal()); addBorrowerBtn.style.fontSize = '18px'; addBorrowerBtn.style.marginLeft = '15px'; const historyBtn = this.createIconButton('📜', 'سجل العمليات', '#ffffff', () => this.showHistoryModal()); historyBtn.style.fontSize = '18px'; historyBtn.style.marginLeft = '15px'; const saveBtn = this.createIconButton('💾', 'حفظ البيانات', '#ffffff', () => this.saveData()); saveBtn.style.fontSize = '18px'; saveBtn.style.marginLeft = '15px'; const loadBtn = this.createIconButton('📂', 'تحميل البيانات', '#ffffff', () => this.showLoadModal()); loadBtn.style.fontSize = '18px'; loadBtn.style.marginLeft = '15px'; const resetBtn = this.createIconButton('🔄', 'إعادة تعيين الأرباح', '#ffffff', () => this.resetProfits()); resetBtn.style.fontSize = '18px'; resetBtn.style.marginLeft = '15px'; const closeBtn = this.createIconButton('✖', 'إغلاق', '#ffffff', () => this.hideMainWindow()); closeBtn.style.fontSize = '18px'; closeBtn.style.marginLeft = '15px'; this.titleBar.appendChild(titleText); this.titleBar.appendChild(profitsText); this.titleBar.appendChild(themeToggleBtn); this.titleBar.appendChild(addItemBtn); this.titleBar.appendChild(addBorrowerBtn); this.titleBar.appendChild(historyBtn); this.titleBar.appendChild(saveBtn); this.titleBar.appendChild(loadBtn); this.titleBar.appendChild(resetBtn); this.titleBar.appendChild(closeBtn); this.contentArea = document.createElement('div'); this.contentArea.style.height = 'calc(100% - 50px)'; this.contentArea.style.overflow = 'hidden'; this.contentArea.style.display = 'flex'; this.contentArea.style.flexDirection = 'column'; const tabs = document.createElement('div'); tabs.style.display = 'flex'; tabs.style.borderBottom = '1px solid var(--border-color)'; tabs.style.backgroundColor = this.darkMode ? '#333' : '#ecf0f1'; const inventoryTab = document.createElement('button'); inventoryTab.textContent = 'المخزون'; inventoryTab.style.padding = '12px 20px'; inventoryTab.style.border = 'none'; inventoryTab.style.background = this.currentView === 'inventory' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); inventoryTab.style.cursor = 'pointer'; inventoryTab.style.fontWeight = 'bold'; inventoryTab.style.fontSize = '16px'; inventoryTab.style.color = this.darkMode ? '#fff' : '#333'; inventoryTab.addEventListener('click', () => this.switchView('inventory')); const borrowersTab = document.createElement('button'); borrowersTab.textContent = 'المقترضين'; borrowersTab.style.padding = '12px 20px'; borrowersTab.style.border = 'none'; borrowersTab.style.background = this.currentView === 'borrowers' ? (this.darkMode ? '#555' : '#bdc3c7') : (this.darkMode ? '#333' : '#ecf0f1'); borrowersTab.style.cursor = 'pointer'; borrowersTab.style.fontSize = '16px'; borrowersTab.style.color = this.darkMode ? '#fff' : '#333'; borrowersTab.addEventListener('click', () => this.switchView('borrowers')); tabs.appendChild(inventoryTab); tabs.appendChild(borrowersTab); this.inventoryList = document.createElement('div'); this.inventoryList.style.overflowY = 'auto'; this.inventoryList.style.flexGrow = '1'; this.inventoryList.style.padding = '15px'; this.inventoryList.style.display = 'grid'; this.inventoryList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.inventoryList.style.gap = '15px'; this.borrowersList = document.createElement('div'); this.borrowersList.style.overflowY = 'auto'; this.borrowersList.style.flexGrow = '1'; this.borrowersList.style.padding = '15px'; this.borrowersList.style.display = 'none'; this.borrowersList.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))'; this.borrowersList.style.gap = '15px'; this.contentArea.appendChild(tabs); this.contentArea.appendChild(this.inventoryList); this.contentArea.appendChild(this.borrowersList); this.mainWindow.appendChild(this.titleBar); this.mainWindow.appendChild(this.contentArea); document.body.appendChild(this.mainWindow); this.addAnimations(); this.loadData(); } createIconButton(icon, title, color, clickHandler) { const btn = document.createElement('button'); btn.innerHTML = `${icon} ${title}`; btn.style.background = 'none'; btn.style.border = 'none'; btn.style.color = color; btn.style.cursor = 'pointer'; btn.style.display = 'flex'; btn.style.alignItems = 'center'; btn.title = title; btn.addEventListener('click', clickHandler); return btn; } addAnimations() { const style = document.createElement('style'); style.textContent = ` @keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -45%); } to { opacity: 1; transform: translate(-50%, -50%); } } `; document.head.appendChild(style); } hideMainWindow() { if (this.mainWindow) { this.mainWindow.style.display = 'none'; } } switchView(view) { this.currentView = view; if (view === 'inventory') { this.inventoryList.style.display = 'grid'; this.borrowersList.style.display = 'none'; this.renderInventory(); } else { this.inventoryList.style.display = 'none'; this.borrowersList.style.display = 'grid'; this.renderBorrowers(); } } showAddItemModal() { const modal = this.createModal('إضافة سلعة جديدة', '#27ae60'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم السلعة:', 'text'); const quantityInput = this.createInputField('الكمية:', 'number'); quantityInput.input.min = '0'; const alertInput = this.createInputField('التنبيه عند:', 'number'); alertInput.input.min = '0'; const priceInput = this.createInputField('سعر البيع:', 'number'); priceInput.input.min = '0'; const costInput = this.createInputField('تكلفة الشراء:', 'number'); costInput.input.min = '0'; costInput.input.value = '0'; form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(quantityInput.label); form.appendChild(quantityInput.input); form.appendChild(alertInput.label); form.appendChild(alertInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(costInput.label); form.appendChild(costInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#27ae60', () => { const item = { id: Date.now(), name: nameInput.input.value, quantity: parseInt(quantityInput.input.value) || 0, alertAt: parseInt(alertInput.input.value) || 0, price: parseInt(priceInput.input.value) || 0, cost: parseInt(costInput.input.value) || 0, originalQuantity: parseInt(quantityInput.input.value) || 0 }; this.inventory.push(item); this.logTransaction('إضافة سلعة', `تم إضافة ${item.name} - الكمية: ${item.quantity}`); this.renderInventory(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showAddBorrowerModal() { const modal = this.createModal('إضافة مقترض جديد', '#3498db'); const form = document.createElement('div'); form.style.display = 'flex'; form.style.flexDirection = 'column'; form.style.gap = '15px'; const nameInput = this.createInputField('اسم المقترض:', 'text'); const itemInput = this.createInputField('السلعة:', 'text'); const priceInput = this.createInputField('السعر:', 'number'); priceInput.input.min = '0'; const dateInput = this.createInputField('تاريخ الإقتراض:', 'date'); const dueDateInput = this.createInputField('تاريخ الاستحقاق:', 'date'); form.appendChild(nameInput.label); form.appendChild(nameInput.input); form.appendChild(itemInput.label); form.appendChild(itemInput.input); form.appendChild(priceInput.label); form.appendChild(priceInput.input); form.appendChild(dateInput.label); form.appendChild(dateInput.input); form.appendChild(dueDateInput.label); form.appendChild(dueDateInput.input); modal.content.appendChild(form); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.justifyContent = 'flex-end'; buttonsDiv.style.marginTop = '20px'; buttonsDiv.style.gap = '10px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); const confirmBtn = this.createActionButton('تم', '#3498db', () => { const borrower = { id: Date.now(), name: nameInput.input.value, item: itemInput.input.value, price: parseInt(priceInput.input.value) || 0, date: dateInput.input.value || new Date().toISOString().split('T')[0], dueDate: dueDateInput.input.value || '', returned: false }; this.borrowers.push(borrower); this.logTransaction('إضافة مقترض', `تم إضافة ${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); modal.element.remove(); }); buttonsDiv.appendChild(cancelBtn); buttonsDiv.appendChild(confirmBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } createModal(title, color) { const modal = document.createElement('div'); modal.style.position = 'fixed'; modal.style.top = '50%'; modal.style.left = '50%'; modal.style.transform = 'translate(-50%, -50%)'; modal.style.width = '450px'; modal.style.maxWidth = '90%'; modal.style.backgroundColor = 'var(--card-bg)'; modal.style.color = 'var(--text-color)'; modal.style.padding = '20px'; modal.style.borderRadius = '10px'; modal.style.boxShadow = '0 5px 15px rgba(0, 0, 0, 0.2)'; modal.style.zIndex = '10000'; modal.style.fontFamily = 'Arial, sans-serif'; const closeBtn = document.createElement('button'); closeBtn.innerHTML = '✖'; closeBtn.style.position = 'absolute'; closeBtn.style.top = '10px'; closeBtn.style.right = '10px'; closeBtn.style.background = 'none'; closeBtn.style.border = 'none'; closeBtn.style.cursor = 'pointer'; closeBtn.style.fontSize = '18px'; closeBtn.style.color = '#7f8c8d'; closeBtn.addEventListener('click', () => modal.remove()); const titleElement = document.createElement('h3'); titleElement.textContent = title; titleElement.style.margin = '0 0 15px 0'; titleElement.style.color = color; titleElement.style.textAlign = 'center'; titleElement.style.fontSize = '18px'; const content = document.createElement('div'); modal.appendChild(closeBtn); modal.appendChild(titleElement); modal.appendChild(content); return { element: modal, content: content }; } createInputField(labelText, inputType) { const label = document.createElement('label'); label.textContent = labelText; label.style.display = 'block'; label.style.marginBottom = '5px'; label.style.fontWeight = '600'; label.style.color = this.darkMode ? '#fff' : '#2c3e50'; label.style.fontSize = '14px'; const input = document.createElement('input'); input.type = inputType; input.style.width = '100%'; input.style.padding = '10px'; input.style.border = '1px solid var(--border-color)'; input.style.borderRadius = '5px'; input.style.fontSize = '14px'; input.style.backgroundColor = 'var(--input-bg)'; input.style.color = 'var(--input-text)'; return { label, input }; } createActionButton(text, color, clickHandler) { const button = document.createElement('button'); button.textContent = text; button.style.padding = '10px 20px'; button.style.border = 'none'; button.style.background = color; button.style.color = 'white'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; button.style.fontSize = '14px'; button.style.fontWeight = 'bold'; button.addEventListener('click', clickHandler); return button; } renderInventory() { this.inventoryList.innerHTML = ''; if (this.inventory.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد عناصر في المخزون'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.inventoryList.appendChild(emptyMessage); return; } const capitalElement = document.createElement('div'); capitalElement.style.padding = '10px'; capitalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#8e44ad'; capitalElement.style.color = 'white'; capitalElement.style.borderRadius = '5px'; capitalElement.style.marginBottom = '10px'; capitalElement.style.fontWeight = 'bold'; capitalElement.style.textAlign = 'center'; capitalElement.style.gridColumn = '1 / -1'; const totalCapital = this.getTotalCapital(); capitalElement.textContent = `رأس المال المستثمر: ${totalCapital} د.ج`; this.inventoryList.appendChild(capitalElement); this.inventory.forEach(item => { const itemElement = document.createElement('div'); itemElement.className = 'item-card'; itemElement.style.padding = '15px'; itemElement.style.border = '1px solid var(--border-color)'; itemElement.style.borderRadius = '8px'; itemElement.style.backgroundColor = item.quantity <= item.alertAt ? (this.darkMode ? '#3a1a1a' : '#ffebee') : 'var(--card-bg)'; itemElement.style.display = 'flex'; itemElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = item.name; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const quantityElement = document.createElement('div'); quantityElement.textContent = `الكمية: ${item.quantity}/${item.originalQuantity}`; quantityElement.style.marginBottom = '5px'; quantityElement.style.color = item.quantity <= item.alertAt ? '#e74c3c' : (this.darkMode ? '#ddd' : '#34495e'); quantityElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `سعر البيع: ${item.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const costElement = document.createElement('div'); costElement.textContent = `تكلفة الشراء: ${item.cost} د.ج`; costElement.style.marginBottom = '5px'; costElement.style.color = this.darkMode ? '#ddd' : '#34495e'; costElement.style.fontSize = '14px'; const profit = item.price - item.cost; const profitElement = document.createElement('div'); profitElement.textContent = `الربح: ${profit} د.ج`; profitElement.style.marginBottom = '5px'; profitElement.style.color = profit > 0 ? '#27ae60' : '#e74c3c'; profitElement.style.fontWeight = profit > 0 ? 'bold' : 'normal'; profitElement.style.fontSize = '14px'; const alertElement = document.createElement('div'); alertElement.textContent = `التنبيه عند: ${item.alertAt}`; alertElement.style.marginBottom = '10px'; alertElement.style.color = '#e67e22'; alertElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.inventory = this.inventory.filter(i => i.id !== item.id); this.logTransaction('حذف سلعة', `تم حذف ${item.name}`); this.renderInventory(); }); deleteBtn.style.fontSize = '16px'; const increaseBtn = this.createIconButton('➕', 'زيادة', '#27ae60', () => { item.quantity++; this.logTransaction('زيادة كمية', `${item.name} - الكمية الجديدة: ${item.quantity}`); this.renderInventory(); }); increaseBtn.style.fontSize = '16px'; const decreaseBtn = this.createIconButton('➖', 'نقصان', '#f39c12', () => { if (item.quantity > 0) { item.quantity--; this.profits += item.price; this.logTransaction('بيع سلعة', `${item.name} - الكمية المتبقية: ${item.quantity} - السعر: ${item.price} د.ج`); this.updateProfitsDisplay(); this.renderInventory(); } }); decreaseBtn.style.fontSize = '16px'; actionsDiv.appendChild(decreaseBtn); actionsDiv.appendChild(increaseBtn); actionsDiv.appendChild(deleteBtn); itemElement.appendChild(nameElement); itemElement.appendChild(quantityElement); itemElement.appendChild(priceElement); itemElement.appendChild(costElement); itemElement.appendChild(profitElement); itemElement.appendChild(alertElement); itemElement.appendChild(actionsDiv); this.inventoryList.appendChild(itemElement); }); } renderBorrowers() { this.borrowersList.innerHTML = ''; const totalElement = document.createElement('div'); totalElement.style.padding = '10px'; totalElement.style.backgroundColor = this.darkMode ? '#2c3e50' : '#3498db'; totalElement.style.color = 'white'; totalElement.style.borderRadius = '5px'; totalElement.style.marginBottom = '10px'; totalElement.style.fontWeight = 'bold'; totalElement.style.textAlign = 'center'; totalElement.style.gridColumn = '1 / -1'; const total = this.borrowers.reduce((sum, borrower) => sum + borrower.price, 0); totalElement.textContent = `إجمالي القروض: ${total} د.ج`; this.borrowersList.appendChild(totalElement); if (this.borrowers.length === 0) { const emptyMessage = document.createElement('div'); emptyMessage.textContent = 'لا توجد سجلات للمقترضين'; emptyMessage.style.textAlign = 'center'; emptyMessage.style.padding = '30px'; emptyMessage.style.color = '#7f8c8d'; emptyMessage.style.gridColumn = '1 / -1'; this.borrowersList.appendChild(emptyMessage); return; } const today = new Date(); today.setHours(0, 0, 0, 0); this.borrowers.forEach(borrower => { const dueDate = borrower.dueDate ? new Date(borrower.dueDate) : null; dueDate?.setHours(0, 0, 0, 0); const isOverdue = dueDate && dueDate < today; const isDueToday = dueDate && dueDate.getTime() === today.getTime(); const borrowerElement = document.createElement('div'); borrowerElement.className = 'borrower-card'; borrowerElement.style.padding = '15px'; borrowerElement.style.border = '1px solid var(--border-color)'; borrowerElement.style.borderRadius = '8px'; borrowerElement.style.backgroundColor = isOverdue ? (this.darkMode ? '#3a1a1a' : '#ffebee') : isDueToday ? (this.darkMode ? '#3a2e0f' : '#fff3e0') : (this.darkMode ? '#1a2a3a' : '#e3f2fd'); borrowerElement.style.display = 'flex'; borrowerElement.style.flexDirection = 'column'; const nameElement = document.createElement('div'); nameElement.textContent = `اسم المقترض: ${borrower.name}`; nameElement.style.fontWeight = 'bold'; nameElement.style.fontSize = '16px'; nameElement.style.marginBottom = '8px'; nameElement.style.color = this.darkMode ? '#fff' : '#2c3e50'; const itemElement = document.createElement('div'); itemElement.textContent = `السلعة: ${borrower.item}`; itemElement.style.marginBottom = '5px'; itemElement.style.color = this.darkMode ? '#ddd' : '#34495e'; itemElement.style.fontSize = '14px'; const priceElement = document.createElement('div'); priceElement.textContent = `السعر: ${borrower.price} د.ج`; priceElement.style.marginBottom = '5px'; priceElement.style.color = this.darkMode ? '#ddd' : '#34495e'; priceElement.style.fontSize = '14px'; const dateElement = document.createElement('div'); dateElement.textContent = `تاريخ الإقتراض: ${borrower.date}`; dateElement.style.marginBottom = '5px'; dateElement.style.color = '#7f8c8d'; dateElement.style.fontSize = '14px'; const dueDateElement = document.createElement('div'); dueDateElement.textContent = `تاريخ الاستحقاق: ${borrower.dueDate || 'غير محدد'}`; dueDateElement.style.marginBottom = '5px'; dueDateElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#7f8c8d'; dueDateElement.style.fontWeight = isOverdue || isDueToday ? 'bold' : 'normal'; dueDateElement.style.fontSize = '14px'; const statusElement = document.createElement('div'); statusElement.textContent = `الحالة: ${isOverdue ? 'متأخر' : isDueToday ? 'ينتهي اليوم' : 'جاري'}`; statusElement.style.marginBottom = '10px'; statusElement.style.color = isOverdue ? '#e74c3c' : isDueToday ? '#f39c12' : '#27ae60'; statusElement.style.fontWeight = 'bold'; statusElement.style.fontSize = '14px'; const actionsDiv = document.createElement('div'); actionsDiv.style.display = 'flex'; actionsDiv.style.justifyContent = 'flex-end'; actionsDiv.style.marginTop = 'auto'; actionsDiv.style.gap = '8px'; const deleteBtn = this.createIconButton('🗑️', 'حذف', '#e74c3c', () => { this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.logTransaction('حذف مقترض', `${borrower.name} - السلعة: ${borrower.item}`); this.renderBorrowers(); }); deleteBtn.style.fontSize = '16px'; const returnBtn = this.createIconButton('🔄', 'تسديد', '#27ae60', () => { borrower.returned = true; this.profits += borrower.price; this.logTransaction('تسديد قرض', `${borrower.name} - المبلغ: ${borrower.price} د.ج`); this.updateProfitsDisplay(); this.borrowers = this.borrowers.filter(b => b.id !== borrower.id); this.renderBorrowers(); }); returnBtn.style.fontSize = '16px'; actionsDiv.appendChild(returnBtn); actionsDiv.appendChild(deleteBtn); borrowerElement.appendChild(nameElement); borrowerElement.appendChild(itemElement); borrowerElement.appendChild(priceElement); borrowerElement.appendChild(dateElement); borrowerElement.appendChild(dueDateElement); borrowerElement.appendChild(statusElement); borrowerElement.appendChild(actionsDiv); this.borrowersList.appendChild(borrowerElement); }); } updateProfitsDisplay() { if (this.titleBar) { const profitsDisplay = document.getElementById('profits-display'); if (profitsDisplay) { profitsDisplay.textContent = `الأرباح: ${this.profits} د.ج`; } } } resetProfits() { this.logTransaction('إعادة تعيين الأرباح', `تم إعادة التعيين من ${this.profits} إلى 0`); this.profits = 0; this.updateProfitsDisplay(); this.showNotification('تم إعادة تعيين الأرباح بنجاح', '#3498db'); } saveData() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `inventory_data_${new Date().toISOString().split('T')[0]}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); this.showNotification('تم حفظ البيانات بنجاح!', '#27ae60'); } showLoadModal() { const modal = this.createModal('تحميل البيانات', '#3498db'); const infoText = document.createElement('p'); infoText.textContent = 'اختر طريقة تحميل البيانات:'; infoText.style.textAlign = 'center'; infoText.style.marginBottom = '20px'; infoText.style.color = this.darkMode ? '#fff' : '#2c3e50'; infoText.style.fontSize = '15px'; modal.content.appendChild(infoText); const buttonsDiv = document.createElement('div'); buttonsDiv.style.display = 'flex'; buttonsDiv.style.flexDirection = 'column'; buttonsDiv.style.gap = '10px'; const loadLocalBtn = this.createActionButton('تحميل من التخزين المحلي', '#2ecc71', () => { this.loadData(); modal.element.remove(); this.showNotification('تم تحميل البيانات من التخزين المحلي', '#2ecc71'); }); loadLocalBtn.style.width = '100%'; loadLocalBtn.style.padding = '12px'; const loadFileBtn = this.createActionButton('تحميل من ملف', '#3498db', () => { this.showFilePicker(); modal.element.remove(); }); loadFileBtn.style.width = '100%'; loadFileBtn.style.padding = '12px'; const cancelBtn = this.createActionButton('إلغاء', '#e74c3c', () => modal.element.remove()); cancelBtn.style.width = '100%'; cancelBtn.style.padding = '12px'; buttonsDiv.appendChild(loadLocalBtn); buttonsDiv.appendChild(loadFileBtn); buttonsDiv.appendChild(cancelBtn); modal.content.appendChild(buttonsDiv); document.body.appendChild(modal.element); } showFilePicker() { const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.style.display = 'none'; input.addEventListener('change', (event) => { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { try { const data = JSON.parse(e.target.result); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } this.showNotification('تم تحميل البيانات من الملف بنجاح', '#2ecc71'); } catch (error) { console.error('Error loading file:', error); this.showNotification('حدث خطأ أثناء تحميل الملف', '#e74c3c'); } }; reader.readAsText(file); }); document.body.appendChild(input); input.click(); document.body.removeChild(input); } loadData() { const savedData = localStorage.getItem(this.storageKey); if (savedData) { try { const data = JSON.parse(savedData); this.inventory = data.inventory || []; this.borrowers = data.borrowers || []; this.profits = data.profits || 0; this.transactionHistory = data.transactionHistory || []; if (data.darkMode !== undefined) { this.darkMode = data.darkMode; localStorage.setItem(`${this.storageKey}_theme`, this.darkMode ? 'dark' : 'light'); this.applyTheme(); } this.updateProfitsDisplay(); if (this.currentView === 'inventory') { this.renderInventory(); } else { this.renderBorrowers(); } } catch (e) { console.error('Failed to parse saved data', e); } } } showNotification(message, color) { const notification = document.createElement('div'); notification.textContent = message; notification.style.position = 'fixed'; notification.style.bottom = '20px'; notification.style.left = '50%'; notification.style.transform = 'translateX(-50%)'; notification.style.backgroundColor = color; notification.style.color = 'white'; notification.style.padding = '10px 20px'; notification.style.borderRadius = '5px'; notification.style.zIndex = '10001'; notification.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)'; notification.style.fontSize = '14px'; notification.style.fontWeight = 'bold'; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } logTransaction(action, details) { const transaction = { id: Date.now(), timestamp: new Date().toISOString(), action, details }; this.transactionHistory.push(transaction); this.autoSave(); } autoSave() { const data = { inventory: this.inventory, borrowers: this.borrowers, profits: this.profits, transactionHistory: this.transactionHistory, darkMode: this.darkMode }; localStorage.setItem(this.storageKey, JSON.stringify(data)); } showHistoryModal() { const modal = this.createModal('سجل العمليات', '#9b59b6'); const historyContainer = document.createElement('div'); historyContainer.style.maxHeight = '400px'; historyContainer.style.overflowY = 'auto'; historyContainer.style.padding = '10px'; historyContainer.style.border = '1px solid var(--border-color)'; historyContainer.style.borderRadius = '5px'; historyContainer.style.marginBottom = '15px'; if (this.transactionHistory.length === 0) { historyContainer.innerHTML = '<p style="text-align:center;color:#7f8c8d">لا توجد عمليات مسجلة</p>'; } else { this.transactionHistory.slice().reverse().forEach(transaction => { const entry = document.createElement('div'); entry.style.padding = '8px'; entry.style.borderBottom = '1px solid var(--border-color)'; entry.style.fontSize = '13px'; const date = new Date(transaction.timestamp); const dateStr = date.toLocaleString('ar-EG', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); entry.innerHTML = ` <div style="display:flex;justify-content:space-between"> <strong>${transaction.action}</strong> <span style="color:#7f8c8d">${dateStr}</span> </div> <div style="margin-top:3px;color:#555">${transaction.details}</div> `; historyContainer.appendChild(entry); }); } modal.content.appendChild(historyContainer); const closeBtn = this.createActionButton('إغلاق', '#7f8c8d', () => modal.element.remove()); closeBtn.style.width = '100%'; modal.content.appendChild(closeBtn); document.body.appendChild(modal.element); } getTotalProfits() { return this.profits; } getInventoryCount() { return this.inventory.length; } getBorrowersCount() { return this.borrowers.length; } getTotalCapital() { return this.inventory.reduce((total, item) => total + (item.cost || 0), 0); } getNetProfit() { return this.profits - this.getTotalCapital(); } } Scratch.extensions.register(new InventoryManagement()); })(Scratch); المرجو تغيير ارقام جدول التاريخ من ارقام العربيه الى ارقام الغربيه ............وهذا الكود اريد تحويله الى سكراتش
كود حساب العمر
كود حساب العمر
