Merge branch 'development' of github.com:rmehta/erpnext
diff --git a/accounts/doctype/loan/loan.js b/accounts/doctype/loan/loan.js
index 37e49dc..d4e063d 100644
--- a/accounts/doctype/loan/loan.js
+++ b/accounts/doctype/loan/loan.js
@@ -8,11 +8,39 @@
 		}
 		cur_frm.refresh();
 	},
+	refresh: function(doc) {
+		cur_frm.cscript.hide_show_buttons(doc);
+	},
+	hide_show_buttons: function(doc) {
+		if(doc.docstatus==0) {
+			hide_field('Installment Reciept'); show_field('Generate');
+		} else if (doc.docstatus==1) {
+			show_field('Installment Reciept'); hide_field('Generate');			
+		}
+	},
 	clear_installments: function(doc) {
 		$.each(getchildren('Loan Installment', doc.name, 'installments', 'Loan'), 
 			function(i, d) {
 				LocalDB.delete_doc('Loan Installment', d.name);
 			}
 		)
+	},
+	'Installment Reciept': function(doc, dt, dn) {
+		var d = new wn.widgets.Dialog({
+			width: 500,
+			title: 'Add a new payment installment',
+			fields: [
+				{fieldtype:'Data', label:'Check Number', fieldname:'check_number', reqd:1},
+				{fieldtype:'Date', label:'Check Date', fieldname:'check_date', reqd:1},
+				{fieldtype:'Button', label:'Update',fieldname:'update'}
+			]
+		})
+		d.show();
+		d.fields_dict.update.input.onclick = function() {
+			var data = d.get_values();
+			if(data) {
+				$c_obj()
+			}
+		}
 	}
 })
\ No newline at end of file
diff --git a/accounts/doctype/loan/loan.txt b/accounts/doctype/loan/loan.txt
new file mode 100644
index 0000000..90c0db2
--- /dev/null
+++ b/accounts/doctype/loan/loan.txt
@@ -0,0 +1,144 @@
+# DocType, Loan
+[
+
+	# These values are common in all dictionaries
+	{
+		'creation': '2011-07-12 10:50:19',
+		'docstatus': 0,
+		'modified': '2011-07-14 11:22:32',
+		'modified_by': 'Administrator',
+		'owner': 'Administrator'
+	},
+
+	# These values are common for all DocType
+	{
+		'_last_update': '1310622631',
+		'colour': 'White:FFF',
+		'doctype': 'DocType',
+		'module': 'Accounts',
+		'name': '__common__',
+		'section_style': 'Simple',
+		'show_in_menu': 0,
+		'version': 11
+	},
+
+	# These values are common for all DocField
+	{
+		'doctype': 'DocField',
+		'name': '__common__',
+		'parent': 'Loan',
+		'parentfield': 'fields',
+		'parenttype': 'DocType',
+		'permlevel': 0
+	},
+
+	# These values are common for all DocPerm
+	{
+		'cancel': 1,
+		'create': 1,
+		'doctype': 'DocPerm',
+		'idx': 1,
+		'name': '__common__',
+		'parent': 'Loan',
+		'parentfield': 'permissions',
+		'parenttype': 'DocType',
+		'permlevel': 0,
+		'read': 1,
+		'role': 'Accounts User',
+		'submit': 1,
+		'write': 1
+	},
+
+	# DocType, Loan
+	{
+		'doctype': 'DocType',
+		'name': 'Loan'
+	},
+
+	# DocPerm
+	{
+		'doctype': 'DocPerm'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'naming_series',
+		'fieldtype': 'Select',
+		'idx': 1,
+		'label': 'Naming Series',
+		'options': '\nLOAN',
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'account',
+		'fieldtype': 'Link',
+		'idx': 2,
+		'label': 'Account',
+		'options': 'Account',
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'loan_amount',
+		'fieldtype': 'Currency',
+		'idx': 3,
+		'label': 'Loan Amount',
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'start_date',
+		'fieldtype': 'Date',
+		'idx': 4,
+		'label': 'Start Date',
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'no_of_installments',
+		'fieldtype': 'Int',
+		'idx': 5,
+		'label': 'No of Installments',
+		'reqd': 1
+	},
+
+	# DocField
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Button',
+		'idx': 6,
+		'label': 'Generate',
+		'trigger': 'Client'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'installments',
+		'fieldtype': 'Table',
+		'idx': 7,
+		'label': 'Installments',
+		'options': 'Loan Installment'
+	},
+
+	# DocField
+	{
+		'allow_on_submit': 1,
+		'colour': 'White:FFF',
+		'doctype': 'DocField',
+		'fieldtype': 'Button',
+		'idx': 8,
+		'label': 'Installment Reciept'
+	}
+]
\ No newline at end of file
diff --git a/accounts/doctype/loan_installment/loan_installment.txt b/accounts/doctype/loan_installment/loan_installment.txt
new file mode 100644
index 0000000..dd65939
--- /dev/null
+++ b/accounts/doctype/loan_installment/loan_installment.txt
@@ -0,0 +1,94 @@
+# DocType, Loan Installment
+[
+
+	# These values are common in all dictionaries
+	{
+		'creation': '2011-07-12 10:53:58',
+		'docstatus': 0,
+		'modified': '2011-07-12 10:53:58',
+		'modified_by': 'Administrator',
+		'owner': 'Administrator'
+	},
+
+	# These values are common for all DocType
+	{
+		'colour': 'White:FFF',
+		'doctype': 'DocType',
+		'istable': 1,
+		'module': 'Accounts',
+		'name': '__common__',
+		'section_style': 'Simple',
+		'show_in_menu': 0,
+		'version': 1
+	},
+
+	# These values are common for all DocField
+	{
+		'doctype': 'DocField',
+		'name': '__common__',
+		'parent': 'Loan Installment',
+		'parentfield': 'fields',
+		'parenttype': 'DocType',
+		'permlevel': 0
+	},
+
+	# DocType, Loan Installment
+	{
+		'doctype': 'DocType',
+		'name': 'Loan Installment'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'amount',
+		'fieldtype': 'Currency',
+		'idx': 1,
+		'label': 'Amount'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'due_date',
+		'fieldtype': 'Date',
+		'idx': 2,
+		'label': 'Due Date'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'check_number',
+		'fieldtype': 'Int',
+		'idx': 3,
+		'label': 'Check Number'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'check_date',
+		'fieldtype': 'Date',
+		'idx': 4,
+		'label': 'Check Date'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'deposit_date',
+		'fieldtype': 'Date',
+		'idx': 5,
+		'label': 'Deposit Date'
+	},
+
+	# DocField
+	{
+		'doctype': 'DocField',
+		'fieldname': 'realized_date',
+		'fieldtype': 'Date',
+		'idx': 6,
+		'label': 'Realized Date'
+	}
+]
\ No newline at end of file
diff --git a/home/page/my_company/my_company.py b/home/page/my_company/my_company.py
index 58a82ad..560ea6e 100644
--- a/home/page/my_company/my_company.py
+++ b/home/page/my_company/my_company.py
@@ -52,12 +52,13 @@
 #
 def add_user(args):
 	args = json.loads(args)
-	add_profile(args['user'])
 	# erpnext-saas
 	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
 		from server_tools.gateway_utils import add_user_gateway
 		add_user_gateway(args['user'])
 	
+	add_profile(args['user'])
+	
 #
 # add profile record
 #
diff --git a/hr/doctype/salary_slip/salary_slip.txt b/hr/doctype/salary_slip/salary_slip.txt
index c9ba1de..d2ce4e3 100644
--- a/hr/doctype/salary_slip/salary_slip.txt
+++ b/hr/doctype/salary_slip/salary_slip.txt
@@ -5,14 +5,14 @@
 	{
 		'creation': '2010-08-08 17:09:20',
 		'docstatus': 0,
-		'modified': '2011-06-27 14:39:16',
+		'modified': '2011-07-13 17:38:55',
 		'modified_by': 'Administrator',
 		'owner': 'Administrator'
 	},
 
 	# These values are common for all DocType
 	{
-		'_last_update': '1308808105',
+		'_last_update': '1310019491',
 		'colour': 'White:FFF',
 		'doctype': 'DocType',
 		'module': 'HR',
@@ -21,7 +21,7 @@
 		'server_code_error': ' ',
 		'show_in_menu': 0,
 		'subject': 'For %(employee_name)s, %(designation)s',
-		'version': 388
+		'version': 392
 	},
 
 	# These values are common for all DocField
@@ -51,58 +51,24 @@
 
 	# DocPerm
 	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		'doctype': 'DocPerm',
-		'match': 'owner',
-		'permlevel': 0,
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		'doctype': 'DocPerm',
-		'match': 'owner',
-		'permlevel': 0,
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		'doctype': 'DocPerm',
-		'match': 'owner',
-		'permlevel': 0,
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		'doctype': 'DocPerm',
-		'match': 'owner',
-		'permlevel': 0,
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
+		'amend': 1,
+		'cancel': 1,
 		'create': 1,
 		'doctype': 'DocPerm',
-		'idx': 3,
+		'idx': 1,
+		'permlevel': 0,
+		'role': 'System Manager',
+		'submit': 1,
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'amend': 0,
+		'cancel': 0,
+		'create': 1,
+		'doctype': 'DocPerm',
+		'idx': 2,
 		'permlevel': 0,
 		'role': 'HR User',
 		'submit': 1,
@@ -111,11 +77,11 @@
 
 	# DocPerm
 	{
-		'amend': 1,
-		'cancel': 1,
+		'amend': 0,
+		'cancel': 0,
 		'create': 1,
 		'doctype': 'DocPerm',
-		'idx': 4,
+		'idx': 3,
 		'permlevel': 0,
 		'role': 'HR Manager',
 		'submit': 1,
@@ -124,18 +90,28 @@
 
 	# DocPerm
 	{
+		'amend': 0,
+		'cancel': 0,
+		'create': 0,
 		'doctype': 'DocPerm',
-		'idx': 5,
+		'idx': 4,
 		'permlevel': 1,
-		'role': 'HR User'
+		'role': 'HR User',
+		'submit': 0,
+		'write': 0
 	},
 
 	# DocPerm
 	{
+		'amend': 0,
+		'cancel': 0,
+		'create': 0,
 		'doctype': 'DocPerm',
-		'idx': 6,
+		'idx': 5,
 		'permlevel': 1,
-		'role': 'HR Manager'
+		'role': 'HR Manager',
+		'submit': 0,
+		'write': 0
 	},
 
 	# DocField
@@ -288,28 +264,6 @@
 	# DocField
 	{
 		'doctype': 'DocField',
-		'fieldname': 'letter_head',
-		'fieldtype': 'Link',
-		'idx': 11,
-		'label': 'Letter Head',
-		'options': 'Letter Head',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'doctype': 'DocField',
-		'fieldname': 'letter_head',
-		'fieldtype': 'Link',
-		'idx': 11,
-		'label': 'Letter Head',
-		'options': 'Letter Head',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'doctype': 'DocField',
 		'fieldtype': 'Column Break',
 		'idx': 12,
 		'oldfieldtype': 'Column Break',
@@ -349,32 +303,6 @@
 
 	# DocField
 	{
-		'doctype': 'DocField',
-		'fieldname': 'company',
-		'fieldtype': 'Select',
-		'idx': 14,
-		'in_filter': 1,
-		'label': 'Company',
-		'options': 'link:Company',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': 'DocField',
-		'fieldname': 'company',
-		'fieldtype': 'Select',
-		'idx': 14,
-		'in_filter': 1,
-		'label': 'Company',
-		'options': 'link:Company',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
 		'colour': 'White:FFF',
 		'doctype': 'DocField',
 		'fieldname': 'month',
@@ -396,7 +324,7 @@
 	{
 		'doctype': 'DocField',
 		'fieldname': 'total_days_in_month',
-		'fieldtype': 'Int',
+		'fieldtype': 'Data',
 		'idx': 16,
 		'label': 'Total days in month',
 		'oldfieldname': 'total_days_in_month',
diff --git a/patches/patch.py b/patches/patch.py
index 9783de5..f184197 100644
--- a/patches/patch.py
+++ b/patches/patch.py
@@ -1,7 +1,7 @@
 # REMEMBER to update this
 # ========================
 
-last_patch = 323
+last_patch = 325
 
 #-------------------------------------------
 
@@ -1289,3 +1289,8 @@
 		reload_doc('stock', 'doctype', 'stock_entry')
 		sql("update `tabDocField` set options = 'get_stock_and_rate' where parent = 'Stock Entry' and label = 'Get Stock and Rate'")
 		sql("delete from `tabDocField` where label = 'Get Current Stock' and parent = 'Stock Entry'")
+	elif patch_no == 324:
+		sql("delete from `tabDocField` where fieldname = 'test_field' and parent = 'Customer'")
+	elif patch_no == 325:
+		sql("update `tabDocField` set fieldtype = 'Data' where parent = 'Salary Slip' and fieldname = 'total_days_in_month'")
+		reload_doc('hr', 'doctype', 'salary_slip')
diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js
index 584f412..2c1e77f 100644
--- a/support/doctype/support_ticket/support_ticket.js
+++ b/support/doctype/support_ticket/support_ticket.js
@@ -33,12 +33,14 @@
 	
 	refresh: function(doc) {
 		cs.make_listing(doc);
-		if(!doc.__islocal) {					
-			
-			if(doc.allocated_to) 
+		if(!doc.__islocal) {											
+			if(in_list(user_roles,'System Manager')) {
+		      if(doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);	
+			  if(doc.status=='Closed') cur_frm.add_custom_button('Re-Open Ticket', cs['Re-Open Ticket']);		
+			}else if(doc.allocated_to) {
 			  set_field_permlevel('status',2);
 			  if(user==doc.allocated_to && doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cs['Close Ticket']);
-			  if(doc.status=='Closed') cur_frm.add_custom_button('Re-Open Ticket', cs['Re-Open Ticket']);
+			}
 			
 			// can't change the main message & subject once set  
 			set_field_permlevel('subject',2);