コード例 #1
0
ファイル: routing_slip.py プロジェクト: stevenc987/sbc-pay
    def create_daily_reports(cls, date: str, **kwargs):
        """Create and return daily report for the day provided."""
        routing_slips: List[RoutingSlipModel] = RoutingSlipModel.search(
            dict(
                dateFilter=dict(
                    endDate=date,
                    startDate=date,
                    target='created_on'
                )
            ),
            page=1, limit=0, return_all=True
        )[0]

        total: float = 0
        no_of_cash: int = 0
        no_of_cheque: int = 0
        total_cash_usd: float = 0
        total_cheque_usd: float = 0
        total_cash_cad: float = 0
        total_cheque_cad: float = 0
        # TODO Only CAD supported now, so just add up the total.
        for routing_slip in routing_slips:
            total += float(routing_slip.total)
            if routing_slip.payment_account.payment_method == PaymentMethod.CASH.value:
                no_of_cash += 1
                # TODO check if the payment is CAD or USD.
                total_cash_cad += float(routing_slip.total)
                if routing_slip.total_usd is not None:
                    total_cash_usd += float(routing_slip.total_usd)
            else:
                no_of_cheque += 1
                total_cheque_cad += float(routing_slip.total)
                if routing_slip.total_usd is not None:
                    total_cheque_usd += float(routing_slip.total_usd)

        report_dict = dict(
            templateName='routing_slip_report',
            reportName=f'Routing-Slip-Daily-Report-{date}',
            templateVars=dict(
                day=date,
                reportDay=str(get_local_time(datetime.now())),
                total=total,
                numberOfCashReceipts=no_of_cash,
                numberOfChequeReceipts=no_of_cheque,
                totalCashInUsd=total_cash_usd,
                totalChequeInUsd=total_cheque_usd,
                totalCashInCad=total_cash_cad,
                totalChequeInCad=total_cheque_cad
            )
        )

        pdf_response = OAuthService.post(current_app.config.get('REPORT_API_BASE_URL'),
                                         kwargs['user'].bearer_token, AuthHeaderType.BEARER,
                                         ContentType.JSON, report_dict)

        return pdf_response, report_dict.get('reportName')
コード例 #2
0
    def find_accounts_settings_by_frequency(cls, valid_date: datetime, frequency: StatementFrequency):
        """Return active statement setting for the account."""
        valid_date = get_local_time(valid_date).date()
        query = db.session.query(StatementSettings, PaymentAccount).join(PaymentAccount)

        query = query.filter(StatementSettings.from_date <= valid_date). \
            filter((StatementSettings.to_date.is_(None)) | (StatementSettings.to_date >= valid_date)). \
            filter(StatementSettings.frequency == frequency.value)

        return query.all()
コード例 #3
0
    def find_active_settings(cls, auth_account_id: str, valid_date: datetime):
        """Return active statement setting for the account."""
        valid_date = get_local_time(valid_date)
        query = cls.query.join(PaymentAccount).filter(PaymentAccount.auth_account_id == auth_account_id)
        # need this to strip of the time information from the date
        todays_datetime = valid_date.today().date()
        query = query.filter(StatementSettings.from_date <= todays_datetime). \
            filter((StatementSettings.to_date.is_(None)) | (StatementSettings.to_date >= todays_datetime))

        return query.one_or_none()
コード例 #4
0
ファイル: statement_task.py プロジェクト: jeznorth/sbc-pay
    def generate_statements(cls):
        """Generate statements.
        Steps:
        1. Get all payment accounts and it's active statement settings.
        """
        current_time = get_local_time(datetime.now())
        # If today is sunday - generate all weekly statements for pervious week
        # If today is month beginning - generate all monthly statements for previous month
        # For every day generate all daily statements for previous day
        generate_weekly = current_time.weekday() == 6  # Sunday is 6
        generate_monthly = current_time.day == 1

        cls._generate_daily_statements(current_time)
        if generate_weekly:
            cls._generate_weekly_statements(current_time)
        if generate_monthly:
            cls._generate_monthly_statements(current_time)

        # Commit transaction
        db.session.commit()