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.
1039 lines
54 KiB
1039 lines
54 KiB
12 months ago
|
--导入公司资料
|
||
|
INSERT INTO QingDao_saidao06.dbo.TCompany(FId,FNo,FName,FAbbr,FAreaId,FParentId,FAddress,FTelephone,FEmail,FWebsite,FWeChatNo,
|
||
|
FWeChatQRCode,FIntroduction,FAdmin,FIsCenter,FLocationLat,FLocationLng)
|
||
|
SELECT QingDao_saidao06.dbo.FNBkCompId(gae01c),
|
||
|
gae01c,gae02c,gae03c,0,0,isnull(gae08c,''''),
|
||
|
isnull(gae06c,''''),'''','''','''','''','''',
|
||
|
isnull(gae14c,''''),0,0,0 FROM
|
||
|
QingDao_MEIKABO_BAK2.dbo.gam05
|
||
|
|
||
|
|
||
|
--导入用户
|
||
|
INSERT INTO QingDao_saidao06.dbo.TUser(FId,FNo,FName,FEmpId,FPW,FCreateTime,FUserType)
|
||
|
SELECT FId,gaa01c,ISNULL(gaa06c,''),0,isnull(gaa02c,''),getdate(),'' as PCClient
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gam01
|
||
|
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.TUserAllowCompany(FId,FUserId,FCompId)
|
||
|
SELECT dbo.FNNewId(),A.FId,C.FId
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.GAM02 AS B,QingDao_saidao06.dbo.TCompany AS C ,QingDao_saidao06.dbo.TUser AS A
|
||
|
WHERE B.gab03c = C.FNo
|
||
|
AND B.gab02c = '2'
|
||
|
AND A.FNo = B.gab01c
|
||
|
|
||
|
delete from QingDao_saidao06.dbo.TUserAllowCompany WHERE FUserId = (SELECT FId FROM QingDao_saidao06.dbo.TUser WHERE FNo = 'ADMIN')
|
||
|
UPDATE QingDao_saidao06.dbo.TUser SET FId = 1 WHERE FNo = 'ADMIN'
|
||
|
|
||
|
--导入支付方式
|
||
|
--现金
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount A,QingDao_MEIKABO_BAK2.dbo.gsm02 B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 1
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '1'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--银行卡
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 2
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '6'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--抵用券
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 5
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '3'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--储值账户
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 3
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '4'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--储值账户
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 9
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '5'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--银行卡
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount A,QingDao_MEIKABO_BAK2.dbo.gsm02 B,QingDao_MEIKABO_BAK2.dbo.gsm14 s
|
||
|
WHERE A.FId = 2
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '6'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
|
||
|
--积分
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 11
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '7'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--经理签单
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 8
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '8'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--疗程账户
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 6
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = '9'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--微信
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 20
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = 'WX'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--支付宝
|
||
|
UPDATE A
|
||
|
SET A.FName = b.gsb03c,
|
||
|
A.FBKAcctId = s.gsn02c,
|
||
|
A.FBKPayNo = s.gsn01c
|
||
|
FROM QingDao_saidao06.dbo.TPayAccount AS A,QingDao_MEIKABO_BAK2.dbo.gsm02 AS B,QingDao_MEIKABO_BAK2.dbo.gsm14 as s
|
||
|
WHERE A.FId = 21
|
||
|
AND B.gsb00c = '001'
|
||
|
AND B.gsb01c = '3'
|
||
|
AND B.gsb02c = 'ZF'
|
||
|
AND s.gsn01c = gsb02c
|
||
|
|
||
|
--电子钱包
|
||
|
|
||
|
IF EXISTS(SELECT TOP 1 1 FROM QingDao_MEIKABO_BAK2.dbo.gcm03 WHERE gcc03i = 1) AND NOT EXISTS(SELECT TOP 1 1 FROM QingDao_saidao06.dbo.TPayAccount WHERE FId = 14 )
|
||
|
BEGIN
|
||
|
INSERT INTO QingDao_saidao06.dbo.TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit,FBKAcctId,FBKPayNo)
|
||
|
SELECT 14,'DZ',(SELECT gsb03c FROM QingDao_MEIKABO_BAK2.dbo.gsm02 WHERE gsb01c = 'o' AND gsb02c = '1' AND gsb00c = '001'),'',1,1,20,-1,'1','2'
|
||
|
END
|
||
|
|
||
|
--内调
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FEnabled,FOrder,FAllowEdit,FBKAcctId,FBKPayNo)
|
||
|
SELECT dbo.FNNewId(),'0',(SELECT gsb03c FROM QingDao_MEIKABO_BAK2.dbo.gsm02 WHERE gsb01c = '3' AND gsb02c = '0' AND gsb00c = '001'),'',0,1,20,-1,'0','0'
|
||
|
|
||
|
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
|
||
|
|
||
|
--导入基本类别
|
||
|
IF NOT EXISTS (SELECT TOP 1 1 FROM QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 11001)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 11002)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 11003)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 11004)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 10001)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 10002)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 10003)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType WITH(NOLOCK) WHERE FId = 10004)
|
||
|
BEGIN
|
||
|
INSERT QingDao_saidao06.dbo.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
|
||
|
VALUES(10004,'ServeDispatchMode','4','自定义2',10012,'','',1,14,1)
|
||
|
END
|
||
|
|
||
|
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gsm02
|
||
|
WHERE gsb00c = '001'
|
||
|
|
||
|
DELETE #BasicType WHERE LEN(FKey) <= 3
|
||
|
|
||
|
DELETE A
|
||
|
FROM QingDao_saidao06.dbo.TBasicType AS A,#BasicType AS B
|
||
|
WHERE A.FKey = B.FKey
|
||
|
AND A.FNo = B.FNo
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TBasicType AS A, QingDao_MEIKABO_BAK2.dbo.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 QingDao_saidao06.dbo.TBasicType AS A, QingDao_MEIKABO_BAK2.dbo.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 QingDao_saidao06.dbo.TBasicType WHERE FKey = 'Store'
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FEnabled)
|
||
|
SELECT FId,'Store',gad01c,gad02c,0,'','',1,1
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gam04
|
||
|
WHERE gad00c = '001'
|
||
|
|
||
|
--导入员工
|
||
|
DECLARE @ExcludeCompNo VARCHAR(5)
|
||
|
SELECT @ExcludeCompNo = ''
|
||
|
IF (SELECT COUNT(1) FROM QingDao_MEIKABO_BAK2.dbo.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,--部门编号
|
||
|
CONVERT(datetime,'2030-01-01') AS FEntryDate ,--到职日期
|
||
|
CONVERT(datetime,'1900-01-01') AS FLeaveDate,--离职日期
|
||
|
CONVERT(datetime,'2030-01-01') AS FExpiredDate,--合约到期日
|
||
|
MAX(ISNULL(haa12c,'')) AS FIdCard,--身份证号
|
||
|
CONVERT(datetime,'1980-01-01') 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 --是否可以预约
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.ham01
|
||
|
WHERE 1=1
|
||
|
--isnull(haa00c,'') != ''
|
||
|
-- AND haa00c IN(SELECT FNo FROM QingDao_saidao06.dbo.TCompany)
|
||
|
-- AND haa00c != '001'
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.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 QingDao_saidao06.dbo.TCompany)
|
||
|
-- AND haa00c = '005'
|
||
|
AND haa00c != @ExcludeCompNo
|
||
|
|
||
|
DELETE QingDao_saidao06.dbo.TEmployee
|
||
|
WHERE FNo IN (SELECT FNo FROM #Employee)
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TEmployeeSub(FEmpId,FCompId,FSerialNo)
|
||
|
SELECT A.FId,A.FCompId,FSerialNo
|
||
|
FROM #Company AS A
|
||
|
|
||
|
DROP TABLE #Employee
|
||
|
|
||
|
--导入项目
|
||
|
DELETE QingDao_saidao06.dbo.TCourse WHERE FId > 1
|
||
|
DELETE QingDao_saidao06.dbo.TItemSub
|
||
|
DELETE QingDao_saidao06.dbo.TItem WHERE FId > 1
|
||
|
SELECT dbo.FNNewId() AS FId,
|
||
|
dbo.FNNewId() AS FCourseId,
|
||
|
FNo AS FNo,
|
||
|
gda03c AS FName,
|
||
|
ISNULL((SELECT FId FROM QingDao_saidao06.dbo.TBasicType WHERE FNo = gda04c AND FKey = 'ItemDiscountType') ,0) AS FDctId,
|
||
|
ISNULL(gda10f,0) AS FPrice,
|
||
|
ISNULL(gda11f,0) AS FVipPrice ,
|
||
|
ISNULL((SELECT FId FROM QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.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 QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.gcm06)
|
||
|
BEGIN
|
||
|
-- INSERT #Temp VALUES(1)
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FEnabled)
|
||
|
SELECT dbo.FNNewId(),'CourseType','1','疗程1',0,'','',1,1
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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,
|
||
|
dbo.FNNewId() 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 QingDao_saidao06.dbo.TCourse
|
||
|
SET FBriefCode = dbo.FNGetFirstPinYin(FName)
|
||
|
END
|
||
|
|
||
|
|
||
|
DROP TABLE #Item
|
||
|
|
||
|
--导入产品
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gfm01
|
||
|
WHERE gfa00c = '001'
|
||
|
-- AND FId NOT IN(SELECT FId FROM TGoods)
|
||
|
|
||
|
DELETE QingDao_saidao06.dbo.TGoods
|
||
|
DELETE QingDao_saidao06.dbo.TGoodsMultiUnit
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TGoods AS A
|
||
|
|
||
|
DROP TABLE #Goods
|
||
|
|
||
|
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.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 QingDao_MEIKABO_BAK2.dbo.GFM01 as g
|
||
|
WHERE ISNULL(gfa08c,'') != ''
|
||
|
AND gfa07c != ISNULL(gfa08c,'')
|
||
|
AND gfa00c = '001'
|
||
|
|
||
|
|
||
|
INSERT INTO TItemCostGoods(FId,FItemId,FGoodsId,FGoodsUnitId,FGoodsQuantity)
|
||
|
SELECT dbo.FNNewId(),FItemId,FGoodsId,FUnitId,gfe03f
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.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)
|
||
|
|
||
|
--导入卡类别
|
||
|
DECLARE @Count INT
|
||
|
SELECT @Count = count(1)
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gam10
|
||
|
WHERE gak00c != '001'
|
||
|
AND gak01c NOT IN(SELECT gak01c FROM QingDao_MEIKABO_BAK2.dbo.gam10 WHERE gak00c = '001')
|
||
|
|
||
|
IF @Count > 0
|
||
|
BEGIN
|
||
|
RAISERROR ('会员卡类别不统一', 16, 1, 1, 1, 1)
|
||
|
return
|
||
|
END
|
||
|
|
||
|
|
||
|
SELECT dbo.FNNewId() 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 QingDao_MEIKABO_BAK2.dbo.gam10
|
||
|
WHERE gak00c = '001'
|
||
|
|
||
|
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.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
|
||
|
|
||
|
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)
|
||
|
|
||
|
--导入套餐
|
||
|
INSERT TCoursePack(FId,FNo,FName,FBriefCode,FItemTimes,FGoodsQuantity,FValidityPeriod,FValidityPeriodUniT,
|
||
|
FCreateDate,FExpiredDate,FDescription,FPrice,FDeptid,FAcctId,FDeposit,FEnabled,FAcctId2,FDeposit2)
|
||
|
SELECT
|
||
|
dbo.FNNewId() as FId,
|
||
|
'' as 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 QingDao_MEIKABO_BAK2.dbo.gtc01
|
||
|
WHERE gta00c = '001'
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
|
||
|
SELECT '' as FID,'' as FNo,'','','' as FItemId,'' as FPackId,0,0,gtb03f,0,0,0,0,getdate(),null,'',1,gtb04f,0,1
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gtc02 AS A
|
||
|
WHERE gtb00c = '001'
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.TCourseGoods(FId,FCourseId,FGoodsId,FPackId,FQuantity,FUnitId,Fprice)
|
||
|
SELECT '' as FID,0,'' as FGoodsId,'' as FPackId,ISNULL(gtd03f,0),'' as FUnitId,ISNULL(gtd04f,0)
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gtc03 AS A
|
||
|
WHERE gtd00c = '001'
|
||
|
|
||
|
--导入折扣
|
||
|
INSERT QingDao_saidao06.dbo.TItemDiscountMaster(FId,FCompId,FItemId,FType,FCreateDate,FWeek,FTimeMode)
|
||
|
SELECT FId,dbo.FNBKCompId(gdf00c),FItemId,1,getdate(),'YYYYYYY',0
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gdm06 as a WHERE FItemId != '' AND gdf02c = 1
|
||
|
|
||
|
UPDATE A
|
||
|
SET A.FPayTypeId = B.FId
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gdm07 AS A,TPayAccount AS B
|
||
|
WHERE A.gdg11i = B.FBKAcctId
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.gdm07 AS A WITH(NOLOCK) ,
|
||
|
(SELECT FMasterId,FCardTypeId,FPayTypeId,MIN(gdg10f) AS FIndex FROM QingDao_MEIKABO_BAK2.dbo.gdm07 AS F,QingDao_MEIKABO_BAK2.dbo.gdm06 AS G
|
||
|
WHERE G.FId = F.FMasterId
|
||
|
-- AND gdg00c = ''002''
|
||
|
GROUP BY FMasterId,FCardTypeId,FPayTypeId) AS B
|
||
|
INNER JOIN QingDao_MEIKABO_BAK2.dbo.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
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.gdm07 AS A,QingDao_saidao06.dbo.TItemDiscountMid AS B
|
||
|
WHERE A.FId = B.FId
|
||
|
|
||
|
--导入项目提成
|
||
|
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
|
||
|
)
|
||
|
|
||
|
SELECT TOP 1 1 FROM QingDao_MEIKABO_BAK2.dbo.syscolumns WHERE name = 'hea56c' AND id = (select id from QingDao_MEIKABO_BAK2.dbo.sysobjects where name ='hem01' and type = 'U')
|
||
|
|
||
|
|
||
|
--导入产品提成
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gfm01
|
||
|
--WHERE gfa00c = ''006''
|
||
|
|
||
|
--select * from #Comm
|
||
|
-- select FCompId,FGoodsId,SUM(1) FROM #Comm GROUP BY FCompId,FGoodsId
|
||
|
-- order by SUM(1) DESC
|
||
|
|
||
|
DELETE QingDao_saidao06.dbo.TGoodsBaseComm
|
||
|
INSERT INTO QingDao_saidao06.dbo.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
|
||
|
|
||
|
--导入储值卡提成
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gam10
|
||
|
-- WHERE gak00c = ''006''
|
||
|
|
||
|
DELETE QingDao_saidao06.dbo.TMemberCardTypeBaseComm
|
||
|
INSERT INTO QingDao_saidao06.dbo.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
|
||
|
|
||
|
--会员基本资料
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gcm01
|
||
|
WHERE gca00c = gca13d
|
||
|
AND gca08i NOT IN( 1,6,7)
|
||
|
-- and gca00c = '006'
|
||
|
AND gca01c NOT LIKE '%散客%'
|
||
|
|
||
|
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 QingDao_saidao06.dbo.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,QingDao_MEIKABO_BAK2.dbo.gbm01 AS B
|
||
|
WHERE A.gca04c = B.gba01c AND FName = ''
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 dbo.FNNewId() as 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#
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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#
|
||
|
INSERT INTO QingDao_saidao06.dbo.TMemberCard(FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FMemo)
|
||
|
SELECT dbo.FNNewId() as 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#
|
||
|
|
||
|
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gcm03 AS A ,QingDao_saidao06.dbo.TBKMember# AS C
|
||
|
WHERE gcc01c = C.FCardNo
|
||
|
AND dbo.FNBKCompId(gcc00c) = C.FCompId
|
||
|
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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#
|
||
|
INSERT INTO QingDao_saidao06.dbo.TMemberCard(FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FMemo)
|
||
|
SELECT dbo.FNNewId() as 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#
|
||
|
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gcm03 AS A ,QingDao_saidao06.dbo.TBKMember# AS C
|
||
|
WHERE gcc01c = C.FCardNo
|
||
|
AND dbo.FNBKCompId(gcc00c) = C.FCompId
|
||
|
--AND gcc03i NOT IN(4)
|
||
|
|
||
|
|
||
|
UPDATE A
|
||
|
SET A.FPoint = B.FBalance
|
||
|
FROM QingDao_saidao06.dbo.TMember AS A,TBKAccount# AS B
|
||
|
WHERE A.FMemId = B.FMemId
|
||
|
AND B.FBKAcctId = 3
|
||
|
|
||
|
DELETE QingDao_saidao06.dbo.TMemberPointHist WHERE FBillType = 'DR'
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TMember AS A WHERE FPoint != 0 AND FMemId IN(SELECT FMemId FROM TBKMember#)
|
||
|
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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#)
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 is NOT NULL
|
||
|
|
||
|
|
||
|
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 QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.gcm06,QingDao_MEIKABO_BAK2.dbo.gcm01, QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TCourse)
|
||
|
INSERT QingDao_saidao06.dbo.TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
|
||
|
SELECT distinct 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#
|
||
|
|
||
|
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 QingDao_saidao06.dbo.TMemberCourse AS A
|
||
|
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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)
|
||
|
|
||
|
|
||
|
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 QingDao_MEIKABO_BAK2.dbo.gcm04 AS A, QingDao_saidao06.dbo.TBKMember# AS C
|
||
|
WHERE A.gcd01c = C.FCardNo
|
||
|
AND A.gcd02i NOT IN(4,888,999,889)
|
||
|
AND a.gcd02i != 0
|
||
|
|
||
|
INSERT INTO QingDao_saidao06.dbo.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 where FAcctId is not null
|
||
|
|
||
|
|
||
|
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 QingDao_saidao06.dbo.TPayAccount WHERE FBKPayNo=gct20c) ELSE '' END AS FPayment,
|
||
|
CASE WHEN ISNULL(gct15c,'') != '' THEN ISNULL(gct15c,'') + '-' + ISNULL((SELECT TOP 1 haa02c FROM QingDao_MEIKABO_BAK2.dbo.ham01 WHERE haa00c = gct00c AND haa01c = gct15c),'') + ',' ELSE ',' END
|
||
|
+CASE WHEN ISNULL(gct16c,'') != '' THEN ISNULL(gct16c,'') + '-' + ISNULL((SELECT TOP 1 haa02c FROM QingDao_MEIKABO_BAK2.dbo.ham01 WHERE haa00c = gct00c AND haa01c = gct16c),'') + ',' ELSE ',' END
|
||
|
+CASE WHEN ISNULL(gct17c,'') != '' THEN ISNULL(gct17c,'') + '-' + ISNULL((SELECT TOP 1 haa02c FROM QingDao_MEIKABO_BAK2.dbo.ham01 WHERE haa00c = gct00c AND haa01c = gct17c),'') + ',' ELSE ',' END
|
||
|
+CASE WHEN ISNULL(gct18c,'') != '' THEN ISNULL(gct18c,'') + '-' + ISNULL((SELECT TOP 1 haa02c FROM QingDao_MEIKABO_BAK2.dbo.ham01 WHERE haa00c = gct00c AND haa01c = gct18c),'') + ',' ELSE ',' END
|
||
|
AS FEmployee
|
||
|
INTO #TransHist
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gcm20, QingDao_saidao06.dbo.TBKMember# AS C
|
||
|
WHERE C.FCardNo = gct02c
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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
|
||
|
|
||
|
|
||
|
|
||
|
INSERT TMemberCoursePack(FId,FMemId,FPackId,FCompId,FItemTimes,FItemUsedTimes,FGoodsQuantity,FGoodsUsedQuantity,FAmount,FArrear,FPurchaseDate,FBizType,FTransId,FUseUp)
|
||
|
SELECT A.FId,A.FMemId,A.FPackId,M.FCompId,0,0,0,0,0,0,getdate(),'DR.Import',0,0
|
||
|
FROM QingDao_saidao06.dbo.TMemberCoursePack AS A,QingDao_MEIKABO_BAK2.dbo.gcm01 AS B,TMember AS M
|
||
|
WHERE M.FMemId = A.FMemId
|
||
|
AND B.gca00c = b.gca13d
|
||
|
AND B.FMemId = a.FMemId
|
||
|
|
||
|
/*
|
||
|
INSERT QingDao_saidao06.dbo.TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
|
||
|
SELECT B.FCardId,B.FMemId,0,'0' as FMemPackId,'' as FItemId,M.FCompId,'' as FPurTimes,getdate() as FUsedPurTimes, 0,0,0,getdate(),NULL,'DR.Import',0,0,0,'',1,'0' as FAdjustPrice
|
||
|
FROM QingDao_MEIKABO_BAK2.dbo.gtc04 AS A,TMember AS M ,QingDao_MEIKABO_BAK2.dbo.gcm01 AS B
|
||
|
WHERE B.gca00c = gca13d
|
||
|
AND B.GCA00C = A.gte00c
|
||
|
AND B.GCA01C = A.GtE01C
|
||
|
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.gtc08 AS A,TMember AS M ,QingDao_MEIKABO_BAK2.dbo.gcm01 AS B
|
||
|
WHERE A.FMemId = M.FMemId
|
||
|
AND B.gca00c = gca13d
|
||
|
AND B.GCA00C = A.gtJ00c
|
||
|
AND B.GCA01C = A.GtJ01C
|
||
|
|
||
|
*/
|
||
|
|
||
|
INSERT QingDao_saidao06.dbo.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 QingDao_MEIKABO_BAK2.dbo.TInventory AS A
|
||
|
|
||
|
UPDATE A
|
||
|
SET A.FUnitId = B.FUnitId
|
||
|
FROM QingDao_saidao06.dbo.TInventoryLog AS A,QingDao_saidao06.dbo.TGoods AS B
|
||
|
WHERE A.FGoodsId = B.FId
|