|
| 1 | +// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors |
| 2 | +// For license information, please see license.txt |
| 3 | + |
| 4 | +frappe.query_reports["Leave Ledger"] = { |
| 5 | + filters: [ |
| 6 | + { |
| 7 | + fieldname: "from_date", |
| 8 | + label: __("From Date"), |
| 9 | + fieldtype: "Date", |
| 10 | + reqd: 1, |
| 11 | + default: frappe.defaults.get_default("year_start_date") |
| 12 | + }, |
| 13 | + { |
| 14 | + fieldname: "to_date", |
| 15 | + label: __("To Date"), |
| 16 | + fieldtype: "Date", |
| 17 | + reqd: 1, |
| 18 | + default: frappe.defaults.get_default("year_end_date") |
| 19 | + }, |
| 20 | + { |
| 21 | + fieldname: "leave_type", |
| 22 | + label: __("Leave Type"), |
| 23 | + fieldtype: "Link", |
| 24 | + options: "Leave Type", |
| 25 | + }, |
| 26 | + { |
| 27 | + fieldname: "employee", |
| 28 | + label: __("Employee"), |
| 29 | + fieldtype: "Link", |
| 30 | + options: "Employee", |
| 31 | + }, |
| 32 | + { |
| 33 | + fieldname: "status", |
| 34 | + label: __("Employee Status"), |
| 35 | + fieldtype: "Select", |
| 36 | + options: [ |
| 37 | + "", |
| 38 | + { "value": "Active", "label": __("Active") }, |
| 39 | + { "value": "Inactive", "label": __("Inactive") }, |
| 40 | + { "value": "Suspended", "label": __("Suspended") }, |
| 41 | + { "value": "Left", "label": __("Left") }, |
| 42 | + ], |
| 43 | + default: "Active", |
| 44 | + }, |
| 45 | + { |
| 46 | + label: __("Company"), |
| 47 | + fieldname: "company", |
| 48 | + fieldtype: "Link", |
| 49 | + options: "Company", |
| 50 | + default: frappe.defaults.get_user_default("Company") |
| 51 | + }, |
| 52 | + { |
| 53 | + fieldname: "department", |
| 54 | + label: __("Department"), |
| 55 | + fieldtype: "Link", |
| 56 | + options: "Department", |
| 57 | + }, |
| 58 | + { |
| 59 | + fieldname: "transaction_type", |
| 60 | + label: __("Transaction Type"), |
| 61 | + fieldtype: "Select", |
| 62 | + options: ["", "Leave Allocation", "Leave Application", "Leave Encashment"], |
| 63 | + }, |
| 64 | + { |
| 65 | + fieldname: "transaction_name", |
| 66 | + label: __("Transaction Name"), |
| 67 | + fieldtype: "Data", |
| 68 | + } |
| 69 | + ], |
| 70 | + formatter: (value, row, column, data, default_formatter) => { |
| 71 | + value = default_formatter(value, row, column, data); |
| 72 | + if (column.fieldname === "leaves") { |
| 73 | + if (data?.leaves < 0) |
| 74 | + value = `<span style='color:red!important'>${value}</span>`; |
| 75 | + else |
| 76 | + value = `<span style='color:green!important'>${value}</span>`; |
| 77 | + } |
| 78 | + return value; |
| 79 | + }, |
| 80 | + onload: () => { |
| 81 | + if ( |
| 82 | + frappe.query_report.get_filter_value("from_date") && |
| 83 | + frappe.query_report.get_filter_value("to_date") |
| 84 | + ) return; |
| 85 | + |
| 86 | + const today = frappe.datetime.now_date(); |
| 87 | + |
| 88 | + frappe.call({ |
| 89 | + type: "GET", |
| 90 | + method: "hrms.hr.utils.get_leave_period", |
| 91 | + args: { |
| 92 | + "from_date": today, |
| 93 | + "to_date": today, |
| 94 | + "company": frappe.defaults.get_user_default("Company") |
| 95 | + }, |
| 96 | + freeze: true, |
| 97 | + callback: (data) => { |
| 98 | + frappe.query_report.set_filter_value("from_date", data.message[0].from_date); |
| 99 | + frappe.query_report.set_filter_value("to_date", data.message[0].to_date); |
| 100 | + } |
| 101 | + }); |
| 102 | + } |
| 103 | +}; |
0 commit comments