mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-06 06:58:27 +00:00
Stock Ageing & release of Analytics
This commit is contained in:
@@ -1076,9 +1076,8 @@ me.list.run();});this.dialog.show();},add_column:function(c){var w=$('<div style
|
||||
* lib/js/wn/views/grid_report.js
|
||||
*/
|
||||
wn.provide("wn.report_dump");$.extend(wn.report_dump,{data:{},with_data:function(doctypes,callback,progress_bar){var missing=[];$.each(doctypes,function(i,v){if(!wn.report_dump.data[v])missing.push(v);})
|
||||
if(missing.length){wn.call({method:"webnotes.widgets.report_dump.get_data",args:{doctypes:doctypes,missing:missing},callback:function(r){$.each(r.message,function(doctype,doctype_data){var data=[];$.each(doctype_data.data,function(i,d){var row={};$.each(doctype_data.columns,function(idx,col){row[col]=d[idx];});row.id=row.name||doctype+"-"+i
|
||||
data.push(row);});wn.report_dump.data[doctype]=data;});$.each(r.message,function(doctype,doctype_data){if(doctype_data.links){$.each(wn.report_dump.data[doctype],function(row_idx,row){$.each(doctype_data.links,function(link_key,link){if(wn.report_dump.data[link[0]][row[link_key]]){row[link_key]=wn.report_dump.data[link[0]][row[link_key]][link[1]];}else{row[link_key]=null;}})})}});callback();},progress_bar:progress_bar})}else{callback();}}});wn.provide("wn.views");wn.views.GridReport=Class.extend({init:function(opts){this.filter_inputs={};this.preset_checks=[];this.tree_grid={show:false};$.extend(this,opts);this.wrapper=$('<div>').appendTo(this.parent);if(this.filters){this.make_filters();}
|
||||
this.make_waiting();this.import_slickgrid();var me=this;this.get_data();},bind_show:function(){var me=this;$(this.page).bind('show',function(){wn.cur_grid_report=me;me.apply_filters_from_route();me.refresh();});},get_data:function(){var me=this;wn.report_dump.with_data(this.doctypes,function(){me.setup_filters();me.init_filter_values();me.refresh();},this.wrapper.find(".progress .bar"));},setup_filters:function(){var me=this;$.each(me.filter_inputs,function(i,v){var opts=v.get(0).opts;if(opts.fieldtype=="Select"&&inList(me.doctypes,opts.link)){$(v).add_options($.map(wn.report_dump.data[opts.link],function(d){return d.name;}));}});this.filter_inputs.refresh&&this.filter_inputs.refresh.click(function(){me.set_route();});this.filter_inputs.reset_filters&&this.filter_inputs.reset_filters.click(function(){me.init_filter_values();me.set_route();});},init_filter_values:function(){var me=this;$.each(this.filter_inputs,function(key,filter){var opts=filter.get(0).opts;if(sys_defaults[key]){filter.val(sys_defaults[key]);}else if(opts.fieldtype=='Select'){filter.get(0).selectedIndex=0;}else if(opts.fieldtype=='Data'){filter.val("");}})
|
||||
if(missing.length){wn.call({method:"webnotes.widgets.report_dump.get_data",args:{doctypes:doctypes,missing:missing},callback:function(r){$.each(r.message,function(doctype,doctype_data){var data=[];$.each(doctype_data.data,function(i,d){var row={};$.each(doctype_data.columns,function(idx,col){row[col]=d[idx];});row.id=row.name||doctype+"-"+i;row.doctype=doctype;data.push(row);});wn.report_dump.data[doctype]=data;});$.each(r.message,function(doctype,doctype_data){if(doctype_data.links){$.each(wn.report_dump.data[doctype],function(row_idx,row){$.each(doctype_data.links,function(link_key,link){if(wn.report_dump.data[link[0]][row[link_key]]){row[link_key]=wn.report_dump.data[link[0]][row[link_key]][link[1]];}else{row[link_key]=null;}})})}});callback();},progress_bar:progress_bar})}else{callback();}}});wn.provide("wn.views");wn.views.GridReport=Class.extend({init:function(opts){this.filter_inputs={};this.preset_checks=[];this.tree_grid={show:false};$.extend(this,opts);this.wrapper=$('<div>').appendTo(this.parent);if(this.filters){this.make_filters();}
|
||||
this.make_waiting();this.import_slickgrid();var me=this;this.get_data();},bind_show:function(){var me=this;$(this.page).bind('show',function(){wn.cur_grid_report=me;me.apply_filters_from_route();me.refresh();});},get_data:function(){var me=this;wn.report_dump.with_data(this.doctypes,function(){me.setup_filters();me.init_filter_values();me.refresh();},this.wrapper.find(".progress .bar"));},setup_filters:function(){var me=this;$.each(me.filter_inputs,function(i,v){var opts=v.get(0).opts;if(opts.fieldtype=="Select"&&inList(me.doctypes,opts.link)){$(v).add_options($.map(wn.report_dump.data[opts.link],function(d){return d.name;}));}});this.filter_inputs.refresh&&this.filter_inputs.refresh.click(function(){me.set_route();});this.filter_inputs.reset_filters&&this.filter_inputs.reset_filters.click(function(){me.init_filter_values();me.set_route();});this.filter_inputs.range&&this.filter_inputs.range.change(function(){me.set_route();});},init_filter_values:function(){var me=this;$.each(this.filter_inputs,function(key,filter){var opts=filter.get(0).opts;if(sys_defaults[key]){filter.val(sys_defaults[key]);}else if(opts.fieldtype=='Select'){filter.get(0).selectedIndex=0;}else if(opts.fieldtype=='Data'){filter.val("");}})
|
||||
if(this.filter_inputs.from_date)
|
||||
this.filter_inputs.from_date.val(dateutil.str_to_user(sys_defaults.year_start_date));if(this.filter_inputs.to_date)
|
||||
this.filter_inputs.to_date.val(dateutil.str_to_user(sys_defaults.year_end_date));},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.options||[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);}
|
||||
@@ -1096,19 +1095,12 @@ this.make();this.show_zero=$('.show-zero input:checked').length;this.load_filter
|
||||
<a href="#" class="grid-report-print"><i class="icon icon-print"></i> Print</a> \
|
||||
<span style="color: #aaa; margin: 0px 10px;"> | </span> \
|
||||
<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; \
|
||||
</div>').appendTo(this.wrapper);this.wrapper.find(".grid-report-export").click(function(){return me.export();});this.wrapper.find(".grid-report-print").click(function(){msgprint("Coming Soon");return false;});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));$('<div style="margin: 10px 0px; text-align: right; display: none" class="show-zero">\
|
||||
<input type="checkbox"> Show rows with zero values\
|
||||
</div>').appendTo(this.wrapper);this.bind_show();wn.cur_grid_report=this;this.apply_filters_from_route();$(this.wrapper).trigger('make');},apply_filters_from_route:function(){var hash=decodeURIComponent(window.location.hash);var me=this;if(hash.indexOf('/')!=-1){$.each(hash.split('/').splice(1).join('/').split('&'),function(i,f){var f=f.split("=");if(me.filter_inputs[f[0]]){me.filter_inputs[f[0]].val(decodeURIComponent(f[1]));}else{console.log("Invalid filter: "+f[0]);}});}else{this.init_filter_values();}},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('&'))},options:{editable:false,enableColumnReorder:false},render:function(){this.grid=new Slick.Grid("#"+this.id,this.dataView,this.dataview_columns,this.options);var me=this;this.dataView.onRowsChanged.subscribe(function(e,args){me.grid.invalidateRows(args.rows);me.grid.render();});this.dataView.onRowCountChanged.subscribe(function(e,args){me.grid.updateRowCount();me.grid.render();});this.tree_grid.show&&this.add_tree_grid_events();},prepare_data_view:function(){this.dataView=new Slick.Data.DataView({inlineFilters:true});this.dataView.beginUpdate();this.dataView.setItems(this.data);if(this.dataview_filter)this.dataView.setFilter(this.dataview_filter);if(this.tree_grid.show)this.dataView.setFilter(this.tree_dataview_filter);this.dataView.endUpdate();},export:function(){var me=this;var res=[$.map(this.columns,function(v){return v.name;})].concat(this.get_view_data());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;},add_tree_grid_events:function(){var me=this;this.grid.onClick.subscribe(function(e,args){if($(e.target).hasClass("toggle")){var item=me.dataView.getItem(args.row);if(item){if(!item._collapsed){item._collapsed=true;}else{item._collapsed=false;}
|
||||
me.dataView.updateItem(item.id,item);}
|
||||
e.stopImmediatePropagation();}});},tree_formatter:function(row,cell,value,columnDef,dataContext){var me=wn.cur_grid_report;value=value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");var data=me.data;var spacer="<span style='display:inline-block;height:1px;width:"+
|
||||
(15*dataContext["indent"])+"px'></span>";var idx=me.dataView.getIdxById(dataContext.id);var link=me.tree_grid.formatter(dataContext);if(columnDef.doctype){link+=me.get_link_open_icon(columnDef.doctype,value);}
|
||||
if(data[idx+1]&&data[idx+1].indent>data[idx].indent){if(dataContext._collapsed){return spacer+" <span class='toggle expand'></span> "+link;}else{return spacer+" <span class='toggle collapse'></span> "+link;}}else{return spacer+" <span class='toggle'></span> "+link;}},tree_dataview_filter:function(item){var me=wn.cur_grid_report;if(!me.apply_filters(item))return false;var parent=item[me.tree_grid.parent_field];while(parent){if(me.item_by_name[parent]._collapsed){return false;}
|
||||
parent=me.parent_map[parent];}
|
||||
return true;},prepare_tree:function(item_dt,group_dt){var group_data=wn.report_dump.data[group_dt];var item_data=wn.report_dump.data[item_dt];var me=this;var item_group_map={};var group_ids=$.map(group_data,function(v){return v.id;});$.each(item_data,function(i,item){var parent=item[me.tree_grid.parent_field];if(!item_group_map[parent])item_group_map[parent]=[];if(group_ids.indexOf(item.name)==-1){item_group_map[parent].push(item);}else{msgprint("Ignoring Item "+item.name.bold()+", because a group exists with the same name!");}});var items=[];$.each(group_data,function(i,group){group.is_group=true;items.push(group);items=items.concat(item_group_map[group.name]||[]);});return items;},set_indent:function(){var me=this;$.each(this.data,function(i,d){var indent=0;var parent=me.parent_map[d.name];if(parent){while(parent){indent++;parent=me.parent_map[parent];}}
|
||||
d.indent=indent;});},apply_filters:function(item){var filters=this.filter_inputs;if(item._show)return true;for(i in filters){if(!this.apply_filter(item,i))return false;}
|
||||
+'='+encodeURIComponent(val);}).join('&'))},options:{editable:false,enableColumnReorder:false},render:function(){this.grid=new Slick.Grid("#"+this.id,this.dataView,this.dataview_columns,this.options);var me=this;this.dataView.onRowsChanged.subscribe(function(e,args){me.grid.invalidateRows(args.rows);me.grid.render();});this.dataView.onRowCountChanged.subscribe(function(e,args){me.grid.updateRowCount();me.grid.render();});this.tree_grid.show&&this.add_tree_grid_events();},prepare_data_view:function(){this.dataView=new Slick.Data.DataView({inlineFilters:true});this.dataView.beginUpdate();this.dataView.setItems(this.data);if(this.dataview_filter)this.dataView.setFilter(this.dataview_filter);if(this.tree_grid.show)this.dataView.setFilter(this.tree_dataview_filter);this.dataView.endUpdate();},export:function(){var me=this;var res=[$.map(this.columns,function(v){return v.name;})].concat(this.get_view_data());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;},apply_filters:function(item){var filters=this.filter_inputs;if(item._show)return true;for(i in filters){if(!this.apply_filter(item,i))return false;}
|
||||
return true;},apply_filter:function(item,fieldname){var filter=this.filter_inputs[fieldname].get(0);if(filter.opts.filter){if(!filter.opts.filter(this[filter.opts.fieldname],item,filter.opts,this)){return false;}}
|
||||
return true;},apply_zero_filter:function(val,item,opts,me){if(!me.show_zero){for(var i=0,j=me.columns.length;i<j;i++){var col=me.columns[i];if(col.formatter==me.currency_formatter&&!col.hidden){if(flt(item[col.field])>0.001||flt(item[col.field])<-0.001){return true;}}}
|
||||
return false;}
|
||||
@@ -1118,20 +1110,27 @@ var link_formatter=me.dataview_columns[cell].link_formatter;var html=repl('<a hr
|
||||
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})
|
||||
if(link_formatter.open_btn){html+=me.get_link_open_icon(eval(link_formatter.doctype),value);}
|
||||
if(link_formatter.open_btn){var doctype=link_formatter.doctype?eval(link_formatter.doctype):dataContext.doctype;html+=me.get_link_open_icon(doctype,value);}
|
||||
return html;}}})},get_link_open_icon:function(doctype,name){return repl(' <i class="icon icon-share" style="cursor: pointer;"\
|
||||
onclick="wn.set_route(\'Form\', \'%(doctype)s\', \'%(name)s\');">\
|
||||
</i>',{name:name,doctype:doctype});},make_date_range_columns:function(){this.columns=[];var me=this;var range=this.filter_inputs.range.val();this.from_date=dateutil.user_to_str(this.filter_inputs.from_date.val());this.to_date=dateutil.user_to_str(this.filter_inputs.to_date.val());var date_diff=dateutil.get_diff(this.to_date,this.from_date);me.column_map={};var add_column=function(date){me.columns.push({id:date,name:dateutil.str_to_user(date),field:date,formatter:me.currency_formatter,width:100});}
|
||||
var build_columns=function(condition){for(var i=0;i<date_diff;i++){var date=dateutil.add_days(me.from_date,i);if(!condition)condition=function(){return true;}
|
||||
if(condition(date))add_column(date);me.last_date=date;if(me.columns.length){me.column_map[date]=me.columns[me.columns.length-1];}}}
|
||||
if(range=='Daily'){build_columns();}else if(range=='Weekly'){build_columns(function(date){if(!me.last_date)return true;return!(dateutil.get_diff(date,me.from_date)%7)});}else if(range=='Monthly'){build_columns(function(date){if(!me.last_date)return true;return dateutil.str_to_obj(me.last_date).getMonth()!=dateutil.str_to_obj(date).getMonth()});}else if(range=='Quarterly'){build_columns(function(date){if(!me.last_date)return true;return dateutil.str_to_obj(date).getDate()==1&&in_list([0,3,6,9],dateutil.str_to_obj(date).getMonth())});}else if(range=='Yearly'){build_columns(function(date){if(!me.last_date)return true;return $.map(wn.report_dump.data['Fiscal Year'],function(v){return date==v.year_start_date?true:null;}).length;});}
|
||||
$.each(this.columns,function(i,col){col.name=me.columns[i+1]?dateutil.str_to_user(dateutil.add_days(me.columns[i+1].id,-1)):dateutil.str_to_user(me.to_date);});}});wn.views.GridReportWithPlot=wn.views.GridReport.extend({render_plot:function(){var plot_data=this.get_plot_data?this.get_plot_data():null;if(!plot_data){this.plot_area.toggle(false);return;}
|
||||
$.each(this.columns,function(i,col){col.name=me.columns[i+1]?dateutil.str_to_user(dateutil.add_days(me.columns[i+1].id,-1)):dateutil.str_to_user(me.to_date);});},});wn.views.GridReportWithPlot=wn.views.GridReport.extend({render_plot:function(){var plot_data=this.get_plot_data?this.get_plot_data():null;if(!plot_data){this.plot_area.toggle(false);return;}
|
||||
wn.require('js/lib/flot/jquery.flot.js');this.plot=$.plot(this.plot_area.toggle(true),plot_data,this.get_plot_options());this.setup_plot_hover();},setup_plot_check:function(){var me=this;me.wrapper.bind('make',function(){me.wrapper.on("click",".plot-check",function(){var checked=$(this).attr("checked");me.item_by_name[$(this).attr("data-id")].checked=checked?true:false;me.render_plot();});});},setup_plot_hover:function(){var me=this;this.tooltip_id=wn.dom.set_unique_id();function showTooltip(x,y,contents){$('<div id="'+me.tooltip_id+'">'+contents+'</div>').css({position:'absolute',display:'none',top:y+5,left:x+5,border:'1px solid #fdd',padding:'2px','background-color':'#fee',opacity:0.80}).appendTo("body").fadeIn(200);}
|
||||
this.previousPoint=null;this.wrapper.find('.plot').bind("plothover",function(event,pos,item){if(item){if(me.previousPoint!=item.dataIndex){me.previousPoint=item.dataIndex;$("#"+me.tooltip_id).remove();showTooltip(item.pageX,item.pageY,me.get_tooltip_text(item.series.label,item.datapoint[0],item.datapoint[1]));}}
|
||||
else{$("#"+me.tooltip_id).remove();me.previousPoint=null;}});},get_tooltip_text:function(label,x,y){var date=dateutil.obj_to_user(new Date(x));var value=fmt_money(y);return value+" on "+date;},get_view_data:function(){var res=[];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);}
|
||||
return res;},get_plot_data:function(){var data=[];var me=this;$.each(this.data,function(i,item){if(item.checked){data.push({label:item.name,data:$.map(me.columns,function(col,idx){if(col.formatter==me.currency_formatter&&!col.hidden&&col.plot!==false){return me.get_plot_points(item,col,idx)}}),points:{show:true},lines:{show:true,fill:true},});data[data.length-1].data=[[dateutil.str_to_obj(me.from_date).getTime(),item.opening]].concat(data[data.length-1].data);}});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()}}}})
|
||||
return res;},get_plot_data:function(){var data=[];var me=this;$.each(this.data,function(i,item){if(item.checked){data.push({label:item.name,data:$.map(me.columns,function(col,idx){if(col.formatter==me.currency_formatter&&!col.hidden&&col.plot!==false){return me.get_plot_points(item,col,idx)}}),points:{show:true},lines:{show:true,fill:true},});data[data.length-1].data=[[dateutil.str_to_obj(me.from_date).getTime(),item.opening]].concat(data[data.length-1].data);}});return data.length?data:false;},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()}}}});wn.views.TreeGridReport=wn.views.GridReportWithPlot.extend({make_transaction_list:function(parent_doctype,doctype){var me=this;var tmap={};$.each(wn.report_dump.data[doctype],function(i,v){if(!tmap[v.parent])tmap[v.parent]=[];tmap[v.parent].push(v);});this.tl=[];$.each(wn.report_dump.data[parent_doctype],function(i,parent){$.each(tmap[parent.name],function(i,d){me.tl.push($.extend(copy_dict(parent),d));});});},add_tree_grid_events:function(){var me=this;this.grid.onClick.subscribe(function(e,args){if($(e.target).hasClass("toggle")){var item=me.dataView.getItem(args.row);if(item){if(!item._collapsed){item._collapsed=true;}else{item._collapsed=false;}
|
||||
me.dataView.updateItem(item.id,item);}
|
||||
e.stopImmediatePropagation();}});},tree_formatter:function(row,cell,value,columnDef,dataContext){var me=wn.cur_grid_report;value=value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");var data=me.data;var spacer="<span style='display:inline-block;height:1px;width:"+
|
||||
(15*dataContext["indent"])+"px'></span>";var idx=me.dataView.getIdxById(dataContext.id);var link=me.tree_grid.formatter(dataContext);if(dataContext.doctype){link+=me.get_link_open_icon(dataContext.doctype,value);}
|
||||
if(data[idx+1]&&data[idx+1].indent>data[idx].indent){if(dataContext._collapsed){return spacer+" <span class='toggle expand'></span> "+link;}else{return spacer+" <span class='toggle collapse'></span> "+link;}}else{return spacer+" <span class='toggle'></span> "+link;}},tree_dataview_filter:function(item){var me=wn.cur_grid_report;if(!me.apply_filters(item))return false;var parent=item[me.tree_grid.parent_field];while(parent){if(me.item_by_name[parent]._collapsed){return false;}
|
||||
parent=me.parent_map[parent];}
|
||||
return true;},prepare_tree:function(item_dt,group_dt){var group_data=wn.report_dump.data[group_dt];var item_data=wn.report_dump.data[item_dt];var me=this;var item_group_map={};var group_ids=$.map(group_data,function(v){return v.id;});$.each(item_data,function(i,item){var parent=item[me.tree_grid.parent_field];if(!item_group_map[parent])item_group_map[parent]=[];if(group_ids.indexOf(item.name)==-1){item_group_map[parent].push(item);}else{msgprint("Ignoring Item "+item.name.bold()+", because a group exists with the same name!");}});var items=[];$.each(group_data,function(i,group){group.is_group=true;items.push(group);items=items.concat(item_group_map[group.name]||[]);});return items;},set_indent:function(){var me=this;$.each(this.data,function(i,d){var indent=0;var parent=me.parent_map[d.name];if(parent){while(parent){indent++;parent=me.parent_map[parent];}}
|
||||
d.indent=indent;});},});
|
||||
/*
|
||||
* lib/js/legacy/widgets/dialog.js
|
||||
*/
|
||||
@@ -2340,7 +2339,7 @@ erpnext.hide_naming_series=function(){if(cur_frm.fields_dict.naming_series){hide
|
||||
* erpnext/startup/js/modules.js
|
||||
*/
|
||||
wn.provide('erpnext.module_page');erpnext.module_page.setup_page=function(module,wrapper){erpnext.module_page.hide_links(wrapper);erpnext.module_page.make_list(module,wrapper);$(wrapper).find("a[title]").tooltip({delay:{show:500,hide:100}});}
|
||||
erpnext.module_page.hide_links=function(wrapper){$(wrapper).find('[href*="List/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[data-doctype]').each(function(){var dt=$(this).attr('data-doctype');if(wn.boot.profile.all_read.indexOf(dt)==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[href*="Form/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});}
|
||||
erpnext.module_page.hide_links=function(wrapper){$(wrapper).find('[href*="List/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[data-doctype]').each(function(){var dt=$(this).attr('data-doctype');if(wn.boot.profile.all_read.indexOf(dt)==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[href*="Form/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[data-role]').each(function(){if(!has_common(user_roles,[$(this).attr("data-role"),"System Manager"])){var html=$(this).html();$(this).parent().css('color','#999');$(this).replaceWith(html);}});}
|
||||
erpnext.module_page.make_list=function(module,wrapper){var $w=$(wrapper).find('.reports-list');var $parent1=$('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);var $parent2=$('<div style="width: 45%; float: left;"></div>').appendTo($w);wrapper.list1=new wn.ui.Listing({parent:$parent1,method:'utilities.get_sc_list',render_row:function(row,data){if(!data.parent_doc_type)data.parent_doc_type=data.doc_type;$(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
|
||||
data-doctype="%(parent_doc_type)s">\
|
||||
%(criteria_name)s</a>',data))},args:{module:module},no_refresh:true,callback:function(r){erpnext.module_page.hide_links($parent1)}});wrapper.list1.run();wrapper.list2=new wn.ui.Listing({parent:$parent2,method:'utilities.get_report_list',render_row:function(row,data){$(row).html(repl('<a href="#!Report2/%(ref_doctype)s/%(name)s" \
|
||||
|
||||
@@ -11,14 +11,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
erpnext.AccountTreeGrid = wn.views.GridReportWithPlot.extend({
|
||||
erpnext.AccountTreeGrid = wn.views.TreeGridReport.extend({
|
||||
init: function(wrapper, title) {
|
||||
this._super({
|
||||
title: title,
|
||||
page: wrapper,
|
||||
parent: $(wrapper).find('.layout-main'),
|
||||
appframe: wrapper.appframe,
|
||||
doctypes: ["Company", "Fiscal Year", "Account", "GL Entry"],
|
||||
doctypes: ["Company", "Fiscal Year", "Account", "GL Entry", "Cost Center"],
|
||||
tree_grid: {
|
||||
show: true,
|
||||
parent_field: "parent_account",
|
||||
@@ -111,6 +111,9 @@ erpnext.AccountTreeGrid = wn.views.GridReportWithPlot.extend({
|
||||
this.prepare_balances();
|
||||
|
||||
},
|
||||
init_account: function(d) {
|
||||
this.reset_item_values(d);
|
||||
},
|
||||
|
||||
prepare_balances: function() {
|
||||
var gl = wn.report_dump.data['GL Entry'];
|
||||
|
||||
105
public/js/app/stock_grid_report.js
Normal file
105
public/js/app/stock_grid_report.js
Normal file
@@ -0,0 +1,105 @@
|
||||
// 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/>.
|
||||
|
||||
erpnext.StockGridReport = wn.views.TreeGridReport.extend({
|
||||
get_item_warehouse: function(warehouse, item) {
|
||||
if(!this.item_warehouse[item]) this.item_warehouse[item] = {};
|
||||
if(!this.item_warehouse[item][warehouse]) this.item_warehouse[item][warehouse] = {
|
||||
balance_qty: 0.0, balance_value: 0.0, fifo_stack: []
|
||||
};
|
||||
return this.item_warehouse[item][warehouse];
|
||||
},
|
||||
|
||||
get_value_diff: function(wh, sl, is_fifo) {
|
||||
// value
|
||||
if(sl.qty > 0) {
|
||||
// incoming - rate is given
|
||||
var rate = sl.incoming_rate;
|
||||
var add_qty = sl.qty;
|
||||
if(wh.balance_qty < 0) {
|
||||
// negative valuation
|
||||
// only add value of quantity if
|
||||
// the balance goes above 0
|
||||
add_qty = wh.balance_qty + sl.qty;
|
||||
if(add_qty < 0) {
|
||||
add_qty = 0;
|
||||
}
|
||||
}
|
||||
var value_diff = (rate * add_qty);
|
||||
|
||||
if(add_qty)
|
||||
wh.fifo_stack.push([add_qty, sl.incoming_rate, sl.posting_date]);
|
||||
} else {
|
||||
// outgoing
|
||||
|
||||
if(is_fifo) {
|
||||
var value_diff = this.get_fifo_value_diff(wh, sl);
|
||||
} else {
|
||||
// average rate for weighted average
|
||||
var rate = (wh.balance_qty.toFixed(2) == 0.00 ? 0 :
|
||||
flt(wh.balance_value) / flt(wh.balance_qty));
|
||||
|
||||
// no change in value if negative qty
|
||||
if((wh.balance_qty + sl.qty).toFixed(2) >= 0.00)
|
||||
var value_diff = (rate * sl.qty);
|
||||
else
|
||||
var value_diff = -wh.balance_value;
|
||||
}
|
||||
}
|
||||
|
||||
// update balance (only needed in case of valuation)
|
||||
wh.balance_qty += sl.qty;
|
||||
wh.balance_value += value_diff;
|
||||
|
||||
return value_diff;
|
||||
},
|
||||
get_fifo_value_diff: function(wh, sl) {
|
||||
// get exact rate from fifo stack
|
||||
var fifo_stack = (wh.fifo_stack || []).reverse();
|
||||
var fifo_value_diff = 0.0;
|
||||
var qty = -sl.qty;
|
||||
|
||||
for(var i=0, j=fifo_stack.length; i<j; i++) {
|
||||
var batch = fifo_stack.pop();
|
||||
if(batch[0] >= qty) {
|
||||
batch[0] = batch[0] - qty;
|
||||
fifo_value_diff += (qty * batch[1]);
|
||||
|
||||
qty = 0.0;
|
||||
if(batch[0]) {
|
||||
// batch still has qty put it back
|
||||
fifo_stack.push(batch);
|
||||
}
|
||||
|
||||
// all qty found
|
||||
break;
|
||||
} else {
|
||||
// consume this batch fully
|
||||
fifo_value_diff += (batch[0] * batch[1]);
|
||||
qty = qty - batch[0];
|
||||
}
|
||||
}
|
||||
if(qty) {
|
||||
// msgprint("Negative values not allowed for FIFO valuation!\
|
||||
// Item " + sl.item_code.bold() + " on " + dateutil.str_to_user(sl.posting_datetime).bold() +
|
||||
// " becomes negative. Values computed will not be accurate.");
|
||||
}
|
||||
|
||||
// reset the updated stack
|
||||
wh.fifo_stack = fifo_stack.reverse();
|
||||
return -fifo_value_diff;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user