def get_price_per_month(self):
     if self.price_per_month is not None:
         if self.price_per_month == int(self.price_per_month):
             self.price_per_month = int(self.price_per_month)
         return sexify.sexy_number(self.price_per_month) + 'đ'
     else:
         return _('have not updated yet')
 def get_price_per_lesson(self):
     if self.price_per_lesson is not None:
         if self.price_per_lesson == int(self.price_per_lesson):
             self.price_per_lesson = int(self.price_per_lesson)
         return sexify.sexy_number(self.price_per_lesson) + 'đ'
     else:
         return _('have not updated yet')
 def get_payment_status(self):
     if self.card_type.form_of_using == FOR_TRAINING_COURSE:
         total_amount = self.yogaclass.get_price_for_training_course()
         if self.yogaclass.payment_periods.all().count() == 0:
             for invoice in self.invoices.all():
                 if invoice.is_charged() is False:
                     return 'Chưa thanh toán'
             return 'Đã thanh toán'
         else:
             result = ''
             for invoice in self.invoices.all():
                 if invoice.is_charged() is True:
                     if invoice.amount == total_amount:
                         return 'Đã thanh toán'
                     else:
                         result += '\n'
                         result += 'Đã thanh toán' + ': ' + \
                             invoice.payment_period.name + \
                             '(' + str(sexify.sexy_number(invoice.payment_period.amount)) + 'đ)'
             if result == '':
                 return 'Chưa thanh toán'
             else:
                 return result
     else:
         for invoice in self.invoices.all():
             if invoice.is_charged() is False:
                 return 'Chưa thanh toán'
         return 'Đã thanh toán'
 def get_price_for_training_class(self):
     if self.price_for_training_class is not None:
         if self.price_for_training_class == int(
                 self.price_for_training_class):
             self.price_for_training_class = int(
                 self.price_for_training_class)
         return sexify.sexy_number(self.price_for_training_class) + 'đ'
     else:
         return _('have not updated yet')
Exemple #5
0
 def full_title(self):
     if self.category == CASH_PROMOTION:
         return 'Khuyến mãi giảm ' + str(sexify.sexy_number(
             self.value)) + 'đ'
     elif self.category == FREE_SOME_LESSON_PROMOTION:
         return 'Khuyến mãi tặng tiền miễn phí ' + str(
             sexify.sexy_number(self.value)) + ' buổi tập'
     elif self.category == PLUS_MONTH_PRACTICE_PROMOTION:
         return 'Khuyến mãi tặng thêm ' + str(
             sexify.sexy_number(self.value)) + ' tháng tập'
     elif self.category == GIFT_PROMOTION:
         pos = -1
         s = 'Khuyến mãi tặng sản phẩm: '
         promotion_type_products = self.promotion_type_products.all()
         for p in promotion_type_products:
             pos += 1
             if pos == len(promotion_type_products) - 1:
                 s += str(p.quantity) + ' ' + p.product.name + '.'
             else:
                 s += str(p.quantity) + ' ' + p.product.name + ', '
         return s
     else:
         return 'Khuyến mãi giảm ' + str(sexify.sexy_number(
             self.value)) + '%'
Exemple #6
0
 def get(self, request, slug):
     if request.session.get('dashboard_card_form'):
         yoga_class = YogaClass.objects.get(slug=slug)
         dashboard_card_form = request.session['dashboard_card_form']
         trainee = get_object_or_404(
             Trainee, pk=dashboard_card_form['trainee'])
         lesson_list = self.__lesson_list_available(
             yoga_class, dashboard_card_form)
         card_type = CardType.objects.get(
             pk=dashboard_card_form['card_type'])
         price = get_price(yoga_class, card_type)
         total_price = get_total_price(
             yoga_class, card_type, lesson_list.count())
         total_price_display = get_total_price_display(total_price)
         context = {
             'yoga_class': yoga_class,
             'trainee': trainee,
             'card_type': card_type,
             'lesson_list': lesson_list,
             'price': price,
             'total_price_display': total_price_display,
             'total_price': total_price,
             'active_nav': 'cards',
             'show_nav': True,
             'FOR_FULL_MONTH': FOR_FULL_MONTH,
             'FOR_PERIOD_TIME_LESSONS': FOR_PERIOD_TIME_LESSONS,
             'FOR_SOME_LESSONS': FOR_SOME_LESSONS,
             'FOR_TRIAL': FOR_TRIAL,
             'FOR_TRAINING_COURSE': FOR_TRAINING_COURSE
         }
         # PROMOTION
         promotion_type = None
         promotion_code = None
         promotion_val = 'không'
         amount = total_price
         if request.session.get('dashboard_promotion_code') and request.session.get('dashboard_promotion_type'):
             # get promotion type
             promotion_type = get_object_or_404(
                 PromotionType, pk=request.session.get('dashboard_promotion_type'))
             # get promotion code
             promotion_code = get_object_or_404(
                 PromotionCode, pk=request.session.get('dashboard_promotion_code'))
             value = int(promotion_type.value)
             if promotion_type.category == CASH_PROMOTION:
                 amount -= value
                 promotion_val = '-' + \
                     sexify.sexy_number(value) + 'đ'
             elif promotion_type.category == PERCENT_PROMOTION:
                 amount -= value*amount/100
                 promotion_val = '-' + \
                     sexify.sexy_number(value*amount) + 'đ'
             elif promotion_type.category == FREE_SOME_LESSON_PROMOTION:
                 promotion_lessons = yoga_class.lessons.filter(
                     date__gt=lesson_list.last().date, is_full=False).order_by('date')[:value]
                 context['promotion_lessons'] = promotion_lessons
             elif promotion_type.category == PLUS_MONTH_PRACTICE_PROMOTION:
                 s = lesson_list.last().date
                 promotion_lessons = yoga_class.lessons.filter(
                     date__gt=s, date__lte=s + relativedelta(months=value), is_full=False).order_by('date')
                 context['promotion_lessons'] = promotion_lessons
             else:
                 promotion_val = promotion_type.full_title
         amount_display = sexify.sexy_number(amount)
         context['dashboard_promotion_type'] = promotion_type
         context['dashboard_promotion_code'] = promotion_code
         context['dashboard_promotion_val'] = promotion_val
         context['amount'] = amount
         context['amount_display'] = amount_display
         return render(request, self.template_name, context=context)
     else:
         messages.error(request, _(
             'Dont have any info about card. Please try again'))
         return redirect('dashboard:cards-new-for-class', slug=slug)
Exemple #7
0
def get_total_price_display(total_price):
    if total_price > 0:
        return sexify.sexy_number(total_price)
    else:
        return _('Free')
Exemple #8
0
    def get(self, request, slug):
        if request.session.get('enroll_card_form'):
            yoga_class = YogaClass.objects.get(slug=slug)
            enroll_card_form = request.session['enroll_card_form']
            card_type = CardType.objects.get(pk=enroll_card_form['card_type'])
            lesson_list = self.__lesson_list_available(yoga_class,
                                                       enroll_card_form)
            # NOTE: check da dang ky buoi tap
            for l in lesson_list:
                if l.roll_calls.filter(
                        card__trainee=request.user.trainee).count() > 0:
                    messages.error(
                        request,
                        _('You have card including one of your choosen lesson list. Please check your card.'
                          ))
                    return redirect('classes:enroll', slug=slug)
            # Payment Form
            form = CardPaymentForm()
            form.fields['name'].initial = request.user.full_name()
            form.fields['email'].initial = request.user.email
            form.fields['phone'].initial = request.user.phone_number
            context = {
                'key': settings.STRIPE_PUBLISHABLE_KEY,
                'form': form,
                'yoga_class': yoga_class,
                'card_type': card_type,
                'lesson_list': lesson_list,
                'active_nav': 'classes',
                'FOR_TRAINING_COURSE': FOR_TRAINING_COURSE
            }
            # NOTE: total_price is price with out promotion
            # NOTE: price is price of one lesson
            if card_type.form_of_using == FOR_TRAINING_COURSE:
                payment_period = None
                if int(enroll_card_form['payment_period']) == 0:
                    total_price = get_price(yoga_class, card_type)
                else:
                    payment_period = yoga_class.payment_periods.all().get(
                        pk=int(enroll_card_form['payment_period']))
                    total_price = payment_period.amount
                context['total_price'] = total_price
                context['payment_period'] = payment_period
            elif card_type.form_of_using == FOR_FULL_MONTH:
                temp_cleaned_data = CardFormForTraineeEnroll(
                    enroll_card_form).cleaned_data
                start_month = temp_cleaned_data['start_at']
                end_month = start_month + relativedelta(months=1)
                number_of_lesson_in_month = yoga_class.lessons.filter(
                    date__range=[start_month, end_month],
                    is_full=False).order_by('date').count()
                price = round(yoga_class.get_price_per_month() /
                              number_of_lesson_in_month / 1000) * 1000
                if lesson_list.count() == number_of_lesson_in_month:
                    total_price = yoga_class.get_price_per_month()
                else:
                    total_price = price * lesson_list.count()
                context['price'] = price
                context['total_price'] = total_price
            else:
                price = get_price(yoga_class, card_type)
                total_price = get_total_price(yoga_class, card_type,
                                              lesson_list.count())
                context['price'] = price
                context['total_price'] = total_price
            # PROMOTION
            promotion_type = None
            promotion_code = None
            promotion_val = 'không'
            amount = total_price
            if request.session.get('promotion_code') and request.session.get(
                    'promotion_type'):
                # get promotion type
                promotion_type = get_object_or_404(
                    PromotionType, pk=request.session.get('promotion_type'))
                # get promotion code
                promotion_code = get_object_or_404(
                    PromotionCode, pk=request.session.get('promotion_code'))
                value = int(promotion_type.value)
                if promotion_type.category == CASH_PROMOTION:
                    amount -= value
                    promotion_val = '-' + \
                                    sexify.sexy_number(value) + 'đ'
                elif promotion_type.category == PERCENT_PROMOTION:
                    reduce = round(value * amount / 100 / 1000) * 1000
                    amount -= reduce
                    promotion_val = '-' + \
                                    sexify.sexy_number(reduce) + 'đ'
                elif promotion_type.category == FREE_SOME_LESSON_PROMOTION:
                    amount -= value * price
                    promotion_val = '-' + \
                                    sexify.sexy_number(value * price) + 'đ'
                elif promotion_type.category == PLUS_MONTH_PRACTICE_PROMOTION:
                    s = lesson_list.last().date
                    promotion_lessons = yoga_class.lessons.filter(
                        date__gt=s,
                        date__lte=s + relativedelta(months=value),
                        is_full=False).order_by('date')
                    context['promotion_lessons'] = promotion_lessons
                else:
                    promotion_val = promotion_type.full_title
            amount_display = sexify.sexy_number(amount)

            context['promotion_type'] = promotion_type
            context['promotion_code'] = promotion_code
            context['promotion_val'] = promotion_val
            context['amount'] = amount
            context['amount_display'] = amount_display
            return render(request, self.template_name, context=context)
        else:
            messages.error(
                request,
                _('You dont have any info to payment. Please try again'))
            return redirect('classes:enroll', slug=slug)