opening balance fixed in general ledger
This commit is contained in:
parent
c3307c5eec
commit
a96ea6ef68
@ -1,9 +1,11 @@
|
||||
#get company letter head
|
||||
#---------------------------------------------------------------------
|
||||
l_head = sql("select content from `tabLetter Head` where ifnull(is_default, 0) = 1 and ifnull(disabled, 0) = 0")
|
||||
l_head = l_head and l_head[0][0] or ''
|
||||
|
||||
|
||||
# Posting date, fiscal year and year start date
|
||||
#-----------------------------------------------
|
||||
#---------------------------------------------------------------------
|
||||
if not filter_values.get('posting_date') or not filter_values.get('posting_date1'):
|
||||
msgprint("Please enter From Date and To Date")
|
||||
raise Exception
|
||||
@ -11,11 +13,16 @@ else:
|
||||
from_date = filter_values['posting_date']
|
||||
to_date = filter_values['posting_date1']
|
||||
|
||||
from_date_year = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",from_date)[0][0]
|
||||
from_date_year = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",from_date)
|
||||
if not from_date_year:
|
||||
msgprint("From Date is out of range. Please check.", raise_exception=1)
|
||||
else:
|
||||
from_date_year = from_date_year[0][0]
|
||||
#to_date_year = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",to_date)[0][0]
|
||||
|
||||
|
||||
# define columns
|
||||
#---------------
|
||||
#---------------------------------------------------------------------
|
||||
col = []
|
||||
col.append(['Date','Date','80px',''])
|
||||
col.append(['Detail','Text','475px',''])
|
||||
@ -30,9 +37,9 @@ for c in col:
|
||||
col_idx[c[0]] = len(colnames)
|
||||
|
||||
|
||||
total_debit, total_credit, total_opening, total_diff = 0,0,0,0
|
||||
|
||||
#total query
|
||||
#---------------------------------------------------------------------
|
||||
total_debit, total_credit, total_opening, total_diff = 0,0,0,0
|
||||
q = query.split('WHERE')[1].split('LIMIT')
|
||||
if len(q) > 2:
|
||||
query_where_clause = 'LIMIT'.join(q[:-1])
|
||||
@ -47,27 +54,32 @@ for t in tot:
|
||||
|
||||
total_diff = total_debit - total_credit
|
||||
|
||||
# opening
|
||||
account = filter_values.get('account')
|
||||
if not account:
|
||||
msgprint('Select an account to proceed',raise_exception=0,small=1)
|
||||
|
||||
|
||||
acc_det = sql("select debit_or_credit, is_pl_account, lft, rgt, group_or_ledger from tabAccount where name = '%s'" % account)
|
||||
|
||||
opening_bal = get_obj('GL Control').get_as_on_balance(account, from_date_year, from_date, acc_det[0][0], acc_det[0][2], acc_det[0][3])[2]
|
||||
closing_bal = get_obj('GL Control').get_as_on_balance(account, from_date_year, to_date, acc_det[0][0], acc_det[0][2], acc_det[0][3])[2]
|
||||
if acc_det[0][0] == 'Credit':
|
||||
closing_bal = -1*closing_bal
|
||||
opening_bal = -1*opening_bal
|
||||
|
||||
out = []
|
||||
|
||||
t_row = ['' for i in range(len(colnames))]
|
||||
t_row[1] = 'Opening as on '+formatdate(from_date)
|
||||
t_row[col_idx['Debit']-1] = opening_bal
|
||||
out.append(t_row)
|
||||
|
||||
# If account mentioned, show opening and closing
|
||||
#---------------------------------------------------------------------
|
||||
account = filter_values.get('account')
|
||||
|
||||
if account and (total_debit != 0 or total_credit != 0):
|
||||
acc_det = sql("select debit_or_credit, is_pl_account, lft, rgt, group_or_ledger from tabAccount where name = '%s'" % account)
|
||||
|
||||
opening_bal = get_obj('GL Control').get_as_on_balance(account, from_date_year, add_days(from_date, -1), acc_det[0][0], acc_det[0][2], acc_det[0][3])[2]
|
||||
closing_bal = get_obj('GL Control').get_as_on_balance(account, from_date_year, to_date, acc_det[0][0], acc_det[0][2], acc_det[0][3])[2]
|
||||
|
||||
if acc_det[0][0] == 'Credit':
|
||||
closing_bal = -1*closing_bal
|
||||
opening_bal = -1*opening_bal
|
||||
|
||||
# add opening row
|
||||
t_row = ['' for i in range(len(colnames))]
|
||||
t_row[1] = 'Opening as on '+formatdate(from_date)
|
||||
t_row[col_idx['Debit']-1] = opening_bal
|
||||
out.append(t_row)
|
||||
|
||||
|
||||
# table output
|
||||
#---------------------------------------------------------------------
|
||||
count = 0
|
||||
for r in res:
|
||||
count +=1
|
||||
@ -79,6 +91,9 @@ for r in res:
|
||||
r[1] = a
|
||||
out.append(r)
|
||||
|
||||
|
||||
# Total, Difference and closing balance
|
||||
#---------------------------------------------------------------------
|
||||
if total_debit != 0 or total_credit != 0:
|
||||
# Total debit/credit
|
||||
t_row = ['' for i in range(len(colnames))]
|
||||
@ -87,7 +102,6 @@ if total_debit != 0 or total_credit != 0:
|
||||
t_row[col_idx['Credit']-1] = total_credit
|
||||
out.append(t_row)
|
||||
|
||||
|
||||
# diffrence (dr-cr)
|
||||
t_row = ['' for i in range(len(colnames))]
|
||||
t_row[1] = 'Total(Dr-Cr)'
|
||||
@ -101,7 +115,9 @@ if total_debit != 0 or total_credit != 0:
|
||||
t_row[col_idx['Debit']-1] = flt(closing_bal)
|
||||
out.append(t_row)
|
||||
|
||||
|
||||
# Print Format
|
||||
#---------------------------------------------------------------------
|
||||
myheader = """<table width = '100%%'><tr><td>"""+l_head+"""</td>
|
||||
</tr>
|
||||
<tr> <td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user