示例#1
0
def get_count_for_period(account, fieldname, from_date, to_date):
	count = 0.0
	count_on_to_date = get_count_on(account, fieldname, to_date)
	count_before_from_date = get_count_on(account, fieldname, from_date - timedelta(days=1))

	fy_start_date = get_fiscal_year(to_date)[1]
	if from_date == fy_start_date:
		count = count_on_to_date
	elif from_date > fy_start_date:
		count = count_on_to_date - count_before_from_date
	else:
		last_year_closing_count = get_count_on(account, fieldname, fy_start_date - timedelta(days=1))
		count = count_on_to_date + (last_year_closing_count - count_before_from_date)

	return count
示例#2
0
	def get_period_amounts(self, accounts, fieldname):
		"""Get amounts for current and past periods"""
		balance = past_balance = 0.0
		count = 0
		for account in accounts:
			balance += (get_balance_on(account, date = self.future_to_date)
				- get_balance_on(account, date = self.future_from_date - timedelta(days=1)))

			count += (get_count_on(account,fieldname, date = self.future_to_date )
				- get_count_on(account,fieldname, date = self.future_from_date - timedelta(days=1)))

			past_balance += (get_balance_on(account, date = self.past_to_date)
				- get_balance_on(account, date = self.past_from_date - timedelta(days=1)))

		return balance, past_balance, count
示例#3
0
def get_count_for_period(account, fieldname, from_date, to_date):
	count = 0.0
	count_on_to_date = get_count_on(account, fieldname, to_date)
	count_before_from_date = get_count_on(account, fieldname, from_date - timedelta(days=1))

	fy_start_date = get_fiscal_year(to_date)[1]
	if from_date == fy_start_date:
		count = count_on_to_date
	elif from_date > fy_start_date:
		count = count_on_to_date - count_before_from_date
	else:
		last_year_closing_count = get_count_on(account, fieldname, fy_start_date - timedelta(days=1))
		count = count_on_to_date + (last_year_closing_count - count_before_from_date)

	return count
示例#4
0
	def get_period_amounts(self, accounts, fieldname):
		"""Get amounts for current and past periods"""
		balance = past_balance = 0.0
		count = 0
		for account in accounts:
			balance += (get_balance_on(account, date = self.future_to_date)
				- get_balance_on(account, date = self.future_from_date - timedelta(days=1)))

			count += (get_count_on(account,fieldname, date = self.future_to_date )
				- get_count_on(account,fieldname, date = self.future_from_date - timedelta(days=1)))

			past_balance += (get_balance_on(account, date = self.past_to_date)
				- get_balance_on(account, date = self.past_from_date - timedelta(days=1)))

		return balance, past_balance, count
示例#5
0
	def get_type_balance(self, fieldname, account_type, root_type=None):
		
		if root_type:
			accounts = [d.name for d in \
				frappe.db.get_all("Account", filters={"account_type": account_type,
				"company": self.company, "is_group": 0, "root_type": root_type})]
		else:
			accounts = [d.name for d in \
				frappe.db.get_all("Account", filters={"account_type": account_type,
				"company": self.company, "is_group": 0})]

		balance = prev_balance = 0.0
		count = 0
		for account in accounts:
			balance += get_balance_on(account, date=self.future_to_date)
			count += get_count_on(account, fieldname, date=self.future_to_date)
			prev_balance += get_balance_on(account, date=self.past_to_date)
		
		if fieldname in ("bank_balance","credit_balance"):
			return {
				'label': self.meta.get_label(fieldname),
				'value': balance,
				'last_value': prev_balance			}
		else:
			return {
				'label': self.meta.get_label(fieldname),
				'value': balance,
				'last_value': prev_balance,
				'count': count
			}
示例#6
0
    def get_type_balance(self, fieldname, account_type, root_type=None):

        if root_type:
            accounts = [d.name for d in \
             frappe.db.get_all("Account", filters={"account_type": account_type,
             "company": self.company, "is_group": 0, "root_type": root_type})]
        else:
            accounts = [d.name for d in \
             frappe.db.get_all("Account", filters={"account_type": account_type,
             "company": self.company, "is_group": 0})]

        balance = prev_balance = 0.0
        count = 0
        for account in accounts:
            balance += get_balance_on(account,
                                      date=self.future_to_date,
                                      in_account_currency=False)
            count += get_count_on(account, fieldname, date=self.future_to_date)
            prev_balance += get_balance_on(account,
                                           date=self.past_to_date,
                                           in_account_currency=False)

        if fieldname in ("bank_balance", "credit_balance"):
            return {
                'label': self.meta.get_label(fieldname),
                'value': balance,
                'last_value': prev_balance
            }
        else:
            return {
                'label': self.meta.get_label(fieldname),
                'value': balance,
                'last_value': prev_balance,
                'count': count
            }
示例#7
0
	def get_year_to_date_balance(self, root_type, fieldname):
		"""Get income to date"""
		balance = 0.0
		count = 0

		for account in self.get_root_type_accounts(root_type):
			balance += get_balance_on(account, date = self.future_to_date)
			count += get_count_on(account, fieldname, date = self.future_to_date)

		if fieldname == 'income':
			filters = {
				"currency": self.currency
			}
			label = get_link_to_report('Profit and Loss Statement', label=self.meta.get_label(root_type + "_year_to_date"), filters=filters)

		elif fieldname == 'expenses_booked':
			filters = {
				"currency": self.currency
			}
			label = get_link_to_report('Profit and Loss Statement', label=self.meta.get_label(root_type + "_year_to_date"), filters=filters)

		return {
			"label": label,
			"value": balance,
			"count": count
		}
示例#8
0
	def get_year_to_date_balance(self, root_type, fieldname):
		"""Get income to date"""
		balance = 0.0
		count = 0

		for account in self.get_root_type_accounts(root_type):
			balance += get_balance_on(account, date = self.future_to_date)
			count += get_count_on(account, fieldname, date = self.future_to_date)

		return {
			"label": self.meta.get_label(root_type + "_year_to_date"),
			"value": balance,
			"count": count
		}
示例#9
0
    def get_year_to_date_balance(self, root_type, fieldname):
        """Get income to date"""
        balance = 0.0
        count = 0

        for account in self.get_root_type_accounts(root_type):
            balance += get_balance_on(account, date=self.future_to_date)
            count += get_count_on(account, fieldname, date=self.future_to_date)

        return {
            "label": self.meta.get_label(root_type + "_year_to_date"),
            "value": balance,
            "count": count
        }
示例#10
0
    def get_type_balance(self, fieldname, account_type, root_type=None):

        if root_type:
            accounts = [d.name for d in \
             frappe.db.get_all("Account", filters={"account_type": account_type,
             "company": self.company, "is_group": 0, "root_type": root_type})]
        else:
            accounts = [d.name for d in \
             frappe.db.get_all("Account", filters={"account_type": account_type,
             "company": self.company, "is_group": 0})]

        balance = prev_balance = 0.0
        count = 0
        for account in accounts:
            balance += get_balance_on(account,
                                      date=self.future_to_date,
                                      in_account_currency=False)
            count += get_count_on(account, fieldname, date=self.future_to_date)
            prev_balance += get_balance_on(account,
                                           date=self.past_to_date,
                                           in_account_currency=False)

        if fieldname in ("bank_balance", "credit_balance"):
            label = ""
            if fieldname == "bank_balance":
                filters = {
                    "root_type": "Asset",
                    "account_type": "Bank",
                    "report_date": self.future_to_date,
                    "company": self.company
                }
                label = get_link_to_report(
                    'Account Balance',
                    label=self.meta.get_label(fieldname),
                    filters=filters)
            else:
                filters = {
                    "root_type": "Liability",
                    "account_type": "Bank",
                    "report_date": self.future_to_date,
                    "company": self.company
                }
                label = get_link_to_report(
                    'Account Balance',
                    label=self.meta.get_label(fieldname),
                    filters=filters)

            return {
                'label': label,
                'value': balance,
                'last_value': prev_balance
            }
        else:
            if account_type == 'Payable':
                label = get_link_to_report(
                    'Accounts Payable',
                    label=self.meta.get_label(fieldname),
                    filters={
                        "report_date": self.future_to_date,
                        "company": self.company
                    })
            elif account_type == 'Receivable':
                label = get_link_to_report(
                    'Accounts Receivable',
                    label=self.meta.get_label(fieldname),
                    filters={
                        "report_date": self.future_to_date,
                        "company": self.company
                    })
            else:
                label = self.meta.get_label(fieldname)

            return {
                'label': label,
                'value': balance,
                'last_value': prev_balance,
                'count': count
            }