Пример #1
0
    def void(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        if c.invoice.is_void():
            h.flash("Invoice was already voided.")
            return redirect_to(action='view', id=c.invoice.id)

        if h.auth.authorized(h.auth.has_organiser_role):
            c.invoice.void = "Administration Change"
            meta.Session.commit()
            h.flash("Invoice was voided.")
            return redirect_to(action='view', id=c.invoice.id)
        else:
            if c.invoice.paid():
                h.flash("Cannot void a paid invoice.")
                return redirect_to(action='view', id=c.invoice.id)
            c.invoice.void = "User cancellation"
            c.person = c.invoice.person
            meta.Session.commit()
            email(lca_info['contact_email'], render('/invoice/user_voided.mako'))
            h.flash("Previous invoice was voided.")
            return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
Пример #2
0
    def _new(self):
        results = self.form_result['invoice']
        del(results['item_count'])

        items = results['items']
        results['items'] = []
        c.invoice = Invoice(**results)

        for i in items:
            item = InvoiceItem()
            if i['description'] != "":
                item.description = i['description']
            else:
                product = Product.find_by_id(i['product'].id)
                category = product.category
                item.product = i['product']
                item.description = product.category.name + ' - ' + product.description
            item.cost = i['cost']
            item.qty = i['qty']
            c.invoice.items.append(item)

        c.invoice.manual = True
        c.invoice.void = None
        meta.Session.add(c.invoice)
        meta.Session.commit()

        h.flash("Manual invoice created")
        return redirect_to(action='view', id=c.invoice.id)
Пример #3
0
 def remind(self):
     c.invoice_collection = Invoice.find_all()
     #c.invoice = c.invoice_collection[0]
     #c.recipient = c.invoice.person
     # create dummy person for example:
     c.recipient = FakePerson()
     return render('/invoice/remind.mako')
Пример #4
0
    def pay(self, id):
        """Request confirmation from user
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person

        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        #return render('/registration/really_closed.mako')

        error = self._check_invoice(person, invoice)
        if error is not None:
            return error

        c.payment = Payment()
        c.payment.amount = invoice.total
        c.payment.invoice = invoice

        meta.Session.commit()
        if c.payment.gateway == 'securepay':
            return render("/invoice/securepay.mako")
        else:
            return render("/invoice/payment.mako")
Пример #5
0
    def refund(self, id):
        invoice = Invoice.find_by_id(id)
        try:
            c.invoice_person = invoice.person.id
        except:
            c.invoice_person = ''

        c.due_date = datetime.date.today().strftime("%d/%m/%Y")

        c.product_categories = ProductCategory.find_all()
        # The form adds one to the count by default, so we need to decrement it
        c.item_count = len(invoice.items) - 1

        defaults = dict()
        defaults['invoice.person'] = c.invoice_person
        defaults['invoice.due_date'] = c.due_date
        for i in range(len(invoice.items)):
            item = invoice.items[i]
            if item.product:
                defaults['invoice.items-' + str(i) +
                         '.product'] = item.product.id
            else:
                defaults['invoice.items-' + str(i) +
                         '.description'] = item.description
            defaults['invoice.items-' + str(i) + '.qty'] = -item.qty
            defaults['invoice.items-' + str(i) + '.cost'] = item.cost
        form = render("/invoice/new.mako")
        return htmlfill.render(form, defaults, use_all_keys=True)
Пример #6
0
    def void(self, id):
        if not h.auth.authorized(
                h.auth.Or(h.auth.is_same_zkpylons_attendee(id),
                          h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        if c.invoice.is_void:
            h.flash("Invoice was already voided.")
            return redirect_to(action='view', id=c.invoice.id)
        elif len(c.invoice.payment_received) and h.auth.authorized(
                h.auth.has_organiser_role):
            h.flash("Invoice has a payment applied to it, do you want to " +
                    h.link_to('Refund', h.url_for(action='refund')) +
                    " instead?")
            return redirect_to(action='view', id=c.invoice.id)
        elif len(c.invoice.payment_received):
            h.flash("Cannot void a paid invoice.")
            return redirect_to(action='view', id=c.invoice.id)
        elif h.auth.authorized(h.auth.has_organiser_role):
            c.invoice.void = "Administration Change"
            meta.Session.commit()
            h.flash("Invoice was voided.")
            return redirect_to(action='view', id=c.invoice.id)
        else:
            c.invoice.void = "User cancellation"
            c.person = c.invoice.person
            meta.Session.commit()
            email(lca_info['contact_email'],
                  render('/invoice/user_voided.mako'))
            h.flash("Previous invoice was voided.")
            return redirect_to(controller='registration',
                               action='pay',
                               id=c.person.registration.id)
Пример #7
0
 def unvoid(self, id):
     c.invoice = Invoice.find_by_id(id, True)
     c.invoice.void = None
     c.invoice.manual = True
     meta.Session.commit()
     h.flash("Invoice was un-voided.")
     return redirect_to(action='view', id=c.invoice.id)
Пример #8
0
 def unvoid(self, id):
     c.invoice = Invoice.find_by_id(id, True)
     c.invoice.void = None
     c.invoice.manual = True
     meta.Session.commit()
     h.flash("Invoice was un-voided.")
     return redirect_to(action='view', id=c.invoice.id)
Пример #9
0
    def check(self, app, environ, start_response):

        if not environ.get('REMOTE_USER'):
            set_redirect()
            raise NotAuthenticatedError('Not Authenticated')

        person = Person.find_by_email(environ['REMOTE_USER'])
        if person is None:
            environ['auth_failure'] = 'NO_USER'
            raise NotAuthorizedError(
                'You are not one of the users allowed to access this resource.'
            )

        invoice = Invoice.find_by_id(self.invoice_id)
        if invoice is None:
            raise NotAuthorizedError(
                "Invoice doesn't exist"
            )

        if person.id <> invoice.person_id:
            set_role("Invoice is not for this user")
            raise NotAuthorizedError(
                "Invoice is not for this user"
            )

        return app(environ, start_response)
Пример #10
0
 def get_invoice(self, id):
     """
     Returns a JSON representation of an existing invoice
     """
     invoice = Invoice.find_by_id(id, True)
     obj = {
         'id':
         invoice.id,
         'person_id':
         invoice.person_id,
         'manual':
         invoice.manual,
         'void':
         invoice.void,
         'issue_date':
         invoice.issue_date.strftime('%d/%m/%Y'),
         'due_date':
         invoice.due_date.strftime('%d/%m/%Y'),
         'items': [{
             'product_id': item.product_id,
             'description': item.description,
             'qty': item.qty,
             'cost': item.cost,
         } for item in invoice.items],
     }
     return dict(r=dict(invoice=obj))
Пример #11
0
    def refund(self, id):
        invoice = Invoice.find_by_id(id)
        try:
            c.invoice_person = invoice.person.id
        except:
            c.invoice_person = ''

        c.due_date = datetime.date.today().strftime("%d/%m/%Y")

        c.product_categories = ProductCategory.find_all()
        # The form adds one to the count by default, so we need to decrement it
        c.item_count = len(invoice.items) - 1

        defaults = dict()
        defaults['invoice.person' ] = c.invoice_person
        defaults['invoice.due_date'] = c.due_date
        for i in range(len(invoice.items)):
            item = invoice.items[i]
            if item.product:
                defaults['invoice.items-' + str(i) + '.product'] = item.product.id
            else:
                defaults['invoice.items-' + str(i) + '.description'] = item.description
            defaults['invoice.items-' + str(i) + '.qty'] = -item.qty
            defaults['invoice.items-' + str(i) + '.cost'] = item.cost
        form = render("/invoice/new.mako")
        return htmlfill.render(form, defaults, use_all_keys=True)
Пример #12
0
    def save_new_invoice(self):
        """
        """
        import json
        debug = ""
        data = request.params['invoice']
        data = json.loads(data)

        person_id = int(data['person_id'],10)
        due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y')

        invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None)
        for invoice_item in data['invoice_items']:
            item = InvoiceItem()

            if invoice_item.has_key('description') and invoice_item['description']:
                item.description = invoice_item['description']
            else:
                product = Product.find_by_id(invoice_item['product_id'])
                category = product.category
                item.product = product
                item.description = product.category.name + ' - ' + product.description

            item.cost = float(invoice_item['cost'])
            item.qty = int(invoice_item['qty'],10)
            invoice.items.append(item)

        meta.Session.add(invoice)
        meta.Session.commit()

        debug += str(invoice.id)
        return debug
Пример #13
0
    def _new(self):
        data = json.loads(request.params['invoice'])

        person_id = int(data['person_id'])
        due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y')

        invoice = Invoice(person_id=person_id,
                          due_date=due_date,
                          manual=True,
                          void=None)
        for item in data['items']:
            invoice_item = InvoiceItem()
            if item.has_key('product_id') and item['product_id']:
                product = Product.find_by_id(item['product_id'])
                category = product.category
                invoice_item.product = product
                invoice_item.description = product.category.name + ' - ' + product.description
            else:
                invoice_item.description = item['description']
            invoice_item.cost = int(item['cost'])
            invoice_item.qty = int(item['qty'])
            invoice.items.append(invoice_item)

        meta.Session.add(invoice)
        meta.Session.commit()

        return dict(r=dict(invoice_id=invoice.id))
Пример #14
0
    def void(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        if c.invoice.is_void:
            h.flash("Invoice was already voided.")
            return redirect_to(action='view', id=c.invoice.id)
        elif len(c.invoice.payment_received) and h.auth.authorized(h.auth.has_organiser_role):
            h.flash("Invoice has a payment applied to it, do you want to " + h.link_to('Refund', h.url_for(action='refund')) + " instead?")
            return redirect_to(action='view', id=c.invoice.id)
        elif len(c.invoice.payment_received):
            h.flash("Cannot void a paid invoice.")
            return redirect_to(action='view', id=c.invoice.id)
        elif h.auth.authorized(h.auth.has_organiser_role):
            c.invoice.void = "Administration Change"
            meta.Session.commit()
            h.flash("Invoice was voided.")
            return redirect_to(action='view', id=c.invoice.id)
        else:
            c.invoice.void = "User cancellation"
            c.person = c.invoice.person
            meta.Session.commit()
            email(Config.get('contact_email'), render('/invoice/user_voided.mako'))
            h.flash("Previous invoice was voided.")
            return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
Пример #15
0
    def pay(self, id):
        """Request confirmation from user
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person

        if not h.auth.authorized(
                h.auth.Or(h.auth.is_same_zkpylons_user(person.id),
                          h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        #return render('/registration/really_closed.mako')

        error = self._check_invoice(person, invoice)
        if error is not None:
            return error

        c.payment = Payment()
        c.payment.amount = invoice.total
        c.payment.invoice = invoice

        meta.Session.commit()
        if c.payment.gateway == 'securepay':
            return render("/invoice/securepay.mako")
        else:
            return render("/invoice/payment.mako")
Пример #16
0
 def extend(self, id):
     c.invoice = Invoice.find_by_id(id, True)
     if c.invoice.is_overdue:
         c.invoice.due_date = datetime.datetime.now() + datetime.timedelta(days=1)
     else:
         c.invoice.due_date = c.invoice.due_date + ((c.invoice.due_date - datetime.datetime.now()) * 2)
     meta.Session.commit()
     return redirect_to(action='view')
Пример #17
0
 def extend(self, id):
     c.invoice = Invoice.find_by_id(id, True)
     if c.invoice.is_overdue:
         c.invoice.due_date = datetime.datetime.now() + datetime.timedelta(days=1)
     else:
         c.invoice.due_date = c.invoice.due_date + ((c.invoice.due_date - datetime.datetime.now()) * 2)
     meta.Session.commit()
     return redirect_to(action='view')
Пример #18
0
    def pdf(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        xml_s = render('/invoice/pdf.mako')

        xsl_f = get_path('zk_root') + '/zkpylons/templates/invoice/pdf.xsl'
        pdf_data = pdfgen.generate_pdf(xml_s, xsl_f)

        filename = Config.get('event_shortname') + '_' + str(c.invoice.id) + '.pdf'
        return pdfgen.wrap_pdf_response(pdf_data, filename)
Пример #19
0
    def pdf(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        xml_s = render('/invoice/pdf.mako')

        xsl_f = file_paths['zk_root'] + '/zkpylons/templates/invoice/pdf.xsl'
        pdf_data = pdfgen.generate_pdf(xml_s, xsl_f)

        filename = lca_info['event_shortname'] + '_' + str(c.invoice.id) + '.pdf'
        return pdfgen.wrap_pdf_response(pdf_data, filename)
Пример #20
0
    def printable(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.printable = True
        c.invoice = Invoice.find_by_id(id, True)
        c.payment_received = None
        c.payment = None
        if c.invoice.is_paid and c.invoice.total > 0:
            c.payment_received = c.invoice.good_payments[0]
            c.payment = c.payment_received.payment
        return render('/invoice/view_printable.mako')
Пример #21
0
    def printable(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.printable = True
        c.invoice = Invoice.find_by_id(id, True)
        c.payment_received = None
        c.payment = None
        if c.invoice.is_paid and c.invoice.total > 0:
            c.payment_received = c.invoice.good_payments[0]
            c.payment = c.payment_received.payment
        return render('/invoice/view_printable.mako')
Пример #22
0
    def pdf(self, id):
        if not h.auth.authorized(
            h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())
        ):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        xml_s = render("/invoice/pdf.mako")

        xsl_f = file_paths["zk_root"] + "/zkpylons/templates/invoice/pdf.xsl"
        pdf_data = pdfgen.generate_pdf(xml_s, xsl_f)

        filename = lca_info["event_shortname"] + "_" + str(c.invoice.id) + ".pdf"
        return pdfgen.wrap_pdf_response(pdf_data, filename)
Пример #23
0
    def pay_manual(self, id):
        """Request confirmation from user
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person

        error = self._check_invoice(person, invoice, ignore_overdue=True)
        if error is not None:
            return error

        c.payment = Payment()
        c.payment.amount = invoice.total
        c.payment.invoice = invoice

        meta.Session.commit()
        return redirect_to(controller='payment', id=c.payment.id, action='new_manual')
Пример #24
0
    def pay_manual(self, id):
        """Request confirmation from user
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person

        error = self._check_invoice(person, invoice, ignore_overdue=True)
        if error is not None:
            return error

        c.payment = Payment()
        c.payment.amount = invoice.total
        c.payment.invoice = invoice

        meta.Session.commit()
        return redirect_to(controller='payment', id=c.payment.id, action='new_manual')
Пример #25
0
    def pdf(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        xml_s = render('/invoice/pdf.mako')

        template_path = file_paths['theme_templates'] + '/invoice/pdf.xsl'
        if(os.path.isfile(template_path)):
            xsl_f = template_path
        else:
            xsl_f = file_paths['zk_root'] + '/zkpylons/templates/invoice/pdf.xsl'
        pdf_data = pdfgen.generate_pdf(xml_s, xsl_f)

        filename = lca_info['event_shortname'] + '_' + str(c.invoice.id) + '.pdf'
        return pdfgen.wrap_pdf_response(pdf_data, filename)
Пример #26
0
 def get_invoice(self, id):
     """
     Returns a JSON representation of an existing invoice
     """
     invoice = Invoice.find_by_id(id, True)
     obj = {
         "id": invoice.id,
         "person_id": invoice.person_id,
         "manual": invoice.manual,
         "void": invoice.void,
         "issue_date": invoice.issue_date.strftime("%d/%m/%Y"),
         "due_date": invoice.due_date.strftime("%d/%m/%Y"),
         "items": [
             {"product_id": item.product_id, "description": item.description, "qty": item.qty, "cost": item.cost}
             for item in invoice.items
         ],
     }
     return dict(r=dict(invoice=obj))
Пример #27
0
 def get_invoice(self, id):
     """
     Returns a JSON representation of an existing invoice
     """
     invoice = Invoice.find_by_id(id, True)
     obj = {
         'id': invoice.id,
         'person_id': invoice.person_id,
         'manual': invoice.manual,
         'void': invoice.void,
         'issue_date': invoice.issue_date.strftime('%d/%m/%Y'),
         'due_date': invoice.due_date.strftime('%d/%m/%Y'),
         'items': [
             {
             'product_id': item.product_id,
             'description': item.description,
             'qty': item.qty,
             'cost': item.cost,
             } for item in invoice.items],
     }
     return dict(r=dict(invoice=obj))
Пример #28
0
    def pay_invoice(self):
        """
        Pay an invoice via the new angular.js interface

        Expects: and invoice_id. Assumes total amount is to be paid.

        TODO: Validation??
        """
        invoice_id = int(request.params['invoice'],10)
        invoice = Invoice.find_by_id(invoice_id, True)
        person = invoice.person

        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        payment = Payment()
        payment.amount = invoice.total
        payment.invoice = invoice

        payment_received = PaymentReceived(
                                    approved=True,
                                    payment=payment,
                                    invoice_id=invoice.id,
                                    success_code='0',
                                    amount_paid=payment.amount,
                                    currency_used='AUD',
                                    response_text='Approved',
                                    client_ip_zookeepr='127.1.0.1',
                                    client_ip_gateway='127.0.0.1',
                                    email_address=person.email_address,
                                    gateway_ref='Rego Desk Cash'
                    )

        meta.Session.add(payment)
        meta.Session.add(payment_received)
        meta.Session.commit()

        return "Payment recorded"
Пример #29
0
    def pay_invoice(self, id):
        """
        Pay an invoice via the new angular.js interface

        Expects: invoice_id. Assumes total amount is to be paid.

        TODO: Validation??
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person
        if not invoice.is_paid:
            payment = Payment()
            payment.amount = invoice.total
            payment.invoice = invoice

            payment_received = PaymentReceived(
                approved=True,
                payment=payment,
                invoice_id=invoice.id,
                success_code='0',
                amount_paid=payment.amount,
                currency_used='AUD',
                response_text='Approved',
                client_ip_zookeepr='127.1.0.1',
                client_ip_gateway='127.0.0.1',
                email_address=person.email_address,
                gateway_ref='Rego Desk Cash')

            meta.Session.add(payment)
            meta.Session.add(payment_received)
            meta.Session.commit()

            return dict(r=dict(message="Payment recorded"))
        else:
            return dict(r=dict(
                message="A payment has already been recorded for this invoice")
                        )
Пример #30
0
    def pay_invoice(self, id):
        """
        Pay an invoice via the new angular.js interface

        Expects: invoice_id. Assumes total amount is to be paid.

        TODO: Validation??
        """
        invoice = Invoice.find_by_id(id, True)
        person = invoice.person
        if not invoice.is_paid:
            payment = Payment()
            payment.amount = invoice.total
            payment.invoice = invoice

            payment_received = PaymentReceived(
                                        approved=True,
                                        payment=payment,
                                        invoice_id=invoice.id,
                                        success_code='0',
                                        amount_paid=payment.amount,
                                        currency_used='AUD',
                                        response_text='Approved',
                                        client_ip_zookeepr='127.1.0.1',
                                        client_ip_gateway='127.0.0.1',
                                        email_address=person.email_address,
                                        gateway_ref='Rego Desk Cash'
                        )

            meta.Session.add(payment)
            meta.Session.add(payment_received)
            meta.Session.commit()

            return dict(r=dict(message="Payment recorded"))
        else:
            return dict(r=dict(message="A payment has already been recorded for this invoice"))
Пример #31
0
 def _to_python(self, value, state):
     invoice = Invoice.find_by_id(int(value), False)
     if invoice is None:
         raise Invalid("Unknown invoice ID.", value, state)
     else:
         return invoice
Пример #32
0
    def index(self):
        c.can_edit = True
        c.invoice_collection = Invoice.find_all()

        return render('/invoice/list.mako')
Пример #33
0
 def _to_python(self, value, state):
     invoice = Invoice.find_by_id(int(value), False)
     if invoice is None:
         raise Invalid("Unknown invoice ID.", value, state)
     else:
         return invoice
Пример #34
0
    def index(self):
        c.can_edit = True
        c.invoice_collection = Invoice.find_all()

        return render('/invoice/list.mako')