Example #1
0
def create_pdf_tickets_for_holder(order):
    """
    Create tickets and invoices for the holders of an order.
    :param order: The order for which to create tickets for.
    """
    if order.status == 'completed' or order.status == 'placed':
        pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html', order=order),
                              UPLOAD_PATHS['pdf']['tickets_all'],
                              dir_path='/static/uploads/pdf/tickets/', identifier=order.identifier, upload_dir='generated/tickets/')

        order.tickets_pdf_url = pdf

        for holder in order.ticket_holders:
            if (not holder.user) or holder.user.id != order.user_id:
                # holder is not the order buyer.
                pdf = create_save_pdf(render_template('pdf/ticket_attendee.html', order=order, holder=holder),
                                      UPLOAD_PATHS['pdf']['ticket_attendee'],
                                      dir_path='/static/uploads/pdf/tickets/', identifier=order.identifier, upload_dir='generated/tickets/')
            else:
                # holder is the order buyer.
                pdf = order.tickets_pdf_url
            holder.pdf_url = pdf
            save_to_db(holder)

        # create order invoices pdf
        order_tickets = OrderTicket.query.filter_by(order_id=order.id, deleted_at=None).all()

        create_save_pdf(render_template('pdf/order_invoice.html', order=order, event=order.event,
                        tax=order.event.tax, order_tickets=order_tickets),
                        UPLOAD_PATHS['pdf']['order'], dir_path='/static/uploads/pdf/tickets/',
                        identifier=order.identifier, upload_dir='generated/invoices/')
        save_to_db(order)
Example #2
0
def create_pdf_tickets_for_holder(order):
    """
    Create tickets for the holders of an order.
    :param order: The order for which to create tickets for.
    """
    if order.status == 'completed':
        pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html',
                                              order=order),
                              UPLOAD_PATHS['pdf']['ticket_attendee'],
                              dir_path='/static/uploads/pdf/tickets/')
        order.tickets_pdf_url = pdf

        for holder in order.ticket_holders:
            if (not holder.user) or holder.user.id != order.user_id:
                # holder is not the order buyer.
                pdf = create_save_pdf(render_template(
                    'pdf/ticket_attendee.html', order=order, holder=holder),
                                      UPLOAD_PATHS['pdf']['ticket_attendee'],
                                      dir_path='/static/uploads/pdf/tickets/')
            else:
                # holder is the order buyer.
                pdf = order.tickets_pdf_url
            holder.pdf_url = pdf
            save_to_db(holder)

        save_to_db(order)
Example #3
0
def create_pdf_tickets_for_holder(order):
    """
    Create tickets and invoices for the holders of an order.
    :param order: The order for which to create tickets for.
    """
    if order.status == 'completed' or order.status == 'placed':
        pdf = create_save_pdf(
            render_template('pdf/ticket_purchaser.html', order=order),
            UPLOAD_PATHS['pdf']['tickets_all'],
            dir_path='/static/uploads/pdf/tickets/',
            identifier=order.identifier,
            extra_identifiers={'extra_identifier': order.identifier},
            upload_dir='generated/tickets/',
        )

        order.tickets_pdf_url = pdf

        for holder in order.ticket_holders:
            # create attendee pdf for every ticket holder
            pdf = create_save_pdf(
                render_template('pdf/ticket_attendee.html',
                                order=order,
                                holder=holder),
                UPLOAD_PATHS['pdf']['tickets_all'],
                dir_path='/static/uploads/pdf/tickets/',
                identifier=order.identifier,
                extra_identifiers={'extra_identifier': holder.id},
                upload_dir='generated/tickets/',
            )
            holder.pdf_url = pdf
            save_to_db(holder)

        admin_info = Setting.query.first()

        # create order invoices pdf
        order_tickets = OrderTicket.query.filter_by(order_id=order.id).all()

        create_save_pdf(
            render_template(
                'pdf/order_invoice.html',
                order=order,
                event=order.event,
                tax=order.event.tax,
                order_tickets=order_tickets,
                admin_info=admin_info,
            ),
            UPLOAD_PATHS['pdf']['order'],
            dir_path='/static/uploads/pdf/tickets/',
            identifier=order.identifier,
            upload_dir='generated/invoices/',
            new_renderer=True,
        )
        save_to_db(order)
Example #4
0
def send_monthly_event_invoice():
    from app import current_app as app
    with app.app_context():
        events = Event.query.all()
        for event in events:
            # calculate net & gross revenues
            currency = event.payment_currency
            ticket_fee_object = db.session.query(TicketFees).filter_by(
                currency=currency).one()
            ticket_fee_percentage = ticket_fee_object.service_fee
            ticket_fee_maximum = ticket_fee_object.maximum_fee
            orders = Order.query.filter_by(event=event).all()
            gross_revenue = event.calc_monthly_revenue()
            ticket_fees = event.tickets_sold * ticket_fee_percentage
            if ticket_fees > ticket_fee_maximum:
                ticket_fees = ticket_fee_maximum
            net_revenue = gross_revenue - ticket_fees
            # save invoice as pdf
            pdf = create_save_pdf(
                render_template('pdf/event_invoice.html',
                                orders=orders,
                                ticket_fee_object=ticket_fee_object,
                                gross_revenue=gross_revenue,
                                net_revenue=net_revenue),
                UPLOAD_PATHS['pdf']['event_invoice'],
                dir_path='/static/uploads/pdf/event_invoices/',
                identifier=event.identifier)
            # save event_invoice info to DB

            event_invoice = EventInvoice(amount=net_revenue,
                                         invoice_pdf_url=pdf,
                                         event_id=event.id)
            save_to_db(event_invoice)
Example #5
0
def send_monthly_event_invoice():
    from app import current_app as app
    with app.app_context():
        events = Event.query.filter_by(deleted_at=None, state='published').all()
        for event in events:
            # calculate net & gross revenues
            user = event.owner
            admin_info = get_settings()
            currency = event.payment_currency
            ticket_fee_object = db.session.query(TicketFees).filter_by(currency=currency).one()
            ticket_fee_percentage = ticket_fee_object.service_fee
            ticket_fee_maximum = ticket_fee_object.maximum_fee
            orders = Order.query.filter_by(event=event).all()
            gross_revenue = event.calc_monthly_revenue()
            ticket_fees = event.tickets_sold * (ticket_fee_percentage / 100)
            if ticket_fees > ticket_fee_maximum:
                ticket_fees = ticket_fee_maximum
            net_revenue = gross_revenue - ticket_fees
            payment_details = {
                'tickets_sold': event.tickets_sold,
                'gross_revenue': gross_revenue,
                'net_revenue': net_revenue,
                'amount_payable': ticket_fees
            }
            # save invoice as pdf
            pdf = create_save_pdf(render_template('pdf/event_invoice.html', orders=orders, user=user,
                                  admin_info=admin_info, currency=currency, event=event,
                                  ticket_fee_object=ticket_fee_object, payment_details=payment_details,
                                  net_revenue=net_revenue), UPLOAD_PATHS['pdf']['event_invoice'],
                                  dir_path='/static/uploads/pdf/event_invoices/', identifier=event.identifier)
            # save event_invoice info to DB

            event_invoice = EventInvoice(amount=net_revenue, invoice_pdf_url=pdf, event_id=event.id)
            save_to_db(event_invoice)
    def after_create_object(self, order, data, view_kwargs):
        """
        after create object method for OrderListPost Class
        :param order:
        :param data:
        :param view_kwargs:
        :return:
        """
        order_tickets = {}
        for holder in order.ticket_holders:
            if holder.id != current_user.id:
                pdf = create_save_pdf(
                    render_template('/pdf/ticket_attendee.html',
                                    order=order,
                                    holder=holder))
            else:
                pdf = create_save_pdf(
                    render_template('/pdf/ticket_purchaser.html', order=order))
            holder.pdf_url = pdf
            save_to_db(holder)
            if order_tickets.get(holder.ticket_id) is None:
                order_tickets[holder.ticket_id] = 1
            else:
                order_tickets[holder.ticket_id] += 1
        for ticket in order_tickets:
            od = OrderTicket(order_id=order.id,
                             ticket_id=ticket,
                             quantity=order_tickets[ticket])
            save_to_db(od)
        order.quantity = order.get_tickets_count()
        save_to_db(order)
        if not has_access('is_coorganizer', event_id=data['event']):
            TicketingManager.calculate_update_amount(order)
        send_email_to_attendees(order, current_user.id)
        send_notif_to_attendees(order, current_user.id)

        order_url = make_frontend_url(path='/orders/{identifier}'.format(
            identifier=order.identifier))
        for organizer in order.event.organizers:
            send_notif_ticket_purchase_organizer(organizer,
                                                 order.invoice_number,
                                                 order_url, order.event.name)

        data['user_id'] = current_user.id
Example #7
0
def send_monthly_event_invoice():
    events = Event.query.filter_by(deleted_at=None, state='published').all()

    for event in events:
        # calculate net & gross revenues
        user = event.owner
        admin_info = get_settings()
        currency = event.payment_currency
        try:
            ticket_fee_object = (db.session.query(TicketFees).filter_by(
                currency=currency).one())
        except NoResultFound:
            logger.error(
                'Ticket Fee not found for event id {id}'.format(id=event.id))
            continue

        ticket_fee_percentage = ticket_fee_object.service_fee
        ticket_fee_maximum = ticket_fee_object.maximum_fee
        orders = Order.query.filter_by(event=event).all()
        gross_revenue = event.calc_monthly_revenue()
        invoice_amount = gross_revenue * (ticket_fee_percentage / 100)
        if invoice_amount > ticket_fee_maximum:
            invoice_amount = ticket_fee_maximum
        net_revenue = gross_revenue - invoice_amount
        payment_details = {
            'tickets_sold': event.tickets_sold,
            'gross_revenue': gross_revenue,
            'net_revenue': net_revenue,
            'amount_payable': invoice_amount,
        }
        # save invoice as pdf
        pdf = create_save_pdf(
            render_template(
                'pdf/event_invoice.html',
                orders=orders,
                user=user,
                admin_info=admin_info,
                currency=currency,
                event=event,
                ticket_fee_object=ticket_fee_object,
                payment_details=payment_details,
                net_revenue=net_revenue,
            ),
            UPLOAD_PATHS['pdf']['event_invoice'],
            dir_path='/static/uploads/pdf/event_invoices/',
            identifier=event.identifier,
        )
        # save event_invoice info to DB

        event_invoice = EventInvoice(amount=invoice_amount,
                                     invoice_pdf_url=pdf,
                                     event_id=event.id)
        save_to_db(event_invoice)
Example #8
0
def export_speakers_pdf_task(self, event_id):
    speakers = db.session.query(Speaker).filter_by(event_id=event_id)
    try:
        speakers_pdf_url = create_save_pdf(
            render_template('pdf/speakers_pdf.html', speakers=speakers),
            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id,
                                                       identifier=''))
        result = {'download_url': speakers_pdf_url}
    except Exception as e:
        result = {'__error': True, 'result': str(e)}
        logging.error('Error in exporting speakers as PDF')

    return result
Example #9
0
def export_attendees_pdf_task(self, event_id):
    attendees = db.session.query(TicketHolder).filter_by(event_id=event_id)
    try:
        attendees_pdf_url = create_save_pdf(
            render_template('pdf/attendees_pdf.html', holders=attendees),
            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id,
                                                       identifier=''))
        result = {'download_url': attendees_pdf_url}
    except Exception as e:
        result = {'__error': True, 'result': str(e)}
        logger.exception('Error in exporting attendees list as PDF')

    return result
Example #10
0
def export_speakers_pdf_task(self, event_id):
    speakers = db.session.query(Speaker).filter_by(event_id=event_id)
    try:
        speakers_pdf_url = create_save_pdf(
            render_template('pdf/speakers_pdf.html', speakers=speakers),
            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id, identifier=''))
        result = {
            'download_url': speakers_pdf_url
        }
    except Exception as e:
        print(traceback.format_exc())
        result = {'__error': True, 'result': str(e)}

    return result
Example #11
0
def export_sessions_pdf_task(self, event_id):
    sessions = db.session.query(Session).filter_by(event_id=event_id)
    try:
        sessions_pdf_url = create_save_pdf(
            render_template('pdf/sessions_pdf.html', sessions=sessions),
            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id, identifier=''))
        result = {
            'download_url': sessions_pdf_url
        }
    except Exception as e:
        print(traceback.format_exc())
        result = {'__error': True, 'result': str(e)}

    return result
Example #12
0
def create_pdf_tickets_for_holder(order):
    """
    Create tickets for the holders of an order.
    :param order: The order for which to create tickets for.
    """
    if order.status == 'completed':
        pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html', order=order),
                              UPLOAD_PATHS['pdf']['ticket_attendee'],
                              dir_path='/static/uploads/pdf/tickets/')
        order.tickets_pdf_url = pdf

        for holder in order.ticket_holders:
            if (not holder.user) or holder.user.id != order.user_id:
                # holder is not the order buyer.
                pdf = create_save_pdf(render_template('pdf/ticket_attendee.html', order=order, holder=holder),
                                      UPLOAD_PATHS['pdf']['ticket_attendee'],
                                      dir_path='/static/uploads/pdf/tickets/')
            else:
                # holder is the order buyer.
                pdf = order.tickets_pdf_url
            holder.pdf_url = pdf
            save_to_db(holder)

        save_to_db(order)
Example #13
0
def export_order_pdf_task(self, event_id):
    orders = db.session.query(Order).filter_by(event_id=event_id)
    event = db.session.query(Event).filter_by(id=int(event_id)).first()
    discount_code = db.session.query(DiscountCode).filter_by(event_id=event_id)
    try:
        order_pdf_url = create_save_pdf(
            render_template('pdf/orders.html', event=event, event_id=event_id, orders=orders,
                            discount_code=discount_code),
            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id, identifier=''))
        result = {
            'download_url': order_pdf_url
        }
    except Exception as e:
        print(traceback.format_exc())
        result = {'__error': True, 'result': str(e)}

    return result
Example #14
0
    def generate_pdf(self, force=False):
        with db.session.no_autoflush:
            latest_invoice_date = (EventInvoice.query.filter_by(
                event=self.event).filter(
                    EventInvoice.issued_at < self.issued_at).with_entities(
                        func.max(EventInvoice.issued_at)).scalar())

            admin_info = Setting.query.first()
            currency = self.event.payment_currency
            ticket_fee_object = (
                TicketFees.query.filter_by(
                    country=self.event.payment_country).first()
                or TicketFees.query.filter_by(country='global').first())
            if not ticket_fee_object:
                logger.error('Ticket Fee not found for event %s', self.event)
                return

            ticket_fee_percentage = ticket_fee_object.service_fee
            ticket_fee_maximum = ticket_fee_object.maximum_fee
            gross_revenue = self.event.calc_revenue(start=latest_invoice_date,
                                                    end=self.issued_at)
            invoice_amount = gross_revenue * (ticket_fee_percentage / 100)
            if invoice_amount > ticket_fee_maximum:
                invoice_amount = ticket_fee_maximum
            self.amount = round_money(invoice_amount)
            if not force and self.amount == 0:
                logger.warning(
                    'Invoice amount of Event %s is 0, hence skipping generation',
                    self.event,
                )
                return
            if not force and self.amount < EventInvoice.MIN_AMOUNT:
                logger.warning(
                    'Invoice amount of Event %s is %f which is less than %f, hence skipping generation',
                    self.event,
                    self.amount,
                    EventInvoice.MIN_AMOUNT,
                )
                return
            net_revenue = round_money(gross_revenue - invoice_amount)
            orders_query = self.event.get_orders_query(
                start=latest_invoice_date, end=self.issued_at)
            first_order_date = orders_query.with_entities(
                func.min(Order.completed_at)).scalar()
            last_order_date = orders_query.with_entities(
                func.max(Order.completed_at)).scalar()
            payment_details = {
                'tickets_sold': self.event.tickets_sold,
                'gross_revenue': round_money(gross_revenue),
                'net_revenue': round_money(net_revenue),
                'first_date': first_order_date or self.previous_month_date,
                'last_date': last_order_date or self.issued_at,
            }
            self.invoice_pdf_url = create_save_pdf(
                render_template(
                    'pdf/event_invoice.html',
                    user=self.user,
                    admin_info=admin_info,
                    currency=currency,
                    event=self.event,
                    ticket_fee=ticket_fee_object,
                    payment_details=payment_details,
                    net_revenue=net_revenue,
                    invoice=self,
                ),
                UPLOAD_PATHS['pdf']['event_invoice'],
                dir_path='/static/uploads/pdf/event_invoices/',
                identifier=self.identifier,
                extra_identifiers={'event_identifier': self.event.identifier},
                new_renderer=True,
            )

        return self.invoice_pdf_url
Example #15
0
def create_pdf_tickets_for_holder(order):
    """
    Create tickets and invoices for the holders of an order.
    :param order: The order for which to create tickets for.
    """
    starts_at = convert_to_user_locale(order.user.email,
                                       date_time=order.event.starts_at,
                                       tz=order.event.timezone)
    ends_at = convert_to_user_locale(order.user.email,
                                     date_time=order.event.ends_at,
                                     tz=order.event.timezone)
    admin_info = Setting.query.first()
    if order.status == 'completed' or order.status == 'placed':
        pdf = create_save_pdf(
            render_template(
                'pdf/ticket_purchaser.html',
                order=order,
                app_name=get_settings()['app_name'],
                admin_info=admin_info,
                starts_at=starts_at,
                ends_at=ends_at,
            ),
            UPLOAD_PATHS['pdf']['tickets_all'],
            dir_path='/static/uploads/pdf/tickets/',
            identifier=order.identifier,
            extra_identifiers={'extra_identifier': order.identifier},
            upload_dir='generated/tickets/',
        )

        order.tickets_pdf_url = pdf

        for holder in order.ticket_holders:
            starts_at = convert_to_user_locale(holder.email,
                                               date_time=order.event.starts_at,
                                               tz=order.event.timezone)
            ends_at = convert_to_user_locale(holder.email,
                                             date_time=order.event.ends_at,
                                             tz=order.event.timezone)

            # create attendee pdf for every ticket holder
            pdf = create_save_pdf(
                render_template(
                    'pdf/ticket_attendee.html',
                    order=order,
                    holder=holder,
                    app_name=get_settings()['app_name'],
                    admin_info=admin_info,
                    starts_at=starts_at,
                    ends_at=ends_at,
                ),
                UPLOAD_PATHS['pdf']['tickets_all'],
                dir_path='/static/uploads/pdf/tickets/',
                identifier=order.identifier,
                extra_identifiers={'extra_identifier': holder.id},
                upload_dir='generated/tickets/',
            )
            holder.pdf_url = pdf
            save_to_db(holder)

        # create order invoices pdf
        order_tickets = OrderTicket.query.filter_by(order_id=order.id).all()

        tickets = []
        for order_ticket in order_tickets:
            ticket = dict(
                id=order_ticket.ticket.id,
                price=order_ticket.price,
                quantity=order_ticket.quantity,
            )
            tickets.append(ticket)

        # calculate order amount using helper function
        order_amount = calculate_order_amount(
            tickets, discount_code=order.discount_code)

        create_save_pdf(
            render_template(
                'pdf/order_invoice.html',
                order=order,
                event=order.event,
                tax=order.event.tax,
                order_tickets=order_tickets,
                event_starts_at=convert_to_user_locale(
                    order.user.email,
                    date=order.event.starts_at_tz,
                ),
                created_at=convert_to_user_locale(
                    order.user.email,
                    date=order.created_at,
                ),
                admin_info=admin_info,
                order_amount=order_amount,
            ),
            UPLOAD_PATHS['pdf']['order'],
            dir_path='/static/uploads/pdf/tickets/',
            identifier=order.identifier,
            upload_dir='generated/invoices/',
            new_renderer=True,
        )
        save_to_db(order)