2017-07-03 12:53:57 +00:00
|
|
|
frappe.provide("erpnext.setup");
|
2015-11-09 11:23:11 +00:00
|
|
|
|
|
|
|
frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
|
2017-05-30 07:24:42 +00:00
|
|
|
if(frappe.sys_defaults.company) {
|
2015-11-09 11:23:11 +00:00
|
|
|
frappe.set_route("desk");
|
|
|
|
return;
|
|
|
|
}
|
2015-11-16 07:28:14 +00:00
|
|
|
};
|
|
|
|
|
2017-09-04 05:44:04 +00:00
|
|
|
frappe.setup.on("before_load", function () {
|
|
|
|
erpnext.setup.slides_settings.map(frappe.setup.add_slide);
|
|
|
|
});
|
|
|
|
|
|
|
|
erpnext.setup.slides_settings = [
|
2017-07-03 12:53:57 +00:00
|
|
|
{
|
|
|
|
// Brand
|
|
|
|
name: 'brand',
|
|
|
|
icon: "fa fa-bookmark",
|
|
|
|
title: __("The Brand"),
|
2017-09-04 05:44:04 +00:00
|
|
|
// help: __('Upload your letter head and logo. (you can edit them later).'),
|
2017-07-03 12:53:57 +00:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
fieldtype: "Attach Image", fieldname: "attach_logo",
|
|
|
|
label: __("Attach Logo"),
|
|
|
|
description: __("100px by 100px"),
|
2017-07-26 12:49:41 +00:00
|
|
|
is_private: 0,
|
|
|
|
align: 'center'
|
2015-11-16 07:28:14 +00:00
|
|
|
},
|
2017-07-03 12:53:57 +00:00
|
|
|
{
|
|
|
|
fieldname: 'company_name',
|
2022-04-28 06:32:54 +00:00
|
|
|
label: __('Company Name'),
|
2017-07-26 12:49:41 +00:00
|
|
|
fieldtype: 'Data',
|
|
|
|
reqd: 1
|
2015-11-24 11:36:54 +00:00
|
|
|
},
|
2017-07-03 12:53:57 +00:00
|
|
|
{
|
|
|
|
fieldname: 'company_abbr',
|
2022-04-28 06:32:54 +00:00
|
|
|
label: __('Company Abbreviation'),
|
2017-07-03 12:53:57 +00:00
|
|
|
fieldtype: 'Data'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
onload: function(slide) {
|
|
|
|
this.bind_events(slide);
|
|
|
|
},
|
|
|
|
bind_events: function (slide) {
|
|
|
|
slide.get_input("company_name").on("change", function () {
|
|
|
|
var parts = slide.get_input("company_name").val().split(" ");
|
|
|
|
var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
|
2022-02-23 15:11:49 +00:00
|
|
|
slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase());
|
2017-07-03 12:53:57 +00:00
|
|
|
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
|
|
|
|
|
|
|
|
slide.get_input("company_abbr").on("change", function () {
|
2022-02-23 15:11:49 +00:00
|
|
|
if (slide.get_input("company_abbr").val().length > 10) {
|
2018-02-14 12:14:06 +00:00
|
|
|
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
|
2017-07-11 07:06:57 +00:00
|
|
|
slide.get_field("company_abbr").set_value("");
|
2015-11-16 07:28:14 +00:00
|
|
|
}
|
2017-07-03 12:53:57 +00:00
|
|
|
});
|
2017-09-04 05:44:04 +00:00
|
|
|
},
|
|
|
|
validate: function() {
|
2017-10-02 06:08:03 +00:00
|
|
|
if ((this.values.company_name || "").toLowerCase() == "company") {
|
|
|
|
frappe.msgprint(__("Company Name cannot be Company"));
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-04 05:44:04 +00:00
|
|
|
if (!this.values.company_abbr) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-23 15:11:49 +00:00
|
|
|
if (this.values.company_abbr.length > 10) {
|
2018-12-06 02:07:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-04 05:44:04 +00:00
|
|
|
return true;
|
2017-07-03 12:53:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Organisation
|
|
|
|
name: 'organisation',
|
|
|
|
title: __("Your Organization"),
|
|
|
|
icon: "fa fa-building",
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
fieldname: 'company_tagline',
|
|
|
|
label: __('What does it do?'),
|
|
|
|
fieldtype: 'Data',
|
2022-04-28 06:32:54 +00:00
|
|
|
placeholder: __('e.g. "Build tools for builders"'),
|
2017-07-03 12:53:57 +00:00
|
|
|
reqd: 1
|
2015-11-16 07:28:14 +00:00
|
|
|
},
|
2017-07-03 12:53:57 +00:00
|
|
|
{ fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
|
|
|
|
{
|
|
|
|
fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
|
|
|
|
options: "", fieldtype: 'Select'
|
2015-11-16 07:28:14 +00:00
|
|
|
},
|
2018-06-28 08:45:34 +00:00
|
|
|
{ fieldname: 'view_coa', label: __('View Chart of Accounts'), fieldtype: 'Button' },
|
2020-12-18 07:47:58 +00:00
|
|
|
{ fieldname: 'fy_start_date', label: __('Financial Year Begins On'), fieldtype: 'Date', reqd: 1 },
|
|
|
|
// end date should be hidden (auto calculated)
|
|
|
|
{ fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1, hidden: 1 },
|
2017-07-03 12:53:57 +00:00
|
|
|
],
|
2015-11-16 07:28:14 +00:00
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
onload: function (slide) {
|
|
|
|
this.load_chart_of_accounts(slide);
|
|
|
|
this.bind_events(slide);
|
|
|
|
this.set_fy_dates(slide);
|
|
|
|
},
|
2015-11-16 07:28:14 +00:00
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
validate: function () {
|
2021-06-26 18:19:32 +00:00
|
|
|
let me = this;
|
|
|
|
let exist;
|
|
|
|
|
2018-09-18 05:12:04 +00:00
|
|
|
if (!this.validate_fy_dates()) {
|
2017-07-03 12:53:57 +00:00
|
|
|
return false;
|
2015-11-09 11:23:11 +00:00
|
|
|
}
|
2018-02-16 09:14:42 +00:00
|
|
|
|
2021-06-26 18:19:32 +00:00
|
|
|
// Validate bank name
|
2021-08-19 08:11:10 +00:00
|
|
|
if(me.values.bank_account) {
|
2021-06-26 18:19:32 +00:00
|
|
|
frappe.call({
|
|
|
|
async: false,
|
|
|
|
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.validate_bank_account",
|
|
|
|
args: {
|
|
|
|
"coa": me.values.chart_of_accounts,
|
|
|
|
"bank_account": me.values.bank_account
|
|
|
|
},
|
|
|
|
callback: function (r) {
|
|
|
|
if(r.message){
|
|
|
|
exist = r.message;
|
|
|
|
me.get_field("bank_account").set_value("");
|
|
|
|
let message = __('Account {0} already exists. Please enter a different name for your bank account.',
|
|
|
|
[me.values.bank_account]
|
|
|
|
);
|
|
|
|
frappe.msgprint(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return !exist; // Return False if exist = true
|
|
|
|
}
|
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
return true;
|
2015-11-09 11:23:11 +00:00
|
|
|
},
|
2015-11-16 07:28:14 +00:00
|
|
|
|
2018-09-18 05:12:04 +00:00
|
|
|
validate_fy_dates: function() {
|
|
|
|
// validate fiscal year start and end dates
|
|
|
|
const invalid = this.values.fy_start_date == 'Invalid date' ||
|
|
|
|
this.values.fy_end_date == 'Invalid date';
|
|
|
|
const start_greater_than_end = this.values.fy_start_date > this.values.fy_end_date;
|
|
|
|
|
|
|
|
if (invalid || start_greater_than_end) {
|
|
|
|
frappe.msgprint(__("Please enter valid Financial Year Start and End Dates"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
set_fy_dates: function (slide) {
|
|
|
|
var country = frappe.wizard.values.country;
|
2015-11-16 07:28:14 +00:00
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
if (country) {
|
|
|
|
var fy = erpnext.setup.fiscal_years[country];
|
|
|
|
var current_year = moment(new Date()).year();
|
|
|
|
var next_year = current_year + 1;
|
|
|
|
if (!fy) {
|
2017-07-05 11:56:34 +00:00
|
|
|
fy = ["01-01", "12-31"];
|
2017-07-03 12:53:57 +00:00
|
|
|
next_year = current_year;
|
2015-11-16 07:28:14 +00:00
|
|
|
}
|
2015-11-09 11:23:11 +00:00
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
var year_start_date = current_year + "-" + fy[0];
|
|
|
|
if (year_start_date > frappe.datetime.get_today()) {
|
2017-07-05 12:26:04 +00:00
|
|
|
next_year = current_year;
|
2017-07-03 12:53:57 +00:00
|
|
|
current_year -= 1;
|
2015-11-16 07:28:14 +00:00
|
|
|
}
|
2017-07-05 12:26:04 +00:00
|
|
|
slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]);
|
|
|
|
slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]);
|
2017-07-03 12:53:57 +00:00
|
|
|
}
|
2015-11-16 07:28:14 +00:00
|
|
|
},
|
2016-07-21 10:31:59 +00:00
|
|
|
|
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
load_chart_of_accounts: function (slide) {
|
|
|
|
var country = frappe.wizard.values.country;
|
2016-07-21 10:31:59 +00:00
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
if (country) {
|
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
|
2018-06-28 08:45:34 +00:00
|
|
|
args: { "country": country, with_standard: true },
|
2017-07-03 12:53:57 +00:00
|
|
|
callback: function (r) {
|
|
|
|
if (r.message) {
|
|
|
|
slide.get_input("chart_of_accounts").empty()
|
|
|
|
.add_options(r.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-07-21 10:31:59 +00:00
|
|
|
},
|
|
|
|
|
2017-07-03 12:53:57 +00:00
|
|
|
bind_events: function (slide) {
|
2018-06-28 08:45:34 +00:00
|
|
|
let me = this;
|
2017-07-03 12:53:57 +00:00
|
|
|
slide.get_input("fy_start_date").on("change", function () {
|
2017-07-05 12:26:04 +00:00
|
|
|
var start_date = slide.form.fields_dict.fy_start_date.get_value();
|
2017-07-03 12:53:57 +00:00
|
|
|
var year_end_date =
|
2017-07-05 12:26:04 +00:00
|
|
|
frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
|
|
|
|
slide.form.fields_dict.fy_end_date.set_value(year_end_date);
|
2017-07-03 12:53:57 +00:00
|
|
|
});
|
2018-06-28 08:45:34 +00:00
|
|
|
|
|
|
|
slide.get_input("view_coa").on("click", function() {
|
|
|
|
let chart_template = slide.form.fields_dict.chart_of_accounts.get_value();
|
|
|
|
if(!chart_template) return;
|
|
|
|
|
|
|
|
me.charts_modal(slide, chart_template);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
charts_modal: function(slide, chart_template) {
|
|
|
|
let parent = __('All Accounts');
|
|
|
|
|
|
|
|
var dialog = new frappe.ui.Dialog({
|
|
|
|
title: chart_template,
|
|
|
|
fields: [
|
|
|
|
{'fieldname': 'expand_all', 'label': __('Expand All'), 'fieldtype': 'Button',
|
|
|
|
click: function() {
|
|
|
|
// expand all nodes on button click
|
|
|
|
coa_tree.load_children(coa_tree.root_node, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{'fieldname': 'collapse_all', 'label': __('Collapse All'), 'fieldtype': 'Button',
|
|
|
|
click: function() {
|
|
|
|
// collapse all nodes
|
|
|
|
coa_tree.get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root)
|
|
|
|
.then(data_list => {
|
|
|
|
data_list.map(d => { coa_tree.toggle_node(coa_tree.nodes[d.parent]); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
// render tree structure in the dialog modal
|
|
|
|
let coa_tree = new frappe.ui.Tree({
|
|
|
|
parent: $(dialog.body),
|
|
|
|
label: parent,
|
|
|
|
expandable: true,
|
|
|
|
method: 'erpnext.accounts.utils.get_coa',
|
|
|
|
args: {
|
|
|
|
chart: chart_template,
|
|
|
|
parent: parent,
|
|
|
|
doctype: 'Account'
|
|
|
|
},
|
|
|
|
onclick: function(node) {
|
|
|
|
parent = node.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// add class to show buttons side by side
|
2018-07-03 05:05:31 +00:00
|
|
|
const form_container = $(dialog.body).find('form');
|
|
|
|
const buttons = $(form_container).find('.frappe-control');
|
|
|
|
form_container.addClass('flex');
|
|
|
|
buttons.map((index, button) => {
|
|
|
|
$(button).css({"margin-right": "1em"});
|
|
|
|
})
|
2018-06-28 08:45:34 +00:00
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
coa_tree.load_children(coa_tree.root_node, true); // expand all node trigger
|
2017-07-03 12:53:57 +00:00
|
|
|
}
|
2016-07-05 16:04:21 +00:00
|
|
|
}
|
2017-07-03 12:53:57 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Source: https://en.wikipedia.org/wiki/Fiscal_year
|
|
|
|
// default 1st Jan - 31st Dec
|
|
|
|
|
|
|
|
erpnext.setup.fiscal_years = {
|
2017-12-12 08:49:35 +00:00
|
|
|
"Afghanistan": ["12-21", "12-20"],
|
2017-07-05 11:56:34 +00:00
|
|
|
"Australia": ["07-01", "06-30"],
|
|
|
|
"Bangladesh": ["07-01", "06-30"],
|
|
|
|
"Canada": ["04-01", "03-31"],
|
|
|
|
"Costa Rica": ["10-01", "09-30"],
|
|
|
|
"Egypt": ["07-01", "06-30"],
|
|
|
|
"Hong Kong": ["04-01", "03-31"],
|
|
|
|
"India": ["04-01", "03-31"],
|
|
|
|
"Iran": ["06-23", "06-22"],
|
|
|
|
"Myanmar": ["04-01", "03-31"],
|
|
|
|
"New Zealand": ["04-01", "03-31"],
|
|
|
|
"Pakistan": ["07-01", "06-30"],
|
|
|
|
"Singapore": ["04-01", "03-31"],
|
|
|
|
"South Africa": ["03-01", "02-28"],
|
|
|
|
"Thailand": ["10-01", "09-30"],
|
|
|
|
"United Kingdom": ["04-01", "03-31"],
|
2017-07-03 12:53:57 +00:00
|
|
|
};
|