// 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 .
pscript['onload_Sales Dashboard'] = function() {
var h = new PageHeader('pt_header','Sales Dashboard');
pscript.make_filters();
$dh(pscript.mnt_div);
$dh(pscript.mnt_div1);
//pscript.dx_axis = [];
wn.require('js/lib/jqplot/css/jqplot.css');
wn.require('js/lib/jqplot/jquery.jqplot.min.js');
pscript.all_onchnge();
}
//=======================================================================
pscript.make_filters = function(){
this.tab = make_table('pt_filters', 2, 4, '800px', ['200px','200px','200px','200px'], {padding: '2px'});
pscript.fiscal_year();
pscript.report_type();
pscript.item_grp();
pscript.month_lst();
}
//=======================================================================
pscript.fiscal_year=function(){
var me = this;
$td(this.tab,0,0).innerHTML = "Select Year";
this.sel_fy = $a($td(this.tab,1,0), 'select', null, {width:'120px'});
$c_obj('Plot Control', 'get_fiscal_year', '', function(r,rt){
if(r.message) fy_lst = r.message;
else fy_lst = [];
empty_select(me.sel_fy);
add_sel_options(me.sel_fy,fy_lst);
me.sel_fy.value = sys_defaults.fiscal_year;
});
}
//=======================================================================
pscript.report_type=function(){
$td(this.tab,0,1).innerHTML = "Select Report";
this.sel_rpt = $a($td(this.tab,1,1), 'select', null, {width:'120px'});
rpt_lst = ['Monthly','Weekly'];
add_sel_options(this.sel_rpt,rpt_lst);
}
//=======================================================================
pscript.item_grp=function(){
var me = this;
$td(this.tab,0,2).innerHTML = "Select Item Group";
this.sel_grp = $a($td(this.tab,1,2), 'select', null, {width:'120px'});
$c_obj('Plot Control', 'get_item_groups', '', function(r,rt){
itg_lst = r.message;
itg_lst.push('All');
empty_select(me.sel_grp);
add_sel_options(me.sel_grp, itg_lst.reverse());
});
}
//=======================================================================
pscript.month_lst=function(){
pscript.mnt_div1 = $a($td(this.tab,0,3));
pscript.mnt_div1.innerHTML = "Select Month";
pscript.mnt_div = $a($td(this.tab,1,3));
this.sel_mnt = $a(pscript.mnt_div, 'select', null, {width:'120px'});
mnt_lst = ['All','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
add_sel_options(this.sel_mnt,mnt_lst);
}
//=======================================================================
pscript.all_onchnge = function(){
pscript.report_change();
pscript.fiscal_year_onchnage();
pscript.month_onchange();
pscript.item_grp_onchange();
pscript.monthly();
}
//=======================================================================
pscript.report_change = function(){
var me = this;
this.sel_rpt.onchange = function(){
$dh(pscript.mnt_div);
$dh(pscript.mnt_div1);
if(me.sel_rpt.value == 'Monthly'){
pscript.monthly();
}
else if(me.sel_rpt.value == 'Weekly'){
$ds(pscript.mnt_div);
$ds(pscript.mnt_div1);
me.sel_mnt.value = 'All';
pscript.get_x_dates();
}
else{
me.sel_mnt.value = 'All';
$i('plot_test').innerHTML = '';
}
}
}
//=======================================================================
pscript.fiscal_year_onchnage = function(){
var me = this;
this.sel_fy.onchange = function(){
if(me.sel_rpt.value == 'Monthly'){
me.sel_mnt.value = 'All';
$dh(pscript.mnt_div);
$dh(pscript.mnt_div1);
pscript.monthly();
}
else if(me.sel_rpt.value == 'Weekly' && me.sel_mnt.value){
pscript.get_x_dates();
}
else{
me.sel_mnt.value = 'All';
me.sel_rpt.value == '';
$i('plot_test').innerHTML = '';
}
}
}
//=======================================================================
pscript.month_onchange = function(){
this.sel_mnt.onchange = function(){
pscript.get_x_dates();
}
}
//=======================================================================
pscript.item_grp_onchange=function(){
var me = this;
this.sel_grp.onchange = function(){
if(me.sel_rpt.value == 'Monthly'){
me.sel_mnt.value = 'All';
$dh(pscript.mnt_div);
$dh(pscript.mnt_div1);
pscript.monthly();
}
else if(me.sel_rpt.value == 'Weekly' && me.sel_mnt.value){
pscript.get_x_dates();
}
else{
me.sel_mnt.value = 'All';
me.sel_rpt.value == '';
$i('plot_test').innerHTML = '';
}
}
}
//=======================================================================
pscript.get_x_dates=function(){
if(this.sel_mnt.value !='All'){
pscript.weekly();
}
else{
$c_obj('Plot Control','yr_wk_dates',this.sel_fy.value,
function(r,rt){
pscript.dx_axis = r.message[0];
pscript.x_axis = r.message[1];
pscript.yearly();
}
);
}
}
//=======================================================================
pscript.draw_graph1 = function(x_axis,line1,t) {
t = t + " ("+sys_defaults.currency +")";
$i('plot_test').innerHTML = '';
// div plot_test contains the container div
$.jqplot('plot_test', [line1],{
title:t,
axesDefaults: {
min:0
},
axes:{
xaxis:{ticks:x_axis}
}
});
}
//=======================================================================
pscript.monthly = function(){
var callback = function(r,rt){
x_axis = r.message.x_axis;
msg_data = r.message.msg_data;
var line1 = [];
for(var i=0; i