Advertisement
0re5ama

Untitled

Jan 4th, 2023
1,953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 5.85 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[p_bb_Get_Detailed_Txn_Report_Business]
  2.     @PACode VARCHAR(25) = NULL,
  3.     @SACode VARCHAR(25) = NULL,
  4.     @FromDate DATE,
  5.     @ToDate DATE
  6. AS
  7. BEGIN
  8.     -- =============================================
  9.     -- Author:      <Binayak Upadhyaya>
  10.     -- Create date: <30 NOV 2015>
  11.     -- Description:
  12.     --           Get Transaction for Approved Transaction For Report for B2B Txn
  13.     -- EXEC p_bb_Get_Detailed_Txn_Report_Business @PACode='MY0001',@SACode=NULL,@FromDate='2016-01-01',@ToDate='2017-01-18'
  14.     -- =============================================
  15.     IF (LEN(LTRIM(RTRIM(@PACode))) = 0)
  16.     BEGIN
  17.         SET @PACode = NULL;
  18.     END;
  19.  
  20.     IF (LEN(LTRIM(RTRIM(@SACode))) = 0)
  21.     BEGIN
  22.         SET @SACode = NULL;
  23.     END;
  24.  
  25.     SELECT a.tran_id AS [Txn No],
  26.         rsp.rsp_name as [State],
  27.         a.created_on AS [Txn Date & Time],
  28.         a.is_approve_date AS [Approval Date & Time],
  29.         ISNULL(sender_first_name, '') + ' ' + ISNULL(sender_middle_name, '') + ' ' + ISNULL(sender_last_name, '') AS [Company Name],
  30.         sender.id_card_type_no AS [Company Registration No],
  31.         sender.sender_dob AS [Business Registration Date],
  32.         sender.address AS [Address],
  33.         sender.mailing_address AS [Mailing Address],
  34.         ISNULL(cntry_code_tbl.CountryName, '') AS [Country],
  35.         sender.handphone as [Sender Contact No],
  36.         -- sender.details AS [Product/Services],
  37.         nb.nature_of_business_text as [Nature of Business],
  38.         a.sender_employer_name AS [Name of Authorize Person],
  39.         nationality.ref_desc AS [Nationality of Authorize Person],
  40.         authPerson.id_card_type_no AS [Card No],
  41.         idCardAuth.id_card_type_name AS [Card Type],
  42.         authPerson.contact_no AS [Authorize Person Contact No],
  43.         CASE
  44.             WHEN a.parent_agent_cd = 'MY0001'
  45.                 THEN designation.ref_desc
  46.             ELSE ISNULL(authPerson.designation, '')
  47.             END AS [Designation],
  48.         ISNULL(receiver_first_name, '') + ' ' + ISNULL(receiver_middle_name, '') + ' ' + ISNULL(receiver_last_name, '') AS [Receiver Name],
  49.         a.receiver_handphone AS [Receiver Contact No],
  50.         a.receiver_bank_ac_no AS [Account No],
  51.         a.receiver_address AS [Receiver Address],
  52.         rcvr_sndr_rln.ref_desc AS [Relationship],
  53.         CONVERT(VARCHAR, CAST(a.total_coll_amount AS MONEY), 1) AS [Transaction Amount],
  54.         sourceOfFund.ref_desc AS [Source Of Fund],
  55.         reson_remit.ref_desc AS [Purpose Of Remittance],
  56.         pay_mode.ref_desc AS [Payout Mode],
  57.         c.CountryName AS [Payout Country],
  58.         a.parent_pay_agent_cd [Receiver Payout Agent],
  59.         a.parent_coll_sub_agent_cd AS [Branch Code],
  60.         subAgent.sub_agent_name [Branch Name],
  61.         a.created_by AS [Teller ID],
  62.         creBy.[user_name] AS [Teller Name],
  63.         a.is_approve_by [Approver ID],
  64.         ISNULL(appByAdmin.user_name, appBy.user_name) AS [Approver Name],
  65.         CASE
  66.             WHEN a.refund_type = 'Y'
  67.                 THEN 'Refund'
  68.             WHEN a.refund_type = 'N'
  69.                 THEN 'Deduct Service Charge'
  70.             ELSE remit.remit_action_name
  71.             END AS [Status Of Txn],
  72.         CASE
  73.             WHEN a.action_cd = 18
  74.                 THEN 'Yes'
  75.             ELSE 'No'
  76.             END AS [Sender OFAC],
  77.         CASE
  78.             WHEN a.action_cd = 19
  79.                 THEN 'Yes'
  80.             ELSE 'No'
  81.             END AS [Receiver OFAC],
  82.         'Yes' AS [Peps & Cft Name Checked]
  83.     --,actionHist.comments AS [Remarks]
  84.     --,a.pay_crncy_cd + ' '+ CONVERT(varchar, CAST((a.total_coll_amount - a.total_charge - g.GstAmt)  AS money), 1) [Payable Amount]           
  85.     FROM dbo.tran_mst AS a --LEFT JOIN [dbo].[tran_action_hist] actionHist on a.tran_id = actionHist.tran_id AND actionHist.action_cd = 11
  86.     INNER JOIN dbo.vw_sender_mst sender
  87.         ON a.sender_auto_id = sender.sender_auto_id
  88.     LEFT JOIN gst_txn_details g
  89.         ON a.tran_id = g.MtradeId
  90.     LEFT JOIN [dbo].[remit_action] remit
  91.         ON a.action_cd = remit.remit_action_cd
  92.     LEFT JOIN remit_user creBy
  93.         ON a.created_by = creBy.remit_user_cd
  94.             AND a.parent_agent_cd = creBy.parent_agent_cd
  95.     LEFT JOIN remit_user appBy
  96.         ON a.is_approve_by = appBy.remit_user_cd
  97.             AND a.parent_agent_cd = appBy.parent_agent_cd
  98.     LEFT JOIN remit_user appByAdmin
  99.         ON a.is_approve_by = appByAdmin.remit_user_cd
  100.             AND appByAdmin.parent_agent_cd = '000000'
  101.     LEFT JOIN vw_company_authorised_personnel authPerson
  102.         ON a.sender_auto_id = authPerson.sender_auto_id
  103.             AND a.authorized_person_id_no = authPerson.id_card_type_no
  104.     LEFT JOIN [dbo].[ref_code_table_dtl] pay_mode
  105.         ON a.payment_mode_cd = pay_mode.ref_code
  106.             AND pay_mode.ref_rec_type = 'PAYMENT_MODE'
  107.     LEFT JOIN [dbo].[ref_code_table_dtl] nationality
  108.         ON authPerson.cntry_cd = nationality.ref_code
  109.             AND nationality.ref_rec_type = 'NATIONALITY'
  110.     LEFT JOIN [dbo].[ref_code_table_dtl] designation
  111.         ON authPerson.designation = designation.ref_code
  112.             AND designation.ref_rec_type = 'DESIGNATION'
  113.     LEFT JOIN [dbo].[ref_code_table_dtl] rcvr_sndr_rln
  114.         ON a.relation_with_sender_cd = rcvr_sndr_rln.ref_code
  115.             AND rcvr_sndr_rln.ref_rec_type = 'RELATIONSHIP'
  116.     LEFT JOIN [dbo].[ref_code_table_dtl] sourceOfFund
  117.         ON a.source_of_fund_cd = sourceOfFund.ref_code
  118.             AND sourceOfFund.ref_rec_type = 'SOURCE_OF_FUND'
  119.     LEFT JOIN [dbo].[ref_code_table_dtl] reson_remit
  120.         ON a.reason_of_remittance_cd = reson_remit.ref_code
  121.             AND reson_remit.ref_rec_type = 'REMITTANCE_REASON'
  122.     LEFT OUTER JOIN vw_countryCodeMap AS c WITH (NOLOCK)
  123.         ON a.paying_cntry_cd = c.CountryCd2
  124.     LEFT JOIN [dbo].[id_card_type] idCardAuth
  125.         ON sender.id_card_type_cd = idCardAuth.id_card_type_cd
  126.     LEFT JOIN dbo.sub_agent subAgent
  127.         ON a.parent_agent_cd = subAgent.parent_agent_cd
  128.         and a.parent_coll_sub_agent_cd = subAgent.sub_agent_cd
  129.     left join region_state_province rsp
  130.         on rsp.cntry_cd = subAgent.cntry_cd
  131.         and rsp.rsp_cd = subAgent.rsp_cd
  132.     LEFT JOIN vw_countryCodeMap cntry_code_tbl
  133.         ON sender.cntry_cd = cntry_code_tbl.CountryCd2
  134.     left outer join bb_company_nature_business nb
  135.         on sender.sender_auto_id = nb.sender_auto_id
  136.     WHERE (a.is_approve = 1)
  137.         AND (
  138.             a.remit_type = 'B2B'
  139.             OR a.remit_type = 'B2P'
  140.             )
  141.         AND a.tran_date BETWEEN @FromDate
  142.             AND @ToDate
  143.         AND (@PACode is null or a.parent_agent_cd = @PACode)
  144.         AND (@SACode is null or a.parent_coll_sub_agent_cd = @SACode);
  145. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement