Make Available Leave HTML Table
This commit is contained in:
parent
c7ccd3ca2e
commit
4bd5583e11
@ -18,7 +18,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
doctype: frm.doc.doctype
|
doctype: frm.doc.doctype
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("employee", erpnext.queries.employee);
|
frm.set_query("employee", erpnext.queries.employee);
|
||||||
},
|
},
|
||||||
@ -27,6 +27,33 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
frm.toggle_reqd("half_day_date", frm.doc.half_day == 1);
|
frm.toggle_reqd("half_day_date", frm.doc.half_day == 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
make_dashboard: function(frm) {
|
||||||
|
var leave_details;
|
||||||
|
if (frm.doc.employee) {
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
|
||||||
|
async: false,
|
||||||
|
args: {
|
||||||
|
employee: frm.doc.employee,
|
||||||
|
date: frm.doc.posting_date
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
if (!r.exc && r.message) {
|
||||||
|
leave_details = r.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("div").remove(".form-dashboard-section");
|
||||||
|
let section = frm.dashboard.add_section(
|
||||||
|
frappe.render_template('leave_application_dashboard', {
|
||||||
|
data: leave_details
|
||||||
|
})
|
||||||
|
);
|
||||||
|
frm.dashboard.show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
if (frm.is_new()) {
|
if (frm.is_new()) {
|
||||||
frm.trigger("calculate_total_days");
|
frm.trigger("calculate_total_days");
|
||||||
@ -43,6 +70,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
employee: function(frm) {
|
employee: function(frm) {
|
||||||
|
frm.trigger("make_dashboard");
|
||||||
frm.trigger("get_leave_balance");
|
frm.trigger("get_leave_balance");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ class NotAnOptionalHoliday(frappe.ValidationError): pass
|
|||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
class LeaveApplication(Document):
|
class LeaveApplication(Document):
|
||||||
|
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
return _("{0}: From {0} of type {1}").format(self.employee_name, self.leave_type)
|
return _("{0}: From {0} of type {1}").format(self.employee_name, self.leave_type)
|
||||||
|
|
||||||
@ -306,6 +307,24 @@ def get_number_of_leave_days(employee, leave_type, from_date, to_date, half_day
|
|||||||
number_of_days = flt(number_of_days) - flt(get_holidays(employee, from_date, to_date))
|
number_of_days = flt(number_of_days) - flt(get_holidays(employee, from_date, to_date))
|
||||||
return number_of_days
|
return number_of_days
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_leave_details(employee, date):
|
||||||
|
allocation_records = get_leave_allocation_records(date, employee).get(employee, frappe._dict())
|
||||||
|
leave_allocation = {}
|
||||||
|
for d in allocation_records:
|
||||||
|
allocation = allocation_records.get(d, frappe._dict())
|
||||||
|
date = allocation.to_date
|
||||||
|
leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, date, status="Approved")
|
||||||
|
leaves_pending = get_leaves_for_period(employee, d, allocation.from_date, date, status="Open")
|
||||||
|
remaining_leaves = allocation.total_leaves_allocated - leaves_taken - leaves_pending
|
||||||
|
leave_allocation[d] = {
|
||||||
|
"total_leaves": allocation.total_leaves_allocated,
|
||||||
|
"leaves_taken": leaves_taken,
|
||||||
|
"pending_leaves": leaves_pending,
|
||||||
|
"remaining_leaves": remaining_leaves}
|
||||||
|
|
||||||
|
return leave_allocation
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
||||||
consider_all_leaves_in_the_allocation_period=False):
|
consider_all_leaves_in_the_allocation_period=False):
|
||||||
@ -316,16 +335,16 @@ def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
|||||||
|
|
||||||
if consider_all_leaves_in_the_allocation_period:
|
if consider_all_leaves_in_the_allocation_period:
|
||||||
date = allocation.to_date
|
date = allocation.to_date
|
||||||
leaves_taken = get_approved_leaves_for_period(employee, leave_type, allocation.from_date, date)
|
leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, date, status=Approved)
|
||||||
|
|
||||||
return flt(allocation.total_leaves_allocated) - flt(leaves_taken)
|
return flt(allocation.total_leaves_allocated) - flt(leaves_taken)
|
||||||
|
|
||||||
def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):
|
def get_leaves_for_period(employee, leave_type, from_date, to_date, status):
|
||||||
leave_applications = frappe.db.sql("""
|
leave_applications = frappe.db.sql("""
|
||||||
select employee, leave_type, from_date, to_date, total_leave_days
|
select employee, leave_type, from_date, to_date, total_leave_days
|
||||||
from `tabLeave Application`
|
from `tabLeave Application`
|
||||||
where employee=%(employee)s and leave_type=%(leave_type)s
|
where employee=%(employee)s and leave_type=%(leave_type)s
|
||||||
and docstatus=1
|
and status = %(status)s and docstatus=1
|
||||||
and (from_date between %(from_date)s and %(to_date)s
|
and (from_date between %(from_date)s and %(to_date)s
|
||||||
or to_date between %(from_date)s and %(to_date)s
|
or to_date between %(from_date)s and %(to_date)s
|
||||||
or (from_date < %(from_date)s and to_date > %(to_date)s))
|
or (from_date < %(from_date)s and to_date > %(to_date)s))
|
||||||
@ -333,6 +352,7 @@ def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):
|
|||||||
"from_date": from_date,
|
"from_date": from_date,
|
||||||
"to_date": to_date,
|
"to_date": to_date,
|
||||||
"employee": employee,
|
"employee": employee,
|
||||||
|
"status": status,
|
||||||
"leave_type": leave_type
|
"leave_type": leave_type
|
||||||
}, as_dict=1)
|
}, as_dict=1)
|
||||||
|
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
{% if data %}
|
||||||
|
<h5 style="margin-top: 20px;"> {{ __("Allocated Leaves") }} </h5>
|
||||||
|
<table class="table table-bordered small">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 20%">{{ __("Leave Type") }}</th>
|
||||||
|
<th style="width: 20%" class="text-right">{{ __("Total Allocated Leaves") }}</th>
|
||||||
|
<th style="width: 20%" class="text-right">{{ __("Used Leaves") }}</th>
|
||||||
|
<th style="width: 20%" class="text-right">{{ __("Pending Leaves") }}</th>
|
||||||
|
<th style="width: 20%" class="text-right">{{ __("Available Leaves") }}</th>
|
||||||
|
</tr>
|
||||||
|
<!-- <p> {{data["Sick Leave"][0]["leaves_taken"]}}</p> -->
|
||||||
|
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for(const [key, value] of Object.entries(data)) { %}
|
||||||
|
<tr>
|
||||||
|
<td> {%= key %} </td>
|
||||||
|
<td> {%= value["total_leaves"] %} </td>
|
||||||
|
<td> {%= value["leaves_taken"] %} </td>
|
||||||
|
<td> {%= value["pending_leaves"] %} </td>
|
||||||
|
<td> {%= value["remaining_leaves"] %} </td>
|
||||||
|
</tr>
|
||||||
|
{% } %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% } else { %}
|
||||||
|
<p style="margin-top: 30px;"> No Leaves have been allocated. </p>
|
||||||
|
{% } %}
|
Loading…
x
Reference in New Issue
Block a user