Difference between revisions of "Queries: Bank Statement"

From iDempiere en
m
Line 101: Line 101:
 
</nowiki>
 
</nowiki>
  
−
''This page is brought to you by [[User:ngordon7000|Neil Gordon]] from [http://www.ntier.co.za nTier Software Services].  Feel free to improve directly or suggest using the Discussion tab.
+
''This page is brought to you by [http://www.ntier.co.za nTier Software Services].  Feel free to improve directly or suggest using the Discussion tab.

Revision as of 15:18, 21 March 2017


General

select c_bankstatement_id,name from c_bankstatement where ad_client_id = 1000009 order by name;

Rough working queries to reinstate voided bank statement

  • Possibly could be converted into a plugin
  • Refer to MBankStatement.voidIt
  • It should also be possible to simply delete the bank statement and reinsert the copy before void was done instead of using the staging table, but I didn't try it.
  • Take a backup before running any queries
-- select docstatus, * from c_bankstatement where C_BankStatement_ID=1000200;

-- Backup
select * into bk_20160906_bankstatement from c_bankstatement where c_bankstatement_id = 1000200;

select count(*) from bk_20160906_bankstatement;

select * into bk_20160906_bankstatementline from c_bankstatementline where c_bankstatement_id = 1000200;

select count(*) from bk_20160906_bankstatementline;

select * into bk_20160906_payment from c_payment;

select count(*) from bk_20160906_payment;

select * into bk_20160906_c_bankaccount from c_bankaccount where c_bankaccount_id  =
(select c_bankaccount_id from c_bankstatement where c_bankstatement_id = 1000200);

select count(*) from bk_20160906_c_bankaccount;

-- Staging tables (must contain the original data before void was done)
select * into zz_stage_bankstatement from c_bankstatement where c_bankstatement_id = 1000200;
delete from zz_stage_bankstatement;
select * into zz_stage_bankstatementline from c_bankstatementline where c_bankstatement_id = 1000200;
delete from zz_stage_bankstatementline;

select count(*) from zz_stage_bankstatement;
select count(*) from zz_stage_bankstatementline;
select count(*) from c_bankstatement where c_bankstatement_id = 1000200;
select count(*) from c_bankstatementline where c_bankstatement_id = 1000200;
select count(*) from c_bankstatementline where c_bankstatement_id = 1000200 and c_payment_id is not null; --106

select count(*) from c_payment where isreconciled = 'Y' and c_payment_id in (select c_payment_id from c_bankstatementline where c_bankstatement_id = 1000200); -- 106

update c_bankstatement
	set
		docstatus = b.docstatus ,
		docaction = b.docaction ,
		processed = b.processed ,
		description = b.description ,
		statementdifference = b.statementdifference
from
	zz_stage_bankstatement b 
where 
	c_bankstatement.c_bankstatement_id = 1000200 and 
	c_bankstatement.c_bankstatement_id = b.c_bankstatement_id ;

update c_bankstatementline
	set
		description = b.description ,
		stmtamt = b.stmtamt ,
		trxamt = b.trxamt ,
		chargeamt = b.chargeamt ,
		interestamt = b.interestamt,
		c_payment_id = b.c_payment_id
from
	zz_stage_bankstatementline b 
where 
	c_bankstatementline.c_bankstatement_id = 1000200 and
	c_bankstatementline.c_bankstatementline_id = b.c_bankstatementline_id ;

-- ba.setCurrentBalance(ba.getCurrentBalance().subtract(getStatementDifference()));

select currentbalance from c_bankaccount where c_bankaccount_id = ( 
	select c_bankaccount_id from c_bankstatement where c_bankstatement_id = 1000200 
	);
	
update c_bankaccount
set currentBalance = currentBalance + 
(select statementdifference from c_bankstatement where c_bankstatement_id = 1000200)
where c_bankaccount_id = ( 
	select c_bankaccount_id from c_bankstatement where c_bankstatement_id = 1000200 
	)
;

select currentbalance from c_bankaccount where c_bankaccount_id = ( 
	select c_bankaccount_id from c_bankstatement where c_bankstatement_id = 1000200 
	);

update c_payment set
isreconciled = 'Y' 
where c_payment_id in (select c_payment_id from c_bankstatementline where c_bankstatement_id = 1000200);

-- Expect 106
select count(*) from c_payment where isreconciled = 'Y' and c_payment_id in (select c_payment_id from c_bankstatementline where c_bankstatement_id = 1000200);

This page is brought to you by nTier Software Services. Feel free to improve directly or suggest using the Discussion tab.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.