Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py
index 521712b..66d22f0 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.py
+++ b/erpnext/accounts/doctype/cost_center/cost_center.py
@@ -18,51 +18,57 @@
 
 
 class DocType:
-  def __init__(self,d,dl):
-    self.doc, self.doclist = d,dl
-    self.nsm_parent_field = 'parent_cost_center'
-        
-  def autoname(self):
-    #company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
-    self.doc.name = self.doc.cost_center_name + ' - ' + self.doc.company_abbr    
-      
-  def get_abbr(self):
-    abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or ''
-    ret = {
-      'company_abbr'  : abbr
-    }
-    return ret
+	def __init__(self,d,dl):
+		self.doc, self.doclist = d,dl
+		self.nsm_parent_field = 'parent_cost_center'
+				
+	def autoname(self):
+		self.doc.name = self.doc.cost_center_name + ' - ' + self.doc.company_abbr		
+			
+	#-------------------------------------------------------------------------
+	def get_abbr(self):
+		abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or ''
+		ret = {
+			'company_abbr'	: abbr
+		}
+		return ret
 
-  def validate(self): 
-    # Cost Center name must be unique
-    # ---------------------------
-    if (self.doc.__islocal or (not self.doc.name)) and sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
-      msgprint("Cost Center Name already exists, please rename")
-      raise Exception
-      
-    check_acc_list = []
-    for d in getlist(self.doclist, 'budget_details'):
-      if [d.account, d.fiscal_year] in check_acc_list:
-        msgprint("Account " + cstr(d.account) + "has been entered more than once for fiscal year " + cstr(d.fiscal_year))
-        raise Exception
-      if [d.account, d.fiscal_year] not in check_acc_list: check_acc_list.append([d.account, d.fiscal_year])
-      
-  def on_update(self):
-    # update Node Set Model
-    import webnotes
-    import webnotes.utils.nestedset
-    # update Node Set Model
-    webnotes.utils.nestedset.update_nsm(self)  
-    
-  def check_if_child_exists(self):
-    return sql("select name from `tabCost Center` where parent_cost_center = %s and docstatus != 2", self.doc.name, debug=0)
-    
-  # On Trash
-  # --------
-  def on_trash(self):
-    if self.check_if_child_exists():
-      msgprint("Child exists for this cost center. You can not trash this account.", raise_exception=1)      
-      
-    # rebuild tree
-    set(self.doc,'old_parent', '')
-    self.update_nsm_model()
+	#-------------------------------------------------------------------------
+	def validate(self): 
+		"""
+			Cost Center name must be unique
+		"""
+		if (self.doc.__islocal or not self.doc.name) and sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
+			msgprint("Cost Center Name already exists, please rename", raise_exception=1)
+			
+		check_acc_list = []
+		for d in getlist(self.doclist, 'budget_details'):
+			if [d.account, d.fiscal_year] in check_acc_list:
+				msgprint("Account " + cstr(d.account) + "has been entered more than once for fiscal year " + cstr(d.fiscal_year), raise_exception=1)
+			else: 
+				check_acc_list.append([d.account, d.fiscal_year])
+			
+	#-------------------------------------------------------------------------
+	def update_nsm_model(self):
+		"""
+			update Nested Set Model
+		"""
+		import webnotes.utils.nestedset
+		webnotes.utils.nestedset.update_nsm(self)
+			
+	#-------------------------------------------------------------------------
+	def on_update(self):
+		self.update_nsm_model()
+		
+	def check_if_child_exists(self):
+		return sql("select name from `tabCost Center` where parent_cost_center = %s and docstatus != 2", self.doc.name)
+		
+	# On Trash
+	#-------------------------------------------------------------------------
+	def on_trash(self):
+		if self.check_if_child_exists():
+			msgprint("Child exists for this cost center. You can not trash this account.", raise_exception=1)			
+			
+		# rebuild tree
+		set(self.doc,'old_parent', '')
+		self.update_nsm_model()
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.txt b/erpnext/accounts/doctype/cost_center/cost_center.txt
index fab2dd5..7bc5810 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.txt
+++ b/erpnext/accounts/doctype/cost_center/cost_center.txt
@@ -5,18 +5,19 @@
 	{
 		'creation': '2010-08-08 17:08:56',
 		'docstatus': 0,
-		'modified': '2010-12-29 18:18:55',
-		'modified_by': 'umair@iwebnotes.com',
+		'modified': '2011-09-26 18:55:05',
+		'modified_by': 'Administrator',
 		'owner': 'Administrator'
 	},
 
 	# These values are common for all DocType
 	{
-		'_last_update': '1308741898',
+		'_last_update': '1316075905',
 		'allow_copy': 1,
 		'allow_trash': 1,
 		'autoname': 'field:cost_center_name',
 		'colour': 'White:FFF',
+		'default_print_format': 'Standard',
 		'doctype': 'DocType',
 		'document_type': 'Master',
 		'in_create': 1,
@@ -26,7 +27,7 @@
 		'section_style': 'Simple',
 		'server_code_error': ' ',
 		'show_in_menu': 0,
-		'version': 104
+		'version': 107
 	},
 
 	# These values are common for all DocField
@@ -60,7 +61,6 @@
 		'cancel': 0,
 		'create': 0,
 		'doctype': 'DocPerm',
-		'idx': 1,
 		'permlevel': 1,
 		'role': 'Accounts Manager',
 		'submit': 0,
@@ -73,7 +73,6 @@
 		'cancel': 1,
 		'create': 1,
 		'doctype': 'DocPerm',
-		'idx': 2,
 		'permlevel': 0,
 		'role': 'Accounts Manager',
 		'submit': 0,
@@ -86,7 +85,6 @@
 		'cancel': 0,
 		'create': 0,
 		'doctype': 'DocPerm',
-		'idx': 3,
 		'permlevel': 1,
 		'role': 'Accounts User',
 		'submit': 0,
@@ -99,7 +97,6 @@
 		'cancel': 0,
 		'create': 0,
 		'doctype': 'DocPerm',
-		'idx': 4,
 		'permlevel': 0,
 		'role': 'Accounts User',
 		'submit': 0,
@@ -111,7 +108,6 @@
 		'cancel': 1,
 		'create': 1,
 		'doctype': 'DocPerm',
-		'idx': 5,
 		'permlevel': 0,
 		'role': 'System Manager',
 		'write': 1
@@ -120,7 +116,6 @@
 	# DocPerm
 	{
 		'doctype': 'DocPerm',
-		'idx': 6,
 		'permlevel': 1,
 		'role': 'All'
 	},
@@ -130,7 +125,6 @@
 		'doctype': 'DocField',
 		'fieldname': 'trash_reason',
 		'fieldtype': 'Small Text',
-		'idx': 1,
 		'label': 'Trash Reason',
 		'oldfieldname': 'trash_reason',
 		'oldfieldtype': 'Small Text',
@@ -142,7 +136,6 @@
 		'doctype': 'DocField',
 		'fieldname': 'cost_center_name',
 		'fieldtype': 'Data',
-		'idx': 2,
 		'in_filter': 0,
 		'label': 'Cost Center Name',
 		'no_copy': 1,
@@ -159,7 +152,6 @@
 		'doctype': 'DocField',
 		'fieldname': 'parent_cost_center',
 		'fieldtype': 'Link',
-		'idx': 3,
 		'label': 'Parent Cost Center',
 		'oldfieldname': 'parent_cost_center',
 		'oldfieldtype': 'Link',
@@ -175,14 +167,12 @@
 		'doctype': 'DocField',
 		'fieldname': 'company_name',
 		'fieldtype': 'Link',
-		'idx': 4,
 		'label': 'Company',
 		'oldfieldname': 'company_name',
 		'oldfieldtype': 'Link',
 		'options': 'Company',
 		'permlevel': 0,
 		'reqd': 1,
-		'search_index': 0,
 		'trigger': 'Client'
 	},
 
@@ -191,7 +181,6 @@
 		'doctype': 'DocField',
 		'fieldname': 'company_abbr',
 		'fieldtype': 'Data',
-		'idx': 5,
 		'label': 'Company Abbr',
 		'oldfieldname': 'company_abbr',
 		'oldfieldtype': 'Data',
@@ -204,8 +193,7 @@
 		'doctype': 'DocField',
 		'fieldname': 'group_or_ledger',
 		'fieldtype': 'Select',
-		'hidden': 1,
-		'idx': 6,
+		'hidden': 0,
 		'label': 'Group or Ledger',
 		'no_copy': 1,
 		'oldfieldname': 'group_or_ledger',
@@ -223,13 +211,11 @@
 		'doctype': 'DocField',
 		'fieldname': 'distribution_id',
 		'fieldtype': 'Link',
-		'idx': 7,
 		'label': 'Distribution Id',
 		'oldfieldname': 'distribution_id',
 		'oldfieldtype': 'Link',
 		'options': 'Budget Distribution',
-		'permlevel': 0,
-		'search_index': 0
+		'permlevel': 0
 	},
 
 	# DocField
@@ -237,7 +223,6 @@
 		'doctype': 'DocField',
 		'fieldname': 'budget_details',
 		'fieldtype': 'Table',
-		'idx': 8,
 		'label': 'Budget Details',
 		'oldfieldname': 'budget_details',
 		'oldfieldtype': 'Table',
@@ -251,7 +236,6 @@
 		'fieldname': 'lft',
 		'fieldtype': 'Int',
 		'hidden': 1,
-		'idx': 9,
 		'in_filter': 1,
 		'label': 'lft',
 		'no_copy': 1,
@@ -269,7 +253,6 @@
 		'fieldname': 'rgt',
 		'fieldtype': 'Int',
 		'hidden': 1,
-		'idx': 10,
 		'in_filter': 1,
 		'label': 'rgt',
 		'no_copy': 1,
@@ -286,13 +269,13 @@
 	{
 		'doctype': 'DocField',
 		'fieldname': 'old_parent',
-		'fieldtype': 'Data',
+		'fieldtype': 'Link',
 		'hidden': 1,
-		'idx': 11,
 		'label': 'old_parent',
 		'no_copy': 1,
 		'oldfieldname': 'old_parent',
 		'oldfieldtype': 'Data',
+		'options': 'Cost Center',
 		'permlevel': 0,
 		'print_hide': 1,
 		'report_hide': 1
diff --git a/erpnext/accounts/doctype/gl_control/gl_control.py b/erpnext/accounts/doctype/gl_control/gl_control.py
index a346b65..44a9e8d 100644
--- a/erpnext/accounts/doctype/gl_control/gl_control.py
+++ b/erpnext/accounts/doctype/gl_control/gl_control.py
@@ -191,6 +191,7 @@
 			else:
 				self.entries.append(le)
 
+
 	# Save GL Entries
 	# ----------------
 	def save_entries(self, cancel, adv_adj, update_outstanding):
@@ -200,7 +201,6 @@
 				tmp=le.debit
 				le.debit, le.credit = abs(flt(le.credit)), abs(flt(tmp))
 
-
 			le_obj = get_obj(doc=le)
 			# validate except on_cancel
 			if not cancel:
@@ -213,10 +213,12 @@
 			# update total debit / credit
 			self.td += flt(le.debit)
 			self.tc += flt(le.credit)
-
+			
+			
 	# Make Multiple Entries
 	# ---------------------
 	def make_gl_entries(self, doc, doclist, cancel=0, adv_adj = 0, use_mapper='', merge_entries = 1, update_outstanding='Yes'):
+		self.entries = []
 		# get entries
 		le_map_list = sql("select * from `tabGL Mapper Detail` where parent = %s", use_mapper or doc.doctype, as_dict=1)
 		self.td, self.tc = 0.0, 0.0
@@ -329,6 +331,7 @@
 			else:
 				msgprint("Allocation amount cannot be greater than advance amount")
 				raise Exception
+				
 
 	# Add extra row in jv detail for unadjusted amount
 	#--------------------------------------------------
@@ -351,7 +354,7 @@
 		add.against_account = cstr(jvd[0][3])
 		add.is_advance = 'Yes'
 		add.save(1)
-
+		
 	# check if advance entries are still valid
 	# ----------------------------------------
 	def validate_jv_entry(self, d, account_head, dr_or_cr):
@@ -359,15 +362,92 @@
 		# 2. check if amount is same
 		# 3. check if is_advance is 'Yes'
 		# 4. check if jv is submitted
-		ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher = '' or t2.against_voucher is null) and (t2.against_invoice = '' or t2.against_invoice is null) and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % ( dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
+		ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and ifnull(t2.against_voucher, '') = '' and ifnull(t2.against_invoice, '') = '' and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % (dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
 		if (not ret):
 			msgprint("Please click on 'Get Advances Paid' button as the advance entries have been changed.")
 			raise Exception
 		return
 
-##############################################################################
-# Repair Outstanding Amount
-##############################################################################
+
+######################################################################################################################
+
+	#------------------------------------------
+	def reconcile_against_document(self, args):
+		"""
+			Cancel JV, Update aginst document, split if required and resubmit jv
+		"""
+		
+		for d in args:
+			self.check_if_jv_modified(d)
+
+			against_fld = {
+				'Journal Voucher' : 'against_jv',
+				'Receivable Voucher' : 'against_invoice',
+				'Payable Voucher' : 'against_voucher'
+			}
+			
+			d['against_fld'] = against_fld[d['against_voucher_type']]
+
+			# cancel JV
+			jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children=1)
+			self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1)
+
+			# update ref in JV Detail
+			self.update_against_doc(d, jv_obj)
+
+			# re-submit JV
+			jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children =1)
+			self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1)
+
+	#------------------------------------------
+	def update_against_doc(self, d, jv_obj):
+		"""
+			Updates against document, if partial amount splits into rows
+		"""
+
+		sql("""
+			update `tabJournal Voucher Detail` t1, `tabJournal Voucher` t2	
+			set t1.%(dr_or_cr)s = '%(allocated_amt)s', t1.%(against_fld)s = '%(against_voucher)s', t2.modified = now() 
+			where t1.name = '%(voucher_detail_no)s' and t1.parent = t2.name""" % d)
+
+		if d['allocated_amt'] < d['unadjusted_amt']:
+			jvd = sql("select cost_center, balance, against_account, is_advance from `tabJournal Voucher Detail` where name = '%s'" % d['voucher_detail_no'])
+			# new entry with balance amount
+			ch = addchild(jv_obj.doc, 'entries', 'Journal Voucher Detail', 1)
+			ch.account = d['account']
+			ch.cost_center = cstr(jvd[0][0])
+			ch.balance = cstr(jvd[0][1])
+			ch.fields[d['dr_or_cr']] = flt(d['unadjusted_amt']) - flt(d['allocated_amt'])
+			ch.fields[d['dr_or_cr']== 'debit' and 'credit' or 'debit'] = 0
+			ch.against_account = cstr(jvd[0][2])
+			ch.is_advance = cstr(jvd[0][3])
+			ch.docstatus = 1
+			ch.save(1)
+
+	#------------------------------------------
+	def check_if_jv_modified(self, args):
+		"""
+			check if there is already a voucher reference
+			check if amount is same
+			check if jv is submitted
+		"""
+		ret = sql("""
+			select t2.%(dr_or_cr)s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 
+			where t1.name = t2.parent and t2.account = '%(account)s' 
+			and ifnull(t2.against_voucher, '')='' and ifnull(t2.against_invoice, '')='' and ifnull(t2.against_jv, '')=''
+			and t1.name = '%(voucher_no)s' and t2.name = '%(voucher_detail_no)s'
+			and t1.docstatus=1 and t2.%(dr_or_cr)s = %(unadjusted_amt)s
+		""" % (args))
+		
+		if not ret:
+			msgprint("Payment Entry has been modified after you pulled it. Please pull it again.", raise_exception=1)
+		
+######################################################################################################################
+		
+
+
+	# Repair Outstanding Amount
+	#---------------------------------
 	def repair_voucher_outstanding(self, voucher_obj):
 		msg = []
 
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index 5d39760..cbb5b7f 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -35,7 +35,7 @@
 		if not (flt(self.doc.debit) or flt(self.doc.credit)):
 			msgprint("GL Entry: Debit or Credit amount is mandatory for %s" % self.doc.account)
 			raise Exception
-			
+
 		# Debit and credit can not done at the same time
 		if flt(self.doc.credit) != 0 and flt(self.doc.debit) != 0:
 			msgprint("Sorry you cannot credit and debit under same account head.")
@@ -185,7 +185,6 @@
 
 		bal = flt(sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s and ifnull(is_cancelled,'No') = 'No'", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0)
 		tds = 0
-		
 		if self.doc.against_voucher_type=='Payable Voucher':
 			# amount to debit
 			bal = -bal
@@ -200,7 +199,7 @@
 			raise Exception
 			
 		# Update outstanding amt on against voucher
-		sql("update `tab%s` set outstanding_amount=%s where name='%s'"% (self.doc.against_voucher_type,bal,self.doc.against_voucher))
+		sql("update `tab%s` set outstanding_amount=%s where name='%s'" % (self.doc.against_voucher_type, bal, self.doc.against_voucher))
 		
 					
 	# Total outstanding can not be greater than credit limit for any time for any customer
diff --git a/erpnext/accounts/doctype/internal_reconciliation/__init__.py b/erpnext/accounts/doctype/internal_reconciliation/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/internal_reconciliation/__init__.py
diff --git a/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.js b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.js
new file mode 100644
index 0000000..bcd5c44
--- /dev/null
+++ b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.js
@@ -0,0 +1,21 @@
+// Booking Entry Id
+// --------------------
+
+cur_frm.fields_dict.voucher_no.get_query = function(doc) {
+
+	if (!doc.account) msgprint("Please select Account first");
+	else {
+		return repl("select voucher_no, posting_date \
+			from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No'\
+			and account = '%(acc)s' \
+			and voucher_type = '%(dt)s' \
+			and voucher_no LIKE '%s' \
+			ORDER BY posting_date DESC, voucher_no DESC LIMIT 50 \
+		", {dt:session.rev_dt_labels[doc.voucher_type] || doc.voucher_type, acc:doc.account});
+	}
+}
+
+cur_frm.cscript.voucher_no  =function(doc, cdt, cdn) {
+	get_server_fields('get_voucher_details', '', '', doc, cdt, cdn, 1)
+}
+
diff --git a/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.py b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.py
new file mode 100644
index 0000000..7c34546
--- /dev/null
+++ b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.py
@@ -0,0 +1,138 @@
+# Please edit this list and import only required elements
+import webnotes
+
+from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.model import db_exists
+from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
+from webnotes.model.doclist import getlist, copy_doclist
+from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
+from webnotes import session, form, is_testing, msgprint, errprint
+
+set = webnotes.conn.set
+sql = webnotes.conn.sql
+get_value = webnotes.conn.get_value
+in_transaction = webnotes.conn.in_transaction
+convert_to_lists = webnotes.conn.convert_to_lists
+	
+# -----------------------------------------------------------------------------------------
+
+
+class DocType:
+	def __init__(self, doc, doclist):
+		self.doc = doc
+		self.doclist = doclist
+		self.acc_type = self.doc.account and sql("select debit_or_credit from `tabAccount` where name = %s", self.doc.account)[0][0].lower() or ''
+		self.dt = {
+			'Sales Invoice': 'Receivable Voucher',
+			'Purchase Invoice': 'Payable Voucher',
+			'Journal Voucher': 'Journal Voucher'
+		}
+		
+	#--------------------------------------------------
+	def get_voucher_details(self):
+		tot_amt = sql("""
+			select sum(%s) from `tabGL Entry` where 
+			voucher_type = %s and voucher_no = %s 
+			and account = %s and ifnull(is_cancelled, 'No') = 'No'
+		"""% (self.acc_type, '%s', '%s', '%s'), (self.dt[self.doc.voucher_type], self.doc.voucher_no, self.doc.account))
+		
+		outstanding = sql("""
+			select sum(%s) - sum(%s) from `tabGL Entry` where 
+			against_voucher = %s and voucher_no != %s
+			and account = %s and ifnull(is_cancelled, 'No') = 'No'
+		""" % ((self.acc_type == 'debit' and 'credit' or 'debit'), self.acc_type, '%s', '%s', '%s'), (self.doc.voucher_no, self.doc.voucher_no, self.doc.account))
+		
+		ret = {
+			'total_amount': flt(tot_amt[0][0]) or 0,	
+			'pending_amt_to_reconcile': flt(tot_amt[0][0]) - flt(outstanding[0][0]) or 0
+		}
+		
+		return ret
+
+		
+	#--------------------------------------------------
+	def get_payment_entries(self):
+		"""
+			Get payment entries for the account and period
+			Payment entry will be decided based on account type (Dr/Cr)
+		"""
+
+		self.doc.clear_table(self.doclist, 'ir_payment_details')		
+		gle = self.get_gl_entries()
+		self.create_payment_table(gle)
+
+	#--------------------------------------------------
+	def get_gl_entries(self):
+		self.validate_mandatory()
+		dc = self.acc_type == 'debit' and 'credit' or 'debit'
+		
+		cond = self.doc.from_date and " and t1.posting_date >= '" + self.doc.from_date + "'" or ""
+		cond += self.doc.to_date and " and t1.posting_date <= '" + self.doc.to_date + "'"or ""
+		
+		cond += self.doc.amt_greater_than and ' and t2.' + dc+' >= ' + self.doc.amt_greater_than or ''
+		cond += self.doc.amt_less_than and ' and t2.' + dc+' <= ' + self.doc.amt_less_than or ''
+
+		gle = sql("""
+			select t1.name as voucher_no, t1.posting_date, t1.total_debit as total_amt,  sum(ifnull(t2.credit, 0)) - sum(ifnull(t2.debit, 0)) as amt_due, t1.remark, t2.against_account, t2.name as voucher_detail_no
+			from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
+			where t1.name = t2.parent  
+			and t1.docstatus = 1 
+			and t2.account = %s
+			and ifnull(t2.against_voucher, '')='' and ifnull(t2.against_invoice, '')='' and ifnull(t2.against_jv, '')=''
+			and t2.%s > 0
+			%s
+			group by t1.name
+		"""% ('%s', dc, cond), self.doc.account, as_dict=1)
+
+		return gle
+
+	#--------------------------------------------------
+	def create_payment_table(self, gle):
+		for d in gle:
+			ch = addchild(self.doc, 'ir_payment_details', 'IR Payment Detail', 1, self.doclist)
+			ch.voucher_no = d.get('voucher_no')
+			ch.posting_date = d.get('posting_date')
+			ch.amt_due =  self.acc_type == 'debit' and flt(d.get('amt_due')) or -1*flt(d.get('amt_due'))
+			ch.total_amt = flt(d.get('total_amt'))
+			ch.against_account = d.get('against_account')
+			ch.remarks = d.get('remark')
+			ch.amt_to_be_reconciled = flt(ch.amt_due)
+			ch.voucher_detail_no = d.get('voucher_detail_no')
+			
+	#--------------------------------------------------
+	def validate_mandatory(self):
+		if not self.doc.account:
+			msgprint("Please select Account first", raise_exception=1)
+	
+	#--------------------------------------------------	
+	def reconcile(self):
+		"""
+			Links booking and payment voucher
+			1. cancel payment voucher
+			2. split into multiple rows if partially adjusted, assign against voucher
+			3. submit payment voucher
+		"""
+		lst = []
+		for d in getlist(self.doclist, 'ir_payment_details'):
+			if d.selected and flt(d.amt_to_be_reconciled) > 0:
+				args = {
+					'voucher_no' : d.voucher_no,
+					'voucher_detail_no' : d.voucher_detail_no, 
+					'against_voucher_type' : self.dt[self.doc.voucher_type], 
+					'against_voucher'  : self.doc.voucher_no,
+					'account' : self.doc.account, 
+					'is_advance' : 'No', 
+					'dr_or_cr' :  self.acc_type=='debit' and 'credit' or 'debit', 
+					'unadjusted_amt' : flt(d.amt_due),
+					'allocated_amt' : flt(d.amt_to_be_reconciled)
+				}
+			
+				lst.append(args)
+		
+		if not sql("select name from `tab%s` where name = %s" %(self.dt[self.doc.voucher_type], '%s'),  self.doc.voucher_no):
+			msgprint("Please select valid Voucher No to proceed", raise_exception=1)
+		if lst:
+			get_obj('GL Control').reconcile_against_document(lst)
+			msgprint("Successfully reconciled.")
+		else:
+			msgprint("No payment entries selected.", raise_exception=1)
diff --git a/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.txt b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.txt
new file mode 100644
index 0000000..cc1523a
--- /dev/null
+++ b/erpnext/accounts/doctype/internal_reconciliation/internal_reconciliation.txt
@@ -0,0 +1,266 @@
+# DocType, Internal Reconciliation
+[
+
+	# These values are common in all dictionaries
+	{
+		'creation': '2011-08-30 11:45:50',
+		'docstatus': 0,
+		'modified': '2011-09-26 14:21:22',
+		'modified_by': 'Administrator',
+		'owner': 'Administrator'
+	},
+
+	# These values are common for all DocType
+	{
+		'_last_update': '1316509358',
+		'colour': 'White:FFF',
+		'default_print_format': 'Standard',
+		'doctype': 'DocType',
+		'document_type': 'Other',
+		'issingle': 1,
+		'module': 'Accounts',
+		'name': '__common__',
+		'section_style': 'Simple',
+		'show_in_menu': 1,
+		'version': 35
+	},
+
+	# These values are common for all DocField
+	{
+		'doctype': 'DocField',
+		'name': '__common__',
+		'parent': 'Internal Reconciliation',
+		'parentfield': 'fields',
+		'parenttype': 'DocType'
+	},
+
+	# These values are common for all DocPerm
+	{
+		'doctype': 'DocPerm',
+		'name': '__common__',
+		'parent': 'Internal Reconciliation',
+		'parentfield': 'permissions',
+		'parenttype': 'DocType',
+		'read': 1
+	},
+
+	# DocType, Internal Reconciliation
+	{
+		'doctype': 'DocType',
+		'name': 'Internal Reconciliation'
+	},
+
+	# DocPerm
+	{
+		'create': 1,
+		'doctype': 'DocPerm',
+		'permlevel': 0,
+		'role': 'System Manager',
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'create': 1,
+		'doctype': 'DocPerm',
+		'permlevel': 0,
+		'role': 'Accounts Manager',
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'create': 1,
+		'doctype': 'DocPerm',
+		'permlevel': 0,
+		'role': 'Accounts User',
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'doctype': 'DocPerm',
+		'permlevel': 1,
+		'role': 'All'
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Column Break',
+		'permlevel': 0,
+		'width': '50%'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'account',
+		'fieldtype': 'Link',
+		'label': 'Account',
+		'options': 'Account',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'voucher_type',
+		'fieldtype': 'Select',
+		'label': 'Voucher Type',
+		'options': 'Sales Invoice\nPurchase Invoice\nJournal Voucher',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldname': 'voucher_no',
+		'fieldtype': 'Link',
+		'label': 'Voucher No',
+		'permlevel': 0,
+		'trigger': 'Client'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldtype': 'Column Break',
+		'permlevel': 0,
+		'width': '50%'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'total_amount',
+		'fieldtype': 'Currency',
+		'label': 'Total Amount',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'pending_amt_to_reconcile',
+		'fieldtype': 'Currency',
+		'label': 'Pending Amt To Reconcile',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Section Break',
+		'label': 'Payment Entries',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Column Break',
+		'label': "<div class = 'field_description'>Filter payment entries based on date:</div>",
+		'permlevel': 0,
+		'width': '50%'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'from_date',
+		'fieldtype': 'Date',
+		'label': 'From Date',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'to_date',
+		'fieldtype': 'Date',
+		'label': 'To Date',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Column Break',
+		'label': "<div class = 'field_description'>Filter payment entries based on amount:</div>",
+		'permlevel': 0,
+		'width': '50%'
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldname': 'amt_greater_than',
+		'fieldtype': 'Data',
+		'label': 'Amount >=',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'amt_less_than',
+		'fieldtype': 'Data',
+		'label': 'Amount <=',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldtype': 'Section Break',
+		'options': 'Simple',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldtype': 'Button',
+		'label': 'Pull Payment Entries',
+		'options': 'get_payment_entries',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'ir_payment_details',
+		'fieldtype': 'Table',
+		'label': 'Payment Entries',
+		'options': 'IR Payment Detail',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'HTML',
+		'label': 'Reconcile HTML',
+		'options': "<div class='field_description'>Select Payment Voucher and Amount to Reconcile in the above table and then click Reconcile button</div>",
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Button',
+		'label': 'Reconcile',
+		'options': 'reconcile',
+		'permlevel': 0,
+		'trigger': 'Client'
+	}
+]
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/internal_reconciliation/test_ir.py b/erpnext/accounts/doctype/internal_reconciliation/test_ir.py
new file mode 100644
index 0000000..b35af6e
--- /dev/null
+++ b/erpnext/accounts/doctype/internal_reconciliation/test_ir.py
@@ -0,0 +1,169 @@
+import unittest
+import webnotes
+
+from webnotes.model.doc import Document
+from webnotes.model.code import get_obj
+from webnotes.utils import cstr, flt
+sql = webnotes.conn.sql
+
+class TestInternalReco(unittest.TestCase):
+	def setUp(self):
+		webnotes.conn.begin()
+		
+		comp1.save(1)
+		cust1.save(1)
+		bank1.save(1)
+		rv1.save(1)
+		rv_gle.save(1)
+
+
+		for t in jv1: t.save(1)
+		for t in jv1[1:]:
+			sql("update `tabJournal Voucher Detail` set parent = '%s' where name = '%s'" % (jv1[0].name, t.name))
+			
+		ir[0].save()
+		for t in ir[1:]:
+			t.save(1)
+			sql("update `tabIR Payment Detail` set voucher_no = '%s', voucher_detail_no = '%s' where parent = 'Internal Reconciliation'" % (jv1[0].name, jv1[1].name))
+		
+		
+		sql("update `tabGL Entry` set voucher_no = %s, against_voucher = %s where voucher_no = 'rv1'", (rv1.name, rv1.name))
+		sql("update `tabSingles` set value = %s where doctype = 'Internal Reconciliation' and field = 'voucher_no'", rv1.name)
+		
+		
+		self.ir = get_obj('Internal Reconciliation', with_children=1)		
+		self.ir.reconcile()
+		
+	#===========================
+	def test_jv(self):
+		"""
+			Test whether JV has benn properly splitted and against doc has been updated
+		"""
+		amt_against_doc = [[cstr(d[0]), flt(d[1]), flt(d[2])]for d in sql("select against_invoice, debit, credit from `tabJournal Voucher Detail` where parent = %s and account = 'cust1 - c1'", jv1[0].name)]
+		self.assertTrue(amt_against_doc == [[rv1.name, 0, 100.0], ['', 0, 400.0]])
+
+	#============================		
+	def test_gl_entry(self):
+		"""
+			Check proper gl entry has been made
+		"""
+		gle = [[cstr(d[0]), flt(d[1])] for d in sql("select against_voucher, sum(credit) - sum(debit) from `tabGL Entry` where voucher_no = %s and account = 'cust1 - c1' and ifnull(is_cancelled, 'No') = 'No' group by against_voucher", jv1[0].name)]
+
+		self.assertTrue([rv1.name, 100.0] in gle)
+		self.assertTrue(['', 400.0] in gle)
+		
+	#============================
+	def test_outstanding(self):
+		"""
+			Check whether Outstanding amount has been properly updated in RV
+		"""
+		amt = sql("select outstanding_amount from `tabReceivable Voucher` where name = '%s'" % rv1.name)[0][0]
+		self.assertTrue(amt == 0)
+		
+	#============================
+	def tearDown(self):
+		webnotes.conn.rollback()
+	
+
+
+
+# test data
+#---------------
+rv1 = Document(fielddata={
+		'doctype':'Receivable Voucher',
+		'docstatus':1,
+		'debit_to':'cust1 - c1',
+		'grand_total': 100,
+		'outstanding_amount': 100,
+		'name': 'rv1'
+	})
+	
+jv1 = [Document(fielddata={
+		'doctype':'Journal Voucher',
+		'docstatus':1,
+		'cheque_no': '163567',
+		'docstatus':1,
+		'company': 'comp1',
+		'posting_date' : '2011-05-02',
+		'remark': 'test data',
+		'fiscal_year': '2011-2012',
+		'total_debit': 500,
+		'total_credit': 500
+	}),
+	Document(fielddata = {
+		'parenttype':'Journal Voucher',
+		'parentfield':'entries',
+		'doctype':'Journal Voucher Detail',
+		'account' : 'cust1 - c1',
+		'credit':500,
+		'debit' : 0,
+		'docstatus':1
+	}),
+	Document(fielddata = {
+		'parenttype':'Journal Voucher',
+		'parentfield':'entries',
+		'doctype':'Journal Voucher Detail',
+		'account' : 'bank1 - c1',
+		'credit':0,
+		'debit' : 500,
+		'docstatus':1
+	})]
+	
+ir = [Document(fielddata = {
+		'doctype':'Internal Reconciliation',
+		'name' : 'Internal Reconciliation',
+		'account':'cust1 - c1',
+		'voucher_type' : 'Sales Invoice',
+		'voucher_no': 'rv1'
+	}),
+	Document(fielddata = {
+		'parenttype':'Internal Reconciliation',
+		'parentfield':'ir_payment_details',
+		'doctype':'IR Payment Detail',
+		'parent': 'Internal Reconciliation',
+		'voucher_no': 'jv1',
+		'name' : '123112',
+		'voucher_detail_no' : 'jvd1',
+		'selected' : 1,
+		'amt_due' : 500,
+		'amt_to_be_reconciled':100
+	})]
+	
+cust1 = Document(fielddata={
+		'doctype':'Account',
+		'docstatus':0,
+		'account_name' : 'cust1',
+		'debit_or_credit': 'Debit',
+		'company' : 'comp1',
+		'lft': 1,
+		'rgt': 2
+	})
+	
+bank1 = Document(fielddata={
+		'doctype':'Account',
+		'docstatus':0,
+		'account_name' : 'bank1',
+		'debit_or_credit': 'Debit',
+		'company' : 'comp1',
+		'lft': 3,
+		'rgt': 4
+	})	
+	
+comp1 = Document(fielddata={
+		'doctype':'Company',
+		'abbr': 'c1',
+		'company_name' : 'comp1',
+		'name': 'comp1'
+	})
+	
+rv_gle = Document(fielddata={
+		'doctype':'GL Entry',
+		'account': 'cust1 - c1',
+		'company' : 'comp1',
+		'voucher_no': 'rv1',
+		'against_voucher': 'rv1',
+		'against_voucher_type': 'Receivable Voucher',
+		'voucher_type' : 'Receivable Voucher',
+		'debit': 100,
+		'credit': 0
+	})
diff --git a/erpnext/accounts/doctype/ir_payment_detail/__init__.py b/erpnext/accounts/doctype/ir_payment_detail/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/ir_payment_detail/__init__.py
diff --git a/erpnext/accounts/doctype/ir_payment_detail/ir_payment_detail.txt b/erpnext/accounts/doctype/ir_payment_detail/ir_payment_detail.txt
new file mode 100644
index 0000000..b35c497
--- /dev/null
+++ b/erpnext/accounts/doctype/ir_payment_detail/ir_payment_detail.txt
@@ -0,0 +1,132 @@
+# DocType, IR Payment Detail
+[
+
+	# These values are common in all dictionaries
+	{
+		'creation': '2011-08-30 11:57:48',
+		'docstatus': 0,
+		'modified': '2011-09-20 15:18:02',
+		'modified_by': 'Administrator',
+		'owner': 'Administrator'
+	},
+
+	# These values are common for all DocType
+	{
+		'colour': 'White:FFF',
+		'default_print_format': 'Standard',
+		'doctype': 'DocType',
+		'istable': 1,
+		'module': 'Accounts',
+		'name': '__common__',
+		'section_style': 'Simple',
+		'show_in_menu': 0,
+		'version': 14
+	},
+
+	# These values are common for all DocField
+	{
+		'doctype': 'DocField',
+		'name': '__common__',
+		'parent': 'IR Payment Detail',
+		'parentfield': 'fields',
+		'parenttype': 'DocType'
+	},
+
+	# DocType, IR Payment Detail
+	{
+		'doctype': 'DocType',
+		'name': 'IR Payment Detail'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'selected',
+		'fieldtype': 'Check',
+		'label': 'Select',
+		'permlevel': 0,
+		'reqd': 1,
+		'width': '60px'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'voucher_no',
+		'fieldtype': 'Link',
+		'label': 'Voucher No',
+		'options': 'Journal Voucher',
+		'permlevel': 1,
+		'reqd': 0,
+		'width': '140px'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'amt_due',
+		'fieldtype': 'Currency',
+		'label': 'Amt Due',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'amt_to_be_reconciled',
+		'fieldtype': 'Currency',
+		'label': 'Amt to be reconciled',
+		'permlevel': 0,
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'posting_date',
+		'fieldtype': 'Date',
+		'label': 'Posting Date',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'total_amt',
+		'fieldtype': 'Currency',
+		'label': 'Total Amt',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'against_account',
+		'fieldtype': 'Data',
+		'label': 'Against Account',
+		'permlevel': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'remarks',
+		'fieldtype': 'Small Text',
+		'label': 'Remarks',
+		'permlevel': 1,
+		'width': '200px'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'voucher_detail_no',
+		'fieldtype': 'Data',
+		'hidden': 1,
+		'label': 'Voucher Detail No',
+		'no_column': 0,
+		'permlevel': 1,
+		'print_hide': 1,
+		'reqd': 0
+	}
+]
\ No newline at end of file
diff --git a/erpnext/patches/patch.py b/erpnext/patches/patch.py
index c1668be..8880e7d 100644
--- a/erpnext/patches/patch.py
+++ b/erpnext/patches/patch.py
@@ -1,7 +1,7 @@
 # REMEMBER to update this
 # ========================
 
-last_patch = 368
+last_patch = 372
 
 #-------------------------------------------
 
@@ -349,3 +349,34 @@
 	elif patch_no == 368:
 		sql("update tabDocPerm set amend = 0 where parent = 'Salary Structure'")
 		sql("update tabDocPerm set cancel = 1 where parent = 'Company' and role = 'System Manager'")
+	elif patch_no == 369:
+		from webnotes.utils import nestedset
+		t = [
+			['Account', 'parent_account'], ['Cost Center', 'parent_cost_center'], 
+			['Item Group', 'parent_item_group'], ['Territory', 'parent_territory'],
+			['Customer Group', 'parent_customer_group'], ['Sales Person', 'parent_sales_person']
+		]
+		for d in t:
+			nestedset.rebuild_tree(d[0], d[1])
+	elif patch_no == 370:
+		reload_doc('hr', 'doctype', 'appraisal')
+		reload_doc('hr', 'doctype', 'appraisal_detail')
+	elif patch_no == 371:
+		comp = sql("select name from tabCompany where docstatus!=2")
+		fy = sql("select name from `tabFiscal Year` order by year_start_date asc")
+		for c in comp:
+			prev_fy = ''
+			for f in fy:
+				fy_obj = get_obj('Fiscal Year', f[0])
+				fy_obj.doc.past_year = prev_fy
+				fy_obj.doc.company = c[0]
+				fy_obj.doc.save()
+				fy_obj.repost()
+				prev_fy = f[0]
+				sql("commit")
+				sql("start transaction")
+	elif patch_no == 372:
+		if sql("select count(name) from `tabDocField` where label = 'View Ledger Entry' and parent = 'Journal Voucher' and fieldtype = 'Button'")[0][0] > 1:
+			sql("delete from `tabDocField` where label = 'View Ledger Entry' and parent = 'Journal Voucher' and fieldtype = 'Button' limit 1")
+		if sql("select count(name) from `tabDocField` where label = 'Get Balance' and parent = 'Journal Voucher' and fieldtype = 'Button'")[0][0] > 1:
+			sql("delete from `tabDocField` where label = 'Get Balance' and parent = 'Journal Voucher' and fieldtype = 'Button' limit 1")
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 45b4973..a163870 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -26,110 +26,110 @@
 	def create_default_accounts(self):
 		self.fld_dict = {'account_name':0,'parent_account':1,'group_or_ledger':2,'is_pl_account':3,'account_type':4,'debit_or_credit':5,'company':6,'tax_rate':7}
 		acc_list_common = [['Application of Funds (Assets)','','Group','No','','Debit',self.doc.name,''],
-												['Current Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
-													['Accounts Receivable','Current Assets','Group','No','','Debit',self.doc.name,''],
-													['Bank Accounts','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
-													['Cash In Hand','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
-														['Cash','Cash In Hand','Ledger','No','Bank or Cash','Debit',self.doc.name,''],
-													['Loans and Advances (Assets)','Current Assets','Group','No','','Debit',self.doc.name,''],
-													['Securities and Deposits','Current Assets','Group','No','','Debit',self.doc.name,''],
-														['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
-													['Stock In Hand','Current Assets','Group','No','','Debit',self.doc.name,''],
-														['Stock','Stock In Hand','Ledger','No','','Debit',self.doc.name,''],
-													['Tax Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
-												['Fixed Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
-													['Capital Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
-													['Computers','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
-													['Furniture and Fixture','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
-													['Office Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
-													['Plant and Machinery','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
-												['Investments','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
-												['Temporary Accounts (Assets)','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
-													['Temporary Account (Assets)','Temporary Accounts (Assets)','Ledger','No','','Debit',self.doc.name,''],
-									['Source of Funds (Liabilities)','','Group','No','','Credit',self.doc.name,''],
-										['Capital Account','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
-											['Reserves and Surplus','Capital Account','Group','No','','Credit',self.doc.name,''],
-											['Shareholders Funds','Capital Account','Group','No','','Credit',self.doc.name,''],
-										['Current Liabilities','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
-											['Accounts Payable','Current Liabilities','Group','No','','Credit',self.doc.name,''],
-											['Duties and Taxes','Current Liabilities','Group','No','','Credit',self.doc.name,''],
-											['Loans (Liabilities)','Current Liabilities','Group','No','','Credit',self.doc.name,''],
-												['Secured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
-												['Unsecured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
-												['Bank Overdraft Account','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
-										['Temporary Accounts (Liabilities)','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
-											['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,''],
-									['Income','','Group','Yes','','Credit',self.doc.name,''],
-										['Direct Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
-											['Sales','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
-											['Service','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
-										['Indirect Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
-									['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''],
-										['Direct Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
-											['Cost of Goods Sold','Direct Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-										['Indirect Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
-											['Advertising and Publicity','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
-											['Bad Debts Written Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Bank Charges','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Books and Periodicals','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Charity and Donations','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Commission on Sales','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Conveyance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Customer Entertainment Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Depreciation Account','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Freight and Forwarding Charges','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
-											['Legal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Miscellaneous Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
-											['Office Maintenance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Office Rent','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Postal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Print and Stationary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Rounded Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Salary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Sales Promotion Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
-											['Service Charges Paid','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Staff Welfare Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Telephone Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Travelling Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
-											['Water and Electricity Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,'']
-									]
+								['Current Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+									['Accounts Receivable','Current Assets','Group','No','','Debit',self.doc.name,''],
+									['Bank Accounts','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
+									['Cash In Hand','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
+										['Cash','Cash In Hand','Ledger','No','Bank or Cash','Debit',self.doc.name,''],
+									['Loans and Advances (Assets)','Current Assets','Group','No','','Debit',self.doc.name,''],
+									['Securities and Deposits','Current Assets','Group','No','','Debit',self.doc.name,''],
+										['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
+									['Stock In Hand','Current Assets','Group','No','','Debit',self.doc.name,''],
+										['Stock','Stock In Hand','Ledger','No','','Debit',self.doc.name,''],
+									['Tax Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
+								['Fixed Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+									['Capital Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+									['Computers','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+									['Furniture and Fixture','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+									['Office Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+									['Plant and Machinery','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+								['Investments','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+								['Temporary Accounts (Assets)','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+									['Temporary Account (Assets)','Temporary Accounts (Assets)','Ledger','No','','Debit',self.doc.name,''],
+						['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''],
+							['Direct Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
+								['Cost of Goods Sold','Direct Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+							['Indirect Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
+								['Advertising and Publicity','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+								['Bad Debts Written Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Bank Charges','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Books and Periodicals','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Charity and Donations','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Commission on Sales','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Conveyance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Customer Entertainment Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Depreciation Account','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Freight and Forwarding Charges','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+								['Legal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Miscellaneous Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+								['Office Maintenance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Office Rent','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Postal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Print and Stationary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Rounded Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Salary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Sales Promotion Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+								['Service Charges Paid','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Staff Welfare Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Telephone Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Travelling Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+								['Water and Electricity Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+						['Income','','Group','Yes','','Credit',self.doc.name,''],
+							['Direct Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
+								['Sales','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
+								['Service','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
+							['Indirect Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
+						['Source of Funds (Liabilities)','','Group','No','','Credit',self.doc.name,''],
+							['Capital Account','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+								['Reserves and Surplus','Capital Account','Group','No','','Credit',self.doc.name,''],
+								['Shareholders Funds','Capital Account','Group','No','','Credit',self.doc.name,''],
+							['Current Liabilities','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+								['Accounts Payable','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+								['Duties and Taxes','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+								['Loans (Liabilities)','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+									['Secured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+									['Unsecured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+									['Bank Overdraft Account','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+							['Temporary Accounts (Liabilities)','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+								['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,'']						
+						]
 		
 		acc_list_india = [
-											['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['CENVAT','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
-											['CENVAT Service Tax','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['CENVAT Service Tax Cess 1','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['CENVAT Service Tax Cess 2','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['CENVAT Edu Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
-											['CENVAT SHE Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
-											['Excise Duty 4','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'4.00'],
-											['Excise Duty 8','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'8.00'],
-											['Excise Duty 10','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'10.00'],
-											['Excise Duty 14','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'14.00'],
-											['Excise Duty Edu Cess 2','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'2.00'],
-											['Excise Duty SHE Cess 1','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'1.00'],
-											['P L A','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['P L A - Cess Portion','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
-											['Edu. Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
-											['Edu. Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
-											['Edu. Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
-											['Excise Duty @ 4','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'4.00'],
-											['Excise Duty @ 8','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'8.00'],
-											['Excise Duty @ 10','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.00'],
-											['Excise Duty @ 14','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'14.00'],
-											['Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.3'],
-											['SHE Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
-											['SHE Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
-											['SHE Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
-											['Professional Tax','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['VAT','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Advertisement)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Commission)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Contractor)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Interest)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Rent)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
-											['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,'']
-										 ]
+							['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['CENVAT','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+							['CENVAT Service Tax','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['CENVAT Service Tax Cess 1','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['CENVAT Service Tax Cess 2','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['CENVAT Edu Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+							['CENVAT SHE Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+							['Excise Duty 4','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'4.00'],
+							['Excise Duty 8','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'8.00'],
+							['Excise Duty 10','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'10.00'],
+							['Excise Duty 14','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'14.00'],
+							['Excise Duty Edu Cess 2','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'2.00'],
+							['Excise Duty SHE Cess 1','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'1.00'],
+							['P L A','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['P L A - Cess Portion','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+							['Edu. Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+							['Edu. Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+							['Edu. Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+							['Excise Duty @ 4','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'4.00'],
+							['Excise Duty @ 8','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'8.00'],
+							['Excise Duty @ 10','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.00'],
+							['Excise Duty @ 14','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'14.00'],
+							['Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.3'],
+							['SHE Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+							['SHE Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+							['SHE Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+							['Professional Tax','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['VAT','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Advertisement)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Commission)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Contractor)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Interest)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Rent)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+							['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,'']
+						 ]
 		# load common account heads
 		for d in acc_list_common:
 			self.add_acc(d)