fixes in AR/AP reports

This commit is contained in:
Nabin Hait
2012-10-19 12:18:31 +05:30
parent 49c93661c1
commit fbdd7fc49f
6 changed files with 116 additions and 84 deletions

View File

@@ -18,7 +18,7 @@ report.customize_filters = function() {
this.hide_all_filters();
this.filter_fields_dict['GL Entry'+FILTER_SEP +'Company'].df.filter_hide = 0;
this.filter_fields_dict['GL Entry'+FILTER_SEP +'From Posting Date'].df.filter_hide = 0;
this.filter_fields_dict['GL Entry'+FILTER_SEP +'From Posting Date'].df.filter_hide = 1;
this.filter_fields_dict['GL Entry'+FILTER_SEP +'To Posting Date'].df.filter_hide = 0;
this.filter_fields_dict['GL Entry'+FILTER_SEP +'Account'].df.filter_hide = 0;
@@ -28,7 +28,6 @@ report.customize_filters = function() {
this.add_filter({fieldname:'range_3', label:'Range 3', fieldtype:'Data', ignore : 1, parent:'GL Entry', report_default:60});
this.add_filter({fieldname:'range_4', label:'Range 4', fieldtype:'Data', ignore : 1, parent:'GL Entry', report_default:90});
this.filter_fields_dict['GL Entry'+FILTER_SEP +'From Posting Date'].df['report_default']=sys_defaults.year_start_date;
this.filter_fields_dict['GL Entry'+FILTER_SEP +'To Posting Date'].df['report_default']=dateutil.obj_to_str(new Date());
this.filter_fields_dict['GL Entry'+FILTER_SEP +'Company'].df['report_default']=sys_defaults.company;

View File

@@ -18,14 +18,14 @@
# ------------------------------------------------------------------
from __future__ import unicode_literals
if not filter_values.get('posting_date') or not filter_values.get('posting_date1'):
msgprint("Please select From Posting Date and To Posting Date ")
if not filter_values.get('posting_date1'):
msgprint("Please select To Posting Date ")
raise Exception
else:
from_date = filter_values.get('posting_date')
to_date = filter_values.get('posting_date1')
if not filter_values['range_1'] or not filter_values['range_2'] or not filter_values['range_3'] or not filter_values['range_4']:
if not filter_values['range_1'] or not filter_values['range_2'] \
or not filter_values['range_3'] or not filter_values['range_4']:
msgprint("Please select aging ranges in no of days in 'More Filters' ")
raise Exception
@@ -74,26 +74,25 @@ if filter_values.has_key('aging_based_on') and filter_values['aging_based_on']:
aging_based_on = filter_values['aging_based_on'].split(NEWLINE)[-1]
if len(res) > 2000 and from_export == 0:
msgprint("This is a very large report and cannot be shown in the browser as it is likely to make your browser very slow.Please select Account or click on 'Export' to open in excel")
raise Exception
# ------------------------------------------------------------------
# main loop starts here
# ------------------------------------------------------------------
msgprint("""This is a very large report and cannot be shown in the browser
as it is likely to make your browser very slow.
Please select Account or click on 'Export' to open in excel""", raise_exception=1)
# get supplier type
supp_type_dict = {}
for each in sql("select t2.name, t1.supplier_type from tabSupplier t1, tabAccount t2 where t1.name = t2.account_name group by t2.name"):
for each in sql("""select t2.name, t1.supplier_type from tabSupplier t1, tabAccount t2
where t1.name = t2.account_name group by t2.name"""):
supp_type_dict[each[0]] = each[1]
# get due_date, bill_no, bill_date from PV
pv_dict = {}
for t in sql("select name, due_date, bill_no, bill_date from `tabPurchase Invoice` group by name"):
for t in sql("""select name, due_date, bill_no, bill_date
from `tabPurchase Invoice` group by name"""):
pv_dict[t[0]] = [cstr(t[1]), t[2], cstr(t[3])]
# pv outside this period
pv_outside_period = [d[0] for d in sql("select distinct name from `tabPurchase Invoice` where (posting_date < '%s' or posting_date > '%s') and docstatus = 1" % (from_date, to_date))]
# pv after to-date
pv_after_to_date = [d[0] for d in sql("""select distinct name from `tabPurchase Invoice`
where posting_date > %s and docstatus = 1""", (to_date,))]
from webnotes.utils import nowdate
@@ -106,7 +105,7 @@ for r in res:
booking_amt = r.pop(7)
# supplier type
r.append(supp_type_dict.get(r[col_idx['Account']], ''))
r.append(supp_type_dict.get(r[col_idx['Account']], ''))
if r[col_idx['Voucher Type']] == 'Purchase Invoice':
r += pv_dict.get(r[col_idx['Voucher No']], ['', '', ''])
@@ -118,23 +117,31 @@ for r in res:
cond = " and ifnull(against_voucher, '') = '%s'" % r[col_idx['Against Voucher']]
# if entry against JV & and not adjusted within period
elif r[col_idx['Against Voucher Type']] == 'Purchase Invoice' and r[col_idx['Against Voucher']] in pv_outside_period:
elif r[col_idx['Against Voucher Type']] == 'Purchase Invoice' \
and r[col_idx['Against Voucher']] in pv_after_to_date:
booking_amt = 0
cond = " and voucher_no = '%s' and ifnull(against_voucher, '') = '%s'" % (r[col_idx['Voucher No']], r[col_idx['Against Voucher']])
cond = """ and voucher_no = '%s' and ifnull(against_voucher, '') = '%s'""" \
% (r[col_idx['Voucher No']], r[col_idx['Against Voucher']])
# if un-adjusted
elif not r[col_idx['Against Voucher']]:
booking_amt = 0
cond = " and ((voucher_no = '%s' and ifnull(against_voucher, '') = '') or (ifnull(against_voucher, '') = '%s' and voucher_type = 'Journal Voucher'))" % (r[col_idx['Voucher No']], r[col_idx['Voucher No']])
cond = """ and ((voucher_no = '%s' and ifnull(against_voucher, '') = '')
or (ifnull(against_voucher, '') = '%s' and voucher_type = 'Journal Voucher'))""" \
% (r[col_idx['Voucher No']], r[col_idx['Voucher No']])
if cond:
outstanding_amt = flt(sql("select sum(ifnull(credit, 0))-sum(ifnull(debit, 0)) from `tabGL Entry` where account = '%s' and ifnull(is_cancelled, 'No') = 'No' and posting_date <= '%s' %s" % (r[col_idx['Account']], to_date, cond))[0][0] or 0)
outstanding_amt = flt(sql("""select sum(ifnull(credit, 0))-sum(ifnull(debit, 0))
from `tabGL Entry` where account = %s and ifnull(is_cancelled, 'No') = 'No'
and posting_date <= %s %s"""
% ('%s', '%s', cond), (r[col_idx['Account']], to_date,))[0][0] or 0)
# add to total outstanding
total_outstanding_amt += flt(outstanding_amt)
# add to total booking amount
if outstanding_amt and r[col_idx['Voucher Type']] == 'Purchase Invoice' and r[col_idx['Against Voucher']]:
if outstanding_amt and r[col_idx['Voucher Type']] == 'Purchase Invoice' \
and r[col_idx['Against Voucher']]:
total_booking_amt += flt(booking_amt)
r += [booking_amt, outstanding_amt]

View File

@@ -1,11 +1,16 @@
SELECT DISTINCT `tabGL Entry`.`Aging_date`,`tabGL Entry`.`account`, `tabGL Entry`.`against_voucher_type`, `tabGL Entry`.`against_voucher`,`tabGL Entry`.`voucher_type`,`tabGL Entry`.`voucher_no`, `tabGL Entry`.`remarks`, `tabGL Entry`.`credit`
FROM `tabGL Entry`,`tabAccount`
WHERE `tabGL Entry`.`posting_date`>= '%(posting_date)s'
AND `tabGL Entry`.`posting_date`<= '%(posting_date1)s'
AND `tabGL Entry`.`account` LIKE '%(account)s%%'
AND `tabGL Entry`.`company` LIKE '%(company)s%%'
AND ((ifnull(`tabGL Entry`.voucher_type,'') = 'Purchase Invoice' and `tabGL Entry`.credit>0) OR `tabGL Entry`.voucher_type = 'Journal Voucher')
AND `tabGL Entry`.`is_cancelled` = 'No'
AND `tabAccount`.master_type = 'Supplier'
AND `tabAccount`.name = `tabGL Entry`.account
ORDER BY `tabGL Entry`.`posting_date`
SELECT DISTINCT
`tabGL Entry`.`Aging_date`,`tabGL Entry`.`account`, `tabGL Entry`.`against_voucher_type`,
`tabGL Entry`.`against_voucher`,`tabGL Entry`.`voucher_type`,`tabGL Entry`.`voucher_no`,
`tabGL Entry`.`remarks`, `tabGL Entry`.`credit`
FROM
`tabGL Entry`,`tabAccount`
WHERE
`tabGL Entry`.`posting_date`<= '%(posting_date1)s'
AND `tabGL Entry`.`account` LIKE '%(account)s%%'
AND `tabGL Entry`.`company` LIKE '%(company)s%%'
AND ((ifnull(`tabGL Entry`.`voucher_type`,'') = 'Purchase Invoice'
AND `tabGL Entry`.`credit`>0) OR `tabGL Entry`.voucher_type = 'Journal Voucher')
AND `tabGL Entry`.`is_cancelled` = 'No'
AND `tabAccount`.master_type = 'Supplier'
AND `tabAccount`.name = `tabGL Entry`.account
ORDER BY `tabGL Entry`.`posting_date`