updates to gzip, chart of accounts
This commit is contained in:
parent
fd1c166f5b
commit
4a91f29d0f
@ -27,11 +27,33 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) {
|
|||||||
title: 'Chart of Accounts',
|
title: 'Chart of Accounts',
|
||||||
single_column: true
|
single_column: true
|
||||||
});
|
});
|
||||||
erpnext.coa.company_select = wrapper.appframe.add_select("Company", ["Loading..."]);
|
|
||||||
|
erpnext.coa.make_page(wrapper);
|
||||||
|
erpnext.coa.load_companies();
|
||||||
|
}
|
||||||
|
erpnext.coa = {
|
||||||
|
make_page: function(wrapper) {
|
||||||
|
erpnext.coa.company_select = wrapper.appframe
|
||||||
|
.add_select("Company", ["Loading..."])
|
||||||
|
.change(function() {
|
||||||
|
erpnext.coa.chart = new erpnext.ChartOfAccounts();
|
||||||
|
});
|
||||||
|
|
||||||
erpnext.coa.opening_date = wrapper.appframe.add_date("Opening Date")
|
erpnext.coa.opening_date = wrapper.appframe.add_date("Opening Date")
|
||||||
.val(dateutil.str_to_user(sys_defaults.year_start_date));
|
.val(dateutil.str_to_user(sys_defaults.year_start_date));
|
||||||
|
|
||||||
|
var end_date = new Date();
|
||||||
|
if(end_date > dateutil.str_to_obj(sys_defaults.year_end_date))
|
||||||
|
end_date = sys_defaults.year_end_date;
|
||||||
|
|
||||||
erpnext.coa.closing_date = wrapper.appframe.add_date("Closing Date")
|
erpnext.coa.closing_date = wrapper.appframe.add_date("Closing Date")
|
||||||
.val(dateutil.obj_to_user(new Date()));
|
.val(dateutil.obj_to_user(end_date));
|
||||||
|
|
||||||
|
erpnext.coa.refresh_btn = wrapper.appframe.add_button("Refresh", function() {
|
||||||
|
erpnext.coa.chart = new erpnext.ChartOfAccounts();
|
||||||
|
}, "icon-refresh");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
erpnext.coa.waiting = $('<div class="well" style="width: 63%; margin: 30px auto;">\
|
erpnext.coa.waiting = $('<div class="well" style="width: 63%; margin: 30px auto;">\
|
||||||
<p style="text-align: center;">Building Trial Balance Report. \
|
<p style="text-align: center;">Building Trial Balance Report. \
|
||||||
@ -43,27 +65,27 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) {
|
|||||||
$('<div id="chart-of-accounts" style="height: 500px; border: 1px solid #aaa;">\
|
$('<div id="chart-of-accounts" style="height: 500px; border: 1px solid #aaa;">\
|
||||||
</div>').appendTo($(wrapper).find('.layout-main'));
|
</div>').appendTo($(wrapper).find('.layout-main'));
|
||||||
|
|
||||||
|
},
|
||||||
|
load_companies: function() {
|
||||||
wn.call({
|
wn.call({
|
||||||
module: "accounts",
|
module: "accounts",
|
||||||
page: "chart_of_accounts",
|
page: "chart_of_accounts",
|
||||||
method: "get_companies",
|
method: "get_companies",
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
erpnext.coa.waiting.toggle();
|
erpnext.coa.waiting.toggle();
|
||||||
erpnext.coa.company_select.empty().add_options(r.message.companies).change();
|
erpnext.coa.company_select.empty().add_options(r.message.companies)
|
||||||
|
.val(sys_defaults.company || r.message.companies[0]).change();
|
||||||
erpnext.coa.fiscal_years = r.message.fiscal_years;
|
erpnext.coa.fiscal_years = r.message.fiscal_years;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.coa.company_select.change(function() {
|
|
||||||
erpnext.coa.load_slickgrid();
|
|
||||||
erpnext.coa.load_data($(this).val());
|
|
||||||
});
|
|
||||||
|
|
||||||
erpnext.coa.opening_date.change(erpnext.coa.refresh);
|
|
||||||
erpnext.coa.closing_date.change(erpnext.coa.refresh);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
erpnext.coa = {
|
erpnext.ChartOfAccounts = Class.extend({
|
||||||
|
init: function() {
|
||||||
|
this.load_slickgrid();
|
||||||
|
this.load_data($(erpnext.coa.company_select).val());
|
||||||
|
},
|
||||||
load_slickgrid: function() {
|
load_slickgrid: function() {
|
||||||
// load tree
|
// load tree
|
||||||
wn.require('js/lib/jquery/jquery.ui.sortable');
|
wn.require('js/lib/jquery/jquery.ui.sortable');
|
||||||
@ -77,20 +99,20 @@ erpnext.coa = {
|
|||||||
wn.dom.set_style('.slick-cell { font-size: 12px; }');
|
wn.dom.set_style('.slick-cell { font-size: 12px; }');
|
||||||
},
|
},
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
erpnext.coa.prepare_balances();
|
this.prepare_balances();
|
||||||
erpnext.coa.render();
|
this.render();
|
||||||
},
|
},
|
||||||
load_data: function(company) {
|
load_data: function(company) {
|
||||||
|
var me = this;
|
||||||
wn.call({
|
wn.call({
|
||||||
module: "accounts",
|
module: "accounts",
|
||||||
page: "chart_of_accounts",
|
page: "chart_of_accounts",
|
||||||
method: "get_chart",
|
method: "get_chart",
|
||||||
args: {company: company},
|
args: {company: company},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
erpnext.coa.gl = r.message.gl;
|
me.gl = r.message.gl;
|
||||||
erpnext.coa.prepare_chart(r.message.chart);
|
me.prepare_chart(r.message.chart);
|
||||||
erpnext.coa.prepare_balances();
|
me.refresh();
|
||||||
erpnext.coa.render();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -104,11 +126,13 @@ erpnext.coa = {
|
|||||||
"id": v[0],
|
"id": v[0],
|
||||||
"name": v[0],
|
"name": v[0],
|
||||||
"parent": v[1],
|
"parent": v[1],
|
||||||
"opening": 0,
|
"debit_or_credit": v[2],
|
||||||
|
"opening_debit": 0,
|
||||||
|
"opening_credit": 0,
|
||||||
"debit": 0,
|
"debit": 0,
|
||||||
"credit": 0,
|
"credit": 0,
|
||||||
"closing": 0,
|
"closing_debit": 0,
|
||||||
"debit_or_credit": v[2],
|
"closing_credit": 0,
|
||||||
"is_pl": v[3]
|
"is_pl": v[3]
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -119,77 +143,108 @@ erpnext.coa = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
erpnext.coa.set_indent(data, parent_map);
|
this.set_indent(data, parent_map);
|
||||||
erpnext.coa.data = data;
|
this.data = data;
|
||||||
erpnext.coa.parent_map = parent_map;
|
this.parent_map = parent_map;
|
||||||
erpnext.coa.data_by_name = data_by_name;
|
this.data_by_name = data_by_name;
|
||||||
},
|
},
|
||||||
prepare_balances: function() {
|
prepare_balances: function() {
|
||||||
var gl = erpnext.coa.gl;
|
var gl = this.gl;
|
||||||
var opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val());
|
var me = this;
|
||||||
var closing_date = dateutil.user_to_obj(erpnext.coa.closing_date.val());
|
|
||||||
var fiscal_year = erpnext.coa.get_fiscal_year(opening_date, closing_date);
|
|
||||||
if (!fiscal_year) return;
|
|
||||||
|
|
||||||
$.each(erpnext.coa.data, function(i, v) {
|
this.opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val());
|
||||||
v.opening = v.debit = v.credit = v.closing = 0;
|
this.closing_date = dateutil.user_to_obj(erpnext.coa.closing_date.val());
|
||||||
|
this.set_fiscal_year();
|
||||||
|
if (!this.fiscal_year) return;
|
||||||
|
|
||||||
|
$.each(this.data, function(i, v) {
|
||||||
|
v.opening_debit = v.opening_credit = v.debit
|
||||||
|
= v.credit = v.closing_debit = v.closing_credit = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each(gl, function(i, v) {
|
$.each(gl, function(i, v) {
|
||||||
|
v[1] = me.data[v[1]].name;
|
||||||
var posting_date = dateutil.str_to_obj(v[0]);
|
var posting_date = dateutil.str_to_obj(v[0]);
|
||||||
var account = erpnext.coa.data_by_name[v[1]];
|
var account = me.data_by_name[v[1]];
|
||||||
|
me.update_balances(account, posting_date, v)
|
||||||
|
});
|
||||||
|
|
||||||
|
this.update_groups();
|
||||||
|
this.format_balances();
|
||||||
|
},
|
||||||
|
update_balances: function(account, posting_date, v) {
|
||||||
// opening
|
// opening
|
||||||
if (posting_date < opening_date || v[4] === "Yes") {
|
if (posting_date < this.opening_date || v[4] === "Y") {
|
||||||
if (account.is_pl === "Yes" && posting_date <= dateutil.str_to_obj(fiscal_year[1])) {
|
if (account.is_pl === "Yes" && posting_date <= dateutil.str_to_obj(this.fiscal_year[1])) {
|
||||||
// balance of previous fiscal_year should
|
// balance of previous fiscal_year should
|
||||||
// not be part of opening of pl account balance
|
// not be part of opening of pl account balance
|
||||||
} else {
|
} else {
|
||||||
if (account.debit_or_credit === "Debit") {
|
if(account.debit_or_credit=='D') {
|
||||||
account.opening += (v[2] - v[3]);
|
account.opening_debit += (v[2] - v[3]);
|
||||||
} else {
|
} else {
|
||||||
account.opening += (v[3] - v[2]);
|
account.opening_credit += (v[3] - v[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (opening_date <= posting_date && posting_date <= closing_date) {
|
} else if (this.opening_date <= posting_date && posting_date <= this.closing_date) {
|
||||||
// in between
|
// in between
|
||||||
account.debit += v[2];
|
account.debit += v[2];
|
||||||
account.credit += v[3];
|
account.credit += v[3];
|
||||||
}
|
}
|
||||||
// closing
|
// closing
|
||||||
if (account.debit_or_credit === "Debit") {
|
if(account.debit_or_credit=='D') {
|
||||||
account.closing = account.opening + account.debit - account.credit;
|
account.closing_debit = account.opening_debit + account.debit - account.credit;
|
||||||
} else {
|
} else {
|
||||||
account.closing = account.opening + account.credit - account.debit;
|
account.closing_credit = account.opening_credit - account.debit + account.credit;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update_groups: function() {
|
||||||
|
// update groups
|
||||||
|
var me= this;
|
||||||
|
$.each(this.data, function(i, account) {
|
||||||
|
// update groups
|
||||||
|
var parent = me.parent_map[account.name];
|
||||||
|
while(parent) {
|
||||||
|
parent_account = me.data_by_name[parent];
|
||||||
|
parent_account.opening_debit += account.opening_debit;
|
||||||
|
parent_account.opening_credit += account.opening_credit;
|
||||||
|
parent_account.debit += account.debit;
|
||||||
|
parent_account.credit += account.credit;
|
||||||
|
parent_account.closing_debit += account.closing_debit;
|
||||||
|
parent_account.closing_credit += account.closing_credit;
|
||||||
|
parent = me.parent_map[parent];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
format_balances: function() {
|
||||||
// format amount
|
// format amount
|
||||||
$.each(erpnext.coa.data, function(i, v) {
|
$.each(this.data, function(i, v) {
|
||||||
v.opening = fmt_money(v.opening);
|
v.opening_debit = fmt_money(v.opening_debit);
|
||||||
|
v.opening_credit = fmt_money(v.opening_credit);
|
||||||
v.debit = fmt_money(v.debit);
|
v.debit = fmt_money(v.debit);
|
||||||
v.credit = fmt_money(v.credit);
|
v.credit = fmt_money(v.credit);
|
||||||
v.closing = fmt_money(v.closing);
|
v.closing_debit = fmt_money(v.closing_debit);
|
||||||
|
v.closing_credit = fmt_money(v.closing_credit);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
get_fiscal_year: function(opening_date, closing_date) {
|
set_fiscal_year: function() {
|
||||||
if (opening_date > closing_date) {
|
if (this.opening_date > this.closing_date) {
|
||||||
msgprint("Opening Date should be before Closing Date");
|
msgprint("Opening Date should be before Closing Date");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fiscal_year = null;
|
this.fiscal_year = null;
|
||||||
|
var me = this;
|
||||||
$.each(erpnext.coa.fiscal_years, function(i, v) {
|
$.each(erpnext.coa.fiscal_years, function(i, v) {
|
||||||
if (opening_date >= dateutil.str_to_obj(v[1]) &&
|
if (me.opening_date >= dateutil.str_to_obj(v[1]) &&
|
||||||
closing_date <= dateutil.str_to_obj(v[2])) {
|
me.closing_date <= dateutil.str_to_obj(v[2])) {
|
||||||
fiscal_year = v;
|
me.fiscal_year = v;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!fiscal_year) {
|
if (!this.fiscal_year) {
|
||||||
msgprint("Opening Date and Closing Date should be within same Fiscal Year");
|
msgprint("Opening Date and Closing Date should be within same Fiscal Year");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return fiscal_year;
|
|
||||||
},
|
},
|
||||||
set_indent: function(data, parent_map) {
|
set_indent: function(data, parent_map) {
|
||||||
$.each(data, function(i, d) {
|
$.each(data, function(i, d) {
|
||||||
@ -205,22 +260,19 @@ erpnext.coa = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var me = this;
|
||||||
erpnext.coa.waiting.toggle(false);
|
erpnext.coa.waiting.toggle(false);
|
||||||
|
this.setup_dataview();
|
||||||
// initialize the model
|
|
||||||
erpnext.coa.dataView = new Slick.Data.DataView({ inlineFilters: true });
|
|
||||||
erpnext.coa.dataView.beginUpdate();
|
|
||||||
erpnext.coa.dataView.setItems(erpnext.coa.data);
|
|
||||||
erpnext.coa.dataView.setFilter(erpnext.coa.filter)
|
|
||||||
erpnext.coa.dataView.endUpdate();
|
|
||||||
|
|
||||||
var columns = [
|
var columns = [
|
||||||
{id: "name", name: "Account", field: "name", width: 400, cssClass: "cell-title",
|
{id: "name", name: "Account", field: "name", width: 300, cssClass: "cell-title",
|
||||||
formatter: erpnext.coa.account_formatter},
|
formatter: this.account_formatter},
|
||||||
{id: "opening", name: "Opening", field: "opening"},
|
{id: "opening_debit", name: "Opening (Dr)", field: "opening_debit", width: 100},
|
||||||
{id: "debit", name: "Debit", field: "debit"},
|
{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100},
|
||||||
{id: "credit", name: "Credit", field: "credit"},
|
{id: "debit", name: "Debit", field: "debit", width: 100},
|
||||||
{id: "closing", name: "Closing", field: "closing"}
|
{id: "credit", name: "Credit", field: "credit", width: 100},
|
||||||
|
{id: "closing_debit", name: "Closing (Dr)", field: "closing_debit", width: 100},
|
||||||
|
{id: "closing_credit", name: "Closing (Cr)", field: "closing_credit", width: 100}
|
||||||
];
|
];
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
@ -229,14 +281,36 @@ erpnext.coa = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// initialize the grid
|
// initialize the grid
|
||||||
var grid = new Slick.Grid("#chart-of-accounts", erpnext.coa.dataView, columns, options);
|
var grid = new Slick.Grid("#chart-of-accounts", this.dataView, columns, options);
|
||||||
erpnext.coa.add_events(grid);
|
this.add_events(grid);
|
||||||
erpnext.coa.grid = grid;
|
this.grid = grid;
|
||||||
|
},
|
||||||
|
setup_dataview: function() {
|
||||||
|
var me = this;
|
||||||
|
// initialize the model
|
||||||
|
this.dataView = new Slick.Data.DataView({ inlineFilters: true });
|
||||||
|
this.dataView.beginUpdate();
|
||||||
|
this.dataView.setItems(this.data);
|
||||||
|
this.dataView.setFilter(this.dataview_filter);
|
||||||
|
this.dataView.endUpdate();
|
||||||
|
},
|
||||||
|
dataview_filter: function(item) {
|
||||||
|
if (item.parent) {
|
||||||
|
var parent = item.parent;
|
||||||
|
while (parent) {
|
||||||
|
if (erpnext.coa.chart.data_by_name[parent]._collapsed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
parent = erpnext.coa.chart.parent_map[parent];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
add_events: function(grid) {
|
add_events: function(grid) {
|
||||||
|
var me = this;
|
||||||
grid.onClick.subscribe(function (e, args) {
|
grid.onClick.subscribe(function (e, args) {
|
||||||
if ($(e.target).hasClass("toggle")) {
|
if ($(e.target).hasClass("toggle")) {
|
||||||
var item = erpnext.coa.dataView.getItem(args.row);
|
var item = me.dataView.getItem(args.row);
|
||||||
if (item) {
|
if (item) {
|
||||||
if (!item._collapsed) {
|
if (!item._collapsed) {
|
||||||
item._collapsed = true;
|
item._collapsed = true;
|
||||||
@ -244,41 +318,29 @@ erpnext.coa = {
|
|||||||
item._collapsed = false;
|
item._collapsed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.coa.dataView.updateItem(item.id, item);
|
me.dataView.updateItem(item.id, item);
|
||||||
}
|
}
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.coa.dataView.onRowsChanged.subscribe(function (e, args) {
|
this.dataView.onRowsChanged.subscribe(function (e, args) {
|
||||||
grid.invalidateRows(args.rows);
|
grid.invalidateRows(args.rows);
|
||||||
grid.render();
|
grid.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.coa.dataView.onRowCountChanged.subscribe(function (e, args) {
|
this.dataView.onRowCountChanged.subscribe(function (e, args) {
|
||||||
grid.updateRowCount();
|
grid.updateRowCount();
|
||||||
grid.render();
|
grid.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
filter: function(item) {
|
|
||||||
if (item.parent) {
|
|
||||||
var parent = item.parent;
|
|
||||||
while (parent) {
|
|
||||||
if (erpnext.coa.data_by_name[parent]._collapsed) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
parent = erpnext.coa.parent_map[parent];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
account_formatter: function (row, cell, value, columnDef, dataContext) {
|
account_formatter: function (row, cell, value, columnDef, dataContext) {
|
||||||
value = value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
value = value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||||
var data = erpnext.coa.data;
|
var data = erpnext.coa.chart.data;
|
||||||
var spacer = "<span style='display:inline-block;height:1px;width:" +
|
var spacer = "<span style='display:inline-block;height:1px;width:" +
|
||||||
(15 * dataContext["indent"]) + "px'></span>";
|
(15 * dataContext["indent"]) + "px'></span>";
|
||||||
var idx = erpnext.coa.dataView.getIdxById(dataContext.id);
|
var idx = erpnext.coa.chart.dataView.getIdxById(dataContext.id);
|
||||||
if (data[idx + 1] && data[idx + 1].indent > data[idx].indent) {
|
if (data[idx + 1] && data[idx + 1].indent > data[idx].indent) {
|
||||||
if (dataContext._collapsed) {
|
if (dataContext._collapsed) {
|
||||||
return spacer + " <span class='toggle expand'></span> " + value;
|
return spacer + " <span class='toggle expand'></span> " + value;
|
||||||
@ -289,4 +351,4 @@ erpnext.coa = {
|
|||||||
return spacer + " <span class='toggle'></span> " + value;
|
return spacer + " <span class='toggle'></span> " + value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
@ -4,12 +4,23 @@ import webnotes
|
|||||||
def get_chart():
|
def get_chart():
|
||||||
company = webnotes.form_dict.get('company')
|
company = webnotes.form_dict.get('company')
|
||||||
res = {}
|
res = {}
|
||||||
res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit, is_pl_account from
|
res["chart"] = webnotes.conn.sql("""select name, parent_account,
|
||||||
|
if(debit_or_credit="Debit", "D", ""),
|
||||||
|
if(is_pl_account="Yes", "Y", "") from
|
||||||
tabAccount where company=%s and docstatus < 2 order by lft""", (company, ))
|
tabAccount where company=%s and docstatus < 2 order by lft""", (company, ))
|
||||||
|
|
||||||
res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0),
|
res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0),
|
||||||
ifnull(credit, 0), ifnull(is_opening, 'No')
|
ifnull(credit, 0), ifnull(is_opening, 'No')
|
||||||
from `tabGL Entry` where company=%s and ifnull(is_cancelled, "No") = "No"
|
from `tabGL Entry` where company=%s and ifnull(is_cancelled, "No") = "No"
|
||||||
order by posting_date""", (company, ))
|
order by posting_date""", (company, ), as_list=1)
|
||||||
|
|
||||||
|
idx_map = {}
|
||||||
|
for i in xrange(len(res["chart"])):
|
||||||
|
idx_map[res["chart"][i][0]] = i
|
||||||
|
|
||||||
|
for d in res["gl"]:
|
||||||
|
d[1] = idx_map[d[1]]
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user