2012-09-13 14:10:56 +00:00
|
|
|
wn.pages['general-ledger'].onload = function(wrapper) {
|
|
|
|
wn.ui.make_app_page({
|
|
|
|
parent: wrapper,
|
|
|
|
title: 'General Ledger',
|
|
|
|
single_column: true
|
|
|
|
});
|
|
|
|
|
|
|
|
erpnext.general_ledger = new wn.views.GridReport({
|
2012-09-14 12:42:17 +00:00
|
|
|
title: "General Ledger",
|
2012-09-17 13:40:36 +00:00
|
|
|
page: wrapper,
|
2012-09-13 14:10:56 +00:00
|
|
|
parent: $(wrapper).find('.layout-main'),
|
|
|
|
appframe: wrapper.appframe,
|
|
|
|
doctypes: ["Company", "Account", "GL Entry"],
|
2012-09-17 13:40:36 +00:00
|
|
|
|
2012-09-13 14:10:56 +00:00
|
|
|
setup_columns: function() {
|
|
|
|
this.columns = [
|
|
|
|
{id: "posting_date", name: "Posting Date", field: "posting_date", width: 100,
|
|
|
|
formatter: this.date_formatter},
|
2012-09-14 12:42:17 +00:00
|
|
|
{id: "account", name: "Account", field: "account", width: 240,
|
|
|
|
link_formatter: {
|
|
|
|
filter_input: "account",
|
|
|
|
open_btn: true,
|
|
|
|
doctype: '"Account"'
|
|
|
|
}},
|
2012-09-13 14:10:56 +00:00
|
|
|
{id: "debit", name: "Debit", field: "debit", width: 100,
|
|
|
|
formatter: this.currency_formatter},
|
|
|
|
{id: "credit", name: "Credit", field: "credit", width: 100,
|
|
|
|
formatter: this.currency_formatter},
|
2012-09-14 12:42:17 +00:00
|
|
|
{id: "voucher_type", name: "Voucher Type", field: "voucher_type", width: 120},
|
|
|
|
{id: "voucher_no", name: "Voucher No", field: "voucher_no", width: 160,
|
|
|
|
link_formatter: {
|
|
|
|
filter_input: "voucher_no",
|
|
|
|
open_btn: true,
|
|
|
|
doctype: "dataContext.voucher_type"
|
|
|
|
}},
|
|
|
|
{id: "remarks", name: "Remarks", field: "remarks", width: 200,
|
|
|
|
formatter: this.text_formatter},
|
|
|
|
|
2012-09-13 14:10:56 +00:00
|
|
|
];
|
|
|
|
},
|
2012-09-14 12:42:17 +00:00
|
|
|
filters: [
|
2012-09-17 13:40:36 +00:00
|
|
|
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
|
2012-09-14 12:42:17 +00:00
|
|
|
filter: function(val, item, opts) {
|
2012-09-19 06:31:01 +00:00
|
|
|
return item.company == val || val == opts.default_value;
|
2012-09-14 12:42:17 +00:00
|
|
|
}},
|
2012-09-17 13:40:36 +00:00
|
|
|
{fieldtype:"Select", label: "Account", link:"Account", default_value: "Select Account...",
|
|
|
|
filter: function(val, item, opts, me) {
|
2012-09-19 06:31:01 +00:00
|
|
|
if(val == opts.default_value) {
|
2012-09-17 13:40:36 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// true if GL Entry belongs to selected
|
|
|
|
// account ledger or group
|
|
|
|
return me.is_child_account(val, item.account);
|
|
|
|
}
|
2012-09-14 12:42:17 +00:00
|
|
|
}},
|
|
|
|
{fieldtype:"Data", label: "Voucher No",
|
|
|
|
filter: function(val, item, opts) {
|
|
|
|
if(!val) return true;
|
2012-09-19 06:31:01 +00:00
|
|
|
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1);
|
2012-09-14 12:42:17 +00:00
|
|
|
}},
|
|
|
|
{fieldtype:"Date", label: "From Date", filter: function(val, item) {
|
2012-09-19 06:31:01 +00:00
|
|
|
return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
|
2012-09-14 12:42:17 +00:00
|
|
|
}},
|
|
|
|
{fieldtype:"Label", label: "To"},
|
|
|
|
{fieldtype:"Date", label: "To Date", filter: function(val, item) {
|
2012-09-19 06:31:01 +00:00
|
|
|
return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
|
2012-09-14 12:42:17 +00:00
|
|
|
}},
|
|
|
|
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
|
|
|
|
{fieldtype:"Button", label: "Reset Filters"}
|
|
|
|
],
|
2012-09-17 13:40:36 +00:00
|
|
|
is_child_account: function(account, item_account) {
|
|
|
|
account = this.account_by_name[account];
|
|
|
|
item_account = this.account_by_name[item_account];
|
|
|
|
|
|
|
|
return (item_account.lft >= account.lft && item_account.rgt <= account.rgt)
|
|
|
|
},
|
2012-09-13 14:10:56 +00:00
|
|
|
prepare_data: function() {
|
2012-09-17 04:34:07 +00:00
|
|
|
// add Opening, Closing, Totals rows
|
|
|
|
// if filtered by account and / or voucher
|
|
|
|
var data = wn.report_dump.data["GL Entry"];
|
2012-09-19 06:31:01 +00:00
|
|
|
var out = [];
|
|
|
|
|
|
|
|
if(!this.account_by_name)
|
|
|
|
this.account_by_name = this.make_name_map(wn.report_dump.data["Account"]);
|
|
|
|
|
2012-09-17 13:40:36 +00:00
|
|
|
var me = this;
|
2012-09-17 04:34:07 +00:00
|
|
|
|
2012-09-19 06:31:01 +00:00
|
|
|
var from_date = dateutil.str_to_obj(this.from_date);
|
|
|
|
var to_date = dateutil.str_to_obj(this.to_date);
|
2012-09-17 04:34:07 +00:00
|
|
|
|
|
|
|
if(to_date < from_date) {
|
|
|
|
msgprint("From Date must be before To Date");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var opening = {
|
|
|
|
account: "Opening", debit: 0.0, credit: 0.0,
|
|
|
|
id:"_opening", _show: true, _style: "font-weight: bold"
|
|
|
|
}
|
|
|
|
var totals = {
|
|
|
|
account: "Totals", debit: 0.0, credit: 0.0,
|
|
|
|
id:"_totals", _show: true, _style: "font-weight: bold"
|
|
|
|
}
|
|
|
|
|
|
|
|
$.each(data, function(i, item) {
|
2012-09-19 06:31:01 +00:00
|
|
|
if((!me.is_default("account") ? me.is_child_account(me.account, item.account) : true) &&
|
|
|
|
(me.voucher_no ? item.voucher_no==me.voucher_no : true)) {
|
2012-09-17 13:40:36 +00:00
|
|
|
|
2012-09-17 04:34:07 +00:00
|
|
|
var date = dateutil.str_to_obj(item.posting_date);
|
2012-09-17 13:40:36 +00:00
|
|
|
|
2012-09-17 04:34:07 +00:00
|
|
|
if(date < from_date) {
|
|
|
|
opening.debit += item.debit;
|
|
|
|
opening.credit += item.credit;
|
|
|
|
} else if(date <= to_date) {
|
|
|
|
totals.debit += item.debit;
|
|
|
|
totals.credit += item.credit;
|
|
|
|
}
|
2012-09-19 06:31:01 +00:00
|
|
|
|
|
|
|
if(me.apply_filters(item)) {
|
|
|
|
out.push(item);
|
|
|
|
}
|
2012-09-17 04:34:07 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var closing = {
|
|
|
|
account: "Closing (Opening + Totals)", debit: opening.debit + totals.debit,
|
|
|
|
credit: opening.credit + totals.credit,
|
|
|
|
id:"_closing", _show: true, _style: "font-weight: bold"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-19 06:31:01 +00:00
|
|
|
if(!me.is_default("account")) {
|
2012-09-19 11:11:19 +00:00
|
|
|
if(me.account_by_name[me.account].debit_or_credit == "Debit") {
|
|
|
|
opening.debit -= opening.credit; opening.credit = 0;
|
|
|
|
closing.debit -= closing.credit; closing.credit = 0;
|
|
|
|
} else {
|
|
|
|
opening.credit -= opening.debit; opening.debit = 0;
|
|
|
|
closing.credit -= closing.debit; closing.debit = 0;
|
|
|
|
}
|
2012-09-19 06:31:01 +00:00
|
|
|
var out = [opening].concat(out).concat([totals, closing]);
|
2012-09-17 04:34:07 +00:00
|
|
|
} else {
|
2012-09-19 06:31:01 +00:00
|
|
|
var out = out.concat([totals]);
|
2012-09-17 04:34:07 +00:00
|
|
|
}
|
2012-09-20 13:33:14 +00:00
|
|
|
|
2012-09-19 11:11:19 +00:00
|
|
|
this.data = out;
|
2012-09-13 14:10:56 +00:00
|
|
|
},
|
2012-09-19 11:11:19 +00:00
|
|
|
get_plot_data: function() {
|
|
|
|
var data = [];
|
|
|
|
var me = this;
|
|
|
|
if(me.is_default("account") || me.voucher_no) return false;
|
|
|
|
var debit_or_credit = me.account_by_name[me.account].debit_or_credit;
|
|
|
|
var balance = debit_or_credit=="Debit" ? me.data[0].debit : me.data[0].credit;
|
|
|
|
data.push({
|
|
|
|
label: me.account,
|
|
|
|
data: [[dateutil.str_to_obj(me.from_date).getTime(), balance]]
|
|
|
|
.concat($.map(me.data, function(col, idx) {
|
|
|
|
if (col.posting_date) {
|
|
|
|
var diff = (debit_or_credit == "Debit" ? 1 : -1) * (flt(col.debit) - flt(col.credit));
|
|
|
|
balance += diff;
|
|
|
|
return [[dateutil.str_to_obj(col.posting_date).getTime(), balance - diff],
|
|
|
|
[dateutil.str_to_obj(col.posting_date).getTime(), balance]]
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
})).concat([
|
|
|
|
// closing
|
|
|
|
[dateutil.str_to_obj(me.to_date).getTime(), balance]
|
|
|
|
]),
|
|
|
|
points: {show: true},
|
|
|
|
lines: {show: true, fill: true},
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
get_plot_options: function() {
|
|
|
|
return {
|
|
|
|
grid: { hoverable: true, clickable: true },
|
|
|
|
xaxis: { mode: "time",
|
|
|
|
min: dateutil.str_to_obj(this.from_date).getTime(),
|
|
|
|
max: dateutil.str_to_obj(this.to_date).getTime() }
|
|
|
|
}
|
|
|
|
},
|
2012-09-13 14:10:56 +00:00
|
|
|
});
|
2012-09-14 12:42:17 +00:00
|
|
|
|
2012-09-13 14:10:56 +00:00
|
|
|
}
|
|
|
|
|