Пример #1
0
    def get(self, request, *args, **kwargs):
        fiscal_period_year = request.GET.get('fiscal_period_year')

        fiscal_period_month = request.GET.get('fiscal_period_month')

        type_policy_array = get_array_or_none(
            request.GET.get('type_policy_array'))

        lower_folio = request.GET.get('lower_folio')
        upper_folio = request.GET.get('upper_folio')

        lower_registry_date = Utilities.string_to_date(
            request.GET.get('lower_registry_date'))
        upper_registry_date = Utilities.string_to_date(
            request.GET.get('upper_registry_date'))

        description = request.GET.get('description')

        lower_account_number = request.GET.get('lower_account_number')
        upper_account_number = request.GET.get('upper_account_number')

        lower_debit = request.GET.get('lower_debit')
        upper_debit = request.GET.get('upper_debit')

        lower_credit = request.GET.get('lower_credit')
        upper_credit = request.GET.get('upper_credit')

        reference = request.GET.get('reference')

        internal_company = request.GET.get('internal_company')

        report_title = request.GET.get('report_title')

        # If the account number is set, the range is ignored.
        account_number_array = get_array_or_none(request.GET.get('account'))

        engine = TransactionsEngine(fiscal_period_year=fiscal_period_year,
                                    fiscal_period_month=fiscal_period_month,
                                    type_policy_array=type_policy_array,
                                    lower_folio=lower_folio,
                                    upper_folio=upper_folio,
                                    lower_registry_date=lower_registry_date,
                                    upper_registry_date=upper_registry_date,
                                    description=description,
                                    lower_account_number=lower_account_number,
                                    upper_account_number=upper_account_number,
                                    lower_debit=lower_debit,
                                    upper_debit=upper_debit,
                                    lower_credit=lower_credit,
                                    upper_credit=upper_credit,
                                    reference=reference,
                                    only_with_transactions=False,
                                    account_array=account_number_array,
                                    internal_company=internal_company)

        transactions_set = engine.search_transactions()

        # Getting the account number.
        account_number = account_number_array[0]

        # Getting the account object.
        account_object = Account.objects.get(number=account_number)

        # Creating the general structure for the response.
        general_structure = self.create_general_structure(
            report_title, fiscal_period_year, fiscal_period_month,
            account_object)

        # Accumulated amounts.
        total_debit = 0
        total_credit = 0

        # Creating the structure for each of the accounts.
        for transaction in transactions_set:
            total_debit += transaction.debit
            total_credit += transaction.credit
            transaction_structure = self.create_transaction_structure(
                transaction)
            general_structure['transactions'].append(transaction_structure)

        # Assigning the accumulated amounts.
        general_structure['total_debit'] = total_debit
        general_structure['total_credit'] = total_credit

        return engine.generate_report(general_structure)
Пример #2
0
    def get(self, request, *args, **kwargs):
        fiscal_period_year = request.GET.get('fiscal_period_year')

        fiscal_period_month = request.GET.get('fiscal_period_month')

        type_policy_array = get_array_or_none(
            request.GET.get('type_policy_array'))

        lower_folio = request.GET.get('lower_folio')
        upper_folio = request.GET.get('upper_folio')

        lower_registry_date = Utilities.string_to_date(
            request.GET.get('lower_registry_date'))
        upper_registry_date = Utilities.string_to_date(
            request.GET.get('upper_registry_date'))

        description = request.GET.get('description')

        lower_account_number = request.GET.get('lower_account_number')
        upper_account_number = request.GET.get('upper_account_number')

        lower_debit = request.GET.get('lower_debit')
        upper_debit = request.GET.get('upper_debit')

        lower_credit = request.GET.get('lower_credit')
        upper_credit = request.GET.get('upper_credit')

        reference = request.GET.get('reference')

        internal_company = request.GET.get('internal_company')

        # If the account number is set, the range is ignored.
        account_number_array = get_array_or_none(request.GET.get('account'))

        engine = TransactionsEngine(fiscal_period_year=fiscal_period_year,
                                    fiscal_period_month=fiscal_period_month,
                                    type_policy_array=type_policy_array,
                                    lower_folio=lower_folio,
                                    upper_folio=upper_folio,
                                    lower_registry_date=lower_registry_date,
                                    upper_registry_date=upper_registry_date,
                                    description=description,
                                    lower_account_number=lower_account_number,
                                    upper_account_number=upper_account_number,
                                    lower_debit=lower_debit,
                                    upper_debit=upper_debit,
                                    lower_credit=lower_credit,
                                    upper_credit=upper_credit,
                                    reference=reference,
                                    only_with_transactions=False,
                                    account_array=account_number_array,
                                    internal_company=internal_company)

        transactions = engine.search_transactions()

        # Grouping all the transactions by accounts.
        grouped_transactions = self.group_transactions_by_account(transactions)

        # Excluding the accounts that overpass the debit limits.
        grouped_transactions = self.exclude_debit_limits(
            lower_debit, upper_debit, grouped_transactions)

        # Excluding the accounts that overpass the credit limits.
        grouped_transactions = self.exclude_credit_limits(
            lower_credit, upper_credit, grouped_transactions)

        response = {'accounts': []}

        for account in grouped_transactions:
            response['accounts'].append({
                'account_id':
                account['account__id'],
                'account_name':
                account['account__name'],
                'account_number':
                str(account['account__number']),
                'total_credit':
                account['total_credit'],
                'total_debit':
                account['total_debit']
            })

        return HttpResponse(
            Utilities.json_to_dumps(response),
            'application/json; charset=utf-8',
        )
Пример #3
0
    def get(self, request):
        lower_fiscal_period_year = request.GET.get('lower_fiscal_period_year')
        upper_fiscal_period_year = request.GET.get('upper_fiscal_period_year')

        lower_fiscal_period_month = request.GET.get(
            'lower_fiscal_period_month')
        upper_fiscal_period_month = request.GET.get(
            'upper_fiscal_period_month')

        type_policy_array = get_array_or_none(
            request.GET.get('type_policy_array'))

        lower_folio = request.GET.get('lower_folio')
        upper_folio = request.GET.get('upper_folio')

        lower_registry_date = Utilities.string_to_date(
            request.GET.get('lower_registry_date'))
        upper_registry_date = Utilities.string_to_date(
            request.GET.get('upper_registry_date'))

        description = request.GET.get('description')

        lower_account_number = request.GET.get('lower_account_number')
        upper_account_number = request.GET.get('upper_account_number')

        lower_debit = request.GET.get('lower_debit')
        upper_debit = request.GET.get('upper_debit')

        lower_credit = request.GET.get('lower_credit')
        upper_credit = request.GET.get('upper_credit')

        reference = request.GET.get('reference')

        # If the account number is set, the range is ignored.
        account_number_array = get_array_or_none(request.GET.get('account'))

        internal_company = request.GET.get('internal_company')

        engine = PolicySearchEngine(
            lower_fiscal_period_year=lower_fiscal_period_year,
            upper_fiscal_period_year=upper_fiscal_period_year,
            lower_fiscal_period_month=lower_fiscal_period_month,
            upper_fiscal_period_month=upper_fiscal_period_month,
            type_policy_array=type_policy_array,
            lower_folio=lower_folio,
            upper_folio=upper_folio,
            lower_registry_date=lower_registry_date,
            upper_registry_date=upper_registry_date,
            description=description,
            lower_account_number=lower_account_number,
            upper_account_number=upper_account_number,
            lower_debit=lower_debit,
            upper_debit=upper_debit,
            lower_credit=lower_credit,
            upper_credit=upper_credit,
            reference=reference,
            only_with_transactions=False,
            account_array=account_number_array,
            internal_company=internal_company)

        result = engine.search_policies()

        return HttpResponse(
            Utilities.query_set_to_dumps(result),
            'application/json; charset=utf-8',
        )
Пример #4
0
    def get(self, request):

        if request.GET.get('export_excel') is not None:
            export_excel = True
        else:
            print(' not excel')
            export_excel = False

        type = request.GET.get('type')

        if type is None:
            return HttpResponse(
                Utilities.json_to_dumps({
                    "error": {
                        "message": "The parameter 'type' is required."
                    }
                }),
                'application/json; charset=utf-8',
            )

        # Make it uppercase so that it's easier to compare.
        type = type.upper()

        if type not in ('PROVIDER', 'CREDITOR', 'THIRD_PARTY'):
            return HttpResponse(
                Utilities.json_to_dumps({
                    "error": {
                        "message":
                        "The parameter 'type' must be PROVIDER, CREDITOR or THIRD_PARTY."
                    }
                }),
                'application/json; charset=utf-8',
            )

        name = request.GET.get('name')
        rfc = request.GET.get('rfc')
        email = request.GET.get('email')
        phone_number = request.GET.get('phone_number')
        accounting_account_number = request.GET.get(
            'accounting_account_number')
        bank_account = request.GET.get('bank_account')
        register_date_lower = Utilities.string_to_date(
            request.GET.get('register_date_lower'))
        register_date_upper = Utilities.string_to_date(
            request.GET.get('register_date_upper'))
        services = request.GET.get('services')

        engine = ProviderSearchEngine(type, name, rfc, email, phone_number,
                                      accounting_account_number, bank_account,
                                      register_date_lower, register_date_upper,
                                      services)

        results = engine.search()

        if export_excel:
            values = [
                'name', 'country', 'colony', 'street', 'outdoor_number',
                'indoor_number', 'zip_code', 'rfc', 'curp', 'phone_number',
                'phone_number_2', 'email', 'cellphone_number', 'office_number',
                'extension_number'
            ]
            return createCSVResponseFromQueryset(results, values)
        else:
            return HttpResponse(
                Utilities.query_set_to_dumps(results),
                'application/json; charset=utf-8',
            )