2015-11-09 11:23:11 +00:00
frappe . provide ( "erpnext.wiz" ) ;
frappe . pages [ 'setup-wizard' ] . on _page _load = function ( wrapper ) {
if ( sys _defaults . company ) {
frappe . set _route ( "desk" ) ;
return ;
}
2015-11-16 07:28:14 +00:00
} ;
function load _erpnext _slides ( ) {
$ . extend ( erpnext . wiz , {
region : {
title : _ _ ( "Region" ) ,
icon : "icon-flag" ,
help : _ _ ( "Select your Country, Time Zone and Currency" ) ,
fields : [
{ fieldname : "country" , label : _ _ ( "Country" ) , reqd : 1 ,
fieldtype : "Select" } ,
{ fieldname : "timezone" , label : _ _ ( "Time Zone" ) , reqd : 1 ,
fieldtype : "Select" } ,
{ fieldname : "currency" , label : _ _ ( "Currency" ) , reqd : 1 ,
fieldtype : "Select" } ,
] ,
onload : function ( slide ) {
frappe . call ( {
method : "frappe.geo.country_info.get_country_timezone_info" ,
callback : function ( data ) {
erpnext . wiz . region . data = data . message ;
erpnext . wiz . region . setup _fields ( slide ) ;
erpnext . wiz . region . bind _events ( slide ) ;
}
} ) ;
} ,
css _class : "single-column" ,
setup _fields : function ( slide ) {
var data = erpnext . wiz . region . data ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
slide . get _input ( "country" ) . empty ( )
. add _options ( [ "" ] . concat ( keys ( data . country _info ) . sort ( ) ) ) ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
slide . get _input ( "currency" ) . empty ( )
. add _options ( frappe . utils . unique ( [ "" ] . concat ( $ . map ( data . country _info ,
function ( opts , country ) { return opts . currency ; } ) ) ) . sort ( ) ) ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
slide . get _input ( "timezone" ) . empty ( )
. add _options ( [ "" ] . concat ( data . all _timezones ) ) ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
if ( data . default _country ) {
slide . set _input ( "country" , data . default _country ) ;
}
} ,
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
bind _events : function ( slide ) {
slide . get _input ( "country" ) . on ( "change" , function ( ) {
var country = slide . get _input ( "country" ) . val ( ) ;
var $timezone = slide . get _input ( "timezone" ) ;
var data = erpnext . wiz . region . data ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
$timezone . empty ( ) ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
// add country specific timezones first
if ( country ) {
var timezone _list = data . country _info [ country ] . timezones || [ ] ;
$timezone . add _options ( timezone _list . sort ( ) ) ;
slide . get _field ( "currency" ) . set _input ( data . country _info [ country ] . currency ) ;
slide . get _field ( "currency" ) . $input . trigger ( "change" ) ;
2015-11-09 11:23:11 +00:00
}
2015-11-16 07:28:14 +00:00
// add all timezones at the end, so that user has the option to change it to any timezone
$timezone . add _options ( [ "" ] . concat ( data . all _timezones ) ) ;
slide . get _field ( "timezone" ) . set _input ( $timezone . val ( ) ) ;
// temporarily set date format
frappe . boot . sysdefaults . date _format = ( data . country _info [ country ] . date _format
|| "dd-mm-yyyy" ) ;
2015-11-09 11:23:11 +00:00
} ) ;
2015-11-16 07:28:14 +00:00
slide . get _input ( "currency" ) . on ( "change" , function ( ) {
var currency = slide . get _input ( "currency" ) . val ( ) ;
if ( ! currency ) return ;
frappe . model . with _doc ( "Currency" , currency , function ( ) {
frappe . provide ( "locals.:Currency." + currency ) ;
var currency _doc = frappe . model . get _doc ( "Currency" , currency ) ;
var number _format = currency _doc . number _format ;
if ( number _format === "#.###" ) {
number _format = "#.###,##" ;
} else if ( number _format === "#,###" ) {
number _format = "#,###.##"
}
frappe . boot . sysdefaults . number _format = number _format ;
locals [ ":Currency" ] [ currency ] = $ . extend ( { } , currency _doc ) ;
} ) ;
} ) ;
2015-11-09 11:23:11 +00:00
}
} ,
2015-11-16 07:28:14 +00:00
user : {
title : _ _ ( "The First User: You" ) ,
icon : "icon-user" ,
fields : [
{ "fieldname" : "first_name" , "label" : _ _ ( "First Name" ) , "fieldtype" : "Data" ,
reqd : 1 } ,
{ "fieldname" : "last_name" , "label" : _ _ ( "Last Name" ) , "fieldtype" : "Data" } ,
{ "fieldname" : "email" , "label" : _ _ ( "Email Address" ) , "fieldtype" : "Data" ,
reqd : 1 , "description" : _ _ ( "You will use it to Login" ) , "options" : "Email" } ,
{ "fieldname" : "password" , "label" : _ _ ( "Password" ) , "fieldtype" : "Password" ,
reqd : 1 } ,
{ fieldtype : "Attach Image" , fieldname : "attach_user" ,
label : _ _ ( "Attach Your Picture" ) } ,
] ,
help : _ _ ( 'The first user will become the System Manager (you can change this later).' ) ,
onload : function ( slide ) {
if ( user !== "Administrator" ) {
slide . form . fields _dict . password . $wrapper . toggle ( false ) ;
slide . form . fields _dict . email . $wrapper . toggle ( false ) ;
slide . form . fields _dict . first _name . set _input ( frappe . boot . user . first _name ) ;
slide . form . fields _dict . last _name . set _input ( frappe . boot . user . last _name ) ;
var user _image = frappe . get _cookie ( "user_image" ) ;
if ( user _image ) {
var $attach _user = slide . form . fields _dict . attach _user . $wrapper ;
$attach _user . find ( ".missing-image" ) . toggle ( false ) ;
$attach _user . find ( "img" ) . attr ( "src" , decodeURIComponent ( user _image ) ) . toggle ( true ) ;
}
delete slide . form . fields _dict . email ;
delete slide . form . fields _dict . password ;
}
} ,
css _class : "single-column"
2015-11-09 11:23:11 +00:00
} ,
2015-11-16 07:28:14 +00:00
org : {
title : _ _ ( "The Organization" ) ,
icon : "icon-building" ,
fields : [
{ fieldname : 'company_name' , label : _ _ ( 'Company Name' ) , fieldtype : 'Data' , reqd : 1 ,
placeholder : _ _ ( 'e.g. "My Company LLC"' ) } ,
{ fieldname : 'company_abbr' , label : _ _ ( 'Company Abbreviation' ) , fieldtype : 'Data' ,
description : _ _ ( 'Max 5 characters' ) , placeholder : _ _ ( 'e.g. "MC"' ) , reqd : 1 } ,
{ fieldname : 'company_tagline' , label : _ _ ( 'What does it do?' ) , fieldtype : 'Data' ,
placeholder : _ _ ( 'e.g. "Build tools for builders"' ) , reqd : 1 } ,
{ fieldname : 'bank_account' , label : _ _ ( 'Bank Account' ) , fieldtype : 'Data' ,
placeholder : _ _ ( 'e.g. "XYZ National Bank"' ) , reqd : 1 } ,
{ fieldname : 'chart_of_accounts' , label : _ _ ( 'Chart of Accounts' ) ,
options : "" , fieldtype : 'Select' } ,
// TODO remove this
{ fieldtype : "Section Break" } ,
{ fieldname : 'fy_start_date' , label : _ _ ( 'Financial Year Start Date' ) , fieldtype : 'Date' ,
description : _ _ ( 'Your financial year begins on' ) , reqd : 1 } ,
{ fieldname : 'fy_end_date' , label : _ _ ( 'Financial Year End Date' ) , fieldtype : 'Date' ,
description : _ _ ( 'Your financial year ends on' ) , reqd : 1 } ,
] ,
help : _ _ ( 'The name of your company for which you are setting up this system.' ) ,
onload : function ( slide ) {
erpnext . wiz . org . load _chart _of _accounts ( slide ) ;
erpnext . wiz . org . bind _events ( slide ) ;
erpnext . wiz . org . set _fy _dates ( slide ) ;
} ,
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
css _class : "single-column" ,
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
set _fy _dates : function ( slide ) {
var country = slide . wiz . get _values ( ) . country ;
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
if ( country ) {
var fy = erpnext . wiz . fiscal _years [ country ] ;
var current _year = moment ( new Date ( ) ) . year ( ) ;
var next _year = current _year + 1 ;
if ( ! fy ) {
fy = [ "01-01" , "12-31" ] ;
next _year = current _year ;
}
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
slide . get _field ( "fy_start_date" ) . set _input ( current _year + "-" + fy [ 0 ] ) ;
slide . get _field ( "fy_end_date" ) . set _input ( next _year + "-" + fy [ 1 ] ) ;
}
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
} ,
2015-11-09 11:23:11 +00:00
2015-11-16 07:28:14 +00:00
load _chart _of _accounts : function ( slide ) {
var country = slide . wiz . get _values ( ) . country ;
if ( country ) {
frappe . call ( {
method : "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country" ,
args : { "country" : country } ,
callback : function ( r ) {
if ( r . message ) {
slide . get _input ( "chart_of_accounts" ) . empty ( )
. add _options ( r . message ) ;
if ( r . message . length === 1 ) {
var field = slide . get _field ( "chart_of_accounts" ) ;
field . set _value ( r . message [ 0 ] ) ;
field . df . hidden = 1 ;
field . refresh ( ) ;
}
2015-11-09 11:23:11 +00:00
}
}
2015-11-16 07:28:14 +00:00
} )
}
} ,
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 ( "" ) ;
slide . get _field ( "company_abbr" ) . set _input ( abbr . slice ( 0 , 5 ) . toUpperCase ( ) ) ;
} ) . val ( frappe . boot . sysdefaults . company _name || "" ) . trigger ( "change" ) ;
slide . get _input ( "company_abbr" ) . on ( "change" , function ( ) {
if ( slide . get _input ( "company_abbr" ) . val ( ) . length > 5 ) {
msgprint ( "Company Abbreviation cannot have more than 5 characters" ) ;
slide . get _field ( "company_abbr" ) . set _input ( "" ) ;
2015-11-09 11:23:11 +00:00
}
2015-11-16 07:28:14 +00:00
} ) ;
// TODO remove this
slide . get _input ( "fy_start_date" ) . on ( "change" , function ( ) {
var year _end _date =
frappe . datetime . add _days ( frappe . datetime . add _months (
frappe . datetime . user _to _obj ( slide . get _input ( "fy_start_date" ) . val ( ) ) , 12 ) , - 1 ) ;
slide . get _input ( "fy_end_date" ) . val ( frappe . datetime . obj _to _user ( year _end _date ) ) ;
} ) ;
2015-11-09 11:23:11 +00:00
}
} ,
2015-11-16 07:28:14 +00:00
branding : {
icon : "icon-bookmark" ,
title : _ _ ( "The Brand" ) ,
help : _ _ ( 'Upload your letter head and logo. (you can edit them later).' ) ,
fields : [
{ fieldtype : "Attach Image" , fieldname : "attach_letterhead" ,
label : _ _ ( "Attach Letterhead" ) ,
description : _ _ ( "Keep it web friendly 900px (w) by 100px (h)" )
} ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Attach Image" , fieldname : "attach_logo" ,
label : _ _ ( "Attach Logo" ) ,
description : _ _ ( "100px by 100px" ) } ,
] ,
css _class : "two-column"
} ,
users : {
icon : "icon-money" ,
"title" : _ _ ( "Add Users" ) ,
"help" : _ _ ( "Add users to your organization, other than yourself" ) ,
"fields" : [ ] ,
before _load : function ( slide ) {
slide . fields = [ ] ;
for ( var i = 1 ; i < 5 ; i ++ ) {
slide . fields = slide . fields . concat ( [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "user_fullname_" + i ,
label : _ _ ( "Full Name" ) } ,
{ fieldtype : "Data" , fieldname : "user_email_" + i ,
label : _ _ ( "Email ID" ) , placeholder : _ _ ( "user@example.com" ) ,
options : "Email" } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Check" , fieldname : "user_sales_" + i ,
label : _ _ ( "Sales" ) , default : 1 } ,
{ fieldtype : "Check" , fieldname : "user_purchaser_" + i ,
label : _ _ ( "Purchaser" ) , default : 1 } ,
{ fieldtype : "Check" , fieldname : "user_accountant_" + i ,
label : _ _ ( "Accountant" ) , default : 1 } ,
] ) ;
2015-11-09 11:23:11 +00:00
}
} ,
2015-11-16 07:28:14 +00:00
css _class : "two-column"
2015-11-09 11:23:11 +00:00
} ,
2015-11-16 07:28:14 +00:00
taxes : {
icon : "icon-money" ,
"title" : _ _ ( "Add Taxes" ) ,
"help" : _ _ ( "List your tax heads (e.g. VAT, Customs etc; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later." ) ,
"fields" : [ ] ,
before _load : function ( slide ) {
slide . fields = [ ] ;
for ( var i = 1 ; i < 4 ; i ++ ) {
slide . fields = slide . fields . concat ( [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "tax_" + i , label : _ _ ( "Tax" ) + " " + i ,
placeholder : _ _ ( "e.g. VAT" ) + " " + i } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Float" , fieldname : "tax_rate_" + i , label : _ _ ( "Rate (%)" ) , placeholder : _ _ ( "e.g. 5" ) } ,
] ) ;
}
} ,
css _class : "two-column"
2015-11-09 11:23:11 +00:00
} ,
2015-11-16 07:28:14 +00:00
customers : {
icon : "icon-group" ,
"title" : _ _ ( "Your Customers" ) ,
"help" : _ _ ( "List a few of your customers. They could be organizations or individuals." ) ,
"fields" : [ ] ,
before _load : function ( slide ) {
slide . fields = [ ] ;
for ( var i = 1 ; i < 6 ; i ++ ) {
slide . fields = slide . fields . concat ( [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "customer_" + i , label : _ _ ( "Customer" ) + " " + i ,
placeholder : _ _ ( "Customer Name" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Data" , fieldname : "customer_contact_" + i ,
label : _ _ ( "Contact Name" ) + " " + i , placeholder : _ _ ( "Contact Name" ) }
] )
}
slide . fields [ 1 ] . reqd = 1 ;
} ,
css _class : "two-column"
2015-11-09 11:23:11 +00:00
} ,
2015-11-16 07:28:14 +00:00
suppliers : {
icon : "icon-group" ,
"title" : _ _ ( "Your Suppliers" ) ,
"help" : _ _ ( "List a few of your suppliers. They could be organizations or individuals." ) ,
"fields" : [ ] ,
before _load : function ( slide ) {
slide . fields = [ ] ;
for ( var i = 1 ; i < 6 ; i ++ ) {
slide . fields = slide . fields . concat ( [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "supplier_" + i , label : _ _ ( "Supplier" ) + " " + i ,
placeholder : _ _ ( "Supplier Name" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Data" , fieldname : "supplier_contact_" + i ,
label : _ _ ( "Contact Name" ) + " " + i , placeholder : _ _ ( "Contact Name" ) } ,
] )
}
slide . fields [ 1 ] . reqd = 1 ;
} ,
css _class : "two-column"
2015-11-09 11:23:11 +00:00
} ,
2015-11-16 07:28:14 +00:00
items : {
icon : "icon-barcode" ,
"title" : _ _ ( "Your Products or Services" ) ,
"help" : _ _ ( "List your products or services that you buy or sell. Make sure to check the Item Group, Unit of Measure and other properties when you start." ) ,
"fields" : [ ] ,
before _load : function ( slide ) {
slide . fields = [ ] ;
for ( var i = 1 ; i < 6 ; i ++ ) {
slide . fields = slide . fields . concat ( [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "item_" + i , label : _ _ ( "Item" ) + " " + i ,
placeholder : _ _ ( "A Product or Service" ) } ,
{ fieldtype : "Select" , label : _ _ ( "Group" ) , fieldname : "item_group_" + i ,
options : [ _ _ ( "Products" ) , _ _ ( "Services" ) ,
_ _ ( "Raw Material" ) , _ _ ( "Consumable" ) , _ _ ( "Sub Assemblies" ) ] ,
"default" : _ _ ( "Products" ) } ,
{ fieldtype : "Select" , fieldname : "item_uom_" + i , label : _ _ ( "UOM" ) ,
options : [ _ _ ( "Unit" ) , _ _ ( "Nos" ) , _ _ ( "Box" ) , _ _ ( "Pair" ) , _ _ ( "Kg" ) , _ _ ( "Set" ) ,
_ _ ( "Hour" ) , _ _ ( "Minute" ) ] ,
"default" : _ _ ( "Unit" ) } ,
{ fieldtype : "Check" , fieldname : "is_sales_item_" + i , label : _ _ ( "We sell this Item" ) , default : 1 } ,
{ fieldtype : "Check" , fieldname : "is_purchase_item_" + i , label : _ _ ( "We buy this Item" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Currency" , fieldname : "item_price_" + i , label : _ _ ( "Rate" ) } ,
{ fieldtype : "Attach Image" , fieldname : "item_img_" + i , label : _ _ ( "Attach Image" ) } ,
] )
}
slide . fields [ 1 ] . reqd = 1 ;
// dummy data
slide . fields . push ( { fieldtype : "Section Break" } ) ;
slide . fields . push ( { fieldtype : "Check" , fieldname : "add_sample_data" ,
label : _ _ ( "Add a few sample records" ) , "default" : 1 } ) ;
} ,
css _class : "two-column"
} ,
} ) ;
// Source: https://en.wikipedia.org/wiki/Fiscal_year
// default 1st Jan - 31st Dec
erpnext . wiz . fiscal _years = {
"Afghanistan" : [ "12-20" , "12-21" ] ,
"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" ] ,
"Italy" : [ "07-01" , "06-30" ] ,
"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" ] ,
} ;
} ;
2015-11-09 11:23:11 +00:00
frappe . wiz . on ( "before_load" , function ( ) {
2015-11-16 07:28:14 +00:00
load _erpnext _slides ( ) ;
2015-11-09 11:23:11 +00:00
frappe . wiz . add _slide ( erpnext . wiz . user ) ;
frappe . wiz . add _slide ( erpnext . wiz . org ) ;
frappe . wiz . add _slide ( erpnext . wiz . branding ) ;
frappe . wiz . add _slide ( erpnext . wiz . users ) ;
frappe . wiz . add _slide ( erpnext . wiz . taxes ) ;
frappe . wiz . add _slide ( erpnext . wiz . customers ) ;
frappe . wiz . add _slide ( erpnext . wiz . suppliers ) ;
frappe . wiz . add _slide ( erpnext . wiz . items ) ;
frappe . wiz . welcome _page = "#welcome-to-erpnext" ;
} ) ;