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-13 06:31:23 +00:00
|
|
|
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.appframe-area'));
|
2012-09-10 08:43:01 +00:00
|
|
|
|
|
|
|
if (wn.boot.profile.can_create.indexOf("Company") !== -1) {
|
|
|
|
wrapper.appframe.add_button('New Company', function() { newdoc('Company'); },
|
|
|
|
'icon-plus');
|
|
|
|
}
|
|
|
|
|
2012-05-22 11:24:46 +00:00
|
|
|
wrapper.appframe.add_button('Refresh', function() {
|
2012-04-16 13:06:46 +00:00
|
|
|
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'));
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
2012-09-10 08:43:01 +00:00
|
|
|
wrapper.$company_select.val(sys_defaults.company || r[0]).change();
|
2012-04-13 13:34:55 +00:00
|
|
|
}
|
|
|
|
});
|
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-07-11 07:48:58 +00:00
|
|
|
|
|
|
|
wrapper.appframe.clear_breadcrumbs();
|
2012-07-12 06:03:00 +00:00
|
|
|
wrapper.appframe.add_breadcrumb('Chart of '+ctype+'s');
|
|
|
|
document.title = 'Chart of '+ctype+'s';
|
2012-07-11 07:48:58 +00:00
|
|
|
wrapper.appframe.add_breadcrumb(' in <a href="#!accounts-home">Accounts</a>');
|
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,
|
2012-05-22 11:24:46 +00:00
|
|
|
args: {ctype: ctype, comp: company},
|
2012-04-13 13:34:55 +00:00
|
|
|
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);
|
|
|
|
}
|
2012-05-22 11:24:46 +00:00
|
|
|
|
|
|
|
// bold
|
|
|
|
$('.balance-bold').removeClass('balance-bold'); // deselect
|
|
|
|
$(link).parent().find('.balance-area:first').addClass('balance-bold'); // select
|
2012-04-13 13:34:55 +00:00
|
|
|
|
2012-05-22 11:24:46 +00:00
|
|
|
},
|
|
|
|
onrender: function(treenode) {
|
2012-05-31 08:02:45 +00:00
|
|
|
if (ctype == 'Account') {
|
|
|
|
var bal = treenode.data && treenode.data.balance.split(' ') || ['',''];
|
2012-06-29 13:37:20 +00:00
|
|
|
if (bal && flt(bal[1])) {
|
|
|
|
treenode.parent.append('<span class="balance-area">\
|
|
|
|
<span style="color: #aaa">'+ bal[0] + '</span> '
|
|
|
|
+ fmt_money(bal[1]) + '</span>');
|
|
|
|
}
|
2012-05-31 08:02:45 +00:00
|
|
|
}
|
2012-04-13 13:34:55 +00:00
|
|
|
}
|
|
|
|
});
|
2012-05-22 11:24:46 +00:00
|
|
|
this.tree.rootnode.$a.click();
|
2012-04-13 13:34:55 +00:00
|
|
|
},
|
|
|
|
make_link_toolbar: function(link) {
|
|
|
|
var data = $(link).data('node-data');
|
|
|
|
if(!data) return;
|
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
link.toolbar = $('<span class="tree-node-toolbar"></span>').insertAfter(link);
|
2012-08-23 13:03:58 +00:00
|
|
|
|
|
|
|
var node_links = [];
|
2012-04-13 13:34:55 +00:00
|
|
|
// edit
|
2012-08-23 13:03:58 +00:00
|
|
|
if (wn.boot.profile.can_read.indexOf(this.ctype) !== -1) {
|
|
|
|
node_links.push('<a href="#!Form/'+encodeURIComponent(this.ctype)+'/'
|
|
|
|
+encodeURIComponent(data.value)+'">Edit</a>');
|
2012-04-17 07:10:37 +00:00
|
|
|
}
|
2012-08-23 13:03:58 +00:00
|
|
|
if (data.expandable) {
|
2012-09-28 10:33:11 +00:00
|
|
|
if((wn.boot.profile.can_create.indexOf(this.ctype) !== -1) ||
|
|
|
|
(wn.boot.profile.in_create.indexOf(this.ctype) !== -1)) {
|
2012-08-23 13:03:58 +00:00
|
|
|
node_links.push('<a onclick="erpnext.account_chart.new_node();">Add Child</a>');
|
|
|
|
}
|
|
|
|
} else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) {
|
|
|
|
node_links.push('<a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>');
|
|
|
|
}
|
|
|
|
|
|
|
|
link.toolbar.append(node_links.join(" | "));
|
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();
|
2012-11-13 06:12:42 +00:00
|
|
|
wn.set_route("general-ledger", "account=" + node.data('label'));
|
2012-04-16 13:06:46 +00:00
|
|
|
},
|
|
|
|
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',
|
2012-07-11 09:09:33 +00:00
|
|
|
options:'Group\nLedger', description:'Further accounts can be made under Groups,\
|
|
|
|
but entries can be made against Ledger'},
|
2012-04-16 13:06:46 +00:00
|
|
|
{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:'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.tax_rate.wrapper).toggle(false);
|
|
|
|
} else {
|
|
|
|
$(fd.account_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');
|
2012-07-11 09:09:33 +00:00
|
|
|
v.master_type = '';
|
2012-04-16 13:06:46 +00:00
|
|
|
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',
|
2012-07-11 09:09:33 +00:00
|
|
|
options:'Group\nLedger', description:'Further accounts can be made under Groups,\
|
|
|
|
but entries can be made against Ledger'},
|
2012-04-16 13:06:46 +00:00
|
|
|
{fieldtype:'Button', fieldname:'create_new', label:'Create New' }
|
|
|
|
]
|
2012-07-11 09:09:33 +00:00
|
|
|
});
|
2012-04-16 13:06:46 +00:00
|
|
|
|
|
|
|
// 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-05-22 11:24:46 +00:00
|
|
|
});
|