Skip to content

Commit

Permalink
feat: Uniform Expiry Report
Browse files Browse the repository at this point in the history
  • Loading branch information
pjamsheer committed Nov 12, 2024
1 parent fd3dd2d commit 8166e73
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, omar jaber and contributors
// For license information, please see license.txt

frappe.query_reports["Uniform Expiry Report"] = {
"filters": [
{
"fieldname":"employee",
"label": __("Employee"),
"fieldtype": "Link",
"options": "Employee"
},
{
"fieldname":"issued_before",
"label": __("Issued Before"),
"fieldtype": "Date",
"default": frappe.datetime.now_date()
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"add_total_row": 1,
"columns": [],
"creation": "2024-11-11 22:02:06.810863",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letterhead": null,
"modified": "2024-11-11 22:02:13.596538",
"modified_by": "Administrator",
"module": "Uniform Management",
"name": "Uniform Expiry Report",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Employee Uniform",
"report_name": "Uniform Expiry Report",
"report_type": "Script Report",
"roles": [
{
"role": "System Manager"
},
{
"role": "Purchase Manager"
},
{
"role": "Accounts Manager"
},
{
"role": "Warehouse Maintainer"
},
{
"role": "Purchase Officer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2024, omar jaber and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import today, getdate, month_diff, date_diff

def execute(filters=None):
filters = frappe._dict(filters or {})
columns, data = get_columns(), get_data(filters)
return columns, data

def get_columns():
return [
_("Employee ID") + ":Data:130",
_("Employee Name") + ":Data:180",
_("Employee Status") + ":Data:140",
_("Designation") + ":Link/Designation:120",
_("Item Code") + ":Link/Item:180",
_("Item Name") + ":Data:180",
_("Issued On") + ":Date:130",
_("Warehouse") + ":Link/Warehouse:120",
_("Expire On") + ":Date:120",
_("Days Left for Expiry") + ":Data:180",
_("Issued Qty") + ":Data:120",
_("Returned Qty") + ":Data:120"
]

def get_data(filters):
data=[]
conditions = []

query = """
select
u.employee, u.employee_id, u.employee_name, ui.item, ui.item_name, ui.issued_on, ui.quantity,
ui.returned, ui.rate, ui.expire_on, u.designation, u.warehouse
from
`tabEmployee Uniform` u, `tabEmployee Uniform Item` ui
where
u.name = ui.parent and u.type='Issue' and u.docstatus = 1 and ui.quantity > ui.returned
"""

if filters.employee:
query += "and u.employee = '%s' "%filters.employee

if filters.issued_before:
query += "and u.issued_on <= '%s' "%filters.issued_before

uniform_list=frappe.db.sql(query,as_dict=1)
for uniform in uniform_list:
employee_status = frappe.db.get_value("Employee", uniform.employee, "status")
days_left_for_expiry = date_diff(uniform.expire_on, getdate())
row = [
uniform.employee_id, uniform.employee_name, employee_status, uniform.designation, uniform.item, uniform.item_name,
uniform.issued_on, uniform.warehouse, uniform.expire_on, days_left_for_expiry, uniform.quantity, uniform.returned
]
data.append(row)

return data

0 comments on commit 8166e73

Please sign in to comment.