fix: keep from_date/to_date as source of truth in payroll register
Add visible year/quarter selectors that sync hidden from_date/to_date filters so the formula editor (which injects from_date via $AyIlSpecial) keeps working without knowing about the quarter UI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f609d8064d
commit
ec95dda8c2
|
|
@ -1,15 +1,45 @@
|
|||
// Copyright (c) 2026, Taxes Az and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
function quarter_dates(year, quarter) {
|
||||
const q = parseInt(quarter, 10);
|
||||
const y = parseInt(year, 10);
|
||||
const start_month = (q - 1) * 3;
|
||||
const end_month = start_month + 2;
|
||||
const start = new Date(y, start_month, 1);
|
||||
const end = new Date(y, end_month + 1, 0);
|
||||
return {
|
||||
from_date: frappe.datetime.obj_to_str(start).slice(0, 10),
|
||||
to_date: frappe.datetime.obj_to_str(end).slice(0, 10),
|
||||
};
|
||||
}
|
||||
|
||||
function sync_quarter_dates(report) {
|
||||
const year = report.get_filter_value("year");
|
||||
const quarter = report.get_filter_value("quarter");
|
||||
if (!year || !quarter) return;
|
||||
const { from_date, to_date } = quarter_dates(year, quarter);
|
||||
report.set_filter_value("from_date", from_date);
|
||||
report.set_filter_value("to_date", to_date);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const current_quarter = String(Math.ceil((now.getMonth() + 1) / 3));
|
||||
const default_dates = quarter_dates(now.getFullYear(), current_quarter);
|
||||
|
||||
frappe.query_reports["Employee Payroll Register"] = {
|
||||
filters: [
|
||||
{
|
||||
fieldname: "year",
|
||||
label: __("Year"),
|
||||
fieldtype: "Int",
|
||||
default: new Date().getFullYear(),
|
||||
default: now.getFullYear(),
|
||||
reqd: 1,
|
||||
width: "80px",
|
||||
on_change: function () {
|
||||
sync_quarter_dates(frappe.query_report);
|
||||
frappe.query_report.refresh();
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "quarter",
|
||||
|
|
@ -21,9 +51,27 @@ frappe.query_reports["Employee Payroll Register"] = {
|
|||
{ value: "3", label: __("Q3 (Jul – Sep)") },
|
||||
{ value: "4", label: __("Q4 (Oct – Dec)") },
|
||||
],
|
||||
default: String(Math.ceil((new Date().getMonth() + 1) / 3)),
|
||||
default: current_quarter,
|
||||
reqd: 1,
|
||||
width: "120px",
|
||||
on_change: function () {
|
||||
sync_quarter_dates(frappe.query_report);
|
||||
frappe.query_report.refresh();
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "from_date",
|
||||
label: __("From"),
|
||||
fieldtype: "Date",
|
||||
default: default_dates.from_date,
|
||||
hidden: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "to_date",
|
||||
label: __("To"),
|
||||
fieldtype: "Date",
|
||||
default: default_dates.to_date,
|
||||
hidden: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "company",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from datetime import date
|
|||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
from frappe.utils import flt, getdate
|
||||
|
||||
import erpnext
|
||||
|
||||
|
|
@ -42,13 +42,16 @@ def execute(filters=None):
|
|||
if not filters:
|
||||
filters = {}
|
||||
|
||||
today = date.today()
|
||||
year = int(filters.get("year") or today.year)
|
||||
quarter = int(filters.get("quarter") or ((today.month - 1) // 3 + 1))
|
||||
start_month = (quarter - 1) * 3 + 1
|
||||
if filters.get("from_date"):
|
||||
fd = getdate(filters["from_date"])
|
||||
else:
|
||||
today = date.today()
|
||||
quarter = (today.month - 1) // 3 + 1
|
||||
fd = date(today.year, (quarter - 1) * 3 + 1, 1)
|
||||
start_month = (fd.month - 1) // 3 * 3 + 1
|
||||
end_month = start_month + 2
|
||||
from_date = date(year, start_month, 1)
|
||||
to_date = date(year, end_month, monthrange(year, end_month)[1])
|
||||
from_date = date(fd.year, start_month, 1)
|
||||
to_date = date(fd.year, end_month, monthrange(fd.year, end_month)[1])
|
||||
|
||||
currency = "AZN"
|
||||
company_currency = erpnext.get_company_currency(filters.get("company"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue