Skip to content

Commit

Permalink
Merge branch 'master' of github.com:webnotes/erpnext
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Doshi committed Sep 14, 2012
2 parents 906e2df + bf65507 commit 7eda68d
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 113 deletions.
7 changes: 6 additions & 1 deletion erpnext/accounts/doctype/fiscal_year/fiscal_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ def repost(self):
if not in_transaction:
sql("start transaction")

self.rebuid_account_tree()
self.clear_account_balances()
self.create_account_balances()
self.update_opening(self.doc.company)
self.post_entries()
sql("commit")

msgprint("Account balance reposted for fiscal year: " + self.doc.name)


def rebuid_account_tree(self):
from webnotes.utils.nestedset import rebuild_tree
rebuild_tree('Account', 'parent_account')

def clear_account_balances(self):
# balances clear - `tabAccount Balance` for fiscal year
sql("update `tabAccount Balance` t1, tabAccount t2 set t1.opening=0, t1.balance=0, t1.debit=0, t1.credit=0 where t1.fiscal_year=%s and t2.company = %s and t1.account = t2.name", (self.doc.name, self.doc.company))
Expand Down
97 changes: 56 additions & 41 deletions erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ erpnext.coa = {
.change(function() {
erpnext.coa.chart = new erpnext.ChartOfAccounts();
});

erpnext.coa.fiscal_year_select = wrapper.appframe
.add_select("Fiscal Year", ["Loading..."]).css("width", "100px")
.change(function() {
var selected_year = $(this).val();
var fiscal_year = $.map(erpnext.coa.fiscal_years, function(v) {
return v[0] === selected_year ? v : null;
});
erpnext.coa.opening_date.val(dateutil.str_to_user(fiscal_year[1]));
erpnext.coa.closing_date.val(dateutil.str_to_user(fiscal_year[2]));
erpnext.coa.refresh_btn.click();
})

erpnext.coa.opening_date = wrapper.appframe.add_date("Opening Date")
.val(dateutil.str_to_user(sys_defaults.year_start_date));
Expand All @@ -50,7 +62,7 @@ erpnext.coa = {
.val(dateutil.obj_to_user(end_date));

erpnext.coa.refresh_btn = wrapper.appframe.add_button("Refresh", function() {
erpnext.coa.chart = new erpnext.ChartOfAccounts();
erpnext.coa.chart.refresh();
}, "icon-refresh");


Expand All @@ -75,6 +87,9 @@ erpnext.coa = {
erpnext.coa.waiting.toggle();
erpnext.coa.company_select.empty().add_options(r.message.companies)
.val(sys_defaults.company || r.message.companies[0]).change();
erpnext.coa.fiscal_year_select.empty()
.add_options($.map(r.message.fiscal_years, function(v) { return v[0]; }))
.val(sys_defaults.fiscal_year);
erpnext.coa.fiscal_years = r.message.fiscal_years;
}
});
Expand All @@ -88,20 +103,44 @@ erpnext.ChartOfAccounts = Class.extend({
},
load_slickgrid: function() {
// load tree
wn.require('js/lib/jquery/jquery.ui.sortable');
wn.require('js/lib/slickgrid/slick.grid.css');
wn.require('js/lib/slickgrid/slick-default-theme.css');
wn.require('js/lib/slickgrid/jquery.event.drag.min.js');
wn.require('js/lib/slickgrid/slick.core.js');
wn.require('js/lib/slickgrid/slick.formatters.js');
wn.require('js/lib/slickgrid/slick.grid.js');
wn.require('js/lib/slickgrid/slick.dataview.js');
wn.dom.set_style('.slick-cell { font-size: 12px; }');
wn.dom.set_style('.slick-cell { font-size: 12px; }');
},
refresh: function() {
this.prepare_balances();
this.render();
},
render: function() {
var me = this;
erpnext.coa.waiting.toggle(false);
this.setup_dataview();

var columns = [
{id: "name", name: "Account", field: "name", width: 300, cssClass: "cell-title",
formatter: this.account_formatter},
{id: "opening_debit", name: "Opening (Dr)", field: "opening_debit", width: 100},
{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100},
{id: "debit", name: "Debit", field: "debit", width: 100},
{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 = {
editable: false,
enableColumnReorder: false
};

// initialize the grid
var grid = new Slick.Grid("#chart-of-accounts", this.dataView, columns, options);
this.add_events(grid);
this.grid = grid;
},
load_data: function(company) {
var me = this;
wn.call({
Expand All @@ -112,6 +151,9 @@ erpnext.ChartOfAccounts = Class.extend({
callback: function(r) {
me.gl = r.message.gl;
me.prepare_chart(r.message.chart);
$.each(me.gl, function(i, v) {
v[1] = me.accounts[v[1]].name;
});
me.refresh();
}
})
Expand Down Expand Up @@ -144,9 +186,9 @@ erpnext.ChartOfAccounts = Class.extend({
}
});
this.set_indent(data, parent_map);
this.data = data;
this.accounts = data;
this.parent_map = parent_map;
this.data_by_name = data_by_name;
this.accounts_by_name = data_by_name;
},
prepare_balances: function() {
var gl = this.gl;
Expand All @@ -157,15 +199,14 @@ erpnext.ChartOfAccounts = Class.extend({
this.set_fiscal_year();
if (!this.fiscal_year) return;

$.each(this.data, function(i, v) {
$.each(this.accounts, 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) {
v[1] = me.data[v[1]].name;
var posting_date = dateutil.str_to_obj(v[0]);
var account = me.data_by_name[v[1]];
var account = me.accounts_by_name[v[1]];
me.update_balances(account, posting_date, v)
});

Expand Down Expand Up @@ -200,11 +241,11 @@ erpnext.ChartOfAccounts = Class.extend({
update_groups: function() {
// update groups
var me= this;
$.each(this.data, function(i, account) {
$.each(this.accounts, function(i, account) {
// update groups
var parent = me.parent_map[account.name];
while(parent) {
parent_account = me.data_by_name[parent];
parent_account = me.accounts_by_name[parent];
parent_account.opening_debit += account.opening_debit;
parent_account.opening_credit += account.opening_credit;
parent_account.debit += account.debit;
Expand All @@ -217,7 +258,7 @@ erpnext.ChartOfAccounts = Class.extend({
},
format_balances: function() {
// format amount
$.each(this.data, function(i, v) {
$.each(this.accounts, function(i, v) {
v.opening_debit = fmt_money(v.opening_debit);
v.opening_credit = fmt_money(v.opening_credit);
v.debit = fmt_money(v.debit);
Expand Down Expand Up @@ -259,46 +300,20 @@ erpnext.ChartOfAccounts = Class.extend({
d.indent = indent;
});
},
render: function() {
var me = this;
erpnext.coa.waiting.toggle(false);
this.setup_dataview();

var columns = [
{id: "name", name: "Account", field: "name", width: 300, cssClass: "cell-title",
formatter: this.account_formatter},
{id: "opening_debit", name: "Opening (Dr)", field: "opening_debit", width: 100},
{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100},
{id: "debit", name: "Debit", field: "debit", width: 100},
{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 = {
editable: false,
enableColumnReorder: false
};

// initialize the grid
var grid = new Slick.Grid("#chart-of-accounts", this.dataView, columns, options);
this.add_events(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.setItems(this.accounts);
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) {
if (erpnext.coa.chart.accounts_by_name[parent]._collapsed) {
return false;
}
parent = erpnext.coa.chart.parent_map[parent];
Expand Down Expand Up @@ -337,7 +352,7 @@ erpnext.ChartOfAccounts = Class.extend({
},
account_formatter: function (row, cell, value, columnDef, dataContext) {
value = value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var data = erpnext.coa.chart.data;
var data = erpnext.coa.chart.accounts;
var spacer = "<span style='display:inline-block;height:1px;width:" +
(15 * dataContext["indent"]) + "px'></span>";
var idx = erpnext.coa.chart.dataView.getIdxById(dataContext.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_companies():
else:
res["companies"] = [r[0] for r in webnotes.conn.sql("""select name from tabCompany
where docstatus!=2""")]

res["fiscal_years"] = webnotes.conn.sql("""select name, year_start_date,
adddate(year_start_date, interval 1 year)
from `tabFiscal Year` where docstatus!=2
Expand Down
Empty file.
Empty file.
65 changes: 65 additions & 0 deletions erpnext/accounts/page/general_ledger/general_ledger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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({
parent: $(wrapper).find('.layout-main'),
appframe: wrapper.appframe,
doctypes: ["Company", "Account", "GL Entry"],
filters: [
{fieldtype:"Select", label: "Company", options:"Company",
filter: function(val, item) {
return item.company == val || val == "Select Company";
}},
{fieldtype:"Select", label: "Account", options:"Account",
filter: function(val, item) {
return item.account == val || val == "Select Account";
}},
{fieldtype:"Date", label: "From Date"},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date"},
{fieldtype:"Button", label: "Refresh"},
],
setup: function() {
this.setup_filters();
this.setup_columns();
},
setup_filters: function() {
var me = this;
// default filters
this.filter_inputs.company.val(sys_defaults.company);
this.filter_inputs.from_date.val(dateutil.str_to_user(sys_defaults.year_start_date));
this.filter_inputs.to_date.val(dateutil.str_to_user(sys_defaults.year_end_date));
this.filter_inputs.refresh.click(function() { me.refresh(); })
},
setup_columns: function() {
this.columns = [
{id: "posting_date", name: "Posting Date", field: "posting_date", width: 100,
formatter: this.date_formatter},
{id: "account", name: "Account", field: "account", width: 240},
{id: "debit", name: "Debit", field: "debit", width: 100,
formatter: this.currency_formatter},
{id: "credit", name: "Credit", field: "credit", width: 100,
formatter: this.currency_formatter},
];
},
prepare_data: function() {
this.prepare_data_view(wn.report_dump.data["GL Entry"]);
},
dataview_filter: function(item) {
var filters = wn.cur_grid_report.filter_inputs;
for (i in filters) {
var filter = filters[i].get(0);
if(filter.opts.filter && !filter.opts.filter($(filter).val(), item)) {
return false;
}
}
return true;
},
});

}

10 changes: 10 additions & 0 deletions erpnext/accounts/page/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import webnotes

@webnotes.whitelist()
def get_chart():
company = webnotes.form_dict.get('company')
res = {}
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, ))
28 changes: 28 additions & 0 deletions erpnext/accounts/page/general_ledger/general_ledger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Page, general-ledger
[

# These values are common in all dictionaries
{
'creation': '2012-09-13 13:50:13',
'docstatus': 0,
'modified': '2012-09-13 13:50:13',
'modified_by': u'Administrator',
'owner': u'Administrator'
},

# These values are common for all Page
{
'doctype': 'Page',
'module': u'Accounts',
'name': '__common__',
'page_name': u'general-ledger',
'standard': u'Yes',
'title': u'General Ledger'
},

# Page, general-ledger
{
'doctype': 'Page',
'name': u'general-ledger'
}
]
37 changes: 37 additions & 0 deletions erpnext/startup/report_data_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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/>.

data_map = {
"Account": {
"columns": ["name", "parent_account", "lft", "rgt", "debit_or_credit", "is_pl_account",
"company"],
"order_by": "lft"
},
"GL Entry": {
"columns": ["account", "posting_date", "cost_center", "debit", "credit", "is_opening",
"company"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date"
},
"Company": {
"columns": ["name"],
"conditions": ["docstatus < 2"]
},
"Fiscal Year": {
"columns": ["name", "year_start_date",
"adddate(year_start_date, interval 1 year) as year_end_date"]
}
}
Loading

0 comments on commit 7eda68d

Please sign in to comment.