销售订单金额、税额、价税合计相关字段重算SQL脚本

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

销售订单金额、税额、价税合计相关字段重算SQL脚本

因配置问题,导致销售订单的金额、税额、价税合计等相关字段错误。 或者数据库维护了订单含税单价后,需要同步计算订单其他金额、税额、价税合计等相关字段。 可以参考以下脚本处理 ```sql /* 以含税单价为准重算订单金额税额等字段(按照通版逻辑,单价精度6,金额精度2) 使用前提: 1、订单为价外税(现在一般已经很少企业使用价内税了,如果是价内税,可能是错误数据,要检查) 2、含税单价保持正确,计价数量不能为0 3、单价精度6,金额精度2 4、没有改过通版计算逻辑 5、适用于SQLSERVER数据库 */ --====================1、创建日志和过程==================== --创建日志 CREATE TABLE ORDER_AMOUNT_CALC_LOG(FID BIGINT ,FENTRYID BIGINT,UPDATE_DATE DATETIME) --创建过程 GO if OBJECT_ID('ORDER_AMOUNT_CALC') <> 0 drop proc ORDER_AMOUNT_CALC; go CREATE PROCEDURE ORDER_AMOUNT_CALC @FBILLNO NVARCHAR(100) AS SELECT SOE.FID,SOE.FENTRYID INTO #DRTMP_SOE FROM T_SAL_ORDER SO INNER JOIN T_SAL_ORDERENTRY SOE ON SO.FID = SOE.FID WHERE SO.FBILLNO = @FBILLNO INSERT INTO ORDER_AMOUNT_CALC_LOG SELECT FID,FENTRYID,GETDATE() FROM #DRTMP_SOE; --单价 UPDATE T_SAL_ORDERENTRY_F SET FPRICE = ROUND((FTAXPRICE/(1+FTAXRATE/100)),6) WHERE FENTRYID IN (SELECT DR.FENTRYID FROM #DRTMP_SOE DR) --维护需修改的销售订单的 折扣率 MERGE INTO T_SAL_ORDERENTRY_F SF USING ( SELECT CASE WHEN FISINCLUDEDTAX=1 THEN ROUND(((SOF.FPRICEUNITQTY*SOF.FTAXPRICE)*SOF.FDISCOUNTRATE/100),2) ELSE ROUND((SOF.FPRICEUNITQTY*SOF.FPRICE)*(SOF.FDISCOUNTRATE/100),2) END AS F_DISCOUNT ,SOF.FENTRYID FROM T_SAL_ORDERENTRY_F SOF LEFT JOIN T_SAL_ORDERFIN SOFIN ON SOF.FID=SOFIN.FID WHERE SOF.FENTRYID IN (SELECT DR.FENTRYID FROM #DRTMP_SOE DR) ) T ON SF.FENTRYID=T.FENTRYID WHEN MATCHED THEN UPDATE SET SF.FDISCOUNT=T.F_DISCOUNT; --销售订单:金额、税额、净价 FAMOUNT、FTAXAMOUNT、FTAXNETPRICE MERGE INTO T_SAL_ORDERENTRY_F SF USING( SELECT CASE WHEN FISINCLUDEDTAX=0 THEN ROUND((FPRICEUNITQTY*FPRICE-FDISCOUNT),2) ELSE ROUND((FPRICEUNITQTY*FTAXPRICE-FDISCOUNT)/(1+SOF.FTAXRATE/100),2) END AS F_AMOUNT, CASE WHEN FISINCLUDEDTAX=0 THEN ROUND(((FPRICEUNITQTY*FPRICE-FDISCOUNT)*SOF.FTAXRATE/100),2) ELSE ROUND(((FPRICEUNITQTY*FTAXPRICE-FDISCOUNT)/(1+SOF.FTAXRATE/100)*SOF.FTAXRATE/100),2) END AS F_TAXAMOUNT, CASE WHEN FISINCLUDEDTAX=0 THEN ROUND(FPRICE-(FDISCOUNT/FPRICEUNITQTY),6) ELSE ROUND(FTAXPRICE-(FDISCOUNT/FPRICEUNITQTY),6) END AS F_TAXNETPRICE , SOF.FENTRYID FROM T_SAL_ORDERENTRY_F SOF LEFT JOIN T_SAL_ORDERFIN SOFIN ON SOF.FID=SOFIN.FID WHERE SOFIN.FISPRICEEXCLUDETAX=1 AND SOF.FENTRYID IN (SELECT DR.FENTRYID FROM #DRTMP_SOE DR) ) T ON SF.FENTRYID=T.FENTRYID WHEN MATCHED THEN UPDATE SET SF.FAMOUNT=T.F_AMOUNT,SF.FTAXAMOUNT=T.F_TAXAMOUNT,SF.FTAXNETPRICE=T.F_TAXNETPRICE; --销售订单:金额(本位币)、税额(本位币) UPDATE SOF SET FAMOUNT_LC=ROUND(FAMOUNT*FEXCHANGERATE,2),FTAXAMOUNT_LC=ROUND(FTAXAMOUNT*FEXCHANGERATE,2) FROM T_SAL_ORDERENTRY_F SOF LEFT JOIN T_SAL_ORDERFIN SOFIN ON SOF.FID=SOFIN.FID WHERE SOFIN.FISPRICEEXCLUDETAX=1 AND SOF.FENTRYID IN (SELECT DR.FENTRYID FROM #DRTMP_SOE DR); --销售订单:价税合计、价税合计(本位币) UPDATE SOF SET FALLAMOUNT=FAMOUNT+FTAXAMOUNT,FALLAMOUNT_LC=FAMOUNT_LC+FTAXAMOUNT_LC FROM T_SAL_ORDERENTRY_F SOF LEFT JOIN T_SAL_ORDERFIN SOFIN ON SOF.FID=SOFIN.FID WHERE SOFIN.FISPRICEEXCLUDETAX=1 AND SOF.FENTRYID IN (SELECT DR.FENTRYID FROM #DRTMP_SOE DR); --销售订单:表头财务金额税额价税 MERGE INTO T_SAL_ORDERFIN SF USING( SELECT SOF.FID,SUM(SOF.FAMOUNT) FAMOUNT,SUM(SOF.FAMOUNT_LC) FAMOUNT_LC,SUM(SOF.FTAXAMOUNT) FTAXAMOUNT,SUM(SOF.FTAXAMOUNT_LC) FTAXAMOUNT_LC,SUM(SOF.FALLAMOUNT) FALLAMOUNT,SUM(SOF.FALLAMOUNT_LC) FALLAMOUNT_LC FROM T_SAL_ORDERENTRY_F SOF LEFT JOIN T_SAL_ORDERFIN SOFIN ON SOF.FID=SOFIN.FID WHERE SOFIN.FISPRICEEXCLUDETAX=1 AND SOF.FID IN (SELECT DR.FID FROM #DRTMP_SOE DR) GROUP BY SOF.FID ) T ON SF.FID=T.FID WHEN MATCHED THEN UPDATE SET SF.FBILLAMOUNT=T.FAMOUNT,SF.FBILLAMOUNT_LC=T.FAMOUNT_LC,SF.FBILLTAXAMOUNT=T.FTAXAMOUNT,SF.FBILLTAXAMOUNT_LC=T.FTAXAMOUNT_LC,SF.FBILLALLAMOUNT=T.FALLAMOUNT,SF.FBILLALLAMOUNT_LC=T.FALLAMOUNT_LC; DROP TABLE #DRTMP_SOE; --====================2、调用过程重算==================== --调用过程前,生成备份语句并执行 DECLARE @BAKTABLE UDT_NVARCHARTABLE INSERT INTO @BAKTABLE VALUES('T_SAL_ORDERENTRY_F') INSERT INTO @BAKTABLE VALUES('T_SAL_ORDERFIN') SELECT 'SELECT * INTO '+FID+'_SQLBAK_'+ REPLACE(SUBSTRING(CONVERT(NVARCHAR,GETDATE(),121),1,10),'-','')+'_'+ REPLACE(SUBSTRING(CONVERT(NVARCHAR,GETDATE(),121),12,5),':','') +' FROM '+FID FROM @BAKTABLE SELECT * FROM T_SAL_ORDER --调用过程:ORDER_AMOUNT_CALC '输入订单号' EXEC ORDER_AMOUNT_CALC 'XSDD000001' --查看日志 SELECT * FROM ORDER_AMOUNT_CALC_LOG ```

销售订单金额、税额、价税合计相关字段重算SQL脚本

因配置问题,导致销售订单的金额、税额、价税合计等相关字段错误。或者数据库维护了订单含税单价后,需要同步计算订单其他金额、税额、价税...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息