Пример #1
0
def calculate_earning(request):
    userprofile = Profile.objects.filter(user__is_active=True)

    earnDict = dict()

    for user in userprofile:

        profileArray = []
        levelDict = dict()
        level = 1
        total_earning = 0

        profileArray.append(user.id)

        general_methods.returnLevelTree(profileArray, levelDict, level)

        for i in range(7):
            total_earning = float(total_earning) + float(
                general_methods.calculate_earning(levelDict, i + 1))

        earnDict[user] = total_earning
Пример #2
0
def return_odenecekler(request):
    perm = general_methods.control_access(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    userprofile = Profile.objects.filter(user__is_active=True).exclude(
        user__groups__name="Admin")
    earnDict = dict()
    earningArray = []
    total = float(0.00)
    total_paid = 0
    not_paid = 0
    datetime_current = datetime.datetime.today()
    year = datetime_current.year
    month = datetime_current.month
    part = str(month) + "/" + str(year)
    total_paid = general_methods.monthlyTotalPaidByDate(str(month), str(year))
    for user in userprofile:

        profileArray = []
        levelDict = dict()
        level = 1
        total_earning = 0

        profileArray.append(user.id)

        general_methods.returnLevelTree(profileArray, levelDict, level)

        # for i in range(7):
        #   total_earning = float(total_earning) + float(general_methods.calculate_earning(levelDict, i + 1))

        order_total_member = general_methods.monthlyMemberOrderTotal(user, )

        total_earning = general_methods.calculate_earning_of_tree(
            levelDict, order_total_member)

        # earnDict[user] = total_earning
        # x = (total_earning * 100) / 118
        x = total_earning
        earnDict[user] = x - (x * 20 / 100)
        total_object = TotalOrderObject(profile=None,
                                        total_price=0,
                                        earning=0,
                                        is_paid=False,
                                        paid_date=None,
                                        tree_price=0,
                                        kdv_tree_price=0,
                                        income_tax_tree_price=0,
                                        total_earn_with_tax=0)
        total_object.profile = user
        total_object.earning = earnDict[user]
        total_object.total_price = order_total_member

        total_object.tree_price = total_earning
        # total_object.kdv_tree_price = total_earning - x
        total_object.income_tax_price = (x * 20 / 100)

        payment = earningPayments.objects.filter(profile=user, payedDate=part)
        if payment.count() > 0:
            total_object.is_paid = True
            total_object.paid_date = payment[0].creationDate

        earningArray.append(total_object)

    for key in earnDict:
        total = total + float(earnDict[key])

    if request.method == 'POST':
        userprofile = Profile.objects.filter(user__is_active=True).exclude(
            user__groups__name="Admin")
        earnDict = dict()
        earningArray = []
        total = 0
        total_paid = 0
        not_paid = 0

        total_paid = general_methods.monthlyTotalPaidByDate(
            request.POST['ay'], request.POST['yil'])

        part = request.POST['ay'] + "/" + request.POST['yil']

        for user in userprofile:

            profileArray = []
            levelDict = dict()
            level = 1
            total_earning = 0

            profileArray.append(user.id)

            general_methods.returnLevelTreeByDate(profileArray,
                                                  levelDict, level,
                                                  int(request.POST['ay']),
                                                  int(request.POST['yil']))

            # for i in range(7):
            #   total_earning = float(total_earning) + float(general_methods.calculate_earning(levelDict, i + 1))

            order_total_member = general_methods.monthlyMemberOrderTotalByDate(
                user, int(request.POST['ay']), int(request.POST['yil']))

            total_earning = general_methods.calculate_earning_of_tree(
                levelDict, order_total_member)

            # earnDict[user] = total_earning
            # x = (total_earning * 100) / 118
            x = total_earning
            earnDict[user] = x - (x * 20 / 100)
            total_object = TotalOrderObject(profile=None,
                                            total_price=0,
                                            earning=0,
                                            is_paid=False,
                                            paid_date=None,
                                            tree_price=0,
                                            kdv_tree_price=0,
                                            income_tax_tree_price=0,
                                            total_earn_with_tax=0)
            total_object.profile = user
            total_object.earning = earnDict[user]
            total_object.total_price = order_total_member
            total_object.tree_price = calculate_order_of_tree(levelDict)
            # total_object.kdv_tree_price = total_earning - x
            total_object.income_tax_price = (x * 20 / 100)
            total_object.total_earn_with_tax = total_earning

            payment = earningPayments.objects.filter(
                profile=user,
                payedDate=request.POST['ay'] + "/" + request.POST['yil'])
            if payment.count() > 0:
                total_object.is_paid = True
                total_object.paid_date = payment[0].creationDate

            earningArray.append(total_object)

        for key in earnDict:
            total = total + float(earnDict[key])

        return render(
            request, 'kazanclar/odenecekler.html', {
                "earnDict": earningArray,
                'total': total,
                'total_paid': total_paid,
                'not_paid': float(total) - float(total_paid),
                'part': part,
                'month': request.POST['ay'],
                'year': request.POST['yil']
            })

    return render(
        request, 'kazanclar/odenecekler.html', {
            "earnDict": earningArray,
            'total': total,
            'total_paid': total_paid,
            'not_paid': float(total) - float(total_paid),
            'part': part,
            'month': str(month),
            'year': str(year)
        })
Пример #3
0
def return_user_dashboard(request):
    perm = general_methods.control_access(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    current_user = request.user
    userprofile = Profile.objects.get(user=current_user)
    orders = Order.objects.filter(isApprove=True, profile_id=userprofile.id)
    my_orders = orders.count()

    onerilenler = Product.objects.filter(category=17)
    total_order_price = general_methods.monthlMemberOrderTotalAllTime(userprofile)['total_price']
    arrayUrun = []
    x = 0
    for order in orders:
        x = x + order.product.count()

    urun_miktar = x

    if total_order_price is None:
        total_order_price = 0

    products = OrderProduct.objects.values('product').annotate(count=Count('product')).order_by('-count')[:3]
    for products in products:
        urunDict = dict()
        urunDict['product'] = Product.objects.get(pk=products['product'])
        urunDict['count'] = products['count']
        arrayUrun.append(urunDict)

    profilList = []
    current_user = request.user
    total_earning = 0

    userprofile = Profile.objects.get(user=current_user)

    profileArray = []
    levelDict = dict()
    level = 1
    profileArray.append(userprofile.id)

    general_methods.returnLevelTree(profileArray, levelDict, level)

    for i in range(7):
        total_earning = float(total_earning) + float(general_methods.calculate_earning(levelDict, i + 1))

    x = general_methods.calculate_earning(levelDict, 2)

    # total_order = general_methods.monthlyMemberOrderTotal(userprofile)['total_price']
    total_order = general_methods.MemberAllOrderTotal(userprofile)['total_price']

    if total_order is None:
        total_order = 0

    total_order = str(float(str(total_order).replace(",", ".")))

    total = 0

    profilList.append(ProfileControlObject(profile=userprofile, is_controlled=False,
                                           total_order=total_order))

    trees = general_methods.rtrnProfileBySponsorID(profilList)



    levelDict2 = dict()

    profileArray =[]

    profileArray.append(userprofile.id)

    returnLevelTreeNewVersion(profileArray, levelDict2, 1)

    tree_order=calculate_order_of_tree(levelDict2)

    total_order_of_tree_all = tree_order['all_order']

    total_order_of_tree_monthly = tree_order['monthly_order']




    return render(request, 'dashboard/user-dashboard.html',
                  {'my_orders': my_orders, 'onerilenler': onerilenler,
                   'total_price': total_order_price, 'total_product': urun_miktar, 'coksatanlar': arrayUrun,'member_count':len(trees)-1,'total_order_all':total_order_of_tree_all,'total_order_monthly':total_order_of_tree_monthly})