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-07-03 12:53:57 +00:00
var erpnext _slides = [
{
// Domain
name : 'domain' ,
domains : [ "all" ] ,
title : _ _ ( 'Select your Domain' ) ,
fields : [
{
fieldname : 'domain' , label : _ _ ( 'Domain' ) , fieldtype : 'Select' ,
options : [
{ "label" : _ _ ( "Distribution" ) , "value" : "Distribution" } ,
{ "label" : _ _ ( "Education" ) , "value" : "Education" } ,
{ "label" : _ _ ( "Manufacturing" ) , "value" : "Manufacturing" } ,
{ "label" : _ _ ( "Retail" ) , "value" : "Retail" } ,
{ "label" : _ _ ( "Services" ) , "value" : "Services" }
] , reqd : 1
2016-07-21 10:31:59 +00:00
} ,
2017-07-03 12:53:57 +00:00
] ,
help : _ _ ( 'Select the nature of your business.' ) ,
onload : function ( slide ) {
slide . get _input ( "domain" ) . on ( "change" , function ( ) {
frappe . setup . domain = $ ( this ) . val ( ) ;
frappe . wizard . refresh _slides ( ) ;
} ) ;
2016-07-21 10:31:59 +00:00
} ,
2017-07-03 12:53:57 +00:00
} ,
{
// Brand
name : 'brand' ,
domains : [ "all" ] ,
icon : "fa fa-bookmark" ,
title : _ _ ( "The Brand" ) ,
help : _ _ ( 'Upload your letter head and logo. (you can edit them later).' ) ,
fields : [
{
fieldtype : "Attach Image" , fieldname : "attach_logo" ,
label : _ _ ( "Attach Logo" ) ,
description : _ _ ( "100px by 100px" ) ,
is _private : 0
2015-11-16 07:28:14 +00:00
} ,
2017-07-03 12:53:57 +00:00
{
fieldname : 'company_name' ,
label : frappe . setup . domain === 'Education' ?
_ _ ( 'Institute Name' ) : _ _ ( 'Company Name' ) ,
fieldtype : 'Data' , reqd : 1
2015-11-24 11:36:54 +00:00
} ,
2017-07-03 12:53:57 +00:00
{
fieldname : 'company_abbr' ,
label : frappe . setup . domain === 'Education' ?
_ _ ( 'Institute Abbreviation' ) : _ _ ( 'Company Abbreviation' ) ,
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 ( "" ) ;
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 ) {
frappe . msgprint ( "Company Abbreviation cannot have more than 5 characters" ) ;
slide . get _field ( "company_abbr" ) . set _input ( "" ) ;
2015-11-16 07:28:14 +00:00
}
2017-07-03 12:53:57 +00:00
} ) ;
}
} ,
{
// Organisation
name : 'organisation' ,
domains : [ "all" ] ,
title : _ _ ( "Your Organization" ) ,
icon : "fa fa-building" ,
help : ( frappe . setup . domain === 'Education' ?
_ _ ( 'The name of the institute for which you are setting up this system.' ) :
_ _ ( 'The name of your company for which you are setting up this system.' ) ) ,
fields : [
{
fieldname : 'company_tagline' ,
label : _ _ ( 'What does it do?' ) ,
fieldtype : 'Data' ,
placeholder : frappe . setup . domain === 'Education' ?
_ _ ( 'e.g. "Primary School" or "University"' ) :
_ _ ( 'e.g. "Build tools for builders"' ) ,
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
} ,
2017-07-03 12:53:57 +00:00
{ fieldtype : "Section Break" , label : "Financial Year" } ,
{ fieldname : 'fy_start_date' , label : _ _ ( 'Start Date' ) , fieldtype : 'Date' , reqd : 1 } ,
{ fieldtype : "Column Break" } ,
{ fieldname : 'fy_end_date' , label : _ _ ( 'End Date' ) , fieldtype : 'Date' , reqd : 1 } ,
] ,
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 ( ) {
// validate fiscal year start and end dates
if ( this . values . fy _start _date == 'Invalid date' || this . values . fy _end _date == 'Invalid date' ) {
frappe . msgprint ( _ _ ( "Please enter valid Financial Year Start and End Dates" ) ) ;
return false ;
2015-11-09 11:23:11 +00:00
}
2017-07-03 12:53:57 +00:00
if ( ( this . values . company _name || "" ) . toLowerCase ( ) == "company" ) {
frappe . msgprint ( _ _ ( "Company Name cannot be Company" ) ) ;
return false ;
}
2015-11-16 07:28:14 +00:00
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
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 ) {
fy = [ "01-01" , "31-12" ] ;
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 ( ) ) {
next _year = current _year
current _year -= 1 ;
2015-11-16 07:28:14 +00:00
}
2017-07-03 12:53:57 +00:00
slide . get _field ( "fy_start_date" ) . set _value ( fy [ 0 ] + "-" + current _year ) ;
slide . get _field ( "fy_end_date" ) . set _value ( fy [ 1 ] + "-" + next _year ) ;
}
2015-11-09 11:23:11 +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" ,
args : { "country" : country } ,
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
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 ( ) ;
}
}
}
} )
}
2016-07-21 10:31:59 +00:00
} ,
2017-07-03 12:53:57 +00:00
bind _events : function ( slide ) {
// 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 . form . fields _dict . fy _end _date . set _value ( frappe . datetime . obj _to _user ( year _end _date ) ) ;
} ) ;
}
} ,
{
// Taxes
name : 'taxes' ,
domains : [ 'manufacturing' , 'services' , 'retail' , 'distribution' ] ,
icon : "fa fa-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." ) ,
add _more : 1 ,
max _count : 4 ,
fields : [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "tax" , label : _ _ ( "Tax" ) ,
placeholder : _ _ ( "e.g. VAT" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Float" , fieldname : "tax_rate" , label : _ _ ( "Rate (%)" ) , placeholder : _ _ ( "e.g. 5" ) }
]
} ,
{
// Customers
name : 'customers' ,
domains : [ 'manufacturing' , 'services' , 'retail' , 'distribution' ] ,
icon : "fa fa-group" ,
title : _ _ ( "Add Customers" ) ,
help : _ _ ( "List a few of your customers. They could be organizations or individuals." ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "customer" , label : _ _ ( "Customer" ) ,
placeholder : _ _ ( "Customer Name" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Data" , fieldname : "customer_contact" ,
label : _ _ ( "Contact Name" ) , placeholder : _ _ ( "Contact Name" ) }
] ,
} ,
{
// Suppliers
name : 'suppliers' ,
domains : [ 'manufacturing' , 'services' , 'retail' , 'distribution' ] ,
icon : "fa fa-group" ,
title : _ _ ( "Your Suppliers" ) ,
help : _ _ ( "List a few of your suppliers. They could be organizations or individuals." ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" } ,
{ fieldtype : "Data" , fieldname : "supplier" , label : _ _ ( "Supplier" ) ,
placeholder : _ _ ( "Supplier Name" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Data" , fieldname : "supplier_contact" ,
label : _ _ ( "Contact Name" ) , placeholder : _ _ ( "Contact Name" ) } ,
]
} ,
{
// Products
name : 'products' ,
domains : [ 'manufacturing' , 'services' , 'retail' , 'distribution' ] ,
icon : "fa fa-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." ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "item" , label : _ _ ( "Item" ) ,
placeholder : _ _ ( "A Product or Service" ) } ,
{ fieldtype : "Select" , label : _ _ ( "Group" ) , fieldname : "item_group" ,
options : [ _ _ ( "Products" ) , _ _ ( "Services" ) ,
_ _ ( "Raw Material" ) , _ _ ( "Consumable" ) , _ _ ( "Sub Assemblies" ) ] ,
"default" : _ _ ( "Products" ) } ,
{ fieldtype : "Select" , fieldname : "item_uom" , label : _ _ ( "UOM" ) ,
options : [ _ _ ( "Unit" ) , _ _ ( "Nos" ) , _ _ ( "Box" ) , _ _ ( "Pair" ) , _ _ ( "Kg" ) , _ _ ( "Set" ) ,
_ _ ( "Hour" ) , _ _ ( "Minute" ) , _ _ ( "Litre" ) , _ _ ( "Meter" ) , _ _ ( "Gram" ) ] ,
"default" : _ _ ( "Unit" ) } ,
{ fieldtype : "Check" , fieldname : "is_sales_item" , label : _ _ ( "We sell this Item" ) , default : 1 } ,
{ fieldtype : "Check" , fieldname : "is_purchase_item" , label : _ _ ( "We buy this Item" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Currency" , fieldname : "item_price" , label : _ _ ( "Rate" ) } ,
{ fieldtype : "Attach Image" , fieldname : "item_img" , label : _ _ ( "Attach Image" ) , is _private : 0 } ,
] ,
get _item _count : function ( ) {
return this . item _count ;
}
} ,
{
// Program
name : 'program' ,
domains : [ "education" ] ,
title : _ _ ( "Program" ) ,
help : _ _ ( "Example: Masters in Computer Science" ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "program" , label : _ _ ( "Program" ) , placeholder : _ _ ( "Program Name" ) } ,
] ,
} ,
{
// Course
name : 'course' ,
domains : [ "education" ] ,
title : _ _ ( "Course" ) ,
help : _ _ ( "Example: Basic Mathematics" ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "course" , label : _ _ ( "Course" ) , placeholder : _ _ ( "Course Name" ) } ,
]
} ,
{
// Instructor
name : 'instructor' ,
domains : [ "education" ] ,
title : _ _ ( "Instructor" ) ,
help : _ _ ( "People who teach at your organisation" ) ,
add _more : 1 ,
max _count : 6 ,
fields : [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "instructor" , label : _ _ ( "Instructor" ) , placeholder : _ _ ( "Instructor Name" ) } ,
]
} ,
{
// Room
name : 'room' ,
domains : [ "education" ] ,
title : _ _ ( "Room" ) ,
help : _ _ ( "Classrooms/ Laboratories etc where lectures can be scheduled." ) ,
add _more : 1 ,
max _count : 4 ,
fields : [
{ fieldtype : "Section Break" , show _section _border : true } ,
{ fieldtype : "Data" , fieldname : "room" , label : _ _ ( "Room" ) } ,
{ fieldtype : "Column Break" } ,
{ fieldtype : "Int" , fieldname : "room_capacity" , label : _ _ ( "Room" ) + " Capacity" } ,
]
} ,
{
// last slide: Bootstrap
name : 'bootstrap' ,
domains : [ "all" ] ,
title : _ _ ( "Bootstrap" ) ,
fields : [ { fieldtype : "Section Break" } ,
{ fieldtype : "Check" , fieldname : "add_sample_data" ,
label : _ _ ( "Add a few sample records" ) , "default" : 1 } ,
{ fieldtype : "Check" , fieldname : "setup_website" ,
label : _ _ ( "Setup a simple website for my organization" ) , "default" : 1 }
]
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 = {
"Afghanistan" : [ "20-12" , "21-12" ] ,
"Australia" : [ "01-07" , "30-06" ] ,
"Bangladesh" : [ "01-07" , "30-06" ] ,
"Canada" : [ "01-04" , "31-03" ] ,
"Costa Rica" : [ "01-10" , "30-09" ] ,
"Egypt" : [ "01-07" , "30-06" ] ,
"Hong Kong" : [ "01-04" , "31-03" ] ,
"India" : [ "01-04" , "31-03" ] ,
"Iran" : [ "23-06" , "22-06" ] ,
"Italy" : [ "01-07" , "30-06" ] ,
"Myanmar" : [ "01-04" , "31-03" ] ,
"New Zealand" : [ "01-04" , "31-03" ] ,
"Pakistan" : [ "01-07" , "30-06" ] ,
"Singapore" : [ "01-04" , "31-03" ] ,
"South Africa" : [ "01-03" , "28-02" ] ,
"Thailand" : [ "01-10" , "30-09" ] ,
"United Kingdom" : [ "01-04" , "31-03" ] ,
} ;
frappe . setup . on ( "before_load" , function ( ) {
erpnext _slides . map ( frappe . setup . add _slide ) ;
2016-07-05 16:04:21 +00:00
2017-07-03 12:53:57 +00:00
// change header brand
let $brand = $ ( 'header .setup-wizard-brand' ) ;
if ( $brand . find ( '.erpnext-icon' ) . length === 0 ) {
$brand . find ( '.frappe-icon' ) . hide ( ) ;
$brand . append ( ` <span>
< img src = "/assets/erpnext/images/erp-icon.svg" class = "brand-icon erpnext-icon"
style = "width:36px;" > < span class = "brand-name" > ERPNext < / s p a n > < / s p a n > ` ) ;
2016-07-21 10:31:59 +00:00
}
2015-11-09 11:23:11 +00:00
} ) ;
2016-07-21 10:31:59 +00:00
2017-05-30 07:24:42 +00:00
var test _values _edu = {
2017-07-03 12:53:57 +00:00
"language" : "english" ,
"domain" : "Education" ,
"country" : "India" ,
"timezone" : "Asia/Kolkata" ,
"currency" : "INR" ,
"first_name" : "Tester" ,
"email" : "test@example.com" ,
"password" : "test" ,
"company_name" : "Hogwarts" ,
"company_abbr" : "HS" ,
"company_tagline" : "School for magicians" ,
"bank_account" : "Gringotts Wizarding Bank" ,
"fy_start_date" : "2016-04-01" ,
"fy_end_date" : "2017-03-31"
2016-07-21 10:31:59 +00:00
}