Example #1
0
def individual_pricing_desp(corp_membership):
    """
    Return the description of pricing for the individual memberships
    joining under this corp_membership.
    """
    description = ''
    if corp_membership:
        corporate_type = corp_membership.corporate_membership_type
        membership_type = corporate_type.membership_type
        admin_fee = membership_type.admin_fee
        if not admin_fee:
            admin_fee = 0

        if not (membership_type.price + admin_fee):
            membership_price = 'free'
        else:
            membership_price = tcurrency(membership_type.price)
            if membership_type.admin_fee:
                membership_price = '%s + %s' % (
                    membership_price, tcurrency(membership_type.admin_fee))

        threshold = corporate_type.apply_threshold
        threshold_limit = corporate_type.individual_threshold
        threshold_price = corporate_type.individual_threshold_price
        if not threshold_price:
            threshold_price = 'free'
        else:
            threshold_price = tcurrency(threshold_price)

        if threshold and threshold_limit > 0:
            description += 'first %d %s, ' % (threshold_limit, threshold_price)
            description += 'then %s ' % membership_price
        else:
            description += '%s ' % membership_price
    return description
Example #2
0
 def how_much_to_pay(self):
     if self.billing_frequency == 1:
         return '%s/%s' % (tcurrency(
             self.payment_amount), self.billing_period)
     else:
         return '%s/%d %ss' % (tcurrency(self.payment_amount),
                               self.billing_frequency, self.billing_period)
Example #3
0
        def add_pricing_fields(form, formforform):
            # include pricing options if any
            if (formforform.custom_payment or formforform.recurring_payment
                ) and formforform.pricing_set.all():

                currency_symbol = get_setting('site', 'global',
                                              'currencysymbol')

                pricing_options = []
                for pricing in formforform.pricing_set.all():

                    if pricing.price == None:
                        pricing_options.append((
                            pricing.pk,
                            mark_safe(
                                '<input type="text" class="custom-price" name="custom_price_%s" value="%s"/> <strong>%s</strong><br>%s'
                                %
                                (pricing.pk,
                                 form.data.get('custom_price_%s' % pricing.pk,
                                               unicode()), pricing.label,
                                 pricing.description))))
                    else:
                        if formforform.recurring_payment:
                            pricing_options.append(
                                (pricing.pk,
                                 mark_safe(
                                     '<strong>%s per %s %s - %s</strong><br>%s'
                                     % (tcurrency(pricing.price),
                                        pricing.billing_frequency,
                                        pricing.billing_period, pricing.label,
                                        pricing.description))))
                        else:
                            pricing_options.append(
                                (pricing.pk,
                                 mark_safe(
                                     '<strong>%s %s</strong><br>%s' %
                                     (tcurrency(pricing.price), pricing.label,
                                      pricing.description))))

                form.fields['pricing_option'] = forms.ChoiceField(
                    label=_('Pricing'),
                    choices=pricing_options,
                    widget=forms.RadioSelect(attrs={'class': 'pricing-field'}))

                form.fields['payment_option'] = forms.ModelChoiceField(
                    label=_('Payment Method'),
                    empty_label=None,
                    queryset=formforform.payment_methods.all(),
                    widget=forms.RadioSelect(attrs={'class': 'payment-field'}),
                    initial=1,
                )
Example #4
0
def get_corpmembership_type_choices(user, corpmembership_app, renew=False):
    cmt_list = []
    corporate_membership_types = corpmembership_app.corp_memb_type.all()

    if not user.profile.is_superuser:
        corporate_membership_types = corporate_membership_types.filter(admin_only=False)
    corporate_membership_types = corporate_membership_types.order_by('position')
    currency_symbol = get_setting("site", "global", "currencysymbol")

    for cmt in corporate_membership_types:
        if not renew:
            price_display = '%s - %s' % (cmt.name, tcurrency(cmt.price))
        else:
            indiv_renewal_price = cmt.membership_type.renewal_price
            if not indiv_renewal_price:
                indiv_renewal_price = 'Free<span class="type-ind-price"></span>'
            else:
                indiv_renewal_price = """
                    %s<span class="type-ind-price">%0.2f</span>
                    """ % (currency_symbol, indiv_renewal_price)
            if not cmt.renewal_price:
                cmt.renewal_price = 0

            price_display = """%s - <b>%s<span class="type-corp-price">%0.2f</span>
                            </b>(individual members:
                            <b>%s</b>)""" % (cmt.name,
                                            currency_symbol,
                                            cmt.renewal_price,
                                            indiv_renewal_price)
        price_display = mark_safe(price_display)
        cmt_list.append((cmt.id, price_display))

    return cmt_list
Example #5
0
def get_corpmembership_type_choices(user, corpmembership_app, renew=False):
    cmt_list = []
    corporate_membership_types = corpmembership_app.corp_memb_type.all()

    if not user.profile.is_superuser:
        corporate_membership_types = corporate_membership_types.filter(
            admin_only=False)
    corporate_membership_types = corporate_membership_types.order_by(
        'position')
    currency_symbol = get_setting("site", "global", "currencysymbol")

    for cmt in corporate_membership_types:
        if not renew:
            price_display = '%s - %s' % (cmt.name, tcurrency(cmt.price))
        else:
            indiv_renewal_price = cmt.membership_type.renewal_price
            if not indiv_renewal_price:
                indiv_renewal_price = 'Free<span class="type-ind-price"></span>'
            else:
                indiv_renewal_price = """
                    %s<span class="type-ind-price">%0.2f</span>
                    """ % (currency_symbol, indiv_renewal_price)
            if not cmt.renewal_price:
                cmt.renewal_price = 0

            price_display = """%s - <b>%s<span class="type-corp-price">%0.2f</span>
                            </b>(individual members:
                            <b>%s</b>)""" % (cmt.name, currency_symbol,
                                             cmt.renewal_price,
                                             indiv_renewal_price)
        price_display = mark_safe(price_display)
        cmt_list.append((cmt.id, price_display))

    return cmt_list
Example #6
0
def detail(request, id=None, template_name="donations/view.html"):
    donation = get_object_or_404(Donation, pk=id)
    if not has_perm(request.user, "donations.view_donation"):
        raise Http403

    EventLog.objects.log(instance=donation)

    donation.donation_amount = tcurrency(donation.donation_amount)
    return render_to_response(template_name, {"donation": donation}, context_instance=RequestContext(request))
Example #7
0
def view(request, id=None, template_name="make_payments/view.html"):
    mp = get_object_or_404(MakePayment, pk=id)
    if not mp.allow_view_by(request.user): raise Http403

    EventLog.objects.log(instance=mp)

    mp.payment_amount = tcurrency(mp.payment_amount)
    return render_to_response(template_name, {'mp': mp},
                              context_instance=RequestContext(request))
Example #8
0
def view(request, id=None, template_name="make_payments/view.html"):
    mp = get_object_or_404(MakePayment, pk=id)
    if not mp.allow_view_by(request.user): raise Http403

    EventLog.objects.log(instance=mp)

    mp.payment_amount = tcurrency(mp.payment_amount)
    return render_to_response(template_name, {'mp':mp},
        context_instance=RequestContext(request))
Example #9
0
def receipt(request, id, guid, template_name="donations/receipt.html"):
    donation = get_object_or_404(Donation, pk=id, guid=guid)

    donation.donation_amount = tcurrency(donation.donation_amount)

    EventLog.objects.log(instance=donation)

    if (not donation.invoice) or donation.invoice.balance > 0 or (not donation.invoice.is_tendered):
        template_name = "donations/view.html"
    return render_to_response(template_name, {"donation": donation}, context_instance=RequestContext(request))
Example #10
0
        def add_pricing_fields(form, formforform):
            # include pricing options if any
            if (formforform.custom_payment or formforform.recurring_payment) and formforform.pricing_set.all():

                currency_symbol = get_setting('site', 'global', 'currencysymbol')

                pricing_options = []
                for pricing in formforform.pricing_set.all():

                    if pricing.price == None:
                        pricing_options.append(
                            (pricing.pk, mark_safe(
                                '<input type="text" class="custom-price" name="custom_price_%s" value="%s"/> <strong>%s</strong><br>%s' %
                                (pricing.pk, form.data.get('custom_price_%s' %pricing.pk, unicode()), pricing.label, pricing.description)))
                        )
                    else:
                        if formforform.recurring_payment:
                            pricing_options.append(
                                (pricing.pk, mark_safe('<strong>%s per %s %s - %s</strong><br>%s' %
                                                        (tcurrency(pricing.price),
                                                         pricing.billing_frequency, pricing.billing_period,
                                                         pricing.label, pricing.description)))
                            )
                        else:
                            pricing_options.append(
                                (pricing.pk, mark_safe('<strong>%s %s</strong><br>%s' %
                                                       (tcurrency(pricing.price),
                                                        pricing.label, pricing.description)))
                            )

                form.fields['pricing_option'] = forms.ChoiceField(
                    label=_('Pricing'),
                    choices = pricing_options,
                    widget=forms.RadioSelect(attrs={'class': 'pricing-field'})
                )

                form.fields['payment_option'] = forms.ModelChoiceField(
                        label=_('Payment Method'),
                        empty_label=None,
                        queryset=formforform.payment_methods.all(),
                        widget=forms.RadioSelect(attrs={'class': 'payment-field'}),
                        initial=1,
                    )
Example #11
0
 def invoice_url(self, instance):
     invoice = instance.invoice
     if invoice:
         if invoice.balance > 0:
             return '<a href="%s">Invoice %s (%s)</a>' % (
                 invoice.get_absolute_url(), invoice.pk,
                 tcurrency(invoice.balance))
         else:
             return '<a href="%s">Invoice %s</a>' % (
                 invoice.get_absolute_url(), invoice.pk)
     return ""
def individual_pricing_desp(corp_membership):
    """
    Return the description of pricing for the individual memberships
    joining under this corp_membership.
    """
    description = ''
    if corp_membership:
        corporate_type = corp_membership.corporate_membership_type
        membership_type = corporate_type.membership_type
        admin_fee = membership_type.admin_fee
        if not admin_fee:
            admin_fee = 0

        if not (membership_type.price + admin_fee):
            membership_price = 'free'
        else:
            membership_price = tcurrency(membership_type.price)
            if membership_type.admin_fee:
                membership_price = '%s + %s' % (
                                    membership_price,
                                    tcurrency(membership_type.admin_fee))

        threshold = corporate_type.apply_threshold
        threshold_limit = corporate_type.individual_threshold
        threshold_price = corporate_type.individual_threshold_price
        if not threshold_price:
            threshold_price = 'free'
        else:
            threshold_price = tcurrency(threshold_price)

        if threshold and threshold_limit > 0:
            description += 'first %d %s, ' % (
                                    threshold_limit,
                                    threshold_price
                                    )
            description += 'then %s ' % membership_price
        else:
            description += '%s ' % membership_price
    return description
Example #13
0
 def get_invoice(self, instance):
     if instance.get_invoice():
         if instance.get_invoice().balance > 0:
             return '<a href="%s">Invoice %s (%s)</a>' % (
                 instance.get_invoice().get_absolute_url(),
                 instance.get_invoice().pk,
                 tcurrency(instance.get_invoice().balance),
             )
         else:
             return '<a href="%s">Invoice %s</a>' % (
                 instance.get_invoice().get_absolute_url(),
                 instance.get_invoice().pk,
             )
     return ""
Example #14
0
 def invoice_url(self, instance):
     invoice = instance.invoice
     if invoice:
         if invoice.balance > 0:
             return '<a href="%s">Invoice %s (%s)</a>' % (
                 invoice.get_absolute_url(),
                 invoice.pk,
                 tcurrency(invoice.balance)
             )
         else:
             return '<a href="%s">Invoice %s</a>' % (
                 invoice.get_absolute_url(),
                 invoice.pk
             )
     return ""
Example #15
0
def run_now(request):
    """Run a recurring payment.
    """
    rp_id = request.POST.get('rp_id')
    rp = get_object_or_404(RecurringPayment, pk=rp_id)

    result_data = {}
    result_data['processed'] = 'false'
    result_data['reason'] = 'done'

    payment_profiles = PaymentProfile.objects.filter(
        customer_profile_id=rp.customer_profile_id,
        status=True,
        status_detail='active').order_by('-update_dt')
    if not payment_profiles:
        valid_cpp_ids, invalid_cpp_ids = rp.populate_payment_profile()
        #print valid_cpp_ids, invalid_cpp_ids

        if valid_cpp_ids:
            payment_profiles = PaymentProfile.objects.filter(
                customer_profile_id=valid_cpp_ids[0])

    if not payment_profiles:
        result_data['reason'] = 'not setup'
    else:
        if rp.status_detail == 'active':
            num_processed = run_a_recurring_payment(rp)
            if num_processed:
                result_data['processed'] = 'true'
                result_data['reason'] = 'processed'
                # get total_paid and balance for this rp
                result_data['total_paid'] = str(rp.total_paid)
                result_data['balance'] = str(rp.get_outstanding_balance())

                # get total amount received for all rps
                d = RecurringPaymentInvoice.objects.filter(
                    invoice__balance=0, ).aggregate(
                        total_amount_received=Sum('invoice__total'))
                result_data['total_amount_received'] = d[
                    'total_amount_received']
                if not result_data['total_amount_received']:
                    result_data['total_amount_received'] = 0
                result_data['total_amount_received'] = tcurrency(
                    result_data['total_amount_received'])

    return HttpResponse(simplejson.dumps(result_data))
Example #16
0
def run_now(request):
    """Run a recurring payment.
    """
    rp_id = request.POST.get('rp_id')
    rp = get_object_or_404(RecurringPayment, pk=rp_id)
    
    result_data = {}
    result_data['processed'] = 'false'
    result_data['reason'] = 'done'
    
    payment_profiles = PaymentProfile.objects.filter(
                        customer_profile_id=rp.customer_profile_id,
                        status=True,
                        status_detail='active'
                        ).order_by('-update_dt')
    if not payment_profiles:
        valid_cpp_ids, invalid_cpp_ids = rp.populate_payment_profile()
        #print valid_cpp_ids, invalid_cpp_ids
        
        if valid_cpp_ids:
            payment_profiles = PaymentProfile.objects.filter(
                           customer_profile_id=valid_cpp_ids[0])        
                        
    if not payment_profiles:
        result_data['reason'] = 'not setup'
    else:
        if rp.status_detail == 'active':
            num_processed = run_a_recurring_payment(rp)
            if num_processed:
                result_data['processed'] = 'true'
                result_data['reason'] = 'processed'
                # get total_paid and balance for this rp
                result_data['total_paid'] = str(rp.total_paid)
                result_data['balance'] = str(rp.get_outstanding_balance())
                
                # get total amount received for all rps
                d = RecurringPaymentInvoice.objects.filter(
                                            invoice__balance=0,
                                            ).aggregate(total_amount_received=Sum('invoice__total'))
                result_data['total_amount_received'] = d['total_amount_received']
                if not result_data['total_amount_received']:
                    result_data['total_amount_received'] = 0
                result_data['total_amount_received'] = tcurrency(result_data['total_amount_received'])
                               
        
    return HttpResponse(simplejson.dumps(result_data))
Example #17
0
def format_currency(value):
    """format currency"""
    from tendenci.core.base.utils import tcurrency

    return tcurrency(value)
Example #18
0
def format_currency(value):
    """format currency"""
    from tendenci.core.base.utils import tcurrency
    return tcurrency(value)
Example #19
0
 def how_much_to_pay(self):
     if self.billing_frequency == 1:
         return '%s/%s' % (tcurrency(self.payment_amount), self.billing_period)
     else:
         return '%s/%d %ss' % (tcurrency(self.payment_amount), self.billing_frequency, self.billing_period)