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.object_content_type and self.object_content_type.name == 'Membership':
         return '--'
     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 how_much_to_pay(self):
     if self.object_content_type and self.object_content_type.name == 'Membership':
         return '--'
     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 #4
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 #5
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 is 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 #6
0
def get_corpmembership_type_choices(user,
                                    corpmembership_app,
                                    renew=False,
                                    exclude_list=None):
    cmt_list = []
    corporate_membership_types = corpmembership_app.corp_memb_type.all()
    if exclude_list:
        corporate_membership_types = corporate_membership_types.exclude(
            id__in=exclude_list)

    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 = '%s<span class="type-ind-price"></span>' % _(
                    'Free')
            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
            if cmt.apply_cap:
                indiv_renewal_price = '%s %s %s' % (
                    indiv_renewal_price, _('Limit'), cmt.membership_cap)
                if cmt.allow_above_cap:
                    indiv_renewal_price = '%s - then %s / member' % (
                        indiv_renewal_price, tcurrency(cmt.above_cap_price))

            data_cap = '\'{"apply_cap": "%s", "membership_cap":"%s", "allow_above_cap": "%s", "above_cap_price": "%s"}\'' % (
                cmt.apply_cap, cmt.membership_cap, cmt.allow_above_cap,
                cmt.above_cap_price)
            price_display = """%s - <b>%s<span class="type-corp-price">%0.2f</span>
                            </b>(individual members:
                            <b>%s</b>)<span class="type-cap" data-cap=%s></span>""" % (
                cmt.name, currency_symbol, cmt.renewal_price,
                indiv_renewal_price, data_cap)
        price_display = mark_safe(price_display)
        cmt_list.append((cmt.id, price_display))

    return cmt_list
Example #7
0
def get_corpmembership_type_choices(user, corpmembership_app, renew=False, exclude_list=None):
    cmt_list = []
    corporate_membership_types = corpmembership_app.corp_memb_type.all()
    if exclude_list:
        corporate_membership_types = corporate_membership_types.exclude(id__in=exclude_list)

    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 #8
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 #9
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 #10
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 #11
0
def detail(request, id=None, template_name="sponsorships/view.html"):
    sponsorship = get_object_or_404(Sponsorship, pk=id)
    if not has_perm(request.user,'sponsorships.view_sponsorship'): raise Http403

    EventLog.objects.log(instance=sponsorship)

    sponsorship.sponsorship_amount = tcurrency(sponsorship.sponsorship_amount)
    return render_to_response(template_name, {'sponsorship':sponsorship},
        context_instance=RequestContext(request))
Example #12
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 #13
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_resp(request=request, template_name=template_name,
        context={'mp':mp})
Example #14
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 #15
0
def get_corpmembership_type_choices(user, corpmembership_app, renew=False, exclude_list=None):
    cmt_list = []
    corporate_membership_types = corpmembership_app.corp_memb_type.all()
    if exclude_list:
        corporate_membership_types = corporate_membership_types.exclude(id__in=exclude_list)

    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 = '%s<span class="type-ind-price"></span>' % _('Free')
            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
            if cmt.apply_cap:
                indiv_renewal_price = '%s %s %s' % (indiv_renewal_price, _('Limit'), cmt.membership_cap)
                if cmt.allow_above_cap:
                    indiv_renewal_price = '%s - then %s / member' % (indiv_renewal_price,
                                                          tcurrency(cmt.above_cap_price))

            data_cap = '\'{"apply_cap": "%s", "membership_cap":"%s", "allow_above_cap": "%s", "above_cap_price": "%s"}\'' % (
                         cmt.apply_cap, cmt.membership_cap, cmt.allow_above_cap, cmt.above_cap_price)
            price_display = """%s - <b>%s<span class="type-corp-price">%0.2f</span>
                            </b>(individual members:
                            <b>%s</b>)<span class="type-cap" data-cap=%s></span>""" % (cmt.name,
                                            currency_symbol,
                                            cmt.renewal_price,
                                            indiv_renewal_price,
                                            data_cap)
        price_display = mark_safe(price_display)
        cmt_list.append((cmt.id, price_display))

    return cmt_list
Example #16
0
 def get_invoice(self, instance):
     inv = instance.get_invoice()
     if inv:
         if inv.balance > 0:
             return '<a href="%s" title="Invoice">#%s (%s)</a>' % (
                 inv.get_absolute_url(), inv.pk, tcurrency(inv.balance))
         else:
             return '<a href="%s" title="Invoice">#%s</a>' % (
                 inv.get_absolute_url(), inv.pk)
     return ""
Example #17
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 #18
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 #19
0
def receipt(request, id, guid, template_name="sponsorships/receipt.html"):
    sponsorship = get_object_or_404(Sponsorship, pk=id, guid=guid)

    sponsorship.sponsorship_amount = tcurrency(sponsorship.sponsorship_amount)

    EventLog.objects.log(instance=sponsorship)

    if (not sponsorship.invoice) or sponsorship.invoice.balance > 0 or (not sponsorship.invoice.is_tendered):
        template_name="sponsorships/view.html"
    return render_to_response(template_name, {'sponsorship':sponsorship},
        context_instance=RequestContext(request))
Example #20
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 #21
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.
    """
    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))

        return membership_price
    return ''
Example #23
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 ""
def individual_pricing_desp(corp_membership):
    """
    Return the description of pricing for the individual memberships
    joining under this corp_membership.
    """
    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))

        return membership_price
    return ''
Example #25
0
 def get_invoice(self, instance):
     inv = instance.get_invoice()
     if inv:
         if inv.balance > 0:
             return '<a href="%s" title="Invoice">#%s (%s)</a>' % (
                 inv.get_absolute_url(),
                 inv.pk,
                 tcurrency(inv.balance)
             )
         else:
             return '<a href="%s" title="Invoice">#%s</a>' % (
                 inv.get_absolute_url(),
                 inv.pk
             )
     return ""
Example #26
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 #27
0
def format_currency(value):
    """format currency"""
    from tendenci.apps.base.utils import tcurrency
    return tcurrency(value)
Example #28
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 #29
0
def format_currency(value):
    """format currency"""
    from tendenci.apps.base.utils import tcurrency
    return tcurrency(value)
Example #30
0
    def summary(self):
        field_map = {}
        for entry_field in self.entry_fields():
            form_field = self.form.fields.get(id=entry_field.field_id)
            vals = [p.strip() for p in form_field.summary_position.split(',')]

            if not vals[-1].isnumeric() or len(vals) > 2:
                fmt = vals.pop()
            else:
                fmt = ""

            if len(vals) == 1:
                row = 1
                col = int(vals[0]) if vals[0].isnumeric() else 0
            elif vals:
                row = int(vals[0]) if vals[0].isnumeric() else 0
                col = int(vals[1]) if vals[1].isnumeric() else 0
            else:
                row = col = 0  # Don't display this value

            if row and not (row in field_map):
                field_map[row] = {}

            if row and col:
                if fmt.startswith("$"):
                    try:
                        value = tcurrency(entry_field.value.strip())
                    except:
                        value = entry_field.value.strip()
                elif fmt.startswith("f"):
                    value = path.basename(entry_field.value)
                elif fmt.startswith("b"):
                    pfx = "NOT " if not entry_field.value else ""
                    value = f"{pfx}{entry_field.field.label}"
                elif fmt.startswith("w"):
                    if fmt[1:].isnumeric():
                        words = int(fmt[1:])
                        value = truncatewords(entry_field.value.strip(), words)
                else:
                    value = entry_field.value.strip()

                field_map[row][col] = value

        # If no field map is provided apply legacy format
        # entry_time followed by first 3 fields by position truncated to 2 words or basename if file field
        if not field_map:
            field_map[1] = {}
            field_map[1][1] = self.entry_time.strftime("%c")
            for i, entry_field in enumerate(self.entry_fields()[:3]):
                if entry_field.field.field_type == 'FileField':
                    field_map[1][i + 2] = path.basename(entry_field.value)
                else:
                    field_map[1][i + 2] = truncatewords(
                        entry_field.value.strip(), 2)

        # If row 1, col 1 is empty, put the entry_time there.
        elif not field_map.get(1, {}).get(1, None):
            if not 1 in field_map:
                field_map[1] = {}
            field_map[1][1] = self.entry_time.strftime("%c")

        rows = []
        for row in sorted(field_map.keys()):
            cols = []
            for col in sorted(field_map[row].keys()):
                cols.append(field_map[row][col])
            rows.append(" - ".join(cols))

        return rows