先开票业务和出库后开票混用的前提下,销售订单列表获取已开票金额SQL参考原创
8人赞赏了该文章
142次浏览
编辑于2024年11月21日 20:01:46
业务场景:
先开票业务和出库后开票混用的前提下,需要在销售订单列表获取已开票金额,
订单明细已新增金额字段,反写规则已经配置,历史数据需要做数据修复处理。
注意:
1. 适用于出库单下推应收单不存在分录合并业务(标准产品下就不允许分录合并下推)
2. 适用于已开票金额字段在订单明细表
3. 适用于业务应付模式
4. F_ORA_AMOUNT 已开票金额 需替换成自定义字段名称
如下SQL语句仅供参考!!!更新前建议做全表备份!!!
merge into t_sal_orderentry t1 using ( select a.fbillno 销售订单单号,b.fentryid,b.fqty 销售数量,b.fbaseunitqty 销售基本数量,b.funitid 销售单位,e.fpriceunitid 计价单位, b.fstockunitid 库存单位,e.fpriceunitqty 计价数量,b.fstockbaseqty 库存基本数量,c.fbasearjoinqty 关联应收数量计价基本, c.fsalbasearjoinqty 关联应收数量销售基本,c.fstockbasearjoinqty 关联应收数量库存基本,e.fpricebaseqty 计价基本数量, d.fbasefinarqty 先开票数量计价基本,d.fsalbasefinarqty 先开票数量销售基本,c.fbasearqty 累计应收数量销售基本, c.farqty 累计应收数量销售,c.faramount 累计应收金额,f.fjoinorderamount 关联应收金额订单 ,f_ora_amount 已开票金额,g.fallamountfor,h.fallamountfor fallamountfor1,isnull(g.fallamountfor,0)+isnull(h.fallamountfor,0) fallamountfornew from t_sal_order a left join t_sal_orderentry b on a.fid=b.fid left join t_sal_orderentry_r c on b.fentryid=c.fentryid left join t_sal_orderentry_e d on b.fentryid=d.fentryid left join t_sal_orderentry_f e on b.fentryid=e.fentryid left join t_sal_orderfin f on a.fid=f.fid left join ( select c.fsid,sum(c.fbasicunitqty) fbasicunitqty,sum(c.fallamountfor) fallamountfor from t_iv_salesic a left join t_iv_salesicentry b on a.fid=b.fid inner join t_iv_salesicentry_lk c on b.fentryid=c.fentryid and upper(fstablename)='T_SAL_ORDERENTRY' where fcancelstatus='A' and a.fdocumentstatus<>'Z' and b.fpushredqty=0 group by c.fsid ) g on b.fentryid=g.fsid --订单下推发票 left join ( select d.forderentryid,sum(c.fbasicunitqty) fbasicunitqty,sum(c.fallamountfor) fallamountfor from t_iv_salesic a left join t_iv_salesicentry b on a.fid=b.fid inner join t_iv_salesicentry_lk c on b.fentryid=c.fentryid and upper(fstablename)='T_AR_RECEIVABLEENTRY' inner join t_ar_receivableentry d on c.fsid=d.fentryid and c.fsbillid=d.fid where fcancelstatus='A' and a.fdocumentstatus<>'Z' and b.fpushredqty=0 group by d.forderentryid ) h on b.fentryid=h.forderentryid --订单下推应收下推发票 where f_ora_amount<>isnull(g.fallamountfor,0)+isnull(h.fallamountfor,0) and a.fbillno='订单单号' --通过单号查询 ) t2 on (t1.fentryid=t2.fentryid) when matched then update set t1.f_ora_amount=t2.fallamountfornew;
采购订单参考:业务模式下采购订单已开票金额获取SQL参考
赞 8
8人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读