[report] payment collection with ageing and payment made with ageing merged to payment period based on invoice date

This commit is contained in:
Akhilesh Darjee
2013-12-02 17:58:23 +05:30
parent 7e8f98368a
commit 9c0569ee2d
11 changed files with 113 additions and 236 deletions

View File

@@ -0,0 +1,48 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
wn.query_reports["Payment Period Based On Invoice Date"] = {
"filters": [
{
fieldname: "from_date",
label: wn._("From Date"),
fieldtype: "Date",
default: wn.defaults.get_user_default("year_start_date"),
},
{
fieldname:"to_date",
label: wn._("To Date"),
fieldtype: "Date",
default: get_today()
},
{
fieldname:"payment_type",
label: wn._("Payment Type"),
fieldtype: "Select",
options: "Incoming\nOutgoing",
default: "Incoming"
},
{
fieldname:"account",
label: wn._("Account"),
fieldtype: "Link",
options: "Account",
get_query: function() {
return {
query: "accounts.utils.get_account_list",
filters: {
is_pl_account: "No",
company: wn.query_report.filters_by_name.company.get_value()
}
}
}
},
{
fieldname:"company",
label: wn._("Company"),
fieldtype: "Link",
options: "Company",
default: wn.defaults.get_default("company")
},
]
}

View File

@@ -0,0 +1,95 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, _
from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
def execute(filters=None):
if not filters: filters = {}
columns = get_columns()
entries = get_entries(filters)
invoice_posting_date_map = get_invoice_posting_date_map(filters)
against_date = ""
outstanding_amount = 0.0
data = []
for d in entries:
if d.against_voucher:
against_date = d.against_voucher and invoice_posting_date_map[d.against_voucher] or ""
outstanding_amount = d.debit or -1*d.credit
else:
against_date = d.against_invoice and invoice_posting_date_map[d.against_invoice] or ""
outstanding_amount = d.credit or -1*d.debit
row = [d.name, d.account, d.posting_date, d.against_voucher or d.against_invoice,
against_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
if d.against_voucher or d.against_invoice:
row += get_ageing_data(d.posting_date, against_date, outstanding_amount)
else:
row += ["", "", "", "", ""]
data.append(row)
return columns, data
def get_columns():
return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140",
"Posting Date:Date:100", "Against Invoice:Link/Purchase Invoice:130",
"Against Invoice Posting Date:Date:130", "Debit:Currency:120", "Credit:Currency:120",
"Reference No::100", "Reference Date:Date:100", "Remarks::150", "Age:Int:40",
"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
]
def get_conditions(filters):
conditions = ""
party_accounts = []
if filters.get("account"):
party_accounts = [filters["account"]]
else:
cond = filters.get("company") and (" and company = '%s'" % filters["company"]) or ""
if filters.get("payment_type") == "Incoming":
cond += " and master_type = 'Customer'"
else:
cond += " and master_type = 'Supplier'"
party_accounts = webnotes.conn.sql_list("""select name from `tabAccount`
where ifnull(master_name, '')!='' and docstatus < 2 %s""" % cond)
if party_accounts:
conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(party_accounts)))
else:
msgprint(_("No Customer or Supplier Accounts found. Accounts are identified based on \
'Master Type' value in account record."), raise_exception=1)
if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
return conditions, party_accounts
def get_entries(filters):
conditions, party_accounts = get_conditions(filters)
entries = webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date,
jvd.against_voucher, jvd.against_invoice, jvd.debit, jvd.credit,
jv.cheque_no, jv.cheque_date, jv.remark
from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" %
(conditions), tuple(party_accounts), as_dict=1)
return entries
def get_invoice_posting_date_map(filters):
invoice_posting_date_map = {}
if filters.get("payment_type") == "Incoming":
for t in webnotes.conn.sql("""select name, posting_date from `tabSales Invoice`"""):
invoice_posting_date_map[t[0]] = t[1]
else:
for t in webnotes.conn.sql("""select name, posting_date from `tabPurchase Invoice`"""):
invoice_posting_date_map[t[0]] = t[1]
return invoice_posting_date_map

View File

@@ -0,0 +1,22 @@
[
{
"creation": "2013-12-02 17:06:37",
"docstatus": 0,
"modified": "2013-12-02 17:06:39",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"add_total_row": 1,
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Journal Voucher",
"report_name": "Payment Period Based On Invoice Date",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Payment Period Based On Invoice Date"
}
]