Guest User

Cash Flow

a guest
Nov 5th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.27 KB | None | 0 0
  1.  
  2. Functions added:
  3. =============
  4.  
  5. CREATE FUNCTION `getAllCashAccounts`() RETURNS varchar(200) CHARSET latin1
  6. BEGIN
  7.  
  8. DECLARE allCashAccounts varchar(500);
  9.  
  10. SET @allCashAccounts = (select GROUP_CONCAT(id) from acc_gl_account where id in (10) or parent_id in (10));
  11.  
  12. RETURN (select @allCashAccounts);
  13.  
  14. END
  15.  
  16.  
  17. CREATE FUNCTION `getAllCashTransactionIds`(`officeId` INT,`startDate` DATE , `endDate` DATE) RETURNS varchar(2000) CHARSET latin1
  18. BEGIN
  19.  
  20. DECLARE allCashAccounts varchar(500);
  21. DECLARE allTxnIds varchar(2000);
  22.  
  23. SET @allCashAccounts = (select getAllCashAccounts());
  24.  
  25. SET @txnIds := (select GROUP_CONCAT(transaction_id) from (SELECT transaction_id, count(transaction_id) AS cnt FROM `acc_gl_journal_entry` WHERE `entry_date` BETWEEN startDate AND endDate and office_id = officeId and FIND_IN_SET(account_id,@allCashAccounts ) GROUP BY transaction_id HAVING cnt <=3) x);
  26.  
  27. RETURN (select @txnIds);
  28.  
  29. END
  30.  
  31.  
  32.  
  33. Query:
  34. =====
  35. select y.AccName, y.Payments, y.Receipts from (select @txnIds := getAllCashTransactionIds(5,'2018-10-11', '2018-10-12'), a.name AccName,  sum(amount) Payments, 0.0 Receipts from acc_gl_account a join  acc_gl_journal_entry e on a.id = e.account_id and a.id <>10  where FIND_IN_SET(transaction_id, @txnIds) and  type_enum = 1 group by e.account_id ) y
Add Comment
Please, Sign In to add comment