2012-02-23 07:05:32 +00:00
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-04-13 13:34:55 +00:00
// tree of chart of accounts / cost centers
// multiple companies
// add node
// edit node
// see ledger
2012-02-21 11:56:50 +00:00
2012-04-13 13:34:55 +00:00
pscript [ 'onload_Accounts Browser' ] = function ( wrapper ) {
2012-04-16 08:03:14 +00:00
wn . require ( 'lib/js/wn/ui/tree.js' ) ;
2012-04-13 06:31:23 +00:00
wrapper . appframe = new wn . ui . AppFrame ( $ ( wrapper ) . find ( '.appframe-area' ) ) ;
wrapper . appframe . add _button ( 'New Company' , function ( ) { newdoc ( 'Company' ) ; } , 'icon-plus' ) ;
2012-04-16 13:06:46 +00:00
wrapper . appframe . add _button ( 'Refresh' , function ( ) {
wrapper . $company _select . change ( ) ;
} , 'icon-refresh' ) ;
2012-04-13 06:31:23 +00:00
2012-04-13 13:34:55 +00:00
// company-select
wrapper . $company _select = $ ( '<select class="accbrowser-company-select"></select>' )
. change ( function ( ) {
var ctype = wn . get _route ( ) [ 1 ] || 'Account' ;
erpnext . account _chart = new erpnext . AccountsChart ( ctype , $ ( this ) . val ( ) , wrapper ) ;
} )
. appendTo ( wrapper . appframe . $w . find ( '.appframe-toolbar' ) ) ;
// default company
if ( sys _defaults . company ) {
$ ( '<option>' )
. html ( sys _defaults . company )
. attr ( 'value' , sys _defaults . company )
. appendTo ( wrapper . $company _select ) ;
wrapper . $company _select
. val ( sys _defaults . company ) . change ( ) ;
2012-02-21 11:56:50 +00:00
}
2012-04-13 13:34:55 +00:00
// load up companies
wn . call ( {
method : 'accounts.page.accounts_browser.accounts_browser.get_companies' ,
callback : function ( r ) {
wrapper . $company _select . empty ( ) ;
$ . each ( r . message , function ( i , v ) {
$ ( '<option>' ) . html ( v ) . attr ( 'value' , v ) . appendTo ( wrapper . $company _select ) ;
} ) ;
wrapper . $company _select . val ( sys _defaults . company || r [ 0 ] ) ;
}
} ) ;
2011-06-08 09:07:15 +00:00
}
2012-04-13 13:34:55 +00:00
pscript [ 'onshow_Accounts Browser' ] = function ( wrapper ) {
// set route
var ctype = wn . get _route ( ) [ 1 ] || 'Account' ;
2012-04-16 08:03:14 +00:00
wrapper . appframe . title ( 'Chart of ' + ctype + 's' ) ;
2012-04-13 13:34:55 +00:00
if ( erpnext . account _chart && erpnext . account _chart . ctype != ctype ) {
wrapper . $company _select . change ( ) ;
}
}
erpnext . AccountsChart = Class . extend ( {
init : function ( ctype , company , wrapper ) {
$ ( wrapper ) . find ( '.tree-area' ) . empty ( ) ;
var me = this ;
me . ctype = ctype ;
2012-04-16 13:06:46 +00:00
me . company = company ;
2012-04-13 13:34:55 +00:00
this . tree = new wn . ui . Tree ( {
parent : $ ( wrapper ) . find ( '.tree-area' ) ,
label : company ,
args : { ctype : ctype } ,
method : 'accounts.page.accounts_browser.accounts_browser.get_children' ,
click : function ( link ) {
if ( me . cur _toolbar )
$ ( me . cur _toolbar ) . toggle ( false ) ;
if ( ! link . toolbar )
me . make _link _toolbar ( link ) ;
if ( link . toolbar ) {
me . cur _toolbar = link . toolbar ;
$ ( me . cur _toolbar ) . toggle ( true ) ;
}
}
} ) ;
this . tree . rootnode . $a . click ( ) ;
} ,
make _link _toolbar : function ( link ) {
var data = $ ( link ) . data ( 'node-data' ) ;
if ( ! data ) return ;
link . toolbar = $ ( '<span class="accbrowser-node-toolbar"></span>' ) . insertAfter ( link ) ;
// edit
$ ( '<a href="#!Form/' + encodeURIComponent ( this . ctype ) + '/'
+ encodeURIComponent ( data . value ) + '">Edit</a>' ) . appendTo ( link . toolbar ) ;
if ( data . expandable ) {
2012-04-16 13:06:46 +00:00
link . toolbar . append ( ' | <a onclick="erpnext.account_chart.new_node();">Add Child</a>' ) ;
} else if ( this . ctype == 'Account' ) {
link . toolbar . append ( ' | <a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>' ) ;
2012-04-13 13:34:55 +00:00
}
} ,
2012-04-16 13:06:46 +00:00
show _ledger : function ( ) {
var me = this ;
var node = me . selected _node ( ) ;
wn . set _route ( 'Report' , 'GL Entry' , 'General Ledger' ,
this . ctype + '=' + node . data ( 'label' ) ) ;
} ,
new _node : function ( ) {
if ( this . ctype == 'Account' ) {
this . new _account ( ) ;
} else {
this . new _cost _center ( ) ;
}
} ,
selected _node : function ( ) {
return this . tree . $w . find ( '.tree-link.selected' ) ;
} ,
2012-04-13 13:34:55 +00:00
new _account : function ( ) {
2012-04-16 13:06:46 +00:00
var me = this ;
// the dialog
var d = new wn . ui . Dialog ( {
title : 'New Account' ,
fields : [
{ fieldtype : 'Data' , fieldname : 'account_name' , label : 'New Account Name' , reqd : true } ,
{ fieldtype : 'Select' , fieldname : 'group_or_ledger' , label : 'Group or Ledger' ,
options : 'Group\nLedger' } ,
{ fieldtype : 'Select' , fieldname : 'account_type' , label : 'Account Type' ,
options : [ '' , 'Fixed Asset Account' , 'Bank or Cash' , 'Expense Account' , 'Tax' ,
'Income Account' , 'Chargeable' ] . join ( '\n' ) } ,
{ fieldtype : 'Float' , fieldname : 'tax_rate' , label : 'Tax Rate' } ,
{ fieldtype : 'Select' , fieldname : 'master_type' , label : 'Master Type' ,
options : [ 'NA' , 'Supplier' , 'Customer' , 'Employee' ] . join ( '\n' ) } ,
{ fieldtype : 'Button' , fieldname : 'create_new' , label : 'Create New' }
]
} )
2012-04-13 13:34:55 +00:00
2012-04-16 13:06:46 +00:00
var fd = d . fields _dict ;
// account type if ledger
$ ( fd . group _or _ledger . input ) . change ( function ( ) {
if ( $ ( this ) . val ( ) == 'Group' ) {
$ ( fd . account _type . wrapper ) . toggle ( false ) ;
$ ( fd . master _type . wrapper ) . toggle ( false ) ;
$ ( fd . tax _rate . wrapper ) . toggle ( false ) ;
} else {
$ ( fd . account _type . wrapper ) . toggle ( true ) ;
$ ( fd . master _type . wrapper ) . toggle ( true ) ;
if ( fd . account _type . get _value ( ) == 'Tax' ) {
$ ( fd . tax _rate . wrapper ) . toggle ( true ) ;
}
}
} ) ;
// tax rate if tax
$ ( fd . account _type . input ) . change ( function ( ) {
if ( $ ( this ) . val ( ) == 'Tax' ) {
$ ( fd . tax _rate . wrapper ) . toggle ( true ) ;
} else {
$ ( fd . tax _rate . wrapper ) . toggle ( false ) ;
}
} )
// create
$ ( fd . create _new . input ) . click ( function ( ) {
var btn = this ;
$ ( btn ) . set _working ( ) ;
var v = d . get _values ( ) ;
if ( ! v ) return ;
var node = me . selected _node ( ) ;
v . parent _account = node . data ( 'label' ) ;
v . company = me . company ;
$c _obj ( 'GL Control' , 'add_ac' , v ,
function ( r , rt ) {
$ ( btn ) . done _working ( ) ;
d . hide ( ) ;
node . trigger ( 'reload' ) ;
} ) ;
} ) ;
// show
d . onshow = function ( ) {
$ ( fd . group _or _ledger . input ) . change ( ) ;
}
d . show ( ) ;
2012-04-13 13:34:55 +00:00
} ,
2012-04-16 13:06:46 +00:00
2012-04-13 13:34:55 +00:00
new _cost _center : function ( ) {
2012-04-16 13:06:46 +00:00
var me = this ;
// the dialog
var d = new wn . ui . Dialog ( {
title : 'New Cost Center' ,
fields : [
{ fieldtype : 'Data' , fieldname : 'cost_center_name' , label : 'New Cost Center Name' , reqd : true } ,
{ fieldtype : 'Select' , fieldname : 'group_or_ledger' , label : 'Group or Ledger' ,
options : 'Group\nLedger' } ,
{ fieldtype : 'Button' , fieldname : 'create_new' , label : 'Create New' }
]
} )
// create
$ ( d . fields _dict . create _new . input ) . click ( function ( ) {
var btn = this ;
$ ( btn ) . set _working ( ) ;
var v = d . get _values ( ) ;
if ( ! v ) return ;
var node = me . selected _node ( ) ;
v . parent _cost _center = node . data ( 'label' ) ;
v . company _name = me . company ;
$c _obj ( 'GL Control' , 'add_cc' , v ,
function ( r , rt ) {
$ ( btn ) . done _working ( ) ;
d . hide ( ) ;
node . trigger ( 'reload' ) ;
} ) ;
} ) ;
d . show ( ) ;
}
2012-04-13 13:34:55 +00:00
} ) ;
/ *
pscript . make _chart = function ( b , wrapper ) {
pscript . ctype = b ;
$ ( wrapper ) . find ( '.tree-area' ) . empty ( )
$ ( wrapper ) . find ( '.layout-sidesection' ) . empty ( )
2011-06-08 09:07:15 +00:00
//================== table body======================================
var ac _main _grid = make _table ( $i ( 'ab_body' ) , 1 , 2 , '100%' , [ '60%' , '40%' ] , { border : "0px" , padding : "4px" , tableLayout : "fixed" , borderCollapse : "collapse" } ) ;
$y ( $td ( ac _main _grid , 0 , 0 ) , { border : "1px solid #dddddd" , padding : "8px" } ) ;
2012-03-22 06:07:08 +00:00
pscript . account _tree = $a ( $td ( ac _main _grid , 0 , 0 ) , 'div' , '' , { minHeight : '400px' } ) ;
2011-06-08 09:07:15 +00:00
$y ( $td ( ac _main _grid , 0 , 1 ) , { border : "1px solid #DDD" } ) ;
pscript . la = $a ( $td ( ac _main _grid , 0 , 1 ) , 'div' ) ;
pscript . acc _period _bal = $a ( $td ( ac _main _grid , 0 , 1 ) , 'div' ) ;
//=====================footer area ==================================
2012-04-13 13:34:55 +00:00
if ( pscript . ctype == 'Account' ) {
2011-06-08 09:07:15 +00:00
var footer = $a ( $i ( 'ab_body' ) , 'div' , '' , { backgroundColor : "#FFD" , padding : "8px" , color : "#444" , fontSize : "12px" , marginTop : "14px" } ) ;
var help1 = $a ( footer , 'span' ) ;
2011-12-28 11:48:09 +00:00
help1 . innerHTML = "<strong>Note:</strong> To create accounts for Customers and Suppliers, please create <a href='#!List/Customer'>Customer</a> and <a href='#!List/Supplier'>Supplier</a>"
2011-06-08 09:07:15 +00:00
+ " Masters. This will ensure that the accounts are linked to your Selling and Buying Processes. The Account Heads for Customer and Supplier will automatically be created."
}
// header and toolbar
// ------------------
2012-04-13 13:34:55 +00:00
wrapper . appframe . $titlebar . find ( '.appframe-title' ) . html ( 'Chart of ' + pscript . ctype + 's' ) ;
2011-06-08 09:07:15 +00:00
// select company
// --------------
var tab = make _table ( select _area , 1 , 2 , null , [ ] , { verticalAlign : 'middle' , padding : '2px' } ) ;
$td ( tab , 0 , 0 ) . innerHTML = 'Select Company' . bold ( ) ;
var sel = $a ( $td ( tab , 0 , 1 ) , 'select' , '' , { width : '160px' } ) ;
// set tree
var set _tree = function ( ) {
if ( pscript . ac _tree ) {
pscript . ac _tree . body . innerHTML = '' ;
}
pscript . make _ac _tree ( ) ;
var cn = sel _val ( sel ) ;
var n = pscript . ac _tree . addNode ( null , cn , null , pscript . ac _tree . std _onclick , pscript . ac _tree . std _onexp ) ;
n . rec = { } ;
n . rec . name = 'Root Node' ;
n . rec . account _name = cn ;
n . rec . cost _center _name = cn ;
pscript . set _ac _head ( '' , n . rec ) ;
$ds ( pscript . ac _head _area ) ;
}
// select company
add _sel _options ( sel , [ 'Loading...' ] ) ;
2011-06-28 09:18:19 +00:00
var callback = function ( r , rt ) {
2011-06-08 09:07:15 +00:00
empty _select ( sel ) ;
2011-06-28 09:18:19 +00:00
add _sel _options ( sel , r . message . cl , sys _defaults . company ) ;
2011-06-08 09:07:15 +00:00
set _tree ( ) ;
sel . onchange = function ( ) { set _tree ( ) ; }
}
$c _obj ( 'GL Control' , 'get_companies' , '' , callback ) ;
2011-06-28 09:18:19 +00:00
pscript . ab _company _sel = sel ;
2011-06-08 09:07:15 +00:00
pscript . make _ac _head ( ) ;
pscript . make _group _area ( ) ;
pscript . make _ledger _area ( ) ;
pscript . make _new _acc _dialog ( ) ;
pscript . make _new _cost _center _dialog ( ) ;
}
pscript . make _ac _tree = function ( ) {
2012-04-13 13:34:55 +00:00
//var type= sel_val($i('ctype'))
var type = pscript . ctype ;
2011-06-08 09:07:15 +00:00
var tree = new Tree ( pscript . account _tree , '90%' ) ;
pscript . ac _tree = tree ;
// on click
tree . std _onclick = function ( node ) {
pscript . cur _node = node ;
// show ledger
pscript . set _ac _head ( node . parent _account , node . rec , type ) ;
}
// on expand
tree . std _onexp = function ( node ) {
if ( node . expanded _once ) return ;
$ds ( node . loading _div ) ;
//set_ac_head
var callback = function ( r , rt ) {
$dh ( node . loading _div ) ;
var n = tree . allnodes [ r . message . parent _acc _name ] ;
var cl = r . message . cl ;
if ( type == 'Account' ) {
for ( var i = 0 ; i < cl . length ; i ++ ) {
var imgsrc = null ;
var has _children = true ;
if ( cl [ i ] . group _or _ledger == 'Ledger' ) {
2012-02-06 10:58:06 +00:00
var imgsrc = 'lib/images/icons/page.png' ;
2011-06-08 09:07:15 +00:00
has _children = false ;
}
var t = tree . addNode ( n , cl [ i ] . account _name , imgsrc , tree . std _onclick , has _children ? tree . std _onexp : null ) ;
t . rec = cl [ i ] ;
t . parent _account = r . message . parent ;
}
}
else {
for ( var i = 0 ; i < cl . length ; i ++ ) {
var imgsrc = null ;
var has _children = true ;
if ( cl [ i ] . group _or _ledger == 'Ledger' ) {
2012-02-06 10:58:06 +00:00
var imgsrc = 'lib/images/icons/page.png' ;
2011-06-08 09:07:15 +00:00
has _children = false ;
}
var t = tree . addNode ( n , cl [ i ] . cost _center _name , imgsrc , tree . std _onclick , has _children ? tree . std _onexp : null ) ;
t . rec = cl [ i ] ;
t . parent _account = r . message . parent ;
}
}
}
if ( type == 'Account' ) {
2012-04-13 13:34:55 +00:00
var arg = [ node . rec . name , node . rec . account _name , sel _val ( pscript . ab _company _sel ) , pscript . ctype ] ;
2011-06-08 09:07:15 +00:00
} else {
2012-04-13 13:34:55 +00:00
var arg = [ node . rec . name , node . rec . cost _center _name , sel _val ( pscript . ab _company _sel ) , pscript . ctype ] ;
2011-06-08 09:07:15 +00:00
}
$c _obj ( 'GL Control' , 'get_cl' , arg . join ( ',' ) , callback ) ;
}
}
pscript . make _ac _head = function ( ) {
var div = $a ( pscript . la , 'div' , 'ac_head' ) ;
div . main _head = $a ( div , 'h3' , '' , { padding : '4px' , margin : '0px' , backgroundColor : '#EEEEEE' , borderBottom : '1px solid #AAAAAA' } ) ;
div . sub _head1 = $a ( div , 'div' ) ;
div . sub _head2 = $a ( div , 'div' ) ;
div . balance _area = $a ( div , 'div' ) ;
$a ( div . balance _area , 'span' , 'sectionHeading' ) . innerHTML = "Balance:" ;
div . balance = $a ( div . balance _area , 'span' , 'ac_balance' ) ;
div . sub _head = $btn ( div , 'Edit' , function ( ) { loaddoc ( this . dt , this . dn ) ; } ) ;
pscript . ac _head _area = div ;
}
// Group / Ledger Area - set properties in the right column
//---------------------------------------------------------
2011-06-28 09:18:19 +00:00
pscript . set _ac _head = function ( parent _account , r , type ) {
var d = pscript . ac _head _area ;
2011-06-08 09:07:15 +00:00
d . main _head . innerHTML = r . account _name ;
$ds ( d . sub _head ) ;
2011-06-28 09:18:19 +00:00
$ds ( d . balance _area ) ;
var callback = function ( r , rt ) {
dcc = r . message ;
}
$c _obj ( 'GL Control' , 'get_company_currency' , pscript . ab _company _sel . value , callback ) ;
2011-06-08 09:07:15 +00:00
if ( r . name != 'Root Node' ) {
// Account group/ledger area
2011-06-28 09:18:19 +00:00
if ( type == 'Account' ) {
2011-06-08 09:07:15 +00:00
d . sub _head . dt = 'Account' ; d . sub _head . dn = r . name
d . sub _head1 . innerHTML = r . debit _or _credit + ' - ' + r . group _or _ledger ;
d . sub _head2 . innerHTML = 'Group: ' + parent _account ;
if ( r . group _or _ledger == 'Ledger' ) {
$ds ( pscript . ledger _area ) ;
$ds ( pscript . gl _rep ) ;
$dh ( pscript . cc _rep ) ;
$dh ( pscript . group _area ) ;
} else {
$dh ( pscript . ledger _area ) ;
$ds ( pscript . group _area ) ;
$ds ( pscript . acc _add _btn ) ;
$dh ( pscript . cc _add _btn ) ;
2011-06-28 09:18:19 +00:00
}
var callback = function ( r , rt ) {
dcc = r . message ;
}
2011-06-28 09:25:50 +00:00
$c _obj ( 'GL Control' , 'get_company_currency' , pscript . ab _company _sel . value , callback ) ;
2011-06-28 09:18:19 +00:00
2011-06-28 13:31:02 +00:00
d . balance . innerHTML = ( dcc ) + ' ' + ( r . balance ? fmt _money ( r . balance ) : '0.00' ) ;
2011-06-08 09:07:15 +00:00
}
//cost center group/ledger area
else {
$dh ( d . balance _area ) ;
d . main _head . innerHTML = r . cost _center _name ;
d . sub _head . dt = 'Cost Center' ; d . sub _head . dn = r . name
d . sub _head1 . innerHTML = '' ;
d . sub _head2 . innerHTML = 'Group: ' + parent _account ;
if ( r . group _or _ledger == 'Ledger' ) {
$ds ( pscript . ledger _area ) ;
$dh ( pscript . gl _rep ) ;
$ds ( pscript . cc _rep ) ;
$dh ( pscript . group _area ) ;
} else {
$dh ( pscript . ledger _area ) ;
$ds ( pscript . group _area ) ;
$ds ( pscript . cc _add _btn ) ;
$dh ( pscript . acc _add _btn ) ;
}
d . balance . innerHTML = '' ;
}
} else {
$dh ( d . sub _head ) ;
$dh ( pscript . ledger _area ) ;
$dh ( pscript . group _area ) ;
$dh ( d . balance _area ) ;
d . sub _head1 . innerHTML = '' ;
d . sub _head2 . innerHTML = 'Explore tree on your left to see details' ;
}
pscript . acc _period _bal . innerHTML = '' ;
}
// Group Area
// ----------
pscript . make _group _area = function ( type ) {
pscript . group _area = $a ( pscript . la , 'div' , 'ac_ledger' ) ;
// refresh
ref _btn = $a ( pscript . group _area , 'div' , '' , { fontSize : '14px' , marginBottom : '8px' , marginTop : '24px' , fontWeight : 'bold' } ) ;
2011-12-12 13:48:23 +00:00
ref _btn . innerHTML = '<img src="lib/images/icons/page_refresh.gif" style="margin-right: 8px"><span class="link_type">Refresh Tree</span>' ;
2011-06-08 09:07:15 +00:00
ref _btn . onclick = function ( ) {
pscript . cur _node . clear _child _nodes ( ) ;
pscript . cur _node . expand ( ) ;
}
pscript . group _area . ref _btn = ref _btn ;
// button for acc adding
pscript . acc _add _btn = $btn ( pscript . group _area , '+ Add a child Account' , function ( ) { pscript . new _acc _dialog . show ( ) ; } ) ;
// button for cost center adding
pscript . cc _add _btn = $btn ( pscript . group _area , '+ Add a child Cost Center' , null ) ;
//showing new cost center dialog
pscript . cc _add _btn . onclick = function ( ) {
// check for cost center name & group or ledger
pscript . cc _dialog . widgets [ 'Create' ] . onclick = function ( ) {
if ( ! pscript . cc _dialog . widgets [ 'New Cost Center Name' ] . value ) {
msgprint ( 'Please enter New Cost Center Name' ) ; return ;
}
if ( ! sel _val ( pscript . cc _dialog . widgets [ 'Group or Ledger' ] ) ) {
msgprint ( 'Please specify cost center is group or ledger' ) ; return ;
}
//args making
args = {
'cost_center_name' : pscript . cc _dialog . widgets [ 'New Cost Center Name' ] . value ,
'parent_cost_center' : pscript . cur _node . rec . name ,
'group_or_ledger' : sel _val ( pscript . cc _dialog . widgets [ 'Group or Ledger' ] ) ,
'company_name' : sel _val ( pscript . ab _company _sel ) ,
'company_abbr' : '' ,
'old_parent' : ''
}
//create cost center -- server to gl control
$c _obj ( 'GL Control' , 'add_cc' , docstring ( args ) , function ( r , rt ) {
pscript . cc _dialog . widgets [ 'New Cost Center Name' ] . value = '' ;
pscript . cc _dialog . hide ( ) ;
pscript . group _area . ref _btn . onclick ( ) ;
} ) ;
}
pscript . new _cost _center _dialog . show ( ) ;
}
}
// Ledger Area
// ----------
pscript . make _ledger _area = function ( ) {
pscript . ledger _area = $a ( pscript . la , 'div' , 'ac_ledger' ) ;
//General ledger report link
pscript . gl _rep = $a ( pscript . ledger _area , 'div' , '' , { fontSize : '14px' , marginBottom : '8px' , fontWeight : 'bold' } ) ;
2011-12-12 13:48:23 +00:00
pscript . gl _rep . innerHTML = '<img src="lib/images/icons/report.png" style="margin-right: 8px"><span class="link_type">Open Ledger</span>' ;
2011-06-08 09:07:15 +00:00
pscript . gl _rep . onclick = function ( ) { pscript . make _report ( 'gl' ) ; }
}
pscript . make _report = function ( flag ) {
if ( flag == 'gl' ) {
var callback = function ( report ) {
report . set _filter ( 'GL Entry' , 'Account' , pscript . cur _node . rec . name )
report . dt . run ( ) ;
}
loadreport ( 'GL Entry' , 'General Ledger' , callback ) ;
}
}
// New Account
pscript . make _new _acc _dialog = function ( ) {
var d = new Dialog ( 300 , 400 , 'Create A New Account' ) ;
d . make _body ( [
[ 'HTML' , 'Heading' ] ,
[ 'Data' , 'New Account Name' ] ,
[ 'Select' , 'Group or Ledger' , 'Specify whether the new account is a Ledger or Group' ] ,
[ 'Select' , 'Account Type' , '[Optional] Specify the type of this account' ] ,
[ 'Data' , 'Tax Rate' , 'Specify the default tax rate' ] ,
[ 'Select' , 'Master Type' , 'Specify the master type of this account' ] ,
[ 'Button' , 'Create' ]
] ) ;
add _sel _options ( d . widgets [ 'Group or Ledger' ] , [ 'Group' , 'Ledger' ] , 'Group' ) ;
add _sel _options ( d . widgets [ 'Account Type' ] , [ '' , 'Fixed Asset Account' , 'Bank or Cash' , 'Expense Account' , 'Tax' , 'Income Account' , 'Chargeable' ] , '' ) ;
add _sel _options ( d . widgets [ 'Master Type' ] , [ 'NA' , 'Supplier' , 'Customer' , 'Employee' ] , 'NA' ) ;
// hide / show account type
d . widgets [ 'Group or Ledger' ] . onchange = function ( ) {
if ( sel _val ( this ) == 'Ledger' ) $ds ( d . rows [ 'Account Type' ] ) ;
else $dh ( d . rows [ 'Account Type' ] ) ;
}
// hide / show tax rate
d . widgets [ 'Account Type' ] . onchange = function ( ) {
if ( sel _val ( this ) == 'Tax' || sel _val ( this ) == 'Chargeable' ) $ds ( d . rows [ 'Tax Rate' ] ) ;
else $dh ( d . rows [ 'Tax Rate' ] ) ;
}
d . onshow = function ( ) {
$dh ( this . rows [ 'Account Type' ] ) ;
$dh ( this . rows [ 'Tax Rate' ] ) ;
this . widgets [ 'Group or Ledger' ] . selectedIndex = 0 ;
this . widgets [ 'Account Type' ] . selectedIndex = 0 ;
this . widgets [ 'Master Type' ] . selectedIndex = 0 ;
d . widgets [ 'New Account Name' ] . value = '' ;
d . widgets [ 'Tax Rate' ] . value = '' ;
}
d . widgets [ 'Create' ] . onclick = function ( ) {
if ( ! d . widgets [ 'New Account Name' ] . value ) {
msgprint ( 'Please enter New Account Name' ) ; return ;
}
if ( ! sel _val ( d . widgets [ 'Master Type' ] ) ) {
msgprint ( 'Please enter master type of this new account' ) ; return ;
}
args = {
'account_name' : d . widgets [ 'New Account Name' ] . value ,
'parent_account' : pscript . cur _node . rec . name ,
'group_or_ledger' : sel _val ( d . widgets [ 'Group or Ledger' ] ) ,
'company' : sel _val ( pscript . ab _company _sel ) ,
'account_type' : sel _val ( d . widgets [ 'Account Type' ] ) ,
'tax_rate' : d . widgets [ 'Tax Rate' ] . value ,
'master_type' : sel _val ( d . widgets [ 'Master Type' ] )
}
$c _obj ( 'GL Control' , 'add_ac' , docstring ( args ) , function ( r , rt ) { d . hide ( ) ; pscript . group _area . ref _btn . onclick ( ) ; } ) ;
}
pscript . new _acc _dialog = d ;
}
// New Cost Center
pscript . make _new _cost _center _dialog = function ( ) {
pscript . cc _dialog = new Dialog ( 300 , 400 , 'Create A New Cost Center' ) ;
pscript . cc _dialog . make _body ( [
[ 'HTML' , 'Heading' ] ,
[ 'Data' , 'New Cost Center Name' ] ,
[ 'Select' , 'Group or Ledger' , 'Specify whether the new cost center is a Ledger or Group' ] ,
[ 'Button' , 'Create' ]
] ) ;
add _sel _options ( pscript . cc _dialog . widgets [ 'Group or Ledger' ] , [ 'Group' , 'Ledger' ] , 'Group' ) ;
pscript . new _cost _center _dialog = pscript . cc _dialog ;
}
2012-04-13 13:34:55 +00:00
* /