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 , {
org : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
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 } ,
2016-03-04 10:11:27 +00:00
{ fieldname : 'domain' , label : _ _ ( 'Domain' ) , fieldtype : 'Select' ,
2016-03-07 11:27:05 +00:00
options : [
2016-03-09 11:01:53 +00:00
{ "label" : _ _ ( "Distribution" ) , "value" : "Distribution" } ,
{ "label" : _ _ ( "Manufacturing" ) , "value" : "Manufacturing" } ,
{ "label" : _ _ ( "Retail" ) , "value" : "Retail" } ,
{ "label" : _ _ ( "Services" ) , "value" : "Services" } ,
{ "label" : _ _ ( "Education" ) , "value" : "Education" } ,
{ "label" : _ _ ( "Other" ) , "value" : "Other" } ,
2016-03-07 11:27:05 +00:00
] , reqd : 1 } ,
2015-11-16 07:28:14 +00:00
{ 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-24 11:36:54 +00:00
validate : function ( ) {
// validate fiscal year start and end dates
if ( this . values . fy _start _date == 'Invalid date' || this . values . fy _end _date == 'Invalid date' ) {
msgprint ( _ _ ( "Please enter valid Financial Year Start and End Dates" ) ) ;
return false ;
}
if ( ( this . values . company _name || "" ) . toLowerCase ( ) == "company" ) {
msgprint ( _ _ ( "Company Name cannot be Company" ) ) ;
return false ;
}
return true ;
} ,
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 : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
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" ) ,
2015-12-09 11:58:51 +00:00
description : _ _ ( "Keep it web friendly 900px (w) by 100px (h)" ) ,
is _private : 0
2015-11-16 07:28:14 +00:00
} ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Attach Image" , fieldname : "attach_logo" ,
label : _ _ ( "Attach Logo" ) ,
2015-12-09 11:58:51 +00:00
description : _ _ ( "100px by 100px" ) ,
is _private : 0
} ,
2015-11-16 07:28:14 +00:00
] ,
css _class : "two-column"
} ,
users : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
icon : "icon-money" ,
2016-02-24 10:28:25 +00:00
title : _ _ ( "Add Users" ) ,
help : _ _ ( "Add users to your organization, other than yourself" ) ,
fields : [ ] ,
2015-11-16 07:28:14 +00:00
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 : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
icon : "icon-money" ,
2016-02-24 10:28:25 +00:00
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." ) ,
2015-11-16 07:28:14 +00:00
"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 : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
icon : "icon-group" ,
2016-02-24 10:28:25 +00:00
title : _ _ ( "Your Customers" ) ,
help : _ _ ( "List a few of your customers. They could be organizations or individuals." ) ,
fields : [ ] ,
2015-11-16 07:28:14 +00:00
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 : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
icon : "icon-group" ,
2016-02-24 10:28:25 +00:00
title : _ _ ( "Your Suppliers" ) ,
help : _ _ ( "List a few of your suppliers. They could be organizations or individuals." ) ,
fields : [ ] ,
2015-11-16 07:28:14 +00:00
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 : {
2016-02-24 10:28:25 +00:00
app _name : "erpnext" ,
2015-11-16 07:28:14 +00:00
icon : "icon-barcode" ,
2016-02-24 10:28:25 +00:00
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 : [ ] ,
2015-11-16 07:28:14 +00:00
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" ) } ,
2015-12-09 11:58:51 +00:00
{ fieldtype : "Attach Image" , fieldname : "item_img_" + i , label : _ _ ( "Attach Image" ) , is _private : 0 } ,
2015-11-16 07:28:14 +00:00
] )
}
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 . 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" ;
} ) ;