Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GST Purchase Register Beta Report #2584

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright (c) 2024, Resilient Tech and contributors
// For license information, please see license.txt
const SUB_SECTION_MAPPING = {
4: {
"ITC Available": [
"Import Of Goods",
"Import Of Service",
"ITC on Reverse Charge",
"Input Service Distributor",
"All Other ITC",
],
"ITC Reversed": ["As per rules 42 & 43 of CGST Rules", "Others"],
"Ineligible ITC": ["Ineligible As Per Section 17(5)", "Others"],
},
5: {
"Composition Scheme, Exempted, Nil Rated": [
"Composition Scheme, Exempted, Nil Rated",
],
"Non-GST": ["Non-GST"],
},
};

frappe.query_reports["GST Purchase Register Beta"] = {
onload: set_category_options,

filters: [
{
fieldname: "company",
label: __("Company"),
fieldtype: "Link",
options: "Company",
reqd: 1,
default: frappe.defaults.get_user_default("Company"),
on_change: report => {
report.set_filter_value({
company_gstin: "",
});
report.refresh();
},
get_query: function () {
return {
filters: {
country: "India",
},
};
},
},
{
fieldname: "company_gstin",
label: __("Company GSTIN"),
fieldtype: "Autocomplete",
reqd: 1,
get_query() {
const company = frappe.query_report.get_filter_value("company");
return india_compliance.get_gstin_query(company);
},
},
{
fieldname: "date_range",
label: __("Date Range"),
fieldtype: "DateRange",
default: [
india_compliance.last_month_start(),
india_compliance.last_month_end(),
],
width: "80",
},
{
fieldtype: "Select",
fieldname: "summary_by",
label: __("Summary By"),
options: "Overview\nSummary by Item\nSummary by Invoice",
default: "Overview",
},
{
fieldtype: "Select",
fieldname: "sub_section",
label: __("Sub Section"),
options: [
{ value: "4", label: __("Eligible ITC") },
{
value: "5",
label: __(
"Values of exempt, nil rated and non-GST inward supplies"
),
},
],
default: "4",
reqd: 1,
on_change: report => {
report.set_filter_value("invoice_category", "");
set_category_options(report);
report.refresh();
},
},
{
fieldtype: "Autocomplete",
fieldname: "invoice_category",
label: __("Invoice Category"),
on_change: report => {
report.set_filter_value("invoice_sub_category", "");
set_sub_category_options(report);
report.refresh();
},
depends_on: 'eval:doc.summary_by!=="Overview"',
},
{
fieldtype: "Autocomplete",
fieldname: "invoice_sub_category",
label: __("Invoice Sub Category"),
depends_on: 'eval:doc.summary_by!=="Overview"',
},
],

formatter: (value, row, column, data, default_formatter) => {
value = default_formatter(value, row, column, data);
if (data && data.indent === 0) {
let $value = $(`<span>${value}</span>`).css("font-weight", "bold");
value = $value.wrap("<p></p>").parent().html();
}

return value;
},

// Override datatable hook for column total calculation
get_datatable_options(datatable_options) {
datatable_options.hooks = {
columnTotal: custom_report_column_total,
};

return datatable_options;
},
};

function set_sub_category_options(report) {
const invoice_category = report.get_filter_value("invoice_category");
const sub_section = report.get_filter_value("sub_section");
const sub_category = SUB_SECTION_MAPPING[sub_section][invoice_category];
report.get_filter("invoice_sub_category").set_data(sub_category || []);

if (invoice_category && sub_category.length === 1) {
report.set_filter_value("invoice_sub_category", sub_category[0]);
}
}

function set_category_options(report) {
const sub_section = report.get_filter_value("sub_section");
report
.get_filter("invoice_category")
.set_data(Object.keys(SUB_SECTION_MAPPING[sub_section]));
}

custom_report_column_total = function (...args) {
const summary_by = frappe.query_report.get_filter_value("summary_by");
if (summary_by !== "Overview")
return frappe.utils.report_column_total.apply(this, args);

const column_field = args[1].column.fieldname;
if (column_field === "description") return;

const total = this.datamanager.data.reduce((acc, row) => {
if (row.indent !== 1) acc += row[column_field] || 0;
return acc;
}, 0);

return total;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"add_total_row": 1,
"columns": [],
"creation": "2024-08-26 20:42:05.592632",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letterhead": null,
"modified": "2024-08-26 20:42:05.592632",
"modified_by": "Administrator",
"module": "GST India",
"name": "GST Purchase Register Beta",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Invoice",
"report_name": "GST Purchase Register Beta",
"report_type": "Script Report",
"roles": [
{
"role": "Purchase User"
},
{
"role": "Accounts User"
},
{
"role": "Auditor"
},
{
"role": "Accounts Manager"
}
]
}
Loading
Loading