Beispiel #1
0
def create_transaction_history_table_html(userprofile, date_start, date_end):
    transactions_all = Transaction.get_transactions_sorted_by_last_modified(userprofile.id)

    transactions_in_timerange = []
    for transaction in transactions_all:
        if (transaction.last_modified.date() > date_start) and (transaction.last_modified.date() < date_end + timedelta(1)):
            transactions_in_timerange.append(transaction)

    if not transactions_in_timerange:
        return ''
    transaction_table = '<table>'
    transaction_table += '<tr align=\'left\'>'
    transaction_table += '<th><b>&#8364;/pp</b></th>'
    transaction_table += '<th><b>&#8364;</b></th>'
    transaction_table += '<th><b>What</b></th>'
    transaction_table += '<th><b>Who</b></th>'
    transaction_table += '<th><b>Date</b></th>'
    for transaction in transactions_in_timerange:
        transaction_table += '<tr style="font-size: 12px">'
        transaction_table += '<td>&#8364;' + transaction.amount_per_person + '</td>'
        transaction_table += '<td>&#8364;' + '%.2f' % float(transaction.amount) + '</td>'
        transaction_table += '<td>' + transaction.what + '</td>'
        transaction_table += '<td>' + transaction.buyer.displayname + '</td>'
        transaction_table += '<td>' + transaction.date.strftime('%d %b') + '</td>'
        transaction_table += '</tr>'

    transaction_table += '</table>'
    return transaction_table
Beispiel #2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        user_profile = self.get_userprofile()

        group_accounts = user_profile.group_accounts.all()
        friends = UserProfile.objects.filter(
            group_accounts__in=group_accounts).distinct()

        transactions_all_sorted = Transaction.get_transactions_sorted_by_last_modified(
            user_profile.id)
        transactionsreal_all_sorted = TransactionReal.get_transactions_real_sorted_by_last_modified(
            user_profile.id)

        for group_account in group_accounts:
            GroupAccount.add_groupaccount_info(group_account, user_profile)

        my_total_balance_float = 0.0
        for group_account in group_accounts:
            my_total_balance_float += group_account.my_balance_float

        my_total_balance_str = '%.2f' % my_total_balance_float
        context['my_total_balance'] = my_total_balance_str
        context['my_total_balance_float'] = my_total_balance_float
        #     invitesAllSorted = GroupAccountInvite.get_invites_sorted_by_date(userProfile)
        slowlastn = 5
        #     context['invitesAll'] = invitesAllSorted[0:slowLastN]
        context['friends'] = friends
        context['transactions_all'] = transactions_all_sorted[0:slowlastn]
        context['transactionsreal_all'] = transactionsreal_all_sorted[
            0:slowlastn]
        context['groups'] = group_accounts
        context['homesection'] = True
        return context
Beispiel #3
0
def create_transaction_history_table_html(userprofile, date_start, date_end):
    transactions_all = Transaction.get_transactions_sorted_by_last_modified(
        userprofile.id)

    transactions_in_timerange = []
    for transaction in transactions_all:
        if (transaction.last_modified.date() > date_start) and (
                transaction.last_modified.date() < date_end + timedelta(1)):
            transactions_in_timerange.append(transaction)

    if not transactions_in_timerange:
        return ''
    transaction_table = '<table>'
    transaction_table += '<tr align=\'left\'>'
    transaction_table += '<th><b>&#8364;/pp</b></th>'
    transaction_table += '<th><b>&#8364;</b></th>'
    transaction_table += '<th><b>What</b></th>'
    transaction_table += '<th><b>Who</b></th>'
    transaction_table += '<th><b>Date</b></th>'
    for transaction in transactions_in_timerange:
        transaction_table += '<tr style="font-size: 12px">'
        transaction_table += '<td>&#8364;' + transaction.amount_per_person + '</td>'
        transaction_table += '<td>&#8364;' + '%.2f' % float(
            transaction.amount) + '</td>'
        transaction_table += '<td>' + transaction.what + '</td>'
        transaction_table += '<td>' + transaction.buyer.displayname + '</td>'
        transaction_table += '<td>' + transaction.date.strftime(
            '%d %b') + '</td>'
        transaction_table += '</tr>'

    transaction_table += '</table>'
    return transaction_table
Beispiel #4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        user_profile = self.get_userprofile()

        group_accounts = user_profile.group_accounts.all()
        friends = UserProfile.objects.filter(group_accounts__in=group_accounts).distinct()

        transactions_all_sorted = Transaction.get_transactions_sorted_by_last_modified(user_profile.id)
        transactionsreal_all_sorted = TransactionReal.get_transactions_real_sorted_by_last_modified(user_profile.id)

        for group_account in group_accounts:
            GroupAccount.add_groupaccount_info(group_account, user_profile)

        my_total_balance_float = 0.0
        for group_account in group_accounts:
            my_total_balance_float += group_account.my_balance_float

        my_total_balance_str = '%.2f' % my_total_balance_float
        context['my_total_balance'] = my_total_balance_str
        context['my_total_balance_float'] = my_total_balance_float
#     invitesAllSorted = GroupAccountInvite.get_invites_sorted_by_date(userProfile)
        slowlastn = 5
#     context['invitesAll'] = invitesAllSorted[0:slowLastN]
        context['friends'] = friends
        context['transactions_all'] = transactions_all_sorted[0:slowlastn]
        context['transactionsreal_all'] = transactionsreal_all_sorted[0:slowlastn]
        context['groups'] = group_accounts
        context['homesection'] = True
        return context
Beispiel #5
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        group_account_id = kwargs['groupaccount_id']
        group = GroupAccount.objects.get(id=group_account_id)
        group_users = UserProfile.objects.filter(group_accounts=group.id)
        if UserProfile.objects.get(user=self.request.user) not in group_users:
            return context

        for user in group_users:
            user.balance = UserProfile.get_balance(group.id, user.id)
            user.n_trans_buyer = Transaction.objects.filter(
                buyer=user, group_account=group).count()
            user.n_trans_consumer = Transaction.objects.filter(
                consumers=user, group_account=group).count()
            amount__sum = Transaction.get_buyer_transactions(user.id).filter(
                group_account=group).aggregate(Sum('amount'))['amount__sum']
            if amount__sum:
                user.total_bought = float(amount__sum)
            else:
                user.total_bought = 0.0
            consumer_transactions = Transaction.get_consumer_transactions(
                user.id).filter(group_account=group)
            total_consumed = 0.0
            for transaction in consumer_transactions:
                total_consumed += transaction.amount_per_person
            user.total_consumed = total_consumed

        total_consumed = 0.0
        total_bought = 0.0
        total_balance = 0.0
        total_shares = 0
        total_shared_with = 0
        for user in group_users:
            total_consumed += user.total_consumed
            total_bought += user.total_bought
            total_balance += user.balance
            total_shares += user.n_trans_buyer
            total_shared_with += user.n_trans_consumer
        context['users'] = group_users
        context['group_name'] = group.name
        context['total_consumed'] = total_consumed
        context['total_bought'] = total_bought
        context['total_balance'] = total_balance
        context['total_shares'] = total_shares
        context['total_shared_with'] = total_shared_with
        return context
Beispiel #6
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        group_account_id = kwargs['groupaccount_id']
        group = GroupAccount.objects.get(id=group_account_id)
        group_users = UserProfile.objects.filter(group_accounts=group.id)
        if UserProfile.objects.get(user=self.request.user) not in group_users:
            return context

        for user in group_users:
            user.balance = UserProfile.get_balance(group.id, user.id)
            user.n_trans_buyer = Transaction.objects.filter(buyer=user, group_account=group).count()
            user.n_trans_consumer = Transaction.objects.filter(consumers=user, group_account=group).count()
            amount__sum = Transaction.get_buyer_transactions(user.id).filter(group_account=group).aggregate(Sum('amount'))['amount__sum']
            if amount__sum:
                user.total_bought = float(amount__sum)
            else:
                user.total_bought = 0.0
            consumer_transactions = Transaction.get_consumer_transactions(user.id).filter(group_account=group)
            total_consumed = 0.0
            for transaction in consumer_transactions:
                total_consumed += transaction.amount_per_person
            user.total_consumed = total_consumed

        total_consumed = 0.0
        total_bought = 0.0
        total_balance = 0.0
        total_shares = 0
        total_shared_with = 0
        for user in group_users:
            total_consumed += user.total_consumed
            total_bought += user.total_bought
            total_balance += user.balance
            total_shares += user.n_trans_buyer
            total_shared_with += user.n_trans_consumer
        context['users'] = group_users
        context['group_name'] = group.name
        context['total_consumed'] = total_consumed
        context['total_bought'] = total_bought
        context['total_balance'] = total_balance
        context['total_shares'] = total_shares
        context['total_shared_with'] = total_shared_with
        return context
Beispiel #7
0
    def get_context_data(self, **kwargs):
        userprofile = UserProfile.objects.get(user=self.request.user)
        userprofile.get_show_table(self.kwargs['tableView'])
        context = super().get_context_data(**kwargs)
        transactions_all_sorted = Transaction.get_transactions_sorted_by_last_modified(userprofile.id)
        paginator = Paginator(transactions_all_sorted, 25)

        page = self.request.GET.get('page')
        try:
            transactions_all_sorted = paginator.page(page)
        except PageNotAnInteger:
            transactions_all_sorted = paginator.page(1)
        except EmptyPage:
            transactions_all_sorted = paginator.page(paginator.num_pages)
        context['transactions_all'] = transactions_all_sorted
        return context
Beispiel #8
0
    def get_context_data(self, **kwargs):
        userprofile = UserProfile.objects.get(user=self.request.user)
        userprofile.get_show_table(self.kwargs['tableView'])
        context = super().get_context_data(**kwargs)
        transactions_all_sorted = Transaction.get_transactions_sorted_by_last_modified(userprofile.id)
        paginator = Paginator(transactions_all_sorted, 25)

        page = self.request.GET.get('page')
        try:
            transactions_all_sorted = paginator.page(page)
        except PageNotAnInteger:
            transactions_all_sorted = paginator.page(1)
        except EmptyPage:
            transactions_all_sorted = paginator.page(paginator.num_pages)
        context['transactions_all'] = transactions_all_sorted
        return context
Beispiel #9
0
    def get_balance(group_account_id, user_profile_id):
        from care.transaction.models import Transaction
        from care.transaction.models import TransactionReal

        buyer_transactions = Transaction.objects.filter(
            group_account__id=group_account_id,
            buyer__id=user_profile_id
        )

        consumer_transactions = Transaction.get_consumer_transactions(
            user_profile_id, filters={'group_account_id': group_account_id}
        )

        sender_real_transactions = TransactionReal.get_transactions_real_sent(
                user_profile_id, {'group_account__id': group_account_id})

        receiver_real_transactions = TransactionReal.get_transactions_real_received(
            user_profile_id, {'group_account_id': group_account_id})

        total_bought = 0.0
        total_consumed = 0.0
        total_sent = 0.0
        total_received = 0.0

        amount__sum = buyer_transactions.aggregate(Sum('amount'))['amount__sum']
        if amount__sum:
            total_bought = float(amount__sum)

        amount__sum = sender_real_transactions.aggregate(Sum('amount'))['amount__sum']
        if amount__sum:
            total_sent = float(amount__sum)

        amount__sum = receiver_real_transactions.aggregate(Sum('amount'))['amount__sum']
        if amount__sum:
            total_received = float(amount__sum)

        amount_per_person__sum = (
            consumer_transactions.aggregate(Sum('amount_per_person_float'))
            ['amount_per_person_float__sum']
        )  # This is a negative number
        if amount_per_person__sum:
            total_consumed = - float(amount_per_person__sum)

        balance = (total_bought + total_sent - total_consumed - total_received)
        return balance