You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
sql-tools/ImportBK/导BOKA_4_Go.sql

2187 lines
79 KiB

--这是最终导入数据的脚本
--先整个执行此文件,
--然后拉到最下面,顺序执行每条语句
--注意: 如果执行了1之后又产生了业务单据, 必须重新执行一次1的第二步
------------------------------------------------------------------
--导入公司
IF object_id('dbo.PImportBKCompany','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKCompany
END
GO
CREATE PROCEDURE PImportBKCompany
AS
BEGIN
DECLARE @Sql VARCHAR(8000)
--公司资料
EXEC PExecImportSQL 'DELETE {TDB}.TCompany WHERE FId > 0'
SELECT @Sql =
'INSERT INTO {TDB}.TCompany(FId,FNo,FName,FAbbr,FAreaId,FParentId,FAddress,FTelephone,FEmail,FWebsite,FWeChatNo,FWeChatQRCode,FIntroduction,FAdmin,FIsCenter)
SELECT dbo.FNBkCompId(gae01c), gae01c,gae02c,gae03c,0,0,isnull(gae08c,''''),isnull(gae06c,''''),'''','''','''','''','''',isnull(gae14c,''''),0 FROM {FDB}.gam05 '
EXEC PExecImportSQL @Sql
EXEC PExecImportSQL 'UPDATE {TDB}.TCompany SET FId = 1 , FIsCenter = 1 WHERE FNo = ''001'''
EXEC PExecImportSQL 'UPDATE {TDB}.TCompany SET FParentId = 1 WHERE FId > 1'
EXEC PExecImportSQL 'UPDATE {TDB}.TCompany SET FParentId = 0 WHERE FId <= 1'
-- EXEC PExecImportSQL 'SELECT * FROM {TDB}.TCompany'
END
GO
/*
SELECT * FROM TCompany
*/
--导入用户
IF object_id('dbo.PImportBKUser','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKUser
END
GO
CREATE PROCEDURE PImportBKUser
AS
BEGIN
EXEC PExecImportSQL 'DELETE {TDB}.TUserAllowCompany '
EXEC PExecImportSQL 'DELETE {TDB}.TUser WHERE FId > 0'
EXEC PExecImportSQL 'INSERT INTO {TDB}.TUser(FId,FNo,FName,FEmpId,FPW,FCreateTime,FUserType)
SELECT FId,gaa01c,ISNULL(gaa06c,''''),0,isnull(gaa02c,''''),getdate(),''PCClient,MOBFrontDesk''
FROM {FDB}.gam01 '
--可登陆公司
EXEC PExecImportSQL 'INSERT {TDB}.TUserAllowCompany(FId,FUserId,FCompId)
SELECT dbo.FNNewId(),A.FId,C.FId
FROM {FDB}.GAM02 AS B,{TDB}.TCompany AS C ,{TDB}.TUser AS A
WHERE B.gab03c = C.FNo
AND B.gab02c = ''2''
AND A.FNo = B.gab01c'
EXEC PExecImportSQL 'DELETE {TDB}.TUserAllowCompany WHERE FUserId = (SELECT FId FROM {TDB}.TUser WHERE FNo = ''ADMIN'') UPDATE {TDB}.TUser SET FId = 1 WHERE FNo = ''ADMIN'' '
END
GO
/*
select * from tuser
*/
--导入支付方式
IF object_id('dbo.PImportBKPayaccount','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKPayaccount
END
GO
CREATE PROCEDURE PImportBKPayaccount
AS
BEGIN
/*
UPDATE A
SET A.FItemTurnoverRate = isnull( gso03i,0),
A.FItemPerfRate = isnull( gso03i,0),
A.FGoodsTurnoverRate =isnull( gso06f,0),
A.FGoodsPerfRate = isnull( gso06f,0),
A.FCardTurnoverRate = isnull( gso05f,0),
A.FCardPerfRate = isnull( gso05f,0),
A.FItemPointRate =isnull( gso04f,0),
A.FGoodsPointRate =isnull( gso04f,0),
A.FIsTurnOver = isnull(gso07f,0)
FROM TPayAccountSetting AS A,fromserver.yantai_GAOYUAN8Yf0ONQV6.dbo.gsm15 AS B,
TPayAccount AS C
WHERE C.FBKPayNo = B.gso02c
AND B.gso00c = '001'
AND C.FId = A.FPayAcctId
*/
--EXEC PExecImportSQL ' DELETE {TDB}.TPayAccount '
EXEC PInitPayAccount
EXEC PExecImportSQL '
IF NOT EXISTS(SELECT TOP 1 1 FROM {TDB}.syscolumns WHERE id=object_id(''TPayAccount'') AND name = ''FBKAcctId'')
BEGIN
ALTER TABLE {TDB}.TPayAccount ADD FBKAcctId INT NOT NULL DEFAULT 0
END '
EXEC PExecImportSQL '
IF NOT EXISTS(SELECT TOP 1 1 FROM {TDB}.syscolumns WHERE id=object_id(''TPayAccount'') AND name = ''FBKPayNo'')
BEGIN
ALTER TABLE {TDB}.TPayAccount ADD FBKPayNo VARCHAR(10) NOT NULL DEFAULT ''''
END'
--支付方式
--EXEC PExecImportSQL ' DELETE {TDB}.TPayAccount WHERE FId IN(20,21,22) '
EXEC PExecImportSQL ' UPDATE {TDB}.TPayAccount SET FBKAcctId = 0 '
EXEC PExecImportSQL ' DELETE {TDB}.TPayAccount WHERE FNo LIKE ''$%'' OR FNo >= ''A'' '
--现金
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 1
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''1''
AND s.gsn01c = gsb02c'
--银行卡
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 2
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''6''
AND s.gsn01c = gsb02c'
--抵用券
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 5
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''3''
AND s.gsn01c = gsb02c'
--储值账户
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 3
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''4''
AND s.gsn01c = gsb02c'
--储值账户
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 9
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''5''
AND s.gsn01c = gsb02c'
--银行卡
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 2
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''6''
AND s.gsn01c = gsb02c'
--积分
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 11
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''7''
AND s.gsn01c = gsb02c'
--经理签单
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 8
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''8''
AND s.gsn01c = gsb02c'
--疗程账户
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 6
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''9''
AND s.gsn01c = gsb02c'
--微信
EXEC PExecImportSQL '
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 20
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''WX''
AND s.gsn01c = gsb02c'
EXEC PExecImportSQL '
--支付宝
UPDATE A
SET A.FName = b.gsb03c,
A.FBKAcctId = s.gsn02c,
A.FBKPayNo = s.gsn01c
FROM {TDB}.TPayAccount AS A,{FDB}.gsm02 AS B,{FDB}.gsm14 as s
WHERE A.FId = 21
AND B.gsb00c = ''001''
AND B.gsb01c = ''3''
AND B.gsb02c = ''ZF''
AND s.gsn01c = gsb02c'
--电子钱包
EXEC PExecImportSQL '
IF EXISTS(SELECT TOP 1 1 FROM {FDB}.gcm03 WHERE gcc03i = 1) AND NOT EXISTS(SELECT TOP 1 1 FROM {TDB}.TPayAccount WHERE FId = 14 )
BEGIN
INSERT INTO {TDB}.TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit,FBKAcctId,FBKPayNo)
SELECT 14,''DZ'',(SELECT gsb03c FROM {FDB}.gsm02 WHERE gsb01c = ''o'' AND gsb02c = ''1'' AND gsb00c = ''001''),'''',1,1,20,-1,''1'',''2''
END'
--内调
EXEC PExecImportSQL '
INSERT INTO {TDB}.TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit,FBKAcctId,FBKPayNo)
SELECT dbo.FNNewId(),''0'',(SELECT gsb03c FROM {FDB}.gsm02 WHERE gsb01c = ''3'' AND gsb02c = ''0'' AND gsb00c = ''001''),'''',0,1,20,-1,''0'',''0''
'
--$支付
EXEC PExecImportSQL '
DECLARE @PayNo varchar(10)
DECLARE @PayName VARCHAR(30)
DECLARE @Id BIGINT
DECLARE CursorOtherPay cursor for
SELECT FId,gsb02c,gsb03c from {FDB}.gsm02 where gsb01c = ''3'' AND (gsb02c LIKE ''$%'' OR gsb02c BETWEEN ''A'' AND ''ZZ'') AND gsb00c=''001''
OPEN CursorOtherPay
FETCH CursorOtherPay INTO @Id,@PayNo,@PayName
WHILE @@fetch_status=0
BEGIN
DECLARE @IsAcct BIT
IF @PayNo LIKE ''$%''
BEGIN
SET @IsAcct = 0
END
ELSE
BEGIN
SET @IsAcct = 1
END
INSERT INTO {TDB}.TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit,FBKAcctId,FBKPayNo)
SELECT @Id,@PayNo,@PayName,'''',@IsAcct,1,20,-1,gsn02c,gsn01c
FROM {FDB}.gsm14
WHERE @PayNo = gsn01c
--DELETE TPayAccount WHERE FNo >= ''A''
PRINT @PayNo
FETCH CursorOtherPay INTO @Id,@PayNo,@PayName
END
CLOSE CursorOtherPay
DEALLOCATE CursorOtherPay'
IF NOT EXISTS(SELECT 1 FROM TPayAccount WHERE FId = 20)
BEGIN
INSERT TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit)
VALUES (20,'WX','微信','微信支付,系统固定',0,1,14,10)
END
IF NOT EXISTS(SELECT 1 FROM TPayAccount WHERE FId = 21)
BEGIN
INSERT TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit)
VALUES (21,'ZFB','支付宝','支付宝支付,系统固定',0,1,14,10)
END
EXEC PExecImportSQL ' DELETE {TDB}.TPayAccount WHERE FId = 10 AND EXISTS(SELECT 1 FROM {TDB}.TPayAccount WHERE FName LIKE ''赠送账户%'')'
END
GO
/*
select * from TPayAccount
*/
--导入基本类别
IF object_id('dbo.PImportBKBasicType','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKBasicType
END
GO
CREATE PROCEDURE PImportBKBasicType
AS
BEGIN
DELETE TBasicTypeSub
EXEC PExecImportSQL '
DELETE {TDB}.TBasicType WHERE FKey IN( ''CustomerSource'',''ServeDispatchKind'')
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
SELECT 30001,''CustomerSource'',''001'',''默认'','''',0,'''',1,-1,1
UNION ALL
SELECT 30002,''CustomerSource'',''002'',''客户介绍'','''',0,'''',1,-1,1
UNION ALL
SELECT 30003,''CustomerSource'',''003'',''内创'','''',0,'''',1,-1,1
UNION ALL
SELECT 30004,''CustomerSource'',''004'',''外创'','''',0,'''',1,-1,1
UNION ALL
SELECT 30005,''CustomerSource'',''005'',''短信营销'','''',0,'''',1,-1,1
UNION ALL
SELECT 10011,''ServeDispatchKind'',''1'',''指定'',0,'''','''',1,14,0
UNION ALL
SELECT 10012,''ServeDispatchKind'',''2'',''非指定'',0,'''','''',2,14,0
UNION ALL
SELECT 10010,''ServeDispatchKind'',''0'',''其他'',0,'''','''',3,14,0'
EXEC PExecImportSQL '
DELETE {TDB}.TBasicType WHERE FId > 0 AND FKey NOT IN (''MemSaleWorkType'',''GoodsSaleWorkType'')
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 11001)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(11001,''ServeWorkType'',''1'',''发型师'',0,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 11002)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(11002,''ServeWorkType'',''2'',''洗护师'',0,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 11003)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(11003,''ServeWorkType'',''3'',''烫染师'',0,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 11004)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(11004,''ServeWorkType'',''4'',''美容师'',0,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 10001)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(10001,''ServeDispatchMode'',''1'',''指定'',10011,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 10002)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(10002,''ServeDispatchMode'',''2'',''非指定'',10012,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 10003)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(10003,''ServeDispatchMode'',''3'',''自定义1'',10011,'''','''',1,14,1)
END
IF NOT EXISTS (SELECT TOP 1 1 FROM {TDB}.TBasicType WITH(NOLOCK) WHERE FId = 10004)
BEGIN
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
VALUES(10004,''ServeDispatchMode'',''4'',''自定义2'',10012,'''','''',1,14,1)
END
'
EXEC PExecImportSQL '
SELECT
FId,
CASE gsb01c
WHEN ''AL'' THEN ''GoodsType''
WHEN ''AJ'' THEN ''ItemType''
WHEN ''AR'' THEN ''ItemKind''
WHEN ''N'' THEN ''Expenses''
WHEN ''K'' THEN ''GoodsUnit''
WHEN ''R'' THEN ''Position''
WHEN ''U'' THEN ''Department''
WHEN ''F'' THEN ''GoodsDiscountType''
WHEN ''A5'' THEN ''OtherIncome''
WHEN ''N'' THEN ''Expenses''
WHEN ''L'' THEN ''ItemDiscountType''
WHEN ''B4'' THEN ''RoomType''
ELSE '''' END AS [FKey] ,gsb02c AS FNo,gsb03c AS FName
INTO #BasicType
FROM {FDB}.gsm02
WHERE gsb00c = ''001''
DELETE #BasicType WHERE LEN(FKey) <= 3
DELETE A
FROM {TDB}.TBasicType AS A,#BasicType AS B
WHERE A.FKey = B.FKey
AND A.FNo = B.FNo
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FEnabled)
SELECT FId as FId,FKey,FNo,FName,0,'''','''',1,1 FROM #BasicType
DROP TABLE #BasicType
--服务类别
UPDATE A
SET A.FNo = CASE WHEN (A.FId = 11001 AND B.gsb02c = ''1'')
OR ( A.FId=11002 AND B.gsb02c=''2'')
OR ( A.FId=11003 AND B.gsb02c=''3'')
OR ( A.FId=11004 AND B.gsb02c=''4'')
THEN B.gsb02c ELSE A.FNo End,
A.FName = CASE WHEN (A.FId = 11001 AND B.gsb02c = ''1'')
OR ( A.FId=11002 AND B.gsb02c=''2'')
OR ( A.FId=11003 AND B.gsb02c=''3'')
OR ( A.FId=11004 AND B.gsb02c=''4'')
THEN B.gsb03c ELSE A.FName End
FROM {TDB}.TBasicType AS A, {FDB}.gsm02 AS B
WHERE gsb01c = ''AK''
AND A.FKey = ''ServeWorkType''
AND B.gsb02c = CASE WHEN A.FId = 11001 THEN ''1''
WHEN A.FId=11002 THEN ''2''
WHEN A.FId=11003 THEN ''3''
WHEN A.FId=11004 THEN ''4''END
--指定方式
UPDATE A
SET A.FNo = CASE WHEN (A.FId = 10001 AND B.gsb02c = ''1'')
OR ( A.FId=10002 AND B.gsb02c=''2'')
OR ( A.FId=10003 AND B.gsb02c=''3'')
OR ( A.FId=10004 AND B.gsb02c=''4'')
THEN B.gsb02c ELSE A.FNo End,
A.FName = CASE WHEN (A.FId = 10001 AND B.gsb02c = ''1'')
OR ( A.FId=10002 AND B.gsb02c=''2'')
OR ( A.FId=10003 AND B.gsb02c=''3'')
OR ( A.FId=10004 AND B.gsb02c=''4'')
THEN B.gsb03c ELSE A.FName End
FROM {TDB}.TBasicType AS A, {FDB}.gsm02 AS B
WHERE gsb01c = ''B''
AND A.FKey = ''ServeDispatchMode''
AND B.gsb02c = CASE WHEN A.FId = 10001 THEN ''1''
WHEN A.FId=10002 THEN ''2''
WHEN A.FId=10003 THEN ''3''
WHEN A.FId=10004 THEN ''4''END
--仓库
DELETE {TDB}.TBasicType WHERE FKey = ''Store''
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FEnabled)
SELECT FId,''Store'',gad01c,gad02c,0,'''','''',1,1
FROM {FDB}.gam04
WHERE gad00c = ''001'''
--入库方式
EXEC PInitBasicTypeRow @Id=22001,@Key='StockInType',@No='001',@Name='其他入库',@ParentId=0,@Description='系统固定,不能修改',@Order=1,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=22002,@Key='StockInType',@No='002',@Name='采购入库',@ParentId=0,@Description='系统固定,不能修改',@Order=2,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=22003,@Key='StockInType',@No='003',@Name='盘盈入库',@ParentId=0,@Description='系统固定,不能修改',@Order=3,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=22005,@Key='StockInType',@No='004',@Name='门店调拨',@ParentId=0,@Description='系统固定,不能修改',@Order=4,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=22007,@Key='StockInType',@No='005',@Name='仓库调拨',@ParentId=0,@Description='系统固定,不能修改',@Order=5,@AllowEdit=0,@Custom=''
--出库方式
EXEC PInitBasicTypeRow @Id=23001,@Key='StockOutType',@No='001',@Name='其他出库',@ParentId=0,@Description='系统固定,不能修改',@Order=1,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23004,@Key='StockOutType',@No='002',@Name='盘亏出库',@ParentId=0,@Description='系统固定,不能修改',@Order=2,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23005,@Key='StockOutType',@No='003',@Name='门店调拨',@ParentId=0,@Description='系统固定,不能修改',@Order=3,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23007,@Key='StockOutType',@No='004',@Name='仓库调拨',@ParentId=0,@Description='系统固定,不能修改',@Order=4,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23006,@Key='StockOutType',@No='005',@Name='员工领用',@ParentId=0,@Description='系统固定,不能修改',@Order=5,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23008,@Key='StockOutType',@No='006',@Name='店内领用',@ParentId=0,@Description='系统固定,不能修改',@Order=6,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23009,@Key='StockOutType',@No='007',@Name='供应商退货',@ParentId=0,@Description='系统固定,不能修改',@Order=7,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23099,@Key='StockOutType',@No='008',@Name='销售出库',@ParentId=0,@Description='系统固定,不能修改',@Order=8,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow @Id=23098,@Key='StockOutType',@No='009',@Name='消耗出库',@ParentId=0,@Description='系统固定,不能修改',@Order=9,@AllowEdit=0,@Custom=''
EXEC PInitBasicTypeRow 50005,'EvalLevel','5','好评',0,'','',5,14
--EXEC PInitBasicTypeRow 50004,'EvalLevel','4','很赞',0,'','',4,14
EXEC PInitBasicTypeRow 50003,'EvalLevel','3','中评',0,'','',3,14
--EXEC PInitBasicTypeRow 50002,'EvalLevel','2','有点弱',0,'','',2,14
EXEC PInitBasicTypeRow 50001,'EvalLevel','1','差评',0,'','',1,14
INSERT TBasicTypeSub(FBasicTypeId,FCompId)
SELECT A.FId,C.FId
FROM TBasicType AS A,TCompany AS C
WHERE A.FId > 0
AND C.FId > 0
AND NOT EXISTS(SELECT TOP 1 1 FROM TBasicTypeSub AS B WHERE B.FCompId = C.FId AND B.FBasicTypeId = A.FId)
END
GO
/*
select * from TBasicType
*/
--导入员工
IF object_id('dbo.PImportBKEmployee','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKEmployee
END
GO
CREATE PROCEDURE PImportBKEmployee
AS
BEGIN
EXEC PExecImportSQL '
DELETE {TDB}.TEmployee WHERE FId > 0
DELETE {TDB}.TEmployeeSub
DECLARE @ExcludeCompNo VARCHAR(5)
SELECT @ExcludeCompNo = ''''
IF (SELECT COUNT(1) FROM {FDB}.gam05) > 1
BEGIN
SELECT @ExcludeCompNo = ''001''
END
SELECT MIN(FId) AS FId,
dbo.FNBKCompId( MIN(haa00c)) AS FCompId,
MIN(haa00c) AS FCompNo,
cast(haa01c as varchar(30)) AS FNo,
haa01c AS FSerialNo,
haa02c AS FName,
haa02c AS FNickname,
MAX(ISNULL(haa03c,'''')) AS FEnLname,
MAX(ISNULL(haa04c,'''')) AS FEnFname,
MAX(ISNULL(haa05i,0)) AS FGender,
(SELECT FId FROM TBasicType WHERE FNo = MAX(haa06c) AND FKey = ''Department'') AS FDeptId,--部门编号
MAX(dbo.FNBKDate(haa08d)) AS FEntryDate ,--到职日期
MAX(dbo.FNBKDate(haa09d)) AS FLeaveDate,--离职日期
MAX(dbo.FNBKDate(haa11d)) AS FExpiredDate,--合约到期日
MAX(ISNULL(haa12c,'''')) AS FIdCard,--身份证号
MAX(dbo.FNBKDate(haa14d)) AS FBirthday,--出生日期
MAX(ISNULL(haa18c,'''')) AS FAddress ,--联络地址
ISNULL(haa20c,'''') AS FMobilePhone ,--行动电话
(SELECT FId FROM TBasicType WHERE FNo = MAX(haa25c) AND FKey = ''Position'') AS FPosId,--职位
--haa27c varchar(1) NULL ,--目前状况(1-未到职 ,2-到职 ,3 -离职)
MAX(ISNULL(haa28i,0)) AS FAllowSign ,--是否可以经理签单
MAX(ISNULL(haa33c,'''')) AS FPW , --密码
MAX(ISNULL(haa32c ,''''))AS FDescription,--备注
MAX(ISNULL(dbo.FNBKDate(haa92d),getdate())) AS FCreateDate ,--登录日期
MAX(ISNULL(haa35c,'''')) AS FLinkMan,--紧急联系人
MAX(ISNULL(haa36c,'''')) AS FLinkManTel,--紧急联系人电话
MAX(ISNULL(haa37c,'''')) AS FLinkManAddr,--紧急联系人地址
MAX(ISNULL(haa46i,1)) AS FAllowBooking --是否可以预约
INTO #Employee
FROM {FDB}.ham01
WHERE isnull(haa00c,'''') != ''''
AND haa00c IN(SELECT FNo FROM {TDB}.TCompany)
-- AND haa00c = ''005''
AND haa00c != @ExcludeCompNo
GROUP BY haa01c,haa02c,ISNULL(haa20c,'''')
UPDATE #Employee
SET FNo = FCompNo + FNo
WHERE FNo IN ( SELECT FNo
FROM #Employee
GROUP BY FNo HAVING COUNT(1) > 1
)
SELECT A.FId,dbo.FNBKCompId(haa00c) AS FCompId,haa01c AS FSerialNo INTO #Company
FROM {FDB}.ham01 AS B
INNER JOIN #Employee AS A ON A.FNo = B.haa01c OR A.FNo = B.haa00c + B.haa01c
WHERE isnull(haa00c,'''') != ''''
AND haa00c IN(SELECT FNo FROM {TDB}.TCompany)
-- AND haa00c = ''005''
AND haa00c != @ExcludeCompNo
DELETE {TDB}.TEmployee
WHERE FNo IN (SELECT FNo FROM #Employee)
INSERT INTO {TDB}.TEmployee(FId,FNo,FName,FEnLname,FEnFname,FNickname,FDeptId,FPosId,FTechTypeId,FBriefCode,FGender,FStature,FWeight,FNationPlace,FNation,FEducation,FMarital,FAddress,FTelephone,FMobilePhone,FQQ,FEmail,FIdCard,FBirthdayType,FBirthday,FCardNo,FPW,FBank,FBankCardNo,FSSNo,FHCNo,FLinkMan,FLinkManTel,FLinkManAddr,FMemo,FIsManager,FAllowBooking,FContractType,FState,FCreatorId,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate,FIntroduction)
SELECT FId,FNo,FName,FEnLname,FEnFname,FNickname,FDeptId,FPosId,0,dbo.FNGetFirstPinYin(FName),FGender,0,0,'''','''','''','''',FAddress,'''',FMobilePhone,'''','''',FIdCard,''G'',FBirthday,'''',FPW,'''','''','''','''',FLinkMan,FLinkManTel,FLinkManAddr,'''',FAllowSign,FAllowBooking,0,1,0,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate,FDescription
FROM #Employee
INSERT {TDB}.TEmployeeSub(FEmpId,FCompId,FSerialNo)
SELECT A.FId,A.FCompId,FSerialNo
FROM #Company AS A
DROP TABLE #Employee '
END
GO
/*
select * from TEmployee
*/
--导入项目
IF object_id('dbo.PImportBKItem','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKItem
END
GO
CREATE PROCEDURE PImportBKItem
AS
BEGIN
-- drop table #Temp
CREATE TABLE #Temp
(
Flag INT
)
EXEC PExecImportSQL '
DELETE {TDB}.TCourse WHERE FId > 1
DELETE {TDB}.TItemSub
DELETE {TDB}.TItem WHERE FId > 1
SELECT FId AS FId,
FCourseId AS FCourseId,
FNo AS FNo,
gda03c AS FName,
ISNULL((SELECT FId FROM {TDB}.TBasicType WHERE FNo = gda04c AND FKey = ''ItemDiscountType'') ,0) AS FDctId,
ISNULL(gda10f,0) AS FPrice,
ISNULL(gda11f,0) AS FVipPrice ,
ISNULL((SELECT FId FROM {TDB}.TBasicType WHERE FNo = gda13c AND FKey = ''ItemType''),0) AS FTypeId,
CASE WHEN gda14i = 1 THEN 1 ELSE 0 END AS FEnabled ,
1 AS FStatTimes,
dbo.FNBKPointMode(gda17i) AS FPointMode,
ISNULL(gda18f,0) AS FPointValue,
ISNULL(gda22f,0) AS FTimes1,
ISNULL(gda23f,0) AS FAmount1,
ISNULL(gda24f,0) AS FTimes2,
ISNULL(gda25f,0) AS FAmount2,
ISNULL(gda26f,0) AS FTimes3,
ISNULL(gda27f,0) AS FAmount3,
ISNULL(gda28f,0) AS FTimes4,
ISNULL(gda29f,0) AS FAmount4
INTO #Item
FROM {FDB}.gdm01
WHERE gda00c = ''001''
-- and FNo NOT IN (SELECT FNo FROM TItem)
-- AND FId IN (SELECT FItemId FROM TMemberCourse WHERE FCourseId NOT IN (SELECT FId FROM TCourse))
INSERT {TDB}.TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking)
SELECT FId,FNo,FNo,FName,FName,FTypeid,dbo.FNGetFirstPinYin(FName),'''',1,1,FStatTimes,'''','''','''',FEnabled,FPrice,FVipPrice,0,FDctId,FPointMode,FPointValue,0,1
FROM #Item
IF EXISTS(SELECT TOP 1 1 FROM {FDB}.gcm06)
BEGIN
-- INSERT #Temp VALUES(1)
DECLARE @Id BIGINT
DELETE {TDB}.TBasicType WHERE FKey = ''CourseType''
SELECT @Id = dbo.FNNewId()
INSERT {TDB}.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FEnabled)
SELECT @Id,''CourseType'',''1'',''疗程1'',0,'''','''',1,1
INSERT INTO {TDB}.TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT I.FCourseId AS FId,
I.FNo + ''L1'' AS FNo,
I.FName + ''-'' + ''疗程1'' AS FName,
'''' AS FBriefCode,
I.FId AS FItemId,
0 AS FPackId,
1 AS FSequence,
@Id AS FTypeId,
1 AS FTimes,
0 AS FFreeTimes,
0 AS FDurable,
0 AS FValidityPeriodUnit,
0 AS FValidityPeriod,
getdate() AS FCreateDate,
NULL AS FExpiredDate,
'''' AS FDescription,
1 AS FEnabled,
I.FPrice AS FPrice,
I.FPrice AS FAmount,
1 AS FCalcMode
FROM #Item AS I
UPDATE {TDB}.TCourse
SET FBriefCode = dbo.FNGetFirstPinYin(FName)
END
DROP TABLE #Item '
EXEC PExecImportSQL '
INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled)
SELECT dbo.FNNewId(),C.FId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled
FROM TItem AS I,TCompany AS C
WHERE I.FId != 0
AND C.FId != 0
AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId)'
--AND C.FId != 1
--删除没有这个项目的公司
EXEC PExecImportSQL '
delete TItemSub WHERE FId NOT IN(
SELECT A.FId FROM TItemSub AS A,
(
SELECT dbo.FNBkCompID(B.gda00c) AS FCompID, B.FId AS FItemId FROM {FDB}.gdm01 AS B
/* WHEREB.gda00c != ''001''*/) AS B
WHERE A.FCompID = B.FCompId
AND A.FItemId = B.FItemId
)
'
DROP TABLE #Temp
/*
EXEC PExecImportSQL 'SELECT a.gda01c,a.gda10f,a.gda03c,b.gda01c, b.gda03c,b.gda10f FROM {FDB}.gdm01 as b, {FDB}.gdm01 as a WHERE a.gda00c = ''009''
and b.gda00c = ''016'' and a.gda01c = b.gda01c '
*/
END
GO
/*
select * from TItem
select * from TUser
*/
--导入产品
IF object_id('dbo.PImportBKGoods','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKGoods
END
GO
CREATE PROCEDURE PImportBKGoods
AS
BEGIN
EXEC PExecImportSQL '
SELECT FId AS FId,
gfa01c AS FNo, -- 产品编号
ISNULL(gfa02c,'''') AS FBarCode, -- 条码编号
ISNULL(gfa03c,'''') AS FName, -- 产品名称
ISNULL((SELECT FId FROM TBasicType WHERE FNo = gfa05c AND FKey = ''GoodsDiscountType'') ,0) AS FDctId, --产品大类(用于折扣)
ISNULL((SELECT FId FROM TBasicType WHERE FNo = gfa07c AND FKey = ''GoodsUnit'') ,0) AS FUnitId, -- 销售单位(标准单位)
--gfa08c varchar(5) NULL, -- 消耗单位
--gfa09f float NULL, -- 销售单位对应消耗单位数量
CASE WHEN gfa10c = ''1'' THEN 0 ELSE 1 END AS FEnabled, -- 是否停用
ISNULL(gfa11f,'''') AS FSalePrice, -- 标准价格(销售单位)
ISNULL(gfa12c,'''') AS FSpecification, -- 产品规格
--gfa15f float NULL, -- 成本金额(消耗单位)
-- gfa16i tinyint NULL, -- 业绩方式
-- gfa17f float NULL, -- 金额或比率
ISNULL(gfa19f,0) AS FSaleCostPrice, -- 销售成本(标准单位)
ISNULL((SELECT FId FROM TBasicType WHERE FNo = gfa20c AND FKey = ''GoodsUnit''),0) AS FPurUnitId, -- 产品进货单位
-- gfa21f float NULL, -- 进货单位对应销售单位数量
ISNULL(gfa22f,0) AS FPurCostPrice, -- 产品进价(标准单位)
-- gfa23c varchar(5) NULL, -- 产品供应商
ISNULL((SELECT FId FROM TBasicType WHERE FNo = gfa24c AND FKey = ''GoodsType''),0) AS FTypeId, -- 统计分类
dbo.FNBKPointMode(gfa25i) AS FPointMode, -- 积分方式
ISNULL(gfa26f,0) AS FPointValue--, -- 积分或比率
--gfa28i int NULL, -- 保质期
--gfa29f float NULL, -- 最高存量(标准单位)
INTO #Goods
FROM {FDB}.gfm01
WHERE gfa00c = ''001''
-- AND FId NOT IN(SELECT FId FROM TGoods)
DELETE {TDB}.TGoods
DELETE {TDB}.TGoodsMultiUnit
INSERT INTO {TDB}.TGoods(FId,FNo,FName,FNoOfPad,FTypeId,FBriefCode,FUnitId,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FValuationMode,FBarCode,FEnabled,FSpecification,FPurUnitId,FConsUnitId,FSupplierId,FStoreId,FConsStoreId,FSaleStoreId,FMaxStock,FMinStock,FPeriodEnabled,FShelfLife,FDctId,FPointMode,FPointValue,FDeptId,FUnitLock,FDescription,FCustom1,FCustom2,FCustom3)
SELECT FId,FNo,FName,FNo,FTypeId,dbo.FNGetFirstPinYin(FName),FUnitId,FSalePrice,FPurCostPrice AS FPurCostPrice,FSaleCostPrice AS FSaleCostPrice,0 AS FConsCostPrice,0,FBarCode,FEnabled,'''',FPurUnitId,0,0,0,0,0,0,0,0,0,FDctId,FPointMode,FPointValue,0,0,'''','''','''',''''
FROM #Goods
INSERT INTO {TDB}.TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock)
SELECT dbo.FNNewId(),A.FId,1,FUnitId,1,1,1,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,0
FROM {TDB}.TGoods AS A
DROP TABLE #Goods'
EXEC PExecImportSQL '
INSERT INTO TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock)
SELECT dbo.FNNewId(),G.FId,0,(SELECT FId FROM {FDB}.gsm02 WHERE gsb00c = ''001'' AND gsb01c = ''k'' AND gsb02c = gfa08c),2,1,isnull(gfa09f,1) as FSalePrice,isnull(gfa15f,0) as FPurCostPrice,isnull(gfa15f,0) as FSaleCostPrice,isnull(gfa15f,0) as FConsCostPrice,isnull(gfa15f,0) as FConsCostPrice,'''',0
FROM {FDB}.GFM01 as g
WHERE ISNULL(gfa08c,'''') != ''''
AND gfa07c != ISNULL(gfa08c,'''')
AND gfa00c = ''001'' '
EXEC PExecImportSQL '
INSERT INTO TItemCostGoods(FId,FItemId,FGoodsId,FGoodsUnitId,FGoodsQuantity)
SELECT dbo.FNNewId(),FItemId,FGoodsId,FUnitId,gfe03f
FROM {FDB}.gfm05 WHERE gfe00c = ''001'''
INSERT TGoodsSub(FId,FCompId,FGoodsId)
SELECT dbo.FNNewId(),C.FId,I.FId
FROM TGoods AS I,TCompany AS C
WHERE I.FId != 0
AND C.FId != 0
AND NOT EXISTS(SELECT TOP 1 1 FROM TGoodsSub AS B WHERE B.FCompId = C.FId AND B.FGoodsId = I.FId)
END
GO
/*
select * from TGoods
*/
--导入卡类别
IF object_id('dbo.PImportBKCardType','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKCardType
END
GO
CREATE PROCEDURE PImportBKCardType
AS
BEGIN
/*
select * into #gam10 from gam10 where 1=2
declare @compNo varchar(10)
declare dbList cursor for
select distinct gae01c from gam05 where gae01c != '001'
open dbList
fetch dbList into @compNo
while @@fetch_status=0
begin
insert #gam10
select * FROM gam10 WHERE gak01c NOT IN(SELECT gak01c FROM gam10 WHERE gak00c = '001')
and gak00c = @compNo and gak01c not in (select gak01c from #gam10)
fetch dbList into @compNo
end
close dbList
deallocate dbList
UPDATE #gam10 SET gak00c = '001'
INSERT gam10
SELECT * FROM #gam10
*/
EXEC PExecImportSQL ' --卡类别
DECLARE @Count INT
SELECT @Count = count(1)
FROM {FDB}.gam10
WHERE gak00c != ''001''
AND gak01c NOT IN(SELECT gak01c FROM {FDB}.gam10 WHERE gak00c = ''001'')
IF @Count > 0
BEGIN
RAISERROR (''会员卡类别不统一'', 16, 1, 1, 1, 1)
return
END
SELECT FId AS FId , --类别代码
ISNULL(gak01c,'''') AS FNo, --类别名称
ISNULL(gak02c,'''') AS FName, --类别名称
ISNULL(gak03i,'''') AS FValueType , --大类(1-储值卡, 2- 资格卡,3-计次卡,4-单次卡)
ISNULL(gak07f,'''') AS FValidityPeriod, --有效期限
ISNULL(gak08c,0) AS FValidityPeriodUnit , --期限单位
ISNULL(gak09f,'''') AS FPrice, --标准售价
ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak14i),0) AS FAcctId , --默认账户类别
ISNULL(gak16f,'''') AS FDeposit, --储值金额 ,Added by WUXM, 2004/02/16
ISNULL(gak06i,'''') AS FTimes,
CASE gak29i WHEN 1 THEN 1
WHEN 0 THEN 2
WHEN 3 THEN 3
ELSE 0 END AS FMaterial, --卡介质类型 0磁卡 1IC卡,2 可视磁卡 3 可视IC卡
ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak35i),0) AS FAcctId2 , --第二账户类别
ISNULL(gak36f,'''') AS FDeposit2 , --第二账户金额
ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak37i),0) AS FAcctId3 , --第三账户类别
ISNULL(gak38f,'''') AS FDeposit3 , --第二账户金额
CASE WHEN gak41i = 1 THEN 0 ELSE 1 END AS FAllowSale, --停止销售 1停止
CASE WHEN gak42i = 1 THEN 0 ELSE 1 END AS FAllowRchg, --停止销售 1停止
ISNULL(gak43f,'''') AS FAlertBalance, --安全余额 Add by maql 2010/03/24
ISNULL(gak40f,'''') AS FMinRchgAmt,
dbo.FNBKPointMode(gak30i) AS FSalePointMode,
dbo.FNBKPointMode(gak30i) AS FRchgPointMode,
ISNULL(CASE WHEN ISNULL(gak30i,0) NOT IN(0,1) THEN ISNULL(gak31i,0) / 100 ELSE gak31i END,0) AS FSalePointValue,
ISNULL(CASE WHEN ISNULL(gak30i,0) NOT IN(0,1) THEN ISNULL(gak31i,0) / 100 ELSE gak31i END,0) AS FRchgPointValue,
ISNULL(gak22f,0) AS FItemTurnoverRate ,
ISNULL(gak24f,0) AS FGoodsTurnoverRate,
ISNULL(gak33f,0) AS FItemPointRate,
ISNULL(gak34f,0) AS FGoodsPointRate
INTO #CardType
FROM {FDB}.gam10
WHERE gak00c = ''001''
INSERT {TDB}.TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,FEnabled,FOrder,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue)
SELECT FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,1,1,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue
FROM #CardType
INSERT INTO {TDB}.TMemberCardTypeAccount(FId,FCardTypeId,FCompId,FAcctId,FItemTurnoverRate,FGoodsTurnoverRate,FCardTurnoverRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FIsTurnover,FIsPerf,FEnabled)
SELECT dbo.FNNewId(),FId,1,3,FItemTurnoverRate,FGoodsTurnoverRate,1,FItemTurnoverRate,FGoodsTurnoverRate,0,FItemPointRate,FGoodsPointRate,1,1,1
FROM #CardType
DROP TABLE #CardType '
-- AND C.FId = 1
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),C.FId,I.FId,FAllowSale,FAllowRchg,FEnabled
FROM TMemberCardType AS I,TCompany AS C
WHERE I.FId > 1
AND C.FId != 0
AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
-- select * from TMemberCardType
END
GO
--导入套餐
IF object_id('dbo.PImportBKCoursePack','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKCoursePack
END
GO
CREATE PROCEDURE PImportBKCoursePack
AS
BEGIN
SELECT * FROM TCoursePack
EXEC PExecImportSQL '
INSERT TCoursePack(FId,FNo,FName,FBriefCode,FItemTimes,FGoodsQuantity,FValidityPeriod,FValidityPeriodUniT,
FCreateDate,FExpiredDate,FDescription,FPrice,FDeptid,FAcctId,FDeposit,FEnabled,FAcctId2,FDeposit2)
SELECT FId,FNo,gta02c AS FName,dbo.FNGetFirstPinYin(gta02c) AS FBriefCode,
0 AS FItemTimes,
0 AS FGoodsQuantity,
0 AS FValidityPeriod,
0 AS FValidityPeriodUnit,
GETDATE() AS FCreateDate,
NULL AS FExpiredDate,
'''' AS FDescription,
gta03f AS FPrice,
0 AS FDeptId,
0 AS FAcctId ,
0 as FDeposit,
1 AS FEnabled,
0 AS FAcctId2,
0 as FDeposit2
FROM {FDB}.gtc01
WHERE gta00c = ''001'' '
EXEC PExecImportSQL '
INSERT INTO {TDB}.TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT A.FId,A.FId,'''','''',A.FItemId,A.FPackId,0,0,gtb03f,0,0,0,0,getdate(),null,'''',1,gtb04f,0,1
FROM {FDB}.gtc02 AS A
WHERE gtb00c = ''001'' '
EXEC PExecImportSQL '
INSERT INTO {TDB}.TCourseGoods(FId,FCourseId,FGoodsId,FPackId,FQuantity,FUnitId,Fprice)
SELECT A.FId,0,A.FGoodsId,A.FPackId,ISNULL(gtd03f,0),FUnitId,ISNULL(gtd04f,0)
FROM {FDB}.gtc03 AS A
WHERE gtd00c = ''001'''
END
GO
--导入折扣
IF object_id('dbo.PImportBKItemDiscount','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKItemDiscount
END
GO
CREATE PROCEDURE PImportBKItemDiscount
AS
BEGIN
EXEC PExecImportSQL '
DELETE TItemDiscountDetail
DELETE TItemDiscountMid
DELETE TItemDiscountMaster '
EXEC PExecImportSQL '
delete {FDB}.gdm07 where gdg03c NOT IN(SELECT gak01c FROM {FDB}.gam10)'
EXEC PExecImportSQL '
INSERT {TDB}.TItemDiscountMaster(FId,FCompId,FItemId,FType,FCreateDate,FWeek,FTimeMode)
SELECT FId,dbo.FNBKCompId(gdf00c),FItemId,1,getdate(),''YYYYYYY'',0
FROM {FDB}.gdm06 as a WHERE FItemId != '''' AND gdf02c = 1
-- AND a.gdf00c =''006''
'
EXEC PExecImportSQL '
UPDATE A
SET A.FPayTypeId = B.FId
FROM {FDB}.gdm07 AS A,TPayAccount AS B
WHERE A.gdg11i = B.FBKAcctId
-- AND a.gdg00c =''006''
'
EXEC PExecImportSQL '
INSERT {TDB}.TItemDiscountMid(FId, FParentId, FCardTypeId,FPayTypeId,FBeginDate,FEndDate)
SELECT A.FId,A.FMasterId,A.FCardTypeId,A.FPayTypeId,ISNULL(dbo.FNBKdate(A.gdg06d),''1753-01-01''),ISNULL(dbo.FNBKdate(A.gdg07d),''9999-12-31'')
FROM {FDB}.gdm07 AS A WITH(NOLOCK) ,
(SELECT FMasterId,FCardTypeId,FPayTypeId,MIN(gdg10f) AS FIndex FROM {FDB}.gdm07 AS F,{FDB}.gdm06 AS G
WHERE G.FId = F.FMasterId
-- AND gdg00c = ''002''
GROUP BY FMasterId,FCardTypeId,FPayTypeId) AS B
INNER JOIN {FDB}.gdm06 AS C WITH(NOLOCK) on c.Fid = B.FMasterId AND C.FItemid != ''''
WHERE gdg02c = 1
AND A.gdg10f = B.FIndex
AND A.FMasterId = B.FMasterId
AND A.FCardTypeId = B.FCardTypeId
AND A.FPayTypeId = B.FPayTypeId
-- AND A.gdg00c = ''002''
order by gdg00c,gdg01c, gdg03c,gdg11i '
EXEC PExecImportSQL '
INSERT {TDB}.TItemDiscountDetail(FId,FParentId,FBeginTime,FEndTime,FCalcMode,FValue,FMinValue)
SELECT dbo.FNNewId(),A.FId,''1753-01-01'',''1753-01-01'',2,ISNULL(gdg04f,0),0
FROM {FDB}.gdm07 AS A,{TDB}.TItemDiscountMid AS B
WHERE A.FId = B.FId
'
END
GO
--导入项目提成
IF object_id('dbo.PImportBKItemBaseCommOne','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKItemBaseCommOne
END
GO
CREATE PROCEDURE PImportBKItemBaseCommOne
(
@WorkType VARCHAR(20),
@DispatchMode VARCHAR(20),
@ModeField VARCHAR(20),
@ValueField VARCHAR(20),
@CostField VARCHAR(20),
@HasPayment BIT
)
AS
BEGIN
--大工 点 业绩
DECLARE @Sql VARCHAR(8000)
SELECT @Sql = '
INSERT #Comm (FId,FMasterId,FCompId,FItemId,FPayTypeId,FWorkType,FDispatchMode,FPerfMode,FPerfValue,FCommMode,FCommValue,FCostMode,FCostValue,FCompNo,FItemNo,FPayTypeNo)
SELECT dbo.FNNewId() AS FId,
dbo.FNNewId(),--dbo.FNBKId(hea33c),
dbo.FNBKCompId(hea00c) AS FCompId,-- 公司别
FItemId AS FItemId, --项目代码
0 AS FPayTypeId,
' + @WorkType + ' AS FWorkType,
' + @DispatchMode + ' AS FDispatchMode,
dbo.FNBKItemPerfMode('+@ModeField+') AS FPerfMode,
ISNULL(' + @ValueField + ',0) AS FPerfValue,
CAST(0 AS INT) AS FCommMode,
CAST(0 AS DECIMAL(10,6)) AS FCommValue,
CAST(0 AS INT) AS FCostMode,
CAST(0 AS DECIMAL(10,6)) AS FCostValue,
hea00c AS FCompNo,
hea01c AS FItemNo, '
+ CASE WHEN @HasPayment = 1 THEN '
hea56c ' ELSE ' CAST(''*'' AS VARCHAR(20))' END + ' AS FPayTypeNo '
+' FROM {FDB}.hem01
WHERE hea18i = 1
AND LEN(hea00c) <= 5
-- AND hea00c = ''005''
AND cast(FItemId as bigint) != 0 '
print @SQL
EXEC PExecImportSQL @SQL
--+ CASE WHEN @HasPayment = 1 THEN ' AND hea56c = ''*'' ' ELSE '' END + '
--大工 点, 提成
SELECT @SQL = '
UPDATE #Comm
SET FCommMode = dbo.FNBKItemCommMode(' + @ModeField + '),
FCommValue = ISNULL(' + @ValueField + ',0),
FCostMode = dbo.FNBKItemCostMode(hea19i),
FCostValue = CASE WHEN ISNULL('+@CostField+',1) = 1 THEN ISNULL(hea12f,0) ELSE 0 END
FROM {FDB}.hem01 AS B
WHERE FCompNo = hea00c
AND #Comm.FItemId = B.FItemId
-- AND hea00c = ''006''
--AND dbo.FNBKCompId(hea00c) = #Comm.FCompId
AND FWorkType = ' + @WorkType +'
AND FDispatchMode = ' + @DispatchMode +'
AND hea18i = 2
AND LEN(hea00c) <= 5
--AND FMasterId = dbo.FNBKId(hea33c)
'
+ CASE WHEN @HasPayment = 1 THEN ' AND hea56c = FPayTypeNo ' ELSE '' END
--CASE WHEN @HasPayment = 1 THEN ' AND hea56c = ''*''' ELSE '' END
print @SQL
EXEC PExecImportSQL @SQL
END
GO
--导入项目提成
IF object_id('dbo.PImportBKItemBaseComm','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKItemBaseComm
END
GO
CREATE PROCEDURE PImportBKItemBaseComm
AS
BEGIN
--drop table #Comm
-- EXEC PExecImportSQL 'SELECT * FROM {FDB}.hem01 '
CREATE TABLE #Comm
(
FId BIGINT not null,
FMasterId BIGINT NOT NULL DEFAULT 0,
FCompId BIGINT not null,
FItemId BIGINT not null,
FPayTypeId BIGINT not null,
FWorkType BIGINT not null,
FDispatchMode BIGINT not null,
FPerfMode INT not null,
FPerfValue Decimal(18,6) not null,
FCommMode INT not null,
FCommValue Decimal(18,6) not null,
FCostMode INT not null,
FCostValue Decimal(18,6) not null,
FCompNo VARCHAR(5) NOT NULL,
FItemNo VARCHAR(20) NOT NULL,
FPayTypeNo VARCHAR(20) NOT NULL
)
-- DROP TABLE #Comm
EXEC PExecImportSQL 'DELETE {FDB}.hem01 WHERE hea01c not in (select gda01c from {FDB}.gdm01)'
DECLARE @HasPayment BIT
DECLARE @Sql NVARCHAR(4000)
SELECT @Sql = N'SELECT @HasPayment = (SELECT TOP 1 1 FROM {FDB}.syscolumns WHERE name = ''hea56c'' AND id = (select id from {FDB}.sysobjects where name =''hem01'' and type = ''U''))'
EXEC PBKBuildSQL @Sql,@Sql OUTPUT
print @Sql
exec sp_executesql @Sql--表示@sql中的语句包含了一个输出参数
,N'@HasPayment BIT out'
,@HasPayment out --和调用存储过程差不多,指定输出参数值
SET @HasPayment = ISNULL(@HasPayment,0)
print @HasPayment
--大工 点
EXEC PImportBKItemBaseCommOne 11001,10001,'hea02i','hea03f','hea29i', @HasPayment
--大工 轮
EXEC PImportBKItemBaseCommOne 11001,10002,'hea08i','hea09f','hea29i',@HasPayment
--大工 3
-- EXEC PImportBKItemBaseCommOne 11001,10004,'hea40i','hea41f','hea29i',@HasPayment
--大工 4
-- EXEC PImportBKItemBaseCommOne 11001,10004,'hea48i','hea49f','hea29i',@HasPayment
--中工 点
EXEC PImportBKItemBaseCommOne 11002,10001,'hea04i','hea05f','hea30i',@HasPayment
--中工 轮
EXEC PImportBKItemBaseCommOne 11002,10002,'hea14i','hea15f','hea30i',@HasPayment
--中工 3
-- EXEC PImportBKItemBaseCommOne 11002,10004,'hea42i','hea43f','hea30i',@HasPayment
--中工 4
-- EXEC PImportBKItemBaseCommOne 11002,10004,'hea50i','hea51f','hea30i',@HasPayment
--小工 点
EXEC PImportBKItemBaseCommOne 11003,10001,'hea06i','hea07f','hea31i',@HasPayment
--小工 轮
EXEC PImportBKItemBaseCommOne 11003,10002,'hea16i','hea17f','hea31i',@HasPayment
--小工 3
-- EXEC PImportBKItemBaseCommOne 11003,10004,'hea44i','hea45f','hea31i',@HasPayment
--小工 4
-- EXEC PImportBKItemBaseCommOne 11003,10004,'hea52i','hea53f','hea31i',@HasPayment
--四工 点
EXEC PImportBKItemBaseCommOne 11004,10001,'hea25i','hea26f','hea32i',@HasPayment
--四工 轮
EXEC PImportBKItemBaseCommOne 11004,10002,'hea27i','hea28f','hea32i',@HasPayment
--四工 3
-- EXEC PImportBKItemBaseCommOne 11004,10004,'hea46i','hea47f','hea32i',@HasPayment
--四工 4
-- EXEC PImportBKItemBaseCommOne 11004,10004,'hea54i','hea55f','hea32i',@HasPayment
-- EXEC PExecImportSQL 'DELETE {TDB}.TItemBaseComm'
--EXEC PExecImportSQL 'SELECT * FROM #Comm'
UPDATE A
SET A.FPayTypeId = B.FId
FROM #Comm AS A,TPayAccount AS B
WHERE A.FPayTypeNo = B.FBKPayNo
AND A.FPayTypeNo != '*'
AND A.FPayTypeNo != ''
DELETE #Comm
WHERE FPayTypeNo != '*'
AND FPayTypeId = 0
-- SELECT * FROM #Comm
-- IF (SELECT COUNT(1) FROM #Comm GROUP BY FMasterId) > 1
--BEGIN
-- END
-- ELSE
BEGIN
EXEC PExecImportSQL '
INSERT TItemBaseComm (FId,FCompId,FItemId,FPayTypeId,FWorkType,FDispatchMode,FPerfMode,FPerfValue,FCommMode,FCommValue,FCostMode,FCostValue)
SELECT dbo.FNNewId(),FCompId,FItemId,FPayTypeId,FWorkType,FDispatchMode,FPerfMode,FPerfValue,FCommMode,FCommValue,FCostMode,FCostValue
FROM #Comm AS A
WHERE NOT EXISTS(SELECT 1 FROM TItemBaseComm AS B
WHERE A.FCompId = B.FCompId
AND A.FItemId = B.FItemId
AND A.FPayTypeId = B.FPayTypeId
AND A.FWorkType = B.FWorkType
AND A.FDispatchMode = B.FDispatchMode)
GROUP BY FCompId,FItemId,FPayTypeId,FWorkType,FDispatchMode,FPerfMode,FPerfValue,FCommMode,FCommValue,FCostMode,FCostValue '
END
--select * from TItemBaseComm WHERE FCompId = 3472331387795668992
--select * from tcompany
drop table #Comm
DELETE TEmpPerfDetailDateCache#
END
GO
--导入产品提成
IF object_id('dbo.PImportBKGoodsBaseComm','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKGoodsBaseComm
END
GO
CREATE PROCEDURE PImportBKGoodsBaseComm
AS
BEGIN
EXEC PExecImportSQL '
select dbo.FNNewId() AS FId,
dbo.FNBKCompId(gfa00c) AS FCompId,
FId AS FGoodsId,
0 AS FPayTypeId,
dbo.FNBKGoodsPerfMode(gfa16i) AS FPerfMode, -- 业绩方式
isnull(gfa17f,0) AS FPerfValue, -- 金额或比率
dbo.FNBKGoodsCommMode(gfa13i) AS FCommMode, -- 提成方式
isnull(gfa14f,0) AS FCommValue,
case when gfa16i IN( 20,21) then 14 when gfa16i = 21 then 15 else 0 end AS FCostMode,
case when gfa16i IN( 20,21) then 1 else 0 end AS FCostValue
INTO #Comm
from {FDB}.gfm01
--WHERE gfa00c = ''006''
--select * from #Comm
-- select FCompId,FGoodsId,SUM(1) FROM #Comm GROUP BY FCompId,FGoodsId
-- order by SUM(1) DESC
DELETE {TDB}.TGoodsBaseComm
INSERT INTO {TDB}.TGoodsBaseComm(FId,FCompId,FGoodsId,FPayTypeId,FPerfMode,FPerfValue,FCommMode,FCommValue,FCostMode,FCostValue)
SELECT dbo.FNNewId(),A.FCompId ,A.FGoodsId,A.FPayTypeId,A.FPerfMode,A.FPerfValue,A.FCommMode,A.FCommValue,A.FCostMode,A.FCostValue
FROM #Comm AS A '
END
GO
--导入储值卡提成
IF object_id('dbo.PImportBKCardBaseComm','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKCardBaseComm
END
GO
CREATE PROCEDURE PImportBKCardBaseComm
AS
BEGIN
EXEC PExecImportSQL '
select dbo.FNNewId() AS FId,
dbo.FNBKCompId(gak00c) AS FCompId,
FId AS FCardTypeId,
0 AS FPayTypeId,
dbo.FNBKCardPerfMode(gak20i) AS FSalePerfMode, -- 卡销售业绩方式
isnull(gak21f,0) AS FSalePerfValue, -- 金额或比率
dbo.FNBKCardCommMode(gak17i) AS FSaleCommMode, -- 卡销售提成方式
isnull(gak18f,0) AS FSaleCommValue,
dbo.FNBKCardPerfMode(gak25i) AS FRchgPerfMode, -- 卡充值业绩方式
isnull(gak26f,0) AS FRchgPerfValue, -- 金额或比率
dbo.FNBKCardCommMode(gak27i) AS FRchgCommMode, -- 卡充值提成方式
isnull(gak28f,0) AS FRchgCommValue,
0 AS FCostMode,
0 AS FCostValue
INTO #Comm
from {FDB}.gam10
-- WHERE gak00c = ''006''
DELETE {TDB}.TMemberCardTypeBaseComm
INSERT INTO {TDB}.TMemberCardTypeBaseComm(FId,FCompId,FCardTypeId,FPayTypeId,FSalePerfMode,FSalePerfValue,FSaleCommMode,FSaleCommValue,FRchgPerfMode,FRchgPerfValue,FRchgCommMode,FRchgCommValue)
SELECT FId,FCompId,FCardTypeId,FPayTypeId,FSalePerfMode,FSalePerfValue,FSaleCommMode,FSaleCommValue,FRchgPerfMode,FRchgPerfValue,FRchgCommMode,FRchgCommValue
FROM #Comm AS A '
END
GO
--清理会员数据
IF object_id('dbo.PImportBKClearMember','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKClearMember
END
GO
CREATE PROCEDURE PImportBKClearMember
AS
BEGIN
EXEC PExecImportSQL '
DELETE {TDB}.TMemberOldTransHist
DELETE {TDB}.TMemberCardOldAcctHist
DELETE {TDB}.TMemberArrear
DELETE {TDB}.TMemberArrearEmployee
DELETE {TDB}.TMemberRepay
DELETE {TDB}.TMemberCardAccount
delete {TDB}.TMemberCardAcctHist
DELETE {TDB}.TMemberCourse
DELETE {TDB}.TMemberTransHist
DELETE {TDB}.TMemberCourseLog
DELETE {TDB}.TMemberPointHist
DELETE {TDB}.TMemberPhoto
DELETE {TDB}.TMemberCard WHERE FCardId > 99
DELETE {TDB}.TMember WHERE FMemId > 99
'
END
GO
--会员资料
IF object_id('dbo.PImportBKMember','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKMember
END
GO
/*
EXEC PExecImportSQL 'SELECT * FROM {TDB}.TConsumeBill '
EXEC PExecImportSQL 'SELECT * FROM {TDB}.TMemberSaleBill '
EXEC PExecImportSQL '
DELETE {TDB}.TMemberOldTransHist
DELETE {TDB}.TMemberCardOldAcctHist
DELETE {TDB}.TMemberArrear
DELETE {TDB}.TMemberArrearEmployee
DELETE {TDB}.TMemberRepay
DELETE {TDB}.TMemberCardAccount
delete {TDB}.TMemberCardAcctHist
DELETE {TDB}.TMemberCourse
DELETE {TDB}.TMemberTransHist
DELETE {TDB}.TMemberCourseHist
DELETE {TDB}.TMemberPointHist
DELETE {TDB}.TMemberPhoto
DELETE {TDB}.TMemberCard WHERE FCardId > 99
DELETE {TDB}.TMember WHERE FMemId > 99
'
*/
CREATE PROCEDURE PImportBKMember
AS
BEGIN
IF OBJECT_ID('TBKMember#') IS NOT NULL
BEGIN
DROP TABLE TBKMember#
END
IF OBJECT_ID('TBKAccount#') IS NOT NULL
BEGIN
DROP TABLE TBKAccount#
END
IF OBJECT_ID('TBKCourse#') IS NOT NULL
BEGIN
DROP TABLE TBKCourse#
END
/*
EXEC PExecImportSQL ' SELECT * FROM {TDB}.TCompany '
EXEC PExecImportSQL ' SELECT * FROM {TDB}.TConsumeBill '
*/
EXEC PExecImportSQL '
IF EXISTS(SELECT TOP 1 1 FROM {TDB}.TMember WHERE FMemId > 99)
BEGIN
RAISERROR (''请先清空所有的会员资料'' , 16, 1, 1, 1, 1)
RETURN
END
IF EXISTS(SELECT TOP 1 1 FROM {TDB}.TMemberCard WHERE FCardId > 99)
BEGIN
RAISERROR (''请先清空所有的会员卡资料'' , 16, 1, 1, 1, 1)
RETURN
END'
IF @@ERROR > 0
BEGIN
RETURN
END
--会员基本资料
EXEC PExecImportSQL '
SELECT FMemId AS FMemId,
gca04c AS gca04c,
dbo.FNBKCompId(gca00c) AS FCompId,
gca01c AS FMemNo, -- 会员编号
CAST('''' AS VARCHAR(100)) AS FName, -- 会员姓名
0 AS FRecvConsSMS, -- 是否发送短信通知(1是2否)
CAST('''' AS VARCHAR(100)) AS FAddress, -- 联络地址
CAST('''' AS VARCHAR(100)) AS FTelephone, -- 家庭Tele No.
CAST('''' AS VARCHAR(100)) AS FMobilePhone, -- Mobile No.
CAST(0 AS BIGINT) AS FChargeEmpId, -- 当前负责业务
CAST('''' AS VARCHAR(100)) AS FEmail, -- E-Mail地址
CAST('''' AS VARCHAR(100)) AS FPostCode, -- 邮编
0 AS FGender, -- 性别(0- female, 1- male )
CAST('''' AS VARCHAR(100)) AS FIdCard , -- 证件编号
CAST(NULL AS DATETIME) AS FBirthday, -- 出生日期
CAST('''' AS VARCHAR(100)) AS FBirthdayType, -- 生日类型
CAST('''' AS VARCHAR(100)) AS FQQ, -- QQ号码
ISNULL(gca12c,'''') AS FCPW,
FCardId AS FCardId,
gca01c AS FCardNo, --卡号
FCardTypeId AS FTypeId, --卡种(Z散客,ZZ门店,ZZZ员工) ,
gca02c,
ISNULL(gca03i,1) AS FValueType, --大类
ISNULL(dbo.FNBKDate(gca05d), ''1753-01-01'') AS FCreateDate , --销售日期
dbo.FNBKDate(gca07d) AS FExpiredDate , --有效日期
dbo.FNBkCardState(gca08i) AS FState, --状态(未销售, 销售未开卡, 正常使用中, 挂失转卡,越期可续卡 , 越期作废卡)
--gca12c varchar(10) NULL , --消费密码
ISNULL(gca14i,0) AS FTotalTimes, --总人次
ISNULL(gca15i,0) AS FUsedTimes , --已使用人次
-- gca18c varchar(10) NULL , --查询密码
ISNULL(gca27c,'''') AS FMemo --备注
INTO TBKMember#
FROM {FDB}.gcm01
WHERE gca00c = gca13d
AND gca08i NOT IN( 1,6,7)
-- and gca00c = ''006''
AND gca01c NOT LIKE ''%散客%'''
IF EXISTS(SELECT FMemNo,count(1) FROM TBKMember# group by FMemNo having count(1) > 1)
BEGIN
RAISERROR ('会员卡重复,导入失败' , 16, 1, 1, 1, 1)
RETURN
END
EXEC PExecImportSQL '
UPDATE A
SET A.FName = ISNULL(gba03c,''''),
-- A.FCreateDate = dbo.FNBkDate(gba02c),
A.FRecvConsSMS = ISNULL(gba04c,''1''),
A.FAddress = ISNULL(gba05c,''''),
A.FTelephone = ISNULL(gba07c,''''),
A.FMobilePhone = ISNULL(gba08c,''''),
A.FChargeEmpId = ISNULL((SELECT TOP 1 FEmpId FROM {TDB}.TEmployeeSub WHERE FSerialNo = gba10c AND FCompId IN( A.FCompId) ),0),
A.FEmail = ISNULL(gba11c,''''),
A.FPostCode = ISNULL(gba12c,'''') ,
A.FGender = ISNULL(gba14i,0) ,
A.FIdCard = ISNULL(gba16c,''''),
A.FBirthday = CASE WHEN ISNULL(gba17d,'''') != '''' THEN dbo.FNBKBirthday(CASE WHEN LEN(gba17d) = 4 THEN ''9999'' + gba17d ELSE gba17d END ) ELSE dbo.FNBKBirthday(CASE WHEN LEN(gba21c) = 4 THEN ''9999'' + gba21c ELSE gba21c END) END ,
A.FBirthdayType = CASE WHEN ISNULL(gba17d,'''') != '''' THEN ''G'' ELSE ''L'' END ,
A.FQQ = ISNULL(gba32c,'''')
FROM TBKMember# AS A,{FDB}.gbm01 AS B
WHERE A.gca04c = B.gba01c AND FName = '''' '
UPDATE TBKMember# SET FCreateDate = '1753-01-01' WHERE FCreateDate IS NULL
UPDATE TBKMember# SET FExpiredDate = '9999-12-31' WHERE FExpiredDate IS NULL
/* EXEC PExecImportSQL ' SELECT * FROM {TDB}.TMember '
DELETE Temp_Member_# WHERE FNo In
(
SELECT FNo FROM Temp_Member_# GROUP BY FNo HAVING count(1) > 999
)
EXEC PExecImportSQL '
SELECT * FROM {FDB}.gcm01 WHERE gca01c = ''19375'' '
EXEC PExecImportSQL '
select * from {FDB}.gam10 WHERE gak01c = ''102'''
EXEC PExecImportSQL '
SELECT * FROM {FDB}.gcm01 WHERE gca08i != 1 AND gca01c NOT LIKE ''散客%'' AND gca02c NOT IN(select gak01c FROM {FDB}.GAM10)'
update TMemberCardType SET FId = dbo.FNBKId(FNo) WHERE FNo IN( '09','11')
*/
/*
SELECT * FROM TBKMember# WHERE FTypeId NOT IN(select FId FROM TMemberCardType)
*/
EXEC PExecImportSQL '
IF EXISTS(SELECT TOP 1 1 FROM {TDB}.TBKMember# WHERE FTypeId NOT IN(select FId FROM {TDB}.TMemberCardType))
BEGIN
RAISERROR (''有会员卡的卡类别不存在,导入失败'' , 16, 1, 1, 1, 1)
RETURN
END'
IF @@ERROR > 0
BEGIN
RETURN;
END
--SELECT * FROM TBKMember# WHERE FTypeId NOT IN(select FId FROM TMemberCardType)
EXEC PExecImportSQL '
INSERT INTO {TDB}.TMember(FMemId,FMemNo,FName,FBriefCode,FTypeId,FCompId,FCreateDate,FGender,FBirthdayType,FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW,FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5)
SELECT FMemId,FMemNo,ISNULL(FName,''''),dbo.FNGetFirstPinYin(FName),0,FCompId,FCreateDate,FGender,FBirthdayType,FBirthday,FTelephone,FMobilePhone,FQQ,'''' AS FWeChat,FIdCard,FEmail,FAddress,0 AS FProId,FCPW,'''' AS FQPW,FChargeEmpId,0 AS FPoint,FRecvConsSMS,FRecvConsSMS AS FRecvBulkSMS,'''' AS FMemo,'''' AS FCustom1,'''' AS FCustom2,'''' AS FCustom3,'''' AS FCustom4,'''' AS FCustom5
FROM TBKMember# '
--DELETE
--EXEC PExecImportSQL ' SELECT * FROM {FDB}.gcm01 WHERE gca08i in(4,5,10) AND gca02c NOT IN(select gak01c FROM {FDB}.GAM10)'
-- delete Temp_Member_# WHERE FMemNo LIKE '%散客%'
-- SELECT * FROM fromServer.s3_qd_NISIKA8HyvUt6pYGo.dbo.gbm01 where gba23c = '5500250'
-- SELECT * FROM Temp_Member_# WHERE FTypeId NOT IN(SELECT FId FROM TMemberCardType)
EXEC PExecImportSQL '
INSERT INTO {TDB}.TMemberCard(FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FMemo)
SELECT FCardId,FCardNo,FCardNo AS FFaceNo,FTypeId,ISNULL(FValueType,0),FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FCompId AS FSaleCompId,0 AS FSaleBillId,FMemo
FROM TBKMember# '
--账户
EXEC PExecImportSQL '
SELECT A.FMemId AS FMemId, --会员ID
A.FCardId AS FCardId, --卡号
C.FCompId AS FCompId,
C.FTypeId AS FCardTypeId,
gcc03i AS FBKAcctId,
case when gcc03i = 0 then 0 else (SELECT FId FROM TPayAccount WHERE FBKAcctId = gcc03i) end AS FAcctId, --帐号类别(1-电子钱包,2-储值帐号,3-积分,4-储值账户二,5-储值账户二)
ISNULL(gcc06f,0) AS FBalance, --馀额
ISNULL(gcc07f,0) AS FAlertBalance, --安全馀额
dbo.FNBKDate(gcc08c) AS FCreateDate, --账号开立日期
dbo.FNBKDate(gcc09d) AS FExpiredDate, --账号截至日期
ISNULL(gcc10f,0) AS FArrear, --帐户欠款
ISNULL(gcc11c,'''') AS FMemo --备注
INTO TBKAccount#
FROM {FDB}.gcm03 AS A ,{TDB}.TBKMember# AS C
WHERE gcc01c = C.FCardNo
AND dbo.FNBKCompId(gcc00c) = C.FCompId
--AND gcc03i NOT IN(4)' --疗程账户,
-- SELECT * FROM TPayAccount ORDER BY FBKAcctId
--写入账户
EXEC PExecImportSQL '
INSERT INTO {TDB}.TMemberCardAccount(FId,FMemId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT dbo.FNNewId(),FMemId,FCardId,FAcctId,FBalance,FBalance,FArrear,FCreateDate,NULL,FMemo
FROM TBKAccount#
WHERE FBKAcctId NOT IN(3,4,888,999,889)
--TODO
AND FCardId IN(SELECT FCardId FROM TMemberCard) '
--delete Temp_Account_# WHERE FCardId = 7583214202515789572
--SELECT * FROM Temp_Account_# WHERE FAcctId IS NULL AND FCardId = 7714057480398863723
--写入积分
EXEC PExecImportSQL '
UPDATE A
SET A.FPoint = B.FBalance
FROM {TDB}.TMember AS A,TBKAccount# AS B
WHERE A.FMemId = B.FMemId
AND B.FBKAcctId = 3 ' --积分
--积分历史
EXEC PExecImportSQL '
DELETE {TDB}.TMemberPointHist WHERE FBillType = ''DR''
INSERT {TDB}.TMemberPointHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime)
SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,''DR'',''Import'',0,'''',FPoint,0,FPoint,'''',getdate()
FROM {TDB}.TMember AS A WHERE FPoint != 0 AND FMemId IN(SELECT FMemId FROM TBKMember#)'
--账户欠款
EXEC PExecImportSQL '
INSERT {TDB}.TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear)
SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,''Account'',A.FCardId,''DR_KK'',''DR_CardSale'',0,'''',0,A.FAcctId,A.FArrear,0,0,A.FArrear
FROM TBKAccount# AS A
WHERE A.FArrear > 0
AND A.FAcctId IS NOT NULL
AND FBKAcctId NOT IN(3,4,888,999,889) AND FMemId IN(SELECT FMemId FROM TBKMember#)
'
--账户历史
EXEC PExecImportSQL '
INSERT INTO {TDB}.TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
SELECT dbo.FNNewId(),A.FMemId,A.FCardId,A.FAcctId,getdate(),A.FCardTypeId,A.FCompId,''DR'',''Import'',0,'''',A.FBalance,0,A.FBalance,A.FArrear,getdate(),''''
FROM TBKAccount# AS A
WHERE (A.FBalance > 0 OR A.FArrear > 0)
AND FBKAcctId NOT IN(3,888,999,889)
-- AND A.FAcctId NOT NULL'
--疗程
EXEC PExecImportSQL '
SELECT FId AS FId,
gca01c AS FMemNo,
dbo.FNBkCompId(gcf00c) AS FCompId,
M.FMemId AS FMemId,
FItemId AS FItemId,
FCourseId AS FCourseId,
0 AS FPackId,
0 AS FMemPackId,
(SELECT TOP 1 FId FROM {TDB}.TBasicType WHERE FKey=''CourseType'') AS FTypeId,
CASE WHEN ISNULL(gcf07f,0) > ISNULL(gcf05f,0) THEN ISNULL(gcf07f,0) ELSE ISNULL(gcf05f,0) END AS FPurTimes,
CASE WHEN ISNULL(gcf07f,0) > ISNULL(gcf05f,0) THEN 0 ELSE ISNULL(gcf05f,0) - ISNULL(gcf07f,0) END AS FUsedPurTimes,
-- CASE WHEN ISNULL(gcf10f,0) > ISNULL(gcf08f,0) THEN ISNULL(gcf10f,0) ELSE ISNULL(gcf08f,0) END AS FPurAmount,
CAST (0 AS DECIMAL(18,6)) AS FPurAmount,
gcf10f,
ISNULL(dbo.FNBKDate(gcf11d),getdate()) AS FPurchaseDate,
dbo.FNBKDate(gcf12d) AS FExpiredDate,
''DR.Import'' AS FBizType,
0 AS FTransId,
0 AS FArrear,
0 AS FDurable,
ISNULL(gcf15c,'''') AS FMemo,
CASE WHEN ISNULL(gcf22i,0) = 1 THEN 2 ELSE 1 END AS FCalcMode,
0 AS FFreeTimes,
0 AS FUsedFreeTimes,
CAST(0 AS DECIMAL(18,6)) AS FAdjustPrice
INTO TBKCourse#
FROM {FDB}.gcm06,{FDB}.gcm01, {TDB}.TBKMember# AS M
WHERE gcf00c = gca00c
AND gca00c = gca13d
AND gca01c = gcf01c
AND gca01c = M.FCardNo
AND gcf02c != ''''
--疗程金额,根据剩余金额反算
UPDATE TBKCourse#
SET FPurAmount = FPurTimes * (ISNULL(gcf10f,0) / (FPurTimes - FUsedPurTimes))
WHERE FPurTimes - FUsedPurTimes > 0
--核算单价
UPDATE TBKCourse#
SET FAdjustPrice = FPurAmount / FPurTimes
WHERE FPurTimes != 0
--select * from #Course WHERE FCourseId NOT IN (SELECT FId FROM {TDB}.TCourse)
INSERT {TDB}.TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FId,FMemId,ISNULL(FCourseId,0),FMemPackId,ISNULL(FItemId,0),FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice
FROM TBKCourse# '
EXEC PExecImportSQL '
INSERT INTO {TDB}.TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime)
SELECT dbo.FNNewId(),FMemId,A.FId AS FMemCourseId,0, ISNULL(FCourseId,0),getdate(),FPurTimes,FFreeTimes,0,0,FCompId,''DR'',''Import'',0,'''',0,getdate()
FROM {TDB}.TMemberCourse AS A '
--服务产品欠款
EXEC PExecImportSQL '
INSERT {TDB}.TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid)
SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,''DR_ItemGoods'',A.FCardId,''DR_XF'',''DR_Consume'',0,'''',0,0,A.FArrear,0,0
FROM TBKAccount# AS A
WHERE A.FArrear > 0
AND A.FBKAcctId = 888'
--疗程欠款
EXEC PExecImportSQL '
INSERT {TDB}.TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear)
SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,''DR_Course'',0,''DR_KK'',''DR_CardSale'',0,'''',0,A.FAcctId,A.FArrear,0,0,0
FROM TBKAccount# AS A
WHERE A.FArrear > 0
AND A.FAcctId IS NOT NULL
AND FBKAcctId IN(4) '
-- EXEC PExecImportSQL ' SELECT * FROM {FDB}.gcm04 WHERE NOT EXISTS(SELECT 1 FROM {TDB}.TPayAccount WHERE FBKAcctId = gcd02i) '
--老系统账户历史
EXEC PExecImportSQL '
SELECT dbo.FNNewId() AS FId,
C.FCardId AS FCardId,
C.FMemId AS FMemId,
C.FTypeId AS FCardTypeId,
dbo.FNBKCompId(gcd00c) AS FCompId,
(SELECT FId FROM TPayAccount WHERE FBKAcctId = gcd02i) AS FAcctId,
dbo.FNBKAcctOper(gcd05i) AS FBizType,
'''' AS FBillType,
0 AS FTransId,
gcd08c AS FTransNo,
gcd05i ,
gcd06f,gcd10f,
CASE WHEN gcd05i IN(0,6) THEN ISNULL(gcd06f,0) ELSE 0 END AS FInAmount,
CASE WHEN gcd05i NOT IN(0,6) THEN ISNULL(gcd06f,0) ELSE 0 END AS FOutAmount,
CASE WHEN gcd05i IN(0,6) THEN ISNULL(gcd06f,0) + ISNULL(gcd10f,0) ELSE ISNULL(gcd10f,0) - ISNULL(gcd06f,0) END AS FBalance,
dbo.FNBKTime(gcd09d,gcd13t) AS FTime,
ISNULL(dbo.FNBKTime(gcd11c,gcd13t),''1753-01-01'') AS FRecordTime,
'''' AS FMemo,
0 AS FArrear
INTO #AcctHist
FROM {FDB}.gcm04 AS A, {TDB}.TBKMember# AS C
WHERE A.gcd01c = C.FCardNo
AND A.gcd02i NOT IN(4,888,999,889)
AND a.gcd02i != 0
INSERT INTO {TDB}.TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
SELECT FId,FMemId,FCardId,FAcctId,ISNULL(FTime,''1753-01-01''),FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo
FROM #AcctHist'
--账户历史
/*SELECT * FROM s3_qd_NISIKA8HyvUt6pYGo..gcm04
SELECT C.FId AS FCardId,
C.FMemId AS FMemId,*/
----交易历史
--select * from TMemberOldTransHist WHERE FMemId IN(SELECT FMemId FROM TBKMember#)
--SELECT * FROM s3_qd_NISIKA8HyvUt6pYGo..gcm20
EXEC PExecImportSQL '
SELECT C.FCardId AS FCardId,
C.FMemId AS FMemId,
dbo.FNBKTime(gct04d,gct19t) AS FTime,
dbo.FNBKCompId(gct00c) AS FCompId,
CASE WHEN gct13c IN (''gn'',''gz'') THEN ''DR.KK'' WHEN gct13c =''gx'' THEN ''DR.XF'' ELSE ''DR'' END AS FBillType,
dbo.FNBKTransBizType(gct06c) AS FBizType,
gct14c AS FTransNo,
isnull(gct07c,'''') + isnull(gct08c,'''') AS FContent,
isnull(gct10f,0) AS FPrice, --标准单价
isnull(gct11f,0) AS FQuantity, --数量
isnull( gct12f,0) AS FAmount, --价格
CASE WHEN ISNULL(gct20c,'''') != '''' THEN (SELECT TOP 1 FName FROM {TDB}.TPayAccount WHERE FBKPayNo=gct20c) ELSE '''' END AS FPayment,
CASE WHEN ISNULL(gct15c,'''') != '''' THEN ISNULL(gct15c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct15c),'''') + '','' ELSE '','' END
+CASE WHEN ISNULL(gct16c,'''') != '''' THEN ISNULL(gct16c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct16c),'''') + '','' ELSE '','' END
+CASE WHEN ISNULL(gct17c,'''') != '''' THEN ISNULL(gct17c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct17c),'''') + '','' ELSE '','' END
+CASE WHEN ISNULL(gct18c,'''') != '''' THEN ISNULL(gct18c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct18c),'''') + '','' ELSE '','' END
AS FEmployee
INTO #TransHist
FROM {FDB}.gcm20, {TDB}.TBKMember# AS C
WHERE C.FCardNo = gct02c
INSERT {TDB}.TMemberOldTransHist(FId,FCompId,FMemId,FTime,FCardId,FBIllType,FBizType,FTransNo,FCOntent,FPrice,FQuantity,FAmount,FPayment,Femployee,FMemo)
SELECT dbo.FNNewId(),FCompId,FMemId,ISNULL(FTime,''1753-01-01''),FCardId,FBIllType,FBizType,FTransNo AS FTransNo,FCOntent,FPrice,FQuantity,FAmount,ISNULL(FPayment,''''),Femployee, '''' AS FMemo
FROM #TransHist'
--select * from TUser
--DROP TABLE Temp_Member_#
--DROP TABLE Temp_Member_Card_#
--DROP TABLE Temp_Account_#
--照片
/*
EXEC PExecImportSQL '
INSERT {TDB}.TMemberPhoto(FMemId,FType,FImage,FImagePath,FChangeId)
select FMemId,1,gbd02p,'''',1 from {FDB}.gbm04 ,{FDB}.gcm01
where gbd00c = gca00c
and gca00c = gca13d
and gca04c = gbd01c and FMemId IN(SELECT FMemId FROM {TDB}.TMember)'
*/
RETURN
--套餐
EXEC PExecImportSQL '
INSERT TMemberCoursePack(FId,FMemId,FPackId,FCompId,FItemTimes,FItemUsedTimes,FGoodsQuantity,FGoodsUsedQuantity,FAmount,FArrear,FPurchaseDate,FBizType,FTransId,FUseUp)
SELECT A.FMemPackId,A.FMemId,A.FPackId,M.FCompId,0,0,0,0,0,0,getdate(),''DR.Import'',0,0
FROM {FDB}.TMemberCoursePack AS A,{FDB}.gcm01 AS B,TMember AS M
WHERE M.FMemId = A.FMemId
AND B.gca00c = b.gca13d
AND B.FMemId = a.FMemId
'
EXEC PExecImportSQL '
INSERT {TDB}.TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT A.FCardId,A.FMemId,0,FMemPackId,FItemId,M.FCompId,FPurTimes,FUsedPurTimes, 0,0,0,getdate(),NULL,''DR.Import'',0,0,0,'''',1,FAdjustPrice
FROM {FDB}.gtc04 AS A,TMember AS M ,{FDB}.gcm01 AS B
WHERE A.FMemId = M.FMemId
AND B.gca00c = gca13d
AND B.GCA00C = A.gte00c
AND B.GCA01C = A.GtE01C
'
SELECT * FROM TMemberGoods
EXEC PExecImportSQL '
INSERT {TDB}.TMemberGoods(FCompId,FId,FMemId,FPackCardId,FCourseCardId,FGoodsId,FUnitId,FPurQuantity,FUsedPurQuantity,FPurAmount,FCalcMode,FFreeQuantity,FUsedFreeQuantity,FAdjustPrice,FBizType,FBillId)
SELECT dbo.FNBKCompId(gca00c),A.FId,A.FMemId,FMemPackId,0,FGoodsId,M.FCompId,FQuantity,FUsedQuantity,0,1,0,0,0,''DR.Import'',0
FROM {FDB}.gtc08 AS A,TMember AS M ,{FDB}.gcm01 AS B
WHERE A.FMemId = M.FMemId
AND B.gca00c = gca13d
AND B.GCA00C = A.gtJ00c
AND B.GCA01C = A.GtJ01C'
END
GO
--导库存
IF object_id('dbo.PImportBKInvntory','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKInvntory
END
GO
CREATE PROCEDURE PImportBKInvntory
AS
BEGIN
EXEC PExecImportSQL '
delete {TDB}.TInventoryLog
delete {TDB}.TInventory '
EXEC PExecImportSQL '
INSERT {TDB}.TInventoryLog(FId,FIOType,FCompId,FGoodsId,FStoreId,FBatchNo,FTime,FBillType,FBizType,FBillId,FBillDetailId,FBillNo,
FUnitId,FInQuantity,FOutQuantity,FInStdQuantity,FOutStdQuantity,FPrice,FAmount,FBalance,FOperatorId,FMemo)
SELECT dbo.FNNewId(),22001, dbo.FNBKCompId(A.FCompNo),A.FGoodsId,A.FStoreId,'''',getdate(),''DR'',''StockIn'',0,0,'''',
A.FUnitId,A.FQuantity,0 AS FOutQuantity,A.FQuantity AS FInStdQuantity,
0 AS FOutStdQuantity,A.FPrice AS FPrice,A.FAmount AS FAmount,A.FQuantity AS FBalance,0 AS FOperatorId,'''' AS FMemo
FROM {FDB}.TInventory AS A'
EXEC PExecImportSQL '
UPDATE A
SET A.FUnitId = B.FUnitId
FROM {TDB}.TInventoryLog AS A,{TDB}.TGoods AS B
WHERE A.FGoodsId = B.FId '
EXEC PExecImportSQL '
DELETE {TDB}.TInventory
INSERT TInventory(FId,FCompId,FGoodsId,FStoreId,FBatchNo,FProdDate,FPeriodDate,FQuantity)
SELECT dbo.FNNewId(),A.FCompId,A.FGoodsId,A.FStoreId,A.FBatchNo,NULL,NULL,A.FInStdQuantity
FROM TInventoryLog AS A '
END
GO
--打印结果
IF object_id('dbo.PImportBKReport','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PImportBKReport
END
GO
CREATE PROCEDURE PImportBKReport
AS
BEGIN
DECLARE @Count VARCHAR(111)
SELECT @Count = SUM(1) FROM TCompany WHERE FId > 0
PRINT @Count + ' 个公司'
SELECT @Count = SUM(1) FROM TItem WHERE FId > 0
PRINT @Count + ' 个项目资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TCourse WHERE FId > 0
PRINT @Count + ' 个疗程资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TGoods WHERE FId > 0
PRINT @Count + ' 个产品资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TEmployee WHERE FId > 0
PRINT @Count + ' 个员工资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMember WHERE FMemId > 99
PRINT @Count + ' 个会员资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberCard WHERE FCardId > 99
PRINT @Count + ' 个储值卡资料' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberCardAccount
PRINT @Count + ' 个储值卡账户' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberCourse
PRINT @Count + ' 个会员疗程' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberArrear
PRINT @Count + ' 条欠款'
SELECT @Count = SUM(1) FROM TMemberCardAcctHist
PRINT @Count + ' 条账户历史' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberCardOldAcctHist
PRINT @Count + ' 条老系统账户历史' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
SELECT @Count = SUM(1) FROM TMemberOldTransHist
PRINT @Count + ' 条老系统交易历史' + CASE WHEN @Count = '0' THEN ' !!!! 请注意, 数量为0 ' ELSE '' END
END
GO
/*
--从这里开始, 一句句执行
--公司
EXEC dbo.PImportBKCompany
--用户
EXEC dbo.PImportBKUser
--账户
EXEC dbo.PImportBKPayAccount
--基本类别
EXEC dbo.PImportBKBasicType
--员工
EXEC dbo.PImportBKEmployee
--项目
EXEC dbo.PImportBKItem
--产品
EXEC dbo.PImportBKGoods
--卡类别
EXEC dbo.PImportBKCardType
--项目折扣
EXEC dbo.PImportBKItemDiscount
--项目提成
EXEC dbo.PImportBKItemBaseComm
--产品提成
EXEC dbo.PImportBKGoodsBaseComm
--卡提成
EXEC dbo.PImportBKCardBaseComm
--会员数据
EXEC dbo.PImportBKMember
SELECT * FROM TCompany
DELETE TBasicTypeSub WHERE FCompId != 1
SELECT * FROM TEmployee
DELETE TEmployee WHERE FId NOT IN(SELECT FEmpId FROM TEmployeeSub)
SELECT * FROM TMember WHERE FCompId = 3472331387795668992
SELECT * FROM TLoginSession
UPDATE TCompany SET FDeleted = 1 WHERE FId = 6397389486610108187
PChangeCenterCompany '002'
UPDATE TCompany SET FNo = '001' WHERE FNo = '002'
SELECT * FROM TConsumeBill
SELECT * FROM TSMSTEMPLATE
SELECT * FROM TMember WHERE FCPW !=''
UPDATE
TSMSTEMPLATE SET FCompId = 1
--库存
EXEC dbo.PImportBKInvntory
-----------------------------------------------
--清理所有的会员数据,谨慎!!!,
--先看看数据库有没有选对, 有没有业务数据了
--看看是不是这个公司
SELECT * FROM TCompany
--这句查看是否已经有消费单了
SELECT * FROM TConsumeBill
--这句查看是否已经有开卡单了
SELECT * FROM TMemberSaleBill
--- select * from TBKMember#
--- select * from TMemberCardAcctHist
----执行清理,上面确认无误后再执行这句
EXEC dbo.PImportBKClearMember
-------------------------------------------------------
--!!!!!!!! 最后检查一下,重要
EXEC dbo.PImportBKReport
--转密码
--结束
*/
/*
INSERT TGoodsDiscountMaster(FId,FCompId,FGoodsId,FType,FCreateDate)
SELECT FId,dbo.FNBKCompId(gdf00c),FItemId,1,getdate()
FROM db108.s3_zibo_XIANGGETY80OjNq.dbo.gdm06 as a
WHERE FItemId != ''
AND gdf02c = 2
AND gdf00c != ''
INSERT TGoodsDiscountDetail(FId,FMasterId,FCardTypeId,FPayTypeId,FBeginDate,FEndDate,FCalcMode,FValue,FMinValue)
SELECT dbo.FNNewId(),A.FMasterId,FCardTypeId,FPayTypeId,'1753-01-01','1753-01-01',2,ISNULL(gdg04f,0),0
FROM db108.s3_zibo_XIANGGETY80OjNq.dbo.gdm07 AS A,
TGoodsDiscountMaster AS B
WHERE A.FMasterId = B.FId
*/