业务模式下采购订单已开票金额获取SQL参考原创
6人赞赏了该文章
114次浏览
编辑于2024年10月12日 11:35:12
业务场景:业务模式下采购订单新增自定义已开票金额和已开票数量字段,历史数据需要SQL更新
注意:
1. 适用于全流程不存在分录合并业务(标准产品下就不允许分录合并下推)
2. 适用于已开票金额和数量字段在订单明细表
3. 适用于业务应付模式
4. F_ORA_AMOUNT 已开票金额 和 F_ORA_QTY 已开票数量 需替换成自定义字段名称
如下SQL语句仅供参考!!!更新前建议做全表备份!!!
MERGE INTO T_PUR_POORDERENTRY T1 USING ( SELECT PO.FBILLNO 采购订单号,PO.FPURCHASEORGID,PO.FDATE 业务日期,PO.FCLOSESTATUS 关闭状态,POE.FENTRYID,POE.FSEQ,POE.FMRPCLOSESTATUS 业务关闭状态,POE.FBASEUNITID 基本单位,POE.FUNITID 采购单位,POE.FSTOCKUNITID 库存单位,POE.FQTY 采购数量,POE.FSTOCKQTY 库存数量,POE.FSTOCKBASEQTY 库存基本数量,POER.FBASESTOCKINQTY 累计入库数量基本,POER.FSTOCKINQTY 累计入库数量,POE.FBASEUNITQTY 采购基本数量,POER.FBASEAPJOINQTY 关联应付数量计价基本,POER.FSTOCKBASEAPJOINQTY 关联应付数量库存基本,POER.FBASEFINAPQTY 先收票数量基本单位,POER.FSTOCKBASEFINAPQTY 先收票数量库存基本,POER.FAPJOINAMOUNT 关联应付金额 ,POE.F_ORA_AMOUNT 已开票金额,POE.F_ORA_QTY 已开票数量,G.FALLAMOUNTFOR 订单下推发票金额,G.FBASICUNITQTY 订单下推发票数量,H.FALLAMOUNTFOR 应付下推发票金额,H.FBASICUNITQTY 应付下推发票数量 ,ISNULL(G.FALLAMOUNTFOR,0)+ISNULL(H.FALLAMOUNTFOR,0) FALLAMOUNTFORNEW,ISNULL(G.FBASICUNITQTY,0)+ISNULL(H.FBASICUNITQTY,0) FBASICUNITQTYNEW FROM T_PUR_POORDER PO LEFT JOIN T_PUR_POORDERENTRY POE ON PO.FID=POE.FID LEFT JOIN T_PUR_POORDERENTRY_R POER ON POE.FENTRYID=POER.FENTRYID LEFT JOIN ( SELECT C.FSID,SUM(C.FBASICUNITQTY) FBASICUNITQTY,SUM(C.FALLAMOUNTFOR) FALLAMOUNTFOR FROM T_IV_PURCHASEIC A LEFT JOIN T_IV_PURCHASEICENTRY B ON A.FID=B.FID INNER JOIN T_IV_PURCHASEICENTRY_LK C ON B.FENTRYID=C.FENTRYID AND UPPER(FSTABLENAME)='T_PUR_POORDERENTRY' WHERE FCANCELSTATUS='A' AND A.FDOCUMENTSTATUS<>'Z' AND B.FPUSHREDQTY=0 GROUP BY C.FSID ) G ON POE.FENTRYID=G.FSID --订单下推发票 LEFT JOIN ( SELECT D.FORDERENTRYID,SUM(C.FBASICUNITQTY) FBASICUNITQTY,SUM(C.FALLAMOUNTFOR) FALLAMOUNTFOR FROM T_IV_PURCHASEIC A LEFT JOIN T_IV_PURCHASEICENTRY B ON A.FID=B.FID INNER JOIN T_IV_PURCHASEICENTRY_LK C ON B.FENTRYID=C.FENTRYID AND UPPER(FSTABLENAME)='T_AP_PAYABLEENTRY' INNER JOIN T_AP_PAYABLEENTRY 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 POE.FENTRYID=H.FORDERENTRYID --订单下推应付下推发票 WHERE (POE.F_ORA_AMOUNT<>ISNULL(G.FALLAMOUNTFOR,0)+ISNULL(H.FALLAMOUNTFOR,0) OR POE.F_ORA_QTY<>ISNULL(G.FBASICUNITQTY,0)+ISNULL(H.FBASICUNITQTY,0)) AND PO.FBILLNO='订单单号' --通过单号查询 ) T2 ON (T1.FENTRYID=T2.FENTRYID) WHEN MATCHED THEN UPDATE SET T1.F_ORA_AMOUNT=T2.FALLAMOUNTFORNEW,T1.F_ORA_QTY=T2.FBASICUNITQTYNEW;
销售订单参考:先开票业务和出库后开票混用的前提下,销售订单列表获取已开票金额SQL参考
赞 6
6人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读