blob: cdc86624ac416e8112dd71c175532f9b2b9591ee [file] [log] [blame]
Rushabh Mehta12852e72012-02-29 15:11:06 +05301// ERPNext - web based ERP (http://erpnext.com)
2// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17// complete my company registration
18// --------------------------------
Anand Doshi1ed4ef12012-04-27 15:30:23 +053019wn.provide('erpnext.complete_setup');
Rushabh Mehta12852e72012-02-29 15:11:06 +053020
Anand Doshi1ed4ef12012-04-27 15:30:23 +053021$.extend(erpnext.complete_setup, {
Anand Doshi1ed4ef12012-04-27 15:30:23 +053022 show: function() {
23 d = erpnext.complete_setup.prepare_dialog();
24 d.show();
25 },
Rushabh Mehta12852e72012-02-29 15:11:06 +053026
Anand Doshi2aa9ba62012-04-30 15:43:34 +053027 prepare_dialog: function() {
Rushabh Mehta2d700dd2012-10-01 14:46:37 +053028 var d = new wn.ui.Dialog({
Anand Doshi1ed4ef12012-04-27 15:30:23 +053029 title: "Setup",
30 fields: [
31 {fieldname:'first_name', label:'Your First Name', fieldtype:'Data', reqd: 1},
32 {fieldname:'last_name', label:'Your Last Name', fieldtype:'Data'},
33 {fieldname:'company_name', label:'Company Name', fieldtype:'Data', reqd:1,
34 description: 'e.g. "My Company LLC"'},
35 {fieldname:'company_abbr', label:'Company Abbreviation', fieldtype:'Data',
36 description:'e.g. "MC"',reqd:1},
37 {fieldname:'fy_start', label:'Financial Year Start Date', fieldtype:'Select',
38 description:'Your financial year begins on"', reqd:1,
39 options: erpnext.complete_setup.fy_start_list.join('\n')},
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053040 {fieldname:'country', label: 'Country', reqd:1,
41 options: "", fieldtype: 'Select'},
Anand Doshi1ed4ef12012-04-27 15:30:23 +053042 {fieldname:'currency', label: 'Default Currency', reqd:1,
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053043 options: "", fieldtype: 'Select'},
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053044 {fieldname:'timezone', label: 'Time Zone', reqd:1,
45 options: "", fieldtype: 'Select'},
Anand Doshi1ed4ef12012-04-27 15:30:23 +053046 {fieldname:'industry', label: 'Industry', reqd:1,
47 options: erpnext.complete_setup.industry_list.join('\n'), fieldtype: 'Select'},
Anand Doshi1ed4ef12012-04-27 15:30:23 +053048 {fieldname:'update', label:'Setup',fieldtype:'Button'},
49 ],
Rushabh Mehta12852e72012-02-29 15:11:06 +053050 });
Anand Doshiafad0ef2013-07-10 12:00:26 +053051
Anand Doshi1ed4ef12012-04-27 15:30:23 +053052 if(user != 'Administrator'){
53 $(d.appframe.$titlebar).find('.close').toggle(false); // Hide close image
54 $('header').toggle(false); // hide toolbar
55 }
56
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053057 wn.call({
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053058 method:"webnotes.country_info.get_country_timezone_info",
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053059 callback: function(data) {
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053060 erpnext.country_info = data.message.country_info;
61 erpnext.all_timezones = data.message.all_timezones;
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053062 d.get_input("country").empty()
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053063 .add_options([""].concat(keys(erpnext.country_info).sort()));
64 d.get_input("currency").empty()
65 .add_options(wn.utils.unique([""].concat($.map(erpnext.country_info,
66 function(opts, country) { return opts.currency; }))).sort());
67 d.get_input("timezone").empty()
68 .add_options([""].concat(erpnext.all_timezones));
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053069 }
70 })
71
Anand Doshi1ed4ef12012-04-27 15:30:23 +053072 // on clicking update
73 d.fields_dict.update.input.onclick = function() {
74 var data = d.get_values();
75 if(!data) return;
76 $(this).set_working();
77 $c_obj('Setup Control','setup_account',data,function(r, rt){
Anand Doshi7edb1912013-06-24 12:11:15 +053078 if(!r.exc) {
79 sys_defaults = r.message;
80 user_fullname = r.message.user_fullname;
81 wn.boot.user_info[user].fullname = user_fullname;
82 d.hide();
83 $('header').toggle(true);
84 wn.container.wntoolbar.set_user_name();
85
86 setTimeout(function() { window.location.reload(); }, 3000);
Anand Doshif4d8d232013-07-04 18:29:55 +053087 } else {
88 $(this).done_working();
Anand Doshi7edb1912013-06-24 12:11:15 +053089 }
Anand Doshi1ed4ef12012-04-27 15:30:23 +053090 });
91 };
92
93 d.fields_dict.country.input.onchange = function() {
94 var country = d.fields_dict.country.input.value;
95 var $timezone = $(d.fields_dict.timezone.input);
96 $timezone.empty();
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053097 // add country specific timezones first
Anand Doshi1ed4ef12012-04-27 15:30:23 +053098 if(country){
Anand Doshi6b2aa7e2013-05-20 13:43:50 +053099 var timezone_list = erpnext.country_info[country].timezones || [];
100 $timezone.add_options(timezone_list.sort());
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530101
102 d.get_input("currency").val(erpnext.country_info[country].currency);
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530103 }
Anand Doshi6b2aa7e2013-05-20 13:43:50 +0530104 // add all timezones at the end, so that user has the option to change it to any timezone
105 $timezone.add_options([""].concat(erpnext.all_timezones));
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530106
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530107 };
108
109 // company name already set
110 if(wn.control_panel.company_name) {
111 var inp = d.fields_dict.company_name.input;
112 inp.value = wn.control_panel.company_name;
113 inp.disabled = true;
114 }
115
116 // set first name, last name
117 if(user_fullname) {
118 u = user_fullname.split(' ');
119 if(u[0]) {
120 d.fields_dict.first_name.input.value = u[0];
121 }
122 if(u[1]) {
123 d.fields_dict.last_name.input.value = u[1];
124 }
125 }
126
Anand Doshiafad0ef2013-07-10 12:00:26 +0530127 return d;
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530128 },
Rushabh Mehta12852e72012-02-29 15:11:06 +0530129
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530130 fy_start_list: ['', '1st Jan', '1st Apr', '1st Jul', '1st Oct'],
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530131
132 industry_list: ['', 'Aerospace and Defence', 'Agriculture', 'Apparel', 'Automobile',
133 'Banking', 'Biotechnology', 'Chemical', 'Communications', 'Consulting', 'Customer Service',
134 'Education', 'Electronics', 'Energy', 'Engineering', 'Entertainment', 'Environmental',
135 'Finance', 'Food and Beverage', 'Government', 'Healthcare', 'Hospitality',
136 'Information Technology', 'Insurance', 'Machinery', 'Manufacturing', 'Media',
137 'Not For Profit', 'Recreation', 'Retail', 'Shipping', 'Technology',
Anand Doshi6b2aa7e2013-05-20 13:43:50 +0530138 'Telecommunications', 'Transportation', 'Trading', 'Utilities', 'Other'],
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530139});