关于库存收发存汇总表一过滤条件分析U8客服中心-北京79号工程师2010年11月问题介绍测试及分析小结问题来源:热线电话问题版本:U890问题描述:库存收发存汇总表一、问题介绍库存收发存汇总表的“金额计算依据”为“结存成本”,怎么每次过滤取到的单价都不一样,该处究竟是怎样取数的?二、测试及分析a、仓库档案情况如下:b、存货核算期初余额如下(按仓库核算):帐套和各模块启用会计期间均为2009-10.接下来我们查看一下不同情况下的库存收发存汇总表“按结存成本取数”的情况:情况1、当前会计期间为10月份,当月有两笔其他入库单,均已记账。查询库存收发存汇总表:我们查看一下后台跟踪情况:selectisnull(max(iid),0)fromufsystem..ua_periodwherecacc_id=N'020'anddend<='2009-10-31'andiyear=2009selectisnull(max(iperiod),0)fromgl_mendwherebflag_ia=1andiperiod<=10ifnotobject_id('tempdb..#ia')isnulldroptable#iaselectisnull(cwhcode,'')ascwhcode,cinvcode,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,casewhencount(*)=1andnot(max(iunitprice)isnull)thenmax(iunitprice)Elsecasewhensum(inum)<>0thensum(imoney)/sum(inum)Elsecasewhensum(iinum)<>0thensum(iimoney)/sum(iinum)else0endEndEndasiunitpriceinto#iaFromia_summarywhereiMonth=9groupbyisnull(cwhcode,''),cinvcode,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10updateaseta.期初结存金额=期初结存数量*b.iunitprice,a.总计_入库金额=总计_入库数量*b.iunitprice,a.总计_出库金额=总计_出库数量*b.iunitprice,a.期末结存金额=期末结存数量*b.iunitpricefromtempdb..TMPUF_3644715_heron975795190_XDainnerjoin#iabona.存货编码=b.cinvcodeand(a.仓库编码=b.cwhcodeorb.cwhcode='')and(a.cfree1=b.cfree1orisnull(b.cfree1,'')='')and(a.cfree2=b.cfree2orisnull(b.cfree2,'')='')and(a.cfree3=b.cfree3orisnull(b.cfree3,'')='')and(a.cfree4=b.cfree4orisnull(b.cfree4,'')='')and(a.cfree5=b.cfree5orisnull(b.cfree5,'')='')and(a.cfree6=b.cfree6orisnull(b.cfree6,'')='')and(a.cfree7=b.cfree7orisnull(b.cfree7,'')='')我们查看蓝色字体的语句。查询下存货总账:无imonth=9的记录,所以取不到单价。引申:期初记账后,imonth=0的记录均有iunitprice值,imonth=10的情况下为什么都为null?先期末处理:此时我们知道了:期末处理后,系统自动将全月平均仓库的iunitprice(平均单价)值回填。情况2、10月份结账,进入11月会计期间。发生业务如下,均已记账。尚未期末处理。查询库存收发存汇总表:单价是怎样取来的?看看后台情况:selectisnull(max(iid),0)fromufsystem..ua_periodwherecacc_id=N'020'anddend<='2009-11-19'andiyear=2009selectisnull(max(iperiod),0)fromgl_mendwherebflag_ia=1andiperiod<=10…casewhencount(*)=1andnot(max(iunitprice)isnull)thenmax(iunitprice)Elsecasewhensum(inum)<>0thensum(imoney)/sum(inum)Elsecasewhensum(iinum)<>0thensum(iimoney)/sum(iinum)else0endEndEndasiunitpriceinto#iaFromia_summarywhereiMonth=10……1、我们得知结束日期<=‘2009-11-19’的最大的存货核算已结账月份为10月份;2、全月平均仓库系统取iunitprice,10月份的iunitprice为23.33,可直接取到单价;先进先出仓库iunitprice值为null,且10月份的inum不为0,则取单价=imoney/inum=40/3.情况3、11月份结账后,我们再来看看。查询库存收发存汇总表:可对比存货总账的情况:情况4、此时再更换一下过滤条件看看。为什么仅修改了一下结束日期(且同样是11月份的日期),单价会发生变化??看看后台情况:不是11,而是10???看看ua_period表的情况:Iid=11的记录的eend日期为2009-11-3000:00:00.000,而过滤条件的截止日期为2009-11-19。所以取max(iid)=10.根据以上介绍的四种情况,我们可以得知计算金额依据——结存成本的取价规则:三、小结1、不输入截止日期的情况下,全月平均计价方式,取最近一个已结账月份(即最大已结账月份)存货总账(ia_summary)的期末平均单价(iunitprice),其他计价方式取最近一个已结账月份的存货总账的期末金额/期末数量,如果期末数量为0,则取该月份的入库金额/入库数量,如果入库数量为0,则直接取单价为0.2、输入截止日期的情况下,尽量输入所需已结账月份所属会计期间的截止日期(如果10月份已结账,现需取10月份的结存成本,可输入截止日期为2009-10-31。因为系统将与ua_period表的eend值进行判断),此时按该月会计期间取价,否则按上一月份会计期间取价。3、如果帐套启用会计期间非该年度第一个会计期间,则无法取到存货核算期初余额的结存成本。谢谢