2011-06-08 09:07:15 +00:00
pscript [ 'onload_Accounts Browser' ] = function ( ) {
// if the user directly loads the page, ask to select the chart
var parent = $i ( 'ab_body' ) ;
parent . innerHTML = 'Please select your chart: '
var sel = $a ( parent , 'select' ) ;
add _sel _options ( sel , [ 'Account' , 'Cost Center' ] , 'Account' ) ;
var btn = $btn ( parent , 'Go' , function ( ) { pscript . make _chart ( sel _val ( sel ) ) ; } , { marginTop : '8px' } ) ;
}
pscript . make _chart = function ( b ) {
pscript . chart _type = b ;
$i ( 'ab_header' ) . innerHTML = '' ;
$i ( 'ab_body' ) . innerHTML = '' ;
//===============comment area========================================
var comment = $a ( $i ( 'ab_body' ) , 'div' , 'comment' , { marginBottom : "8px" } ) ;
comment . innerHTML = "Note: Explore and click on the tree node to add a new child" ;
var select _area = $a ( 'ab_body' , 'div' , '' , { margin : '8px 0px' } ) ;
//================== 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" } ) ;
pscript . account _tree = $a ( $td ( ac _main _grid , 0 , 0 ) , 'div' ) ;
$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 ==================================
if ( pscript . chart _type == 'Account' ) {
var footer = $a ( $i ( 'ab_body' ) , 'div' , '' , { backgroundColor : "#FFD" , padding : "8px" , color : "#444" , fontSize : "12px" , marginTop : "14px" } ) ;
var help1 = $a ( footer , 'span' ) ;
help1 . innerHTML = "<strong>Note:</strong> To create accounts for Customers and Suppliers, please create <a href='#Page/Selling'>Customer</a> and <a href='#Page/Buying'>Supplier</a>"
+ " 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
// ------------------
var h1 = 'Chart of ' + pscript . chart _type + 's' ;
if ( pscript . chart _type == 'Account' ) var d = 'accounting' ;
else var d = 'cost center' ;
var desc = 'Manage multiple companies and the ' + d + ' structures of each company.' ;
$i ( 'ab_body' ) . page _head = new PageHeader ( 'ab_header' , h1 , desc ) ;
// 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 _comp ( ) ;
pscript . make _new _cost _center _dialog ( ) ;
}
//New company link
pscript . make _new _comp = function ( ) {
$i ( 'ab_body' ) . page _head . add _button ( 'New Company' , function ( ) { new _doc ( 'Company' ) ; } , 0 , 'ui-icon-plus' ) ;
}
pscript . make _ac _tree = function ( ) {
//var type= sel_val($i('chart_type'))
var type = pscript . chart _type ;
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' ) {
2011-12-12 13:48:23 +00:00
var imgsrc = 'lib/images/icons/page.gif' ;
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' ) {
2011-12-12 13:48:23 +00:00
var imgsrc = 'lib/images/icons/page.gif' ;
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' ) {
var arg = [ node . rec . name , node . rec . account _name , sel _val ( pscript . ab _company _sel ) , pscript . chart _type ] ;
} else {
var arg = [ node . rec . name , node . rec . cost _center _name , sel _val ( pscript . ab _company _sel ) , pscript . chart _type ] ;
}
$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' ) ; }
//Budget report link
/ * p s c r i p t . c c _ r e p = $ a ( p s c r i p t . l e d g e r _ a r e a , ' d i v ' , ' ' , { f o n t S i z e : ' 1 4 p x ' , m a r g i n B o t t o m : ' 8 p x ' , f o n t W e i g h t : ' b o l d ' } ) ;
pscript . cc _rep . innerHTML = '<img src="images/icons/report.png" style="margin-right: 8px"><span class="link_type">Budget vs Actual Analysis Report</span>' ;
pscript . cc _rep . onclick = function ( ) { pscript . make _report ( 'budget' ) ; } * /
}
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 ) ;
}
/ * e l s e {
loadreport ( 'Budget Detail' , 'Periodical Budget Report' , function ( f ) {
f . set _filter ( 'Cost Center' , 'ID' , pscript . cur _node . rec . name ) ;
f . dt . run ( ) ;
} ) ;
} * /
}
// 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 ;
}