Merge branch 'fixes'
diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js
index 7038fe9..d2b0a0e 100644
--- a/accounts/page/accounts_home/accounts_home.js
+++ b/accounts/page/accounts_home/accounts_home.js
@@ -212,6 +212,11 @@
 				route: "query-report/Payment Collection With Ageing",
 				doctype: "Journal Voucher"
 			},
+			{
+				"label":wn._("Payment Made With Ageing"),
+				route: "query-report/Payment Made With Ageing",
+				doctype: "Journal Voucher"
+			},
 		]
 	}
 ]
diff --git a/accounts/report/accounts_payable/accounts_payable.py b/accounts/report/accounts_payable/accounts_payable.py
index 4e9b2c8..71aeb35 100644
--- a/accounts/report/accounts_payable/accounts_payable.py
+++ b/accounts/report/accounts_payable/accounts_payable.py
@@ -1,6 +1,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import getdate, nowdate, flt, cstr
+from webnotes import msgprint, _
 from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
 
 def execute(filters=None):
@@ -79,13 +80,16 @@
 	supplier_accounts = []
 	if filters.get("account"):
 		supplier_accounts = [filters["account"]]
-	elif filters.get("company"):
+	else:
 		supplier_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
 			where ifnull(master_type, '') = 'Supplier' and docstatus < 2 %s""" % 
 			conditions, filters)
 	
 	if supplier_accounts:
 		conditions += " and account in (%s)" % (", ".join(['%s']*len(supplier_accounts)))
+	else:
+		msgprint(_("No Supplier Accounts found. Supplier Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
 		
 	if filters.get("report_date"):
 		if before_report_date:
diff --git a/accounts/report/accounts_receivable/accounts_receivable.py b/accounts/report/accounts_receivable/accounts_receivable.py
index 47908c3..d791fad 100644
--- a/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/accounts/report/accounts_receivable/accounts_receivable.py
@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 import webnotes
+from webnotes import msgprint, _
 from webnotes.utils import getdate, nowdate, flt, cstr
 
 def execute(filters=None):
@@ -68,13 +69,16 @@
 	customer_accounts = []
 	if filters.get("account"):
 		customer_accounts = [filters["account"]]
-	elif filters.get("company"):
+	else:
 		customer_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
 			where ifnull(master_type, '') = 'Customer' and docstatus < 2 %s""" % 
 			conditions, filters)
 	
 	if customer_accounts:
 		conditions += " and account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
+	else:
+		msgprint(_("No Customer Accounts found. Customer Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
 		
 	if filters.get("report_date"):
 		if upto_report_date:
diff --git a/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py
index 50f74e0..1268852 100644
--- a/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py
+++ b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py
@@ -16,6 +16,7 @@
 
 from __future__ import unicode_literals
 import webnotes
+from webnotes import msgprint, _
 from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
 
 def execute(filters=None):
@@ -55,13 +56,16 @@
 	customer_accounts = []
 	if filters.get("account"):
 		customer_accounts = [filters["account"]]
-	elif filters.get("company"):
+	else:
+		cond = filters.get("company") and (" and company = '%s'" % filters["company"]) or ""
 		customer_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
-			where ifnull(master_type, '') = 'Customer' and docstatus < 2 
-			and company = %s""", filters["company"])
+			where ifnull(master_type, '') = 'Customer' and docstatus < 2 %s""" % cond)
 	
 	if customer_accounts:
 		conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
+	else:
+		msgprint(_("No Customer Accounts found. Customer Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
 		
 	if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
 	if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
diff --git a/accounts/report/payment_made_with_ageing/__init__.py b/accounts/report/payment_made_with_ageing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/__init__.py
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js
new file mode 100644
index 0000000..533fe61
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js
@@ -0,0 +1,40 @@
+wn.query_reports["Payment Made With Ageing"] = {
+	"filters": [
+		{
+			fieldname: "from_date",
+			label: "From Date",
+			fieldtype: "Date",
+			default: wn.defaults.get_user_default("year_start_date"),
+		},
+		{
+			fieldname:"to_date",
+			label: "To Date",
+			fieldtype: "Date",
+			default: get_today()
+		},
+		{
+			fieldname:"account",
+			label: "Supplier Account",
+			fieldtype: "Link",
+			options: "Account",
+			get_query: function() {
+				return {
+					query: "accounts.utils.get_account_list", 
+					filters: {
+						is_pl_account: "No",
+						debit_or_credit: "Credit",
+						company: wn.query_report.filters_by_name.company.get_value(),
+						master_type: "Supplier"
+					}
+				}
+			}
+		},
+		{
+			fieldname:"company",
+			label: "Company",
+			fieldtype: "Link",
+			options: "Company",
+			default: sys_defaults.company
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py
new file mode 100644
index 0000000..e7f13ef
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py
@@ -0,0 +1,89 @@
+# 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/>.
+
+from __future__ import unicode_literals
+import webnotes
+from webnotes import msgprint, _
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	entries = get_entries(filters)
+	pi_posting_date_map = get_pi_posting_date_map()
+	
+	data = []
+	for d in entries:
+		against_voucher_date = d.against_voucher and pi_posting_date_map[d.against_voucher] or ""
+		
+		row = [d.name, d.account, d.posting_date, d.against_voucher, against_voucher_date, 
+			d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
+			
+		if d.against_voucher:
+			row += get_ageing_data(against_voucher_date, d.posting_date, d.debit or -1*d.credit)
+		else:
+			row += ["", "", "", "", ""]
+			
+		data.append(row)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Against Invoice:Link/Purchase Invoice:130", 
+		"Against Invoice Posting Date:Date:130", "Debit:Currency:120", "Credit:Currency:120", 
+		"Reference No::100", "Reference Date:Date:100", "Remarks::150", "Age:Int:40", 
+		"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	supplier_accounts = []
+	if filters.get("account"):
+		supplier_accounts = [filters["account"]]
+	else:
+		cond = filters.get("company") and (" and company = '%s'" % filters["company"]) or ""
+		supplier_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
+			where ifnull(master_type, '') = 'Supplier' and docstatus < 2 %s""" % cond)
+	
+	if supplier_accounts:
+		conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(supplier_accounts)))
+	else:
+		msgprint(_("No Supplier Accounts found. Supplier Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
+	if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
+
+	return conditions, supplier_accounts
+	
+def get_entries(filters):
+	conditions, supplier_accounts = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jvd.against_voucher, jvd.debit, jvd.credit, jv.cheque_no, jv.cheque_date, jv.remark
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" % 
+		(conditions), tuple(supplier_accounts), as_dict=1)
+		
+	return entries
+	
+def get_pi_posting_date_map():
+	pi_posting_date_map = {}
+	for t in webnotes.conn.sql("""select name, posting_date from `tabPurchase Invoice`"""):
+		pi_posting_date_map[t[0]] = t[1]
+		
+	return pi_posting_date_map
\ No newline at end of file
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt
new file mode 100644
index 0000000..c5c85da
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-05-02 12:10:21", 
+  "docstatus": 0, 
+  "modified": "2013-05-02 12:10:21", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 1, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Payment Made With Ageing", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Payment Made With Ageing"
+ }
+]
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_googledrive.py b/setup/doctype/backup_manager/backup_googledrive.py
index a705f0e..533b37d 100644
--- a/setup/doctype/backup_manager/backup_googledrive.py
+++ b/setup/doctype/backup_manager/backup_googledrive.py
@@ -92,8 +92,7 @@
 			mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
 		
 		#Compare Local File with Server File
-		param = {}
-	  	children = drive_service.children().list(folderId=files_folder_id, **param).execute()
+	  	children = drive_service.children().list(folderId=files_folder_id).execute()
 	  	for child in children.get('items', []):
 			file = drive_service.files().get(fileId=child['id']).execute()
 			if filename == file['title'] and size == int(file['fileSize']):
diff --git a/setup/doctype/backup_manager/backup_manager.js b/setup/doctype/backup_manager/backup_manager.js
index 8d2d8de..c78be3a 100644
--- a/setup/doctype/backup_manager/backup_manager.js
+++ b/setup/doctype/backup_manager/backup_manager.js
@@ -1,67 +1,90 @@
-cur_frm.cscript.refresh = function(doc) {
-	cur_frm.disable_save();
-}
-
-//dropbox
-cur_frm.cscript.allow_dropbox_access = function(doc) {
-	if (doc.send_notifications_to == '') {
-		msgprint("Please enter email address.")
-	}
-	else {
-		wn.call({
-			method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url",
-			callback: function(r) {
-				if(!r.exc) {
-					cur_frm.set_value("dropbox_access_secret", r.message.secret);
-					cur_frm.set_value("dropbox_access_key", r.message.key);
-					cur_frm.save(null, function() {
-						window.open(r.message.url);
-					});
-				}
+$.extend(cur_frm.cscript, {
+	refresh: function() {
+		cur_frm.disable_save();
+		
+		if(!(cint(cur_frm.doc.dropbox_access_allowed) || 
+			cint(cur_frm.doc.gdrive_access_allowed))) {
+				cur_frm.set_intro(wn._("You can start by selecting backup frequency and \
+					granting access for sync"));
+		} else {
+			var services = {
+				"dropbox": wn._("Dropbox"),
+				"gdrive": wn._("Google Drive")
 			}
-		})
-	}
-}
-
-cur_frm.cscript.backup_right_now = function(doc) {
-	msgprint("Backing up and uploading. This may take a few minutes.")
-	wn.call({
-		method: "setup.doctype.backup_manager.backup_manager.take_backups_dropbox",
-		callback: function(r) {
-			msgprint("Backups taken. Please check your email for the response.")
+			var active_services = [];
+			
+			$.each(services, function(service, label) {
+				var access_allowed = cint(cur_frm.doc[service + "_access_allowed"]);
+				var frequency = cur_frm.doc["upload_backups_to_" + service];
+				if(access_allowed && frequency && frequency !== "Never") {
+					active_services.push(label + " [" + frequency + "]");
+				}
+			});
+			
+			if(active_services.length > 0) {
+				cur_frm.set_intro(wn._("Backups will be uploaded to") + ": " + 
+					wn.utils.comma_and(active_services));
+			} else {
+				cur_frm.set_intro("");
+			}
 		}
-	})
-}
-//gdrive
-cur_frm.cscript.allow_gdrive_access = function(doc) {
-	if (doc.send_notifications_to == '') {
-		msgprint("Please enter email address.")
-	}
-	else {
-		wn.call({
-			method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
-			callback: function(r) {
-				if(!r.exc) {
-					window.open(r.message.authorize_url);
+		
+	},
+	
+	validate_send_notifications_to: function() {
+		if(!cur_frm.doc.send_notifications_to) {
+			msgprint(wn._("Please specify") + ": " + 
+				wn._(wn.meta.get_label(cur_frm.doctype, "send_notifications_to")));
+			return false;
+		}
+		
+		return true;
+	},
+	
+	allow_dropbox_access: function() {
+		if(cur_frm.cscript.validate_send_notifications_to()) {
+			wn.call({
+				method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url",
+				callback: function(r) {
+					if(!r.exc) {
+						cur_frm.set_value("dropbox_access_secret", r.message.secret);
+						cur_frm.set_value("dropbox_access_key", r.message.key);
+						cur_frm.save(null, function() {
+							window.open(r.message.url);
+						});
+					}
 				}
-			}
-		})
-	}
-}
-
-cur_frm.cscript.validate_gdrive = function(doc) {
-	wn.call({
-		method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
-		args: {
-			verification_code: doc.verification_code
-		},
-	});
-}
-
-cur_frm.cscript.upload_backups_to_dropbox = function(doc) {
-	cur_frm.save()
-}
-
-cur_frm.cscript.upload_backups_to_gdrive = function(doc) {
-	cur_frm.save()
-}
+			});
+		}
+	},
+	
+	allow_gdrive_access: function() {
+		if(cur_frm.cscript.validate_send_notifications_to()) {
+			wn.call({
+				method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
+				callback: function(r) {
+					if(!r.exc) {
+						window.open(r.message.authorize_url);
+					}
+				}
+			});
+		}
+	},
+	
+	validate_gdrive: function() {
+		wn.call({
+			method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
+			args: {
+				verification_code: cur_frm.doc.verification_code
+			},
+		});
+	},
+	
+	upload_backups_to_dropbox: function() {
+		cur_frm.save();
+	},
+	
+	upload_backups_to_gdrive: function() {
+		cur_frm.save();
+	},
+});
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_manager.py b/setup/doctype/backup_manager/backup_manager.py
index a8ecd63..c91cf11 100644
--- a/setup/doctype/backup_manager/backup_manager.py
+++ b/setup/doctype/backup_manager/backup_manager.py
@@ -20,8 +20,8 @@
 	if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
 		take_backups_dropbox()
 		
-	if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
-		take_backups_gdrive()
+	# if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
+	# 	take_backups_gdrive()
 	
 @webnotes.whitelist()
 def take_backups_dropbox():
@@ -35,7 +35,7 @@
 	except Exception:
 		file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
 		error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
-		print error_message
+		webnotes.errprint(error_message)
 		send_email(False, "Dropbox", error_message)
 
 #backup to gdrive 
@@ -51,7 +51,7 @@
 	except Exception:
 		file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
 		error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
-		print error_message
+		webnotes.errprint(error_message)
 		send_email(False, "Google Drive", error_message)
 
 def send_email(success, service_name, error_status=None):
diff --git a/setup/doctype/backup_manager/backup_manager.txt b/setup/doctype/backup_manager/backup_manager.txt
index 9a43f34..2d6f191 100644
--- a/setup/doctype/backup_manager/backup_manager.txt
+++ b/setup/doctype/backup_manager/backup_manager.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-15 11:06:59", 
+  "creation": "2013-04-30 12:58:38", 
   "docstatus": 0, 
-  "modified": "2013-03-15 17:27:33", 
+  "modified": "2013-05-02 11:42:08", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -109,6 +109,7 @@
   "doctype": "DocField", 
   "fieldname": "sync_with_gdrive", 
   "fieldtype": "Section Break", 
+  "hidden": 1, 
   "label": "Sync with Google Drive"
  }, 
  {