From ad37f276da3519f3f4b096b071cc629cc60c39f2 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 12 Sep 2012 17:13:36 +0530 Subject: [PATCH 1/3] Created Chart of Accounts using Slick Grid and Tree --- .../page/chart_of_accounts/__init__.py | 0 .../chart_of_accounts/chart_of_accounts.css | 21 ++ .../chart_of_accounts/chart_of_accounts.html | 0 .../chart_of_accounts/chart_of_accounts.js | 201 ++++++++++++++++++ .../chart_of_accounts/chart_of_accounts.py | 25 +++ .../chart_of_accounts/chart_of_accounts.txt | 28 +++ public/images/collapse.gif | Bin 0 -> 846 bytes public/images/expand.gif | Bin 0 -> 851 bytes public/js/all-app.js | 8 +- public/js/all-web.js | 8 +- 10 files changed, 283 insertions(+), 8 deletions(-) create mode 100644 erpnext/accounts/page/chart_of_accounts/__init__.py create mode 100644 erpnext/accounts/page/chart_of_accounts/chart_of_accounts.css create mode 100644 erpnext/accounts/page/chart_of_accounts/chart_of_accounts.html create mode 100644 erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js create mode 100644 erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py create mode 100644 erpnext/accounts/page/chart_of_accounts/chart_of_accounts.txt create mode 100644 public/images/collapse.gif create mode 100644 public/images/expand.gif diff --git a/erpnext/accounts/page/chart_of_accounts/__init__.py b/erpnext/accounts/page/chart_of_accounts/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.css b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.css new file mode 100644 index 0000000000..00e05d4994 --- /dev/null +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.css @@ -0,0 +1,21 @@ +.cell-title { + font-weight: bold; +} + +.cell-effort-driven { + text-align: center; +} + +.toggle { + height: 9px; + width: 9px; + display: inline-block; +} + +.toggle.expand { + background: url(images/expand.gif) no-repeat center center; +} + +.toggle.collapse { + background: url(images/collapse.gif) no-repeat center center; +} \ No newline at end of file diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.html b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js new file mode 100644 index 0000000000..010b1fc1cd --- /dev/null +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js @@ -0,0 +1,201 @@ +// 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 . + +/* todo + - load / display chart of accounts + - settings for company, start date, end data + - load balances + - open ledger on link +*/ + +wn.pages['chart-of-accounts'].onload = function(wrapper) { + wn.ui.make_app_page({ + parent: wrapper, + title: 'Chart of Accounts', + single_column: true + }); + wrapper.appframe.add_button("Refresh", function() {}, "icon-refresh").css("margin-right", "12px"); + erpnext.coa.company_select = wrapper.appframe.add_select("Company", ["Loading..."]); + wrapper.appframe.add_date("Opening Date"); + wrapper.appframe.add_date("Closing Date"); + + $('
\ +
').appendTo($(wrapper).find('.layout-main')); + + wn.call({ + module: "accounts", + page: "chart_of_accounts", + method: "get_companies", + callback: function(r) { + erpnext.coa.company_select.empty().add_options(r.message).change(); + } + }); + + erpnext.coa.company_select.change(function() { + erpnext.coa.load_slickgrid(); + erpnext.coa.load_data($(this).val()); + }); +} + +erpnext.coa = { + 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; }'); + }, + load_data: function(company) { + wn.call({ + module: "accounts", + page: "chart_of_accounts", + method: "get_chart", + args: {company: company}, + callback: function(r) { + erpnext.coa.prepare_data(r.message); + erpnext.coa.render() + } + }) + }, + prepare_data: function(indata) { + var data = []; + var parent_map = {}; + var data_by_name = {}; + $.each(indata, function(i, v) { + if(v[0]) { + var d = { + "id": v[0], + "name": v[0], + "parent": v[1], + "opening": Math.random() * 100, + "debits": Math.random() * 100, + "credits": Math.random() * 100 + }; + d["closing"] = d['opening'] + d['debits'] - d['credits']; + + data.push(d); + data_by_name[d.name] = d; + if(d.parent) { + parent_map[d.name] = d.parent; + } + } + }); + erpnext.coa.set_indent(data, parent_map); + erpnext.coa.data = data; + erpnext.coa.parent_map = parent_map; + erpnext.coa.data_by_name = data_by_name; + }, + set_indent: function(data, parent_map) { + $.each(data, function(i, d) { + var indent = 0; + var parent = parent_map[d.name]; + if(parent) { + while(parent) { + indent++; + parent = parent_map[parent]; + } + } + d.indent = indent; + }); + }, + render: function() { + // 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 = [ + {id: "name", name: "Account", field: "name", width: 400, cssClass: "cell-title", + formatter: erpnext.coa.account_formatter}, + {id: "opening", name: "Opening", field: "opening"}, + {id: "debits", name: "Debits", field: "debits"}, + {id: "credits", name: "Credits", field: "credits"}, + {id: "closing", name: "Closing", field: "closing"} + ]; + + var options = { + editable: false, + enableColumnReorder: false + }; + + // initialize the grid + var grid = new Slick.Grid("#chart-of-accounts", erpnext.coa.dataView, columns, options); + erpnext.coa.add_events(grid); + }, + add_events: function(grid) { + grid.onClick.subscribe(function (e, args) { + if ($(e.target).hasClass("toggle")) { + var item = erpnext.coa.dataView.getItem(args.row); + if (item) { + if (!item._collapsed) { + item._collapsed = true; + } else { + item._collapsed = false; + } + + erpnext.coa.dataView.updateItem(item.id, item); + } + e.stopImmediatePropagation(); + } + }); + + erpnext.coa.dataView.onRowsChanged.subscribe(function (e, args) { + grid.invalidateRows(args.rows); + grid.render(); + }); + + erpnext.coa.dataView.onRowCountChanged.subscribe(function (e, args) { + grid.updateRowCount(); + 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) { + value = value.replace(/&/g,"&").replace(//g,">"); + var data = erpnext.coa.data; + var spacer = ""; + var idx = erpnext.coa.dataView.getIdxById(dataContext.id); + if (data[idx + 1] && data[idx + 1].indent > data[idx].indent) { + if (dataContext._collapsed) { + return spacer + "  " + value; + } else { + return spacer + "  " + value; + } + } else { + return spacer + "  " + value; + } + } +} diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py new file mode 100644 index 0000000000..b3c21872ee --- /dev/null +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py @@ -0,0 +1,25 @@ +import webnotes + +@webnotes.whitelist() +def get_chart(): + company = webnotes.form_dict.get('company') + return webnotes.conn.sql("""select name, parent_account from + tabAccount where company=%s and docstatus < 2 order by lft""", company) + +@webnotes.whitelist() +def get_companies(): + """get a list of companies based on permission""" + + # check if match permission exists + res = webnotes.conn.sql("""select role, `match` from `tabDocPerm` + where parent='Account' and permlevel=0 and `read`=1""", as_dict=1) + + match = any((r["match"] for r in res + if r["role"] in webnotes.user.roles and r["match"]=="company")) + + # if match == company is specified and companies are specified in user defaults + if match and webnotes.user.get_defaults().get("company"): + return webnotes.user.get_defaults().get("company") + else: + return [r[0] for r in webnotes.conn.sql("""select name from tabCompany + where docstatus!=2""")] diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.txt b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.txt new file mode 100644 index 0000000000..e9d5ab5065 --- /dev/null +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.txt @@ -0,0 +1,28 @@ +# Page, chart-of-accounts +[ + + # These values are common in all dictionaries + { + 'creation': '2012-09-12 14:43:52', + 'docstatus': 0, + 'modified': '2012-09-12 14:43:53', + 'modified_by': u'Administrator', + 'owner': u'Administrator' + }, + + # These values are common for all Page + { + 'doctype': 'Page', + 'module': u'Accounts', + 'name': '__common__', + 'page_name': u'Chart of Accounts', + 'standard': u'Yes', + 'title': u'Chart of Accounts' + }, + + # Page, chart-of-accounts + { + 'doctype': 'Page', + 'name': u'chart-of-accounts' + } +] \ No newline at end of file diff --git a/public/images/collapse.gif b/public/images/collapse.gif new file mode 100644 index 0000000000000000000000000000000000000000..01e691450c48632dc92a40a8c2b509bf99987225 GIT binary patch literal 846 zcmZ?wbhEHb$FyaIl$)g-gQVfI}k_i-?$k!^A~S3=)P?0Tm31hZvXy UI%HM~I5JIC=Ul}jAi!V^09i~Z*8l(j literal 0 HcmV?d00001 diff --git a/public/images/expand.gif b/public/images/expand.gif new file mode 100644 index 0000000000000000000000000000000000000000..1b24ef1248de55c6140895f6760758a1579f14cf GIT binary patch literal 851 zcmZ?wbhEHb$FyaIl$)g-gPK!J(0fMMMlpH!w1DF=kxpFl=aGX3~-h X>0od?I!Q%XL14k81*aJp85yhr3QsCm literal 0 HcmV?d00001 diff --git a/public/js/all-app.js b/public/js/all-app.js index 5876391adb..50e3ca2a2a 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -183,7 +183,7 @@ return cookies[c];} wn.dom.set_box_shadow=function(ele,spread){$(ele).css('-moz-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);') $(ele).css('-webkit-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);') $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){$.fn.add_options=function(options_list){for(var i=0;i').html(label).attr('value',value).appendTo(this);} -$(this).val(options_list[0].value||options_list[0]);} +return $(this).val(options_list[0].value||options_list[0]);} $.fn.set_working=function(){var ele=this.get(0);$(ele).attr('disabled','disabled');if(ele.loading_img){$(ele.loading_img).toggle(true);}else{ele.loading_img=$('').insertAfter(ele);}} $.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery); @@ -854,10 +854,10 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w \ ×\ ').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();}) -if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){if(!this.$w.find('.appframe-toolbar').length) -this.$w.append('
');args={label:label,icon:''};if(icon){args.icon='';} +if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.$w.find('.appframe-toolbar'));return this.buttons[label];},clear_buttons:function(){this.$w.find('.appframe-toolbar').empty();}});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\ + %(icon)s %(label)s',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) +this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\
');}else{$(opts.parent).html('
\ diff --git a/public/js/all-web.js b/public/js/all-web.js index 8f682f14c6..2454dded70 100644 --- a/public/js/all-web.js +++ b/public/js/all-web.js @@ -70,7 +70,7 @@ return cookies[c];} wn.dom.set_box_shadow=function(ele,spread){$(ele).css('-moz-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);') $(ele).css('-webkit-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);') $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){$.fn.add_options=function(options_list){for(var i=0;i').html(label).attr('value',value).appendTo(this);} -$(this).val(options_list[0].value||options_list[0]);} +return $(this).val(options_list[0].value||options_list[0]);} $.fn.set_working=function(){var ele=this.get(0);$(ele).attr('disabled','disabled');if(ele.loading_img){$(ele.loading_img).toggle(true);}else{ele.loading_img=$('').insertAfter(ele);}} $.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery); @@ -513,10 +513,10 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w \ ×\
').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();}) -if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){if(!this.$w.find('.appframe-toolbar').length) -this.$w.append('
');args={label:label,icon:''};if(icon){args.icon='';} +if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.$w.find('.appframe-toolbar'));return this.buttons[label];},clear_buttons:function(){this.$w.find('.appframe-toolbar').empty();}});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\ + %(icon)s %(label)s',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) +this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\
');}else{$(opts.parent).html('
\ From 0fa8e33835c8bcd9152cce6101b645523873c4fc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 12 Sep 2012 18:14:12 +0530 Subject: [PATCH 2/3] chart of accounts: balances calculation --- .../chart_of_accounts/chart_of_accounts.js | 74 ++++++++++++++++--- .../chart_of_accounts/chart_of_accounts.py | 9 ++- public/js/all-app.js | 4 +- public/js/all-web.js | 4 +- 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js index 010b1fc1cd..43fe56c310 100644 --- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js @@ -27,10 +27,11 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) { title: 'Chart of Accounts', single_column: true }); - wrapper.appframe.add_button("Refresh", function() {}, "icon-refresh").css("margin-right", "12px"); erpnext.coa.company_select = wrapper.appframe.add_select("Company", ["Loading..."]); - wrapper.appframe.add_date("Opening Date"); - wrapper.appframe.add_date("Closing Date"); + erpnext.coa.opening_date = wrapper.appframe.add_date("Opening Date") + .val(dateutil.str_to_user(sys_defaults.year_start_date)); + erpnext.coa.closing_date = wrapper.appframe.add_date("Closing Date") + .val(dateutil.obj_to_user(new Date())); $('
\
').appendTo($(wrapper).find('.layout-main')); @@ -48,6 +49,9 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) { 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 = { @@ -63,6 +67,10 @@ erpnext.coa = { wn.require('js/lib/slickgrid/slick.dataview.js'); wn.dom.set_style('.slick-cell { font-size: 12px; }'); }, + refresh: function() { + erpnext.coa.prepare_balances(); + erpnext.coa.render(); + }, load_data: function(company) { wn.call({ module: "accounts", @@ -70,12 +78,14 @@ erpnext.coa = { method: "get_chart", args: {company: company}, callback: function(r) { - erpnext.coa.prepare_data(r.message); - erpnext.coa.render() + erpnext.coa.gl = r.message.gl; + erpnext.coa.prepare_chart(r.message.chart); + erpnext.coa.prepare_balances(); + erpnext.coa.render(); } }) }, - prepare_data: function(indata) { + prepare_chart: function(indata) { var data = []; var parent_map = {}; var data_by_name = {}; @@ -85,11 +95,12 @@ erpnext.coa = { "id": v[0], "name": v[0], "parent": v[1], - "opening": Math.random() * 100, - "debits": Math.random() * 100, - "credits": Math.random() * 100 + "opening": 0, + "debit": 0, + "credit": 0, + "closing": 0, + "debit_or_credit": v[2], }; - d["closing"] = d['opening'] + d['debits'] - d['credits']; data.push(d); data_by_name[d.name] = d; @@ -103,6 +114,44 @@ erpnext.coa = { erpnext.coa.parent_map = parent_map; erpnext.coa.data_by_name = data_by_name; }, + prepare_balances: function() { + var gl = erpnext.coa.gl; + var opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val()); + var closing_date = dateutil.user_to_obj(erpnext.coa.closing_date.val()); + $.each(erpnext.coa.data, function(i, v) { + v.opening = v.debit = v.credit = v.closing = 0; + }); + $.each(gl, function(i, v) { + var posting_date = dateutil.str_to_obj(v[0]); + var account = erpnext.coa.data_by_name[v[1]]; + // opening + if (posting_date < opening_date) { + if (account.debit_or_credit === "Debit") { + account.opening += (v[2] - v[3]); + } else { + account.opening += (v[3] - v[2]); + } + } else if (opening_date <= posting_date && posting_date <= closing_date) { + // in between + account.debit += v[2]; + account.credit += v[3]; + } + // closing + if (account.debit_or_credit === "Debit") { + account.closing = account.opening + account.debit - account.credit; + } else { + account.closing = account.opening + account.credit - account.debit; + } + }); + + // format amount + $.each(erpnext.coa.data, function(i, v) { + v.opening = fmt_money(v.opening); + v.debit = fmt_money(v.debit); + v.credit = fmt_money(v.credit); + v.closing = fmt_money(v.closing); + }); + }, set_indent: function(data, parent_map) { $.each(data, function(i, d) { var indent = 0; @@ -128,8 +177,8 @@ erpnext.coa = { {id: "name", name: "Account", field: "name", width: 400, cssClass: "cell-title", formatter: erpnext.coa.account_formatter}, {id: "opening", name: "Opening", field: "opening"}, - {id: "debits", name: "Debits", field: "debits"}, - {id: "credits", name: "Credits", field: "credits"}, + {id: "debit", name: "Debit", field: "debit"}, + {id: "credit", name: "Credit", field: "credit"}, {id: "closing", name: "Closing", field: "closing"} ]; @@ -141,6 +190,7 @@ erpnext.coa = { // initialize the grid var grid = new Slick.Grid("#chart-of-accounts", erpnext.coa.dataView, columns, options); erpnext.coa.add_events(grid); + erpnext.coa.grid = grid; }, add_events: function(grid) { grid.onClick.subscribe(function (e, args) { diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py index b3c21872ee..620368f079 100644 --- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py @@ -3,8 +3,13 @@ import webnotes @webnotes.whitelist() def get_chart(): company = webnotes.form_dict.get('company') - return webnotes.conn.sql("""select name, parent_account from - tabAccount where company=%s and docstatus < 2 order by lft""", company) + res = {} + res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit from + tabAccount where company=%s and docstatus < 2 order by lft""", (company, )) + res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0), ifnull(credit, 0) + from `tabGL Entry` where company=%s and ifnull(is_cancelled, "No") = "No" + order by posting_date""", (company, )) + return res @webnotes.whitelist() def get_companies(): diff --git a/public/js/all-app.js b/public/js/all-app.js index 50e3ca2a2a..7ab9092a96 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -492,7 +492,7 @@ return val;},full_str:function(){var d=new Date();return d.getFullYear()+'-'+(d. else if(user_fmt=='dd/mm/yyyy'){var d=d.split('/');return d[2]+'-'+d[1]+'-'+d[0];} else if(user_fmt=='yyyy-mm-dd'){return d;} else if(user_fmt=='mm/dd/yyyy'){var d=d.split('/');return d[2]+'-'+d[0]+'-'+d[1];} -else if(user_fmt=='mm-dd-yyyy'){var d=d.split('-');return d[2]+'-'+d[0]+'-'+d[1];}},global_date_format:function(d){if(d.substr)d=this.str_to_obj(d);return nth(d.getDate())+' '+month_list_full[d.getMonth()]+' '+d.getFullYear();},get_today:function(){var today=new Date();var m=(today.getMonth()+1)+'';if(m.length==1)m='0'+m;var d=today.getDate()+'';if(d.length==1)d='0'+d;return today.getFullYear()+'-'+m+'-'+d;},get_cur_time:function(){var d=new Date();var hh=d.getHours()+'' +else if(user_fmt=='mm-dd-yyyy'){var d=d.split('-');return d[2]+'-'+d[0]+'-'+d[1];}},user_to_obj:function(d){return dateutil.str_to_obj(dateutil.user_to_str(d));},global_date_format:function(d){if(d.substr)d=this.str_to_obj(d);return nth(d.getDate())+' '+month_list_full[d.getMonth()]+' '+d.getFullYear();},get_today:function(){var today=new Date();var m=(today.getMonth()+1)+'';if(m.length==1)m='0'+m;var d=today.getDate()+'';if(d.length==1)d='0'+d;return today.getFullYear()+'-'+m+'-'+d;},get_cur_time:function(){var d=new Date();var hh=d.getHours()+'' var mm=cint(d.getMinutes()/5)*5+'' return(hh.length==1?'0'+hh:hh)+':'+(mm.length==1?'0'+mm:mm);}} wn.datetime.only_date=function(val){if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');var d=tmp[0].split('-');}else{var d=val.split('-');} @@ -857,7 +857,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) -this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\ +this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\
');}else{$(opts.parent).html('
\ diff --git a/public/js/all-web.js b/public/js/all-web.js index 2454dded70..33c47a2358 100644 --- a/public/js/all-web.js +++ b/public/js/all-web.js @@ -379,7 +379,7 @@ return val;},full_str:function(){var d=new Date();return d.getFullYear()+'-'+(d. else if(user_fmt=='dd/mm/yyyy'){var d=d.split('/');return d[2]+'-'+d[1]+'-'+d[0];} else if(user_fmt=='yyyy-mm-dd'){return d;} else if(user_fmt=='mm/dd/yyyy'){var d=d.split('/');return d[2]+'-'+d[0]+'-'+d[1];} -else if(user_fmt=='mm-dd-yyyy'){var d=d.split('-');return d[2]+'-'+d[0]+'-'+d[1];}},global_date_format:function(d){if(d.substr)d=this.str_to_obj(d);return nth(d.getDate())+' '+month_list_full[d.getMonth()]+' '+d.getFullYear();},get_today:function(){var today=new Date();var m=(today.getMonth()+1)+'';if(m.length==1)m='0'+m;var d=today.getDate()+'';if(d.length==1)d='0'+d;return today.getFullYear()+'-'+m+'-'+d;},get_cur_time:function(){var d=new Date();var hh=d.getHours()+'' +else if(user_fmt=='mm-dd-yyyy'){var d=d.split('-');return d[2]+'-'+d[0]+'-'+d[1];}},user_to_obj:function(d){return dateutil.str_to_obj(dateutil.user_to_str(d));},global_date_format:function(d){if(d.substr)d=this.str_to_obj(d);return nth(d.getDate())+' '+month_list_full[d.getMonth()]+' '+d.getFullYear();},get_today:function(){var today=new Date();var m=(today.getMonth()+1)+'';if(m.length==1)m='0'+m;var d=today.getDate()+'';if(d.length==1)d='0'+d;return today.getFullYear()+'-'+m+'-'+d;},get_cur_time:function(){var d=new Date();var hh=d.getHours()+'' var mm=cint(d.getMinutes()/5)*5+'' return(hh.length==1?'0'+hh:hh)+':'+(mm.length==1?'0'+mm:mm);}} wn.datetime.only_date=function(val){if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');var d=tmp[0].split('-');}else{var d=val.split('-');} @@ -516,7 +516,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) -this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\ +this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\
');}else{$(opts.parent).html('
\ From 588a98a10f89f5d9e37efa3f743a27f585201042 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 12 Sep 2012 19:00:14 +0530 Subject: [PATCH 3/3] fixes to chart_of_accounts, added opening + pl condition --- .../chart_of_accounts/chart_of_accounts.js | 41 ++++++++++++++++--- .../chart_of_accounts/chart_of_accounts.py | 15 +++++-- public/js/all-app.js | 2 +- public/js/all-web.js | 2 +- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js index 43fe56c310..7cf5648b93 100644 --- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js @@ -41,7 +41,8 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) { page: "chart_of_accounts", method: "get_companies", callback: function(r) { - erpnext.coa.company_select.empty().add_options(r.message).change(); + erpnext.coa.company_select.empty().add_options(r.message.companies).change(); + erpnext.coa.fiscal_years = r.message.fiscal_years; } }); @@ -100,6 +101,7 @@ erpnext.coa = { "credit": 0, "closing": 0, "debit_or_credit": v[2], + "is_pl": v[3] }; data.push(d); @@ -118,18 +120,27 @@ erpnext.coa = { var gl = erpnext.coa.gl; var opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val()); 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) { v.opening = v.debit = v.credit = v.closing = 0; }); + $.each(gl, function(i, v) { var posting_date = dateutil.str_to_obj(v[0]); var account = erpnext.coa.data_by_name[v[1]]; // opening - if (posting_date < opening_date) { - if (account.debit_or_credit === "Debit") { - account.opening += (v[2] - v[3]); + if (posting_date < opening_date || v[4] === "Yes") { + if (account.is_pl === "Yes" && posting_date <= dateutil.str_to_obj(fiscal_year[1])) { + // balance of previous fiscal_year should + // not be part of opening of pl account balance } else { - account.opening += (v[3] - v[2]); + if (account.debit_or_credit === "Debit") { + account.opening += (v[2] - v[3]); + } else { + account.opening += (v[3] - v[2]); + } } } else if (opening_date <= posting_date && posting_date <= closing_date) { // in between @@ -152,6 +163,26 @@ erpnext.coa = { v.closing = fmt_money(v.closing); }); }, + get_fiscal_year: function(opening_date, closing_date) { + if (opening_date > closing_date) { + msgprint("Opening Date should be before Closing Date"); + return; + } + + var fiscal_year = null; + $.each(erpnext.coa.fiscal_years, function(i, v) { + if (opening_date >= dateutil.str_to_obj(v[1]) && + closing_date <= dateutil.str_to_obj(v[2])) { + fiscal_year = v; + } + }); + + if (!fiscal_year) { + msgprint("Opening Date and Closing Date should be within same Fiscal Year"); + return; + } + return fiscal_year; + }, set_indent: function(data, parent_map) { $.each(data, function(i, d) { var indent = 0; diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py index 620368f079..14984fbdb9 100644 --- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py +++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py @@ -4,9 +4,10 @@ import webnotes def get_chart(): company = webnotes.form_dict.get('company') res = {} - res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit from + res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit, is_pl_account from tabAccount where company=%s and docstatus < 2 order by lft""", (company, )) - res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0), ifnull(credit, 0) + res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0), + ifnull(credit, 0), ifnull(is_opening, 'No') from `tabGL Entry` where company=%s and ifnull(is_cancelled, "No") = "No" order by posting_date""", (company, )) return res @@ -23,8 +24,14 @@ def get_companies(): if r["role"] in webnotes.user.roles and r["match"]=="company")) # if match == company is specified and companies are specified in user defaults + res = {} if match and webnotes.user.get_defaults().get("company"): - return webnotes.user.get_defaults().get("company") + res["companies"] = webnotes.user.get_defaults().get("company") else: - return [r[0] for r in webnotes.conn.sql("""select name from tabCompany + 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 + order by year_start_date asc""") + return res diff --git a/public/js/all-app.js b/public/js/all-app.js index 7ab9092a96..0ae6190b40 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -856,7 +856,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();}) if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) + %(icon)s %(label)s',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\ diff --git a/public/js/all-web.js b/public/js/all-web.js index 33c47a2358..911e6abe17 100644 --- a/public/js/all-web.js +++ b/public/js/all-web.js @@ -515,7 +515,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();}) if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='';} this.buttons[label]=$(repl('',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) + %(icon)s %(label)s',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar) this.$w.append('
');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('
\
\
\