AR发票行的会计分录从一张发票迁移到另一张发票。
现象:美国公司的AR发票号:32001208 少了6条行会计分录。
美国公司的AR发票号:32001220 多了6条行会计分录。这样AR这边的会计分录不平,无法传输到总帐。AR无法关帐原因:由于以前用户发现AutoInvoice生成的发票有个Item:100A1256应该在发票32001208中,却实际产生在了发票32001220中,于是做了Datafix,把发票32001220中的6条Item:100A1256行迁移到了发票:32001208中,但是没有迁移相应的会计分录。
分析:
1)AR发票的会计分录存储在表:RA_CUST_TRX_LINE_GL_DIST_ALL,这表记录了发票头ID 和 发票行ID, 原先的Datafix应该是更改了AR发票行表中的发票头ID,别的应该没有改,所以需要找到这6条会计分录行,并更改其发票头ID即可。2)如果发票已经被核销,那么由于核销表AR_RECEIVABLE_APPLICATIONS_ALL中记录了被核销的发票头ID和发票行ID,因此也可能出现错误。而核销产生的会计分配信息表AR_CASH_BASIS_DISTS_ALL中没有记录发票头ID和发票行ID, 如果两张发票是同一客户的那么也不受影响。解决:使用Datafix把AR发票号:32001220 多出的6条行会计分录迁移到发票:32001208中。
分析SQL:
-- Check 发票头:32001208 SELECT * FROM RA_CUSTOMER_TRX_ALL WHERE trx_number = ' 32001208 ' #返回1条, Customer_trx_id = 4597 , Org_id = 121, Sold_to_customer_id = 1212 -- Check 发票头:32001220 SELECT * FROM RA_CUSTOMER_TRX_ALL WHERE trx_number = ' 32001220 ' #返回1条, Customer_trx_id = 4609 , Org_id = 121, Sold_to_customer_id = 1212 获取用户反映缺失会计分录的发票行 Select RCTL. * From RA_CUSTOMER_TRX_LINES_ALL RCTL, RA_CUSTOMER_TRX_ALL RCT Where RCTL.customer_trx_id = RCT.customer_trx_id AND RCTL.Line_Number > = 26 AND rctl.line_number < = 31 And rct.trx_number = ' 32001208 ' And RCT.org_id = 121 返回6行 customer_trx_id CUSTOMER_TRX_LINE_ID 4597 36907 4597 36908 4597 36909 4597 36910 4597 36931 4597 36932 还要检查核销表中记录的发票头ID和发票行ID是否正确。也即:核销表中 这6条记录的的customer_trx_id 应该是4597 ,而不应该是4609; 我们用反证法来查一下有没有错误的记录: Select * From AR_RECEIVABLE_APPLICATIONS_ALL araa Where araa.applied_customer_trx_id = 4609 And araa.applied_CUSTOMER_TRX_LINE_ID In ( 36907, 36908, 36909, 36910, 36931, 36932) #返回结果:无记录,所以不用考虑。 -- 获取用户反映的缺失的会计分录 Select RCTLG. * From RA_CUST_TRX_LINE_GL_DIST_ALL RCTLG, RA_CUSTOMER_TRX_LINES_ALL RCTL, RA_CUSTOMER_TRX_ALL RCT Where RCTL.customer_trx_line_id = RCTLG.customer_trx_line_id And RCTL.customer_trx_id = RCT.customer_trx_id AND RCTL.Line_Number > = 26 AND rctl.line_number < = 31 And rct.trx_number = ' 32001208 ' And RCT.org_id = 121 #返回6条 , 这6条记录的customer_trx_id 均为4609,需要更改为4597
检查RA_CUST_TRX_LINE_GL_DIST_ALL表上的Trigger
使用Toad工具->Database->Schema Browser->选择AR用户->RA_CUST_TRX_LINE_GL_DIST_ALL表有三个Trigger与Update有关:APPS.AX_RA_CUST_TRX_LINE_GL_ARU2 (更新gl_date时触发)APPS.AX_RA_CUST_TRX_LINE_GL_ARU1 (更新posting_control_id时触发)APPS.ra_cust_trx_line_gl_dist_bri(任何字段更新都受影响)查看其判断逻辑后发现更改customer_trx_id不会引起什么问题,但是ra_cust_trx_line_gl_dist_bri会尝试从上下文环境中获取当前的更改是否由某个并发请求产生,因此需要模拟环境,否则会引起Trigger的不能处理例外,从而导致失败。登陆美国系统,进入AR,Examine ,得到user_id=1111, resp_id=50317, resp_appl_id=222
--备份:用户已经备份数据
Select RCTLG.CUST_TRX_LINE_GL_DIST_ID From RA_CUST_TRX_LINE_GL_DIST_ALL RCTLG, RA_CUSTOMER_TRX_LINES_ALL RCTL, RA_CUSTOMER_TRX_ALL RCT Where RCTL.customer_trx_line_id = RCTLG.customer_trx_line_id And RCTL.customer_trx_id = RCT.customer_trx_id And RCTL.Line_Number > = 26 And rctl.line_number < = 31 And rct.trx_number = ' 32001208 ' And RCT.org_id = 121 返回: CUST_TRX_LINE_GL_DIST_ID 58239 57424 57425 57426 57438 58240
执行更改:
BEGIN fnd_global.APPS_INITIALIZE( user_id => 1111 ,resp_id => 50317 ,resp_appl_id => 222 ); Update RA_CUST_TRX_LINE_GL_DIST_ALL A Set A.customer_trx_id = 4597 Where a.org_id = 121 And a.customer_trx_id = 4609 And a.CUST_TRX_LINE_GL_DIST_ID In ( Select RCTLG.CUST_TRX_LINE_GL_DIST_ID From RA_CUST_TRX_LINE_GL_DIST_ALL RCTLG, RA_CUSTOMER_TRX_LINES_ALL RCTL, RA_CUSTOMER_TRX_ALL RCT Where RCTL.customer_trx_line_id = RCTLG.customer_trx_line_id And RCTL.customer_trx_id = RCT.customer_trx_id And RCTL.Line_Number > = 26 And rctl.line_number < = 31 And rct.trx_number = ' 32001208 ' And RCT.org_id = 121); END;