解决方案: |
/*核销产生错误的原因是由于去年的发票核销记录有问题。 举例:某发票有两笔记录 存货A 100 存货B 100 。做收款单200,正常核销后发票子表的回款金额(imoneysum,iexchsum),和发票金额(isum)一致。 但是你的数据中确存在不一致的记录。表现为存货A回款金额(imoneysum,iexchsum) 为200,而存货B的回款金额为0。应收系统在年度结转时将发票未回款部分 结转到下一个年度的AP_DETAIL表中。造成了数据错误。 详细说明一下:若选项为库存生单,若某发票已经核销,但是还没有形成出库单,年度结转后,应收应付明细(AP_DETAIL)表中不会存在记录。 发票表(salebillvouchs)表中有所有记录。发票主表的csource为“销售”。发货单表(dispatchlists)中有记录。这些记录用于下年生成出库单。 若已经生成的销售出库单,未核销则AP_DETAIL表和销售发票(salebillvouch)表有相关记录。用于核销。发票主表的csource为“应收”。 另外01004001客户的期初余额200511094号发票有问题。但是已经形成的凭证。请和客户确认如何修改。 下面是调整过程*/ use ufdata_002_2006 /*1、首先找出回款金额大于发票金额的记录*/ select sbvid,abs(imoney)发票金额,abs(imoneysum)回款金额,* from salebillvouchs where abs(imoneysum)>abs(isum) select ccuscode as 客户,csbvcode as 发票号, csource,* from salebillvouch where sbvid in (select sbvid from salebillvouchs where abs(imoneysum)>abs(isum)) /*2、更新部分核销的发票错误记录*/ UPDATE salebillvouchs SET imoneysum = 496.34, iexchsum = 496.34 WHERE autoid='3074' AND cinvcode = '0201023'and isum=496.34 UPDATE salebillvouchs SET imoneysum = 992.68, iexchsum = 992.68 WHERE autoid='3075' AND cinvcode = '0201023'and isum=992.68 UPDATE salebillvouchs SET imoneysum = 1341, iexchsum = 1341 WHERE autoid='3076' AND cinvcode = '0301038'and isum=1341 UPDATE salebillvouchs SET imoneysum = 610.82, iexchsum = 610.82 WHERE autoid='3077' AND cinvcode = '0301038'and isum=1072.8 /*3、更新应收应付错误记录*/ delete from ap_detail where iperiod=0 and cvouchtype='27' and cvouchid='2005110766' and ibvid in ('3074','3075','3076') go update ap_detail set idamount=isum-imoneysum ,idamount_f=isum-imoneysum , idamount_s=(isum-imoneysum)/iprice from ap_detail a join salebillvouchs b on a.ibvid=b.autoid and b.sbvid='801' /*4、下面的发票已经全部核销不应该结转*/ delete from ap_detail where ibvid in (select autoid from salebillvouchs where sbvid ='804') /*5、同时更新发票子表记录*/ UPDATE salebillvouchs SET imoneysum = isum, iexchsum = isum WHERE sbvid ='804' update salebillvouchs SET imoneysum = isum, iexchsum = isum WHERE sbvid='919' update salebillvouchs SET imoneysum = isum, iexchsum = isum WHERE sbvid='932' update salebillvouchs SET imoneysum = isum, iexchsum = isum WHERE sbvid='915' /*6、下面的发票是由于尾差问题造成的,明年就没有了*/ update salebillvouchs SET imoneysum = isum, iexchsum = isum WHERE sbvid='102' 使用前请先备份数据。 |