Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

// medicalcare.js frappe.queryreports["Medical Care"] = { "filters": [ { "fieldname":…

  1. User

    // medical_care.js

    frappe.query_reports["Medical Care"] = { "filters": [ { "fieldname": "employee", "label": __("Employee"), "fieldtype": "Link", "options": "Employee", "width": "120", "on_change": function() { const employee = frappe.query_report.get_filter_value('employee'); const department_filter = frappe.query_report.get_filter('department');

                if (employee) {
                    // جعل فلتر الإدارة للقراءة فقط
                    department_filter.df.read_only = 1;
                    department_filter.refresh();
    
                    // إخفاء عمود الإدارة في التقرير
                    frappe.query_report.toggle_column('department', true);
                } else {
                    // إعادة تفعيل فلتر الإدارة وجعله قابل للتعديل
                    department_filter.df.read_only = 0;
                    department_filter.refresh();
    
                    // إظهار عمود الإدارة في التقرير
                    frappe.query_report.toggle_column('department', false);
                }
    
                // إذا تم تحديد الإدارة مسبقًا، إخفاء عمود الموظف
                const department = frappe.query_report.get_filter_value('department');
                if (department) {
                    frappe.query_report.toggle_column('employee_name', true);
                } else {
                    frappe.query_report.toggle_column('employee_name', false);
                }
    
                // تحديث التقرير لتطبيق التعديلات
                frappe.query_report.refresh();
            }
        },
        {
            "fieldname": "department",
            "label": __("Department"),
            "fieldtype": "Link",
            "options": "Department",
            "width": "120",
            "on_change": function() {
                const department = frappe.query_report.get_filter_value('department');
                const employee_filter = frappe.query_report.get_filter('employee');
    
                if (department) {
                    // تفريغ فلتر الموظف وجعله غير قابل للتعديل
                    frappe.query_report.set_filter_value('employee', null);
                    employee_filter.df.read_only = 1;
                    employee_filter.refresh();
    
                    // إخفاء عمود الموظف في التقرير
                    frappe.query_report.toggle_column('employee_name', true);
                } else {
                    // إعادة تفعيل فلتر الموظف وجعله قابل للتعديل
                    employee_filter.df.read_only = 0;
                    employee_filter.refresh();
    
                    // إظهار عمود الموظف في التقرير
                    frappe.query_report.toggle_column('employee_name', false);
                }
    
                // إذا تم تحديد الموظف مسبقًا، إخفاء عمود الإدارة
                const employee = frappe.query_report.get_filter_value('employee');
                if (employee) {
                    frappe.query_report.toggle_column('department', true);
                } else {
                    frappe.query_report.toggle_column('department', false);
                }
    
                // تحديث التقرير لتطبيق التعديلات
                frappe.query_report.refresh();
            }
        },
        {
            "fieldname": "cost_center",
            "label": __("Cost Center"),
            "fieldtype": "Link",
            "options": "Cost Center",
            "width": "120"
        },
        {
            "fieldname": "custom_employee_type",
            "label": __("Employment Type"),
            "fieldtype": "Link",
            "options": "Employment Type",
            "width": "120"
        },
        {
            "fieldname": "from_date",
            "label": __("From Date"),
            "fieldtype": "Date",
            "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), // تعيين تاريخ افتراضي لشهر ماضي
            "reqd": 1,
            "width": "120"
        },
        {
            "fieldname": "to_date",
            "label": __("To Date"),
            "fieldtype": "Date",
            "default": frappe.datetime.get_today(),
            "reqd": 1,
            "width": "120"
        }
    ],
    "formatter": function(value, row, column, data, default_formatter) {
        return default_formatter(value, row, column, data);
    },
    "onload": function(report) {
        // عند تحميل التقرير، وإخفاء الأعمدة بناءً على القيم الحالية للفلاتر
        const employee = frappe.query_report.get_filter_value('employee');
        const department = frappe.query_report.get_filter_value('department');
    
        if (employee) {
            frappe.query_report.toggle_column('department', true);
        }
    
        if (department) {
            frappe.query_report.toggle_column('employee_name', true);
        }
    
        // تحديث التقرير بناءً على حالة الفلاتر
        frappe.query_report.refresh();
    },
    "before_run": function() {
        // قبل تنفيذ التقرير، يمكن إضافة تحقق من صحة الفلاتر هنا إذا لزم الأمر
    },
    "after_refresh": function(report) {
        // بعد تحديث التقرير، يمكن إضافة وظائف إضافية هنا إذا لزم الأمر
    },
    "toggle_column": function(column_name, hide) {
        // دالة مساعدة لإخفاء أو إظهار الأعمدة
        const columns = frappe.query_report.columns;
        for (let i = 0; i < columns.length; i++) {
            if (columns[i].fieldname === column_name) {
                frappe.query_report.toggle_display(columns[i].fieldname, !hide);
                break;
            }
        }
    }
    

    };

  2. Assistant

    The JavaScript code provided is for a report in a Frappe framework application, specifically designed to handle the "Medical Care" report. It includes a set of filters related to employee records and manages their visibility based on user inputs. Below is a brief explanation of its key components:

    Key Components

    1. Filters Setup:

      • The report has several filters for users to specify the data they wish to query:
        • Employee: A link to the Employee document. It becomes read-only if an employee is selected, and the department filter is automatically made read-only as well.
        • Department: A link to the Department document. It triggers similar behavior: if a department is selected, the employee filter is cleared and made read-only.
        • Cost Center, Employment Type, From Date, and To Date: Additional filters to refine the query.
    2. Dynamic Behavior:

      • The report dynamically shows or hides filters and columns based on user selection. For example:
        • Selecting an employee disables the department filter and hides the department column in the report.
        • Conversely, selecting a department disables the employee filter and hides the employee column.
    3. Handling Column Visibility:

      • A helper function toggle_column is defined to abstract the logic of showing or hiding columns in the report based on the current filter state.
    4. Report Lifecycle Hooks:

      • The report has lifecycle hooks like onload, before_run, and after_refresh that allow developers to modify the report state before it is rendered or after it is refreshed.
    5. Automatic Date Settings:

      • The date filters default to one month prior for the "From Date" and today’s date for the "To Date," ensuring the user has a sensible date range to start with.

    Customization & Enhancements

    • Validation Logic: The before_run function provides a placeholder for adding validation logic for the filters before the report is run, which is crucial for ensuring that the report executes with valid filter parameters.

    • Localization Support: The use of the __() function suggests that the code is ready for localization, which is essential for multi-language support in applications.

    Usage

    This setup is particularly useful for HR departments or medical care administrators needing to generate reports based on specific employee attributes and department data. The dynamic adjustment of filters and columns improves user experience by simplifying the interface based on the user's selection, allowing for more focused reporting and analysis.

    This report configuration can be a foundational element in building a more comprehensive HR or medical care management application within the Frappe framework.

  3. User

    اريد ان اضيف ايقونه للموظف في عمود الموظفين

  4. Assistant

    لإضافة أيقونة إلى عمود الموظفين ضمن تقرير "الرعاية الطبية" في تطبيق Frappe، يمكنك تعديل دالة formatter الخاصة بالتقرير. يُستخدم formatter لتخصيص تنسيق القيم في الأعمدة، بما في ذلك إضافة أيقونات أو تعديلات على النصوص المعروضة.

    إليك كيفية تعديل دالة formatter لإضافة أيقونة بجانب اسم الموظف:

    "formatter": function(value, row, column, data, default_formatter) {
        if (column.fieldname === 'employee_name') {
            // إضافة الأيقونة قبل اسم الموظف
            return `<img src="/path/to/icon.png" style="width:16px; height:16px; margin-right:5px;" /> ${value}`;
        }
        return default_formatter(value, row, column, data);
    }
    

    الشرح:

    • شرط if: يتحقق مما إذا كانت القيمة الحالية في العمود هي عمود اسم الموظف (employee_name).
    • إضافة الأيقونة: يتم استخدام علامة <img> لإضافة الأيقونة، يجب عليك تحديد المسار الصحيح لملف الأيقونة (/path/to/icon.png).
    • تنسيق الأيقونة: تم تعيين حجم الأيقونة باستخدام CSS (style="width:16px; height:16px; margin-right:5px;") لضمان عدم تداخلها مع اسم الموظف.
    • إرجاع القيمة: يتم دمج الأيقونة مع قيمة الموظف (value) وإرجاعها.

    ملاحظات:

    1. المسار إلى الأيقونة: تأكد من استخدام المسار الصحيح للأيقونة في مجلد الأصول الخاص بتطبيقك.
    2. التخصيص الإضافي: يمكنك تخصيص حجم الأيقونة والهوامش وفقًا لتصميم واجهة المستخدم الخاص بك.
    3. اختبار: بعد إجراء التغييرات، تأكد من اختبار التقرير للتأكد من أن الأيقونات تظهر بشكل صحيح وتعمل كما هو متوقع.

    بعد إضافة هذا الكود، ستظهر الأيقونة بجانب أسماء الموظفين في العمود المخصص لذلك.