def xmlrpc_getOnlyClearedTransactions(self,queryParams,client_id):
		"""
		* Purpose:
			- This function will check for cleared transactions
		
		* Input:
			- [accountname,vouchercode,financialstart,todate]
		
		* Output:
			- if transaction is exist in bankrecon table 
			- it will return boolean True else False
		"""
		from_date = str(datetime.strptime(str(queryParams[2]),"%d-%m-%Y"))
		to_date = str(datetime.strptime(str(queryParams[3]),"%d-%m-%Y"))
		accObj = rpc_account.account()
		accountcode = accObj.xmlrpc_getAccountCodeByAccountName([queryParams[0]], client_id)
		connection = dbconnect.engines[client_id].connect()
		Session = dbconnect.session(bind=connection)
		result = Session.query(dbconnect.BankRecon).filter(and_(dbconnect.BankRecon.accountcode==accountcode,\
				dbconnect.BankRecon.vouchercode==queryParams[1],\
				dbconnect.BankRecon.clearancedate >= from_date,\
				dbconnect.BankRecon.clearancedate <= to_date)).\
				first()
		Session.close()
		connection.connection.close()
		if result != None:
			return True
		else:
			return False
Exemplo n.º 2
0
	def xmlrpc_setTransaction(self,queryParams_master,queryParams_details,client_id):
		"""
		Purpose: adds a new voucher in the database given its reference number 
		and transaction details (dr and cr), along with narration and the date.
		This function is used to create a new voucher.  
		The entire transaction is recorded in terms of Dr and Cr and the respected amounts.
		The function call 3 funtions from same file rpc_transation.py
		1 . xmlrpc_getProjectcodeByProjectName  
		2 . xmlrpc_setVoucherMaster
		3 . xmlrpc_setVoucherDetails 
		
		and call 1 function from rpc_account.py "to get accountcode by accountname"
		1 . xmlrpc_getAccountCodeByAccountName
		
		queryParams_master list will contain :
		* reference Number
		* the actual transaction date
		* Voucher type
		* project name
		* Narration
		
		queryParams_details list will contain :
		
		* DrCr flag,
		* AccountName
		* the amount for the respective account.
		The function returns "success" .
		"""
		queryParams_master = blankspace.remove_whitespaces(queryParams_master)
		print "queryParams_master"
		print queryParams_master
		projectcode = self.xmlrpc_getProjectcodeByProjectName([queryParams_master[3]],client_id)
		
		params_master = [queryParams_master[0],queryParams_master[1],queryParams_master[2],projectcode,queryParams_master[4]]
		print "params master"
		print params_master
		vouchercode = self.xmlrpc_setVoucherMaster(params_master,client_id)
		
		print "query for masters is successful and voucher code is " + str(vouchercode)
		for detailRow in queryParams_details:
			queryParams_details = blankspace.remove_whitespaces(detailRow)
			account = rpc_account.account();
			accountcode = account.xmlrpc_getAccountCodeByAccountName([detailRow[1]],client_id);
			params_details = [vouchercode,str(detailRow[0]),str(accountcode),float(detailRow[2])]
			self.xmlrpc_setVoucherDetails(params_details,client_id)
		return 1
Exemplo n.º 3
0
def runabt():
	"""
	+ As we have imported all the nested XMLRPC resource,so that create one handler ``abt`` 
	  calls another if a method with a given prefix is called.
	+ and publish that handelr instance ``abt`` to server .
	+ this is ``def runabt()`` which is outside ``class abt():``.	"""
	import rpc_main
	# create the instance of class abt
	abt = rpc_main.abt()
	groups=rpc_groups.groups()
	abt.putSubHandler('groups',groups)

	account=rpc_account.account()
	abt.putSubHandler('account',account)

	organisation = rpc_organisation.organisation()
	abt.putSubHandler('organisation',organisation)

	transaction=rpc_transaction.transaction()
	abt.putSubHandler('transaction',transaction)

	data=rpc_data.data()
	abt.putSubHandler('data',data)

	reports=rpc_reports.reports()
	abt.putSubHandler('reports',reports)

	user = rpc_user.user()
	abt.putSubHandler('user',user)

	getaccountsbyrule=rpc_getaccountsbyrule.getaccountsbyrule()
	abt.putSubHandler('getaccountsbyrule',getaccountsbyrule)

	print "initialising application"
	
	#publish the object and make it to listen on the given port through reactor
	print "starting server"
	reactor.listenTCP(7081, server.Site(abt))
	#start the service by running the reactor.
	reactor.run()
	def xmlrpc_setTransaction(self,queryParams_master,queryParams_details,client_id):
		"""
		* Purpose:
			- This function is used to create a new voucher. 
			- adds a new voucher in the database given its reference number 
			  and transaction details (dr and cr), along with narration and the date.
			- the entire transaction is recorded in terms of Dr and Cr and the respected amounts.
			- the function call 3 funtions from same file rpc_transation.py
			  ``xmlrpc_getProjectcodeByProjectName`` ``xmlrpc_setVoucherMaster``
			  ``xmlrpc_setVoucherDetails``
			- and call ``xmlrpc_getAccountCodeByAccountName`` from rpc_account.py 
			  to get accountcode by accountname

		* Input: 
			- queryParams_master list will contain:
			- reference number,transaction date ,voucher type,project name,narration
			- queryParams_details list will contain:
			- DrCr flag,AccountName,the amount for the respective account.

		* Output:
			- function returns 1 integer.
		"""
		queryParams_master = blankspace.remove_whitespaces(queryParams_master)
		projectcode = self.xmlrpc_getProjectcodeByProjectName([queryParams_master[3]],client_id)
		
		params_master = [queryParams_master[0],queryParams_master[1],queryParams_master[2],projectcode,\
		queryParams_master[4],queryParams_master[5],queryParams_master[6]]
		
		vouchercode = self.xmlrpc_setVoucherMaster(params_master,client_id)
		
		print "query for masters is successful and voucher code is " + str(vouchercode)
		for detailRow in queryParams_details:
			queryParams_details = blankspace.remove_whitespaces(detailRow)
			account = rpc_account.account();
			accountcode = account.xmlrpc_getAccountCodeByAccountName([detailRow[1]],client_id);
			params_details = [vouchercode,str(detailRow[0]),str(accountcode),float(detailRow[2])]
			self.xmlrpc_setVoucherDetails(params_details,client_id)
		return 1
Exemplo n.º 5
0
def runabt():
	"""
	+ As we have imported all the nested XMLRPC resource,so that create one handler ``abt`` 
	  calls another if a method with a given prefix is called.
	+ and publish that handelr instance ``abt`` to server .
	+ this is ``def runabt()`` which is outside ``class abt():``.
	"""
	import rpc_main
	# create the instance of class abt
	abt = rpc_main.abt()
	groups=rpc_groups.groups()
	abt.putSubHandler('groups',groups)

	account=rpc_account.account()
	abt.putSubHandler('account',account)

	organisation = rpc_organisation.organisation()
	abt.putSubHandler('organisation',organisation)

	transaction=rpc_transaction.transaction()
	abt.putSubHandler('transaction',transaction)

	data=rpc_data.data()
	abt.putSubHandler('data',data)

	reports=rpc_reports.reports()
	abt.putSubHandler('reports',reports)

	user = rpc_user.user()
	abt.putSubHandler('user',user)

	getaccountsbyrule=rpc_getaccountsbyrule.getaccountsbyrule()
	abt.putSubHandler('getaccountsbyrule',getaccountsbyrule)

	print "initialising application"
	#the code to daemonise published instance.
	
 	# Daemonizing abt
	# Accept commandline arguments
	# A workaround for debugging
	def usage():
		print "Usage: %s [d|debug] [h|help]\n" % (sys.argv[0])
		print "\td (debug)\tStart server in debug mode. Do not fork a daemon."
		print "\td (help)\tShow this help"

	try:
		opts, args = getopt.getopt(sys.argv[1:], "hd", ["help","debug"])
	except getopt.GetoptError:
		usage()
		os._exit(2)

	debug = 0
	for opt, arg in opts:
		if opt in ("h", "help"):
			usage()
			os.exit(0)
		elif opt in ("d", "debug"):
			debug = 1

	# Do not fork if we are debug mode
	if debug == 0:
		try:
			pid = os.fork()
		except OSError, e:
			raise Exception, "Could not fork a daemon: %s" % (e.strerror)

		if pid != 0:
			os._exit(0)

		# Prevent it from being orphaned
		os.setsid()
	
		# Change working directory to root
		os.chdir("/")

		# Change umask
		os.umask(0)

		# All prints should be replaced with logging, preferrably into syslog
		# The standard I/O file descriptors are redirected to /dev/null by default.
		if (hasattr(os, "devnull")):
			REDIRECT_TO = os.devnull
		else:
			REDIRECT_TO = "/dev/null"

		# Redirect the standard I/O file descriptors to the specified file.  Since
		# the daemon has no controlling terminal, most daemons redirect stdin,
		# stdout, and stderr to /dev/null.  This is done to prevent sideeffects
		# from reads and writes to the standard I/O file descriptors.

		# This call to open is guaranteed to return the lowest file descriptor,
		# which will be 0 (stdin), since it was closed above.
		os.open(REDIRECT_TO, os.O_RDWR)	# standard input (0)

		# Duplicate standard input to standard output and standard error.
		os.dup2(0, 1)			# standard output (1)
		os.dup2(0, 2)			# standard error (2)
Exemplo n.º 6
0
	def xmlrpc_rollover(self,queryParams,client_id):
		"""
		* Purpose:
			- This function is to forward the closing balance of current year 
			  to next financial year as opening balance 
			- it will first get the all accountname and corrosponding closing 
			  balance of current financial year.
			- then its create the schema and dump of current year's database
			  and then get the reverse pattern match from both as save to file
			  db.dump
			- then from db.dump it will only give the dump of ``account`` ``subgroups``
			  and ``organisation`` table 
			- then ``rpc_Deploy`` function will deploy new databse for given
			  newFinancialTo date and Organisation and OrganisationType
			  where ``newFinancialFrom`` date will calculate by adding one day to 
			  current ``financialTo`` date
			- and the restore all the values of ``account`` ``subgroups`` and
			  ``organisation``
			- update ``openingbalance`` of the restored ``account`` table with 
			  the calculated ``closingbalance``.
			- after restoring values it also update ``rolloverflag`` of previous 
			  organisation as ``1`` , so that organisation should not rollover again
		* Input: 
		 	- [organisationName,financialFrom,financialTo],client_id
		 	
		* Output:
			- boolean newOrganisaionFromDate
			- created new financile year and database 
			- restore accounts its closingbalance as openingbalance and subgroups 
		"""
	
		organisation = rpc_organisation.organisation()
		financialFrom = queryParams[1] # get financial from date 
		financialTo = queryParams[2] # get financial to date
		
		
		NewFinancialYear = self.newFinancialYears([financialFrom,financialTo])
		
		orgType = organisation.xmlrpc_getorgTypeByname([queryParams[0]],client_id)
		
	##########################################################
		account = rpc_account.account()
		report = rpc_reports.reports()
		accounts = account.xmlrpc_getAllAccountNames(client_id)
		rollOverAccounts = {}
		for acc in accounts:
			
			closingRow = report.xmlrpc_calculateBalance([acc,queryParams[1],queryParams[2],\
									queryParams[2]],client_id)
			# [group_name,bal_brought,curbal,total_DrBal,total_CrBal,opening_baltype,baltype]
			closing_balance = 0.00
			print acc
			if (str(closingRow[6])  == "Cr" 
				and (str(closingRow[0])== "Current Asset" 
				or str(closingRow[0])== "Fixed Assets" 
				or str(closingRow[0])== "Investment" 
				or str(closingRow[0])== "Loans(Asset)" 
				or str(closingRow[0])== "Miscellaneous Expenses(Asset)"
				)
				):
			
				closing_balance = -float(closingRow[2])
				rollOverAccounts[acc] = closing_balance
			
			if (str(closingRow[6])  == "Dr" 
				and  (str(closingRow[0])== "Current Asset" 
				or str(closingRow[0])== "Fixed Assets" 
				or str(closingRow[0])== "Investment" 
				or str(closingRow[0])== "Loans(Asset)" 
				or str(closingRow[0])== "Miscellaneous Expenses(Asset)"
				
				)):
			
				closing_balance = float(closingRow[2])
				rollOverAccounts[acc] = closing_balance
			
			if (str(closingRow[6])  == "Cr"
				and  (str(closingRow[0])== "Corpus" 
				or str(closingRow[0])== "Capital" 
				or str(closingRow[0])== "Current Liability" 
				or str(closingRow[0])== "Loans(Liability)" 
				or str(closingRow[0])== "Reserves")):
			
				closing_balance = float(closingRow[2])
				rollOverAccounts[acc] = closing_balance
			
			if (str(closingRow[6])  == "Dr"
				and  (str(closingRow[0])== "Corpus" 
				or str(closingRow[0])== "Capital" 
				or str(closingRow[0])== "Current Liability" 
				or str(closingRow[0])== "Loans(Liability)"
				or str(closingRow[0])== "Reserves")):	
			
				closing_balance = -float(closingRow[2])
				rollOverAccounts[acc] = closing_balance
	
		
		profitloss= report.xmlrpc_getBalancesheetDisplay([queryParams[1],queryParams[1],queryParams[2],"balancesheet",orgType,None],client_id)
		
		Flag = profitloss[0]
		netFlag = profitloss[3]
		netPL = '%.2f'%(float(profitloss[1]))
		netOpening = '%.2f'%(float(profitloss[2]))
		connection = dbconnect.engines[client_id].connect()
		Session = dbconnect.session(bind=connection)
		connection = dbconnect.engines[client_id].raw_connection()
		dbconnect.engines[client_id].execute("delete from profit_loss;")
		connection.commit()
		Session.add(dbconnect.ProfitLoss(Flag,netPL))
		Session.commit()
		database = dbconnect.getDatabaseName([queryParams[0],financialFrom,financialTo])
		try:
			os.system("sqlite3 /opt/abt/db/"+database+" .sch > schema")
			os.system("sqlite3 /opt/abt/db/"+database+" .dump > dump")
			os.system("grep -vxw -f schema dump > /opt/abt/db/db.dump")
			os.system("grep -w 'account\|subgroups\|organisation\|users\|flags\|profit_loss' /opt/abt/db/db.dump > /opt/abt/db/db_dump.dump")
		except:
			print "problem to dump database"
	
		################################################################
		
		connection = dbconnect.engines[client_id].raw_connection()
		dbconnect.engines[client_id].execute("delete from profit_loss;")
		connection.commit()
		Session.add(dbconnect.ProfitLoss(netFlag,netOpening))
		Session.commit()
		
		Session.close()
		dbconnect.engines[client_id].dispose()
		
		
		del dbconnect.engines[client_id]
		self.client_id = self.xmlrpc_Deploy([queryParams[0],NewFinancialYear[0],NewFinancialYear[1],orgType])
	
		print "new database is not deployed"
		newDatabase = dbconnect.getDatabaseName([queryParams[0],NewFinancialYear[0],NewFinancialYear[1]])
		
		print "deployment is done and the new dbname is " + newDatabase
		connection = dbconnect.engines[self.client_id[1]].raw_connection()
		dbconnect.engines[self.client_id[1]].execute("delete from subgroups;")
		connection.commit()
		dbconnect.engines[self.client_id[1]].execute("delete from flags;")
		connection.commit()
		
		
		try:
			os.system("sqlite3 /opt/abt/db/"+ newDatabase+"< /opt/abt/db/db_dump.dump")
			for account in rollOverAccounts.keys():
				connection = dbconnect.engines[self.client_id[1]].raw_connection()
				
				editStatement = 'update account set openingbalance = '+str(rollOverAccounts[account])+\
						' where accountname = "' + account + '"'
				dbconnect.engines[self.client_id[1]].execute(editStatement)
	
				connection.commit()
			queryParams.append(database) #dbname
			queryParams.append("1") #rollover flag
			# parsing abt.xml file to update rollover flag from '0' to '1'
			self.xmlrpc_writeToXmlFile(queryParams,"/opt/abt/abt.xml");
			Session.close()
			
		except:
			print "in rollover exception"
		
		return "rollover"
Exemplo n.º 7
0
        Session.add_all([dbconnect.Flags(None, "mandatory"), dbconnect.Flags(None, "automatic")])
        Session.commit()

        Session.close()
        connection.close()
        return True, self.client_id


# create the instance of class abt

abt = abt()

groups = rpc_groups.groups()
abt.putSubHandler("groups", groups)

account = rpc_account.account()
abt.putSubHandler("account", account)

organisation = rpc_organisation.organisation()
abt.putSubHandler("organisation", organisation)

transaction = rpc_transaction.transaction()
abt.putSubHandler("transaction", transaction)

data = rpc_data.data()
abt.putSubHandler("data", data)

reports = rpc_reports.reports()
abt.putSubHandler("reports", reports)

user = rpc_user.user()