|
发表于 2021-5-10 23:52:46
|
显示全部楼层
本帖最后由 wa911126 于 2021-5-10 23:54 编辑
----------------------------------------------初始化U8菜单(UFMeta)----------------------------------------------
DELETE FROM [AA_CustomerButton] WHERE cButtonKey='EK_TB_WBSXDD'
INSERT INTO [AA_CustomerButton]([cButtonID], [cButtonKey], [cButtonType], [cProjectNO], [cFormKey], [cVoucherKey],
[cKeyBefore], [iOrder], [cGroup], [cCustomerObjectName], [cCaption], [cLocaleID], [cImage], [cToolTip], [cHotKey],
[bInneralCommand], [cVariant], [cVisibleAsKey], [cEnableAsKey])
VALUES(newid(), 'EK_TB_WBSXDD','default', 'U8CustDef', '17_List', '17_List',
'PrintTemplate','0','ICOMMON','EKU8.WBXSDD','导入外部销售订单','zh-cn','refresh','导入外部销售订单','',
1,'导入外部销售订单','PrintTemplate','PrintTemplate')
----------------------------------------------导入外部销售订单数据(UFDATA)----------------------------------------------
CREATE PROCEDURE ZDY_EK_WBXSDDDR(
@cMaker VARCHAR(10), -----制单人
@userTabe VARCHAR(50), -----用户临时表
@val VARCHAR(50) output -----输出参数
)
AS
DECLARE @error INT =0 ----------事务中操作的错误记录
--------------------------------开启事务
BEGIN TRANSACTION
IF OBJECT_ID(N'tempdb..#Temp',N'U') IS NOT NULL DROP Table #Temp
CREATE TABLE #Temp(
ID INT IDENTITY,WBdDate DATETIME,cCusDepart VARCHAR(10),cCusPPerson VARCHAR(10),WBcCusCode VARCHAR(10),WBcCusName VARCHAR(50),cCCCode VARCHAR(10),iCusTaxRate DECIMAL(10,2),
cCusExch_name VARCHAR(10),cInvoiceCompany VARCHAR(10),cCusName VARCHAR(10),cInvCode VARCHAR(10),cInvName VARCHAR(10),
WBInvCode VARCHAR(10),WBInvName VARCHAR(50),WBiQuantity DECIMAL(10,2),iinvnowcost DECIMAL(10,2),bsaleprice int,cCusInvCode VARCHAR(50),cCusInvName VARCHAR(50))
IF OBJECT_ID(N'tempdb..#Temp_SOMain',N'U') IS NOT NULL DROP Table #Temp_SOMain
CREATE TABLE #Temp_SOMain(
ID INT IDENTITY,WBdDate DATETIME,cCusDepart VARCHAR(10),cCusPPerson VARCHAR(10),WBcCusCode VARCHAR(10),cCusName VARCHAR(50),iCusTaxRate DECIMAL(10,2),cCusExch_name VARCHAR(10),cInvoiceCompany VARCHAR(10),
cInvCode VARCHAR(10),cInvName VARCHAR(50),WBiQuantity DECIMAL(10,2),iinvnowcost DECIMAL(10,2),bsaleprice int,cCusInvCode VARCHAR(50),cCusInvName VARCHAR(50))
----------------------------------------------导入外部销售订单数据----------------------------------------------
DECLARE @TabeSQL VARCHAR(2000)
SET @TabeSQL='INSERT INTO #Temp(WBdDate,WBcCusCode,WBcCusName,WBInvCode,WBInvName,WBiQuantity,cCCCode,'+
'cCusDepart,iCusTaxRate,cCusExch_name,cInvoiceCompany,cCusName,cCusPPerson,cInvCode,cInvName,cCusInvCode,cCusInvName)'+
'SELECT a.订单日期 AS WBdDate,a.门店号 AS WBcCusCode,a.门店 AS WBcCusName,a.产品编码 AS WBInvCode,a.产品名称 AS WBInvName,a.数量 AS WBiQuantity,b.cCCCode,'+
'b.cCusDepart,b.iCusTaxRate,b.cCusExch_name,b.cInvoiceCompany,b.cCusName,b.cCusPPerson,c.cInvCode,d.cInvName,c.cCusInvCode,c.cCusInvName '+
'FROM '+@userTabe+' a '+
'INNER JOIN Customer b on a.门店号=b.cCusCode '+
'INNER JOIN CusInvContrapose c on a.门店号=c.cCusCode and a.产品编码=c.cCusInvCode '+
'INNER JOIN Inventory d on c.cInvCode=d.cInvCode'
EXEC (@TabeSQL)
SET @error+=@@ERROR ---------------记录有可能产生的错误号
----------------------------------------------整理外部销售订单数据----------------------------------------------
DECLARE @WBdDate DATETIME
DECLARE @WBcCusCode VARCHAR(10)
DECLARE @cCCCode VARCHAR(10)
DECLARE @cInvCode VARCHAR(10)
DECLARE @cInvName VARCHAR(50)
DECLARE @cCusInvCode VARCHAR(50)
DECLARE @cCusInvName VARCHAR(50)
DECLARE @WBiQuantity DECIMAL(10,2)
DECLARE @cCusDepart VARCHAR(10)
DECLARE @iCusTaxRate VARCHAR(10)
DECLARE @cCusExch_name VARCHAR(10)
DECLARE @cInvoiceCompany VARCHAR(10)
DECLARE @cCusPPerson VARCHAR(10)
DECLARE @cCusName VARCHAR(50)
DECLARE cur_WBXSDD CURSOR FOR --定义游标
SELECT WBdDate,cCCCode,WBcCusCode,cCusName,cCusDepart,cCusPPerson,cCusExch_name,iCusTaxRate,cInvoiceCompany,cInvCode,cInvName,cCusInvCode,cCusInvName,SUM(WBiQuantity)
FROM #Temp
GROUP BY WBdDate,cCCCode,WBcCusCode,cCusName,cCusDepart,cCusPPerson,cCusExch_name,iCusTaxRate,cInvoiceCompany,cInvCode,cInvName,cCusInvCode,cCusInvName
OPEN cur_WBXSDD --打开游标
FETCH NEXT FROM cur_WBXSDD --将游标向下移1行并将获取的数据,放入定义变量中
INTO @WBdDate,@cCCCode,@WBcCusCode,@cCusName,@cCusDepart,@cCusPPerson,@cCusExch_name,@iCusTaxRate,@cInvoiceCompany,@cInvCode,@cInvName,@cCusInvCode,@cCusInvName,@WBiQuantity
WHILE @@fetch_status=0 --判断是否成功获取数据
BEGIN
DECLARE @Autoid INT
DECLARE @dstartdate VARCHAR(50)
DECLARE @bsaleprice VARCHAR(50)
DECLARE @iinvnowcost DECIMAL(10,2)
SELECT @dstartdate=MAX(dstartdate) FROM SA_CusUPriceView WHERE binvalid=0 AND ccusccode=@cCCCode AND cinvcode=@cInvCode AND dstartdate<=@WBdDate
SELECT @Autoid=MAX(autoid) FROM SA_CusUPriceView WHERE binvalid=0 AND ccusccode=@cCCCode AND cinvcode=@cInvCode AND dstartdate=@dstartdate
SELECT @iinvnowcost=iinvnowcost,@bsaleprice=bsaleprice FROM SA_CusUPriceView WHERE binvalid=0 AND ccusccode=@cCCCode AND cinvcode=@cInvCode AND dstartdate=@dstartdate AND Autoid=@Autoid
INSERT INTO #Temp_SOMain(WBdDate,cCusDepart,cCusPPerson,WBcCusCode,cCusName,iCusTaxRate,cCusExch_name,cInvoiceCompany,cInvCode,cInvName,cCusInvCode,cCusInvName,WBiQuantity,iinvnowcost,bsaleprice)
SELECT @WBdDate,@cCusDepart,@cCusPPerson,@WBcCusCode,@cCusName,@iCusTaxRate,@cCusExch_name,@cInvoiceCompany,@cInvCode,@cInvName,@cCusInvCode,@cCusInvName,@WBiQuantity,@iinvnowcost,@bsaleprice
SET @error+=@@ERROR ---------------记录有可能产生的错误号
FETCH NEXT FROM cur_WBXSDD --将游标向下移1行
INTO @WBdDate,@cCCCode,@WBcCusCode,@cCusName,@cCusDepart,@cCusPPerson,@cCusExch_name,@iCusTaxRate,@cInvoiceCompany,@cInvCode,@cInvName,@cCusInvCode,@cCusInvName,@WBiQuantity
END
CLOSE cur_WBXSDD --关闭游标
DEALLOCATE cur_WBXSDD
----------------------------------------------添加数据到U8销售订单中--------------------------------------------
----------------------------------------------添加销售订单主表数据----------------------------------------------
DECLARE @#Temp_SOMain_ID DATETIME
DECLARE @XSdDate DATETIME
DECLARE @XScCusDepart VARCHAR(10)
DECLARE @XScCusPPerson VARCHAR(10)
DECLARE @XScCusCode VARCHAR(10)
DECLARE @XScCusName VARCHAR(50)
DECLARE @XSiCusTaxRate DECIMAL(10,2)
DECLARE @XScCusExch_name VARCHAR(10)
DECLARE @XScInvoiceCompany VARCHAR(10)
DECLARE cur_XSDD CURSOR FOR
SELECT DISTINCT WBdDate,cCusDepart,cCusPPerson,WBcCusCode,cCusName,iCusTaxRate,cCusExch_name,cInvoiceCompany
FROM #Temp_SOMain
OPEN cur_XSDD
FETCH NEXT FROM cur_XSDD
INTO @XSdDate,@XScCusDepart,@XScCusPPerson,@XScCusCode,@XScCusName,@XSiCusTaxRate,@XScCusExch_name,@XScInvoiceCompany
WHILE @@fetch_status=0
BEGIN
DECLARE @XSID INT
DECLARE @cSOCode VARCHAR(50)
DECLARE @cSysBarCode VARCHAR(50)
SELECT @XSID=ISNULL(Max(ID),1000000000) + 1 FROM SO_SOMain
SELECT @cSOCode='XSDD'+replace(replace(replace(CONVERT(varchar(100),GETDATE(),120),'-',''),' ',''),':','')+right(cast((isnull(Max(ID),0) + 1) as nvarchar(10)),5) from SO_SOMain
SET @cSysBarCode='||SA17|'+CONVERT(varchar(20),@XSID)
INSERT INTO SO_SOMain
(ID,cSTCode,dDate,cSOCode,cCusCode,cDepCode,cPersonCode,cexch_name,iExchRate,iTaxRate,cMemo,iStatus,cMaker,bDisFlag,
bReturnFlag,cCusName,bOrder,iVTid,cBusType,dPreMoDateBT,dPreDateBT,iverifystate,iswfcontrolled,dcreatesystime,bcashsale,
iPrintCount,bmustbook,cSysBarCode,contract_status,cinvoicecompany)
VALUES(@XSID,'01',@XSdDate,@cSOCode,@XScCusCode,@XScCusDepart,@XScCusPPerson,@XScCusExch_name,1,@XSiCusTaxRate,NULL,0,@cMaker,0,
0,@XScCusName,0,95,'普通销售',@XSdDate,@XSdDate,0,0,GETDATE(),0,0,0,@cSysBarCode,1,@XScInvoiceCompany)
SET @error+=@@ERROR ---------------记录有可能产生的错误号
IF((SELECT Max(ID) FROM SO_SOMain)=@XSID)
BEGIN
----------------------------------------------添加销售订单子表数据----------------------------------------------
DECLARE @XScInvCode VARCHAR(10)
DECLARE @XScInvName VARCHAR(50)
DECLARE @XScCusInvCode VARCHAR(50)
DECLARE @XScCusInvName VARCHAR(50)
DECLARE @XSiQuantity DECIMAL(10,2)
DECLARE @XSiinvnowcost DECIMAL(10,2)
DECLARE @XSbsaleprice int
DECLARE @IROWNO INT
SET @IROWNO=1
DECLARE cur_XSDD_B CURSOR FOR
SELECT cInvCode,cInvName,WBiQuantity,iinvnowcost,bsaleprice,cCusInvCode,cCusInvName
FROM #Temp_SOMain WHERE WBdDate=@XSdDate AND WBcCusCode=@XScCusCode
OPEN cur_XSDD_B
FETCH NEXT FROM cur_XSDD_B
INTO @XScInvCode,@XScInvName,@XSiQuantity,@XSiinvnowcost,@XSbsaleprice,@XScCusInvCode,@XScCusInvName
WHILE @@fetch_status=0
BEGIN
DECLARE @XSBID INT
DECLARE @cSysBarCodeB VARCHAR(50)
DECLARE @iQuotedPrice DECIMAL(10,2) --报价
DECLARE @iUnitPrice DECIMAL(10,2) --原币无税单价
DECLARE @iTaxUnitPrice DECIMAL(10,2) --原币含税单价
DECLARE @iMoney DECIMAL(10,2) --原币无税金额
DECLARE @iTax DECIMAL(10,2) --原币税额
DECLARE @iSum DECIMAL(10,2) --原币价税合计
DECLARE @iNatUnitPrice DECIMAL(10,2) --本币无税单价
DECLARE @iNatMoney DECIMAL(10,2) --本币无税金额
DECLARE @iNatTax DECIMAL(10,2) --本币税额
DECLARE @iNatSum DECIMAL(10,2) --本币价税合计
DECLARE @DIS numeric --通用数值
DECLARE @KL numeric --通用数值
DECLARE @SALE numeric --通用数值
SELECT @XSBID=ISNULL(Max(iSOsID),1000000000) + 1 FROM SO_SODetails
SET @cSysBarCodeB='||SA17|'+CONVERT(varchar(20),@XSID)+'|'+CONVERT(varchar(10),@IROWNO)
IF @XSbsaleprice=1 --含税价格本
BEGIN
SET @iQuotedPrice=@XSiinvnowcost
SET @iUnitPrice=ROUND(@XSiinvnowcost/(1+@XSiCusTaxRate*0.01),2)
SET @iTaxUnitPrice=@XSiinvnowcost
SET @iMoney=ROUND(@XSiQuantity*(@XSiinvnowcost/(1+@XSiCusTaxRate*0.01)),2)
SET @iTax=ROUND((@XSiQuantity*@XSiinvnowcost)/(1+@XSiCusTaxRate*0.01)*(@XSiCusTaxRate*0.01),2)
SET @iSum=ROUND(@XSiQuantity*@XSiinvnowcost,2)
SET @iNatUnitPrice=ROUND(@XSiinvnowcost/(1+@XSiCusTaxRate*0.01),2)
SET @iNatMoney=ROUND(@XSiQuantity*(@XSiinvnowcost/(1+@XSiCusTaxRate*0.01)),2)
SET @iNatTax=ROUND((@XSiQuantity*@XSiinvnowcost)/(1+@XSiCusTaxRate*0.01)*(@XSiCusTaxRate*0.01),2)
SET @iNatSum=ROUND(@XSiQuantity*@XSiinvnowcost,2)
END
ELSE IF @XSbsaleprice=0 --不含税价格本
BEGIN
SET @iQuotedPrice=ROUND(@XSiinvnowcost*(1+@XSiCusTaxRate*0.01),2)
SET @iUnitPrice=@XSiinvnowcost
SET @iTaxUnitPrice=ROUND(@XSiinvnowcost*(1+@XSiCusTaxRate*0.01),2)
SET @iMoney=ROUND(@XSiQuantity*@XSiinvnowcost,2)
SET @iTax=ROUND(@XSiQuantity*@XSiinvnowcost*(@XSiCusTaxRate*0.01),2)
SET @iSum=ROUND(@XSiQuantity*(@XSiinvnowcost*(1+@XSiCusTaxRate*0.01)),2)
SET @iNatUnitPrice=@XSiinvnowcost
SET @iNatMoney=ROUND(@XSiQuantity*@XSiinvnowcost,2)
SET @iNatTax=ROUND(@XSiQuantity*@XSiinvnowcost*(@XSiCusTaxRate*0.01),2)
SET @iNatSum=ROUND(@XSiQuantity*(@XSiinvnowcost*(1+@XSiCusTaxRate*0.01)),2)
END
SET @DIS=0.00 SET @KL=100.0000000000 SET @SALE=0.0000000000
INSERT INTO SO_SODetails
(cSOCode,ID,iSOsID,cInvCode,dPreDate,iQuantity,iQuotedPrice,iUnitPrice,iTaxUnitPrice,iMoney,iTax,iSum,iDisCount,iNatUnitPrice,iNatMoney
,iNatTax,iNatSum,iNatDisCount,KL,KL2,cInvName,iTaxRate,cMemo,fSaleCost,fSalePrice,dPreMoDate,iRowNo,cCusInvCode,cCusInvName
,fcusminprice,ballpurchase,bOrderBOM,bOrderBOMOver,busecusbom,bsaleprice,bgift,cbSysBarCode)
VALUES(@cSOCode,@XSID,@XSBID,@XScInvCode,@XSdDate,@XSiQuantity,@iQuotedPrice,@iUnitPrice,@iTaxUnitPrice,@iMoney,@iTax,@iSum,@DIS,@iNatUnitPrice,@iNatMoney
,@iNatTax,@iNatSum,@DIS,@KL,@KL,@XScInvName,@XSiCusTaxRate,NULL,@SALE,@SALE,@XSdDate,@IROWNO,@XScCusInvCode,@XScCusInvName,
@SALE,0,0,0,0,1,0,@cSysBarCodeB)
SET @error+=@@ERROR ---------------记录有可能产生的错误号
FETCH NEXT FROM cur_XSDD_B
INTO @XScInvCode,@XScInvName,@XSiQuantity,@XSiinvnowcost,@XSbsaleprice,@XScCusInvCode,@XScCusInvName
END
CLOSE cur_XSDD_B
DEALLOCATE cur_XSDD_B
SET @IROWNO=@IROWNO+1
END
FETCH NEXT FROM cur_XSDD
INTO @XSdDate,@XScCusDepart,@XScCusPPerson,@XScCusCode,@XScCusName,@XSiCusTaxRate,@XScCusExch_name,@XScInvoiceCompany
END
CLOSE cur_XSDD
DEALLOCATE cur_XSDD
--判断事务的提交或者回滚
IF(@error<>0)
BEGIN
ROLLBACK TRANSACTION
SET @val='销售订单导入失败,请检查来源数据!'
RETURN -1 --设置操作结果错误标识
END
ELSE
BEGIN
COMMIT TRANSACTION
SET @val='销售订单导入成功,请重新刷新!'
RETURN 1 --操作成功的标识
END
GO
|
|