Skip to content

Commit

Permalink
feat: Allocated Leaves Scedule on form dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Dec 8, 2023
1 parent 8fd4da4 commit 078bc6d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
61 changes: 39 additions & 22 deletions hrms/hr/doctype/leave_allocation/leave_allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ frappe.ui.form.on("Leave Allocation", {
query: "erpnext.controllers.queries.employee_query",
};
});

frm.set_query("leave_type", function () {
return {
filters: {
Expand All @@ -25,28 +26,6 @@ frappe.ui.form.on("Leave Allocation", {
});
},

make_dashboard: async function (frm) {
response = await frappe.db.get_value("Leave Type", frm.doc.leave_type, [
"is_earned_leave",
"earned_leave_frequency",
]);
leave_type = response.message;
if (
!leave_type.is_earned_leave ||
leave_type.earned_leave_frequency != "Monthly"
)
return;
$("div").remove(".form-dashboard-section.custom");

frm.dashboard.add_section(
frappe.render_template("leave_allocation_dashboard", {
data: leave_details,
}),
__("Allocated Leaves")
);
frm.dashboard.show();
},

refresh: function (frm) {
if (frm.doc.docstatus === 1 && frm.doc.expired) {
var valid_expiry = moment(frappe.datetime.get_today()).isBetween(
Expand Down Expand Up @@ -163,6 +142,7 @@ frappe.ui.form.on("Leave Allocation", {
);
}
},

calculate_total_leaves_allocated: function (frm) {
if (
cint(frm.doc.carry_forward) == 1 &&
Expand All @@ -184,6 +164,7 @@ frappe.ui.form.on("Leave Allocation", {
);
}
},

get_monthly_earned_leave: async function (frm) {
await frappe.run_serially([
() =>
Expand Down Expand Up @@ -213,7 +194,9 @@ frappe.ui.form.on("Leave Allocation", {
rounding: frm.rounding,
},
callback: function (r) {
frm.monthly_leaves = r.message;
frm.new_leaves = r.message;
frm.trigger("make_dashboard");
},
}),
]);
Expand All @@ -231,6 +214,40 @@ frappe.ui.form.on("Leave Allocation", {
},
});
},

make_dashboard: async function (frm) {
response = await frappe.db.get_value("Leave Type", frm.doc.leave_type, [
"is_earned_leave",
"earned_leave_frequency",
]);
leave_type = response.message;
if (
!leave_type.is_earned_leave ||
leave_type.earned_leave_frequency != "Monthly"
)
return;
$("div").remove(".form-dashboard-section.custom");

const from_date_array = frm.doc.from_date.split("-");
const from_month = from_date_array[1] - 1;
const to_date_array = frm.doc.to_date.split("-");
let to_month = to_date_array[1] - 1;
if (to_date_array[0] > from_date_array[0]) to_month += 12;

const months = [];
for (let i = from_month; i <= to_month; i++) {
months.push(moment().month(i).format("MMMM"));
}

frm.dashboard.add_section(
frappe.render_template("leave_allocation_dashboard", {
months: months,
monthly_leaves: frm.monthly_leaves,
}),
__("Allocated Leaves")
);
frm.dashboard.show();
},
});

frappe.tour["Leave Allocation"] = [
Expand Down
28 changes: 9 additions & 19 deletions hrms/hr/doctype/leave_allocation/leave_allocation_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@

{% if not jQuery.isEmptyObject(data) %}
{% if monthly_leaves %}
<table class="table table-bordered small">
<thead>
<tr>
<th style="width: 16%">{{ __("Leave Type") }}</th>
<th style="width: 16%" class="text-right">{{ __("Total Allocated Leaves") }}</th>
<th style="width: 16%" class="text-right">{{ __("Expired Leaves") }}</th>
<th style="width: 16%" class="text-right">{{ __("Used Leaves") }}</th>
<th style="width: 16%" class="text-right">{{ __("Leaves Pending Approval") }}</th>
<th style="width: 16%" class="text-right">{{ __("Available Leaves") }}</th>
<th style="width: 50%">{{ __("Month") }}</th>
<th style="width: 50%">{{ __("No. of Leaves") }}</th>
</tr>
</thead>
<tbody>
{% for(const [key, value] of Object.entries(data)) { %}
{% let color = cint(value["remaining_leaves"]) > 0 ? "green" : "red" %}
<tr>
<td> {%= key %} </td>
<td class="text-right"> {%= value["total_leaves"] %} </td>
<td class="text-right"> {%= value["expired_leaves"] %} </td>
<td class="text-right"> {%= value["leaves_taken"] %} </td>
<td class="text-right"> {%= value["leaves_pending_approval"] %} </td>
<td class="text-right" style="color: {{ color }}"> {%= value["remaining_leaves"] %} </td>
</tr>
{% for(const value of months) { %} {% %}
<tr>
<td>{%= value %}</td>
<td>{%= monthly_leaves %}</td>
</tr>
{% } %}
</tbody>
</table>
{% else %}
<p style="margin-top: 30px;"> No Leave has been allocated. </p>
<p style="margin-top: 30px">No Leave has been allocated.</p>
{% endif %}

0 comments on commit 078bc6d

Please sign in to comment.