Merge branch 'unicode' of github.com:webnotes/erpnext into unicode

This commit is contained in:
Anand Doshi 2012-09-17 21:24:39 +05:30
commit 6b52d77c76
33 changed files with 827 additions and 638 deletions

View File

@ -17,13 +17,4 @@
"erpnext/startup/js/feature_setup.js",
"conf.js"
],
"public/js/kb_common.js": [
"erpnext/utilities/page/kb_common/kb_common.js",
],
"public/js/complete_setup.js": [
"erpnext/startup/js/complete_setup.js",
],
"public/js/gantt_task.js": [
"erpnext/projects/gantt_task.js",
]
}

View File

@ -1,369 +0,0 @@
// 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/>.
/* 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
});
erpnext.coa.make_page(wrapper);
erpnext.coa.load_companies();
}
erpnext.coa = {
make_page: function(wrapper) {
erpnext.coa.company_select = wrapper.appframe
.add_select("Company", ["Loading..."])
.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));
var end_date = new Date();
if(end_date > dateutil.str_to_obj(sys_defaults.year_end_date))
end_date = sys_defaults.year_end_date;
erpnext.coa.closing_date = wrapper.appframe.add_date("Closing Date")
.val(dateutil.obj_to_user(end_date));
erpnext.coa.refresh_btn = wrapper.appframe.add_button("Refresh", function() {
erpnext.coa.chart.refresh();
}, "icon-refresh");
erpnext.coa.waiting = $('<div class="well" style="width: 63%; margin: 30px auto;">\
<p style="text-align: center;">Building Trial Balance Report. \
Please wait for a few moments</p>\
<div class="progress progress-striped active">\
<div class="bar" style="width: 100%"></div></div>')
.appendTo($(wrapper).find('.layout-main'));
$('<div id="chart-of-accounts" style="height: 500px; border: 1px solid #aaa;">\
</div>').appendTo($(wrapper).find('.layout-main'));
},
load_companies: function() {
wn.call({
module: "accounts",
page: "chart_of_accounts",
method: "get_companies",
callback: function(r) {
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;
}
});
}
};
erpnext.ChartOfAccounts = Class.extend({
init: function() {
this.load_slickgrid();
this.load_data($(erpnext.coa.company_select).val());
},
load_slickgrid: function() {
// load tree
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.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({
module: "accounts",
page: "chart_of_accounts",
method: "get_chart",
args: {company: company},
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();
}
})
},
prepare_chart: 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],
"debit_or_credit": v[2],
"opening_debit": 0,
"opening_credit": 0,
"debit": 0,
"credit": 0,
"closing_debit": 0,
"closing_credit": 0,
"is_pl": v[3]
};
data.push(d);
data_by_name[d.name] = d;
if(d.parent) {
parent_map[d.name] = d.parent;
}
}
});
this.set_indent(data, parent_map);
this.accounts = data;
this.parent_map = parent_map;
this.accounts_by_name = data_by_name;
},
prepare_balances: function() {
var gl = this.gl;
var me = this;
this.opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val());
this.closing_date = dateutil.user_to_obj(erpnext.coa.closing_date.val());
this.set_fiscal_year();
if (!this.fiscal_year) return;
$.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) {
var posting_date = dateutil.str_to_obj(v[0]);
var account = me.accounts_by_name[v[1]];
me.update_balances(account, posting_date, v)
});
this.update_groups();
this.format_balances();
},
update_balances: function(account, posting_date, v) {
// opening
if (posting_date < this.opening_date || v[4] === "Y") {
if (account.is_pl === "Yes" && posting_date <= dateutil.str_to_obj(this.fiscal_year[1])) {
// balance of previous fiscal_year should
// not be part of opening of pl account balance
} else {
if(account.debit_or_credit=='D') {
account.opening_debit += (v[2] - v[3]);
} else {
account.opening_credit += (v[3] - v[2]);
}
}
} else if (this.opening_date <= posting_date && posting_date <= this.closing_date) {
// in between
account.debit += v[2];
account.credit += v[3];
}
// closing
if(account.debit_or_credit=='D') {
account.closing_debit = account.opening_debit + account.debit - account.credit;
} else {
account.closing_credit = account.opening_credit - account.debit + account.credit;
}
},
update_groups: function() {
// update groups
var me= this;
$.each(this.accounts, function(i, account) {
// update groups
var parent = me.parent_map[account.name];
while(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;
parent_account.credit += account.credit;
parent_account.closing_debit += account.closing_debit;
parent_account.closing_credit += account.closing_credit;
parent = me.parent_map[parent];
}
});
},
format_balances: function() {
// format amount
$.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);
v.credit = fmt_money(v.credit);
v.closing_debit = fmt_money(v.closing_debit);
v.closing_credit = fmt_money(v.closing_credit);
});
},
set_fiscal_year: function() {
if (this.opening_date > this.closing_date) {
msgprint("Opening Date should be before Closing Date");
return;
}
this.fiscal_year = null;
var me = this;
$.each(erpnext.coa.fiscal_years, function(i, v) {
if (me.opening_date >= dateutil.str_to_obj(v[1]) &&
me.closing_date <= dateutil.str_to_obj(v[2])) {
me.fiscal_year = v;
}
});
if (!this.fiscal_year) {
msgprint("Opening Date and Closing Date should be within same Fiscal Year");
return;
}
},
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;
});
},
setup_dataview: function() {
var me = this;
// initialize the model
this.dataView = new Slick.Data.DataView({ inlineFilters: true });
this.dataView.beginUpdate();
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.accounts_by_name[parent]._collapsed) {
return false;
}
parent = erpnext.coa.chart.parent_map[parent];
}
}
return true;
},
add_events: function(grid) {
var me = 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();
}
});
this.dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
this.dataView.onRowCountChanged.subscribe(function (e, args) {
grid.updateRowCount();
grid.render();
});
},
account_formatter: function (row, cell, value, columnDef, dataContext) {
value = value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
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);
if (data[idx + 1] && data[idx + 1].indent > data[idx].indent) {
if (dataContext._collapsed) {
return spacer + " <span class='toggle expand'></span>&nbsp;" + value;
} else {
return spacer + " <span class='toggle collapse'></span>&nbsp;" + value;
}
} else {
return spacer + " <span class='toggle'></span>&nbsp;" + value;
}
}
});

View File

@ -1,49 +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, ))
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, ), as_list=1)
idx_map = {}
for i in xrange(len(res["chart"])):
idx_map[res["chart"][i][0]] = i
for d in res["gl"]:
d[1] = idx_map[d[1]]
return res
@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
res = {}
if match and webnotes.user.get_defaults().get("company"):
res["companies"] = webnotes.user.get_defaults().get("company")
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
order by year_start_date asc""")
return res

View File

@ -1,28 +0,0 @@
# 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'
}
]

View File

@ -0,0 +1,226 @@
// 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/>.
wn.require("js/app/account_tree_grid.js");
wn.require("js/app/account_tree_grid.css");
wn.pages['financial-analytics'].onload = function(wrapper) {
wn.ui.make_app_page({
parent: wrapper,
title: 'Financial Analytics',
single_column: true
});
erpnext.trial_balance = new erpnext.FinancialAnalytics(wrapper, 'Financial Analytics');
}
erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
filters: [
{fieldtype:"Select", label: "PL or BS", options:["Profit and Loss", "Balance Sheet"],
filter: function(val, item, opts) {
if(val=='Profit and Loss') {
return item.is_pl_account=='Yes' || item._show;
} else {
return item.is_pl_account=='No' || item._show;
}
}},
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
return item.company == val || val == opts.default_value || item._show;
}},
{fieldtype:"Select", label: "Fiscal Year", link:"Fiscal Year",
default_value: "Select Fiscal Year..."},
{fieldtype:"Date", label: "From Date"},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date"},
{fieldtype:"Select", label: "Range",
options:["Daily", "Weekly", "Monthly", "Quarterly", "Yearly"]},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"}
],
setup_columns: function() {
this.columns = [
{id: "check", name: "Plot", field: "check", width: 30,
formatter: function(row, cell, value, columnDef, dataContext) {
return repl("<input type='checkbox' account='%(name)s' \
class='plot-check' %(checked)s>", {
"name": dataContext.name,
"checked": dataContext.checked ? "checked" : ""
})
}},
{id: "name", name: "Account", field: "name", width: 300,
formatter: this.account_formatter},
];
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 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)) {
me.columns.push({
from_date: date,
id: date,
name: dateutil.str_to_user(date),
field: date,
formatter: me.currency_formatter,
width: 100
});
}
me.last_date = date;
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;
});
}
},
init_filter_values: function() {
this._super();
this.filter_inputs.range.val('Weekly');
},
prepare_balances: function() {
var me = this;
$.each(wn.report_dump.data['GL Entry'], function(i, gl) {
var posting_date = dateutil.str_to_obj(gl.posting_date);
var account = me.accounts_by_name[gl.account];
var col = me.column_map[gl.posting_date];
if(col) {
if(gl.voucher_type=='Period Closing Voucher') {
// period closing voucher not to be added
// to profit and loss accounts (else will become zero!!)
if(account.is_pl_account!='Yes')
me.add_balance(col.field, account, gl);
} else {
me.add_balance(col.field, account, gl);
}
} else if(account.is_pl_account!='Yes'
&& (posting_date < dateutil.str_to_obj(me.from_date))) {
me.add_balance('opening', account, gl);
}
});
// make balances as cumulative
if(me.filter_inputs.pl_or_bs.val()=='Balance Sheet') {
$.each(me.accounts, function(i, ac) {
if((ac.rgt - ac.lft)==1 && ac.is_pl_account!='Yes') {
var opening = flt(ac.opening);
//if(opening) throw opening;
$.each(me.columns, function(i, col) {
if(col.formatter==me.currency_formatter) {
ac[col.field] = opening + flt(ac[col.field]);
opening = ac[col.field];
}
});
}
})
}
this.update_groups();
},
add_balance: function(field, account, gl) {
account[field] = flt(account[field]) +
((account.debit_or_credit == "Debit" ? 1 : -1) * (gl.debit - gl.credit))
},
init_account: function(d) {
var me = this;
$.each(this.columns, function(i, col) {
if (col.formatter==me.currency_formatter) {
d[col.from_date] = 0;
}
});
},
init_refresh: function() {
var me = this;
$.each(this.accounts || [], function(i, account) {
account.checked && me.preset_checks.push(account.name);
});
},
init_plot: function() {
var me = this;
if(this.preset_checks.length) {
$.each(me.preset_checks, function(i, name) {
me.accounts_by_name[name].checked = true;
});
} else {
$.each(this.accounts, function(i, account) {
if(!account.parent_account) {
account.checked = true;
}
});
}
},
get_plot_data: function() {
var data = [];
var me = this;
var pl_or_bs = this.filter_inputs.pl_or_bs.val();
$.each(this.accounts, function(i, account) {
var show = pl_or_bs == "Profit and Loss" ? account.is_pl_account=="Yes" : account.is_pl_account!="Yes";
if (show && account.checked) {
data.push({
label: account.name,
data: $.map(me.columns, function(col, idx) {
if(col.formatter==me.currency_formatter)
return [[idx, account[col.field]]]
})
});
}
});
return data;
},
add_grid_events: function() {
this._super();
var me = this;
this.wrapper.find('.plot-check').click(function() {
var checked = $(this).attr("checked");
me.accounts_by_name[$(this).attr("account")].checked = checked ? true : false;
me.render_plot();
});
}
})

View File

@ -0,0 +1,28 @@
# Page, financial-analytics
[
# These values are common in all dictionaries
{
u'creation': '2012-09-17 13:46:47',
u'docstatus': 0,
u'modified': '2012-09-17 13:46:47',
u'modified_by': u'Administrator',
u'owner': u'Administrator'
},
# These values are common for all Page
{
u'doctype': u'Page',
'module': u'Accounts',
u'name': u'__common__',
'page_name': u'financial-analytics',
'standard': u'Yes',
'title': u'Financial Analytics'
},
# Page, financial-analytics
{
u'doctype': u'Page',
u'name': u'financial-analytics'
}
]

View File

@ -6,60 +6,147 @@ wn.pages['general-ledger'].onload = function(wrapper) {
});
erpnext.general_ledger = new wn.views.GridReport({
title: "General Ledger",
page: wrapper,
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: "account", name: "Account", field: "account", width: 240,
link_formatter: {
filter_input: "account",
open_btn: true,
doctype: '"Account"'
}},
{id: "debit", name: "Debit", field: "debit", width: 100,
formatter: this.currency_formatter},
{id: "credit", name: "Credit", field: "credit", width: 100,
formatter: this.currency_formatter},
{id: "voucher_type", name: "Voucher Type", field: "voucher_type", width: 120},
{id: "voucher_no", name: "Voucher No", field: "voucher_no", width: 160,
link_formatter: {
filter_input: "voucher_no",
open_btn: true,
doctype: "dataContext.voucher_type"
}},
{id: "remarks", name: "Remarks", field: "remarks", width: 200,
formatter: this.text_formatter},
];
},
filters: [
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
return item.company == val || val == opts.default_value || item._show;
}},
{fieldtype:"Select", label: "Account", link:"Account", default_value: "Select Account...",
filter: function(val, item, opts, me) {
if(val == opts.default_value || item._show) {
return true;
} else {
// true if GL Entry belongs to selected
// account ledger or group
return me.is_child_account(val, item.account);
}
}},
{fieldtype:"Data", label: "Voucher No",
filter: function(val, item, opts) {
if(!val) return true;
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1) || item._show;
}},
{fieldtype:"Date", label: "From Date", filter: function(val, item) {
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 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"}
],
init_filter_values: function() {
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.voucher_no.val("");
this.filter_inputs.account.get(0).selectedIndex = 0;
},
is_child_account: function(account, item_account) {
account = this.account_by_name[account];
item_account = this.account_by_name[item_account];
return (item_account.lft >= account.lft && item_account.rgt <= account.rgt)
},
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;
}
// add Opening, Closing, Totals rows
// if filtered by account and / or voucher
var data = wn.report_dump.data["GL Entry"];
this.make_account_by_name();
var me = this;
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;
}
return true;
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 ? me.is_child_account(account, item.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);
},
make_account_by_name: function() {
this.account_by_name = {};
var me = this;
$.each(wn.report_dump.data['Account'], function(i, v) {
me.account_by_name[v.name] = v;
})
}
});
}

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

@ -0,0 +1,27 @@
// 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/>.
wn.require("js/app/account_tree_grid.js");
wn.require("js/app/account_tree_grid.css");
wn.pages['trial-balance'].onload = function(wrapper) {
wn.ui.make_app_page({
parent: wrapper,
title: 'Trial Balance',
single_column: true
});
erpnext.trial_balance = new erpnext.AccountTreeGrid(wrapper, 'Trial Balance');
}

View File

@ -0,0 +1,28 @@
# Page, trial-balance
[
# These values are common in all dictionaries
{
u'creation': '2012-09-17 13:47:16',
u'docstatus': 0,
u'modified': '2012-09-17 13:47:16',
u'modified_by': u'Administrator',
u'owner': u'Administrator'
},
# These values are common for all Page
{
u'doctype': u'Page',
'module': u'Accounts',
u'name': u'__common__',
'page_name': u'trial-balance',
'standard': u'Yes',
'title': u'Trial Balance'
},
# Page, trial-balance
{
u'doctype': u'Page',
u'name': u'trial-balance'
}
]

View File

@ -43,6 +43,7 @@
<li><a href="http://taitems.github.com/jQuery.Gantt/">JQuery.Gantt</a> - Gantt Chart</li>
<li>JSON2 - JSON builder, parser</li>
<li>JSColor - color picker</li>
<li><a href="https://github.com/dcneiner/Downloadify">Downloadify</a> - Export CSV files from the browser</li>
</ul>
</ul>

View File

@ -17,7 +17,7 @@
pscript.onload_Projects = function(wrapper) {
wn.ui.make_app_page({parent:wrapper, title:'Gantt Chart: All Tasks', single_column:true});
if(!erpnext.show_task_gantt)
wn.require('js/gantt_task.js');
wn.require('js/app/gantt_task.js');
var gantt_area = $('<div>').appendTo($(wrapper).find('.layout-main'));
erpnext.show_task_gantt(gantt_area);

View File

@ -87,7 +87,7 @@ def boot_session(bootinfo):
# load subscription info
import conf
for key in ['max_users', 'expires_on', 'max_space', 'status']:
for key in ['max_users', 'expires_on', 'max_space', 'status', 'developer_mode']:
if hasattr(conf, key): bootinfo[key] = getattr(conf, key)
company = webnotes.conn.sql("select name, default_currency from `tabCompany`", as_dict=1)
@ -96,7 +96,7 @@ def boot_session(bootinfo):
company_dict.setdefault(c['name'], {}).update(c)
bootinfo['company'] = company_dict
def get_letter_heads():
"""load letter heads with startup"""
import webnotes

View File

@ -20,11 +20,16 @@ data_map = {
"company"],
"order_by": "lft"
},
"Cost Center": {
"columns": ["name", "parent_cost_center", "lft", "rgt", "debit_or_credit",
"company"],
"order_by": "lft"
},
"GL Entry": {
"columns": ["account", "posting_date", "cost_center", "debit", "credit", "is_opening",
"company"],
"company", "voucher_type", "voucher_no", "remarks"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date"
"order_by": "posting_date, account"
},
"Company": {
"columns": ["name"],
@ -32,6 +37,6 @@ data_map = {
},
"Fiscal Year": {
"columns": ["name", "year_start_date",
"adddate(year_start_date, interval 1 year) as year_end_date"]
"adddate(adddate(year_start_date, interval 1 year), interval -1 day) as year_end_date"]
}
}

View File

@ -76,7 +76,7 @@ erpnext.startup.start = function() {
// complete registration
if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
wn.require("js/complete_setup.js");
wn.require("js/app/complete_setup.js");
erpnext.complete_setup.show();
}
if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {

View File

@ -215,4 +215,4 @@ KBQuestion = function(parent, det, kb) {
this.make()
}
wn.require('js/kb_common.js');
wn.require('js/app/kb_common.js');

View File

@ -3536,6 +3536,18 @@ div.appframe-toolbar {
border-bottom: 1px solid #ccc;
}
div.appframe-toolbar .label {
margin: 2px 2px;
}
div.appframe-toolbar input, div.appframe-toolbar select {
font-size: 80%;
margin: 2px 2px;
}
div.appframe-toolbar button {
padding: 3px 7px !important;
}
/*

View File

@ -2570,6 +2570,18 @@ div.appframe-toolbar {
border-bottom: 1px solid #ccc;
}
div.appframe-toolbar .label {
margin: 2px 2px;
}
div.appframe-toolbar input, div.appframe-toolbar select {
font-size: 80%;
margin: 2px 2px;
}
div.appframe-toolbar button {
padding: 3px 7px !important;
}
/*

View File

@ -139,7 +139,7 @@ wn.provide('wn.settings');wn.provide('wn.ui');
*/
wn.require=function(items){if(typeof items==="string"){items=[items];}
var l=items.length;for(var i=0;i<l;i++){var src=items[i];wn.assets.execute(src);}}
wn.assets={executed_:{},check:function(){if(window._version_number!=localStorage.getItem("_version_number")){localStorage.clear();localStorage.setItem("_version_number",window._version_number)}},exists:function(src){if('localStorage'in window&&localStorage.getItem(src))
wn.assets={executed_:{},check:function(){if(window._version_number!=localStorage.getItem("_version_number")){localStorage.clear();localStorage.setItem("_version_number",window._version_number)}},exists:function(src){if('localStorage'in window&&localStorage.getItem(src)&&!wn.boot.developer_mode)
return true},add:function(src,txt){if('localStorage'in window){localStorage.setItem(src,txt);}},get:function(src){return localStorage.getItem(src);},extn:function(src){if(src.indexOf('?')!=-1){src=src.split('?').slice(-1)[0];}
return src.split('.').slice(-1)[0];},load:function(src){var t=src;$.ajax({url:t,data:{q:Math.floor(Math.random()*1000)},dataType:'text',success:function(txt){wn.assets.add(src,txt);},async:false})},execute:function(src){if(!wn.assets.exists(src)){wn.assets.load(src);}
var type=wn.assets.extn(src);if(wn.assets.handler[type]){wn.assets.handler[type](wn.assets.get(src),src);wn.assets.executed_[src]=1;}},handler:{js:function(txt,src){wn.dom.eval(txt);},css:function(txt,src){wn.dom.set_style(txt);}}}
@ -179,7 +179,7 @@ $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){
this.selectedIndex=0;return $(this);}
$.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=$('<img src="images/lib/ui/button-load.gif" \
style="margin-left: 4px; margin-bottom: -2px; display: inline;" />').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);
$.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery);wn.to_csv=function(data){var res=[];$.each(data,function(i,row){row=$.map(row,function(col){return typeof(col)==="string"?('"'+col.replace(/"/g,'\"')+'"'):col;});res.push(row.join(","));});return res.join("\n");}
/*
* lib/js/wn/model.js
*/
@ -356,8 +356,9 @@ $(page).bind('show',onshow);if(onshow)
$(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},change_to:function(label){if(this.page&&this.page.label==label){return;}
var me=this;if(label.tagName){var page=label;}else{var page=wn.pages[label];}
if(!page){console.log('Page not found '+label);return;}
if(this.page){$(this.page).toggle(false);$(this.page).trigger('hide');}
this.page=page;$(this.page).fadeIn();this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
if(this.page&&this.page!=page){$(this.page).toggle(false);$(this.page).trigger('hide');}
if(!this.page||this.page!=page){this.page=page;$(this.page).fadeIn();}
this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
onclick="wn.set_route(\'%(module_small)s-home\')">\
<i class="icon-home icon-white"></i> %(module)s Home\
</span>',{module:module,module_small:module.toLowerCase()}));}
@ -393,8 +394,7 @@ msgprint(r.server_messages);}
if(r.exc){r.exc=JSON.parse(r.exc);if(r.exc instanceof Array){$.each(r.exc,function(i,v){if(v)console.log(v);})}else{console.log(r.exc);}};if(r['403']){wn.container.change_to('403');}
if(r.docs){LocalDB.sync(r.docs);}}
wn.request.call=function(opts){wn.request.prepare(opts);var ajax_args={url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2)
opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})}
opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2);opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})}
$.ajax(ajax_args);}
wn.call=function(opts){var args=$.extend({},opts.args)
if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;}
@ -609,7 +609,7 @@ msg=JSON.stringify(msg);if(msg.substr(0,8)=='__small:'){show_alert(msg.substr(8)
if(!msg_dialog){msg_dialog=new wn.ui.Dialog({title:"Message",onhide:function(){msg_dialog.msg_area.empty();}});msg_dialog.msg_area=$('<div class="msgprint">').appendTo(msg_dialog.body);}
if(msg.search(/<br>|<p>|<li>/)==-1)
msg=replace_newlines(msg);msg_dialog.set_title(title||'Message')
msg_dialog.msg_area.append(msg);msg_dialog.show();}
msg_dialog.msg_area.append(msg);msg_dialog.show();return msg_dialog;}
var growl_area;function show_alert(txt,id){if(!growl_area){if(!$('#dialog-container').length){$('<div id="dialog-container">').appendTo('body');}
growl_area=$a($i('dialog-container'),'div','',{position:'fixed',bottom:'8px',right:'8px',width:'320px',zIndex:10});}
var wrapper=$a(growl_area,'div','',{position:'relative'});var body=$a(wrapper,'div','notice');var c=$a(body,'i','icon-remove-sign',{cssFloat:'right',cursor:'pointer'});$(c).click(function(){$dh(this.wrapper)});c.wrapper=wrapper;var t=$a(body,'div','',{color:'#FFF'});$(t).html(txt);if(id){$(t).attr('id',id);}
@ -847,14 +847,14 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
<span class="appframe-title"></span>\
<span class="close">&times;</span>\
</div>').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();})
if(title)this.title(title);},title:function(txt){this.clear_breadcrumbs();this.add_breadcrumb(txt);},add_button:function(label,click,icon){this.make_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="icon '+icon+'"></i>';}
if(title)this.title(title);},title:function(txt){this.clear_breadcrumbs();this.add_breadcrumb(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="icon '+icon+'"></i>';}
this.buttons[label]=$(repl('<button class="btn btn-small">\
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},add_help_button:function(txt){this.make_toolbar();$('<button class="btn btn-small" style="float:right;" button-type="help">\
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},add_help_button:function(txt){this.add_toolbar();$('<button class="btn btn-small" style="float:right;" button-type="help">\
<b>?</b></button>').data('help-text',txt).click(function(){msgprint($(this).data('help-text'),'Help');}).appendTo(this.toolbar);},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_breadcrumb:function(html){if(!this.$breadcrumbs)
this.$breadcrumbs=$('</span>\
<span class="breadcrumb-area"></span>').appendTo(this.$titlebar);var crumb=$('<span>').html(html);if(!this.$breadcrumbs.find('span').length){crumb.addClass('appframe-title');}
crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},make_toolbar:function(){if(!this.toolbar)
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span style='margin: 2px 4px;'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.make_toolbar();return $("<select style='width: 160px; margin: 2px 4px;'>").add_options(options).appendTo(this.toolbar);},add_date:function(label,date){this.make_toolbar();return $("<input style='width: 80px; margin: 2px 4px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},add_toolbar:function(){if(!this.toolbar)
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span class='label'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 100px;'>").add_options(options).appendTo(this.toolbar);},add_data:function(label){this.add_toolbar();return $("<input style='width: 100px;' placeholder='"+label+"'>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
<div class="layout-appframe"></div>\
<div class="layout-main"></div>\
</div>');}else{$(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
@ -1072,12 +1072,36 @@ 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: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=doctype+"-"+i;data.push(row);});wn.report_dump.data[doctype]=data;});callback();},progress_bar:progress_bar})}else{callback();}}});wn.provide("wn.views");wn.views.GridReport=Class.extend({init:function(opts){this.filter_inputs={};$.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();wn.cur_grid_report=this;},get_data:function(){var me=this;wn.report_dump.with_data(this.doctypes,function(){$.each(me.filter_inputs,function(i,v){var opts=v.get(0).opts;if(opts.fieldtype=="Select"&&inList(me.doctypes,opts.options)){$(v).add_options($.map(wn.report_dump.data[opts.options],function(d){return d.name;}));}});me.setup();me.refresh();},this.wrapper.find(".progress .bar"));},make_waiting:function(){this.waiting=$('<div class="well" style="width: 63%; margin: 30px auto;">\
if(missing.length){wn.call({method:"webnotes.widgets.report_dump.get_data",args:{doctypes: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=doctype+"-"+i;data.push(row);});wn.report_dump.data[doctype]=data;});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=[];$.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();},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();});},make_waiting:function(){this.waiting=$('<div class="well" style="width: 63%; margin: 30px auto;">\
<p style="text-align: center;">Loading Report...</p>\
<div class="progress progress-striped active">\
<div class="bar" style="width: 10%"></div></div>').appendTo(this.wrapper);},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,["Select "+v.options]);}else if(v.fieldtype=='Button'){input=me.appframe.add_button(v.label);}else if(v.fieldtype=='Date'){input=me.appframe.add_date(v.label);}else if(v.fieldtype=='Label'){input=me.appframe.add_label(v.label);}
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.prepare_data();this.render();},render:function(){this.waiting.toggle(false);this.grid_wrapper=$("<div style='height: 500px; border: 1px solid #aaa;'>").appendTo(this.wrapper);this.id=wn.dom.set_unique_id(this.grid_wrapper.get(0));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();},options:{editable:false,enableColumnReorder:false},dataview_filter:function(item){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>";}})
<div class="bar" style="width: 10%"></div></div>').appendTo(this.wrapper);},make_grid_wrapper:function(){$('<div class="plot" style="margin-bottom: 15px; display: none; \
height: 300px; width: 100%;"></div>').appendTo(this.wrapper);$('<div style="text-align: right;"> \
<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; \
background-color: #eee; margin-top: 15px;'>").appendTo(this.wrapper);this.id=wn.dom.set_unique_id(this.grid_wrapper.get(0));var me=this;$(this.page).bind('show',function(){wn.cur_grid_report=me;me.apply_filters_from_route();me.refresh();});wn.cur_grid_report=this;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.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);}
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.init_refresh&&this.init_refresh();this.waiting.toggle(false);if(!this.grid_wrapper)
this.make_grid_wrapper();this.setup_columns();this.apply_link_formatters();this.prepare_data();this.init_plot&&this.init_plot();this.render();this.render_plot();},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("=");if(me.filter_inputs[f[0]]){me.filter_inputs[f[0]].val(decodeURIComponent(f[1]));}else{console.log("Invalid filter: "+f[0]);}});}},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.grid=new Slick.Grid("#"+this.id,this.dataView,this.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.add_grid_events&&this.add_grid_events();},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;})].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;},render_plot:function(){if(!this.get_plot_data)return;wn.require('js/lib/flot/jquery.flot.js');$.plot(this.wrapper.find('.plot').toggle(true),this.get_plot_data());},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;},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,wn.cur_grid_report)){return false;}}
if(wn.cur_grid_report.custom_dataview_filter){return wn.cur_grid_report.custom_dataview_filter(item);}
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})
if(link_formatter.open_btn){html+=repl(' <i class="icon icon-share" style="cursor: pointer;"\
onclick="wn.set_route(\'Form\', \'%(doctype)s\', \'%(value)s\');">\
</i>',{value:value,doctype:eval(link_formatter.doctype)});}
return html;}}})}})
/*
* lib/js/legacy/widgets/dialog.js
*/
@ -2248,7 +2272,7 @@ me.dialog.clear();me.dialog.show();}});
*/
wn.Application=Class.extend({init:function(){var me=this;if(window.app){wn.call({method:'startup',callback:function(r,rt){wn.provide('wn.boot');wn.boot=r;if(wn.boot.profile.name=='Guest'){window.location='index.html';return;}
me.startup();}})}else{this.startup();}},startup:function(){this.load_bootinfo();this.make_page_container();this.make_nav_bar();this.set_favicon();$(document).trigger('startup');if(wn.boot){wn.route();}
$(document).trigger('app_ready');},load_bootinfo:function(){if(wn.boot){LocalDB.sync(wn.boot.docs);wn.control_panel=wn.boot.control_panel;this.set_globals();}else{this.set_as_guest();}},set_globals:function(){profile=wn.boot.profile;user=wn.boot.profile.name;user_fullname=wn.user_info(user).fullname;user_defaults=profile.defaults;user_roles=profile.roles;user_email=profile.email;sys_defaults=wn.boot.sysdefaults;},set_as_guest:function(){profile={name:'Guest'};user='Guest';user_fullname='Guest';user_defaults={};user_roles=['Guest'];user_email='';sys_defaults={};},make_page_container:function(){wn.container=new wn.views.Container();wn.views.make_403();wn.views.make_404();},make_nav_bar:function(){if(wn.boot){wn.container.wntoolbar=new wn.ui.toolbar.Toolbar();}},logout:function(){var me=this;me.logged_out=true;wn.call({method:'logout',callback:function(r){if(r.exc){console.log(r.exc);}
$(document).trigger('app_ready');},load_bootinfo:function(){if(wn.boot){LocalDB.sync(wn.boot.docs);wn.control_panel=wn.boot.control_panel;this.set_globals();if(wn.boot.developer_mode){(console.warn||console.log)("LocalStorage is OFF for developer mode. Please build before going live.");}}else{this.set_as_guest();}},set_globals:function(){profile=wn.boot.profile;user=wn.boot.profile.name;user_fullname=wn.user_info(user).fullname;user_defaults=profile.defaults;user_roles=profile.roles;user_email=profile.email;sys_defaults=wn.boot.sysdefaults;},set_as_guest:function(){profile={name:'Guest'};user='Guest';user_fullname='Guest';user_defaults={};user_roles=['Guest'];user_email='';sys_defaults={};},make_page_container:function(){wn.container=new wn.views.Container();wn.views.make_403();wn.views.make_404();},make_nav_bar:function(){if(wn.boot){wn.container.wntoolbar=new wn.ui.toolbar.Toolbar();}},logout:function(){var me=this;me.logged_out=true;wn.call({method:'logout',callback:function(r){if(r.exc){console.log(r.exc);}
me.redirect_to_login();}})},redirect_to_login:function(){window.location.href='index.html';},set_favicon:function(){var link=$('link[type="image/x-icon"]').remove().attr("href");var favicon='\
<link rel="shortcut icon" href="'+link+'" type="image/x-icon"> \
<link rel="icon" href="'+link+'" type="image/x-icon">'
@ -2261,7 +2285,7 @@ wn.provide('wn.modules');$.extend(wn.modules,erpnext.modules);wn.modules['Core']
erpnext.startup.start=function(){console.log('Starting up...');$('#startup_div').html('Starting up...').toggle(true);erpnext.startup.set_globals();if(user!='Guest'){if(wn.boot.user_background){erpnext.set_user_background(wn.boot.user_background);}
wn.boot.profile.allow_modules=wn.boot.profile.allow_modules.concat(['To Do','Knowledge Base','Calendar','Activity','Messages'])
erpnext.toolbar.setup();erpnext.startup.set_periodic_updates();$('footer').html('<div class="web-footer erpnext-footer">\
<a href="#!attributions">ERPNext | Attributions and License</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("js/complete_setup.js");erpnext.complete_setup.show();}
<a href="#!attributions">ERPNext | Attributions and License</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("js/app/complete_setup.js");erpnext.complete_setup.show();}
if(wn.boot.expires_on&&in_list(user_roles,'System Manager')){var today=dateutil.str_to_obj(dateutil.get_today());var expires_on=dateutil.str_to_obj(wn.boot.expires_on);var diff=dateutil.get_diff(expires_on,today);if(0<=diff&&diff<=15){var expiry_string=diff==0?"today":repl("in %(diff)s day(s)",{diff:diff});$('header').append(repl('<div class="expiry-info"> \
Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
Please renew your subscription to continue using ERPNext \

View File

@ -26,7 +26,7 @@ wn.provide('wn.settings');wn.provide('wn.ui');
*/
wn.require=function(items){if(typeof items==="string"){items=[items];}
var l=items.length;for(var i=0;i<l;i++){var src=items[i];wn.assets.execute(src);}}
wn.assets={executed_:{},check:function(){if(window._version_number!=localStorage.getItem("_version_number")){localStorage.clear();localStorage.setItem("_version_number",window._version_number)}},exists:function(src){if('localStorage'in window&&localStorage.getItem(src))
wn.assets={executed_:{},check:function(){if(window._version_number!=localStorage.getItem("_version_number")){localStorage.clear();localStorage.setItem("_version_number",window._version_number)}},exists:function(src){if('localStorage'in window&&localStorage.getItem(src)&&!wn.boot.developer_mode)
return true},add:function(src,txt){if('localStorage'in window){localStorage.setItem(src,txt);}},get:function(src){return localStorage.getItem(src);},extn:function(src){if(src.indexOf('?')!=-1){src=src.split('?').slice(-1)[0];}
return src.split('.').slice(-1)[0];},load:function(src){var t=src;$.ajax({url:t,data:{q:Math.floor(Math.random()*1000)},dataType:'text',success:function(txt){wn.assets.add(src,txt);},async:false})},execute:function(src){if(!wn.assets.exists(src)){wn.assets.load(src);}
var type=wn.assets.extn(src);if(wn.assets.handler[type]){wn.assets.handler[type](wn.assets.get(src),src);wn.assets.executed_[src]=1;}},handler:{js:function(txt,src){wn.dom.eval(txt);},css:function(txt,src){wn.dom.set_style(txt);}}}
@ -66,7 +66,7 @@ $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){
this.selectedIndex=0;return $(this);}
$.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=$('<img src="images/lib/ui/button-load.gif" \
style="margin-left: 4px; margin-bottom: -2px; display: inline;" />').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);
$.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery);wn.to_csv=function(data){var res=[];$.each(data,function(i,row){row=$.map(row,function(col){return typeof(col)==="string"?('"'+col.replace(/"/g,'\"')+'"'):col;});res.push(row.join(","));});return res.join("\n");}
/*
* lib/js/wn/model.js
*/
@ -243,8 +243,9 @@ $(page).bind('show',onshow);if(onshow)
$(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},change_to:function(label){if(this.page&&this.page.label==label){return;}
var me=this;if(label.tagName){var page=label;}else{var page=wn.pages[label];}
if(!page){console.log('Page not found '+label);return;}
if(this.page){$(this.page).toggle(false);$(this.page).trigger('hide');}
this.page=page;$(this.page).fadeIn();this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
if(this.page&&this.page!=page){$(this.page).toggle(false);$(this.page).trigger('hide');}
if(!this.page||this.page!=page){this.page=page;$(this.page).fadeIn();}
this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
onclick="wn.set_route(\'%(module_small)s-home\')">\
<i class="icon-home icon-white"></i> %(module)s Home\
</span>',{module:module,module_small:module.toLowerCase()}));}
@ -280,8 +281,7 @@ msgprint(r.server_messages);}
if(r.exc){r.exc=JSON.parse(r.exc);if(r.exc instanceof Array){$.each(r.exc,function(i,v){if(v)console.log(v);})}else{console.log(r.exc);}};if(r['403']){wn.container.change_to('403');}
if(r.docs){LocalDB.sync(r.docs);}}
wn.request.call=function(opts){wn.request.prepare(opts);var ajax_args={url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2)
opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})}
opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2);opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})}
$.ajax(ajax_args);}
wn.call=function(opts){var args=$.extend({},opts.args)
if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;}
@ -496,7 +496,7 @@ msg=JSON.stringify(msg);if(msg.substr(0,8)=='__small:'){show_alert(msg.substr(8)
if(!msg_dialog){msg_dialog=new wn.ui.Dialog({title:"Message",onhide:function(){msg_dialog.msg_area.empty();}});msg_dialog.msg_area=$('<div class="msgprint">').appendTo(msg_dialog.body);}
if(msg.search(/<br>|<p>|<li>/)==-1)
msg=replace_newlines(msg);msg_dialog.set_title(title||'Message')
msg_dialog.msg_area.append(msg);msg_dialog.show();}
msg_dialog.msg_area.append(msg);msg_dialog.show();return msg_dialog;}
var growl_area;function show_alert(txt,id){if(!growl_area){if(!$('#dialog-container').length){$('<div id="dialog-container">').appendTo('body');}
growl_area=$a($i('dialog-container'),'div','',{position:'fixed',bottom:'8px',right:'8px',width:'320px',zIndex:10});}
var wrapper=$a(growl_area,'div','',{position:'relative'});var body=$a(wrapper,'div','notice');var c=$a(body,'i','icon-remove-sign',{cssFloat:'right',cursor:'pointer'});$(c).click(function(){$dh(this.wrapper)});c.wrapper=wrapper;var t=$a(body,'div','',{color:'#FFF'});$(t).html(txt);if(id){$(t).attr('id',id);}
@ -508,14 +508,14 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
<span class="appframe-title"></span>\
<span class="close">&times;</span>\
</div>').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();})
if(title)this.title(title);},title:function(txt){this.clear_breadcrumbs();this.add_breadcrumb(txt);},add_button:function(label,click,icon){this.make_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="icon '+icon+'"></i>';}
if(title)this.title(title);},title:function(txt){this.clear_breadcrumbs();this.add_breadcrumb(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="icon '+icon+'"></i>';}
this.buttons[label]=$(repl('<button class="btn btn-small">\
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},add_help_button:function(txt){this.make_toolbar();$('<button class="btn btn-small" style="float:right;" button-type="help">\
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},add_help_button:function(txt){this.add_toolbar();$('<button class="btn btn-small" style="float:right;" button-type="help">\
<b>?</b></button>').data('help-text',txt).click(function(){msgprint($(this).data('help-text'),'Help');}).appendTo(this.toolbar);},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_breadcrumb:function(html){if(!this.$breadcrumbs)
this.$breadcrumbs=$('</span>\
<span class="breadcrumb-area"></span>').appendTo(this.$titlebar);var crumb=$('<span>').html(html);if(!this.$breadcrumbs.find('span').length){crumb.addClass('appframe-title');}
crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},make_toolbar:function(){if(!this.toolbar)
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span style='margin: 2px 4px;'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.make_toolbar();return $("<select style='width: 160px; margin: 2px 4px;'>").add_options(options).appendTo(this.toolbar);},add_date:function(label,date){this.make_toolbar();return $("<input style='width: 80px; margin: 2px 4px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},add_toolbar:function(){if(!this.toolbar)
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span class='label'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 100px;'>").add_options(options).appendTo(this.toolbar);},add_data:function(label){this.add_toolbar();return $("<input style='width: 100px;' placeholder='"+label+"'>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
<div class="layout-appframe"></div>\
<div class="layout-main"></div>\
</div>');}else{$(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
@ -699,7 +699,7 @@ if(errfld.length)msgprint('<b>Mandatory fields required in '+
*/
wn.Application=Class.extend({init:function(){var me=this;if(window.app){wn.call({method:'startup',callback:function(r,rt){wn.provide('wn.boot');wn.boot=r;if(wn.boot.profile.name=='Guest'){window.location='index.html';return;}
me.startup();}})}else{this.startup();}},startup:function(){this.load_bootinfo();this.make_page_container();this.make_nav_bar();this.set_favicon();$(document).trigger('startup');if(wn.boot){wn.route();}
$(document).trigger('app_ready');},load_bootinfo:function(){if(wn.boot){LocalDB.sync(wn.boot.docs);wn.control_panel=wn.boot.control_panel;this.set_globals();}else{this.set_as_guest();}},set_globals:function(){profile=wn.boot.profile;user=wn.boot.profile.name;user_fullname=wn.user_info(user).fullname;user_defaults=profile.defaults;user_roles=profile.roles;user_email=profile.email;sys_defaults=wn.boot.sysdefaults;},set_as_guest:function(){profile={name:'Guest'};user='Guest';user_fullname='Guest';user_defaults={};user_roles=['Guest'];user_email='';sys_defaults={};},make_page_container:function(){wn.container=new wn.views.Container();wn.views.make_403();wn.views.make_404();},make_nav_bar:function(){if(wn.boot){wn.container.wntoolbar=new wn.ui.toolbar.Toolbar();}},logout:function(){var me=this;me.logged_out=true;wn.call({method:'logout',callback:function(r){if(r.exc){console.log(r.exc);}
$(document).trigger('app_ready');},load_bootinfo:function(){if(wn.boot){LocalDB.sync(wn.boot.docs);wn.control_panel=wn.boot.control_panel;this.set_globals();if(wn.boot.developer_mode){(console.warn||console.log)("LocalStorage is OFF for developer mode. Please build before going live.");}}else{this.set_as_guest();}},set_globals:function(){profile=wn.boot.profile;user=wn.boot.profile.name;user_fullname=wn.user_info(user).fullname;user_defaults=profile.defaults;user_roles=profile.roles;user_email=profile.email;sys_defaults=wn.boot.sysdefaults;},set_as_guest:function(){profile={name:'Guest'};user='Guest';user_fullname='Guest';user_defaults={};user_roles=['Guest'];user_email='';sys_defaults={};},make_page_container:function(){wn.container=new wn.views.Container();wn.views.make_403();wn.views.make_404();},make_nav_bar:function(){if(wn.boot){wn.container.wntoolbar=new wn.ui.toolbar.Toolbar();}},logout:function(){var me=this;me.logged_out=true;wn.call({method:'logout',callback:function(r){if(r.exc){console.log(r.exc);}
me.redirect_to_login();}})},redirect_to_login:function(){window.location.href='index.html';},set_favicon:function(){var link=$('link[type="image/x-icon"]').remove().attr("href");var favicon='\
<link rel="shortcut icon" href="'+link+'" type="image/x-icon"> \
<link rel="icon" href="'+link+'" type="image/x-icon">'
@ -712,7 +712,7 @@ wn.provide('wn.modules');$.extend(wn.modules,erpnext.modules);wn.modules['Core']
erpnext.startup.start=function(){console.log('Starting up...');$('#startup_div').html('Starting up...').toggle(true);erpnext.startup.set_globals();if(user!='Guest'){if(wn.boot.user_background){erpnext.set_user_background(wn.boot.user_background);}
wn.boot.profile.allow_modules=wn.boot.profile.allow_modules.concat(['To Do','Knowledge Base','Calendar','Activity','Messages'])
erpnext.toolbar.setup();erpnext.startup.set_periodic_updates();$('footer').html('<div class="web-footer erpnext-footer">\
<a href="#!attributions">ERPNext | Attributions and License</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("js/complete_setup.js");erpnext.complete_setup.show();}
<a href="#!attributions">ERPNext | Attributions and License</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("js/app/complete_setup.js");erpnext.complete_setup.show();}
if(wn.boot.expires_on&&in_list(user_roles,'System Manager')){var today=dateutil.str_to_obj(dateutil.get_today());var expires_on=dateutil.str_to_obj(wn.boot.expires_on);var diff=dateutil.get_diff(expires_on,today);if(0<=diff&&diff<=15){var expiry_string=diff==0?"today":repl("in %(diff)s day(s)",{diff:diff});$('header').append(repl('<div class="expiry-info"> \
Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
Please renew your subscription to continue using ERPNext \

View File

@ -0,0 +1,259 @@
// 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.AccountTreeGrid = wn.views.GridReport.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"]
});
},
setup_columns: function() {
this.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,
formatter: this.currency_formatter},
{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100,
formatter: this.currency_formatter},
{id: "debit", name: "Debit", field: "debit", width: 100,
formatter: this.currency_formatter},
{id: "credit", name: "Credit", field: "credit", width: 100,
formatter: this.currency_formatter},
{id: "closing_debit", name: "Closing (Dr)", field: "closing_debit", width: 100,
formatter: this.currency_formatter},
{id: "closing_credit", name: "Closing (Cr)", field: "closing_credit", width: 100,
formatter: this.currency_formatter}
];
},
filters: [
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
return item.company == val || val == opts.default_value || item._show;
}},
{fieldtype:"Select", label: "Fiscal Year", link:"Fiscal Year",
default_value: "Select Fiscal Year..."},
{fieldtype:"Date", label: "From Date"},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date"},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"}
],
setup_filters: function() {
this._super();
var me = this;
// default filters
this.filter_inputs.fiscal_year.change(function() {
var fy = $(this).val();
$.each(wn.report_dump.data["Fiscal Year"], function(i, v) {
if (v.name==fy) {
me.filter_inputs.from_date.val(dateutil.str_to_user(v.year_start_date));
me.filter_inputs.to_date.val(dateutil.str_to_user(v.year_end_date));
}
});
me.set_route();
});
},
init_filter_values: function() {
this.filter_inputs.company.val(sys_defaults.company);
this.filter_inputs.fiscal_year.val(sys_defaults.fiscal_year);
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));
},
prepare_data: function() {
var me = this;
var data = [];
var parent_map = {};
var data_by_name = {};
$.each(wn.report_dump.data["Account"], function(i, v) {
var d = copy_dict(v);
me.init_account(d);
data.push(d);
data_by_name[d.name] = d;
if(d.parent_account) {
parent_map[d.name] = d.parent_account;
}
});
this.set_indent(data, parent_map);
this.accounts = data;
this.parent_map = parent_map;
this.accounts_by_name = data_by_name;
this.prepare_balances();
this.prepare_data_view(this.accounts);
},
init_account: function(d) {
$.extend(d, {
"opening_debit": 0,
"opening_credit": 0,
"debit": 0,
"credit": 0,
"closing_debit": 0,
"closing_credit": 0
});
},
prepare_balances: function() {
var gl = wn.report_dump.data['GL Entry'];
var me = this;
this.opening_date = dateutil.user_to_obj(this.filter_inputs.from_date.val());
this.closing_date = dateutil.user_to_obj(this.filter_inputs.to_date.val());
this.set_fiscal_year();
if (!this.fiscal_year) return;
$.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) {
var posting_date = dateutil.str_to_obj(v.posting_date);
var account = me.accounts_by_name[v.account];
me.update_balances(account, posting_date, v)
});
this.update_groups();
},
update_balances: function(account, posting_date, v) {
// opening
if (posting_date < this.opening_date || v.is_opening === "Yes") {
if (account.is_pl_account === "Yes" &&
posting_date <= dateutil.str_to_obj(this.fiscal_year[1])) {
// balance of previous fiscal_year should
// not be part of opening of pl account balance
} else {
if(account.debit_or_credit=='Debit') {
account.opening_debit += (v.debit - v.credit);
} else {
account.opening_credit += (v.credit - v.debit);
}
}
} else if (this.opening_date <= posting_date && posting_date <= this.closing_date) {
// in between
account.debit += v.debit;
account.credit += v.credit;
}
// closing
if(account.debit_or_credit=='Debit') {
account.closing_debit = account.opening_debit + account.debit - account.credit;
} else {
account.closing_credit = account.opening_credit - account.debit + account.credit;
}
},
update_groups: function() {
// update groups
var me= this;
$.each(this.accounts, function(i, account) {
// update groups
var parent = me.parent_map[account.name];
while(parent) {
parent_account = me.accounts_by_name[parent];
$.each(me.columns, function(c, col) {
if (col.formatter == me.currency_formatter) {
parent_account[col.field] += account[col.field];
}
});
parent = me.parent_map[parent];
}
});
},
set_fiscal_year: function() {
if (this.opening_date > this.closing_date) {
msgprint("Opening Date should be before Closing Date");
return;
}
this.fiscal_year = null;
var me = this;
$.each(wn.report_dump.data["Fiscal Year"], function(i, v) {
if (me.opening_date >= dateutil.str_to_obj(v.year_start_date) &&
me.closing_date <= dateutil.str_to_obj(v.year_end_date)) {
me.fiscal_year = v;
}
});
if (!this.fiscal_year) {
msgprint("Opening Date and Closing Date should be within same Fiscal Year");
return;
}
},
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;
});
},
account_formatter: function (row, cell, value, columnDef, dataContext) {
value = value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var data = wn.cur_grid_report.accounts;
var spacer = "<span style='display:inline-block;height:1px;width:" +
(15 * dataContext["indent"]) + "px'></span>";
var idx = wn.cur_grid_report.dataView.getIdxById(dataContext.id);
var account_link = repl('<a href="#general-ledger/account=%(enc_value)s">%(value)s</a>', {
value: value,
enc_value: encodeURIComponent(value)
});
if (data[idx + 1] && data[idx + 1].indent > data[idx].indent) {
if (dataContext._collapsed) {
return spacer + " <span class='toggle expand'></span>&nbsp;" + account_link;
} else {
return spacer + " <span class='toggle collapse'></span>&nbsp;" + account_link;
}
} else {
return spacer + " <span class='toggle'></span>&nbsp;" + account_link;
}
},
add_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();
}
});
},
custom_dataview_filter: function(item) {
if (item.parent_account) {
var parent = item.parent_account;
while (parent) {
if (wn.cur_grid_report.accounts_by_name[parent]._collapsed) {
return false;
}
parent = wn.cur_grid_report.parent_map[parent];
}
}
return true;
}
});

File diff suppressed because one or more lines are too long

View File

@ -1,10 +0,0 @@
/*
* erpnext/projects/gantt_task.js
*/
wn.require('js/lib/jQuery.Gantt/css/style.css');wn.require('js/lib/jQuery.Gantt/js/jquery.fn.gantt.min.js');erpnext.show_task_gantt=function(parent,project){$(parent).css('min-height','300px').html('<div class="help-box">Loading...</div>')
var get_source=function(r){var source=[];$.each(r.message,function(i,v){source.push({name:v.project,desc:v.subject,values:[{label:v.subject,desc:v.description||v.subject,from:'/Date("'+v.exp_start_date+'")/',to:'/Date("'+v.exp_end_date+'")/',customClass:{'Open':'ganttRed','Pending Review':'ganttOrange','Working':'','Completed':'ganttGreen','Cancelled':'ganttGray'}[v.status],dataObj:v}]})});return source}
wn.call({method:'projects.page.projects.projects.get_tasks',args:{project:project||''},callback:function(r){$(parent).empty();if(!r.message.length){$(parent).html('<div class="help-box">No Tasks Yet.</div>');}else{var gantt_area=$('<div class="gantt">').appendTo(parent);gantt_area.gantt({source:get_source(r),navigate:project?"button":"scroll",scale:"weeks",minScale:"weeks",maxScale:"months",onItemClick:function(data){wn.set_route('Form','Task',data.name);},onAddClick:function(dt,rowId){newdoc('Task');}});}
$('<button class="btn"><i class="icon icon-plus"></i>\
Create a new Task</button>').click(function(){wn.model.with_doctype('Task',function(){var new_name=LocalDB.create('Task');if(project)
locals.Task[new_name].project=project;wn.set_route('Form','Task',new_name);});}).appendTo(parent);}})}

View File

@ -1,30 +0,0 @@
/*
* erpnext/utilities/page/kb_common/kb_common.js
*/
KBItemToolbar=function(args,kb){$.extend(this,args);var me=this;this.make=function(){this.wrapper=$a(this.parent,'div','',{});this.line1=$a(this.wrapper,'div','',{color:'#888',fontSize:'11px',margin:'7px 0px'});this.make_timestamp();this.make_answers();if(this.with_tags)
this.make_tags();this.setup_del();}
this.make_timestamp=function(){this.line1.innerHTML=repl('By %(name)s | %(when)s',{name:wn.utils.full_name(this.det.first_name,this.det.last_name),when:wn.datetime.comment_when(this.det.modified)});if(has_common(user_roles,['Administrator','System Manager'])){this.line1.innerHTML+=' | <a style="cursor:pointer;"\
class="del-link">delete</a>';}}
this.make_answers=function(){if(this.doctype=='Question'){if(this.det.answers==0){this.line1.innerHTML+=' | no answers';}else if(this.det.answers==1){this.line1.innerHTML+=' | 1 answer';}else{this.line1.innerHTML+=' | '+this.det.answers+' answers';}}}
this.make_tags=function(){this.line1.innerHTML+=' | '
this.tags_area=$a(this.line1,'span','kb-tags')
this.tags=new TagList(this.tags_area,this.det._user_tags&&(this.det._user_tags.split(',')),this.doctype,this.det.name,0,kb.set_tag_filter)}
this.setup_del=function(){$(this.line1).find('.del-link').click(function(){console.log(1);this.innerHTML='deleting...';this.disabled=1;$c_page('utilities','questions','delete',{dt:me.doctype,dn:me.det.name},function(r,rt){kb.list.run()});});}
this.make();}
EditableText=function(args){$.extend(this,args);var me=this;me.$w=$(repl('<div class="ed-text">\
<div class="ed-text-display %(disp_class)s"></div>\
<a class="ed-text-edit" style="cursor: pointer; float: right; margin-top: -16px;">[edit]</a>\
<textarea class="ed-text-input %(inp_class)s hide"></textarea>\
<div class="help hide"><br>Formatted as <a href="#markdown-reference"\
target="_blank">markdown</a></div>\
<button class="btn btn-small btn-info hide ed-text-save">Save</button>\
<a class="ed-text-cancel hide" style="cursor: pointer;">Cancel</a>\
</div>',args)).appendTo(me.parent);this.set_display=function(txt){me.$w.find('.ed-text-display').html(wn.markdown(txt));me.text=txt;}
this.set_display(me.text);if(me.height)me.$w.find('.ed-text-input').css('height',me.height);me.$w.find('.ed-text-edit').click(function(){me.$w.find('.ed-text-input').val(me.text);me.show_as_input();})
me.$w.find('.ed-text-save').click(function(){var v=me.$w.find('.ed-text-input').val();if(!v){msgprint('Please write something!');return;}
var btn=this;$(btn).set_working();$c_page('utilities','question_view','update_item',{dt:me.dt,dn:me.dn,fn:me.fieldname,text:v},function(r){$(btn).done_working();if(r.exc){msgprint(r.exc);return;}
me.set_display(v);me.show_as_text();});})
me.$w.find('.ed-text-cancel').click(function(){me.show_as_text();})
this.show_as_text=function(){me.$w.find('.ed-text-display, .ed-text-edit').toggle(true);me.$w.find('.ed-text-input, .ed-text-save, .ed-text-cancel, .help').toggle(false);}
this.show_as_input=function(){me.$w.find('.ed-text-display, .ed-text-edit').toggle(false);me.$w.find('.ed-text-input, .ed-text-save, .ed-text-cancel, .help').toggle(true);}}

View File

@ -11,13 +11,9 @@ if(!this.opts.hide_refresh){make_btn('Refresh','ui-icon-refresh',function(btn){m
if(this.opts.show_new){make_btn('New ','ui-icon-document',function(){new_doc(me.dt);},1);}
if(this.opts.show_report){make_btn('Report Builder','ui-icon-clipboard',function(){loadreport(me.dt,null,null,null,1);},0);}
if(!this.opts.hide_export){make_btn('Export','ui-icon-circle-arrow-e',function(){me.do_export();});}
if(!this.opts.hide_print){make_btn('Print','ui-icon-print',function(){me.do_print();});}
if(this.opts.show_calc){make_btn('Calc','ui-icon-calculator',function(){me.do_calc();});$dh(me.buttons['Calc'])}
this.loading_img=$a(this.btn_area,'img','',{display:'none',marginBottom:'-2px'});this.loading_img.src='images/lib/ui/button-load.gif';if(!keys(this.buttons).length)
$dh(this.btn_area);}
Listing.prototype.do_print=function(){this.build_query();if(!this.query){alert('No Query!');return;}
args={query:this.query,title:this.head_text,colnames:this.colnames,colwidths:this.colwidths,coltypes:this.coltypes,has_index:(this.no_index?0:1),has_headings:1,check_limit:1,is_simple:1}
wn.require('js/print_query.js');_p.print_query=new _p.PrintQuery();_p.print_query.show_dialog(args);}
Listing.prototype.do_calc=function(){show_calc(this.result_tab,this.colnames,this.coltypes,0)}
Listing.prototype.add_filter=function(label,ftype,options,tname,fname,cond){if(!this.filter_area){alert('[Listing] make() must be called before add_filter');}
var me=this;if(!this.filter_set){var h=$a(this.filter_area,'div','',{fontSize:'14px',fontWeight:'bold',marginBottom:'4px'});h.innerHTML='Filter your search';this.filter_area.div=$a(this.filter_area,'div');this.perm=[[1,1],]

View File

@ -1,41 +0,0 @@
/*
* lib/js/legacy/widgets/print_query.js
*/
_p.PrintQuery=function(){this.args={};}
_p.PrintQuery.prototype.show_dialog=function(args){this.args=args;var me=this;if(!this.dialog){var d=new Dialog(400,300,"Print");d.make_body([['Data','Max rows','Blank to print all rows'],['Data','Rows per page'],['Button','Go'],]);d.widgets['Go'].onclick=function(){d.hide();me.render(cint(d.widgets['Max rows'].value),cint(d.widgets['Rows per page'].value))}
d.onshow=function(){this.widgets['Rows per page'].value='35';this.widgets['Max rows'].value='500';}
this.dialog=d;}
this.dialog.show();}
_p.PrintQuery.prototype.render=function(max_rows,page_len){var me=this;var args=me.args;if(cint(max_rows)!=0)args.query+=' LIMIT 0,'+cint(max_rows);if(!args.query)return;var callback=function(r,rt){if(!r.values){return;}
if(!page_len)page_len=r.values.length;if(r.colnames&&r.colnames.length)
args.colnames=args.has_index?add_lists(['Sr'],r.colnames):r.colnames;if(r.colwidths&&r.colwidths.length)
args.colwidths=args.has_index?add_lists(['25px'],r.colwidths):r.colwidths;if(r.coltypes)
args.coltypes=args.has_index?add_lists(['Data'],r.coltypes):r.coltypes;if(args.coltypes){for(var i in args.coltypes)
if(args.coltypes[i]=='Link')args.coltypes[i]='Data';}
if(args.colwidths){var tw=0;for(var i=0;i<args.colwidths.length;i++)tw+=cint(args.colwidths[i]?args.colwidths[i]:100);for(var i=0;i<args.colwidths.length;i++)args.colwidths[i]=cint(cint(args.colwidths[i]?args.colwidths[i]:100)/tw*100)+'%';}
var has_heading=args.colnames?1:0;if(!args.has_headings)has_heading=0;var tl=[]
for(var st=0;st<r.values.length;st=st+page_len){tl.push(me.build_table(r,st,page_len,has_heading,args.rb))}
var html='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+'<html><head>'
+'<title>'+args.title+'</title>'
+'<style>'+_p.def_print_style_body+_p.def_print_style_other+'</style>'
+'</head><body>'
+(r.header_html?r.header_html:'')
+tl.join('\n<div style="page-break-after: always;"></div>\n')
+(r.footer_html?r.footer_html:'')
+'</body></html>';_p.preview(html);}
var out_args=copy_dict(args);if(args.is_simple){out_args.simple_query=args.query;delete out_args.query;}
if(args.filter_values)
out_args.filter_values=args.filter_values;$c('webnotes.widgets.query_builder.runquery',out_args,callback);}
_p.PrintQuery.prototype.build_table=function(r,start,page_len,has_heading,rb){var div=document.createElement('div');if(!r.page_template){var head=$a(div,'div',null,{fontSize:'20px',fontWeight:'bold',margin:'16px 0px',borderBottom:'1px solid #CCC',paddingBottom:'8px'});head.innerHTML=args.title;}
var m=start+page_len;if(m>r.values.length)m=r.values.length
var t=make_table(div,m+has_heading-start,r.values[0].length+args.has_index,'100%',null);t.className='simpletable';if(args.colwidths)
$y(t,{tableLayout:'fixed'});if(has_heading){for(var i=0;i<args.colnames.length;i++){$td(t,0,i).innerHTML=args.colnames[i].bold();if(args.colwidths&&args.colwidths[i]){$w($td(t,0,i),args.colwidths[i]);}}}
for(var ri=start;ri<m;ri++){if(args.has_index)
$td(t,ri+has_heading-start,0).innerHTML=ri+1;for(var ci=0;ci<r.values[0].length;ci++){if(ri-start==0&&args.colwidths&&args.colwidths[i]){$w($td(t,0,i),args.colwidths[i]);}
var c=$td(t,ri+has_heading-start,ci+args.has_index)
c.div=$a(c,'div','',{whiteSpace:'normal'});$s(c.div,r.values[ri][ci],args.coltypes?args.coltypes[ci+args.has_index]:null);}}
if(r.style){for(var i=0;i<r.style.length;i++){$yt(t,r.style[i][0],r.style[i][1],r.style[i][2]);}}
if(rb&&rb.aftertableprint){rb.aftertableprint(t);}
if(r.page_template)return repl(r.page_template,{table:div.innerHTML});else return div.innerHTML;}

View File

@ -207,7 +207,7 @@ c.style.color=row.style.color;if(row.style.backgroundColor)
c.style.backgroundColor=row.style.backgroundColor;if(row.style.fontWeight)
c.style.fontWeight=row.style.fontWeight;if(row.style.fontSize)
c.style.fontSize=row.style.fontSize;var w=this.get_col_width(ci);if(w)$w(c,w);c.val=val;var me=this;c.div=$a(c,'div','',{width:(cint(w)-7)+'px'});$s(c.div,val,this.coltypes[ci],this.coloptions[ci])}
_r.DataTable.prototype.do_print=function(){this._get_query(true);args={query:this.query,title:this.rep_name?this.rep_name:this.dt,colnames:null,colwidhts:null,coltypes:null,has_index:this.has_index,has_headings:this.has_headings,check_limit:1,is_simple:(this.is_simple?'Yes':''),sc_id:(this.search_criteria?this.search_criteria.name:''),filter_values:docstring(this.filter_vals),};wn.require('js/print_query.js');_p.print_query=new _p.PrintQuery();_p.print_query.show_dialog(args);}
_r.DataTable.prototype.do_print=function(){this._get_query(true);args={query:this.query,title:this.rep_name?this.rep_name:this.dt,colnames:null,colwidhts:null,coltypes:null,has_index:this.has_index,has_headings:this.has_headings,check_limit:1,is_simple:(this.is_simple?'Yes':''),sc_id:(this.search_criteria?this.search_criteria.name:''),filter_values:docstring(this.filter_vals),};_p.print_query=new _p.PrintQuery();_p.print_query.show_dialog(args);}
_r.DataTable.prototype.do_export=function(){this._get_query(true);var me=this;export_query(this.query,function(q){export_csv(q,(me.rep_name?me.rep_name:me.dt),(me.search_criteria?me.search_criteria.name:''),me.is_simple,docstring(me.filter_vals));});}
_r.DataTable.prototype.do_calc=function(){_r.show_calc(this.tab,this.colnames,this.coltypes,1);}
_r.DataTable.prototype.get_col_data=function(colname){var ci=0;if(!this.htab)return[];for(var i=1;i<this.htab.rows[0].cells.length;i++){var hc=this.htab.rows[0].cells[i];if(hc.val==colname){ci=i;break;}}
@ -233,4 +233,44 @@ cl.push(_r.calc_dialog.colnames[i]);}
if(!cl.length){this.hide();alert("No Numeric Column");return;}
var s=this.widgets['Column'];empty_select(s);add_sel_options(s,cl);if(s.inp)s.inp.value=cl[0];else s.value=cl[0];this.set_calc();}
_r.calc_dialog=d;}
_r.calc_dialog.datatab=tab;_r.calc_dialog.colnames=colnames;_r.calc_dialog.coltypes=coltypes;_r.calc_dialog.show();}
_r.calc_dialog.datatab=tab;_r.calc_dialog.colnames=colnames;_r.calc_dialog.coltypes=coltypes;_r.calc_dialog.show();}
/*
* lib/js/legacy/widgets/print_query.js
*/
_p.PrintQuery=function(){this.args={};}
_p.PrintQuery.prototype.show_dialog=function(args){this.args=args;var me=this;if(!this.dialog){var d=new Dialog(400,300,"Print");d.make_body([['Data','Max rows','Blank to print all rows'],['Data','Rows per page'],['Button','Go'],]);d.widgets['Go'].onclick=function(){d.hide();me.render(cint(d.widgets['Max rows'].value),cint(d.widgets['Rows per page'].value))}
d.onshow=function(){this.widgets['Rows per page'].value='35';this.widgets['Max rows'].value='500';}
this.dialog=d;}
this.dialog.show();}
_p.PrintQuery.prototype.render=function(max_rows,page_len){var me=this;var args=me.args;if(cint(max_rows)!=0)args.query+=' LIMIT 0,'+cint(max_rows);if(!args.query)return;var callback=function(r,rt){if(!r.values){return;}
if(!page_len)page_len=r.values.length;if(r.colnames&&r.colnames.length)
args.colnames=args.has_index?add_lists(['Sr'],r.colnames):r.colnames;if(r.colwidths&&r.colwidths.length)
args.colwidths=args.has_index?add_lists(['25px'],r.colwidths):r.colwidths;if(r.coltypes)
args.coltypes=args.has_index?add_lists(['Data'],r.coltypes):r.coltypes;if(args.coltypes){for(var i in args.coltypes)
if(args.coltypes[i]=='Link')args.coltypes[i]='Data';}
if(args.colwidths){var tw=0;for(var i=0;i<args.colwidths.length;i++)tw+=cint(args.colwidths[i]?args.colwidths[i]:100);for(var i=0;i<args.colwidths.length;i++)args.colwidths[i]=cint(cint(args.colwidths[i]?args.colwidths[i]:100)/tw*100)+'%';}
var has_heading=args.colnames?1:0;if(!args.has_headings)has_heading=0;var tl=[]
for(var st=0;st<r.values.length;st=st+page_len){tl.push(me.build_table(r,st,page_len,has_heading,args.rb))}
var html='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+'<html><head>'
+'<title>'+args.title+'</title>'
+'<style>'+_p.def_print_style_body+_p.def_print_style_other+'</style>'
+'</head><body>'
+(r.header_html?r.header_html:'')
+tl.join('\n<div style="page-break-after: always;"></div>\n')
+(r.footer_html?r.footer_html:'')
+'</body></html>';_p.preview(html);}
var out_args=copy_dict(args);if(args.is_simple){out_args.simple_query=args.query;delete out_args.query;}
if(args.filter_values)
out_args.filter_values=args.filter_values;$c('webnotes.widgets.query_builder.runquery',out_args,callback);}
_p.PrintQuery.prototype.build_table=function(r,start,page_len,has_heading,rb){var div=document.createElement('div');if(!r.page_template){var head=$a(div,'div',null,{fontSize:'20px',fontWeight:'bold',margin:'16px 0px',borderBottom:'1px solid #CCC',paddingBottom:'8px'});head.innerHTML=args.title;}
var m=start+page_len;if(m>r.values.length)m=r.values.length
var t=make_table(div,m+has_heading-start,r.values[0].length+args.has_index,'100%',null);t.className='simpletable';if(args.colwidths)
$y(t,{tableLayout:'fixed'});if(has_heading){for(var i=0;i<args.colnames.length;i++){$td(t,0,i).innerHTML=args.colnames[i].bold();if(args.colwidths&&args.colwidths[i]){$w($td(t,0,i),args.colwidths[i]);}}}
for(var ri=start;ri<m;ri++){if(args.has_index)
$td(t,ri+has_heading-start,0).innerHTML=ri+1;for(var ci=0;ci<r.values[0].length;ci++){if(ri-start==0&&args.colwidths&&args.colwidths[i]){$w($td(t,0,i),args.colwidths[i]);}
var c=$td(t,ri+has_heading-start,ci+args.has_index)
c.div=$a(c,'div','',{whiteSpace:'normal'});$s(c.div,r.values[ri][ci],args.coltypes?args.coltypes[ci+args.has_index]:null);}}
if(r.style){for(var i=0;i<r.style.length;i++){$yt(t,r.style[i][0],r.style[i][1],r.style[i][2]);}}
if(rb&&rb.aftertableprint){rb.aftertableprint(t);}
if(r.page_template)return repl(r.page_template,{table:div.innerHTML});else return div.innerHTML;}