| frappe.provide("erpnext.financial_statements"); |
| |
| erpnext.financial_statements = { |
| "filters": get_filters(), |
| "formatter": function(value, row, column, data, default_formatter) { |
| if (column.fieldname=="account") { |
| value = data.account_name; |
| |
| column.link_onclick = |
| "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")"; |
| column.is_tree = true; |
| } |
| |
| value = default_formatter(value, row, column, data); |
| |
| if (!data.parent_account) { |
| value = $(`<span>${value}</span>`); |
| |
| var $value = $(value).css("font-weight", "bold"); |
| if (data.warn_if_negative && data[column.fieldname] < 0) { |
| $value.addClass("text-danger"); |
| } |
| |
| value = $value.wrap("<p></p>").parent().html(); |
| } |
| |
| return value; |
| }, |
| "open_general_ledger": function(data) { |
| if (!data.account) return; |
| var project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; }) |
| |
| frappe.route_options = { |
| "account": data.account, |
| "company": frappe.query_report.get_filter_value('company'), |
| "from_date": data.from_date || data.year_start_date, |
| "to_date": data.to_date || data.year_end_date, |
| "project": (project && project.length > 0) ? project[0].$input.val() : "" |
| }; |
| frappe.set_route("query-report", "General Ledger"); |
| }, |
| "tree": true, |
| "name_field": "account", |
| "parent_field": "parent_account", |
| "initial_depth": 3, |
| onload: function(report) { |
| // dropdown for links to other financial statements |
| erpnext.financial_statements.filters = get_filters() |
| |
| report.page.add_inner_button(__("Balance Sheet"), function() { |
| var filters = report.get_values(); |
| frappe.set_route('query-report', 'Balance Sheet', {company: filters.company}); |
| }, __('Financial Statements')); |
| report.page.add_inner_button(__("Profit and Loss"), function() { |
| var filters = report.get_values(); |
| frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company}); |
| }, __('Financial Statements')); |
| report.page.add_inner_button(__("Cash Flow Statement"), function() { |
| var filters = report.get_values(); |
| frappe.set_route('query-report', 'Cash Flow', {company: filters.company}); |
| }, __('Financial Statements')); |
| } |
| }; |
| |
| function get_filters(){ |
| return [ |
| { |
| "fieldname":"company", |
| "label": __("Company"), |
| "fieldtype": "Link", |
| "options": "Company", |
| "default": frappe.defaults.get_user_default("Company"), |
| "reqd": 1 |
| }, |
| { |
| "fieldname":"finance_book", |
| "label": __("Finance Book"), |
| "fieldtype": "Link", |
| "options": "Finance Book" |
| }, |
| { |
| "fieldname":"cost_center", |
| "label": __("Cost Center"), |
| "fieldtype": "MultiSelect", |
| get_data: function() { |
| var cost_centers = frappe.query_report.get_filter_value("cost_center") || ""; |
| |
| const values = cost_centers.split(/\s*,\s*/).filter(d => d); |
| const txt = cost_centers.match(/[^,\s*]*$/)[0] || ''; |
| let data = []; |
| |
| frappe.call({ |
| type: "GET", |
| method:'frappe.desk.search.search_link', |
| async: false, |
| no_spinner: true, |
| args: { |
| doctype: "Cost Center", |
| txt: txt, |
| filters: { |
| "company": frappe.query_report.get_filter_value("company"), |
| "name": ["not in", values] |
| } |
| }, |
| callback: function(r) { |
| data = r.results; |
| } |
| }); |
| return data; |
| } |
| }, |
| { |
| "fieldname":"from_fiscal_year", |
| "label": __("Start Year"), |
| "fieldtype": "Link", |
| "options": "Fiscal Year", |
| "default": frappe.defaults.get_user_default("fiscal_year"), |
| "reqd": 1 |
| }, |
| { |
| "fieldname":"to_fiscal_year", |
| "label": __("End Year"), |
| "fieldtype": "Link", |
| "options": "Fiscal Year", |
| "default": frappe.defaults.get_user_default("fiscal_year"), |
| "reqd": 1 |
| }, |
| { |
| "fieldname": "periodicity", |
| "label": __("Periodicity"), |
| "fieldtype": "Select", |
| "options": [ |
| { "value": "Monthly", "label": __("Monthly") }, |
| { "value": "Quarterly", "label": __("Quarterly") }, |
| { "value": "Half-Yearly", "label": __("Half-Yearly") }, |
| { "value": "Yearly", "label": __("Yearly") } |
| ], |
| "default": "Yearly", |
| "reqd": 1 |
| }, |
| // Note: |
| // If you are modifying this array such that the presentation_currency object |
| // is no longer the last object, please make adjustments in cash_flow.js |
| // accordingly. |
| { |
| "fieldname": "presentation_currency", |
| "label": __("Currency"), |
| "fieldtype": "Select", |
| "options": erpnext.get_presentation_currency_list() |
| } |
| ] |
| } |