def deleteAnExpense(self, expenseKey):
		from google.appengine.ext import db
		from tuition.tools.models import Expenses

		expenseToDelete = Expenses.get(expenseKey)
		amount = expenseToDelete.amount
		db.delete(expenseToDelete.key())
		isSaved = True
		return self.respond(isSaved=isSaved, key=expenseKey, amount=amount)
Beispiel #2
0
    def deleteAnExpense(self, expenseKey):
        from google.appengine.ext import db
        from tuition.tools.models import Expenses

        expenseToDelete = Expenses.get(expenseKey)
        amount = expenseToDelete.amount
        db.delete(expenseToDelete.key())
        isSaved = True
        return self.respond(isSaved=isSaved, key=expenseKey, amount=amount)
	def getTodaysExpense(self):
		import datetime
		from tuition.tools.models import Expenses
		from tuition.utils.manager import AppManager

		serializedObjects = []
		loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email())
		today = datetime.date.today()
		todaysExpense = Expenses.all().filter('user ='******'dateOfExpense =', today).order('-dateOfExpense')
		todaysExpense = todaysExpense.fetch(limit=1000)
		for expense in todaysExpense:
			serializedObjects.append(expense.toDict)
		return self.respond(expenses=serializedObjects)
Beispiel #4
0
def updateExpensesCreatedAndUpdatedOn(request):
	from tuition.tools.models import Expenses
	from tuition.utils.manager import AppManager
	from google.appengine.ext import db
	from django import http
	import datetime

	if not AppManager.isCurrentUserAppAdmin():
		raise Exception('Unauthorized Access')

	isOver = False
	pageNo = int(request.GET.get('pageNo', 0))
	expenses = Expenses.all().fetch(limit=60, offset=pageNo*60)
	if expenses:
		for expense in expenses:
			expense.createdOn = datetime.datetime.now()
			expense.updatedOn = datetime.datetime.now()
		db.put(expenses)
		pageNo += 1
	else:
		isOver = True

	content = """
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
				<head><title>Update Expenses</title></head>
				<body style="font-size: 18px;">
					<div style="text-align:center font-weight:bold">
						Number of records processed in this run : %d
						<form action="/updateExpensesCreatedAndUpdatedOn" method="GET">
							<input type="hidden" name="pageNo" value="%d" />
							<input type=submit value="Next"/>
						</form>
					</div>
				</body>
			</html>""" % (len(expenses), pageNo)
	if isOver:
		content = """
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head><title>Update Expenses</title></head>
				<body style="font-size: 18px;">
					<div style="text-align:center font-weight:bold">
						Updation Complete
					</div>
				</body>
				</html>
		"""
	response = http.HttpResponse()
	response.write(content)
	return response
	def getExpenseThisWeek(self):
		import datetime
		from tuition.tools.models import Expenses
		from tuition.utils.manager import AppManager
		from tuition.utils.utils import weekStartEnd

		serializedObjects = []
		loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email())
		startOfWeek = weekStartEnd().get('start')
		thisWeeksExpense = Expenses.all().filter('user ='******'dateOfExpense >=', startOfWeek).order('-dateOfExpense')
		thisWeeksExpense = thisWeeksExpense.fetch(limit=1000)
		for expense in thisWeeksExpense:
			serializedObjects.append(expense.toDict)
		return self.respond(expenses=serializedObjects)
	def getExpenseOfYear(self, value):
		import datetime
		from tuition.tools.models import Expenses
		from tuition.utils.manager import AppManager
		from tuition.utils.appConstants import MONTH_NUM_FULL_NAME_DICT

		serializedList = []
		year = int(value.get('year', 2013))
		dateToCheck = datetime.date(year, 1, 1)
		loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email())
		expenseOfTheYear = Expenses.all().filter('user ='******'dateOfExpense >=', dateToCheck).fetch(1000)
		for expense in expenseOfTheYear:
			serializedList.append(expense.toDict)
		return self.respond(expenses=serializedList)
	def getExpenseThisMonth(self, values):
		import datetime
		from tuition.tools.models import Expenses
		from tuition.utils.manager import AppManager
		from tuition.utils.utils import getMonthEnd

		serializedObjects = []
		year = int(values.get('year', 2013))
		month = int(values.get('month', datetime.date.today().month))
		loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email())
		firstOfMonth = datetime.date(year, month, 1)
		endOfMonth = datetime.date(year, month, getMonthEnd(month, year))
		thisMonthExpense = Expenses.all().filter('user ='******'dateOfExpense >=', firstOfMonth).filter('dateOfExpense <=', endOfMonth).order('-dateOfExpense')
		thisMonthExpense = thisMonthExpense.fetch(limit=1000)
		for expense in thisMonthExpense:
			serializedObjects.append(expense.toDict)
		return self.respond(expenses=serializedObjects)
Beispiel #8
0
    def getTodaysExpense(self):
        import datetime
        from tuition.tools.models import Expenses
        from tuition.utils.manager import AppManager

        serializedObjects = []
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        today = datetime.date.today()
        todaysExpense = Expenses.all().filter(
            'user ='******'dateOfExpense =',
                                           today).order('-dateOfExpense')
        todaysExpense = todaysExpense.fetch(limit=1000)
        for expense in todaysExpense:
            serializedObjects.append(expense.toDict)
        return self.respond(expenses=serializedObjects)
Beispiel #9
0
    def saveDebt(self, serializedFormValues):
        from tuition.utils.manager import AppManager
        from tuition.tools.forms import DebtForm
        from tuition.tools.models import Debt, Expenses

        modelsToPut = []
        savedExpenseKey = None
        savedDebtKey = None
        form = DebtForm(data=serializedFormValues)
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        if form.is_valid():
            dictToSave = {
                'user': loggedInEmployee.key(),
                'type': form.cleaned_data['type'],
                'amount': form.cleaned_data['amount'],
                'incurredDate': form.cleaned_data['incurredDate'],
                'returnDate': form.cleaned_data['returnDate'],
                'expenseOfMonth': form.cleaned_data['expenseOfMonth'],
                'hasReturned': form.cleaned_data['hasReturned'],
                'comments': form.cleaned_data['comments']
            }
            newDebt = Debt(**dictToSave)
            modelsToPut.append(newDebt)

            if form.cleaned_data['hasReturned']:
                dictToSave = {
                    'user': loggedInEmployee.key(),
                    'type': 'Debt Return',
                    'amount': newDebt.amount,
                    'dateOfExpense': form.cleaned_data['expenseOfMonth'],
                    'comments': ''
                }
                newExpense = Expenses(**dictToSave)
                modelsToPut.append(newExpense)

            if len(modelsToPut) > 1:
                savedDebtKey, savedExpenseKey = db.put(modelsToPut)
            elif len(modelsToPut) == 1:
                savedDebtKey = db.put(modelsToPut)
            return self.respond(isSaved=True,
                                savedDebtKey=str(savedDebtKey),
                                savedExpenseKey=str(savedExpenseKey),
                                savedDebt=newDebt.toDict)
        else:
            return self.respond(isSaved=False, errors=form.errors)
Beispiel #10
0
    def getExpenseOfYear(self, value):
        import datetime
        from tuition.tools.models import Expenses
        from tuition.utils.manager import AppManager
        from tuition.utils.appConstants import MONTH_NUM_FULL_NAME_DICT

        serializedList = []
        year = int(value.get('year', 2013))
        dateToCheck = datetime.date(year, 1, 1)
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        expenseOfTheYear = Expenses.all().filter(
            'user ='******'dateOfExpense >=',
                                                     dateToCheck).fetch(1000)
        for expense in expenseOfTheYear:
            serializedList.append(expense.toDict)
        return self.respond(expenses=serializedList)
Beispiel #11
0
    def getExpenseThisWeek(self):
        import datetime
        from tuition.tools.models import Expenses
        from tuition.utils.manager import AppManager
        from tuition.utils.utils import weekStartEnd

        serializedObjects = []
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        startOfWeek = weekStartEnd().get('start')
        thisWeeksExpense = Expenses.all().filter(
            'user ='******'dateOfExpense >=',
                                           startOfWeek).order('-dateOfExpense')
        thisWeeksExpense = thisWeeksExpense.fetch(limit=1000)
        for expense in thisWeeksExpense:
            serializedObjects.append(expense.toDict)
        return self.respond(expenses=serializedObjects)
Beispiel #12
0
    def saveAnExpense(self, serializedFormValues):
        from tuition.utils.manager import AppManager
        from tuition.tools.forms import ExpenseForm
        from tuition.tools.models import Expenses

        form = ExpenseForm(data=serializedFormValues)
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        if form.is_valid():
            dictToSave = {
                'user': loggedInEmployee.key(),
                'type': form.cleaned_data['type'],
                'amount': form.cleaned_data['amount'],
                'dateOfExpense': form.cleaned_data['dateOfExpense'],
                'comments': form.cleaned_data['comments']
            }
            newExpense = Expenses(**dictToSave)
            return self.respond(isSaved=True,
                                savedExpenseKey=str(db.put(newExpense)))
        else:
            return self.respond(isSaved=False, errors=form.errors)
Beispiel #13
0
    def getExpenseThisMonth(self, values):
        import datetime
        from tuition.tools.models import Expenses
        from tuition.utils.manager import AppManager
        from tuition.utils.utils import getMonthEnd

        serializedObjects = []
        year = int(values.get('year', 2013))
        month = int(values.get('month', datetime.date.today().month))
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        firstOfMonth = datetime.date(year, month, 1)
        endOfMonth = datetime.date(year, month, getMonthEnd(month, year))
        thisMonthExpense = Expenses.all().filter(
            'user ='******'dateOfExpense >=',
                firstOfMonth).filter('dateOfExpense <=',
                                     endOfMonth).order('-dateOfExpense')
        thisMonthExpense = thisMonthExpense.fetch(limit=1000)
        for expense in thisMonthExpense:
            serializedObjects.append(expense.toDict)
        return self.respond(expenses=serializedObjects)
Beispiel #14
0
    def markDebtReturn(self, serializedFormValues):
        from tuition.tools.models import Expenses, Debt
        from tuition.tools.forms import DebtReturnForm
        from tuition.utils.manager import AppManager

        modelsToPut = []
        form = DebtReturnForm(data=serializedFormValues)
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        debt = Debt.get(serializedFormValues['key'])
        form.debtIncurredDate = debt.incurredDate
        if form.is_valid() and not debt.hasReturned:
            dictToSave = {
                'expenseOfMonth': form.cleaned_data['markAsExpense'],
                'hasReturned': True
            }
            for key, value in dictToSave.iteritems():
                setattr(debt, key, value)
            modelsToPut.append(debt)
            # we need to mark it as an expense of the given date.
            dictToSave = {
                'user': loggedInEmployee.key(),
                'type': 'Debt Return',
                'amount': debt.amount,
                'dateOfExpense': form.cleaned_data['markAsExpense'],
                'comments': form.cleaned_data['returnComments']
            }
            expense = Expenses(**dictToSave)
            modelsToPut.append(expense)
            savedDebtKey, savedExpenseKey = db.put(modelsToPut)
            return self.respond(isSaved=True,
                                savedDebtKey=str(savedDebtKey),
                                savedExpenseKey=str(savedExpenseKey),
                                savedDebt=debt.toDict)
        else:
            return self.respond(isSaved=False,
                                errors=form.errors,
                                debtAlreadyReturned=debt.hasReturned)