updates to general ledger, todo

This commit is contained in:
Rushabh Mehta 2012-09-17 10:04:07 +05:30
parent cfb5466d30
commit 4ce6b60fce
3 changed files with 65 additions and 20 deletions

View File

@ -43,23 +43,23 @@ wn.pages['general-ledger'].onload = function(wrapper) {
filters: [
{fieldtype:"Select", label: "Company", options:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
return item.company == val || val == opts.default_value;
return item.company == val || val == opts.default_value || item._show;
}},
{fieldtype:"Select", label: "Account", options:"Account", default_value: "Select Account...",
filter: function(val, item, opts) {
return item.account == val || val == opts.default_value;
return item.account == val || val == opts.default_value || item._show;
}},
{fieldtype:"Data", label: "Voucher No",
filter: function(val, item, opts) {
if(!val) return true;
return item.voucher_no.indexOf(val)!=-1;
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1) || item._show;
}},
{fieldtype:"Date", label: "From Date", filter: function(val, item) {
return dateutil.user_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
return item._show || dateutil.user_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date", filter: function(val, item) {
return dateutil.user_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
return item._show || dateutil.user_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"}
@ -79,7 +79,58 @@ wn.pages['general-ledger'].onload = function(wrapper) {
this.filter_inputs.account.get(0).selectedIndex = 0;
},
prepare_data: function() {
this.prepare_data_view(wn.report_dump.data["GL Entry"]);
// add Opening, Closing, Totals rows
// if filtered by account and / or voucher
var data = wn.report_dump.data["GL Entry"];
var account = this.filter_inputs.account.val();
var from_date = dateutil.user_to_obj(this.filter_inputs.from_date.val());
var to_date = dateutil.user_to_obj(this.filter_inputs.to_date.val());
var voucher_no = this.filter_inputs.voucher_no.val();
var default_account = this.filter_inputs.account.get(0).opts.default_value;
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) {
if((account!=default_account ? item.account==account : true) &&
(voucher_no ? item.voucher_no==voucher_no : true)) {
var date = dateutil.str_to_obj(item.posting_date);
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;
}
}
})
var closing = {
account: "Closing (Opening + Totals)", debit: opening.debit + totals.debit,
credit: opening.credit + totals.credit,
id:"_closing", _show: true, _style: "font-weight: bold"
}
if(account != default_account) {
var out = [opening].concat(data).concat([totals, closing]);
} else {
var out = data.concat([totals]);
}
this.prepare_data_view(out);
},
});

View File

@ -1,10 +0,0 @@
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, ))

View File

@ -1082,12 +1082,16 @@ this.make_waiting();this.import_slickgrid();var me=this;this.get_data();wn.cur_g
<a href="#" class="grid-report-export"><i class="icon icon-download-alt"></i> Export</a> \
</div>').appendTo(this.wrapper);this.wrapper.find(".grid-report-export").click(function(){return me.export();});this.grid_wrapper=$("<div style='height: 500px; border: 1px solid #aaa; \
background-color: #eee; margin-top: 15px;'>").appendTo(this.wrapper);this.id=wn.dom.set_unique_id(this.grid_wrapper.get(0));var me=this;$(wn.container.page).bind('show',function(){wn.cur_grid_report=me;me.apply_filters_from_route();me.refresh();});this.apply_filters_from_route();},load_filters:function(callback){callback();},make_filters:function(){var me=this;$.each(this.filters,function(i,v){v.fieldname=v.fieldname||v.label.replace(/ /g,'_').toLowerCase();var input=null;if(v.fieldtype=='Select'){input=me.appframe.add_select(v.label,[v.default_value]);}else if(v.fieldtype=='Button'){input=me.appframe.add_button(v.label);if(v.icon){$('<i class="icon '+v.icon+'"></i>').prependTo(input);}}else if(v.fieldtype=='Date'){input=me.appframe.add_date(v.label);}else if(v.fieldtype=='Label'){input=me.appframe.add_label(v.label);}else if(v.fieldtype=='Data'){input=me.appframe.add_data(v.label);}
if(v.cssClass){input&&input.addClass(v.cssClass);}
input&&(input.get(0).opts=v);me.filter_inputs[v.fieldname]=input;});},import_slickgrid:function(){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.grid.js');wn.require('js/lib/slickgrid/slick.dataview.js');wn.dom.set_style('.slick-cell { font-size: 12px; }');},refresh:function(){this.render();},apply_filters_from_route:function(){var hash=window.location.hash;var me=this;if(hash.indexOf('/')!=-1){$.each(hash.split('/').splice(1).join('/').split('&'),function(i,f){var f=f.split("=");me.filter_inputs[f[0]].val(decodeURIComponent(f[1]));});}},set_route:function(){wn.set_route(wn.container.page.page_name,$.map(this.filter_inputs,function(v){var val=v.val();var opts=v.get(0).opts;if(val&&val!=opts.default_value)
if(input){input&&(input.get(0).opts=v);if(v.cssClass){input.addClass(v.cssClass);}
input.keypress(function(e){if(e.which==13){me.refresh();}})}
me.filter_inputs[v.fieldname]=input;});},import_slickgrid:function(){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.grid.js');wn.require('js/lib/slickgrid/slick.dataview.js');wn.dom.set_style('.slick-cell { font-size: 12px; }');},refresh:function(){this.render();},apply_filters_from_route:function(){var hash=window.location.hash;var me=this;if(hash.indexOf('/')!=-1){$.each(hash.split('/').splice(1).join('/').split('&'),function(i,f){var f=f.split("=");me.filter_inputs[f[0]].val(decodeURIComponent(f[1]));});}},set_route:function(){wn.set_route(wn.container.page.page_name,$.map(this.filter_inputs,function(v){var val=v.val();var opts=v.get(0).opts;if(val&&val!=opts.default_value)
return encodeURIComponent(opts.fieldname)
+'='+encodeURIComponent(val);}).join('&'))},render:function(){this.waiting.toggle(false);if(!this.grid_wrapper)this.make_grid_wrapper();this.apply_link_formatters();this.prepare_data();this.grid=new Slick.Grid("#"+this.id,this.dataView,this.columns,this.options);this.dataView.onRowsChanged.subscribe(function(e,args){grid.invalidateRows(args.rows);grid.render();});this.dataView.onRowCountChanged.subscribe(function(e,args){grid.updateRowCount();grid.render();});},prepare_data_view:function(items){this.dataView=new Slick.Data.DataView({inlineFilters:true});this.dataView.beginUpdate();this.dataView.setItems(items);this.dataView.setFilter(this.dataview_filter);this.dataView.endUpdate();},export:function(){var me=this;var res=[$.map(this.columns,function(v){return v.name;})];var col_map=$.map(this.columns,function(v){return v.field;});for(var i=0,len=this.dataView.getLength();i<len;i++){var d=this.dataView.getItem(i);var row=$.map(col_map,function(col){return d[col];});res.push(row);}
+'='+encodeURIComponent(val);}).join('&'))},render:function(){this.waiting.toggle(false);if(!this.grid_wrapper)this.make_grid_wrapper();this.apply_link_formatters();this.prepare_data();this.grid=new Slick.Grid("#"+this.id,this.dataView,this.columns,this.options);this.dataView.onRowsChanged.subscribe(function(e,args){grid.invalidateRows(args.rows);grid.render();});this.dataView.onRowCountChanged.subscribe(function(e,args){grid.updateRowCount();grid.render();});},prepare_data_view:function(items){this.dataView=new Slick.Data.DataView({inlineFilters:true});this.dataView.beginUpdate();this.dataView.setItems(items);this.dataView.setFilter(this.dataview_filter);this.dataView.endUpdate();},export:function(){var me=this;var res=[$.map(this.columns,function(v){return v.name;})];var col_map=$.map(this.columns,function(v){return v.field;});for(var i=0,len=this.dataView.getLength();i<len;i++){var d=this.dataView.getItem(i);var row=[];$.each(col_map,function(i,col){var val=d[col];if(val===null||val===undefined){val=""}
row.push(val);})
res.push(row);}
wn.require("js/lib/downloadify/downloadify.min.js");wn.require("js/lib/downloadify/swfobject.js");var id=wn.dom.set_unique_id();var msgobj=msgprint('<p id="'+id+'">You must have Flash 10 installed to download this file.</p>');Downloadify.create(id,{filename:function(){return me.title+'.csv';},data:function(){return wn.to_csv(res);},swf:'js/lib/downloadify/downloadify.swf',downloadImage:'js/lib/downloadify/download.png',onComplete:function(){msgobj.hide();},onCancel:function(){msgobj.hide();},onError:function(){msgobj.hide();},width:100,height:30,transparent:true,append:false});return false;},options:{editable:false,enableColumnReorder:false},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,filter.opts)){return false;}}
return true;},date_formatter:function(row,cell,value,columnDef,dataContext){return dateutil.str_to_user(value);},currency_formatter:function(row,cell,value,columnDef,dataContext){return"<div style='text-align: right;'>"+fmt_money(value)+"</div>";},text_formatter:function(row,cell,value,columnDef,dataContext){return"<span title='"+value+"'>"+value+"</div>";},apply_link_formatters:function(){var me=this;$.each(this.columns,function(i,col){if(col.link_formatter){col.formatter=function(row,cell,value,columnDef,dataContext){var link_formatter=wn.cur_grid_report.columns[cell].link_formatter;var html=repl('<a href="#" \
return true;},date_formatter:function(row,cell,value,columnDef,dataContext){return dateutil.str_to_user(value);},currency_formatter:function(row,cell,value,columnDef,dataContext){return repl('<div style="text-align: right; %(_style)s">%(value)s</div>',{_style:dataContext._style||"",value:fmt_money(value)});},text_formatter:function(row,cell,value,columnDef,dataContext){return repl('<span style="%(_style)s" title="%(esc_value)s">%(value)s</span>',{_style:dataContext._style||"",esc_value:cstr(value).replace(/"/g,'\"'),value:cstr(value)});},apply_link_formatters:function(){var me=this;$.each(this.columns,function(i,col){if(col.link_formatter){col.formatter=function(row,cell,value,columnDef,dataContext){if(!value)return"";if(dataContext._show){return repl('<span style="%(_style)s">%(value)s</span>',{_style:dataContext._style||"",value:value});}
var link_formatter=wn.cur_grid_report.columns[cell].link_formatter;var html=repl('<a href="#" \
onclick="wn.cur_grid_report.filter_inputs.%(col_name)s.val(\'%(value)s\'); \
wn.cur_grid_report.set_route(); return false;">\
%(value)s</a>',{value:value,col_name:link_formatter.filter_input,page_name:wn.container.page.page_name})