<reponame>mohsinalimat/branch<filename>branch/branch/report/trial_balance_branch/trial_balance_branch.js<gh_stars>0frappe.require("assets/branch/js/financial_statements_branch.js", function() {
	frappe.query_reports["Trial Balance Branch"] = {
		"filters": [
			{
				"fieldname": "company",
				"label": __("Company"),
				"fieldtype": "Link",
				"options": "Company",
				"default": frappe.defaults.get_user_default("Company"),
				"reqd": 1
			},
			{
				"fieldname": "company_branch",
				"label": __("Company Branch"),
				"fieldtype": "Link",
				"options": "Company Branch",
				get_query: () => {
				let company = frappe.query_report.get_filter_value("company");
				return {
					filters: {
						...company && {company},
					}
				}
			}
			},
			{
				"fieldname": "fiscal_year",
				"label": __("Fiscal Year"),
				"fieldtype": "Link",
				"options": "Fiscal Year",
				"default": frappe.defaults.get_user_default("fiscal_year"),
				// "reqd": 0,
				"on_change": function(query_report) {
					var fiscal_year = query_report.get_values().fiscal_year;
					if (!fiscal_year) {
						return;
					}
					frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) {
						var fy = frappe.model.get_doc("Fiscal Year", fiscal_year);
						frappe.query_report.set_filter_value({
							from_date: fy.year_start_date,
							to_date: fy.year_end_date
						});
					});
				}
			},
			{
				"fieldname": "from_date",
				"label": __("From Date"),
				"fieldtype": "Date",
				"default": frappe.defaults.get_user_default("year_start_date"),
			},
			{
				"fieldname": "to_date",
				"label": __("To Date"),
				"fieldtype": "Date",
				"default": frappe.defaults.get_user_default("year_end_date"),
			},
			{
				"fieldname": "cost_center",
				"label": __("Cost Center"),
				"fieldtype": "Link",
				"options": "Cost Center",
				"get_query": function() {
					var company = frappe.query_report.get_filter_value('company');
					return {
						"doctype": "Cost Center",
						"filters": {
							"company": company,
						}
					}
				}
			},
			{
				"fieldname": "project",
				"label": __("Project"),
				"fieldtype": "Link",
				"options": "Project"
			},
			{
				"fieldname": "finance_book",
				"label": __("Finance Book"),
				"fieldtype": "Link",
				"options": "Finance Book",
			},
			{
				"fieldname": "presentation_currency",
				"label": __("Currency"),
				"fieldtype": "Select",
				"options": erpnext.get_presentation_currency_list()
			},
			{
				"fieldname": "with_period_closing_entry",
				"label": __("Period Closing Entry"),
				"fieldtype": "Check",
				"default": 1
			},
			{
				"fieldname": "show_zero_values",
				"label": __("Show zero values"),
				"fieldtype": "Check"
			},
			{
				"fieldname": "show_unclosed_fy_pl_balances",
				"label": __("Show unclosed fiscal year's P&L balances"),
				"fieldtype": "Check"
			},
			{
				"fieldname": "include_default_book_entries",
				"label": __("Include Default Book Entries"),
				"fieldtype": "Check",
				"default": 1
			}
		],
		"formatter": branch.financial_statements_branch.formatter,
		"tree": true,
		"name_field": "account",
		"parent_field": "parent_account",
		"initial_depth": 3,

		onload: function(report) {
		const views_menu = report.page.add_custom_button_group(__('Financial Statements Branch'));
		report.page.add_custom_menu_item(views_menu, __("Balance Sheet Branch"), function() {
			var filters = report.get_values();
			frappe.set_route('query-report', 'Balance Sheet Branch', {company: filters.company});
		});

		report.page.add_custom_menu_item(views_menu, __("Profit and Loss Branch"), function() {
			var filters = report.get_values();
			frappe.set_route('query-report', 'Profit and Loss Statement Branch', {company: filters.company});
		});

		report.page.add_custom_menu_item(views_menu, __("Trial Balance Branch"), function() {
			var filters = report.get_values();
			frappe.set_route('query-report', 'Trial Balance Branch', {company: filters.company});
		});
	}
	}

	branch.utils.add_dimensions('Trial Balance Branch', 6);
});